Difference: GaudiPython (1 vs. 27)

Revision 272013-06-25 - JaapPanman

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

Gaudi Python FAQ

Line: 19 to 19
 

FAQs


Deleted:
<
<
 

How to get access and instantiate an LHCb Event class

Changed:
<
<
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. GaudiPythin.Bindings.gbl represents the C++ global namespace (::) You can abbreviate the namespace with assignments:
>
>
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. GaudiPythin.Bindings.gbl represents the C++ global namespace (::) You can abbreviate the namespace with assignments:
 
from GaudiPython.Bindings import gbl
std  = gbl.std
Line: 66 to 66
 

How to access to DoxyGen documentation for C++ class/instances?

Changed:
<
<
Starting from LHCb v22r9 it is very easy to get an easy access to the DoxyGen documentation pages for the certain classes, types, objects and instances:
<!-- SyntaxHighlightingPlugin -->
 1800&gt;<cite>&gt;&gt; import LoKiCore.doxygenurl as doxy </cite><br /> &gt;<cite>&gt;&gt; o = ... ## arbitrary object </cite><br /> &gt;<cite>&gt;&gt; doxy.browse ( o ) ## ask DoxyGen for the objects</cite><br /> &gt;<cite>&gt;&gt; doxy.browse ( "LHCb::MCVertex") ## ask doxyGen for the class by name</cite><br /> 
 1810
<!-- end SyntaxHighlightingPlugin -->
The idea from Thomas Ruf has been used.
>
>
Starting from LHCb v22r9 it is very easy to get an easy access to the DoxyGen documentation pages for the certain classes, types, objects and instances:
<!-- SyntaxHighlightingPlugin -->
 1800>>> import LoKiCore.doxygenurl as doxy 
 1810>>> o = ...    ## arbitrary object 
 1820>>> doxy.browse ( o )     ## ask DoxyGen for the objects
 1830>>> doxy.browse ( "LHCb::MCVertex")     ## ask doxyGen for the class by name
 1840
<!-- end SyntaxHighlightingPlugin -->
The idea from Thomas Ruf has been used.
 
Deleted:
<
<
 

How to run using a job options file several iterations

This is a minimalistic example on how to run a gaudi job (DaVinci in this case) for a number of events several times. In between the runs the user can access any information or change the algorithms or their properties.

Line: 88 to 93
 


Deleted:
<
<
 

How to access Linker tables

Changed:
<
<
The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.
>
>
The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.
  First, do not forget to add in the requirements file the line
Line: 99 to 103
 use LinkerInstances v* Event
Changed:
<
<
Then the usage is standard. For the sake of example, let's assume that the variable track contains a VELO Track you are interested in, from the 'Rec/Track/Velo' container. A simple manipulation is:
>
>
Then the usage is standard. For the sake of example, let's assume that the variable track contains a VELO Track you are interested in, from the 'Rec/Track/Velo' container. A simple manipulation is:
 
>>> from eventassoc import linkedTo
Line: 159 to 164
 
  • Direct manipulation with histogram service
  • Usage of functionality offered by HistoUtils module
  • Access to "the nice" histogramming through the base-class inheritance (OO-spirit)
Changed:
<
<
Direct manipulation with the histogram service allows to book and fill hisrogram from the simple (Gaudi)Python scripts in a relatively intuitive way:
>
>
Direct manipulation with the histogram service allows to book and fill hisrogram from the simple (Gaudi)Python scripts in a relatively intuitive way:
  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Line: 228 to 221
 fill ( histo , tracks , lambda t : t.pt() )

# use the sequnce, applythe function, but filter out even values:

Deleted:
<
<
 fill ( histo , [1,2,3,4,5,6,7] , lambda x : x*x , lambda y : 0==y%2 )
Deleted:
<
<
# use the sequence and apply the function:
 
Added:
>
>
# use the sequence and apply the function:
 # for each track in sequence evaluate "p()" and fill the histogram with track momentum,
Deleted:
<
<
 # keepingonly track with small transverse momentum:
Deleted:
<
<
 tracks = ...
Added:
>
>
fill ( histo , tracks , lambda t : t.p() , lambda t : t.pt() < 1000 )
 
Deleted:
<
<
fill ( histo , tracks , lambda t : t.p() , lambda t : t.pt() < 1000 )
  %ENDSYNTAX%
Line: 256 to 245
 aida = HistoUtils.getAsAIDA ( path )

# get as native ROOT:

Deleted:
<
<
 root = HistoUtils.getAsROOT( path )
Changed:
<
<
%ENDSYNTAX% HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
>
>
%ENDSYNTAX% HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
 
Changed:
<
<
OO-spirit is described in detail here and it allows to reuse the whole functionality of easy-and-friendly histograms, including booking-on-demand. Also it is a recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.
>
>
OO-spirit is described in detail here and it allows to reuse the whole functionality of easy-and-friendly histograms, including booking-on-demand. Also it is a recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.
 

How to deal with Gaudi N-tuples in GaudiPython ?

Changed:
<
<
The direct manipulation (booking&filling of columns) with the native Gaudi N-tuples in Python seems to be a very difficult task. Up to now no good and easy disprove of this statement are known. Therefore one needs to find an alternative way. Three relatively easy options have been demonstrated
  1. A direct manipulation with ROOT (T)-trees&N-tuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
  3. Access to "the nice" N-tuples through the base-class inheritance (OO-spirit)
Please consult ROOT manual for the first way, here we describe only the second way. The third way (OO-spirit) is described in detail here and it allows to reuse the whole functionality of easy-and-friendly N-tuples, including booking-on-demand. It is nice, simple, safe and it represents the recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.
>
>
The direct manipulation (booking&filling of columns) with the native Gaudi N-tuples in Python seems to be a very difficult task. Up to now no good and easy disprove of this statement are known. Therefore one needs to find an alternative way. Three relatively easy options have been demonstrated
  1. A direct manipulation with ROOT (T)-trees&N-tuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
  3. Access to "the nice" N-tuples through the base-class inheritance (OO-spirit)

Please consult ROOT manual for the first way, here we describe only the second way. The third way (OO-spirit) is described in detail here and it allows to reuse the whole functionality of easy-and-friendly N-tuples, including booking-on-demand. It is nice, simple, safe and it represents the recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.

  The module GaudiPython.TupleUtils (appears in Gaudi v19r5) contains essentially one important function nTuple :
Line: 339 to 319
 

How to access Relation tables in (Gaudi)Python?

There are many Relation tables flying around in Gaudi/LHCb software. They are used in many areas:

Changed:
<
<
  1. As representationof Monte Carlo truth links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. -matching of Calorimeter clusters with recontructed tracks
  3. As the main representation of Monte Carlo links for (Proto)Particles for LoKi
The relation tables provides easy, intuitive and efficient way for relation between any objects in Gaudi. The python interface looks very similar to C++ interface. E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted for selection of Monte Carlo "merged" neutral pions.
>
>
  1. As representationof Monte Carlo truth links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. -matching of Calorimeter clusters with recontructed tracks
  3. As the main representation of Monte Carlo links for (Proto)Particles for LoKi

The relation tables provides easy, intuitive and efficient way for relation between any objects in Gaudi. The python interface looks very similar to C++ interface. E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted<LHCb::CaloCluster,LHCb::MCParticle,float> for selection of Monte Carlo "merged" neutral pions.

  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Deleted:
<
<
 #!/usr/bin/env python2.4
Changed:
<
<
# ========================================================================= ## import everything from bender
>
>
# ========================================================================= ## import everything from bender
 from MainMC import *
Changed:
<
<
# ========================================================================= ## Simple examples of manipulations with relation tables
>
>
# ========================================================================= ## Simple examples of manipulations with relation tables
 # @author Vanya BELYAEV ibelyaev@physicsNOSPAMPLEASE.syr.edu
Deleted:
<
<
 # @date 2007-09-26
Deleted:
<
<
 class MergedPi0(AlgoMC) :
Deleted:
<
<
 """ simple class to plot dikaon mass peak """

## standard constructor

Line: 371 to 346
 return AlgoMC.__init__ ( self , name )

## standard mehtod for analyses

Deleted:
<
<
 def analyse( self ) :
Deleted:
<
<
 """ Standard method for Analysis """
Changed:
<
<
finder = self.mcFinder(" pi0->2gamma MC-finder")
>
>
finder = self.mcFinder(" pi0->2gamma MC-finder")
 
Changed:
<
<
mcpi0 = finder.find ( "pi0 -> gamma gamma" ) ;
>
>
mcpi0 = finder.find ( "pi0 -> gamma gamma" ) ;
  if mcpi0.empty() : return self.Warning("No MC-pi0 is found (1)", SUCCESS )
Line: 383 to 356
 if mcpi0.empty() : return self.Warning("No MC-pi0 is found (1)", SUCCESS )

#get only pi0s, which satisfy the criteria:

Deleted:
<
<
 #1) large Pt
Changed:
<
<
mc1 = MCPT > 500 # * MeV
>
>
mc1 = MCPT > 500 # * MeV
 # 2) valid origin vertex
Deleted:
<
<
 mc2 = MCOVALID
Changed:
<
<
# 3) vertex near the primary vertex

