#ifndef __JTRIGGEREDEVENT__ #define __JTRIGGEREDEVENT__ #include #include #include #include "km3net-dataformat/online/JDAQEvent.hh" #include "JMath/JMathToolkit.hh" #include "JTrigger/JHitR1.hh" #include "JTrigger/JEvent.hh" #include "JDetector/JModuleRouter.hh" #include "JDetector/JDetectorToolkit.hh" #include "JTrigger/JTimesliceRouter.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } /** * Auxiliary classes and methods for triggering. */ namespace JTRIGGER { using KM3NETDAQ::JDAQSuperFrame; using KM3NETDAQ::JDAQEvent; using KM3NETDAQ::JDAQKeyHit; using KM3NETDAQ::JDAQTriggeredHit; using KM3NETDAQ::JDAQSnapshotHit; using JDETECTOR::JModule; using JDETECTOR::JModuleRouter; using JDETECTOR::JTimeRange; using JDETECTOR::getTimeRange; /** * Auxiliary class to build JDAQEvent for a triggered event. * * The data structure includes a list of raw data hits that triggered the event and * optionally a list of all raw hits within a preset time window around the event (snapshot). */ class JTriggeredEvent : public JDAQEvent { public: /** * Default constructor. */ JTriggeredEvent() : JDAQEvent() {} /** * Constructor based on an L1 coincidence hit. * Only the module where the L1 coincidence hit happened will contribute to the triggered hits in the event. * Only modules within a shpere of radius DMax_m will contribute to the snapshot hits. * * \param chronometer daq chronometer * \param mask trigger mask * \param hit hit * \param timesliceRouter timeslice router * \param moduleRouter module router * \param TMaxLocal_ns Maximal time for L1 [ns] * \param DMax_m Maximal distance for snapshot. * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns]. */ 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) : JDAQEvent() { using namespace std; using namespace JPP; // Header setDAQChronometer(chronometer); trigger_mask = mask; // Triggered hits const JTimeRange timeRange(hit.getT1(), hit.getT1() + TMaxLocal_ns); const JModule& root = moduleRouter.getModule(hit.getModuleID()); const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit.getModuleIdentifier()); const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit.getModuleIdentifier(), getTimeRange(timeRange, root)); for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) { const JCalibration& calibration = root.getPMT(i->getPMT()).getCalibration(); const double t1 = getTime(*i, calibration); if (!frame.testHighRateVeto(i->getPMT()) && !frame.testFIFOStatus (i->getPMT())) { if (timeRange(t1)) { triggeredHits.push_back(JDAQTriggeredHit(hit.getModuleIdentifier(), *i, mask)); } } } // Snapshot hits if (snapshot.is_valid()) { const JTimeRange timeRange(hit.getT1() + snapshot.getLowerLimit() - TMaxLocal_ns, hit.getT1() + snapshot.getUpperLimit() + TMaxLocal_ns); for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) { if (!super_frame->empty()) { if (moduleRouter.hasModule(super_frame->getModuleID())) { const JModule& module = moduleRouter.getModule(super_frame->getModuleID()); if (getDistance(root.getPosition(), hit.getPosition()) < DMax_m) { const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module)); for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) { const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration(); const double t1 = getTime(*i, calibration); if (timeRange(t1)) { snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i)); } } } } } } } } /** * Constructor. * * \param event event * \param timesliceRouter timeslice router * \param moduleRouter module router * \param TMaxLocal_ns Maximal time for L1 [ns] * \param snapshot time before first (<= 0) and after last (>= 0) triggered hit [ns]. */ JTriggeredEvent(const JEvent& event, const JTimesliceRouter& timesliceRouter, const JModuleRouter& moduleRouter, const double TMaxLocal_ns, const JTimeRange& snapshot = JTimeRange::DEFAULT_RANGE) : JDAQEvent() { using namespace std; // Header setDAQChronometer(event.getDAQChronometer()); overlays = event.getOverlays(); trigger_mask = event.getTriggerMask(); // Triggered hits for (JEvent::const_iterator hit = event.begin(); hit != event.end(); ++hit) { const JTimeRange timeRange(hit->getT1(), hit->getT1() + TMaxLocal_ns); const JModule& module = moduleRouter.getModule(hit->getModuleID()); const JDAQSuperFrame& frame = timesliceRouter.getSuperFrame(hit->getModuleIdentifier()); const JDAQFrameSubset subset = timesliceRouter.getFrameSubset(hit->getModuleIdentifier(), getTimeRange(timeRange, module)); for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) { const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration(); const double t1 = getTime(*i, calibration); if (!frame.testHighRateVeto(i->getPMT()) && !frame.testFIFOStatus (i->getPMT())) { if (timeRange(t1)) { triggeredHits.push_back(JDAQTriggeredHit(hit->getModuleIdentifier(), *i, hit->getTriggerMask())); } } } } if (!triggeredHits.empty()) { // combine trigger masks of identical hits and remove redundant hits sort(triggeredHits.begin(), triggeredHits.end(), less()); vector::iterator out = triggeredHits.begin(); for (vector::const_iterator i = triggeredHits.begin(); ++i != triggeredHits.end(); ) { if (static_cast(*i) == static_cast(*out)) out->addTriggerMask(*i); else *(++out) = *i; } triggeredHits.resize(distance(triggeredHits.begin(), ++out)); } // Snapshot hits if (snapshot.is_valid()) { const JTimeRange timeRange(event. begin()->getT1() + snapshot.getLowerLimit() - TMaxLocal_ns, event.rbegin()->getT1() + snapshot.getUpperLimit() + TMaxLocal_ns); for (JDAQTimeslice::const_iterator super_frame = timesliceRouter->begin(); super_frame != timesliceRouter->end(); ++super_frame) { if (!super_frame->empty()) { if (moduleRouter.hasModule(super_frame->getModuleID())) { const JModule& module = moduleRouter.getModule(super_frame->getModuleID()); const JDAQFrameSubset& subset = timesliceRouter.getFrameSubset(super_frame->getModuleIdentifier(), getTimeRange(timeRange, module)); for (JDAQFrameSubset::const_iterator i = subset.begin(); i != subset.end(); ++i) { const JCalibration& calibration = module.getPMT(i->getPMT()).getCalibration(); const double t1 = getTime(*i, calibration); if (timeRange(t1)) { snapshotHits.push_back(JDAQSnapshotHit(super_frame->getModuleIdentifier(), *i)); } } } } } } } }; } #endif