Difference: LoKiTutorial (1 vs. 14)

Revision 142009-07-30 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 13 to 13
  This tutorial has last been tested with DaVinci v24r0, the slides available as pdf or
Changed:
<
<
pptx, also the slides are available through:
>
>
pptx, also the (slightly obsolete) slides are available through:
 
Line: 131 to 131
 exersize for LoKi-tutorial """ author = " Vanya BELYAEV Ivan.Belyaev@nikhefNOSPAMPLEASE.nl "
Changed:
<
<
version = " CVS Tag $Name: $, version $Revision: 1.13 $ "
>
>
version = " CVS Tag $Name: $, version $Revision: 1.14 $ "
 # ========================================================================= ## The general configuration stuff # =========================================================================
Line: 338 to 338
 """ # ========================================================================= author = " Vanya BELYAEV Ivan.Belyaev@nikhefNOSPAMPLEASE.nl "
Changed:
<
<
version = " CVS Tag $Name: $, version $Revision: 1.13 $ "
>
>
version = " CVS Tag $Name: $, version $Revision: 1.14 $ "
 # ========================================================================= ## The general configuration stuff # =========================================================================
Line: 901 to 901
  Please note that if one wants to have access to Monte Carlo truth information, one must to use the macro LOKI_MCALGORITHM.
Deleted:
<
<

The configuration

Please note that for this exercise one needs to load both muons and kaons. Do not forget to include the following lines into the configuration py -file:
<!-- SyntaxHighlightingPlugin -->
 1000...
 1010
 1020importOptions( '$COMMONPARTICLESROOT/options/StandardKaons.opts'  ) 
 1030importOptions( '$COMMONPARTICLESROOT/options/StandardMuons.opts' ) 
 1040
 1050...
 1060PsiPhi.PhysDesktop.InputLocations = [
 1070  'Phys/StdTightKaons' ,   ## use the "standard tight kaons" 
 1080  'Phys/StdLooseMuons'   ## use the "standard loose muons"
 1090] 
<!-- end SyntaxHighlightingPlugin -->
 

The solution

The full solution to this exercise ( *.cpp & *.py files) is available in the directory solutions/PsiPhi/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.

Changed:
<
<
-- Vanya Belyaev - 10 Oct 2008
>
>
-- Vanya Belyaev - 30 July 2k+9
 

META FILEATTACHMENT attachment="20071003_Tutorial_LoKi_v6r0.pdf" attr="" comment="" date="1191247669" name="20071003_Tutorial_LoKi_v6r0.pdf" path="20071003_Tutorial_LoKi_v6r0.pdf" size="18790217" stream="20071003_Tutorial_LoKi_v6r0.pdf" user="Main.VanyaBelyaev" version="1"

Revision 132009-07-30 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 12 to 11
 
Changed:
<
<
This tutorial has last been tested with DaVinci v20r3,
>
>
This tutorial has last been tested with DaVinci v24r0,
 the slides available as pdf or pptx, also the slides are available through:
Line: 37 to 36
 of Tutorial/LoKiTutor package. E.g. for the clean environment one can perform the following actions: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%
Changed:
<
<
> setenvDaVinci v20r3
> SetupProject DaVinci v20r3
> getpack Tutorial/LoKiTutor v8r0
>
>
> SetupProject DaVinci v24r0 --build-env
> getpack Tutorial/LoKiTutor v9r0
 %ENDSYNTAX%

To build the tutorial one needs to use the standard procedure, described in much detail

Line: 45 to 45
 To build the tutorial one needs to use the standard procedure, described in much detail for the basic tutorial: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%
Added:
>
>
 > cd Tutorial/LoKiTutor/cmt
Changed:
<
<
> cmt br make
> source ./setup.[c]sh
>
>
> make
> SetupProject DaVinci v24r0
 %ENDSYNTAX%

If everything is done in a correct way one can now run simple DaVinci job:

Line: 122 to 131
 exersize for LoKi-tutorial """ author = " Vanya BELYAEV Ivan.Belyaev@nikhefNOSPAMPLEASE.nl "
Changed:
<
<
version = " CVS Tag $Name: $, version $Revision: 1.12 $ "
>
>
version = " CVS Tag $Name: $, version $Revision: 1.13 $ "
 # ========================================================================= ## The general configuration stuff # ========================================================================= from Gaudi.Configuration import * # =========================================================================
Changed:
<
<
## The general configuratiin stuff from DaVinci importOptions ( "$DAVINCIROOT/options/DaVinciCommon.opts")
>
>
## The general configuration stuff form DaVinci from Configurables import DaVinci
 # ========================================================================= ## pick-up the 'configurable' for our specific algorithm # =========================================================================
Line: 139 to 147
 ## create the configurable specific algorithm: hello = HelloWorld('Hello')
Changed:
<
<
ApplicationMgr ( TopAlg = [ hello ] , ## execuet only "our" algorithm EvtMax = 50 , ## process 50 events
>
>
DaVinci ( DataType = 'DC06' , ## data type UserAlgorithms = [ hello ] , ## the list of algorithms EvtMax = 100 ## number of events
  )

## input data:

Line: 161 to 169
 Clearly only few lines are important here: %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Added:
>
>
from Gaudi.Configuration import * from Configurables import DaVinci
 from Configurables import LoKi__MyHelloWorld as HelloWorld
Deleted:
<
<
## create the configurable specific algorithm:
 hello = HelloWorld('Hello')
Changed:
<
<
ApplicationMgr ( TopAlg = [ hello ] , ## execuet only "our" algorithm EvtMax = 50 , ## process 50 events
>
>
DaVinci ( DataType = 'DC06' , ## data type UserAlgorithms = [ hello ] , ## the list of algorithms EvtMax = 100 ## number of events
  )

## input data:

Line: 296 to 306
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// get all reconstructed primary vertices:

Changed:
<
<
LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices(); // "desktop" is a member function of class DVAlgorithm
>
>
VRange pvs = vselect ('pv' , ISPRIMARY ) ;
  // create the function from the list of primary vertices and some helper object (essentially it is a pointer to IDistanceCalculator tool) Fun fun = MIPCHI2 ( pvs , geo() ) ; /// "geo" is a member function of class LoKi::Algo
Line: 328 to 338
 """ # ========================================================================= author = " Vanya BELYAEV Ivan.Belyaev@nikhefNOSPAMPLEASE.nl "
Changed:
<
<
version = " CVS Tag $Name: $, version $Revision: 1.12 $ "
>
>
version = " CVS Tag $Name: $, version $Revision: 1.13 $ "
 # ========================================================================= ## The general configuration stuff # ========================================================================= from Gaudi.Configuration import * # =========================================================================
Changed:
<
<
## The general configuratiin stuff from DaVinci importOptions ( "$DAVINCIROOT/options/DaVinciCommon.opts") importOptions ( "$COMMONPARTICLESROOT/options/StandardPions.opts" ) importOptions ( "$COMMONPARTICLESROOT/options/StandardKaons.opts" ) importOptions ( "$COMMONPARTICLESROOT/options/StandardMuons.opts" )
>
>
## The general configuration stuff from DaVinci from Configurables import DaVinci
 # ========================================================================= ## pick-up the 'configurable' for our specific algorithm # =========================================================================
Line: 342 to 349
 # ========================================================================= ## pick-up the 'configurable' for our specific algorithm # =========================================================================
Deleted:
<
<
 from Configurables import LoKi__GetData as GetData
Deleted:
<
<
from Configurables import PhysDesktop
  ## create the configurable specific algorithm:
Changed:
<
<
alg = GetData () alg.addTool ( PhysDesktop ) alg.PhysDesktop.InputLocations = [ 'Phys/StdLoosePions' , 'Phys/StdTightKaons' , 'Phys/StdLooseMuons' ]

