Belle II Software  release-08-01-10
generateTwoPhoton.py
1 #!/usr/bin/env python
2 
3 
10 
11 # -------------------------------------------------------------------------------------
12 # BG simulation: two-photon (QED)
13 # usage:
14 # basf2 generateTwoPhoton.py equivTime_us num [sampleType phase outdir]
15 # arguments:
16 # equivTime_us equivalent SuperKEKB running time in micro-seconds
17 # num output file number
18 # sampleType one of: study, usual, PXD, ECL
19 # phase 2, 31 (= early phase 3, ie Run 1), 32 (= Run 2) or 3 (D = 3)
20 # outdir output directory path
21 # -------------------------------------------------------------------------------------
22 
23 import basf2 as b2
24 import sys
25 import os
26 from background import add_output
27 
28 # read parameters
29 
30 argvs = sys.argv
31 argc = len(argvs)
32 
33 if argc == 3:
34  equivTime = argvs[1] # equivalent SuperKEKB running time in micro-seconds
35  num = argvs[2] # output file number
36  sampleType = 'usual' # study, usual, PXD, ECL
37  phase = 3 # phase number
38  outdir = 'output' # output directory path
39 elif argc == 4:
40  equivTime = argvs[1]
41  num = argvs[2]
42  sampleType = argvs[3]
43  phase = 3
44  outdir = 'output'
45 elif argc == 5:
46  equivTime = argvs[1]
47  num = argvs[2]
48  sampleType = argvs[3]
49  phase = int(argvs[4])
50  outdir = 'output'
51 elif argc == 6:
52  equivTime = argvs[1]
53  num = argvs[2]
54  sampleType = argvs[3]
55  phase = int(argvs[4])
56  outdir = argvs[5]
57 else:
58  print('Usage:')
59  print(' basf2', argvs[0], 'equivTime_us num [sampleType phase outdir]')
60  print('Arguments:')
61  print(' equivTime_us equivalent SuperKEKB running time in micro-seconds')
62  print(' num output file number')
63  print(' sampleType one of: study, usual, PXD, ECL (D = usual)')
64  print(' phase 2, 31 (= early phase 3, ie Run 1), 32 (= Run 2) or 3 (D = 3)')
65  print(' outdir output directory path (D = output)')
66  sys.exit()
67 
68 # set parameters
69 
70 bgType = 'twoPhoton'
71 crossect = 7.28e6 # nb
72 
73 if phase == 3:
74  lumi = 600 # /nb/s (1/nb/s = 1e33/cm^2/s)
75 elif phase == 31:
76  lumi = 30 # /nb/s
77 elif phase == 32:
78  lumi = 280 # /nb/s
79 elif phase == 2:
80  lumi = 20 # /nb/s
81 else:
82  print('phase ', phase, 'not supported')
83  sys.exit()
84 
85 realTime = float(equivTime) * 1000 # ns
86 numEvents = int(crossect * lumi * realTime * 1e-9)
87 fname = bgType + '_' + sampleType + '-phase' + str(phase) + '-' + num
88 outputFile = outdir + '/' + fname + '.root'
89 
90 if numEvents == 0:
91  b2.B2ERROR('number of events is 0 -> increase equivTime_us')
92  sys.exit()
93 
94 # make output directory if doesn't exists
95 
96 if not os.path.exists(outdir):
97  os.makedirs(outdir)
98 
99 # log messages
100 
101 b2.B2RESULT('Events to be generated: ' + str(numEvents) + ' - corresponds to ' + equivTime +
102  ' us of running at ' + str(lumi) + ' /nb/s (phase ' + str(phase) + ')')
103 b2.B2RESULT('Output file: ' + outputFile)
104 
105 # Suppress messages and warnings during processing:
106 b2.set_log_level(b2.LogLevel.RESULT)
107 
108 # Create path
109 main = b2.create_path()
110 
111 # Event info setter
112 eventinfosetter = b2.register_module('EventInfoSetter')
113 eventinfosetter.param('evtNumList', [numEvents])
114 main.add_module(eventinfosetter)
115 
116 # Gearbox
117 gearbox = b2.register_module('Gearbox')
118 if phase == 2:
119  gearbox.param('fileName', 'geometry/Beast2_phase2.xml')
120 elif phase == 31:
121  gearbox.param('fileName', 'geometry/Belle2_earlyPhase3.xml')
122 elif phase == 32:
123  gearbox.param('fileName', 'geometry/Belle2_Run2.xml')
124 if sampleType == 'study':
125  gearbox.param('override', [
126  ("/DetectorComponent[@name='PXD']//ActiveChips", 'true', ''),
127  ("/DetectorComponent[@name='PXD']//SeeNeutrons", 'true', ''),
128  ("/DetectorComponent[@name='SVD']//ActiveChips", 'true', ''),
129  ("/DetectorComponent[@name='SVD']//SeeNeutrons", 'true', ''),
130  ("/DetectorComponent[@name='TOP']//BeamBackgroundStudy", '1', ''),
131  ("/DetectorComponent[@name='ARICH']//BeamBackgroundStudy", '1', ''),
132  ("/DetectorComponent[@name='ECL']//BeamBackgroundStudy", '1', ''),
133  ("/DetectorComponent[@name='KLM']//BKLM/BeamBackgroundStudy", '1', ''),
134  ("/DetectorComponent[@name='KLM']//EKLM/BeamBackgroundStudy", '1', ''),
135  ])
136 main.add_module(gearbox)
137 
138 # Generator (settings from Nakayama-san 15th campaign)
139 aafh = b2.register_module('AafhInput')
140 aafh.param({
141  'mode': 5,
142  'rejection': 2,
143  'suppressionLimits': [1e100] * 4,
144  'minMass': 0.001,
145  'maxFinalWeight': 2.5,
146  'maxSubgeneratorWeight': 1.0,
147  'subgeneratorWeights': [1.000e+00, 2.216e+01, 3.301e+03, 6.606e+03, 1.000e+00,
148  1.675e+00, 5.948e+00, 6.513e+00],
149 })
150 main.add_module(aafh)
151 
152 # Geant geometry
153 geometry = b2.register_module('Geometry')
154 geometry.param('useDB', False)
155 addComp = ["MagneticField3dQuadBeamline"]
156 # add beast detectors
157 if sampleType == 'study' and (phase == 31 or phase == 32):
158  addComp.extend(["BEAMABORT", "MICROTPC", "CLAWS", "HE3TUBE"])
159 
160 geometry.param({"excludedComponents": ["MagneticField"],
161  "additionalComponents": addComp})
162 main.add_module(geometry)
163 
164 # Geant simulation
165 fullsim = b2.register_module('FullSim')
166 if sampleType == 'study':
167  fullsim.param('PhysicsList', 'FTFP_BERT_HP')
168  fullsim.param('UICommandsAtIdle', ['/process/inactivate nKiller'])
169  fullsim.param('StoreAllSecondaries', True)
170  fullsim.param('SecondariesEnergyCut', 0.000001) # [MeV] need for CDC EB neutron flux
171 main.add_module(fullsim)
172 
173 # Show progress of processing
174 progress = b2.register_module('Progress')
175 main.add_module(progress)
176 
177 # Output
178 if phase == 31 or phase == 32:
179  phase = 3
180 add_output(main, bgType, realTime, sampleType, phase, fileName=outputFile)
181 
182 # Process events
183 b2.process(main)
184 
185 # Print call statistics
186 print(b2.statistics)