Belle II Software  release-08-01-10
test_VariableToReturnValue.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import os
12 import basf2
13 import ROOT
14 import b2test_utils
15 
16 inputFile = b2test_utils.require_file('mdst14.root', 'validation')
17 path = basf2.create_path()
18 path.add_module('RootInput', inputFileName=inputFile)
19 
20 # Add path for high multiplicity events
21 mod = basf2.register_module('VariableToReturnValue')
22 mod.param('variable', 'nTracks')
23 high_multiplicity_path = basf2.create_path()
24 high_multiplicity_path.add_module('VariablesToNtuple', particleList='', variables=['nTracks'], fileName='highMultiplicity.root')
25 mod.if_value('>= 12', high_multiplicity_path, basf2.AfterConditionPath.CONTINUE)
26 path.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