#ifndef __JTRIGGERPARAMETERS__ #define __JTRIGGERPARAMETERS__ #include #include #include #include #include #include "JROOT/JRoot.hh" #include "JPhysics/JConstants.hh" #include "JTrigger/JPrescaler.hh" #include "JTrigger/JTrigger3DShower_t.hh" #include "JTrigger/JTriggerMXShower_t.hh" #include "JTrigger/JTrigger3DMuon_t.hh" #include "JTrigger/JTriggerNB_t.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { /** * Data structure for L2 parameters. */ struct JL2Parameters : public TObject { /** * Default constructor. */ JL2Parameters() { reset(); } /** * Constructor. * * \param numberOfHits minimal number of hits * \param TMaxLocal_ns maximal time difference [ns] * \param ctMin minimal cosine space angle between PMT axes */ JL2Parameters(const int numberOfHits, const double TMaxLocal_ns, const double ctMin) { this->numberOfHits = numberOfHits; this->TMaxLocal_ns = TMaxLocal_ns; this->ctMin = ctMin; } /** * Virtual destructor. */ virtual ~JL2Parameters() {} /** * Reset L2 parameters. */ void reset() { numberOfHits = 0; TMaxLocal_ns = 0.0; ctMin = 1.0; } /** * Equality * * \param parameters L2 parameters * \return true if equals; else false */ bool equals(const JL2Parameters& parameters) const { return (this->numberOfHits == parameters.numberOfHits && this->TMaxLocal_ns == parameters.TMaxLocal_ns && this->ctMin == parameters.ctMin); } /** * Check validity. * * \return true if not-equal to default value; else false */ inline bool is_valid() const { return !this->equals(JL2Parameters()); } ClassDef(JL2Parameters, 1); int numberOfHits; ///< minimal number of hits double TMaxLocal_ns; ///< maximal time difference [ns] double ctMin; ///< minimal cosine space angle between PMT axes }; /** * Data structure for all trigger parameters. */ class JTriggerParameters : public TObject { public: /** * Default constructor. */ JTriggerParameters() { reset(); } /** * Virtual destructor. */ virtual ~JTriggerParameters() {} /** * Set dependent trigger parameters. * * \param DMax_m maximal distance between PMTs [m] */ void set(const double DMax_m = 0.0) { using namespace JPHYSICS; const double t1 = DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight(); if (t1 > TMaxEvent_ns) { TMaxEvent_ns = t1; } trigger3DMuon.DMax_m = DMax_m; // backward compatibility if (!L2.is_valid()) { L2 = JL2Parameters(2, TMaxLocal_ns, ctMin); } if (triggerNB.enabled && triggerNB.write.prescale == 0) { triggerNB.write.prescale = 1; } } /** * Reset trigger parameters. */ void reset() { trigger3DShower.reset(); triggerMXShower.reset(); trigger3DMuon .reset(); triggerNB .reset(); highRateVeto_Hz = std::numeric_limits::max(); L2Min = 2; ctMin = -1.0; TMaxLocal_ns = 10.0; TMaxEvent_ns = 1000.0; numberOfBins = 1000; combineL1 = true; disableHighRateVeto = false; L2.reset(); SN.reset(); NB.reset(); writeTimeslices = 0; writeSummary = 1; writeL0 = 0; writeL1 = 0; writeL2 = 0; writeSN = 0; } /** * Test equality for high-rate vetos. * * \param R1_Hz high-rate veto * \param R2_Hz high-rate veto * \return true if equal; else false */ static bool equals(const double R1_Hz, const double R2_Hz) { using namespace std; if (R1_Hz <= numeric_limits::max() && R2_Hz <= numeric_limits::max()) { return (int) R1_Hz == (int) R2_Hz; } else { return (R1_Hz > numeric_limits::max() && R2_Hz > numeric_limits::max()); } } /** * Equality * * \param parameters trigger parameters * \return true if equals; else false */ bool equals(const JTriggerParameters& parameters) const { return (trigger3DShower.equals(parameters) && triggerMXShower.equals(parameters) && trigger3DMuon .equals(parameters) && triggerNB .equals(parameters) && equals(highRateVeto_Hz, parameters.highRateVeto_Hz) && L2Min == parameters.L2Min && ctMin == parameters.ctMin && TMaxLocal_ns == parameters.TMaxLocal_ns && TMaxEvent_ns == parameters.TMaxEvent_ns && numberOfBins == parameters.numberOfBins && combineL1 == parameters.combineL1 && disableHighRateVeto == parameters.disableHighRateVeto && L2.equals(parameters.L2) && SN.equals(parameters.SN) && NB.equals(parameters.NB) && writeSummary .equals(parameters.writeSummary) && writeL0 .equals(parameters.writeL0) && writeL1 .equals(parameters.writeL1) && writeL2 .equals(parameters.writeL2) && writeSN .equals(parameters.writeSN)); } /** * Equal operator for trigger parameters. * * \param first event * \param second event * \result true if first event equal to second; else false */ friend inline bool operator==(const JTriggerParameters& first, const JTriggerParameters& second) { return first.equals(second); } /** * Type conversion operators. */ inline operator JTrigger3DShower_t::JParameters() const { return trigger3DShower; } //!< JTrigger3DShower parameters inline operator JTriggerMXShower_t::JParameters() const { return triggerMXShower; } //!< JTriggerMXShower parameters inline operator JTrigger3DMuon_t::JParameters() const { return trigger3DMuon; } //!< JTrigger3DMuon parameters inline operator JTriggerNB_t::JParameters() const { return triggerNB; } //!< JTrigger3DMuon parameters /** * Action method at file open. * * \param version version */ static void actionAtFileOpen(int version) { ROOT_IO_VERSION = version; } /** * Action method at file read. */ void actionAtFileRead() { if (ROOT_IO_VERSION <= 7) { L2 = JL2Parameters(2, TMaxLocal_ns, ctMin); } if (ROOT_IO_VERSION <= 6) { trigger3DMuon .numberOfModules = 1; trigger3DShower.numberOfModules = 1; } else if (ROOT_IO_VERSION <= 8) { trigger3DMuon .numberOfModules = trigger3DMuon .numberOfHits; trigger3DShower.numberOfModules = trigger3DShower.numberOfHits; } if (ROOT_IO_VERSION <= 11) { triggerNB.write.prescale = triggerNB.enabled ? 1 : 0; } } ClassDef(JTriggerParameters,14); // Trigger specific parameters JTrigger3DShower_t::JParameters trigger3DShower; JTriggerMXShower_t::JParameters triggerMXShower; JTrigger3DMuon_t::JParameters trigger3DMuon; JTriggerNB_t::JParameters triggerNB; // Global parameters double highRateVeto_Hz; ///< high-rate veto [Hz] int L2Min; ///< minimal number of L0 hits for L2 double ctMin; ///< this parameter has been deprecated double TMaxLocal_ns; ///< maximal time difference between L0 hits for L1 double TMaxEvent_ns; ///< maximal time before and after event for snapshot int numberOfBins; ///< number of bins for lookup table of timeslice bool combineL1; ///< combine multiple L1s in many-fold coincidence bool disableHighRateVeto;///< disable high-rate veto JL2Parameters L2; ///< L2 processing JL2Parameters SN; ///< Supernova trigger JL2Parameters NB; ///< nano-beacon trigger JPrescaler writeTimeslices; ///< write JDAQTimeslice with L0 data (deprecated) JPrescaler writeSummary; ///< write JDAQSummaryslice JPrescaler writeL0; ///< write JDAQTimeslice with L0 data JPrescaler writeL1; ///< write JDAQTimeslice with L1 data JPrescaler writeL2; ///< write JDAQTimeslice with L2 data JPrescaler writeSN; ///< write JDAQTimeslice with SN data static int ROOT_IO_VERSION; //!< Streamer version of JTriggerParameters as obtained from ROOT file. }; } /** * Read L2 parameters from input. * * \param in input stream * \param parameters L2 parameters * \return input stream */ std::istream& operator>>(std::istream& in, JTRIGGER::JL2Parameters& parameters); /** * Write L2 parameters to output. * * \param out output stream * \param parameters L2 parameters * \return output stream */ std::ostream& operator<<(std::ostream& out, const JTRIGGER::JL2Parameters& parameters); /** * Read trigger parameters from input. * * \param in input stream * \param parameters trigger parameters * \return input stream */ std::istream& operator>>(std::istream& in, JTRIGGER::JTriggerParameters& parameters); /** * Write trigger parameters to output. * * \param out output stream * \param parameters trigger parameters * \return output stream */ std::ostream& operator<<(std::ostream& out, const JTRIGGER::JTriggerParameters& parameters); #endif