RdChannelBeaconSuppressor.cc
Go to the documentation of this file.
1 
10 
11 #include <set>
12 
13 #include <fwk/CentralConfig.h>
14 
15 #include <utl/ErrorLogger.h>
16 #include <utl/Reader.h>
17 #include <utl/config.h>
18 #include <utl/TimeStamp.h>
19 #include <utl/UTCDateTime.h>
20 
21 #include <evt/Event.h>
22 #include <revt/REvent.h>
23 #include <revt/Station.h>
24 #include <revt/Channel.h>
25 
26 #include <det/Detector.h>
27 #include <rdet/RDetector.h>
28 #include <rdet/Station.h>
29 #include <rdet/Channel.h>
30 
31 
32 
33 using namespace fwk;
34 using namespace utl;
35 using namespace std;
36 using namespace revt;
37 
39 
42  {
43  INFO("RdChannelBeaconSuppressor::Init()");
44 
45  // Read in the configurations of the xml file
46  const Branch topBranch =
47  CentralConfig::GetInstance()->GetTopBranch("RdChannelBeaconSuppressor");
48  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
49 
50  topBranch.GetChild("Frequencies").GetData(fXMLFrequencies);
51  topBranch.GetChild("GetBeaconFrequenciesFromDatabase").GetData(fGetBeaconFrequenciesFromDatabase);
52  topBranch.GetChild("SurpressionFactor").GetData(fSurpressionFactor);
53  topBranch.GetChild("NeighbouringBinsToBeSurpressed").GetData(fNeighbouringBinsToBeSurpressed);
54  topBranch.GetChild("NeighbouringBandwidthToBeSurpressed").GetData(fNeighbouringBandwidthToBeSurpressed);
55  topBranch.GetChild("CompensateTotalSpectrumPower").GetData(fCompensateTotalSpectrumPower);
56  return eSuccess;
57  }
58 
59 
61  RdChannelBeaconSuppressor::Run(evt::Event& event)
62  {
63  // Check if there are events at all
64  if(!event.HasREvent()) {
65  INFOFinal("No radio event found!");
66  return eContinueLoop;
67  }
68 
69  REvent& rEvent = event.GetREvent();
70 
71  // copy frequencies provided in the XML file to a local vector
72  std::vector<double> frequencies = fXMLFrequencies;
73 
74  // add beacon frequencies of database to those specified in the xml file
75  if (fGetBeaconFrequenciesFromDatabase) {
76  det::Detector& detector = det::Detector::GetInstance();
77  const rdet::RDetector& RDetector = detector.GetRDetector();
78  vector<double> BeaconFrequencies = RDetector.GetBeaconFrequencies();
79  for (auto it = BeaconFrequencies.begin(); it != BeaconFrequencies.end(); ++it)
80  frequencies.push_back(*it);
81  }
82 
83  // loop through stations and for every station through every channel
84  for (auto sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
85  Station& station = *sIt;
86 
88  std::set<int> frequencyBins;
89 
90  for (auto cIt = station.ChannelsBegin(); cIt != station.ChannelsEnd(); ++cIt) {
91  Channel& channel = *cIt;
92  if (!channel.IsActive())
93  continue;
94  stringstream message;
95  message << "Suppressing sine waves of channel " << channel.GetId()
96  << " of station " << channel.GetStationId() << ".";
97  INFOIntermediate(message.str());
98 
99  auto& spectrum = channel.GetChannelFrequencySpectrum();
100 
101  //fixme TH: the following should be refactored to use FFTDataContainer::GetBinOfFrequency() method
102 
103  // loop through frequencies and find corresponding frequency bin in the spectrum
104  for (unsigned int freqN=0; freqN < frequencies.size(); ++freqN) {
105  // check if frequency is inside the range (take care that the order of the spectrum is unknown)
106  if( (frequencies[freqN] <
107  min(channel.GetFrequencyOfBin(0),channel.GetFrequencyOfBin(spectrum.GetSize()-1)))
108  || (frequencies[freqN] >
109  max(channel.GetFrequencyOfBin(0),channel.GetFrequencyOfBin(spectrum.GetSize()-1))) ) {
110  ERROR("Frequency must be inside of the spectrum!");
111  return eFailure;
112  }
113 
114  // find nearest frequency bin:
115  double bin = (frequencies[freqN]-channel.GetFrequencyOfBin(0)) * (spectrum.GetSize()-1)
116  / (channel.GetFrequencyOfBin(spectrum.GetSize()-1) - channel.GetFrequencyOfBin(0));
117 
118  unsigned int intBin = round(bin);
119 
120  // consistency check, whether bin is approximately integer
121  if (abs( double(intBin)/bin -1.) > 1e-3) {
122  double nearestIntFreq = channel.GetFrequencyOfBin(intBin);
123  stringstream message;
124  message << "Frequency does not correspond to approxemately integer bin of spectrum! The nearest integer frequency is "
125  << nearestIntFreq / MHz << " MHz (bin #" << intBin << ")" ;
126  INFODebug(message.str());
127  }
128 
129  // store frequencies of the closest spectrum bin
130  frequencyBins.insert(intBin);
131 
132  // also surpress surounding bins if specified:
133  // calculate number of bins from bandwidth if specified
134  if (fNeighbouringBandwidthToBeSurpressed > 0)
135  fNeighbouringBinsToBeSurpressed = round(fNeighbouringBandwidthToBeSurpressed/spectrum.GetBinning());
136 
137  // add neighbouring bins, but do not allow for bins outside of the spectrum
138  for (unsigned int i = 1; i <= fNeighbouringBinsToBeSurpressed; ++i) {
139  if ( intBin >= i)
140  frequencyBins.insert(intBin-i);
141  if ( (intBin+i) < spectrum.GetSize())
142  frequencyBins.insert(intBin+i);
143  }
144  }
145 
146  // count how many bins are in the design bandwidth (for later compensation of surpression)
147  unsigned int numberOfbinsInDesignBandwidth = 0;
148  double lowerDesignFreq = 0;
149  double upperDesignFreq = 0;
150  // for performance: only fill values, when compensation will be done later
151  if (fCompensateTotalSpectrumPower) {
152  det::Detector& detector = det::Detector::GetInstance();
153  const rdet::Channel& detChannel
154  = detector.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
155  lowerDesignFreq = detChannel.GetDesignLowerFreq();
156  upperDesignFreq = detChannel.GetDesignUpperFreq(); }
157 
158  for (auto it = frequencyBins.begin(); it != frequencyBins.end(); ++it) {
159  message.str("");
160  message << "Suppressing spectral bin " << *it << " corresponding to frequency "
161  << channel.GetFrequencyOfBin(*it)/megahertz << " MHz.";
162  INFODebug(message.str());
163 
164  spectrum[*it] *= fSurpressionFactor; // surpress spectral bin
165  if (fCompensateTotalSpectrumPower)
166  if( (channel.GetFrequencyOfBin(*it) >= lowerDesignFreq) && (channel.GetFrequencyOfBin(*it) <= upperDesignFreq) )
167  ++numberOfbinsInDesignBandwidth;
168  }
169 
170  // calculate compensation: the power of a possible signal in the design bandwidth should be preserved
171  // For this, a flat frequency spectrum of the signal is assumend, which corresponds to a first order correction
172  // the correction compensates for the fraction of surpressed bins within the design bandwidth
173  if (fCompensateTotalSpectrumPower) {
174  // get maximum frequency of spectrum (depending on Nyquist zone could be the first or last bin of the spectrum)
175  double maxFrequency = 0;
176  if (maxFrequency<channel.GetFrequencyOfBin(0))
177  maxFrequency = channel.GetFrequencyOfBin(0);
178  if (maxFrequency<channel.GetFrequencyOfBin(spectrum.GetSize()-1))
179  maxFrequency = channel.GetFrequencyOfBin(spectrum.GetSize()-1);
180 
181  const double relativeBandWidth = (upperDesignFreq-lowerDesignFreq)/maxFrequency;
182  // total power should be constant, but compensation is applied on amplitude spectrum
183  double compensationFactor = sqrt(1.+double(numberOfbinsInDesignBandwidth)/double(spectrum.GetSize())/relativeBandWidth);
184 
185  message.str("");
186  message << "Multiplying each bin in the spectrum by " << compensationFactor
187  << " such that the total signal power within the design bandwidth is preserved.";
188  INFOIntermediate(message.str());
189 
190  // apply compensation factor
191  for (ChannelFrequencySpectrum::SizeType i = 0; i < spectrum.GetSize(); ++i)
192  spectrum[i]*=compensationFactor;
193  }
194  }
195  }
196 
197  return eSuccess;
198  }
199 
200 
202  RdChannelBeaconSuppressor::Finish()
203  {
204  INFOFinal("RdChannelBeaconSuppressor::Finish()");
205 
206  return eSuccess;
207  }
208 
209 }
bool IsActive() const
int GetId() const
Return Id of the Channel.
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.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
StationIterator StationsEnd()
Definition: REvent.h:130
StationIterator StationsBegin()
Definition: REvent.h:128
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
ChannelIterator ChannelsBegin()
begin Channel iterator for read/write
bool HasREvent() const
int GetStationId() const
Return Id of the station to which this Channel belongs.
const std::vector< double > & GetBeaconFrequencies() const
Get vector of Beacon Frequencies for given detector-time from Manager.
Definition: RDetector.cc:183
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
#define INFOIntermediate(y)
Definition: VModule.h:162
#define max(a, b)
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
std::vector< std::complex< double > >::size_type SizeType
Definition: Trace.h:58
double abs(const SVector< n, T > &v)
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
constexpr double megahertz
Definition: AugerUnits.h:155
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
int GetId() const
Get the station Id.
#define INFODebug(y)
Definition: VModule.h:163
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
ChannelFrequencySpectrum & GetChannelFrequencySpectrum()
retrieve Channel Frequency Spectrum (write access, only use this if you intend to change the data) ...
double GetFrequencyOfBin(const ChannelFrequencySpectrum::SizeType bin) const
Get the frequency corresponding to a bin of the frequency spectrum.
Class that holds the data associated to an individual radio channel.
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
#define INFOFinal(y)
Definition: VModule.h:161
#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
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.