RdStationTimingCalibrator.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <utl/ReadStream.h>
5 #include <utl/AugerUnits.h>
6 
7 #include <evt/Event.h>
8 #include <revt/REvent.h>
9 #include <revt/StationRecData.h>
10 
11 #include <rdet/RDetector.h>
12 #include <rdet/Channel.h>
13 
14 #include <string>
15 #include <vector>
16 
17 
18 using namespace evt;
19 using namespace revt;
20 using namespace std;
21 using namespace utl;
22 using namespace fwk;
23 
24 
25 namespace RdStationTimingCalibratorOG {
26 
27 
28  struct OffsetEntry {
29  unsigned int stationId;
30  double offset;
31  double uncertainty;
32  };
33 
34 
35  inline
36  istream&
37  operator>>(istream& is, OffsetEntry& entry)
38  {
39  return is >> entry.stationId >> ws >> entry.offset >> ws >> entry.uncertainty;
40  }
41 
42 
45  {
46  // trigger detector update to read standard station positions
47  Branch topB = CentralConfig::GetInstance()->GetTopBranch("RdStationTimingCalibrator");
48 
49  topB.GetChild("TimingOffset_Butterfly_DE").GetData(fTimingOffset_Butterfly_DE);
50  topB.GetChild("TimingOffset_Butterfly_NL").GetData(fTimingOffset_Butterfly_NL);
51  topB.GetChild("TimingOffset_LPDA_DE").GetData(fTimingOffset_LPDA_DE);
52  topB.GetChild("TimingOffset_LPDA_NL").GetData(fTimingOffset_LPDA_NL);
53  topB.GetChild("TimingOffset_RD").GetData(fTimingOffset_RD);
54 
55  topB.GetChild("TimingUncertainty_Butterfly_DE").GetData(fTimingUncertainty_Butterfly_DE);
56  topB.GetChild("TimingUncertainty_Butterfly_NL").GetData(fTimingUncertainty_Butterfly_NL);
57  topB.GetChild("TimingUncertainty_LPDA_DE").GetData(fTimingUncertainty_LPDA_DE);
58  topB.GetChild("TimingUncertainty_LPDA_NL").GetData(fTimingUncertainty_LPDA_NL);
59  topB.GetChild("TimingUncertainty_RD").GetData(fTimingUncertainty_RD);
60 
61  const string rdStationTimeOffsetsFile =
62  topB.GetChild("RdStationTimeOffsetsFile").Get<string>();
63 
64  ifstream posFile(rdStationTimeOffsetsFile.c_str());
65  if (!posFile.is_open()) {
66  ostringstream err;
67  err << "Cannot open time offsets file '" << rdStationTimeOffsetsFile << "'!";
68  ERROR(err);
69  return eFailure;
70  }
71 
72  vector<OffsetEntry> offsets;
73  ReadStream(posFile).GetLines(offsets);
74 
75  fOffsets.clear();
76 
77  for (const auto& entry : offsets) {
78  const unsigned int sId = entry.stationId;
79 
80  try {
81  // check for double entries in GPS positions correction file
82  if (fOffsets.find(sId) != fOffsets.end()) {
83  ostringstream err;
84  err << "Duplicate entry for station id " << sId << " found in the offsets file!";
85  ERROR(err);
86  return eFailure;
87  }
88 
89  // store offset
90  fOffsets.emplace(entry.stationId, make_pair(entry.offset * ns, entry.uncertainty * ns));
91 
93  ostringstream warn;
94  warn << "Station id " << sId << " has a time offset in the corrections file but is not found in the RDetector!";
95  WARNING(warn);
96  }
97  }
98 
99  return eSuccess;
100  }
101 
102 
104  RdStationTimingCalibrator::Run(Event& event)
105  {
106  if (!event.HasREvent())
107  return eSuccess;
108 
109  REvent& rEvent = event.GetREvent();
110 
111  for (auto& station : rEvent.StationsRange()) {
112 
113  if (!station.HasRecData())
114  continue;
115 
116  StationRecData& recData = station.GetRecData();
117 
118  if (!recData.HasParameter(eTraceStartTime)) {
119  ostringstream err;
120  err << "Trying to correct trace start time for " <<
121  "station id " << station.GetId() << ", but no trace start time available in ParameterStorage!";
122  ERROR(err);
123  return eFailure;
124  }
125 
126  const TimeInterval oldTime = recData.GetParameter(eTraceStartTime);
127  const auto& offsetIt = fOffsets.find(station.GetId()); // search for correction value for individual station
128 
129  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
130  const rdet::Channel& detChannel = rDetector.GetStation(station.GetId()).GetChannel(1);
131  const string antennaTypeName = detChannel.GetAntennaTypeName();
132  const int bitDepth = detChannel.GetBitDepth();
133 
134  double stationOffset = 0;
135  double stationUncertainty = 0;
136 
137  if (offsetIt == fOffsets.end()) { // no correction value found for station. use hardware default.
138  if (antennaTypeName.find("Butterfly") != string::npos && bitDepth == 12){
139  stationOffset = fTimingOffset_Butterfly_DE;
140  stationUncertainty = fTimingUncertainty_Butterfly_DE;
141  } else if (antennaTypeName.find("Butterfly") != string::npos && bitDepth == 14){
142  stationOffset = fTimingOffset_Butterfly_NL;
143  stationUncertainty = fTimingUncertainty_Butterfly_NL;
144  } else if (antennaTypeName.find("SmallBlackSpider") != string::npos && bitDepth == 12){
145  stationOffset = fTimingOffset_LPDA_DE;
146  stationUncertainty = fTimingUncertainty_LPDA_DE;
147  } else if (antennaTypeName.find("SmallBlackSpider") != string::npos && bitDepth == 14){
148  stationOffset = fTimingOffset_LPDA_NL;
149  stationUncertainty = fTimingUncertainty_LPDA_NL;
150  } else if (station.GetId() > rDetector.GetRdSdStationIdLink()) {
151  stationOffset = fTimingOffset_RD;
152  stationUncertainty = fTimingUncertainty_RD;
153  } else {
154  // only release warining if station is candiate, i.e. if not rejected nor excluded
155  if (station.IsCandidate()) {
156  // if also not in hardware lists there is no defined correction value available.
157  // no offset will be applied and a warning is trown.
158  ostringstream warning;
159  warning << "No correction value found for station id=" << station.GetId()
160  << " and no correction value found for hardware type (" << antennaTypeName << "," << bitDepth << " bits)"
161  << ". This might cause inconsistent analysis results!";
162  WARNING(warning);
163  }
164  continue;
165  }
166  } else {
167  stationOffset = offsetIt->second.first;
168  stationUncertainty = offsetIt->second.second;
169  }
170 
171  const TimeInterval& offset = stationOffset;
172 
173  // set corrected start time, keep parameter open
174  recData.SetParameter(eTraceStartTime, oldTime + offset, false);
175 
176  // store value that has been added to the trace start time
177  recData.SetParameter(eTraceStartTimeCorrectionByTimeCalibration, offset);
178 
179  if (recData.HasParameterError(eTraceStartTime)) {
180  /* If an uncertainty has already been set by the RdChannelBeaconTimingCalibrator (runs before this module).
181  Keep the uncertainty, not override. Only set (default) uncertainty if not set yet. No other module
182  (than RdChannelBeaconTimingCalibrator) should set it. Once the ModuleSequence is adjusted such that the this module
183  can run before the RdChannelBeaconTimingCalibrator. This comment can be deleted and the ERROR below can be activated. */
184 
185  //ERROR("revt::StationRecData has already ParameterError for eTraceStartTime but it should not. Check whats going on.");
186  } else {
187  recData.SetParameterError(eTraceStartTime, stationUncertainty, false); // keep parameter open
188  }
189 
190  // also change relative position of signal search window accordingly
191  recData.SetParameter(eSignalSearchWindowStart, recData.GetParameter(eSignalSearchWindowStart) - offset, false);
192  recData.SetParameter(eSignalSearchWindowStop, recData.GetParameter(eSignalSearchWindowStop) - offset, false);
193  }
194 
195  return eSuccess;
196  }
197 
198 
200  RdStationTimingCalibrator::Finish()
201  {
202  return eSuccess;
203  }
204 
205 }
206 
int GetBitDepth() const
Get number of bits of ADC.
void operator>>(const Event &theEvent, IoSdEvent &rawSEvent)
Branch GetTopBranch() const
Definition: Branch.cc:63
Class to access station level reconstructed data.
void SetParameterError(Parameter i, double value, bool lock=true)
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
bool is(const double a, const double b)
Definition: testlib.cc:113
bool HasParameterError(const Parameter i1) const
void Init()
Initialise the registry.
Base class for exceptions trying to access non-existing components.
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
bool HasREvent() const
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
T Get() const
Definition: Branch.h:271
Class representing a document branch.
Definition: Branch.h:107
int GetRdSdStationIdLink() const
Get Rd - Sd Station Id link.
Definition: RDetector.h:127
const double ns
#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
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
bool HasParameter(const Parameter i) const
const std::string & GetAntennaTypeName() const
Get description of Antenna-Type.
void SetParameter(Parameter i, double value, bool lock=true)
void GetLines(std::vector< T > &v, const bool filterComments=true, const bool trim=false)
Definition: ReadStream.h:101
#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

, generated on Tue Sep 26 2023.