Diana Software
MPulserFlagByRegularTiming.cc
Go to the documentation of this file.
2 #include "QEvent.hh"
3 #include "QRawEvent.hh"
4 #include "QRunData.hh"
5 #include "QBool.hh"
6 #include "QBaseType.hh"
7 #include "QCoincidenceTiming.hh"
8 #include <sstream>
9 
10 using std::flush;
11 using std::map;
12 using std::stringstream;
13 using namespace Diana;
14 
16 
18 {
19  // we manually handle filters
20  GetBool("SkipEvents",false,false);
21 
22  if (GetIteration() == 1) {
23 
24  fExpectedTimeInterval = GetDouble("ExpectedTimeInterval", -1);
25  if (fExpectedTimeInterval <= 0) {
26  fExpectedTimeInterval = 305.536;
27  }
28 
29  fTimeIntervalUncertainty = GetDouble("TimeIntervalUncertainty", 0.500);
30  fTimeIntervalStepSize = GetDouble("TimeIntervalStepSize", 0.008);
31 
32  int numberOfTimeAdjustments = GetInt("NumberOfTimeAdjustments", 0);
33  for (int i = 1; i <= numberOfTimeAdjustments; ++i) {
34  stringstream parameterName;
35  parameterName << "TimeAdjustment_" << i << flush;
36  double timeAdjustment = GetDouble(parameterName.str(), 0.0);
37  fTimeAdjustments.push_back(timeAdjustment);
38  }
39 
40  fTimeTolerance = GetDouble("TimeTolerance", 1.0);
41  fFalsePositiveRate = GetDouble("FalsePositiveRate", 0.001);
42 
43  fUseCoincidences = GetBool("UseCoincidences", false);
44 
45  if (fUseCoincidences) {
46  fNecessaryCoincidentEvents = GetInt("NecessaryCoincidentEvents", 2);
47  fSufficientCoincidentEvents = GetInt("SufficientCoincidentEvents", 5);
48  fMaxRandomCoincidentEvents = GetInt("MaxRandomCoincidentEvents", 2);
49  }
50 
51  } else {
52  ev.Add<QBool>("IsPulser");
53  ev.Add<QInt>("Goodness");
54  ev.Add<QInt>("GoodnessThreshold");
55  if(fUseCoincidences) ev.Require<QCoincidenceTiming>("CoincidenceTiming_PulserFlag","Timing");
56  }
57 
58  ev.Require<QHeader>("DAQ","Header");
59  ev.Require<QPulseInfo>("DAQ","PulseInfo");
60 }
61 
63 {
64 
65  const QHeader& header = ev.Get<QHeader>("DAQ","Header");
66  const QPulseInfo& pulseInfo = ev.Get<QPulseInfo>("DAQ","PulseInfo");
67  const int& channel = pulseInfo.GetChannelId();
68 
69  const double time = header.GetTime().GetFromStartRunNs() / 1e9;
70 
71 
72  if (GetIteration() == 1 && ev.Get<QBool>("SkipEvent")==false) {
73  fTimingAnalyzer[channel].AddValue(time);
74  }
75  else if (GetIteration() == 2) {
76 
77  unsigned int goodness = 0;
78  unsigned int goodnessThreshold = 0;
79 
80  if (fTimingAnalyzer.count(channel) != 0) {
81  goodness = fTimingAnalyzer[channel].GetGoodness(time);
82  goodnessThreshold = fTimingAnalyzer[channel].GetGoodnessThreshold();
83  }
84 
85  bool isPulser = (goodness > goodnessThreshold);
86 
87  if (fUseCoincidences) {
88  const QCoincidenceTiming& coincTiming = ev.Get<QCoincidenceTiming>("CoincidenceTiming_PulserFlag","Timing");
89  int numberOfCoincidentEvents_SamePulserGroup = coincTiming.fNumberOfCoincidentEvents_SameHeaterGroup;
90  int numberOfCoincidentEvents = coincTiming.fNumberOfCoincidentEvents;
91 
92  // require at least some coincident events in the same heater group
93  isPulser = isPulser
94  && numberOfCoincidentEvents_SamePulserGroup
95  >= fNecessaryCoincidentEvents;
96 
97  // also flag events where a whole heater group fired
98  isPulser = isPulser
99  ||
100  (
101  numberOfCoincidentEvents_SamePulserGroup
102  >= fSufficientCoincidentEvents
103  &&
104  numberOfCoincidentEvents
105  <= numberOfCoincidentEvents_SamePulserGroup
106  + fMaxRandomCoincidentEvents
107  );
108  }
109 
110  ev.Get<QBool>("IsPulser") = isPulser;
111  ev.Get<QInt>("Goodness") = goodness;
112  ev.Get<QInt>("GoodnessThreshold") = goodnessThreshold;
113 
114  }
115 
116 }
117 
119 {
120  // called at the end of the event loop
121  if (GetIteration() == 1) {
122 
123  for (map<int, QTimingAnalyzer>::iterator channelIter
124  = fTimingAnalyzer.begin();
125  channelIter != fTimingAnalyzer.end();
126  ++channelIter) {
127 
128  Debug("Operating on channel %d", channelIter->first);
129 
130  QTimingAnalyzer& timingAnalyzer = channelIter->second;
131 
132  timingAnalyzer.SetExpectedPeriod(fExpectedTimeInterval);
133  timingAnalyzer.SetAdjustments(fTimeAdjustments);
134  timingAnalyzer.SetTolerance(fTimeTolerance);
135 
136  timingAnalyzer.FindPeriod(fTimeIntervalUncertainty,
137  fTimeIntervalStepSize);
138 
139  Info("Best time interval for channel %d: %f",
140  channelIter->first,
141  timingAnalyzer.GetPeriod());
142 
143  timingAnalyzer.ComputeGoodnessThreshold(fFalsePositiveRate);
144  // argument is false positive rate under the null hypothesis
145 
146  }
147  SetRunAgain(true);
148 
149  }
150  else {
151  SetRunAgain(false);
152  }
153 }
const int channel
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Flag heater events by their regular timing.
void Do(Diana::QEvent &ev)
Do method.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
bool wrapped into a QObject
Definition: QBool.hh:17
coincidence timing
int fNumberOfCoincidentEvents_SameHeaterGroup
diana event
Definition: QEvent.hh:46
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
const Diana::QTime & GetTime() const
get time
Definition: QHeader.hh:28
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
Analyzes a list of values for the occurance of elements separated by regular intervals.
void SetExpectedPeriod(const double period)
Set period for repetition of values.
void SetAdjustments(const std::vector< double > &adjustments)
Set adjustments.
void SetTolerance(const double tolerance)
Set size of window in which to look for event.
void ComputeGoodnessThreshold(const double falseRate)
Compute goodness threshold at given false positive rate.
double GetPeriod() const
Get period.
void FindPeriod(const double uncertainty, const double stepSize=0.008)
Find period by searching within 'uncertainty' of fPeriod.
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...