Skip to content
Snippets Groups Projects
Commit 53324ad6 authored by Christopher Rob Jones's avatar Christopher Rob Jones
Browse files

Merge branch 'AM_process' into 'master'

Follow LHCb!3806

See merge request !914
parents 503b1937 b37b8934
No related branches found
No related tags found
1 merge request!914Follow https://gitlab.cern.ch/lhcb/LHCb/-/merge_requests/3806
Pipeline #4686662 passed
......@@ -14,6 +14,7 @@ from Functors.grammar import BoundFunctor
from PyConf.components import force_location
from PyConf.Algorithms import MCReconstructedAlg
import Functors as F
from PyConf.reading import get_tes_root
class MCReconstructed:
......@@ -32,7 +33,6 @@ class MCReconstructed:
for neutral particles, default = "Relations/NeutralPP2MCP"
use_best_mcmatch (bool, optional): If False, associates reconstructed track
to all the MCParticles rather than the best matched MCParticle, default = False.
process (str, optional): Process type (Hlt2 or Spruce or Turbo), default = 'Spruce'
output_level (int, optional): Standard Gaudi Algorithm OutputLevel
Example:
......@@ -51,17 +51,10 @@ class MCReconstructed:
use_best_mcmatch=True,
relations_charged="Relations/ChargedPP2MCP",
relations_neutral="Relations/NeutralPP2MCP",
process='Spruce',
output_level=INFO):
if process == 'Spruce':
root_in_tes = '/Event/Spruce/HLT2'
elif process == 'Hlt2' or process == 'Turbo':
root_in_tes = '/Event/HLT2'
else:
raise ValueError(
f"The specified 'process' {process} is not recognised. Can only be 'Hlt2' or 'Spruce' or 'Turbo'. Please check!"
)
root_in_tes = get_tes_root()
ChargedPP2MCP = force_location(
f'{root_in_tes}/{relations_charged}') if isinstance(
relations_charged, str) and root_in_tes else relations_charged
......
......@@ -38,23 +38,13 @@ class MCReconstructible:
Args:
mc_track_info (DataHandle, optional) : MCTrackInfo handle (TES)
process (str, optional) : Process type (Hlt2 or Spruce or Turbo), default = 'Spruce'
Example:
mc_trackinfo = MCReconstructible(make_mc_track_info())
mc_trackinfo = MCReconstructible(get_mc_track_info())
allvariables['HasT'] = mc_trackinfo.HasT
"""
def __init__(self, mc_track_info, process='Spruce'):
if process in {'Spruce', 'Turbo'}:
raise ValueError(
"MCTrackInfo is not persisted in Spruce/Turbo at the moment, this will be fixed in the future, see: "
"https://gitlab.cern.ch/lhcb/Moore/-/issues/440")
elif process != 'Hlt2':
raise ValueError(
f"The specified 'process' {process} is not recognised. Can only be 'Hlt2' or 'Spruce' or 'Turbo'."
)
def __init__(self, mc_track_info):
# Save the input
self.mc_track_info = mc_track_info
......@@ -116,7 +106,7 @@ class MCReconstructible:
mc_property: the property you want to check
Example:
mc_trackinfo = MCReconstructible(make_mc_track_info())
mc_trackinfo = MCReconstructible(get_mc_track_info())
allvariables['HasProperty'] = mc_trackinfo.get_info(Property)
"""
return F.VALUE_OR(-1) @ F.MC_TRACKINFO(mc_property) @ F.MC_PROPERTY(
......
......@@ -24,10 +24,8 @@ List of available collections (with contents):
import io, sys
import Functors as F
from Functors.grammar import BoundFunctor
from PyConf.application import make_data_with_FetchDataFromFile
from PyConf.Algorithms import MCTruthAndBkgCatAlg, WeightedRelTableAlg
from .FunctorCollection import FunctorCollection
from PyConf.reading import get_odin, get_decreports
__all__ = (
"EventInfo",
......@@ -42,26 +40,20 @@ __all__ = (
)
def EventInfo(odin, extra_info=False):
def EventInfo(extra_info=False):
"""
Collection of most-used functors for event information.
Args:
odin (DataHandle): Location of LHCb::ODIN
extra_info (bool, optional): Stores not only run number and event number,
but other information such as bunch ID, GPS time, etc. Defaults to False.
Example:
from FunTuple import FunTuple_Particles as Funtuple
from FunTuple.functorcollections import EventInfo
from DaVinci.algorithms import get_odin
from DaVinci import options
#Get LHCb::ODIN location using DV option
#Note correct attribute option.input_raw_format (0.3, is it always?) needed to get odin
odin = get_odin(options)
variables = EventInfo(odin)
variables = EventInfo()
# ...
tuple = Funtuple(name="MyTuple",
......@@ -70,6 +62,7 @@ def EventInfo(odin, extra_info=False):
...
)
"""
odin = get_odin()
event_info = {
"EVENTNUMBER": F.EVENTNUMBER(odin),
"RUNNUMBER": F.RUNNUMBER(odin)
......@@ -84,33 +77,24 @@ def EventInfo(odin, extra_info=False):
return FunctorCollection(event_info)
def SelectionInfo(sel_type, dec_report, line_names):
def SelectionInfo(sel_type, line_names):
"""
Collection of most-used functors for tupling trigger/sprucing information.
Args:
sel_type (str): Name of the selection type i.e. "Hlt1" or "Hlt2" or "Spruce".
Used as branch name prefix when tupling.
dec_report (DataHandle): Location of LHCb::DecReports is PyConf DataHandle type
Used as branch name prefix when tupling and as source ID to get decision reports.
line_names (list(str)): List of line names for which the decision is requested
Example:
from FunTuple import FunTuple_Particles as Funtuple
from DaVinci import options
from FunTuple.functorcollections import SelectionInfo
from DaVinci.algorithms import get_decreports
#Get HLT2 LHCb::DecReport location using DV option
#Note correct attribute for options.stream ("default") and
# options.process ("HLT2" or "Spruce") is needed for dec report
sel_type = "Hlt2"
dec = get_decreports(sel_type, options)
#List of lines you want decisions for
hlt2_lines = ['Hlt2CharmD0ToKmPipLineDecision']
variables = SelectionInfo(sel_type, dec, hlt2_lines)
variables = SelectionInfo(sel_type, hlt2_lines)
tuple = Funtuple(name="MyTuple",
fields=...,
......@@ -118,6 +102,8 @@ def SelectionInfo(sel_type, dec_report, line_names):
...
)
"""
#get decreports
dec_report = get_decreports(sel_type)
#check that the code ends with decision
add_suff_to_elem = lambda s: s + 'Decision' if not s.endswith('Decision') else s
line_names = list(map(add_suff_to_elem, line_names))
......@@ -171,9 +157,10 @@ def MCKinematics(mctruth):
from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg
#load particles onto TES location for a given event cycle
input_data = make_data_with_FetchDataFromFile("/Event/HLT2/<linename>/Particles")
input_data = get_particles("/Event/HLT2/<linename>/Particles")
#define an algorithm that builds one-to-one relation table b/w Reco Particle -> Truth MC Particle.
#Here "options" is the DV options object (see DaVinciExamples or DaVinciTutorials)
mctruth = configured_MCTruthAndBkgCatAlg(inputs=input_data)
variables = MCKinematics(mctruth)
......@@ -214,9 +201,10 @@ def MCHierarchy(mctruth=None):
from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg
#load particles onto TES location for a given event cycle
input_data = make_data_with_FetchDataFromFile("/Event/HLT2/<linename>/Particles")
input_data = get_particles("/Event/HLT2/<linename>/Particles")
#define an algorithm that builds one-to-one relation table b/w Reco Particle -> Truth MC Particle.
#Here "options" is the DV options object (see DaVinciExamples or DaVinciTutorials)
mctruth = configured_MCTruthAndBkgCatAlg(inputs=input_data)
variables = MCHierarchy(mctruth)
......@@ -258,9 +246,10 @@ def MCVertexInfo(mctruth):
from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg
#load particles onto TES location for a given event cycle
input_data = make_data_with_FetchDataFromFile("/Event/HLT2/<linename>/Particles")
input_data = get_particles("/Event/HLT2/<linename>/Particles")
#define an algorithm that builds one-to-one relation table b/w Reco Particle -> Truth MC Particle.
#Here "options" is the DV options object (see DaVinciExamples or DaVinciTutorials)
mctruth = configured_MCTruthAndBkgCatAlg(inputs=input_data)
variables = MCVertexInfo(mctruth)
......@@ -318,7 +307,7 @@ def MCReconstructible_Collection(mcreconstructible_alg,
from DaVinciMCTools import MCReconstructible
#load MCParticles onto TES location for a given event cycle
input_data = force_location("/Event/HLT2/MC/Particles")
input_data = get_particles("/Event/HLT2/MC/Particles")
#define the helper class and get functor collection
reconstructible = MCReconstructible()
......@@ -450,7 +439,7 @@ def MCReconstructed_Collection(mcreconstructed_alg, extra_info=False):
from DaVinciMCTools import MCReconstructed
#load particles onto TES location for a given event cycle
input_data = force_location("/Event/HLT2/MC/Particles")
input_data = get_particles("/Event/HLT2/MC/Particles")
#map MCParticle -> reconstructed track
mcreconstructed_alg = MCReconstructed(input_data)
......@@ -593,21 +582,27 @@ def TrackIsolation(iso_rel_table):
def __print_collection(coll_name):
"""Nicely print out the contents of a collection."""
from PyConf.Algorithms import MCTruthAndBkgCatAlg, WeightedRelTableAlg
from PyConf.application import make_data_with_FetchDataFromFile
from Functors.grammar import BoundFunctor
from PyConf.reading import get_tes_root, get_hlt_reports
from DaVinciMCTools import MCReconstructible
from DaVinciMCTools import MCReconstructed
_mc_rtible_rted = [
"MCReconstructible_Collection", "MCReconstructed_Collection"
]
print(f"{coll_name}:")
coll = globals()[coll_name]
#get functor collection
if coll_name == 'EventInfo':
dummy_dh = make_data_with_FetchDataFromFile("dummy")
dummy_dh.force_type("LHCb::Odin")
f_dict = coll(dummy_dh).functor_dict
with get_odin.bind(
process="Hlt2", stream="dummy_strm", input_raw_format=0.5):
f_dict = coll().functor_dict
elif coll_name == 'SelectionInfo':
dummy_dh = make_data_with_FetchDataFromFile("dummy2")
dummy_dh.force_type("LHCb::DecReports")
f_dict = coll("Sel", dummy_dh,
['dummy_line_name_Decision']).functor_dict
with get_hlt_reports.bind(process="Hlt2", stream="dummy_strm"):
f_dict = coll("Hlt2", ['dummy_line_name_Decision']).functor_dict
elif 'MC' in coll_name and coll_name not in _mc_rtible_rted:
dummy_dh = make_data_with_FetchDataFromFile("dummy3")
dummy_alg = MCTruthAndBkgCatAlg(Input=dummy_dh)
......@@ -619,16 +614,15 @@ def __print_collection(coll_name):
ReferenceParticles=dummy_dh1, InputCandidates=dummy_dh2)
f_dict = coll(dummy_alg).functor_dict
elif coll_name == 'MCReconstructible_Collection':
from DaVinciMCTools import MCReconstructible
dummy_dh = make_data_with_FetchDataFromFile("dummy6")
dummy_dh.force_type('LHCb::MCProperty')
r_tible = MCReconstructible(process='Hlt2', mc_track_info=dummy_dh)
r_tible = MCReconstructible(mc_track_info=dummy_dh)
f_dict = coll(r_tible, extra_info=True).functor_dict
elif coll_name == 'MCReconstructed_Collection':
from DaVinciMCTools import MCReconstructed
dummy_dh = make_data_with_FetchDataFromFile("dummy7")
r_ted = MCReconstructed(dummy_dh, process='Hlt2')
f_dict = coll(r_ted, extra_info=True).functor_dict
with get_tes_root.bind(process="Hlt2"):
r_ted = MCReconstructed(dummy_dh)
f_dict = coll(r_ted, extra_info=True).functor_dict
else:
f_dict = coll().functor_dict
......
......@@ -13,11 +13,11 @@ import sys
import pytest
from PyConf.application import make_data_with_FetchDataFromFile
from PyConf.application import default_raw_event, make_odin
import Functors as F
from FunTuple import FunctorCollection
from FunTuple.functorcollections import Kinematics, EventInfo
from PyConf.reading import get_odin
@pytest.fixture()
......@@ -121,10 +121,8 @@ def test_with_event_variables(data_handle, func_name, name_argument):
"""
Check that event variables passed as an optional argument are dealt with correctly.
"""
with default_raw_event.bind(raw_event_format=0.5):
odin_loc = make_odin(stream="Spruce")
event_variables = EventInfo(odin_loc, extra_info=True)
with get_odin.bind(process="Hlt2", stream="", input_raw_format=0.5):
event_variables = EventInfo(extra_info=True)
tuple = getattr(this_module, func_name)(
name=name_argument,
......
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