RdChannelNoiseGenerator.cc
Go to the documentation of this file.
2 #include <iostream>
3 #include <cmath>
4 
5 #include <fwk/CentralConfig.h>
6 #include <fwk/RandomEngineRegistry.h>
7 
8 #include <utl/config.h>
9 #include <utl/ErrorLogger.h>
10 #include <utl/Noise.h>
11 #include <utl/NoiseWhite.h>
12 #include <utl/NoiseSaS.h>
13 #include <utl/NoiseCCIR670.h>
14 #include <utl/RandomEngine.h>
15 #include <utl/Reader.h>
16 #include <utl/StringCompare.h>
17 #include <utl/TraceAlgorithm.h>
18 
19 #include <evt/Event.h>
20 #include <rdet/RDetector.h>
21 #include <rdet/Channel.h>
22 #include <revt/Channel.h>
23 #include <revt/Station.h>
24 #include <revt/REvent.h>
25 
26 #include <boost/random.hpp>
27 #include <boost/random/exponential_distribution.hpp>
28 #include <boost/random/uniform_real.hpp>
29 
30 using namespace utl;
31 using namespace fwk;
32 
33 
34 
36 
38  fInfoLevel(0),
39  fSaSSigmaOverride(0.),
40  fSaSAlphaOverride(0.),
41  fNoiseRMS(-1),
42  randgen(time(nullptr)),
43  interval_noise(4.75*micro*volt, 7.28*micro*volt),
44  interval_h(0, 1),
45  randomGenerator_sigma(randgen, interval_noise),
46  randomGenerator_h(randgen, interval_h)
47  { }
48 
49 
52  {
53  INFO("RdChannelNoiseGenerator::Init()");
54 
55  // Read in the configurations of the xml file
56  Branch topBranch =
57  CentralConfig::GetInstance()->GetTopBranch("RdChannelNoiseGenerator");
58  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
59 
60  RandomEngine* const prndEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
61  topBranch.GetChild("NoiseModel").GetData(fNoiseType);
62 
63  topBranch.GetChild("NoiseRMS").GetData(fNoiseRMS);
64 
65  if (StringEquivalent(fNoiseType, "WhiteNoise")) {
66  double noiseTemp;
67  topBranch.GetChild("WhiteNoiseTemperature").GetData(noiseTemp);
68  fNoise = new NoiseWhite(noiseTemp, prndEngine);
69  } else if (StringEquivalent(fNoiseType,"CCIR670")) {
70  std::string atmosphereNoiseString;
71  topBranch.GetChild("CCIR670AtmosphereProfile").GetData(atmosphereNoiseString);
72  AtmosphereNoise atmosphereNoise = eNoAtmosphereNoise;
73  if (StringEquivalent(atmosphereNoiseString,"None")) {
74  atmosphereNoise = eNoAtmosphereNoise;
75  } else if (StringEquivalent(atmosphereNoiseString,"Day")) {
76  atmosphereNoise = eDayAtmosphereNoise;
77  } else if (StringEquivalent(atmosphereNoiseString,"Night")) {
78  atmosphereNoise = eNightAtmosphereNoise;
79  }
80 
81  std::string industryProfileString;
82  topBranch.GetChild("CCIR670IndustryProfile").GetData(industryProfileString);
83  IndustryNoise industryProfile = eNoIndustryNoise;
84  if (StringEquivalent(industryProfileString, "None")) {
85  industryProfile = eNoIndustryNoise;
86  } else if (StringEquivalent(industryProfileString, "Rural")) {
87  industryProfile = eRuralIndustryNoise;
88  } else if (StringEquivalent(industryProfileString, "Urban")) {
89  industryProfile = eUrbanIndustryNoise;
90  }
91 
92  fNoise = new NoiseCCIR670(AtmosphereNoise(atmosphereNoise), IndustryNoise(industryProfile), prndEngine);
93  } else if (StringEquivalent(fNoiseType, "SaSNoise")) {
94  fNoise_time_domain = new NoiseSaS(prndEngine);
95  topBranch.GetChild("SaSSigmaOverride").GetData(fSaSSigmaOverride);
96  topBranch.GetChild("SaSAlphaOverride").GetData(fSaSAlphaOverride);
97  } else {
98  WARNING("Illegal noise type defined!");
99  return eFailure;
100  }
101 
102  return eSuccess;
103  }
104 
105 
107  RdChannelNoiseGenerator::Run(evt::Event& event)
108  {
109  if (!event.HasREvent()) {
110  WARNING("No radio event found!");
111  return eContinueLoop;
112  }
113  INFO("Run()");
114  std::cout << fNoiseRMS << " " << fNoiseType << std::endl;
115 
116  revt::REvent& rEvent = event.GetREvent();
117  det::Detector& zedet = det::Detector::GetInstance();
118 
119  if (fNoiseRMS >= 0 && (fNoiseType == "WhiteNoise" || fNoiseType == "CCIR670")) {
120  INFO("adding noise");
121  for (revt::REvent::StationIterator sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
122  revt::Station& station = *sIt;
123  for (revt::Station::ChannelIterator cIt = station.ChannelsBegin(); cIt != station.ChannelsEnd(); ++cIt) {
124  revt::Channel& channel = *cIt;
125  revt::ChannelFFTDataContainer noiseChannelData = channel.GetFFTDataContainer();
126  revt::ChannelFrequencySpectrum& noiseSpec = noiseChannelData.GetFrequencySpectrum();
127  const rdet::Channel& channelDet=zedet.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
128  // generate noise in frequency domain
129  for (revt::ChannelFrequencySpectrum::SizeType bin = 0; bin < noiseSpec.GetSize(); ++bin) {
130  double binFrequency = channel.GetFrequencyOfBin(bin);
131  double antennaHeight = channelDet.GetIntegratedEffectiveAntennaHeight(binFrequency);
132  noiseSpec[bin] = antennaHeight*fNoise->GetSpectralFieldNoiseAtFrequency(binFrequency, noiseSpec.GetBinning());
133  }
134  // normalize noise trace to desired RMS in time domain
135  revt::ChannelTimeSeries& noiseTrace = noiseChannelData.GetTimeSeries();
136  const double RMS = utl::TraceAlgorithm::RootMeanSquare(noiseTrace, 0, noiseTrace.GetSize() - 1);
138  for (revt::ChannelTimeSeries::SizeType bin = 0; bin < trace.GetSize(); ++bin) {
139  trace[bin] += noiseTrace[bin] * fNoiseRMS / RMS;
140  }
141  }
142  }
143  } else if (fNoiseType == "WhiteNoise" || fNoiseType == "CCIR670"){
144  // loop through all stations
145  for (revt::REvent::StationIterator sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
146  revt::Station& station = *sIt;
147  for (revt::Station::ChannelIterator cIt = station.ChannelsBegin(); cIt != station.ChannelsEnd(); ++cIt) {
148  revt::Channel& channel = *cIt;
149  const rdet::Channel& channelDet=zedet.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
151  for (revt::ChannelFrequencySpectrum::SizeType bin = 0; bin < mySpec.GetSize(); ++bin) {
152  double binFrequency = channel.GetFrequencyOfBin(bin);
153  double antennaHeight = channelDet.GetIntegratedEffectiveAntennaHeight(binFrequency);
154  mySpec[bin] += antennaHeight*fNoise->GetSpectralFieldNoiseAtFrequency(binFrequency, mySpec.GetBinning());
155  }
156 
157  }
158 
159  }
160 
161  } else if (fNoiseType == "SaSNoise") {
162  // SaS noise see GAP-2011-017
163  evt::Event fNoiseEvent(event);
164  for (revt::REvent::StationIterator sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
165  revt::Station& station = *sIt;
166  for (revt::Station::ChannelIterator cIt = station.ChannelsBegin();cIt != station.ChannelsEnd(); ++cIt) {
167  revt::Channel& channel = *cIt;
168  revt::Channel& noise_channel = fNoiseEvent.GetREvent().GetStation(station.GetId()).GetChannel(channel.GetId());
170  double alpha = fSaSAlphaOverride ? fSaSAlphaOverride : (1./91)*log(randomGenerator_h())+1.999;
171  revt::ChannelTimeSeries& noiseTime = noise_channel.GetChannelTimeSeries();
172  double cof0 = pow(1 - pow(0.29, 2), -0.5);
173  for (revt::ChannelTimeSeries::SizeType bin = 0; bin < noiseTime.GetSize(); ++bin) {
174  if (bin == 0) {
175  noiseTime[bin] = sigma*fNoise_time_domain->CreateSaSNoiseInTimeDomain(alpha);
176  } else {
177  noiseTime[bin] = (sigma*fNoise_time_domain->CreateSaSNoiseInTimeDomain(alpha)+ 0.29*cof0*noiseTime[bin-1])/cof0;
178  }
179  }
180  const rdet::Channel& channelDet=zedet.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
182  const revt::ChannelFrequencySpectrum& noiseSpec = noise_channel.GetChannelFrequencySpectrum();
183  for (revt::ChannelFrequencySpectrum::SizeType bin = 0; bin < mySpec.GetSize(); ++bin) {
184  double binFrequency = channel.GetFrequencyOfBin(bin);
185  double antennaHeight = channelDet.GetIntegratedEffectiveAntennaHeight(binFrequency);
186  mySpec[bin] += antennaHeight*noiseSpec[bin];
187  }
188  }
189  }
190  }
191  return eSuccess;
192  }
193 
194 
196  RdChannelNoiseGenerator::Finish()
197  {
198  INFO("RdChannelNoiseGenerator::Finish()");
199  return eSuccess;
200  }
201 
202 }
ChannelFFTDataContainer & GetFFTDataContainer()
retrieve Channel FFTDataContainer (write access)
Branch GetTopBranch() const
Definition: Branch.cc:63
int GetId() const
Return Id of the Channel.
Report success to RunController.
Definition: VModule.h:62
boost::indirect_iterator< InternalChannelIterator, Channel & > ChannelIterator
Iterator over station for read/write.
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
Skip remaining modules in the current loop and continue with next iteration of the loop...
Definition: VModule.h:68
double GetBinning() const
size of one slot
Definition: Trace.h:138
#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.
revt::REvent & GetREvent()
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
double pow(const double x, const unsigned int i)
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
bool HasREvent() const
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
Definition: REvent.h:190
bool StringEquivalent(const std::string &a, const std::string &b, Predicate p)
Utility to compare strings for equivalence. It takes a predicate to determine the equivalence of indi...
Definition: StringCompare.h:38
double CreateSaSNoiseInTimeDomain(const double alpha)
Returns the noise in time domain.
Definition: NoiseSaS.cc:22
ChannelTimeSeries & GetChannelTimeSeries()
retrieve Channel Time Series (write access, only use this if you intend to change the data) ...
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
virtual std::complex< double > GetSpectralFieldNoiseAtFrequency(double parFrequency, double parBandwidth) const =0
Returns the noise (complex value representing amplitude and phase) at a given frequency.
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
Noise profiles based on the textbook of Meinke and Grundlach.
Definition: NoiseCCIR670.h:32
AtmosphereNoise
Definition: NoiseCCIR670.h:29
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
std::vector< std::complex< double > >::size_type SizeType
Definition: Trace.h:58
Wraps the random number engine used to generate distributions.
Definition: RandomEngine.h:27
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
C< T > & GetTimeSeries()
read out the time series (write access)
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
int GetId() const
Get the station Id.
static double RootMeanSquare(const Trace< T > &trace, const unsigned int bin1, const unsigned int bin2)
Evaluate the RootMeanSquare of trace between bin1 and bin2.
Class producing noise originating from a Symmetric alpha-Stable distribution function.
Definition: NoiseSaS.h:29
boost::variate_generator< boost::mt19937, boost::uniform_real< double > > randomGenerator_h
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
constexpr double volt
Definition: AugerUnits.h:229
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.
Report failure to RunController, causing RunController to terminate execution.
Definition: VModule.h:64
constexpr double micro
Definition: AugerUnits.h:65
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
boost::variate_generator< boost::mt19937, boost::uniform_real< double > > randomGenerator_sigma
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
double GetIntegratedEffectiveAntennaHeight(const double freq) const
IndustryNoise
Definition: NoiseCCIR670.h:30
Class producing white noise with a given temperature.
Definition: NoiseWhite.h:27

, generated on Tue Sep 26 2023.