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

Merge branch 'AM_process' into 'master'

Make "process" a required input and configure pyconf functions globally once with user input

Closes #59 and #74

See merge request !731
parents ee988d5f a299e47a
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!731Make "process" a required input and configure pyconf functions globally once with user input
Pipeline #4686671 passed
Showing
with 62 additions and 93 deletions
......@@ -5,3 +5,4 @@ input_type: ROOT
simulation: true
conddb_tag: sim-20171127-vc-md100
dddb_tag: dddb-20171126
process: Turbo
\ No newline at end of file
......@@ -4,3 +4,4 @@ input_type: ROOT
simulation: true
conddb_tag: sim-20171127-vc-md100
dddb_tag: dddb-20171126
process: Turbo
......@@ -20,4 +20,5 @@ data_type: Upgrade
simulation: true
conddb_tag: sim-20201218-vc-md100
dddb_tag: dddb-20201211
process: Turbo
......@@ -5,3 +5,4 @@ input_type: ROOT
simulation: true
conddb_tag: sim-20171127-vc-md100
dddb_tag: dddb-20171126
process: Turbo
......@@ -18,7 +18,8 @@ import Functors as F
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
from PyConf.reading import get_particles, get_pvs
from DaVinci.algorithms import add_filter, get_decreports, get_odin
from DaVinci.algorithms import add_filter
from PyConf.reading import get_decreports, get_odin
from DecayTreeFitter import DTFAlg
from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg
from PyConf.Algorithms import PrintDecayTree
......@@ -26,10 +27,9 @@ from PyConf.Algorithms import PrintDecayTree
from DaVinci import Options, make_config
#
# Definition of strucing line
# Definition of Sprucing line
#
bd2dsk_line = "SpruceB2OC_BdToDsmK_DsmToHHH_FEST_Line"
bd2dsk_data = get_particles(f"/Event/Spruce/{bd2dsk_line}/Particles", "Spruce")
_basic = 'basic'
_composite = 'composite'
......@@ -255,10 +255,13 @@ def alg_config(options: Options):
"""
Algorithm configuration function called from the comad line
"""
#get the particles from line
bd2dsk_data = get_particles(f"/Event/Spruce/{bd2dsk_line}/Particles")
#
# DecayTreeFitter Algorithm
#
v2_pvs = get_pvs(options.process)
v2_pvs = get_pvs()
#
# DecayTreeFitter Algorithm
......@@ -298,18 +301,15 @@ def alg_config(options: Options):
# event variables
#
odin = None
odin = get_odin(options) # does not work
odin = get_odin()
decreports = None
decreports = get_decreports(
'Spruce',
options) # name of line incorrect, Gerhard has a fix I need to try
decreports = get_decreports('Spruce')
evt_vars = FunctorCollection(event_variables(v2_pvs, odin, decreports))
#
# Sprucing filter
#
my_filter = add_filter(options, "HDRFilter_B0DsK",
f"HLT_PASS('{bd2dsk_line}')")
my_filter = add_filter("HDRFilter_B0DsK", f"HLT_PASS('{bd2dsk_line}')")
#
# FunTuple
......
......@@ -73,8 +73,7 @@ def main(options: Options):
#associate FunctorCollection to field (branch) name
variables = {'ALL': variables_all, 'Ds': variables_ds}
filter_data = add_filter(options, "SpruceFilter",
f"HLT_PASS('{spruce_line}')")
filter_data = add_filter("SpruceFilter", f"HLT_PASS('{spruce_line}')")
#Configure Funtuple algorithm
tuple_data = Funtuple(
......
......@@ -16,9 +16,8 @@ and MCReconstructed.
from FunTuple import FunTuple_MCParticles as MCFuntuple
from DaVinciMCTools import MCReconstructible, MCReconstructed
from DaVinci import Options, make_config
from RecoConf.data_from_file import make_mc_track_info
from FunTuple.functorcollections import MCReconstructed_Collection, MCReconstructible_Collection
from PyConf.reading import get_mc_particles, get_pp2mcp_relations, get_charged_protoparticles, get_neutral_protoparticles
from PyConf.reading import get_mc_particles, get_pp2mcp_relations, get_charged_protoparticles, get_neutral_protoparticles, get_mc_track_info
def main(options: Options):
......@@ -28,21 +27,16 @@ def main(options: Options):
# PP2MCP relations need MC particles and ProtoParticles
# Since MC is already unpacked, only unpack protos and relations
extra_inputs = []
extra_inputs += [get_charged_protoparticles(options.process)]
extra_inputs += [get_neutral_protoparticles(options.process)]
extra_inputs += [get_charged_protoparticles()]
extra_inputs += [get_neutral_protoparticles()]
relations_charged = get_pp2mcp_relations(
"/Event/HLT2/Relations/ChargedPP2MCP",
process=options.process,
extra_inputs=extra_inputs)
"/Event/HLT2/Relations/ChargedPP2MCP", extra_inputs=extra_inputs)
relations_neutral = get_pp2mcp_relations(
"/Event/HLT2/Relations/NeutralPP2MCP",
process=options.process,
extra_inputs=extra_inputs)
"/Event/HLT2/Relations/NeutralPP2MCP", extra_inputs=extra_inputs)
#Get variables related to reconstructible information.
mcrtible = MCReconstructible(
process=options.process, mc_track_info=make_mc_track_info())
mcrtible = MCReconstructible(mc_track_info=get_mc_track_info())
#The option extra_info is set to False by default and can be set to True to get more information
vars_rtible = MCReconstructible_Collection(mcrtible, extra_info=True)
print('Reconstructible functors:', vars_rtible.functor_dict.keys())
......@@ -62,8 +56,7 @@ def main(options: Options):
MC_data,
use_best_mcmatch=False,
relations_charged=relations_charged,
relations_neutral=relations_neutral,
process=options.process)
relations_neutral=relations_neutral)
#The option extra_info below is set to False by default in the functor collection.
vars_rted = MCReconstructed_Collection(mcrted_all, extra_info=False)
#Note:
......
......@@ -53,6 +53,6 @@ def main(options: Options):
"variables": variables,
}
algs = configured_FunTuple(options, {"B0Dspi": config})
algs = configured_FunTuple({"B0Dspi": config})
return make_config(options, algs)
......@@ -10,11 +10,11 @@
###############################################################################
"""
Option file for testing the ParticleTaggerAlg algorithm and the related ThOr
functors MAP_INPUT_ARRAY.
functors MAP_INPUT_ARRAY.
The aim of this example, is to retrieve and store in the final ntuple some
variables related to the additional tracks generated in the event that are not
included in the decay chain. This kind of task has been developed for flavour
included in the decay chain. This kind of task has been developed for flavour
tagging pourposes but can be extended also to other area.
In particular, the job runs over a spruced sample and retrieves a
......@@ -26,7 +26,7 @@ tracks to the B candidate of the events.
Then the MAP_INPUT_ARRAY functor takes in input this relation map and for each
entry stores the output of an external functor (i.e F.P, F.PT) in a vector.
In addition, MC truth information for each track in the 'make_long-pions'
In addition, MC truth information for each track in the 'make_long-pions'
location is retrieved and stored in the final tuples via the 'configured_MCTruthAndBkgCatAlg' function.
N.B. the job runs over a spruced sample, but the same flow can be used also for
......@@ -189,8 +189,7 @@ def main(options: Options):
# Define a filter in order to process only the event with at least on candidates of interest.
# This is a very important step aimed to reduce both the computation time required by the job and
# to prevent any failure due to empty TES location.
filter_B0DsK = add_filter(options, "HDRFilter_B0DsK",
f"HLT_PASS('{bd2dsk_line}')")
filter_B0DsK = add_filter("HDRFilter_B0DsK", f"HLT_PASS('{bd2dsk_line}')")
# Configure DaVinci passing the options and a list of the user-defined algortithms to be run.
return make_config(options, [filter_B0DsK, tuple_B0DsK])
......@@ -17,7 +17,6 @@ from FunTuple import FunctorCollection as FC
from FunTuple import FunTuple_Particles as Funtuple
from DaVinci.algorithms import add_filter
from DaVinci import make_config, Options
from DaVinci.algorithms import get_odin
from FunTuple.functorcollections import EventInfo
from PyConf.reading import get_particles, get_rec_summary
......@@ -34,21 +33,19 @@ def main(options: Options):
#get RecSummary object that holds information about nPVs, nTracks, nFTClusters
# Note more information can be added to the RecSummary object
# (see MRs: https://gitlab.cern.ch/lhcb/Moore/-/merge_requests/1649)
rec_summary = get_rec_summary(options.process)
rec_summary = get_rec_summary()
evt_vars = FC({
'nTracks': F.VALUE_OR(-1) @ F.NTRACKS(rec_summary),
'nPVs': F.VALUE_OR(-1) @ F.NPVS(rec_summary),
'nFTClusters': F.VALUE_OR(-1) @ F.NFTCLUSTERS(rec_summary)
})
#Get RunNUmber and EventNumber
odin = get_odin(options)
evt_vars += EventInfo(odin, extra_info=True)
evt_vars += EventInfo(extra_info=True)
#get particles to run over
line_name = 'Hlt2SLB_LbToLcMuNu_LcToPKPi_Line'
particles = get_particles(
f"/Event/HLT2/{line_name}/Particles", process=options.process)
my_filter = add_filter(options, "Myfilter", f"HLT_PASS('{line_name}')")
particles = get_particles(f"/Event/HLT2/{line_name}/Particles")
my_filter = add_filter("Myfilter", f"HLT_PASS('{line_name}')")
#define tupling algorithm
my_tuple = Funtuple(
name="Tuple",
......
......@@ -18,32 +18,26 @@ from FunTuple import FunctorCollection, functorcollections
from FunTuple import FunTuple_Particles as Funtuple, FunTuple_MCParticles as MCFuntuple
from DaVinci.algorithms import add_filter
from DaVinci import Options, make_config
from RecoConf.data_from_file import make_mc_track_info
from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg
from DaVinci.algorithms import get_odin, get_decreports
from PyConf.Algorithms import WeightedRelTableAlg
from Gaudi.Configuration import INFO
from PyConf.reading import get_particles, get_mc_particles
from PyConf.reading import get_particles, get_mc_particles, get_mc_track_info
def main(options: Options):
line_name = 'Hlt2Charm_D0ToKmPip_Line'
d02kpi_data = get_particles(
f"/Event/HLT2/{line_name}/Particles", process=options.process)
d02kpi_data = get_particles(f"/Event/HLT2/{line_name}/Particles")
MC_data = get_mc_particles("/Event/HLT2/MC/Particles")
#Get variables related to reconstructible information.
mcrtible = MCReconstructible(
process='Hlt2', mc_track_info=make_mc_track_info())
mcrtible = MCReconstructible(mc_track_info=get_mc_track_info())
#Get variables related to reconstructed information.
mcrted_all = MCReconstructed(
MC_data, use_best_mcmatch=True, process='Hlt2')
mcrted_all = MCReconstructed(MC_data, use_best_mcmatch=True)
#get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output
mctruth = configured_MCTruthAndBkgCatAlg(
inputs=d02kpi_data, process=options.process)
mctruth = configured_MCTruthAndBkgCatAlg(inputs=d02kpi_data)
#configure "WeightedRelTableAlg" algorithm for HLT2 output
iso_rel_table = WeightedRelTableAlg(
......@@ -52,12 +46,6 @@ def main(options: Options):
Cut=(F.DR2() < 0.4),
OutputLevel=INFO)
#get location to odin
odin = get_odin(options)
#get location to hlt2 dec report
dec = get_decreports("Hlt2", options)
# use functorcollections to add variables, please expand when there's new collections :)
collections = [
functorcollections.Kinematics(),
......@@ -76,8 +64,8 @@ def main(options: Options):
]
evt_collections = [
functorcollections.EventInfo(odin),
functorcollections.SelectionInfo("Hlt2", dec, [line_name])
functorcollections.EventInfo(),
functorcollections.SelectionInfo("Hlt2", [line_name])
]
assert len(collections) + len(evt_collections) + len(
......@@ -127,8 +115,7 @@ def main(options: Options):
event_variables=evt_vars,
inputs=d02kpi_data)
my_filter = add_filter(options, "HDRFilter_D0Kpi",
f"HLT_PASS('{line_name}')")
my_filter = add_filter("HDRFilter_D0Kpi", f"HLT_PASS('{line_name}')")
mc_tuple = MCFuntuple(
name="MCTuple",
......
......@@ -14,11 +14,10 @@ Read an HLT2 file and create an ntuple with the new DaVinci configuration.
import Functors as F
from FunTuple import FunctorCollection as FC
from FunTuple import FunTuple_Particles as Funtuple
from PyConf.reading import get_particles, get_pvs
from PyConf.reading import get_particles, get_pvs, get_odin
from DaVinci.algorithms import add_filter
from DaVinci import Options, make_config
from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg
from DaVinci.algorithms import get_odin, get_decreports
from FunTuple.functorcollections import SelectionInfo
......@@ -30,7 +29,7 @@ def main(options: Options):
}
# Creating v2 reconstructed vertices to be used in the following functor
v2_pvs = get_pvs(process=options.process)
v2_pvs = get_pvs()
d0_variables = FC({
"ID": F.PARTICLE_ID,
......@@ -65,15 +64,12 @@ def main(options: Options):
}
line_name = 'Hlt2Charm_D0ToKmPip_Line'
d02kpi_data = get_particles(
f"/Event/HLT2/{line_name}/Particles", process=options.process)
d02kpi_data = get_particles(f"/Event/HLT2/{line_name}/Particles")
my_filter = add_filter(options, "HDRFilter_D0Kpi",
f"HLT_PASS('{line_name}')")
my_filter = add_filter("HDRFilter_D0Kpi", f"HLT_PASS('{line_name}')")
#get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output
mctruth = configured_MCTruthAndBkgCatAlg(
inputs=d02kpi_data, process=options.process)
mctruth = configured_MCTruthAndBkgCatAlg(inputs=d02kpi_data)
#add helper lambda that configures a functor to get truth information
MCTRUTH = lambda func: F.MAP_INPUT(Functor=func, Relations=mctruth.MCAssocTable)
trueid_bkgcat_info = {
......@@ -97,16 +93,15 @@ def main(options: Options):
#sort of related issue (https://gitlab.cern.ch/lhcb/Rec/-/issues/356)
#variables['D0'] += FC({'TRUEPT_Kaon': MCTRUTH(F.CHILD(1, F.PT))})
#get ODIN and DecReports location
odin = get_odin(options)
hlt2_dec = get_decreports("Hlt2", options)
#get odin which hold the event information
odin = get_odin()
#define event level variables
evt_variables = FC({
"RUNNUMBER": F.RUNNUMBER(odin),
"EVENTNUMBER": F.EVENTNUMBER(odin)
})
evt_variables += SelectionInfo("Hlt2", hlt2_dec, [line_name])
evt_variables += SelectionInfo("Hlt2", [line_name])
#For now remove: The 'Hlt2' line decision tuples fine but breaks unit test with an error. (Why?)
#see linked issue here: https://gitlab.cern.ch/lhcb/DaVinci/-/merge_requests/654#note_5320732
evt_variables.pop('Hlt2')
......
......@@ -21,8 +21,7 @@ from PyConf.reading import get_particles
def main(options: Options):
bs2jpsiphi_line = "Hlt2BsToJpsiPhi_JPsi2MuMu_PhiToKK_Line"
bs2jpsiphi_data = get_particles(
f"/Event/HLT2/{bs2jpsiphi_line}/Particles", process=options.process)
bs2jpsiphi_data = get_particles(f"/Event/HLT2/{bs2jpsiphi_line}/Particles")
fields = {
'Bs': "[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC",
'Jpsi': "[B_s0 -> ^(J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC",
......@@ -36,7 +35,7 @@ def main(options: Options):
'ALL': variables_all, #adds variables to all branches
}
filter_bs = add_filter(options, "HDRFilter_Bs2JpsiPhi",
filter_bs = add_filter("HDRFilter_Bs2JpsiPhi",
f"HLT_PASS('{bs2jpsiphi_line}')")
tuple_bs = Funtuple(
......
......@@ -85,9 +85,8 @@ def main(options: Options):
loki_preamble=loki_preamble,
inputs=bd2dspi_line)
filter_B0DsK = add_filter(options, "HDRFilter_B0DsK",
f"HLT_PASS('{line_B0DsK}')")
filter_B0Dspi = add_filter(options, "HDRFilter_B0Dspi",
filter_B0DsK = add_filter("HDRFilter_B0DsK", f"HLT_PASS('{line_B0DsK}')")
filter_B0Dspi = add_filter("HDRFilter_B0Dspi",
f"HLT_PASS('{line_B0Dspi}')")
algs = {
......
......@@ -37,7 +37,7 @@ def main(options: Options):
line_name = 'Spruce_Test_line'
B_data = get_particles(f"/Event/Spruce/{line_name}/Particles")
my_filter = add_filter(options, "HDRFilter_B", f"HLT_PASS('{line_name}')")
my_filter = add_filter("HDRFilter_B", f"HLT_PASS('{line_name}')")
#helper lambda function
MCTRUTH = lambda func: F.MAP_INPUT(Functor=func, Relations=mctruth.MCAssocTable)
......
......@@ -35,13 +35,11 @@ def main(options: Options):
'Kp': "[B+ -> (J/psi(1S) -> mu+ mu- ) ^K+]CC"
}
b2jpsik_data = get_particles(
"/Event/HLT2/Hlt2B2JpsiKLine/Particles", process=options.process)
b2jpsik_data = get_particles("/Event/HLT2/Hlt2B2JpsiKLine/Particles")
tagged_data = get_particles(
"/Event/HLT2/Hlt2B2JpsiKLine/LongTaggingParticles/Particles",
process=options.process)
"/Event/HLT2/Hlt2B2JpsiKLine/LongTaggingParticles/Particles")
pvs = get_pvs(process=options.process)
pvs = get_pvs()
ftAlg = WeightedRelTableAlg(
ReferenceParticles=b2jpsik_data,
......@@ -87,7 +85,7 @@ def main(options: Options):
'Kp': variables_all + track_iso_variables,
}
my_filter = add_filter(options, "HDRFilter_B2JpsiK",
my_filter = add_filter("HDRFilter_B2JpsiK",
"HLT_PASS('Hlt2B2JpsiKLineDecision')")
my_tuple = Funtuple(
name="Tuple",
......
......@@ -15,7 +15,6 @@ import Functors as F
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
from DaVinci import Options, make_config
from DaVinci.algorithms import get_decreports
from PyConf.reading import get_particles
from FunTuple.functorcollections import SelectionInfo
......@@ -28,10 +27,7 @@ def main(options: Options):
variables = {"B0": B0_variables}
b02dpi_data = get_particles(
"/Event/HLT2/Hlt2B2OC_BdToDmPi_DmToPimPimKp_Line/Particles",
process=options.process)
hlt1_dec = get_decreports("Hlt1", options)
"/Event/HLT2/Hlt2B2OC_BdToDmPi_DmToPimPimKp_Line/Particles")
Hlt1_decisions = [
'Hlt1TrackMVADecision', 'Hlt1TwoTrackMVADecision', 'Hlt1D2KKDecision',
......@@ -44,7 +40,7 @@ def main(options: Options):
]
#define event level variables
evt_variables = SelectionInfo("Hlt1", hlt1_dec, Hlt1_decisions)
evt_variables = SelectionInfo("Hlt1", Hlt1_decisions)
#define FunTuple instance
my_tuple = Funtuple(
......
......@@ -16,6 +16,7 @@
<argument name="extra_options_yaml"><text>
evt_max: 100
print_freq: 1
process: Turbo
msg_svc_format: "% F%40W%S%7W%R%T %0W%M"
</text></argument>
<argument name="timeout"><integer>3600</integer></argument>
......
......@@ -16,6 +16,7 @@
<argument name="extra_options_yaml"><text>
evt_max: 7
input_raw_format: 4.3
process: Turbo
</text></argument>
<argument name="timeout"><integer>3600</integer></argument>
<argument name="args"><set>
......
......@@ -25,11 +25,12 @@
print_freq: 1
data_type: Upgrade
simulation: true
process: Turbo
</text></argument>
<argument name="timeout"><integer>3600</integer></argument>
<argument name="reference"><text>$DAVINCIEXAMPLESROOT/tests/refs/test_davinci_tupling_weightedrelation_trackvariables.ref</text></argument>
<argument name="validator"><text>
findReferenceBlock("""Tuple SUCCESS ID=DecayTree Title="DecayTree" #items=32 {B_THOR_P,B_THOR_PT,B_THOR_MASS,B_First_P,B_First_PT,B_Sum_P,B_Sum_PT,B_Max_P,B_Ma}""")
countErrorLines({"FATAL":0, "ERROR":0})
countErrorLines({"FATAL":0, "ERROR":0})
</text></argument>
</extension>
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