CentralTriggerSimulator.cc
Go to the documentation of this file.
1 
9 #include <sdet/SDetector.h>
10 #include <sdet/SDetectorConstants.h>
11 #include <evt/Event.h>
12 #include <sevt/SEvent.h>
13 #include <sevt/SEventSimData.h>
14 #include <sevt/T3.h>
15 #include <sevt/EventTrigger.h>
16 #include <sevt/Header.h>
17 #include <sevt/Station.h>
18 #include <sevt/StationSimData.h>
19 #include <sevt/StationTriggerData.h>
20 #include <sevt/StationGPSData.h>
21 #include <sevt/PMT.h>
22 #include <sevt/PMTSimData.h>
23 #include <fevt/FEvent.h>
24 #include <fevt/Eye.h>
25 #include <fevt/EyeTriggerData.h>
26 #include <utl/ErrorLogger.h>
27 #include <utl/UTMPoint.h>
28 #include <utl/AugerUnits.h>
29 #include <utl/TabularStream.h>
30 #include <utl/String.h>
31 #include <utl/Is.h>
32 #include "XbAlgo.h"
34 
35 using namespace CentralTriggerSimulatorXb;
36 using std::map;
37 using std::vector;
38 using std::string;
39 using std::ostringstream;
40 using namespace fwk;
41 using namespace utl;
42 
43 
44 // global variables for the Xb
45 struct Station* array = nullptr;
46 int nstat = 0;
47 int maxstat = 0;
48 unsigned int second_ = 0;
49 int newt2config = 1;
50 int verbose = 0;
51 int debug = 0;
52 int trivial_algo = 180;
53 int carmen_miranda = 300;
54 
55 
56 namespace CentralTriggerSimulatorXb {
57 
58  inline
59  bool
61  {
62  //return !(station.IsInGrid() || station.IsInPair()) || station.IsDense();
63  return !(station.IsInGrid() ||
66  }
67 
68 
69  void
71  {
72  // clear memory (ain't that ugly? what is wrong with new/delete? why malloc?)
73  // memory allocated by this module
74  array = nullptr;
75 
76  if (neighbour) {
77  free(neighbour);
78  neighbour = nullptr;
79  }
80 
81  if (exists) {
82  free(exists);
83  exists = nullptr;
84  }
85  }
86 
87 }
88 
89 
92 {
93  /*
94  * These variables may need to be updated when there is
95  * an update to XbAlgo, especially changes to the
96  * reference microsecond or offset (for example, those
97  * performed in the commit to r31608). The values for
98  * fDefaultOffset and fDefaultWindow below are applied
99  * to Dense Stations to compensate for the values
100  * of offset and window from XbAlgo as applied to
101  * normal (non-dense) stations.
102  */
103  fDefaultOffset = TimeInterval(-125*microsecond);
104  fDefaultWindow = TimeInterval(30*microsecond);
105  return eSuccess;
106 }
107 
108 
111 {
112  if (!event.HasSEvent())
113  return eSuccess;
114  auto& sEvent = event.GetSEvent();
115 
116  ArrayInit();
117  XbAlgoT2Init();
118 
119  const auto& sDetector = det::Detector::GetInstance().GetSDetector();
120 
121  // collect all T2 triggers from all stations. Note that these are simulated T2s and are in StationSimData,
122  // not in sevt::Station
123  // Store all these triggers in a map, separating them by second.
124 
125  map<int, vector<t2>> t2InputSeconds;
126 
127  for (const auto& s : sEvent.StationsRange()) {
128 
129  if (!s.HasSimData())
130  continue;
131 
132  try {
133  const auto& dStation = sDetector.GetStation(s);
134  if (IsSpecialStation(dStation))
135  continue;
136  } catch (utl::NonExistentComponentException& ex) {
137  continue; // ignore when a station is not commissioned
138  }
139 
140  const auto& sSim = s.GetSimData();
141 
142  for (const auto& t : sSim.TriggerTimesRange()) {
143  const auto& trig = sSim.GetTriggerData(t);
144  if (!trig.IsT2())
145  continue;
146  const auto& gps = sSim.GetGPSData(t);
147  const int sec = gps.GetSecond();
148  if (Is(sec).NotIn(t2InputSeconds)) {
149  vector<t2> t2Input;
150  t2Input.reserve(fgMaxStations);
151  t2InputSeconds.insert(make_pair(sec, t2Input));
152  }
153  t2 t2station;
154  t2station.time/*microsecond*/ = gps.GetCorrectedNanosecond() / 1000;
155  t2station.ID = s.GetId();
156  t2station.energy = trig.IsT2TimeOverThresholdLike() ? TOTVALUE : 0;
157  t2InputSeconds[sec].push_back(t2station);
158  }
159 
160  }
161 
162  // iterate over the lists of T2s (one list per second) to find posible T3s
163 
164  for (auto& st2 : t2InputSeconds) {
165  second_ = st2.first;
166  auto& t2Input = st2.second; // not sure if copy is needed here
167 
168  const auto allT3Clusters = XbAlgoT2Process(&t2Input[0], t2Input.size());
169 
170  if (allT3Clusters.empty()) {
171  WARNING("no T3 clusters found.");
172  continue;
173  }
174 
175  ostringstream info;
176  info << "found " << allT3Clusters.size()
177  << " T3 cluster" << String::Plural(allT3Clusters)
178  << " while processing event second " << second_ << ':';
179  INFO(info);
180 
181  // Loop over T3 clusters
182  for (const auto& cluster : allT3Clusters) {
183 
184  const auto t3Cluster = XbAlgoT3Build(cluster);
185 
186  const unsigned int refSecond = t3Cluster.refSecond;
187  const int refMicroSecond = t3Cluster.refuSecond;
188  const TimeStamp trigTime(refSecond, 1000*refMicroSecond);
189 
190  sevt::T3 simT3;
191  simT3.SetTime(trigTime);
192 
193  const auto& algo = cluster.algo;
194  simT3.SetAlgorithm(algo);
195 
196  info.str("");
197  info << "T3 cluster: algorithm " << algo << ", "
198  "reference time " << trigTime << " "
199  "(" << t3Cluster.refSecond << " s, " << t3Cluster.refuSecond << " us)";
200  INFO(info);
201 
202  // for T2 stations in T3 cluster
203  for (unsigned int i = 0; i < cluster.nelem; ++i) {
204  const auto& t3Station = cluster.point[i];
205  if (!simT3.HasStation(t3Station.ID)) {
206  const int dt = int(t3Station.time) - refMicroSecond;
207  const TimeInterval offset = dt*microsecond;
208  simT3.AddStation(t3Station.ID, offset, TimeInterval(0));
209  }
210  }
211 
212  // this should go into event builder...
213  // Now add dense stations that are never included by Xb.
214  for (const auto& s : sDetector.StationsRange()) {
215  if (IsSpecialStation(s))
216  simT3.AddStation(s.GetId(), fDefaultOffset, fDefaultWindow);
217  }
218 
219  // the rest contains trigger window info (T3 stations + silents)
220  const auto& t3Stations = t3Cluster.point;
221 
222  for (const auto& station : t3Stations) {
223  if (!simT3.HasStation(station.ID))
224  simT3.AddStation(station.ID, TimeInterval(station.offset*microsecond),
225  TimeInterval(station.window*microsecond));
226  }
227 
228  if (!sEvent.HasSimData())
229  sEvent.MakeSimData();
230 
231  sEvent.GetSimData().AddT3(simT3);
232 
233  }
234 
235  // release memory malloced by XbAlgo
236  for (const auto& cluster : allT3Clusters)
237  free(cluster.point);
238 
239  }
240 
241  return eSuccess;
242 }
243 
244 
247 {
248  MemoryCleanup();
249  return eSuccess;
250 }
251 
252 
253 void
255 {
256  // reserve enough memory to avoid copying on resize
257  fStations.clear();
258  fStations.reserve(fgMaxStations);
259 
260  const auto& sDetector = det::Detector::GetInstance().GetSDetector();
261 
262  Station s;
263  int maxId = 0;
264  for (const auto& station : sDetector.StationsRange()) {
265  if (!IsSpecialStation(station)) {
266  const int sId = station.GetId();
267  s.Id = sId;
268  if (sId > maxId)
269  maxId = sId;
270  const utl::UTMPoint position(station.GetPosition(), utl::ReferenceEllipsoid::eWGS84);
271  s.Northing = position.GetNorthing();
272  s.Easting = position.GetEasting();
273  s.Altitude = position.GetHeight();
274  fStations.push_back(s);
275  }
276  }
277 
278  // add trailling station
279  s.Id = -1;
280  s.Northing = 0;
281  s.Easting = 0;
282  s.Altitude = 0;
283  fStations.push_back(s);
284 
285  // fill global variables
286  maxstat = maxId;
287  nstat = fStations.size() - 1;
288  array = &fStations[0];
289 
290  BuildNeighbour();
291 }
struct Station * array
IsProxy< T > Is(const T &x)
Definition: Is.h:46
Detector description interface for Station-related data.
int newt2config
void SetAlgorithm(const std::string &algo)
Set the trigger algorithm.
Definition: T3.h:69
double Northing
Definition: XbArray.h:8
bool HasStation(const int id) const
Definition: T3.h:80
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
This class contains the basic information to build a surface event.
Definition: T3.h:36
void SetTime(const utl::TimeStamp &stamp)
Set the trigger time stamp.
Definition: T3.h:63
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
bool IsInGrid(const SDetectorConstants::GridIndex index=SDetectorConstants::eStandard) const
Tells whether the station is in the regular triangular grid.
int trivial_algo
int debug
Definition: dump1090.h:276
Base class for exceptions trying to access non-existing components.
int time
Definition: XbT2.h:9
int Id
Definition: XbArray.h:11
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
const char * Plural(const T n)
Definition: String.h:104
char * exists
Definition: XbArray.cc:12
constexpr double s
Definition: AugerUnits.h:163
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
void XbAlgoT2Init()
initialisation of XbAlgoT2 algorithm, building fake station and resetting histograms ...
Definition: XbAlgo.cc:37
int carmen_miranda
vector< t2list > XbAlgoT2Process(struct t2 *input, int nt2)
Main function, processing T2 and returning clusters of T2.
Definition: XbAlgo.cc:153
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
#define TOTVALUE
Definition: XbAlgo.h:33
unsigned short ID
Definition: XbT2.h:10
unsigned short energy
Definition: XbT2.h:11
double Easting
Definition: XbArray.h:9
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void BuildNeighbour()
Definition: XbArray.cc:23
a second level trigger
Definition: XbT2.h:8
t3 XbAlgoT3Build(struct t2list in)
builds t3 from a list of t2
Definition: XbAlgo.cc:434
bool IsSpecialStation(const sdet::Station &station)
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
double Altitude
Definition: XbArray.h:10
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
unsigned int second_
char * neighbour
Definition: XbArray.cc:10
constexpr double microsecond
Definition: AugerUnits.h:147
bool HasSEvent() const
void AddStation(const int id, const utl::TimeInterval &offset, const utl::TimeInterval &window)
Add a station to request data, specifying offset and window size.
Definition: T3.cc:13
Definition: XbArray.h:7

, generated on Tue Sep 26 2023.