5 #include "G4RunManager.hh" 6 #include "G4Trajectory.hh" 21 for(
int t=0; t<size; t++)
29 vector<G4ThreeVector> zthre;
30 for(
int t=0; t<size; t++)
31 zthre.push_back(G4ThreeVector(0,0,0));
36 vector<int>
vector_mtids(map<int, TInfos> tinfos, vector<int> tids)
39 for(
unsigned int t=0; t<tids.size(); t++)
40 mtids.push_back(tinfos[tids[t]].mtid);
45 vector<int>
vector_mpids(map<int, TInfos> tinfos, vector<int> tids)
48 for(
unsigned int t=0; t<tids.size(); t++)
49 mpids.push_back(tinfos[tids[t]].mpid);
54 vector<G4ThreeVector>
vector_mvert(map<int, TInfos> tinfos, vector<int> tids)
56 vector<G4ThreeVector> mvert;
57 for(
unsigned int t=0; t<tids.size(); t++)
58 mvert.push_back(tinfos[tids[t]].mv);
66 hd_msg = gemcOpt.
args[
"LOG_MSG"].args +
" Event Action: >> ";
67 Modulo = (int) gemcOpt.args[
"PRINT_EVENT"].arg ;
68 VERB = gemcOpt.args[
"OUT_VERBOSITY"].arg ;
69 catch_v = gemcOpt.args[
"CATCH"].args;
70 SAVE_ALL_MOTHERS = (
int) gemcOpt.args[
"SAVE_ALL_MOTHERS"].arg ;
72 MAXP = (int) gemcOpt.args[
"NGENP"].arg;
84 cout << hd_msg <<
" Begin of event " << evtN << endl;
85 cout << hd_msg <<
" Random Number: " << G4UniformRand() << endl;
93 cout << hd_msg <<
" End of Event " << evtN <<
" Routine..." << endl;
103 for(map<string, MSensitiveDetector*>::iterator it = SeDe_Map.begin(); it!= SeDe_Map.end(); it++)
107 MHC = it->second->GetMHitCollection();
108 nhits = MHC->GetSize();
110 for(
int h=0; h<nhits; h++)
112 vector<int> tids = (*MHC)[h]->
GetTIds();
113 for(
unsigned int t=0; t<tids.size(); t++)
114 track_db.insert(tids[t]);
120 map<int, TInfos> tinfos;
121 set<int>::iterator it;
124 G4TrajectoryContainer *trajectoryContainer;
128 trajectoryContainer = evt->GetTrajectoryContainer();
130 while(trajectoryContainer && track_db.size())
133 for(
unsigned int i=0; i< trajectoryContainer->size(); i++)
136 G4Trajectory* trj = (G4Trajectory*)(*(evt->GetTrajectoryContainer()))[i];
137 int tid = trj->GetTrackID();
141 it = track_db.find(tid);
142 if(it != track_db.end())
144 int mtid = trj->GetParentID();
145 tinfos[tid] =
TInfos(mtid);
155 map<int, TInfos>::iterator itm;
156 for(itm = tinfos.begin(); itm != tinfos.end(); itm++)
158 int mtid = (*itm).second.mtid;
160 for(
unsigned int i=0; i< trajectoryContainer->size() && mtid != 0; i++)
162 G4Trajectory* trj = (G4Trajectory*)(*(evt->GetTrajectoryContainer()))[i];
163 int tid = trj->GetTrackID();
166 tinfos[(*itm).first].mpid = trj->GetPDGEncoding();
167 tinfos[(*itm).first].mv = trj->GetPoint(0)->GetPosition();
179 map<string, MOutput_Factory>::iterator ito = Out->find(MOut->outType);
180 if(ito == Out->end())
182 if(MOut->outType !=
"no")
183 cout << hd_msg <<
" Warning: output type <" << MOut->outType <<
"> is not registered in the <MOutput_Factory>. " << endl
184 <<
" This event will not be written out." << endl;
197 head.
beamPol = gen_action->getBeamPol();
198 head.
targetPol = gen_action->getTargetPol();
203 vector<MGeneratedParticle> MPrimaries;
204 for(
int pv=0; pv<evt->GetNumberOfPrimaryVertex() && pv<MAXP; pv++)
207 G4PrimaryVertex* MPV = evt->GetPrimaryVertex(pv);
208 Mparticle.
vertex = MPV->GetPosition();
209 for(
int pp = 0; pp<MPV->GetNumberOfParticle() && pv<MAXP; pp++)
212 G4PrimaryParticle *PP = MPV->GetPrimary(pp);
213 Mparticle.
momentum = PP->GetMomentum();
214 Mparticle.
PID = PP->GetPDGcode();
216 MPrimaries.push_back(Mparticle) ;
218 ProcessOutput-> WriteGenerated(MOut, MPrimaries);
220 for(map<string, MSensitiveDetector*>::iterator it = SeDe_Map.begin(); it!= SeDe_Map.end(); it++)
224 MHC = it->second->GetMHitCollection();
225 nhits = MHC->GetSize();
232 ProcessOutput->
SetBankHeader(it->second->SDID.id, it->first, MOut);
236 hitType = it->second->GetDetectorHitType(vname);
239 map<string, MPHB_Factory>::iterator itp = MProcessHit_Map->find(hitType);
240 if(itp == MProcessHit_Map->end())
242 cout << hd_msg <<
" Warning: hit Type <" << hitType <<
"> is not registered in the <MProcessHit_Map>. " << endl
243 <<
" This hit collection will not be processed." << endl;
248 ProcessHitRoutine->
gpars = gPars;
250 for(
int h=0; h<nhits; h++)
257 vector<int> tids = aHit->
GetTIds();
264 int thisHitSize = aHit->
GetId().size();
266 vector<G4ThreeVector> zthre =
vector_zthre(thisHitSize);
272 output = ProcessHitRoutine->
ProcessHit(aHit, gemcOpt);
273 ProcessOutput->
ProcessOutput(output, MOut, (*MBank_Map)[hitType]);
275 string vname = aHit->
GetId()[aHit->
GetId().size()-1].name;
276 if(VERB > 4 || vname.find(catch_v) != string::npos)
278 cout << hd_msg <<
" Hit " << h + 1 <<
" -- total number of steps this hit: " << aHit->
GetPos().size() << endl;
279 cout << aHit->
GetId();
281 for(
unsigned int e=0; e<aHit->
GetPos().size(); e++) Etot = Etot + aHit->
GetEdep()[e];
282 cout <<
" Total energy deposited: " << Etot/MeV <<
" MeV" << endl;
285 delete ProcessHitRoutine;
298 delete ProcessOutput;
300 if(evtN%Modulo == 0 )
301 cout <<
" done." << endl << endl;;
virtual PH_output ProcessHit(MHit *, gemc_opts)=0
Virtual Method to process the hit.
void SetmPIDs(vector< int > mpid)
void SetmTrackIds(vector< int > tid)
vector< identifier > GetId()
virtual void WriteEvent(MOutputs *)=0
Pure Virtual Method to write event on disk.
G4THitsCollection< MHit > MHitCollection
vector< G4ThreeVector > vector_zthre(int size)
provides a vector of (0,0,0)
vector< int > vector_mpids(map< int, TInfos > tinfos, vector< int > tids)
void EndOfEventAction(const G4Event *)
Routine at the end of each event.
void BeginOfEventAction(const G4Event *)
Routine at the start of each event.
MEventAction(gemc_opts, map< string, double >)
Constructor copies gemc options.
vector< G4ThreeVector > vector_mvert(map< int, TInfos > tinfos, vector< int > tids)
MOutputBaseClass * GetMOutputClass(map< string, MOutput_Factory > *MProcessOutput_Map, string outputType)
Instantiates MOutputBaseClass.
vector< G4ThreeVector > GetPos()
string name
Name of the volume. Since this is the key of the STL map, it has to be unique.
map< string, double > gpars
MPHBaseClass * GetMPHClass(map< string, MPHB_Factory > *MProcessHit_Map, string HCname)
Return MPHBaseClass from the Hit Process Map.
vector< int > vector_mtids(map< int, TInfos > tinfos, vector< int > tids)
virtual void RecordAndClear(MOutputs *, MBank)=0
Pure Virtual Method to record hits in event / then clear hits objects on heap.
map< string, opts > args
Options map.
virtual void SetOutpHeader(header, MOutputs *)=0
Pure Virtual Method to set the output header. MOutputs needed for some output (txt) ...
vector< double > GetEdep()
void SetmVerts(vector< G4ThreeVector > ver)
virtual void SetBankHeader(int, string, MOutputs *)=0
Pure Virtual Method to set the bank header.
~MEventAction()
Destructor.
vector< int > vector_zint(int size)
provides a vector of 0
virtual void ProcessOutput(PH_output, MOutputs *, MBank)=0
Pure Virtual Method to process the output.