Belle II Software light-2406-ragdoll
test_VariableToReturnValue.py
1#!/usr/bin/env python3
2
3
10
11import os
12import basf2
13import ROOT
14import b2test_utils
15
16inputFile = b2test_utils.require_file('mdst14.root', 'validation')
17path = basf2.create_path()
18path.add_module('RootInput', inputFileName=inputFile)
19
20# Add path for high multiplicity events
21mod = basf2.register_module('VariableToReturnValue')
22mod.param('variable', 'nTracks')
23high_multiplicity_path = basf2.create_path()
24high_multiplicity_path.add_module('VariablesToNtuple', particleList='', variables=['nTracks'], fileName='highMultiplicity.root')
25mod.if_value('>= 12', high_multiplicity_path, basf2.AfterConditionPath.CONTINUE)
26path.add_module(mod)
27
28
30 basf2.process(path)
31
32 # Testing
33 assert os.path.isfile('highMultiplicity.root'), "highMultiplicity.root wasn't created"
34 f = ROOT.TFile('highMultiplicity.root')
35 t = f.Get('ntuple')
36 assert bool(t), "ntuple isn't contained in file"
37 assert t.GetListOfBranches().Contains('nTracks'), "nTracks branch is missing"
38 assert t.GetListOfBranches().Contains('__weight__'), "weight branch is missing"
39
40 for event in t:
41 assert event.nTracks >= 12, "Expected >= 12 tracks in selected high multiplicity events"
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:189