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