RdChannelRiseTimeCalculator.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/Math.h>
11 
12 #include <evt/Event.h>
13 
14 #include <revt/REvent.h>
15 #include <revt/StationRecData.h>
16 #include <revt/Channel.h>
17 #include <revt/Station.h>
18 
19 #include <vector>
20 
21 using namespace revt;
22 using namespace fwk;
23 using namespace utl;
24 using namespace std;
25 
26 
28 
31  {
32  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdChannelRiseTimeCalculator");
33  topBranch.GetChild("RiseTimeWindow").GetData(fRiseTimeWindow);
34 
35  if (fRiseTimeWindow > 2000 * nanosecond) {
36  ERROR("this window should be narrower: short window around the main pulse");
37  return eFailure;
38  }
39 
40  return eSuccess;
41  }
42 
43 
45  RdChannelRiseTimeCalculator::Run(evt::Event& event)
46  {
47  // Check if there are events at all
48  if (!event.HasREvent()) {
49  WARNING("No radio event found!");
50  return eContinueLoop;
51  }
52 
53  REvent& rEvent = event.GetREvent();
54 
55  // loop through stations and for every station through every channel
57  sIt != rEvent.CandidateStationsEnd(); ++sIt) {
58 
59  Station& station = *sIt;
60 
61  const double signalSearchWindowStart = station.GetRecData().GetParameter(eSignalSearchWindowStart);
62  const double signalSearchWindowStop = station.GetRecData().GetParameter(eSignalSearchWindowStop);
63  const double noiseWindowStart = station.GetRecData().GetParameter(eNoiseWindowStart);
64  const double noiseWindowStop = station.GetRecData().GetParameter(eNoiseWindowStop);
65 
66  for (Station::ChannelIterator cIt = station.ChannelsBegin();
67  cIt != station.ChannelsEnd(); ++cIt) {
68 
69  Channel& channel = *cIt;
70 
71  if (!channel.IsActive())
72  continue;
73 
74  // Work on the time series of this channel
75  ChannelTimeSeries& trace = channel.GetChannelTimeSeries();
76 
77  double noiseRMS = 0;
78  Noisefinder(trace, noiseRMS, noiseWindowStart, noiseWindowStop);
79 
80  // Find the index of the pulse maximum position
81  double peakAmplitude = 0;
82  double peakTime = 0;
83  double peakTimeError = 0;
84  unsigned int maxPosition = 0;
85  Pulsefinder(trace, peakAmplitude, peakTime, peakTimeError, signalSearchWindowStart, signalSearchWindowStop, maxPosition);
86 
87  if (!channel.HasRecData())
88  channel.MakeRecData();
89  channel.GetRecData().SetParameter(eChannelSignalToNoise, peakAmplitude / noiseRMS);
90 
91  // Define the window used for rise time calculation
92  const double samplingFrequency = 1. / trace.GetBinning();
93  const double riseTimeWindowFrequency = fRiseTimeWindow * samplingFrequency;
94  int startRiseTimeWindow = 0;
95  int stopRiseTimeWindow = 0;
96  if (maxPosition != 0) {
97  const int half = 0.5 * riseTimeWindowFrequency;
98  startRiseTimeWindow = int(maxPosition) - half;
99  stopRiseTimeWindow = int(maxPosition) + half;
100  // work-around when startRiseTimeWindow moves out of the trace
101  //#warning JN: this check should probably be done somewhere else
102  if (startRiseTimeWindow < 0) {
103  WARNING("RiseTimeWindowStart outside of trace, RiseTimeWindow adjusted to start of trace");
104  startRiseTimeWindow = 0;
105  stopRiseTimeWindow = riseTimeWindowFrequency;
106  }
107  }
108 
109  // Construction of the cumulative function
110  double cumulativeSum = 0;
111  // unsigned int cumulativeVectorSize = riseTimeWindowFrequency;
112  std::vector<double> cumulative;
113  MakeCumulative(trace, startRiseTimeWindow, stopRiseTimeWindow, cumulative, cumulativeSum);
114 
115  // Normalize cumulative function
116  std::vector<double> normalizedCumulative;
117  for (const auto &value : cumulative)
118  normalizedCumulative.push_back(value / cumulativeSum);
119 
120  // Rise time calculation
121  double riseTime = 0;
122  GetRiseTime(startRiseTimeWindow, stopRiseTimeWindow, normalizedCumulative, riseTime, samplingFrequency);
123  channel.GetRecData().SetParameter(eRiseTime, riseTime);
124  }
125  }
126 
127  return eSuccess;
128  }
129 
130 
131  void
132  RdChannelRiseTimeCalculator::Noisefinder(const revt::ChannelTimeSeries& channeltrace,
133  double& rmsNoise, const double noiseWindowStart, const double noiseWindowStop)
134  const
135  {
136  const unsigned int start = noiseWindowStart / channeltrace.GetBinning();
137  const unsigned int stop = noiseWindowStop / channeltrace.GetBinning();
138  rmsNoise = TraceAlgorithm::RootMeanSquare(channeltrace, start, stop);
139  }
140 
141 
142  void
143  RdChannelRiseTimeCalculator::Pulsefinder(const revt::ChannelTimeSeries& channeltrace,
144  double& peakAmplitude, double& peakTime, double& peakTimeError,
145  const double signalSearchWindowStart, const double signalSearchWindowStop,
146  unsigned int& sample)
147  const
148  {
149  peakAmplitude = 0;
150  unsigned int start = signalSearchWindowStart / channeltrace.GetBinning();
151  unsigned int stop = signalSearchWindowStop / channeltrace.GetBinning();
152  for (unsigned int i = start; i < stop; ++i) {
153  if (channeltrace.At(i) > peakAmplitude) {
154  peakAmplitude = channeltrace.At(i);
155  peakTime = i * channeltrace.GetBinning();
156  sample = i;
157  }
158  }
159  //#warning Error of PeakTime is currently set to bin size
160  peakTimeError = channeltrace.GetBinning(); // Binsize as error, has to be changed later
161  }
162 
163  void
164  RdChannelRiseTimeCalculator::MakeCumulative(const revt::ChannelTimeSeries& channeltrace,
165  const unsigned int startRiseTimeWindow, const unsigned int stopRiseTimeWindow,
166  std::vector<double>& cumulative, double &cumulativeSum)
167  const
168  {
169  for (unsigned int k = startRiseTimeWindow; k < stopRiseTimeWindow + 1; ++k) {
170  cumulativeSum += Sqr(channeltrace.At(k));
171  cumulative.push_back(cumulativeSum);
172  }
173  }
174 
175 
176  void
177  RdChannelRiseTimeCalculator::GetRiseTime(const unsigned int startCumulative, const unsigned int stopCumulative,
178  std::vector<double>& normalizedCumulative, double &riseTime,
179  const double samplingFrequency)
180  const
181  {
182  bool foundmin = false;
183  bool foundmax = false;
184  unsigned int minCumulative = 0;
185  unsigned int maxCumulative = 0;
186  double lowerCumulativeLimit = 0.2;
187  double upperCumulativeLimit = 0.6;
188 
189  for (unsigned int k = startCumulative; k < stopCumulative + 1; ++k) {
190  if (!foundmin) {
191  if (normalizedCumulative.at(k - startCumulative) < lowerCumulativeLimit)
192  continue;
193  else {
194  minCumulative = k;
195  foundmin = true;
196  }
197  }
198  if (!foundmax) {
199  if (normalizedCumulative.at(k - startCumulative) < upperCumulativeLimit)
200  continue;
201  else {
202  maxCumulative = k;
203  foundmax = true;
204  }
205  }
206  if (foundmin && foundmax)
207  break;
208  }
209  riseTime = (maxCumulative - minCumulative) / samplingFrequency;
210  }
211 
212 }
Branch GetTopBranch() const
Definition: Branch.cc:63
void MakeRecData()
Make channel reconstructed data object.
T & At(const SizeType i)
trace entry with checked address
Definition: Trace.h:205
bool IsActive() const
constexpr T Sqr(const T &x)
boost::filter_iterator< CandidateStationFilter, AllStationIterator > CandidateStationIterator
Iterator over all CandidateStations (i.e., HasSignal, HasNoSignal)
Definition: REvent.h:141
boost::indirect_iterator< InternalChannelIterator, Channel & > ChannelIterator
Iterator over station for read/write.
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
void SetParameter(Parameter i, double value, bool lock=true)
double GetBinning() const
size of one slot
Definition: Trace.h:138
ChannelRecData & GetRecData()
Get channel level reconstructed data.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
ChannelIterator ChannelsBegin()
begin Channel iterator for read/write
bool HasREvent() const
bool HasRecData() const
Check whether channel reconstructed data exists.
ChannelTimeSeries & GetChannelTimeSeries()
retrieve Channel Time Series (write access, only use this if you intend to change the data) ...
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
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
Class that holds the data associated to an individual radio channel.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.