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