Belle II Software  release-05-01-25
v2nt_multiple_trees_samename.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import ROOT
5 import b2test_utils
6 from basf2 import set_random_seed, create_path, process
7 from b2test_utils import configure_logging_for_tests
8 from modularAnalysis import variablesToNtuple
9 
10 set_random_seed("1337")
11 # make logging a bit less verbose and more reproducible
12 configure_logging_for_tests()
13 
14 
16 testpath = create_path()
17 testpath.add_module('EventInfoSetter', evtNumList=[10], runList=[0], expList=[0])
18 testpath.add_module('ParticleLoader', decayStringsWithCuts=[('e+', '')])
19 variablesToNtuple("e+", ['electronID', 'p', 'isSignal'], path=testpath)
20 variablesToNtuple("e+", ['electronID', 'p', 'isSignal'], path=testpath)
22  b2test_utils.safe_process(testpath) # throws B2FATAL, *this* script needs to exit happily
23 
24 
26 testpath = create_path()
27 testpath.add_module('EventInfoSetter', evtNumList=[10], runList=[0], expList=[0])
28 variablesToNtuple("e+", ['electronID', 'p', 'isSignal'], path=testpath)
31 
32 
34 testpath = create_path()
35 testpath.add_module('EventInfoSetter', evtNumList=[10], runList=[0], expList=[0])
36 testpath.add_module('ParticleLoader', decayStringsWithCuts=[('e+', '')])
37 testpath.add_module('ParticleLoader', decayStringsWithCuts=[('pi+', '')])
38 variablesToNtuple("e+", ['electronID', 'p', 'isSignal'], treename='firsttree',
39  filename="firstfile.root", path=testpath)
40 
41 variablesToNtuple("", ['nTracks'], treename='intermediate',
42  filename="secondfile.root", path=testpath)
43 
44 variablesToNtuple("pi+", ['electronID', 'p', 'isSignal'], treename='secondtree',
45  filename="firstfile.root", path=testpath)
46 
49  f1 = ROOT.TFile('firstfile.root')
50  t1 = f1.Get('firsttree')
51  t2 = f1.Get('secondtree')
52  assert bool(t1), "firsttree isn't contained in file"
53  assert bool(t2), "secondtree isn't contained in file"
54 
55  f2 = ROOT.TFile('secondfile.root')
56  t = f2.Get('intermediate')
57  assert bool(t), "intermediate isn't contained in file"
variablesToNtuple
Definition: variablesToNtuple.py:1
b2test_utils.clean_working_directory
def clean_working_directory()
Definition: __init__.py:176
b2test_utils.safe_process
def safe_process(*args, **kwargs)
Definition: __init__.py:224