RdChannelADCToVoltageConverter.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/VModule.h>
5 
6 #include <utl/config.h>
7 #include <utl/AugerUnits.h>
8 #include <utl/ErrorLogger.h>
9 #include <utl/Reader.h>
10 #include <utl/TraceAlgorithm.h>
11 
12 #include <evt/Event.h>
13 #include <revt/REvent.h>
14 #include <revt/Station.h>
15 #include <revt/Channel.h>
16 
17 #include <rdet/RDetector.h>
18 #include <rdet/Station.h>
19 #include <rdet/Channel.h>
20 
21 #include <string>
22 
23 using namespace revt;
24 using namespace fwk;
25 using namespace utl;
26 using std::ostringstream;
27 
28 
30 
31 
34  {
35  Branch topBranch =
36  CentralConfig::GetInstance()->GetTopBranch("RdChannelADCToVoltageConverter");
37  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
38 
39  fFailOnWrongADCFrequency =
40  topBranch.GetChild("FailOnWrongADCFrequency").Get<std::string>() == "yes";
41 
42  return eSuccess;
43  }
44 
45 
47  RdChannelADCToVoltageConverter::Run(evt::Event& event)
48  {
49  // Check if there are events at all
50  if (!event.HasREvent()) {
51  WARNING("No radio event found!");
52  return eContinueLoop;
53  }
54 
55  det::Detector& detector = det::Detector::GetInstance();
56 
57  REvent& rEvent = event.GetREvent();
58 
59  // loop through stations and for every station through every channel
60  for (auto& station : rEvent.StationsRange()) {
61  for (auto& channel : station.ChannelsRange()) {
62 
63  if (!channel.IsActive())
64  continue;
65 
66  const rdet::Channel& channelDet =
67  detector.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
68  const revt::ChannelADCTimeSeries& adcTrace = channel.GetChannelADCTimeSeries();
69 
70  // get channel information from detector
71  const double bitDepth = channelDet.GetBitDepth();
72  const double samplingFrequency = channelDet.GetSamplingFrequency();
73  const double minVoltage = channelDet.GetMinVoltage();
74  const double maxVoltage = channelDet.GetMaxVoltage();
75  const double voltagePerCount = (maxVoltage - minVoltage) / pow(2, bitDepth);
76  const double traceBinning = adcTrace.GetBinning();
77  const double traceMax = TraceAlgorithm::Max(adcTrace, 0, adcTrace.GetSize() - 1);
78  const double traceMin = TraceAlgorithm::Min(adcTrace, 0, adcTrace.GetSize() - 1);
79 
80  if (!CloseTo(1.0 / traceBinning, samplingFrequency, 1e-6)) {
81  ostringstream info;
82  info << "ADC Sampling Frequency of station " << station.GetId()
83  << ", Channel " << channel.GetId()
84  << " according to detector config is "
85  << samplingFrequency / (mega * hertz)
86  << " MHz and does not match sampling frequency of data, which is "
87  << 1.0 / traceBinning / (mega * hertz) << " MHz.";
88 
89  if (fFailOnWrongADCFrequency) {
90  info << "Aborting.";
91  ERROR(info);
92  return eFailure;
93  } else {
94  info << "Excluding station.";
95  ERROR(info);
96  station.SetExcludedReason(revt::eHardwareMismatch);
97  continue;
98  }
99  }
100 
101  // illegal entries
102  if ((traceMin < minVoltage / voltagePerCount) || (traceMax > maxVoltage / voltagePerCount - 1)) {
103  ostringstream info;
104  info << "ADC trace of Channel " << channel.GetId()
105  << ", Station " << station.GetId() << " has illegal entries.\n"
106  << "Allowed trace minimum is: " << minVoltage / voltagePerCount
107  << " and current trace minimum: " << traceMin << ".\n"
108  << "Allowed trace maximum is: " << maxVoltage / voltagePerCount - 1
109  << " and current trace maximum: " << traceMax <<".\nAborting ...";
110  ERROR(info);
111 
112  // let the pipeline fail. This should not be happening and thus not glossed over
113  return eFailure;
114  }
115 
116  // saturations
117  if ((traceMin == minVoltage / voltagePerCount) || (traceMax == minVoltage / voltagePerCount - 1)) {
118  ostringstream info;
119  info << "ADC trace of Channel " << channel.GetId()
120  << ", Station " << station.GetId() << " has saturated samples!";
121  INFOIntermediate(info);
122 
123  channel.SetSaturated();
124  fNumberOfSaturatedChannels++;
125  }
126 
127  // do the conversion from ADC counts to voltage
128  revt::ChannelTimeSeries& trace = channel.GetChannelTimeSeries();
129  trace.Clear();
130  trace.SetBinning(adcTrace.GetBinning());
131  trace = minVoltage + adcTrace * voltagePerCount;
132 
133  if(fInfoLevel >= eInfoDebug) {
134  ostringstream info;
135  info << "Station " << station.GetId() << " Channel " << channel.GetId()
136  << " has minVoltage = " << minVoltage << " and voltageperCount = "
137  << voltagePerCount;
138  INFO(info);
139  }
140  }
141  }
142 
143  return eSuccess;
144  }
145 
146 
148  RdChannelADCToVoltageConverter::Finish()
149  {
150  ostringstream info;
151  info << "There were " << fNumberOfSaturatedChannels << " saturated channels!";
152  INFO(info);
153 
154  return eSuccess;
155  }
156 
157 
158  bool
159  RdChannelADCToVoltageConverter::CloseTo(const double a, const double b, const double tolerance)
160  {
161  return fabs(a - b) < tolerance;
162  }
163 
164 }
int GetBitDepth() const
Get number of bits of ADC.
Branch GetTopBranch() const
Definition: Branch.cc:63
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
double GetMaxVoltage() const
Get voltage corresponding to max number of counts.
void Init()
Initialise the registry.
Detector description interface for Channel-related data.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double pow(const double x, const unsigned int i)
bool HasREvent() const
T Get() const
Definition: Branch.h:271
#define INFOIntermediate(y)
Definition: VModule.h:162
Class representing a document branch.
Definition: Branch.h:107
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
SizeType GetSize() const
Definition: Trace.h:156
#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
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?)
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
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.