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