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