#ifndef __JTRIGGER__JTRIGGERMXSHOWER__ #define __JTRIGGER__JTRIGGERMXSHOWER__ #include "JTrigger/JAlgorithm.hh" #include "JTrigger/JMatch3G.hh" #include "JTrigger/JParametersHelper.hh" #include "JTrigger/JTriggerInterface.hh" #include "JTrigger/JTimeslice.hh" #include "JTrigger/JTimesliceClone.hh" #include "JTrigger/JTriggerOutput.hh" #include "JTrigger/JTriggerMXShower_t.hh" #include "JDetector/JDetector.hh" #include "JDetector/JModuleMapper.hh" #include "JMath/JMathToolkit.hh" #include "JPhysics/JConstants.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using JDETECTOR::JModule; using JDETECTOR::JModuleMapper; using JDETECTOR::JDetector; using JDETECTOR::JMaximalDistance; /** * Module attributes. */ struct JAttributes { double Tmin_ns; //!< minimal time difference [ns] double Tmax_ns; //!< maximal time difference [ns] }; /** * Set module attributes. * * \param first first module * \param second second module * \param attributes module attributes */ inline void setAttributes(const JModule& first, const JModule& second, JAttributes& attributes) { using namespace JPP; typedef JTriggerMXShower_t::JParameters JParameters_t; // get trigger parameters const JParameters_t& parameters = JParametersHelper::getParameters(); const double d = getDistance(first.getPosition(), second.getPosition()); double t1 = 0.0; if (d <= 0.5 * parameters.DMax_m) t1 = d * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns; else if (d <= parameters.DMax_m) t1 = (parameters.DMax_m - d) * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns; attributes.Tmin_ns = -t1; attributes.Tmax_ns = +t1; } /** * Shower trigger. */ class JTriggerMXShower : public JTriggerMXShower_t, public JTriggerInterface { public: /** * Type definition of module mapper. */ typedef JModuleMapper JModuleMapper_t; /** * Constructor. * * \param input trigger parameters * \param detector detector; */ JTriggerMXShower(const JParameters& input, const JDetector& detector) : parameters(input), mapper(detector, JMaximalDistance(parameters.DMax_m)), match(parameters.DMax_m, parameters.TMaxExtra_ns) { using namespace JPP; TMaxEvent_ns = parameters.DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns; if (parameters.numberOfHits == 0) { parameters.numberOfHits = 1; } if (parameters.numberOfHits == 1) { parameters.factoryLimit = 1; } if (parameters.numberOfModules < 1) { parameters.numberOfModules = 1; } } /** * Process trigger. * * \param inputL1 input L1 data * \param inputL0 input L0 data * \param out output data */ template void operator()(const JTriggerInput& inputL1, const JTimeslice inputL0, std::back_insert_iterator out) const { typedef JTimesliceClone JTimeslice_t; typedef typename JTimeslice_t::value_type JFrame_t; typedef typename JModuleMapper_t::container_type container_type; if (parameters.enabled) { JTimeslice_t clone(inputL0, mapper); for (JTriggerInput::const_iterator root = inputL1.begin(); root != inputL1.end(); ++root) { buffer.clear(); const container_type& zip = mapper.getList(root->getModuleID()); for (typename container_type::const_iterator mod = zip.begin(); mod != zip.end(); ++mod) { const double Tmin = root->getT() + mod->Tmin_ns; const double Tmax = root->getT() + mod->Tmax_ns; JFrame_t& frame = clone[mod->first]; if (!frame.empty()) { frame.fast_forward(root->getT() - TMaxEvent_ns); for (typename JFrame_t::const_iterator i = frame.get(); *i <= Tmax; ++i) { if (*i >= Tmin) { buffer.push_back(JHitR1(frame.getModuleID(), frame.getPosition(), frame.getJHit(*i))); } } } } if (distance (buffer.begin(), buffer.end()) >= parameters.numberOfHits - 1 && getNumberOfModules(buffer.begin(), buffer.end()) >= parameters.numberOfModules - 1) { if (distance(buffer.begin(), buffer.end()) < parameters.factoryLimit) { JTriggerInput::iterator q = clusterize(buffer.begin(), buffer.end(), match, parameters.numberOfHits - 1); if (distance (buffer.begin(), q) >= parameters.numberOfHits - 1 && getNumberOfModules(buffer.begin(), q) >= parameters.numberOfModules - 1) { *out = JEvent(inputL1.getDAQChronometer(), *root, buffer.begin(), q, this->getTriggerBit()); ++out; } } else { // Anomalous large event JEvent event(inputL1.getDAQChronometer(), *root, buffer.begin(), buffer.end(), this->getTriggerBit()); event.addTriggerBit(FACTORY_LIMIT); *out = event; ++out; } } } } } private: JParametersHelper parameters; JModuleMapper_t mapper; mutable std::vector buffer; JMatch3G match; double TMaxEvent_ns; }; } #endif