loki & bender user friendly physics analysis tools

39
LoKi & Bender LoKi & Bender User Friendly Physics User Friendly Physics Analysis Tools Analysis Tools Vanya BELYAEV NIKHEF, NIKHEF, Amsterdam, Amsterdam, on leave from ITEP/Moscow on leave from ITEP/Moscow

Upload: lance

Post on 08-Feb-2016

47 views

Category:

Documents


2 download

DESCRIPTION

LoKi & Bender User Friendly Physics Analysis Tools. Vanya BELYAEV NIKHEF, Amsterdam, on leave from ITEP/Moscow. Trivia (I). The modern HEP experiment in the coming “LHC-epoch” are large and enormously difficult & complicated - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: LoKi  & Bender  User Friendly Physics Analysis Tools

LoKi & Bender LoKi & Bender User Friendly Physics Analysis User Friendly Physics Analysis

Tools Tools

Vanya BELYAEV NIKHEF, NIKHEF, Amsterdam, Amsterdam,

on leave from ITEP/Moscow on leave from ITEP/Moscow

Page 2: LoKi  & Bender  User Friendly Physics Analysis Tools

Trivia (I)

•The modern HEP experiment in the coming “LHC-The modern HEP experiment in the coming “LHC-epoch” are large and enormously difficult & epoch” are large and enormously difficult & complicated complicated

•Many different& sophisticated techniques for Many different& sophisticated techniques for particle/jet detection and identification particle/jet detection and identification •&simulation&simulation

•Many different reconstruction techniques and Many different reconstruction techniques and methods methods

•Many physicists & Software engineers work hard Many physicists & Software engineers work hard on the software development on the software development •In parallel …In parallel …

•Huge data samples (Huge data samples (≥≥10101010 /year) are expected /year) are expected

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 22

Page 3: LoKi  & Bender  User Friendly Physics Analysis Tools

Trivia (II)

• Complexity of the problem demands the Complexity of the problem demands the outstanding powerfulness of the software, outstanding powerfulness of the software, and (unavoidably) the complexity and (unavoidably) the complexity

• C++ “de-facto” standard of the sofware for C++ “de-facto” standard of the sofware for LHC epoch LHC epoch

•No real alternative for reconstruction & No real alternative for reconstruction & simulation tasksimulation task

•(almost) no generic way to make these tasks (almost) no generic way to make these tasks “simple”“simple”

Should it be the only one option for physics analysis?Should it be the only one option for physics analysis?

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 33

Page 4: LoKi  & Bender  User Friendly Physics Analysis Tools

Trivia (III)

•What bad in usage of C++ for physics analysis?What bad in usage of C++ for physics analysis?

•C++ is not something very simpleC++ is not something very simple

•Some initial learning period is required:Some initial learning period is required:

•learning curve is non-trivial, and does take timelearning curve is non-trivial, and does take time

• C++ requires some discipline & training C++ requires some discipline & training

• C++ offers many non-trivial ways for solution C++ offers many non-trivial ways for solution of many difficult problemsof many difficult problems

•Often a great fun for young students…Often a great fun for young students…

What about the senior physicists?What about the senior physicists?

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 44

Page 5: LoKi  & Bender  User Friendly Physics Analysis Tools

Trivia (IV)

• The practice shows that as concern the The practice shows that as concern the epoche of C++ dominance many epoche of C++ dominance many experienced senior physicists are cut off from experienced senior physicists are cut off from the real physics analysis the real physics analysis

•Few exceptions are also obvious: Few exceptions are also obvious:

•“ “ Hi, Bill! Would you be so kind to prepare Hi, Bill! Would you be so kind to prepare HBOOK-ntuple with the HBOOK-ntuple with the <a,b,c,…,x,y,z><a,b,c,…,x,y,z> variables for me around tomorrow lunchtime?” variables for me around tomorrow lunchtime?”

•Is it the only way to reuse their great physics Is it the only way to reuse their great physics experience?experience?

• Are there some other exceptions?Are there some other exceptions?

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 55

Page 6: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 66

Counterexample?

KALKAL by genius Hartwig by genius Hartwig AlbrechtAlbrecht

• Script-like fileScript-like file• All technical details are All technical details are

well hidden from end-well hidden from end-usersusers

• Transparent physical Transparent physical content of the codecontent of the code

• Looping, histograms, N-Looping, histograms, N-tuples, MC truth - at most tuples, MC truth - at most 1 line!1 line!

• TypicalTypical analysis program ~ analysis program ~ 50-70 lines50-70 lines

