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

Merge branch 'AM_update_tuple_examples' into 'master'

Update the tuple examples

See merge request !558
parents aeda4b8b 875f252d
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!558Update the tuple examples
Pipeline #2802639 passed
......@@ -14,91 +14,100 @@ Example of a typical DaVinci job:
- tuple of the selected candidates
This example is meant to be run with
$ ./run davinci run-mc --testfiledb Upgrade_Bd2KstarMuMu $DAVINCIROOT/options/DaVinciDB-Example.yaml --user_algorithms example-tupling-advanced-run-mc:main
$ ./run davinci run-mc --inputfiledb Upgrade_Bd2KstarMuMu_ldst $DAVINCIROOT/options/DaVinciDB-Example.yaml --user_algorithms example-tupling-advanced-run-mc:main
"""
__author__ = "Davide Fazzini"
__author__ = "Davide Fazzini, Abhijit Mathad"
__date__ = "2021-06-18"
import Functors as F
from PyConf.Algorithms import FunTuple_Particles as FunTuple
from DaVinci.standard_particles import make_detached_mumu, make_KsDD
from DaVinci.reco_objects import upfront_reconstruction_from_file as upfront_reconstruction
from FunTuple import ParticleTupleProp, convert_to_parsable_objs
# Define an helper function for creating the tuple
def CreateSimpleTuple(name, tree_name, parsable_objs, loki_preamble, inputs):
ftup = FunTuple(
name=name,
tree_name=tree_name,
branch_names_prefix=parsable_objs[0],
decay_descriptors=parsable_objs[1],
loki_functors=parsable_objs[2][0],
loki_functor_branch_names=parsable_objs[2][1],
thor_functors=parsable_objs[3][0],
thor_functor_branch_names=parsable_objs[3][1],
loki_preamble=loki_preamble,
input_location=inputs)
return ftup
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
from FunTuple.NewTupleTools import Kinematics
# Prepare the node with the selection
dimuons = make_detached_mumu()
kshorts = make_KsDD()
'''
Tuple observables related to Jpsi -> mu+ mu-
'''
#FunTuple: make branches to tuple (NB: adding a special keyword 'ALL' with throw an error)
branches = {}
branches['Jpsi'] = 'J/psi(1S) -> mu+ mu-'
branches['MuPlus'] = 'J/psi(1S) -> ^mu+ mu-'
#FunTuple: define list of preambles for loki
loki_preamble = ['TRACK_MAX_PT = MAXTREE(ISBASIC & HASTRACK, PT, -1)']
#FunTuple: Jpsi info
ParticleJpsi = ParticleTupleProp(
branch_name_prefix="Jpsi",
decay_descriptor="J/psi(1S) -> mu+ mu-",
#Dict -> {name:functor}
particle_code_loki={
'LOKI_P': 'P',
'LOKI_PT': 'PT',
'LOKI_Muonp_PT': 'CHILD(PT, 1)',
'LOKI_Muonm_PT': 'CHILD(PT, 2)',
'LOKI_MAXPT': 'TRACK_MAX_PT',
'LOKI_N_HIHGPT_TRCKS': 'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))'
},
particle_code_thor={
'THOR_P': F.P,
'THOR_PT': F.PT
})
#FunTuple: make collection of functors for Jpsi
variables_jpsi = FunctorCollection({
'LOKI_P':
'P',
'LOKI_MAXPT':
'TRACK_MAX_PT',
'LOKI_NTRCKS_ABV_THRSHLD':
'NINTREE(ISBASIC & (PT > 15*MeV))',
'LOKI_Muonp_PT':
'CHILD(PT, 1)',
'LOKI_Muonm_PT':
'CHILD(PT, 2)',
'THOR_PT':
F.PT
})
#FunTuple: extend the collection given dictionary
#In case of common entries (i.e. common key and not functor code) the program warns user and overwrites the previous entry
variables_jpsi.extend({
'LOKI_PT': 'PT'
}) #OR like dictionaries can do variables_jpsi['LOKI_PT'] = 'PT'
#FunTuple: Remove from collection given the list of variable names
variables_jpsi.remove(['THOR_PT', 'LOKI_P'])
#FunTuple: Join two functor
#If entries already exist user is warned about picking entries from the base instance.
variables_extra = FunctorCollection({'LOKI_PT': 'PT', 'THOR_P': F.P})
variables_jpsi += variables_extra
#FunTuple: Can also subtract two FunctorCollection to get unique entries like below
#variables_unique = variables_jpsi - variables_extra
print('Variables in Jpsi branch', variables_jpsi)
#FunTuple: make functor collection from the imported functor library Kinematics
variables_all = FunctorCollection(Kinematics)
print('Variables in ALL branch', variables_all)
print('Variables in MuPlus branch', variables_extra)
#FunTuple: Mu plus info: Can also muon and make a seperate ParticleTupleProp object
ParticleMuPlus = ParticleTupleProp(
branch_name_prefix="MuPlus",
decay_descriptor="J/psi(1S) -> ^mu+ mu-",
particle_code_loki={'LOKI_P': 'P'},
particle_code_thor={'THOR_P': F.P})
#FunTuple: associate functor collections to branch name
variables = {}
variables['ALL'] = variables_all #adds variables to all branches
variables['Jpsi'] = variables_jpsi
variables['MuPlus'] = variables_extra
#FunTuple: Do not need to do this if a custom gaudi property for ParticleTupleProp is implemented
parsable_objs_dimuons = convert_to_parsable_objs(
[ParticleJpsi, ParticleMuPlus])
ftup_dimuons = CreateSimpleTuple("DimuonsTuple", "DecayTree",
parsable_objs_dimuons, loki_preamble, dimuons)
#FunTuple: define list of preambles for loki
loki_preamble = ['TRACK_MAX_PT = MAXTREE(ISBASIC & HASTRACK, PT, -1)']
ParticleKS = ParticleTupleProp(
branch_name_prefix="Ks",
decay_descriptor="KS0 -> pi+ pi-",
#Dict -> {name:functor}
particle_code_loki={
'LOKI_P': 'P',
'LOKI_PT': 'PT',
'LOKI_Muonp_PT': 'CHILD(PT, 1)',
'LOKI_Muonm_PT': 'CHILD(PT, 2)',
'LOKI_MAXPT': 'TRACK_MAX_PT',
'LOKI_N_HIHGPT_TRCKS': 'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))'
},
particle_code_thor={
'THOR_P': F.P,
'THOR_PT': F.PT
})
parsable_objs_kshorts = convert_to_parsable_objs([ParticleKS])
ftup_kshorts = CreateSimpleTuple("KsTuple", "DecayTree", parsable_objs_kshorts,
loki_preamble, kshorts)
#FunTuple: Configure Funtuple algorithm
tuple_dimuons = Funtuple(
name="DimuonsTuple",
tree_name="DecayTree",
branches=branches,
variables=variables,
loki_preamble=loki_preamble,
inputs=dimuons)
'''
Tuple observables related to KS0 -> 2pi
'''
#FunTuple: As above make branches
branches_KS = {}
branches_KS['KS'] = 'KS0 -> pi+ pi-'
#FunTuple: Associate the functor collections to branch names
variables_KS = {}
variables_KS['ALL'] = variables_all
variables_KS['KS'] = variables_jpsi
#FunTuple: Configure Funtuple algorithm
tuple_kshorts = Funtuple(
name="KsTuple",
tree_name="DecayTree",
branches=branches_KS,
variables=variables_KS,
loki_preamble=loki_preamble,
inputs=kshorts)
def main():
......@@ -112,7 +121,7 @@ def main():
tools = []
algs = {
"Reco": upfront_reconstruction(),
"DiMuons": upfront_reconstruction() + [dimuons, ftup_dimuons],
"KShorts": upfront_reconstruction() + [kshorts, ftup_kshorts]
"DiMuons": upfront_reconstruction() + [dimuons, tuple_dimuons],
"KShorts": upfront_reconstruction() + [kshorts, tuple_kshorts]
}
return algs, tools
......@@ -14,73 +14,68 @@ Example of a typical DaVinci job:
- tuple of the selected candidates
This example is meant to be run with
$ ./run davinci run-mc --simplejob --testfiledb Upgrade_Bd2KstarMuMu --joboptfile example-tupling-basic.yaml --user_algorithms example-tupling-basic-run-mc:main
$ ./run davinci run-mc --simplejob --inputfiledb Upgrade_Bd2KstarMuMu --joboptfile example-tupling-basic.yaml --user_algorithms example-tupling-basic-run-mc:main
"""
__author__ = "Maurizio Martinelli"
__author__ = "Maurizio Martinelli, Abhijit Mathad"
__date__ = "2021-05-03"
import Functors as F
from PyConf.Algorithms import FunTuple_Particles as FunTuple
from DaVinci.standard_particles import make_detached_mumu
from DaVinci.reco_objects import upfront_reconstruction_from_file as upfront_reconstruction
from FunTuple import ParticleTupleProp, convert_to_parsable_objs
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
# Prepare the node with the selection
dimuons = make_detached_mumu()
# Define a helper function to create the FunTuple instance
def CreateSimpleTuple(name, tree_name, parsable_objs, loki_preamble, inputs):
ftup = FunTuple(
name=name,
tree_name=tree_name,
branch_names_prefix=parsable_objs[0],
decay_descriptors=parsable_objs[1],
loki_functors=parsable_objs[2][0],
loki_functor_branch_names=parsable_objs[2][1],
thor_functors=parsable_objs[3][0],
thor_functor_branch_names=parsable_objs[3][1],
loki_preamble=loki_preamble,
input_location=inputs)
return ftup
#FunTuple: Jpsi info
branches = {}
branches['Jpsi'] = 'J/psi(1S) -> mu+ mu-'
branches['MuPlus'] = 'J/psi(1S) -> ^mu+ mu-'
#make collection of functors for Jpsi
variables_jpsi = FunctorCollection({
'LOKI_P':
'P',
'LOKI_PT':
'PT',
'LOKI_Muonp_PT':
'CHILD(PT, 1)',
'LOKI_Muonm_PT':
'CHILD(PT, 2)',
'LOKI_MAXPT':
'TRACK_MAX_PT',
'LOKI_N_HIGHPT_TRCKS':
'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))',
'THOR_P':
F.P,
'THOR_PT':
F.PT
})
# Prepare the node with the selection
dimuons = make_detached_mumu()
#make collection of functors for Muplus
variables_muplus = FunctorCollection({'LOKI_P': 'P', 'THOR_P': F.P})
#associate FunctorCollection to branch name
variables = {}
variables['Jpsi'] = variables_jpsi
variables['MuPlus'] = variables_muplus
#FunTuple: define list of preambles for loki
loki_preamble = ['TRACK_MAX_PT = MAXTREE(ISBASIC & HASTRACK, PT, -1)']
#FunTuple: Jpsi info
ParticleJpsi = ParticleTupleProp(
branch_name_prefix="Jpsi",
decay_descriptor="J/psi(1S) -> mu+ mu-",
#Dict -> {name:functor}
particle_code_loki={
'LOKI_P': 'P',
'LOKI_PT': 'PT',
'LOKI_Muonp_PT': 'CHILD(PT, 1)',
'LOKI_Muonm_PT': 'CHILD(PT, 2)',
'LOKI_MAXPT': 'TRACK_MAX_PT',
'LOKI_N_HIHGPT_TRCKS': 'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))'
},
particle_code_thor={
'THOR_P': F.P,
'THOR_PT': F.PT
})
#FunTuple: Mu plus info: Can also muon and make a seperate ParticleTupleProp object
ParticleMuPlus = ParticleTupleProp(
branch_name_prefix="MuPlus",
decay_descriptor="J/psi(1S) -> ^mu+ mu-",
particle_code_loki={'LOKI_P': 'P'},
particle_code_thor={'THOR_P': F.P})
#FunTuple: Do not need to do this if a custom gaudi property for ParticleTupleProp is implemented
parsable_objs_dimuons = convert_to_parsable_objs(
[ParticleJpsi, ParticleMuPlus])
ftup_dimuons = CreateSimpleTuple("DimuonsTuple", "DecayTree",
parsable_objs_dimuons, loki_preamble, dimuons)
#Configure Funtuple algorithm
tuple_dimuons = Funtuple(
name="DimuonsTuple",
tree_name="DecayTree",
branches=branches,
variables=variables,
loki_preamble=loki_preamble,
inputs=dimuons)
def main():
tools = []
algs = upfront_reconstruction() + [dimuons, ftup_dimuons]
algs = upfront_reconstruction() + [dimuons, tuple_dimuons]
return algs, tools
......@@ -15,15 +15,15 @@ Example of a typical DaVinci job:
- tuple of the selected candidates
"""
__author__ = "Maurizio Martinelli"
__author__ = "Maurizio Martinelli, Abhijit Mathad"
__date__ = "2021-03-16"
from DaVinci import options, run_davinci
from DaVinci.standard_particles import make_detached_mumu, make_KsDD
from DaVinci.reco_objects import upfront_reconstruction_from_file as upfront_reconstruction
import Functors as F
from PyConf.Algorithms import FunTuple_Particles as FunTuple
from FunTuple import ParticleTupleProp, convert_to_parsable_objs
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
# print control flow and data flow graphs
options.control_flow_file = 'control_flow.gv'
......@@ -44,79 +44,69 @@ print(options)
dimuons = make_detached_mumu()
kshorts = make_KsDD()
# Add FUNTuples
def CreateSimpleTuple(name, tree_name, parsable_objs, loki_preamble, inputs):
ftup = FunTuple(
name=name,
tree_name=tree_name,
branch_names_prefix=parsable_objs[0],
decay_descriptors=parsable_objs[1],
loki_functors=parsable_objs[2][0],
loki_functor_branch_names=parsable_objs[2][1],
thor_functors=parsable_objs[3][0],
thor_functor_branch_names=parsable_objs[3][1],
loki_preamble=loki_preamble,
input_location=inputs)
return ftup
#FunTuple: make branches to tuple
branches = {}
branches['Jpsi'] = 'J/psi(1S) -> mu+ mu-'
branches['MuPlus'] = 'J/psi(1S) -> ^mu+ mu-'
#FunTuple: make collection of functors for Jpsi
variables_jpsi = FunctorCollection({
'LOKI_P':
'P',
'LOKI_PT':
'PT',
'LOKI_Muonp_PT':
'CHILD(PT, 1)',
'LOKI_Muonm_PT':
'CHILD(PT, 2)',
'LOKI_MAXPT':
'TRACK_MAX_PT',
'LOKI_N_HIGHPT_TRCKS':
'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))',
'THOR_P':
F.P,
'THOR_PT':
F.PT
})
#FunTuple: make collection of functors for Muplus
variables_muplus = FunctorCollection({'LOKI_P': 'P', 'THOR_P': F.P})
#FunTuple: associate functor collections to branch name
variables = {}
variables['Jpsi'] = variables_jpsi
variables['MuPlus'] = variables_muplus
#FunTuple: define list of preambles for loki
loki_preamble = ['TRACK_MAX_PT = MAXTREE(ISBASIC & HASTRACK, PT, -1)']
#FunTuple: Jpsi info
ParticleJpsi = ParticleTupleProp(
branch_name_prefix="Jpsi",
decay_descriptor="J/psi(1S) -> mu+ mu-",
#Dict -> {name:functor}
particle_code_loki={
'LOKI_P': 'P',
'LOKI_PT': 'PT',
'LOKI_Muonp_PT': 'CHILD(PT, 1)',
'LOKI_Muonm_PT': 'CHILD(PT, 2)',
'LOKI_MAXPT': 'TRACK_MAX_PT',
'LOKI_N_HIHGPT_TRCKS': 'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))'
},
particle_code_thor={
'THOR_P': F.P,
'THOR_PT': F.PT
})
#FunTuple: Mu plus info: Can also muon and make a seperate ParticleTupleProp object
ParticleMuPlus = ParticleTupleProp(
branch_name_prefix="MuPlus",
decay_descriptor="J/psi(1S) -> ^mu+ mu-",
particle_code_loki={'LOKI_P': 'P'},
particle_code_thor={'THOR_P': F.P})
#FunTuple: Do not need to do this if a custom gaudi property for ParticleTupleProp is implemented
parsable_objs_dimuons = convert_to_parsable_objs(
[ParticleJpsi, ParticleMuPlus])
ftup_dimuons = CreateSimpleTuple("DimuonsTuple", "DecayTree",
parsable_objs_dimuons, loki_preamble, dimuons)
ParticleKS = ParticleTupleProp(
branch_name_prefix="Ks",
decay_descriptor="KS0 -> pi+ pi-",
#Dict -> {name:functor}
particle_code_loki={
'LOKI_P': 'P',
'LOKI_PT': 'PT',
'LOKI_Muonp_PT': 'CHILD(PT, 1)',
'LOKI_Muonm_PT': 'CHILD(PT, 2)',
'LOKI_MAXPT': 'TRACK_MAX_PT',
'LOKI_N_HIHGPT_TRCKS': 'NINTREE(ISBASIC & HASTRACK & (PT > 1500*MeV))'
},
particle_code_thor={
'THOR_P': F.P,
'THOR_PT': F.PT
})
parsable_objs_kshorts = convert_to_parsable_objs([ParticleKS])
ftup_kshorts = CreateSimpleTuple("KsTuple", "DecayTree", parsable_objs_kshorts,
loki_preamble, kshorts)
#FunTuple: Configure Funtuple algorithm
tuple_dimuons = Funtuple(
name="DimuonsTuple",
tree_name="DecayTree",
branches=branches,
variables=variables,
loki_preamble=loki_preamble,
inputs=dimuons)
#FunTuple: similarly for Ks we can make branches, functor collections, variables and FunTuple instance
branches_KS = {}
branches_KS['KS'] = 'KS0 -> pi+ pi-'
#associate the functor collections to KS branch name (NB: here we use functor collection used for jpsi)
variables_KS = {}
variables_KS['KS'] = variables_jpsi
#funtuple instance
tuple_kshorts = Funtuple(
name="KsTuple",
tree_name="DecayTree",
branches=branches_KS,
variables=variables_KS,
loki_preamble=loki_preamble,
inputs=kshorts)
algs = {
'DiMuons': upfront_reconstruction() + [dimuons, ftup_dimuons],
'KShorts': upfront_reconstruction() + [kshorts, ftup_kshorts]
'DiMuons': upfront_reconstruction() + [dimuons, tuple_dimuons],
'KShorts': upfront_reconstruction() + [kshorts, tuple_kshorts]
}
run_davinci(options, algs)
......@@ -36,15 +36,9 @@
<argument name="validator"><text>
findReferenceBlock("""DimuonsTuple SUCCESS Booked 1 N-Tuples and 0 Event Tag Collections
DimuonsTuple SUCCESS List of booked N-Tuples in directory "FILE1/DimuonsTuple"
DimuonsTuple SUCCESS ID=DecayTree Title="DecayTree" #items=10 {Jpsi_LOKI_P,Jpsi_LOKI_PT,Jpsi_LOKI_Muonp_PT,Jpsi_LOKI_Muonm_PT,Jpsi_LOKI_MAXPT,Jp}
DimuonsTuple SUCCESS ID=DecayTree Title="DecayTree" #items=24 {Jpsi_LOKI_MAXPT,Jpsi_LOKI_NTRCKS_ABV_THRSHLD,Jpsi_LOKI_Muonp_PT,Jpsi_LOKI_Muonm_P}
KsTuple SUCCESS Booked 1 N-Tuples and 0 Event Tag Collections
KsTuple SUCCESS List of booked N-Tuples in directory "FILE1/KsTuple"
KsTuple SUCCESS ID=DecayTree Title="DecayTree" #items=8 {Ks_LOKI_P,Ks_LOKI_PT,Ks_LOKI_Muonp_PT,Ks_LOKI_Muonm_PT,Ks_LOKI_MAXPT,Ks_LOKI_N_HI}
""", stdout, result, causes, signature_offset = 0, id = "Stream3")
KsTuple SUCCESS ID=DecayTree Title="DecayTree" #items=14 {KS_LOKI_MAXPT,KS_LOKI_NTRCKS_ABV_THRSHLD,KS_LOKI_Muonp_PT,KS_LOKI_Muonm_PT,KS_LOK}""")
</text></argument>
<argument name="validator"><text>
from DaVinciTests.QMTest.DaVinciExclusions import preprocessor
validateWithReference(preproc = preprocessor)
countErrorLines({"FATAL":0})
</text></argument>
</extension>
......@@ -59,7 +59,7 @@ RootHistSvc INFO Writing ROOT histograms to: DV-examp
HistogramPersistencySvc INFO Added successfully Conversion service:RootHistSvc
UnpackChargedProtos.ChargedProto... INFO Using retuned RICH el and mu DLL values in combined DLLs
FunctionalParticleMaker.LoKi::Hy... INFO CUT: ' ( (TrTYPE==3) &TrALL) '
DimuonsTuple INFO Initialising the FunTuple algorithm
DimuonsTuple INFO Initialising the FunTupleBase algorithm
DimuonsTuple INFO Conducting checks with LoKi
DimuonsTuple INFO Conducting checks with ThOr
DimuonsTuple INFO Setting the properties of ParticleTupleProp objects!
......@@ -117,7 +117,7 @@ LAZY_AND: DaVinci #=10 Sum=10
UnpackProtoParticle/UnpackNeutralProtos #=10 Sum=10 Eff=|( 100.0000 +- 0.00000 )%|
UnpackProtoParticle/UnpackChargedProtos #=10 Sum=10 Eff=|( 100.0000 +- 0.00000 )%|
CombineParticles/CombineParticles #=10 Sum=3 Eff=|( 30.00000 +- 14.4914 )%|
FunTuple_Particles/DimuonsTuple #=3 Sum=3 Eff=|( 100.0000 +- 0.00000 )%|
FunTupleBase_Particles/DimuonsTuple #=3 Sum=3 Eff=|( 100.0000 +- 0.00000 )%|
LAZY_AND: WriteFSR #=10 Sum=10 Eff=|( 100.0000 +- 0.00000 )%|
RecordStream/FSROutputStreamDstWriter #=10 Sum=10 Eff=|( 100.0000 +- 0.00000 )%|
ToolSvc INFO Removing all tools created by ToolSvc
......
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