RdStationPulseShapeRejector.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 
5 #include <fwk/CentralConfig.h>
6 #include <fwk/VModule.h>
7 #include <det/Detector.h>
8 #include <rdet/RDetector.h>
9 #include <algorithm>
10 
11 #include <utl/ErrorLogger.h>
12 #include <utl/Reader.h>
13 #include <utl/config.h>
14 
15 #include <evt/Event.h>
16 #include <evt/ShowerRRecData.h>
17 #include <evt/ShowerSRecData.h>
18 #include <evt/ShowerRecData.h>
19 #include <revt/REvent.h>
20 #include <revt/Station.h>
21 #include <revt/Header.h>
22 #include <revt/StationRecData.h>
23 
24 #include <TMath.h>
25 
26 using namespace std;
27 
29 
32  {
33  const auto topB = fwk::CentralConfig::GetInstance()->GetTopBranch("RdStationPulseShapeRejector");
34  topB.GetChild("InfoLevel").GetData(fInfoLevel);
35  topB.GetChild("checkT1Crossings").GetData(fCheckT1Crossings);
36  topB.GetChild("checkT2Crossings").GetData(fCheckT2Crossings);
37  topB.GetChild("T1").GetData(fT1);
38  topB.GetChild("T2").GetData(fT2);
39  topB.GetChild("T1MinSNR").GetData(fT1MinSNR);
40  topB.GetChild("PulseRegion").GetData(fPulseRegion);
41  topB.GetChild("TPer").GetData(fTPer);
42  topB.GetChild("T2MinSNR").GetData(fT2MinSNR);
43  topB.GetChild("NCMax").GetData(fNCMax);
44  topB.GetChild("UseVerticalComponent").GetData(fUseVerticalComponent);
45  return eSuccess;
46  }
47 
49  RdStationPulseShapeRejector::Run(evt::Event& event)
50  {
51  stringstream sstr;
52  revt::REvent& rEvent = event.GetREvent();
54  ++sIt) {
55  fTotalStations++;
56  revt::Station& station = *sIt;
57 
58  int traceMaxInt = FindTraceMaximum(station);
59  bool t1CrossingDeselected = false;
60 
61  if (fCheckT1Crossings) {
62  t1CrossingDeselected = !CheckT1Crossings(station, traceMaxInt);
63  sstr.str("");
64  sstr << "T1Crossing check returned " << t1CrossingDeselected;
65  INFODebug(sstr.str());
66  if (t1CrossingDeselected) {
67  sstr.str("");
68  sstr << "Rejecting station " << station.GetId();
69  INFOFinal(sstr.str());
70 
72  fRejectedStations++;
73  }
74  }
75 
76  if ((!t1CrossingDeselected) && fCheckT2Crossings) {
77  sstr.str("");
78  sstr << "Checking station " << station.GetId();
79  INFODebug(sstr.str());
80  CheckT2Crossings(station, traceMaxInt);
81  }
82  }
83 
84  return eSuccess;
85  }
86 
87  bool
88  RdStationPulseShapeRejector::CheckT1Crossings(revt::Station& station, int peakInt)
89  {
90  stringstream sstr;
91  sstr.str("");
92  sstr << "RdStationPulseShapeRejector::CheckT1Crossings";
93  INFODebug(sstr.str());
94 
95  revt::StationFFTDataContainer& efieldData = station.GetFFTDataContainer();
96  const revt::StationTimeSeries& stationTrace = efieldData.GetConstTimeSeries();
97  const double peakTime = station.GetRecData().GetParameter(revt::ePeakTimeMag) -
98  station.GetRecData().GetParameter(revt::eTraceStartTime);
99  const double binning = stationTrace.GetBinning() / utl::nanosecond;
100  const double peakMag = stationTrace[peakInt].GetMag();
101  double prevMag = 0;
102  double signalToNoise = 0;
103  double prevSNR = 0;
104  const revt::StationRecData& recStation = station.GetRecData();
105  const double noise = recStation.GetParameter(revt::eNoise);
106  int start = recStation.GetParameter(revt::eSignalSearchWindowStart) / binning;
107  int stop = (peakTime - fPulseRegion) / utl::nanosecond / binning;
108 
109  for (int i = start; i < stop; i++) {
110  signalToNoise = stationTrace[i].GetMag() / noise;
111  if ((stationTrace[i].GetMag() > fT1 * peakMag && signalToNoise > sqrt(fT1MinSNR)) &&
112  (prevMag < fT1 * peakMag || prevSNR < sqrt(fT1MinSNR))) {
113  sstr.str("");
114  sstr << "station rejected. peak located at " << peakInt
115  << " with magnitude " << peakMag << " . Crossed at " << i
116  << " with magnitude " << stationTrace[i].GetMag();
117  INFODebug(sstr.str());
118  return false;
119  }
120 
121  prevMag = stationTrace[i].GetMag();
122  prevSNR = signalToNoise;
123  }
124 
125  prevMag = 0;
126  prevSNR = 0;
127  start = (peakTime + fPulseRegion) / utl::nanosecond / binning;
128  stop = recStation.GetParameter(revt::eSignalSearchWindowStop) / binning;
129 
130  for (int i = start; i < stop; i++) {
131  signalToNoise = stationTrace[i].GetMag() / noise;
132  if ((stationTrace[i].GetMag() > fT1 * peakMag && signalToNoise > sqrt(fT1MinSNR)) &&
133  (prevMag < fT1 * peakMag || prevSNR < sqrt(fT1MinSNR))) {
134  sstr.str("");
135  sstr << "station rejected. peak located at " << peakInt << " with magnitude "
136  << peakMag << " . Crossed at " << i
137  << " with magnitude " << stationTrace[i].GetMag();
138  INFODebug(sstr.str());
139  return false;
140  }
141 
142  prevSNR = signalToNoise;
143  prevMag = stationTrace[i].GetMag();
144  }
145 
146  return true;
147  }
148 
149  void
150  RdStationPulseShapeRejector::CheckT2Crossings(revt::Station& station, int peakInt)
151  {
152  stringstream sstr;
153  sstr.str("");
154  sstr << "CheckT2Crossings";
155  INFODebug(sstr.str());
156 
157  revt::StationFFTDataContainer& efieldData = station.GetFFTDataContainer();
158  const revt::StationTimeSeries& stationTrace = efieldData.GetConstTimeSeries();
159  const double binning = stationTrace.GetBinning();
160  const double peakMag = stationTrace[peakInt].GetMag();
161  int start = peakInt - (fTPer / binning);
162  int stop = peakInt + (fTPer / binning);
163  int numberOfCrossings = 0;
164  double prevMag = stationTrace[start].GetMag();
165  const revt::StationRecData& recStation = station.GetRecData();
166  double noise;
167  if (fUseVerticalComponent) {
168  noise = recStation.GetParameter(revt::eNoiseRmsMag);
169  } else {
170  noise = recStation.GetParameter(revt::eNoiseRmsNSEWPlane);
171  }
172 
173  double signalToNoise = 0;
174  double prevSNR = 0;
175  double mag;
176  for (int i = start; i < peakInt; i++) {
177  if (fUseVerticalComponent) {
178  mag = stationTrace[i].GetMag();
179  } else {
180  mag = sqrt(stationTrace[i][0] * stationTrace[i][0] + stationTrace[i][1] * stationTrace[i][1]);
181  }
182 
183  signalToNoise = mag / noise;
184  if ((mag > fT2 * peakMag && signalToNoise > sqrt(fT2MinSNR)) && (prevMag <= fT2 * peakMag || prevSNR < sqrt(fT2MinSNR))) {
185  sstr.str("");
186  sstr << "NC increased at index " << i << " and relative time " << (i - peakInt) * binning;
187  INFODebug(sstr.str());
188  numberOfCrossings++;
189  }
190 
191  prevMag = mag;
192  prevSNR = signalToNoise;
193  }
194 
195  if (numberOfCrossings > fNCMax + 1) { //Plus 1 because the pulse maximum itself will also be counted by NC
196  sstr.str("");
197  sstr << "Station rejected: " << station.GetId();
198  INFOFinal(sstr.str());
199 
201  fRejectedStations++;
202  return;
203  } else {
204  sstr.str("");
205  sstr << "Station not rejected with NC=" << numberOfCrossings;
206  INFODebug(sstr.str());
207  }
208 
209  numberOfCrossings = 0;
210  for (int i = peakInt; i < stop; i++) {
211  if (fUseVerticalComponent) {
212  mag = stationTrace[i].GetMag();
213  } else {
214  mag = sqrt(stationTrace[i][0] * stationTrace[i][0] + stationTrace[i][1] * stationTrace[i][1]);
215  }
216 
217  signalToNoise = mag / noise;
218  if ((mag > fT2 * peakMag && signalToNoise > sqrt(fT2MinSNR)) && (prevMag <= fT2 * peakMag || prevSNR < sqrt(fT2MinSNR))) {
219  sstr.str("");
220  sstr << "NC increased at index " << i << " and relative time " << (i - peakInt) * binning;
221  INFODebug(sstr.str());
222  numberOfCrossings++;
223  }
224 
225  prevSNR = signalToNoise;
226  prevMag = mag;
227  }
228 
229  if (numberOfCrossings > fNCMax) {
230  sstr.str("");
231  sstr << "Station rejected: " << station.GetId();
232  INFOFinal(sstr.str());
233 
235  fRejectedStations++;
236  return;
237  } else {
238  sstr.str("");
239  sstr << "Station not rejected with NC=" << numberOfCrossings;
240  INFODebug(sstr.str());
241  }
242  }
243 
244  int
245  RdStationPulseShapeRejector::FindTraceMaximum(revt::Station& station)
246  {
247  const revt::StationTimeSeries& stationTrace = station.GetFFTDataContainer().GetConstTimeSeries();
248  const double peakTime = station.GetRecData().GetParameter(revt::ePeakTimeMag) -
249  station.GetRecData().GetParameter(revt::eTraceStartTime);
250  const double binning = stationTrace.GetBinning();
251  int peakInt = peakTime / binning;
252  double peakMag = stationTrace[peakInt].GetMag();
253  stringstream sstr;
254  for (int i = peakInt - fPulseRegion; i < peakInt + fPulseRegion; i++) {
255  if (stationTrace[i].GetMag() > peakMag) {
256  sstr.str("");
257  sstr << "Corrected peak from i=" << peakInt << " and P=" << peakMag
258  << " to i=" << i << " t=" << i * binning << " and P=" << stationTrace[i].GetMag();
259  INFODebug(sstr.str());
260 
261  peakMag = stationTrace[i].GetMag();
262  peakInt = i;
263  }
264  }
265 
266  sstr.str("");
267  sstr << "Peak is at index " << peakInt << " and time "
268  << peakInt * binning + station.GetRecData().GetParameter(revt::eTraceStartTime);
269  INFODebug(sstr.str());
270 
271  return peakInt;
272  }
273 
275  RdStationPulseShapeRejector::Finish()
276  {
277  stringstream sstr;
278  sstr.str("");
279  sstr << "Rejected " << fRejectedStations << " stations out of a total of " << fTotalStations << " stations.";
280  INFOFinal(sstr.str());
281  return eSuccess;
282  }
283 
284 }
Class to access station level reconstructed data.
StationRecData & GetRecData()
Get station level reconstructed data.
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
double GetBinning() const
size of one slot
Definition: Trace.h:138
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
class to hold data at the radio Station level.
constexpr double nanosecond
Definition: AugerUnits.h:143
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
void SetRejectedReason(const unsigned long long int reason)
int GetId() const
Get the station Id.
#define INFODebug(y)
Definition: VModule.h:163
double GetParameter(const Parameter i) const
Template class for a data container that offers and takes both time series and corresponding frequenc...
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const StationFFTDataContainer & GetFFTDataContainer() const
retrieve Station FFTDataContainer (read access)
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
Definition: Trace-fwd.h:19
SignalStationIterator SignalStationsEnd()
Definition: REvent.h:114
#define INFOFinal(y)
Definition: VModule.h:161
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
boost::filter_iterator< SignalStationFilter, AllStationIterator > SignalStationIterator
Iterator over all signal stations.
Definition: REvent.h:109
SignalStationIterator SignalStationsBegin()
Definition: REvent.h:112

, generated on Tue Sep 26 2023.