# Difference: LoKiLUG (5 vs. 6)

#### Revision 62007-07-16 - VanyaBelyaev

Line: 1 to 1

 META TOPICPARENT name="LoKi"
Changed:
<
<

>
>

>
>

>
>

Line: 21 to 23

Changed:
<
<

>
>

# LoKi User Guide

Changed:
<
<

>
>

## Introduction

All off-line OO software for simulation,
Line: 52 to 54
Often a simple operation corresponding to one "physics" statement results in an enormous code with complicated and probably non-obvious content:
Changed:
<
<
>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
ParticleVector::const_iterator im; for ( im = vDsK.begin(); im = vDsK.end(); im++ ) { if((*im)->particleID().pid() == m_DsPlusID||
Line: 64 to 66
return StatusCode::FAILURE; } }
Changed:
<
<
>
>
%ENDSYNTAX%
The usage of comments becomes mandatory for understanding makes the code even longer and again results in additional complexity.
Line: 97 to 98
The attractiveness of specialised, physics-oriented code for physics analysis could be demonstrated e.g. with "typical" code fragment in KAL:
Changed:
<
<
>
>
%SYNTAX{ syntax="fortran" numbered="1000" numstep="10"}%
HYPOTH E+ MU+ PI+ 5 K+ PROTON

IDENT PI+ PI+

Changed:
<
<
IDENT K+ K+
>
>
IDENT K+ K
IDENT PROTON PROTON IDENT E+ E+ IDENT MU+ MU+
Line: 117 to 119
ENDSEL

GO 1000000

Changed:
<
<
>
>
%ENDSYNTAX%
This KAL pseudo-code gives an example of self-explanatory code. The physical content of selection of
Changed:
<
<
${\mathrm{D}}^{*+}\rightarrow {\mathrm{D}}^0 \pi^+$, followed by ${\mathrm{D}}^0\rightarrow {\mathrm{K}}^-\pi^0$ decay is clear and unambigously visible between lines. Indeed no comments
>
>
, followed by decay is clear and unambigously visible between these lines. Indeed no comments
are needed for understanding the analysis within 2 minutes.
Line: 133 to 135
similar transparency of the physical content of code with native C++. The best answer to this argument could be just an example from T. Glebe's Pattern of
Changed:
<
<
${\mathrm{K}}^0_{\mathrm{S}}\rightarrow \pi^+\pi^-$ reconstruction:
>
>
reconstruction: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
TrackPattern piMinus = pi_minus.with ( pt > 0.1 & p > 1 ) ; TrackPattern piPlus = pi_plus.with ( pt > 0.1 & p > 1 ) ; TwoProngDecay kShort = K0S.decaysTo ( PiPlus & PiMinus ) ; kShort.with( vz > 0 ) ; kShort.with( pt > 0.1 ) ;
Changed:
<
<
>
>
%ENDSYNTAX%

This code fragment is not so transparent as specialized

Line: 154 to 155
Here it is a good moment to jump to the end of the whole story and present some LoKi fragment for illustration:
Changed:
<
<
>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
select ( "Pi+" , ID =="pi+" && P > 5 * GeV ) ; select ( "K-" , ID =="K-" && P > 5 * GeV ) ;
>
>
for ( Loop D0 = loop("K- pi+","D0") ; D0 ; ++D0 ) { if ( P( D0 ) > 10 * GeV ){ D0->save("D0"); }
Line: 163 to 165
} for ( Loop Dstar = loop( "D0 Pi+" , "D*+" ) ; Dstar ; ++Dstar ) {
Changed:
<
<
plot ( M( Dstar ) / GeV , " Mass of D0 pi+ " , 2.0 , 2.1 , 100 );
>
>
plot ( M ( Dstar ) / GeV , " Mass of D0 pi+ " , 2.0 , 2.1 ) ;
}
Changed:
<
<
>
>
%ENDSYNTAX%
The physical content of these lines is quite transparent. Again I suppose that it is not obscured with C++ semantics.
Line: 209 to 210
It is the real pleasure to thank the leaders of ITEP/Moscow, CERN-LBD, LAPP/Annecy and Syracuse University teams for the kind support.
Changed:
<
<

>
>

### Who is LoKi?

• Loki is a god of wit and mischief in Norse mythology
• LoKi could be interpreted as Loops&Kinematics
Changed:
<
<

>
>

## LoKi ingredients

