#ifndef EVT_UTIL_HH_INCLUDED #define EVT_UTIL_HH_INCLUDED #include "Evt.hh" inline string _trk_tostr( Trk* t , string prefix , Evt& evt , int code = 0 ) { string s = ""; string ss = t->name(); if ( t == evt.primary_neutrino() ) ss += " (primary neutrino)"; if ( t == evt.leading_lepton() ) ss += " (leading_lepton)"; ss += " E="+str( t->E ); ss += " status/id=" + str(t->status) +"/"+str(t->id); if (code ==2 ) s += prefix + "--> "+ ss + "\n"; // primary if (code ==0 ) s += prefix + "\b+-"+ ss + "\n"; // non-last sibling if (code ==1 ) s += prefix + "\b`-"+ ss + "\n"; // last sibling vector kids = t->get_daughters( evt.mc_trks ); for (unsigned i = 0 ; i < kids.size() ; i++) { bool last = i == kids.size()-1; Trk* k = kids[i]; string new_infix; if (last) new_infix = " "; else new_infix = " |"; s += _trk_tostr( k, prefix + new_infix , evt , last?1:0 ); } return s; } /*! Return string with a tree representing mc track relations */ inline string pretty_mc_tracks( Evt& evt ) { string s = "Monte Carlo Tracks for event " + str( evt.id ) +"\n"; foreach( p, evt.mc_trks ) { if ( p.mother_id == -1 || p.mother_id == -2 ) // todo: takek from definitions s += _trk_tostr( &p, " ", evt , 2 ); } return s; } /*! Return pointer to the best reconstructed track of a certain rec_type. (best is defined as the one with the most rec_stages, and within those, the one with the hightest value of lik(elihood) The optional (lambda) function selection_func(Trk) should return true if the track is to be considered. For example, to find the best existing downgoing track with rec_type 4000: best_reco_track( e.trks , 0 , [](Trk& t){return t.dir.z<0;} ) for existing producitons: for JGandalf track-fit : rec_type = 4000 for aashowerfit : rec_type = 101 for future procuctions: see km3net-dataformat/definitions/reconstruction.hh/py Returns a nullptr when no track of the requested rectype exists. */ inline bool ___altrks( Trk& t ) {return true;} // just for the default argument template inline Trk* best_reco_track( vector& trks, int rec_type , F selection_func = ___altrks ) { Trk* r = 0; for( auto& t : trks ) { if ( t.rec_type != rec_type ) continue; if ( !selection_func(t) ) continue; if ( !r || (t.rec_stages.size() > r -> rec_stages.size() ) || ( (t.rec_stages.size() == r -> rec_stages.size() ) && t.lik > r->lik ) ) r = &t; } return r; } /*! Return pointer to the best reconstructed track of a certain rec_type. (best is defined as the one with the most rec_stages, and within those, the one with the hightest value of lik(elihood) for existing producitons: for JGandalf track-fit : rec_type = 4000 for aashowerfit : rec_type = 101 for future procuctions: see km3net-dataformat/definitions/reconstruction.hh/py */ inline Trk* best_reco_track( Evt& evt, int rec_type ) { return best_reco_track( evt.trks , rec_type ); } /*! find out which hits are signal, etc */ inline void add_truth_to_hits( Evt& evt , double delta = 10 ) { double offset = fmod( evt.mc_t , 1e8 ); map > M; for(auto& h : evt.mc_hits ) M[h.pmt_id].push_back( &h ); for(auto& h : evt.hits ) { h.origin = h.type = -1; for( auto p : M[h.pmt_id] ) { cout << h.t - p->t - offset << endl; if ( abs( h.t - p->t - offset ) < delta ) { h.origin = p->origin; if ( p->type !=-1 ) h.type = p->type; } } } } #endif