Belle II Software light-2406-ragdoll
streamer_test.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from ROOT import TFile
13
14from b2test_utils import skip_test_if_light, clean_working_directory
15skip_test_if_light() # light builds don't contain simulation, reconstruction etc; skip before trying to import # noqa
16
17from simulation import add_simulation
18from reconstruction import add_reconstruction
19
20main = basf2.Path()
21main.add_module('EventInfoSetter', evtNumList=[5])
22main.add_module('ParticleGun', pdgCodes=[211, -211, 321, -321], nTracks=2)
23
24# detector simulation
25components = ['MagneticField', 'BeamPipe', 'CDC']
26simulation_components = ['CDC']
27add_simulation(main, simulation_components)
28add_reconstruction(main, simulation_components)
29basf2.set_module_parameters(main, type="Geometry", useDB=False, components=components)
30
31# output path
32main.add_module('RootOutput', outputFileName='streamer_test.root')
33
34with 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()")