Commit 235add5f authored by Rosen Matev's avatar Rosen Matev
Browse files

Merge branch 'sstahl_Hlt2Reco_newConf' into 'master'

configurations for Hlt1 and Hlt2 track reconstruction

Closes #41 and #33

See merge request lhcb/Moore!199
parents c693e15f 7812dece
###############################################################################
# (c) Copyright 2019 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. #
###############################################################################
from __future__ import absolute_import, division, print_function
import math
from PyConf import configurable
from Hlt1Conf.lines import (
require_all,
require_any,
TrackV1FilterWithPVs,
TrackCombinerWithPVs,
)
from Hlt1Conf.reconstruction import (
gec, RawData, FilterEmptyPVs, make_forward_tracks,
make_param_forward_fitted_tracks, make_pvs, EmptyFilter)
from PyConf.Algorithms import FTRawBankDecoder
from PyConf.components import Algorithm
from PyConf.environment import EverythingHandler
def patch_hybrid_tool():
"""Remove Hybrid modules that require a DVAlgorithm.
Some modules import functors that depend on the DVAlgorithm context being
available. The LoKi::Hybrid::Tool tool loads these modules by default, but
we don't want nor need them, so remove them from the default list.
"""
# List of modules we will delete from the default list
dv_modules = ["LoKiPhys.decorators", "LoKiArrayFunctors.decorators"]
from Configurables import LoKi__Hybrid__Tool
factory = LoKi__Hybrid__Tool("HybridFactory")
for m in dv_modules:
del factory.Modules[factory.Modules.index(m)]
# Add the Track functors as we'll need most of these
# It can be important to include this in the Modules, otherwise the functor
# context patching might not be applied in time (e.g. if a Track functor is
# imported and instantiated in the preamble)
factory.Modules.append('LoKiTrack.decorators')
@configurable
def one_track_MVA(
preambulo=["from GaudiKernel.SystemOfUnits import GeV"],
code=require_all(
"TrCHI2PDOF < {max_trchi2dof}",
# "TrGHOSTPROB < {max_trgp}"
require_any(
require_all("TrPT > {max_pt}", "TrMINIPCHI2 > {min_ipchi2}"),
require_all(
"in_range({min_pt}, TrPT, {max_pt})",
"log(TrMINIPCHI2) > ({param1} / ((TrPT / GeV - {param2}) ** 2) + "
"({param3} / {max_pt}) * ({max_pt} - TrPT) + "
"{log_min_ipchi2})"))).
format(
# TrackMVALoose cuts from ZombieMoore
max_trchi2dof=2.5,
max_trgp=0.2,
min_pt=2000,
max_pt=26000,
min_ipchi2=7.4,
# For some reason, having the `math.log` in the functor string
# itself gives a recursion error
log_min_ipchi2=math.log(7.4),
param1=1.0,
param2=2.0,
param3=1.248),
make_input_tracks=make_param_forward_fitted_tracks,
make_pvs=make_pvs,
):
return TrackV1FilterWithPVs(
Preambulo=preambulo,
Code=code,
Input=make_input_tracks(),
InputVertices=make_pvs()).Output
@configurable
def two_track_MVA(
daughter_cuts=require_all(
"TrPT > {min_track_pt}",
"TrP > {min_track_p}",
"TrCHI2PDOF < {max_track_chi2pdof}",
# "TrGHOSTPROB < {max_track_ghostprob}"
).format(
min_track_pt=500,
min_track_p=3000,
max_track_chi2pdof=3,
max_track_ghostprob=0.2),
CombinationCut=require_all(
"RV_TrNUM(TrMINIPCHI2 > {min_one_track_ipchi2}) > 0",
"RV_PT > {min_vertex_pt}").format(
min_one_track_ipchi2=6, min_vertex_pt=3000),
VertexCut=require_all("VCHI2PDOF < {max_vertex_chi2pdof}").format(
max_vertex_chi2pdof=16),
combiner_preamble=[
"from LoKiPhys.decorators import RV_TrNUM, RV_PT, VCHI2PDOF"
],
make_input_tracks=make_param_forward_fitted_tracks,
make_pvs=make_pvs,
):
preambulo = ["from GaudiKernel.SystemOfUnits import GeV"]
daughters = TrackV1FilterWithPVs(
Preambulo=preambulo,
Code=daughter_cuts,
Input=make_input_tracks(),
InputVertices=make_pvs()).Output
return TrackCombinerWithPVs(
NBodies=2,
Preamble=combiner_preamble,
CombinationCut=CombinationCut,
VertexCut=VertexCut,
InputTracks=daughters,
InputVertices=make_pvs()).OutputVertices
ftdec_v = 4
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = gec(FTDecodingVersion=ftdec_v)
NoPVFilter = FilterEmptyPVs()
one_track = one_track_MVA()
two_track_filter = EmptyFilter(InputLocation=two_track_MVA())
env = EverythingHandler(
threadPoolSize=1, nEventSlots=1, evtMax=1000, debug=True)
env.registerLine('one_track_mva', algs=[gec, NoPVFilter, one_track])
env.registerLine('two_track_mva', algs=[gec, NoPVFilter, two_track_filter])
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
# env.plotDataFlow()
patch_hybrid_tool()
......@@ -17,15 +17,17 @@ Run like any other options file:
from __future__ import absolute_import, division, print_function
from PyConf.environment import EverythingHandler
from Hlt1Conf.reconstruction import (
gec, )
from PyConf.Algorithms import FTRawBankDecoder
from Hlt2Conf.setup import setup
from Hlt2Conf.data_from_file import raw_event_from_file
from Hlt2Conf.lines import hlt2_line_builders
from Hlt2Conf.reconstruction import upfront_reconstruction, stateProvider_with_simplified_geom
from RecoConf.reco_objects_from_file import (
make_raw_data_for_gec_from_file, upfront_reconstruction,
stateProvider_with_simplified_geom)
from RecoConf.hlt1_tracking import require_gec
input_files = [
# MinBias 30000000
......@@ -58,7 +60,8 @@ lines_to_run = [
]
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v), \
gec.bind(FTDecodingVersion=ftdec_v), \
require_gec.bind(make_raw = make_raw_data_for_gec_from_file,
FTDecodingVersion=ftdec_v), \
raw_event_from_file.bind(raw_event_format=raw_event_format):
for name, builder in hlt2_line_builders(lines_to_run).items():
......
......@@ -22,7 +22,7 @@ import string
from Configurables import CombineParticles, FilterDesktop
from Hlt1Conf.reconstruction import EmptyFilter
from RecoConf.hlt1_tracking import EmptyFilter
from PyConf.components import make_algorithm
__all__ = [
......
......@@ -15,18 +15,18 @@ import math
from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad
from Hlt1Conf.reconstruction import FilterEmptyPVs
from RecoConf.hlt1_tracking import require_pvs, require_gec
from RecoConf.reco_objects_from_file import make_pvs as get_pvs_from_file
from ..algorithms import require_all, ParticleFilter, ParticleCombiner
from ..framework import configurable
from ..reconstruction import gec, make_pvs
from ..standard_particles import make_mass_constrained_jpsi2mumu, make_phi2kk
from . import hlt2_line_builder
# make sure we passed GEC and have PV in event
def prefilters():
return [gec(), FilterEmptyPVs(make_pvs=make_pvs)]
return [require_gec(), require_pvs(get_pvs_from_file())]
@configurable
......
......@@ -23,11 +23,11 @@ import math
from GaudiKernel.SystemOfUnits import GeV, MeV, mm, mrad
from Hlt1Conf.reconstruction import FilterEmptyPVs
from RecoConf.hlt1_tracking import require_pvs, require_gec
from RecoConf.reco_objects_from_file import make_pvs as get_pvs_from_file
from ..algorithms import require_all, ParticleCombinerWithPVs, ParticleFilterWithPVs
from ..framework import configurable
from ..reconstruction import gec, make_pvs
from ..standard_particles import make_has_rich_pions, make_has_rich_kaons
from . import hlt2_line_builder
......@@ -39,7 +39,7 @@ _PION_M = 139.57061 # +/- 0.00024
# @shared
@configurable
def make_selected_particles(make_particles=make_has_rich_pions,
make_pvs=make_pvs,
make_pvs=get_pvs_from_file,
trchi2_max=3,
mipchi2_min=8,
pt_min=800 * MeV,
......@@ -81,7 +81,7 @@ def make_charm_kaons(pid='PIDK > 3'):
@configurable
def make_dzeros(particles=None,
descriptors=None,
make_pvs=make_pvs,
make_pvs=get_pvs_from_file,
am_min=1715 * MeV,
am_max=2015 * MeV,
amaxchild_pt_min=1500 * MeV,
......@@ -126,7 +126,7 @@ def make_dzeros(particles=None,
def make_dstars(dzeros=None,
soft_pions=None,
descriptors=None,
make_pvs=make_pvs,
make_pvs=get_pvs_from_file,
q_am_min=130 * MeV - _PION_M,
q_am_max=165 * MeV - _PION_M,
q_m_min=130 * MeV - _PION_M,
......@@ -156,7 +156,7 @@ def make_dstars(dzeros=None,
def charm_prefilters():
return [gec(), FilterEmptyPVs(make_pvs=make_pvs)]
return [require_gec(), require_pvs(get_pvs_from_file())]
@hlt2_line_builder('Hlt2CharmHadD02KmPipLine')
......
......@@ -28,7 +28,7 @@ from PyConf import configurable
from .algorithms import require_all, ParticleCombiner
from .hacks import patched_hybrid_tool
from .reconstruction import make_protoparticles
from RecoConf.reco_objects_from_file import make_protoparticles
@configurable
......
###############################################################################
# (c) Copyright 2019 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. #
###############################################################################
from RecoConf.hlt1_tracking import (require_gec, require_pvs, make_pvs,
make_hlt1_tracks,
make_velokalman_fitted_tracks)
from PyConf.Algorithms import FTRawBankDecoder
from PyConf.environment import EverythingHandler
ftdec_v = 4
def hlt1_full_track_reco_line():
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = require_gec(FTDecodingVersion=ftdec_v)
NoPVFilter = require_pvs(make_pvs())
fitted_tracks = make_velokalman_fitted_tracks(make_hlt1_tracks())["Pr"]
return [gec, NoPVFilter, fitted_tracks]
env = EverythingHandler(
threadPoolSize=1, nEventSlots=1, evtMax=1000, debug=True)
env.registerLine('Hlt1_reco_baseline', algs=hlt1_full_track_reco_line())
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
###############################################################################
# (c) Copyright 2019 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. #
###############################################################################
from PyConf.environment import EverythingHandler
from PyConf.Algorithms import FTRawBankDecoder
from RecoConf.hlt1_tracking import (
require_gec,
require_pvs,
make_pvs,
)
from RecoConf.hlt2_tracking import make_hlt2_tracks
ftdec_v = 4
def hlt2_full_track_reco_line():
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = require_gec(FTDecodingVersion=ftdec_v)
NoPVFilter = require_pvs(make_pvs())
best_tracks = make_hlt2_tracks()["Best"]
return [gec, NoPVFilter, best_tracks]
env = EverythingHandler(
threadPoolSize=1, nEventSlots=1, evtMax=100, debug=True)
env.registerLine("Hlt2_reco_baseline", algs=hlt2_full_track_reco_line())
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
###############################################################################
# (c) Copyright 2019 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. #
###############################################################################
from PyConf.environment import EverythingHandler
from RecoConf.hlt1_tracking import (
require_gec,
require_pvs,
make_pvs,
)
from RecoConf.hlt2_tracking import make_hlt2_tracks, get_global_materiallocator
from PyConf.Algorithms import FTRawBankDecoder
from PyConf.Tools import DetailedMaterialLocator
ftdec_v = 4
def hlt2_full_geometry_track_reco_line():
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v), \
get_global_materiallocator.bind(materiallocator = DetailedMaterialLocator):
gec = require_gec(FTDecodingVersion=ftdec_v)
NoPVFilter = require_pvs(make_pvs())
best_tracks = make_hlt2_tracks()["Best"]
return [gec, NoPVFilter, best_tracks]
env = EverythingHandler(
threadPoolSize=1, nEventSlots=1, evtMax=100, debug=True)
env.registerLine(
"Hlt2_reco_full_geometry", algs=hlt2_full_geometry_track_reco_line())
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
......@@ -8,49 +8,35 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import absolute_import, division, print_function
from Hlt1Conf.reconstruction import (
gec,
FilterEmptyPVs,
from RecoConf.hlt1_tracking import (
require_gec,
require_pvs,
make_pvs,
make_hlt1_tracks,
)
from PyConf.Algorithms import (FTRawBankDecoder)
from RecoConf.mcchecking import (
make_velo_full_clusters,
make_links_lhcbids_mcparticles,
make_links_tracks_mcparticles,
monitor_track_efficiency,
)
from PyConf.environment import (
EverythingHandler, )
from RecoConf.mc_checking import (monitor_track_efficiency)
from PyConf.environment import (EverythingHandler)
ftdec_v = 4
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = gec(FTDecodingVersion=ftdec_v)
NoPVFilter = FilterEmptyPVs()
env = EverythingHandler(
threadPoolSize=1,
nEventSlots=1,
evtMax=100,
debug=True,
HistoFile="test.root")
env.registerLine(
'Reconstruction',
algs=[
gec,
make_pvs(),
make_velo_full_clusters(),
make_links_lhcbids_mcparticles(),
make_links_tracks_mcparticles(),
monitor_track_efficiency()
])
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
#env.plotDataFlow()
def mc_matching_line():
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = require_gec(FTDecodingVersion=ftdec_v)
NoPVFilter = require_pvs(make_pvs())
Hlt1_forward_efficiencies = monitor_track_efficiency(
make_hlt1_tracks()["Forward"])
return [gec, NoPVFilter, Hlt1_forward_efficiencies]
env = EverythingHandler(
threadPoolSize=1,
nEventSlots=1,
evtMax=1000,
debug=True,
HistoFile="MCMatching_Hlt1ForwardTracking.root")
env.registerLine('MCMatching_Hlt1ForwardTracking', algs=mc_matching_line())
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
......@@ -8,7 +8,6 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import absolute_import, division, print_function
from PyConf import configurable
from PyConf.components import (
make_algorithm,
......@@ -29,7 +28,8 @@ from Configurables import (
from PyConf.Algorithms import (
MakeSelection__Track_v1 as TrackV1Selection,
LHCb__Converters__Track__v1__fromV2TrackV1TrackVector as
fromV2TrackV1TrackVector,
FromV2TrackV1TrackVector,
LHCb__Converters__Track__v1__fromV2TrackV1Track as FromV2TrackV1Track,
FTRawBankDecoder,
TracksVPMergerConverter,
TracksVPConverter,
......@@ -38,7 +38,6 @@ from PyConf.Algorithms import (
TracksFitConverter,
VeloClusterTrackingSIMD,
SciFiTrackForwarding,
PrFilterIPSoA as PrFilterIP,
TrackBeamLineVertexFinderSoA,
SciFiTrackForwardingStoreHit,
VeloKalman,
......@@ -71,157 +70,174 @@ EmptyFilter = make_algorithm(
LoKi__VoidFilter, input_transform=__emptyfilter_input_transform)
def make_raw_data():
return RawData().RawEvent
# maker functions
@configurable
def gec(raw=RawData, FTDecodingVersion=None, **kwargs):
def require_gec(make_raw=make_raw_data, FTDecodingVersion=None, **kwargs):
# TODO use FTDecodingVersion=smart.REQUIRED above
cut = 9750 if FTDecodingVersion == 4 else 11000
props = dict(NumberFTUTClusters=cut, **kwargs) # kwargs take precedence
return Algorithm(PrGECFilter, RawEventLocations=raw().RawEvent, **props)
return Algorithm(PrGECFilter, RawEventLocations=make_raw(), **props)
## VELO
@configurable
def make_velo_hits(raw=RawData):
return VeloClusterTrackingSIMD(
RawEventLocation=raw().RawEvent).HitsLocation
def make_velo_hits(make_raw=make_raw_data):
return VeloClusterTrackingSIMD(RawEventLocation=make_raw()).HitsLocation
@configurable
def make_velo_tracks(raw=RawData):
return VeloClusterTrackingSIMD(
RawEventLocation=raw().RawEvent).TracksLocation
def make_velo_tracks_simdly(make_raw=make_raw_data):
tracking = VeloClusterTrackingSIMD(RawEventLocation=make_raw())
return {
"Forward": tracking.TracksLocation,
"Backward": tracking.TracksBackwardLocation
}
@configurable
def make_velo_tracks_backward(raw=RawData):
return VeloClusterTrackingSIMD(
RawEventLocation=raw().RawEvent).TracksBackwardLocation
def make_velo_tracks(make_velo_pr_tracks=make_velo_tracks_simdly,
make_velo_hits=make_velo_hits):
''' returns a dict of velo tracks, allowing the consumer to choose the container type'''
velo_tracks = make_velo_pr_tracks()
velo_pr_tracks = velo_tracks['Forward']
velo_pr_tracks_backward = velo_tracks['Backward']
@configurable
def make_pvs(make_velo_tracks=make_velo_tracks,
make_velo_tracks_backward=make_velo_tracks_backward):
forwards = make_velo_tracks()
backwards = make_velo_tracks_backward()
return TrackBeamLineVertexFinderSoA(
TracksLocation=forwards,
TracksBackwardLocation=backwards).OutputVertices
velo_tracks_v2 = TracksVPMergerConverter(
TracksForwardLocation=velo_pr_tracks,
TracksBackwardLocation=velo_pr_tracks_backward,
HitsLocation=make_velo_hits()).OutputTracksLocation
velo_tracks_v1 = FromV2TrackV1Track(
InputTracksName=velo_tracks_v2).OutputTracksName
@configurable
def FilterEmptyPVs(make_pvs=make_pvs):
return EmptyFilter(InputLocation=make_pvs())
return {
"Pr": velo_pr_tracks,
"Pr::backward": velo_pr_tracks_backward,
"v2": velo_tracks_v2,
"v1": velo_tracks_v1
}
@configurable
def make_IPselectedTracks(make_tracks=make_velo_tracks,
make_pvs=make_pvs,
ip_cut=0.1 * mm):
return PrFilterIP(
IPcut=ip_cut, Input=make_tracks(), InputVertices=make_pvs()).Output
def make_pvs_tblv(velo_tracks):
return TrackBeamLineVertexFinderSoA(
TracksLocation=velo_tracks["Pr"],
TracksBackwardLocation=velo_tracks["Pr::backward"]).OutputVertices
@configurable
def make_UT_clusters(raw=RawData):
return UTDecoding(RawEventLocations=raw().RawEvent).UTHitsLocation
def make_pvs(make_velo_tracks=make_velo_tracks, make_pvs=make_pvs_tblv):
return make_pvs(make_velo_tracks())
@configurable
def make_VeloUT_tracks(make_velo_tracks=make_IPselectedTracks,
make_ut_clusters=make_UT_clusters):
ut_tracks = VeloUTTracking(
InputTracksName=make_velo_tracks(),
UTHits=make_ut_clusters()).OutputTracksName
return ut_tracks
def require_pvs(pvs):
return EmptyFilter(name='require_pvs', InputLocation=pvs)
## UPSTREAM
@configurable
def make_ft_clusters(raw=RawData):
return FTRawBankDecoder(RawEventLocations=raw().RawEvent).OutputLocation
def make_ut_clusters(make_raw=make_raw_data):
return UTDecoding(RawEventLocations=make_raw()).UTHitsLocation