forked from WCSim/WCSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWCSimWCHit.hh
179 lines (142 loc) · 4.82 KB
/
WCSimWCHit.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef WCSimWCHit_h
#define WCSimWCHit_h 1
#include "G4VHit.hh"
#include "G4THitsCollection.hh"
#include "G4Allocator.hh"
#include "G4ThreeVector.hh"
#include "G4LogicalVolume.hh"
#include "G4ios.hh"
// for sort, find, count_if
#include <algorithm>
//for less_equal, bind2nd,...
#include <functional>
// compose2 is not part of the C++ standard
// use this kludgy technique to use it
#include <ext/functional>
using __gnu_cxx::identity_element;
using __gnu_cxx::unary_compose;
using __gnu_cxx::binary_compose;
using __gnu_cxx::compose1;
using __gnu_cxx::compose2;
using __gnu_cxx::identity;
using __gnu_cxx::select1st;
using __gnu_cxx::select2nd;
using __gnu_cxx::project1st;
using __gnu_cxx::project2nd;
using __gnu_cxx::constant_void_fun;
using __gnu_cxx::constant_unary_fun;
using __gnu_cxx::constant_binary_fun;
using __gnu_cxx::constant0;
using __gnu_cxx::constant1;
using __gnu_cxx::constant2;
using __gnu_cxx::subtractive_rng;
using __gnu_cxx::mem_fun1;
using __gnu_cxx::mem_fun1_ref;
class WCSimWCHit : public G4VHit
{
public:
WCSimWCHit();
~WCSimWCHit();
WCSimWCHit(const WCSimWCHit&);
const WCSimWCHit& operator=(const WCSimWCHit&);
G4int operator==(const WCSimWCHit&) const;
inline void* operator new(size_t);
inline void operator delete(void*);
void Draw();
void Print();
public:
void SetTubeID (G4int tube) { tubeID = tube; };
void SetTrackID (G4int track) { trackID = track; };
void SetEdep (G4double de) { edep = de; };
void SetPos (G4ThreeVector xyz) { pos = xyz; };
void SetRot (G4RotationMatrix rotMatrix) { rot = rotMatrix; };
void SetLogicalVolume(G4LogicalVolume* logV) { pLogV = logV;}
void AddParentID (G4int primParentID)
{ primaryParentID.push_back(primParentID); }
// This is temporarily used for the drawing scale
void SetMaxPe(G4int number = 0) {maxPe = number;};
void AddPe(G4float hitTime)
{
// First increment the totalPe number
totalPe++;
if (totalPe > maxPe)
maxPe = totalPe;
time.push_back(hitTime);
}
G4int GetTubeID() { return tubeID; };
G4int GetTrackID() { return trackID; };
G4ThreeVector GetPos() { return pos; };
G4int GetTotalPe() { return totalPe;};
G4float GetTime(int i) { return time[i];};
G4int GetParentID(int i) { return primaryParentID[i];};
G4LogicalVolume* GetLogicalVolume() {return pLogV;};
void SortHitTimes() { sort(time.begin(),time.end()); }
// low is the trigger time, up is trigger+950ns (end of event)
G4float GetFirstHitTimeInGate(G4float low,G4float upevent)
{
G4float firsttime;
std::vector<G4float>::iterator tfirst = time.begin();
std::vector<G4float>::iterator tlast = time.end();
std::vector<G4float>::iterator found =
std::find_if(tfirst,tlast,
compose2(std::logical_and<bool>(),
std::bind2nd(std::greater_equal<G4float>(),low),
std::bind2nd(std::less_equal<G4float>(),upevent)
)
);
if ( found != tlast ) {
firsttime = *found; // first hit time
}
else {
firsttime = -10000.; //error code.
}
//G4cout << "firsthit time " << firsttime << "\n";
return firsttime;
}
// pmtgate and evgate are durations, ie not absolute times
G4int GetPeInGate(double low, double pmtgate,double evgate) {
// M Fechner; april 2005
// assumes that time has already been sorted
std::vector<G4float>::iterator tfirst = time.begin();
std::vector<G4float>::iterator tlast = time.end();
// select min time
G4float mintime = (pmtgate < evgate) ? pmtgate : evgate;
// return number of hits in the time window...
G4int number = std::count_if(tfirst,tlast,
compose2(std::logical_and<bool>(),
std::bind2nd(std::greater_equal<G4float>(),low),
std::bind2nd(std::less_equal<G4float>(),mintime)
)
);
totalPeInGate = number;
// G4cout << "numer = " << number <<"\n";
return number;
}
private:
G4int tubeID;
G4int trackID;
G4double edep;
G4ThreeVector pos;
G4RotationMatrix rot;
G4LogicalVolume* pLogV;
// This is temporarily used for the drawing scale
// Since its static *every* WChit sees the same value for this.
static G4int maxPe;
G4int totalPe;
std::vector<G4float> time;
std::vector<G4int> primaryParentID;
G4int totalPeInGate;
};
typedef G4THitsCollection<WCSimWCHit> WCSimWCHitsCollection;
extern G4Allocator<WCSimWCHit> WCSimWCHitAllocator;
inline void* WCSimWCHit::operator new(size_t)
{
void *aHit;
aHit = (void *) WCSimWCHitAllocator.MallocSingle();
return aHit;
}
inline void WCSimWCHit::operator delete(void *aHit)
{
WCSimWCHitAllocator.FreeSingle((WCSimWCHit*) aHit);
}
#endif