mc3 = abs ( MCVFASPF( MCVZ ) ) < 500 # * Gaudi.Units.mm

>
>
# 2) vertex near the primary vertex mc3 = abs ( MCVFASPF( MCVZ ) ) < 500 # * Gaudi.Units.mm
  mccut = mc1 & mc2 & mc3
Line: 413 to 377
 itable = iTable( table , 1 )

# consruct "Ecal-acceptance" cuts

Changed:
<
<
outer = ( abs(MCPY/MCPZ) < 3.00/12.5 ) & ( abs(MCPX/MCPZ) < 4.00/12.5 )

inner = ( abs(MCPY/MCPZ) > 0.32/12.5 ) | ( abs(MCPX/MCPZ) > 0.32/12.5 )

>
>
outer = ( abs(MCPY/MCPZ) < 3.00/12.5 ) & ( abs(MCPX/MCPZ) < 4.00/12.5 ) inner = ( abs(MCPY/MCPZ) > 0.32/12.5 ) | ( abs(MCPX/MCPZ) > 0.32/12.5 )
 accept = outer &inner

# loop over mcpi0:

Line: 441 to 395
 if not accept ( gamma2 ) : continue

pt = MCPT ( pi0 ) / 1000

Deleted:
<
<
 mnpt = min( MCPT ( gamma1 ) , MCPT ( gamma2 ) ) / 1000
