3 #include <fwk/CentralConfig.h>
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>
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>
20 #include <evt/ShowerRecData.h>
21 #include <evt/ShowerSRecData.h>
22 #include <evt/ShowerFRecData.h>
24 #include <det/Detector.h>
25 #include <rdet/RDetector.h>
26 #include <rdet/Station.h>
27 #include <rdet/Channel.h>
29 #include <fevt/FEvent.h>
31 #include <fevt/EyeRecData.h>
33 #include <boost/lexical_cast.hpp>
34 #include <boost/algorithm/string/split.hpp>
46 using std::ostringstream;
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);
84 topBranch.
GetChild(
"MinNumberOfStationsWithPulse").
GetData(fMinNumberOfStationsWithPulse);
87 topBranch.
GetChild(
"AllowedTimeAroundEventTime").
GetData(fAllowedTimeAroundEventTime);
91 const auto vectorSelectedEventIds = topBranch.
GetChild(
"SelectedEventIds").
Get<vector<int>>();
92 fSelectedEventIds = set<int>(vectorSelectedEventIds.begin(), vectorSelectedEventIds.end());
94 const auto vectorDeselectedEventIds = topBranch.
GetChild(
"DeselectedEventIds").
Get<vector<int>>();
95 fDeselectedEventIds = set<int>(vectorDeselectedEventIds.begin(), vectorDeselectedEventIds.end());
97 const auto vectorSelectedEventDates = topBranch.
GetChild(
"SelectedEventDates").
Get<vector<TimeStamp>>();
98 fSelectedEventDates = set<TimeStamp>(vectorSelectedEventDates.begin(), vectorSelectedEventDates.end());
102 const auto vectorSelectedRunEventIds = topBranch.
GetChild(
"SelectedRunEventIds").
Get<vector<string>>();
103 if (vectorSelectedRunEventIds.size() > 0) {
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]));
116 const auto vectorDeselectedRunEventIds = topBranch.
GetChild(
"DeselectedRunEventIds").
Get<vector<string>>();
117 if (vectorDeselectedRunEventIds.size() > 0) {
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]));
130 string tmp = topBranch.
GetChild(
"UsedEye").
Get<
string>();
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";
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" ;
172 string eventTimesFilename = topBranch.
GetChild(
"EventTimesFilename").
Get<
string>();
173 if (eventTimesFilename !=
"") {
176 fin.open(eventTimesFilename.c_str(), std::ios::in);
177 fin.getline(line, 256);
180 info <<
"loop through file " << eventTimesFilename;
184 WARNING(
"File could not be opened");
189 unsigned long runId, eventId, GPSSecond, GPSNanoSecond;
190 fin >> runId >> eventId >> GPSSecond >> GPSNanoSecond;
191 fEventGPSSeconds.push_back(GPSSecond);
192 fin.getline(line, 256);
194 info << runId <<
"\t" << eventId <<
"\t" << GPSSecond <<
"\t"
200 std::sort(fEventGPSSeconds.begin(), fEventGPSSeconds.end());
214 WARNING(
"No radio event found!");
216 return eContinueLoop;
219 REvent& rEvent =
event.GetREvent();
223 if (fEventGPSSeconds.size() > 0) {
226 unsigned long earlierEventTime = 0;
227 unsigned long laterEventTime = 10000000000;
229 const auto low = std::lower_bound(fEventGPSSeconds.begin(), fEventGPSSeconds.end(), currentGPSSecond);
230 const auto up = std::upper_bound(fEventGPSSeconds.begin(), fEventGPSSeconds.end(), currentGPSSecond);
232 if (
low != fEventGPSSeconds.end()) {
233 earlierEventTime = fEventGPSSeconds[(
low - fEventGPSSeconds.begin()) - 1];
236 if (up != fEventGPSSeconds.end()) {
237 laterEventTime = *up;;
240 if ( !(((currentGPSSecond - earlierEventTime) *
utl::second < fAllowedTimeAroundEventTime) ||
241 ((laterEventTime - currentGPSSecond) *
utl::second < fAllowedTimeAroundEventTime)) ) {
243 info <<
"event is larger then " << fAllowedTimeAroundEventTime /
utl::minute
244 <<
" min away from any given event time" <<
" (" << currentGPSSecond <<
" , "
245 << earlierEventTime <<
" - " << laterEventTime <<
")";
247 return eContinueLoop;
252 if (event.
HasRecShower() &&
event.GetRecShower().HasSRecShower()) {
253 const det::Detector& detector = det::Detector::GetInstance();
255 const utl::Vector axis =
event.GetRecShower().GetSRecShower().GetAxis();
256 const double zenith = axis.
GetTheta(referenceCS);
257 const double energy =
event.GetRecShower().GetSRecShower().GetEnergy();
259 if (zenith > fMaxSDZenith) {
261 info <<
"SD reconstructed zenith angle is greater than " << fMaxSDZenith /
utl::deg
262 <<
"deg, event will be skipped";
266 return eContinueLoop;
269 if (zenith < fMinSDZenith) {
271 info <<
"SD reconstructed zenith angle is smaller than " << fMinSDZenith /
utl::deg
272 <<
"deg, event will be skipped";
276 return eContinueLoop;
279 if (energy < fMinSDEnergy){
281 info <<
"SD reconstructed energy is smaller than " <<fMinSDEnergy /
utl::eV
282 <<
"eV, event will be skipped";
286 return eContinueLoop;
293 ERROR(
"No FEvent available but FD input specified in the settings!");
294 return eContinueLoop;
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)
305 ERROR(
"Selected FD eye has no RecData or FRecShower but FD input specified in the settings!");
306 return eContinueLoop;
311 const det::Detector& detector = det::Detector::GetInstance();
313 const double zenith = axis.
GetTheta(referenceCS);
314 if (zenith > fMaxFDZenith) {
316 info <<
"FD reconstructed zenith angle is greater than " << fMaxFDZenith /
utl::deg
317 <<
"deg, event will be skipped";
320 return eContinueLoop;
327 if (eventts < fAllowedTimeBegin) {
330 <<
" comes before minimum allowed Time";
334 return eContinueLoop;
337 if (eventts > fAllowedTimeStop) {
340 <<
" comes after maximum allowed Time";
344 if (fBreakLoopAtMaxDateTime)
347 return eContinueLoop;
351 if (fSelectedEventIds.size() > 0 &&
352 fSelectedEventIds.find(rEvent.
GetHeader().
GetId()) == fSelectedEventIds.end()) {
355 <<
" is not selected";
358 return eContinueLoop;
361 if (fDeselectedEventIds.size() > 0 &&
362 fDeselectedEventIds.find(rEvent.
GetHeader().
GetId()) != fDeselectedEventIds.end()) {
367 ++fNRejectedEventRejectionList;
369 return eContinueLoop;
372 if (fSelectedEventDates.size() > 0 &&
373 fSelectedEventDates.find(rEvent.
GetHeader().
GetTime()) == fSelectedEventDates.end()) {
376 <<
" is not selected";
379 return eContinueLoop;
383 if (fSelectedRunEventIds.size() > 0 &&
384 fSelectedRunEventIds.find(eventIdentifier) == fSelectedRunEventIds.end()) {
386 info <<
"The current event " << eventIdentifier.first <<
"." << eventIdentifier.second
387 <<
" is not selected";
390 return eContinueLoop;
393 if (fDeselectedRunEventIds.size() > 0 &&
394 fDeselectedRunEventIds.find(eventIdentifier) != fDeselectedRunEventIds.end()) {
396 info <<
"The current event ID " << eventIdentifier.first <<
"." << eventIdentifier.second
399 ++fNRejectedEventRejectionList;
401 return eContinueLoop;
405 if (fUseTriggerInformation && !CheckTrigger(rEvent.
GetTrigger())) {
406 INFOFinal(
"Event does not fulfill selected trigger conditions.");
407 ++fNRejectedTriggerConditions;
409 return eContinueLoop;
415 info <<
"Event must contain at least " << fMinNumberOfStations
419 ++fNRejectedMinNumberOfStations;
424 return eContinueLoop;
429 info <<
"Event must contain not more than " << fMaxNumberOfStations
434 return eContinueLoop;
440 info <<
"Event ID must be at least " << fMinEventId <<
" but it is "
444 return eContinueLoop;
447 if (fMaxEventId > 0 && rEvent.
GetHeader().
GetId() > fMaxEventId) {
449 info <<
"Event ID must be at most " << fMaxEventId <<
" but it is "
453 return eContinueLoop;
457 for (
int stationId : fAllParticipatingStationIds){
460 info <<
"Required station with ID " << stationId
461 <<
" does not take part in this event.";
464 return eContinueLoop;
469 if (fAtLeastOneParticipatingStationIds.size() > 0 ) {
470 bool OneTakesPlace =
false;
471 for (
int stationId : fAtLeastOneParticipatingStationIds) {
473 OneTakesPlace =
true;
478 if (!OneTakesPlace) {
479 INFOFinal(
"None of the required station take part in this event.");
481 return eContinueLoop;
486 for (
int stationId : fNotParticipatingStationIds)
489 info <<
"Not allowed station with ID " << stationId
490 <<
" does take part in this event.";
492 ++fNRejectedStationRejectionList;
494 return eContinueLoop;
498 if (fMinSignalToNoise > 0){
499 const unsigned int numberOfStationsWithPulseFound = CountStationWithPulse(event);
500 if (numberOfStationsWithPulseFound < fMinNumberOfStationsWithPulse) {
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.";
507 ++fNRejectedMinNumberOfStationsWithPulse;
509 return eContinueLoop;
520 RdEventPreSelector::Finish()
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;
540 const REvent& rEvent =
event.GetREvent();
542 unsigned int numberOfStationsWithPulseFound = 0;
543 bool PulseFound =
false;
546 for (
const auto& station : rEvent.StationsRange()) {
549 if (!station.HasRecData()) {
550 ERROR(
"Station has no RecData! Please call RdEventInitializer first!");
552 const auto& recStation = station.GetRecData();
555 for (
const auto& channel : station.ChannelsRange()) {
556 if (!channel.IsActive())
559 const auto& ChannelDet =
563 const auto& trace = channel.GetChannelTimeSeries();
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);
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 "
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.";
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!";
599 double NoiseWindowStart = recStation.GetParameter(eNoiseWindowStart);
600 double NoiseWindowStop = recStation.GetParameter(eNoiseWindowStop);
601 double SignalSearchWindowStart = recStation.GetParameter(eSignalSearchWindowStart);
602 double SignalSearchWindowStop = recStation.GetParameter(eSignalSearchWindowStop);
604 double MeanNoise = 0;
607 unsigned int sample = 0;
609 double PeakAmplitude = 0;
611 double PeakTimeError = 0;
613 double TraceStop = (trace.GetSize() - 1) * trace.GetBinning();
616 NoiseWindowStart = min(
max(0.0, NoiseWindowStart), TraceStop);
617 NoiseWindowStop =
max(min(NoiseWindowStop, TraceStop), NoiseWindowStart);
619 SignalSearchWindowStart = min(
max(0.0, SignalSearchWindowStart), TraceStop);
620 SignalSearchWindowStop =
max(min(SignalSearchWindowStop, TraceStop),
621 SignalSearchWindowStart);
626 SignalSearchWindowStart, SignalSearchWindowStop, sample);
628 PeakAmplitude = PeakAmplitude - MeanNoise;
629 RMSNoise =
sqrt(
Sqr(RMSNoise) -
Sqr(MeanNoise));
631 const double SignalToNoise = PeakAmplitude / RMSNoise;
633 if (SignalToNoise > fMinSignalToNoise)
639 ++numberOfStationsWithPulseFound;
643 return numberOfStationsWithPulseFound;
706 RdEventPreSelector::CloseTo(
const double a,
const double b,
const double tolerance)
709 return fabs(a - b) < tolerance;
Interface class to access the Event Trigger (T3)
bool IsCalibrationTrigger() const
Check if Event comes from calibration trigger.
constexpr T Sqr(const T &x)
bool IsPassThroughTrigger() const
Check if Event comes from PASSTHROUGH trigger.
Fluorescence Detector Eye Event.
bool HasRecShower() const
bool IsPeriodicTrigger() const
Check if Event comes from PERIODIC trigger.
Interface class to access to the Radio part of an event.
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
EyeIterator EyesEnd(const ComponentSelector::Status status)
static void Noisefinder(const utl::Trace< double > &channeltrace, double &noiseRMS, double &noiseMean, double NoiseWindowStart, double NoiseWindowStop)
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
bool IsGUITrigger() const
Check if Event comes from GUI trigger.
double pow(const double x, const unsigned int i)
A TimeStamp holds GPS second and nanosecond for some event.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define INFOIntermediate(y)
Class representing a document branch.
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
bool HasFRecShower() const
Check if reconstructed shower info has been allocated.
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
EyeIterator EyesBegin(const ComponentSelector::Status status)
int GetNumberOfStations() const
Get total number of stations in the event.
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.
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
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.
unsigned long GetGPSSecond() const
GPS second.
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) ...
Interface class to access to Fluorescence reconstruction of a Shower.
const rdet::RDetector & GetRDetector() const
bool HasStation(const int stationId) const
Check whether station exists.
#define ERROR(message)
Macro for logging error messages.
const Station & GetStation(const int stationId) const
Get station by Station Id.
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)
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
const utl::Vector & GetAxis() const
Shower Axis as reconstructed by the FD or FD eye.