4 #include "G4SDManager.hh" 5 #include "G4UnitsTable.hh" 6 #include "G4ParticleTypes.hh" 19 collectionName.insert(
HCname);
24 hd_msg1 =
gemcOpt.
args[
"LOG_MSG"].args +
" New Hit: <<< ";
26 hd_msg3 =
gemcOpt.
args[
"LOG_MSG"].args +
" End of Hit Collections >> ";
40 if(HCID < 0) HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
41 HCE->AddHitsCollection( HCID, hitCollection );
42 ProcessHitRoutine = NULL;
50 double depe = aStep->GetTotalEnergyDeposit();
56 if(depe == 0 && RECORD_PASSBY == 0 && aStep->GetTrack()->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition())
return false;
59 if(
HCname ==
"Mirrors" && RECORD_MIRROR == 0)
return false;
61 G4Track *trk = aStep->GetTrack();
62 if(trk->GetDefinition()->GetParticleName().find(
"unknown") != string::npos)
return false;
64 G4StepPoint *prestep = aStep->GetPreStepPoint();
65 G4StepPoint *poststep = aStep->GetPostStepPoint();
67 G4VTouchable* TH = (G4VTouchable*) aStep->GetPreStepPoint()->GetTouchable();
72 double Dx = aStep->GetStepLength();
73 string name = TH->GetVolume(0)->GetName();
74 G4ThreeVector xyz = poststep->GetPosition();
75 G4ThreeVector Lxyz = prestep->GetTouchableHandle()->GetHistory()
76 ->GetTopTransform().TransformPoint(xyz);
77 G4ThreeVector vert = trk->GetVertexPosition();
78 double ctime = poststep->GetGlobalTime();
79 G4ThreeVector pxyz = prestep->GetMomentum();
80 double ene = prestep->GetTotalEnergy();
81 int tid = trk->GetTrackID();
82 int pid = trk->GetDefinition()->GetPDGEncoding();
83 int q = (int) trk->GetDefinition()->GetPDGCharge();
88 if(ProcessHitRoutine == NULL)
93 if(!ProcessHitRoutine)
95 cout << endl << hd_msg2 <<
" Hit Process Routine <" <<
GetDetectorHitType(name) <<
"> not found. Exiting. " << endl;
101 int singl_hit_size = VID.size();
102 int multi_hit_size = PID.size()/singl_hit_size;
105 for(
int mh = 0; mh<multi_hit_size; mh++)
107 vector<identifier> mhPID;
109 for(
int this_id = 0; this_id<singl_hit_size; this_id++)
112 this_shit.
name = PID[this_id + mh*singl_hit_size].name;
113 this_shit.
rule = PID[this_id + mh*singl_hit_size].rule;
114 this_shit.
id = PID[this_id + mh*singl_hit_size].id;
115 this_shit.
time = PID[this_id + mh*singl_hit_size].time;
116 this_shit.
TimeWindow = PID[this_id + mh*singl_hit_size].TimeWindow;
117 this_shit.
TrackId = PID[this_id + mh*singl_hit_size].TrackId;
118 this_shit.
id_sharing = PID[this_id + mh*singl_hit_size].id_sharing;
119 mhPID.push_back(this_shit);
122 if(HIT_VERBOSITY > 9 || name.find(catch_v) != string::npos)
123 cout << endl << hd_msg2 <<
" Before hit Process Identification:" << endl << VID
124 << hd_msg2 <<
" After: hit Process Identification:" << endl << mhPID << endl;
127 if(HIT_VERBOSITY > 9) cout << endl << endl <<
" BEGIN SEARCH for same hit in Identifier Set..." << endl;
129 set<vector<identifier> > :: iterator itid;
132 for(itid =
Id_Set.begin(); itid!=
Id_Set.end() && !hit_found; itid++)
134 if(*itid == mhPID) hit_found=1;
135 if(HIT_VERBOSITY > 9 )
136 cout <<
" >> Current Step: " << mhPID
137 <<
" >> Set Hit Index: " << *itid
138 << (hit_found ?
" >> FOUND at this Set Entry. " :
" >> Not found yet. ") << endl;
140 if(HIT_VERBOSITY > 10) cout <<
" SEARCH ENDED." << (hit_found ?
" 1 " :
" No ") <<
"hit found in the Set." << endl << endl;
152 thisHit->
SetEdep(depe*mhPID[singl_hit_size-1].id_sharing);
159 thisHit->
SetId(mhPID);
162 hitCollection->insert(thisHit);
165 if(HIT_VERBOSITY > 6 || name.find(catch_v) != string::npos)
167 string pid = aStep->GetTrack()->GetDefinition()->GetParticleName();
168 cout << endl << hd_msg1 << endl
169 <<
" > This element was not hit yet in this event. Identity:" << endl << thisHit->
GetId()
170 <<
" > Creating new hit by a E=" << ene/MeV <<
", p=" << pxyz.mag()/MeV <<
" MeV " << pid
171 <<
", track ID = " << tid <<
", inside Hit Collection <" <<
HCname <<
">." << endl
172 <<
" > Energy Deposited this step: " << depe/MeV <<
" MeV" << endl
173 <<
" > Time of this step: " << G4BestUnit(ctime,
"Time") << endl
174 <<
" > Position of this step: " << xyz/cm <<
" cm" << endl
175 <<
" > Local Position in volume: " << Lxyz/cm <<
" cm" << endl;
186 cout <<
" Hit not found in collection but found in PID. This should never happen. Exiting." << endl;
195 thisHit->
SetEdep(depe*mhPID[singl_hit_size-1].id_sharing);
204 if(HIT_VERBOSITY > 6 || name.find(catch_v) != string::npos)
206 string pid = aStep->GetTrack()->GetDefinition()->GetParticleName();
207 cout << hd_msg2 <<
" Step Number " << thisHit->
GetPos().size()
208 <<
" inside Identity: " << endl << thisHit->
GetId()
209 <<
" > Adding hit inside Hit Collection <" <<
HCname <<
">." 210 <<
" by a E=" << ene/MeV <<
", p=" << pxyz.mag()/MeV <<
" MeV " 211 << pid <<
", track ID = " << tid << endl
212 <<
" > Energy Deposited this step: " << depe/MeV <<
" MeV" << endl
213 <<
" > Time of this step: " << G4BestUnit(ctime,
"Time")
214 <<
" is within this element Time Window of " <<
SDID.
TimeWindow/ns <<
" ns. " << endl
215 <<
" > Position of this step: " << xyz/cm <<
" cm" << endl
216 <<
" > Local Position in volume: " << Lxyz/cm <<
" cm" << endl;
235 int nhitC = hitCollection->GetSize();
239 if(HIT_VERBOSITY > 2 && nhitC)
242 cout << hd_msg3 <<
" Hit Collections <" <<
HCname <<
">: " << nhitC <<
" hits." << endl;
244 for (
int i=0; i<nhitC; i++)
246 aHit = (*hitCollection)[i];
247 string vname = aHit->
GetId()[aHit->
GetId().size()-1].name;
248 if(HIT_VERBOSITY > 5 || vname.find(catch_v) != string::npos)
250 cout << hd_msg3 <<
" Hit " << i + 1 <<
" -- total number of steps this hit: " << aHit->
GetPos().size() << endl;
251 cout << aHit->
GetId();
253 for(
unsigned int e=0; e<aHit->
GetPos().size(); e++) Etot = Etot + aHit->
GetEdep()[e];
254 cout <<
" Total energy deposited: " << Etot/MeV <<
" MeV" << endl;
258 delete ProcessHitRoutine;
265 for(
unsigned int i=0; i<hitCollection->GetSize(); i++)
266 if((*hitCollection)[i]->GetId() == PID)
return (*hitCollection)[i];
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.
SDId get_SDId(string SD, gemc_opts gemcOpt)
Connects to DB and retrieve SDId.
SDId SDID
SDId used for identification.
virtual void EndOfEvent(G4HCofThisEvent *)
Virtual Method called at the end of each hit event.
virtual ~MSensitiveDetector()
MHit * find_existing_hit(vector< identifier >)
returns hit collection hit inside identifer
virtual void Initialize(G4HCofThisEvent *)
Virtual Method called at the beginning of each hit event.
void SetPos(G4ThreeVector xyz)
vector< identifier > GetId()
double TimeWindow
If two steps happens withing the same TimeWindow, they belong to the same Hit.
int id
manually assing ID. 0 if "ncopy" (will be set at hit processing time)
map< string, MPHB_Factory > * MProcessHit_Map
Hit Process Routine Factory Map.
G4THitsCollection< MHit > MHitCollection
string name
Name of the detector.
void SetDetector(detector det)
map< string, detector > * Hall_Map
detector map
MSensitiveDetector(G4String, gemc_opts)
Constructor.
void SetEdep(double depe)
double TimeWindow
Time Window. If abs(steptime - time) is smaller than TimeWindow, it's the same hit.
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()
gemc_opts gemcOpt
gemc option class
MPHBaseClass * GetMPHClass(map< string, MPHB_Factory > *MProcessHit_Map, string HCname)
Return MPHBaseClass from the Hit Process Map.
virtual vector< identifier > ProcessID(vector< identifier >, G4Step *, detector, gemc_opts)=0
Virtual Method to calculate new identifier.
double minEnergy
Minimum energy of the hit to be recorded in the output stream.
void SetId(vector< identifier > iden)
G4String HCname
Sensitive Detector/Hit Collection Name.
map< string, opts > args
Options map.
double id_sharing
A single step can generate multiple identifiers. This variable represent the percentage sharing of th...
void SetThreshold(double E)
string GetDetectorHitType(string name)
returns detector hitType
set< vector< identifier > > Id_Set
Identifier Set. Used to determine if a step is inside a new/existing element.
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
Virtual Method called for each step of each hit.
double time
Time of the first step.
void SetLPos(G4ThreeVector xyz)
vector< identifier > GetDetectorIdentifier(string name)
returns detector identity
void SetTime(double ctime)
vector< double > GetEdep()
void SetVert(G4ThreeVector ver)
string rule
"manual" or "ncopy"