GEMC  2.3
Geant4 Monte-Carlo Framework
identifier.cc
Go to the documentation of this file.
1 // G4 headers
2 #include "G4UnitsTable.hh"
3 
4 // gemc headers
5 #include "detector.h"
6 #include "identifier.h"
7 
8 // C++ headers
9 #include <iostream>
10 using namespace std;
11 
12 // CLHEP units
13 #include "CLHEP/Units/PhysicalConstants.h"
14 using namespace CLHEP;
15 
17 {
18  // If the volume is the same, and if hits are within the time window, it's one hit
19  if(I.name == this->name && I.rule == this->rule && I.id == this->id && fabs(I.time - this->time) <= this->TimeWindow)
20  return true;
21 
22  // If the volume is the same, if it's a "flux" detector, and if it's the same track, it's one hit
23  if(I.name == this->name && I.rule == this->rule && I.id == this->id && this->TimeWindow == 0 && I.TrackId == this->TrackId)
24  return true;
25 
26 // cout << " name1 " << I.name << " name2 " << this->name
27 // << " rule1 " << I.rule << " rule2 " << this->rule
28 // << " id1 " << I.id << " id2 " << this->id
29 // << " time diff " << fabs(I.time - this->time) << " time window " << this->TimeWindow ;
30 
31  return false;
32 }
33 
34 
35 bool identifier::operator < (const identifier& I) const
36 {
37  if(this->name == I.name)
38  if(this->id < I.id) return true;
39  if(this->time < I.time) return true;
40 
41  return false;
42 }
43 
44 bool identifier::operator > (const identifier& I) const
45 {
46  if(this->name == I.name)
47  if(this->id > I.id) return true;
48  if(this->time > I.time) return true;
49 
50  return false;
51 }
52 
53 
54 ostream &operator<<(ostream &stream, vector<identifier> Iden)
55 {
56  for(unsigned int i=0; i<Iden.size(); i++)
57  {
58  cout << " identifier " << i+1 ;
59  cout << ": " ;
60  cout.width(10);
61  if(Iden[i].id_sharing <1 && Iden[i].id_sharing > 0.001)
62  cout << Iden[i].name << " " << Iden[i].id << " Percentage: " << Iden[i].id_sharing << endl ;
63  else
64  cout << Iden[i].name << " " << Iden[i].id << endl ;
65  }
66  if(Iden.size())
67  cout << " identifier time: " << Iden[0].time/ns << " ns - TimeWindow: " << Iden[0].TimeWindow/ns << " ns." << endl;
68 
69  return stream;
70 }
71 
72 
73 // Sets the ncopy ID accordingly to Geant4 Volumes copy number
74 vector<identifier> SetId(vector<identifier> Iden, G4VTouchable* TH, double time, double TimeWindow, int TrackId)
75 {
76  vector<identifier> identity = Iden;
77 
78  // Look for "ncopy" flag, set to volume copy number
79  for(unsigned int i=0; i<identity.size(); i++)
80  {
81  if(identity[i].rule.find("ncopy") != string::npos)
82  {
83  // h=1 don't need to check volume itself
84  for(int h=0; h<TH->GetHistoryDepth(); h++)
85  {
86  string pname = TH->GetVolume(h)->GetName();
87  int pcopy = TH->GetVolume(h)->GetCopyNo();
88  if(pname.find(identity[i].name) != string::npos) identity[i].id = pcopy;
89  }
90 
91  // Make sure id is not still zero
92  if(identity[i].id == 0)
93  {
94  cout << " Something is wrong. Identity " << identity[i].id << " is zero. Full Identity:" << endl;
95  cout << identity;
96  cout << " Exiting. " << endl;
97  exit(0);
98  }
99  }
100 
101  identity[i].time = time;
102  identity[i].TimeWindow = TimeWindow;
103  identity[i].TrackId = TrackId;
104  }
105 
106  return identity;
107 }
108 
109 
110 vector<identifier> get_identifiers(string var)
111 {
112  vector<identifier> identity;
113  stringstream idvars(var);
114 
115  identifier iden;
116  while(!idvars.eof())
117  {
118  idvars >> iden.name >> iden.rule >> iden.id;
119  identity.push_back(iden);
120  }
121  return identity;
122 }
123 
124 
125 
126 
127 
128 
129 
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.
Definition: identifier.cc:74
vector< identifier > get_identifiers(string var)
Definition: identifier.cc:110
STL namespace.
int id
manually assing ID. 0 if "ncopy" (will be set at hit processing time)
Definition: identifier.h:39
string name
Name of the detector.
Definition: identifier.h:37
int TrackId
If Time Window is 0, it&#39;s a "flux" detector: if it&#39;s the same track, it&#39;s the same hit...
Definition: identifier.h:42
bool operator==(const identifier &I) const
Overloaded "==" operator for the class &#39;identifier&#39;.
Definition: identifier.cc:16
double time
Time of the first step.
Definition: identifier.h:40
bool operator<(const identifier &I) const
Overloaded "<" operator for the class &#39;identifier&#39;.
Definition: identifier.cc:35
bool operator>(const identifier &I) const
Overloaded ">" operator for the class &#39;identifier&#39;.
Definition: identifier.cc:44
string rule
"manual" or "ncopy"
Definition: identifier.h:38