#ifndef __JAANET__JEVTWEIGHTKM3BUU__ #define __JAANET__JEVTWEIGHTKM3BUU__ #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 KM3BUU data. */ struct JEvtWeightKM3BUU : public JClonable, public JEvtWeightFactorHelper { typedef JEvtWeightFactorHelper JFluxHelper_t; /** * Default constructor. */ JEvtWeightKM3BUU() : JFluxHelper_t() {} /** * Constructor. * * \param header header */ JEvtWeightKM3BUU(const JHead& header) : JFluxHelper_t() { configure(header); } /** * Constructor. * * \param header header * \param flux flux */ JEvtWeightKM3BUU(const JHead& header, const JFlux& flux) : JFluxHelper_t() { configure(header); JFluxHelper_t::configure(flux); } /** * Copy constructor. * * \param object original object */ JEvtWeightKM3BUU(const JEvtWeightKM3BUU& object) { this->norm = object.norm; JFluxHelper_t::configure(*(object.get())); } /** * Weight 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, "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 { 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, "JEvtWeightKM3BUU::getWeight(): Unspecified flux function."); } else { THROW(JIndexOutOfRange, "JEvtWeightKM3BUU::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight."); } } } }; } #endif