RdDummyChannelToStationConverter.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
8 #include <utl/TraceAlgorithm.h>
9 
10 #include <evt/Event.h>
11 #include <revt/REvent.h>
12 #include <revt/Station.h>
13 #include <revt/Channel.h>
14 #include <rdet/RDetector.h>
15 #include <rdet/Channel.h>
16 
17 
18 
19 using namespace revt;
20 using namespace fwk;
21 using namespace utl;
22 using namespace std;
23 
25 
27  {
28  }
29 
30 
31  RdDummyChannelToStationConverter::~RdDummyChannelToStationConverter()
32  {
33  }
34 
35 
38  {
39  // Initialize your module here. This method
40  // is called once at the beginning of the run.
41  // The eSuccess flag indicates the method ended
42  // successfully. For other possible return types,
43  // see the VModule documentation.
44 
45  INFO("RdDummyChannelToStationConverter::Init()");
46  Branch topBranch =
47  CentralConfig::GetInstance()->GetTopBranch("RdDummyChannelToStationConverter");
48 
49  topBranch.GetChild("UseIntegratedAntennaPattern").GetData(fUseIntegratedAntennaPattern);
50 
51  return eSuccess;
52  }
53 
54 
56  RdDummyChannelToStationConverter::Run(evt::Event& event)
57  {
58  // Check if there are events at all
59  if(!event.HasREvent()) {
60  WARNING("No radio event found!");
61  return eContinueLoop;
62  }
63 
64  REvent& rEvent = event.GetREvent();
65 // stringstream fMessage;
66  Vector3D VDZero;
67  VDZero = 0.0, 0.0, 0.0;
68  stringstream fMessage;
69  // loop through stations and for every station through every channel
70  for (REvent::StationIterator sIt = rEvent.StationsBegin();
71  sIt != rEvent.StationsEnd(); ++sIt) {
72  Station& station = *sIt;
73  StationTimeSeries& newstationtimeseries=station.GetStationTimeSeries();
74  bool firststationchannel = true;
75 
76  for (Station::ChannelIterator cIt = station.ChannelsBegin();
77  cIt != station.ChannelsEnd(); ++cIt) {
78  Channel& channel = *cIt;
79  //only works for active channels
80  if (!channel.IsActive())
81  continue;
82 
83  fMessage.str("");
84  fMessage << "Copying channel "
85  << channel.GetId()
86  << " of station "
87  << channel.GetStationId()
88  << " to the StationTimeSeries.";
89  INFO(fMessage.str());
90 
91  // Work on the trace of this channel
92  const revt::ChannelTimeSeries& channeltrace =
93  channel.GetChannelTimeSeries();
94 
95  // when working on the first channel, fill station timeseries with zeroes and set some station-specific quantities
96  if (firststationchannel) {
97  firststationchannel = false;
98  // overwrite the station time series with an empty one of the correct size
99  newstationtimeseries = StationTimeSeries(channeltrace.GetSize(),channeltrace.GetBinning(),VDZero);
100  // set the Nyquist zone of the station, does no check if Nyquist zones of Channels are the same!
101  station.SetNyquistZone(channel.GetNyquistZone());
102  }
103 
104  // check if newstationtimeseries.GetSize() is correct
105  if (newstationtimeseries.GetSize() != channeltrace.GetSize()) {
106  fMessage.str("");
107  fMessage << "Number of samples in trace of "
108  << channel.GetId()
109  << " belonging to station "
110  << channel.GetStationId()
111  << " is different than the number of samples in other channels of that station.";
112  WARNING(fMessage.str());
113  return eFailure;
114  }
115 
116  const rdet::RDetector& rDetector =
117  det::Detector::GetInstance().GetRDetector();
118  const rdet::Channel& detChannel =
119  rDetector.GetStation(station.GetId()).GetChannel(channel.GetId());
120  double orientAzimuth = detChannel.GetOrientationAzimuth();
121  double orientZenith = detChannel.GetOrientationZenith();
122 
123  if (orientAzimuth < 0 && orientAzimuth > -360 * deg)
124  orientAzimuth += 360 * deg;
125 
126  // Doing some kind of dodgy association of the channels to the coordinates
127  // The design-decision is that this module is only for testing purposes so
128  // a proper coordinate transformation is not done here.
129  fMessage.str("");
130  double alignMargin = 5*deg;
131  if ( orientZenith > alignMargin ) {
132  fMessage << "Encountering a channel that seems to be vertically aligned, not converting.";
133  WARNING(fMessage.str());
134  continue;
135  }
136 
137  double correspondingCoordinate; // Will always be initialized or ignored in the code below
138  double correspondingSign; // Will always be initialized or ignored in the code below
139  fMessage.str("");
140  fMessage << "Associating channel " << channel.GetId() << " for station " << station.GetId() << " at " <<
141  orientAzimuth/deg << " deg azimuthal angle";
142  if ( orientAzimuth < alignMargin or orientAzimuth > 360 * deg - alignMargin ) {
143  fMessage << " with a positive x coordinate.";
144  INFO(fMessage.str());
145  correspondingCoordinate = 0;
146  correspondingSign = 1;
147  } else if ( orientAzimuth > 90 * deg - alignMargin or orientAzimuth < 90 * deg + alignMargin ) {
148  fMessage << " with a positive y coordinate.";
149  INFO(fMessage.str());
150  correspondingCoordinate = 1;
151  correspondingSign = 1;
152  } else if ( orientAzimuth > 180 * deg - alignMargin or orientAzimuth < 180 * deg + alignMargin ) {
153  fMessage << " with a negative x coordinate.";
154  INFO(fMessage.str());
155  correspondingCoordinate = 0;
156  correspondingSign = -1;
157  } else if ( orientAzimuth > 270 * deg - alignMargin or orientAzimuth < 270 * deg + alignMargin ) {
158  fMessage << " with a negative y coordinate.";
159  INFO(fMessage.str());
160  correspondingCoordinate = 1;
161  correspondingSign = -1;
162  } else {
163  fMessage.str("");
164  fMessage << "No good dodgy conversion possible because the antenna does not seem to be aligned with " <<
165  "any spatial coordinate within " << alignMargin/deg << "deg.";
166  WARNING(fMessage.str());
167  continue;
168  }
169 
170  // if UseIntegratedAntennaResponse is active, scale the Channel spectrum with the integrated antenna response
171  if (fUseIntegratedAntennaPattern) {
172  // retrieve a write-access reference of the channel spectrum
173  revt::ChannelFrequencySpectrum& channelspectrum = channel.GetChannelFrequencySpectrum();
174  // get the design bandwidth from the channel
175  const double lowerDesignFreq = detChannel.GetDesignLowerFreq();
176  const double upperDesignFreq = detChannel.GetDesignUpperFreq();
177 
178  // get the integrated antenna response and apply it to the data
179  for (ChannelFrequencySpectrum::SizeType i=0; i<channelspectrum.GetSize(); ++i) {
180  const double freq = channel.GetFrequencyOfBin(i);
181  // apply antenna response, if outside design band set to zero
182  if ((freq >= lowerDesignFreq) && (freq <= upperDesignFreq))
183  channelspectrum[i] /= detChannel.GetIntegratedEffectiveAntennaHeight(freq);
184  else
185  channelspectrum[i] = 0.0;
186  }
187  }
188 
189  // if UseIntegratedAntennaResponse is active, the frequency spectrum has been changed
190  // we therefore have to make sure the time domain representation is up-to-date
191  // consequently, we request a new reference to the channel trace
192  const revt::ChannelTimeSeries& newchanneltrace = channel.GetChannelTimeSeries();
193  for (ChannelTimeSeries::SizeType i=0; i<newchanneltrace.GetSize(); ++i) {
194  newstationtimeseries[i][correspondingCoordinate] = correspondingSign * newchanneltrace[i];
195  }
196  }
197  }
198 
199 
200 
201  return eSuccess;
202  }
203 
204 
206  RdDummyChannelToStationConverter::Finish()
207  {
208  // Put any termination or cleanup code here.
209  // This method is called once at the end of the run.
210 
211  INFO("RdDummyChannelToStationConverter::Finish()");
212 
213  return eSuccess;
214  }
215 
216 }
Branch GetTopBranch() const
Definition: Branch.cc:63
bool IsActive() const
int GetId() const
Return Id of the Channel.
double GetDesignUpperFreq() const
Get design value of the freq-band.
boost::indirect_iterator< InternalChannelIterator, Channel & > ChannelIterator
Iterator over station for read/write.
utl::TraceV3D StationTimeSeries
int freq
Definition: dump1090.h:244
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.
double GetOrientationZenith() const
Get zenith-direction of Antenna for this Channel.
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
bool HasREvent() const
int GetStationId() const
Return Id of the station to which this Channel belongs.
StationTimeSeries & GetStationTimeSeries()
retrieve Station Time Series (write access, only use this if you intend to change the data) ...
unsigned int GetNyquistZone() const
Get the Nyquist zone.
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
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
constexpr double deg
Definition: AugerUnits.h:140
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
void SetNyquistZone(const unsigned int zone)
Set the Nyquist zone.
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
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
Definition: Trace-fwd.h:19
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 Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
double GetIntegratedEffectiveAntennaHeight(const double freq) const
double GetOrientationAzimuth() const
Get azimuth-direction of Antenna for this Channel.

, generated on Tue Sep 26 2023.