Commit 3f43a91e authored by Patrick Koppenburg's avatar Patrick Koppenburg 🍃
Browse files

Merge branch 'MC_Sprucing' into 'master'

Test MC associations for Sprucing output

See merge request !653
parents 20c1c9f4 9da05da2
Pipeline #3591120 passed with stage
in 27 seconds
###############################################################################
# (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. #
###############################################################################
from FunTuple import FunctorCollection
import Functors as F
from FunTuple import FunTuple_Particles as Funtuple
from FunTuple.functorcollections import Kinematics
from DaVinci.truth_matching import ConfiguredMCTruthAndBkgCatAlg
from DaVinci.algorithms import add_filter
from PyConf.application import make_data_with_FetchDataFromFile
#FunTuple: define branches.
fields = {
'B0': "[B0 -> D_s- K+]CC",
'Ds': "[B0 -> ^D_s- K+]CC",
'Kp': "[B0 -> D_s- ^K+]CC"
}
#FunTuple: make functor collection from the imported functor library Kinematics
variables_all = Kinematics()
#FunTuple: associate functor collections to branch name
variables = {
'ALL': variables_all, #adds variables to all branches
}
def main():
B_data = make_data_with_FetchDataFromFile(
"/Event/Spruce/Spruce_Test_line/Particles")
my_filter = add_filter("HDRFilter_B",
"HLT_PASS('Spruce_Test_lineDecision')")
#get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output
mctruth = ConfiguredMCTruthAndBkgCatAlg(
inputs=B_data, root_in_tes="/Event/Spruce/HLT2")
#Add trueid info to each of the branches
trueid_bkgcat_info = {
"TRUEID":
F.MAP_INPUT(Functor=F.PARTICLE_ID, Relations=mctruth.MCAssocTable),
"TRUEKEY":
F.MAP_INPUT(Functor=F.OBJECT_KEY, Relations=mctruth.MCAssocTable),
"TRUEPT":
F.MAP_INPUT(Functor=F.PT, Relations=mctruth.MCAssocTable),
"TRUEPX":
F.MAP_INPUT(Functor=F.PX, Relations=mctruth.MCAssocTable),
"TRUEPY":
F.MAP_INPUT(Functor=F.PY, Relations=mctruth.MCAssocTable),
"TRUEPZ":
F.MAP_INPUT(Functor=F.PZ, Relations=mctruth.MCAssocTable),
"TRUEENERGY":
F.MAP_INPUT(Functor=F.ENERGY, Relations=mctruth.MCAssocTable),
"TRUEP":
F.MAP_INPUT(Functor=F.P, Relations=mctruth.MCAssocTable),
"TRUEFOURMOMENTUM":
F.MAP_INPUT(Functor=F.FOURMOMENTUM, Relations=mctruth.MCAssocTable),
"BKGCAT":
F.BKGCAT(Relations=mctruth.BkgCatTable)
}
for branch in variables.keys():
variables[branch] += FunctorCollection(trueid_bkgcat_info)
my_tuple = Funtuple(
name="Tuple",
tuple_name="DecayTree",
fields=fields,
variables=variables,
inputs=B_data)
return {"UserAlgs": [my_filter, mctruth, my_tuple]}, []
###############################################################################
# (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. #
###############################################################################
annsvc_config: 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/spruce_MCtestfile.tck.json'
evt_max: -1
histo_file: 'sprucing_mc_histos.root'
input_raw_format: 0.3
lumi: false
ntuple_file: 'sprucing_mc_tuple.root'
print_freq: 1
skip_events: 0
process: 'Spruce'
stream: 'default'
\ No newline at end of file
<?xml version="1.0" ?>
<!--
###############################################################################
# (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. #
###############################################################################
-->
<!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: nskidmor
# Purpose: Test for the new DaVinci configuration checking the correct processing of a spruced file WITH MC association
# Prerequisites: None
# inputfiledb test_spruce_MCtools $DAVINCIROOT/options/DaVinciDB-Example.yaml
# joboptfile ../../python/DaVinciExamples/tupling/options_davinci_tupling_from_spruce_mc.yaml
# user_algorithms ../../python/DaVinciExamples/tupling/options_davinci_tupling_from_spruce_mc:main
#######################################################
-->
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program"><text>davinci</text></argument>
<argument name="args"><set>
<text>run-mc</text>
<text>--inputfiledb</text>
<text>test_spruce_MCtools</text>
<text>$DAVINCIROOT/options/DaVinciDB-Example.yaml</text>
<text>--joboptfile</text>
<text>../../python/DaVinciExamples/tupling/option_davinci_tupling_from_spruce_mc.yaml</text>
<text>--user_algorithms</text>
<text>../../python/DaVinciExamples/tupling/option_davinci_tupling_from_spruce_mc:main</text>
</set></argument>
<argument name="validator"><text>
findReferenceBlock("""Tuple SUCCESS Booked 1 N-Tuples and 0 Event Tag Collections"""
, stdout, result, causes, signature_offset = 0)
import os
from ROOT import TFile
#open the TFile and TTree
ntuple = './sprucing_mc_tuple.root'
ttree_name = 'Tuple/DecayTree'
if not os.path.isfile(ntuple):
raise Exception(f"File: {ntuple} does not exist!")
f = TFile.Open(ntuple)
t_B = f.Get(ttree_name)
#check if all elements of bkg cat are zero or not
B0_BKGCAT = [str(entry.B0_BKGCAT) for entry in t_B]
print('B_BKGCAT: ' + ', '.join(B0_BKGCAT))
Ds_BKGCAT = [str(entry.Ds_BKGCAT) for entry in t_B]
print('Ds_BKGCAT: ' + ', '.join(Ds_BKGCAT))
is_all_element_zero = all([v == 0 for v in B0_BKGCAT]) or all(
[v == 60 for v in Ds_BKGCAT])
if is_all_element_zero:
raise Exception('MC background association not working')
f.Close()
print('Test successfully completed!')
countErrorLines({"FATAL":0, "ERROR":0})
</text></argument>
</extension>
......@@ -84,3 +84,17 @@ test_read_xgen:
Author: 'Davide Fazzini'
Data: '2021-11'
Comment: "B+ -> J/psi(1S) (-> mu+ mu-) K+ ntuple produced for testing DV on xgen files"
test_spruce_MCtools:
filenames:
- 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/spruce_MCtestfile.dst'
qualifiers:
data_type: Upgrade
input_type: DST
simulation: true
conddb_tag: sim-20171127-vc-md100
dddb_tag: dddb-20171126
metadata:
Author: 'Nicole Skidmore'
Data: '2022-02'
Comment: "DST file to test MC tools on Sprucing output"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment