Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
8 #include "JDAQ/JDAQEvent.hh"
9 #include "JTrigger/JEvent.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JTRIGGER {}
20 namespace JPP { using namespace JTRIGGER; }
21 
22 namespace JTRIGGER {
23 
29  using JDETECTOR::JModule;
33 
34 
35  /**
36  * Auxiliary class to build JDAQEvent for a triggered event.
37  *
38  * The data structure includes a list of raw data hits that triggered the event and
39  * optionally a list of all raw hits within a preset time window around the event (snapshot).
40  */
42  public JDAQEvent
43  {
44  public:
45 
46 
47  /**
48  * Default constructor.
49  */
51  JDAQEvent()
52  {}
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param event event
59  * \param timesliceRouter timeslice router
60  * \param moduleRouter module router
61  * \param TMaxLocal_ns Maximal time for L1 [ns]
62  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
63  */
65  const JTimesliceRouter& timesliceRouter,
66  const JModuleRouter& moduleRouter,
67  const double TMaxLocal_ns,
68  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE) :
69  JDAQEvent()
70  {
71  using namespace std;
72 
73  // Header
74 
76 
77  overlays = event.getOverlays();
78  trigger_mask = event.getTriggerMask();
79 
80 
81  // Triggered hits
82 
83  for (JEvent::const_iterator hit = event.begin(); hit != event.end(); ++hit) {
84 
85  const JTimeRange timeRange(hit->getT(), hit->getT() + TMaxLocal_ns);
86 
87  const JModule& module = moduleRouter.getModule(hit->getModuleID());
88 
89  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit->getModuleIdentifier());
90  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit->getModuleIdentifier(), getTimeRange(timeRange, module));
91 
92  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
93 
94  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
95 
96  const double t1 = getTime(*i, calibration);
97 
98  if (!frame.testHighRateVeto(i->getPMT()) &&
99  !frame.testFIFOStatus (i->getPMT())) {
100 
101  if (timeRange(t1)) {
102  triggeredHits.push_back(JDAQTriggeredHit(hit->getModuleIdentifier(), *i, hit->getTriggerMask()));
103  }
104  }
105  }
106  }
107 
108 
109  if (!triggeredHits.empty()) {
110 
111  // combine trigger masks of identical hits and remove redundant hits
112 
113  sort(triggeredHits.begin(), triggeredHits.end(), less<JDAQKeyHit>());
114 
116 
117  for (vector<JDAQTriggeredHit>::const_iterator i = triggeredHits.begin(); ++i != triggeredHits.end(); ) {
118 
119  if (static_cast<const JDAQKeyHit&>(*i) == static_cast<const JDAQKeyHit&>(*out))
120  out->addTriggerMask(*i);
121  else
122  *(++out) = *i;
123  }
124 
125  triggeredHits.resize(distance(triggeredHits.begin(), ++out));
126  }
127 
128 
129  // Snapshot hits
130 
131  if (snapshot.is_valid()) {
132 
133  const JTimeRange timeRange(event. begin()->getT() + snapshot.getLowerLimit() - TMaxLocal_ns,
134  event.rbegin()->getT() + snapshot.getUpperLimit() + TMaxLocal_ns);
135 
136  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
137 
138  if (!super_frame->empty()) {
139 
140  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
141 
142  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
143 
144  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
145 
146  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
147 
148  const double t1 = getTime(*i, calibration);
149 
150  if (timeRange(t1)) {
151  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
152  }
153  }
154  }
155  }
156  }
157  }
158  };
159 }
160 
161 #endif
JTriggeredEvent()
Default constructor.
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:506
DAQ key hit.
Definition: JDAQKeyHit.hh:24
const JDAQSuperFrame & getSuperFrame(const JDAQModuleIdentifier &module) const
Get super frame.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:47
JDAQKeyHit JDAQSnapshotHit
Definition: JDAQEvent.hh:28
const_iterator begin() const
Definition: JDAQFrame.hh:48
Router for direct addressing of module data in detector data structure.
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
Data structure for PMT calibration.
double getTime(const Hit &hit)
Get true time of hit.
std::vector< JDAQTriggeredHit > triggeredHits
Definition: JDAQEvent.hh:317
JRange< double > JTimeRange
Type definition for time range.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e.
Subset of data frame.
Definition: JDAQFrame.hh:28
JTriggeredEvent(const JEvent &event, const JTimesliceRouter &timesliceRouter, const JModuleRouter &moduleRouter, const double TMaxLocal_ns, const JTimeRange &snapshot=JTimeRange::DEFAULT_RANGE)
Constructor.
const_iterator< T > begin() const
Get begin of data.
Hit data structure.
Definition: JDAQHit.hh:36
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
JDAQFrameSubset getFrameSubset(const JDAQModuleIdentifier &module, const JTimeRange &timeRange) const
Get subset of frame given module identifier and range of hit times.
JTimeRange getTimeRange(const JTimeRange &timeRange, const JModule &module)
Get de-calibrated time range.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
Auxiliary class to build JDAQEvent for a triggered event.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:141
Direct access to module in detector data structure.
bool testHighRateVeto() const
Test high-rate veto status.
const_iterator end() const
Definition: JDAQFrame.hh:49
std::vector< JDAQSnapshotHit > snapshotHits
Definition: JDAQEvent.hh:318
Data frame of one optical module.
Triggered event.
Definition: JEvent.hh:31
bool testFIFOStatus() const
Test FIFO status.