Belle II Software  release-06-02-00
v2nt_multiple_trees_samename.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import ROOT
13 import b2test_utils
14 from basf2 import create_path, set_random_seed
15 from b2test_utils import configure_logging_for_tests
16 from modularAnalysis import variablesToNtuple
17 
18 set_random_seed("1337")
19 # make logging a bit less verbose and more reproducible
20 configure_logging_for_tests()
21 
22 
24 testpath = create_path()
25 testpath.add_module('EventInfoSetter', evtNumList=[10], runList=[0], expList=[0])
26 testpath.add_module('ParticleLoader', decayStrings=['e+'])
27 variablesToNtuple("e+:all", ['electronID', 'p', 'isSignal'], path=testpath)
28 variablesToNtuple("e+:all", ['electronID', 'p', 'isSignal'], path=testpath)
30  b2test_utils.safe_process(testpath) # throws B2FATAL, *this* script needs to exit happily
31 
32 
34 testpath = create_path()
35 testpath.add_module('EventInfoSetter', evtNumList=[10], runList=[0], expList=[0])
36 variablesToNtuple("e+", ['electronID', 'p', 'isSignal'], path=testpath)
39 
40 
42 testpath = create_path()
43 testpath.add_module('EventInfoSetter', evtNumList=[10], runList=[0], expList=[0])
44 testpath.add_module('ParticleLoader', decayStrings=['e+'])
45 testpath.add_module('ParticleLoader', decayStrings=['pi+'])
46 variablesToNtuple("e+:all", ['electronID', 'p', 'isSignal'], treename='firsttree',
47  filename="firstfile.root", path=testpath)
48 
49 variablesToNtuple("", ['nTracks'], treename='intermediate',
50  filename="secondfile.root", path=testpath)
51 
52 variablesToNtuple("pi+:all", ['electronID', 'p', 'isSignal'], treename='secondtree',
53  filename="firstfile.root", path=testpath)
54 
57  f1 = ROOT.TFile('firstfile.root')
58  t1 = f1.Get('firsttree')
59  t2 = f1.Get('secondtree')
60  assert bool(t1), "firsttree isn't contained in file"
61  assert bool(t2), "secondtree isn't contained in file"
62 
63  f2 = ROOT.TFile('secondfile.root')
64  t = f2.Get('intermediate')
65  assert bool(t), "intermediate isn't contained in file"
def clean_working_directory()
Definition: __init__.py:185
def safe_process(*args, **kwargs)
Definition: __init__.py:233