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