Belle II Software  release-08-01-10
SimpleMCTracking.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
36 
37 import basf2 as b2
38 
39 b2.set_log_level(b2.LogLevel.INFO)
40 # set_log_level(LogLevel.DEBUG)
41 b2.set_random_seed(1028307)
42 
43 # register necessary modules
44 eventinfosetter = b2.register_module('EventInfoSetter')
45 
46 # generate one event
47 eventinfosetter.param('expList', [0])
48 eventinfosetter.param('runList', [1])
49 eventinfosetter.param('evtNumList', [1])
50 eventinfoprinter = b2.register_module('EventInfoPrinter')
51 
52 # create geometry
53 gearbox = b2.register_module('Gearbox')
54 geometry = b2.register_module('Geometry')
55 
56 # simulate CDC only; B-field outside CDC = 0
57 geometry.param('components', ['MagneticFieldConstant4LimitedRCDC', 'CDC'])
58 
59 # particle gun to shoot particles in the detector
60 pGun = b2.register_module('ParticleGun')
61 
62 # choose the particles you want to simulate
63 param_pGun = {
64  'pdgCodes': [211],
65  'nTracks': 1,
66  'varyNTracks': 0,
67  'momentumGeneration': 'uniform',
68  'momentumParams': [1.0, 1.0],
69  'thetaGeneration': 'uniform',
70  # 'thetaGeneration': 'uniformCos',
71  'thetaParams': [90., 90.],
72  'phiGeneration': 'uniform',
73  'phiParams': [0., 360.],
74  'xVertexParams': [0.0, 0.0],
75  'yVertexParams': [0.0, 0.0],
76  'zVertexParams': [0.0, 0.0],
77 }
78 pGun.param(param_pGun)
79 
80 # simulation
81 g4sim = b2.register_module('FullSim')
82 # this is needed for the MCTrackFinder to work correctly <- obsolete ?
83 g4sim.param('StoreAllSecondaries', True)
84 # g4sim.param('SecondariesEnergyCut', 0.0)
85 g4sim.param('UICommandsAtIdle', ['/control/execute interactions.mac'])
86 # suppress delta-rays
87 g4sim.param('ProductionCut', 1000000.)
88 
89 # digitizer
90 cdcDigitizer = b2.register_module('CDCDigitizer')
91 
92 # find MCTracks
93 # mctrackfinder = register_module('MCTrackFinder')
94 # mctrackfinder = register_module('TrackFinderMCTruth')
95 mctrackfinder = b2.register_module('TrackFinderMCTruthRecoTracks')
96 
97 # select which detectors you would like to use
98 param_mctrackfinder = { # select which particles to use: primary particles
99  'UseCDCHits': 1,
100  'UseSVDHits': 0,
101  'UsePXDHits': 0,
102  # 'UseClusters': False,
103  'WhichParticles': ['primary'],
104  # 'WhichParticles': ['CDC'],
105 }
106 mctrackfinder.param(param_mctrackfinder)
107 
108 # setupgf
109 setupgf = b2.register_module('SetupGenfitExtrapolation')
110 # param_setupgf = {}
111 # setupgf.param(param_setupgf)
112 
113 # fitting
114 cdcfitting = b2.register_module('DAFRecoFitter')
115 # param_cdcfitting = {}
116 # cdcfitting.param(param_cdcfitting)
117 
118 # build track
119 buildtrack = b2.register_module("TrackCreator")
120 
121 # output
122 output = b2.register_module('RootOutput')
123 output.param('outputFileName', 'SimpleMCTrackingOutput.root')
124 
125 # create path
126 main = b2.create_path()
127 
128 # add modules to path
129 main.add_module(eventinfosetter)
130 main.add_module(eventinfoprinter)
131 main.add_module(gearbox)
132 main.add_module(geometry)
133 
134 main.add_module(pGun)
135 main.add_module(g4sim)
136 main.add_module(cdcDigitizer)
137 
138 main.add_module(mctrackfinder)
139 main.add_module(setupgf)
140 main.add_module(cdcfitting)
141 main.add_module(buildtrack)
142 
143 main.add_module(output)
144 
145 # Process events
146 b2.process(main)
147 print(b2.statistics)