Sd5T5Tester.cc
Go to the documentation of this file.
1 #include "Sd5T5Tester.h"
2 #include <utl/ErrorLogger.h>
3 #include <utl/AugerException.h>
4 #include <utl/Point.h>
5 #include <utl/Vector.h>
6 #include <utl/CoordinateSystemPtr.h>
7 #include <utl/AugerUnits.h>
8 #include <utl/Branch.h>
9 
10 #include <fwk/CentralConfig.h>
11 
12 #include <evt/Event.h>
13 #include <evt/ShowerRecData.h>
14 #include <evt/ShowerSRecData.h>
15 #include <sevt/SEvent.h>
16 #include <sevt/Station.h>
17 #include <det/Detector.h>
18 #include <sdet/SDetector.h>
19 #include <sdet/Station.h>
20 
21 #include <sstream>
22 #include <iostream>
23 #include <vector>
24 
25 using namespace std;
26 using namespace utl;
27 using namespace fwk;
28 
29 #define DEBUG(x) std::cout << #x << " " << x << std::endl
30 
31 
32 namespace Sd5T5Tester {
33 
34  static const int kNone = -1;
35 
36 
39  {
40  // initialize internal variables
41  fCounter = 0;
42  for (int i = 0; i < 7; ++i)
43  fCrownId[i] = kNone;
44 
45  // get constants to compute first crown from SdEventSelector
46  CentralConfig* const cc = CentralConfig::GetInstance();
47  Branch topB = cc->GetTopBranch("SdEventSelector");
48 
49  topB.GetChild("FirstCrownDistanceRange").GetData(fFirstCrownDistanceRange);
50 
51  return eSuccess;
52  }
53 
54 
56  Sd5T5Tester::Run(evt::Event& event)
57  {
58  if (!event.HasSEvent() ||
59  !event.HasRecShower() ||
60  !event.GetRecShower().HasSRecShower())
61  return eContinueLoop;
62 
63  sevt::SEvent& sEvent = event.GetSEvent();
64 
65  ostringstream msg;
66  msg << "Counter = " << fCounter;
67  INFO(msg);
68 
69  if (fCounter == 0) {
70  // check whether we should use this event
71  // and then reconstruct unmodified event
72 
73  const sdet::Station& sCenter = GetHottestStation(sEvent);
74 
75  const Crown crown = GetCrown(sEvent, sCenter);
76 
77  // skip events which already have missing stations in first or second crow
78  if (!IsAccepted(sEvent, crown))
79  return eBreakLoop;
80 
81  UpdateFirstCrown(sCenter, crown);
82  // continue to reconstruct unmodified event
83 
84  ++fCounter;
85  return eSuccess;
86  }
87 
88  if (fCounter == 8) {
89  // we now tried all possibilities for
90  // current event, now exit loop and
91  // start anew
92  fCounter = 0;
93  return eBreakLoop;
94  }
95 
96  // modify event for fCounter 1 to 7
97 
98  // modify Auger ID to mark the modified events
99  ostringstream augerId;
100  augerId << event.GetHeader().GetId() << "-" << fCounter;
101  event.GetHeader().SetId(augerId.str());
102 
103  // turn off next station, reactivate others
104  for (int iStation = 1; iStation <= 7; ++iStation) {
105  const int stationId = fCrownId[iStation - 1];
106  if (stationId == kNone)
107  continue;
108 
109  sevt::Station& station = event.GetSEvent().GetStation(stationId);
110 
111  if (iStation == fCounter) {
112  ostringstream msg;
113  msg << "Disabling station " << stationId;
114  INFO(msg);
116  } else
117  station.ClearRejectionStatus();
118  }
119 
120  // count up for next iteration
121  ++fCounter;
122  return eSuccess;
123  }
124 
125 
127  Sd5T5Tester::Finish()
128  {
129  return eSuccess;
130  }
131 
132 
133  const sdet::Station&
134  Sd5T5Tester::GetHottestStation(const sevt::SEvent& sEvent)
135  const
136  {
137  // find candidate station with largest signal
138 
139  const sevt::Station* maxStation = 0;
140 
141  double maxSignal = 0;
143  sEnd = sEvent.CandidateStationsEnd(); sIt != sEnd; ++sIt) {
144  const double signal = sIt->GetRecData().GetTotalSignal();
145  if (maxSignal < signal) {
146  maxSignal = signal;
147  maxStation = &(*sIt);
148  }
149  }
150 
151  if (!maxStation)
152  throw utl::DoesNotComputeException("Sd5T5Tester::GetHottestStation failed");
153 
154  return det::Detector::GetInstance().GetSDetector().GetStation(*maxStation);
155  }
156 
157 
159  Sd5T5Tester::GetCrown(const sevt::SEvent& sEvent,
160  const sdet::Station& sCenter)
161  const
162  {
163  // find direct neighbours that form a hexagon
164  // aka "crown" around centered station,
165  // following code in SdEventSelector
166 
167  Crown result;
168 
169  CoordinateSystemPtr siteCS = det::Detector::GetInstance().GetSiteCoordinateSystem();
170 
171  // assign station to index according to its orientation
172  const sdet::SDetector& sDet = det::Detector::GetInstance().GetSDetector();
174  sEnd = sEvent.StationsEnd(); sIt != sEnd; ++sIt) {
175  if (!(sIt->IsCandidate() || sIt->IsSilent()))
176  continue;
177 
178  const sdet::Station& s = sDet.GetStation(*sIt);
179 
180  const Vector r = s.GetPosition() - sCenter.GetPosition();
181 
182  const double dist = r.GetMag();
183  if (dist < fFirstCrownDistanceRange[0] ||
184  fFirstCrownDistanceRange[1] < dist)
185  continue;
186 
187  result.push_back(&s);
188  }
189 
190  return result;
191  }
192 
193 
194  bool
195  Sd5T5Tester::IsAccepted(const sevt::SEvent& sev, const Crown& crown)
196  const
197  {
198  size_t nCandidates = 0;
200  end = sev.CandidateStationsEnd(); it != end; ++it)
201  ++nCandidates;
202 
203  if (nCandidates < 4)
204  return false;
205 
206  if (crown.size() != 6)
207  return false;
208 
209  for (Crown::const_iterator it = crown.begin();
210  it != crown.end(); ++it) {
211  const Crown c = GetCrown(sev, **it);
212  if (c.size() != 6)
213  return false;
214  }
215 
216  return true;
217  }
218 
219 
220  void
221  Sd5T5Tester::UpdateFirstCrown(const sdet::Station& sCenter, const Crown& crown)
222  {
223  // find direct neighbours that form a hexagon
224  // aka "crown" around centered station,
225  // following code in SdEventSelector
226 
227  // reset to list with dummy values
228  for (int i = 0; i < 7; ++i)
229  fCrownId[i] = kNone;
230 
231  fCrownId[6] = sCenter.GetId();
232 
233  CoordinateSystemPtr siteCS = det::Detector::GetInstance().GetSiteCoordinateSystem();
234 
235  for (size_t iS = 0; iS < 6; ++iS) {
236  const sdet::Station& sCrown = *crown[iS];
237 
238  const Vector r = sCrown.GetPosition() - sCenter.GetPosition();
239 
240  const int phi = r.GetPhi(siteCS) / degree;
241  const size_t index = ((phi - 30 + 720) % 360) / 60;
242 
243  fCrownId[index] = sCrown.GetId();
244  }
245  }
246 
247 }
StationIterator StationsEnd()
End of all stations.
Definition: SEvent.h:59
const double degree
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
Detector description interface for Station-related data.
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
sevt::StationRecData & GetRecData()
Get station level reconstructed data.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
int crown(double x1, double x2, double y1, double y2)
Definition: XbArray.cc:14
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double GetMag() const
Definition: Vector.h:58
utl::Point GetPosition() const
Tank position.
CandidateStationIterator CandidateStationsBegin()
Definition: SEvent.h:72
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
class to hold data at Station level
constexpr double s
Definition: AugerUnits.h:163
void SetRejected(const int reason)
Set rejected station flag.
const Data result[]
double GetTotalSignal() const
Total integrated signal in VEM unit, averaged over pmts.
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Base class for inconsistency/illogicality exceptions.
std::vector< const sdet::Station * > Crown
Definition: Sd5T5Tester.h:36
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
StationIterator StationsBegin()
Beginning of all stations.
Definition: SEvent.h:57
Vector object.
Definition: Vector.h:30
Detector description interface for SDetector-related data.
Definition: SDetector.h:42
Main configuration utility.
Definition: CentralConfig.h:51
CandidateStationIterator CandidateStationsEnd()
Definition: SEvent.h:74
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: SDetector.cc:192
int GetId() const
Station ID.
boost::indirect_iterator< InternalConstStationIterator, const Station & > ConstStationIterator
Definition: SEvent.h:54
bool HasSEvent() const
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
boost::filter_iterator< CandidateStationFilter, ConstStationIterator > ConstCandidateStationIterator
Definition: SEvent.h:70

, generated on Tue Sep 26 2023.