CentralTriggerEventBuilder.cc
Go to the documentation of this file.
1 
10 
11 #include <evt/Event.h>
12 
13 #include <sevt/SEvent.h>
14 #include <sevt/SEventSimData.h>
15 #include <sevt/T3.h>
16 #include <sevt/EventTrigger.h>
17 #include <sevt/Header.h>
18 #include <sevt/Station.h>
19 #include <sevt/StationSimData.h>
20 #include <sevt/StationTriggerData.h>
21 #include <sevt/StationGPSData.h>
22 #include <sevt/PMT.h>
23 #include <sevt/PMTSimData.h>
24 #include <sevt/SEventSimData.h>
25 
26 #include <fevt/FEvent.h>
27 #include <fevt/Eye.h>
28 #include <fevt/EyeTriggerData.h>
29 
30 #include <sdet/SDetector.h>
31 
32 #include <utl/ErrorLogger.h>
33 #include <utl/String.h>
34 #include <utl/UTMPoint.h>
35 #include <utl/AugerUnits.h>
36 #include <utl/TabularStream.h>
37 
38 #include <fwk/CentralConfig.h>
39 
40 using namespace CentralTriggerEventBuilderNS;
41 using namespace std;
42 using namespace fwk;
43 using namespace utl;
44 
45 
48 {
49  fSDetector = &det::Detector::GetInstance().GetSDetector();
50  fDefaultWindow = TimeInterval(200*microsecond);
51  fDefaultOffset = TimeInterval(0);
52 
53  Branch topB = CentralConfig::GetInstance()->GetTopBranch("CentralTriggerEventBuilder");
54  topB.GetChild("ForceEventBuildWithoutT3").GetData(fForceEventBuildWithoutT3);
55 
56  return eSuccess;
57 }
58 
59 
62 {
63  return BuildEvent(event);
64 }
65 
66 
69 {
70  return eSuccess;
71 }
72 
73 
76 {
77  if (!event.HasSEvent())
78  return eSuccess;
79  sevt::SEvent& sEvent = event.GetSEvent();
80 
81  // CHECK for FD T3s and count them.
82  // REMEMBER the earlierst FD T3 time, as eventual SD trigger time !
83  int nTrigEyes = 0;
84  TimeStamp t3Time;
85  if (event.HasFEvent()) {
86  const fevt::FEvent& fEvent = event.GetFEvent();
87 
89  eyeIt != fEvent.EyesEnd(fevt::ComponentSelector::eHasData); ++eyeIt)
90 
91  if (eyeIt->HasTriggerData() && eyeIt->GetTriggerData().IsT3Accepted()) {
92  ++nTrigEyes;
93  const TimeStamp& eyeT3time = eyeIt->GetTriggerData().GetT3Time();
94  if (!t3Time || eyeT3time < t3Time)
95  t3Time = eyeT3time;
96  }
97  }
98 
99  string initAlgo;
100  switch (nTrigEyes) {
101  case 1:
102  initAlgo = "FD";
103  break;
104  case 2:
105  initAlgo = "Stereo";
106  break;
107  case 3:
108  initAlgo = "Trio";
109  break;
110  case 4:
111  initAlgo = "Quad";
112  break;
113  default:
114  initAlgo = "None";
115  break;
116  }
117 
118  // No T3 at all
119  if (initAlgo == "None" &&
120  !(sEvent.HasSimData() && sEvent.GetSimData().T3sBegin() != sEvent.GetSimData().T3sEnd())) {
121 
122  if (!fForceEventBuildWithoutT3) {
123  INFO("no FD trigger and no SD T3, continuing");
124  return eContinueLoop;
125  }
126 
127  initAlgo = "Forced";
128  INFO("No T3. As specified, forcing build of event in spite of no T3.");
129  t3Time = det::Detector::GetInstance().GetTime();
130 
131  }
132 
133  if (!sEvent.HasTrigger())
134  sEvent.MakeTrigger();
135  sevt::EventTrigger& evTrig = sEvent.GetTrigger();
136  evTrig.SetSender("SSimulation");
137  evTrig.SetSDPAngle(0);
138 
139  // Decide the time of the event and type/id
140  TimeStamp trigTime;
141  sevt::T3 t3;
142 
143  if (initAlgo != "None") { // Either FD T3 or forced build of event without T3
144  evTrig.SetTime(t3Time);
145  evTrig.SetAlgorithm(initAlgo);
146 
147  // should we really add the entire array for FD T3 ?
148 
149  for (sdet::SDetector::StationIterator sIt = fSDetector->StationsBegin();
150  sIt != fSDetector->StationsEnd(); ++sIt)
151  t3.AddStation(sIt->GetId(), fDefaultOffset, fDefaultWindow);
152 
153  ostringstream info;
154  info << "Trigger (FD or forced) time set to: " << t3Time;
155  INFO(info);
156  } else { // SD T3
157  const auto& simData = sEvent.GetSimData();
158  const int nT3 = simData.GetNumberOfT3s();
159  const auto begin = simData.T3sBegin();
160  const auto end = simData.T3sEnd();
161  {
162  ostringstream info;
163  info << "Got " << nT3 << " T3 trigger" << (nT3 != 1 ? "s" : "") << ':';
164  unsigned int it3 = 0;
165  for (auto t3It = begin; t3It != end; ++t3It) {
166  info << "\n#" << ++it3 << " n=" << t3It->GetNumberOfStations() << " (" << t3It->GetAlgorithm() << "):\n";
167  TabularStream tab("l|l|l");
168  tab << "ID" << endc << "offset" << endc << "window" << endr << hline;
169  for (auto sIt = t3It->StationsBegin(); sIt != t3It->StationsEnd(); ++sIt)
170  tab << sIt->fId << endc << sIt->fOffset/microsecond << endc << sIt->fWindow/microsecond << endr;
171  tab << delr;
172  info << tab;
173  }
174  INFO(info);
175  }
176  auto t3It = begin;
177  t3 = *t3It++;
178  if (nT3 > 1) {
179  INFO("Merging.");
180  t3.SetAlgorithm("Merged");
181  for ( ; t3It != end; t3It++)
182  for (auto sIt = t3.StationsBegin(), end = t3.StationsEnd(); sIt != end; ++sIt)
183  t3.AddStation(sIt->fId, sIt->fOffset, sIt->fWindow);
184  }
185  if (t3) {
186  evTrig.SetTime(t3.GetTime());
187  evTrig.SetAlgorithm(t3.GetAlgorithm());
188  {
189  ostringstream info;
190  info << "SD Trigger time set to: " << sEvent.GetTrigger().GetTime();
191  INFO(info);
192  }
193  } else
194  WARNING("No valid trigger combination found.");
195  }
196 
197  evTrig.SetId(sEvent.GetHeader().GetId());
198  evTrig.SetPreviousId(event.HasFEvent() ? event.GetFEvent().GetHeader().GetId() : 0);
199 
200  vector<int> addedTOTStations;
201  vector<int> addedMopsStations;
202  vector<int> addedRDStations;
203  vector<int> addedT1Stations;
204  vector<int> addedT2Stations;
205  // Iterate over station checking for traces, copying everything to sevt::Station
206  int numStations = 0;
207  int errorZeroStations = 0;
208 
209  bool outOfWindowStations = false;
210  TabularStream tab("r|rl");
211  tab << "station" << endc << "diff" << endc << " [ns]" << endr << hline;
212 
213  for (sevt::T3::StationIterator t3sIt = t3.StationsBegin();
214  t3sIt != t3.StationsEnd(); ++t3sIt) {
215 
216  const int sId = t3sIt->fId;
217 
218  const TimeStamp start = evTrig.GetTime() + (t3sIt->fOffset - t3sIt->fWindow);
219  const TimeStamp end = start + 2.*t3sIt->fWindow + TimeInterval(1*microsecond);
220 
221  if (!sEvent.HasStation(sId)) {
222  ostringstream info;
223  info << "skipping station " << sId;
224  INFO(info);
225  continue;
226  }
227 
228  sevt::Station& station = sEvent.GetStation(sId);
229 
230  if (!station.HasSimData()) {
231  ostringstream info;
232  info << "station " << station.GetId() << " does not have sim data";
233  INFO(info);
234  continue;
235  }
236 
237  // Trigger/GPS data are created and assigned even if they are not T1/T2.
238  // If later it happens that there is a T1/T2, the error code is changed
239  // The loop continues with the next station after the first T1/T2 found.
240  if (!station.HasTriggerData())
241  station.MakeTriggerData();
242  sevt::StationTriggerData& sTrig = station.GetTriggerData();
244  sTrig.SetOffsetMicroSecond(t3sIt->fOffset.GetInterval() / microsecond);
245  sTrig.SetWindowMicroSecond(t3sIt->fWindow.GetInterval() / microsecond);
246 
247  ++numStations;
248 
249  // If the station does not have GPS data it shouldn't have triggers,
250  // since they are _supposed_ to be created at the same time. However,
251  // there is no way to enforce that. It is possible to have a tank trigger
252  // simulator without gps simulator, in which case the gps data is created
253  // here. Might this cause trouble?
254  if (!station.HasGPSData()) {
255  //WARNING("Creating GPS data!");
256  station.MakeGPSData();
257  sevt::StationGPSData& gpsData = station.GetGPSData();
258 
259  const int offset = 0;
260  const int current100 = 100000000;
261  const int next100 = 100000000;
262  const int current40 = 40000000;
263  const int next40 = 40000000;
264  const int previousST = 0;
265  const int nextST = 0;
266  const int currentST = 0;
267  const int second = evTrig.GetTime().GetGPSSecond();
268  const int tickFall = 0;
269  const int tick =
270  (unsigned int)(evTrig.GetTime().GetGPSNanoSecond() /
271  (next100 > 0 ? (1e9 + nextST - currentST)/next100 : 10.0));
272  gpsData.SetSecond(second);
273  gpsData.SetCurrent100(current100);
274  gpsData.SetNext100(next100);
275  gpsData.SetCurrent40(current40);
276  gpsData.SetNext40(next40);
277  gpsData.SetPreviousST(previousST);
278  gpsData.SetNextST(nextST);
279  gpsData.SetCurrentST(currentST);
280  gpsData.SetOffset(offset);
281  gpsData.SetTick(tick);
282  gpsData.SetTickFall(tickFall);
283  }
284 
285  sevt::StationSimData& stationSimData = station.GetSimData();
286 
288  tIt != stationSimData.TriggerTimesEnd(); ++tIt) {
289 
290  const TimeStamp& trigTime = *tIt;
291 
292  if (trigTime < start || trigTime > end) {
293  outOfWindowStations = true;
294  const bool early = (trigTime < start);
295  tab << station.GetId() << ' ' << endc
296  << ' ' << (early ? (start - trigTime) : (trigTime - end)) / nanosecond << endc
297  << (early ? " early" : " late") << endr;
298  } else {
299  // If it is a T1/T2, copy the traces to the station and set the error code
300  const sevt::StationTriggerData& candidateTrigger = stationSimData.GetTriggerData(trigTime);
301  if (candidateTrigger.IsT1() || candidateTrigger.IsT2()) {
302  ++errorZeroStations;
303  sTrig = candidateTrigger;
304  sTrig.SetOffsetMicroSecond(t3sIt->fOffset.GetInterval() / microsecond);
305  sTrig.SetWindowMicroSecond(t3sIt->fWindow.GetInterval() / microsecond);
307 
308  station.GetGPSData() = stationSimData.GetGPSData(trigTime);
309  for (auto pmtIt = station.PMTsBegin(sdet::PMTConstants::eAnyType);
310  pmtIt != station.PMTsEnd(sdet::PMTConstants::eAnyType); ++pmtIt) {
311 
312  if (!pmtIt->HasSimData()) {
313  ostringstream warn;
314  warn << "Station " << sId << ", "
315  "pmt " << pmtIt->GetId() << " does not have sim data but is still in the event?";
316 
317  // it will warn for sPMT and scintillator PMT from *accidental stations*
318  // as SdAccidentalInjectorKG only uses eWaterCherenkovLarge PMTs.
319  // PMTSimData() is made in G4StationSimulatorOG for all PMTs.
320  WARNING(warn);
321  continue;
322  }
323 
324  const sevt::PMTSimData& simData = pmtIt->GetSimData();
325 
326  // this is needed to avoid NonExistentComponentException in case sPMT and/or scintillator PMT
327  // have no FADC traces (no photoelectrons produced)
328  if (!simData.HasFADCTrace())
329  continue;
330 
332  for (auto simIt = simData.FADCTriggeredTracesBegin(trigTime, gain),
333  end = simData.FADCTriggeredTracesEnd(trigTime, gain);
334  simIt != end; ++simIt) {
335  const auto label = static_cast<sevt::StationConstants::SignalComponent>(simIt->GetLabel());
336  if (!pmtIt->HasFADCTrace(label))
337  pmtIt->MakeFADCTrace(label);
338  pmtIt->GetFADCTrace(gain, label) = simIt->GetTrace();
339  }
340  // repeating the whole thing with double-valued traces
341  for (auto simIt = simData.FADCTriggeredTracesDBegin(trigTime, gain),
342  end = simData.FADCTriggeredTracesDEnd(trigTime, gain);
343  simIt != end; ++simIt) {
344  const auto label = static_cast<sevt::StationConstants::SignalComponent>(simIt->GetLabel());
345  if (!pmtIt->HasFADCTrace(label))
346  pmtIt->MakeFADCTrace(label);
347  pmtIt->GetFADCTraceD(gain, label) = simIt->GetTrace();
348  }
349  }
350 
351  }
352 
354  addedTOTStations.push_back(sId);
355  else if (sTrig.IsMultiplicityOfPositiveSteps())
356  addedMopsStations.push_back(sId);
357  else if (sTrig.IsRDThreshold())
358  addedRDStations.push_back(sId);
359  else if (sTrig.IsT2Threshold())
360  addedT2Stations.push_back(sId);
361  else if (sTrig.IsT1Threshold())
362  addedT1Stations.push_back(sId);
363 
364  break; // important, this is to take only the first trigger in the time window.
365  }
366  }
367  }
368  }
369 
370  if (outOfWindowStations) {
371  tab << delr;
372  cerr << tab << endl;
373  }
374 
375  // this value includes stations that are part of central trigger
376  evTrig.SetNStations(numStations);
377  sEvent.SetNErrorZeroStations(errorZeroStations);
378 
379  if (!addedTOTStations.empty() ||
380  !addedMopsStations.empty() ||
381  !addedRDStations.empty() ||
382  !addedT1Stations.empty() ||
383  !addedT2Stations.empty()) {
384  ostringstream info;
385  info << "\nAdding stations:";
386  if (!addedTOTStations.empty())
387  info << '\n' << String::OfSortedIds(addedTOTStations) << " as TOT";
388  if (!addedMopsStations.empty())
389  info << '\n' << String::OfSortedIds(addedMopsStations) << " as MoPS";
390  if (!addedRDStations.empty())
391  info << '\n' << String::OfSortedIds(addedRDStations) << " as RD Threshold";
392  if (!addedT1Stations.empty())
393  info << '\n' << String::OfSortedIds(addedT1Stations) << " as T1 Threshold";
394  if (!addedT2Stations.empty())
395  info << '\n' << String::OfSortedIds(addedT2Stations) << " as T2 Threshold";
396  INFO(info);
397  }
398 
399  return eSuccess;
400 }
StationIterator StationsEnd() const
Iterator over the list of T3Stations in T3.
Definition: T3.h:98
Branch GetTopBranch() const
Definition: Branch.cc:63
bool IsTimeOverThresholdDeconvoluted() const
Time Over Threshold deconvoluted.
Station Level Simulated Data
int GetId() const
Get the station Id.
bool HasStation(const int stationId) const
Check whether station exists.
Definition: SEvent.cc:81
void SetAlgorithm(const std::string &algo)
Set the trigger algorithm.
Definition: T3.h:69
void SetCurrentST(const int num)
boost::filter_iterator< ComponentSelector, ConstAllEyeIterator > ConstEyeIterator
Definition: FEvent.h:56
bool HasFEvent() const
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
This class contains the basic information to build a surface event.
Definition: T3.h:36
void SetCurrent100(const int num)
PMTIterator PMTsBegin(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
begin PMT iterator for read/write
void SetOffsetMicroSecond(const int offset)
bool HasTriggerData() const
Check whether trigger data object exists.
void SetTime(const utl::TimeStamp &time)
Set time of the trigger.
sevt::StationGPSData & GetGPSData(const utl::TimeStamp &time)
Get simulated GPSData.
void SetNext40(const int num)
unsigned int GetNumberOfT3s() const
Get the number of T3s.
Definition: SEventSimData.h:31
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
Definition: SEvent.h:148
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
void SetTick(const unsigned int num)
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
FADCTriggeredTraceIterator FADCTriggeredTracesBegin(const utl::TimeStamp &stamp, const sdet::PMTConstants::PMTGain gain)
Definition: PMTSimData.h:275
int GetId() const
Definition: SEvent/Header.h:20
void SetCurrent40(const int num)
void SetPreviousId(const unsigned int id)
Set Id of the FD trigger that contains data for this event.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
int gain
Definition: dump1090.h:241
void MakeTriggerData()
Make trigger data object.
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
bool HasSimData() const
check whether the SimData object exists
Definition: SEvent.h:143
bool HasFADCTrace(StationConstants::SignalComponent source=StationConstants::eTotal) const
Check if FADC trace (prior to local trigger simulation) exists.
Definition: PMTSimData.h:186
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
sevt::StationTriggerData & GetTriggerData(const utl::TimeStamp &time)
Get simulated TriggerData.
Class representing a document branch.
Definition: Branch.h:107
class to hold data at Station level
bool IsT1Threshold() const
T1 threshold.
bool HasSimData() const
Check whether station simulated data exists.
void SetNErrorZeroStations(const unsigned int n)
Set number of error zero stations.
Definition: SEvent.h:133
Interface class to access the Event Trigger (T3)
constexpr double nanosecond
Definition: AugerUnits.h:143
const EndRow endr
decltype(std::begin(boost::adaptors::keys(TriggerGPSMap()))) typedef TriggerTimeIterator
const double second
Definition: GalacticUnits.h:32
bool HasTrigger() const
check whether the central trigger object exists
Definition: SEvent.h:153
void SetSecond(const unsigned int sec)
Set end of traces raw time.
void MakeTrigger()
Create the central trigger object.
Definition: SEvent.cc:102
const int tab
Definition: SdInspector.cc:35
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
utl::TimeStamp GetTime() const
Get the trigger time stamp.
Definition: T3.h:66
a t3: algo, second, usecond and a vector of &lt;t3stat&gt;
Definition: XbT2.h:29
PMTIterator PMTsEnd(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
end PMT iterator for read/write
sevt::StationGPSData & GetGPSData()
Get GPS data for the station.
void SetOffset(const int os)
Set GPS offset compared to a reference.
StationIterator StationsBegin() const
Iterator over the list of T3Stations in T3.
Definition: T3.h:96
class to format data in tabular form
void SetId(const unsigned int id)
Set Id of the trigger.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
SEventSimData & GetSimData()
Get the object with simulated data, throw if n.a.
Definition: SEvent.h:138
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
bool IsT2Threshold() const
T2 threshold.
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
bool HasGPSData() const
Check whether GPS data object edists.
TriggerTimeIterator TriggerTimesBegin() const
Beginning of simulated local trigger times list.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
Definition: SEvent.h:116
FADCTriggeredTraceIterator FADCTriggeredTracesEnd(const utl::TimeStamp &stamp, const sdet::PMTConstants::PMTGain gain)
Definition: PMTSimData.h:277
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
bool IsTimeOverThreshold() const
T1 TOT is always promoted to T2 TOT.
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
utl::TimeStamp GetTime() const
Get time of the trigger.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const DeleteRow delr
void SetNStations(const unsigned int num)
Set number of stations in the trigger.
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
double GetGPSNanoSecond() const
GPS nanosecond.
Definition: TimeStamp.h:127
void SetSDPAngle(const double ang)
Set SDPAngle of the trigger.
Station Trigger Data description
T3Iterator T3sEnd()
Iterator over the list of T3s.
Definition: SEventSimData.h:38
Class to hold simulated data at PMT level.
Definition: PMTSimData.h:40
void SetNext100(const int num)
void SetWindowMicroSecond(const int window)
void SetAlgorithm(const std::string &algo)
Set algorithm of the trigger.
TriggerTimeIterator TriggerTimesEnd() const
End of simulated local trigger times list.
FADCTriggeredTraceDIterator FADCTriggeredTracesDEnd(const utl::TimeStamp &stamp, const sdet::PMTConstants::PMTGain gain)
Definition: PMTSimData.h:304
sevt::Header & GetHeader()
Definition: SEvent.h:155
FADCTriggeredTraceDIterator FADCTriggeredTracesDBegin(const utl::TimeStamp &stamp, const sdet::PMTConstants::PMTGain gain)
Definition: PMTSimData.h:302
sevt::StationSimData & GetSimData()
Get simulated data at station level.
boost::transform_iterator< InternalStationFunctor, ConstInternalStationIterator, const sevt::T3::T3Station & > StationIterator
StationIterator returns a pointer to a T3Station.
Definition: T3.h:93
sevt::StationTriggerData & GetTriggerData()
Get Trigger data for the station.
string OfSortedIds(vector< int > ids)
Definition: String.cc:65
void MakeGPSData()
Make GPS data object.
T3Iterator T3sBegin()
Iterator over the list of T3s.
Definition: SEventSimData.h:34
constexpr double microsecond
Definition: AugerUnits.h:147
const HLine hline('-')
const EndColumn endc
bool HasSEvent() const
void SetNextST(const int num)
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
void SetErrorCode(const int errorCode)
void SetPreviousST(const int num)
void MakeFADCTrace(StationConstants::SignalComponent source=StationConstants::eTotal)
Make FADC trace prior to local trigger simulation.
Definition: PMTSimData.cc:40
void SetSender(const std::string &sender)
Set sender of the trigger.
std::string GetAlgorithm() const
Get the trigger algorithm.
Definition: T3.h:72
void SetTickFall(const unsigned int num)
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)

, generated on Tue Sep 26 2023.