RdChannelVoltageToADCConverter.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/config.h>
6 #include <utl/AugerUnits.h>
7 #include <utl/ErrorLogger.h>
8 #include <utl/Reader.h>
9 
10 #include <evt/Event.h>
11 #include <revt/REvent.h>
12 #include <revt/Station.h>
13 #include <revt/Channel.h>
14 
15 #include <rdet/RDetector.h>
16 #include <rdet/Station.h>
17 #include <rdet/Channel.h>
18 
19 
20 using namespace revt;
21 using namespace fwk;
22 using namespace utl;
23 
24 
26 
29  {
30  return eSuccess;
31  }
32 
33 
35  RdChannelVoltageToADCConverter::Run(evt::Event& event)
36  {
37  // Check if there are events at all
38  if(!event.HasREvent()) {
39  WARNING("No radio event found!");
40  return eContinueLoop;
41  }
42 
43  const det::Detector& detector = det::Detector::GetInstance();
44  REvent& rEvent = event.GetREvent();
45 
46  // loop through stations and for every station through every channel
47  for (auto& station : rEvent.StationsRange()) {
48  for (auto& channel : station.ChannelsRange()) {
49 
50  const rdet::Channel& channelDet =
51  detector.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
52 
53  // get channel information from detector
54  const double bitDepth = channelDet.GetBitDepth();
55  const double samplingFrequency = channelDet.GetSamplingFrequency();
56  const double minVoltage = channelDet.GetMinVoltage();
57  const double maxVoltage = channelDet.GetMaxVoltage();
58  const double voltagePerCount = (maxVoltage - minVoltage) / pow(2, bitDepth);
59 
60  // assume that the pedestal of the ADC corresponds to the middle of its voltage range
61  const double voltagePedestal = 0.5 * (minVoltage + maxVoltage);
62 
63  const ChannelTimeSeries& trace = channel.GetChannelTimeSeries();
64  const double traceBinning = trace.GetBinning();
65 
66  if (!CloseTo(1.0 / traceBinning, samplingFrequency, 1e-5)) {
67  std::ostringstream warning;
68  warning << "\n\tVoltage Sampling Frequency of "
69  << samplingFrequency / (mega * hertz)
70  << " MHz does not match sampling frequency of data, which is "
71  << 1.0 / traceBinning / (mega * hertz)
72  << " MHz. Aborting ...";
73  WARNING(warning);
74  return eFailure;
75  }
76 
77  // do the conversion for the full trace, this implies that the simulated data have no DC offset,
78  // which is fulfilled if the detector response has been applied already
79  ChannelADCTimeSeries& adcTrace = channel.GetChannelADCTimeSeries();
80  adcTrace.Clear();
81  adcTrace.SetBinning(traceBinning);
82 
83  for (const auto& entry : trace) {
84  int adcCount = floor((entry + voltagePedestal - minVoltage) / voltagePerCount);
85  adcCount += int(minVoltage / voltagePerCount);
86 
87  // check for under- and overflows of the ADC
88  if (adcCount < (minVoltage / voltagePerCount))
89  adcCount = minVoltage / voltagePerCount;
90 
91  if (adcCount > maxVoltage / voltagePerCount -1)
92  adcCount = maxVoltage / voltagePerCount - 1;
93 
94  // add count to trace
95  adcTrace.PushBack(adcCount);
96  }
97  }
98  }
99 
100  return eSuccess;
101  }
102 
103 
105  RdChannelVoltageToADCConverter::Finish()
106  {
107  return eSuccess;
108  }
109 
110 
111  bool
112  RdChannelVoltageToADCConverter::CloseTo(const double a, const double b, const double tolerance)
113  {
114  return fabs(a - b) < tolerance;
115  }
116 
117 
118 }
int GetBitDepth() const
Get number of bits of ADC.
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
double GetMaxVoltage() const
Get voltage corresponding to max number of counts.
void Init()
Initialise the registry.
Detector description interface for Channel-related data.
double pow(const double x, const unsigned int i)
bool HasREvent() const
double GetMinVoltage() const
Get voltage corresponding to 0 counts.
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
void Clear()
Definition: Trace.h:158
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
constexpr double hertz
Definition: AugerUnits.h:153
void SetBinning(const double binning)
Definition: Trace.h:139
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
double GetSamplingFrequency() const
Get sampling Frequency of ADC (unit?)
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
constexpr double mega
Definition: AugerUnits.h:72
Predicate for approximate equality (for floating point)
Definition: Test.h:91

, generated on Tue Sep 26 2023.