Skip to content
Snippets Groups Projects
Commit ce6aed65 authored by Abhijit Mathad's avatar Abhijit Mathad Committed by Patrick Koppenburg
Browse files

Follow Analysis!980

parent ab5a5176
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!907Follow https://gitlab.cern.ch/lhcb/Analysis/-/merge_requests/980
###############################################################################
# (c) Copyright 2023 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. #
###############################################################################
"""
Test for branches related to multiple candidates in an event.
- test that the branches related to totCandidates and nCandidates are filled correctly
"""
import Functors as F
from Hlt2Conf.standard_particles import make_detached_mumu
from RecoConf.reconstruction_objects import upfront_reconstruction
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
from DaVinci import Options, make_config
def main(options: Options):
# Prepare the node with the selection
dimuons = make_detached_mumu()
#FunTuple: Jpsi info
fields = {}
fields['Jpsi'] = 'J/psi(1S) -> mu+ mu-'
#make collection of functors for Jpsi
variables_jpsi = FunctorCollection({
'THOR_MASS': F.MASS,
})
#associate FunctorCollection to field (branch) name
variables = {}
variables['Jpsi'] = variables_jpsi
#Configure Funtuple algorithm
tuple_dimuons = Funtuple(
name="DimuonsTuple",
tuple_name="DecayTree",
fields=fields,
variables=variables,
inputs=dimuons,
store_multiple_cand_info=True)
return make_config(options, upfront_reconstruction() + [tuple_dimuons])
<?xml version="1.0" ?>
<!--
###############################################################################
# (c) Copyright 2023 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. #
###############################################################################
-->
<!--
This is a test that checks that the multiplecand_branches example runs
-->
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program"><text>lbexec</text></argument>
<argument name="args"><set>
<text>DaVinciTests.multiplecand_branches:main</text>
</set></argument>
<argument name="options_yaml_fn"><text>$DAVINCIEXAMPLESROOT/example_data/Upgrade_Bd2KstarMuMu_ldst.yaml</text></argument>
<argument name="extra_options_yaml"><text>
evt_max: 10
histo_file: DV-example-tupling-DTF-his.root
input_raw_format: 4.3
ntuple_file: DV-example-tupling-DTF-ntp.root
input_process: Brunel
</text></argument>
<argument name="validator"><text>
import sys, os, glob
from ROOT import TFile
from PyConf.components import findRootObjByDir
B_vars_stored=['totCandidates', 'nCandidate', 'EVENTNUMBER', 'RUNNUMBER', 'Jpsi_THOR_MASS']
#sort the expected vars
B_vars_stored = sorted(B_vars_stored)
#open the TFile and TTree
ntuple = './DV-example-tupling-DTF-ntp.root'
if not os.path.isfile(ntuple): raise Exception(f"File: {ntuple} does not exist!")
f = TFile.Open(ntuple)
t_B = findRootObjByDir(f, 'DimuonsTuple', 'DecayTree')
#sort the stores vars
b_names = sorted([b.GetName() for b in t_B.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)
f.Close()
print('Test successfully completed!')
os.system(f"rm {ntuple}")
</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