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