Skip to content
Snippets Groups Projects
Commit 05bd0b91 authored by Patrick Koppenburg's avatar Patrick Koppenburg :leaves:
Browse files

Merge branch 'erodrigu-pyconf-3' into 'master'

DaVinci based on PyConf - work on structure, enhancements, new modules

See merge request !508
parents 4cf89311 57300cbf
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!508DaVinci based on PyConf - work on structure, enhancements, new modules
Pipeline #2371875 passed
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
Definitions of "common particles" very similar to those of Runs 1 & 2.
"""
from PyConf.tonic import configurable
from PyConf.Algorithms import FunctionalParticleMaker
from PyConf.Algorithms import LHCb__Phys__ParticleMakers__PhotonMaker as PhotonMaker
from .reco_objects import make_charged_protoparticles as _make_charged_protoparticles
from .reco_objects import make_neutral_protoparticles as _make_neutral_protoparticles
from .reco_objects import make_pvs as _make_pvs
from .selectors import default_particle_cuts, default_track_cuts
from .selectors import get_long_track_selector, get_down_track_selector
from .filters import all_protoparticle_filter as standard_protoparticle_filter
from .algorithms_pyconf import ParticleFilterWithPVs, ParticleCombinerWithPVs
#########
# Helpers
#########
@configurable
def _make_particles(species,
make_protoparticles=_make_charged_protoparticles,
get_track_selector=get_long_track_selector,
make_protoparticle_filter=standard_protoparticle_filter):
"""
Helper configurable to create `LHCb::Particle`s from `LHCb::ProtoParticle`s.
Args:
species (str): Particle species hypothesis accepted by
`FunctionalParticleMaker`, i.e. one of the strings
"pion", "kaon", "muon", "electron", "proton".
"""
particles = FunctionalParticleMaker(
ParticleID=species,
InputProtoParticles=make_protoparticles(),
TrackSelector=get_track_selector(),
ProtoParticleFilter=make_protoparticle_filter()).Particles
return particles
@configurable
def make_photons(make_neutral_protoparticles=_make_neutral_protoparticles,
pvs=_make_pvs,
**kwargs):
"""
Configurable to create photon `LHCb::Particle`s from `LHCb::ProtoParticle`s.
"""
particles = PhotonMaker(
InputProtoParticles=make_neutral_protoparticles(),
InputPrimaryVertices=pvs(),
**kwargs).Particles
return particles
def _make_std_loose_particles(particles, pvs, name):
return ParticleFilterWithPVs(
particles, pvs, name=name, Code=default_particle_cuts())
#######################
# Bacic particle makers
#######################
def make_long_pions():
return _make_particles(species="pion")
def make_long_kaons():
return _make_particles(species="kaon")
def make_long_protons():
return _make_particles(species="proton")
def make_long_muons():
return _make_particles(species="muon")
def make_long_electrons_no_brem():
return _make_particles(species="electron")
def make_down_pions():
return _make_particles(
species="pion", get_track_selector=get_down_track_selector)
def make_down_kaons():
return _make_particles(
species="kaon", get_track_selector=get_down_track_selector)
def make_down_protons():
return _make_particles(
species="proton", get_track_selector=get_down_track_selector)
#################################
# Particle makers with loose cuts
#################################
@configurable
def make_std_loose_pions():
with get_long_track_selector.bind(
Code=default_track_cuts()), standard_protoparticle_filter.bind(
Code='PP_HASRICH'):
return _make_std_loose_particles(
make_long_pions(), _make_pvs(), name='StdLoosePions')
@configurable
def make_std_loose_kaons():
with get_long_track_selector.bind(
Code=default_track_cuts()), standard_protoparticle_filter.bind(
Code='PP_HASRICH'):
return _make_std_loose_particles(
make_long_kaons(), _make_pvs(), name='StdLooseKaons')
@configurable
def make_std_loose_protons():
with get_long_track_selector.bind(
Code=default_track_cuts()), standard_protoparticle_filter.bind(
Code='PP_HASRICH'):
return _make_std_loose_particles(
make_long_protons(), _make_pvs(), name='StdLooseProtons')
def make_std_loose_muons():
#with get_long_track_selector.bind(Code=default_track_cuts()):
return _make_std_loose_particles(
make_long_muons(), _make_pvs(), name='StdLooseMuons')
@configurable
def make_std_loose_jpsi2mumu():
muons = make_std_loose_muons()
descriptors = ["J/psi(1S) -> mu+ mu-"]
daughters_code = {"mu+": "ALL", "mu-": "ALL"}
combination_code = "(ADAMASS('J/psi(1S)') < 100.*MeV) & (ADOCACHI2CUT(30,''))"
vertex_code = "(CHI2VX < 25.)"
return ParticleCombinerWithPVs(
name="StdLooseJpsi2MuMu",
particles=muons,
pvs=_make_pvs(),
DecayDescriptors=descriptors,
DaughtersCuts=daughters_code,
CombinationCut=combination_code,
MotherCut=vertex_code)
This diff is collapsed.
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
Definitions of:
- `Particle` and `ProtoParticle` filters.
- Track selectors.
- Default cuts à la runs 1&2 common particles.
"""
from __future__ import absolute_import, division, print_function
from PyConf.tonic import configurable
from PyConf.Tools import LoKi__Hybrid__ProtoParticleFilter as ProtoParticleFilter
from PyConf.Tools import LoKi__Hybrid__TrackSelector as TrackSelector
from .hacks import patched_hybrid_tool
#########################
# Helpers to combine cuts
#########################
def require_all(*cuts):
"""
Return a cut string requiring all (string) arguments.
Example:
>>> require_all('PT > {pt_min}', 'DLLK < {dllk_max}')
'(PT > {pt_min}) & (DLLK < {dllk_max})'
"""
return " & ".join(["({})".format(c) for c in cuts])
def require_any(*cuts):
"""
Return a cut string requiring at least one of the (string) arguments passes.
Example:
>>> require_any('M < 8*GeV', 'PT > 3*GeV')
'(M < 8*GeV) | (PT > 3*GeV)'
"""
return " | ".join(["({})".format(c) for c in cuts])
#######################
# Protoparticle filters
#######################
@configurable
def all_protoparticle_filter(Code="PP_ALL", **kwargs):
"""
Get a `LoKi__Hybrid__ProtoParticleFilter` instance
that by default selects all protoparticles.
Args:
Code (str): The "Code" argument to pass to the filter tool.
Default = "PP_ALL".
kwargs: Keyword arguments accepted by `LoKi__Hybrid__Tool`.
Returns:
`LoKi__Hybrid__ProtoParticleFilter` instance wrapped as a `PyConf.components.Tool`.
"""
return ProtoParticleFilter(
Code=Code, Factory=patched_hybrid_tool("PPFactory"), **kwargs)
#################
# Track selectors
#################
@configurable
def get_all_track_selector(Code="TrALL", **kwargs):
"""
Get a `LoKi__Hybrid__TrackSelector` instance
that by default selects all tracks.
Args:
Code (str): The "Code" argument to pass to the tool.
Default = "TrALL".
kwargs: Keyword arguments accepted by `LoKi__Hybrid__TrackSelector`.
Returns:
`LoKi__Hybrid__TrackSelector` instance wrapped as a `PyConf.components.Tool`.
"""
return TrackSelector(Code=Code, **kwargs)
@configurable
def get_long_track_selector(Code='TrALL', **kwargs):
"""
Get a `LoKi__Hybrid__TrackSelector` instance
that by default selects all long tracks.
Args:
Code (str): The "Code" argument to pass to the tool.
Default = "TrALL & TrLONG".
kwargs: Keyword arguments accepted by `LoKi__Hybrid__TrackSelector`.
Returns:
`LoKi__Hybrid__TrackSelector` instance wrapped as a `PyConf.components.Tool`.
"""
return TrackSelector(Code=require_all("TrLONG", Code), **kwargs)
@configurable
def get_down_track_selector(Code='TrALL', **kwargs):
"""
Get a `LoKi__Hybrid__TrackSelector` instance
that by default selects all downstream tracks.
Args:
Code (str): The "Code" argument to pass to the tool.
Default = "TrALL & TrDOWNSTREAM".
kwargs: Keyword arguments accepted by `LoKi__Hybrid__TrackSelector`.
Returns:
`LoKi__Hybrid__TrackSelector` instance wrapped as a `PyConf.components.Tool`.
"""
return TrackSelector(Code=require_all("TrDOWNSTREAM", Code), **kwargs)
@configurable
def get_upstream_track_selector(Code='TrALL', **kwargs):
"""
Get a `LoKi__Hybrid__TrackSelector` instance
that by default selects all upstream tracks.
Args:
Code (str): The "Code" argument to pass to the tool.
Default = "TrALL & TrUPSTREAM".
kwargs: Keyword arguments accepted by `LoKi__Hybrid__TrackSelector`.
Returns:
`LoKi__Hybrid__TrackSelector` instance wrapped as a `PyConf.components.Tool`.
"""
return TrackSelector(Code=require_all("TrUPSTREAM", Code), **kwargs)
#################################
# Default track and particle cuts
#################################
def default_track_cuts():
"""
Return a string with the default track cuts.
"""
return require_all("TrCHI2<5", "~TrCLONE")
def default_particle_cuts():
"""
Return a string with the default particle standard loose cuts.
"""
return require_all("PT>250*MeV", "MIPCHI2DV(PRIMARY)>4.")
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
Definitions of enums specifying the standard locations of
packed and unpacked objects, and various linker tables.
.. note::
These locations are what has been used in Runs 1 & 2,
and may need a revision once the Run 3 event model is finalised
and the definition of what gets persisted gets formalised.
"""
from __future__ import absolute_import, division, print_function
from enum import Enum
class LocationsPackedReco(Enum):
"""
Locations of packed reconstruction objects, stored under "/Event/pRec".
"""
PackedPVs = "/Event/pRec/Vertex/Primary"
PackedCaloElectrons = "/Event/pRec/Calo/Electrons"
PackedCaloPhotons = "/Event/pRec/Calo/Photons"
PackedCaloMergedPi0s = "/Event/pRec/Calo/MergedPi0s"
PackedCaloSplitPhotons = "/Event/pRec/Calo/SplitPhotons"
PackedMuonPIDs = "/Event/pRec/Muon/MuonPID"
PackedRichPIDs = "/Event/pRec/Rich/PIDs"
PackedTracks = "/Event/pRec/Track/Best"
PackedMuonTracks = "/Event/pRec/Track/Muon"
PackedNeutralProtos = "/Event/pRec/ProtoP/Neutrals"
PackedChargedProtos = "/Event/pRec/ProtoP/Charged"
LocationsUnpackedReco = Enum(
"LocationsUnpackedReco",
{e.name: e.value.replace("pRec", "Rec")
for e in LocationsPackedReco})
LocationsUnpackedReco.__doc__ = """
Locations of packed reconstruction objects, stored under "/Event/pRec".
"""
class LocationsPackedSim(Enum):
"""
Locations of packed simulation objects, stored under "/Event/pSim".
"""
PackedMCParticles = "/Event/pSim/MCParticles"
PackedMCVertices = "/Event/pSim/MCVertices"
PackedMCVPHits = "/Event/pSim/VP/Hits"
PackedMCUTHits = "/Event/pSim/UT/Hits"
PackedMCFTHits = "/Event/pSim/FT/Hits"
PackedMCRichHits = "/Event/pSim/Rich/Hits"
PackedMCEcalHits = "/Event/pSim/Ecal/Hits"
PackedMCHcalHits = "/Event/pSim/Hcal/Hits"
PackedMCMuonHits = "/Event/pSim/Muon/Hits"
PackedMCRichDigitSummaries = "/Event/pSim/Rich/DigitSummaries"
class LocationsUnpackedSim(Enum):
"""
Locations of unpacked simulation objects, stored under "/Event/MC".
"""
PackedMCParticles = "/Event/MC/Particles"
PackedMCVertices = "/Event/MC/Vertices"
PackedMCVPHits = "/Event/MC/VP/Hits"
PackedMCUTHits = "/Event/MC/UT/Hits"
PackedMCFTHits = "/Event/MC/FT/Hits"
PackedMCRichHits = "/Event/MC/Rich/Hits"
PackedMCEcalHits = "/Event/MC/Ecal/Hits"
PackedMCHcalHits = "/Event/MC/Hcal/Hits"
PackedMCMuonHits = "/Event/MC/Muon/Hits"
PackedMCRichDigitSummaries = "/Event/MC/Rich/DigitSummaries"
# Location of MCTrackInfo objects
LocationMCTrackInfo = "/Event/MC/TrackInfo"
class LocationsBooleMCParticleLinkers(Enum):
"""
Locations of MC linker tables to MCParticles created by Boole.
"""
EcalDigits = "/Event/Link/Raw/Ecal/Digits"
FTLiteClusters = "/Event/Link/Raw/FT/LiteClusters"
HcalDigits = "/Event/Link/Raw/Hcal/Digits"
MuonDigits = "/Event/Link/Raw/Muon/Digits"
UTClusters = "/Event/Link/Raw/UT/Clusters"
VPDigits = "/Event/Link/Raw/VP/Digits"
class LocationsBooleMCHitsLinkers(Enum):
"""
Locations for MC linker tables to MCHits created by Boole.
These locations are only propagated out of Boole for eXtendend DIGI and DST types.
"""
FTLiteClusters = "/Event/Link/Raw/FT/LiteClusters2MCHits"
UTClusters = "/Event/Link/Raw/UT/Clusters2MCHits"
VPDigits = "/Event/Link/Raw/VP/Digits2MCHits"
class LocationsBrunelMCLinkers(Enum):
"""
Locations of MC linker tables created by Brunel.
"""
CaloElectrons = "/Event/Link/Rec/Calo/Electrons"
CaloMergedPi0s = "/Event/Link/Rec/Calo/MergedPi0s"
CaloPhotons = "/Event/Link/Rec/Calo/Photons"
CaloSplitPhotons = "/Event/Link/Rec/Calo/SplitPhotons"
Tracks = "/Event/Link/Rec/Track/Best"
def enums_as_dict(enums):
"""
Return a {name: value} dict of all enum members.
Example:
>>> class MyEnum(Enum):
a = 1
b = 2
>>> enums_as_dict(MyEnum)
{'a': 1, 'b': 2}
"""
return {e.name: e.value for e in enums}
......@@ -89,7 +89,7 @@ def print_allowed_option_values(allowedValues, name=None):
print(set_color("green") +
"Known job option configurations and allowed values:")
for name, values in allowedValues.iteritems():
print("%s \t : %s" % (name, value), set_color("plain"))
print("%s \t : %s" % (name, values), set_color("plain"))
else:
print(set_color("green") +
"Allowed values for DaVinci option %s:" % name)
......
......@@ -8,11 +8,16 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
Configurables to make the various reconstruction objects from the
packed data on file.
######
### N.B. THIS FILE IS INTENDED TO AVOID DEPENDENCIES ON MOORE,
### IS NEEDED FOR TESTING PURPOSES AND NEEDS TO BE REMOVED IN PRODUCTION
######
.. note::
1) What is defined here relies on data paths used in Runs 1 & 2,
and may need a revision once the Run 3 event model is finalised
and the definition of what gets persisted gets formalised.
2) Code very heavily relies on its Moore equivalent. Thank you, RTA team.
"""
from PyConf import configurable
from .data_from_file import reco_unpackers
......@@ -54,7 +59,8 @@ def make_tracks():
def reconstruction(from_file=True):
"""Return reconstruction objects.
Note it is advised to use this function if more than one object is needed,
Note:
It is advised to use this function if more than one object is needed,
rather than the accessors below as it makes the configuration slower.
"""
# removed reco since it will not be done in DV
......
......@@ -19,18 +19,13 @@ from __future__ import absolute_import, division, print_function
from GaudiKernel.SystemOfUnits import GeV, MeV, mm, picosecond
from PyConf.Algorithms import (
FunctionalParticleMaker,
LHCb__Phys__ParticleMakers__PhotonMaker as PhotonMaker,
LHCb__Phys__ParticleMakers__MergedPi0Maker as MergedPi0Maker,
Proto2ChargedBasic,
)
from PyConf.Tools import (LoKi__Hybrid__ProtoParticleFilter as
ProtoParticleFilter, LoKi__Hybrid__TrackSelector as
TrackSelector)
from PyConf import configurable
from PyConf.Algorithms import (
FunctionalParticleMaker, LHCb__Phys__ParticleMakers__PhotonMaker as
PhotonMaker, LHCb__Phys__ParticleMakers__MergedPi0Maker as MergedPi0Maker,
Proto2ChargedBasic)
from .algorithms_pyconf import (
require_all,
ParticleFilter,
......@@ -40,7 +35,9 @@ from .algorithms_pyconf import (
NeutralParticleCombinerWithPVs,
)
from .hacks import patched_hybrid_tool
from .selectors import get_all_track_selector, get_long_track_selector, get_down_track_selector
from .filters import all_protoparticle_filter as standard_protoparticle_filter
from .reco_objects import (
make_charged_protoparticles as _make_charged_protoparticles, make_pvs as
_make_pvs, make_neutral_protoparticles as _make_neutral_protoparticles)
......@@ -49,32 +46,6 @@ _KAON0_M = 497.611 * MeV # +/- 0.013, PDG, PR D98, 030001 and 2019 update
_LAMBDA_M = 1115.683 * MeV # +/- 0.006, PDG, PR D98, 030001 and 2019 update
@configurable
def get_all_track_selector(Code='TrALL', **kwargs):
return TrackSelector(Code=Code, **kwargs)
@configurable
def get_long_track_selector(Code='TrALL', **kwargs):
return TrackSelector(Code=require_all('TrLONG', Code), **kwargs)
@configurable
def get_down_track_selector(Code='TrALL', **kwargs):
return TrackSelector(Code=require_all('TrDOWNSTREAM', Code), **kwargs)
@configurable
def get_upstream_track_selector(Code='TrALL', **kwargs):
return TrackSelector(Code=require_all('TrUPSTREAM', Code), **kwargs)
@configurable
def standard_protoparticle_filter(Code='PP_ALL', **kwargs):
return ProtoParticleFilter(
Code=Code, Factory=patched_hybrid_tool('PPFactory'), **kwargs)
@configurable
def _make_particles(species,
make_protoparticles=_make_charged_protoparticles,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment