StationTriggerUtil.cc
Go to the documentation of this file.
1 #include <det/Detector.h>
2 
3 #include <sdet/SDetector.h>
4 #include <sdet/StationTriggerUtil.h>
5 
6 #include <sevt/PMT.h>
7 #include <sevt/PMTSimData.h>
8 #include <sevt/SEvent.h>
9 #include <sevt/Station.h>
10 #include <sevt/StationSimData.h>
11 #include <sevt/StationTriggerData.h>
12 
13 #include <utl/Accumulator.h>
14 #include <utl/TimeStamp.h>
15 #include <utl/TimeInterval.h>
16 #include <utl/TimeDistribution.h>
17 
18 #include <vector>
19 
20 using namespace det;
21 using namespace sevt;
22 using namespace utl;
23 
24 
25 namespace sdet {
26 
27  namespace Trigger {
28 
29  void
30  Buffer(sevt::Station& station, const TimeStamp& eventTime,
31  const StationTriggerData::Algorithm algorithm,
32  const int pldBits, const int start, const int stop)
33  {
34  const auto& dStation = Detector::GetInstance().GetSDetector().GetStation(station);
35 
36  const auto triggerTime = eventTime + TimeInterval(stop * dStation.GetFADCBinSize());
37 
38  // Copy the trace information
39  for (auto& pmt : station.PMTsRange(sdet::PMTConstants::eAnyType)) {
40 
41  if (!pmt.HasSimData())
42  continue;
43 
44  auto& pmtSim = pmt.GetSimData();
45 
46  for (const auto& t : pmtSim.FADCTracesRange(sdet::PMTConstants::eHighGain)) {
47 
48  const auto component = static_cast<StationConstants::SignalComponent>(t.GetLabel());
49 
50  if (!pmtSim.HasFADCTrace(triggerTime, component))
51  pmtSim.MakeFADCTrace(triggerTime, component);
52  else {
53  ERROR("PMT already had trace at this time, not replacing!");
54  continue;
55  }
56  auto& hg = pmtSim.GetFADCTrace(triggerTime, sdet::PMTConstants::eHighGain, component);
57  auto& lg = pmtSim.GetFADCTrace(triggerTime, sdet::PMTConstants::eLowGain, component);
58  auto& hgD = pmtSim.GetFADCTraceD(triggerTime, sdet::PMTConstants::eHighGain, component);
59  auto& lgD = pmtSim.GetFADCTraceD(triggerTime, sdet::PMTConstants::eLowGain, component);
60 
61  // This zeros the triggered trace
62 
63  for (unsigned int i = 0, n = dStation.GetFADCTraceLength(); i < n; ++i) {
64  hg[i] = 0;
65  lg[i] = 0;
66  hgD[i] = 0;
67  lgD[i] = 0;
68  }
69 
70  const auto& hgSim = pmtSim.GetFADCTrace(sdet::PMTConstants::eHighGain, component);
71  const auto& lgSim = pmtSim.GetFADCTrace(sdet::PMTConstants::eLowGain, component);
72  const auto& hgSimD = pmtSim.GetFADCTraceD(sdet::PMTConstants::eHighGain, component);
73  const auto& lgSimD = pmtSim.GetFADCTraceD(sdet::PMTConstants::eLowGain, component);
74 
75  // Copy in the information
76  for (int i = start; i < stop; ++i) {
77  const int bin = i - start;
78  hg[bin] = hgSim.At(i);
79  lg[bin] = lgSim.At(i);
80  hgD[bin] = hgSimD.At(i);
81  lgD[bin] = lgSimD.At(i);
82  }
83 
84  if (!pmt.HasFADCTrace(component))
85  pmt.MakeFADCTrace(component);
86 
87  auto& pmtHG = pmt.GetFADCTrace(sdet::PMTConstants::eHighGain, component);
88  auto& pmtLG = pmt.GetFADCTrace(sdet::PMTConstants::eLowGain, component);
89  pmtHG = hg;
90  pmtLG = lg;
91 
92  auto& pmtHGD = pmt.GetFADCTraceD(sdet::PMTConstants::eHighGain, component);
93  auto& pmtLGD = pmt.GetFADCTraceD(sdet::PMTConstants::eLowGain, component);
94  pmtHGD = hgD;
95  pmtLGD = lgD;
96 
97  }
98 
99  }
100 
101  auto& sSim = station.GetSimData();
102  if (sSim.HasTriggerData(triggerTime)) {
103  ERROR("Trigger data already in sim data, not changing!");
104  return;
105  }
106 
107  sSim.MakeTriggerAndGPSData(triggerTime);
108  auto& trig = sSim.GetTriggerData(triggerTime);
109  trig.SetAlgorithm(algorithm);
110  trig.SetPLDTrigger(pldBits);
111  trig.SetOffsetMicroSecond(0);
112  trig.SetErrorCode(0);
113  }
114 
115 
116  void
117  PrepareTraces(const sevt::Station& station,
118  int& startBin, int& stopBin,
119  std::vector<const TimeDistributionI*>& traces)
120  {
121  traces.clear();
122 
123  Accumulator::Safe<Accumulator::Min<int>> minBin;
124  Accumulator::Safe<Accumulator::Max<int>> maxBin;
125 
126  unsigned int nTraces = 0;
127  for (const auto& pmt : station.PMTsRange()) {
128  if (pmt.HasSimData() && pmt.GetSimData().HasFADCTrace()) {
129  const auto& fadc = pmt.GetSimData().GetFADCTrace();
130  minBin(fadc.GetStart());
131  maxBin(fadc.GetStop());
132  traces.push_back(&fadc);
133  ++nTraces;
134  }
135  }
136 
137  if (!nTraces)
138  return;
139 
140  startBin = minBin.GetMin();
141  stopBin = maxBin.GetMax();
142 
143  if (nTraces < 3) {
144  static const TimeDistributionI empty(traces.front()->GetBinning());
145  for (int i = nTraces; i < 3; ++i)
146  traces.push_back(&empty);
147  }
148  }
149 
150  }
151 
152 }
void PrepareTraces(const sevt::Station &station, int &startBin, int &stopBin, std::vector< const TimeDistributionI * > &traces)
Histogram class for time distributions with suppressed empty bins.
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
class to hold data at Station level
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
sevt::StationSimData & GetSimData()
Get simulated data at station level.
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

, generated on Tue Sep 26 2023.