Belle II Software  release-08-01-10
streamer_test.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2
12 from ROOT import TFile
13 
14 from b2test_utils import skip_test_if_light, clean_working_directory
15 skip_test_if_light() # light builds don't contain simulation, reconstruction etc; skip before trying to import # noqa
16 
17 from simulation import add_simulation
18 from reconstruction import add_reconstruction
19 
20 main = basf2.Path()
21 main.add_module('EventInfoSetter', evtNumList=[5])
22 main.add_module('ParticleGun', pdgCodes=[211, -211, 321, -321], nTracks=2)
23 
24 # detector simulation
25 components = ['MagneticField', 'BeamPipe', 'CDC']
26 simulation_components = ['CDC']
27 add_simulation(main, simulation_components)
28 add_reconstruction(main, simulation_components)
29 basf2.set_module_parameters(main, type="Geometry", useDB=False, components=components)
30 
31 # output path
32 main.add_module('RootOutput', outputFileName='streamer_test.root')
33 
34 with clean_working_directory():
35  basf2.process(main)
36 
37  # load file and see if it can be read properly
38  tfile = TFile('streamer_test.root')
39  tree = tfile.Get('tree')
40 
41  # seems to be ok, most of the time
42  tree.Project("", "MCParticles.m_pdg")
43 
44  # Used to create problems when genfit::AbsTrackRep didn't have schema
45  # evolution. With no '+' in linkdef, this crashes
46  tree.Project("", "abs(MCParticles.m_pdg)")
47 
48  # wether TTreeFormula chokes on something depends on alphabetical order...
49  # so this should get it to iterate over the entire contents
50  tree.Project("", "ZZZ.Doesnt.Exist")
51 
52  # also test using some class members
53  tree.Project("", "GF2Tracks.getNumPoints()")