Belle II Software development
MakeMC.py
1#!/usr/bin/env python3
2
3
10
11"""This steering file shows how to generate particle gun
12 MC samples in DST root format for ECL charged PID analysis.
13
14Input:
15 No file is required
16
17Output:
18 Mdst file
19
20Usage:
21 $ basf2 MakeMC.py -- --pdgCode <integer>
22 --momentum <min> <max>
23 --theta <min> <max>
24 --fileNumber <integer>
25"""
26
27import glob
28import argparse
29import basf2 as b2
30from simulation import add_simulation
31from reconstruction import add_reconstruction
32
33
34def argparser():
35
36 parser = argparse.ArgumentParser()
37
38 parser.add_argument('--pdgCode',
39 type=int,
40 required=True,
41 help='PDG code of particle'
42 'More information:'
43 'http://pdg.lbl.gov/2019/reviews/rpp2018-rev-monte-carlo-numbering.pdf')
44
45 parser.add_argument('--momentum',
46 type=float,
47 required=True,
48 nargs=2,
49 help='Range for momentum of particle in GeV'
50 'First argument is minimum and second is maximum.'
51 'Example: --momentum 0.5 1')
52
53 parser.add_argument('--theta',
54 type=float,
55 required=True,
56 nargs=2,
57 help='Range for polar angle of particle in degree'
58 'First argument is minimum and second is maximum.'
59 'Example: --theta 12.4 155.1')
60
61 parser.add_argument('--fileNumber',
62 type=int,
63 required=True,
64 help='File numbering scheme')
65 return parser
66
67
68args = argparser().parse_args()
69
70momentumRange = list(args.momentum)
71thetaRange = list(args.theta)
72
73# Create path. Register necessary modules to this path.
74mainPath = b2.create_path()
75
76# Register and add 'EventInfoSetter' module and settings
77eventInfoSetter = b2.register_module('EventInfoSetter')
78eventInfoSetter.param({'evtNumList': [100],
79 'runList': [1],
80 'expList': [0]})
81mainPath.add_module(eventInfoSetter)
82
83# Set log level
84b2.set_log_level(b2.LogLevel.INFO)
85
86# Random number for generation
87b2.set_random_seed(123456)
88
89# Register and add 'ParticleGun' generator module and settings
90particleGun = b2.register_module('ParticleGun')
91param_particleGun = {
92 'pdgCodes': [args.pdgCode],
93 'nTracks': 1,
94 'momentumGeneration': 'uniform',
95 'momentumParams': momentumRange,
96 'thetaGeneration': 'uniform',
97 'thetaParams': thetaRange,
98 'phiGeneration': 'uniform',
99 'phiParams': [0., 360.],
100 'vertexGeneration': 'uniform',
101 'xVertexParams': [0.0, 0.0],
102 'yVertexParams': [0.0, 0.0],
103 'zVertexParams': [0.0, 0.0],
104}
105particleGun.param(param_particleGun)
106mainPath.add_module(particleGun)
107
108# Add beam background 'BGx1'
109pathToBkgDirectory = '/group/belle2/BGFile/OfficialBKG/15thCampaign/bgoverlay_phase3/'
110bgFiles = glob.glob(pathToBkgDirectory + '*.root')
111
112# Add simulation
113add_simulation(mainPath, bkgfiles=bgFiles)
114
115# Add reconstruction
116add_reconstruction(mainPath)
117
118# Register and add 'RootOutput' module
119outputFile = b2.register_module('RootOutput')
120outputFile.param('outputFileName',
121 f'pdg{args.pdgCode}_BGx1_{args.fileNumber}.mdst.root')
122mainPath.add_module(outputFile)
123
124# Process the events and print call statistics
125mainPath.add_module('Progress')
126b2.process(mainPath)
127print(b2.statistics)