EventStationPositionsManager.cc
Go to the documentation of this file.
1 #include <sdet/EventStationPositionsManager.h>
2 
3 #include <fwk/RunController.h>
4 #include <evt/Event.h>
5 #include <sevt/SEvent.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/Point.h>
8 
9 #include <AugerEvent.h>
10 #include <IoSdData.h>
11 
12 #include <det/Detector.h>
13 #include <sdet/SDetector.h>
14 #include <sdet/SManagerRegister.h> // needed for registration macro
15 
16 using namespace std;
17 using namespace fwk;
18 using namespace evt;
19 using namespace sevt;
20 using namespace sdet;
21 using namespace det;
22 using namespace utl;
23 
24 REGISTER_S_MANAGER("EventStationPositionsManager", EventStationPositionsManager)
25 
26 
27 namespace sdet {
28 
29  const string outdatedMessage =
30  "Station list source is outdated or no real manager present";
31 
32 
33  void
34  EventStationPositionsManager::Init(const string& configLink)
35  {
36  // call shadowed VManager::Init() first
37  VManager::Init(configLink);
38 
39  fBranch.GetChild("Band").GetData(fBand);
40  fBranch.GetChild("Zone").GetData(fZone);
41  fBranch.GetChild("Ellipsoid").GetData(fEllipsoid);
42  /*
43  * If the IsUUB property does not exist (as is the case
44  * for the pre-upgrade XML), set IsUUB to 0.
45  */
46  if (fBranch.GetChild("IsUUB"))
47  fBranch.GetChild("IsUUB").GetData(fIsUUB);
48  else
49  fIsUUB = 0;
50  fBranch.GetChild("Commission").GetData(fCommission);
51  fBranch.GetChild("CommissionUUB").GetData(fCommissionUUB);
52  fBranch.GetChild("Decommission").GetData(fDecommission);
53  }
54 
55 
56  inline
57  void
58  UTMToAxes(const double easting, const double northing,
59  double& axis1, double& axis2)
60  {
61  axis1 = 6.666970851e-4*easting + 3.849861836e-4*northing - 2559.709820;
62  axis2 = 6.082521603e-8*easting + 7.698225084e-4*northing - 4592.669600;
63  }
64 
65 
66  inline
67  void
68  AxesToUTM(const double axis1, const double axis2,
69  double& easting, double& northing)
70  {
71  easting = 394392 + 1500*axis1 - 750.146*axis2;
72  northing = 5965850 - 0.118518*axis1 + 1299.06*axis2;
73  }
74 
75 
76  // Generic data getters
77 
78  template<>
80  EventStationPositionsManager::GetStationData<>(int& returnData,
81  const string& componentProperty,
82  const string& componentName,
83  const IndexMap& componentIndex)
84  const
85  {
86  if (componentName != "stationList")
87  return eNotFound;
88 
89  if (componentProperty == "axis1" ||
90  componentProperty == "axis2") {
91 
92  double easting;
93  GetData(easting, "easting", componentName, componentIndex);
94  double northing;
95  GetData(northing, "northing", componentName, componentIndex);
96  double axis1;
97  double axis2;
98  UTMToAxes(easting, northing, axis1, axis2);
99 
100  returnData = int(round(componentProperty == "axis1" ? axis1 : axis2));
101 
102  ostringstream warn;
103  warn << outdatedMessage << ", guessing station with id="
104  << FindComponent<string>("stationId", componentIndex) << " has "
105  << componentProperty << '=' << returnData;
106  WARNING(warn);
107  return eFound;
108 
109  } else if (componentProperty == "groupId") {
110 
111  ostringstream warn;
112  warn << outdatedMessage << ", guessing "
113  << componentProperty << " for station with id="
114  << FindComponent<string>("stationId", componentIndex) << " is impossible!";
115  WARNING(warn);
116  returnData = 0;
117  return eFound;
118 
119  } else if (componentProperty == "zone") {
120 
121  returnData = fZone;
122  return eFound;
123 
124  } else if (componentProperty == "isUUB") {
125 
126  returnData = fIsUUB;
127  return eFound;
128  }
129 
130  return eNotFound;
131  }
132 
133 
134  template<>
136  EventStationPositionsManager::GetStationData(double& returnData,
137  const string& componentProperty,
138  const string& componentName,
139  const IndexMap& componentIndex)
140  const
141  {
142  if (componentName != "stationList")
143  return eNotFound;
144 
145  if (componentProperty == "northing" ||
146  componentProperty == "easting" ||
147  componentProperty == "altitude") {
148 
149  const IoSdStation* const st = FindStation(componentIndex);
150 
151  ostringstream message;
152  message << outdatedMessage;
153 
154  if (st) {
155  returnData = (componentProperty == "northing") ? st->northing() :
156  (componentProperty == "easting" ? st->easting() : st->altitude());
157  message << ", taking " << componentProperty << '=' << returnData << " "
158  "for station id=" << st->id() << " from raw event";
159  WARNING(message);
160  return eFound;
161  }
162 
163  message << ", station with id=" << FindComponent<string>("stationId", componentIndex)
164  << " can not be found in raw event either";
165  ERROR(message);
166  return eNotFound;
167 
168  } else if (componentProperty == "axis1" ||
169  componentProperty == "axis2") {
170 
171  int axis = 0;
172  const Status status =
173  GetStationData(axis, componentProperty, componentName, componentIndex);
174  returnData = axis;
175  return status;
176 
177  }
178 
179  return eNotFound;
180  }
181 
182 
183  template<>
185  EventStationPositionsManager::GetStationData(string& returnData,
186  const string& componentProperty,
187  const string& componentName,
188  const IndexMap& componentIndex)
189  const
190  {
191  if (componentName != "stationList")
192  return eNotFound;
193 
194  if (componentProperty == "name") {
195 
196  const auto st = FindStation(componentIndex);
197 
198  ostringstream message;
199  message << outdatedMessage;
200 
201  if (st) {
202  returnData = st->name();
203  message << ", taking " << componentProperty << "='" << returnData << "' "
204  "for station id=" << st->id() << " from raw event";
205  WARNING(message);
206  return eFound;
207  }
208 
209  message << ", station with id=" << FindComponent<string>("stationId", componentIndex)
210  << " can not be found in raw event either";
211  ERROR(message);
212  return eNotFound;
213 
214  } else if (componentProperty == "commission") {
215 
216  returnData = fCommission;
217  return eFound;
218 
219  } else if (componentProperty == "commissionUUB") {
220 
221  returnData = fCommissionUUB;
222  return eFound;
223 
224  } else if (componentProperty == "decommission") {
225 
226  returnData = fDecommission;
227  return eFound;
228 
229  } else if (componentProperty == "band") {
230 
231  returnData = fBand;
232  return eFound;
233 
234  } else if (componentProperty == "ellipsoid") {
235 
236  returnData = fEllipsoid;
237  return eFound;
238 
239  }
240 
241  return eNotFound;
242  }
243 
244 
245  template<>
247  EventStationPositionsManager::GetStationData(vector<int>& returnData,
248  const string& componentProperty,
249  const string& componentName,
250  const IndexMap& /* componentIndex */)
251  const
252  {
253  if (componentName != "stationList")
254  return eNotFound;
255 
256  if (componentProperty == "stationGroup") {
257  ostringstream message;
258  message << outdatedMessage << ", station will not be part of any group";
259  WARNING(message);
260  returnData.clear();
261  return eFound;
262  }
263 
264  return eNotFound;
265  }
266 
267 
268  template<>
270  EventStationPositionsManager::GetStationData(vector<bool>& returnData,
271  const string& componentProperty,
272  const string& componentName,
273  const IndexMap& componentIndex)
274  const
275  {
276  if (componentName == "stationList" && componentProperty == "inGrid") {
277 
278  const int sId = FindComponent<int>("stationId", componentIndex);
279 
280  const auto& sDetector = det::Detector::GetInstance().GetSDetector();
281  const auto& pos = sDetector.GetStation(sId).GetPosition();
282  vector<bool> grid(SDetectorConstants::kGridIndexSize);
283  for (const auto& s : sDetector.AllStationsRange()) {
284  if (s.GetId() == sId /* || !s.IsInGrid(SDetectorConstants::eAny)) */)
285  continue;
286 
287  const double d = (pos - s.GetPosition()).GetMag();
288  if (d < 100*meter && s.GetId() < sId) {
289  // looks like doublet/triplet
290  grid.clear();
291  break;
292  } else if (fabs(d - 433*meter) < 100*meter) {
293  // looks like 433 m infill
294  grid[SDetectorConstants::eInfill433] = true;
295  } else if (fabs(d - 750*meter) < 100*meter) {
296  // looks like 750 m infill
297  grid[SDetectorConstants::eInfill750] = true;
298  } else if (fabs(d - 1500*meter) < 150*meter) {
299  // looks like standard array
300  grid[SDetectorConstants::eStandard] = true;
301  }
302  }
303 
304  ostringstream message;
305  message << "guessed inGrid property from distances to neighbours =";
306  if (grid.empty())
307  message << " 0";
308  else {
309  for (size_t i = 0, n = grid.size(); i < n; ++i) {
310  if (grid[i])
311  message << ' ' << (i + 1);
312  }
313  }
314  WARNING(message);
315 
316  returnData = grid;
317 
318  return eFound;
319  }
320 
321  return eNotFound;
322  }
323 
324 
325  const IoSdStation*
326  EventStationPositionsManager::FindStation(const int id)
327  const
328  {
329  const auto& event = RunController::GetInstance().GetCurrentEvent();
330 
331  if (!event.HasRawEvent()) {
332  ERROR("Event has no raw event!");
333  return 0;
334  }
335 
336  const auto& rawEvent = event.GetRawEvent();
337 
338  if (!rawEvent.HasSd()) {
339  ERROR("Event has no raw SD event!");
340  return 0;
341  }
342 
343  const auto& stations = rawEvent.Sd().Stations;
344 
345  for (const auto& s : stations)
346  if (int(s.id()) == id)
347  return &s;
348 
349  return nullptr;
350  }
351 
352 }
Manager to retrieve station positions from the raw event.
void AxesToUTM(const double axis1, const double axis2, double &easting, double &northing)
void UTMToAxes(const double easting, const double northing, double &axis1, double &axis2)
const double meter
Definition: GalacticUnits.h:29
void Init()
Initialise the registry.
constexpr double s
Definition: AugerUnits.h:163
#define REGISTER_S_MANAGER(_name_, _Type_)
const unsigned char kGridIndexSize
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
const string outdatedMessage
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.