• All senior persons, All senior persons, including the including the spokesman spokesman successfully successfully participated in physics analysisparticipated in physics analysis

HYPOTH E+ MU+ PI+ 5 K+ PROTONHYPOTH E+ MU+ PI+ 5 K+ PROTON

IDENT PI+ PI+IDENT PI+ PI+IDENT K+ K+ IDENT K+ K+ IDENT E+ E+IDENT E+ E+IDENT PROTON PROTON IDENT PROTON PROTON IDENT MU+ MU+IDENT MU+ MU+

SELECT K- pi+SELECT K- pi+ IF P > 2 THEN IF P > 2 THEN SAVEFITM D0 DMASS 0.040 CHI2 4SAVEFITM D0 DMASS 0.040 CHI2 4 ENDIFENDIFENDSELENDSEL

SELECT D0 pi+SELECT D0 pi+ PLOT MASS L 2.0 H 2.1 NB 100 @PLOT MASS L 2.0 H 2.1 NB 100 @ TEXT ‘ mass D0 pi+ ‘TEXT ‘ mass D0 pi+ ‘ENDSELENDSEL

GO 1000 GO 1000

Page 7: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 77

Is the goal achievable with C++ ?

• Majority (but me) is Majority (but me) is convinced that convinced that C++C++ features features (verbosity, static nature etc) (verbosity, static nature etc) do not allow to use it as do not allow to use it as friendly language for physics friendly language for physics analysisanalysis

TrackPattern PiMinus = pi_minus.with ( pt > 0.1 & p > 1 ) ;TrackPattern PiMinus = pi_minus.with ( pt > 0.1 & p > 1 ) ;

TrackPattern PiPlus = pi_plus.with ( pt > 0.1 & p > 1 ) ;TrackPattern PiPlus = pi_plus.with ( pt > 0.1 & p > 1 ) ;

TwoProngDecay kShort = K0S.decaysTo ( PiMinus & PiPlus ) ;TwoProngDecay kShort = K0S.decaysTo ( PiMinus & PiPlus ) ;

kShort.with ( vz > 0 ) ;kShort.with ( vz > 0 ) ;

kShort.with ( pt > 0.1 ) ;kShort.with ( pt > 0.1 ) ;

GPatternGPattern package by package by Thorsten Glebe (HERA-Thorsten Glebe (HERA-

B)B)

•Native C++Native C++

•Easy, readable and very Easy, readable and very efficientefficient

Page 8: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 88

Try to merge the best ideas: LoKiLoKi

• KALKAL by Hartwig Albrecht by Hartwig Albrecht• ‘‘1-line’ semantics1-line’ semantics• Predefined variablesPredefined variables

• GPatternGPattern and and GCombinerGCombiner by by Thorsten GlebeThorsten Glebe• Cuts and patternsCuts and patterns

select ( “K-” , ID == “K-” && CL > 0.01 && P > 5 * GeV ) ;select ( “K-” , ID == “K-” && CL > 0.01 && P > 5 * GeV ) ;select ( “PI+” , ID == “pi+” && CL > 0.01 && P > 5 * GeV ) ;select ( “PI+” , ID == “pi+” && CL > 0.01 && P > 5 * GeV ) ; for ( Loop D0 = loop( “K- PI+” , “D0” ) ; D0 ; ++D0 ) for ( Loop D0 = loop( “K- PI+” , “D0” ) ; D0 ; ++D0 ) {{ if( P( D0 ) > 10 * GeV ) { D0->save( “D0” ) ; }if( P( D0 ) > 10 * GeV ) { D0->save( “D0” ) ; } } } for ( Loop Dstar = loop( “D0 PI+” , “D*+” ) ; Dstar ; ++Dstar )for ( Loop Dstar = loop( “D0 PI+” , “D*+” ) ; Dstar ; ++Dstar ) {{ plot ( “Mass of D0 pi+”, M(Dstar) / GeV , 2.0 , 2.1 , 100 ) ;plot ( “Mass of D0 pi+”, M(Dstar) / GeV , 2.0 , 2.1 , 100 ) ; }}

• HepChooserHepChooser and and HepCombinerHepCombiner from from obsolete obsolete CLHEPCLHEP

•Combinations, loopsCombinations, loops• LokiLoki by Andrei Alexandresku by Andrei Alexandresku

•Functions, name and Functions, name and spiritspirit

Page 9: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 99

LoKiLoKi: major design ideas

• Compact, easy to read and Compact, easy to read and transparent codetransparent code

• Hide Hide all all technicalities technicalities

• Implement Implement all ‘everyday idioms’all ‘everyday idioms’ as 1-line functionsas 1-line functions

• Locality: Locality:

• Declare, create and use the Declare, create and use the objects only ‘locally’objects only ‘locally’

• 1 analysis = 1 short file1 analysis = 1 short file

• High CPU performanceHigh CPU performance

• Reuse of the most modern Reuse of the most modern C++C++ techniques techniques

• Paradigm of templated Paradigm of templated compile time compile time metaprogrammingmetaprogramming• Lets compiler to “write” the code Lets compiler to “write” the code

• Implement everything as Implement everything as reusablereusable components components • LoKiLoKi functions are functions are

compatible withcompatible with LoLokkii, , STLSTL, , boostboost, , CLHEPCLHEP

• LoKiLoKi functions are used with functions are used with cuts, other functions, cuts, other functions, histograms, tuples, MC truth, histograms, tuples, MC truth, etcetc

• Weak coupling with concrete Weak coupling with concrete Event model, tools, etcEvent model, tools, etc

• Extendable Extendable

Page 10: LoKi  & Bender  User Friendly Physics Analysis Tools

Compactness of the code

•Important for readabilityImportant for readability

•Important for debuggingImportant for debugging

•Number of simple errors (typos) is Number of simple errors (typos) is proportional to the overall number of linesproportional to the overall number of lines

•Number of non-trivial errors also grows with Number of non-trivial errors also grows with the code lengththe code length

•There many models, but clearly:There many models, but clearly:

• the first derivative is positive : E’ > 0 the first derivative is positive : E’ > 0

• the second derivative is also positive: E’’ > 0the second derivative is also positive: E’’ > 0

•Some people claims also the ESome people claims also the Enn ≥≥ 0 0

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1010

Page 11: LoKi  & Bender  User Friendly Physics Analysis Tools

Locality

•““Typical” physics analysis code does not Typical” physics analysis code does not follow the concept of localityfollow the concept of locality

•Declaration & usage of variables often goes in Declaration & usage of variables often goes in the different places or event different the different places or event different compiling units compiling units

•True also for “good old FORTRAN” True also for “good old FORTRAN”

•C++ allows to eliminate some part of non-C++ allows to eliminate some part of non-localitylocality

• And (with proper design) it allows to eliminate And (with proper design) it allows to eliminate practically all non-locality:practically all non-locality: for( Loop B0 = loop ( “pi+ pi-” ), B0 , ++B ){…} for( Loop B0 = loop ( “pi+ pi-” ), B0 , ++B ){…}

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1111

Page 12: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF 13 May'2k+8 NIKHEF ColloquiumColloquium

Vanya BELYAEV Vanya BELYAEV 1212

Compactness & LocalityOne PPT slide == One screen of the code One PPT slide == One screen of the code

1 PPT slide of cut description1 PPT slide of cut description

1 page A4 of 1 page A4 of C++C++ code code

Page 13: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF 13 May'2k+8 NIKHEF ColloquiumColloquium

Vanya BELYAEV Vanya BELYAEV 1313

Compact code. Code metrics

Selection SLOC Person-month Cost [k$]

<…> 2.6 k2.6 k 6.56.5 7373

<…> 362362 0.80.8 99

<…> 1.1 k1.1 k 2.32.3 3030

<…> 1.5 k1.5 k 3.6 3.6 4040

<…> 1.4 k1.4 k 3.43.4 3838

<…> 3.2 k3.2 k 8.0 8.0 9191

<…> 530530 1.21.2 14 14

<…> 1.0 k1.0 k 2.32.3 3030

LoKiLoKi 128128 0.30.3 22

COCOMOCOCOMO model : model : SLOCCountSLOCCount by David A.Wheeler, by David A.Wheeler, 2k+42k+4

Page 14: LoKi  & Bender  User Friendly Physics Analysis Tools

The basics

• select/filter the particles with certain propertiesselect/filter the particles with certain properties

•Functors: functions and predicates Functors: functions and predicates

• Loop over multy-particle combinations, e.g. all Loop over multy-particle combinations, e.g. all pairs in the eventpairs in the event

• Easy creation of virtual particles (on-demand)Easy creation of virtual particles (on-demand)

•Optionally apply various kinematical constraintsOptionally apply various kinematical constraints

• Easy histograms & n-tuples (local!)Easy histograms & n-tuples (local!)

• “ “Save” interesting particles/combinations for the Save” interesting particles/combinations for the subsequent detailed analysissubsequent detailed analysis

• MC-truth match MC-truth match

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1414

Page 15: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1515

selection/filterinig

