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