WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimWCTrigger.hh
Go to the documentation of this file.
1 #ifndef WCSimWCTrigger_h
2 #define WCSimWCTrigger_h 1
3 
4 #include "WCSimRootOptions.hh"
5 #include "WCSimEnumerations.hh"
6 #include "WCSimWCDAQMessenger.hh"
8 #include "G4VDigitizerModule.hh"
9 #include "WCSimWCDigi.hh"
10 #include "WCSimWCHit.hh"
11 #include "globals.hh"
12 #include "Randomize.hh"
13 #include <map>
14 #include <vector>
15 
17 typedef G4TDigiCollection<WCSimWCDigiTrigger> WCSimWCTriggeredDigitsCollection;
18 
19 // *******************************************
20 // BASE CLASS
21 // *******************************************
22 
33 class WCSimWCTriggerBase : public G4VDigitizerModule
34 {
35 
36 public:
37 
40 
41  virtual ~WCSimWCTriggerBase();
42 
44  void Digitize();
45 
47  int NumberOfGatesInThisEvent() { return TriggerTimes.size(); }
49  Double_t GetTriggerTime(int i) { return TriggerTimes[i];}
53  std::vector<Float_t> GetTriggerInfo(int i) { return TriggerInfos[i];}
55  G4String GetTriggerClassName(){ return triggerClassName; }
56 
57  //
58  // Trigger algorithm option set methods
59  //
60 
62  void SetMultiDigitsPerTrigger(G4bool allow_multi) { multiDigitsPerTrigger = allow_multi; }
64 
65  // NDigits options
67  void SetNDigitsThreshold(G4int threshold) { ndigitsThreshold = threshold; }
69  void SetNDigitsWindow(G4int window) { ndigitsWindow = window; }
71  void SetNDigitsAdjustForNoise (G4bool adjust) { ndigitsAdjustForNoise = adjust; }
73  void SetNDigitsPreTriggerWindow(G4int window) { ndigitsPreTriggerWindow = - abs(window); }
75  void SetNDigitsPostTriggerWindow(G4int window) { ndigitsPostTriggerWindow = + abs(window); }
76 
77  // Save trigger failures options
79  void SetSaveFailuresMode (G4int mode ) { saveFailuresMode = mode; }
83  void SetSaveFailuresPreTriggerWindow(G4int window) { saveFailuresPreTriggerWindow = - abs(window); }
85  void SetSaveFailuresPostTriggerWindow(G4int window) { saveFailuresPostTriggerWindow = + abs(window); }
86 
88  void SetDarkRate(double idarkrate){ PMTDarkRate = idarkrate; }
89 
92 
93 protected:
94 
96  virtual void DoTheWork(WCSimWCDigitsCollection* WCDCPMT) = 0;
97 
99  void GetVariables();
100 
102  virtual bool GetDefaultMultiDigitsPerTrigger() { return true; }
104  virtual int GetDefaultNDigitsWindow() { return 200; }
106  virtual int GetDefaultNDigitsThreshold() { return 25; }
108  virtual int GetDefaultNDigitsPreTriggerWindow() { return -400; }
110  virtual int GetDefaultNDigitsPostTriggerWindow() { return 950; }
111 
116 
117  //these are the algorithms that perform triggering
118  //they are stored here so that different trigger classes can use the same algorithms without copying code
134  void AlgNDigits(WCSimWCDigitsCollection* WCDCPMT, bool remove_hits, bool test=false);
135  void AlgNoTrigger(WCSimWCDigitsCollection* WCDCPMT, bool remove_hits, bool test=false);
136 
137 
139  std::map<int,int> DigiHitMap;
140 
141  std::vector<Double_t> TriggerTimes;
142  std::vector<TriggerType_t> TriggerTypes;
143  std::vector< std::vector<Float_t> > TriggerInfos;
144 
147  G4String detectorElement;
148 
150  void ReInitialize() {
151  TriggerTimes.clear();
152  TriggerTypes.clear();
153  TriggerInfos.clear();
154  DigiHitMap.clear();
155  }
156 
157  double PMTDarkRate;
158 
159  // Trigger algorithm options
161  //NDigits
167  //Save failures
169  G4double saveFailuresTime;
172 
173  G4String triggerClassName;
174 
175 private:
178 
180  void FillDigitsCollection(WCSimWCDigitsCollection* WCDCPMT, bool remove_hits, TriggerType_t save_triggerType);
181 
184  int i, j;
185  TriggerType_t index_type;
186  double index_time;
187  std::vector<float> index_info;
188  for (i = 1; i < (int) TriggerTimes.size(); ++i) {
189  index_time = TriggerTimes[i];
190  index_type = TriggerTypes[i];
191  index_info = TriggerInfos[i];
192  for (j = i; j > 0 && TriggerTimes[j-1] > index_time; j--) {
193  TriggerTimes[j] = TriggerTimes[j-1];
194  TriggerTypes[j] = TriggerTypes[j-1];
195  TriggerInfos[j] = TriggerInfos[j-1];
196  }//j
197  TriggerTimes[j] = index_time;
198  TriggerTypes[j] = index_type;
199  TriggerInfos[j] = index_info;
200  }//i
201  }
202 
203  static const double offset;
204  static const double LongTime;
205 
207 };
208 
209 // *******************************************
210 // CONTAINER CLASS
211 // *******************************************
212 
213 class WCSimWCDigiTrigger : public G4VDigi
214 {
215 public:
216 
221  int operator==(const WCSimWCDigiTrigger&) const;
222 
223  inline void* operator new(size_t);
224  inline void operator delete(void*);
225 
226  void Draw() {}
227  void Print();
228 
229  inline void SetTubeID(G4int tube) { tubeID = tube; }
230  inline void AddGate (G4int gate) { Gates.insert(gate); }
231  inline void AddPe () { totalPe++; }
232  inline void SetPe (G4int gate, G4double Q) { pe.insert(std::pair<int,double>(gate,Q)); }
233  inline void SetTime (G4int gate, G4double T) { time.insert(std::pair<int,double>(gate,T)); }
234 
236  void AddDigiCompositionInfo(G4int gate, std::vector<int> &digi_comp){
237  fDigiComp.insert(std::pair<int, std::vector<int> >(gate, digi_comp));
238  digi_comp.clear();
239  }
240 
241  inline G4int GetTubeID() {return tubeID;}
242  inline std::vector<G4double> GetPe (int gate) { return FindInMultimap(gate, pe); }
243  inline std::vector<G4double> GetTime (int gate) { return FindInMultimap(gate, time); }
244  std::vector<std::vector<int> > GetDigiCompositionInfo(int gate)
245  {
246  std::vector<std::vector<int> > v;
247  std::multimap<int, std::vector<int> >::iterator it = fDigiComp.begin();
248  for (; it != fDigiComp.end(); ++it) {
249  if((it->first) == gate)
250  v.push_back(it->second);
251  }
252  return v;
253  }
254 
255  inline int NumberOfGates() { return Gates.size(); }
256  inline int NumberOfSubEvents() { return Gates.size() - 1; }
257  inline bool HasHitsInGate(int gate) { return Gates.count(gate) > 0; }
258 
259 private:
260  G4int tubeID;
261 
262  std::set<int> Gates;
263 
264  //lists (meaning multimap) of information for each digit created on the PMT
265  std::multimap<int,double> pe;
266  std::multimap<int,double> time;
267  std::multimap<int, std::vector<int> > fDigiComp;
268 
269  //integrated hit/digit parameters
270  G4int totalPe;
271 
272  template <typename T> std::vector<T> FindInMultimap(const int compare, typename std::multimap<int,T> &map)
273  {
274  typename std::vector<T> v;
275  typename std::multimap<int,T>::iterator it = map.begin();
276  for (; it != map.end(); ++it) {
277  if((it->first) == compare)
278  v.push_back(it->second);
279  }
280  return v;
281  }
282 
283 };
284 
285 extern G4Allocator<WCSimWCDigiTrigger> WCSimWCDigiTriggerAllocator;
286 
287 inline void* WCSimWCDigiTrigger::operator new(size_t)
288 {
289  void* aDigi;
290  aDigi = (void*) WCSimWCDigiTriggerAllocator.MallocSingle();
291  return aDigi;
292 }
293 
294 inline void WCSimWCDigiTrigger::operator delete(void* aDigi)
295 {
296  WCSimWCDigiTriggerAllocator.FreeSingle((WCSimWCDigiTrigger*) aDigi);
297 }
298 
299 
300 
301 // *******************************************
302 // DERIVED CLASSES
303 // *******************************************
304 
305 
314 {
315 public:
316 
319 
321 
322 private:
324  void DoTheWork(WCSimWCDigitsCollection* WCDCPMT);
325 
326  bool GetDefaultMultiDigitsPerTrigger() { return false; }
327  int GetDefaultNDigitsWindow() { return 200; }
328  int GetDefaultNDigitsThreshold() { return 25; }
329  int GetDefaultNDigitsPreTriggerWindow() { return -400; }
330  int GetDefaultNDigitsPostTriggerWindow() { return 950; }
331 };
332 
334 {
335 public:
336 
339 
341 
342 private:
344  void DoTheWork(WCSimWCDigitsCollection* WCDCPMT);
345 
346  bool GetDefaultMultiDigitsPerTrigger() { return true; }
347  int GetDefaultNDigitsWindow() { return 0; }
348  int GetDefaultNDigitsThreshold() { return 0; }
351 };
352 
361 {
362 public:
363 
364  //not recommended to override these methods
367 
368 private:
369  void DoTheWork(WCSimWCDigitsCollection* WCDCPMT);
370 
371  bool GetDefaultMultiDigitsPerTrigger() { return false; }
372  int GetDefaultNDigitsWindow() { return 200; }
373  int GetDefaultNDigitsThreshold() { return 50; }
374  int GetDefaultNDigitsPreTriggerWindow() { return -400; }
375  int GetDefaultNDigitsPostTriggerWindow() { return 950; }
376 };
377 
378 
379 #endif //WCSimWCTrigger_h
std::vector< std::vector< Float_t > > TriggerInfos
Additional information associated with each trigger.
int GetDefaultNDigitsPostTriggerWindow()
This is not an NDigits trigger.
void SetTubeID(G4int tube)
G4int saveFailuresPreTriggerWindow
The pretrigger window to save before an SaveFailures trigger.
std::multimap< int, double > time
Digit time.
void SetSaveFailuresPreTriggerWindow(G4int window)
Set the pretrigger window for the SaveFailures trigger (value will be forced negative) ...
virtual ~WCSimWCTriggerBase()
int operator==(const WCSimWCDigiTrigger &) const
enum ETriggerType TriggerType_t
std::vector< Double_t > TriggerTimes
The times of the triggers.
A simple NDigits trigger class.
void SaveOptionsToOutput(WCSimRootOptions *wcopt)
Save current values of options.
void AddGate(G4int gate)
bool GetDefaultMultiDigitsPerTrigger()
SKI saves only earliest digit on a PMT in the trigger window.
Double_t GetTriggerTime(int i)
Get the time of the ith trigger.
G4String triggerClassName
Save the name of the trigger class.
std::vector< std::vector< int > > GetDigiCompositionInfo(int gate)
void SortTriggersByTime()
sort the Trigger vectors (Time, Type, Info) by Trigger Time
std::map< int, int > DigiHitMap
Keeps track of the PMTs that have been added to the output WCSimWCTriggeredDigitsCollection.
void AlgNoTrigger(WCSimWCDigitsCollection *WCDCPMT, bool remove_hits, bool test=false)
void DoTheWork(WCSimWCDigitsCollection *WCDCPMT)
This should call the trigger algorithms, and handle any temporary DigitsCollection&#39;s.
void SetNDigitsWindow(G4int window)
Set the time window for the NDigits trigger.
int GetDefaultNDigitsWindow()
This is not an NDigits trigger.
void SetTime(G4int gate, G4double T)
TriggerType_t GetTriggerType(int i)
Get the trigger type of the ith trigger.
int GetDefaultNDigitsPreTriggerWindow()
This is not an NDigits trigger.
virtual int GetDefaultNDigitsThreshold()
Set the default trigger class specific NDigits threshold (in ns) (overridden by .mac) ...
std::multimap< int, double > pe
Digit charge.
void AddDigiCompositionInfo(G4int gate, std::vector< int > &digi_comp)
Add a whole vector for one digit to fDigiComp. Clear input vector once added.
std::vector< T > FindInMultimap(const int compare, typename std::multimap< int, T > &map)
void DoTheWork(WCSimWCDigitsCollection *WCDCPMT)
Calls the workhorse of this class: AlgNDigits.
int NumberOfGatesInThisEvent()
Returns the number of trigger gates in the event (i.e. the number of triggers passed) ...
std::vector< G4double > GetTime(int gate)
int GetDefaultNDigitsWindow()
SK max light travel time ~200 ns.
int GetDefaultNDigitsPostTriggerWindow()
SK SLE trigger window ~+950.
virtual void DoTheWork(WCSimWCDigitsCollection *WCDCPMT)=0
This should call the trigger algorithms, and handle any temporary DigitsCollection&#39;s.
WCSimWCTriggerNoTrigger(G4String name, WCSimDetectorConstruction *, WCSimWCDAQMessenger *, G4String detectorElement)
Create WCSimWCTriggerNoTrigger instance with knowledge of the detector and DAQ options.
int GetDefaultNDigitsPreTriggerWindow()
SK SLE trigger window ~-400.
double PMTDarkRate
Dark noise rate of the PMTs.
int GetDefaultNDigitsWindow()
SK max light travel time ~200 ns.
void SetNDigitsThreshold(G4int threshold)
Set the threshold for the NDigits trigger.
void SetMultiDigitsPerTrigger(G4bool allow_multi)
Set whether to allow the number of digits per PMT per trigger to go &gt; 1.
bool HasHitsInGate(int gate)
int GetDefaultNDigitsPostTriggerWindow()
SK SLE trigger window ~+950.
G4TDigiCollection< WCSimWCDigi > WCSimWCDigitsCollection
Definition: WCSimWCDigi.hh:214
double GetPreTriggerWindow(TriggerType_t t)
Get the pretrigger window for a given trigger algorithm.
G4TDigiCollection< WCSimWCDigiTrigger > WCSimWCTriggeredDigitsCollection
bool GetDefaultMultiDigitsPerTrigger()
SKI saves only earliest digit on a PMT in the trigger window.
void SetNDigitsAdjustForNoise(G4bool adjust)
Automatically adjust the NDigits threshold based on the average noise occupancy?
G4int ndigitsPostTriggerWindow
The posttrigger window to save after an NDigits trigger.
G4bool multiDigitsPerTrigger
Allow the number of digits per PMT saved in each trigger window to go &gt; 1?
int GetDefaultNDigitsPreTriggerWindow()
SK SLE trigger window ~-400.
void ReInitialize()
Clear the Trigger* vectors and DigiHitMap.
int GetDefaultNDigitsThreshold()
2 * SK NDigits threshold ~25
void SetSaveFailuresPostTriggerWindow(G4int window)
Set the posttrigger window for the SaveFailures trigger (value will be forced positive) ...
The base class for WCSim triggering algorithms.
G4bool ndigitsAdjustForNoise
Automatically adjust the NDigits trigger threshold based on the average dark noise rate...
std::vector< TriggerType_t > TriggerTypes
The type of the triggers.
G4int saveFailuresMode
The mode for saving events which don&#39;t pass triggers.
std::vector< G4double > GetPe(int gate)
void AlgNDigits(WCSimWCDigitsCollection *WCDCPMT, bool remove_hits, bool test=false)
An NDigits trigger algorithm.
void AdjustNDigitsThresholdForNoise()
modify the NDigits threshold based on the average dark noise rate
bool GetDefaultMultiDigitsPerTrigger()
We want to save everything.
WCSimWCTriggerNDigits(G4String name, WCSimDetectorConstruction *, WCSimWCDAQMessenger *, G4String detectorElement)
Create WCSimWCTriggerNDigits instance with knowledge of the detector and DAQ options.
G4int ndigitsThreshold
The threshold for the NDigits trigger.
G4String GetTriggerClassName()
Get the trigger class name.
virtual int GetDefaultNDigitsWindow()
Set the default trigger class specific NDigits window (in ns) (overridden by .mac) ...
G4int saveFailuresPostTriggerWindow
The posttrigger window to save after an SaveFailures trigger.
G4int ndigitsPreTriggerWindow
The pretrigger window to save before an NDigits trigger.
static const double LongTime
An arbitrary long time to use in loops (ns)
G4int tubeID
PMT id of the digit.
std::vector< Float_t > GetTriggerInfo(int i)
Get the additional trigger information associated with the ith trigger.
bool digitizeCalled
Has Digitize() been called yet?
G4int totalPe
Total charge on digit.
const WCSimWCDigiTrigger & operator=(const WCSimWCDigiTrigger &)
void SetDarkRate(double idarkrate)
Knowledge of the dark rate (use for automatically adjusting for noise)
G4int ndigitsWindow
The time window for the NDigits trigger.
void SetNDigitsPostTriggerWindow(G4int window)
Set the posttrigger window for the NDigits trigger (value will be forced positive) ...
WCSimDetectorConstruction * myDetector
Know about the detector, so can add appropriate PMT time smearing.
std::multimap< int, std::vector< int > > fDigiComp
Stores the unique IDs of each photon making up a digit.
virtual int GetDefaultNDigitsPostTriggerWindow()
Set the default trigger class specific NDigits posttrigger window (in ns) (overridden by ...
WCSimWCTriggerNDigits2(G4String name, WCSimDetectorConstruction *, WCSimWCDAQMessenger *, G4String detectorElement)
std::set< int > Gates
&#39;Gates&#39; specifies subevent
void SetPe(G4int gate, G4double Q)
int GetDefaultNDigitsThreshold()
This is not an NDigits trigger.
void SetSaveFailuresMode(G4int mode)
Set the mode for saving failed triggers (0:save only triggered events, 1:save both triggered events &amp;...
WCSimWCTriggeredDigitsCollection * DigitsCollection
The main output of the class - collection of digits in the trigger window.
virtual int GetDefaultNDigitsPreTriggerWindow()
Set the default trigger class specific NDigits pretrigger window (in ns) (overridden by ...
G4Allocator< WCSimWCDigiTrigger > WCSimWCDigiTriggerAllocator
void DoTheWork(WCSimWCDigitsCollection *WCDCPMT)
Calls the workhorse of this class: AlgNoTrigger.
WCSimWCTriggerBase(G4String name, WCSimDetectorConstruction *, WCSimWCDAQMessenger *, G4String)
Create WCSimWCTriggerBase instance with knowledge of the detector and DAQ options.
G4bool GetMultiDigitsPerTrigger()
void FillDigitsCollection(WCSimWCDigitsCollection *WCDCPMT, bool remove_hits, TriggerType_t save_triggerType)
takes all trigger times, then loops over all Digits &amp; fills the output DigitsCollection ...
int GetDefaultNDigitsThreshold()
SK NDigits threshold ~25.
static const double offset
Hit time offset (ns)
double GetPostTriggerWindow(TriggerType_t t)
Get the posttrigger window for a given trigger algorithm.
virtual bool GetDefaultMultiDigitsPerTrigger()
Set the default trigger class specific decision of whether to save multiple digits per PMT per trigge...
void GetVariables()
Get the default threshold, etc. from the derived class, and override with read from the ...
void SetSaveFailuresTime(G4double time)
Set the dummy trigger time for the failed triggers.
An (incomplete) example of running two trigger algorithms, one after the other.
void SetNDigitsPreTriggerWindow(G4int window)
Set the pretrigger window for the NDigits trigger (value will be forced negative) ...
WCSimWCDAQMessenger * DAQMessenger
Get the options from the .mac file.
void Digitize()
The main user-callable routine of the class. Gets the input &amp; creates the output WCSimWCTriggeredDigi...
G4double saveFailuresTime
The dummy trigger time for failed events.