Belle II Software development
VertexGunFull.py
1#!/usr/bin/env python3
2
3
10
11from basf2 import set_log_level, LogLevel, register_module, create_path, process, statistics, set_random_seed, print_params
12
13# suppress messages and warnings during processing:
14set_log_level(LogLevel.ERROR)
15set_random_seed(1028307)
16
17# first vertex
18vertex1 = register_module('ParticleGun')
19
20# setting the number of tracks and pdg codes for the first vertex
21vertex1.param('nTracks', -1) # a negative track number means one track for every PDG code
22vertex1.param('pdgCodes', [-11, 11, -13, 13])
23
24# set the starting parameters of the particle originating from the first vertex
25vertex1.param('momentumGeneration', 'normal')
26vertex1.param('momentumParams', [1, 0.05])
27
28vertex1.param('thetaGeneration', 'uniform')
29vertex1.param('thetaParams', [17, 150])
30
31vertex1.param('phiGeneration', 'uniform')
32vertex1.param('phiParams', [0, 360])
33
34# make sure all particles of vertex1 in one event start at the same postion
35vertex1.param('independentVertices', False)
36
37vertex1.param('vertexGeneration', 'fixed')
38vertex1.param('xVertexParams', [0.0, 0.0])
39vertex1.param('yVertexParams', [0.0, 0.0])
40vertex1.param('zVertexParams', [0.0, 0.0])
41
42# second vertex
43vertex2 = register_module('ParticleGun')
44
45# setting the number of tracks and pdg codes for the first vertex
46vertex2.param('nTracks', -1) # a negative track number means one track for every PDG code
47vertex2.param('pdgCodes', [-211, 211, -211])
48
49# set the starting parameters of the particle originating from the first vertex
50vertex2.param('momentumGeneration', 'normal')
51vertex2.param('momentumParams', [1, 0.05])
52
53vertex2.param('thetaGeneration', 'uniform')
54vertex2.param('thetaParams', [17, 150])
55
56vertex2.param('phiGeneration', 'uniform')
57vertex2.param('phiParams', [0, 360])
58
59# make sure all particles of vertex2 in one event start at the same postion
60vertex2.param('independentVertices', False)
61
62vertex2.param('vertexGeneration', 'fixed')
63vertex2.param('xVertexParams', [1, 1])
64vertex2.param('yVertexParams', [1, 1])
65vertex2.param('zVertexParams', [1, 1])
66
67# third vertex
68vertex3 = register_module('ParticleGun')
69
70# setting the number of tracks and pdg codes for the first vertex
71vertex3.param('nTracks', -1) # a negative track number means one track for every PDG code
72vertex3.param('pdgCodes', [-11, 11])
73
74# set the starting parameters of the particle originating from the first vertex
75vertex3.param('momentumGeneration', 'normal')
76vertex3.param('momentumParams', [0.5, 0.01])
77
78vertex3.param('thetaGeneration', 'uniform')
79vertex3.param('thetaParams', [60, 120])
80
81vertex3.param('phiGeneration', 'uniform')
82vertex3.param('phiParams', [0, 360])
83
84# make sure all particles of vertex3 in one event start at the same postion
85vertex3.param('independentVertices', False)
86
87vertex3.param('vertexGeneration', 'fixed')
88vertex3.param('xVertexParams', [0, 0])
89vertex3.param('yVertexParams', [0, 0])
90vertex3.param('zVertexParams', [3, 3])
91
92# ============================================================================
93# Print the parameters of the particle guns
94print_params(vertex1)
95print_params(vertex2)
96print_params(vertex3)
97
98# ============================================================================
99# Now lets create the necessary modules to perform a simulation
100#
101# Create Event information
102eventinfosetter = register_module('EventInfoSetter')
103# Show progress of processing
104progress = register_module('Progress')
105# Load parameters
106gearbox = register_module('Gearbox')
107# Create geometry
108geometry = register_module('Geometry')
109# Run simulation
110simulation = register_module('FullSim')
111# Save output of simulation
112output = register_module('RootOutput')
113
114# Setting the option for all non particle gun modules: want to process 100 MC
115# events
116eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
117
118# Set output filename
119output.param('outputFileName', 'ParticleGunOutput.root')
120
121# ============================================================================
122# Do the simulation
123mcparticleprinter = register_module('PrintMCParticles')
124mcparticleprinter.logging.log_level = LogLevel.INFO
125main = create_path()
126main.add_module(eventinfosetter)
127main.add_module(progress)
128main.add_module(gearbox)
129main.add_module(geometry)
130main.add_module(vertex1)
131main.add_module(vertex2)
132main.add_module(vertex3)
133main.add_module(mcparticleprinter)
134main.add_module(simulation)
135main.add_module(output)
136
137# Process events
138process(main)
139
140# Print call statistics
141print(statistics)