Typical analysis algorithm consists of quite complex combination of the following elementary actions:
Line: 236 to 237
LoKi has been designed to attack all these five major actions.
Changed:
<
<

>
>

## Selection

Changed:
<
<

>
>

### Selection of Particles

LoKi allows to select/filter a subset of reconstructed particles (of C++ type LHCb::Particle) which fulfills the chosen criteria, based on their kinematic, identification and topological properties and to refer later to this selected subset with the defined tag:

Changed:
<
<

>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
select( "AllKaons" , abs( ID ) == 321 && PT > 100 * MeV ) ;
Changed:
<
<
>
>
%ENDSYNTAX%
Here from all particles, loaded by DaVinci, the subset of particles identified as charged kaons (abs(ID)==321) with transverse momentum greater
Line: 283 to 282
sub-selections. The following example illustrates the idea: the selected sample of kaons is subdivided into samples of positive and negative kaons:
Changed:
<
<
>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Range kaons = select( "AllKaons" , abs( ID ) == 321 && PT > 100 * MeV ); select( "kaon+" , kaons , Q > 0.5 ) ; select( "kaon-" , kaons , Q < -0.5 ) ;
Changed:
<
<
>
>
%ENDSYNTAX%
Here all positive kaons (Q>0.5) are selected into the subset named "kaon+" and all negative kaons (Q<-0.5) go to the subset named "kaon-". These subsets again could be subject to further selection/filtering
Line: 300 to 297
LHCb::Particle::Vector, LHCb::Particle::ConstVector and LHCb::Particle::Container (also known as LHCb::Particles).
Changed:
<
<

>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
const LHCb::Particle::ConstVector& particles = ... ; Range kaons_1 = select( "Kaons_1" , particles , abs( ID ) == 321 ) ;

const LHCb::Particle::Container* event = get<LHCb::Particle::Container>( "..." ) ; Range kaons_2 = select( "Kaons_2" , event , 321 == abs( ID ) ) ;

Changed:
<
<
>
>
%ENDSYNTAX%
Also any arbitrary sequnce of objects, implicitely convertible to the C++ type const LHCb::Particle* can be used as input for selection of particles:
Changed:
<
<