•Simple selection of particles (vertices, MC-Simple selection of particles (vertices, MC-pargticles, etc) according to kinematical and/or pargticles, etc) according to kinematical and/or topological criteriatopological criteria

select(“Kaon” , ID==“K-” || ID==“K+” ) ;select(“Kaon” , ID==“K-” || ID==“K+” ) ;

select(“Pi+” , ID==“pi+” && CL>0.01 && PT>100*MeV );select(“Pi+” , ID==“pi+” && CL>0.01 && PT>100*MeV );

const Vertex* pv = … ;const Vertex* pv = … ;

select(“MyMu” , ID==“mu+” && IPCHI2(point(pv))>4);select(“MyMu” , ID==“mu+” && IPCHI2(point(pv))>4);

all kaons (no cuts)all kaons (no cuts)

Positive pions with Confidence Level in excess of 1% and pT > 100 Positive pions with Confidence Level in excess of 1% and pT > 100 MeV/c2MeV/c2

Positive muons with Positive muons with 22IP with respect to the primary vertex in excess IP with respect to the primary vertex in excess of 4of 4

Page 16: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1616

LoKi: functions and cuts

Large set (>150) of predefined Large set (>150) of predefined functionsfunctions

•Simple properties of particles Simple properties of particles •P,PT,PX,M,CL,ID,Q,LV01,M12,DMASS,DMCHI2,….P,PT,PX,M,CL,ID,Q,LV01,M12,DMASS,DMCHI2,….

•Simple properties of Vertices Simple properties of Vertices •VCHI2,VTYPE,VX,VZ,VDOF,VPRONGS,VTRACKS,…VCHI2,VTYPE,VX,VZ,VDOF,VPRONGS,VTRACKS,…

•Topological properties of Particles and Vertices Topological properties of Particles and Vertices •IP,IPCHI2,VDCHI2,VDTIME,VDSIGN,DDANG,…IP,IPCHI2,VDCHI2,VDTIME,VDSIGN,DDANG,…

•Operations with Functions – other FunctionsOperations with Functions – other Functions•+ - * / sin cos tan abs pow min max …+ - * / sin cos tan abs pow min max … sin(PT)/acos(PY/PZ)+min(abs(PX),abs(PY)) > 100sin(PT)/acos(PY/PZ)+min(abs(PX),abs(PY)) > 100

Cuts/predicates are formed from functionsCuts/predicates are formed from functions

Page 17: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1717

LoKi: multiparticle loops

Loops over particle combinations, selects combinations Loops over particle combinations, selects combinations according to kinematical and topological criteriaaccording to kinematical and topological criteria

for( Loop D0 = loop( “K- pi+ pi+ pi-” , “D0”) ; D0 ; ++D0 )for( Loop D0 = loop( “K- pi+ pi+ pi-” , “D0”) ; D0 ; ++D0 ){{

if( PT( D0 ) > 1 * GeV && VCHI2( D0 ) < 49 ) if( PT( D0 ) > 1 * GeV && VCHI2( D0 ) < 49 ) {{

plot( “K- pi+ pi+ pi- mass”, M(D0)/GeV , 1.5 , 2.0 , 200 );plot( “K- pi+ pi+ pi- mass”, M(D0)/GeV , 1.5 , 2.0 , 200 );

Cut dm = abs( DMASS(“D0”) ) < 30 * MeV ;Cut dm = abs( DMASS(“D0”) ) < 30 * MeV ; if( dm( D0 ) ) { D0->save(“D0”) ; } if( dm( D0 ) ) { D0->save(“D0”) ; }

} } }}

simple loop over all K- simple loop over all K- + + + + - combinations- combinations

Require pT of combination in excess of 1 GeV/c and Require pT of combination in excess of 1 GeV/c and 22VX VX < 49< 49

Book and fill (1 action!) the Book and fill (1 action!) the histogramhistogram

Save the combinations with |Save the combinations with |M|<30 MeV/c2M|<30 MeV/c2

Page 18: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1818

LoKi: Histograms

•Histograms are local & booked on-demandHistograms are local & booked on-demand•No need for pre-booking! No need for pre-booking!

•Include variants for effective implicit loops Include variants for effective implicit loops

for( Loop D0 = loop( “K- pi+” , “D0”) ; D0 ; ++D0 )for( Loop D0 = loop( “K- pi+” , “D0”) ; D0 ; ++D0 ){{

plot( “K- pi+ mass”, M(D0)/GeV , 1.7 , 2.0 , 150 );plot( “K- pi+ mass”, M(D0)/GeV , 1.7 , 2.0 , 150 );}}

