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