Changed:
<
<
self.plot ( pt , "ALL pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , "ALL pi0->gamma gamma : min pt of photon " , 0 , 5 )

>
>
self.plot ( pt , "ALL pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , "ALL pi0->gamma gamma : min pt of photon " , 0 , 5 )
  clus1 = itable.relations ( gamma1 )
Deleted:
<
<
 clus2 = itable.relations ( gamma1 )

# each photon have some associated cluster(s) in ECAL

Line: 453 to 404
 clus2 = itable.relations ( gamma1 )

# each photon have some associated cluster(s) in ECAL

Deleted:
<
<
 if clus1.empty() or clus2.empty() : continue
Changed:
<
<
self.plot ( pt , "ECAL pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , "ECAL pi0->gamma gamma : min pt of photon " , 0 , 5 )

>
>
self.plot ( pt , "ECAL pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , "ECAL pi0->gamma gamma : min pt of photon " , 0 , 5 )
  # select only 1 or 2-cluster pi0s
Deleted:
<
<
 clus0 = itable.relations ( pi0 )
Deleted:
<
<
 if 1 = clus0.size() and 2 = clus0.size() : continue
Changed:
<
<
self.plot ( pt , " 1||2 pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , " 1||2 pi0->gamma gamma : min pt of photon " , 0 , 5 )

>
>
self.plot ( pt , " 1||2 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 1||2 pi0->gamma gamma : min pt of photon " , 0 , 5 )
  # select only true "2-cluster" pi0
Changed:
<
<
if 2 = clus0.size() and 1 clus1.size() and 1 = clus2.size() and clus1.front().to() = clus2.front().to() :

self.plot ( pt , " 2 pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , " 2 pi0->gamma gamma : min pt of photon " , 0 , 5 )

>
>
if 2 = clus0.size() and 1 = clus1.size() and 1 = clus2.size() and clus1.front().to() clus2.front().to() : self.plot ( pt , " 2 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 2 pi0->gamma gamma : min pt of photon " , 0 , 5 )
  # select only true "1-cluster" pi0
Added:
>
>
if 1 = clus0.size() and 1 = clus1.size() and 1 = clus2.size() and clus1.front().to() = clus2.front().to() : self.plot ( pt , " 1 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 1 pi0->gamma gamma : min pt of photon " , 0 , 5 )
 
Changed:
<
<
if 1 = clus0.size() and 1 clus1.size() and 1 clus2.size() and clus1.front().to() = clus2.front().to() :

self.plot ( pt , " 1 pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , " 1 pi0->gamma gamma : min pt of photon " , 0 , 5 )

return SUCCESS # =========================================================================

>
>
return SUCCESS # =========================================================================
 %ENDSYNTAX%

The example illustrate:

  • retrival the relation table from Transient Event Store (the line 01410)
Changed:
<
<
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted , see the lines 01440-01450)
>
>
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted<LHCb::MCParticle,LHCb::CaloCluster,float> , see the lines 01440-01450)
 
  • selection of , which:
Changed:
<
<
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
>
>
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
 
    • have an origin vertex within +-50 centimeters in z-direction around the primary vertex (the line 01320)
    • each of the photon is in the geometrical acceptance of Ecal (the lines 01620-01630)
  • Retrieve from the relation table the number of associated Ecal clusters for and each of the daughter photons (the lines 01710-01720&01810)
Line: 520 to 454
  %ENDSYNTAX%
Deleted:
<
<
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
 
Deleted:
<
<

How to access LHCb::Track -> MC truth Relation tables in (Gaudi)Python?

 
Changed:
<
<
To access Relation tables for LHCb::Track-> MC Truth in python one needs to activate "on-demand" conversion of Linker objects into Relation tables. it can be done just in one line:
>
>
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
 
Deleted:
<
<
%SYNTAX{ syntax="python" numbered="1800" numstep="10"}%
 
Changed:
<
<
# activate automatic "on-demand" converison of LHcbTrack->MC Linker objects into Relation Tables
>
>

How to access LHCb::Track -> MC truth Relation tables in (Gaudi)Python?

 
Added:
>
>
To access Relation tables for LHCb::Track-> MC Truth in python one needs to activate "on-demand" conversion of Linker objects into Relation tables. it can be done just in one line:

%SYNTAX{ syntax="python" numbered="1800" numstep="10"}%

# activate automatic "on-demand" converison of LHcbTrack->MC Linker objects into Relation Tables

 import Track2MC _Configuration

# OPTIONALLY: decorate the relation tables,e.g. for easy iteration

Line: 542 to 478
  %ENDSYNTAX%
Changed:
<
<
As soon as it is done, the rest is trivial. e.g. exploiting "direct" relations ( LHCb::Track -> MC) :
>
>
As soon as it is done, the rest is trivial. e.g. exploiting "direct" relations ( LHCb::Track -> MC) :
  %SYNTAX{ syntax="python" numbered="1800" numstep="10"}%
Line: 553 to 487
 print ' #number of tracks: ', tracks.size()

# get the relation table from the Transient Event Store

Changed:
<
<
table = evt['Relations/Rec/Trac/Default']
>
>
table = evt['Relations/Rec/Track/Default']
 print ' Relation table, # of links', table.relations().size()

# loop over the tracks

Line: 584 to 510
  %ENDSYNTAX%
Changed:
<
<
The inverse relations ( MC -> LHCb::Track) are also trivial:
>
>
The inverse relations ( MC -> LHCb::Track) are also trivial:
  %SYNTAX{ syntax="python" numbered="1800" numstep="10"}%

Revision 262013-06-24 - JessicaElevant

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

Gaudi Python FAQ

Line: 19 to 19
 

FAQs


Added:
>
>
 

How to get access and instantiate an LHCb Event class

Changed:
<
<
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. GaudiPythin.Bindings.gbl represents the C++ global namespace (::) You can abbreviate the namespace with assignments:
>
>
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. GaudiPythin.Bindings.gbl represents the C++ global namespace (::) You can abbreviate the namespace with assignments:
 
from GaudiPython.Bindings import gbl
std  = gbl.std
Line: 66 to 66
 

How to access to DoxyGen documentation for C++ class/instances?

Changed:
<
<
Starting from LHCb v22r9 it is very easy to get an easy access to the DoxyGen documentation pages for the certain classes, types, objects and instances:
<!-- SyntaxHighlightingPlugin -->
 1800>>> import LoKiCore.doxygenurl as doxy 
 1810>>> o = ...    ## arbitrary object 
 1820>>> doxy.browse ( o )     ## ask DoxyGen for the objects
 1830>>> doxy.browse ( "LHCb::MCVertex")     ## ask doxyGen for the class by name
 1840
<!-- end SyntaxHighlightingPlugin -->
The idea from Thomas Ruf has been used.
>
>
Starting from LHCb v22r9 it is very easy to get an easy access to the DoxyGen documentation pages for the certain classes, types, objects and instances:
<!-- SyntaxHighlightingPlugin -->
 1800&gt;<cite>&gt;&gt; import LoKiCore.doxygenurl as doxy </cite><br /> &gt;<cite>&gt;&gt; o = ... ## arbitrary object </cite><br /> &gt;<cite>&gt;&gt; doxy.browse ( o ) ## ask DoxyGen for the objects</cite><br /> &gt;<cite>&gt;&gt; doxy.browse ( "LHCb::MCVertex") ## ask doxyGen for the class by name</cite><br /> 
 1810
<!-- end SyntaxHighlightingPlugin -->
The idea from Thomas Ruf has been used.
 
Added:
>
>
 

How to run using a job options file several iterations

This is a minimalistic example on how to run a gaudi job (DaVinci in this case) for a number of events several times. In between the runs the user can access any information or change the algorithms or their properties.

Line: 93 to 88
 


Added:
>
>
 

How to access Linker tables

Changed:
<
<
The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.
>
>
The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.
  First, do not forget to add in the requirements file the line
Line: 103 to 99
 use LinkerInstances v* Event
Changed:
<
<
Then the usage is standard. For the sake of example, let's assume that the variable track contains a VELO Track you are interested in, from the 'Rec/Track/Velo' container. A simple manipulation is:
>
>
Then the usage is standard. For the sake of example, let's assume that the variable track contains a VELO Track you are interested in, from the 'Rec/Track/Velo' container. A simple manipulation is:
 
>>> from eventassoc import linkedTo
Line: 164 to 159
 
  • Direct manipulation with histogram service
  • Usage of functionality offered by HistoUtils module
  • Access to "the nice" histogramming through the base-class inheritance (OO-spirit)
Changed:
<
<
Direct manipulation with the histogram service allows to book and fill hisrogram from the simple (Gaudi)Python scripts in a relatively intuitive way:
>
>
Direct manipulation with the histogram service allows to book and fill hisrogram from the simple (Gaudi)Python scripts in a relatively intuitive way:
  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Line: 221 to 228
 fill ( histo , tracks , lambda t : t.pt() )

# use the sequnce, applythe function, but filter out even values:

Deleted:
<
<
fill ( histo , [1,2,3,4,5,6,7] , lambda x : x*x , lambda y : 0==y%2 )
 
Added:
>
>
fill ( histo , [1,2,3,4,5,6,7] , lambda x : x*x , lambda y : 0==y%2 )
  # use the sequence and apply the function:
Added:
>
>
 # for each track in sequence evaluate "p()" and fill the histogram with track momentum,
Added:
>
>
 # keepingonly track with small transverse momentum:
Added:
>
>
 tracks = ...
Deleted:
<
<
fill ( histo , tracks , lambda t : t.p() , lambda t : t.pt() < 1000 )
 
Added:
>
>
fill ( histo , tracks , lambda t : t.p() , lambda t : t.pt() < 1000 )
  %ENDSYNTAX%

Line: 245 to 256
 aida = HistoUtils.getAsAIDA ( path )

# get as native ROOT:

Deleted:
<
<
root = HistoUtils.getAsROOT( path )
 
Changed:
<
<
%ENDSYNTAX% HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
>
>
root = HistoUtils.getAsROOT( path )
 
Added:
>
>
%ENDSYNTAX% HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
 
Changed:
<
<
OO-spirit is described in detail here and it allows to reuse the whole functionality of easy-and-friendly histograms, including booking-on-demand. Also it is a recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.
>
>
OO-spirit is described in detail here and it allows to reuse the whole functionality of easy-and-friendly histograms, including booking-on-demand. Also it is a recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.
 

How to deal with Gaudi N-tuples in GaudiPython ?

Changed:
<
<
The direct manipulation (booking&filling of columns) with the native Gaudi N-tuples in Python seems to be a very difficult task. Up to now no good and easy disprove of this statement are known. Therefore one needs to find an alternative way. Three relatively easy options have been demonstrated
  1. A direct manipulation with ROOT (T)-trees&N-tuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
  3. Access to "the nice" N-tuples through the base-class inheritance (OO-spirit)

Please consult ROOT manual for the first way, here we describe only the second way. The third way (OO-spirit) is described in detail here and it allows to reuse the whole functionality of easy-and-friendly N-tuples, including booking-on-demand. It is nice, simple, safe and it represents the recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.

>
>
The direct manipulation (booking&filling of columns) with the native Gaudi N-tuples in Python seems to be a very difficult task. Up to now no good and easy disprove of this statement are known. Therefore one needs to find an alternative way. Three relatively easy options have been demonstrated
  1. A direct manipulation with ROOT (T)-trees&N-tuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
  3. Access to "the nice" N-tuples through the base-class inheritance (OO-spirit)
Please consult ROOT manual for the first way, here we describe only the second way. The third way (OO-spirit) is described in detail here and it allows to reuse the whole functionality of easy-and-friendly N-tuples, including booking-on-demand. It is nice, simple, safe and it represents the recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.
  The module GaudiPython.TupleUtils (appears in Gaudi v19r5) contains essentially one important function nTuple :
Line: 319 to 339
 

How to access Relation tables in (Gaudi)Python?

There are many Relation tables flying around in Gaudi/LHCb software. They are used in many areas:

Changed:
<
<
  1. As representationof Monte Carlo truth links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. -matching of Calorimeter clusters with recontructed tracks
  3. As the main representation of Monte Carlo links for (Proto)Particles for LoKi

The relation tables provides easy, intuitive and efficient way for relation between any objects in Gaudi. The python interface looks very similar to C++ interface. E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted<LHCb::CaloCluster,LHCb::MCParticle,float> for selection of Monte Carlo "merged" neutral pions.

>
>
  1. As representationof Monte Carlo truth links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. -matching of Calorimeter clusters with recontructed tracks
  3. As the main representation of Monte Carlo links for (Proto)Particles for LoKi
The relation tables provides easy, intuitive and efficient way for relation between any objects in Gaudi. The python interface looks very similar to C++ interface. E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted for selection of Monte Carlo "merged" neutral pions.
  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Added:
>
>
 #!/usr/bin/env python2.4
Changed:
<
<
# ========================================================================= ## import everything from bender
>
>
# ========================================================================= ## import everything from bender
 from MainMC import *
Changed:
<
<
# ========================================================================= ## Simple examples of manipulations with relation tables
>
>
# ========================================================================= ## Simple examples of manipulations with relation tables
 # @author Vanya BELYAEV ibelyaev@physicsNOSPAMPLEASE.syr.edu
Added:
>
>
 # @date 2007-09-26
Added:
>
>
 class MergedPi0(AlgoMC) :
Added:
>
>
  """ simple class to plot dikaon mass peak """

## standard constructor

Line: 346 to 371
  return AlgoMC.__init__ ( self , name )

## standard mehtod for analyses

Added:
>
>
  def analyse( self ) :
Added:
>
>
  """ Standard method for Analysis """
Changed:
<
<
finder = self.mcFinder(" pi0->2gamma MC-finder")
>
>
finder = self.mcFinder(" pi0->2gamma MC-finder")
 
Changed:
<
<
mcpi0 = finder.find ( "pi0 -> gamma gamma" ) ;
>
>
mcpi0 = finder.find ( "pi0 -> gamma gamma" ) ;
  if mcpi0.empty() : return self.Warning("No MC-pi0 is found (1)", SUCCESS )

Line: 356 to 383
  if mcpi0.empty() : return self.Warning("No MC-pi0 is found (1)", SUCCESS )

#get only pi0s, which satisfy the criteria:

Added:
>
>
  #1) large Pt
Changed:
<
<
mc1 = MCPT > 500 # * MeV
>
>
mc1 = MCPT > 500 # * MeV
  # 2) valid origin vertex
Added:
>
>
  mc2 = MCOVALID
Changed:
<
<
# 2) vertex near the primary vertex mc3 = abs ( MCVFASPF( MCVZ ) ) < 500 # * Gaudi.Units.mm
>
>
# 3) vertex near the primary vertex

mc3 = abs ( MCVFASPF( MCVZ ) ) < 500 # * Gaudi.Units.mm

  mccut = mc1 & mc2 & mc3

Line: 377 to 413
  itable = iTable( table , 1 )

# consruct "Ecal-acceptance" cuts

Changed:
<
<
outer = ( abs(MCPY/MCPZ) < 3.00/12.5 ) & ( abs(MCPX/MCPZ) < 4.00/12.5 ) inner = ( abs(MCPY/MCPZ) > 0.32/12.5 ) | ( abs(MCPX/MCPZ) > 0.32/12.5 )
>
>
outer = ( abs(MCPY/MCPZ) < 3.00/12.5 ) & ( abs(MCPX/MCPZ) < 4.00/12.5 )

inner = ( abs(MCPY/MCPZ) > 0.32/12.5 ) | ( abs(MCPX/MCPZ) > 0.32/12.5 )

  accept = outer &inner

# loop over mcpi0:

Line: 395 to 441
  if not accept ( gamma2 ) : continue

pt = MCPT ( pi0 ) / 1000

Added:
>
>
  mnpt = min( MCPT ( gamma1 ) , MCPT ( gamma2 ) ) / 1000

Changed:
<
<
self.plot ( pt , "ALL pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , "ALL pi0->gamma gamma : min pt of photon " , 0 , 5 )
>
>
self.plot ( pt , "ALL pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , "ALL pi0->gamma gamma : min pt of photon " , 0 , 5 )

  clus1 = itable.relations ( gamma1 )
Added:
>
>
  clus2 = itable.relations ( gamma1 )

# each photon have some associated cluster(s) in ECAL

Line: 404 to 453
  clus2 = itable.relations ( gamma1 )

# each photon have some associated cluster(s) in ECAL

Added:
>
>
  if clus1.empty() or clus2.empty() : continue

Changed:
<
<
self.plot ( pt , "ECAL pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , "ECAL pi0->gamma gamma : min pt of photon " , 0 , 5 )
>
>
self.plot ( pt , "ECAL pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , "ECAL pi0->gamma gamma : min pt of photon " , 0 , 5 )

  # select only 1 or 2-cluster pi0s
Added:
>
>
  clus0 = itable.relations ( pi0 )
Added:
>
>
  if 1 = clus0.size() and 2 = clus0.size() : continue
Changed:
<
<
self.plot ( pt , " 1||2 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 1||2 pi0->gamma gamma : min pt of photon " , 0 , 5 )
>
>
self.plot ( pt , " 1||2 pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , " 1||2 pi0->gamma gamma : min pt of photon " , 0 , 5 )

  # select only true "2-cluster" pi0
Changed:
<
<
if 2 = clus0.size() and 1 = clus1.size() and 1 = clus2.size() and clus1.front().to() clus2.front().to() : self.plot ( pt , " 2 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 2 pi0->gamma gamma : min pt of photon " , 0 , 5 )
>
>
if 2 = clus0.size() and 1 clus1.size() and 1 = clus2.size() and clus1.front().to() = clus2.front().to() :

self.plot ( pt , " 2 pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , " 2 pi0->gamma gamma : min pt of photon " , 0 , 5 )

  # select only true "1-cluster" pi0
Deleted:
<
<
if 1 = clus0.size() and 1 = clus1.size() and 1 = clus2.size() and clus1.front().to() = clus2.front().to() : self.plot ( pt , " 1 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 1 pi0->gamma gamma : min pt of photon " , 0 , 5 )
 
Changed:
<
<
return SUCCESS # =========================================================================
>
>
if 1 = clus0.size() and 1 clus1.size() and 1 clus2.size() and clus1.front().to() = clus2.front().to() :

self.plot ( pt , " 1 pi0->gamma gamma " , 0 , 5 )

self.plot ( mnpt , " 1 pi0->gamma gamma : min pt of photon " , 0 , 5 )

return SUCCESS # =========================================================================

 %ENDSYNTAX%

The example illustrate:

  • retrival the relation table from Transient Event Store (the line 01410)
Changed:
<
<
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted<LHCb::MCParticle,LHCb::CaloCluster,float> , see the lines 01440-01450)
>
>
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted , see the lines 01440-01450)
 
  • selection of , which:
Changed:
<
<
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
>
>
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
 
    • have an origin vertex within +-50 centimeters in z-direction around the primary vertex (the line 01320)
    • each of the photon is in the geometrical acceptance of Ecal (the lines 01620-01630)
  • Retrieve from the relation table the number of associated Ecal clusters for and each of the daughter photons (the lines 01710-01720&01810)
Line: 454 to 520
  %ENDSYNTAX%
Added:
>
>
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
 
Added:
>
>

How to access LHCb::Track -> MC truth Relation tables in (Gaudi)Python?

 
Changed:
<
<
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp

How to access LHCb::Track -> MC truth Relation tables in (Gaudi)Python?

To access Relation tables for LHCb::Track-> MC Truth in python one needs to activate "on-demand" conversion of Linker objects into Relation tables. it can be done just in one line:

>
>
To access Relation tables for LHCb::Track-> MC Truth in python one needs to activate "on-demand" conversion of Linker objects into Relation tables. it can be done just in one line:
  %SYNTAX{ syntax="python" numbered="1800" numstep="10"}%

Changed:
<
<
# activate automatic "on-demand" converison of LHcbTrack->MC Linker objects into Relation Tables import LoKiPhysMC.track2MC_Configuration
>
>
# activate automatic "on-demand" converison of LHcbTrack->MC Linker objects into Relation Tables

import Track2MC _Configuration

  # OPTIONALLY: decorate the relation tables,e.g. for easy iteration
Added:
>
>
 import Relations.Rels

# OPTIONALLY: decorate MC-particles for "nice" methods

Line: 478 to 542
  %ENDSYNTAX%
Changed:
<
<
As soon as it is done, the rest is trivial. e.g. exploiting "direct" relations ( LHCb::Track -> MC) :
>
>
As soon as it is done, the rest is trivial. e.g. exploiting "direct" relations ( LHCb::Track -> MC) :
  %SYNTAX{ syntax="python" numbered="1800" numstep="10"}%

Line: 510 to 584
  %ENDSYNTAX%
Changed:
<
<
The inverse relations ( MC -> LHCb::Track) are also trivial:
>
>
The inverse relations ( MC -> LHCb::Track) are also trivial:
  %SYNTAX{ syntax="python" numbered="1800" numstep="10"}%

Revision 252011-12-10 - SuvayuAli

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

Gaudi Python FAQ

Line: 64 to 64
  From DaVinci v23r0 onwards, new MC association is available. This is implemented in terms of simple tool interfaces that lend themselves very well to interactive use in Python. GaudiPython examples are here.
Changed:
<
<

How to access to DoxyGen documentation for C++ class/instances?

>
>

How to access to DoxyGen documentation for C++ class/instances?

  Starting from LHCb v22r9 it is very easy to get an easy access to the
Changed:
<
<
DoxyGen documentation pages for the certain classes, types, objects and instances:
>
>
DoxyGen documentation pages for the certain classes, types, objects and instances:
 %SYNTAX{ syntax="python" numbered="1800" numstep="10"}% >>> import LoKiCore.doxygenurl as doxy
>>> o = ... ## arbitrary object

Revision 242011-11-30 - PaalMariusBjoernstad

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

Gaudi Python FAQ

Line: 14 to 14
 Have a look at the following tutorials:
Changed:
<
<
>
>
 

FAQs

Revision 232010-05-06 - VanyaBelyaev

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

Gaudi Python FAQ

Line: 545 to 545
  The corresponding example in Bender is attached here
Changed:
<
<
-- Vanya Belyaev - 30-Apr-2010
>
>
Note that very similar examle in C++ is provided here.

-- Vanya Belyaev - 06-May-2k+10

-- Vanya Belyaev - 30-Apr-2k+10

  -- StefanRoiser - 13 Apr 2006
Changed:
<
<
-- Vanya Belyaev - 25 Sep 2007
>
>
-- Vanya Belyaev - 25 Sep 2k+7
  -- JuanPalacios - 27 Jun 2009

Revision 222010-04-30 - VanyaBelyaev

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

Gaudi Python FAQ

Line: 457 to 459
 It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
Added:
>
>

How to access LHCb::Track -> MC truth Relation tables in (Gaudi)Python?

To access Relation tables for LHCb::Track-> MC Truth in python one needs to activate "on-demand" conversion of Linker objects into Relation tables. it can be done just in one line:

<!-- SyntaxHighlightingPlugin -->
 1800# activate  automatic "on-demand" converison of  LHcbTrack->MC Linker objects into Relation Tables  
 1810import LoKiPhysMC.track2MC_Configuration
 1820
 1830# OPTIONALLY: decorate the relation tables,e.g. for easy iteration 
 1840import Relations.Rels
 1850 
 1860# OPTIONALLY: decorate MC-particles for "nice" methods
 1870import LoKiMC.MC 
<!-- end SyntaxHighlightingPlugin -->

As soon as it is done, the rest is trivial. e.g. exploiting "direct" relations ( LHCb::Track -> MC) :

<!-- SyntaxHighlightingPlugin -->
 1800# get the tracks for Transient Event Store 
 1810tracks = evt['Rec/Track/Best']
 1820print ' #number of tracks: ', tracks.size() 
 1830
 1840# get the relation table from the Transient Event Store
 1850table = evt['Relations/Rec/Trac/Default']
 1860print ' Relation table, # of links', table.relations().size()
 1870
 1880# loop over the tracks
 1890for track in tracks : 
 1900  
 1910  # for each track get related MC-particles:
 1920  mcps = table.relations ( track ) 
 1930
 1940   # check the number of related particles:
 1950   if mcps.empty() : continue 
 1960   print ' # of related MC-Particles ', mcps.size()
 1970
 1980   # get the first related particle:
 1990   mcp = mcps[0]._to() 
 2000
 2010   # get the associetd weight 
 2020   weight = mcps[0].weight()
 2030
 2040   print ' the first associated particle ', mcp.pname() , weight 
<!-- end SyntaxHighlightingPlugin -->

The inverse relations ( MC -> LHCb::Track) are also trivial:

<!-- SyntaxHighlightingPlugin -->
 1800# get MC-particles for TES 
 1810mcparticles  = evt['MC/Particles']
 1820print ' #number of tracks: ', tracks.size() 
 1830
 1840# get the relation table from the Transient Event Store
 1850table = evt['Relations/Rec/Trac/Default']
 1860print ' Relation table, # of links', table.relations().size()
 1870
 1880# get 'inverse'-view for the relation table:
 1890itable = table.inverse() 
 1900
 1910# loop over mc-particles 
 1920for mcp in mcparticles :
 1930
 1940     trks = itable.relations ( mcp ) 
 1950   
 1960     print ' # of related tracks: ', trks.size() 
 1970
 1980     if trks.empty() : continue
 1990
 2000     # get the first related track:
 2010
 2020     track = trks[0].to() 
 2030     weight = trks[0].weight() 
 2040
 2050     print ' the first associated track ', track.key() , weight 
<!-- end SyntaxHighlightingPlugin -->

The corresponding example in Bender is attached here

-- Vanya Belyaev - 30-Apr-2010

 -- StefanRoiser - 13 Apr 2006

-- Vanya Belyaev - 25 Sep 2007

Line: 463 to 553
  -- JuanPalacios - 27 Jun 2009
Added:
>
>
 
META FILEATTACHMENT attachment="GaudiPython_20071017.pdf" attr="h" comment="" date="1192624741" name="GaudiPython_20071017.pdf" path="GaudiPython_20071017.pdf" size="1976032" stream="GaudiPython_20071017.pdf" user="Main.PereMato" version="1"
Added:
>
>
META FILEATTACHMENT attachment="Track2MC.py.txt" attr="" comment="" date="1272626145" name="Track2MC.py.txt" path="Track2MC.py" size="8113" stream="Track2MC.py" tmpFilename="/usr/tmp/CGItemp3708" user="ibelyaev" version="1"

Revision 212010-01-05 - unknown

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

Gaudi Python FAQ

Line: 273 to 273
 be converted into C++ lines using almost "1->1" correspondence.
Changed:
<
<
The module TupleUtils (appears in Gaudi v19r5) contains essentially one important function nTuple :
>
>
The module GaudiPython.TupleUtils (appears in Gaudi v19r5) contains essentially one important function nTuple :
  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Changed:
<
<
from TupleUtils import nTuple
>
>
import GaudiPython import TupleUtils as TupleUtils nTuple = TupleUtils.nTuple

gaudi = AppMgr() gaudi.HistogramPersistency = 'ROOT' ntSvc = GaudiPython.iService ( 'NTupleSvc' ) ntSvc.Output = [ "MYLUN1 DATAFILE='TupleEx4_1.root' OPT='NEW'"] gaudi.config() gaudi.initialize()

 # get N-tuple (book-on-demand) t = nTuple ( 'the/path/to/the/directory' , ## path 'MyNtupleID' , ## the literal ID of the tuple
Line: 286 to 293
  LUN = 'MYLUN1' ) ## logical unit

# fill it with data e.g. trivial scalar columns:

Added:
>
>
import math
 for i in range ( 1 , 1000 ) : t.column ( 'i' , i ) ## integer scalar t.column ( 'a' , math.sin(i) ) ## float scalar

Revision 202009-09-07 - unknown

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

Gaudi Python FAQ

Line: 40 to 40
 We get access to the global namespace and create shortcuts as explained above. Then we can instantiate some STL types
Added:
>
>
from GaudiPython.Bindings import gbl std = gbl.std
 myvector = std.vector('double')()
Changed:
<
<
particleVector = gbl.std.vector('const LHCb::Particle *')(50, 0)
>
>
particleVector = std.vector('const LHCb::Particle *')(50, 0)

 
Deleted:
<
<
from ROOT import Math
 
Changed:
<
<
vXYZ = Math.XYZVector(0.,1.,45)
>
>
Root::Math Generic Vector and Transformation classes, as well as LHCb-specific geometry classes and functions are available in the LHCbMath module:

import LHCbMath

vXYZ = LHCbMath.XYZVector(0.,1.,45)
 print vXYZ.x(), " ", vXYZ.y(), " ", vXYZ.z()

Line: 101 to 109
 
>>> from eventassoc import linkedTo
>>> location = 'Rec/Track/Velo'
Changed:
<
<
>>> Track = gaudimodule.gbl.LHCb.Track
>>> MCParticle = gaudimodule.gbl.LHCb.MCParticle
>
>
>>> Track = gbl.LHCb.Track
>>> MCParticle = LHCb.MCParticle
 >>> LT = linkedTo(MCParticle,Track,location)
>>> LT.notFound() == False
True

Revision 192009-06-27 - JuanPalacios

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

Gaudi Python FAQ

Line: 52 to 52
 
Added:
>
>

How to run the new MC associators

From DaVinci v23r0 onwards, new MC association is available. This is implemented in terms of simple tool interfaces that lend themselves very well to interactive use in Python. GaudiPython examples are here.

 

How to access to DoxyGen documentation for C++ class/instances?

Starting from LHCb v22r9 it is very easy to get an easy access to the

Line: 441 to 445
  -- Vanya Belyaev - 25 Sep 2007
Added:
>
>
-- JuanPalacios - 27 Jun 2009
 
META FILEATTACHMENT attachment="GaudiPython_20071017.pdf" attr="h" comment="" date="1192624741" name="GaudiPython_20071017.pdf" path="GaudiPython_20071017.pdf" size="1976032" stream="GaudiPython_20071017.pdf" user="Main.PereMato" version="1"

Revision 182009-06-26 - JuanPalacios

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

Gaudi Python FAQ

Line: 14 to 14
 Have a look at the following tutorials:
Changed:
<
<
>
>
 

FAQs


How to get access and instantiate an LHCb Event class

Changed:
<
<
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. The gaudimodule.gbl represents the C++ global namespace (::) You can abbreviate the namespace with assignments like
>
>
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. GaudiPythin.Bindings.gbl represents the C++ global namespace (::) You can abbreviate the namespace with assignments:
 
Changed:
<
<
std = gaudimodule.gbl.std LHCb = gaudimodule.gbl.LHCb
>
>
from GaudiPython.Bindings import gbl std = gbl.std LHCb = gbl.LHCb
 
Added:
>
>
Then you can create your own instances of LHCb event model types:
 
Changed:
<
<
import gaudimodule gaudimodule.loaddict('MCEventDict') # will not be needed when class # 'autoload' will be enabled myparticle = gaudimodule.gbl.LHCb.MCParticle()
>
>
myMCParticle = LHCb.MCParticle() myRecVertex = RecVertex()
 
Added:
>
>

How to access common classes (e.g. STL containers, ROOT::Math classes etc.)

We get access to the global namespace and create shortcuts as explained above. Then we can instantiate some STL types

 
Deleted:
<
<
The equivalent classes for reconstructed particles are:
 
Changed:
<
<
gaudimodule.loaddict('PhysEventDict') gaudimodule.loaddict('PhysDict')
>
>
myvector = std.vector('double')() particleVector = gbl.std.vector('const LHCb::Particle *')(50, 0)

from ROOT import Math

vXYZ = Math.XYZVector(0.,1.,45) print vXYZ.x(), " ", vXYZ.y(), " ", vXYZ.z()

 
Added:
>
>

 

How to access to DoxyGen documentation for C++ class/instances?

Starting from LHCb v22r9 it is very easy to get an easy access to the

Line: 53 to 64
 %ENDSYNTAX% The idea from Thomas Ruf has been used.
Deleted:
<
<

How to access common classes (e.g. STL containers, CLHEP classes etc.)

To get access to a C++ class via Python its corresponding Reflex dictionary has to be loaded. A new package RELAX has been setup which contains dictionaries for commonly used HEP libraries and classes (e.g. CLHEP, HepMC, STL containers). The dictionaries are called Rflx (e.g. CLHEPRflx, STLRflx). These dictionaries can be explicitly loaded via Gaudi Python

import gaudimodule
gaudimodule.loaddict('STLRflx')

and then can be accessed via the global namespace

myvector = gaudimodule.gbl.std.vector('double')()
particleVector = gaudimodule.gbl.std.vector('LHCb::Particle *')()
 

How to run using a job options file several iterations

This is a minimalistic example on how to run a gaudi job (DaVinci in this case) for a number of events several times. In between the runs the user can access any information or change the algorithms or their properties.

Changed:
<
<
import gaudimodule gaudi = gaudimodule.AppMgr( outputlevel = 3,
>
>
from GaudiPython import AppMgr gaudi = AppMgr( outputlevel = 3,
  joboptions = '$DAVINCIROOT/options/DVDC06MCParticleMaker.opts') gaudi.initialize()

Revision 172008-12-10 - MarcoCattaneo

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

Gaudi Python FAQ

Line: 12 to 12
 

Getting Started

Have a look at the following tutorials:

Changed:
<
<
>
>
 

Revision 162008-11-10 - MarcoCattaneo

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

Gaudi Python FAQ

Line: 8 to 8
  Welcome to the Gaudi Python FAQ page. If you have questions (and answers) please add them to the page. The goal of this page is to create documentation for the Gaudi Python package.
Added:
>
>
 

Getting Started

Have a look at the following tutorials:

Revision 152008-09-16 - MarcoCattaneo

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

Gaudi Python FAQ

Line: 10 to 10
 

Getting Started

Changed:
<
<
Have a look at a gaudipython tutorial from a physicist point of view
>
>
Have a look at the following tutorials:

 

FAQs


Revision 142008-02-12 - AnatolySolomin

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

Gaudi Python FAQ

Line: 52 to 52
 

How to access common classes (e.g. STL containers, CLHEP classes etc.)

Changed:
<
<
To get access to a C++ class via Python it's corresponding Reflex dictionary has to be loaded. A new package RELAX has been setup which contains dictionaries for commonly used HEP libraries and classes (e.g. CLHEP, HepMC, STL containers). The dictionaries are called Rflx (e.g. CLHEPRflx, STLRflx). These dictionaries can be explicitly loaded via Gaudi Python
>
>
To get access to a C++ class via Python its corresponding Reflex dictionary has to be loaded. A new package RELAX has been setup which contains dictionaries for commonly used HEP libraries and classes (e.g. CLHEP, HepMC, STL containers). The dictionaries are called Rflx (e.g. CLHEPRflx, STLRflx). These dictionaries can be explicitly loaded via Gaudi Python
 
import gaudimodule

Revision 132007-10-17 - PereMato

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

Gaudi Python FAQ

Line: 442 to 442
 -- StefanRoiser - 13 Apr 2006

-- Vanya Belyaev - 25 Sep 2007

Added:
>
>
META FILEATTACHMENT attachment="GaudiPython_20071017.pdf" attr="h" comment="" date="1192624741" name="GaudiPython_20071017.pdf" path="GaudiPython_20071017.pdf" size="1976032" stream="GaudiPython_20071017.pdf" user="Main.PereMato" version="1"

Revision 122007-10-01 - VanyaBelyaev

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

Gaudi Python FAQ

Line: 46 to 46
 >>> doxy.browse ( o ) ## ask DoxyGen for the objects
>>> doxy.browse ( "LHCb::MCVertex") ## ask doxyGen for the class by name
%ENDSYNTAX%
Changed:
<
<
The idea from Thomas Ruf has been used.
>
>
The idea from Thomas Ruf has been used.
 


Line: 148 to 148
 

Changed:
<
<

How to deal with Gaudi/AIDA histograms in GaudiPython ?

>
>

How to deal with Gaudi/AIDA histograms in GaudiPython ?

 
Changed:
<
<
There are three major ways of dealing with Gaudi/AIDA histograms in GaudiPython
>
>
There are three major ways of dealing with Gaudi/AIDA histograms in GaudiPython
 
  • Direct manipulation with histogram service
Changed:
<
<
  • Usage of functionality offered by HistoUtils module
>
>
  • Usage of functionality offered by HistoUtils module
 
  • Access to "the nice" histogramming through the base-class inheritance (OO-spirit)

Direct manipulation with the histogram service allows to book and fill hisrogram from the simple (Gaudi)Python scripts

Line: 171 to 171
  %ENDSYNTAX%
Changed:
<
<
The module HistoUtils (appears form Gaudi v19r5) provides couple of functions, which simplified a bit the booking of histograms and profiles:
>
>
The module HistoUtils (available from Gaudi v19r5) provides couple of functions, which simplified a bit the booking of histograms and profiles:
  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%
Line: 252 to 252
 The direct manipulation (booking&filling of columns) with the native Gaudi N-tuples in Python seems to be a very difficult task. Up to now no good and easy disprove of this statement are known. Therefore one needs to find an alternative way. Three relatively easy options have been demonstrated
Changed:
<
<
  1. A direct manipulation with ROOT trees&Ntuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
>
>
  1. A direct manipulation with ROOT (T)-trees&N-tuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
 
  1. Access to "the nice" N-tuples through the base-class inheritance (OO-spirit)

Please consult ROOT manual for the first way, here we describe only the second way. The third way (OO-spirit)

Line: 263 to 263
 be converted into C++ lines using almost "1->1" correspondence.
Changed:
<
<
The module TupleUtils contains essentially one important function nTuple :
>
>
The module TupleUtils (appears in Gaudi v19r5) contains essentially one important function nTuple :
  %SYNTAX{ syntax="python" numbered="1000" numstep="10"}%

Revision 112007-09-30 - VanyaBelyaev

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

Gaudi Python FAQ

Line: 36 to 36
 gaudimodule.loaddict('PhysDict')
Added:
>
>

How to access to DoxyGen documentation for C++ class/instances?

Starting from LHCb v22r9 it is very easy to get an easy access to the DoxyGen documentation pages for the certain classes, types, objects and instances:

<!-- SyntaxHighlightingPlugin -->
 1800>>> import LoKiCore.doxygenurl as doxy 
 1810>>> o = ...    ## arbitrary object 
 1820>>> doxy.browse ( o )     ## ask DoxyGen for the objects
 1830>>> doxy.browse ( "LHCb::MCVertex")     ## ask doxyGen for the class by name
 1840
<!-- end SyntaxHighlightingPlugin -->
The idea from Thomas Ruf has been used.
 

How to access common classes (e.g. STL containers, CLHEP classes etc.)

Line: 225 to 238
 root = HistoUtils.getAsROOT( path )

%ENDSYNTAX%

Changed:
<
<
HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
>
>
HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
 

OO-spirit is described in detail here and it allows to reuse

Line: 288 to 301
 

How to access Relation tables in (Gaudi)Python?

There are many Relation tables flying around in Gaudi/LHCb software. They are used in many areas:

Changed:
<
<
  1. As representationof Monte Carlo links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. chi2-matching of Calorimeter clusters with reocntructed tracks
>
>
  1. As representationof Monte Carlo truth links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. -matching of Calorimeter clusters with recontructed tracks
 
  1. As the main representation of Monte Carlo links for (Proto)Particles for LoKi

The relation tables provides easy, intuitive and efficient way for relation between any objects in Gaudi. The python interface looks very similar to C++ interface.

Changed:
<
<
E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted<LHCb::CaloCluster,LHCb::MCParticle,float>
>
>
E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted<LHCb::CaloCluster,LHCb::MCParticle,float>
 for selection of Monte Carlo "merged" neutral pions.
Deleted:
<
<

 %SYNTAX{ syntax="python" numbered="1000" numstep="10"}% #!/usr/bin/env python2.4 # =========================================================================
Line: 402 to 413
 %ENDSYNTAX%

The example illustrate:

Changed:
<
<
  • retrival the relation table from Transient Event Store (the line 01410)
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted<LHCb::MCParticle,LHCb::CaloCluster,float> , see the lines 01440-01450)
  • selection of pi0, which
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
    • have an origin vertex within +-50 centimeters arounf the primary vertex (the line 01320)
    • each of the photon in in the geometrical acceptance of Ecal (the lines 01620-01630)
  • Retrieve from the relation table the number of associated Ecal clusters for pi0 and each of the daughter photons (the lines 01710-01720&01810)
  • makes the plots of the transverse momentum of the pi0 and the minimal pt of dauhter photons for each case
>
>
  • retrival the relation table from Transient Event Store (the line 01410)
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted<LHCb::MCParticle,LHCb::CaloCluster,float> , see the lines 01440-01450)
  • selection of , which:
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
    • have an origin vertex within +-50 centimeters in z-direction around the primary vertex (the line 01320)
    • each of the photon is in the geometrical acceptance of Ecal (the lines 01620-01630)
  • Retrieve from the relation table the number of associated Ecal clusters for and each of the daughter photons (the lines 01710-01720&01810)
  • makes the plots of the transverse momentum of the and the minimal pt of dauhter photons for each case.
 
Changed:
<
<
In addition one can make an explict loop e.g. through all associated clusters e.g. compare with lines 01800-01810 in the previous listing:
>
>
In addition one can make an explict loop e.g. through all associated clusters e.g. compare with lines 01800-01810 in the previous listing:
  %SYNTAX{ syntax="python" numbered="1800" numstep="10"}% # select only 1 or 2-cluster pi0s
Line: 425 to 436
  %ENDSYNTAX%
Changed:
<
<
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
>
>
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
  -- StefanRoiser - 13 Apr 2006

Revision 102007-09-26 - VanyaBelyaev

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

Gaudi Python FAQ

Line: 225 to 225
 root = HistoUtils.getAsROOT( path )

%ENDSYNTAX%

Changed:
<
<
HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel.
>
>
HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel
 

OO-spirit is described in detail here and it allows to reuse

Line: 286 to 285
  %ENDSYNTAX%
Added:
>
>

How to access Relation tables in (Gaudi)Python?

There are many Relation tables flying around in Gaudi/LHCb software. They are used in many areas:

  1. As representationof Monte Carlo links for Calorimeter objects
  2. As the dynamic extension of recontruction classes, e.g. chi2-matching of Calorimeter clusters with reocntructed tracks
  3. As the main representation of Monte Carlo links for (Proto)Particles for LoKi

The relation tables provides easy, intuitive and efficient way for relation between any objects in Gaudi. The python interface looks very similar to C++ interface. E.g. the following example shows how one can use the relation table of C++ type Relation::RelationWeighted<LHCb::CaloCluster,LHCb::MCParticle,float> for selection of Monte Carlo "merged" neutral pions.

%SYNTAX{ syntax="python" numbered="1000" numstep="10"}% #!/usr/bin/env python2.4 # ========================================================================= ## import everything from bender from MainMC import * # ========================================================================= ## Simple examples of manipulations with relation tables # @author Vanya BELYAEV ibelyaev@physicsNOSPAMPLEASE.syr.edu # @date 2007-09-26 class MergedPi0(AlgoMC) : """ simple class to plot dikaon mass peak """

## standard constructor def init ( self , name = 'MergedPi0' ) : """ Standard constructor """ return AlgoMC.__init__ ( self , name )

## standard mehtod for analyses def analyse( self ) : """ Standard method for Analysis """

finder = self.mcFinder(" pi0->2gamma MC-finder")

mcpi0 = finder.find ( "pi0 -> gamma gamma" ) ;

if mcpi0.empty() : return self.Warning("No MC-pi0 is found (1)", SUCCESS )

#get only pi0s, which satisfy the criteria: #1) large Pt mc1 = MCPT > 500 # * MeV # 2) valid origin vertex mc2 = MCOVALID # 2) vertex near the primary vertex mc3 = abs ( MCVFASPF( MCVZ ) ) < 500 # * Gaudi.Units.mm

mccut = mc1 & mc2 & mc3

mcpi = self.mcselect ( "mcpi" , mcpi0 , mccut )

if mcpi.empty() : return self.Warning ( "No MC-pi0 are found (2)", SUCCESS )

# get the relation table from TES table = self.get( "Relations/" + "Rec/Calo/Clusters" ) # LHCb::CaloClusterLocation::Default

 
Added:
>
>
#invert the table(create the inverse table) for local usage iTable = cpp.Relations.RelationWeighted(LHCb.MCParticle,LHCb.CaloCluster,'float') itable = iTable( table , 1 )
 
Added:
>
>
# consruct "Ecal-acceptance" cuts outer = ( abs(MCPY/MCPZ) < 3.00/12.5 ) & ( abs(MCPX/MCPZ) < 4.00/12.5 ) inner = ( abs(MCPY/MCPZ) > 0.32/12.5 ) | ( abs(MCPX/MCPZ) > 0.32/12.5 ) accept = outer &inner
 
Added:
>
>
# loop over mcpi0: for pi0 in mcpi :

# get daughter MC-photons gamma1 = pi0.child(1) if not gamma1 : continue gamma2 = pi0.child(2) if not gamma2 : continue

# both MC-photons in Ecal acceptance if not accept ( gamma1 ) : continue if not accept ( gamma2 ) : continue

pt = MCPT ( pi0 ) / 1000 mnpt = min( MCPT ( gamma1 ) , MCPT ( gamma2 ) ) / 1000

self.plot ( pt , "ALL pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , "ALL pi0->gamma gamma : min pt of photon " , 0 , 5 )

clus1 = itable.relations ( gamma1 ) clus2 = itable.relations ( gamma1 )

# each photon have some associated cluster(s) in ECAL if clus1.empty() or clus2.empty() : continue

self.plot ( pt , "ECAL pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , "ECAL pi0->gamma gamma : min pt of photon " , 0 , 5 )

# select only 1 or 2-cluster pi0s clus0 = itable.relations ( pi0 ) if 1 = clus0.size() and 2 = clus0.size() : continue

self.plot ( pt , " 1||2 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 1||2 pi0->gamma gamma : min pt of photon " , 0 , 5 )

# select only true "2-cluster" pi0 if 2 = clus0.size() and 1 = clus1.size() and 1 = clus2.size() and clus1.front().to() clus2.front().to() : self.plot ( pt , " 2 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 2 pi0->gamma gamma : min pt of photon " , 0 , 5 )

# select only true "1-cluster" pi0 if 1 = clus0.size() and 1 = clus1.size() and 1 = clus2.size() and clus1.front().to() = clus2.front().to() : self.plot ( pt , " 1 pi0->gamma gamma " , 0 , 5 ) self.plot ( mnpt , " 1 pi0->gamma gamma : min pt of photon " , 0 , 5 )

return SUCCESS # ========================================================================= %ENDSYNTAX%

The example illustrate:

  • retrival the relation table from Transient Event Store (the line 01410)
  • inversion of table (on-flight conversion to the C++ type Relations::RelationWeigted<LHCb::MCParticle,LHCb::CaloCluster,float> , see the lines 01440-01450)
  • selection of pi0, which
    • satisfy the decay pattern "pi0 -> gamma gamma" (the line 01220)
    • have an origin vertex within +-50 centimeters arounf the primary vertex (the line 01320)
    • each of the photon in in the geometrical acceptance of Ecal (the lines 01620-01630)
  • Retrieve from the relation table the number of associated Ecal clusters for pi0 and each of the daughter photons (the lines 01710-01720&01810)
  • makes the plots of the transverse momentum of the pi0 and the minimal pt of dauhter photons for each case

In addition one can make an explict loop e.g. through all associated clusters e.g. compare with lines 01800-01810 in the previous listing:

<!-- SyntaxHighlightingPlugin -->
 1800# select only 1 or 2-cluster pi0s 
 1810            clus0 = itable.relations ( pi0 ) 
 1820            # make explicit loop over related clusters: 
 1830            for link in clus0 : 
 1840                     #get the related cluster  of type LHCb::CaloCluster
 1850                     cluster = link.to() 
 1860                     #get the weigth for the relation (cumulated energy deposition from the given MC-particle)
 1870                     weight = link.weight() 
 1880                      
<!-- end SyntaxHighlightingPlugin -->
 
Added:
>
>
It is worth to compare these lines with corrresponding C++ example from Ex/LoKiExample package, see the file $LOKIEXAMPLEROOT/src/LoKi_MCMergedPi0s.cpp
  -- StefanRoiser - 13 Apr 2006

Revision 92007-09-25 - VanyaBelyaev

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

Gaudi Python FAQ

Line: 6 to 6
 

Introduction

Changed:
<
<
Welcome to the Gaudi Python FAQ page. If you have questions (and anwers) please add them to the page. The goal of this page is to create documentation for the Gaudi Python package.
>
>
Welcome to the Gaudi Python FAQ page. If you have questions (and answers) please add them to the page. The goal of this page is to create documentation for the Gaudi Python package.
 

Getting Started

Line: 133 to 133
 sc = OfflineVertexFitter.fit(daughterVect,MotherCand, MotherVertex)
Added:
>
>

How to deal with Gaudi/AIDA histograms in GaudiPython ?

There are three major ways of dealing with Gaudi/AIDA histograms in GaudiPython

  • Direct manipulation with histogram service
  • Usage of functionality offered by HistoUtils module
  • Access to "the nice" histogramming through the base-class inheritance (OO-spirit)

Direct manipulation with the histogram service allows to book and fill hisrogram from the simple (Gaudi)Python scripts in a relatively intuitive way:

<!-- SyntaxHighlightingPlugin -->
 1000# get the service (assume that gaudi is the ApplMgr object):
 1010svc = gaudi.histosvc() 
 1020
 1030# book the histogram
 1040h1 = svc.book('some/path','id','title',100,0.0,1.0) 
 1050
 1060# fill it  (e.g. in a loop):
 1070for i in range(0,100): h1.fill( math.sin( i ) ) 
<!-- end SyntaxHighlightingPlugin -->

The module HistoUtils (appears form Gaudi v19r5) provides couple of functions, which simplified a bit the booking of histograms and profiles:

<!-- SyntaxHighlightingPlugin -->
 1000from HistoUtils import book 
 1010
 1020# book the histogram
 1030h1 = book('some/path','id','title',100,0.0,1.0) 
 1040
 1050# fill it  (e.g. in a loop):
 1060for i in range(0,100): h1.fill( math.sin( i ) ) 
<!-- end SyntaxHighlightingPlugin -->

Also it provides "powerful fill" with implicit loop and selection:

<!-- SyntaxHighlightingPlugin -->
 1000from HistoUtils import fill 
 1010
 1020# book the histogram
 1030histo = ... 
 1040
 1050# fill it  with single value:
 1060value = ... 
 1070fill ( histo , value ) 
 1080
 1090# fill it with arbitrary sequence of objects, convertible to double:
 1100fill ( histo , [1,2,3,4,5,6,7] ) 
 1110
 1120# use the sequence and apply the function:
 1130#  fill histogram with 1*1, 2*2 , 3*3, 4*4
 1140fill ( histo , [1,2,3,4,5] , lambda x : x*x ) 
 1150
 1160# use the sequence and apply the function:
 1170# for each track in sequence evaluate "pt()" and fill the histo
 1180tracks = ... 
 1190fill ( histo , tracks , lambda t : t.pt() ) 
 1200
 1210# use the sequnce, applythe function, but filter out even values:
 1220fill ( histo , [1,2,3,4,5,6,7] , lambda x : x*x , lambda y : 0==y%2 )
 1230
 1240
 1250# use the sequence and apply the function:
 1260# for each track in sequence evaluate "p()" and fill the histogram with track momentum, 
 1270# keepingonly track with small transverse momentum:
 1280tracks = ... 
 1290fill ( histo , tracks , lambda t : t.p() , lambda t : t.pt() < 1000 ) 
 1300
<!-- end SyntaxHighlightingPlugin -->

Also the module exports two functions which provides the access to the histogram by their location in Histogram Transient Store:

<!-- SyntaxHighlightingPlugin -->
 1000import HistoUtils 
 1010
 1020path = 'some/path/to/my/histo/ID'
 1030
 1040# get as AIDA:
 1050aida = HistoUtils.getAsAIDA ( path ) 
 1060
 1070# get as native ROOT:
 1080root = HistoUtils.getAsROOT( path ) 
<!-- end SyntaxHighlightingPlugin -->
HistoUtils are partly inspired by Tadashi Maeno' API from ATLAS' PyKernel.

OO-spirit is described in detail here and it allows to reuse the whole functionality of easy-and-friendly histograms, including booking-on-demand. Also it is a recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.

How to deal with Gaudi N-tuples in GaudiPython ?

The direct manipulation (booking&filling of columns) with the native Gaudi N-tuples in Python seems to be a very difficult task. Up to now no good and easy disprove of this statement are known. Therefore one needs to find an alternative way. Three relatively easy options have been demonstrated

  1. A direct manipulation with ROOT trees&Ntuples
  2. Use of "smart-and-easy" N-tuples via TupleUtils module (starting from Gaudi version v19r5)
  3. Access to "the nice" N-tuples through the base-class inheritance (OO-spirit)

Please consult ROOT manual for the first way, here we describe only the second way. The third way (OO-spirit) is described in detail here and it allows to reuse the whole functionality of easy-and-friendly N-tuples, including booking-on-demand. It is nice, simple, safe and it represents the recommended way for prototyping, since the resulting code is very easy to be converted into C++ lines using almost "1->1" correspondence.

The module TupleUtils contains essentially one important function nTuple :

<!-- SyntaxHighlightingPlugin -->
 1000from TupleUtils import nTuple 
 1010
 1020# get N-tuple (book-on-demand)
 1030t = nTuple ( 'the/path/to/the/directory' , ## path 
 1040             'MyNtupleID' ,  ## the literal ID of the tuple
 1050             'It is the title for my N-tuple ', ## title 
 1060              LUN = 'MYLUN1' ) ## logical unit 
 1070
 1080# fill it with data e.g. trivial scalar columns:
 1090for i in range ( 1 , 1000 ) :
 1100   t.column ( 'i' , i )             ## integer scalar
 1110   t.column ( 'a' , math.sin(i) )   ## float scalar 
 1120   t.column ( 'b' , math.cos(i) )   ## one more float scalar
 1130   t.write ()                       ## commit the row
 1140 
<!-- end SyntaxHighlightingPlugin -->

It is important at the end of the job to release all implicitely aquired n-tuples:

<!-- SyntaxHighlightingPlugin -->
 1000import TupleUtils
 1010
 1020# get the list of "active" N-tuples:
 1030print TupleUtils.activeTuples() 
 1040
 1050# release all "active" N-tuples:
 1060TupleUtils.releaseTuples () 
<!-- end SyntaxHighlightingPlugin -->

 -- StefanRoiser - 13 Apr 2006
Added:
>
>
-- Vanya Belyaev - 25 Sep 2007

Revision 82007-04-25 - ThomasRuf

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

Gaudi Python FAQ

Line: 10 to 10
 

Getting Started

Added:
>
>
Have a look at a gaudipython tutorial from a physicist point of view
 

FAQs


Revision 72006-12-15 - unknown

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

Gaudi Python FAQ

Line: 16 to 16
 

How to get access and instantiate an LHCb Event class

The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. The gaudimodule.gbl represents the C++ global namespace (::)

Added:
>
>
You can abbreviate the namespace with assignments like
std  = gaudimodule.gbl.std
LHCb = gaudimodule.gbl.LHCb
 
import gaudimodule
Line: 24 to 29
 myparticle = gaudimodule.gbl.LHCb.MCParticle()
Added:
>
>
The equivalent classes for reconstructed particles are:
gaudimodule.loaddict('PhysEventDict')
gaudimodule.loaddict('PhysDict')
 

How to access common classes (e.g. STL containers, CLHEP classes etc.)

Line: 38 to 49
 
myvector = gaudimodule.gbl.std.vector('double')()
Added:
>
>
particleVector = gaudimodule.gbl.std.vector('LHCb::Particle *')()
 


Line: 93 to 105
 
Added:
>
>

How to do a vertex fit

First get the vertex fitter tool:
appMgr = gaudimodule.AppMgr(outputlevel=3)
OflineVertexFitter = appMgr.toolsvc().create('OfflineVertexFitter', interface='IVertexFit')

Then create the mother particle and vertex along the lines of

pidMother   = gaudimodule.gbl.LHCb.ParticleID(pidOfMother)
MotherVertex = gaudimodule.gbl.LHCb.Vertex()
MotherCand = gaudimodule.gbl.LHCb.Particle(pidMother)

Put the daughters which you want to fit into a vector of LHCb::Particle* :

particleVector = gaudimodule.gbl.std.vector('LHCb::Particle *')
daughterVect = particleVector()
daughterVect.push_back(dau1)
daughterVect.push_back(dauN)

Finally, perform the vertex fit:

sc = OfflineVertexFitter.fit(daughterVect,MotherCand, MotherVertex)
 -- StefanRoiser - 13 Apr 2006

Revision 62006-11-17 - unknown

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

Gaudi Python FAQ

Revision 52006-06-01 - PereMato

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

Gaudi Python FAQ

Line: 41 to 41
 


Added:
>
>

How to run using a job options file several iterations

This is a minimalistic example on how to run a gaudi job (DaVinci in this case) for a number of events several times. In between the runs the user can access any information or change the algorithms or their properties.

import gaudimodule
gaudi = gaudimodule.AppMgr( outputlevel = 3,
                            joboptions  = '$DAVINCIROOT/options/DVDC06MCParticleMaker.opts')
gaudi.initialize()

gaudi.run(10)
#---You can change the algorimths or other parameters here
gaudi.evtsel().rewind()
gaudi.run(10)


 

How to access Linker tables

The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.

Revision 42006-04-13 - StefanRoiser

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

Gaudi Python FAQ

Line: 12 to 12
 

FAQs

Added:
>
>

 

How to get access and instantiate an LHCb Event class

The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. The gaudimodule.gbl represents the C++ global namespace (::)

Line: 39 to 40
 myvector = gaudimodule.gbl.std.vector('double')()
Changed:
<
<
>
>

 

How to access Linker tables

The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.

Revision 32006-04-13 - EduardoRodrigues

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

Gaudi Python FAQ

Line: 39 to 39
 myvector = gaudimodule.gbl.std.vector('double')()
Added:
>
>

How to access Linker tables

The LHCb linker tables can be accessed in Python via the eventassoc.py module in Event/LinkerInstances.

First, do not forget to add in the requirements file the line

use LinkerInstances v* Event

Then the usage is standard. For the sake of example, let's assume that the variable track contains a VELO Track you are interested in, from the 'Rec/Track/Velo' container. A simple manipulation is:

>>> from eventassoc import linkedTo
>>> location = 'Rec/Track/Velo'
>>> Track = gaudimodule.gbl.LHCb.Track
>>> MCParticle = gaudimodule.gbl.LHCb.MCParticle
>>> LT = linkedTo(MCParticle,Track,location)
>>> LT.notFound() == False
True
>>> range = LT.range(track)
>>> range
<ROOT.vector<LHCb::MCParticle*> object at 0xfe27e90>
>>> range.size()
1L
>>> mcp = range[0]
>>> mcp
{ momentum :   (-65.73,-63.69,1777.86,1785.68)
particleID :   { pid :   211
 }
 }
 

-- StefanRoiser - 13 Apr 2006

Revision 22006-04-13 - PereMato

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

Gaudi Python FAQ

Line: 12 to 12
 

FAQs

Changed:
<
<

LHCb related

>
>

How to get access and instantiate an LHCb Event class

 
Changed:
<
<

How to get access to an LHCb Event class

The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace

>
>
The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace. The gaudimodule.gbl represents the C++ global namespace (::)
 
import gaudimodule
Added:
>
>
gaudimodule.loaddict('MCEventDict') # will not be needed when class # 'autoload' will be enabled
 myparticle = gaudimodule.gbl.LHCb.MCParticle()


Changed:
<
<

LCG related


How to access common classes (e.g. STL containers, CLHEP classes etc.)

>
>

How to access common classes (e.g. STL containers, CLHEP classes etc.)

  To get access to a C++ class via Python it's corresponding Reflex dictionary has to be loaded. A new package RELAX has been setup which contains dictionaries for commonly used HEP libraries and classes (e.g. CLHEP, HepMC, STL containers). The dictionaries are called Rflx (e.g. CLHEPRflx, STLRflx). These dictionaries can be explicitly loaded via Gaudi Python
Line: 44 to 39
 myvector = gaudimodule.gbl.std.vector('double')()

Changed:
<
<
>
>

  -- StefanRoiser - 13 Apr 2006

Revision 12006-04-13 - StefanRoiser

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

Gaudi Python FAQ

Introduction

Welcome to the Gaudi Python FAQ page. If you have questions (and anwers) please add them to the page. The goal of this page is to create documentation for the Gaudi Python package.

Getting Started

FAQs

LHCb related


How to get access to an LHCb Event class

The LHCb Event classes now live in the namespace "LHCb". In order to get access you have to use this namespace

import gaudimodule
myparticle = gaudimodule.gbl.LHCb.MCParticle()


LCG related


How to access common classes (e.g. STL containers, CLHEP classes etc.)

To get access to a C++ class via Python it's corresponding Reflex dictionary has to be loaded. A new package RELAX has been setup which contains dictionaries for commonly used HEP libraries and classes (e.g. CLHEP, HepMC, STL containers). The dictionaries are called Rflx (e.g. CLHEPRflx, STLRflx). These dictionaries can be explicitly loaded via Gaudi Python

import gaudimodule
gaudimodule.loaddict('STLRflx')

and then can be accessed via the global namespace

myvector = gaudimodule.gbl.std.vector('double')()

-- StefanRoiser - 13 Apr 2006

 
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