3 #include <fwk/CentralConfig.h>
6 #include <revt/REvent.h>
7 #include <revt/Station.h>
8 #include <revt/Channel.h>
9 #include <revt/StationGPSData.h>
11 #include <det/Detector.h>
12 #include <rdet/RDetector.h>
13 #include <rdet/Channel.h>
15 #include <utl/ErrorLogger.h>
16 #include <utl/Trace.h>
17 #include <utl/Reader.h>
18 #include <utl/config.h>
19 #include <utl/AugerUnits.h>
35 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RdChannelGalacticCalibrator");
38 topBranch.
GetChild(
"RejectIfCalibrationFailed").
GetData(fRejectIfCalibrationFailed);
40 GetCalibrationConstants();
48 REvent& rEvent =
event.GetREvent();
51 for (
auto& station : rEvent.CandidateStationsRange()) {
53 const int stationId = station.GetId() - 100;
54 const unsigned long gpsSec = station.GetGPSData().GetSecond();
57 GetDataEvent(gpsSec, year, month);
60 info <<
"Run galactic calibration for station " << stationId
61 <<
" in " << month <<
"/" << year <<
".";
64 bool stationRejected =
false;
66 for (
auto& channel : station.ChannelsRange()) {
67 if (!channel.IsActive() || stationRejected)
70 const int channelId = channel.GetId();
71 const auto& rDetector = det::Detector::GetInstance().GetRDetector();
72 const auto& detChannel = rDetector.GetStation(station.GetId()).GetChannel(channel.GetId());
74 auto& spectrum = channel.GetChannelFrequencySpectrum();
75 const double lowerDesignFreq = detChannel.GetDesignLowerFreq();
76 const double upperDesignFreq = detChannel.GetDesignUpperFreq();
77 const int lowerBin = int(lowerDesignFreq / spectrum.GetBinning());
78 const int upperBin = int(upperDesignFreq / spectrum.GetBinning());
79 const double lowerFreq = channel.GetFrequencyOfBin(lowerBin + 1) /
MHz;
80 const double upperFreq = channel.GetFrequencyOfBin(upperBin + 1) /
MHz;
82 bool frequencyFilled[100] = {
false };
84 const int indexMonth = GetMonthIndex(month, year);
87 if (!channel.HasRecData()) {
88 channel.MakeRecData();
92 const double currentFreq = channel.GetFrequencyOfBin(f) /
MHz;
93 if (currentFreq > upperFreq || currentFreq < lowerFreq) {
99 channelMap = fCalibrationConstantChannel1[stationId];
101 if (channelId == 2) {
102 channelMap = fCalibrationConstantChannel2[stationId];
105 const int intFreq = int(currentFreq);
106 const auto it = channelMap.find(make_pair(indexMonth, intFreq));
107 if (it == channelMap.end()) {
109 info <<
"no calibration constant in map for station " << stationId
110 <<
", channel " << channel.GetId() <<
" at a frequency of "
111 << intFreq <<
"MHz.";
113 if (fRejectIfCalibrationFailed) {
114 info <<
" Rejecting station " << stationId <<
".";
121 stationRejected =
true;
131 const double C0 = it->second;
134 if (!frequencyFilled[intFreq]) {
135 const auto par = GetParameterName(intFreq);
136 channel.GetRecData().SetParameter(par, C0);
137 frequencyFilled[intFreq] =
true;
148 RdChannelGalacticCalibrator::Finish()
156 RdChannelGalacticCalibrator::GetDataEvent(
const int gps,
int&
year,
int& month)
158 const time_t utc = gps + 315964819 + 16;
159 const tm*
const t = gmtime(&utc);
160 year = t->tm_year + 1900;
161 month = t->tm_mon + 1;
166 RdChannelGalacticCalibrator::GetCalibrationConstants()
169 obj.open(fNameConstantsFile.c_str());
171 if (!obj.is_open()) {
172 const string error =
"File with calibration constants not found. The trace cannot be corrected.";
178 info <<
"file found : " << fNameConstantsFile;
184 obj >> channel >> year >> month >> antenna >> frequency >> calConstant;
186 const int indexMonth = GetMonthIndex(month, year);
188 fCalibrationConstantChannel1[antenna].insert({{indexMonth, frequency}, calConstant});
191 fCalibrationConstantChannel2[antenna].insert({{indexMonth, frequency}, calConstant});
198 RdChannelGalacticCalibrator::GetMonthIndex(
int month,
int year)
200 return 12 * (year - fInitYear) + month;
204 revt::ChannelRRecDataQuantities
205 RdChannelGalacticCalibrator::GetParameterName(
unsigned int intFreq)
208 return eChannelGalacticCalibrationFactor30MHz;
210 return eChannelGalacticCalibrationFactor31MHz;
212 return eChannelGalacticCalibrationFactor32MHz;
214 return eChannelGalacticCalibrationFactor33MHz;
216 return eChannelGalacticCalibrationFactor34MHz;
218 return eChannelGalacticCalibrationFactor35MHz;
220 return eChannelGalacticCalibrationFactor36MHz;
222 return eChannelGalacticCalibrationFactor37MHz;
224 return eChannelGalacticCalibrationFactor38MHz;
226 return eChannelGalacticCalibrationFactor39MHz;
228 return eChannelGalacticCalibrationFactor40MHz;
230 return eChannelGalacticCalibrationFactor41MHz;
232 return eChannelGalacticCalibrationFactor42MHz;
234 return eChannelGalacticCalibrationFactor43MHz;
236 return eChannelGalacticCalibrationFactor44MHz;
238 return eChannelGalacticCalibrationFactor45MHz;
240 return eChannelGalacticCalibrationFactor46MHz;
242 return eChannelGalacticCalibrationFactor47MHz;
244 return eChannelGalacticCalibrationFactor48MHz;
246 return eChannelGalacticCalibrationFactor49MHz;
248 return eChannelGalacticCalibrationFactor50MHz;
250 return eChannelGalacticCalibrationFactor51MHz;
252 return eChannelGalacticCalibrationFactor52MHz;
254 return eChannelGalacticCalibrationFactor53MHz;
256 return eChannelGalacticCalibrationFactor54MHz;
258 return eChannelGalacticCalibrationFactor55MHz;
260 return eChannelGalacticCalibrationFactor56MHz;
262 return eChannelGalacticCalibrationFactor57MHz;
264 return eChannelGalacticCalibrationFactor58MHz;
266 return eChannelGalacticCalibrationFactor59MHz;
268 return eChannelGalacticCalibrationFactor60MHz;
270 return eChannelGalacticCalibrationFactor61MHz;
272 return eChannelGalacticCalibrationFactor62MHz;
274 return eChannelGalacticCalibrationFactor63MHz;
276 return eChannelGalacticCalibrationFactor64MHz;
278 return eChannelGalacticCalibrationFactor65MHz;
280 return eChannelGalacticCalibrationFactor66MHz;
282 return eChannelGalacticCalibrationFactor67MHz;
284 return eChannelGalacticCalibrationFactor68MHz;
286 return eChannelGalacticCalibrationFactor69MHz;
288 return eChannelGalacticCalibrationFactor70MHz;
290 return eChannelGalacticCalibrationFactor71MHz;
292 return eChannelGalacticCalibrationFactor72MHz;
294 return eChannelGalacticCalibrationFactor73MHz;
296 return eChannelGalacticCalibrationFactor74MHz;
298 return eChannelGalacticCalibrationFactor75MHz;
300 return eChannelGalacticCalibrationFactor76MHz;
302 return eChannelGalacticCalibrationFactor77MHz;
304 return eChannelGalacticCalibrationFactor78MHz;
306 return eChannelGalacticCalibrationFactor79MHz;
308 return eChannelGalacticCalibrationFactor80MHz;
310 throw logic_error(
"no corresponding parameter found");
Branch GetTopBranch() const
Base class for all exceptions used in the auger offline code.
std::map< std::pair< int, int >, double > calibrationMap
Interface class to access to the Radio part of an event.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
#define INFOIntermediate(y)
Class representing a document branch.
std::vector< std::complex< double > >::size_type SizeType
void GetData(bool &b) const
Overloads of the GetData member template function.
ResultFlag
Flag returned by module methods to the RunController.
#define ERROR(message)
Macro for logging error messages.