#ifndef __JAANET__JEVTWEIGHTGSEAGEN__ #define __JAANET__JEVTWEIGHTGSEAGEN__ #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 GSeaGen data. */ struct JEvtWeightGSeaGen : public JFluxHelper, public JClonable { /** * Default Constructor. */ JEvtWeightGSeaGen() : JFluxHelper() {} /** * Constructor. * * \param header header */ JEvtWeightGSeaGen(const JHead& header) : JFluxHelper() { configure(header); } /** * Constructor. * * \param header header * \param flux flux */ JEvtWeightGSeaGen(const JHead& header, const JFlux& flux) : JFluxHelper() { configure(header); JFluxHelper::configure(flux); } /** * Copy constructor. * * \param object original object */ JEvtWeightGSeaGen(const JEvtWeightGSeaGen& object) { this->norm = object.norm; if (object.is_valid()) { JFluxHelper::configure(*(object.get())); } } /** * Weight normalisation 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); norm = 1.0 / Nevents / dt; } else { THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen."); } } /** * 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_gseagen(header); } /** * Get weight of given event. * * \param evt event * \return weight [Hz] */ double getWeight(const Evt& evt) const override { using namespace JPP; if (is_valid() && 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 (!is_valid()) { THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function."); } else { THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight."); } } } }; } #endif