ApplicationMgr ( TopAlg = [ alg ] , ## execuet only "our" algorithm EvtMax = 100 , ## process 100 events

>
>
data = GetData ( 'GetData' , ## Algorithm instamce name ## Input particles InputLocations = [ 'StdLoosePions' , 'StdTightKaons' , 'StdLooseMuons' ] )

DaVinci ( DataType = 'DC06' , ## data type UserAlgorithms = [ data ] , ## the list of algorithms EvtMax = 100 ## number of events

  )

## input data:

Line: 772 to 777
 %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%

## use Monte Carlo truth only for charged tracks (speed-up the execution):

Changed:
<
<
PP2MCs = [ "Relations/Rec/ProtoP/Charged' ]
>
>
alg = MyALG ( .... , PP2MCs = [ "Relations/Rec/ProtoP/Charged' ] )
  %ENDSYNTAX%

Revision 122008-10-10 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 12 to 12
 
Changed:
<
<
This tutorial has last been tested with DaVinci v19r5, the slides available as pdf or pptx.
>
>
This tutorial has last been tested with DaVinci v20r3, the slides available as pdf or pptx, also the slides are available through:
 

Prerequisites

It is assumed that you are more or less familiar with the basic tutorial, also some level of familiarity with
Line: 32 to 37
 of Tutorial/LoKiTutor package. E.g. for the clean environment one can perform the following actions: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%
Changed:
<
<
> setenvDaVinci v19r5
> getpack Tutorial/LoKiTutor v6r0
> getpack Phys/DaVinci v19r5
> cd Phys/DaVinci/v19r5/cmt
> cmt show uses | grep cmtuser
%ENDSYNTAX% If you have the valid DaVinci environment from your previous DaVinci tutorial, there is no nesessity to "getpack" the package Phys/DaVinci again: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}% > setenvDaVinci v19r5
> getpack Tutorial/LoKiTutor v6r0
> cd Phys/DaVinci/v19r5/cmt
> cmt show uses | grep cmtuser
>
>
> setenvDaVinci v20r3
> SetupProject DaVinci v20r3
> getpack Tutorial/LoKiTutor v8r0
 %ENDSYNTAX%
Changed:
<
<
If everything is ok, CMT reports that the local version of Tutorial/LoKiTutor package is used.
>
>
 To build the tutorial one needs to use the standard procedure, described in much detail for the basic tutorial: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%
Added:
>
>
> cd Tutorial/LoKiTutor/cmt
 > cmt br make
> source ./setup.[c]sh
%ENDSYNTAX%

If everything is done in a correct way one can now run simple DaVinci job: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%

Changed:
<
<
> DaVinci.exe $DAVINCIROOT/options/DaVinci.opts
>
>
> gaudirun.py $DAVINCIROOT/options/DaVinci.py
 %ENDSYNTAX%

In a similar way one can run the most trivial (empty, "Hello, World!") LoKi-algorithm: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%

Changed:
<
<
> DaVinci.exe $LOKITUTORROOT/solutions/HelloWorld/HelloWorld.opts
>
>
> cd $LOKITUTORROOT/cmt
> cp ../solution/HelloWorld/HelloWorld.cpp ../src
> make
> gaudirun.py $LOKITUTORROOT/solutions/HelloWorld/HelloWorld.py
 %ENDSYNTAX%

Line: 109 to 108
 

The configuration

Of course the configuration of this simple ("do-nothing") algorithm does not require a lot of efforts:
Changed:
<
<
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // (1) get some "basic/standard" job-configuration from DaVinci #include "$DAVINCIROOT/options/DaVinciCommon.opts" // ======================================================================== // (2) use LoKi service (MANDATORY!!!) ExtSvc += { "LoKiSvc" } ; // ======================================================================== // (3) execute ONLY our algorithm TopAlg = { "HelloWorld/Hello"} ; // ======================================================================== // (4) define input data #include "$LOKITUTORDATA" // ======================================================================== // (5) run 20 events EvtMax = 20 ;
>
>
<!-- SyntaxHighlightingPlugin -->
 1000#!/usr/bin/env gaudirun.py
 1010# =============================================================================
 1020## @file
 1030#  The configuration fiel to run the simplest "Hello World!" exersize for
 1040#  LoKi-tutorial
 1050#  @author Vanya  BELYAEV Ivan.Belyaev@nikhef.nl
 1060#  @date 2008-10-07
 1070# =============================================================================
 1080"""
 1090The simple configuration file to run the simplest 'Hello World!'
 1100exersize for LoKi-tutorial
 1110"""
 1120__author__   = " Vanya  BELYAEV Ivan.Belyaev@nikhef.nl "
 1130__version__  = " CVS Tag $Name:  $, version $Revision: 1.12 $  "
 1140# =============================================================================
 1150## The general configuration stuff
 1160# =============================================================================
 1170from  Gaudi.Configuration import *
 1180# =============================================================================
 1190## The general configuratiin stuff from DaVinci
 1200importOptions ( "$DAVINCIROOT/options/DaVinciCommon.opts")
 1210# =============================================================================
 1220## pick-up the 'configurable' for our specific algorithm 
 1230# =============================================================================
 1240
 1250from  Configurables import LoKi__MyHelloWorld as HelloWorld
 1260
 1270## create the configurable specific algorithm:
 1280hello = HelloWorld('Hello')
 1290
 1300ApplicationMgr (
 1310    TopAlg = [ hello ] , ## execuet only "our" algorithm 
 1320    EvtMax = 50        , ## process 50 events 
 1330    ) 
 1340
 1350## input data:
 1360from LoKiExample.Bs2Jpsiphi_mm_data import Inputs
 1370EventSelector (
 1380    Input     = Inputs , ## input data 
 1390    PrintFreq = 1
 1400    ) 
 1410
 1420# =============================================================================
 1430# The END 
 1440# =============================================================================
 1450
<!-- end SyntaxHighlightingPlugin -->

Clearly only few lines are important here: %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%

from Configurables import LoKi__MyHelloWorld as HelloWorld

## create the configurable specific algorithm: hello = HelloWorld('Hello')

ApplicationMgr ( TopAlg = [ hello ] , ## execuet only "our" algorithm EvtMax = 50 , ## process 50 events )

## input data: from Bs2Jpsiphi_mm_data import Inputs EventSelector ( Input = Inputs , ## input data PrintFreq = 1 )

 %ENDSYNTAX%
Added:
>
>
The rest is just some kind of documentation, decorations and comments.

 As the input data for this particular exercise one can use any arbitrary input data, e.g.
Changed:
<
<
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // use data sample, used for DaVinci tests: #include "$DAVINCIROOT/options/DaVinciTestData.opts"
>
>
%SYNTAX{ syntax="python" numbered="1000" numstep="10"}%

# use another data:

EventSelector ( Input = [ 'PFN:file1.dst' , 'PFN:file2.dst'] , ## input data PrintFreq = 1 )

 %ENDSYNTAX%

Also one can follow the instructions from DaVinci tutorial and find some appropriate data using LHCb bookkeeping data base.

Deleted:
<
<
Put your configuration *.opts file into options directory of Tutorial/LoKiTutor package and run the exercise.
 

The solution

Changed:
<
<
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory
>
>
The full solution to this exercise ( *.cpp & *.py files) is available in the directory
 solutions/HelloWorld/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.

Line: 234 to 296
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// get all reconstructed primary vertices:

Changed:
<
<
LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices(); /// "desktop" is a member function of class DVAlgorithm
>
>
LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices(); // "desktop" is a member function of class DVAlgorithm
 
Changed:
<
<
// create the function from the list of primary vertices and some helper object (IGeomDispCalculator tool)
>
>
// create the function from the list of primary vertices and some helper object (essentially it is a pointer to IDistanceCalculator tool)
 Fun fun = MIPCHI2 ( pvs , geo() ) ; /// "geo" is a member function of class LoKi::Algo

// use it explicitly:

Line: 253 to 315
 

The configuration

Of course the configuration of this algorithm require a bit more typing, in particular one needs to specify the input locations for the algorithm:
Changed:
<
<
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // (1) get some "basic/standard" job-configuration from DaVinci // ======================================================================== #include "$DAVINCIROOT/options/DaVinciCommon.opts" #include "$COMMONPARTICLESROOT/options/StandardPions.opts" #include "$COMMONPARTICLESROOT/options/StandardKaons.opts" #include "$COMMONPARTICLESROOT/options/StandardMuons.opts" // ======================================================================== // (2) load LoKi service ExtSvc += { "LoKiSvc" } ; // ======================================================================== // (3) append algorithm to the default list: TopAlg += { "GetData"} ; // ======================================================================== // (4) configure "our" algorithm: InputLocations = { "Phys/StdLoosePions" , // use the "standard loose pions" "Phys/StdTightKaons" , // use the "standard loose kaons" "Phys/StdLooseMuons" // use the "standard loose muons" } ; // ======================================================================== // (5) define input data #include "$LOKITUTORDATA" // ======================================================================== // (6) run 200 events EvtMax = 200 ;
>
>
%SYNTAX{ syntax="python" numbered="1000" numstep="10"}% #!/usr/bin/env gaudirun.py # ========================================================================= ## @file # The configuration file for 'GetData'-solution for LoKi-tutorial # @author Vanya BELYAEV Ivan.Belyaev@nikhefNOSPAMPLEASE.nl # @date 2008-10-07 # ========================================================================= """ The configuration file for 'GetData'-solution for LoKi-tutorial """ # ========================================================================= author = " Vanya BELYAEV Ivan.Belyaev@nikhefNOSPAMPLEASE.nl " version = " CVS Tag $Name: $, version $Revision: 1.12 $ " # ========================================================================= ## The general configuration stuff # ========================================================================= from Gaudi.Configuration import * # ========================================================================= ## The general configuratiin stuff from DaVinci importOptions ( "$DAVINCIROOT/options/DaVinciCommon.opts") importOptions ( "$COMMONPARTICLESROOT/options/StandardPions.opts" ) importOptions ( "$COMMONPARTICLESROOT/options/StandardKaons.opts" ) importOptions ( "$COMMONPARTICLESROOT/options/StandardMuons.opts" ) # ========================================================================= ## pick-up the 'configurable' for our specific algorithm # =========================================================================

from Configurables import LoKi__GetData as GetData from Configurables import PhysDesktop

## create the configurable specific algorithm: alg = GetData () alg.addTool ( PhysDesktop ) alg.PhysDesktop.InputLocations = [ 'Phys/StdLoosePions' , 'Phys/StdTightKaons' , 'Phys/StdLooseMuons' ]

ApplicationMgr ( TopAlg = [ alg ] , ## execuet only "our" algorithm EvtMax = 100 , ## process 100 events )

## input data: from Bs2Jpsiphi_mm_data import Inputs EventSelector ( Input = Inputs , ## input data PrintFreq = 10 )

# ========================================================================= # The END # =========================================================================

 %ENDSYNTAX%

The solution

Changed:
<
<
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory
>
>
The full solution to this exercise ( *.cpp & *.py files) is available in the directory
 solutions/GetData/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
Line: 478 to 569
 

The solution

Changed:
<
<
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory
>
>
The full solution to this exercise ( *.cpp & *.py files) is available in the directory
 solutions/LoKiLoop/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
Line: 678 to 769
 by disabling the Monte Carlo truth for calorimeter objects and neutral protoparticles, which are enabled in the default configuration. It could be done using the following section for the property PP2MCs in your algorithm:
Changed:
<
<
%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
>
>
%SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
 
Changed:
<
<
// use Monte Carlo truth only for charged tracks: PP2MCs = { "Relations/Rec/ProtoP/Charged" } ;
>
>
## use Monte Carlo truth only for charged tracks (speed-up the execution): PP2MCs = [ "Relations/Rec/ProtoP/Charged' ]
  %ENDSYNTAX%

The solution

Changed:
<
<
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory
>
>
The full solution to this exercise ( *.cpp & *.py files) is available in the directory
 solutions/PsiMC/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.

Line: 805 to 896
 

The configuration

Please note that for this exercise one needs to load both muons and kaons.
Changed:
<
<
Do not forget to include the following lines into the configuration opts -file: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
>
>
Do not forget to include the following lines into the configuration py -file: %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
  ...
Changed:
<
<
#include "$COMMONPARTICLESROOT/options/StandardKaons.opts" #include "$COMMONPARTICLESROOT/options/StandardMuons.opts"
>
>
importOptions( '$COMMONPARTICLESROOT/options/StandardKaons.opts' ) importOptions( '$COMMONPARTICLESROOT/options/StandardMuons.opts' )
  ...
Changed:
<
<
InputLocations = { "Phys/StdTightKaons" , // use the "standard tight kaons" "Phys/StdLooseMuons" // use the "standard loose muons" } ;
>
>
InputLocations = [ 'Phys/StdTightKaons' , ## use the "standard tight kaons" 'Phys/StdLooseMuons' ## use the "standard loose muons" ]
  %ENDSYNTAX%

The solution

Changed:
<
<
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory
>
>
The full solution to this exercise ( *.cpp & *.py files) is available in the directory
 solutions/PsiPhi/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
Changed:
<
<
-- Vanya Belyaev - 26 Sep 2007
>
>
-- Vanya Belyaev - 10 Oct 2008
 
META FILEATTACHMENT attachment="20071003_Tutorial_LoKi_v6r0.pdf" attr="" comment="" date="1191247669" name="20071003_Tutorial_LoKi_v6r0.pdf" path="20071003_Tutorial_LoKi_v6r0.pdf" size="18790217" stream="20071003_Tutorial_LoKi_v6r0.pdf" user="Main.VanyaBelyaev" version="1"
META FILEATTACHMENT attachment="20071003_Tutorial_LoKi_v6r0.pptx" attr="" comment="" date="1191247808" name="20071003_Tutorial_LoKi_v6r0.pptx" path="20071003_Tutorial_LoKi_v6r0.pptx" size="440284" stream="20071003_Tutorial_LoKi_v6r0.pptx" user="Main.VanyaBelyaev" version="1"
Added:
>
>
META FILEATTACHMENT attachment="20081007_Tutorial_LoKi_v8r0.pptx" attr="" comment="" date="1223636958" name="20081007_Tutorial_LoKi_v8r0.pptx" path="20081007_Tutorial_LoKi_v8r0.pptx" size="416257" stream="20081007_Tutorial_LoKi_v8r0.pptx" user="Main.VanyaBelyaev" version="1"
META FILEATTACHMENT attachment="20081007_Tutorial_LoKi_v8r0.pdf" attr="" comment="" date="1223636985" name="20081007_Tutorial_LoKi_v8r0.pdf" path="20081007_Tutorial_LoKi_v8r0.pdf" size="18693015" stream="20081007_Tutorial_LoKi_v8r0.pdf" user="Main.VanyaBelyaev" version="1"

Revision 112007-12-20 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Revision 102007-12-20 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Revision 92007-10-02 - LesyaShchutska

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 641 to 641
 
  1. make a loop over dimuons
  2. apply some cuts to the compound particle
  3. plot some distributions for the compound and/or daughter particles with and without matching to Monte Carlo truth
Changed:
<
<
    • if you already familar with N-tuples (see here), fill N-tuple with all these variables
>
>
    • if you are already familiar with N-tuples (see here), fill N-tuple with all these variables
 
  1. save "interesting" candidates and count them

The algorithm

Revision 82007-10-02 - LesyaShchutska

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 18 to 18
 the DaVinci tutorial is supposed. It is also recommended to look through histograms & N-tuples pages.
Changed:
<
<
You are also invited to the lhcb-loki mailing list.
>
>
You are also invited to the lhcb-loki mailing list.
 

Setup the environment for DaVinci

For this particular tutorial we'll concentrate on the interactive jobs and let the batch system and GRID, Ganga and DIRAC tool some rest.
Line: 459 to 459
  // avoid very long names: using namespace LoKi ; using namespace LoKi::Types ;
Changed:
<
<
using namespsce LoKi::Cuts ;
>
>
using namespace LoKi::Cuts ;
  ... put your lines here ...
Line: 485 to 485
  The next exercise illustrates the usage of Monte Carlo information in LoKi.
Changed:
<
<
LoKi offers nice possibility to perform easy "on-flight" access to Monte Calro truth information.
>
>
LoKi offers nice possibility to perform easy "on-the-fly" access to Monte Calro truth information.
 Not all possible cases are covered on the equal basis but the most frequent idioms are reflected and well-covered in LoKi.
Line: 505 to 505
 // get all true fast Monte Carlo muons from decay/interaction of selected beauty particles: MCRange mcmu = mcselect ( "mcmu" , "mu+" == MCABSID && FROMMCTREE ( beauty ) && MCPT > 1 * Gaudi::Units::GeV ) ; %ENDSYNTAX%
Changed:
<
<
The objects of type MCRange have the stantard interface of the container and could be inpected through the explicit loop:
>
>
The objects of type MCRange have the stantard interface of the container and could be inspected through the explicit loop:
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

MCRange mc =

Line: 523 to 523
 are LoKi Monte Carlo particle functions.

Selection of Monte Carlo decays

Changed:
<
<
For the frequent case of the special selection of particles, which satisfy teh certain decay patters
>
>
For the frequent case of the special selection of particles, which satisfy the certain decay patterns
 LoKi offers the special utility MCFinder, which is essentially just a thin wrapper over the brilliant tool MCDecayFinder, the masterpiece written by Olivier Dormond from Lausanne Univertity:

%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

Line: 538 to 538
 MCRange mcmu = finder -> findDecays ( "J/psi(1S) -> ^mu+ ^mu-") ;

%ENDSYNTAX%

Changed:
<
<
The selected Monte Carlo particles could be subjected by the further selection:
>
>
The selected Monte Carlo particles could be subjected to the further selection:
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// from the selected true muons from psi->mu+mu- decay select only the fast muons:

Line: 551 to 551
 There are variety of the methods in LoKi for Monte Carlo truth matching. Here we describe the most trivial (which covers well the most frequent case) one, the function MCTRUTH. This function being constructed with the list
Changed:
<
<
of Monte Carlo particles, evaluated to true for reconstructed particles,
>
>
of Monte Carlo particles, is evaluated to true for reconstructed particles,
 which are matched with one of the Monte Carlo particle (or one of its
Changed:
<
<
Monte Carlo daughter particle) used for construction of the function.
>
>
Monte Carlo daughter particles) used for construction of the function.
 e.g. : %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 564 to 564
 MCRange mcmu = .... ;

// create the function (predicate) using the list of true muons

Changed:
<
<
Cut fromMC = MCTRUTH ( mc , mcmu ) ; /// thi sfunction evaluated for "true" for particles, matched to true MC muons
>
>
Cut fromMC = MCTRUTH ( mc , mcmu ) ; /// this function evaluated to "true" for particles, matched to true MC muons
  // select recontructed muons, matched with true MC-muons: Range mu = select ( "goodmu" , "mu+" == ABSID && fromMC ) ; /// use the function/predicate %ENDSYNTAX%
Changed:
<
<
The constructed function/predicate formMC (the line 01070) could be used also directly:
>
>
The constructed function/predicate fromMC (the line 01070) could be used also directly:
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

const LHCb::Particle* p = ... ;

Line: 581 to 581
  %ENDSYNTAX% Important note: the function MCTRUTH evaluates to true also for recontructed particles,
Changed:
<
<
which are matched to Monte Carlo particles form decay trees of the original Monte Carlo particles.
>
>
which are matched to Monte Carlo particles from decay trees of the original Monte Carlo particles.
  The function MCTRUTH described above is very useful for selection of "True"-decays and combinations:
Line: 589 to 589
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// get all Monte Carlo psis, which decay into mu+ mu-:

Changed:
<
<
MCRange mcPsi = ... ; // you already know hoe to get them!
>
>
MCRange mcPsi = ... ; // you already know how to get them!
  // get all Monte Carlo muons from the decay psi -> mu+ mu-: MCRange mcmu = ... ; // you know well how to get them!!!
Line: 607 to 607
 // make the loop for ( Loop psi = loop ( "mu+ mu-" , "J/psi(1S)" ) ; psi ; ++psi ) {
Changed:
<
<
// fast evalaution of mass
>
>
// fast evaluation of mass
  const double m12 = psi->mass(1,2) ; if ( m12 < 2.0 * Gaudi::UnitsGeV || m12 > 4 * Gaudi::Units::GeV ) { continue ; } // skip bad combinations:
Line: 632 to 632
 %ENDSYNTAX%

Now you know all the major ingredients useful for simple Monte Carlo match.

Changed:
<
<
Lets try to write the algorithm for
>
>
Let's try to write the algorithm for
 selection using your experience from the previous exercise:
  1. find true Monte Carlo decays
  2. create the helper matching predicates/functions for Monte match of and
  3. select the good positive muons
  4. select the good negative muos
  5. make a loop over dimuons
Changed:
<
<
  1. apply some cuts for the compound particle
>
>
  1. apply some cuts to the compound particle
 
  1. plot some distributions for the compound and/or daughter particles with and without matching to Monte Carlo truth
    • if you already familar with N-tuples (see here), fill N-tuple with all these variables
  2. save "interesting" candidates and count them
Line: 656 to 656
  // avoid very long names: using namespace LoKi ; using namespace LoKi::Types ;
Changed:
<
<
using namespsce LoKi::Cuts ;
>
>
using namespace LoKi::Cuts ;
  ... put your lines here ...

return StatusCode::SUCCESS ; // RETURN } %ENDSYNTAX%

Changed:
<
<
Note: for access to Monte Carlo truth one needs to use the macro LOKI_MCALGORITHM= istead of LOKI_ALGORITHM.
>
>
Note: for access to Monte Carlo truth one needs to use the macro LOKI_MCALGORITHM instead of LOKI_ALGORITHM.
 

The configuration

Changed:
<
<
The configuration of the job is quite standard and does not require the additional effors
>
>
The configuration of the job is quite standard and does not require the additional efforts
 with respect to the previous exercise. Please note that for this algorithm one needs only
Changed:
<
<
muons as input partiles, therefore for the reaosns of CPU efficiency other
>
>
muons as input particles, therefore for the reasons of CPU efficiency other
 input locations could be suppressed. Also since we are working only with charged particles, one can gain some CPU performace by disabling the Monte Carlo truth for calorimeter objects and neutral protoparticles,
Changed:
<
<
which are enabled in the default configuration. it could be done using the following settion for th eproeprty PP2MCs for your algorithm:
>
>
which are enabled in the default configuration. It could be done using the following section for the property PP2MCs in your algorithm:
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// use Monte Carlo truth only for charged tracks:

Line: 685 to 685
 

The solution

Changed:
<
<
The full solution for this exercise ( *.cpp & *.opts files) is available in the directory solutions/PsiMC/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
>
>
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory solutions/PsiMC/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
 

Combine everything altogether and get the nice peak.

Changed:
<
<
The purpose of the next exercise if combine all ingredient togather and write the "realistic" but simple analysis algorithm
>
>
The purpose of the next exercise is to combine all ingredient together and write the "realistic" but simple analysis algorithm
 for decay. Essentialy one now has all ingredients ready and one just
Changed:
<
<
need to combine them in a rigth way within one algorithm.
  • Please note that it is a bit different from DaVinci approach where users encouraged to split the one algorithm into smaller algorithmm which run in the sequence. Here we'll study the possibility to recontruct teh whole chain in one algorithm.
>
>
need to combine them in a right way within one algorithm.
  • Please note that it is a bit different from DaVinci approach where users encouraged to split the one algorithm into smaller algorithmm which run in the sequence. Here we'll study the possibility to recontruct the whole chain in one algorithm.
 
Changed:
<
<
The analysis of decay chain could be natually split into three simlar phases
>
>
The analysis of decay chain could be naturally split into three similar phases
 
  1. selection of through the loop over dimuons
  2. selection of through the loop over dikaons
  3. selection of through the loop over selected and candidates
Changed:
<
<
From the Exercise 3 you already know well how to reach the first goal, and from the Exercise 4 you know how to read the second goal.
>
>
From the Exercise 3 you already know well how to reach the first goal, and from the Exercise 4 you know how to reach the second goal.
 Therefore here one just needs to concentrate on the third item. The overall design of the algorithm could be sketched as:
Line: 791 to 790
  // avoid very long names: using namespace LoKi ; using namespace LoKi::Types ;
Changed:
<
<
using namespsce LoKi::Cuts ;
>
>
using namespace LoKi::Cuts ;
  ... put your lines here, essentially the compilation from the previous examples.
Line: 803 to 802
 

The configuration

Changed:
<
<
Pleas note that for this exercise one needs to load both muons and kaons.
>
>
Please note that for this exercise one needs to load both muons and kaons.
 Do not forget to include the following lines into the configuration ==opts==-file: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 814 to 813
  ... InputLocations = {
Changed:
<
<
"Phys/StdTightKaons" , // use the "standard loose kaons"
>
>
"Phys/StdTightKaons" , // use the "standard tight kaons"
  "Phys/StdLooseMuons" // use the "standard loose muons" } ;
Line: 822 to 821
 

The solution

Changed:
<
<
The full solution for this exercise ( *.cpp & *.opts files) is available in the directory solutions/PsiPhi/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
>
>
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory solutions/PsiPhi/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
 

-- Vanya Belyaev - 26 Sep 2007

Revision 72007-10-01 - LesyaShchutska

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 15 to 15
 

Prerequisites

It is assumed that you are more or less familiar with the basic tutorial, also some level of familiarity with
Changed:
<
<
the DaVinci tutorial is assumed.
>
>
the DaVinci tutorial is supposed.
 It is also recommended to look through histograms & N-tuples pages. You are also invited to the lhcb-loki mailing list.
Line: 25 to 25
 Batch and GRID-aware actions for LoKi-bases analysis are identical to the actions needed for native DaVinci and thus are not covered by this tutorial. For more details on GRID&batch see DaVinci tutorial.
Changed:
<
<
The package Tutorial/LoKiTutor is used as the placeholder for the tutorial excersizes.
>
>
The package Tutorial/LoKiTutor is used as the placeholder for the tutorial exercises.
 Please take care that you have installed and working version of DaVinci with local version of Tutorial/LoKiTutor package.
Changed:
<
<
E.g. fro the clean enavironment one can perform the following actions:
>
>
E.g. for the clean environment one can perform the following actions:
 %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}% > setenvDaVinci v19r5
> getpack Tutorial/LoKiTutor v6r0
Line: 52 to 52
 > source ./setup.[c]sh
%ENDSYNTAX%
Changed:
<
<
If the everything is done in a correct way one can now run simple DaVinci job:
>
>
If everything is done in a correct way one can now run simple DaVinci job:
 
<!-- SyntaxHighlightingPlugin -->
 1000> DaVinci.exe $DAVINCIROOT/options/DaVinci.opts
<!-- end SyntaxHighlightingPlugin -->
Line: 62 to 62
 > DaVinci.exe $LOKITUTORROOT/solutions/HelloWorld/HelloWorld.opts
%ENDSYNTAX%
Changed:
<
<
>
>
 

The most trivial (empty) "Hello,World!" LoKi algorithm

Changed:
<
<
The most trivial LoKi empty algorithm ("Hello,World!") demonstrate in a very clear way
>
>
The most trivial LoKi empty algorithm ("Hello,World!") demonstrates in a very clear way
 the main principles of any LoKi-based algorithms:
  • It resides in a single *.cpp file, no header (*.h) is required
  • To get access to LoKi classes one needs to include the file LoKi/LoKi.h which imports around 90-95% of functionality, available in LoKi
Line: 124 to 124
 EvtMax = 20 ; %ENDSYNTAX%
Changed:
<
<
As the input data for this partcular excersize one can use any arbitrary inpiut data, e.g.
>
>
As the input data for this particular exercise one can use any arbitrary input data, e.g.
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // use data sample, used for DaVinci tests: #include "$DAVINCIROOT/options/DaVinciTestData.opts"
Line: 133 to 133
 Also one can follow the instructions from DaVinci tutorial and find some appropriate data using LHCb bookkeeping data base.
Changed:
<
<
Put your configuration *.opts file into options directory of Tutorial/LoKiTutor package and run the excersize.
>
>
Put your configuration *.opts file into options directory of Tutorial/LoKiTutor package and run the exercise.
 

The solution

Changed:
<
<
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/HelloWorld/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
>
>
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory solutions/HelloWorld/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
 
Changed:
<
<
>
>
 

Simple selection of particles

Changed:
<
<
The second excersize demonstrates the simple selections of particles using LoKi functors.
>
>
The second exercise demonstrates the simple selections of particles using LoKi functors.
 
Changed:
<
<
The basic working horse for the simple selections if the member function select. It allows to select/filter from all input particles only the particles, which satisfy the certain criteria.
>
>
The basic working horse for the simple selections is the member function select. It allows to select/filter from all input particles only those satisfying the certain criteria.
 For more information see LoKi User Guide/TWiki.

%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

Line: 166 to 165
 Range mufast = select ( "fastmuons" , "mu+" == ABSID && P > 10 * Gaudi::Units::GeV && 500 < PT / Gaudi::Units::MeV ) ;

// get positive muons from all fast muons (subset)

Changed:
<
<
Range mu1 = select ( "fastmuons-" , mufast , Q > 0 ) ;
>
>
Range mu1 = select ( "fastmuons+" , mufast , Q > 0 ) ;
  %ENDSYNTAX%
Changed:
<
<
In this example ID, P, PT and Q are the simplest LoKi functors, which evaluate the particle id, momentum, transverse momentum and the charge correspondingly. Almost exaustive list of corrently available particle functors is available here.
>
>
In this example ID, P, PT and Q are the simplest LoKi functors, which evaluate the particle id, momentum, transverse momentum and the charge correspondingly. Almost exhaustive list of currently available particle functors is available here.
 
Changed:
<
<
The return value of function select represent a lighweigted (named) container which contains the selected particles and could be directly inspected:
>
>
The return value of function select represents a lightweight (named) container which contains the selected particles and can be directly inspected:
  %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 195 to 194
 If you are not familar with easy and friendly histogramming in Gaudi, see here.

Changed:
<
<
Lets write the simple algorithm which selects, counts an dfill some histos for the particles, which satisfy certain criteria. E.g. good, or fast or well identified muos or kaons.
>
>
Let's write the simple algorithm which selects, counts and fills some histos for the particles, which satisfy certain criteria. E.g. good or fast or well identified muos or kaons.
  Start new algorithm in src directory of Tutorial/LoKiTutor package: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 208 to 207
  // avoid very long names: using namespace LoKi ; using namespace LoKi::Types ;
Changed:
<
<
using namespsce LoKi::Cuts ;
>
>
using namespace LoKi::Cuts ;
  ... put your lines here ...
Line: 218 to 217
  Put your selection lines after the line 01080. E.g. try to select fast&well-identified muons. Consult these pages for the list of functions.
Changed:
<
<
Probably following functions could be useful:
>
>
Probably the following functions could be useful:
 
P
momentum of the particle
ID
numerical ID of the particle
KEY
the key of the particle
PT
transverse momentum
Changed:
<
<
PX , PY , PZ
x-,y-&z-components of the particle mometum
>
>
PX , PY , PZ
x-,y-,z-components of the particle mometum
 
PIDK
PIDmu
Changed:
<
<
Useful quantity for separation of particles form decays of beautyparticles from the particles, originating in the primary vertices are
>
>
Useful quantity for separation of particles from decays of beautyparticles and the particles, originating in the primary vertices, are
 the minimal of impact parameter, calculated over all reconstructed primary vertices. This quantity in LoKi is evaluated using the function MIPCHI2 : %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Changed:
<
<
// get all reocntructed primary vertices:
>
>
// get all reconstructed primary vertices:
 LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices(); /// "desktop" is a member functionof class DVAlgorithm

// create the function from the list of primary vertices and some helper object (IGeomDispCalculator tool) Fun fun = MIPCHI2 ( pvs , geo() ) ; /// "geo" is a member function of class LoKi::Algo

Changed:
<
<
// use it explicitely:
>
>
// use it explicitly:
 const LHCb::Particle* p = ... ; const double minChi2 = fun ( p ) ;
Line: 247 to 246
  %ENDSYNTAX%
Changed:
<
<
Try to select, count particle and make the simple plots..
>
>
Try to select, count particles and make the simple plots..
 

The configuration

Of course the configuration of this algorithm require a bit more typing,
Line: 282 to 281
 

The solution

Changed:
<
<
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/GetData/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
>
>
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory solutions/GetData/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
 
Changed:
<
<
>
>
 

The loops over multiparticle combinations

The next example illustrates the looping over the multiparticle combinations.

Changed:
<
<
Assuming we want to loop over all combinations and plot the invarinat mass of the dikaons. It could be done easily by the explictit double loop in the spirit on native DaVinci:
>
>
Let's assume we want to loop over all combinations and plot the invariant mass of the dikaons. It could be done easily by the explicit double loop in the spirit of native DaVinci:
  %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 301 to 299
 Range kminus = select ( "k-" , ... ) ; // you already know how to select "good" negative kaons!

// make explicit double loop

Changed:
<
<
for ( Range::iterator ik1 = kplus.begin() ; kplue.end() = ik1 ; ++ik1 )
>
>
for ( Range::iterator ik1 = kplus.begin() ; kplus.end() = ik1 ; ++ik1 )
 { const LHCb::Particle* k1 = *ik1 ; for ( Range::iterator ik2 = kminus.begin() ; kminus.end() = ik2 ; ++ik2 ) { const LHCb::Particle* k2 = *ik2 ;
Changed:
<
<
// evaluate the invarinat mass:
>
>
// evaluate the invariant mass:
  const double mass = ( k1->momentum() + k2->momentum() ).M() ;

// fill the histo:

Changed:
<
<
plot ( mass / Gaudi::Units::GeV , "dikaon invarinat mass inGeV " , 1. , 1.1 , 200 ) ;
>
>
plot ( mass / Gaudi::Units::GeV , "dikaon invariant mass in GeV " , 1. , 1.1 , 200 ) ;
  } } %ENDSYNTAX%
Line: 326 to 324
 // make a loop over all dikaon combinations: for ( Loop dikaons = loop ( "k+ k-" ) ; dikaons ; ++dikaons ) {
Changed:
<
<
// fast evaluation of the invarinat mass:
>
>
// fast evaluation of the invariant mass:
  const double mass = dikaon->mass(1,2) ;

// fill the histo:

Line: 336 to 334
  For such trivial case both approaches (the native DaVinci) and LoKi (see above) are very similar. The clear difference appears immediately as soon as one goes to a bit more complicated tasks.
Changed:
<
<
Usually we have no interest to see the invarinat mass of all combinations. If one tries to reconstruct , one also performes the vertex fit and creates the compound
>
>
Usually we have no interest in seeing the invariant mass of all combinations. If one tries to reconstruct , one also performs the vertex fit and creates the compound
 particle for .
Changed:
<
<
You already know well how to do in in DaVinci - one needs to use explicitely some vertex fitter tool. In LoKi the compound particle as the effective "mother" particle of the loop automatically and implicitely on-demand. Please, note that to use this functionality one needs to specify the indentifier of the effective
>
>
You already know well how to do it in DaVinci - one needs to use explicitly some vertex fitter tool. In LoKi the compound particle is the effective "mother" particle of the loop automatically and implicitly on demand. Please, note that in order to use this functionality one needs to specify the identifier of the effective
 compound particle: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // make a loop over all dikaon combinations:
Line: 351 to 349
  const LHCb::Particle* phi = dikaons->particle() ;

// fill the histo:

Changed:
<
<
plot ( M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ; // function M gets as argument the particle
>
>
plot ( M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass in GeV " , 1. , 1.1 , 200 ) ; // function M gets the particle as the argument
 } %ENDSYNTAX% One also can get the access to the effective vertex of the dikaon combiation:
Line: 363 to 361
  const LHCb::Vertex* v = dikaons->vertex() ;

// fill the histo:

Changed:
<
<
plot ( VCHI2 ( v ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets as an argument the vertex
>
>
plot ( VCHI2 ( v ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets the vertex as the argument
 } %ENDSYNTAX% Please note that explicit cast to LHCb::Particle or LHCb::Vertex is usually not needed, one can use
Line: 373 to 371
 for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) { // fill the histos:
Changed:
<
<
plot ( M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ; // function M gets as argument the particle plot ( VCHI2 ( dikaon ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets as an argument the vertex
>
>
plot ( M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass in GeV " , 1. , 1.1 , 200 ) ; // function M gets the particle as the argument plot ( VCHI2 ( dikaon ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets the vertex as the argument
 } %ENDSYNTAX% Obviously the creation of the compound particle and vertex fit are the CPU-consuming procedures, therefore
Changed:
<
<
it is desirable to cut "non-interetsing" combinations as soon as possible, e.g.:
>
>
it is desirable to cut "non-interesting" combinations as soon as possible, e.g.:
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // make a loop over all dikaon combinations: for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons )
Line: 388 to 386
  // skip high-mass combiations if ( mass > 1100 * Gaudi::Units::MeV ) { continue ; } // CONTINUE // fill the histos:
Changed:
<
<
plot ( M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ; // function M gets as argument the particle plot ( VCHI2 ( dikaon ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets as an argument the vertex
>
>
plot ( M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass in GeV " , 1. , 1.1 , 200 ) ; // function M gets the particle as the argument plot ( VCHI2 ( dikaon ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets the vertex as the argument
 } %ENDSYNTAX% Often one needs to get the access to the daughter particle (e.g. to the first kaon, or to the secon dkaon).
Line: 412 to 410
  if ( ... ) { continue ; } if ( ... ) { continue ; }

Changed:
<
<
// save combination, if good enough:
>
>
// save combination if good enough:
  phi -> save ( "myGoodPhi" ) ; } %ENDSYNTAX%
Line: 436 to 434
  %ENDSYNTAX%
Changed:
<
<
Now you know all ingredients to code the simple algorithm with makes the loop
>
>
Now you know all ingredients to code the simple algorithm which makes the loop
 over multi-particle combinations, applies some cuts, plots the distributions for
Changed:
<
<
the compound particle and save interesting combinations for subsequent analysis. Lets try to write such algorithm for selection using your experience from the previous excersize:
>
>
the compound particle and saves interesting combinations for subsequent analysis. Let's try to write such algorithm for selection using your experience from the previous exercise:
 
  1. select the good positive kaons
  2. select the good negative kaons
  3. make a loop over dikaons
  4. apply some cuts for the compound particle
  5. plot some distributions for the compound and/or daughter particles
    • if you already familar with N-tuples (see here), fill N-tuple with all these variables
Changed:
<
<
  1. save "interesting" combiations and count them
>
>
  1. save "interesting" combinations and count them
 

The algorithm:

Line: 474 to 472
 
M12
The invariant mass of the first and second daughter particles
CHILD
Meta-function, which delegates the evaluation of another function to daughter particle, e.g. CHILD( P , 1 ) evaluates the momentum of the first daughter particle
DMASS
The function is able to evaluate the invariant mass difference with respect to some reference mass: e.g. DMASS("phi(1020") evalutes the difference between the invarinat mass of the particle and the nominal mass of .
Changed:
<
<
ADMASS
The function evaluates the absolute value of the invariant mass diffrence with respect to some reference mass: e.g. ADMASS("phi(1020") evalutes the absolute valeu of the difference between the invarinat mass of the particle and the nominal mass of .
>
>
ADMASS
The function evaluates the absolute value of the invariant mass diffrence with respect to some reference mass: e.g. ADMASS("phi(1020") evalutes the absolute value of the difference between the invariant mass of the particle and the nominal mass of .
 

The solution

Changed:
<
<
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/LoKiLoop/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
>
>
The full solution to this exercise ( *.cpp & *.opts files) is available in the directory solutions/LoKiLoop/ in the Tutorial/LoKiTutor package and could be inspected/copied in case of problems.
 
Changed:
<
<
>
>
 

Easy matching to Monte Carlo truth

Changed:
<
<
The next excersize illustrates the usage of Monte Carlo information in LoKi.
>
>
The next exercise illustrates the usage of Monte Carlo information in LoKi.
 
Changed:
<
<
LoKi offers nice possibility to perform easy "on-fligh" access to Monte Calro truth information. Not all possible cases are covered on the equal basis but the most friequent idioms
>
>
LoKi offers nice possibility to perform easy "on-flight" access to Monte Calro truth information. Not all possible cases are covered on the equal basis but the most frequent idioms
 are reflected and well-covered in LoKi.

Selection of Monte Carlo particles

Following the major principle of the equality of all animals, LoKi offers the functionality of selection of Monte Carlo particles, which is very similar to the functionlity,

Changed:
<
<
described for the second excersize:
>
>
described for the second exercise:
  %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 636 to 633
  Now you know all the major ingredients useful for simple Monte Carlo match. Lets try to write the algorithm for
Changed:
<
<
selection using your experience from the previous excersize:
>
>
selection using your experience from the previous exercise:
 
  1. find true Monte Carlo decays
  2. create the helper matching predicates/functions for Monte match of and
  3. select the good positive muons
Line: 671 to 668
 

The configuration

The configuration of the job is quite standard and does not require the additional effors

Changed:
<
<
with respect to the previous excersize.
>
>
with respect to the previous exercise.
 Please note that for this algorithm one needs only muons as input partiles, therefore for the reaosns of CPU efficiency other input locations could be suppressed.
Line: 688 to 685
 

The solution

Changed:
<
<
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory
>
>
The full solution for this exercise ( *.cpp & *.opts files) is available in the directory
 solutions/PsiMC/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.

Changed:
<
<

Combine everything altogather and get the nice peak.

>
>

Combine everything altogether and get the nice peak.

 
Changed:
<
<
The purpose of the next excersize if combine all ingredient togather and write the "realistic" but simple analysis algorithm
>
>
The purpose of the next exercise if combine all ingredient togather and write the "realistic" but simple analysis algorithm
 for decay. Essentialy one now has all ingredients ready and one just need to combine them in a rigth way within one algorithm.
  • Please note that it is a bit different from DaVinci approach where users encouraged to split the one algorithm into smaller algorithmm which run in the sequence. Here we'll study the possibility to recontruct teh whole chain in one algorithm.
Line: 708 to 705
 
  1. selection of through the loop over dikaons
  2. selection of through the loop over selected and candidates
Changed:
<
<
From the Excersize 3 you already know well how to reach the first goal, and from the Excersize 4 you know how to read the second goal.
>
>
From the Exercise 3 you already know well how to reach the first goal, and from the Exercise 4 you know how to read the second goal.
 Therefore here one just needs to concentrate on the third item. The overall design of the algorithm could be sketched as:
Line: 806 to 803
 

The configuration

Changed:
<
<
Pleas note that for this excersize one needs to load both muons and kaons.
>
>
Pleas note that for this exercise one needs to load both muons and kaons.
 Do not forget to include the following lines into the configuration ==opts==-file: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 825 to 822
 

The solution

Changed:
<
<
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory
>
>
The full solution for this exercise ( *.cpp & *.opts files) is available in the directory
 solutions/PsiPhi/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.

Revision 62007-10-01 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial: Getting started with LoKi

Line: 10 to 10
 
Changed:
<
<
This tutorial has last been tested with DaVinci v19r5.
>
>
This tutorial has last been tested with DaVinci v19r5, the slides available as pdf or pptx.
 

Prerequisites

It is assumed that you are more or less familiar with the basic tutorial, also some level of familiarity with the DaVinci tutorial is assumed. It is also recommended to look through histograms & N-tuples pages.
Changed:
<
<
You are also invited to the lhcb-loki mailing list.
>
>
You are also invited to the lhcb-loki mailing list.
 

Setup the environment for DaVinci

For this particular tutorial we'll concentrate on the interactive jobs and let the batch system and GRID, Ganga and DIRAC tool some rest.
Line: 830 to 831
 

-- Vanya Belyaev - 26 Sep 2007

Added:
>
>
META FILEATTACHMENT attachment="20071003_Tutorial_LoKi_v6r0.pdf" attr="" comment="" date="1191247669" name="20071003_Tutorial_LoKi_v6r0.pdf" path="20071003_Tutorial_LoKi_v6r0.pdf" size="18790217" stream="20071003_Tutorial_LoKi_v6r0.pdf" user="Main.VanyaBelyaev" version="1"
META FILEATTACHMENT attachment="20071003_Tutorial_LoKi_v6r0.pptx" attr="" comment="" date="1191247808" name="20071003_Tutorial_LoKi_v6r0.pptx" path="20071003_Tutorial_LoKi_v6r0.pptx" size="440284" stream="20071003_Tutorial_LoKi_v6r0.pptx" user="Main.VanyaBelyaev" version="1"

Revision 52007-09-29 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"
Changed:
<
<

LHCb LoKi Tutorial

>
>

LHCb LoKi Tutorial: Getting started with LoKi

 This hands-on tutorial is an introduction to LoKi - C++ toolkit for easy and friendly physics analysis. The purpose of these exercises is to allow you to write a complete though simple analysis algorithms for "typical" decay: .

Revision 42007-09-28 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial

This hands-on tutorial is an introduction to LoKi - C++ toolkit for easy and friendly physics analysis.
Line: 152 to 152
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// get all positive muons:

Changed:
<
<
Range muplus = select ( "mymu+" , "mu+" == ID ) ;
>
>
Range muplus = select ( "mymu+" , "mu+" == ID ) ; /// "select" is a member function of class LoKi::Algo
  // get all negative muons: Range muminus = select ( "mumu-" , "mu-" == ID ) ;
Line: 231 to 231
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

// get all reocntructed primary vertices:

Changed:
<
<
LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices();
>
>
LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices(); /// "desktop" is a member functionof class DVAlgorithm
  // create the function from the list of primary vertices and some helper object (IGeomDispCalculator tool)
Changed:
<
<
Fun fun = MIPCHI2 ( pvs , geo() ) ;
>
>
Fun fun = MIPCHI2 ( pvs , geo() ) ; /// "geo" is a member function of class LoKi::Algo
  // use it explicitely: const LHCb::Particle* p = ... ;
Line: 424 to 424
  // save combination, if good enough: phi -> save ( "myGoodPhi" ) ; // MIND THE NAME }
Added:
>
>
 // get the previously saved combinations: Range phis = selected ( "myGoodPhi" ) ; // NOTE THE NAME
Added:
>
>
always() << " Number of phi-candidates: " << phis.size() << endreq ; // use the counter: counter ("#phis") += phis.size() ;

 %ENDSYNTAX%

Now you know all ingredients to code the simple algorithm with makes the loop

Line: 486 to 492
 

Selection of Monte Carlo particles

Changed:
<
<
Following the major principle of the equality of all anymals, LoKi offers the functionality of selection of Monte Carlo particles, whcih is very similar to the functionlity,
>
>
Following the major principle of the equality of all animals, LoKi offers the functionality of selection of Monte Carlo particles, which is very similar to the functionlity,
  described for the second excersize:

%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

Line: 553 to 558
 e.g. : %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Changed:
<
<
// retrieve Monte Carlo mathcing objects
>
>
// retrieve Monte Carlo matching object:
 MCMatch mc = mcTruth() ; // the member function of class LoKi::MCAlgo

// get some MC-particles, (e.g.mc-muons)

Line: 688 to 693
 

Changed:
<
<

Combine everything altogather

>
>

Combine everything altogather and get the nice peak.

  The purpose of the next excersize if combine all ingredient togather and write the "realistic" but simple analysis algorithm for decay. Essentialy one now has all ingredients ready and one just
Line: 703 to 708
  From the Excersize 3 you already know well how to reach the first goal, and from the Excersize 4 you know how to read the second goal. Therefore here one just needs to concentrate on the third item.
Changed:
<
<
The overall schema of the algorithm could be sketched as:
>
>
The overall design of the algorithm could be sketched as:
  %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% #include "LoKi/LoKi.h"
Line: 729 to 733
  dimuon -> save ( "psi" ) ; // MIND THE NAME }

Changed:
<
<
... and here one need to add the seelction of Bs ...
>
>
... and here one needs to add the selection of Bs ...
  return StatusCode::SUCCESS ; // RETURN }
Line: 744 to 748
 Please mind the names of "component" used for -candidate selection: loop("psi phi",...).
Added:
>
>
To make your lines more CPU-efficient, try to skip all unnesessary actions, e.g.:

<!-- SyntaxHighlightingPlugin -->
 1000Range muplus = select ( ... ) ;
 1010if ( muplus.empty() ) { return StatusCode::SUCCEES ; }   // no need to continue the execution
 1020...
 1030for (  Loop dimuon = ... )
 1040{ 
 1050   ... 
 1060  dimuon->save ( "psi" ) ; 
 1070}
 1080Range psis = selected ( "psi" ) ;
 1090if ( psis.empty() ) { return StatusCode::SUCCESS ; } // noneed to continue the execution .
 1100
<!-- end SyntaxHighlightingPlugin -->
 
Added:
>
>
Plase also note that if one needs to code selection algorithm, one must take care about setFilterPassed method:

<!-- SyntaxHighlightingPlugin -->
 1000for (  Loop Bs = ... )
 1010{ 
 1020   ... 
 1030  Bs->save ( "Bs" ) ; 
 1040}
 1050Range bs = selected ( "Bs" ) ;
 1060
 1070// filter decision depends on the saved Bs-candidates:  
 1080setFilterPassed ( !bs.empty() ) ;   // "setFilterPassed" is a member function of class Algorithm, redefined in DVAlgorithm  
 1090
<!-- end SyntaxHighlightingPlugin -->

The algorithm

Start new algorithm in src directory of Tutorial/LoKiTutor package: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

 
Added:
>
>
#include "LoKi/LoKi.h"
 
Added:
>
>
LOKI_ALGORITHM(PsiPhi) { // avoid very long names: using namespace LoKi ; using namespace LoKi::Types ; using namespsce LoKi::Cuts ;
 
Added:
>
>
... put your lines here, essentially the compilation from the previous examples.
 
Added:
>
>
return StatusCode::SUCCESS ; // RETURN } %ENDSYNTAX%
 
Added:
>
>
Please note that if one wants to have access to Monte Carlo truth information, one must to use the macro LOKI_MCALGORITHM.
 
Added:
>
>

The configuration

Pleas note that for this excersize one needs to load both muons and kaons. Do not forget to include the following lines into the configuration ==opts==-file: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
 
Added:
>
>
...
 
Added:
>
>
#include "$COMMONPARTICLESROOT/options/StandardKaons.opts" #include "$COMMONPARTICLESROOT/options/StandardMuons.opts"
 
Added:
>
>
... InputLocations = { "Phys/StdTightKaons" , // use the "standard loose kaons" "Phys/StdLooseMuons" // use the "standard loose muons" } ;
 
Added:
>
>
%ENDSYNTAX%
 
Changed:
<
<
>
>

The solution

 
Added:
>
>
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/PsiPhi/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
 

-- Vanya Belyaev - 26 Sep 2007

Revision 32007-09-27 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial

This hands-on tutorial is an introduction to LoKi - C++ toolkit for easy and friendly physics analysis.
Line: 13 to 13
 

Prerequisites

It is assumed that you are more or less familiar with the basic tutorial, also some level of familiarity with
Changed:
<
<
the DaVinci tutorial is assumed. You are also invited to the lhcb-loki mailing list.
>
>
the DaVinci tutorial is assumed. It is also recommended to look through histograms & N-tuples pages. You are also invited to the lhcb-loki mailing list.
 

Setup the environment for DaVinci

For this particular tutorial we'll concentrate on the interactive jobs and let the batch system and GRID, Ganga and DIRAC tool some rest.
Line: 57 to 60
 > DaVinci.exe $LOKITUTORROOT/solutions/HelloWorld/HelloWorld.opts
%ENDSYNTAX%
Added:
>
>
 

The most trivial (empty) "Hello,World!" LoKi algorithm

The most trivial LoKi empty algorithm ("Hello,World!") demonstrate in a very clear way the main principles of any LoKi-based algorithms:
Line: 65 to 69
 
  • The body of the algorithm is defined using LOKI_ALGORITHM or LOKI_MCALGORITHM macros
    • The macro LOKI_ALGORITHM should be used for Monte Carlo-independent studies
Changed:
<
<

The algorithm

>
>

The algorithm

 The simplest algorithm looks like: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% // Include files
Line: 98 to 102
  Put your algorithm into src ditrectory of Tutorial/LoKiTutor package and build the package.
Changed:
<
<

The configuration

>
>

The configuration

 Of course the configuration of this simple ("do-nothing") algorithm does not require a lot of efforts:

%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

Line: 129 to 133
  Put your configuration *.opts file into options directory of Tutorial/LoKiTutor package and run the excersize.
Changed:
<
<

The solution

>
>

The solution

  The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/HelloWorld/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
Changed:
<
<
>
>
 

Simple selection of particles

The second excersize demonstrates the simple selections of particles using LoKi functors.

Line: 184 to 190
 // fill the historgam through implicit loop: plot ( PT / Gaudi::Units::GeV , particles.begin() , particles.end() , " pt of selecte dparticles (implicit loop) " , 0 , 5 ) ; %ENDSYNTAX%
Added:
>
>
If you are not familar with easy and friendly histogramming in Gaudi, see here.
  Lets write the simple algorithm which selects, counts an dfill some histos for the particles, which satisfy certain criteria. E.g. good, or fast or well identified muos or kaons.
Line: 193 to 201
  #include "LoKi/LoKi.h"
Changed:
<
<
LOKI_ALGORITHM(SelectParticles)
>
>
LOKI_ALGORITHM(GetData)
 { // avoid very long names: using namespace LoKi ; using namespace LoKi::Types ; using namespsce LoKi::Cuts ;
Changed:
<
<
>
>
... put your lines here ...
  return StatusCode::SUCCESS ; // RETURN } %ENDSYNTAX%

Put your selection lines after the line 01080. E.g. try to select fast&well-identified muons. Consult these pages for the list of functions.

Added:
>
>
 Probably following functions could be useful:
Changed:
<
<
  1. P momentum of the particle
  2. ID numerical ID of the particle
  3. KEY the key of the particle
  4. PT transverse momentum
  5. PX , PY , PZ x-,y-&z-components of the particle mometum
  6. PIDK
  7. PIDmu
>
>
P
momentum of the particle
ID
numerical ID of the particle
KEY
the key of the particle
PT
transverse momentum
PX , PY , PZ
x-,y-&z-components of the particle mometum
PIDK
PIDmu
  Useful quantity for separation of particles form decays of beautyparticles from the particles, originating in the primary vertices are the minimal of impact parameter, calculated over all reconstructed primary vertices.
Line: 224 to 233
 // get all reocntructed primary vertices: LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices();
Changed:
<
<
// create the function
>
>
// create the function from the list of primary vertices and some helper object (IGeomDispCalculator tool)
 Fun fun = MIPCHI2 ( pvs , geo() ) ;

// use it explicitely:

Line: 232 to 241
 const double minChi2 = fun ( p ) ;

// use it for selection:

Changed:
<
<
Range pionsNotFromPV = select ("pions" , "pi+" == ABSID && 9 < fun ( p ) ) ;
>
>
Range pionsNotFromPV = select ("pions" , "pi+" == ABSID && 9 < fun ) ;
  %ENDSYNTAX%

Try to select, count particle and make the simple plots..

Changed:
<
<

The configuration

>
>

The configuration

 Of course the configuration of this algorithm require a bit more typing, in particular one needs to specify the input locations for the algorithm: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Line: 257 to 266
 // ======================================================================== // (4) configure "our" algorithm: InputLocations = {
Changed:
<
<
"Phys/StdLoosePions" , // use the "standard" pions "Phys/StdTightKaons" , // use the "standard" kaons "Phys/StdLooseMuons" // use the "standard" muons
>
>
"Phys/StdLoosePions" , // use the "standard loose pions" "Phys/StdTightKaons" , // use the "standard loose kaons" "Phys/StdLooseMuons" // use the "standard loose muons"
 } ; // ======================================================================== // (5) define input data
Line: 269 to 278
 EvtMax = 200 ; %ENDSYNTAX%

Changed:
<
<

The solution

>
>

The solution

  The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/GetData/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
Added:
>
>

The loops over multiparticle combinations

The next example illustrates the looping over the multiparticle combinations.

Assuming we want to loop over all combinations and plot the invarinat mass of the dikaons. It could be done easily by the explictit double loop in the spirit on native DaVinci:

<!-- SyntaxHighlightingPlugin -->
 1000Range kplus = select ( "k+" , ... ) ; // you already know how to select "good" positive kaons!
 1010Range kminus = select ( "k-" , ... ) ; // you already know how to select "good" negative kaons!
 1020
 1030// make explicit double loop
 1040for ( Range::iterator ik1 = kplus.begin() ; kplue.end() != ik1 ; ++ik1 ) 
 1050{
 1060  const LHCb::Particle* k1 = *ik1 ; 
 1070  for ( Range::iterator ik2 = kminus.begin() ; kminus.end() != ik2 ; ++ik2  )
 1080   {
 1090     const LHCb::Particle* k2 = *ik2 ;
 1100
 1110     // evaluate the invarinat mass:
 1120     const double mass = ( k1->momentum() + k2->momentum() ).M() ;  
 1130     
 1140     // fill the histo:
 1150     plot ( mass / Gaudi::Units::GeV , "dikaon invarinat mass inGeV " , 1. , 1.1 , 200 ) ;
 1160   }
 1170} 
<!-- end SyntaxHighlightingPlugin -->

LoKi offers the alternative way of doing the same stuff using loop function and Loop object:

<!-- SyntaxHighlightingPlugin -->
 1000Range kplus = select ( "k+" , ... ) ; // you already know how to select "good" positive kaons!
 1010Range kminus = select ( "k-" , ... ) ; // you already know how to select "good" negative kaons!
 1020
 1030// make a loop over all dikaon combinations:  
 1040for ( Loop dikaons = loop ( "k+ k-" ) ; dikaons ; ++dikaons ) 
 1050{ 
 1060     // fast evaluation of the invarinat mass: 
 1070     const double mass = dikaon->mass(1,2) ; 
 1080
 1090     // fill the histo:
 1100     plot ( mass / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ;
 1110} 
<!-- end SyntaxHighlightingPlugin -->

For such trivial case both approaches (the native DaVinci) and LoKi (see above) are very similar. The clear difference appears immediately as soon as one goes to a bit more complicated tasks. Usually we have no interest to see the invarinat mass of all combinations. If one tries to reconstruct , one also performes the vertex fit and creates the compound particle for . You already know well how to do in in DaVinci - one needs to use explicitely some vertex fitter tool. In LoKi the compound particle as the effective "mother" particle of the loop automatically and implicitely on-demand. Please, note that to use this functionality one needs to specify the indentifier of the effective compound particle:

<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030     // get the effective particle of the loop:
 1040     const LHCb::Particle* phi = dikaons->particle() ;
 1050
 1060     // fill the histo:
 1070     plot (  M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ; // function M gets as argument the particle 
 1080} 
<!-- end SyntaxHighlightingPlugin -->
One also can get the access to the effective vertex of the dikaon combiation:
<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030     // get the effective vertex of the loop:
 1040     const LHCb::Vertex* v = dikaons->vertex() ;
 1050
 1060     // fill the histo:
 1070     plot (  VCHI2 ( v ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets as an argument the vertex 
 1080} 
<!-- end SyntaxHighlightingPlugin -->
Please note that explicit cast to LHCb::Particle or LHCb::Vertex is usually not needed, one can use the looping object of type Loop directly as the argument for many functions:
<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030     // fill the histos:
 1040      plot (  M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ; // function M gets as argument the particle 
 1050      plot (  VCHI2 ( dikaon ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets as an argument the vertex 
 1060} 
<!-- end SyntaxHighlightingPlugin -->
Obviously the creation of the compound particle and vertex fit are the CPU-consuming procedures, therefore it is desirable to cut "non-interetsing" combinations as soon as possible, e.g.:
<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030     // evaluate the mass through sum of 4-momenta (fast)
 1040      const double mass  = dikaons->mass(1,2) ;
 1050      // skip high-mass combiations 
 1060      if ( mass > 1100 * Gaudi::Units::MeV ) { continue ; }          // CONTINUE 
 1070      // fill the histos:
 1080      plot (  M ( phi ) / Gaudi::Units::GeV , "dikaon invariant mass inGeV " , 1. , 1.1 , 200 ) ; // function M gets as argument the particle 
 1090      plot (  VCHI2 ( dikaon ) , "chi2 of the vertex fit " , 0 , 100 ) ; // function VCHI2 gets as an argument the vertex 
 1100} 
<!-- end SyntaxHighlightingPlugin -->
Often one needs to get the access to the daughter particle (e.g. to the first kaon, or to the secon dkaon). It could be done in an easy way:
<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030      // get the first kaon:
 1040      const LHCb::Particle* k1 = dikaons(1) ;  // NB!   Indices start from 1 ! 
 1050      // get the second kaon:
 1060      const LHCb::Particle* k2 = dikaons(2) ; // NB!   Indices start from 1 !
 1070} 
<!-- end SyntaxHighlightingPlugin -->
Finally one can apply some cuts for the compound particle and save "good" candidates:
<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030      if ( ... ) { continue ; } 
 1040      if ( ... ) { continue ; } 
 1050      
 1060      // save combination, if good enough:
 1070      phi -> save ( "myGoodPhi" ) ;     
 1080} 
 1090 
<!-- end SyntaxHighlightingPlugin -->
The "saved" compound particles could be inspected through the function selected:
<!-- SyntaxHighlightingPlugin -->
 1000// make a loop over all dikaon combinations:  
 1010for ( Loop dikaons = loop ( "k+ k-" , "phi(1020)" ) ; dikaons ; ++dikaons ) 
 1020{ 
 1030      ....
 1040      // save combination, if good enough:
 1050      phi -> save ( "myGoodPhi" ) ;                    // MIND THE NAME 
 1060} 
 1070// get the previously saved combinations:
 1080Range phis = selected ( "myGoodPhi" ) ;     // NOTE THE NAME 
 1090
<!-- end SyntaxHighlightingPlugin -->

Now you know all ingredients to code the simple algorithm with makes the loop over multi-particle combinations, applies some cuts, plots the distributions for the compound particle and save interesting combinations for subsequent analysis. Lets try to write such algorithm for selection using your experience from the previous excersize:

  1. select the good positive kaons
  2. select the good negative kaons
  3. make a loop over dikaons
  4. apply some cuts for the compound particle
  5. plot some distributions for the compound and/or daughter particles
    • if you already familar with N-tuples (see here), fill N-tuple with all these variables
  6. save "interesting" combiations and count them

The algorithm:

Start new algorithm in src directory of Tutorial/LoKiTutor package:

<!-- SyntaxHighlightingPlugin -->
 1000#include "LoKi/LoKi.h"
 1010
 1020LOKI_ALGORITHM(LoKiLoop) 
 1030{
 1040    // avoid very long names:
 1050    using namespace LoKi ;
 1060    using namespace LoKi::Types ;
 1070    using namespsce LoKi::Cuts  ;
 1080
 1090    ... put your lines here ... 
 1100
 1110    return StatusCode::SUCCESS ;                             // RETURN 
 1120}
<!-- end SyntaxHighlightingPlugin -->
Note some functions which could be useful (in addition to these functions):
M
The invariant mass of the particle, LHCb::Particle::momentum().M(),
M12
The invariant mass of the first and second daughter particles
CHILD
Meta-function, which delegates the evaluation of another function to daughter particle, e.g. CHILD( P , 1 ) evaluates the momentum of the first daughter particle
DMASS
The function is able to evaluate the invariant mass difference with respect to some reference mass: e.g. DMASS("phi(1020") evalutes the difference between the invarinat mass of the particle and the nominal mass of .
ADMASS
The function evaluates the absolute value of the invariant mass diffrence with respect to some reference mass: e.g. ADMASS("phi(1020") evalutes the absolute valeu of the difference between the invarinat mass of the particle and the nominal mass of .

The solution

The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/LoKiLoop/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.

Easy matching to Monte Carlo truth

The next excersize illustrates the usage of Monte Carlo information in LoKi.

LoKi offers nice possibility to perform easy "on-fligh" access to Monte Calro truth information. Not all possible cases are covered on the equal basis but the most friequent idioms are reflected and well-covered in LoKi.

Selection of Monte Carlo particles

Following the major principle of the equality of all anymals, LoKi offers the functionality of selection of Monte Carlo particles, whcih is very similar to the functionlity, described for the second excersize:

<!-- SyntaxHighlightingPlugin -->
 1000// get the true Monte Carlo positive kaons  
 1010MCRange mckaon = mcselect ( "mck+" , "K+" == MCID ) ;
 1020
 1030// get all beauty particles 
 1040MCRange beauty  = mcselect ( "mck+" , BEAUTY ) ;
 1050
 1060// get all true fast Monte Carlo muons from decay/interaction of selected beauty particles:
 1070MCRange mcmu = mcselect ( "mcmu" , "mu+" == MCABSID && FROMMCTREE ( beauty ) && MCPT > 1 * Gaudi::Units::GeV ) ;  
<!-- end SyntaxHighlightingPlugin -->
The objects of type MCRange have the stantard interface of the container and could be inpected through the explicit loop:
<!-- SyntaxHighlightingPlugin -->
 1000MCRange mc = 
 1010
 1020always() << " Number of MC-particles " << mc.size() << endreq ;
 1030
 1040// explicit loop:
 1050for ( MCRange::iterator imc = mc.begin() ; mc.end() != imc ; ++imc ) 
 1060{
 1070    const LHCb::MCParticle* p = *imc ;
 1080    plot ( MCP ( p ) /Gaudi::Units::GeV , "pt of Monte Carlo particle in GeV " , 0 , 10 )  ; 
 1090} 
<!-- end SyntaxHighlightingPlugin -->
In these examples MCID, MCPT, MCP, FROMMCTREE and BEAUTY are LoKi Monte Carlo particle functions.

Selection of Monte Carlo decays

For the frequent case of the special selection of particles, which satisfy teh certain decay patters LoKi offers the special utility MCFinder, which is essentially just a thin wrapper over the brilliant tool MCDecayFinder, the masterpiece written by Olivier Dormond from Lausanne Univertity:

<!-- SyntaxHighlightingPlugin -->
 1000// get the wrapper for MCDecayFinder tool 
 1010MCFinder finder = mcFinder() ;
 1020
 1030// get all Monte Carlo psis, which decay into mu+ mu-:  
 1040MCRange mcPsi  = finder -> findDecays ( "J/psi(1S) ->  mu+  mu-") ;
 1050
 1060// get all Monte Carlo muons from the  decay  psi -> mu+ mu-:  
 1070MCRange mcmu  = finder -> findDecays ( "J/psi(1S) ->  ^mu+  ^mu-") ;
<!-- end SyntaxHighlightingPlugin -->
The selected Monte Carlo particles could be subjected by the further selection:
<!-- SyntaxHighlightingPlugin -->
 1000// from the selected true muons from psi->mu+mu- decay select only the fast muons:
 1010MCRange fastMuons = mcselect ( "fastMu" , mcmu , MCPT > 0.5 * Gaudi::Units::GeV && 10 < MCP / Gaudi::Units::GeV ) ;
 1020 
<!-- end SyntaxHighlightingPlugin -->

Match to Monte Carlo truth

There are variety of the methods in LoKi for Monte Carlo truth matching. Here we describe the most trivial (which covers well the most frequent case) one, the function MCTRUTH. This function being constructed with the list of Monte Carlo particles, evaluated to true for reconstructed particles, which are matched with one of the Monte Carlo particle (or one of its Monte Carlo daughter particle) used for construction of the function. e.g. :

<!-- SyntaxHighlightingPlugin -->
 1000// retrieve Monte Carlo mathcing objects 
 1010MCMatch mc = mcTruth() ;                               // the member function of class LoKi::MCAlgo 
 1020
 1030// get some MC-particles, (e.g.mc-muons) 
 1040MCRange mcmu  = .... ;
 1050
 1060// create the function (predicate) using the list of true muons           
 1070Cut fromMC = MCTRUTH ( mc , mcmu ) ;  /// thi sfunction evaluated for "true" for particles, matched to true MC muons
 1080  
 1090// select recontructed muons, matched with true MC-muons:
 1100Range mu = select ( "goodmu" , "mu+" == ABSID && fromMC ) ;  /// use the function/predicate 
 1110
<!-- end SyntaxHighlightingPlugin -->
The constructed function/predicate formMC (the line 01070) could be used also directly:
<!-- SyntaxHighlightingPlugin -->
 1000const LHCb::Particle* p = ... ;
 1010
 1020if ( fromMC ( p ) ) 
 1030 {
 1040    ... it is a particle matched with true MC-muons ...
 1050 } 
<!-- end SyntaxHighlightingPlugin -->
Important note: the function MCTRUTH evaluates to true also for recontructed particles, which are matched to Monte Carlo particles form decay trees of the original Monte Carlo particles.

The function MCTRUTH described above is very useful for selection of "True"-decays and combinations:

<!-- SyntaxHighlightingPlugin -->
 1000// get all Monte Carlo psis, which decay into mu+ mu-:  
 1010MCRange mcPsi  = ... ;                  // you already know hoe to get them! 
 1020
 1030// get all Monte Carlo muons from the  decay  psi -> mu+ mu-:  
 1040MCRange mcmu  = ... ;                  // you know well  how to get them!!!
 1050
 1060// create the function/predicate  for "true" psi
 1070Cut truePsi = MCTRUTH ( mc , mcPsi ) ;  // check the matching with Monte Carlo true psi 
 1080
 1090// create the function/predicate  for "true" muon from psi 
 1100Cut trueMu = MCTRUTH ( mc , mcmu ) ;  // check the matching with Monte Carlo true muon from psi 
 1110
 1120// get the reocnstructed muons:
 1130Range muplus = select ( "mu+" , .... )  ;                     //  you know well how to get them!
 1140Range muminus = select ( "mu-" , .... )  ;                     //  you know well how to get them!
 1150
 1160// make the loop 
 1170for ( Loop psi = loop ( "mu+ mu-" , "J/psi(1S)" ) ; psi ; ++psi ) 
 1180{
 1190    // fast evalaution of mass
 1200    const double m12 = psi->mass(1,2) ;
 1210    if ( m12 < 2.0 * Gaudi::UnitsGeV || m12 > 4 * Gaudi::Units::GeV ) { continue ; } // skip bad combinations: 
 1220
 1230     plot ( m12 , "mass of all dimuons " , 2 , 4 ) ;
 1240     const LHCb::Particle* mu1 = psi ( 1 ) ;   // access to the first daughter particle of the loop 
 1250     const LHCb::Particle* mu2 = psi ( 2 ) ;   // get the second daughter particle of the loop 
 1260
 1270    if ( trueMu ( mu1 ) || trueMu ( mu2 ) )    // use the matching predicates
 1280    {
 1290     plot ( m12 , "mass of all dimuons, at least one is true  " , 2 , 4 ) ; // at least one muon is a true muon form J/psi
 1300    }
 1310    if ( trueMu ( mu1 ) && trueMu ( mu2 ) )    // use the matching predicates 
 1320    {
 1330      plot ( m12 , "mass of all dimuons, both muons are true  " , 2 , 4 ) ;  // both muons are true muons from J/psi:
 1340    }
 1350    if ( truePsi ( psi ) )     // use the matching predicates
 1360    {
 1370      plot ( m12 , "mass of all dimuons, true J/psi " , 2 , 4 ) ; // the dimuon combination is true psi 
 1380    }
 1390}
<!-- end SyntaxHighlightingPlugin -->

Now you know all the major ingredients useful for simple Monte Carlo match. Lets try to write the algorithm for selection using your experience from the previous excersize:

  1. find true Monte Carlo decays
  2. create the helper matching predicates/functions for Monte match of and
  3. select the good positive muons
  4. select the good negative muos
  5. make a loop over dimuons
  6. apply some cuts for the compound particle
  7. plot some distributions for the compound and/or daughter particles with and without matching to Monte Carlo truth
    • if you already familar with N-tuples (see here), fill N-tuple with all these variables
  8. save "interesting" candidates and count them

The algorithm

Start new algorithm in src directory of Tutorial/LoKiTutor package:

<!-- SyntaxHighlightingPlugin -->
 1000#include "LoKi/LoKi.h"
 1010
 1020LOKI_MCALGORITHM(PsiMC) 
 1030{
 1040    // avoid very long names:
 1050    using namespace LoKi ;
 1060    using namespace LoKi::Types ;
 1070    using namespsce LoKi::Cuts  ;
 1080
 1090    ... put your lines here ... 
 1100
 1110    return StatusCode::SUCCESS ;                             // RETURN 
 1120}
<!-- end SyntaxHighlightingPlugin -->
Note: for access to Monte Carlo truth one needs to use the macro LOKI_MCALGORITHM= istead of LOKI_ALGORITHM.

The configuration

The configuration of the job is quite standard and does not require the additional effors with respect to the previous excersize. Please note that for this algorithm one needs only muons as input partiles, therefore for the reaosns of CPU efficiency other input locations could be suppressed. Also since we are working only with charged particles, one can gain some CPU performace by disabling the Monte Carlo truth for calorimeter objects and neutral protoparticles, which are enabled in the default configuration. it could be done using the following settion for th eproeprty PP2MCs for your algorithm:

<!-- SyntaxHighlightingPlugin -->
 1000// use Monte Carlo truth only for charged tracks: 
 1010PsiMC.PP2MCs = { "Relations/Rec/ProtoP/Charged" } ;
<!-- end SyntaxHighlightingPlugin -->

The solution

The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/PsiMC/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.

Combine everything altogather

The purpose of the next excersize if combine all ingredient togather and write the "realistic" but simple analysis algorithm for decay. Essentialy one now has all ingredients ready and one just need to combine them in a rigth way within one algorithm.

  • Please note that it is a bit different from DaVinci approach where users encouraged to split the one algorithm into smaller algorithmm which run in the sequence. Here we'll study the possibility to recontruct teh whole chain in one algorithm.

The analysis of decay chain could be natually split into three simlar phases

  1. selection of through the loop over dimuons
  2. selection of through the loop over dikaons
  3. selection of through the loop over selected and candidates

From the Excersize 3 you already know well how to reach the first goal, and from the Excersize 4 you know how to read the second goal. Therefore here one just needs to concentrate on the third item. The overall schema of the algorithm could be sketched as:

<!-- SyntaxHighlightingPlugin -->
 1000#include "LoKi/LoKi.h"
 1010LOKI_ALGORITHM(PsiPhi) 
 1020{
 1030
 1040    ....
 1050   Range kplus= select ( "k+" , ... ) ;
 1060   Range kminus= select ( "k-" , ... ) ;
 1070   for ( Loop dikaon = loop ( "k+ k-" , .... ) ...  ) 
 1080   {
 1090       ...
 1100      dikaon -> save ( "phi" ) ;                // MIND THE NAME 
 1110   }
 1120   
 1130   ....
 1140   Range muplus= select ( "m+" , ... ) ;
 1150   Range muminus= select ( "m-" , ... ) ;
 1160   for ( Loop dimuon =  loop (  "m+ m-" , ...) ...  ) 
 1170   {
 1180       ...
 1190      dimuon -> save ( "psi" ) ;            // MIND THE NAME 
 1200   }
 1210   
 1220   ... and here one need to add the seelction of Bs ...
 1230
 1240    return StatusCode::SUCCESS ;                             // RETURN 
 1250}
<!-- end SyntaxHighlightingPlugin -->
How to make the selection of ?
<!-- SyntaxHighlightingPlugin -->
 1000for (  Loop Bs = loop ( "psi phi" , "B_s0" ) ; Bs ; ++Bs )          /// MIND THE NAME
 1010{
 1020  ...
 1030}
<!-- end SyntaxHighlightingPlugin -->
Please mind the names of "component" used for -candidate selection: loop("psi phi",...).

 

Line: 286 to 757
 
Added:
>
>
 

Revision 22007-09-26 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial

This hands-on tutorial is an introduction to LoKi - C++ toolkit for easy and friendly physics analysis. The purpose of these exercises is to allow you to write a complete though simple analysis algorithms for "typical" decay:
Changed:
<
<
.
>
>
.
 
Changed:
<
<
The exercises covers the following topics:

The exercises covers the following topics:

>
>
The exercises cover the following topics:
 
Line: 56 to 54
  In a similar way one can run the most trivial (empty, "Hello, World!") LoKi-algorithm: %SYNTAX{ syntax="sh" numbered="1000" numstep="1"}%
Changed:
<
<
> DaVinci.exe $LOKITUTORROOT/src/HelloWorld/HelloWorld.opts
>
>
> DaVinci.exe $LOKITUTORROOT/solutions/HelloWorld/HelloWorld.opts
 %ENDSYNTAX%

The most trivial (empty) "Hello,World!" LoKi algorithm

Changed:
<
<
The most trivial LoKi empty algorithm (=="Hello,World!") demonstrate in a very clear way
>
>
The most trivial LoKi empty algorithm ("Hello,World!") demonstrate in a very clear way
 the main principles of any LoKi-based algorithms:
  • It resides in a single *.cpp file, no header (*.h) is required
  • To get access to LoKi classes one needs to include the file LoKi/LoKi.h which imports around 90-95% of functionality, available in LoKi
  • The body of the algorithm is defined using LOKI_ALGORITHM or LOKI_MCALGORITHM macros
    • The macro LOKI_ALGORITHM should be used for Monte Carlo-independent studies
Added:
>
>

The algorithm

 The simplest algorithm looks like: %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%
Deleted:
<
<
// $Id:$ // ========================================================================
 // Include files // ======================================================================== #include "LoKi/LoKi.h" // from the package Phys/LoKi
Line: 83 to 80
  return StatusCode::SUCCESS ; // RETURN } %ENDSYNTAX%
Changed:
<
<
Please, do not forget to add some Doxygen comments. It is a good style for the codeing, even for your tutorial algorithms:
>
>
Please, do not forget to add some Doxygen comments. It is a good style even for your tutorial algorithm:
 %SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}% /** @file * it is a simple tutorial algorithm for ...
Line: 99 to 96
  */ %ENDSYNTAX%
Added:
>
>
Put your algorithm into src ditrectory of Tutorial/LoKiTutor package and build the package.

The configuration

Of course the configuration of this simple ("do-nothing") algorithm does not require a lot of efforts:

<!-- SyntaxHighlightingPlugin -->
 1000// (1) get some "basic/standard" job-configuration from DaVinci 
 1010#include "$DAVINCIROOT/options/DaVinciCommon.opts"
 1020// ============================================================================
 1030// (2) use LoKi service                  (MANDATORY!!!)
 1040ApplicationMgr.ExtSvc += { "LoKiSvc" } ;
 1050// ============================================================================
 1060// (3) execute *ONLY* our algorithm 
 1070ApplicationMgr.TopAlg  = { "HelloWorld/Hello"} ;
 1080// ============================================================================
 1090// (4) define input data
 1100#include "$LOKITUTORDATA"
 1110// ============================================================================
 1120// (5) run 20 events 
 1130ApplicationMgr.EvtMax = 20 ;
<!-- end SyntaxHighlightingPlugin -->

As the input data for this partcular excersize one can use any arbitrary inpiut data, e.g.

<!-- SyntaxHighlightingPlugin -->
 1000// use data sample, used for DaVinci tests:
 1010#include "$DAVINCIROOT/options/DaVinciTestData.opts"
<!-- end SyntaxHighlightingPlugin -->

Also one can follow the instructions from DaVinci tutorial and find some appropriate data using LHCb bookkeeping data base.

Put your configuration *.opts file into options directory of Tutorial/LoKiTutor package and run the excersize.

The solution

The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/HelloWorld/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.

Simple selection of particles

The second excersize demonstrates the simple selections of particles using LoKi functors. The basic working horse for the simple selections if the member function select. It allows to select/filter from all input particles only the particles, which satisfy the certain criteria. For more information see LoKi User Guide/TWiki.

<!-- SyntaxHighlightingPlugin -->
 1000// get all positive muons: 
 1010Range muplus = select ( "mymu+" , "mu+" == ID ) ;
 1020
 1030// get all negative muons:
 1040Range muminus = select ( "mumu-" , "mu-" == ID ) ;
 1050
 1060// get all (positive&negative) muons:
 1070Range muall  = select ("mymuons" , "mu+" == ABSID ) ;
 1080
 1090// get all FAST muons:
 1100Range mufast = select ( "fastmuons" , "mu+" == ABSID && P > 10 * Gaudi::Units::GeV  && 500 < PT / Gaudi::Units::MeV ) ;
 1110 
 1120// get positive muons from all fast muons (subset) 
 1130Range mu1 = select ( "fastmuons-" , mufast , Q > 0 ) ;
<!-- end SyntaxHighlightingPlugin -->

In this example ID, P, PT and Q are the simplest LoKi functors, which evaluate the particle id, momentum, transverse momentum and the charge correspondingly. Almost exaustive list of corrently available particle functors is available here.

The return value of function select represent a lighweigted (named) container which contains the selected particles and could be directly inspected:

%SYNTAX{ syntax="cpp" numbered="1000" numstep="10"}%

Range particles = ... ;

// print the size of the conatiner always() << " Number of selected particles: " << particles.size() << endreq ;

 
Added:
>
>
// make the explicit loop over the container: for ( Range::iterator ip = particles.begin() ; particles.end() = ip ; ++ip ) { const LHCb::Particle* p = *ip ; // fill the histogram: plot ( PT ( p ) / Gaudi::Units::GeV , "pt of selected particles [in GeV]" , 0 , 5 ) ; }

// fill the historgam through implicit loop: plot ( PT / Gaudi::Units::GeV , particles.begin() , particles.end() , " pt of selecte dparticles (implicit loop) " , 0 , 5 ) ; %ENDSYNTAX%

Lets write the simple algorithm which selects, counts an dfill some histos for the particles, which satisfy certain criteria. E.g. good, or fast or well identified muos or kaons.

Start new algorithm in src directory of Tutorial/LoKiTutor package:

<!-- SyntaxHighlightingPlugin -->
 1000#include "LoKi/LoKi.h"
 1010
 1020LOKI_ALGORITHM(SelectParticles) 
 1030{
 1040    // avoid very long names:
 1050    using namespace LoKi ;
 1060    using namespace LoKi::Types ;
 1070    using namespsce LoKi::Cuts  ;
 1080
 1090
 1100
 1110    return StatusCode::SUCCESS ;                             // RETURN 
 1120}
<!-- end SyntaxHighlightingPlugin -->

Put your selection lines after the line 01080. E.g. try to select fast&well-identified muons. Consult these pages for the list of functions. Probably following functions could be useful:

  1. P momentum of the particle
  2. ID numerical ID of the particle
  3. KEY the key of the particle
  4. PT transverse momentum
  5. PX , PY , PZ x-,y-&z-components of the particle mometum
  6. PIDK
  7. PIDmu

Useful quantity for separation of particles form decays of beautyparticles from the particles, originating in the primary vertices are the minimal of impact parameter, calculated over all reconstructed primary vertices. This quantity in LoKi is evaluated using the function MIPCHI2 :

<!-- SyntaxHighlightingPlugin -->
 1000// get all reocntructed primary vertices: 
 1010LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices(); 
 1020
 1030// create the function
 1040Fun fun = MIPCHI2 ( pvs , geo() ) ;
 1050
 1060// use it explicitely:
 1070const LHCb::Particle* p = ... ;
 1080const double minChi2 = fun ( p ) ;
 1090
 1100 // use it for selection:
 1110Range pionsNotFromPV = select ("pions" , "pi+" == ABSID && 9 < fun ( p )  ) ; 
<!-- end SyntaxHighlightingPlugin -->

Try to select, count particle and make the simple plots..

The configuration

Of course the configuration of this algorithm require a bit more typing, in particular one needs to specify the input locations for the algorithm:
<!-- SyntaxHighlightingPlugin -->
 1000// (1) get some "basic/standard" job-configuration from DaVinci 
 1010// ============================================================================
 1020#include "$DAVINCIROOT/options/DaVinciCommon.opts"
 1030#include "$COMMONPARTICLESROOT/options/StandardPions.opts"
 1040#include "$COMMONPARTICLESROOT/options/StandardKaons.opts"
 1050#include "$COMMONPARTICLESROOT/options/StandardMuons.opts"
 1060// ============================================================================
 1070// (2) load LoKi service 
 1080ApplicationMgr.ExtSvc += { "LoKiSvc" } ;
 1090// ============================================================================
 1100// (3) append algorithm to the default list: 
 1110ApplicationMgr.TopAlg += { "GetData"} ;
 1120// ============================================================================
 1130// (4) configure "our" algorithm:
 1140GetData.PhysDesktop.InputLocations = {
 1150  "Phys/StdLoosePions" ,  // use the "standard" pions
 1160  "Phys/StdTightKaons" ,  // use the "standard" kaons 
 1170  "Phys/StdLooseMuons" // use the "standard" muons 
 1180} ;
 1190// ============================================================================
 1200// (5) define input data
 1210#include "$LOKITUTORDATA"
 1220// ============================================================================
 1230// (6) run 200 events 
 1240ApplicationMgr.EvtMax = 200 ;
<!-- end SyntaxHighlightingPlugin -->
 
Added:
>
>

The solution

 
Added:
>
>
The full solution for this excersize ( *.cpp & *.opts files) is available in the directory solutions/GetData/ in the Tutorial/LoKiTutor package and could be inspected/copied in the case of the problems.
 

Revision 12007-09-26 - VanyaBelyaev

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="LHCbSoftwareTutorials"

LHCb LoKi Tutorial

This hands-on tutorial is an introduction to LoKi - C++ toolkit for easy and friendly physics analysis. The purpose of these exercises is to allow you to write a complete though simple analysis algorithms for "typical" decay: .

The exercises covers the following topics:

The exercises covers the following topics:

This tutorial has last been tested with DaVinci v19r5.

Prerequisites

It is assumed that you are more or less familiar with the basic tutorial, also some level of familiarity with the DaVinci tutorial is assumed. You are also invited to the lhcb-loki mailing list.

Setup the environment for DaVinci

For this particular tutorial we'll concentrate on the interactive jobs and let the batch system and GRID, Ganga and DIRAC tool some rest. Batch and GRID-aware actions for LoKi-bases analysis are identical to the actions needed for native DaVinci and thus are not covered by this tutorial. For more details on GRID&batch see DaVinci tutorial.

The package Tutorial/LoKiTutor is used as the placeholder for the tutorial excersizes. Please take care that you have installed and working version of DaVinci with local version of Tutorial/LoKiTutor package. E.g. fro the clean enavironment one can perform the following actions:

<!-- SyntaxHighlightingPlugin -->
 1000> setenvDaVinci v19r5
 1001> getpack Tutorial/LoKiTutor v6r0 
 1002> getpack Phys/DaVinci v19r5 
 1003> cd Phys/DaVinci/v19r5/cmt
 1004> cmt show uses | grep cmtuser  
<!-- end SyntaxHighlightingPlugin -->
If you have the valid DaVinci environment from your previous DaVinci tutorial, there is no nesessity to "getpack" the package Phys/DaVinci again:
<!-- SyntaxHighlightingPlugin -->
 1000> setenvDaVinci v19r5
 1001> getpack Tutorial/LoKiTutor v6r0 
 1002> cd Phys/DaVinci/v19r5/cmt
 1003> cmt show uses | grep cmtuser  
<!-- end SyntaxHighlightingPlugin -->
If everything is ok, CMT reports that the local version of Tutorial/LoKiTutor package is used. To build the tutorial one needs to use the standard procedure, described in much detail for the basic tutorial:
<!-- SyntaxHighlightingPlugin -->
 1000> cmt br make 
 1001> source ./setup.[c]sh
<!-- end SyntaxHighlightingPlugin -->

If the everything is done in a correct way one can now run simple DaVinci job:

<!-- SyntaxHighlightingPlugin -->
 1000> DaVinci.exe $DAVINCIROOT/options/DaVinci.opts
<!-- end SyntaxHighlightingPlugin -->

In a similar way one can run the most trivial (empty, "Hello, World!") LoKi-algorithm:

<!-- SyntaxHighlightingPlugin -->
 1000> DaVinci.exe $LOKITUTORROOT/src/HelloWorld/HelloWorld.opts
<!-- end SyntaxHighlightingPlugin -->

The most trivial (empty) "Hello,World!" LoKi algorithm

The most trivial LoKi empty algorithm (=="Hello,World!") demonstrate in a very clear way the main principles of any LoKi-based algorithms:
  • It resides in a single *.cpp file, no header (*.h) is required
  • To get access to LoKi classes one needs to include the file LoKi/LoKi.h which imports around 90-95% of functionality, available in LoKi
  • The body of the algorithm is defined using LOKI_ALGORITHM or LOKI_MCALGORITHM macros
    • The macro LOKI_ALGORITHM should be used for Monte Carlo-independent studies

The simplest algorithm looks like:

<!-- SyntaxHighlightingPlugin -->
 1000// $Id:$
 1010// ============================================================================
 1020// Include files 
 1030// ============================================================================
 1040#include "LoKi/LoKi.h"                       // from the package Phys/LoKi
 1050// ============================================================================
 1060LOKI_ALGORITHM(HelloWorld)       // algorithm C++ type as the parameter of macro
 1070{
 1080
 1090  always() << " Hello, World! " << endreq ;
 1100  
 1110  return StatusCode::SUCCESS ;                                     // RETURN 
 1120} 
<!-- end SyntaxHighlightingPlugin -->
Please, do not forget to add some Doxygen comments. It is a good style for the codeing, even for your tutorial algorithms:
<!-- SyntaxHighlightingPlugin -->
 1000/** @file
 1010  *  it is a simple tutorial algorithm for ...
 1020  *  @author  ...
 1030  *  @date ...
 1040  */
 1050// and/or: 
 1060/** @class AAA
 1070  *  it is a simple tutorial algorithm for ...
 1080  *  @author  ...
 1090  *  @date ...
 1100  */
<!-- end SyntaxHighlightingPlugin -->

-- Vanya Belyaev - 26 Sep 2007

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 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