WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimWCDigi.hh
Go to the documentation of this file.
1 #ifndef WCSimWCDigi_h
2 #define WCSimWCDigi_h 1
3 
4 #include "G4VDigi.hh"
5 #include "G4TDigiCollection.hh"
6 #include "G4Allocator.hh"
7 #include "G4ThreeVector.hh"
8 #include "G4LogicalVolume.hh"
9 #include "G4ios.hh"
10 
11 #include <set>
12 #include <map>
13 #include <vector>
14 
15 // for sort, find, count_if
16 #include <algorithm>
17 //for less_equal, bind2nd,...
18 #include <functional>
19 
20 // compose2 is not part of the C++ standard
21 #include <ext/functional>
22 using __gnu_cxx::compose2;
23 
24 
25 
26 class WCSimWCDigi : public G4VDigi
27 {
28 
29 public:
30 
31  WCSimWCDigi();
32  ~WCSimWCDigi();
33  WCSimWCDigi(const WCSimWCDigi&);
34  const WCSimWCDigi& operator=(const WCSimWCDigi&);
35  int operator==(const WCSimWCDigi&) const;
36 
37  inline void* operator new(size_t);
38  inline void operator delete(void*);
39 
40  void Draw();
41  void Print();
42 
43 private:
44 
45  //PMT parameters
46  G4int tubeID;
47  G4RotationMatrix rot;
48  G4ThreeVector pos;
49  G4LogicalVolume* pLogV;
50 
51  //'Gates' is a digit counter or specifies subevent
52  //'TriggerTimes' specifies e.g. the subevent trigger time
53  std::set<int> Gates; // list of gates that were hit
54  std::vector<double> TriggerTimes;
55 
56  //lists (meaning vector/map) of information for each hit/digit created on the PMT
57  std::map<int,double> pe;
58  std::map<int,double> time_presmear;
59  std::map<int,double> time;
60  std::vector<G4double> time_double;
61 
69  std::map<int, std::vector<int> > fDigiComp;
70  std::map<int, G4int> primaryParentID;
71 
72 
73  //integrated hit/digit parameters
74  G4int totalPe;
75 
76  //parameters not actually used?
78  G4double edep;
79  static G4int maxPe;
80  G4int trackID;
81 
82 public:
83  void RemoveDigitizedGate(G4int gate);
84 
85  inline void SetTubeID(G4int tube) {tubeID = tube;};
86  inline void AddGate(int g,double t) { Gates.insert(g); TriggerTimes.push_back(t);}
87  inline void SetPe(G4int gate, G4double Q) {pe[gate] = Q;};
88  inline void SetTime(G4int gate, G4double T) {time[gate] = T;};
89  inline void SetPreSmearTime(G4int gate, G4double T) {time_presmear[gate] = T;};
90  inline void SetParentID(G4int gate, G4int parent) { primaryParentID[gate] = parent; };
91 
92  // Add a digit number and unique photon number to fDigiComp
93  inline void AddPhotonToDigiComposition(int digi_number, int photon_number){
94  fDigiComp[digi_number].push_back(photon_number);
95  }
96  // Add a whole vector for one digit to fDigiComp. Clear input vector once added.
97  void AddDigiCompositionInfo(std::vector<int> & digi_comp){
98  const size_t size = fDigiComp.size();
99  fDigiComp[size] = digi_comp;
100  digi_comp.clear();
101  }
102 
103  inline G4int GetParentID(int gate) { return primaryParentID[gate];};
104  inline G4double GetGateTime(int gate) { return TriggerTimes[gate];}
105  inline G4int GetTubeID() {return tubeID;};
106  inline G4double GetPe(int gate) {return pe[gate];};
107  inline G4double GetTime(int gate) {return time[gate];};
108  inline G4double GetPreSmearTime(int gate) {return time_presmear[gate];};
109  std::vector<int> GetDigiCompositionInfo(int gate);
110  inline std::map< int, std::vector<int> > GetDigiCompositionInfo(){return fDigiComp;}
111 
112  inline int NumberOfGates() { return Gates.size();}
113  inline int NumberOfSubEvents() { return (Gates.size()-1);}
114  inline bool HasHitsInGate(int number) { return (Gates.count(number)>0); }
115 
116  G4LogicalVolume* GetLogicalVolume() {return pLogV;};
117 
118 
119  void SetEdep (G4double de) { edep = de; };
120  void SetPos (G4ThreeVector xyz) { pos = xyz; };
121  void SetLogicalVolume(G4LogicalVolume* logV) { pLogV = logV;}
122  void SetTrackID (G4int track) { trackID = track; };
123  void SetRot (G4RotationMatrix rotMatrix) { rot = rotMatrix; };
124  G4int GetTotalPe() { return totalPe;};
125 
126  void SetMaxPe(G4int number = 0) {maxPe = number;};
127 
128  void AddPe(G4double hitTime)
129  {
130  // Increment the totalPe number
131  totalPe++;
132 
133  time_double.push_back(hitTime);
134  }
135 
136  void SortHitTimes() { sort(time_double.begin(),time_double.end()); }
137 
138 
140  int i, j;
141  double index_time,index_timepresmear,index_pe;
142  std::vector<int> index_digicomp;
143  int index_primaryparentid;
144  for (i = 1; i < (int) time.size(); ++i)
145  {
146  index_time = time[i];
147  index_timepresmear = time_presmear[i];
148  index_pe = pe[i];
149  index_digicomp = fDigiComp[i];
150  index_primaryparentid = primaryParentID[i];
151  for (j = i; j > 0 && time[j-1] > index_time; j--) {
152  time[j] = time[j-1];
153  time_presmear[j] = time_presmear[j-1];
154  pe[j] = pe[j-1];
155  fDigiComp[j] = fDigiComp[j-1];
157  //G4cout <<"swapping "<<time[j-1]<<" "<<index_time<<G4endl;
158  }
159 
160  time[j] = index_time;
161  time_presmear[j] = index_timepresmear;
162  pe[j] = index_pe;
163  fDigiComp[j] = index_digicomp;
164  primaryParentID[j] = index_primaryparentid;
165  }
166  }
167 
168  void insertionSort(int a[], int array_size)
169  {
170  int i, j, index;
171  for (i = 1; i < array_size; ++i)
172  {
173  index = a[i];
174  for (j = i; j > 0 && a[j-1] > index; j--)
175  a[j] = a[j-1];
176 
177  a[j] = index;
178  }
179  }
180 
181 
182  G4double GetFirstHitTimeInGate(G4double low,G4double upevent)
183  {
184  G4double firsttime;
185  std::vector<G4double>::iterator tfirst = time_double.begin();
186  std::vector<G4double>::iterator tlast = time_double.end();
187 
188  std::vector<G4double>::iterator found =
189  std::find_if(tfirst,tlast,
190  compose2(std::logical_and<bool>(),
191  std::bind2nd(std::greater_equal<G4double>(),low),
192  std::bind2nd(std::less_equal<G4double>(),upevent)
193  )
194  );
195  if ( found != tlast ) {
196  firsttime = *found; // first hit time
197  }
198  else {
199  firsttime = -10000.; //error code.
200  }
201  //G4cout << "firsthit time " << firsttime << "\n";
202  return firsttime;
203  }
204 
205  // G. Pronost:
206  // Sort function by Hit Time (using first time, assuming hit time in a hit are sorted)
208  bool operator() (const WCSimWCDigi * const &a,
209  const WCSimWCDigi * const &b) const;
210  };
211 
212 };
213 
214 typedef G4TDigiCollection<WCSimWCDigi> WCSimWCDigitsCollection;
215 extern G4Allocator<WCSimWCDigi> WCSimWCDigiAllocator;
216 
217 inline void* WCSimWCDigi::operator new(size_t)
218 {
219  void* aDigi;
220  aDigi = (void*) WCSimWCDigiAllocator.MallocSingle();
221  return aDigi;
222 }
223 
224 inline void WCSimWCDigi::operator delete(void* aDigi)
225 {
226  WCSimWCDigiAllocator.FreeSingle((WCSimWCDigi*) aDigi);
227 }
228 
229 #endif
230 
231 
232 
233 
234 
235 
236 
237 
238 
int operator==(const WCSimWCDigi &) const
Definition: WCSimWCDigi.cc:49
void SortHitTimes()
Definition: WCSimWCDigi.hh:136
void SetMaxPe(G4int number=0)
Definition: WCSimWCDigi.hh:126
void SetPreSmearTime(G4int gate, G4double T)
Definition: WCSimWCDigi.hh:89
void SetLogicalVolume(G4LogicalVolume *logV)
Definition: WCSimWCDigi.hh:121
void SetRot(G4RotationMatrix rotMatrix)
Definition: WCSimWCDigi.hh:123
G4Allocator< WCSimWCDigi > WCSimWCDigiAllocator
Definition: WCSimWCDigi.cc:8
int NumberOfGates()
Definition: WCSimWCDigi.hh:112
void SortArrayByHitTime()
Definition: WCSimWCDigi.hh:139
std::set< int > Gates
Definition: WCSimWCDigi.hh:53
std::map< int, std::vector< int > > GetDigiCompositionInfo()
Definition: WCSimWCDigi.hh:110
std::vector< G4double > time_double
Same information as &quot;time&quot; but stored in a vector for quick time sorting.
Definition: WCSimWCDigi.hh:60
void AddPhotonToDigiComposition(int digi_number, int photon_number)
Definition: WCSimWCDigi.hh:93
const WCSimWCDigi & operator=(const WCSimWCDigi &)
Definition: WCSimWCDigi.cc:38
bool operator()(const WCSimWCDigi *const &a, const WCSimWCDigi *const &b) const
Definition: WCSimWCDigi.cc:112
void SetTrackID(G4int track)
Definition: WCSimWCDigi.hh:122
void SetTubeID(G4int tube)
Definition: WCSimWCDigi.hh:85
G4double GetFirstHitTimeInGate(G4double low, G4double upevent)
Definition: WCSimWCDigi.hh:182
G4int tubeID
Definition: WCSimWCDigi.hh:46
G4LogicalVolume * GetLogicalVolume()
Definition: WCSimWCDigi.hh:116
static G4int maxPe
Definition: WCSimWCDigi.hh:79
G4int trackID
Definition: WCSimWCDigi.hh:80
G4int totalPe
Definition: WCSimWCDigi.hh:74
std::map< int, double > time_presmear
Time of each Digi, before smearing.
Definition: WCSimWCDigi.hh:58
void SetPe(G4int gate, G4double Q)
Definition: WCSimWCDigi.hh:87
std::map< int, double > time
Time of each Digi.
Definition: WCSimWCDigi.hh:59
G4TDigiCollection< WCSimWCDigi > WCSimWCDigitsCollection
Definition: WCSimWCDigi.hh:214
G4LogicalVolume * pLogV
Definition: WCSimWCDigi.hh:49
void AddDigiCompositionInfo(std::vector< int > &digi_comp)
Definition: WCSimWCDigi.hh:97
int NumberOfSubEvents()
Definition: WCSimWCDigi.hh:113
bool HasHitsInGate(int number)
Definition: WCSimWCDigi.hh:114
void AddGate(int g, double t)
Definition: WCSimWCDigi.hh:86
void RemoveDigitizedGate(G4int gate)
Definition: WCSimWCDigi.cc:79
void insertionSort(int a[], int array_size)
Definition: WCSimWCDigi.hh:168
std::map< int, double > pe
Charge of each Digi.
Definition: WCSimWCDigi.hh:57
G4RotationMatrix rot
Definition: WCSimWCDigi.hh:47
G4double edep
Definition: WCSimWCDigi.hh:78
std::vector< double > TriggerTimes
Definition: WCSimWCDigi.hh:54
void SetEdep(G4double de)
Definition: WCSimWCDigi.hh:119
void AddPe(G4double hitTime)
Definition: WCSimWCDigi.hh:128
G4double GetPreSmearTime(int gate)
Definition: WCSimWCDigi.hh:108
std::map< int, std::vector< int > > fDigiComp
IDs of the hits that make up this Digit (do not use for Hits)
Definition: WCSimWCDigi.hh:69
std::map< int, G4int > primaryParentID
Primary parent ID of the Hit (do not use for Digits)
Definition: WCSimWCDigi.hh:70
void SetPos(G4ThreeVector xyz)
Definition: WCSimWCDigi.hh:120
void SetTime(G4int gate, G4double T)
Definition: WCSimWCDigi.hh:88
G4double GetPe(int gate)
Definition: WCSimWCDigi.hh:106
void SetParentID(G4int gate, G4int parent)
Definition: WCSimWCDigi.hh:90
void Print()
Definition: WCSimWCDigi.cc:58
void Draw()
Definition: WCSimWCDigi.cc:56
G4double GetGateTime(int gate)
Definition: WCSimWCDigi.hh:104
G4double GetTime(int gate)
Definition: WCSimWCDigi.hh:107
G4int GetTubeID()
Definition: WCSimWCDigi.hh:105
G4int GetTotalPe()
Definition: WCSimWCDigi.hh:124
G4int GetParentID(int gate)
Definition: WCSimWCDigi.hh:103
G4ThreeVector pos
Definition: WCSimWCDigi.hh:48
G4int totalPeInGate
Definition: WCSimWCDigi.hh:77