#ifndef __JAANET__JEVTWEIGHTKM3BUU__ #define __JAANET__JEVTWEIGHTKM3BUU__ #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/JEvtWeightFactorHelper.hh" #include "JAAnet/JFlux.hh" /** * \author bjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JClonable; /** * Implementation of event weighting for KM3BUU data. */ struct JEvtWeightKM3BUU : public JFluxHelper, public JClonable { /** * Default constructor. */ JEvtWeightKM3BUU() : JFluxHelper() {} /** * Constructor. * * \param header header */ JEvtWeightKM3BUU(const JHead& header) : JFluxHelper() { configure(header); } /** * Constructor. * * \param header header * \param flux flux */ JEvtWeightKM3BUU(const JHead& header, const JFlux& flux) : JFluxHelper() { configure(header); JFluxHelper::configure(flux); } /** * Copy constructor. * * \param object original object */ JEvtWeightKM3BUU(const JEvtWeightKM3BUU& object) { setNormalisation(object.getNormalisation()); if (static_cast(object)) { JFluxHelper::configure(*(object.get())); } } /** * Get name. * * \return name */ virtual const char* const getName() const override { return "KM3BUU"; } /** * Weight configuration. * * \param header header */ void configure(const JHead& header) override { using namespace JPP; if (check(header)) { const double Nevents = header.genvol.numberOfEvents; const double dt = (header.tgen.numberOfSeconds > 0.0 ? header.tgen.numberOfSeconds : 1.0); setNormalisation(1.0 / Nevents / dt); } else { THROW(JValueOutOfRange, "JEvtWeightKM3BUU::configure(): Provided header is inconsistent with KM3BUU."); } } /** * 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_km3buu(header); } /** * Get weight of given event. * * \param evt event * \return weight [Hz] */ double getWeight(const Evt& evt) const override { using namespace JPP; if (static_cast(*this) && evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) { return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt); } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) { return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE]; } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) { return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt); } else { if (!static_cast(*this)) { THROW(JNullPointerException, "JEvtWeightKM3BUU::getWeight(): Unspecified flux function."); } else { THROW(JIndexOutOfRange, "JEvtWeightKM3BUU::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight."); } } } }; } #endif