Jpp  19.1.0-rc.1
the software that should make you happy
JTriggeredEvent.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGEREDEVENT__
2 #define __JTRIGGEREDEVENT__
3 
4 #include <vector>
5 #include <utility>
6 #include <algorithm>
7 
9 #include "JMath/JMathToolkit.hh"
10 #include "JTrigger/JHitR1.hh"
11 #include "JTrigger/JEvent.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace JTRIGGER {}
23 namespace JPP { using namespace JTRIGGER; }
24 
25 /**
26  * Auxiliary classes and methods for triggering.
27  */
28 namespace JTRIGGER {
29 
36  using JDETECTOR::JModule;
40 
41 
42  /**
43  * Auxiliary class to build JDAQEvent for a triggered event.
44  *
45  * The data structure includes a list of raw data hits that triggered the event and
46  * optionally a list of all raw hits within a preset time window around the event (snapshot).
47  */
49  public JDAQEvent
50  {
51  public:
52 
53 
54  /**
55  * Default constructor.
56  */
58  JDAQEvent()
59  {}
60 
61 
62  /**
63  * Constructor based on an L1 coincidence hit.
64  * Only the module where the L1 coincidence hit happened will contribute to the triggered hits in the event.
65  * Only modules within a shpere of radius DMax_m will contribute to the snapshot hits.
66  *
67  * \param chronometer daq chronometer
68  * \param mask trigger mask
69  * \param hit hit
70  * \param timesliceRouter timeslice router
71  * \param moduleRouter module router
72  * \param TMaxLocal_ns Maximal time for L1 [ns]
73  * \param DMax_m Maximal distance for snapshot.
74  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
75  */
76  JTriggeredEvent(const JDAQChronometer& chronometer,
77  const KM3NETDAQ::JTriggerMask_t& mask,
78  const JHitR1& hit,
79  const JTimesliceRouter& timesliceRouter,
80  const JModuleRouter& moduleRouter,
81  const double TMaxLocal_ns,
82  const double DMax_m,
83  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE()) :
84  JDAQEvent()
85  {
86  using namespace std;
87  using namespace JPP;
88 
89  // Header
90 
91  setDAQChronometer(chronometer);
92 
93  trigger_mask = mask;
94 
95  // Triggered hits
96 
97  const JTimeRange timeRange(hit.getT1(), hit.getT1() + TMaxLocal_ns);
98 
99  const JModule& root = moduleRouter.getModule(hit.getModuleID());
100 
101  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit.getModuleIdentifier());
102  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit.getModuleIdentifier(), getTimeRange(timeRange, root));
103 
104  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
105 
106  const JCalibration& calibration = root.getPMT(i->getPMT()).getCalibration();
107 
108  const double t1 = getTime(*i, calibration);
109 
110  if (!frame.testHighRateVeto(i->getPMT()) &&
111  !frame.testFIFOStatus (i->getPMT())) {
112 
113  if (timeRange(t1)) {
114  triggeredHits.push_back(JDAQTriggeredHit(hit.getModuleIdentifier(), *i, mask));
115  }
116  }
117  }
118 
119  // Snapshot hits
120 
121  if (snapshot.is_valid()) {
122 
123  const JTimeRange timeRange(hit.getT1() + snapshot.getLowerLimit() - TMaxLocal_ns,
124  hit.getT1() + snapshot.getUpperLimit() + TMaxLocal_ns);
125 
126  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
127 
128  if (!super_frame->empty()) {
129 
130  if (moduleRouter.hasModule(super_frame->getModuleID())) {
131 
132  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
133 
134  if (getDistance(root.getPosition(), hit.getPosition()) < DMax_m) {
135 
136  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
137 
138  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
139 
140  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
141 
142  const double t1 = getTime(*i, calibration);
143 
144  if (timeRange(t1)) {
145  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
146  }
147  }
148  }
149  }
150  }
151  }
152  }
153  }
154 
155  /**
156  * Constructor.
157  *
158  * \param event event
159  * \param timesliceRouter timeslice router
160  * \param moduleRouter module router
161  * \param TMaxLocal_ns Maximal time for L1 [ns]
162  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
163  */
164  JTriggeredEvent(const JEvent& event,
165  const JTimesliceRouter& timesliceRouter,
166  const JModuleRouter& moduleRouter,
167  const double TMaxLocal_ns,
168  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE()) :
169  JDAQEvent()
170  {
171  using namespace std;
172 
173  // Header
174 
176 
177  overlays = event.getOverlays();
178  trigger_mask = event.getTriggerMask();
179 
180  // Triggered hits
181 
182  for (JEvent::const_iterator hit = event.begin(); hit != event.end(); ++hit) {
183 
184  const JTimeRange timeRange(hit->getT1(), hit->getT1() + TMaxLocal_ns);
185 
186  const JModule& module = moduleRouter.getModule(hit->getModuleID());
187 
188  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit->getModuleIdentifier());
189  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit->getModuleIdentifier(), getTimeRange(timeRange, module));
190 
191  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
192 
193  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
194 
195  const double t1 = getTime(*i, calibration);
196 
197  if (!frame.testHighRateVeto(i->getPMT()) &&
198  !frame.testFIFOStatus (i->getPMT())) {
199 
200  if (timeRange(t1)) {
201  triggeredHits.push_back(JDAQTriggeredHit(hit->getModuleIdentifier(), *i, hit->getTriggerMask()));
202  }
203  }
204  }
205  }
206 
207  if (!triggeredHits.empty()) {
208 
209  // combine trigger masks of identical hits and remove redundant hits
210 
211  sort(triggeredHits.begin(), triggeredHits.end(), less<JDAQKeyHit>());
212 
214 
215  for (vector<JDAQTriggeredHit>::const_iterator i = triggeredHits.begin(); ++i != triggeredHits.end(); ) {
216 
217  if (static_cast<const JDAQKeyHit&>(*i) == static_cast<const JDAQKeyHit&>(*out))
218  out->addTriggerMask(*i);
219  else
220  *(++out) = *i;
221  }
222 
223  triggeredHits.resize(distance(triggeredHits.begin(), ++out));
224  }
225 
226 
227  // Snapshot hits
228 
229  if (snapshot.is_valid()) {
230 
231  const JTimeRange timeRange(event. begin()->getT1() + snapshot.getLowerLimit() - TMaxLocal_ns,
232  event.rbegin()->getT1() + snapshot.getUpperLimit() + TMaxLocal_ns);
233 
234  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
235 
236  if (!super_frame->empty()) {
237 
238  if (moduleRouter.hasModule(super_frame->getModuleID())) {
239 
240  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
241 
242  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
243 
244  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
245 
246  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
247 
248  const double t1 = getTime(*i, calibration);
249 
250  if (timeRange(t1)) {
251  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
252  }
253  }
254  }
255  }
256  }
257  }
258  }
259  };
260 }
261 
262 #endif
Time calibration (including definition of sign of time offset).
Reduced data structure for L1 hit.
Auxiliary methods for geometrical methods.
Direct access to module in detector data structure.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Data structure for time calibration.
const JCalibration & getCalibration() const
Get calibration.
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
bool hasModule(const JObjectID &id) const
Has module.
Data structure for a composite optical module.
Definition: JModule.hh:75
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:172
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
static JRange< double, std::less< double > > DEFAULT_RANGE()
Default range.
Definition: JRange.hh:555
Triggered event.
Reduced data structure for L1 hit.
Definition: JHitR1.hh:35
double getT1() const
Get leading edge of hit.
Auxiliary class to build JDAQEvent for a triggered event.
JTriggeredEvent(const JDAQChronometer &chronometer, const KM3NETDAQ::JTriggerMask_t &mask, const JHitR1 &hit, const JTimesliceRouter &timesliceRouter, const JModuleRouter &moduleRouter, const double TMaxLocal_ns, const double DMax_m, const JTimeRange &snapshot=JTimeRange::DEFAULT_RANGE())
Constructor based on an L1 coincidence hit.
JTriggeredEvent(const JEvent &event, const JTimesliceRouter &timesliceRouter, const JModuleRouter &moduleRouter, const double TMaxLocal_ns, const JTimeRange &snapshot=JTimeRange::DEFAULT_RANGE())
Constructor.
JTriggeredEvent()
Default constructor.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
const_iterator< T > begin() const
Get begin of data.
std::vector< JDAQSnapshotHit > snapshotHits
Definition: JDAQEvent.hh:265
std::vector< JDAQTriggeredHit > triggeredHits
Definition: JDAQEvent.hh:264
bool testFIFOStatus() const
Test FIFO status.
bool testHighRateVeto() const
Test high-rate veto status.
Subset of data frame.
Definition: JDAQFrame.hh:24
const_iterator end() const
Definition: JDAQFrame.hh:44
const_iterator begin() const
Definition: JDAQFrame.hh:43
Hit data structure.
Definition: JDAQHit.hh:35
int getModuleID() const
Get module identifier.
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
Data frame of one optical module.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
double getTime(const Hit &hit)
Get true time of hit.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
JTimeRange getTimeRange(const JTimeRange &timeRange, const JModule &module)
Get de-calibrated time range.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
JDAQKeyHit JDAQSnapshotHit
Definition: JDAQEvent.hh:24
unsigned long long int JTriggerMask_t
Type definition of trigger mask.
Definition: root.py:1
Definition: JSTDTypes.hh:14
Calibration.
Definition: JHead.hh:330
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
const JDAQSuperFrame & getSuperFrame(const JDAQModuleIdentifier &module) const
Get super frame.
JDAQFrameSubset getFrameSubset(const JDAQModuleIdentifier &module, const JTimeRange &timeRange) const
Get subset of frame given module identifier and range of hit times.