plot( loop( “K- pi+”, “D0” ) , “(2)K-pi+ mass” , M12 / GeV , plot( loop( “K- pi+”, “D0” ) , “(2)K-pi+ mass” , M12 / GeV , 1.7 , 2.0 , 150 ) ;1.7 , 2.0 , 150 ) ;

plot( select(“Kaons”, ID == “K-” ) , “PT of kaons “, PT plot( select(“Kaons”, ID == “K-” ) , “PT of kaons “, PT /GeV , 0 , 5 , 100 );/GeV , 0 , 5 , 100 );

Book and fill the histogramBook and fill the histogram

Make a loop, book and fill the histogramMake a loop, book and fill the histogram

Select particle, make a loop, book and fill the histogramSelect particle, make a loop, book and fill the histogram

Page 19: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 1919

LoKi: N-tuples

• N-Tuples are local & booked on-demand: No need for pre-booking of N-Tuple N-Tuples are local & booked on-demand: No need for pre-booking of N-Tuple and its items and its items

• Include variants for effective implicit loops Include variants for effective implicit loops

• Both ROOT and HBOOK are supported as persistency: the C++ code is neutral Both ROOT and HBOOK are supported as persistency: the C++ code is neutral with respect to the N-Tuple actual persistency with respect to the N-Tuple actual persistency

Tuple tuple = ntuple(“My N-Tuple for K- pi+ combinations”);Tuple tuple = ntuple(“My N-Tuple for K- pi+ combinations”);for( Loop D0 = loop( “K- pi+” , “D0”) ; D0 ; ++D0 )for( Loop D0 = loop( “K- pi+” , “D0”) ; D0 ; ++D0 ){{

tuple -> column( “M” , M(D0)/GeV);tuple -> column( “M” , M(D0)/GeV);tuple -> column( “PT” ,PT(D0)/GeV);tuple -> column( “PT” ,PT(D0)/GeV);

tuple ->fill(“PX,PY,PZ”, tuple ->fill(“PX,PY,PZ”, PX(D0)/GeV, PY(D0)/GeV, PZ(D0)/GeV);PX(D0)/GeV, PY(D0)/GeV, PZ(D0)/GeV);

tuple->write() ; tuple->write() ; }}

Book N-tupleBook N-tuple

Fill columns one-by-oneFill columns one-by-one

Fill few columns at once Fill few columns at once

Commit N-Tuple rowCommit N-Tuple row

Page 20: LoKi  & Bender  User Friendly Physics Analysis Tools

What else is needed?

• Easy “formal” match to MC-truth. Easy “formal” match to MC-truth.

• The simple and naïve questions The simple and naïve questions

• What MC particle matches to this RC particle?What MC particle matches to this RC particle?

• What RC particle matches to this MC particle?What RC particle matches to this MC particle?•Unfortunately they are not formal enough and therefore not so Unfortunately they are not formal enough and therefore not so

well defined for all cases, require a lot of “if”s and “artificial” well defined for all cases, require a lot of “if”s and “artificial” cutoffs.cutoffs.

• Reformulate: Does this MC-particle directly or indirectly (through Reformulate: Does this MC-particle directly or indirectly (through daughters) makes the contribution to the given RC-particle? daughters) makes the contribution to the given RC-particle?

• Formal, well-defined, recursive & applicable for all caseFormal, well-defined, recursive & applicable for all case

• One matches a bit more, but one looses nothingOne matches a bit more, but one looses nothing• Some final filtering is required Some final filtering is required

• Easy to code & very efficient:Easy to code & very efficient:

• just around O(10+10) (recursive) linesjust around O(10+10) (recursive) lines

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2020

Page 21: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2121

LoKi: MC matching

MCRange mcD0s = finder->findDecays(“D0 -> K- pi+”);MCRange mcD0s = finder->findDecays(“D0 -> K- pi+”);

Cut mccut = MCTRUTH( mcTruth() , mcD0s );Cut mccut = MCTRUTH( mcTruth() , mcD0s );

for( Loop D0 = loop( “K- pi+” , “D0” ) ; D0 ; ++D0 )for( Loop D0 = loop( “K- pi+” , “D0” ) ; D0 ; ++D0 )

{{ if( mccut( D0 ) ) if( mccut( D0 ) ) {{ plot(“mass of true D0->K- pi+”,plot(“mass of true D0->K- pi+”, M(D0)/GeV,1.7,2.0,150);M(D0)/GeV,1.7,2.0,150); } } }}

Create MC cut Create MC cut

Does Does thisthis D0 matches to one of the MC truth D0 ? D0 matches to one of the MC truth D0 ?

Find MC decaysFind MC decays

