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