2 #include <utl/ErrorLogger.h>
4 #include <fwk/CentralConfig.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>
17 #include <rdet/RDetector.h>
18 #include <rdet/Channel.h>
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>
41 INFO(
"UserModule::Init()");
44 CentralConfig::GetInstance()->
GetTopBranch(
"RdChannelGalacticBackgroundCalibrator");
48 topBranch.
GetChild(
"InterpolateFilterGaps").
GetData(fInterpolateFilterGaps);
49 topBranch.
GetChild(
"RejectUncalibratedStations").
GetData(fRejectUncalibratedStations);
53 finput.open(fInputFileName.c_str(), ios::in);
55 ERROR(
"Input file could not be opened");
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);
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) {
76 while (v_channelconstants[jj][ichannel][j+ibin] == 0 &&
77 (j+ibin)<v_channelconstants[jj][ichannel].size()-1)
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;
98 RdChannelGalacticBackgroundCalibrator::Run(
evt::Event& event)
100 INFO(
"RdChannelGalacticBackgroundCalibrator::Run()");
102 REvent& rEvent =
event.GetREvent();
103 std::ostringstream info;
105 for (
auto& station : rEvent.CandidateStationsRange()) {
106 const int fStationId = station.GetId() - 100;
108 for (
auto& channel : station.ChannelsRange()) {
110 if (!channel.IsActive())
113 const int fChannelId = channel.GetId();
115 if(v_channelfrequencies[fStationId][fChannelId-1].size() == 0) {
116 info <<
"Station ID " << fStationId+100 <<
" with channel "
117 << fChannelId <<
" not in calibration list!";
119 if (fRejectUncalibratedStations) {
120 info <<
" Station rejected!";
128 const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
135 const int lowerBin = (int)(lowerDesignFreq / spectrum.
GetBinning());
136 const int upperBin = (int)(upperDesignFreq / spectrum.
GetBinning());
137 const unsigned int nSpecBins = upperBin - lowerBin;
139 const double lowerFreq = channel.GetFrequencyOfBin(lowerBin+1) /
MHz;
140 const double upperFreq = channel.GetFrequencyOfBin(upperBin+1) /
MHz;
142 const double spectrumBinning = spectrum.
GetBinning();
143 const unsigned int spectrumSize = spectrum.
GetSize();
145 double currentFreq = 0;
146 double nearestFreqDist = 0;
147 int jjNearestFreq = 0;
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 <<
").";
159 currentFreq=channel.GetFrequencyOfBin(i) /
MHz;
160 if (currentFreq >= lowerFreq && currentFreq < upperFreq) {
161 nearestFreqDist = upperFreq;
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));
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
178 if (v_channelconstants[fStationId][fChannelId-1][jjNearestFreq] == 0.0)
182 spectrum[i] /= v_channelconstants[fStationId][fChannelId-1][jjNearestFreq];
193 RdChannelGalacticBackgroundCalibrator::Finish()
195 INFO(
"RdChannelGalacticBackgroundCalibrator::Finish()");
Branch GetTopBranch() const
double GetDesignUpperFreq() const
Get design value of the freq-band.
Interface class to access to the Radio part of an event.
double GetDesignLowerFreq() const
Get design value of the freq-band.
double GetBinning() const
size of one slot
#define INFO(message)
Macro for logging informational messages.
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.
Detector description interface for RDetector-related data.
Class representing a document branch.
std::vector< std::complex< double > >::size_type SizeType
double abs(const SVector< n, T > &v)
#define WARNING(message)
Macro for logging warning messages.
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.
const Station & GetStation(const int stationId) const
Get station by Station Id.