>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
/// SEQUENCE is an arbitrary sequence of objects,
Changed:
<
<
/// implicitely convertible to /// type Particle*. e.q. std::vector<Particle*>, /// ParticleVector, Particles, std::set<Particle*> etc.
>
>
/// implicitely convertible to type const LHCb::Particle* /// e.q. std::vector<LHCb::Particle*>, /// LHCb::Particle::ConstVector, LHCb::Particles, std::set<LHCb::Particle*> etc.
SEQUENCE particles = ... ;
Changed:
<
<
Range kaons = select( "AllKaons" , // 'tag'
>
>
Range kaons = select ( "AllKaons" , // 'tag'
particles.begin () , // begin of sequence particles.end () , // end of sequence abs( ID ) == 321 ) ; // cut
Changed:
<
<
>
>
%ENDSYNTAX%
The output of selection (object of type Range) could be directly inspected through the explicit loop over the content of the selected container:
Changed:
<
<


>
>
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Range kaons = select( "AllKaons" , abs( ID ) == 321 && PT > 100 * MeV ) ;

// regular C++ loop:

Line: 341 to 333
const LHCb::Particle* k = *kaon ; /* do something with this raw C++ pointer */ }
Changed:
<
<
>
>
%ENDSYNTAX%

Changed:
<
<

>
>

### Selection of Monte Carlo Particles

In a similar way one can select Monte Carlo particles (of C++ type LHCb::MCParticle), which satisfy the certain criteria:
Line: 372 to 363

Changed:
<
<

>
>

### Selection of Generator Particles

Similar to the selection of reconstructed particles and the selection of Monte Carlo particles one can perform the selection of
Line: 400 to 391

Changed:
<
<

>
>

### Selection of Vertices

The similar approach is used for selection/filtering of vertices (of C++ type LHCb::VertexBase):
Line: 475 to 466

Changed:
<
<

>
>

### Selection of Monte Carlo Vertices and Generator Vertices

The selection of Monte Carlo Vertices and Generator Vertices is performed similar to the the selection of reconstructed Vertices with following difference:
Line: 489 to 480

Changed:
<
<

>
>

### Selection of minimal/maximal candidate

It is not unusual to select from some sequence or container of objects the object which maximizes or minimizes
Line: 562 to 553

Changed:
<
<

>
>

All selection functions, described above returns the light pseudocontainer of selected objects. Alternatively the selection result could be accessed using the unique tag (used as the first
Line: 584 to 575

Changed:
<
<

>
>

## Loops

Changed:
<
<

>
>

### Looping over the reconstructed particles

Changed:
<
<
>
>

#### Simple one-particle loops

Above it has been already shown how to perform simple looping over the selected range of particles:
Line: 625 to 616
effective loops over multi-particle combinations. But this gives no essential gain.

Changed:
<
<
>
>

#### Loops over the multi-particle combinations

Looping over multi-particle combinations is performed using the special object Loop.
Line: 679 to 670
combinations of the particles of the same type.
Changed:
<
<

>
>

Inside the loop there are several ways to access the information about the properties of the combination.
Changed:
<
<
>
>

For access to the daughter particles (the selection components) one could use following constructions:
Line: 749 to 740
Loop::m one could use the equivalent methods Loop::momentum and Loop::mass respectively.

Changed:
<
<
>
>

Access to information on the effective mother particle of the combination requires the call of loop method
Line: 840 to 831
containers/selections.

Changed:
<
<

>
>

Changed:
<
<

>
>

## Usage of kinematic constraints in LoKi

Changed:
<
<

>
>

Changed:
<
<

>
>

### Monte Carlo truth matching

LoKi offers fast, easy, flexible and configurable access to Monte Carlo truth information.
Line: 936 to 927
The latter way is especially convenient for analysis.
Deleted:
<
<

## LoKi Reference Manual

Changed:
<
<

### LoKi's Particle Functions

ALL
The trivial "select-all" predicate of C++ type LoKi::BooleanConstant(true), which always returns true
ABSID
The simple function (of type LoKi::Particles::AbsIdentifier()), which returns the absolute value of PDG-identifier of the particle:
   const LHCb::Particle* p = ... ;
const double absid = ABSID( p ) ;

For the invalid argument LoKi::Constanst::InvalidID is returned.The special comparison operators against std::string and LHb::ParticleID objects are defined:
   Range kaons = select ( "kaons" , "K+" == ABSID ) ;
Range muons = select ( "muons" , LHCb::ParticleID( 13 ) == ABSID ) ;

EQUALTO
Simple predicate ( of C++ type LoKi::EqualToValue) which checks if the value of the certain function equal to some predefined value:
   Range k1 = select ( "positive" , EQUALTO( Q , +1.0 ) ) ;
Range k2 = select ( "positive" , Q == +1 ) ; ///< the same

HASKEY
Predicate which returns true if the argument has the assigned key, see also KEY
KEY
Function, which returns the value of the assigned key. For invalid arguments, of if no key is assigned LoKi::Constants::InvalidKey is returned, see also HASKEY
ID
The simple function (of type LoKi::Particles::Identifier()), which returns the value of PDG-identifier of the particle:
   const LHCb::Particle* p = ... ;
const double id = ID( p ) ;

For the invalid argument LoKi::Constanst::InvalidID is returned.The special comparison operators against std::string and LHb::ParticleID objects are defined:
   Range kaons = select ( "kaons" , "K+" == ID ) ;
Range muons = select ( "muons" , LHCb::ParticleID( 13 ) == ID ) ;

NONE
The trivial "select-none" predicate of C++ type LoKi::BooleanConstant(false), which always returns false
ONE
The trivial function of C++ type LoKi::Constant(1), which always returns 1
PALL
alias for ALL, see here
PFALSE
alias for NONE, see here
PNONE
alias for NONE, see here
PONE
alias for ONE, see here
PSWITCH
alias for SWITCH, see here
PTRUE
alias for ALL, see here
PZERO
alias for ZERO, see here
SWITCH
The function (C++ type LoKi::Switch), which acts according the rule: result = condition ? function1 : function2:
   Fun signedPT = SWITCH( 0 < Q , PT , -1*PT ) ;

VALID
The trivial function of C++ type LoKi::Valid(), which check the validity of the argument:
   const std::vector<const LHCb::Particle*>& p = ... ;
// check for invalid pointers:
if ( std::find_if ( p.begin() , p.end() , !VALID ) != p.end() ) { ... there are null pointers ... }

ZERO
The trivial function of C++ type LoKi::Constant(0), which always returns 0
>
>
See here

Copyright &© 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback