RdChannelAmplitudeTemperatureDependenceCorrector.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/config.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
8 #include <utl/AugerUnits.h>
9 
10 #include <evt/Event.h>
11 #include <revt/REvent.h>
12 #include <revt/Channel.h>
13 #include <revt/ChannelRecData.h>
14 #include <revt/ChannelRRecDataQuantities.h>
15 #include <revt/Station.h>
16 
17 #include <det/Detector.h>
18 #include <rdet/RDetector.h>
19 #include <rdet/Channel.h>
20 
21 
22 using namespace revt;
23 using namespace fwk;
24 using namespace std;
25 using namespace utl;
26 
27 
28 /* RS: for the module to gather CRS temperatures, you should have RMonitoringSQLConfig.xml
29  configured to AERA.sqlite and RSQLConfig.xml to AERA_4_A.sqlite
30 */
31 
33 
36  {
37  // Read in the configurations of the xml file
38  Branch topBranch =
39  CentralConfig::GetInstance()->GetTopBranch("RdChannelAmplitudeTemperatureDependenceCorrector");
40  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
41  topBranch.GetChild("RejectIfCorrectionFailed").GetData(fRejectIfCorrectionFailed);
42 
43  return eSuccess;
44  }
45 
46 
48  RdChannelAmplitudeTemperatureDependenceCorrector::Run(evt::Event& event)
49  {
50  // Check if there are events at all
51  if (!event.HasREvent()) {
52  WARNING("No radio event found!");
53  return eContinueLoop;
54  }
55 
56  ostringstream info;
57  REvent& rEvent = event.GetREvent();
58 
59  const det::Detector& detector = det::Detector::GetInstance();
60  const rdet::RDetector& rDetector = detector.GetRDetector();
61 
62  const double crsTemperature = rDetector.GetTemperature("CRS"); // in Kelvin
63  const bool hasCrsTemp = isnan(crsTemperature);
64  INFODebug("CRS temperature: " + to_string(crsTemperature) + "deg kelvin");
65 
66  // loop through stations and for every station through every channel
67  for (auto& station : rEvent.StationsRange()) {
68  info.str("");
69  info << "Current station id " << station.GetId();
70  INFODebug(info);
71 
72  // reject station if there is no CRS temperature available
73  if (fRejectIfCorrectionFailed && hasCrsTemp) {
74  WARNING("No CRS temperature available. Station will be rejected.\n");
75  station.SetRejectedReason(eNoTemperatureCorrection);
76  continue;
77  }
78 
79  for (auto& channel : station.ChannelsRange()) {
80  if (!channel.IsActive())
81  continue;
82 
83  auto& timeSeries = channel.GetChannelTimeSeries(); //-> Get the Amplitude A
84  const auto& detChannel = rDetector.GetStation(station).GetChannel(channel);
85 
86  // check for ADC type to establish if it is a DE or NL station. Reject for unknown type
87  const auto& adcType = GetAdcType(detChannel.GetADCType());
88  if (adcType == eUndefined) {
89  WARNING("unknown filteramplifier. Station will be rejected, temp correction can't be applied.");
90  station.SetRejectedReason(eNoTemperatureCorrection);
91  continue;
92  }
93 
94  /* reject station if antenna type isn't SmallBlackSpider or Butterfly,
95  because there are no known correction factors for other types */
96  const string AntennaType = detChannel.GetAntennaTypeName();
97  if ((AntennaType.substr(0, string("SmallBlackSpider").length()) != "SmallBlackSpider") &&
98  (AntennaType.substr(0, string("Butterfly").length()) != "Butterfly")) {
99  info.str("");
100  info << "unknown antenna type: " << AntennaType
101  << " Station will be rejected, temp correction can't be applied.";
102  WARNING(info);
103 
104  station.SetRejectedReason(eNoTemperatureCorrection);
105  continue;
106  }
107 
108  info.str("");
109  info << "Antenna type: " << AntennaType << ", ADC type: " << adcType;
110  INFODebug(info);
111 
112  // get station temp depending on adc type
113  double stationTemp = std::nan("1");
114  if (adcType == eDE_Phase1 || adcType == eDE_Phase2) {
115  // stored in the DB in C, converted into Kelvin by Offline
116  stationTemp = station.GetHWTemperatureExt();
117  } else {
118  //stored in C and not transformed during reading by Offline
119  stationTemp = station.GetHWTemperature() + 273.15;
120  }
121 
122  if (fRejectIfCorrectionFailed && isnan(stationTemp)) {
123  WARNING("No station temperature data available. Station will be rejected");
124  station.SetRejectedReason(eNoTemperatureCorrection);
125  continue;
126  }
127 
128  // check if sensor values are reasonable (-50C to 100C), otherwise reject station
129  if(fRejectIfCorrectionFailed && (stationTemp < 223.15 || stationTemp > 373.15)) {
130  WARNING("Incorrect sensor temperature. Station will be rejected");
131  station.SetRejectedReason(eNoTemperatureCorrection);
132  continue;
133  }
134 
135  ostringstream info;
136  info << "Temperatures used for correction of LNA amplitudes: T = " << crsTemperature
137  << "Temperatures for correction of FilterAmplifier amplitudes: T = " << stationTemp
138  << ", Tref= " << fReferenceTemperatur;
139  INFODebug(info);
140 
141  // FA amplitude correction. Filter is inside station electronics box hence use station temp
142  const double FAfactor = GetFilterAmplifierAmplitudeCorrectionFactor(adcType);
143  const double filterAmplifierAmplitudeCorrectionFactor =
144  pow(10, FAfactor * 1e-3 * (fReferenceTemperatur - stationTemp) * 0.05);
145 
146  // LNA Amplitude correction. LNA is outside, hence CRS temp
147  const double LNAfactor = GetLNAAmplitudeCorrectionFactor(detChannel.GetAntennaTypeName());
148  const double LNAAmplitudeCorrectionFactor =
149  pow(10, LNAfactor * 1e-3 * (fReferenceTemperatur - crsTemperature) * 0.05);
150 
151  // save corrections factors in channel parameter storage
152  if (!channel.HasRecData()) {
153  channel.MakeRecData();
154  }
155 
156  channel.GetRecData().SetParameter(eAmplitudeLNATemperatureCorrectionFactor,
157  LNAAmplitudeCorrectionFactor);
158  channel.GetRecData().SetParameter(eAmplitudeFilterAmpTemperatureCorrectionFactor,
159  filterAmplifierAmplitudeCorrectionFactor);
160 
161  // perform correction
162  for (auto& el : timeSeries) {
163  el *= LNAAmplitudeCorrectionFactor * filterAmplifierAmplitudeCorrectionFactor;
164  }
165  }
166  }
167 
168  return eSuccess;
169  }
170 
171 
173  RdChannelAmplitudeTemperatureDependenceCorrector::Finish()
174  {
175  return eSuccess;
176  }
177 
178 
180  RdChannelAmplitudeTemperatureDependenceCorrector::GetAdcType(const std::string adcString)
181  {
182  if (adcString.substr(0, 4) == "AERA") {
183  if (adcString.substr(4, 2) == "DE") {
184  // KIT Filteramplifier Phase 1
185  return eDE_Phase1;
186  } else {
187  // Dutch Filteramplifier phase 1
188  return eNL_Phase1;
189  }
190  }
191 
192  // KIT Filteramplifier Phase 2
193  if (adcString.substr(0, 6) == "ADC_DE") {
194  return eDE_Phase2;
195  }
196 
197  // Dutch Filteramplifier Phase 2
198  if (adcString.substr(0, 6) == "ADC_NL") {
199  return eNL_Phase2;
200  }
201 
202  return eUndefined;
203  }
204 
205 
206  double
207  RdChannelAmplitudeTemperatureDependenceCorrector::GetLNAAmplitudeCorrectionFactor(
208  const string AntennaType)
209  {
210  if (AntennaType.substr(0, string("SmallBlackSpider").length()) == "SmallBlackSpider") {
211  // LNA phase 1
212  return -15;
213  }
214 
215  if (AntennaType.substr(0, string("Butterfly").length()) == "Butterfly") {
216  // Butterfly LNA, -26mdB/K
217  return -26;
218  }
219 
220  WARNING("unknown antenna type, no correction");
221  return 0;
222  }
223 
224 
225  double
226  RdChannelAmplitudeTemperatureDependenceCorrector::GetFilterAmplifierAmplitudeCorrectionFactor(
227  const AdcType adcType)
228  {
229  switch(adcType)
230  {
231  case eDE_Phase1:
232  return -25;
233  case eDE_Phase2:
234  return -8;
235  case eNL_Phase1:
236  return -25;
237  case eNL_Phase2:
238  // probably 0
239  return 0;
240  default:
241  WARNING("unknown filteramplifier, no correction.");
242  return 0;
243  }
244  }
245 
246 }
Branch GetTopBranch() const
Definition: Branch.cc:63
double GetTemperature(const std::string &site) const
Definition: RDetector.cc:250
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
void Init()
Initialise the registry.
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
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
Class representing a document branch.
Definition: Branch.h:107
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
#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
#define INFODebug(y)
Definition: VModule.h:163
const Channel & GetChannel(const int id) const
Get specified Channel by id.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141

, generated on Tue Sep 26 2023.