2 #include "G4SDManager.hh" 3 #include "G4UnitsTable.hh" 4 #include "G4ParticleTypes.hh" 5 #include "G4VProcess.hh" 12 #include "CLHEP/Units/PhysicalConstants.h" 13 using namespace CLHEP;
18 collectionName.insert(
HCname);
23 hd_msg3 =
gemcOpt.
optMap[
"LOG_MSG"].args +
" End of Hit Collections >> ";
44 if(HCID < 0) HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
45 HCE->AddHitsCollection( HCID, hitCollection );
46 ProcessHitRoutine = NULL;
48 cout <<
" > " << collectionName[0] <<
" initialized." << endl;
56 double depe = aStep->GetTotalEnergyDeposit();
62 G4VTouchable* THH = (G4VTouchable*) aStep->GetPreStepPoint()->GetTouchable();
63 string aname = THH->GetVolume(0)->GetName();
65 if(depe == 0 && RECORD_PASSBY == 0 && aStep->GetTrack()->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition())
70 if(
HCname ==
"mirror" && RECORD_MIRROR == 0)
return false;
72 G4Track *trk = aStep->GetTrack();
73 if(trk->GetDefinition()->GetParticleName().find(
"unknown") != string::npos)
return false;
75 G4StepPoint *prestep = aStep->GetPreStepPoint();
76 G4StepPoint *poststep = aStep->GetPostStepPoint();
77 string processName =
"na";
79 G4VTouchable* TH = (G4VTouchable*) aStep->GetPreStepPoint()->GetTouchable();
84 double Dx = aStep->GetStepLength();
85 string name = TH->GetVolume(0)->GetName();
86 G4ThreeVector xyz = poststep->GetPosition();
87 G4ThreeVector Lxyz = prestep->GetTouchableHandle()->GetHistory()
88 ->GetTopTransform().TransformPoint(xyz);
89 G4ThreeVector vert = trk->GetVertexPosition();
90 double ctime = poststep->GetGlobalTime();
91 G4ThreeVector pxyz = prestep->GetMomentum();
92 double ene = prestep->GetTotalEnergy();
93 int tid = trk->GetTrackID();
94 int pid = trk->GetDefinition()->GetPDGEncoding();
95 int q = (int) trk->GetDefinition()->GetPDGCharge();
96 if(trk->GetCreatorProcess())
97 processName = trk->GetCreatorProcess()->GetProcessName();
98 string materialName = poststep->GetMaterial()->GetName();
103 if(ProcessHitRoutine == NULL)
110 if(ProcessHitRoutine == NULL)
112 cout << endl <<
" !!! Error: >" << name <<
"< NOT FOUND IN ProcessHit Map. Exiting" << endl;
118 vector<identifier> PID = ProcessHitRoutine->
processID(VID, aStep, (*
hallMap)[name]);
119 int singl_hit_size = VID.size();
120 int multi_hit_size = PID.size()/singl_hit_size;
123 for(
int mh = 0; mh<multi_hit_size; mh++)
125 vector<identifier> mhPID;
127 for(
int this_id = 0; this_id<singl_hit_size; this_id++)
130 this_shit.
name = PID[this_id + mh*singl_hit_size].name;
131 this_shit.
rule = PID[this_id + mh*singl_hit_size].rule;
132 this_shit.
id = PID[this_id + mh*singl_hit_size].id;
133 this_shit.
time = PID[this_id + mh*singl_hit_size].time;
134 this_shit.
TimeWindow = PID[this_id + mh*singl_hit_size].TimeWindow;
135 this_shit.
TrackId = PID[this_id + mh*singl_hit_size].TrackId;
136 this_shit.
id_sharing = PID[this_id + mh*singl_hit_size].id_sharing;
137 mhPID.push_back(this_shit);
140 if(verbosity > 9 || name.find(catch_v) != string::npos)
141 cout << endl << hd_msg2 <<
" Before hit Process Identification:" << endl << VID
142 << hd_msg2 <<
" After: hit Process Identification:" << endl << mhPID << endl;
145 if(verbosity > 9) cout << endl << endl <<
" BEGIN SEARCH for same hit in Identifier Set..." << endl;
147 set<vector<identifier> > :: iterator itid;
150 for(itid =
Id_Set.begin(); itid!=
Id_Set.end() && !hit_found; itid++)
152 if(*itid == mhPID) hit_found=1;
154 cout <<
" >> Current Step: " << mhPID
155 <<
" >> Set Hit Index: " << *itid
156 << (hit_found ?
" >> FOUND at this Set Entry. " :
" >> Not found yet. ") << endl;
158 if(verbosity > 10) cout <<
" SEARCH ENDED." << (hit_found ?
" 1 " :
" No ") <<
"hit found in the Set." << endl << endl;
170 thisHit->
SetEdep(depe*mhPID[singl_hit_size-1].id_sharing);
176 thisHit->
SetId(mhPID);
182 hitCollection->insert(thisHit);
185 if(verbosity > 6 || name.find(catch_v) != string::npos)
187 string pid = aStep->GetTrack()->GetDefinition()->GetParticleName();
188 cout << endl << hd_msg1 << endl
189 <<
" > This element was not hit yet in this event. Identity:" << endl << thisHit->
GetId()
190 <<
" > Creating new hit by a E=" << ene/MeV <<
", p=" << pxyz.mag()/MeV <<
" MeV " << pid
191 <<
", track ID = " << tid <<
", inside Hit Collection <" <<
HCname <<
">." << endl
192 <<
" > Energy Deposited this step: " << depe/MeV <<
" MeV" << endl
193 <<
" > Time of this step: " << G4BestUnit(ctime,
"Time") << endl
194 <<
" > Position of this step: " << xyz/cm <<
" cm" << endl
195 <<
" > Local Position in volume: " << Lxyz/cm <<
" cm" << endl;
206 cout <<
" Hit not found in collection but found in PID. This should never happen. Exiting." << endl;
215 thisHit->
SetEdep(depe*mhPID[singl_hit_size-1].id_sharing);
226 if(verbosity > 6 || name.find(catch_v) != string::npos)
228 string pid = aStep->GetTrack()->GetDefinition()->GetParticleName();
229 cout << hd_msg2 <<
" Step Number " << thisHit->
GetPos().size()
230 <<
" inside Identity: " << endl << thisHit->
GetId()
231 <<
" > Adding hit inside Hit Collection <" <<
HCname <<
">." 232 <<
" by a E=" << ene/MeV <<
", p=" << pxyz.mag()/MeV <<
" MeV " 233 << pid <<
", track ID = " << tid << endl
234 <<
" > Energy Deposited this step: " << depe/MeV <<
" MeV" << endl
235 <<
" > Time of this step: " << G4BestUnit(ctime,
"Time")
236 <<
" is within this element Time Window of " <<
SDID.
timeWindow/ns <<
" ns. " << endl
237 <<
" > Position of this step: " << xyz/cm <<
" cm" << endl
238 <<
" > Local Position in volume: " << Lxyz/cm <<
" cm" << endl;
252 int nhitC = hitCollection->GetSize();
256 if(verbosity > 2 && nhitC)
259 cout << hd_msg3 <<
" Hit Collections <" <<
HCname <<
">: " << nhitC <<
" hits." << endl;
261 for (
int i=0; i<nhitC; i++)
263 aHit = (*hitCollection)[i];
264 string vname = aHit->
GetId()[aHit->
GetId().size()-1].name;
265 if(verbosity > 5 || vname.find(catch_v) != string::npos)
267 cout << hd_msg3 <<
" Hit " << i + 1 <<
" -- total number of steps this hit: " << aHit->
GetPos().size() << endl;
268 cout << aHit->
GetId();
270 for(
unsigned int e=0; e<aHit->
GetPos().size(); e++) Etot = Etot + aHit->
GetEdep()[e];
271 cout <<
" Total energy deposited: " << Etot/MeV <<
" MeV" << endl;
275 if(ProcessHitRoutine)
delete ProcessHitRoutine;
282 for(
unsigned int i=0; i<hitCollection->GetSize(); i++)
283 if((*hitCollection)[i]->GetId() == PID)
return (*hitCollection)[i];
293 if(procName ==
"eIoni")
return 1;
294 if(procName ==
"compt")
return 2;
295 if(procName ==
"eBrem")
return 3;
296 if(procName ==
"phot")
return 4;
297 if(procName ==
"conv")
return 5;
298 if(procName ==
"annihil")
return 6;
299 if(procName ==
"photonNuclear")
return 7;
300 if(procName ==
"electronNuclear")
return 8;
301 if(procName ==
"hadElastic")
return 9;
302 if(procName ==
"protonInelastic")
return 10;
303 if(procName ==
"neutronInelastic")
return 11;
304 if(procName ==
"pi-Inelastic")
return 12;
305 if(procName ==
"pi+Inelastic")
return 13;
306 if(procName ==
"hIoni")
return 14;
307 if(procName ==
"nCapture")
return 15;
308 if(procName ==
"Decay")
return 16;
309 if(procName ==
"muIoni")
return 17;
310 if(procName ==
"CoulombScat")
return 18;
311 if(procName ==
"Cerenkov")
return 19;
312 if(procName ==
"dInelastic")
return 20;
313 if(procName ==
"muPairProd")
return 21;
314 if(procName ==
"ionIoni")
return 22;
315 if(procName ==
"hPairProd")
return 23;
316 if(procName ==
"tInelastic")
return 24;
317 if(procName ==
"kaon-Inelastic")
return 25;
319 if(procName ==
"na")
return 90;
321 cout <<
" process name " << procName <<
" not catalogued." << endl;
vector< identifier > SetId(vector< identifier > Iden, G4VTouchable *TH, double time, double TimeWindow, int TrackId)
Sets the ncopy ID accordingly to Geant4 Volumes copy number. Sets time, TimeWindow, TrackId.
virtual void EndOfEvent(G4HCofThisEvent *)
Virtual Method called at the end of each hit event.
sensitiveID SDID
sensitiveID used for identification, hit properties and digitization
G4String HCname
Sensitive Detector/Hit Collection Name.
MHit * find_existing_hit(vector< identifier >)
returns hit collection hit inside identifer
void SetPos(G4ThreeVector xyz)
vector< identifier > GetId()
vector< identifier > GetDetectorIdentifier(string name)
returns detector identity
virtual vector< identifier > processID(vector< identifier >, G4Step *, detector)=0
int id
manually assing ID. 0 if "ncopy" (will be set at hit processing time)
goptions gemcOpt
gemc option class
string name
Name of the detector.
void SetDetector(detector det)
int processID(string procName)
map< string, HitProcess_Factory > * hitProcessMap
Hit Process Routine Factory Map.
void SetEdep(double depe)
double TimeWindow
Time Window. If abs(steptime - time) is smaller than TimeWindow, it's the same hit.
virtual void Initialize(G4HCofThisEvent *)
Virtual Method called at the beginning of each hit event.
int TrackId
If Time Window is 0, it's a "flux" detector: if it's the same track, it's the same hit...
void SetMom(G4ThreeVector pxyz)
vector< G4ThreeVector > GetPos()
void SetProcID(int procID)
map< string, aopt > optMap
Options map.
set< vector< identifier > > Id_Set
Identifier Set. Used to determine if a step is inside a new/existing element.
G4THitsCollection< MHit > MHitCollection
void SetId(vector< identifier > iden)
double timeWindow
If two steps happens within the same TimeWindow, they belong to the same Hit.
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
Virtual Method called for each step of each hit.
double id_sharing
A single step can generate multiple identifiers. This variable represent the percentage sharing of th...
map< string, detector > * hallMap
detector map
double time
Time of the first step.
void SetSDID(sensitiveID s)
virtual ~sensitiveDetector()
void SetLPos(G4ThreeVector xyz)
void SetMatName(string mname)
string GetDetectorHitType(string name)
returns detector hitType
sensitiveDetector(G4String, goptions, string factory, int run, string variation, string system)
Constructor.
void SetTime(double ctime)
vector< double > GetEdep()
void SetVert(G4ThreeVector ver)
string rule
"manual" or "ncopy"
HitProcess * getHitProcess(map< string, HitProcess_Factory > *hitProcessMap, string HCname)