Belle II Software development
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
23import basf2 as b2
24import sys
25import os
26from background import add_output
27
28# read parameters
29
30argvs = sys.argv
31argc = len(argvs)
32
33if 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
39elif argc == 4:
40 equivTime = argvs[1]
41 num = argvs[2]
42 sampleType = argvs[3]
43 phase = 3
44 outdir = 'output'
45elif argc == 5:
46 equivTime = argvs[1]
47 num = argvs[2]
48 sampleType = argvs[3]
49 phase = int(argvs[4])
50 outdir = 'output'
51elif argc == 6:
52 equivTime = argvs[1]
53 num = argvs[2]
54 sampleType = argvs[3]
55 phase = int(argvs[4])
56 outdir = argvs[5]
57else:
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
70bgType = 'twoPhoton'
71crossect = 7.28e6 # nb
72
73if phase == 3:
74 lumi = 600 # /nb/s (1/nb/s = 1e33/cm^2/s)
75elif phase == 31:
76 lumi = 30 # /nb/s
77elif phase == 32:
78 lumi = 280 # /nb/s
79elif phase == 2:
80 lumi = 20 # /nb/s
81else:
82 print('phase ', phase, 'not supported')
83 sys.exit()
84
85realTime = float(equivTime) * 1000 # ns
86numEvents = int(crossect * lumi * realTime * 1e-9)
87fname = bgType + '_' + sampleType + '-phase' + str(phase) + '-' + num
88outputFile = outdir + '/' + fname + '.root'
89
90if 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
96if not os.path.exists(outdir):
97 os.makedirs(outdir)
98
99# log messages
100
101b2.B2RESULT('Events to be generated: ' + str(numEvents) + ' - corresponds to ' + equivTime +
102 ' us of running at ' + str(lumi) + ' /nb/s (phase ' + str(phase) + ')')
103b2.B2RESULT('Output file: ' + outputFile)
104
105# Suppress messages and warnings during processing:
106b2.set_log_level(b2.LogLevel.RESULT)
107
108# Create path
109main = b2.create_path()
110
111# Event info setter
112eventinfosetter = b2.register_module('EventInfoSetter')
113eventinfosetter.param('evtNumList', [numEvents])
114main.add_module(eventinfosetter)
115
116# Gearbox
117gearbox = b2.register_module('Gearbox')
118if phase == 2:
119 gearbox.param('fileName', 'geometry/Beast2_phase2.xml')
120elif phase == 31:
121 gearbox.param('fileName', 'geometry/Belle2_earlyPhase3.xml')
122elif phase == 32:
123 gearbox.param('fileName', 'geometry/Belle2_Run2.xml')
124if 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 ])
136main.add_module(gearbox)
137
138# Generator (settings from Nakayama-san 15th campaign)
139aafh = b2.register_module('AafhInput')
140aafh.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})
150main.add_module(aafh)
151
152# Geant geometry
153geometry = b2.register_module('Geometry')
154geometry.param('useDB', False)
155addComp = ["MagneticField3dQuadBeamline"]
156# add beast detectors
157if sampleType == 'study' and (phase == 31 or phase == 32):
158 addComp.extend(["BEAMABORT", "MICROTPC", "CLAWS", "HE3TUBE"])
159
160geometry.param({"excludedComponents": ["MagneticField"],
161 "additionalComponents": addComp})
162main.add_module(geometry)
163
164# Geant simulation
165fullsim = b2.register_module('FullSim')
166if 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
171main.add_module(fullsim)
172
173# Show progress of processing
174progress = b2.register_module('Progress')
175main.add_module(progress)
176
177# Output
178if phase == 31 or phase == 32:
179 phase = 3
180add_output(main, bgType, realTime, sampleType, phase, fileName=outputFile)
181
182# Process events
183b2.process(main)
184
185# Print call statistics
186print(b2.statistics)