#ifndef __JAANET__JWEIGHTMUPAGE__ #define __JAANET__JWEIGHTMUPAGE__ #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Evt.hh" #include "JLang/JException.hh" #include "JLang/JClonable.hh" #include "JAAnet/JHead.hh" #include "JAAnet/JHeadToolkit.hh" #include "JAAnet/JEvtWeight.hh" #include "JAAnet/JEvtWeightFactor.hh" #include "JAAnet/JEvtWeightFactorHelper.hh" /** * \author mdejong */ namespace JAANET { using JLANG::JClonable; using JLANG::JValueOutOfRange; /** * Implementation of event weighing for MUPAGE data. */ struct JEvtWeightMupage : public JClonable, public JEvtWeightFactorHelper { /** * Default Constructor. */ JEvtWeightMupage() : JEvtWeightFactorHelper() {} /** * Constructor. * * \param header header */ JEvtWeightMupage(const JHead& header) : JEvtWeightFactorHelper() { configure(header); } /** * Constructor. * * \param header header * \param factor factor */ JEvtWeightMupage(const JHead& header, const JEvtWeightFactor& factor) { configure(header); JEvtWeightFactorHelper::configure(factor); } /** * Copy constructor. * * \param object original object */ JEvtWeightMupage(const JEvtWeightMupage& object) { this->norm = object.norm; if (object.is_valid()) { JEvtWeightFactorHelper::configure(*(object.get())); } } /** * Configuration. * * \param header header */ void configure(const JHead& header) override { const double dt = (header.time_interval.t2 - header.time_interval.t1 > 0.0 ? header.time_interval.t2 - header.time_interval.t1 : header.livetime.numberOfSeconds); if (check(header) && dt > 0.0) { norm = 1.0 / dt; } else { THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE."); } } /** * Check whether header is consistent with this event weighter. * * \param header header * \return true if consistent; else false */ bool check(const JHead& header) const override { return is_mupage(header); } /** * Get rate of given event. * * \param evt event * \return weight [1/s] */ double getWeight(const Evt& evt) const override { if (is_valid()) { return getFactor(evt) * norm; } else { return norm; } } }; } #endif