#ifndef WEIGHTHH #define WEIGHTHH #include "Evt.hh" #include "Flux.hh" #include "Head_util.hh" /*! \brief Construct a function to weight the events. This function takes a Head object, a desired live-time and optionally a Flux object. It returns a function that can be used to compute the event weight. Depending on the flux and the information in Head, the weigh should be computed in the correct way. For data-files, the weighting function should always return 1.0. For mupage files, the weighting function will apply a simple scaling to the desired live-time. For neutrino-mc (genhen, gseagen) files, the weighting function will use the 'w2' and the flux to compute the correct weight. */ inline std::function< double (const Evt& evt) > make_weight_function( Head& head, double livetime = -1, const DiffuseFlux* flux = NULL ) { double mupage_livetime, ngen; bool have_flux = (flux != NULL); bool have_livetime = (livetime != -1); if (!have_livetime) livetime = 365 * 24 * 3600; // default: 1 yr switch ( filetype( head ) ) { case filetype_t::data : if ( !have_livetime ) fatal("livetime is specified for data file"); return [] ( const Evt & evt ) // flux and livetime ignored { return 1; }; break; case filetype_t::mupage : if ( have_flux ) fatal("Flux is specified for mupage-file"); mupage_livetime = head.mc_livetime(); return [ = ] ( const Evt & evt ) { return livetime / mupage_livetime; }; break; case filetype_t::genhen : case filetype_t::gseagen : if (!have_flux) fatal("no flux specified for genhen/gseagen file"); ngen = head.ngen() / ( 365 * 24 * 3600 ) ; return [ = ]( const Evt & evt ) { const Trk& nu = * ( const_cast< Evt&>(evt)).primary_neutrino(); // todo: fix const stuff return livetime / ngen * evt.w[1] * flux->dNdEdOmega( nu ) ; }; break; default : print("no weighting scheme implemented for filetype", filetype(head) ); return []( const Evt & evt ) { print("weight function not valid.") ; return 0; }; } } #endif