RdChannelSpectrumAverager.cc
Go to the documentation of this file.
1 
10 
11 #include <cmath>
12 #include <string>
13 
14 #include <evt/Event.h>
15 
16 #include <fwk/CentralConfig.h>
17 
18 #include <utl/ErrorLogger.h>
19 #include <utl/Reader.h>
20 #include <utl/config.h>
21 #include <utl/Trace.h>
22 #include <utl/TraceAlgorithm.h>
23 
24 #include <revt/REvent.h>
25 #include <revt/Header.h>
26 #include <revt/Station.h>
27 #include <revt/Channel.h>
28 
29 using namespace std;
30 using namespace fwk;
31 using namespace utl;
32 using namespace revt;
33 
35 
37  {
38  }
39 
40  RdChannelSpectrumAverager::~RdChannelSpectrumAverager()
41  {
42  }
43 
46  {
47  // Initialize your module here. This method
48  // is called once at the beginning of the run.
49  // The eSuccess flag indicates the method ended
50  // successfully. For other possible return types,
51  // see the VModule documentation.
52 
53  INFO("RdChannelSpectrumAverager::Init()");
54 
55  // Read in the configurations of the xml file
56  // Branch topBranch =
57  // CentralConfig::GetInstance()->GetTopBranch("RdChannelSpectrumAverager");
58  // topBranch.GetChild("").GetData(f);
59 
60  return eSuccess;
61  }
62 
64  RdChannelSpectrumAverager::Run(evt::Event& event)
65  {
66  // Check if there are events at all
67  if(!event.HasREvent()) {
68  WARNING("No radio event found!");
69  return eContinueLoop;
70  }
71 
72  REvent& rEvent = event.GetREvent();
73 
74  // loop through each station and each channel of the event
75  for (REvent::StationIterator sIt = rEvent.StationsBegin();
76  sIt != rEvent.StationsEnd(); ++sIt) {
77  Station& station = *sIt;
78 
79  for (Station::ChannelIterator cIt = station.ChannelsBegin();
80  cIt != station.ChannelsEnd(); ++cIt) {
81  Channel& channel = *cIt;
82  stringstream fMessage("");
83  fMessage << "Replacing amplitude spectrum by mean ampltitude spectrum for channel "
84  << channel.GetId()
85  << " of station "
86  << channel.GetStationId()
87  << ".";
88  INFO(fMessage.str());
89 
90  // construct the key for accesing the maps
91  pair<int,int> key(station.GetId(), channel.GetId());
92 
93  // get the spectrum and calculate the amplitude spectrum
96 
97  Trace<double> amplitude;
98  for (ChannelFrequencySpectrum::SizeType i = 0; i < spectrum.GetSize(); ++i)
99  amplitude.PushBack(abs(spectrum[i]));
100 
101  // check if it is first run for this station and channel
102  // (then the ID does not exist in the counter map)
103  if (fCounter.find(key) == fCounter.end()) {
104  fCounter[key] = 1; // set counter to 1 for this channel and station
105  fMeanAmplitude[key] = amplitude; // current amplitude spectrum is also the mean spectrum
106  } else {
107  // check if size of the spectrum fits and then calculate the mean amplitude
108  if (fMeanAmplitude[key].GetSize() != amplitude.GetSize()) {
109  ERROR("Size of current spectrum and mean spectrum do not match!");
110  return eContinueLoop;
111  }
112 
113  // increase counter and calculate new mean value
114  ++fCounter[key];
115  fMeanAmplitude[key] = (amplitude + double(fCounter[key]-1)*fMeanAmplitude[key]) / double(fCounter[key]);
116 
117  // change amplitude of spectrum to mean amplitude
118  // spectral bins with an amplitude of 0 will be set to a phase 0, otherwise the phase is not touched.
119  for (ChannelFrequencySpectrum::SizeType i = 0; i < amplitude.GetSize(); ++i)
120  if (amplitude[i] > 0)
121  spectrum[i] *= fMeanAmplitude[key][i]/amplitude[i];
122 // spectrum[i] = fMeanAmplitude[key][i];
123  else
124  spectrum[i] = fMeanAmplitude[key][i];
125  }
126  }
127  }
128 
129  return eSuccess;
130  }
131 
133  RdChannelSpectrumAverager::Finish()
134  {
135  // Put any termination or cleanup code here.
136  // This method is called once at the end of the run.
137 
138  INFO("RdChannelSpectrumAverager::Finish()");
139  return eSuccess;
140  }
141 }
int GetId() const
Return Id of the Channel.
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
#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.
ChannelIterator ChannelsBegin()
begin Channel iterator for read/write
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
bool HasREvent() const
int GetStationId() const
Return Id of the station to which this Channel belongs.
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
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)
SizeType GetSize() const
Definition: Trace.h:156
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
int GetId() const
Get the station Id.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
ChannelFrequencySpectrum & GetChannelFrequencySpectrum()
retrieve Channel Frequency Spectrum (write access, only use this if you intend to change the data) ...
Class that holds the data associated to an individual radio channel.
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.