TankTriggerSimulator.cc
Go to the documentation of this file.
1 #include <fwk/CentralConfig.h>
2 #include <det/Detector.h>
3 #include <sdet/SDetector.h>
4 #include <sdet/Station.h>
5 #include <evt/Event.h>
6 #include <sevt/PMT.h>
7 #include <sevt/PMTCalibData.h>
8 #include <sevt/SEvent.h>
9 #include <sevt/Header.h>
10 #include <sevt/Station.h>
11 #include <sevt/StationTriggerData.h>
12 #include <utl/AugerUnits.h>
13 #include <utl/ErrorLogger.h>
14 #include <utl/TimeDistribution.h>
15 #include <utl/MultiTrace.h>
16 #include <utl/PhysicalConstants.h>
17 #include <utl/Reader.h>
18 #include <utl/TimeStamp.h>
19 #include <utl/RandomEngine.h>
20 #include <utl/TabularStream.h>
21 #include <sdet/StationTriggerAlgorithm.h>
22 #include <sdet/StationTriggerUtil.h>
23 
24 #include "TankTriggerSimulator.h"
25 
26 #include <cmath>
27 
28 using namespace fwk;
29 using namespace det;
30 using namespace evt;
31 using namespace sevt;
32 using namespace utl;
33 using namespace std;
34 
35 
36 namespace TankTriggerSimulatorOG {
37 
38 #define PARAMETER_SET(_p_, _b_) f##_p_ = _b_.GetChild(#_p_).Get<decltype(f##_p_)>()
39 
40  void
41  TankTriggerSimulator::T1ThresholdParameters::Set(const Branch& b)
42  {
43  PARAMETER_SET(LevelVEM, b);
44  PARAMETER_SET(Multiplicity, b);
45  }
46 
47 
48  void
49  TankTriggerSimulator::T2ThresholdParameters::Set(const Branch& b)
50  {
51  PARAMETER_SET(LevelVEM, b);
52  PARAMETER_SET(Multiplicity, b);
53  }
54 
55 
56  void
57  TankTriggerSimulator::TOTParameters::Set(const Branch& b)
58  {
59  PARAMETER_SET(LevelVEM, b);
60  PARAMETER_SET(Occupancy, b);
61  PARAMETER_SET(Window, b);
62  PARAMETER_SET(Multiplicity, b);
63  }
64 
65 
66  void
67  TankTriggerSimulator::IntegralParameters::Set(const Branch& b)
68  {
69  PARAMETER_SET(Window, b);
70  PARAMETER_SET(Decrement, b);
71  PARAMETER_SET(Threshold, b);
72  PARAMETER_SET(BaselineTolerance, b);
73  PARAMETER_SET(BaselineStep, b);
74  }
75 
76 
77  void
78  TankTriggerSimulator::TOTdParameters::Set(const Branch& b)
79  {
80  PARAMETER_SET(LevelVEM, b);
81  PARAMETER_SET(DecayFD, b);
82  PARAMETER_SET(DecayFN, b);
83  PARAMETER_SET(Occupancy, b);
84  PARAMETER_SET(Window, b);
85  PARAMETER_SET(Multiplicity, b);
86  }
87 
88 
89  void
90  TankTriggerSimulator::MOPSParameters::Set(const Branch& b)
91  {
92  PARAMETER_SET(Occupancy, b);
93  PARAMETER_SET(Window, b);
94  PARAMETER_SET(MinUp, b);
95  PARAMETER_SET(MaxUp, b);
96  PARAMETER_SET(VetoOffset, b);
97  PARAMETER_SET(Multiplicity, b);
98  }
99 
100 #undef PARAMETER_SET
101 
102 
105  {
106  auto& cc = *CentralConfig::GetInstance();
107  Branch topB = cc.GetTopBranch("TankTriggerSimulatorOG");
108 
109  if (!topB) {
110  WARNING("Top branch <TankTriggerSimulatorOG> not found, trying <TankTriggerSimulator> instead.");
111  topB = cc.GetTopBranch("TankTriggerSimulator");
112  }
113 
114  fT1Threshold.Set(topB.GetChild("T1Threshold"));
115 
116  fT2Threshold.Set(topB.GetChild("T2Threshold"));
117 
118  fTOT.Set(topB.GetChild("TOT"));
119 
120  fIntegral.Set(topB.GetChild("Integral"));
121 
122  fTOTd.Set(topB.GetChild("TOTd"));
123 
124  fMOPS.Set(topB.GetChild("MOPS"));
125 
126  return eSuccess;
127  }
128 
129 
131  TankTriggerSimulator::Run(evt::Event& event)
132  {
133  if (!event.HasSEvent()) {
134  ERROR("Nonexisting SEvent.");
135  return eFailure;
136  }
137 
138  auto& sEvent = event.GetSEvent();
139 
140  const auto& eventTime = event.GetHeader().GetTime();
141 
142  vector<const TimeDistributionI*> traces;
143 
144  TabularStream tab("r|r|r|r|l");
145  tab << "ID" << endc
146  << "(start, stop)" << endc
147  << "bins" << endc
148  << "latch" << endc
149  << "" << endr;
150 
151  for (auto& station : sEvent.StationsRange()) {
152 
153  using namespace sdet::Trigger;
154  int startBin = 0;
155  int stopBin = 0;
156  PrepareTraces(station, startBin, stopBin, traces);
157 
158  if (traces.size() < 3)
159  continue;
160 
161  const auto& dStation = Detector::GetInstance().GetSDetector().GetStation(station);
162 
163  // Set the thresholds according to this particular station.
164  FADCCalibInfo calib;
165  const int nThresholds = GetCalibInfo(station, calib);
166 
167  if (nThresholds < 3)
168  continue;
169 
170  const int n = 3; // number of traces
171  const ThresholdUp t1th(calib.fT1Threshold, fT1Threshold.fMultiplicity, n);
172  const ThresholdUp t2th(calib.fT2Threshold, fT2Threshold.fMultiplicity, n);
173  const TimeOverThreshold tot(calib.fTOTThreshold, fTOT.fOccupancy, fTOT.fWindow, fTOT.fMultiplicity, n);
174  // UUB has 4x resolution in fadc
175  const int adcFactor = station.IsUUB() ? 4 : 1;
176  const int integralThreshold = adcFactor * fIntegral.fThreshold;
177  const DecayingIntegral integ(fIntegral.fWindow, fIntegral.fDecrement, integralThreshold,
178  calib.fBaseline, fIntegral.fBaselineTolerance, fIntegral.fBaselineStep, n);
179  const TimeOverThresholdDeconvolved totd(calib.fTOTdThreshold,
180  fTOTd.fDecayFD, fTOTd.fDecayFN,
181  fTOTd.fOccupancy, fTOTd.fWindow,
182  fTOTd.fMultiplicity, n);
183  const int mopsMinUp = adcFactor * fMOPS.fMinUp;
184  const int mopsMaxUp = adcFactor * fMOPS.fMaxUp;
185 
186  // DFN: We need to use different veto offset here for UB and UUB.
187  const int vetoOffset = station.IsUUB() ? fMOPS.fVetoOffset+3 : fMOPS.fVetoOffset;
188  const MultiplicityOfPositiveSteps mops(fMOPS.fOccupancy, fMOPS.fWindow,
189  mopsMinUp, mopsMaxUp, vetoOffset,
190  fMOPS.fMultiplicity, n);
191 
192  sdet::StationTriggerAlgorithm stationTrigger(t1th, t2th, tot, integ, totd, mops,
193  dStation.GetLatchBin(), dStation.GetFADCTraceLength());
194 
195  const auto info = stationTrigger.Run(startBin, stopBin, traces);
196 
197  if (info.empty())
198  Buffer(station, eventTime, StationTriggerData::eSilent, StationTriggerData::ePLDNone, 0, 0);
199  else {
200  for (const auto& i : info) {
201  tab << station.GetId() << endc
202  << "(" << startBin << ", " << stopBin << ")" << endc
203  << "(" << i.GetStart() << ", " << i.GetStop() << ")" << endc
204  << i.GetLatch() << endc;
205  if (i.IsT1Threshold())
206  tab << "T1Thr ";
207  if (i.IsTimeOverThreshold())
208  tab << "ToT ";
209  if (i.IsTimeOverThresholdDeconvoluted())
210  tab << "ToTd ";
211  if (i.IsMultiplicityOfPositiveSteps())
212  tab << "MoPs ";
213  if (i.IsT2Threshold())
214  tab << "T2thr ";
215  tab << endr;
216 
217  Buffer(station, eventTime, i.GetTrigger(), i.GetPLDBits(), i.GetStart(), i.GetStop());
218 
219  }
220  }
221  }
222 
223  DEBUGLOG(tab);
224 
225  return eSuccess;
226  }
227 
228 
229  int
230  TankTriggerSimulator::GetCalibInfo(const Station& station, FADCCalibInfo& calibInfo)
231  const
232  {
233  const bool isUUB = station.IsUUB();
234 
235  int nPMTs = 0;
236 
237  for (const auto& pmt : station.PMTsRange()) {
238 
239  const auto& calib = pmt.GetCalibData();
240  const auto base = calib.GetBaseline();
241 
242  const auto& sim = pmt.GetSimData();
243  const double vem = sim.GetTriggerVEMPeak(isUUB);
244 
245  const int pmtId = pmt.GetId() - sdet::Station::GetFirstPMTId();
246  calibInfo.fBaseline[pmtId] = base;
247  calibInfo.fT1Threshold[pmtId] = round(base + vem * fT1Threshold.fLevelVEM);
248  calibInfo.fT2Threshold[pmtId] = round(base + vem * fT2Threshold.fLevelVEM);
249  calibInfo.fTOTThreshold[pmtId] = round(base + vem * fTOT.fLevelVEM);
250  calibInfo.fTOTdThreshold[pmtId] = round(base + vem * fTOTd.fLevelVEM);
251 
252  ++nPMTs;
253 
254  }
255 
256  return nPMTs;
257  }
258 
259 }
Branch GetTopBranch() const
Definition: Branch.cc:63
void PrepareTraces(const sevt::Station &station, int &startBin, int &stopBin, std::vector< const TimeDistributionI * > &traces)
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Class representing a document branch.
Definition: Branch.h:107
class to hold data at Station level
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
const EndRow endr
const int tab
Definition: SdInspector.cc:35
class to format data in tabular form
Local station hardware (PLD) and software (T2) trigger algorithm.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
bool IsUUB() const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
static unsigned int GetFirstPMTId()
Id of first pmt in station.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
std::vector< StationTriggerInfo > Run(const int start, const int stop, const std::vector< const Trace< T > * > &traces)
void Buffer(sevt::Station &station, const TimeStamp &eventTime, const StationTriggerData::Algorithm algorithm, const int pldBits, const int start, const int stop)
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const EndColumn endc
bool HasSEvent() const
#define PARAMETER_SET(_p_, _b_)

, generated on Tue Sep 26 2023.