#ifndef __JAANET__JEVTWEIGHTFACTORHELPER__ #define __JAANET__JEVTWEIGHTFACTORHELPER__ #include #include "km3net-dataformat/offline/Evt.hh" #include "JAAnet/JEvtWeightFactor.hh" #include "JAAnet/JFlux.hh" #include "JAAnet/JDiffuseFlux.hh" /** * \author bjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { /** * 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 std::shared_ptr { typedef JEvtWeightFactorHelper JEvtWeightFactorHelper_t; typedef std::shared_ptr pointer_type; /** * 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) { using namespace JPP; JEvtWeightFactor_t* p = dynamic_cast(factor.clone()); if (p != NULL) { this->reset(p); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast to class derived from JEvtWeightFactor."); } } /** * Get reference to event-weight factor. * * \return reference to event-weight factor */ JEvtWeightFactor_t& getEvtWeightFactor() const { using namespace JPP; if (static_cast(*this)) { return *(this->get()); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::getEvtWeightFactor(): Event-weight factor is not set."); } } /** * Get weight-factor of given event. * * \param evt event * \return event-weight factor */ double getFactor(const Evt& evt) const { const JEvtWeightFactor_t& weightFactor = getEvtWeightFactor(); return weightFactor.getFactor(evt); } }; /** * Explicit emplate specialization of event-weight factor helper for diffuse flux objects. */ template<> struct JEvtWeightFactorHelper : public std::shared_ptr { typedef JEvtWeightFactorHelper JDiffuseFluxHelper_t; typedef std::shared_ptr pointer_type; /** * 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) { using namespace JPP; JDiffuseFlux* p = dynamic_cast(diffuseFlux.clone()); if (p != NULL) { reset(p); } else { THROW(JNullPointerException, "JDiffuseFluxHelper::configure(): Unable to retrieve diffuse flux interface."); } } /** * Get reference to diffuse flux factor. * * \return reference to diffuse flux factor */ JDiffuseFlux& getDiffuseFlux() const { using namespace JPP; if (static_cast(*this)) { return *(this->get()); } else { THROW(JNullPointerException, "JDiffuseFluxHelper::getDiffuseFlux(): Diffuse flux factor is not set."); } } /** * 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 { const JDiffuseFlux& diffuseFlux = getDiffuseFlux(); return diffuseFlux.getFactor(type, log10E, costh); } /** * 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 { const JDiffuseFlux& diffuseFlux = getDiffuseFlux(); return diffuseFlux.getFactor(evt); } }; /** 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