RdChannelAmplitudeCalibrator.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/VModule.h>
5 
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
8 #include <utl/config.h>
9 #include <utl/TraceAlgorithm.h>
10 #include <utl/AugerUnits.h>
11 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
12 
13 #include <evt/Event.h>
14 #include <revt/Header.h>
15 #include <revt/REvent.h>
16 #include <revt/Station.h>
17 #include <revt/Channel.h>
18 
19 #include <rdet/RDetector.h>
20 #include <rdet/Station.h>
21 #include <rdet/Channel.h>
22 
23 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
24 
25 using namespace utl;
26 using namespace fwk;
27 using namespace std;
28 using namespace revt;
29 using namespace boost;
30 
31 
33 
35  fInfoLevel(0)
36  { }
37 
38 
39  RdChannelAmplitudeCalibrator::~RdChannelAmplitudeCalibrator()
40  { }
41 
44  {
45  // Initialize your module here. This method
46  // is called once at the beginning of the run.
47  // The eSuccess flag indicates the method ended
48  // successfully. For other possible return types,
49  // see the VModule documentation.
50 
51  OUT(eFinal)<<"RdChannelAmplitudeCalibrator::Init()"<< endl;
52 
53  // Read in the configurations of the xml file
54  Branch topBranch =
55  CentralConfig::GetInstance()->GetTopBranch("RdChannelAmplitudeCalibrator");
56  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
57  return eSuccess;
58  }
59 
60 
62  RdChannelAmplitudeCalibrator::Run(evt::Event& event)
63  {
64  // Check if there are events at all
65  if(!event.HasREvent()) {
66  if(fInfoLevel > eNone) {
67  WARNING("No radio event found!");
68  }
69  return eContinueLoop;
70  }
71 
72  det::Detector& thedet = det::Detector::GetInstance();
73  REvent& rEvent = event.GetREvent();
74 
75  // loop through stations and for every station through every channel
76  for (REvent::StationIterator sIt = rEvent.StationsBegin();
77  sIt != rEvent.StationsEnd(); ++sIt) {
78  Station& station = *sIt;
79 
80  ostringstream message;
81 
82  for (Station::ChannelIterator cIt = station.ChannelsBegin();
83  cIt != station.ChannelsEnd(); ++cIt) {
84 
85  Channel& channel = *cIt;
86  if (!channel.IsActive())
87  continue;
88 
89  const rdet::Channel& channeldet = thedet.GetRDetector().GetStation(station.GetId()).GetChannel(channel.GetId());
90  const TabulatedFunction& channelcalibration = channeldet.GetCalibrationFunction();
91 
92  // fixme TH: application of calibration function deactivated until rdet::Channel::GetCalibrationFunction() has been implemented
93  // check if there is actually a valid calibration function and skip channel if not
94  // if (channelcalibration.GetNPoints()<2)
95  continue;
96 
97  message.str("");
98  message << "Applying calibration to channel "<< channel.GetId() << " of station " << station.GetId();
99  OUT(eObscure) << message.str() << endl;
100 
101  ApplyResponse(channel, channelcalibration);
102  }
103  }
104 
105  return eSuccess;
106  }
107 
108 
110  RdChannelAmplitudeCalibrator::Finish()
111  {
112  // Put any termination or cleanup code here.
113  // This method is called once at the end of the run.
114 
115  OUT(eFinal) << "RdChannelAmplitudeCalibrator::Finish()"<<endl;
116 
117  return eSuccess;
118  }
119 
120  void
121  RdChannelAmplitudeCalibrator::ApplyResponse(Channel& channel, const TabulatedFunction& response) const
122  {
123  ChannelFrequencySpectrum& channelspectrum = channel.GetChannelFrequencySpectrum();
124  for (ChannelFrequencySpectrum::SizeType i = 0; i < channelspectrum.GetSize(); ++i) {
125  const double freq = channel.GetFrequencyOfBin(i);
126 
127  if ( (freq>=response.XFront()) && (freq<=response.XBack()) ) {
128  channelspectrum[i] *= response.Y(freq);
129  }
130  }
131  }
132 
133 }
Branch GetTopBranch() const
Definition: Branch.cc:63
bool IsActive() const
#define OUT(x)
int GetId() const
Return Id of the Channel.
Report success to RunController.
Definition: VModule.h:62
ArrayConstReference XBack() const
read-only reference to back of array of X
int freq
Definition: dump1090.h:244
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
Class to hold collection (x,y) points and provide interpolation between them.
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
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
const utl::TabulatedFunction & GetCalibrationFunction() const
Get a TabulatedFunction with calibration factors for the frequency bins of the Channel, not yet implemented.
bool HasREvent() const
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
ArrayConstReference XFront() const
read-only reference to front of array of X
std::vector< std::complex< double > >::size_type SizeType
Definition: Trace.h:58
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
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.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
void ApplyResponse(revt::Channel &channel, const utl::TabulatedFunction &response) const
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
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141

, generated on Tue Sep 26 2023.