Belle II Software  release-05-01-25
test_VariableToReturnValue.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import os
5 import sys
6 import basf2
7 import ROOT
8 import b2test_utils
9 from ROOT import Belle2
10 
11 inputFile = b2test_utils.require_file('mdst12.root', 'validation')
12 path = basf2.create_path()
13 path.add_module('RootInput', inputFileName=inputFile)
14 
15 # Add path for high multiplicity events
16 mod = basf2.register_module('VariableToReturnValue')
17 mod.param('variable', 'nTracks')
18 high_multiplicity_path = basf2.create_path()
19 high_multiplicity_path.add_module('VariablesToNtuple', particleList='', variables=['nTracks'], fileName='highMultiplicity.root')
20 mod.if_value('>= 12', high_multiplicity_path, basf2.AfterConditionPath.CONTINUE)
21 path.add_module(mod)
22 
23 
25  basf2.process(path)
26 
27  # Testing
28  assert os.path.isfile('highMultiplicity.root'), "highMultiplicity.root wasn't created"
29  f = ROOT.TFile('highMultiplicity.root')
30  t = f.Get('ntuple')
31  assert bool(t), "ntuple isn't contained in file"
32  assert t.GetListOfBranches().Contains('nTracks'), "nTracks branch is missing"
33  assert t.GetListOfBranches().Contains('__weight__'), "weight branch is missing"
34 
35  for event in t:
36  assert event.nTracks >= 12, "Expected >= 12 tracks in selected high multiplicity events"
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
b2test_utils.clean_working_directory
def clean_working_directory()
Definition: __init__.py:176
b2test_utils.require_file
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:47