#ifndef __JAANET__JEVTWEIGHTMISCELLANEOUS__ #define __JAANET__JEVTWEIGHTMISCELLANEOUS__ #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 bjjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JClonable; /** * Implementation of event weighing for miscellaneous data\n * such as a merged offline file containing neutrinos and atmospheric muons.\n * A uniform weight of 1.0 is applied to all events. */ struct JEvtWeightMiscellaneous: public JClonable, public JEvtWeightFactorHelper { /** * Default constructor. */ JEvtWeightMiscellaneous() : JEvtWeightFactorHelper() {} /** * Constructor. * * \param header header */ JEvtWeightMiscellaneous(const JHead& header) : JEvtWeightFactorHelper() { configure(header); } /** * Constructor. * * \param header header * \param factor factor */ JEvtWeightMiscellaneous(const JHead& header, const JEvtWeightFactor& factor) : JEvtWeightFactorHelper() { configure(header); JEvtWeightFactorHelper::configure(factor); } /** * Copy constructor. * * \param object original object */ JEvtWeightMiscellaneous(const JEvtWeightMiscellaneous& object) { this->norm = object.norm; if (object.is_valid()) { JEvtWeightFactorHelper::configure(*(object.get())); } } /** * Configuration. * * \param header header */ void configure(const JHead& header) override { using namespace JPP; if (check(header)) { norm = 1.0; } else { THROW(JValueOutOfRange, "JEvtWeightMiscellaneous::configure(): Provided header is inconsistent with a miscellaneous, merged offline file."); } } /** * 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 header.simul.empty() && !is_daq(header); } /** * Get weight of given event. * * \param evt event * \return weight [1/s] */ double getWeight(const Evt& evt) const override { if (is_valid()) { 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