RdStationRiseTimeCalculator.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/Reader.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/TimeStamp.h>
8 #include <utl/TimeInterval.h>
9 #include <utl/TraceAlgorithm.h>
10 #include <utl/Trace.h>
11 #include <utl/Math.h>
12 
13 #include <evt/Event.h>
14 #include <evt/Header.h>
15 #include <sevt/Header.h>
16 #include <sevt/EventTrigger.h>
17 #include <revt/REvent.h>
18 #include <revt/EventTrigger.h>
19 #include <revt/Header.h>
20 #include <revt/StationRecData.h>
21 #include <revt/StationHeader.h>
22 #include <revt/StationGPSData.h>
23 #include <revt/Channel.h>
24 #include <revt/Station.h>
25 
26 #include <rdet/RDetector.h>
27 #include <rdet/Station.h>
28 
29 using namespace revt;
30 using namespace fwk;
31 using namespace utl;
32 using namespace std;
33 
34 
36 
38  {
39  // Initialize your module here. This method
40  // is called once at the beginning of the run.
41  // The eSuccess flag indicates the method ended
42  // successfully. For other possible return types,
43  // see the VModule documentation.
44 
45  INFO("RdStationRiseTimeCalculator::Init()");
46 
47  // Read in the configurations of the xml file
48  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdStationRiseTimeCalculator");
49  topBranch.GetChild("RiseTimeWindow").GetData(fRiseTimeWindow);
50 
51  if (fRiseTimeWindow > 2000*nanosecond) {
52  ERROR("this window should be narrower: short window around the main pulse");
53  return eFailure;
54  }
55 
56  return eSuccess;
57  }
58 
59 
61  RdStationRiseTimeCalculator::Run(evt::Event& event)
62  {
63  // Check if there are events at all
64  if (!event.HasREvent()) {
65  WARNING("No radio event found!");
66  return eContinueLoop;
67  }
68 
69  REvent& rEvent = event.GetREvent();
70 
71  // loop through stations and for every station through every channel
73  sIt != rEvent.CandidateStationsEnd(); ++sIt) {
74 
75  Station& station = *sIt;
76 
77  if (!station.HasRecData()) {
78  WARNING("Station has no RecData! Please call RdEventInitializer first!");
79  return eFailure;
80  }
81 
82  //double SignalSearchWindowStart = station.GetRecData().GetParameter(eSignalSearchWindowStart);
83  //double SignalSearchWindowStop = station.GetRecData().GetParameter(eSignalSearchWindowStop);
84 
85  // get station component with max SNR
86  const double SNR[3] = {
87  station.GetRecData().GetParameter(ePeakAmplitudeNS)/station.GetRecData().GetParameter(eNoiseRmsNS),
88  station.GetRecData().GetParameter(ePeakAmplitudeEW)/station.GetRecData().GetParameter(eNoiseRmsEW),
89  station.GetRecData().GetParameter(ePeakAmplitudeV)/station.GetRecData().GetParameter(eNoiseRmsV)
90  };
91 
92  int chwithmaxSNR = 0;
93  double tempSNRmax = 0;
94  for (int k = 0; k < 3; ++k) {
95  if (SNR[k] > tempSNRmax) {
96  tempSNRmax = SNR[k];
97  chwithmaxSNR = k;
98  }
99  }
100 
101  const double relTime = station.GetRecData().GetParameter(eTraceStartTime);
102 
103  // get trace with max SNR
104  const StationTimeSeries& stationtrace = station.GetStationTimeSeries();
105 
106  unsigned int maxPosition = 0;
107  if (chwithmaxSNR == 0)
108  maxPosition = station.GetRecData().GetParameter(ePeakTimeNS) - relTime;
109  else if (chwithmaxSNR == 1)
110  maxPosition = station.GetRecData().GetParameter(ePeakTimeEW) - relTime;
111  else if (chwithmaxSNR == 2)
112  maxPosition = station.GetRecData().GetParameter(ePeakTimeV) - relTime;
113 
114  const double samplingFrequency = 1. / stationtrace.GetBinning();
115 
116  // define the window used for rise time calculation
117  unsigned int startRiseTimeWindow = 0;
118  unsigned int stopRiseTimeWindow = 0;
119  if (maxPosition) {
120  startRiseTimeWindow = (maxPosition - (fRiseTimeWindow/2.)) * samplingFrequency;
121  stopRiseTimeWindow = (maxPosition + (fRiseTimeWindow/2.)) * samplingFrequency;
122  // work-around when startRiseTimeWindow moves out of the trace
123  //#warning JN: this check should probably be done somewhere else
124  if (maxPosition < fRiseTimeWindow/2.) {
125  WARNING("RiseTimeWindowStart outside of trace, RiseTimeWindow adjusted to start of trace");
126  startRiseTimeWindow = 0;
127  stopRiseTimeWindow = fRiseTimeWindow * samplingFrequency;
128  }
129  }
130 
131  // construction of the cumulative function
132  double cumulativeSum = 0;
133  const unsigned int cumulativeVectorSize = static_cast<unsigned int>(fRiseTimeWindow * samplingFrequency);
134  vector<double> cumulative(cumulativeVectorSize);
135  MakeCumulative(stationtrace, startRiseTimeWindow, stopRiseTimeWindow, cumulative, cumulativeSum, chwithmaxSNR);
136 
137  // normalize cumulative function
138  vector<double> normalizedCumulative(cumulativeVectorSize);
139  for (unsigned int k = startRiseTimeWindow; k < stopRiseTimeWindow + 1; ++k)
140  normalizedCumulative.at(k - startRiseTimeWindow) = cumulative.at(k - startRiseTimeWindow) / cumulativeSum;
141 
142  // rise time calculation
143  unsigned int minCumulative = 0;
144  unsigned int maxCumulative = 0;
145  GetRiseTime(startRiseTimeWindow, stopRiseTimeWindow, normalizedCumulative, minCumulative, maxCumulative);
146  const double riseTime = (maxCumulative - minCumulative) / samplingFrequency;
147 
148  station.GetRecData().SetParameter(eStationRiseTime, riseTime);
149 
150  }
151 
152  return eSuccess;
153  }
154 
155 
156  void
157  RdStationRiseTimeCalculator::MakeCumulative(const revt::StationTimeSeries& stationtrace,
158  const unsigned int startRiseTimeWindow, const unsigned int stopRiseTimeWindow,
159  vector<double>& cumulative, double& cumulativeSum, const unsigned int chwithmaxSNR)
160  const
161  {
162  cumulativeSum = Sqr(stationtrace.At(startRiseTimeWindow)[chwithmaxSNR]);
163  cumulative.at(0) = cumulativeSum;
164  for (unsigned int k = startRiseTimeWindow + 1; k < stopRiseTimeWindow + 1; ++k) {
165  const double tmpSum = Sqr(stationtrace.At(k)[chwithmaxSNR]);
166  cumulativeSum += tmpSum;
167  cumulative.at(k - startRiseTimeWindow) = cumulative.at(k - startRiseTimeWindow - 1) + tmpSum;
168  }
169  }
170 
171 
172  void
173  RdStationRiseTimeCalculator::GetRiseTime(const unsigned int startCumulative, const unsigned int stopCumulative,
174  vector<double>& normalizedCumulative, unsigned int& minCumulative, unsigned int& maxCumulative)
175  const
176  {
177  bool foundmin = false;
178  bool foundmax = false;
179  const double lowerCumulativeLimit = 0.2;
180  const double upperCumulativeLimit = 0.6;
181 
182  for (unsigned int k = startCumulative; k < stopCumulative+1; ++k) {
183  if (!foundmin) {
184  if (normalizedCumulative.at(k - startCumulative) < lowerCumulativeLimit)
185  continue;
186  else {
187  minCumulative = k;
188  foundmin = true;
189  }
190  }
191  if (!foundmax) {
192  if (normalizedCumulative.at(k - startCumulative) < upperCumulativeLimit)
193  continue;
194  else {
195  maxCumulative = k;
196  foundmax = true;
197  }
198  }
199  if (foundmin && foundmax)
200  break;
201  }
202  }
203 
204 }
Branch GetTopBranch() const
Definition: Branch.cc:63
T & At(const SizeType i)
trace entry with checked address
Definition: Trace.h:205
constexpr T Sqr(const T &x)
boost::filter_iterator< CandidateStationFilter, AllStationIterator > CandidateStationIterator
Iterator over all CandidateStations (i.e., HasSignal, HasNoSignal)
Definition: REvent.h:141
StationRecData & GetRecData()
Get station level reconstructed data.
CandidateStationIterator CandidateStationsEnd()
Definition: REvent.h:146
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
#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 HasREvent() const
StationTimeSeries & GetStationTimeSeries()
retrieve Station Time Series (write access, only use this if you intend to change the data) ...
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
constexpr double nanosecond
Definition: AugerUnits.h:143
CandidateStationIterator CandidateStationsBegin()
Definition: REvent.h:144
#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
double GetParameter(const Parameter i) const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
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
void SetParameter(Parameter i, double value, bool lock=true)
bool HasRecData() const
Check whether station reconstructed data exists.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.