RdChannelGalacticBackgroundCalibrator.cc
Go to the documentation of this file.
2 #include <utl/ErrorLogger.h>
3 
4 #include <fwk/CentralConfig.h>
5 
6 #include <evt/Event.h>
7 #include <revt/REvent.h>
8 #include <evt/ShowerRecData.h>
9 #include <evt/ShowerRRecData.h>
10 #include <revt/Header.h>
11 #include <revt/Station.h>
12 #include <revt/Channel.h>
13 #include <revt/StationRecData.h>
14 #include <revt/StationTriggerData.h>
15 #include <revt/StationGPSData.h>
16 
17 #include <rdet/RDetector.h>
18 #include <rdet/Channel.h>
19 
20 #include <utl/Trace.h>
21 #include <utl/TraceAlgorithm.h>
22 #include <utl/ErrorLogger.h>
23 #include <utl/Reader.h>
24 #include <utl/config.h>
25 #include <utl/AugerUnits.h>
26 
27 
28 
29 using namespace std;
30 using namespace utl;
31 using namespace fwk;
32 using namespace revt;
33 using namespace rdet;
34 
35 
37 
40  {
41  INFO("UserModule::Init()");
42 
43  Branch topBranch =
44  CentralConfig::GetInstance()->GetTopBranch("RdChannelGalacticBackgroundCalibrator");
45 
46  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
47  topBranch.GetChild("InputFileName").GetData(fInputFileName);
48  topBranch.GetChild("InterpolateFilterGaps").GetData(fInterpolateFilterGaps);
49  topBranch.GetChild("RejectUncalibratedStations").GetData(fRejectUncalibratedStations);
50 
51  // open input file and fill calibration constants in vectors
52  fstream finput;
53  finput.open(fInputFileName.c_str(), ios::in);
54  if(!finput.good()) {
55  ERROR("Input file could not be opened");
56  return eFailure;
57  }
58  while(finput.good()) {
59  std::vector<double> vTmp;
60  int inputStationId, inputChannel;
61  double inputFrequency, inputConstant;
62  finput >> inputStationId >> inputChannel >> inputFrequency >> inputConstant;
63  v_channelfrequencies[inputStationId][inputChannel-1].push_back(inputFrequency);
64  v_channelconstants[inputStationId][inputChannel-1].push_back(inputConstant);
65  }
66  finput.close();
67 
68  // linearly interpolate filter gaps if option is selected
69  if (fInterpolateFilterGaps) {
70  for (int jj=0; jj<200; jj++) {
71  for (int ichannel=0; ichannel<2; ichannel++) {
72  for (unsigned int ibin=1; ibin<=v_channelconstants[jj][ichannel].size(); ibin++) {
73  if (v_channelconstants[jj][ichannel][ibin] == 0.0 &&
74  v_channelconstants[jj][ichannel][ibin-1] != 0.0) {
75  int j=0;
76  while (v_channelconstants[jj][ichannel][j+ibin] == 0 &&
77  (j+ibin)<v_channelconstants[jj][ichannel].size()-1)
78  j++;
79  if ((j+ibin)!=v_channelconstants[jj][ichannel].size()-1) {
80  double loweredge = v_channelconstants[jj][ichannel][ibin-1];
81  double upperedge = v_channelconstants[jj][ichannel][j+ibin];
82  for (int ifill=1; ifill<=j;ifill++) {
83  v_channelconstants[jj][ichannel][ibin+ifill-1] =
84  loweredge + (upperedge-loweredge)/(j+1) * ifill;
85  }
86  }
87  }
88  }
89  }
90  }
91  }
92 
93  return eSuccess;
94  }
95 
96 
98  RdChannelGalacticBackgroundCalibrator::Run(evt::Event& event)
99  {
100  INFO("RdChannelGalacticBackgroundCalibrator::Run()");
101 
102  REvent& rEvent = event.GetREvent();
103  std::ostringstream info;
104 
105  for (auto& station : rEvent.CandidateStationsRange()) {
106  const int fStationId = station.GetId() - 100;
107 
108  for (auto& channel : station.ChannelsRange()) {
109 
110  if (!channel.IsActive())
111  continue;
112 
113  const int fChannelId = channel.GetId();
114 
115  if(v_channelfrequencies[fStationId][fChannelId-1].size() == 0) {
116  info << "Station ID " << fStationId+100 << " with channel "
117  << fChannelId << " not in calibration list!";
118 
119  if (fRejectUncalibratedStations) {
120  info << " Station rejected!";
121  // probably a new rejection flag should be created for this
122  station.SetRejectedReason(revt::eManuallyRejected);
123  }
124  WARNING(info);
125  continue;
126  }
127 
128  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
129  const rdet::Channel& detChannel = rDetector.GetStation(station.GetId()).GetChannel(channel.GetId());
130  const double lowerDesignFreq = detChannel.GetDesignLowerFreq();
131  const double upperDesignFreq = detChannel.GetDesignUpperFreq();
132 
133  revt::ChannelFrequencySpectrum& spectrum = channel.GetChannelFrequencySpectrum();
134 
135  const int lowerBin = (int)(lowerDesignFreq / spectrum.GetBinning());
136  const int upperBin = (int)(upperDesignFreq / spectrum.GetBinning());
137  const unsigned int nSpecBins = upperBin - lowerBin;
138 
139  const double lowerFreq = channel.GetFrequencyOfBin(lowerBin+1) / MHz;
140  const double upperFreq = channel.GetFrequencyOfBin(upperBin+1) / MHz;
141 
142  const double spectrumBinning = spectrum.GetBinning();
143  const unsigned int spectrumSize = spectrum.GetSize();
144 
145  double currentFreq = 0;
146  double nearestFreqDist = 0;
147  int jjNearestFreq = 0;
148 
149  if (nSpecBins != v_channelfrequencies[fStationId][fChannelId-1].size()) {
150  info << "The calibration constants (" << v_channelfrequencies[fStationId][fChannelId-1].size()
151  << ") of station ID " << fStationId+100 << " with channel " << fChannelId
152  << " do not match the number of spectral bins (" << nSpecBins << ").";
153  WARNING(info);
154  }
155 
156  // loop to DIVIDE spectral elements with calibration factors
157  // the nearest frequency in the calibration constant list is applied
158  for (ChannelFrequencySpectrum::SizeType i = 0; i < spectrumSize; i++) {
159  currentFreq=channel.GetFrequencyOfBin(i) / MHz;
160  if (currentFreq >= lowerFreq && currentFreq < upperFreq) {
161  nearestFreqDist = upperFreq;
162  jjNearestFreq = 0;
163  for (unsigned int jj=0; jj<v_channelfrequencies[fStationId][fChannelId-1].size(); jj++) {
164  if (abs(v_channelfrequencies[fStationId][fChannelId-1][jj] -
165  (currentFreq + 0.5*spectrumBinning/MHz)) < nearestFreqDist) {
166  nearestFreqDist = abs(v_channelfrequencies[fStationId][fChannelId-1][jj] -
167  (currentFreq + 0.5*spectrumBinning/MHz));
168  jjNearestFreq = jj;
169  }
170  }
171  info << fixed << "Station ID " << fStationId + 100 << " Channel "
172  << fChannelId << " has a calibration constant of "
173  << v_channelconstants[fStationId][fChannelId-1][jjNearestFreq]
174  << " applied to frequency " << currentFreq + 0.5*spectrumBinning/MHz
175  << " MHz." << endl;
176  INFODebug(info);
177 
178  if (v_channelconstants[fStationId][fChannelId-1][jjNearestFreq] == 0.0)
179  // set frequency bin to zero if calibration constant is zero (gap)
180  spectrum[i] = 0.0;
181  else
182  spectrum[i] /= v_channelconstants[fStationId][fChannelId-1][jjNearestFreq];
183  }
184  }
185 
186  } // channel loop
187  } // station loop
188  return eSuccess;
189  }
190 
191 
193  RdChannelGalacticBackgroundCalibrator::Finish()
194  {
195  INFO("RdChannelGalacticBackgroundCalibrator::Finish()");
196 
197  return eSuccess;
198  }
199 }
Branch GetTopBranch() const
Definition: Branch.cc:63
double GetDesignUpperFreq() const
Get design value of the freq-band.
constexpr double MHz
Definition: AugerUnits.h:159
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
double GetDesignLowerFreq() const
Get design value of the freq-band.
double GetBinning() const
size of one slot
Definition: Trace.h:138
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
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
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
Class representing a document branch.
Definition: Branch.h:107
std::vector< std::complex< double > >::size_type SizeType
Definition: Trace.h:58
double abs(const SVector< n, T > &v)
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
#define INFODebug(y)
Definition: VModule.h:163
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
#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.