Difference: ParticleSelection (1 vs. 31)

Revision 312019-06-27 - LaurentDufour

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

Particle Selection Toolkit

Line: 149 to 149
  & (ADMASS('J/psi(1S)') < 42.*MeV) """) %ENDSYNTAX%
Changed:
<
<
It allows to achieve more compact (but still easy readable) code minimizing number of intermediate local objects
>
>
It allows to achieve more compact (but still easy readable) code minimizing number of intermediate local objects. Note that we now import the FilterDesktop algorithm from GaudiConfUtils.ConfigurableGenerators instead of directly from Configurables.
 

Debugging of selections

Line: 227 to 227
  FilterSelection , CombineSelection , Hlt1Selection , Hlt2Selection , L0Selection , StrippingSelection ,
Changed:
<
<
MomentumScaling )
>
>
MomentumScaling , TupleSelection )
 

## start selection using soem standard seelctions

Revision 292016-11-25 - VanyaBelyaev

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

Particle Selection Toolkit

Line: 155 to 155
  There are several useful methods for debugging your selection:
  1. one can visualize the selection graph using SelPy.graph function
Changed:
<
<
  1. one can force the selection to print the selcted content using PrintSelection
>
>
  1. one can force the selection to print the selected content using PrintSelection
 
  1. one can use the tricks described here

Added:
>
>

PrintSelection

PrintSelection is a very simple way to print the content of your selection. It just inserts PrintDecayTree algorithm into the algorithm sequence

<!-- SyntaxHighlightingPlugin -->
from PhysConf.Selections import PrintSelection
## some selection 
selection = PrintSelection ( selection )
<!-- end SyntaxHighlightingPlugin -->
The function returns decorated selection that could be used as input for other selections ans selection sequences. Each time non-empty selection appears in the data-flow, the content is printed to terminal/log-file.

visualization

To understand better the structure and the data flow for complicated selections, one can build a selection graph using SelPy.graph function

<!-- SyntaxHighlightingPlugin -->
from SelPy.graph import view 
## some selection 
selection = ...
view (selection )
<!-- end SyntaxHighlightingPlugin -->
When the script is executed, it produces nice graph. that illustrate the structure of the selection, and interdependencies of various algorithms
 

Building a sequencer

Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.
Line: 179 to 203
 SeqMyBs = SelectionSequence("SeqMyBs", TopSelection = SelMyBs, EventPreSelector = [ prescale ]) %ENDSYNTAX%
Added:
>
>

Specific selection

There are many other very useful objects in Selection framework, in particular
  • FilterSelection: very simple function that wraps FilterDesktop algorithm in SimlpeSelection described above
  • CombineSelction wraps CombineParticles algorithm in SimpleSelection
  • TupleSelection wraps DecayTreeTuple algorithm in SimpleSelection
  • LimitSelection is a useful concept when one needs to require certain number of objects in selection, e.g. not more than 400 pions
  • CheckPVSelection is a useful way to insert check on PV-existence into the algorithm flow
  • TriggerSelection allowes to make a filtering on trigger decision. There exist four varinats of generic TriggerSelection
    • L0Selection allows to check L0-decision via inspection of L0DUReport object
    • Hlt1Selection allows to check Hlt1-decision
    • Hlt1Selection checks Hlt1-decision
    • StrippingSelection checks Strippign-decision
  • MomentumScaling : simple pseudo-selection that inserts global TrackScaleSate algorithm into the sequence
  • MomentumSmear: simlpe pseuso-selection, that inserts TrackSmearState algorithm into the sequence
  • PassThroughSelection generi selection used for implementation of some of selections. described above
  • PayloadSelection generic selection that allows to insert arbotrary algorithm ("useful payload") into selection sequence. It could be an arbitrary type of algorith, e.g. even the primitive "Hello,world!"

All of them can be illustrated using this example:

<!-- SyntaxHighlightingPlugin -->
from PhysConf.Selections import (  PrintSelection  ,
                                   FilterSelection , CombineSelection   ,
                                   Hlt1Selection   , Hlt2Selection      , 
                                   L0Selection     , StrippingSelection ,
                                   MomentumScaling ) 


## start selection using soem standard seelctions
from StandardParticles import StdLoosePions    as pions
from StandardParticles import StdLooseKaons    as kaons
from StandardParticles import StdAllLoosePions as soft_pions

## filter them
pions = FilterSelection (
    'GOOD_pions'       , ## the name 
    [ pions ]          , ## input locations 
    Code = "PT>1*GeV"    ## algoriothm properties 
    )

## print it
pions = PrintSelection ( pions )

## filter kaons
kaons = FilterSelection (
    'GOOD_kaons'       , ## the name 
    [ kaons ]          , ## input locations 
    Code = "PT>1*GeV"    ## algoriothm properties 
    )

## print it
kaons = PrintSelection ( kaons )

## apply some trigger selections:
l0    = L0Selection  ( "L0_trigger" , "L0_CHANNEL_SUB('Muon')" )
hlt1  = Hlt1Selection( "L1_trigger" , "Hlt1.*(C|c)arm.*"       )
hlt2  = Hlt2Selection( "L2_trigger" , "Hlt2.*D0.*"             )
strip = StrippingSelection( "Stripping"  , ".*D0.*"                 )

## make D0
d0 = CombineSelection (
    "D0"                             , ## the name             
    [ hlt2 , strip , pions , kaons ] , ## input
    DecayDescriptor = "[ D0 -> K- pi+]cc" ,  
    CombinationCut  = " in_range ( 1.6 * GeV , AM , 2.0 * GeV )",
    MotherCut       = " CHI2VX < 10 "
    )

## print it!
d0 = PrintSelection  ( d0 )

## if we have D0, apply momentumn scaling
d0 = MomentumScaling ( d0 )

## make Dstar
dstar = CombineSelection (
    "Dstar"                         , ## the name             
    [ l0 , hlt1 , d0 , soft_pions ] , ## input
    DecayDescriptor = "[ D*(2010)+ -> D0 pi+]cc" ,  
    CombinationCut  = " AM - AM1 < 160 * MeV "   ,
    MotherCut       = " CHI2VX < 10 "
    )

## print it!
dstar = PrintSelection  ( dstar )
<!-- end SyntaxHighlightingPlugin -->

This selection correspond to a following sequence of algoriths:

<!-- SyntaxHighlightingPlugin -->
L0_trigger
L1_trigger
L2_trigger
Stripping
SelFilterPhys_StdLoosePions_Particles
GOOD_pions
GOOD_pions_PRINT
SelFilterPhys_StdLooseKaons_Particles
GOOD_kaons
GOOD_kaons_PRINT
D0
D0_PRINT
SCALER
SelFilterPhys_StdAllLoosePions_Particles
Dstar
<!-- end SyntaxHighlightingPlugin -->
 

Bringing it all together: grabbing the sequencer and adding it to a DaVinci configurable.

It is very easy to get the sequence from the modules where the SelectionSequence has been written and add it to the DaVinci configurable's main sequence:

Revision 282016-02-23 - VanyaBelyaev

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

Particle Selection Toolkit

Line: 29 to 29
 
  • AutomaticData (also known as DataOnDemand).
There is a special Selection class that is not designed to write data, it simply accepts or rejects an event, but otherwise looks just like any other Selection:
  • EventSelection.
Added:
>
>
There are several helper selections that coudl be useful for certain cases
  • PrintSelection allows to print the content of selection (for debugging)
  • LimitSelection allows to set a limit of numbers of candidates in selection
Both are specializations of very powerful and flexible PassThroughSelection
 

SelectionSequence

Line: 143 to 147
  & (MINTREE('mu+'==ABSID, PIDmu) > -5.0) & (MAXTREE('mu+'==ABSID, PIDK) < 5.0) & (ADMASS('J/psi(1S)') < 42.*MeV)
Changed:
<
<
"" )
>
>
""")
 %ENDSYNTAX%
