#ifndef __JAANET__JEVTWEIGHTGSEAGEN__ #define __JAANET__JEVTWEIGHTGSEAGEN__ #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 { using JLANG::JClonable; using JLANG::JIndexOutOfRange; using JLANG::JNullPointerException; /** * Implementation of event weighting for GSeaGen data. */ struct JEvtWeightGSeaGen : public JClonable, public JEvtWeightFactorHelper { typedef JEvtWeightFactorHelper JFluxHelper_t; /** * Default Constructor. */ JEvtWeightGSeaGen() : JFluxHelper_t() {} /** * Constructor. * * \param header header */ JEvtWeightGSeaGen(const JHead& header) : JFluxHelper_t() { configure(header); } /** * Constructor. * * \param header header * \param flux flux */ JEvtWeightGSeaGen(const JHead& header, const JFlux& flux) : JFluxHelper_t() { configure(header); JFluxHelper_t::configure(flux); } /** * Copy constructor. * * \param object original object */ JEvtWeightGSeaGen(const JEvtWeightGSeaGen& object) { this->norm = object.norm; if (object.is_valid()) { JFluxHelper_t::configure(*(object.get())); } } /** * Weight normalisation configuration. * * \param header header */ void configure(const JHead& header) override { const double Nevents = header.genvol.numberOfEvents; const double dt = (header.tgen.numberOfSeconds > 0.0 ? header.tgen.numberOfSeconds : 1.0); if (check(header) && Nevents > 0.0 && dt > 0.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 { if (is_valid() && evt.w.size() > 1) { return evt.w[1] * getFactor(evt) * norm; } else if (evt.w.size() > 2) { return evt.w[2] * norm; } 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