#ifndef __JAANET__JEVTWEIGHTFACTORHELPER__ #define __JAANET__JEVTWEIGHTFACTORHELPER__ #include "km3net-dataformat/offline/Evt.hh" #include "JLang/JSharedPointer.hh" #include "JAAnet/JEvtWeightFactor.hh" #include "JAAnet/JFlux.hh" #include "JAAnet/JDiffuseFlux.hh" /** * \author bjung */ namespace JAANET { using JLANG::JSharedPointer; using JLANG::JNullPointerException; /** * Helper class for event-weight factor. * * The template argument corresponds to the desired event-weight factor class. * This class must contain the method `getFactor(const Evt&)`. */ template struct JEvtWeightFactorHelper : public JSharedPointer { using JSharedPointer::is_valid; using JSharedPointer::reset; using JSharedPointer::get; /** * Default constructor. */ JEvtWeightFactorHelper() {} /** * Constructor. * * \param factor event-weight factor */ JEvtWeightFactorHelper(const JEvtWeightFactor_t& factor) { configure(factor); } /** * Configure event-weight factor. * * \param factor event-weight factor */ void configure(const JEvtWeightFactor_t& factor) { JEvtWeightFactor_t* p = dynamic_cast(factor.clone()); if (p != NULL) { reset(p); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast to class derived from JEvtWeightFactor."); } } /** * Get weight-factor of given event. * * \param evt event * \return event-weight factor */ double getFactor(const Evt& evt) const { if (is_valid()) { return get()->getFactor(evt); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Unspecified event-weighting factor."); } } }; /** * Explicit emplate specialization of event-weight factor helper for diffuse flux objects. */ template<> struct JEvtWeightFactorHelper : public JSharedPointer { using JSharedPointer::is_valid; /** * Default constructor. */ JEvtWeightFactorHelper() {} /** * Constructor. * * \param diffuseFlux diffuse flux function */ JEvtWeightFactorHelper(const JDiffuseFlux& diffuseFlux) { configure(diffuseFlux); } /** * Configure oscillation probability function. * * \param diffuseFlux diffuse flux function */ void configure(const JDiffuseFlux& diffuseFlux) { JDiffuseFlux* p = dynamic_cast(diffuseFlux.clone()); if (p != NULL) { reset(p); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast from JEvtWeightFactor to JDiffuseFlux."); } } /** * Get diffuse flux corresponding to given neutrino type, energy and zenith angle. * * \param type PDG particle type * \param log10E logarithmic neutrino energy [GeV] * \param costh cosine zenith angle * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1] */ double getFactor(const int type, const double log10E, const double costh) const { if (is_valid()) { return get()->getFactor(type, log10E, costh); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::dNdEdOmega(): Unspecified diffuse flux function."); } } /** * Get diffuse flux corresponding to given neutrino type, energy and zenith angle. * * \param evt event * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1] */ double getFactor(const Evt& evt) const { if (is_valid()) { return get()->getFactor(evt); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Unspecified diffuse flux function."); } } }; /** Type definition of event-weight factor helper for flux functions.*/ typedef JEvtWeightFactorHelper JFluxHelper; /** Type definition of event-weight factor helper for diffuse flux objects. */ typedef JEvtWeightFactorHelper JDiffuseFluxHelper; } #endif