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