3 #include <fwk/CentralConfig.h>
4 #include <fwk/RandomEngineRegistry.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
8 #include <utl/config.h>
9 #include <utl/AugerUnits.h>
10 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
11 #include <utl/RandomEngine.h>
13 #include <evt/Event.h>
14 #include <revt/REvent.h>
15 #include <revt/Station.h>
16 #include <revt/Channel.h>
18 #include <rdet/RDetector.h>
19 #include <rdet/Station.h>
20 #include <rdet/Channel.h>
22 #include <CLHEP/Random/RandGauss.h>
29 using namespace boost;
31 using CLHEP::RandGauss;
40 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RdChannelResponseIncorporator");
43 topBranch.
GetChild(
"NumResponsesToCache").
GetData(fNumResponsesToCache);
44 topBranch.
GetChild(
"ForwardResponseOnFirstCall").
GetData(fForwardResponseOnFirstCall);
45 topBranch.
GetChild(
"OverrideInverseBandLimits").
GetData(fInverseBandLimitsOverride);
46 topBranch.
GetChild(
"InverseLowerFrequencyLimit").
GetData(fInverseLowerFrequency);
47 topBranch.
GetChild(
"InverseUpperFrequencyLimit").
GetData(fInverseUpperFrequency);
48 topBranch.
GetChild(
"OverrideForwardBandLimits").
GetData(fForwardBandLimitsOverride);
49 topBranch.
GetChild(
"ForwardLowerFrequencyLimit").
GetData(fForwardLowerFrequency);
50 topBranch.
GetChild(
"ForwardUpperFrequencyLimit").
GetData(fForwardUpperFrequency);
52 topBranch.
GetChild(
"SmearChannelTraceToMimicInaccurateHardwareDescription").
GetData(
53 fSmearChannelTraceToMimicInaccurateHardwareDescription);
55 topBranch.
GetChild(
"RelativeGaussianUcertainty").
GetData(fRelativeGaussianUcertainty);
56 if (fSmearChannelTraceToMimicInaccurateHardwareDescription)
57 fRandomEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
60 info <<
"Read config:"
61 <<
"\n\t ForwardResponseOnFirstCall : "
62 << fForwardResponseOnFirstCall
63 <<
"\n\t SmearChannelTraceToMimicInaccurateHardwareDescription : "
64 << fSmearChannelTraceToMimicInaccurateHardwareDescription
65 <<
"\n\t RelativeGaussianUcertainty : "
66 << fRelativeGaussianUcertainty <<
"\n";
78 WARNING(
"No radio event found!");
83 REvent& rEvent =
event.GetREvent();
85 ostringstream message;
90 for (
auto& station : rEvent.StationsRange()) {
91 for (
auto& channel : station.ChannelsRange()) {
93 if (!channel.IsActive()) {
108 if (!fForwardResponseOnFirstCall) {
112 message <<
"Applying inverse detector response to channel "
113 << channel.GetId() <<
" of station " << station.GetId();
116 if (fInverseBandLimitsOverride)
117 ApplyResponse(channel, channelresponse,
true, fInverseLowerFrequency, fInverseUpperFrequency);
119 ApplyResponse(channel, channelresponse,
true, designLowerfrequency, designUpperfrequency);
125 message <<
"Later call: applying inverse response to channel "
126 << channel.GetId() <<
" of station " << station.GetId();
129 if (fInverseBandLimitsOverride)
130 ApplyResponse(channel, channelresponse,
true, fInverseLowerFrequency, fInverseUpperFrequency);
132 ApplyResponse(channel, channelresponse,
true, designLowerfrequency, designUpperfrequency);
136 message <<
"First call: applying forward response to channel "
137 << channel.GetId() <<
" of station " << station.GetId();
140 if (fForwardBandLimitsOverride)
141 ApplyResponse(channel, channelresponse,
false, fForwardLowerFrequency, fForwardUpperFrequency);
143 ApplyResponse(channel, channelresponse,
false, designLowerfrequency, designUpperfrequency);
145 if (fSmearChannelTraceToMimicInaccurateHardwareDescription) {
147 const double smearFactor = RandGauss::shoot(&fRandomEngine->GetEngine(), 1,
148 fRelativeGaussianUcertainty);
151 message <<
"Station " << station.GetId() <<
" channel " << channel.GetId()
152 <<
" smeared with " << smearFactor;
155 for (
auto& val : trace)
171 RdChannelResponseIncorporator::Finish()
174 msg <<
"RdChannelResponseIncorporator cache hit fraction was "
175 <<
static_cast<double>(fCacheHits) / static_cast<double>(fCacheAsks)
176 <<
" for a cache with " << fNumResponsesToCache <<
" entries.";
185 RdChannelResponseIncorporator::GetCachedOverallResponse(
const ResponseMap& responsemap)
const
188 vector<CacheRecord>::iterator leastusedentry = fCacheRegistry.begin();
189 for (vector<CacheRecord>::iterator i = fCacheRegistry.begin(); i != fCacheRegistry.end(); ++i) {
190 if (i->get<0>() == responsemap) {
196 if (i->get<2>() < leastusedentry->get<2>())
201 if (fCacheRegistry.size() == fNumResponsesToCache)
202 fCacheRegistry.erase(leastusedentry);
203 fCacheRegistry.emplace_back(responsemap, CalculateOverallResponse(responsemap), 0);
204 return fCacheRegistry.back().get<1>();
209 RdChannelResponseIncorporator::CalculateOverallResponse(
const ResponseMap& responsemap)
const
212 const rdet::RDetector& rdetector = det::Detector::GetInstance().GetRDetector();
218 totalresponse.
Pow(beginentry->second);
222 for (
auto it = beginentry; it != responsemap.
End(); ++it) {
225 tempresponse.
Pow(it->second);
226 totalresponse *= tempresponse;
229 return totalresponse;
235 bool inverse,
double lowerfreq,
double upperfreq)
const
240 if ((freq < lowerfreq) || (freq > upperfreq)) {
241 channelspectrum[i] = complex<double>(0.0, 0.0);
244 channelspectrum[i] /= response.
Y(freq).
GetComplex();
246 channelspectrum[i] *= response.
Y(freq).
GetComplex();
Branch GetTopBranch() const
const_iterator End() const
Get an iterator to the end of the ResponseMap.
double GetDesignUpperFreq() const
Get design value of the freq-band.
Interface class to access to the Radio part of an event.
void SetChannelResponseApplied(const bool parFlag)
double GetDesignLowerFreq() const
Get design value of the freq-band.
void Pow(const double power)
calculate the power of a TabulatedFunctionComplexLgAmpPhase (correctly treating amplitude and phase) ...
#define INFO(message)
Macro for logging informational messages.
std::complex< double > GetComplex() const
Get the complex number in standard notation; this clips the phase to 2*pi!
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.
std::map< std::string, double >::const_iterator const_iterator
#define INFOIntermediate(y)
Class representing a document branch.
const utl::TabulatedFunctionComplexLgAmpPhase & GetHardwareResponseProfile(const std::string &identifier) const
Get the response (TabulatedFunctionComplexLgAmpPhase) which corresponds to a hardware profile identif...
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
std::vector< std::complex< double > >::size_type SizeType
const utl::ResponseMap & GetResponseMap() const
Get the ResponseMap of the Channel.
Top of the hierarchy of the detector description interface.
bool GetChannelResponseApplied() const
access to fChannelResponseApplied flag
A helper class which manages a list of system response identifiers (std::strings) and their correspon...
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
utl::ComplexLgAmpPhase Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
ResultFlag
Flag returned by module methods to the RunController.
const_iterator Begin() const
Get an iterator to the first element of the ResponseMap.
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
const Station & GetStation(const int stationId) const
Get station by Station Id.