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