#ifndef __JAANET__JEVTWEIGHTGENHEN__ #define __JAANET__JEVTWEIGHTGENHEN__ #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 Genhen data. */ struct JEvtWeightGenhen : public JFluxHelper, public JClonable { /** * Default Constructor. */ JEvtWeightGenhen() : JFluxHelper() {} /** * Constructor. * * \param header header */ JEvtWeightGenhen(const JHead& header) : JFluxHelper() { configure(header); } /** * Constructor. * * \param header header * \param flux flux */ JEvtWeightGenhen(const JHead& header, const JFlux& flux) : JFluxHelper() { configure(header); JFluxHelper::configure(flux); } /** * Copy constructor. * * \param object original object */ JEvtWeightGenhen(const JEvtWeightGenhen& object) { setNormalisation(object.getNormalisation()); if (static_cast(object)) { JFluxHelper::configure(*(object.get())); } } /** * Get name. * * \return name */ virtual const char* const getName() const override { return "Genhen"; } /** * Weight normalisation configuration. * * \param header header */ void configure(const JHead& header) override { using namespace JPP; if (check(header)) { const double Nevents = header.genvol.numberOfEvents; setNormalisation(1.0 / Nevents / (60*60*24*365)); } else { THROW(JValueOutOfRange, "JEvtWeightGenhen::configure(): Provided header is inconsistent with Genhen."); } } /** * 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_genhen(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, "JEvtWeightGenhen::getWeight(): Unspecified flux function."); } else { THROW(JIndexOutOfRange, "JEvtWeightGenhen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight."); } } } }; } #endif