“how to write loki functors ?”

21
“How to write LoKi functors?” Vanya BELYAEV

Upload: odin

Post on 24-Feb-2016

79 views

Category:

Documents


0 download

DESCRIPTION

“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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: “How to write   LoKi functors ?”

“How to write LoKi functors?”

Vanya BELYAEV

Page 2: “How to write   LoKi functors ?”

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…

24 Mar 2k+9

Page 3: “How to write   LoKi functors ?”

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

24 Mar 2k+9

Page 4: “How to write   LoKi functors ?”

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

24 Mar 2k+9

Page 5: “How to write   LoKi functors ?”

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”

24 Mar 2k+9

Page 6: “How to write   LoKi functors ?”

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

24 Mar 2k+9

Page 7: “How to write   LoKi functors ?”

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”

24 Mar 2k+9

Page 8: “How to write   LoKi functors ?”

Vanya BELYAEV 8

Event Data access

• Trivial for “other” frameworks:

VRange primaries = vselect ( "Primaries", PRIMARY ) ;

… const LHCb::Particle* B = … ; VRange::iterator ipv = select_min( primaries.begin() , primaries.end() , VIPCHI2( B , geo() ) , VALL ) ;

…const LHCb::VertexBase* primary = *ipv ;

24 Mar 2k+9

Page 9: “How to write   LoKi functors ?”

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 …

24 Mar 2k+9

Page 10: “How to write   LoKi functors ?”

Vanya BELYAEV 10

Backup solution

• Each LoKi functor 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>

24 Mar 2k+9

Page 11: “How to write   LoKi functors ?”

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

24 Mar 2k+9

Page 12: “How to write   LoKi functors ?”

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

24 Mar 2k+9

Page 13: “How to write   LoKi functors ?”

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” ;

24 Mar 2k+9

Page 14: “How to write   LoKi functors ?”

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());

24 Mar 2k+9

Page 15: “How to write   LoKi functors ?”

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)

24 Mar 2k+9

Page 16: “How to write   LoKi functors ?”

Vanya BELYAEV 16

For BPV* and *DV

class MyFunctor :virtual public LoKi::Functor<T1,T2>,virtual public LoKi::AuxDesktopBase

IPhysDesktop* getDesktop() const ; bool validDesktop() const ; void loadDesktop()

24 Mar 2k+9

Page 17: “How to write   LoKi functors ?”

Vanya BELYAEV 17

The last C++ hint

• Get access to DVAlgorithm:

DVAlgorithm* dv = Gaudi::Utils::getDVAlgorithm

( const IAlgContextSvc* ) ;

SmartIF<IAlgContextSvc> cntx ( lokiSvc() ) ;

24 Mar 2k+9

Page 18: “How to write   LoKi functors ?”

Vanya BELYAEV 18

Decoration

• Optional, but very useful• Add a symbol into LoKi::Cuts namespace• either type: typedef MyFunctor MYNICEFUNCTOR ;• Or instance const MyFunctor MYNICEFUNCTOR(…) ;

• please be compatible with Python•Up to now all symbols in LoKi::Cuts

namespace are in uppercase

24 Mar 2k+9

Page 19: “How to write   LoKi functors ?”

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

24 Mar 2k+9

Page 20: “How to write   LoKi functors ?”

Vanya BELYAEV 20

Your functor is ready

• Now you can use your function in C++ using namespace LoKi::Cuts

• The functor is available in Pythonfrom LoKiXXX.decorators import *

• The functor is available for CombineParticles/FilterDesktop framework

from Configurables import LoKi__Hybrid__Tool as FactoryFactory ( “HybridFactory” , Modules += [ “LoKiXXX.decorators” ] )

24 Mar 2k+9

Page 21: “How to write   LoKi functors ?”

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 )

24 Mar 2k+9