Belle II Software development
ParticleGun.py
1#!/usr/bin/env python
2
3
10
11
17
18import sys
19import basf2
20from simulation import add_simulation
21from reconstruction import add_reconstruction
22
23
24def getpdgCode(x):
25 return {
26 'muon+': -13,
27 'muon-': 13,
28 'pion+': 211,
29 'pion-': -211,
30 'kaon+': 321,
31 'kaon-': -321,
32 'electron+': -11,
33 'electron-': 11,
34 'proton+': 2212,
35 'proton-': -2212,
36 'deuteron+': 1000010020,
37 'deuteron-': -1000010020,
38 'gamma': 22,
39 'klong': 130,
40 }[x]
41
42
43particle = sys.argv[1]
44pdgCode = getpdgCode(particle)
45pdgCodeNeg = -pdgCode
46nEvent = int(sys.argv[2])
47stream = sys.argv[3]
48print(pdgCode)
49print(nEvent)
50
51main = basf2.create_path()
52
53# specify number of events to be generated in job
54eventInfoSetter = basf2.register_module('EventInfoSetter')
55eventInfoSetter.param('expList', [0])
56eventInfoSetter.param('runList', [0])
57eventInfoSetter.param('evtNumList', [nEvent])
58main.add_module(eventInfoSetter)
59
60# generate single-track events with positive pions
61# particle gun to shoot particles in the detector
62# choose the particles you want to simulate
63pGun = basf2.register_module('ParticleGun')
64param_pGun = {
65 'pdgCodes': [pdgCode, pdgCodeNeg],
66 'nTracks': 1,
67 'varyNTracks': 0,
68 'momentumGeneration': 'uniform',
69 'momentumParams': [2.5, 7.0],
70 'thetaGeneration': 'uniformCos',
71 'thetaParams': [15., 150.],
72 'phiGeneration': 'uniform',
73 'phiParams': [0.0, 360.0],
74 'vertexGeneration': 'uniform',
75 'xVertexParams': [0.0, 0.0],
76 'yVertexParams': [0.0, 0.0],
77 'zVertexParams': [0.0, 0.0],
78 }
79pGun.param(param_pGun)
80main.add_module(pGun)
81
82# detector simulation
83add_simulation(main)
84
85# reconstruction
86add_reconstruction(main)
87
88output = basf2.register_module('RootOutput')
89outfile = f'{particle}_{stream}.root'
90output.param('outputFileName', outfile)
91output.param('branchNames', ['MCParticles', 'Muids'])
92main.add_module(output)
93
94basf2.process(main)
95
96# Print call statistics
97print(basf2.statistics)