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

Merge branch 'AM_v2' into 'master'

Test of FunTuple with v2 Composites and ChargedBasic

See merge request !695
parents 524eb7e1 f26b973a
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!695Test of FunTuple with v2 Composites and ChargedBasic
Pipeline #4067482 passed
###############################################################################
# (c) Copyright 2021-2022 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.Algorithms import ChargedBasicsProducer, UniqueIDGeneratorAlg
from PyConf.Algorithms import ThOrCombiner__2ChargedBasics
from PyConf.Algorithms import ThOrCombiner__CompositesChargedBasics
import Functors as F
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Composites
from FunTuple import FunTuple_ChargedBasics
from DaVinci import options
#make unique_id_generator
unique_id_gen = UniqueIDGeneratorAlg()
#produce charged basic particles
produce_muons = ChargedBasicsProducer(
InputUniqueIDGenerator=unique_id_gen, ParticleID='muon')
produce_jpsi = ThOrCombiner__2ChargedBasics(
InputUniqueIDGenerator=unique_id_gen,
DecayDescriptor="J/psi(1S) -> mu+ mu-",
Input1=produce_muons.Particles,
Input2=produce_muons.Particles)
produce_kaons = ChargedBasicsProducer(
InputUniqueIDGenerator=unique_id_gen, ParticleID='kaon')
produce_B = ThOrCombiner__CompositesChargedBasics(
InputUniqueIDGenerator=unique_id_gen,
DecayDescriptor="[B+ -> J/psi(1S) K+]cc",
Input1=produce_jpsi.Output,
Input2=produce_kaons.Particles)
#define FunTuple instance
# Cannot yet use CHILD functors with v2.
variables = FunctorCollection({"PX": F.PX, "PY": F.PY, "PZ": F.PZ})
#Note CC here and cc (small case) above in the decay descriptor. Needs to be uniform.
# Decay descriptor parsing is not yet available with v2 Composites.
# Hence, we are simply running over all particles in TES and not selecting any subset using the decay descriptor for the moment.
bfields = {"B": "[B+ -> J/psi(1S) K+]CC"}
bvars = {"B": variables}
ntuple_composite = FunTuple_Composites(
name="TupleB",
tuple_name="DecayTree",
fields=bfields,
variables=bvars,
inputs=produce_B.Output)
# Decay descriptor parsing is not yet available with v2 Composites or ChargedBasic (see above comment).
kfields = {"K": "[B+ -> J/psi(1S) ^K+]CC"}
kvars = {"K": variables}
ntuple_charged_basic = FunTuple_ChargedBasics(
name="TupleK",
tuple_name="DecayTree",
fields=kfields,
variables=kvars,
inputs=produce_kaons.Particles)
options.evt_max = 2
def main():
return {
"UserAlgs_1": [ntuple_composite],
'UserAlgs_2': {ntuple_charged_basic}
}, []
###############################################################################
# (c) Copyright 2022 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. #
###############################################################################
#non-sense json file
annsvc_config: 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/NovemberFEST/hlt2_D0_Kpi_10evts_newPacking.tck.json'
evt_max: -1
histo_file: 'v2_example.root'
lumi: false
ntuple_file: 'v2_example.root'
print_freq: 1
#non-sense process
process: 'Hlt2'
stream: 'default'
\ No newline at end of file
<?xml version="1.0" ?>
<!--
###############################################################################
# (c) Copyright 2021-2022 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. #
###############################################################################
-->
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<!--
#######################################################
# SUMMARY OF THIS TEST
# ...................
# Author: Abhijit Mathad
# Purpose: Test for the new DaVinci configuration checking the correct processing v2 composites
# Prerequisites: None
# inputfiledb FEST_November_2021_dst_newPacking $DAVINCIROOT/options/DaVinciDB-Example.yaml
# joboptfile ../options/option_davinci_v2_composites.yaml
# user_algorithms ../options/option_davinci_v2_composites:main
#######################################################
-->
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program"><text>davinci</text></argument>
<argument name="args"><set>
<text>--inputfiledb</text>
<text>FEST_November_2021_dst_newPacking</text>
<text>$DAVINCIROOT/options/DaVinciDB-Example.yaml</text>
<text>--joboptfile</text>
<text>../options/option_davinci_v2_composites.yaml</text>
<text>--user_algorithms</text>
<text>../options/option_davinci_v2_composites:main</text>
</set></argument>
<argument name="reference"><text>../refs/test_davinci_v2_composites.ref</text></argument>
<argument name="error_reference"><text>../refs/empty.ref</text></argument>
<argument name="validator"><text>
#from DaVinciTests.QMTest.DaVinciExclusions import preprocessor
#validateWithReference(preproc = preprocessor)
import sys, os, glob
from ROOT import TFile
B_vars_stored =['B_PX', 'B_PY', 'B_PZ']
K_vars_stored =['K_PX', 'K_PY', 'K_PZ']
#sort the expected vars
B_vars_stored = sorted(B_vars_stored)
#open the TFile and TTree
ntuple = './v2_example.root'
if not os.path.isfile(ntuple): raise Exception(f"File: {ntuple} does not exist!")
f = TFile.Open(ntuple)
t_B = f.Get('TupleB/DecayTree')
t_K = f.Get('TupleK/DecayTree')
#sort the stores vars
b_names = sorted([b.GetName() for b in t_B.GetListOfLeaves()])
K_names = sorted([K.GetName() for K in t_K.GetListOfLeaves()])
B_excluded_1 = set(B_vars_stored) - set(b_names)
B_excluded_2 = set(b_names) - set(B_vars_stored)
if len(B_excluded_1) != 0: raise Exception('Number of stored variables is less than what is expected. The extra variables expected are: ' , B_excluded_1)
if len(B_excluded_2) != 0: raise Exception('Number of stored variables is greater than what is expected. The extra variables stored are: ', B_excluded_2)
K_excluded_1 = set(K_vars_stored) - set(K_names)
K_excluded_2 = set(K_names) - set(K_vars_stored)
if len(K_excluded_1) != 0: raise Exception('Number of stored variables is less than what is expected. The extra variables expected are: ' , K_excluded_1)
if len(K_excluded_2) != 0: raise Exception('Number of stored variables is greater than what is expected. The extra variables stored are: ', K_excluded_2)
f.Close()
print('Test successfully completed!')
os.system(f"rm {ntuple}")
#countErrorLines({"FATAL":0, "ERROR":0})
</text></argument>
</extension>
This diff is collapsed.
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