Belle II Software  release-06-02-00
test_VariableToReturnValue.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import os
13 import basf2
14 import ROOT
15 import b2test_utils
16 
17 inputFile = b2test_utils.require_file('mdst14.root', 'validation')
18 path = basf2.create_path()
19 path.add_module('RootInput', inputFileName=inputFile)
20 
21 # Add path for high multiplicity events
22 mod = basf2.register_module('VariableToReturnValue')
23 mod.param('variable', 'nTracks')
24 high_multiplicity_path = basf2.create_path()
25 high_multiplicity_path.add_module('VariablesToNtuple', particleList='', variables=['nTracks'], fileName='highMultiplicity.root')
26 mod.if_value('>= 12', high_multiplicity_path, basf2.AfterConditionPath.CONTINUE)
27 path.add_module(mod)
28 
29 
31  basf2.process(path)
32 
33  # Testing
34  assert os.path.isfile('highMultiplicity.root'), "highMultiplicity.root wasn't created"
35  f = ROOT.TFile('highMultiplicity.root')
36  t = f.Get('ntuple')
37  assert bool(t), "ntuple isn't contained in file"
38  assert t.GetListOfBranches().Contains('nTracks'), "nTracks branch is missing"
39  assert t.GetListOfBranches().Contains('__weight__'), "weight branch is missing"
40 
41  for event in t:
42  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:185