Belle II Software development
extmuid_createPions.py
1#!/usr/bin/env python3
2
3
10
11
18
19"""
20<header>
21 <output>pion-ExtMuidValidation.root</output>
22 <contact>piilonen@vt.edu</contact>
23 <description>Create events with 1 pion track for ext/muid validation.</description>
24</header>
25"""
26
27import glob
28import basf2 as b2
29import os
30from simulation import add_simulation
31from reconstruction import add_reconstruction
32
33ACTIVE = True
34
35
36def run():
37 """
38 Create pion sample for the ExtMuid validation.
39 """
40
41 b2.set_random_seed(654321)
42
43 output_filename = '../pion-ExtMuidValidation.root'
44
45 print(output_filename)
46
47 path = b2.create_path()
48
49 eventinfosetter = b2.register_module('EventInfoSetter')
50 eventinfosetter.param('evtNumList', [1000])
51 path.add_module(eventinfosetter)
52
53 pgun = b2.register_module('ParticleGun')
54 param_pgun = {
55 'pdgCodes': [-211, 211],
56 'nTracks': 1,
57 'varyNTracks': 0,
58 'momentumGeneration': 'uniform',
59 'momentumParams': [0.5, 5.0],
60 'thetaGeneration': 'uniformCos',
61 'thetaParams': [15., 150.],
62 'phiGeneration': 'uniform',
63 'phiParams': [0.0, 360.0],
64 'vertexGeneration': 'fixed',
65 'xVertexParams': [0.0],
66 'yVertexParams': [0.0],
67 'zVertexParams': [0.0],
68 }
69 pgun.param(param_pgun)
70 path.add_module(pgun)
71
72 # add simulation and reconstruction modules to the path
73 if 'BELLE2_BACKGROUND_DIR' in os.environ:
74 background_files = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
75 add_simulation(path, bkgfiles=background_files)
76 else:
77 b2.B2FATAL('BELLE2_BACKGROUND_DIR is not set.')
78
79 add_reconstruction(path)
80
81 output = b2.register_module('RootOutput')
82 output.param('outputFileName', output_filename)
83 output.param('branchNames', ['MCParticles', 'ExtHits', 'KLMMuidLikelihoods', 'KLMHit2ds'])
84 path.add_module(output)
85 path.add_module('Progress')
86
87 b2.process(path)
88 print(b2.statistics)
89
90
91if __name__ == '__main__':
92 if ACTIVE:
93 run()
94 else:
95 print("This validation deactivated and thus basf2 is not executed.\n"
96 "If you want to run this validation, please set the 'ACTIVE' flag above to 'True'.\n"
97 "Exiting.")