Page 22: LoKi  & Bender  User Friendly Physics Analysis Tools

What else is missing?

•What could be added?What could be added?

• What can be improved?What can be improved?

•Locality: one still needs at least one more Locality: one still needs at least one more “unit”: come job-configuration file (e.g. the list “unit”: come job-configuration file (e.g. the list of input data files, name of the output file with of input data files, name of the output file with histograms & n-tuples, output DST, etc…)histograms & n-tuples, output DST, etc…)

•Compilation time… Compilation time…

•What is missing?What is missing?

•Interactivity!Interactivity!

Solution? Go to Python!Solution? Go to Python!

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2222

Page 23: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2323

Why PythonPython ?

• PythonPython is a language with the special emphasize for is a language with the special emphasize for fast prototyping and development fast prototyping and development

• Scripting and interactivity combined in a natural way Scripting and interactivity combined in a natural way

• Easy integration with the third party software Easy integration with the third party software

• Availability of external packagesAvailability of external packages• visualization, statistical analysis visualization, statistical analysis

•ROOTROOT, , HippoDrawHippoDraw, , PanoramixPanoramix,, PyX PyX, , GNUplotGNUplot

• Event displayEvent display•PanoramixPanoramix

•Bookkeeping data base Bookkeeping data base

• Interface to Interface to GRIDGRID•GANGAGANGA

• and many othersand many others

Page 24: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2424

Python in LHCb

DaVinciDaVinci

C++ Analysis ApplicationC++ Analysis Application

GaudiGaudi

Services, Algorithms & Services, Algorithms &

Application ControlApplication Control

LoKiLoKi

Physics Analysis ToolKit Physics Analysis ToolKit

Event ModelEvent Model

BenderBender

Python Analysis ApplicationPython Analysis Application

GaudiPythonGaudiPython

BenderBender

DictionariesDictionaries

Ext

erna

ls:

Ext

erna

ls:

Vis

ualiz

ati

on,

Event

Vis

ualiz

ati

on,

Event

Dis

pla

y,

etc

D

isp

lay,

etc

Page 25: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2525

(Gaudi)Python(Gaudi)Python

The generic package for The generic package for Gaudi & PythonGaudi & Python bindingsbindings

• Access to major Access to major GaudiGaudi Components Components

• Services, algorithms and tools Services, algorithms and tools

• Application ConfigurationApplication Configuration

• Algorithm scheduleAlgorithm schedule

• Configuration of all components Configuration of all components

• “ “Dynamic” reconfiguration is possible Dynamic” reconfiguration is possible

The technique The technique

•LCG dictionariesLCG dictionaries for for C++/PythonC++/Python binding binding

Page 26: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2626

Bender = LoKi+Python+Bender = LoKi+Python+…

•LCG dictionariesLCG dictionaries for for C++/PythonC++/Python binding binding •A bit of raw A bit of raw BoostBoost also also

• >95%>95% of of LoKiLoKi’s ’s C++C++ functionality is available in functionality is available in PythonPython•Non-trivial due to heavy templated nature ofNon-trivial due to heavy templated nature of LoKi LoKi

•Situation improves with Situation improves with PyLCGPyLCG evolution evolution

•The mixture of The mixture of C++C++ and and PythonPython is possible is possible •C++C++ algorithm with algorithm with PythonPython cuts (“ cuts (“LoKiHybridLoKiHybrid”) ”)

•The bulk of actual computations in The bulk of actual computations in C++C++•Minimal Minimal PythonPython-related penalty-related penalty

•The conversion between existing The conversion between existing PythonPython BenderBender’s and ’s and C++ LoKiC++ LoKi’ s algorithms is simple in both directions: ’ s algorithms is simple in both directions: • Semantics is very similar Semantics is very similar

Page 27: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2727

Physics analysis

•Functions and cutsFunctions and cuts

•Selection of particles Selection of particles

•Looping over combinationsLooping over combinations

•Saving/retrieve of interesting combinations, Saving/retrieve of interesting combinations,

•Vertex/Mass-Vertex/Direction/Lifetime fitsVertex/Mass-Vertex/Direction/Lifetime fits

cut = (ID ==‘D+’) & (P > 5*GeV ) & (PT > 2*GeV )cut = (ID ==‘D+’) & (P > 5*GeV ) & (PT > 2*GeV )

