RdClusterFinder.cc
Go to the documentation of this file.
1 #include "RdClusterFinder.h"
2 
3 #include <fwk/CentralConfig.h>
4 #include <utl/Branch.h>
5 #include <utl/RadioGeometryUtilities.h>
6 
7 #include <det/Detector.h>
8 #include <rdet/RDetector.h>
9 
10 #include <evt/Event.h>
11 #include <evt/ShowerRecData.h>
12 #include <evt/ShowerRRecData.h>
13 
14 #include <revt/REvent.h>
15 #include <revt/StationRecData.h>
16 
17 #include <vector>
18 #include <algorithm>
19 
20 using namespace std;
21 using namespace fwk;
22 using namespace utl;
23 using namespace evt;
24 using namespace revt;
25 
26 
27 namespace RdClusterFinder {
28 
29  bool
30  SortPairByDistance(const pair<double, int> x, const pair<double, int> y)
31  {
32  return (x.first > y.first);
33  }
34 
35 
38  {
39  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdClusterFinder");
40  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
41  topBranch.GetChild("MaximumDiscontinuity").GetData(fMaximumDiscontinuity);
42  topBranch.GetChild("RejectLonelyStations").GetData(fRejectLonelyStations);
43  topBranch.GetChild("LonelyIfNoneInDistance").GetData(fLonelyIfNoneInDistance);
44  topBranch.GetChild("LonelyIfOneInDistance").GetData(fLonelyIfOneInDistance);
45  topBranch.GetChild("LonelyIfNoneInDistancePhase3").GetData(fLonelyIfNoneInDistancePhase3);
46  topBranch.GetChild("LonelyIfOneInDistancePhase3").GetData(fLonelyIfOneInDistancePhase3);
47  topBranch.GetChild("IgnoreRejectedStations").GetData(fIgnoreRejectedStations);
48  topBranch.GetChild("IgnoreExcludedStations").GetData(fIgnoreExcludedStations);
49 
50  if (fIgnoreRejectedStations > 2)
51  ERROR("Wrong config. IgnoreRejectedStations must be 0, 1 or 2.");
52 
53  return eSuccess;
54  }
55 
56 
58  RdClusterFinder::Run(Event& event)
59  {
60  // Check if there are no events at all
61  if (!event.HasREvent()) {
62  WARNING("eContinueLoop, No radio event found!");
63  return eContinueLoop;
64  }
65 
66  REvent& rEvent = event.GetREvent();
67  ostringstream info;
68 
69  // cluster finder will not work properly for less than 3 signal stations and reject all remaining stations
70  if (rEvent.GetNumberOfSignalStations() < 3) {
71  return eSuccess;
72  }
73 
74  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
75  vector<int> selectedCluster;
76  vector<int> deselectedStations;
77 
78  const Point& showerCore = event.GetRecShower().GetRRecShower().GetReferenceCorePosition(event);
79  const utl::Vector& showerAxis = event.GetRecShower().GetRRecShower().GetReferenceAxis(event);
80 
81  // distance between Sd axis and signal stations and station id
82  vector<pair<double, int> > distanceToSdAxis;
83  for (const auto& station : rEvent.StationsRange()) {
84 
85  if (!UseStation(station))
86  continue;
87 
88  const Point& stationPosition = rDetector.GetStation(station).GetPosition();
89  const float distance = utl::RadioGeometryUtilities::GetDistanceToAxis(showerAxis, showerCore,
90  stationPosition);
91  distanceToSdAxis.emplace_back(distance, station.GetId());
92  }
93  sort(distanceToSdAxis.begin(), distanceToSdAxis.end(), SortPairByDistance);
94 
95  // check axis distances for jumps larger than fMaximumDiscontinuity and deselect
96  // loop from furthest away from axis to 2nd closest stations
97  for (auto itCurrent = distanceToSdAxis.begin(); itCurrent != prev(distanceToSdAxis.end()); ++itCurrent) {
98  selectedCluster.push_back(itCurrent->second);
99 
100  auto itNext = next(itCurrent);
101  const double deltaR = itCurrent->first - itNext->first;
102  if (deltaR > fMaximumDiscontinuity) {
103  copy(selectedCluster.begin(), selectedCluster.end(), std::back_inserter(deselectedStations));
104  selectedCluster.clear();
105  }
106  }
107 
108  // reject the deselected stations
109  for (const auto& deselectedStation : deselectedStations) {
110  Station& theStation = rEvent.GetStation(deselectedStation);
112 
113  //Display some information for low level bug tracking
114  info.str("");
115  info << "Deselected station ID : " << deselectedStation;
116  INFOFinal(info.str());
117  }
118 
119  // get reference coordinate system of detector (usually PampaAmarilla)
120  // needed to detect AERA phase 3 via position aka south
121  const CoordinateSystemPtr referenceCS =
122  det::Detector::GetInstance().GetReferenceCoordinateSystem();
123 
124  /* lonely station rejection
125  count close and remote number of neighboring stations that are interpreted as signal station.
126  iStation: current station under investigation, only iterate signal stations
127  jStation: all possible neighbour stations, use all station iterator to include rejected
128  and excluded stations with may be counted as a signal station depending on xml config */
129  if (fRejectLonelyStations) {
130  for (auto& iStation : rEvent.SignalStationsRange()) {
131  unsigned int closeNeighbors = 0;
132  unsigned int remoteNeighbors = 0;
133 
134  double closeDist = 0;
135  double remoteDist = 0;
136 
137  /* check for iStation in phase 3 and use larger distances
138  We could hardcode a list of phase 3 IDs but IDs can change if station is moved.
139  Everything south of 14.6 km im PampaAmarilla is considered phase 3 */
140  if (rDetector.GetStation(iStation.GetId()).GetPosition().GetY(referenceCS) < 14.6 * km) {
141  closeDist = fLonelyIfNoneInDistancePhase3;
142  remoteDist = fLonelyIfOneInDistancePhase3;
143  } else {
144  closeDist = fLonelyIfNoneInDistance;
145  remoteDist = fLonelyIfOneInDistance;
146  }
147 
148  for (const auto& jStation : rEvent.AllStationsRange()) {
149 
150  if (iStation.GetId() == jStation.GetId())
151  continue;
152 
153  if (!UseStation(jStation))
154  continue;
155 
156  info.str("");
157  info << "checking stations: " << iStation.GetId() << ", " << jStation.GetId();
158  INFODebug(info.str());
159 
160  const double distij = (rDetector.GetStation(iStation.GetId()).GetPosition() -
161  rDetector.GetStation(jStation.GetId()).GetPosition()).GetMag();
162 
163  if (distij < closeDist)
164  ++closeNeighbors;
165  if (distij < remoteDist)
166  ++remoteNeighbors;
167  }
168 
169  if (!closeNeighbors || remoteNeighbors <= 1) {
170  iStation.SetRejectedReason(revt::eLonelyStation);
171 
172  info.str("");
173  if (!closeNeighbors)
174  info << "Station with ID " << iStation.GetId()
175  << " rejected as lonely due to # of close neighbors = " << closeNeighbors;
176  else if (remoteNeighbors <= 1)
177  info << "Station with ID " << iStation.GetId()
178  << " rejected as lonely due to # of remote neighbors = " << remoteNeighbors;
179  INFOFinal(info.str());
180  }
181  }
182  }
183 
184  return eSuccess;
185  }
186 
187 
189  RdClusterFinder::Finish()
190  {
191  return eSuccess;
192  }
193 
194 
195  bool
196  RdClusterFinder::UseStation(const revt::Station& station)
197  {
198  if (station.IsExcluded() && !fIgnoreExcludedStations)
199  return false;
200 
201  if (!CheckRejection(station))
202  return false;
203 
204  // if fIgnoreExcludedStations they are skipped already above, if not they count as signal
205  if (!(station.IsExcluded() || station.GetRecData().GetPulseFound()))
206  return false;
207 
208  return true;
209  }
210 
211 
212  bool
213  RdClusterFinder::CheckRejection(const revt::Station& station)
214  {
215  switch (fIgnoreRejectedStations)
216  {
217  case 0:
218  // skip rejected station -> eqiv. to SignalStationsRange
219  return !station.HasSignal();
220 
221  case 1:
222  // confirmed noise station - problem: double rejections not covered
223  return !(station.GetRejectedReason() == revt::eLargeTimeResidual ||
227 
228  case 2:
229  // all rejected stations will be treated as signal stations -> nothing to do
230  return true;
231 
232  default:
233  throw InvalidConfigurationException("invalid config fIgnoreRejectedStations.");
234  }
235  }
236 
237 }
Branch GetTopBranch() const
Definition: Branch.cc:63
Point object.
Definition: Point.h:32
static double GetDistanceToAxis(const utl::Vector &ShowerAxis, const utl::Point &CorePosition, const utl::Point &AntennaPosition)
computes the distance from the antenna position to the shower &quot;line&quot; defined by the core position and...
StationRecData & GetRecData()
Get station level reconstructed data.
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
Base class for exceptions arising because configuration data are not valid.
bool SortPairByDistance(const pair< double, int > x, const pair< double, int > y)
bool IsExcluded() const
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasREvent() const
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
Definition: REvent.h:190
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Iterator next(Iterator it)
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
const double km
#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
void SetRejectedReason(const unsigned long long int reason)
#define INFODebug(y)
Definition: VModule.h:163
int GetNumberOfSignalStations() const
Get number of signal stations in the event.
Definition: REvent.h:209
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
Vector object.
Definition: Vector.h:30
unsigned long long int GetRejectedReason() const
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
#define INFOFinal(y)
Definition: VModule.h:161
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
bool HasSignal() const

, generated on Tue Sep 26 2023.