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 | |
---|
19 | bool identifier::operator == (const identifier& I) const |
---|
20 | { |
---|
21 | if(I.name == this->name && I.rule == this->rule && I.id == this->id && fabs(I.time - this->time) <= this->TimeWindow) |
---|
22 | return true; |
---|
23 | else |
---|
24 | return false; |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | bool identifier::operator < (const identifier& I) const |
---|
29 | { |
---|
30 | if(this->name == I.name) |
---|
31 | if(this->id < I.id) return true; |
---|
32 | if(this->time < I.time) return true; |
---|
33 | |
---|
34 | return false; |
---|
35 | } |
---|
36 | |
---|
37 | bool identifier::operator > (const identifier& I) const |
---|
38 | { |
---|
39 | if(this->name == I.name) |
---|
40 | if(this->id > I.id) return true; |
---|
41 | if(this->time > I.time) return true; |
---|
42 | |
---|
43 | return false; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | ostream &operator<<(ostream &stream, vector<identifier> Iden) |
---|
48 | { |
---|
49 | for(int i=0; i<Iden.size(); i++) |
---|
50 | { |
---|
51 | cout << " id " << i+1 ; |
---|
52 | cout << " " ; |
---|
53 | cout.width(10); |
---|
54 | cout << Iden[i].name << " " << Iden[i].id << endl; |
---|
55 | } |
---|
56 | cout << " identifier time: " << Iden[0].time/ns << " ns - TimeWindow: " << Iden[0].TimeWindow/ns << " ns." << endl; |
---|
57 | |
---|
58 | return stream; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | #include <cmath> |
---|
63 | vector<int> set_IDshifts(vector<int> maxs) |
---|
64 | { |
---|
65 | vector<int> y; |
---|
66 | int max; |
---|
67 | for(int i=0; i<maxs.size(); i++) |
---|
68 | { |
---|
69 | max = 0; |
---|
70 | while( ( 1 << max ) < maxs[i] ) max++; |
---|
71 | y.push_back( max ); |
---|
72 | } |
---|
73 | return y; |
---|
74 | } |
---|
75 | |
---|
76 | // Sets the ncopy ID accordingly to Geant4 Volumes copy number |
---|
77 | vector<identifier> SetId(vector<identifier> Iden, G4VTouchable* TH, double time, double TimeWindow) |
---|
78 | { |
---|
79 | vector<identifier> identity = Iden; |
---|
80 | |
---|
81 | // Look for "ncopy" flag, set to volume copy number |
---|
82 | for(int i=0; i<identity.size(); i++) |
---|
83 | { |
---|
84 | if(identity[i].rule.find("ncopy") != string::npos) |
---|
85 | { |
---|
86 | // h=1 don't need to check volume itself |
---|
87 | for(int h=0; h<TH-> GetHistoryDepth(); h++) |
---|
88 | { |
---|
89 | string pname = TH->GetVolume(h)->GetName(); |
---|
90 | int pcopy = TH->GetVolume(h)->GetCopyNo(); |
---|
91 | if(pname.find(identity[i].name) != string::npos) identity[i].id = pcopy; |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | // Make sure id is not still zero |
---|
96 | if(identity[i].id == 0) |
---|
97 | { |
---|
98 | cout << " Something is wrong. Identity not completely set." << endl; |
---|
99 | cout << identity; |
---|
100 | cout << " Exiting. " << endl; |
---|
101 | exit(0); |
---|
102 | } |
---|
103 | identity[i].time = time; |
---|
104 | identity[i].TimeWindow = TimeWindow; |
---|
105 | } |
---|
106 | |
---|
107 | return identity; |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|