k = self.select( tag = ‘K+’ , k = self.select( tag = ‘K+’ ,

cuts = ( ‘K+’ == ID ) & ( PT > 0.5 * GeV )cuts = ( ‘K+’ == ID ) & ( PT > 0.5 * GeV )

for phi in for phi in self.loop(formula=‘K+ K-’, pid=‘phi(1020)’)self.loop(formula=‘K+ K-’, pid=‘phi(1020)’)::

m = M( phi ) / GeV m = M( phi ) / GeV

p = P( phi ) / GeVp = P( phi ) / GeV

Page 28: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2828

Histos & N-TuplesHistos & N-Tuples

•HistogramsHistograms

•N-TuplesN-Tuples

h1 = self.plot ( “ phi mass ” ,

M( phi ) ,

1000, 1050 )

tup = self.nTuple( ”Phi NTuple”)tup = self.nTuple( ”Phi NTuple”)

tup.column ( “ID”, ID(phi) )tup.column ( “ID”, ID(phi) )

tup.column ( “p” , P (phi) )tup.column ( “p” , P (phi) )

tup.column ( “pt”, PT(phi) ) tup.column ( “pt”, PT(phi) )

tup.write()tup.write()

Page 29: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 2929

HistoHisto visualization

•The histogram visualization can be done throughThe histogram visualization can be done through•ROOTROOT

• native native ROOTROOT through through PythonPython prompt prompt

• rootPlotterrootPlotter from from PIPI through through AIDAAIDA pointer pointer

•Panoramix/LaJocondePanoramix/LaJoconde

•Directly through Directly through AIDAAIDA pointer pointer

•HippoDrawHippoDraw • hippoPlotterhippoPlotter from from PI PI through through AIDAAIDA pointer pointer

•Few lines “common interface” for Few lines “common interface” for trivialtrivial plotting exist plotting exist

•The interactive analysis of The interactive analysis of GaudiGaudi N-Tuples is possible N-Tuples is possible in in BenderBender with with ROOTROOT persistency and persistency and ROOTROOT module module directlydirectly

Page 30: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3030

EverythingEverything can be combined

Bender/Python promptBender/Python prompt

PanoramixPanoramix

PI/ROOTPI/ROOT

ROOTROOT

HippoDrawHippoDraw

Page 31: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF 13 May'2k+8 NIKHEF ColloquiumColloquium

Vanya BELYAEV Vanya BELYAEV 3131

Event Display: PanoramixPanoramix

The integrated analysis and visualization of statistical The integrated analysis and visualization of statistical and event data is possibleand event data is possible

Page 32: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3232

Result

from Bender.Main import *from Bender.Main import *

class Dstar(Algo):class Dstar(Algo):def analyse( self) :def analyse( self) :

self.select ( ‘K-’ , (‘K-’ ==ID)&(PT>1*GeV) )self.select ( ‘K-’ , (‘K-’ ==ID)&(PT>1*GeV) )self.select ( ‘pi+’, (‘pi+’==ID)&(P >3*GeV) )self.select ( ‘pi+’, (‘pi+’==ID)&(P >3*GeV) )dmass = ABSDM(“D0”) < 30 * MeV dmass = ABSDM(“D0”) < 30 * MeV

for D0 in self.loop ( ‘K- pi+’ , ‘D0’ ) :for D0 in self.loop ( ‘K- pi+’ , ‘D0’ ) :If ( VCHI2(D0) < 4 ) & dmass( D0 ) : D0.save(‘D0’)If ( VCHI2(D0) < 4 ) & dmass( D0 ) : D0.save(‘D0’)

tup = self.nTuple ( “D*+ N-Tuple ” )tup = self.nTuple ( “D*+ N-Tuple ” )

for Dst in self.loop ( ‘D0 pi+’ , ‘D*(2010)+’ ) : for Dst in self.loop ( ‘D0 pi+’ , ‘D*(2010)+’ ) : dm = M(Dst)-M1(Dst)dm = M(Dst)-M1(Dst)

h1 = self.plot( “Delta mass for D*+” , dm , 130 * MeV , 170 * MeV ) h1 = self.plot( “Delta mass for D*+” , dm , 130 * MeV , 170 * MeV ) tup.column ( ‘M’ , M(Dst) / GeV ) tup.column ( ‘M’ , M(Dst) / GeV ) tup.column ( ‘DM’ , dm / GeV ) tup.column ( ‘DM’ , dm / GeV ) tup.column ( ‘p’ , P (Dst) / GeV )tup.column ( ‘p’ , P (Dst) / GeV )tup.column ( ‘pt’ , PT(Dst) / GeV ) tup.column ( ‘pt’ , PT(Dst) / GeV ) tup.write ()tup.write ()

return SUCCESSreturn SUCCESS

Page 33: LoKi  & Bender  User Friendly Physics Analysis Tools

The life is not perfect

•Bender has a lot of nice features. But it also Bender has a lot of nice features. But it also has some clear disadvantage: has some clear disadvantage:

•Some CPU penalty is practically unavoidableSome CPU penalty is practically unavoidable

•but could be minimized with careful design. but could be minimized with careful design.

•the weak points are well identified and could the weak points are well identified and could be avoided be avoided

•some external optimizers, like Psyco could be some external optimizers, like Psyco could be helpfulhelpful

•But a bid dangerous to use e.g. in But a bid dangerous to use e.g. in Online/Trigger applicationsOnline/Trigger applications

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3333

Page 34: LoKi  & Bender  User Friendly Physics Analysis Tools

Solution? “Hybrid”

• When the problem is identified, one has 95% When the problem is identified, one has 95% of the solution in the hand. Lets use “Hybrid”! of the solution in the hand. Lets use “Hybrid”!

•““hybrid” solution for selection criteria for hybrid” solution for selection criteria for Online/Trigger application:Online/Trigger application:

• describe the selection criteria in a friendly way describe the selection criteria in a friendly way using using PythonPython strings strings • reuse of reuse of LoKi&Bender LoKi&Bender conceptsconcepts

• convert convert PythonPython into into C++ C++ at initialization phaseat initialization phase

• use the constructed use the constructed C++ C++ objects in objects in C++ C++ algorithms/tools algorithms/tools •No penalty due to No penalty due to PythonPython

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3434

Page 35: LoKi  & Bender  User Friendly Physics Analysis Tools

Configuration of Trigger

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3535

Page 36: LoKi  & Bender  User Friendly Physics Analysis Tools

Hybrid

•The “The “hybridhybrid” approach allows the implementation of ” approach allows the implementation of very efficient and powerful “very efficient and powerful “hybridhybrid” factories:” factories:

•Expressions, parameters, units, functions, ….Expressions, parameters, units, functions, ….

•The approach combines the great CPU performance The approach combines the great CPU performance of of C++ C++ with the great flexibility of with the great flexibility of PythonPython

•The The hybridhybrid approach allows to define all cuts in approach allows to define all cuts in ““easy-and-friendlyeasy-and-friendly” way” way

•The preliminary testing with The preliminary testing with interactivityinteractivity ((GaudiPythonGaudiPython or or BenderBender) is possible ) is possible and and recommendedrecommended

•The The samesame uniform semantics as for uniform semantics as for LoKi/C++ LoKi/C++ and and Bender/PythonBender/Python

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3636

Page 37: LoKi  & Bender  User Friendly Physics Analysis Tools

Summary

•The powerful and simultaneously User friendly The powerful and simultaneously User friendly physics analysis is reality (in LHCb)physics analysis is reality (in LHCb)

•LoKi: The powerful C++ Tool kitLoKi: The powerful C++ Tool kit

•Bender: The interactive python-based environment Bender: The interactive python-based environment for the physics analysisfor the physics analysis•Many physicists in LHCb use themMany physicists in LHCb use them

• Including the senior physicistsIncluding the senior physicists

• including the spokesmanincluding the spokesman

•Also the useful hybrid product as a result: it is not Also the useful hybrid product as a result: it is not very user friendly, but rather simple, formal, save very user friendly, but rather simple, formal, save and efficient. and efficient.

•The base for in High Level Trigger The base for in High Level Trigger

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3737

Page 38: LoKi  & Bender  User Friendly Physics Analysis Tools

More information

•Savannah portals for LoKi and Bender: Savannah portals for LoKi and Bender: • http://savannah.cern.ch/Loki• http://savannah.cern.ch/Bender

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3838

Page 39: LoKi  & Bender  User Friendly Physics Analysis Tools

13 May'2k+8 NIKHEF Colloquium13 May'2k+8 NIKHEF Colloquium Vanya BELYAEV Vanya BELYAEV 3939

LoKi BenderLoKi Bender

• LokiLoki is a god of wit and mischief in Norse is a god of wit and mischief in Norse mythologymythology

• LoLoops & ops & KiKinematicsnematics

Ostap Suleiman Berta Maria Ostap Suleiman Berta Maria BenderBender-bei-bei

• The cult-hero of books by The cult-hero of books by I.Il’fI.Il’f && E.Petrov: E.Petrov: “The 12 chairs”“The 12 chairs” ,,“The “The golden calf”golden calf”

• The title: The title: ““The great schemer”The great schemer”

• Attractive & brilliant cheaterAttractive & brilliant cheater

Essential for successful and good physics analysisEssential for successful and good physics analysis