CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
BesEventAction.cc
Go to the documentation of this file.
1#include "BesEventAction.hh"
2#include "G4Event.hh"
3#include "G4TrajectoryContainer.hh"
4#include "G4Trajectory.hh"
5#include "G4VVisManager.hh"
6
7#include "G4DigiManager.hh"
8#include "BesMdcDigitizer.hh"
9#include "BesCgemDigitizer.hh"
10#include "BesTofDigitizer.hh"
11#include "BesMucDigitizer.hh"
12#include "BesEmcDigitizer.hh"
13
14#include "BesRunAction.hh"
15#include "G4RunManager.hh"
16#include "BesAsciiIO.hh"
17#include "BesMdcHit.hh"
18#include "BesCgemHit.hh"
19#include "BesRootIO.hh"
20#include "BesTDSWriter.hh"
21#include "BesTuningIO.hh"
22
24#include "BesTruthTrack.hh"
25#include "BesTruthVertex.hh"
26#include <fstream>
27
28#include "GaudiKernel/SvcFactory.h"
29#include "GaudiKernel/ISvcLocator.h"
30#include "GaudiKernel/SmartDataPtr.h"
31#include "GaudiKernel/Bootstrap.h"
32
33using namespace std;
34
35#include "ReadBoostRoot.hh"
36#include "G4UImanager.hh"
37
39 :m_runAction(runAction)
40{
41 ISvcLocator* svcLocator = Gaudi::svcLocator();
42 IRealizationSvc *tmpReal;
43 StatusCode sc = svcLocator->service("RealizationSvc",tmpReal);
44 if (!sc.isSuccess())
45 {
46 std::cout << " Could not initialize Realization Service in BesEventAction" << std::endl;
47 } else {
48 m_RealizationSvc=dynamic_cast<RealizationSvc*>(tmpReal);
49 }
50
51 m_DM = G4DigiManager::GetDMpointer();
52
54 {
55 BesMdcDigitizer* mdcDM = new BesMdcDigitizer("BesMdcDigitizer");
56 m_DM->AddNewModule(mdcDM);
57 }
58
60 {
61 BesCgemDigitizer* cgemDM = new BesCgemDigitizer("BesCgemDigitizer");
62 m_DM->AddNewModule(cgemDM);
63 }
65 {
66 BesTofDigitizer* tofDM = new BesTofDigitizer("BesTofDigitizer");
67 m_DM->AddNewModule(tofDM);
68 }
70 {
71 BesEmcDigitizer* emcDM = new BesEmcDigitizer("BesEmcDigitizer");
72 m_DM->AddNewModule(emcDM);
73 }
75 {
76 BesMucDigitizer* mucDM = new BesMucDigitizer("BesMucDigitizer");
77 m_DM->AddNewModule(mucDM);
78 }
79
80}
81
83{
84 delete m_DM;
85}
86
87void BesEventAction::BeginOfEventAction(const G4Event* evt)
88{
89
90 G4int eventId = evt->GetEventID();
91 //if (eventId%5000==0)
92 // G4cout<<"---> Begin of event: "<<eventId<<G4endl;
93
94 G4UImanager* uiMgr = G4UImanager::GetUIpointer();
95 //if(eventId == 46 || eventId == 75)
96 // uiMgr->ApplyCommand("/tracking/verbose 1");
97 //else
98 // uiMgr->ApplyCommand("/tracking/verbose 0");
99
100 //mc truth
101 if (m_runAction)
102 if (m_runAction->GetMCTruthFlag()!=0)
103 {
105 sensitiveManager->BeginOfTruthEvent(evt);
106 }
107}
108
109void BesEventAction::EndOfEventAction(const G4Event* evt)
110{
111 if (G4VVisManager::GetConcreteInstance())
112 {
113 G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
114 G4int n_trajectories = 0;
115 if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
116
117 for (G4int i=0; i<n_trajectories; i++)
118 {
119 G4Trajectory* trj = (G4Trajectory*)
120 ((*(evt->GetTrajectoryContainer()))[i]);
121
122 trj->DrawTrajectory(50);
123
124 }
125 }
126
127 //mc truth
129 if (m_runAction)
130 if (m_runAction->GetMCTruthFlag()!=0)
131 {
132 sensitiveManager->EndOfTruthEvent(evt);
133 }
134
136 if (m_runAction)
137 {
138 //Ascii I/O, output hit collections
139 BesAsciiIO* asciiIO = m_runAction->GetAsciiIO();
140 if (asciiIO) {
141 if (m_RealizationSvc->UseDBFlag() == true) asciiIO->SaveHitAsciiEvents(m_RealizationSvc->getRunId(), evt);
142 else asciiIO->SaveHitAsciiEvents(m_runAction->GetRunId(), evt);
143 }
144
145 //Root I/O, output MdcHit collections
146 BesRootIO* rootIO = m_runAction->GetRootIO();
147 if (rootIO){
148 //emc digitization
149 if (ReadBoostRoot::GetEmc()) m_DM->Digitize("BesEmcDigitizer");
150
151 if (m_RealizationSvc->UseDBFlag() == true) rootIO->SaveHitRootEvent(m_RealizationSvc->getRunId(), evt);
152 else rootIO->SaveHitRootEvent(m_runAction->GetRunId(), evt);
153 }
154 }
155 }else{
156 //Tuning I/O
158 if (m_runAction)
159 {
160 BesTuningIO* tuningIO = m_runAction->GetTuningIO();
161 if (tuningIO){
163 {
164 tuningIO->GetRootEvent(evt->GetEventID());
165 }
166 else{
167 tuningIO->GetNextEvents();
168 }
169 }
170
171 }
172 }
173 //mdc digitization
174
176 m_DM->Digitize("BesMdcDigitizer");
177
178 //cgem digitization
179
181 m_DM->Digitize("BesCgemDigitizer");
182
183 //tof digitization
185 m_DM->Digitize("BesTofDigitizer");
186
187 //emc digitization
189 m_DM->Digitize("BesEmcDigitizer");
190
191 //muc digitization
193 m_DM->Digitize("BesMucDigitizer");
194
195
196 if (m_runAction)
197 {
198 //Ascii I/O, output digi collections
199 BesAsciiIO* asciiIO = m_runAction->GetAsciiIO();
200 if (asciiIO)
201 {
202 if (m_RealizationSvc->UseDBFlag() == true) asciiIO->SaveAsciiEvents(m_RealizationSvc->getRunId(), evt);
203 else asciiIO->SaveAsciiEvents(m_runAction->GetRunId(), evt);
204 }
205
206 // Root I/O,output digi collections
207 BesTDSWriter* tdsWriter = m_runAction->GetTDSWriter();
208 if (tdsWriter)
209 {
210 if (m_RealizationSvc->UseDBFlag() == true) tdsWriter->SaveAll(evt, m_RealizationSvc->getRunId() );
211 else tdsWriter->SaveAll(evt, m_runAction->GetRunId() );
212 }
213 }
214 }
215
216 sensitiveManager->ClearEvent();
217 //HepRandom::saveEngineStatus("EndSimCurrEvt.rndm");
218}
219
220
221
222
223
224
225
226
227
228
229
230
231
void SaveHitAsciiEvents(G4int, const G4Event *)
void SaveAsciiEvents(G4int, const G4Event *)
Definition BesAsciiIO.cc:65
virtual void EndOfEventAction(const G4Event *)
BesEventAction(BesRunAction *)
virtual void BeginOfEventAction(const G4Event *)
virtual ~BesEventAction()
void SaveHitRootEvent(G4int, const G4Event *)
Definition BesRootIO.cc:68
BesTuningIO * GetTuningIO()
G4int GetRunId()
BesRootIO * GetRootIO()
BesTDSWriter * GetTDSWriter()
G4int GetMCTruthFlag()
BesAsciiIO * GetAsciiIO()
void EndOfTruthEvent(const G4Event *)
void BeginOfTruthEvent(const G4Event *)
static BesSensitiveManager * GetSensitiveManager()
void SaveAll(const G4Event *, int)
void GetRootEvent(int evtID)
void GetNextEvents(void)
static G4int GetFormatAR()
static G4int GetHitOut()
static G4int GetCgem()
static G4int GetTuning()
static G4int GetMdc()
static G4int GetMuc()
static G4int GetTof()
static G4int GetEmc()