#ifndef __JAANET__JEVTWEIGHTFACTORFUNCTION__ #define __JAANET__JEVTWEIGHTFACTORFUNCTION__ #include "km3net-dataformat/offline/Evt.hh" #include "flux/Flux.hh" #include "JLang/JClonable.hh" #include "JAAnet/JEvtWeightFactor.hh" #include "JAAnet/JFlux.hh" #include "JAAnet/JDiffuseFlux.hh" /** * \author bjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JClonable; /** * Implementation of event-weight factor interface. * * The first template argument refers to a function of which the copy constuctor needs to be defined. * The second template argument corresponds to the desired event-weight factor interface class. */ template struct JEvtWeightFactorFunction : public JClonable > { /** * Constructor. * * \param function function for event-weight factor */ JEvtWeightFactorFunction(const JFunction_t& function) : function(function) {} /** * Get weight-factor for given event. * * \param evt event * \return event-weight factor */ double getFactor(const Evt& evt) const override { return function(evt); } private: JFunction_t function; //!< event-weight factor object. }; /** * Implementation of event-weight factor interface for diffuse flux objects. * * The template argument corresponds to a function of which the copy constructor needs to be defined. */ template struct JEvtWeightFactorFunction : public JClonable > { /** * Constructor. * * \param function flux function */ JEvtWeightFactorFunction(const JDiffuseFluxFunction_t& function) : function(function) {} /** * Get event-weight factor for given particle PDG-identifier, energy and zenith-angle. * * \param type PDG particle type * \param log10E logarithmic neutrino energy [GeV] * \param costh cosine zenith angle * \return event-weight factor */ double dNdEdOmega(int type, double log10E, double costh) const override { return function.dNdEdOmega(type, log10E, costh); } private: JDiffuseFluxFunction_t function; //!< diffuse flux function object }; /** Type definition of event-weight factor pointer. */ typedef double (*pEvtWeightFactor)(const Evt&); /** Type definition of flux function pointer. */ using pFlux = pEvtWeightFactor; /** * Implementation of C-style event-weight factor. * * The template argument refers to the desired event-weight factor interface class. */ template struct JEvtWeightFactorFunction : public JClonable > { /** * Constructor. * * \param pFunction pointer to event-weight factor */ JEvtWeightFactorFunction(pEvtWeightFactor pFunction) : pFunction(pFunction) {} /** * Get weight-factor for given event. * * \param evt event * \return event-weight factor */ double getFactor(const Evt& evt) const override { return (*pFunction)(evt); } private: pEvtWeightFactor pFunction; //!< Event-weight factor pointer. }; /** Type definition of pointer to diffuse flux function. */ typedef double (*pDiffuseFlux)(int, double, double); /** * Implementation of C-style diffuse flux event-weight factor. */ template<> struct JEvtWeightFactorFunction : public JClonable > { /** * Constructor. * * \param pFunction pointer to diffuse flux function */ JEvtWeightFactorFunction(pDiffuseFlux pFunction) : pFunction(pFunction) {} /** * Get event-weight factor for given particle PDG-identifier, energy and zenith-angle. * * \param type PDG particle type * \param log10E logarithmic neutrino energy [GeV] * \param costh cosine zenith angle * \return event-weight factor */ double dNdEdOmega(int type, double log10E, double costh) const override { return (*pFunction)(type, log10E, costh); } private: pDiffuseFlux pFunction; //!< Pointer to diffuse flux function. }; /** * Auxiliary method for creating an interface to an event-weight factor. * * \param function function object * \return event-weight factor interface */ template inline JEvtWeightFactorFunction make_weightFactor(const JFunction_t& function) { return JEvtWeightFactorFunction(function); } /** * Auxiliary method for creating an interface to an event-weight factor. * * \param function function pointer * \return event-weight factor interface */ template inline JEvtWeightFactorFunction make_weightFactor(pEvtWeightFactor function) { return JEvtWeightFactorFunction(function); } /** * Auxiliary method for creating an interface to a flux function. * * \param flux flux function object * \return flux function interface */ template inline JEvtWeightFactorFunction make_fluxFunction(const JFunction_t& flux) { return JEvtWeightFactorFunction(flux); } /** * Auxiliary method for creating an interface to a flux function. * * \param flux flux function pointer * \return flux function interface */ inline JEvtWeightFactorFunction make_fluxFunction(pFlux flux) { return JEvtWeightFactorFunction(flux); } /** * Auxiliary method for creating an interface to a diffuse flux function. * * \param flux diffuse flux function object * \return diffuse flux function interface */ template inline JEvtWeightFactorFunction make_diffuseFluxFunction(const JFunction_t& flux) { return JEvtWeightFactorFunction(flux); } /** * Auxiliary method for creating an interface to a diffuse flux function. * * \param flux diffuse flux function pointer * \return diffuse flux function interface */ inline JEvtWeightFactorFunction make_diffuseFluxFunction(pDiffuseFlux flux) { return JEvtWeightFactorFunction(flux); } } #endif