RdEventPreSelector.cc
Go to the documentation of this file.
1 #include "RdEventPreSelector.h"
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
8 #include <utl/TraceAlgorithm.h>
9 #include <utl/RadioTraceUtilities.h>
10 
11 #include <evt/Event.h>
12 #include <revt/REvent.h>
13 #include <revt/Header.h>
14 #include <revt/Station.h>
15 #include <revt/Channel.h>
16 #include <revt/EventTrigger.h>
17 #include <revt/StationRecData.h>
18 #include <revt/StationHeader.h>
19 
20 #include <evt/ShowerRecData.h>
21 #include <evt/ShowerSRecData.h> // for SD zenith cut
22 #include <evt/ShowerFRecData.h> // for FD zenith cut
23 
24 #include <det/Detector.h>
25 #include <rdet/RDetector.h>
26 #include <rdet/Station.h>
27 #include <rdet/Channel.h>
28 
29 #include <fevt/FEvent.h>
30 #include <fevt/Eye.h>
31 #include <fevt/EyeRecData.h>
32 
33 #include <boost/lexical_cast.hpp>
34 #include <boost/algorithm/string/split.hpp>
35 
36 
37 using namespace fwk;
38 using namespace utl;
39 using namespace evt;
40 using namespace revt;
41 using namespace fevt;
42 using std::vector;
43 using std::pair;
44 using std::set;
45 using std::string;
46 using std::ostringstream;
47 using std::fstream;
48 using std::min;
49 using std::max;
50 
51 
52 namespace RdEventPreSelector {
53 
56  {
57  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdEventPreSelector");
58 
59  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
60  topBranch.GetChild("MinEventId").GetData(fMinEventId);
61  topBranch.GetChild("MaxEventId").GetData(fMaxEventId);
62  topBranch.GetChild("MinNumberOfStations").GetData(fMinNumberOfStations);
63  topBranch.GetChild("MaxNumberOfStations").GetData(fMaxNumberOfStations);
64  topBranch.GetChild("AllParticipatingStationIds").GetData(fAllParticipatingStationIds);
65  topBranch.GetChild("AtLeastOneParticipatingStationIds").GetData(fAtLeastOneParticipatingStationIds);
66  topBranch.GetChild("NotParticipatingStationIds").GetData(fNotParticipatingStationIds);
67  topBranch.GetChild("UseTriggerInformation").GetData(fUseTriggerInformation);
68  topBranch.GetChild("UseSelfTriggeredEvent").GetData(fUseSelfTriggeredEvent);
69  topBranch.GetChild("UseExternallyTriggeredEvent").GetData(fUseExternallyTriggeredEvent);
70  topBranch.GetChild("UseCalibrationTriggeredEvent").GetData(fUseCalibrationTriggeredEvent);
71  topBranch.GetChild("UseScintillatorTriggeredEvent").GetData(fUseScintillatorTriggeredEvent);
72  topBranch.GetChild("UseSDTriggeredEvent").GetData(fUseSDTriggeredEvent);
73  topBranch.GetChild("UseGUITriggeredEvent").GetData(fUseGUITriggeredEvent);
74  topBranch.GetChild("UseFDTriggeredEvent").GetData(fUseFDTriggeredEvent);
75  topBranch.GetChild("UseHEATTriggeredEvent").GetData(fUseHEATTriggeredEvent);
76  topBranch.GetChild("UseAERAletTriggeredEvent").GetData(fUseAERAletTriggeredEvent);
77  topBranch.GetChild("UseAIRPLANETriggeredEvent").GetData(fUseAIRPLANETriggeredEvent);
78  topBranch.GetChild("UsePeriodicTriggeredEvent").GetData(fUsePeriodicTriggeredEvent);
79  topBranch.GetChild("UsePassThroughTriggeredEvent").GetData(fUsePassThroughTriggeredEvent);
80  topBranch.GetChild("FirstAllowedEventDateTime").GetData(fAllowedTimeBegin);
81  topBranch.GetChild("LastAllowedEventDateTime").GetData(fAllowedTimeStop);
82  topBranch.GetChild("BreakLoopAtMaxDateTime").GetData(fBreakLoopAtMaxDateTime);
83  topBranch.GetChild("MinSignalToNoise").GetData(fMinSignalToNoise);
84  topBranch.GetChild("MinNumberOfStationsWithPulse").GetData(fMinNumberOfStationsWithPulse);
85  topBranch.GetChild("MaxSDZenith").GetData(fMaxSDZenith);
86  topBranch.GetChild("MinSDEnergy").GetData(fMinSDEnergy);
87  topBranch.GetChild("AllowedTimeAroundEventTime").GetData(fAllowedTimeAroundEventTime);
88  topBranch.GetChild("FDInput").GetData(fFDInput);
89  topBranch.GetChild("MaxFDZenith").GetData(fMaxSDZenith);
90 
91  const auto vectorSelectedEventIds = topBranch.GetChild("SelectedEventIds").Get<vector<int>>();
92  fSelectedEventIds = set<int>(vectorSelectedEventIds.begin(), vectorSelectedEventIds.end());
93 
94  const auto vectorDeselectedEventIds = topBranch.GetChild("DeselectedEventIds").Get<vector<int>>();
95  fDeselectedEventIds = set<int>(vectorDeselectedEventIds.begin(), vectorDeselectedEventIds.end());
96 
97  const auto vectorSelectedEventDates = topBranch.GetChild("SelectedEventDates").Get<vector<TimeStamp>>();
98  fSelectedEventDates = set<TimeStamp>(vectorSelectedEventDates.begin(), vectorSelectedEventDates.end());
99 
100  ostringstream info;
101 
102  const auto vectorSelectedRunEventIds = topBranch.GetChild("SelectedRunEventIds").Get<vector<string>>();
103  if (vectorSelectedRunEventIds.size() > 0) {
104  info.str("");
105  info << "only the following events will be selected:" << std::endl;
106  for (string runEventId : vectorSelectedRunEventIds) {
107  vector<string> splits;
108  boost::split(splits, runEventId, boost::is_any_of("."));
109  info << splits[0] << "." << splits[1] << ", ";
110  fSelectedRunEventIds.emplace(boost::lexical_cast<int>(splits[0]),
111  boost::lexical_cast<int>(splits[1]));
112  }
113  INFOFinal(info);
114  }
115 
116  const auto vectorDeselectedRunEventIds = topBranch.GetChild("DeselectedRunEventIds").Get<vector<string>>();
117  if (vectorDeselectedRunEventIds.size() > 0) {
118  info.str("");
119  info << "the following events will be rejected:" << std::endl;
120  for (string runEventId : vectorDeselectedRunEventIds) {
121  vector<string> splits;
122  boost::split(splits, runEventId, boost::is_any_of("."));
123  info << splits[0] << "." << splits[1] << ", ";
124  fDeselectedRunEventIds.emplace(boost::lexical_cast<int>(splits[0]),
125  boost::lexical_cast<int>(splits[1]));
126  }
127  INFOFinal(info);
128  }
129 
130  string tmp = topBranch.GetChild("UsedEye").Get<string>();
131  if (tmp == "CO")
132  fWhichEye = 4;
133  if (tmp == "HE")
134  fWhichEye = 5;
135  if (tmp == "HECO")
136  fWhichEye = 6;
137 
138  info.str("");
139  info <<" \nEvent id Minimum: "<< fMinEventId << " / Maximum: " << fMaxEventId << "\n";
140  info <<"Number of station Minimum: " << fMinNumberOfStations << " / Maximum: " << fMaxNumberOfStations << "\n";
141  if (!fUseTriggerInformation)
142  info << "Will not use trigger information";
143  else {
144  info << "Will use the following trigger mask:";
145  if (fUseSelfTriggeredEvent)
146  info << "\n\tSelf Trigger" ;
147  if (fUseExternallyTriggeredEvent)
148  info << "\n\tExternal Trigger" ;
149  if (fUseCalibrationTriggeredEvent)
150  info << "\n\tCalibration Trigger" ;
151  if (fUseScintillatorTriggeredEvent)
152  info << "\n\tScintillator Trigger" ;
153  if (fUseSDTriggeredEvent)
154  info << "\n\tSD Trigger" ;
155  if (fUseGUITriggeredEvent)
156  info << "\n\tGUI Trigger" ;
157  if (fUseFDTriggeredEvent)
158  info << "\n\tFD Trigger" ;
159  if (fUseHEATTriggeredEvent)
160  info << "\n\tHEAT Trigger" ;
161  if (fUseAERAletTriggeredEvent)
162  info << "\n\tAERALET Trigger" ;
163  if (fUseAIRPLANETriggeredEvent)
164  info << "\n\tAIRPLANE Trigger" ;
165  if (fUsePeriodicTriggeredEvent)
166  info << "\n\tPeriodic Trigger" ;
167  if (fUsePassThroughTriggeredEvent)
168  info << "\n\tPassThrough Trigger" ;
169  }
170  INFOFinal(info);
171 
172  string eventTimesFilename = topBranch.GetChild("EventTimesFilename").Get<string>();
173  if (eventTimesFilename != "") {
174  fstream fin;
175  char line[256];
176  fin.open(eventTimesFilename.c_str(), std::ios::in); // opening data
177  fin.getline(line, 256); // read/skip first line
178 
179  info.str("");
180  info << "loop through file " << eventTimesFilename;
181  INFODebug(info);
182 
183  if (!fin.good()) {
184  WARNING("File could not be opened");
185  return eFailure;
186  }
187 
188  while(fin.good()) {
189  unsigned long runId, eventId, GPSSecond, GPSNanoSecond;
190  fin >> runId >> eventId >> GPSSecond >> GPSNanoSecond;
191  fEventGPSSeconds.push_back(GPSSecond);
192  fin.getline(line, 256); // read rest of the lines
193  info.str("");
194  info << runId << "\t" << eventId << "\t" << GPSSecond << "\t"
195  << GPSNanoSecond;
196  INFODebug(info);
197  }
198 
199  fin.close();
200  std::sort(fEventGPSSeconds.begin(), fEventGPSSeconds.end());
201  }
202 
203  return eSuccess;
204  }
205 
206 
208  RdEventPreSelector::Run(evt::Event& event)
209  {
210  ++fNumberOfEvents;
211 
212  // Check if there is an radio event at all
213  if (!event.HasREvent()) {
214  WARNING("No radio event found!");
215  ++fNRejected;
216  return eContinueLoop;
217  }
218 
219  REvent& rEvent = event.GetREvent();
220  ostringstream info;
221 
222  // select only event around specific times
223  if (fEventGPSSeconds.size() > 0) {
224  const unsigned long currentGPSSecond = rEvent.GetHeader().GetTime().GetGPSSecond();
225  // find entry that is closest to current event time
226  unsigned long earlierEventTime = 0;
227  unsigned long laterEventTime = 10000000000;
228 
229  const auto low = std::lower_bound(fEventGPSSeconds.begin(), fEventGPSSeconds.end(), currentGPSSecond);
230  const auto up = std::upper_bound(fEventGPSSeconds.begin(), fEventGPSSeconds.end(), currentGPSSecond);
231 
232  if (low != fEventGPSSeconds.end()) {
233  earlierEventTime = fEventGPSSeconds[(low - fEventGPSSeconds.begin()) - 1];
234  }
235 
236  if (up != fEventGPSSeconds.end()) {
237  laterEventTime = *up;;
238  }
239 
240  if ( !(((currentGPSSecond - earlierEventTime) * utl::second < fAllowedTimeAroundEventTime) ||
241  ((laterEventTime - currentGPSSecond) * utl::second < fAllowedTimeAroundEventTime)) ) {
242  info.str("");
243  info << "event is larger then " << fAllowedTimeAroundEventTime / utl::minute
244  << " min away from any given event time" << " (" << currentGPSSecond << " , "
245  << earlierEventTime << " - " << laterEventTime << ")";
246  INFODebug(info);
247  return eContinueLoop;
248  }
249  } // end select only event around specific times
250 
251  // check if there is an SD event and apply max zenith cut
252  if (event.HasRecShower() && event.GetRecShower().HasSRecShower()) {
253  const det::Detector& detector = det::Detector::GetInstance();
254  const utl::CoordinateSystemPtr referenceCS = detector.GetReferenceCoordinateSystem();
255  const utl::Vector axis = event.GetRecShower().GetSRecShower().GetAxis();
256  const double zenith = axis.GetTheta(referenceCS);
257  const double energy = event.GetRecShower().GetSRecShower().GetEnergy();
258 
259  if (zenith > fMaxSDZenith) {
260  info.str("");
261  info << "SD reconstructed zenith angle is greater than " << fMaxSDZenith / utl::deg
262  << "deg, event will be skipped";
263  INFOFinal(info.str());
264 
265  fNRejected++;
266  return eContinueLoop;
267  }
268 
269  if (zenith < fMinSDZenith) {
270  info.str("");
271  info << "SD reconstructed zenith angle is smaller than " << fMinSDZenith / utl::deg
272  << "deg, event will be skipped";
273  INFOFinal(info.str());
274 
275  fNRejected++;
276  return eContinueLoop;
277  }
278 
279  if (energy < fMinSDEnergy){
280  info.str("");
281  info << "SD reconstructed energy is smaller than " <<fMinSDEnergy /utl::eV
282  << "eV, event will be skipped";
283  INFOFinal(info.str());
284 
285  fNRejected++;
286  return eContinueLoop;
287  }
288  }
289 
290  // if FD is selected as input: check if there is an FD event, apply max zenith cut and test selected eye
291  if (fFDInput) {
292  if (!event.HasFEvent()) {
293  ERROR("No FEvent available but FD input specified in the settings!");
294  return eContinueLoop;
295  }
296 
297  FEvent& fdEvent = event.GetFEvent();
298  for (auto eyeIter = fdEvent.EyesBegin(ComponentSelector::eHasData);
299  eyeIter != fdEvent.EyesEnd(ComponentSelector::eHasData); ++eyeIter) {
300  if (eyeIter->GetId() != fWhichEye)
301  continue; // continue until selected eye
302  const fevt::Eye& eye = *eyeIter;
303 
304  if (!eye.HasRecData() || !eye.GetRecData().HasFRecShower()) {
305  ERROR("Selected FD eye has no RecData or FRecShower but FD input specified in the settings!");
306  return eContinueLoop;
307  }
308 
309  const ShowerFRecData& shower = eye.GetRecData().GetFRecShower();
310  const utl::Vector axis = shower.GetAxis();
311  const det::Detector& detector = det::Detector::GetInstance();
312  const utl::CoordinateSystemPtr referenceCS = detector.GetReferenceCoordinateSystem();
313  const double zenith = axis.GetTheta(referenceCS);
314  if (zenith > fMaxFDZenith) {
315  info.str("");
316  info << "FD reconstructed zenith angle is greater than " << fMaxFDZenith / utl::deg
317  << "deg, event will be skipped";
318  INFOFinal(info);
319  fNRejected++;
320  return eContinueLoop;
321  }
322  }
323  }
324 
325  // check preselected time range
326  const TimeStamp& eventts = rEvent.GetHeader().GetTime();
327  if (eventts < fAllowedTimeBegin) {
328  info.str("");
329  info << "Event ID " << rEvent.GetHeader().GetId()
330  << " comes before minimum allowed Time";
331  INFOFinal(info);
332 
333  fNRejected++;
334  return eContinueLoop;
335  }
336 
337  if (eventts > fAllowedTimeStop) {
338  info.str("");
339  info << "Event ID " << rEvent.GetHeader().GetId()
340  << " comes after maximum allowed Time";
341  INFOFinal(info.str());
342 
343  fNRejected++;
344  if (fBreakLoopAtMaxDateTime)
345  return eBreakLoop;
346 
347  return eContinueLoop;
348  }
349 
350  // check for specific (de)selected event ids
351  if (fSelectedEventIds.size() > 0 &&
352  fSelectedEventIds.find(rEvent.GetHeader().GetId()) == fSelectedEventIds.end()) {
353  info.str("");
354  info << "The current event ID " << rEvent.GetHeader().GetId()
355  << " is not selected";
356  INFOFinal(info);
357  ++fNRejected;
358  return eContinueLoop;
359  }
360 
361  if (fDeselectedEventIds.size() > 0 &&
362  fDeselectedEventIds.find(rEvent.GetHeader().GetId()) != fDeselectedEventIds.end()) {
363  info.str("");
364  info << "The current event ID " << rEvent.GetHeader().GetId()
365  << " is deselected";
366  INFOFinal(info);
367  ++fNRejectedEventRejectionList;
368  ++fNRejected;
369  return eContinueLoop;
370  }
371 
372  if (fSelectedEventDates.size() > 0 &&
373  fSelectedEventDates.find(rEvent.GetHeader().GetTime()) == fSelectedEventDates.end()) {
374  info.str("");
375  info << "The current event date " << rEvent.GetHeader().GetTime()
376  << " is not selected";
377  INFOFinal(info.str());
378  ++fNRejected;
379  return eContinueLoop;
380  }
381 
382  const pair<int, int> eventIdentifier (rEvent.GetHeader().GetRunNumber(), rEvent.GetHeader().GetId());
383  if (fSelectedRunEventIds.size() > 0 &&
384  fSelectedRunEventIds.find(eventIdentifier) == fSelectedRunEventIds.end()) {
385  info.str("");
386  info << "The current event " << eventIdentifier.first << "." << eventIdentifier.second
387  << " is not selected";
388  INFOFinal(info);
389  ++fNRejected;
390  return eContinueLoop;
391  }
392 
393  if (fDeselectedRunEventIds.size() > 0 &&
394  fDeselectedRunEventIds.find(eventIdentifier) != fDeselectedRunEventIds.end()) {
395  info.str("");
396  info << "The current event ID " << eventIdentifier.first << "." << eventIdentifier.second
397  << " is deselected";
398  INFOFinal(info);
399  ++fNRejectedEventRejectionList;
400  ++fNRejected;
401  return eContinueLoop;
402  }
403 
404  // check trigger flags
405  if (fUseTriggerInformation && !CheckTrigger(rEvent.GetTrigger())) {
406  INFOFinal("Event does not fulfill selected trigger conditions.");
407  ++fNRejectedTriggerConditions;
408  ++fNRejected;
409  return eContinueLoop;
410  }
411 
412  // check if number of stations contained in the event passes the cuts
413  if (rEvent.GetNumberOfStations() < fMinNumberOfStations) {
414  info.str("");
415  info << "Event must contain at least " << fMinNumberOfStations
416  << " stations but does contain only " << rEvent.GetNumberOfStations()
417  << " stations.";
418  INFOFinal(info);
419  ++fNRejectedMinNumberOfStations;
420  ++fNRejected;
421 
422  if (rEvent.GetNumberOfStations() > fMaxNumberOfAvailableStationsInLargestEvents)
423  fMaxNumberOfAvailableStationsInLargestEvents = rEvent.GetNumberOfStations();
424  return eContinueLoop;
425  }
426 
427  if (fMaxNumberOfStations > 0 && rEvent.GetNumberOfStations() > fMaxNumberOfStations) {
428  info.str("");
429  info << "Event must contain not more than " << fMaxNumberOfStations
430  << " stations but does contain " << rEvent.GetNumberOfStations()
431  << " stations.";
432  INFOFinal(info);
433  ++fNRejected;
434  return eContinueLoop;
435  }
436 
437  // check if cuts for event IDs are passed
438  if (rEvent.GetHeader().GetId() < fMinEventId) {
439  info.str("");
440  info << "Event ID must be at least " << fMinEventId << " but it is "
441  << rEvent.GetHeader().GetId() << ".";
442  INFOFinal(info);
443  ++fNRejected;
444  return eContinueLoop;
445  }
446 
447  if (fMaxEventId > 0 && rEvent.GetHeader().GetId() > fMaxEventId) {
448  info.str("");
449  info << "Event ID must be at most " << fMaxEventId << " but it is "
450  << rEvent.GetHeader().GetId() << ".";
451  INFOFinal(info);
452  ++fNRejected;
453  return eContinueLoop;
454  }
455 
456  // look if all required station ids take part
457  for (int stationId : fAllParticipatingStationIds){
458  if (!rEvent.HasStation(stationId)) {
459  info.str("");
460  info << "Required station with ID " << stationId
461  << " does not take part in this event.";
462  INFOFinal(info);
463  ++fNRejected;
464  return eContinueLoop;
465  }
466  }
467 
468  // look if one of the required stations take part
469  if (fAtLeastOneParticipatingStationIds.size() > 0 ) {
470  bool OneTakesPlace = false;
471  for (int stationId : fAtLeastOneParticipatingStationIds) {
472  if (rEvent.HasStation(stationId)) {
473  OneTakesPlace = true;
474  break;
475  }
476  }
477 
478  if (!OneTakesPlace) {
479  INFOFinal("None of the required station take part in this event.");
480  ++fNRejected;
481  return eContinueLoop;
482  }
483  }
484 
485  // look if any not-allowed station ids take part
486  for (int stationId : fNotParticipatingStationIds)
487  if (rEvent.HasStation(stationId)) {
488  info.str("");
489  info << "Not allowed station with ID " << stationId
490  << " does take part in this event.";
491  INFOFinal(info);
492  ++fNRejectedStationRejectionList;
493  ++fNRejected;
494  return eContinueLoop;
495  }
496 
497  // check if a minimum number of stations fulfills the SNR condition (has pulses in the ADC trace)
498  if (fMinSignalToNoise > 0){
499  const unsigned int numberOfStationsWithPulseFound = CountStationWithPulse(event);
500  if (numberOfStationsWithPulseFound < fMinNumberOfStationsWithPulse) {
501  info.str("");
502  info << "Event must contain at least " << fMinNumberOfStationsWithPulse
503  << " stations with ADC pulse fulfilling the condition on an SNR cut of "
504  << fMinSignalToNoise << ", but it only contains: "
505  << numberOfStationsWithPulseFound << " stations.";
506  INFOFinal(info);
507  ++fNRejectedMinNumberOfStationsWithPulse;
508  ++fNRejected;
509  return eContinueLoop;
510  }
511  }
512 
513  // if all cuts are passed, return eSuccess at the end
514  ++fNAccepted;
515  return eSuccess;
516  }
517 
518 
520  RdEventPreSelector::Finish()
521  {
522  ostringstream sstr;
523  sstr << fNRejected << " events rejected (total number of events = " << fNumberOfEvents << ")"
524  << "\n\tEvent does not fulfill trigger conditions:\t" << fNRejectedTriggerConditions
525  << "\n\tEvent in EventRejectionList:\t" << fNRejectedEventRejectionList
526  << "\n\tEvent has not enough stations:\t" << fNRejectedMinNumberOfStations
527  << " (of those rejected stations, no event had more than "
528  << fMaxNumberOfAvailableStationsInLargestEvents << " stations.)"
529  << "\n\tEvent has Station in StationRejectionList:\t" << fNRejectedStationRejectionList;
530  INFO(sstr);
531  return eSuccess;
532  }
533 
534 
535  unsigned int
536  RdEventPreSelector::CountStationWithPulse(evt::Event& event)
537  const
538  {
539  const det::Detector& zedet = det::Detector::GetInstance();
540  const REvent& rEvent = event.GetREvent();
541 
542  unsigned int numberOfStationsWithPulseFound = 0;
543  bool PulseFound = false;
544 
545  // loop over stations and for every station over each channel
546  for (const auto& station : rEvent.StationsRange()) {
547 
548  // RRecStation event should have been generated by RdEventInitializer
549  if (!station.HasRecData()) {
550  ERROR("Station has no RecData! Please call RdEventInitializer first!");
551  }
552  const auto& recStation = station.GetRecData();
553 
554  // loop over the channels
555  for (const auto& channel : station.ChannelsRange()) {
556  if (!channel.IsActive())
557  continue;
558 
559  const auto& ChannelDet =
560  zedet.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
561 
562  // read the trace of the channel
563  const auto& trace = channel.GetChannelTimeSeries();
564 
565  // check if the content of each trace is correct
566  const double bitDepth = ChannelDet.GetBitDepth();
567  const double samplingFrequency = ChannelDet.GetSamplingFrequency();
568  const double traceBinning = trace.GetBinning();
569  const double traceMax = TraceAlgorithm::Max(trace, 0, trace.GetSize()-1);
570  const double traceMin = TraceAlgorithm::Min(trace, 0, trace.GetSize()-1);
571 
572  if (!CloseTo(1.0 / traceBinning, samplingFrequency, 1e-6)) {
573  ostringstream warning;
574  warning << "ADC Sampling Frequency of " << samplingFrequency / MHz
575  << " MHz does not match sampling frequency of data, which is "
576  << 1.0/traceBinning / MHz << " MHz. Aborting."
577  << " Was processing Station : " << station.GetId() << " Channel "
578  << channel.GetId();
579  ERROR(warning);
580  }
581 
582  if ((traceMin < 0) || (traceMax > pow(2, bitDepth)-1)) {
583  ostringstream warning;
584  warning << "ADC trace of Channel " << channel.GetId()
585  << ", Station " << station.GetId()
586  << " has illegal entries. Aborting.";
587  ERROR(warning);
588  continue;
589  }
590 
591  if (!traceMin || traceMax == pow(2, bitDepth)-1) {
592  ostringstream warning;
593  warning << "ADC trace of Channel " << channel.GetId()
594  << ", Station " << station.GetId()
595  << " has saturated samples!";
596  INFOIntermediate(warning);
597  }
598 
599  double NoiseWindowStart = recStation.GetParameter(eNoiseWindowStart);
600  double NoiseWindowStop = recStation.GetParameter(eNoiseWindowStop);
601  double SignalSearchWindowStart = recStation.GetParameter(eSignalSearchWindowStart);
602  double SignalSearchWindowStop = recStation.GetParameter(eSignalSearchWindowStop);
603 
604  double MeanNoise = 0;
605  double RMSNoise = 0;
606 
607  unsigned int sample = 0;
608 
609  double PeakAmplitude = 0;
610  double PeakTime = 0;
611  double PeakTimeError = 0;
612 
613  double TraceStop = (trace.GetSize() - 1) * trace.GetBinning();
614 
615  // clip windows at trace boundaries
616  NoiseWindowStart = min(max(0.0, NoiseWindowStart), TraceStop);
617  NoiseWindowStop = max(min(NoiseWindowStop, TraceStop), NoiseWindowStart);
618 
619  SignalSearchWindowStart = min(max(0.0, SignalSearchWindowStart), TraceStop);
620  SignalSearchWindowStop = max(min(SignalSearchWindowStop, TraceStop),
621  SignalSearchWindowStart);
622 
623  // calculate noise and find pulse
624  utl::RadioTraceUtilities::Noisefinder(trace, RMSNoise, MeanNoise, NoiseWindowStart, NoiseWindowStop);
625  utl::RadioTraceUtilities::Pulsefinder(trace, PeakAmplitude, PeakTime, PeakTimeError,
626  SignalSearchWindowStart, SignalSearchWindowStop, sample);
627 
628  PeakAmplitude = PeakAmplitude - MeanNoise;
629  RMSNoise = sqrt(Sqr(RMSNoise) - Sqr(MeanNoise));
630 
631  const double SignalToNoise = PeakAmplitude / RMSNoise;
632 
633  if (SignalToNoise > fMinSignalToNoise)
634  PulseFound = true;
635 
636  } //end of loop over the channels
637 
638  if (PulseFound)
639  ++numberOfStationsWithPulseFound;
640 
641  } //end of loop over stations
642 
643  return numberOfStationsWithPulseFound;
644  }
645 
646 
647  bool
648  RdEventPreSelector::CheckTrigger(const EventTrigger& evtrig)
649  {
650  INFOIntermediate("RdEventPreSelector::CheckTrigger");
651  if (evtrig.IsSelfTrigger())
652  INFODebug("IS SELF TRIGGER");
653  if (evtrig.IsExternalTrigger())
654  INFODebug("IS EXTERNAL TRIGGER");
655  if (evtrig.IsCalibrationTrigger())
656  INFODebug("IS CALIBRATION TRIGGER");
657  if (evtrig.IsScintillatorTrigger())
658  INFODebug("IS SCINTILLATOR TRIGGER");
659  if (evtrig.IsSDTrigger())
660  INFODebug("IS SD TRIGGER");
661  if (evtrig.IsGUITrigger())
662  INFODebug("IS GUI TRIGGER");
663  if (evtrig.IsFDTrigger())
664  INFODebug("IS FD TRIGGER");
665  if (evtrig.IsHEATTrigger())
666  INFODebug("IS HEAT TRIGGER");
667  if (evtrig.IsAERAletTrigger())
668  INFODebug("IS AERALET TRIGGER");
669  if (evtrig.IsAIRPLANETrigger())
670  INFODebug("IS AIRPLANE TRIGGER");
671  if (evtrig.IsPeriodicTrigger())
672  INFODebug("IS PERIODIC TRIGGER");
673  if (evtrig.IsPassThroughTrigger())
674  INFODebug("IS PASSTHROUGH TRIGGER");
675 
676  if (fUseSelfTriggeredEvent && evtrig.IsSelfTrigger())
677  return true;
678  if (fUseExternallyTriggeredEvent && evtrig.IsExternalTrigger())
679  return true;
680  if (fUseCalibrationTriggeredEvent && evtrig.IsCalibrationTrigger())
681  return true;
682  if (fUseScintillatorTriggeredEvent && evtrig.IsScintillatorTrigger())
683  return true;
684  if (fUseSDTriggeredEvent && evtrig.IsSDTrigger())
685  return true;
686  if (fUseGUITriggeredEvent && evtrig.IsGUITrigger())
687  return true;
688  if (fUseFDTriggeredEvent && evtrig.IsFDTrigger())
689  return true;
690  if (fUseHEATTriggeredEvent && evtrig.IsHEATTrigger())
691  return true;
692  if (fUseAERAletTriggeredEvent && evtrig.IsAERAletTrigger())
693  return true;
694  if (fUseAIRPLANETriggeredEvent && evtrig.IsAIRPLANETrigger())
695  return true;
696  if (fUsePeriodicTriggeredEvent && evtrig.IsPeriodicTrigger())
697  return true;
698  if (fUsePassThroughTriggeredEvent && evtrig.IsPassThroughTrigger())
699  return true;
700 
701  return false;
702  }
703 
704 
705  bool
706  RdEventPreSelector::CloseTo(const double a, const double b, const double tolerance)
707  const
708  {
709  return fabs(a - b) < tolerance;
710  }
711 
712 }
713 
Interface class to access the Event Trigger (T3)
constexpr double second
Definition: AugerUnits.h:145
bool IsCalibrationTrigger() const
Check if Event comes from calibration trigger.
constexpr double eV
Definition: AugerUnits.h:185
constexpr T Sqr(const T &x)
bool IsPassThroughTrigger() const
Check if Event comes from PASSTHROUGH trigger.
constexpr double MHz
Definition: AugerUnits.h:159
bool HasRecData() const
Definition: FEvent/Eye.h:116
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
bool HasRecShower() const
bool IsPeriodicTrigger() const
Check if Event comes from PERIODIC trigger.
bool HasFEvent() const
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
utl::TimeStamp GetTime() const
Definition: REvent/Header.h:17
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
Definition: REvent.h:229
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
static void Noisefinder(const utl::Trace< double > &channeltrace, double &noiseRMS, double &noiseMean, double NoiseWindowStart, double NoiseWindowStop)
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool IsGUITrigger() const
Check if Event comes from GUI trigger.
double pow(const double x, const unsigned int i)
bool HasREvent() const
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
constexpr double deg
Definition: AugerUnits.h:140
T Get() const
Definition: Branch.h:271
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define INFOIntermediate(y)
Definition: VModule.h:162
#define max(a, b)
Class representing a document branch.
Definition: Branch.h:107
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
bool HasFRecShower() const
Check if reconstructed shower info has been allocated.
Definition: EyeRecData.h:330
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
Definition: EyeRecData.h:323
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
int GetNumberOfStations() const
Get total number of stations in the event.
Definition: REvent.h:206
static void Pulsefinder(const utl::Trace< double > &channeltrace, double &peakAmplitude, double &peakTime, double &peakTimeError, double signalSearchWindowStart, double signalSearchWindowStop, unsigned int &sample)
bool IsHEATTrigger() const
Check if Event comes from HEAT trigger.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
constexpr double minute
Definition: AugerUnits.h:149
#define INFODebug(y)
Definition: VModule.h:163
bool IsSDTrigger() const
Check if Event comes from SD trigger.
bool IsExternalTrigger() const
Check if Event was externally triggered.
bool IsSelfTrigger() const
Check if Event was selftriggered.
bool IsAERAletTrigger() const
Check if Event comes from AERALET trigger.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const double low[npar]
Definition: UnivRec.h:77
int GetRunNumber() const
Event id in the run (Start at zero at the beginning of each run) /provided by the daq...
Definition: REvent/Header.h:22
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
Definition: Detector.h:141
Vector object.
Definition: Vector.h:30
Interface class to access to Fluorescence reconstruction of a Shower.
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
bool HasStation(const int stationId) const
Check whether station exists.
Definition: REvent.cc:132
#define INFOFinal(y)
Definition: VModule.h:161
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
int GetId() const
Definition: REvent/Header.h:21
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
bool IsScintillatorTrigger() const
Check if Event comes from scintillator trigger.
bool IsFDTrigger() const
Check if Event comes from FD trigger.
bool IsAIRPLANETrigger() const
Check if Event comes from AIRPLANE trigger.
Predicate for approximate equality (for floating point)
Definition: Test.h:91
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
Definition: FEvent/Eye.cc:130
const utl::Vector & GetAxis() const
Shower Axis as reconstructed by the FD or FD eye.

, generated on Tue Sep 26 2023.