#ifndef __JAANET__JWEIGHTMUPAGE__ #define __JAANET__JWEIGHTMUPAGE__ #include "km3net-dataformat/definitions/weightlist.hh" #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 {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JClonable; /** * Implementation of event weighing for MUPAGE data. */ struct JEvtWeightMupage final : public JEvtWeightFactorHelper, public JClonable { /** * 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); } /** * Get name. * * \return name */ const char* const getName() const override final { return "MUPAGE"; } /** * Configuration. * * \param header header */ void configure(const JHead& header) override final { using namespace JPP; if (check(header)) { const double dt = ( header.time_interval.t2 - header.time_interval.t1 > 0.0 ? header.time_interval.t2 - header.time_interval.t1 : (header.livetime.numberOfSeconds > 0.0 ? header.livetime.numberOfSeconds : 1.0) ); setNormalisation(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 final { return is_mupage(header); } /** * Get rate of given event. * * \param evt event * \return weight [1/s] */ double getWeight(const Evt& evt) const override final { if (static_cast(*this)) { return getFactor(evt) * getNormalisation(evt); } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) { return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE]; } else { return getNormalisation(evt); } } }; } #endif