RdChannelSelector.cc
Go to the documentation of this file.
1 #include "RdChannelSelector.h"
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
8 
9 #include <evt/Event.h>
10 #include <revt/REvent.h>
11 
12 #include <det/Detector.h>
13 #include <rdet/Channel.h>
14 
15 
16 using namespace fwk;
17 using namespace utl;
18 using namespace std;
19 using namespace revt;
20 
21 
22 namespace RdChannelSelector {
23 
26  {
27  // Read in the configurations of the xml file
28  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdChannelSelector");
29  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
30  topBranch.GetChild("UseLowGainIfHighGainIsSaturated").GetData(fUseLowGainIfHighGainIsSaturated);
31 
32  if(!fUseLowGainIfHighGainIsSaturated) {
33  ostringstream info;
34  info << "RdChannelSelector set up to replace saturated high gain channels.";
35  INFO(info);
36  }
37 
38  return eSuccess;
39  }
40 
41 
43  RdChannelSelector::Run(evt::Event& event)
44  {
45  // Check if there are events at all
46  if(!event.HasREvent()) {
47  WARNING("No radio event found!");
48  return eContinueLoop;
49  }
50 
51  ostringstream info;
52 
53  REvent& rEvent = event.GetREvent();
54  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
55 
56  const double tolerance = 1e-3;
57 
58  for (auto& station : rEvent.StationsRange()) {
59  unsigned int activeChannels = 0;
60 
61  for (auto& channel : station.ChannelsRange()) {
62  const auto& detChannel = rDetector.GetStation(station.GetId()).GetChannel(channel.GetId());
63  const string channelType = detChannel.GetChannelType();
64 
65  info.str("");
66  info << "station " << station.GetId() << " channel " << channel.GetId() << " has type "
67  << channelType << " and is active? " << channel.IsActive();
68  INFODebug(info);
69 
70  if (!channel.IsActive())
71  continue;
72 
73  /* At EventIO level we do not know that a channel is empty. So we get this information
74  here from the database and set emtpy channels as not active */
75  if (channelType == "Empty") {
76  info.str("");
77  info << "station " << station.GetId() << " Channel " << channel.GetId()
78  << " has type Empty but is active. Set to not active.";
79  INFOIntermediate(info);
80 
81  channel.SetNotActive();
82  continue;
83  }
84 
85  /* Filtered channels are used by NL stations for triggering and are not used in
86  standard reconstructions */
87  if (channelType == "FilteredHighGain" || channelType == "FilteredLowGain") {
88  info.str("");
89  info << "station " << station.GetId() << " Channel " << channel.GetId()
90  << " has type " << channelType << " but is active. Set to not active.";
91  INFOIntermediate(info);
92 
93  channel.SetNotActive();
94  continue;
95  }
96 
97  /* Loop over high gain channels and check if the high gain or a corresponding
98  low gain channel should be used if it exists */
99  if (channelType == "AntennaHighGain") {
100  activeChannels++;
101 
102  // is there a corresponding low gain channel?
103  const auto& lowGainChannel = GetLowGainChannel(station, rDetector, detChannel, tolerance);
104  const bool hasLowGainChannel = lowGainChannel.is_initialized();
105 
106  // when to use low gain channel
107  if (fUseLowGainIfHighGainIsSaturated &&
108  channel.IsSaturated() && hasLowGainChannel) {
109  channel.SetNotActive();
110 
111  info.str("");
112  info << "Saturated high gain channel " << channel.GetId() << " of station " << station.GetId()
113  << " deactivated. Use low gain channel " << lowGainChannel->GetId() << " instead.";
114  INFOIntermediate(info);
115  continue;
116  }
117 
118  // use high gain channel
119  if (hasLowGainChannel)
120  lowGainChannel->SetNotActive();
121 
122  info.str("");
123  info << "Using high gain channel " << channel.GetId() << " of station " << station.GetId() << ".";
124  INFOIntermediate(info);
125  continue;
126  }
127  } // channel loop
128 
129  if (activeChannels < 2 || activeChannels > 3) {
130  info.str("");
131  info << "Station " << station.GetId() << " does not have two or three active channels, "
132  << "station will be excluded.";
133  WARNING(info);
134  station.SetExcludedReason(eHardwareMismatch);
135  }
136  } // station loop
137 
138  return eSuccess;
139  }
140 
141 
143  RdChannelSelector::Finish()
144  {
145  return eSuccess;
146  }
147 
148 
149  boost::optional<revt::Channel&>
150  RdChannelSelector::GetLowGainChannel(revt::Station& station,
151  const rdet::RDetector& rDetector,
152  const rdet::Channel& detChannel,
153  const double tolerance)
154  {
155  for (auto& newChannel : station.ChannelsRange()) {
156  const auto& newDetChannel = rDetector.GetStation(station.GetId()).GetChannel(newChannel.GetId());
157 
158  if (IsClose(detChannel.GetOrientationZenith(), newDetChannel.GetOrientationZenith(), tolerance)
159  && IsClose(detChannel.GetOrientationAzimuth(), newDetChannel.GetOrientationAzimuth(), tolerance)
160  && IsClose(detChannel.GetOrientationZeta(), newDetChannel.GetOrientationZeta(), tolerance)
161  && newDetChannel.GetChannelType() == "AntennaLowGain") {
162 
163  return newChannel;
164  }
165  }
166 
167  return boost::none;
168  }
169 
170 
171  bool
172  RdChannelSelector::IsClose(const double a, const double b, const double tolerance)
173  {
174  return fabs(a - b) < tolerance;
175  }
176 
177 }
double GetOrientationZeta() const
Get zeta-tilt of Antenna for this 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
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
bool HasREvent() const
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
#define INFOIntermediate(y)
Definition: VModule.h:162
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
int GetId() const
Station ID.
#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.
#define INFODebug(y)
Definition: VModule.h:163
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
double GetOrientationAzimuth() const
Get azimuth-direction of Antenna for this Channel.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.