1 / 21

“How to write LoKi functors ?”

“How to write LoKi functors ?” . Vanya BELYAEV. … . I am not sure that this question is right or valid question at all… Let me try to convince you … Each framework has its own application range The complicated stuff for one framework is usually just a trivial within another framework

odin
Download Presentation

“How to write LoKi functors ?”

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. “How to write LoKifunctors?” Vanya BELYAEV

  2. • I am not sure that this question is right or valid question at all… • Let me try to convince you … • Each framework has its own application range • The complicated stuff for one framework is usually just a trivial within another framework • Choose right framework… • Each problem could be drastically simplified with “non-dogmatic” approach • Otherwise: back-up solution for couple of last slides… Vanya BELYAEV

  3. Frameworks and their purposes • We have many “frameworks”, somehow suited for “analysis” purposes: • pure Gaudi + LHCb event model • + the same in Python • “minimal” DaVinci: input/output, standard components, low-level tools: fitters, makers, etc.. • CombineParticles & FilterDesktop • + TupleTool&Co • LoKi • Bender Vanya BELYAEV

  4. “Analysis I” • Select/filter events/candidates using CombineParticle & FilterDesktop • Rather generic • Dump the event into (complicated) NTuple/TTree (“image of event”) using TupleTool&Co • Rather generic • Analyse it with (complicated) ROOT/HBOOK macros/kumacs • Specific Vanya BELYAEV

  5. “Analysis – II” • Embed the NTuples/histograms into the specific C++/Python “analysis” algorithm • “Analysis” • Specific C++/python code • Easy& intuitive structure of NTuple/Tree/histos • (multidimensional histogram) • Event selection/filtering is not main goal, but one gets it for free • Analysis in ROOT/PAW is statistical only • No “reconstruction” Vanya BELYAEV

  6. Analysis & Selection • Try to distinguish these concepts… • “Analysis” is a bit more private stuff • Well suited for your particular needs • Your own choice of tools & methods • “Selection” needs to satisfy some general criteria & constraints • E.g. must run for event stripping, or needs to be “HLT2-aware” But there is no Berlin Wall between these concepts Vanya BELYAEV

  7. Some cuts/variables are rather difficult to CombineParticles/FiltyerDesktop framework • Either code your own functor • Or (much better) reconsider the framework • The main difficulty is access to “other” event–data, e.g. primary vertices and selection of “the best” • Or notorious “vertex isolation” Vanya BELYAEV

  8. Event Data access • Trivial for “other” frameworks: VRangeprimaries = vselect ( "Primaries", PRIMARY ) ; … const LHCb::Particle* B = … ; VRange::iteratoripv = select_min( primaries.begin() , primaries.end() , VIPCHI2( B , geo() ) , VALL ) ; … const LHCb::VertexBase* primary = *ipv; Vanya BELYAEV

  9. Event Data access • Trivial for “other” frameworks: pvs= self.vselect( "Primaries", PRIMARY ) ; B = … ; pv= LoKi.SelectVertex.selectMin( pvs, VIPCHI2( B , self.geo() ) , VALL ) ; # or even code five lines yourself: def selectMin ( lst , fun , cut ) : for o in lst : … return … Vanya BELYAEV

  10. Backup solution • Each LoKifunctor inherits from • LoKi::Functor<TYPE1,TYPE2> • TYPE2 : • double - “ function” • bool - “predicate” • std::vector<TYPE3> - various streamers • TYPE1: const LHCb::Particle*, const LHCb::VertexBase*, const LHCb::MCParticle*, const LHCb::MCVertex*, const HepMC::GenParticle*, const HepMC::GenVertex*, LHCb::Track, LHCb::RecVertex, void, const LHCb::L0DUReport*, const LHCb::HltDecisionReport*, const LHCb::ODIN*, LoKi::Holder<TYPE3,TYPE4>, std::vector<TYPE5> Vanya BELYAEV

  11. “The method” • Only one essential method: result_type operator() ( argument a ) const ; • Never use TYPE1, TYPE2: • Use result_type and argument only Vanya BELYAEV

  12. Required by system: • Virtual destructor: virtual ~MyFunctor() {} • Usually empty… • Clone method (“virtual constructor”) virtual MyFunctor* clone() const ; • Typical implementation (recommended) return new MyFunctor(*this) ; • Attention: refers to copy constructor • And probably implicitly relies on their agreement also Vanya BELYAEV

  13. Optional • Nice self-printout: std::ostream& fillStream( std::ostream& s ) const; • The implementation is up to you… • The default: print the actual C++ type • Recommended: • Be compatible with python (the same symbol) • Valid python expression (instance!) return s << “M” ; Vanya BELYAEV

  14. Internals: • Useful inside the implementation Error, Warning, Exceptions, Assert • Similar to GaudiAlgorithm/GaudiTool “toString”, “objType”, “id”, “printOut” • Services: LoKi::ILoKiSvc* lokiSvc() const ; • Many services are available through SmartIF SmartIF<ISvcLocator> svc ( lokiSvc()); if (!svc ) { … } SmartIF<IToolSvc> tool ( lokiSvc()); Vanya BELYAEV

  15. Rare stuff: long event() const ; void setEvent( long evt ) const ; void setEvent() const ; • Could be used for various optimization • Should be used with some care (fragile) Vanya BELYAEV

  16. For BPV* and *DV class MyFunctor :virtual public LoKi::Functor<T1,T2> ,virtual public LoKi::AuxDesktopBase IPhysDesktop* getDesktop() const ; boolvalidDesktop() const ; void loadDesktop() Vanya BELYAEV

  17. The last C++ hint • Get access to DVAlgorithm: DVAlgorithm* dv = Gaudi::Utils::getDVAlgorithm ( const IAlgContextSvc* ) ; SmartIF<IAlgContextSvc> cntx ( lokiSvc() ) ; Vanya BELYAEV

  18. Decoration • Optional, but very useful • Add a symbol into LoKi::Cuts namespace • either type: typedefMyFunctor MYNICEFUNCTOR ; • Or instance const MyFunctor MYNICEFUNCTOR(…) ; • please be compatible with Python • Up to now all symbols in LoKi::Cuts namespace are in uppercase Vanya BELYAEV

  19. Want to use it in Python? • Make dictionaries: <class name=“…::MyFunctor” /> • Hint: put it into one of the “standard” namespaces, it will be picked up automatically • Find proper python/LoKiXXX/functions.py • declare your symbol to the python: • “typedef”: MYNICEFUNCTOR = XXX.MyFunctor • “instance” MYNICEFUNCTOR = XXX.MyFunctor(…) • Please be in agreement with LoKi::Cuts Vanya BELYAEV

  20. Your functor is ready • Now you can use your function in C++ using namespace LoKi::Cuts • The functor is available in Python from LoKiXXX.decorators import * • The functor is available for CombineParticles/FilterDesktop framework from Configurables import LoKi__Hybrid__Tool as Factory Factory ( “HybridFactory” , Modules += [ “LoKiXXX.decorators” ] ) Vanya BELYAEV

  21. Warnings… • Please do not code functors like: const LHCb::Particle* B = … ; const bool ok = SelectSpecificDecay ( B ) ; • Please do not code functors like sin( Slog pt)/cosh( S ip ) Vanya BELYAEV

More Related