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 
9 #include "JTrigger/JHitR1.hh"
10 #include "JTrigger/JEvent.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JTRIGGER {}
21 namespace JPP { using namespace JTRIGGER; }
22 
23 namespace JTRIGGER {
24 
30  using JDETECTOR::JModule;
34 
35 
36  /**
37  * Auxiliary class to build JDAQEvent for a triggered event.
38  *
39  * The data structure includes a list of raw data hits that triggered the event and
40  * optionally a list of all raw hits within a preset time window around the event (snapshot).
41  */
43  public JDAQEvent
44  {
45  public:
46 
47 
48  /**
49  * Default constructor.
50  */
52  JDAQEvent()
53  {}
54 
55 
56  /**
57  * Constructor based on an L1 coincidence hit.
58  * Only the module where the L1 coincidence hit happened will contribute to the triggered hits in the event.
59  * Only modules within a shpere of radius DMax_m will contribute to the snapshot hits.
60  *
61  * \param chronometer daq chronometer
62  * \param mask trigger mask
63  * \param hit hit
64  * \param timesliceRouter timeslice router
65  * \param moduleRouter module router
66  * \param TMaxLocal_ns Maximal time for L1 [ns]
67  * \param DMax_m Maximal distance for snapshot.
68  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
69  */
70  JTriggeredEvent(const JDAQChronometer& chronometer,
71  const KM3NETDAQ::JTriggerMask_t& mask,
72  const JHitR1& hit,
73  const JTimesliceRouter& timesliceRouter,
74  const JModuleRouter& moduleRouter,
75  const double TMaxLocal_ns,
76  const double DMax_m,
77  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE) :
78  JDAQEvent()
79  {
80  using namespace std;
81 
82  // Header
83 
84  setDAQChronometer(chronometer);
85 
86  trigger_mask = mask;
87 
88  // Triggered hits
89 
90  const JTimeRange timeRange(hit.getT1(), hit.getT1() + TMaxLocal_ns);
91 
92  const JModule& root = moduleRouter.getModule(hit.getModuleID());
93 
94  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit.getModuleIdentifier());
95  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit.getModuleIdentifier(), getTimeRange(timeRange, root));
96 
97  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
98 
99  const JCalibration& calibration = root.getPMT(i->getPMT()).getCalibration();
100 
101  const double t1 = getTime(*i, calibration);
102 
103  if (!frame.testHighRateVeto(i->getPMT()) &&
104  !frame.testFIFOStatus (i->getPMT())) {
105 
106  if (timeRange(t1)) {
107  triggeredHits.push_back(JDAQTriggeredHit(hit.getModuleIdentifier(), *i, mask));
108  }
109  }
110  }
111 
112  // Snapshot hits
113 
114  if (snapshot.is_valid()) {
115 
116  const JTimeRange timeRange(hit.getT1() + snapshot.getLowerLimit() - TMaxLocal_ns,
117  hit.getT1() + snapshot.getUpperLimit() + TMaxLocal_ns);
118 
119  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
120 
121  if (!super_frame->empty()) {
122 
123  if (moduleRouter.hasModule(super_frame->getModuleID())) {
124 
125  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
126 
127  if (root.getDistance(hit) < DMax_m) {
128 
129  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
130 
131  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
132 
133  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
134 
135  const double t1 = getTime(*i, calibration);
136 
137  if (timeRange(t1)) {
138  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
139  }
140  }
141  }
142  }
143  }
144  }
145  }
146  }
147 
148  /**
149  * Constructor.
150  *
151  * \param event event
152  * \param timesliceRouter timeslice router
153  * \param moduleRouter module router
154  * \param TMaxLocal_ns Maximal time for L1 [ns]
155  * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns].
156  */
157  JTriggeredEvent(const JEvent& event,
158  const JTimesliceRouter& timesliceRouter,
159  const JModuleRouter& moduleRouter,
160  const double TMaxLocal_ns,
161  const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE) :
162  JDAQEvent()
163  {
164  using namespace std;
165 
166  // Header
167 
169 
170  overlays = event.getOverlays();
171  trigger_mask = event.getTriggerMask();
172 
173  // Triggered hits
174 
175  for (JEvent::const_iterator hit = event.begin(); hit != event.end(); ++hit) {
176 
177  const JTimeRange timeRange(hit->getT1(), hit->getT1() + TMaxLocal_ns);
178 
179  const JModule& module = moduleRouter.getModule(hit->getModuleID());
180 
181  const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit->getModuleIdentifier());
182  const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit->getModuleIdentifier(), getTimeRange(timeRange, module));
183 
184  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
185 
186  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
187 
188  const double t1 = getTime(*i, calibration);
189 
190  if (!frame.testHighRateVeto(i->getPMT()) &&
191  !frame.testFIFOStatus (i->getPMT())) {
192 
193  if (timeRange(t1)) {
194  triggeredHits.push_back(JDAQTriggeredHit(hit->getModuleIdentifier(), *i, hit->getTriggerMask()));
195  }
196  }
197  }
198  }
199 
200  if (!triggeredHits.empty()) {
201 
202  // combine trigger masks of identical hits and remove redundant hits
203 
204  sort(triggeredHits.begin(), triggeredHits.end(), less<JDAQKeyHit>());
205 
207 
208  for (vector<JDAQTriggeredHit>::const_iterator i = triggeredHits.begin(); ++i != triggeredHits.end(); ) {
209 
210  if (static_cast<const JDAQKeyHit&>(*i) == static_cast<const JDAQKeyHit&>(*out))
211  out->addTriggerMask(*i);
212  else
213  *(++out) = *i;
214  }
215 
216  triggeredHits.resize(distance(triggeredHits.begin(), ++out));
217  }
218 
219 
220  // Snapshot hits
221 
222  if (snapshot.is_valid()) {
223 
224  const JTimeRange timeRange(event. begin()->getT1() + snapshot.getLowerLimit() - TMaxLocal_ns,
225  event.rbegin()->getT1() + snapshot.getUpperLimit() + TMaxLocal_ns);
226 
227  for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) {
228 
229  if (!super_frame->empty()) {
230 
231  if (moduleRouter.hasModule(super_frame->getModuleID())) {
232 
233  const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
234 
235  const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module));
236 
237  for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) {
238 
239  const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration();
240 
241  const double t1 = getTime(*i, calibration);
242 
243  if (timeRange(t1)) {
244  snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i));
245  }
246  }
247  }
248  }
249  }
250  }
251  }
252  };
253 }
254 
255 #endif
JTriggeredEvent()
Default constructor.
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:569
DAQ key hit.
Definition: JDAQKeyHit.hh:19
const JDAQSuperFrame & getSuperFrame(const JDAQModuleIdentifier &module) const
Get super frame.
int getModuleID() const
Get module identifier.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:50
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.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JDAQKeyHit JDAQSnapshotHit
Definition: JDAQEvent.hh:24
const_iterator begin() const
Definition: JDAQFrame.hh:42
then JPlot1D f $WORKDIR postfit[prefit\] root
Router for direct addressing of module data in detector data structure.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
double getT1() const
Get leading edge of hit.
Data structure for PMT calibration.
double getTime(const Hit &hit)
Get true time of hit.
std::vector< JDAQTriggeredHit > triggeredHits
Definition: JDAQEvent.hh:266
JRange< double > JTimeRange
Type definition for time range.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
then for NAME in JDAQPreamble JDAQChronometer JDAQModuleIdentifier JDAQPMTIdentifier JDAQFrameStatus JDAQUTCExtended JDAQTimeslice JDAQTimesliceHeader JDAQSuperFrame JDAQSuperFrameHeader JDAQHit JDAQSummaryslice JDAQSummarysliceHeader JDAQSummaryFrame JDAQEvent JDAQEventHeader JDAQTriggerCounter JDAQTriggerMask JDAQKeyHit JDAQTriggeredHit
Subset of data frame.
Definition: JDAQFrame.hh:22
unsigned long long int JTriggerMask_t
Type definition of trigger mask.
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:34
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:174
Direct access to module in detector data structure.
bool testHighRateVeto() const
Test high-rate veto status.
Reduced data structure for L1 hit.
bool hasModule(const JObjectID &id) const
Has module.
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
const_iterator end() const
Definition: JDAQFrame.hh:43
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
std::vector< JDAQSnapshotHit > snapshotHits
Definition: JDAQEvent.hh:267
Data frame of one optical module.
Triggered event.
bool testFIFOStatus() const
Test FIFO status.