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