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

Merge branch 'dfazzini_test_array_funtuple' into 'master'

Adding test for funtuple array with user-defined length

See merge request !694
parents 696138ff b8e54b27
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!694Adding test for funtuple array with user-defined length
Pipeline #4037174 passed
...@@ -50,7 +50,9 @@ variables_B = FunctorCollection({ ...@@ -50,7 +50,9 @@ variables_B = FunctorCollection({
F.MASS, F.MASS,
"TagTr_P": "TagTr_P":
F.MAP_INPUT_ARRAY(Functor=F.MAP_RANGE(Functor=F.P), Relations=tagAlg_rels), F.MAP_INPUT_ARRAY(Functor=F.MAP_RANGE(Functor=F.P), Relations=tagAlg_rels),
"TagTr_PT": # Currently this stores a branch called "indx" which corresponds to nPVs.
# You can give a custom name for this via following
"TagTr_PT[nTags]":
F.MAP_INPUT_ARRAY( F.MAP_INPUT_ARRAY(
Functor=F.MAP_RANGE(Functor=F.PT), Relations=tagAlg_rels), Functor=F.MAP_RANGE(Functor=F.PT), Relations=tagAlg_rels),
}) })
......
...@@ -24,7 +24,7 @@ FSROutputStreamDstWriter INFO Set up File Summary Record ...@@ -24,7 +24,7 @@ FSROutputStreamDstWriter INFO Set up File Summary Record
FSROutputStreamDstWriter INFO Events output: 1 FSROutputStreamDstWriter INFO Events output: 1
B0DsK_Tuple SUCCESS Booked 1 N-Tuples and 0 Event Tag Collections B0DsK_Tuple SUCCESS Booked 1 N-Tuples and 0 Event Tag Collections
B0DsK_Tuple SUCCESS List of booked N-Tuples in directory "FILE1/B0DsK_Tuple" B0DsK_Tuple SUCCESS List of booked N-Tuples in directory "FILE1/B0DsK_Tuple"
B0DsK_Tuple SUCCESS ID=DecayTree Title="DecayTree" #items=10 {B0_THOR_MASS,indx,B0_TagTr_P[1]/V,B0_TagTr_PT[1]/V,B0_THOR_P,B0_THOR_PT,Ds_THOR_P} B0DsK_Tuple SUCCESS ID=DecayTree Title="DecayTree" #items=11 {B0_THOR_MASS,indx,B0_TagTr_P[1]/V,nTags,B0_TagTr_PT[1]/V,B0_THOR_P,B0_THOR_PT,Ds_}
LAZY_AND: DaVinci #=113 Sum=78 Eff=|( 69.02655 +- 4.34974 )%| LAZY_AND: DaVinci #=113 Sum=78 Eff=|( 69.02655 +- 4.34974 )%|
NONLAZY_OR: FileSummaryRecords #=113 Sum=113 Eff=|( 100.0000 +- 0.00000 )%| NONLAZY_OR: FileSummaryRecords #=113 Sum=113 Eff=|( 100.0000 +- 0.00000 )%|
LAZY_AND: GenFSR #=113 Sum=113 Eff=|( 100.0000 +- 0.00000 )%| LAZY_AND: GenFSR #=113 Sum=113 Eff=|( 100.0000 +- 0.00000 )%|
......
###############################################################################
# (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. #
###############################################################################
"""
Option file for testing if FunTuple handles correctly an array with a user-defined size.
This example is meant to be run with:
$ ./run davinci run-mc --inputfiledb Spruce_all_lines_dst Phys/DaVinci/options/DaVinciDB-Example.yaml --user_algorithms DaVinciTests/tests/options/option_davinci_funtuple_array:main
"""
import Functors as F
from PyConf.components import force_location
from PyConf.Algorithms import ParticleTaggerAlg, ParticleContainerMerger
from FunTuple import FunctorCollection, FunTuple_Particles as Funtuple
from DaVinci.algorithms import add_filter
from DaVinci.standard_particles import make_long_pions_from_spruce
from DaVinci.reco_objects import reconstruction
from DaVinci import options
options.annsvc_config = 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/spruce_all_lines_realtime_newPacking.tck.json'
options.evt_max = 100
options.histo_file = 'DV-test-array-his.root'
options.ntuple_file = 'DV-test-array-ntp.root'
options.process = 'Spruce'
bd2dsk_line = "SpruceB2OC_BdToDsmK_DsmToHHH_FEST_Line"
bd2dsk_data = force_location(f"/Event/Spruce/{bd2dsk_line}/Particles")
# In this test we want to save the information regarding long pions available in the event
# storing them in a set of arrays.
with reconstruction.bind(process=options.process):
pions = make_long_pions_from_spruce()
tagging_container = ParticleContainerMerger(
InputContainers=[pions]).OutputContainer
tagAlg = ParticleTaggerAlg(
Input=bd2dsk_data, TaggingContainer=tagging_container, OutputLevel=3)
tagAlg_rels = tagAlg.OutputRelations
#make collection of functors
variables_B = FunctorCollection({
'THOR_MASS':
F.MASS,
"TagTr_P":
F.MAP_INPUT_ARRAY(Functor=F.MAP_RANGE(Functor=F.P), Relations=tagAlg_rels),
# Currently this stores a branch called "indx" which corresponds to nPVs.
# You can give a custom name for this via following
"TagTr_PT[nTags]":
F.MAP_INPUT_ARRAY(
Functor=F.MAP_RANGE(Functor=F.PT), Relations=tagAlg_rels),
})
# Defining fields and variables we want to store in our tuple
fields = {'B0': "[B0 -> D_s- K+]CC"}
variables = {'B0': variables_B}
tuple_B0DsK = Funtuple(
name="B0DsK_Tuple",
tuple_name="DecayTree",
fields=fields,
variables=variables,
inputs=bd2dsk_data)
filter_B0DsK = add_filter("HDRFilter_B0DsK",
f"HLT_PASS('{bd2dsk_line}Decision')")
def main():
algs = [filter_B0DsK, tuple_B0DsK]
return algs, []
<?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: dfazzini
# Purpose: Test for checking if FunTuple handles correctly an array with a user-defined size.
# Prerequisites: None
# inputfiledb Spruce_all_lines_dst $DAVINCIROOT/options/DaVinciDB-Example.yaml
# user_algorithms ../options/option_davinci_funtuple_array:main
#######################################################
-->
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program"><text>davinci</text></argument>
<argument name="timeout"><integer>1000</integer></argument>
<argument name="args"><set>
<text>run-mc</text>
<text>--inputfiledb</text>
<text>Spruce_all_lines_dst</text>
<text>$DAVINCIROOT/options/DaVinciDB-Example.yaml</text>
<text>--user_algorithms</text>
<text>../options/option_davinci_funtuple_array:main</text>
</set></argument>
<argument name="reference"><text>../refs/test_davinci_funtuple_array.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 os
from ROOT import TFile
list_vars = ["B0_THOR_MASS", "B0_TagTr_P", "B0_TagTr_PT", "nTags", "indx"]
vars_stored = []
ntuple = "DV-test-array-ntp.root"
if not os.path.isfile(ntuple): raise Exception(f"File: {ntuple} does not exist!")
infile = TFile.Open(ntuple)
intree = infile.Get('B0DsK_Tuple/DecayTree')
assert intree.GetEntries()
for var in list_vars:
vars_stored.append(var)
vars_stored = sorted(vars_stored)
names = sorted([b.GetName() for b in intree.GetListOfLeaves()])
excluded_1 = set(vars_stored) - set(names)
excluded_2 = set(names) - set(vars_stored)
if len(excluded_1) != 0: raise Exception('Number of stored variables is less than what is expected. The extra variables expected are: ' , excluded_1)
if len(excluded_2) != 0: raise Exception('Number of stored variables is greater than what is expected. The extra variables stored are: ', excluded_2)
infile.Close()
</text></argument>
</extension>
source diff could not be displayed: it is too large. Options to address this: view the blob.
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