Added:
>
>
It allows to achieve more compact (but still easy readable) code minimizing number of intermediate local objects

Debugging of selections

There are several useful methods for debugging your selection:

  1. one can visualize the selection graph using SelPy.graph function
  2. one can force the selection to print the selcted content using PrintSelection
  3. one can use the tricks described here
 

Building a sequencer

Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.

Revision 272016-02-10 - VanyaBelyaev

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

Particle Selection Toolkit

Line: 78 to 78
  _MyJpsi = FilterDesktop('MyJpsi')
Changed:
<
<
_MyJpsi.Code = " (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0)" "& (MINTREE('mu+'==ABSID, PIDmu) > -5.0)" "& (MAXTREE('mu+'==ABSID, PIDK) < 5.0)" "& (ADMASS('J/psi(1S)') < 42.*MeV)"
>
>
_MyJpsi.Code = """ (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0) & (MINTREE('mu+'==ABSID, PIDmu) > -5.0) & (MAXTREE('mu+'==ABSID, PIDK) < 5.0) & (ADMASS('J/psi(1S)') < 42.*MeV) """
  from PhysSelPython.Wrappers import Selection
Line: 118 to 120
  The Selection class will use the Selection.algName() method of each of the RequiredSelections to set the InputLocations of MyBs, and will store the Selections, such that they can be used to build a sequencer that can run all the algorithms necessary for the selection.
Added:
>
>

Combine two steps in one: SimpleSelection

As seen from previous examples, typically one has two steps for creation of Seelction

  1. creation and configuration of algorithm
  2. creation of Selection object

These two steps can be merged into one with usage of SimpleSelection helper:

<!-- SyntaxHighlightingPlugin -->
from PysSelPython.Wrappers import SimpleSelection , AuitomaticData
dimuons = AutomaticData(Location = 'Phys/StdLooseDiMuon/Particles')

from GaudiConfUtils.ConfigurableGenerators import FilterDesktop
selMyJpsi  = SimpleSelection (
    'MyJpsi'  , ##  the name 
   FilterDesktop, ## algorithms TYPE 
    [ dimuons ]  , ## list of input/required selections 
     ## all remaining arguments are algorithm properties:
     Code = """
      (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0)
   & (MINTREE('mu+'==ABSID, PIDmu) > -5.0)
   & (MAXTREE('mu+'==ABSID, PIDK) < 5.0)
   & (ADMASS('J/psi(1S)') < 42.*MeV)
"" )
<!-- end SyntaxHighlightingPlugin -->
 

Building a sequencer

Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.
Line: 230 to 258
 Beware that passing more than one Selection to the StrippingLine's algos argument is not a well defined operation and should not be done.

-- JuanPalacios - 26-Feb-2010

Added:
>
>
-- VanyaBelyaev - 2016-02-10
  |*META PREFERENCE*|name="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" title="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" type="Set" value="
"|

Revision 242010-11-08 - unknown

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

Particle Selection Toolkit

Introduction

Changed:
<
<
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and use of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the ANALYSIS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
>
>
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and use of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the PHYS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
 

Warning

This wiki explains how to write a selection starting from scratch (i.e. final state particles). You should not do that on a stripped DST. In that case use the candidate available on the DST. DaVinciTutorial8 explains how to use the selection framework to do this. You can simply make a DST location of Particles look like a Selection by using AutomaticData.
Line: 20 to 20
 This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in a handful of simple python classes) uses python concepts to address these issues.

Selection toolkit concepts and classes

Changed:
<
<
The building blocks of the selection toolkit are the Selection and the SelectionSequence. A Selection is a basic unit that either passes or fails, and may write LHCb::Particles to a location which it exports with the outputLocation() method. It knows about other Selections it needs to obtain input particles. A SelectionSequence essentially takes a Selection object, resolves its Selection requirements, and makes a flat list of Selections. It exports a self-contained GaudiSequencer with all the algorithm configurables necessary to perform the selection via the sequence() method. It also allows the user to specify a set of algorithms to run before or after the selection sequence. The building blocks are designed to be configured at construction, and do not support and changes to configuration. This is the only way they can be safely re-used, and the only way one can be sure that the intended configuration is what has been used in a program. Components that take a name as constructor argument create a Gaudi Configurable internally, so there is a mechanism in place that only allows a given name to be used once. The Selection Toolkit is thus very different to the plain Gaudi Configurables, and users should remember this. Fortunately, disallowed operations result in exceptions, so there is little chance of misconfiguring a job.
>
>
The building blocks of the selection toolkit are the Selection and the SelectionSequence. A Selection is a basic unit that either passes or fails, and may write LHCb::Particles to a location which it exports with the outputLocation() method. It knows about other Selections that it requires to pass in order to obtain input particles. A SelectionSequence essentially takes a Selection object, resolves its Selection requirements, and makes a flat list of Selections. It exports a self-contained GaudiSequencer with all the algorithm configurables necessary to perform the selection via the sequence() method. It also allows the user to specify a set of algorithms to run before or after the selection sequence. The building blocks are designed to be configured at construction, and do not support and changes to configuration. This is the only way they can be safely re-used, and the only way one can be sure that the intended configuration is what has been used in a program. Components that take a name as constructor argument create a Gaudi Configurable internally, so there is a mechanism in place that only allows a given name to be used once. The Selection Toolkit is thus very different to the plain Gaudi Configurables, and users should remember this. Fortunately, disallowed operations result in exceptions, so there is little chance of misconfiguring a job.
 

Selection

Changed:
<
<
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in three particle producing classes:
>
>
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. A Selection requires all its RequiredSelections to pass. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in three particle-producing classes:
 
  • Selection.
  • MergedSelection.
  • AutomaticData (also known as DataOnDemand).
Changed:
<
<
There is a special Selection class that does not write data, it simply accepts or rejects an event, but otherwise looks just like any other Selection:
>
>
There is a special Selection class that is not designed to write data, it simply accepts or rejects an event, but otherwise looks just like any other Selection:
 
  • EventSelection.

Revision 222010-07-29 - unknown

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

Particle selections

>
>

Particle Selection Toolkit

 

Introduction

Changed:
<
<
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the ANALYSIS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
>
>
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and use of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the ANALYSIS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
 

Warning

This wiki explains how to write a selection starting from scratch (i.e. final state particles). You should not do that on a stripped DST. In that case use the candidate available on the DST. DaVinciTutorial8 explains how to use the selection framework to do this. You can simply make a DST location of Particles look like a Selection by using AutomaticData.
Line: 17 to 17
 
  • The need to look at the file (or files imported to it via importOptions) to get information about, for example, the cuts applied.
  • When the sequencer is defined in the same file as the algorithms that the top selection depends on, one cannot get these algorithms without also instantiating the top algorithm plus the sequencer. This is not a big problem, but it seems unnecessary.
Changed:
<
<
This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in four simple python classes) uses python concepts to address these issues.
>
>
This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in a handful of simple python classes) uses python concepts to address these issues.
 
Changed:
<
<

Selection "framework" concepts and classes

Explain the concepts, mention "configure once, use many times" and "configure once only" principles.
>
>

Selection toolkit concepts and classes

The building blocks of the selection toolkit are the Selection and the SelectionSequence. A Selection is a basic unit that either passes or fails, and may write LHCb::Particles to a location which it exports with the outputLocation() method. It knows about other Selections it needs to obtain input particles. A SelectionSequence essentially takes a Selection object, resolves its Selection requirements, and makes a flat list of Selections. It exports a self-contained GaudiSequencer with all the algorithm configurables necessary to perform the selection via the sequence() method. It also allows the user to specify a set of algorithms to run before or after the selection sequence. The building blocks are designed to be configured at construction, and do not support and changes to configuration. This is the only way they can be safely re-used, and the only way one can be sure that the intended configuration is what has been used in a program. Components that take a name as constructor argument create a Gaudi Configurable internally, so there is a mechanism in place that only allows a given name to be used once. The Selection Toolkit is thus very different to the plain Gaudi Configurables, and users should remember this. Fortunately, disallowed operations result in exceptions, so there is little chance of misconfiguring a job.
 

Selection

Changed:
<
<
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in four classes:
>
>
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in three particle producing classes:
 
  • Selection.
  • MergedSelection.
  • AutomaticData (also known as DataOnDemand).
Added:
>
>
There is a special Selection class that does not write data, it simply accepts or rejects an event, but otherwise looks just like any other Selection:
 
  • EventSelection.
Added:
>
>
 

SelectionSequence

A SelectionSequence is a model of an entity that contains all the necessary Selections needed for a selection chain to work, and exports these in a correctly ordered and configured GaudiSequencer via the method sequence(). It also makes the output locations of the data written by the head of the decay chain available via the outputLocations() method. There are two implementations of the SelectionSequence.
  • The SelectionSequence class is a python entity that, given a single Selection instance (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a GaudiAlgorithm with all the necessary algorithm Configurables. This can be passed directly to the application manager and are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocations(). The SelectionSequence is the glue that sticks the Sequence building blocks together.

Revision 212010-07-28 - unknown

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

Particle selections

Line: 6 to 6
 This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the ANALYSIS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.

Warning

Changed:
<
<
This wiki explains how to write a selection starting from scratch (i.e. final state particles). You should not do that on a stripped DST. In that case use the candidate available on the DST. DaVinciTutorial8 explains how to use the selection framework to do this.
>
>
This wiki explains how to write a selection starting from scratch (i.e. final state particles). You should not do that on a stripped DST. In that case use the candidate available on the DST. DaVinciTutorial8 explains how to use the selection framework to do this. You can simply make a DST location of Particles look like a Selection by using AutomaticData.
 

Motivation

In most cases GaudiSequencers are full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:
Line: 19 to 19
  This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in four simple python classes) uses python concepts to address these issues.
Changed:
<
<

Concepts

>
>

Selection "framework" concepts and classes

Explain the concepts, mention "configure once, use many times" and "configure once only" principles.
 

Selection

Changed:
<
<
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in two classes, Selection and AutomaticData (also known as DataOnDemand, see below).
>
>
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in four classes:
  • Selection.
  • MergedSelection.
  • AutomaticData (also known as DataOnDemand).
  • EventSelection.
 

SelectionSequence

A SelectionSequence is a model of an entity that contains all the necessary Selections needed for a selection chain to work, and exports these in a correctly ordered and configured GaudiSequencer via the method sequence(). It also makes the output locations of the data written by the head of the decay chain available via the outputLocations() method. There are two implementations of the SelectionSequence.
Changed:
<
<
  • The SelectionSequence class is a python entity that, given a single Selection instance (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a GaudiAlgorithm with all the necessary algorithm Configurables. This can be passed directly to the application manager and are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocations(). The SelectionSequence is the glue that sticks the Sequence building blocks together. * The MultiSelectionSequence class is a python entity that is instantiated from an arbitrary number of SelectionSequences. It's sequence() method returns a GaudiSequencer with the sequences of its component SelectionSequences in OR mode. This is used to run a selection which is the OR of a series of independent Selections.
>
>
  • The SelectionSequence class is a python entity that, given a single Selection instance (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a GaudiAlgorithm with all the necessary algorithm Configurables. This can be passed directly to the application manager and are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocations(). The SelectionSequence is the glue that sticks the Sequence building blocks together.
  • The MultiSelectionSequence class is a python entity that is instantiated from an arbitrary number of SelectionSequences. It's sequence() method returns a GaudiSequencer with the sequences of its component SelectionSequences in OR mode. This is used to run a selection which is the OR of a series of independent Selections.
 
Changed:
<
<

Modules

Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changed a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
>
>
The StrippingStream class conforms to the SelectionSequence concept, but needs to be processed with a StrippingConf before it's fields can be considered to be consistent. This means a correctly created StrippingStream object can be used just like any other SelectionSequence.
 
Changed:
<
<

The Selection "framework" classes

To get information on the building block classes, Selection and DataOnDemand, and the glue class, SelectionSequence, it is simplest to look at the python documentation:
>
>

Getting help: documentation

To get the most up-to-date information on the building block classes, it is simplest to look at the python documentation:
 %SYNTAX{ syntax="python"}% # set some environment that gives us the necessary $PYTHON_PATH
Changed:
<
<
SetupProject DaVinci v24r2p3
>
>
SetupProject DaVinci v25r6
 python
Changed:
<
<
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand, AutomaticData, MultiSelectionSequence
>
>
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand, AutomaticData, MultiSelectionSequence, MergedSelection
 >>> help(Selection)
>>> help(SelectionSequence)
>>> help(DataOnDemand) # same as AutomaticData
>>> help(MultiSelectionSequence)
Added:
>
>
>>> help(MergedSelection)
 %ENDSYNTAX%
Added:
>
>

Particle selection implementations in python modules

Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changed a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
 

Examples

There are a many working examples in CVS,
Line: 136 to 144
 from BsSelections.Sequences import SeqMyBs as theSequence MySelection = theSequence.sequence() dv = DaVinci()
Changed:
<
<
dv.DataType = 'DC06'
>
>
dv.DataType = '2010'
 dv.EvtMax = 500 dv.UserAlgorithms = [MySelection] dv.Input = [...]
Line: 211 to 219
 For versions of DaVinci greater or equal to v25r1 it is possible to pass the Selection as a constructor argument: %SYNTAX{syntax="python"}% line = StrippingLine('JpsiInclusive'
Changed:
<
<
, prescale = 1.
>
>
, prescale = 0.25
  , algos = [ Jpsi ] ) %ENDSYNTAX%
Changed:
<
<
For older versions, it is necessary to build a SelectionSequence:
>
>
For earlier versions, it was possible to pass a SelectionSequence object, but it was deemed unsafe, since the combination of EventPreselectors and pre-defined StrippingLine event pre-selections (minimum number of orimary vertices, pre-scales) is not well defined.
 
Changed:
<
<
<!-- SyntaxHighlightingPlugin -->
# build the SelectionSequence
sequence = SelectionSequence("Seq"+name,
                              TopSelection = Jpsi
                            )
# Define the line
line = StrippingLine('JpsiInclusive'
                    , prescale = 1.
                    , algos = [ sequence ] )
<!-- end SyntaxHighlightingPlugin -->
Beware that passing more than one Selection or SelectionSequence to the StrippingLine's algos argument is not a well defined operation and should not be done.
>
>
Beware that passing more than one Selection to the StrippingLine's algos argument is not a well defined operation and should not be done.
  -- JuanPalacios - 26-Feb-2010

Revision 202010-06-16 - PatrickSKoppenburg

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

Particle selections

Introduction

This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the ANALYSIS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
Added:
>
>

Warning

This wiki explains how to write a selection starting from scratch (i.e. final state particles). You should not do that on a stripped DST. In that case use the candidate available on the DST. DaVinciTutorial8 explains how to use the selection framework to do this.
 

Motivation

In most cases GaudiSequencers are full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:

Revision 192010-06-08 - unknown

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

Particle selections

Line: 14 to 14
 
  • The need to look at the file (or files imported to it via importOptions) to get information about, for example, the cuts applied.
  • When the sequencer is defined in the same file as the algorithms that the top selection depends on, one cannot get these algorithms without also instantiating the top algorithm plus the sequencer. This is not a big problem, but it seems unnecessary.
Changed:
<
<
This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in three classes) uses python concepts to address these issues.
>
>
This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in four simple python classes) uses python concepts to address these issues.
 

Concepts

Line: 22 to 22
 This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in two classes, Selection and AutomaticData (also known as DataOnDemand, see below).

SelectionSequence

Changed:
<
<
A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.
>
>
A SelectionSequence is a model of an entity that contains all the necessary Selections needed for a selection chain to work, and exports these in a correctly ordered and configured GaudiSequencer via the method sequence(). It also makes the output locations of the data written by the head of the decay chain available via the outputLocations() method. There are two implementations of the SelectionSequence.
  • The SelectionSequence class is a python entity that, given a single Selection instance (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a GaudiAlgorithm with all the necessary algorithm Configurables. This can be passed directly to the application manager and are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocations(). The SelectionSequence is the glue that sticks the Sequence building blocks together. * The MultiSelectionSequence class is a python entity that is instantiated from an arbitrary number of SelectionSequences. It's sequence() method returns a GaudiSequencer with the sequences of its component SelectionSequences in OR mode. This is used to run a selection which is the OR of a series of independent Selections.
 

Modules

Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changed a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
Changed:
<
<

The new classes

>
>

The Selection "framework" classes

 To get information on the building block classes, Selection and DataOnDemand, and the glue class, SelectionSequence, it is simplest to look at the python documentation: %SYNTAX{ syntax="python"}% # set some environment that gives us the necessary $PYTHON_PATH SetupProject DaVinci v24r2p3 python
Changed:
<
<
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand
>
>
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand, AutomaticData, MultiSelectionSequence
 >>> help(Selection)
>>> help(SelectionSequence)
Changed:
<
<
>>> help(DataOnDemand)
>
>
>>> help(DataOnDemand) # same as AutomaticData
>>> help(MultiSelectionSequence)
 %ENDSYNTAX%

Examples

Changed:
<
<
There are a few working examples in CVS,
>
>
There are a many working examples in CVS,
 
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer (in ANALYSIS project)
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
Line: 173 to 176
 dv.UserAlgorithms = [ conf.sequence() ] %ENDSYNTAX%
Changed:
<
<
This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.
>
>
This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst. It is possible to use a MultiSelectionSequence to make a single MicroDST with an OR of the two selections above:

<!-- SyntaxHighlightingPlugin -->
...
from BsSelections.Sequences import SeqMyBs1 as selSeq1
from PhysSelPython.Wrappers import MultiSelectionSequence
multiSeq = MultiSelectionSequence('Seq0orSeq1', Sequences = [selSeq0, selSeq1])
conf = MicroDSTWriter()
...
conf.SelectionSequences = [multiSeq]
...
<!-- end SyntaxHighlightingPlugin -->
 

Making a StrippingLine

Creating a StrippingLine is very straight-forward. We first create a Selection, as shown in the examples above:

Revision 182010-05-09 - unknown

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

Particle selections

Line: 19 to 19
 

Concepts

Selection

Changed:
<
<
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in two classes, Selection and DataOnDemand (see below).
>
>
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in two classes, Selection and AutomaticData (also known as DataOnDemand, see below).
 

SelectionSequence

A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.
Line: 58 to 58
 from Configurables import FilterDesktop

# Wrap StdLooseMuons

Changed:
<
<
SelStdLooseMuons = DataOnDemand('SelStdLooseMuons', Location = 'Phys/StdLooseMuons')
>
>
SelStdLooseMuons = DataOnDemand(Location = 'Phys/StdLooseMuons')
  _MyJpsi = FilterDesktop('MyJpsi')

Revision 172010-02-26 - unknown

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

Particle selections

Line: 176 to 176
 This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.

Making a StrippingLine

Added:
>
>
Creating a StrippingLine is very straight-forward. We first create a Selection, as shown in the examples above:
 %SYNTAX{syntax="python"}%
Changed:
<
<
_muons = DataOnDemand( ... )
>
>
 _Jpsi = CombineParticles("", ...)
Added:
>
>
_muons = DataOnDemand( ... )
 
Added:
>
>
# create the selection
 Jpsi = Selection( "Sel"+name, Algorithm = _Jpsi, RequiredSelections = [ _muons ] )
Added:
>
>
%ENDSYNTAX%
 
Added:
>
>
For versions of DaVinci greater or equal to v25r1 it is possible to pass the Selection as a constructor argument:
<!-- SyntaxHighlightingPlugin -->
line = StrippingLine('JpsiInclusive'
                    , prescale = 1.
                    , algos = [ Jpsi ] )
<!-- end SyntaxHighlightingPlugin -->

For older versions, it is necessary to build a SelectionSequence:

%SYNTAX{syntax="python"}%

 # build the SelectionSequence sequence = SelectionSequence("Seq"+name, TopSelection = Jpsi
Line: 194 to 209
  , algos = [ sequence ] )

%ENDSYNTAX%

Changed:
<
<
-- JuanPalacios - 2009-10-02
>
>
Beware that passing more than one Selection or SelectionSequence to the StrippingLine's algos argument is not a well defined operation and should not be done.

-- JuanPalacios - 26-Feb-2010

  |*META PREFERENCE*|name="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" title="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" type="Set" value="
"|

Revision 162009-11-24 - AnatolySolomin

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

Particle selections

Line: 42 to 42
 

Examples

There are a few working examples in CVS,
Changed:
<
<
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer
>
>
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer (in ANALYSIS project)
 
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
  • PhysSel/Ccbar/python/Ccbar.
  • Phys/StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for StrippingBs2JpsiPhi*.py). Phys/StrippingSelections/python/StrippingSelections/StreamBMuon shows how a StrippingStream is made out of them.

Revision 152009-11-24 - AnatolySolomin

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

Particle selections

Introduction

Changed:
<
<
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
>
>
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, which is part of the ANALYSIS project, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
 

Motivation

In most cases GaudiSequencers are full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:

Revision 142009-11-24 - AnatolySolomin

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

Particle selections

Line: 45 to 45
 
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
  • PhysSel/Ccbar/python/Ccbar.
Changed:
<
<
  • Phys/StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for StrippingBs2JpsiPhi*.py). Phys/StrippingSelections/python/StrippingSelections/StreamBMuon shows how a StrippingStream is made out of them.
>
>
  • Phys/StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for StrippingBs2JpsiPhi*.py). Phys/StrippingSelections/python/StrippingSelections/StreamBMuon shows how a StrippingStream is made out of them.
  In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!
Line: 75 to 75
 Note that the InputLocations of the FilterDesktop are not set. These are set by the Selection constructor, and are taken from the RequiredSelections arguments.

Building a selection algorithm that uses other selection algorithms

Changed:
<
<
Here, we build a Selection that takes as input particles from two Selections previously defined as described above. Assume that a selection MyPhi has been written in a similar way to MyJpsi, in MyPsi.py, module PhiSelections.
>
>
Here, we build a Selection that takes as input particles from two Selections previously defined as described above. Assume that a selection MyPhi has been written in a similar way to MyJpsi in MyPsi.py, in module PhiSelections.
  %SYNTAX{ syntax="python"}% import SystemOfUnits as Units

Revision 132009-11-24 - unknown

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

Particle selections

Line: 44 to 44
 
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
Changed:
<
<
  • Phys/StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for Bs2JpsiPhi*.py). Phys/StrippingSelections/options/StrippingBs2JpsiPhi*.py are examples of how to add them to the stripping.
>
>
  • PhysSel/Ccbar/python/Ccbar.
  • Phys/StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for StrippingBs2JpsiPhi*.py). Phys/StrippingSelections/python/StrippingSelections/StreamBMuon shows how a StrippingStream is made out of them.
  In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!

Revision 122009-11-24 - AnatolySolomin

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

Particle selections

Line: 19 to 19
 

Concepts

Selection

Changed:
<
<
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run previously. It is expressed in two classes, Selection and DataOnDemand (see below).
>
>
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run beforehand. It is expressed in two classes, Selection and DataOnDemand (see below).
 

SelectionSequence

A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.
Line: 44 to 44
 
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
Changed:
<
<
  • StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for Bs2JpsiPhi*.py. StrippingSelections/options/StrippingBs2JpsiPhi*.py are examples of how to add them to the stripping.
>
>
  • Phys/StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for Bs2JpsiPhi*.py). Phys/StrippingSelections/options/StrippingBs2JpsiPhi*.py are examples of how to add them to the stripping.
  In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!

Revision 112009-11-20 - unknown

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

Particle selections

Line: 175 to 175
 This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.

Making a StrippingLine

Added:
>
>
%SYNTAX{syntax="python"}% _muons = DataOnDemand( ... ) _Jpsi = CombineParticles("", ...)

Jpsi = Selection( "Sel"+name, Algorithm = _Jpsi, RequiredSelections = [_muons] )

# build the SelectionSequence sequence = SelectionSequence("Seq"+name, TopSelection = Jpsi ) # Define the line line = StrippingLine('JpsiInclusive' , prescale = 1. , algos = [ sequence ] )

 
Added:
>
>
%ENDSYNTAX%
 -- JuanPalacios - 2009-10-02

|*META PREFERENCE*|name="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" title="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" type="Set" value="

"|

Revision 102009-11-09 - AnatolySolomin

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

Particle selections

Line: 25 to 25
 A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.

Modules

Changed:
<
<
Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changes a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
>
>
Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changed a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
 

The new classes

To get information on the building block classes, Selection and DataOnDemand, and the glue class, SelectionSequence, it is simplest to look at the python documentation:

Revision 92009-11-09 - AnatolySolomin

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

Particle selections

Introduction

Changed:
<
<
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
>
>
This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
 

Motivation

Changed:
<
<
In most cases GaudiSequencers full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:
>
>
In most cases GaudiSequencers are full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:
 
  • The need to know the location of the file defining the GaudiSequencer. Normally this requires having certain environment variables set.
  • The need to know the name of the sequencer, so it can be grabbed and added to the application manager.
Line: 19 to 19
 

Concepts

Selection

Changed:
<
<
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run previously. It is expressed in two classes, Selection and DataOnDemand (see below).
>
>
This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run previously. It is expressed in two classes, Selection and DataOnDemand (see below).
 
Changed:
<
<

SelectionSequence

A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.
>
>

SelectionSequence

A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.
 

Modules

Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changes a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
Line: 44 to 44
 
  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
Changed:
<
<
  • StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhy selections (search for Bs2jpsiPhi*.py. StrippingSelections/options/StrippingBs2JpsiPhi*.py are examples of how to add them to the stripping.
>
>
  • StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhi selections (search for Bs2JpsiPhi*.py. StrippingSelections/options/StrippingBs2JpsiPhi*.py are examples of how to add them to the stripping.
  In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!
Line: 122 to 122
 SeqMyBs = SelectionSequence("SeqMyBs", TopSelection = SelMyBs, EventPreSelector = [ prescale ]) %ENDSYNTAX%
Changed:
<
<

Bringing it all together: grabbing the sequencer and adding it to a DaVinci configurable.

It is very easy to get the sequence from the modules where the SelectionSequence has been written and add it to the DaVinci configurable's main sequence:
>
>

Bringing it all together: grabbing the sequencer and adding it to a DaVinci configurable.

It is very easy to get the sequence from the modules where the SelectionSequence has been written and add it to the DaVinci configurable's main sequence:
  %SYNTAX{ syntax="python"}% from BsSelections.Sequences import SeqMyBs as theSequence
Line: 149 to 149
 DaVinci().UserAlgorithms = [ SeqMyBs.sequence() ] %ENDSYNTAX%
Changed:
<
<

Making a MicroDST

It is equally trivial to use the SelectionSequence to make a MicroDST without explicitly knowing the names of any algorithms:
>
>

Making a MicroDST

It is equally trivial to use the SelectionSequence to make a MicroDST without explicitly knowing the names of any algorithms:
 %SYNTAX{syntax="python"}% from Gaudi.Configuration import * from Configurables import DaVinci, MicroDSTWriter
Line: 174 to 174
  This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.
Changed:
<
<

Making a StrippingLine

>
>

Making a StrippingLine

  -- JuanPalacios - 2009-10-02

Revision 82009-10-21 - PatrickSKoppenburg

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

Particle selections

Line: 29 to 29
 

The new classes

To get information on the building block classes, Selection and DataOnDemand, and the glue class, SelectionSequence, it is simplest to look at the python documentation:
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 # set some environment that gives us the necessary $PYTHON_PATH SetupProject DaVinci v24r2p3 python
Line: 37 to 37
 >>> help(Selection)
>>> help(SelectionSequence)
>>> help(DataOnDemand)
Changed:
<
<
>
>
%ENDSYNTAX%
 

Examples

There are a few working examples in CVS,
Line: 51 to 51
 

Building a simple selection algorithm using standard input particles

Here, we will build a J/Psi Selection algorithm that only requires some standard muons, which are available on-demand. Assume this selection is called MyJpsi.py and is in python module JpsiSelections. The standard muons have to be wrapped with the DataOnDemand class, which mimicks a Selection.
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 import SystemOfUnits as Units from Gaudi.Configuration import * from Configurables import FilterDesktop
Line: 69 to 69
 from PhysSelPython.Wrappers import Selection

SelMyJpsi = Selection("SelMyJpsi", Algorithm=_MyJpsi, RequiredSelections = [SelStdLooseMuons] )

Changed:
<
<
>
>
%ENDSYNTAX%
  Note that the InputLocations of the FilterDesktop are not set. These are set by the Selection constructor, and are taken from the RequiredSelections arguments.

Building a selection algorithm that uses other selection algorithms

Here, we build a Selection that takes as input particles from two Selections previously defined as described above. Assume that a selection MyPhi has been written in a similar way to MyJpsi, in MyPsi.py, module PhiSelections.
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 import SystemOfUnits as Units from Gaudi.Configuration import * from Configurables import CombineParticles
Line: 98 to 97
 from PhysSelPython.Wrappers import Selection

SelMyBs = Selection("SelMyBs", Algorithm = _MyBs, RequiredSelections = [SelMyJpsi, SelMyPhi] )

Changed:
<
<
>
>
%ENDSYNTAX%
  The Selection class will use the Selection.algName() method of each of the RequiredSelections to set the InputLocations of MyBs, and will store the Selections, such that they can be used to build a sequencer that can run all the algorithms necessary for the selection.

Building a sequencer

Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 # define what we get in case from import * all = ( 'SeqMyBs',)

from MyBs import SelMyBs from PhysSelPython.Wrappers import SelectionSequence SeqMyBs = SelectionSequence("SeqMyBs", TopSelection = SelMyBs)

Changed:
<
<
>
>
%ENDSYNTAX%
 

Prescales

Any additional algorithms can be pre-pendeded to the sequence using EventPreSelector (array). Typically to add a prescale:
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 from Configurables import DeterministicPrescaler prescale = DeterministicPrescaler("MyPrescale", AcceptFraction = 0.1) SeqMyBs = SelectionSequence("SeqMyBs", TopSelection = SelMyBs, EventPreSelector = [ prescale ])
Changed:
<
<
>
>
%ENDSYNTAX%
 

Bringing it all together: grabbing the sequencer and adding it to a DaVinci configurable.

It is very easy to get the sequence from the modules where the SelectionSequence has been written and add it to the DaVinci configurable's main sequence:
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 from BsSelections.Sequences import SeqMyBs as theSequence MySelection = theSequence.sequence() dv = DaVinci()
Line: 136 to 133
 dv.EvtMax = 500 dv.UserAlgorithms = [MySelection] dv.Input = [...]
Changed:
<
<
>
>
%ENDSYNTAX%
  There's an added advantage: it is also possible to add to the sequence another analysis DVAlgorithm, taking as input particles from the main selection in the sequence, without knowing the name of the main selection algorithm:
Changed:
<
<
>
>
%SYNTAX{ syntax="python"}%
 from BsSelections.Sequences import SeqMyBs from Configurables import SomeDVAlgoType myUserAlgo = SomeDVAlgoType('MyUserAlgo')
Line: 150 to 147
 SeqMyBs.Members += [ myUserAlgo ] # add SeqMyBs' GaudiSequencer to DaVinci configurable DaVinci().UserAlgorithms = [ SeqMyBs.sequence() ]
Changed:
<
<
>
>
%ENDSYNTAX%
 

Making a MicroDST

It is equally trivial to use the SelectionSequence to make a MicroDST without explicitly knowing the names of any algorithms:
Line: 181 to 177
 

Making a StrippingLine

-- JuanPalacios - 2009-10-02

Added:
>
>
|*META PREFERENCE*|name="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" title="SYNTAXHIGHLIGHTINGPLUGIN_FORMAT_PREPEND" type="Set" value="
"|

Revision 72009-10-21 - PatrickSKoppenburg

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

Particle selections

Line: 119 to 117
 
Added:
>
>

Prescales

Any additional algorithms can be pre-pendeded to the sequence using EventPreSelector (array). Typically to add a prescale:
from Configurables import DeterministicPrescaler
prescale =  DeterministicPrescaler("MyPrescale", AcceptFraction = 0.1)
SeqMyBs = SelectionSequence("SeqMyBs", TopSelection = SelMyBs,  EventPreSelector = [ prescale ])
 

Bringing it all together: grabbing the sequencer and adding it to a DaVinci configurable.

It is very easy to get the sequence from the modules where the SelectionSequence has been written and add it to the DaVinci configurable's main sequence:

Revision 62009-10-19 - unknown

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

Particle selections

Line: 148 to 148
 

Making a MicroDST

It is equally trivial to use the SelectionSequence to make a MicroDST without explicitly knowing the names of any algorithms:
Changed:
<
<
>
>
%SYNTAX{syntax="python"}%
 from Gaudi.Configuration import * from Configurables import DaVinci, MicroDSTWriter
Line: 166 to 166
 dv = DaVinci() dv.DataType = 'DC06' dv.EvtMax = 500
Changed:
<
<
dv.UserAlgorithms = [ selSeq.sequence() ]
>
>
dv.UserAlgorithms = [ conf.sequence() ]
 
Changed:
<
<
>
>
%ENDSYNTAX%
  This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.

Revision 52009-10-02 - unknown

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

Particle selections

Line: 6 to 6
 This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.

Motivation

Changed:
<
<
In most cases GaudiSequencers full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:
>
>
In most cases GaudiSequencers full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:
 
  • The need to know the location of the file defining the GaudiSequencer. Normally this requires having certain environment variables set.
  • The need to know the name of the sequencer, so it can be grabbed and added to the application manager.
Line: 14 to 14
 
  • The need to look at the file (or files imported to it via importOptions) to get information about, for example, the cuts applied.
  • When the sequencer is defined in the same file as the algorithms that the top selection depends on, one cannot get these algorithms without also instantiating the top algorithm plus the sequencer. This is not a big problem, but it seems unnecessary.
Added:
>
>
This is an absurd and error-prone situation. The selection "framework" (it is really two concepts expressed in three classes) uses python concepts to address these issues.

Concepts

Selection

This is the building block of the framework. A Selection is a python entity that uses other Selections to build particles and write them to a TES location. The TES location is exported to the user via the outputLocation() method, and the Selections needed via the RequiredSelections field. In itself, it does nothing, since it relies on its required selections to be run previously. It is expressed in two classes, Selection and DataOnDemand (see below).

SelectionSequence

A SelectionSequence is a python entity that, given a Selection (refered to as "top selection" from now on), recursively iterates through all the RequiredSelections to create an ordered list of all the Selections that must be run. It creates a list of algorithm Configurables that can be passed directly to the application manager. These are accessible via the method sequence(). The output TES location of the top selection is available via the method outputLocation(). It is expressed in the SelectionSequence class (see below). The SelectionSequence is the glue that sticks the Sequence building blocks together.

Modules

Instances of the above can be defined in python modules, such that they can be re-used in other modules or directly in scripts. The module structure can be used to reflect the nature of the selections (for example, one can easily guess what StrippingSelections.FredsCrazyBs2JpsiPhi.Phi or OfflineSelections.PrescaledJps2MuMu.Jpsi could mean). Furthermore, python documentation tools can be used to provide information about the details of each component of a selection. There is currently no convention on how to set up the "raw" modules, but this can be changes a posteriory by use of master modules that import different components of the "raw" ones. Therefore, do not pay too much attention to the module structure in the examples below, for they are just one way of doing things.
 

The new classes

Changed:
<
<
There are two building block classes, Selection and DataOnDemand, and a further glue class, SelectionSequence, that puts the building blocks together to make a self-contained selection. To get information about these, it is simplest to look at the python documentation:
>
>
To get information on the building block classes, Selection and DataOnDemand, and the glue class, SelectionSequence, it is simplest to look at the python documentation:
 
# set some environment that gives us the necessary $PYTHON_PATH
SetupProject DaVinci v24r2p3
Line: 69 to 82
 from Gaudi.Configuration import * from Configurables import CombineParticles
Added:
>
>
# define what we get in case from import * all = ( 'SelMyBs')
 _MyBs = CombineParticles('MyBs') _MyBs.DecayDescriptor = "B_s0 -> J/psi(1S) phi(1020)"
Line: 91 to 107
 Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.
Added:
>
>
# define what we get in case from import * all = ( 'SeqMyBs',)
 from MyBs import SelMyBs

from PhysSelPython.Wrappers import SelectionSequence

Line: 120 to 140
 myUserAlgo = SomeDVAlgoType('MyUserAlgo') # explicit path is either '/Event/Phys/'+ SeqMyBs.algName() # or 'Event/Hlt/'+ SeqMyBs.algName()
Changed:
<
<
myUserAlgo.InputLocations = [ SeqMyBs.algName() ]
>
>
myUserAlgo.InputLocations = [ SeqMyBs.outputLocation() ]
 SeqMyBs.Members += [ myUserAlgo ] # add SeqMyBs' GaudiSequencer to DaVinci configurable DaVinci().UserAlgorithms = [ SeqMyBs.sequence() ]
Line: 152 to 172
  This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.
Changed:
<
<
-- JuanPalacios - 21 Jul 2009
>
>

Making a StrippingLine

-- JuanPalacios - 2009-10-02

Revision 42009-10-02 - unknown

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

Particle selections

Introduction

This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.
Added:
>
>

Motivation

In most cases GaudiSequencers full of algorithms, with each algorithm requiring data from and providing data to others. Currently, these are defined in one or more .py files, which are obtained via importOptions. These are no more than glorified .opts files, and they share many of their disadvantages:

  • The need to know the location of the file defining the GaudiSequencer. Normally this requires having certain environment variables set.
  • The need to know the name of the sequencer, so it can be grabbed and added to the application manager.
  • The need to know which one of the algorithms in the sequencer is the one writing the data out, i.e. the one performing the selection we care about.
  • The need to look at the file (or files imported to it via importOptions) to get information about, for example, the cuts applied.
  • When the sequencer is defined in the same file as the algorithms that the top selection depends on, one cannot get these algorithms without also instantiating the top algorithm plus the sequencer. This is not a big problem, but it seems unnecessary.
 

The new classes

Changed:
<
<
Under construction. Try, using DaVinci v23r3p1 or newer,
>
>
There are two building block classes, Selection and DataOnDemand, and a further glue class, SelectionSequence, that puts the building blocks together to make a self-contained selection. To get information about these, it is simplest to look at the python documentation:
 
Added:
>
>
# set some environment that gives us the necessary $PYTHON_PATH SetupProject DaVinci v24r2p3
 python
Changed:
<
<
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence
>
>
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand
 >>> help(Selection)
>>> help(SelectionSequence)
Added:
>
>
>>> help(DataOnDemand)
 

Examples

Changed:
<
<
There are currently two working examples in CVS, see Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r8 or newer, and PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer. In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!
>
>
There are a few working examples in CVS,

  • Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r10 or newer
  • PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer.
  • StrippingSelections/python/StrippingSelections has working examples for three different Bs2JpsiPhy selections (search for Bs2jpsiPhi*.py. StrippingSelections/options/StrippingBs2JpsiPhi*.py are examples of how to add them to the stripping.

In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!

 

Building a simple selection algorithm using standard input particles

Here, we will build a J/Psi Selection algorithm that only requires some standard muons, which are available on-demand. Assume this selection is called MyJpsi.py and is in python module JpsiSelections. The standard muons have to be wrapped with the DataOnDemand class, which mimicks a Selection.
Line: 26 to 44
 from Configurables import FilterDesktop

# Wrap StdLooseMuons

Changed:
<
<
SelStdLooseMuons = DataOnDemand('SelStdLooseMuons', Location = 'StdLooseMuons')
>
>
SelStdLooseMuons = DataOnDemand('SelStdLooseMuons', Location = 'Phys/StdLooseMuons')
 
Changed:
<
<
MyJpsi = FilterDesktop('MyJpsi')
>
>
_MyJpsi = FilterDesktop('MyJpsi')
 
Changed:
<
<
MyJpsi.Code = " (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0)"
>
>
_MyJpsi.Code = " (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0)"
  "& (MINTREE('mu+'==ABSID, PIDmu) > -5.0)" "& (MAXTREE('mu+'==ABSID, PIDK) < 5.0)" "& (ADMASS('J/psi(1S)') < 42.*MeV)"

from PhysSelPython.Wrappers import Selection

Changed:
<
<
SelMyJpsi = Selection("SelMyJpsi", Algorithm=MyJpsi, RequiredSelections = [SelStdLooseMuons] )
>
>
SelMyJpsi = Selection("SelMyJpsi", Algorithm=_MyJpsi, RequiredSelections = [SelStdLooseMuons] )
 
Line: 51 to 69
 from Gaudi.Configuration import * from Configurables import CombineParticles
Changed:
<
<
MyBs = CombineParticles('MyBs') DecayDescriptor = "B_s0 -> J/psi(1S) phi(1020)"
>
>
_MyBs = CombineParticles('MyBs') _MyBs.DecayDescriptor = "B_s0 -> J/psi(1S) phi(1020)"
 
Changed:
<
<
CombinationCut = "ADAMASS('B_s0') < 600.*MeV" MotherCut = "(VFASPF(VCHI2/VDOF)<5.) & (BPVIPCHI2() < 10.)" ReFitPVs = True
>
>
_MyBs.CombinationCut = "ADAMASS('B_s0') < 600.*MeV" _MyBs.MotherCut = "(VFASPF(VCHI2/VDOF)<5.) & (BPVIPCHI2() < 10.)" _MyBs.ReFitPVs = True
  from MyJpsi import SelMyJpsi from MyPhi import SelMyPhi

from PhysSelPython.Wrappers import Selection

Changed:
<
<
SelMyBs = Selection("SelMyBs", Algorithm = MyBs, RequiredSelections = [SelMyJpsi, SelMyPhi] )
>
>
SelMyBs = Selection("SelMyBs", Algorithm = _MyBs, RequiredSelections = [SelMyJpsi, SelMyPhi] )
 

Revision 32009-08-12 - JuanPalacios

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

Particle selections

Line: 18 to 18
 There are currently two working examples in CVS, see Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r8 or newer, and PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer. In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!

Building a simple selection algorithm using standard input particles

Changed:
<
<
Here, we will build a J/Psi Selection algorithm that only requires some standard muons, which are available on-demand. Assume this selection is called MyJpsi.py and is in python module JpsiSelections
>
>
Here, we will build a J/Psi Selection algorithm that only requires some standard muons, which are available on-demand. Assume this selection is called MyJpsi.py and is in python module JpsiSelections. The standard muons have to be wrapped with the DataOnDemand class, which mimicks a Selection.
 
import GaudiKernel.SystemOfUnits as Units
from Gaudi.Configuration import *
from Configurables import FilterDesktop
Added:
>
>
# Wrap StdLooseMuons SelStdLooseMuons = DataOnDemand('SelStdLooseMuons', Location = 'StdLooseMuons')
 MyJpsi = FilterDesktop('MyJpsi')

MyJpsi.Code = " (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0)"

Line: 34 to 37
  from PhysSelPython.Wrappers import Selection
Changed:
<
<
SelMyJpsi = Selection(MyJpsi, requiredSelections = ['StdLooseMuons'] )
>
>
SelMyJpsi = Selection("SelMyJpsi", Algorithm=MyJpsi, RequiredSelections = [SelStdLooseMuons] )
 
Changed:
<
<
Note two things:
  1. The InputLocations of the FilterDesktop are not set. These are set by the Selection constructor, and are taken from the requiredSelections arguments.
  2. When a requiredSelection is a string, it is assumed that he particles required can be obtained from the DataOnDemandSvc.
>
>
Note that the InputLocations of the FilterDesktop are not set. These are set by the Selection constructor, and are taken from the RequiredSelections arguments.
 

Building a selection algorithm that uses other selection algorithms

Here, we build a Selection that takes as input particles from two Selections previously defined as described above. Assume that a selection MyPhi has been written in a similar way to MyJpsi, in MyPsi.py, module PhiSelections.
Line: 62 to 63
  from PhysSelPython.Wrappers import Selection
Changed:
<
<
SelMyBs = Selection(MyBs, requiredSelections = [SelMyJpsi, SelMyPhi] )
>
>
SelMyBs = Selection("SelMyBs", Algorithm = MyBs, RequiredSelections = [SelMyJpsi, SelMyPhi] )
 
Changed:
<
<
Note that here the requiredSelections are Selections, not strings. The Selection class will use the names of the algorithms used to make those selections to set the InputLocations of MyBs, and will store the Selections, such that they can be used to build a sequencer that can run all the algorithms necessary for the selection.
>
>
The Selection class will use the Selection.algName() method of each of the RequiredSelections to set the InputLocations of MyBs, and will store the Selections, such that they can be used to build a sequencer that can run all the algorithms necessary for the selection.
 

Building a sequencer

Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.
Line: 76 to 77
  from PhysSelPython.Wrappers import SelectionSequence
Changed:
<
<
SeqMyBs = SelectionSequence(SelMyBs)
>
>
SeqMyBs = SelectionSequence("SeqMyBs", TopSelection = SelMyBs)
 
Line: 96 to 97
 There's an added advantage: it is also possible to add to the sequence another analysis DVAlgorithm, taking as input particles from the main selection in the sequence, without knowing the name of the main selection algorithm:
Changed:
<
<
from BsSelections.Sequences import SeqMyBs as theSequence MySelection = theSequence.sequence()
>
>
from BsSelections.Sequences import SeqMyBs
 from Configurables import SomeDVAlgoType myUserAlgo = SomeDVAlgoType('MyUserAlgo')
Changed:
<
<
# explicit path is either '/Event/Phys/'+theSequence.topAlgName() # or 'Event/Hlt/'+ theSequence.topAlgName() myUserAlgo.InputLocations = [theSequence.topAlgName()] MySelection.Members += [myUserAlgo]
>
>
# explicit path is either '/Event/Phys/'+ SeqMyBs.algName() # or 'Event/Hlt/'+ SeqMyBs.algName() myUserAlgo.InputLocations = [ SeqMyBs.algName() ] SeqMyBs.Members += [ myUserAlgo ] # add SeqMyBs' GaudiSequencer to DaVinci configurable DaVinci().UserAlgorithms = [ SeqMyBs.sequence() ]
 

Making a MicroDST

It is equally trivial to use the SelectionSequence to make a MicroDST without explicitly knowing the names of any algorithms:
from Gaudi.Configuration import *
Changed:
<
<
from Configurables import DaVinci, PhysMicroDST
>
>
from Configurables import DaVinci, MicroDSTWriter
 
Changed:
<
<
from BsSelections.Sequences import SeqMyBs as theSequence MySelection = theSequence.sequence()
>
>
from BsSelections.Sequences import SeqMyBs0 as selSeq0 from BsSelections.Sequences import SeqMyBs1 as selSeq1
 
Changed:
<
<
conf = PhysMicroDST()
>
>
conf = MicroDSTWriter()
 conf.OutputPrefix = "MicroDST"
Changed:
<
<
conf.MicroDSTFile = "MyTestMDST.mdst" conf.MicroDSTSelectionAlg = theSequence.algo
>
>
conf.OutputFilePrefix = "Test" conf.SelectionSequences = [selSeq0, selSeq1]
 conf.CopyL0DUReport = False conf.CopyHltDecReports = False conf.CopyMCTruth = True
Line: 126 to 128
 dv = DaVinci() dv.DataType = 'DC06' dv.EvtMax = 500
Changed:
<
<
dv.UserAlgorithms = [MySelection]
>
>
dv.UserAlgorithms = [ selSeq.sequence() ]
 
Added:
>
>
This should result in the creation of two MicroDSTs, TestSeqMyBs0.mdst and TestSeqMyBs1.mdst.
 -- JuanPalacios - 21 Jul 2009

Revision 22009-07-23 - JuanPalacios

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

Particle selections

Line: 106 to 106
 MySelection.Members += [myUserAlgo]
Added:
>
>

Making a MicroDST

It is equally trivial to use the SelectionSequence to make a MicroDST without explicitly knowing the names of any algorithms:
from Gaudi.Configuration import *
from Configurables import DaVinci, PhysMicroDST

from BsSelections.Sequences import SeqMyBs as theSequence
MySelection = theSequence.sequence()

conf = PhysMicroDST()
conf.OutputPrefix = "MicroDST"
conf.MicroDSTFile = "MyTestMDST.mdst"
conf.MicroDSTSelectionAlg = theSequence.algo
conf.CopyL0DUReport = False
conf.CopyHltDecReports = False
conf.CopyMCTruth = True

dv = DaVinci()
dv.DataType = 'DC06'
dv.EvtMax = 500
dv.UserAlgorithms = [MySelection]

  -- JuanPalacios - 21 Jul 2009

Revision 12009-07-21 - JuanPalacios

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

Particle selections

Introduction

This wiki explains the use of new python wrapper classes that are intended to simplify both the writing and using of particle selections in DaVinci. The classes are released in the new package PhysSel/PhysSelPython, and are particularly powerful when it comes to building a selection out of other selections. They do away with the need to use importOptions, and hence to know the directories where different selections are located. It also returns to the (python) user useful information and data structures that simplify the use of the selections in a typical DaVinci job, but also in jobs that may analyse the DST or MicroDST output of a DaVinci job. Furthermore, the fact that the selections are written in python modules allows to make use of the inbuilt python documentation framework, so authors of selectors can make the necessary details about a selection available to users in an interactive python environment.

The new classes

Under construction. Try, using DaVinci v23r3p1 or newer,
python
>>> from PhysSelPython.Wrappers import Selection, SelectionSequence
>>> help(Selection)
>>> help(SelectionSequence)

Examples

There are currently two working examples in CVS, see Ex/MicroDSTExample/python/MicroDSTExample/Selections, tag v2r8 or newer, and PhysSel/B2DsX/python/B2DsX, tag jpalac_20090716 or newer. In the following sections, we give examples on how to write a new selection using these python classes. Pay no attention to the actual cuts applied, these are not necessarily good selections!

Building a simple selection algorithm using standard input particles

Here, we will build a J/Psi Selection algorithm that only requires some standard muons, which are available on-demand. Assume this selection is called MyJpsi.py and is in python module JpsiSelections

import GaudiKernel.SystemOfUnits as Units
from Gaudi.Configuration import *
from Configurables import FilterDesktop

MyJpsi = FilterDesktop('MyJpsi')

MyJpsi.Code = "  (MAXTREE('mu+'==ABSID, TRCHI2DOF) < 5.0)" \
             "& (MINTREE('mu+'==ABSID, PIDmu) > -5.0)" \
             "& (MAXTREE('mu+'==ABSID, PIDK) < 5.0)" \
             "& (ADMASS('J/psi(1S)') < 42.*MeV)"

from PhysSelPython.Wrappers import Selection

SelMyJpsi = Selection(MyJpsi, requiredSelections = ['StdLooseMuons'] )

Note two things:

  1. The InputLocations of the FilterDesktop are not set. These are set by the Selection constructor, and are taken from the requiredSelections arguments.
  2. When a requiredSelection is a string, it is assumed that he particles required can be obtained from the DataOnDemandSvc.

Building a selection algorithm that uses other selection algorithms

Here, we build a Selection that takes as input particles from two Selections previously defined as described above. Assume that a selection MyPhi has been written in a similar way to MyJpsi, in MyPsi.py, module PhiSelections.

import GaudiKernel.SystemOfUnits as Units
from Gaudi.Configuration import *
from Configurables import CombineParticles

MyBs = CombineParticles('MyBs')
MyBs.DecayDescriptor = "B_s0 -> J/psi(1S) phi(1020)"

MyBs.CombinationCut = "ADAMASS('B_s0') < 600.*MeV"
MyBs.MotherCut = "(VFASPF(VCHI2/VDOF)<5.) & (BPVIPCHI2() < 10.)"
MyBs.ReFitPVs = True

from JpsiSelections.MyJpsi import SelMyJpsi
from PhiSelections.MyPhi import SelMyPhi

from PhysSelPython.Wrappers import Selection

SelMyBs = Selection(MyBs, requiredSelections = [SelMyJpsi, SelMyPhi] )

Note that here the requiredSelections are Selections, not strings. The Selection class will use the names of the algorithms used to make those selections to set the InputLocations of MyBs, and will store the Selections, such that they can be used to build a sequencer that can run all the algorithms necessary for the selection.

Building a sequencer

Finally, we can use the SelectionSequencer class to put together a valid GaudiSequencer that can then be used to feed to an application configurable. This is a trivial step, since all the necessary information about all selections required is accessible from the top selection.

from BsSelections.MyBs import SelMyBs

from PhysSelPython.Wrappers import SelectionSequence

SeqMyBs = SelectionSequence(SelMyBs)

Bringing it all together: grabbing the sequencer and adding it to a DaVinci configurable.

It is very easy to get the sequence from the modules where the SelectionSequence has been written and add it to the DaVinci configurable's main sequence:

from BsSelections.Sequences import SeqMyBs as theSequence
MySelection = theSequence.sequence()
dv = DaVinci()
dv.DataType = 'DC06'
dv.EvtMax = 500
dv.UserAlgorithms = [MySelection]
dv.Input =  [...]

There's an added advantage: it is also possible to add to the sequence another analysis DVAlgorithm, taking as input particles from the main selection in the sequence, without knowing the name of the main selection algorithm:

from BsSelections.Sequences import SeqMyBs as theSequence
MySelection = theSequence.sequence()
from Configurables import SomeDVAlgoType
myUserAlgo = SomeDVAlgoType('MyUserAlgo')
# explicit path is either '/Event/Phys/'+theSequence.topAlgName() 
# or 'Event/Hlt/'+ theSequence.topAlgName()
myUserAlgo.InputLocations = [theSequence.topAlgName()] 
MySelection.Members += [myUserAlgo]

-- JuanPalacios - 21 Jul 2009

 
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