Jpp
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 "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 based on an L1 coincidence hit.
57  * Only the module where the L1 coincidence hit happened will contribute to the triggered hits in the event.
58  * Only modules within a shpere of radius DMax_m will contribute to the snapshot hits.
59  *
60  * \param chronometer daq chronometer
61  * \param mask trigger mask
62  * \param hit hit
63  * \param timesliceRouter timeslice router
64  * \param moduleRouter module router
65  * \param TMaxLocal_ns Maximal time for L1 [ns]
66  * \param DMax_m Maximal distance for snapshot.
67  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
68  */
69  JTriggeredEvent(const JDAQChronometer& chronometer,
70  const KM3NETDAQ::JTriggerMask_t& mask,
71  const JHitR1& hit,
72  const JTimesliceRouter& timesliceRouter,
73  const JModuleRouter& moduleRouter,
74  const double TMaxLocal_ns,
75  const double DMax_m,
76  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE) :
77  JDAQEvent()
78  {
79  using namespace std;
80 
81  // Header
82 
83  setDAQChronometer(chronometer);
84 
85  trigger_mask = mask;
86 
87  // Triggered hits
88 
89  const JTimeRange timeRange(hit.getT1(), hit.getT1() + TMaxLocal_ns);
90 
91  const JModule& triggeredModule = moduleRouter.getModule(hit.getModuleID());
92 
93  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit.getModuleIdentifier());
94  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit.getModuleIdentifier(), getTimeRange(timeRange, triggeredModule));
95 
96  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
97 
98  const JCalibration& calibration = triggeredModule.getPMT(i->getPMT()).getCalibration();
99 
100  const double t1 = getTime(*i, calibration);
101 
102  if (!frame.testHighRateVeto(i->getPMT()) &&
103  !frame.testFIFOStatus (i->getPMT())) {
104 
105  if (timeRange(t1)) {
106  triggeredHits.push_back(JDAQTriggeredHit(hit.getModuleIdentifier(), *i, mask));
107  }
108  }
109  }
110 
111  // Snapshot hits
112 
113  if (snapshot.is_valid()) {
114 
115  const JTimeRange timeRange(hit.getT1() + snapshot.getLowerLimit() - TMaxLocal_ns,
116  hit.getT1() + snapshot.getUpperLimit() + TMaxLocal_ns);
117 
118  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
119 
120  if (!super_frame->empty()) {
121 
122  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
123 
124  if (module.getDistance(hit) < DMax_m){
125 
126  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
127 
128  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
129 
130  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
131 
132  const double t1 = getTime(*i, calibration);
133 
134  if (timeRange(t1)) {
135  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
136  }
137  }
138  }
139  }
140  }
141  }
142  }
143 
144  /**
145  * Constructor.
146  *
147  * \param event event
148  * \param timesliceRouter timeslice router
149  * \param moduleRouter module router
150  * \param TMaxLocal_ns Maximal time for L1 [ns]
151  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
152  */
153  JTriggeredEvent(const JEvent& event,
154  const JTimesliceRouter& timesliceRouter,
155  const JModuleRouter& moduleRouter,
156  const double TMaxLocal_ns,
157  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE) :
158  JDAQEvent()
159  {
160  using namespace std;
161 
162  // Header
163 
165 
166  overlays = event.getOverlays();
167  trigger_mask = event.getTriggerMask();
168 
169  // Triggered hits
170 
171  for (JEvent::const_iterator hit = event.begin(); hit != event.end(); ++hit) {
172 
173  const JTimeRange timeRange(hit->getT1(), hit->getT1() + TMaxLocal_ns);
174 
175  const JModule& module = moduleRouter.getModule(hit->getModuleID());
176 
177  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit->getModuleIdentifier());
178  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit->getModuleIdentifier(), getTimeRange(timeRange, module));
179 
180  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
181 
182  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
183 
184  const double t1 = getTime(*i, calibration);
185 
186  if (!frame.testHighRateVeto(i->getPMT()) &&
187  !frame.testFIFOStatus (i->getPMT())) {
188 
189  if (timeRange(t1)) {
190  triggeredHits.push_back(JDAQTriggeredHit(hit->getModuleIdentifier(), *i, hit->getTriggerMask()));
191  }
192  }
193  }
194  }
195 
196  if (!triggeredHits.empty()) {
197 
198  // combine trigger masks of identical hits and remove redundant hits
199 
200  sort(triggeredHits.begin(), triggeredHits.end(), less<JDAQKeyHit>());
201 
203 
204  for (vector<JDAQTriggeredHit>::const_iterator i = triggeredHits.begin(); ++i != triggeredHits.end(); ) {
205 
206  if (static_cast<const JDAQKeyHit&>(*i) == static_cast<const JDAQKeyHit&>(*out))
207  out->addTriggerMask(*i);
208  else
209  *(++out) = *i;
210  }
211 
212  triggeredHits.resize(distance(triggeredHits.begin(), ++out));
213  }
214 
215 
216  // Snapshot hits
217 
218  if (snapshot.is_valid()) {
219 
220  const JTimeRange timeRange(event. begin()->getT1() + snapshot.getLowerLimit() - TMaxLocal_ns,
221  event.rbegin()->getT1() + snapshot.getUpperLimit() + TMaxLocal_ns);
222 
223  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
224 
225  if (!super_frame->empty()) {
226 
227  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
228 
229  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
230 
231  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
232 
233  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
234 
235  const double t1 = getTime(*i, calibration);
236 
237  if (timeRange(t1)) {
238  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
239  }
240  }
241  }
242  }
243  }
244  }
245  };
246 }
247 
248 #endif
KM3NETDAQ::JDAQChronometer::setDAQChronometer
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
Definition: JDAQChronometer.hh:99
KM3NETDAQ::JDAQSnapshotHit
JDAQKeyHit JDAQSnapshotHit
Definition: JDAQEvent.hh:24
JTRIGGER::JTriggeredEvent::JTriggeredEvent
JTriggeredEvent()
Default constructor.
Definition: JTriggeredEvent.hh:50
KM3NETDAQ::JDAQFrameStatus::testHighRateVeto
bool testHighRateVeto() const
Test high-rate veto status.
Definition: JDAQFrameStatus.hh:201
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:30
JDETECTOR::getCalibration
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
Definition: JDetectorToolkit.hh:866
JTRIGGER::JTriggeredEvent::JTriggeredEvent
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.
Definition: JTriggeredEvent.hh:69
JTRIGGER::JTimesliceRouter::getFrameSubset
JDAQFrameSubset getFrameSubset(const JDAQModuleIdentifier &module, const JTimeRange &timeRange) const
Get subset of frame given module identifier and range of hit times.
Definition: JTimesliceRouter.hh:270
JAANET::getTimeRange
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e.
Definition: JAAnetToolkit.hh:134
KM3NETDAQ::JDAQEvent::begin
const_iterator< T > begin() const
Get begin of data.
KM3NETDAQ::JTriggerMask_t
unsigned long long int JTriggerMask_t
Type definition of trigger mask.
Definition: JDAQTriggerMask.hh:21
JDETECTOR::JModuleRouter::getModule
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Definition: JModuleRouter.hh:89
KM3NETDAQ::JDAQFrameSubset::const_iterator
const typedef JDAQHit * const_iterator
Definition: JDAQFrame.hh:26
JDETECTOR::JCalibration
Data structure for PMT calibration.
Definition: JDetector/JCalibration.hh:35
KM3NETDAQ::JDAQTriggerMask::trigger_mask
JTriggerMask_t trigger_mask
Definition: JDAQTriggerMask.hh:267
JTRIGGER::JEvent
Triggered event.
Definition: JEvent.hh:31
JGEOMETRY3D::JVector3D::getDistance
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:269
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< double >::DEFAULT_RANGE
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:558
KM3NETDAQ::JDAQModuleIdentifier::getModuleID
int getModuleID() const
Get module identifier.
Definition: JDAQModuleIdentifier.hh:72
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JTOOLS::JTimeRange
JRange< double > JTimeRange
Type definition for time range.
Definition: JTools/JTimeRange.hh:19
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
KM3NETDAQ::JDAQFrameSubset::end
const_iterator end() const
Definition: JDAQFrame.hh:43
KM3NETDAQ::JDAQTriggeredHit
DAQ triggered hit.
Definition: JDAQTriggeredHit.hh:20
KM3NETDAQ::JDAQModuleIdentifier::getModuleIdentifier
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
Definition: JDAQModuleIdentifier.hh:50
KM3NETDAQ::JDAQEvent::snapshotHits
std::vector< JDAQSnapshotHit > snapshotHits
Definition: JDAQEvent.hh:267
JDETECTOR::JModule::getPMT
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:173
JTRIGGER::JTimesliceRouter::getSuperFrame
const JDAQSuperFrame & getSuperFrame(const JDAQModuleIdentifier &module) const
Get super frame.
Definition: JTimesliceRouter.hh:254
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
JModuleRouter.hh
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
KM3NETDAQ::JDAQKeyHit
DAQ key hit.
Definition: JDAQKeyHit.hh:19
KM3NETDAQ::JDAQFrameStatus::testFIFOStatus
bool testFIFOStatus() const
Test FIFO status.
Definition: JDAQFrameStatus.hh:245
JTRIGGER::JTriggeredEvent
Auxiliary class to build JDAQEvent for a triggered event.
Definition: JTriggeredEvent.hh:41
JDetectorToolkit.hh
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
KM3NETDAQ::JDAQFrameSubset
Subset of data frame.
Definition: JDAQFrame.hh:22
JTRIGGER::JHitR1
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
JTimesliceRouter.hh
KM3NETDAQ::JDAQEventHeader::overlays
unsigned int overlays
Definition: JDAQEventHeader.hh:97
KM3NETDAQ::JDAQChronometer::getDAQChronometer
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
Definition: JDAQChronometer.hh:88
std
Definition: jaanetDictionary.h:36
KM3NETDAQ::JDAQSuperFrame
Data frame of one optical module.
Definition: JDAQSuperFrame.hh:22
JDAQEvent.hh
KM3NETDAQ::JDAQEvent::triggeredHits
std::vector< JDAQTriggeredHit > triggeredHits
Definition: JDAQEvent.hh:266
JTRIGGER
Checksum.
Definition: JSupport/JSupport.hh:35
JDETECTOR::getTimeRange
JTimeRange getTimeRange(const JTimeRange &timeRange, const JModule &module)
Get de-calibrated time range.
Definition: JDetectorToolkit.hh:339
JEvent.hh
JTRIGGER::JHit::getT1
double getT1() const
Get leading edge of hit.
Definition: JHit.hh:170
KM3NETDAQ::JDAQChronometer
DAQ chronometer.
Definition: JDAQChronometer.hh:21
JTRIGGER::JTriggeredEvent::JTriggeredEvent
JTriggeredEvent(const JEvent &event, const JTimesliceRouter &timesliceRouter, const JModuleRouter &moduleRouter, const double TMaxLocal_ns, const JTimeRange &snapshot=JTimeRange::DEFAULT_RANGE)
Constructor.
Definition: JTriggeredEvent.hh:153
JTRIGGER::JTimesliceRouter
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
Definition: JTimesliceRouter.hh:62
KM3NETDAQ::JDAQFrameSubset::begin
const_iterator begin() const
Definition: JDAQFrame.hh:42