27from background
import add_output
64 print(
' basf2', argvs[0],
'generator equivTime_us num [sampleType phase outdir]')
66 print(
' generator one of: bbbrem, bhwide, bhwide_largeangle')
67 print(
' equivTime_us equivalent SuperKEKB running time in micro-seconds')
68 print(
' num output file number')
69 print(
' sampleType one of: study, usual, PXD, ECL (D = usual)')
70 print(
' phase 2, 31 (= early phase 3, ie Run 1), 32 (= Run 2) or 3 (D = 3)')
71 print(
' outdir output directory path (D = output)')
76if generator ==
'bbbrem':
79elif generator ==
'bhwide':
82elif generator ==
'bhwide_largeangle':
83 bgType =
'BHWideLargeAngle'
86 print(
'unknown generator: ', generator)
98 print(
'phase ', phase,
'not supported')
101realTime = float(equivTime) * 1000
102numEvents = int(crossect * lumi * realTime * 1e-9)
103fname = bgType +
'_' + sampleType +
'-phase' + str(phase) +
'-' + num
104outputFile = outdir +
'/' + fname +
'.root'
107 b2.B2ERROR(
'number of events is 0 -> increase equivTime_us')
112if not os.path.exists(outdir):
117b2.B2RESULT(
'Events to be generated: ' + str(numEvents) +
' - corresponds to ' + equivTime +
118 ' us of running at ' + str(lumi) +
' /nb/s (phase ' + str(phase) +
')')
119b2.B2RESULT(
'Output file: ' + outputFile)
123b2.set_log_level(b2.LogLevel.RESULT)
126main = b2.create_path()
127kill = b2.create_path()
130def add_cut(name, minParticles, maxParticles, minTheta, maxTheta=None):
131 """Add a generator level cut and kill the event if the cut is not passed. In
132 this case the cut is on the min/max charged particles which have a
133 center-of-mass theta angle between minTheta
and maxTheta. If maxTheta
is not
134 given assume it to be 180-minTheta
for a symmetric window
"""
138 maxTheta = 180 - minTheta
139 selection = main.add_module(
'GeneratorPreselection')
140 selection.param(
'applyInCMS',
True)
141 selection.param(
'nChargedMin', minParticles)
142 selection.param(
'nChargedMax', maxParticles)
143 selection.param(
'MinChargedTheta', minTheta)
144 selection.param(
'MaxChargedTheta', maxTheta)
145 selection.param(
'MinChargedP', 0.)
146 selection.param(
'MinChargedPt', 0.)
147 selection.if_value(
"!=11", kill)
148 selection.set_name(
"generator cut: " + name)
152eventinfosetter = b2.register_module(
'EventInfoSetter')
153eventinfosetter.param(
'evtNumList', [numEvents])
154main.add_module(eventinfosetter)
157gearbox = b2.register_module(
'Gearbox')
159 gearbox.param(
'fileName',
'geometry/Beast2_phase2.xml')
161 gearbox.param(
'fileName',
'geometry/Belle2_earlyPhase3.xml')
163 gearbox.param(
'fileName',
'geometry/Belle2_Run2.xml')
164if sampleType ==
'study':
165 gearbox.param(
'override', [
166 (
"/DetectorComponent[@name='PXD']//ActiveChips",
'true',
''),
167 (
"/DetectorComponent[@name='PXD']//SeeNeutrons",
'true',
''),
168 (
"/DetectorComponent[@name='SVD']//ActiveChips",
'true',
''),
169 (
"/DetectorComponent[@name='SVD']//SeeNeutrons",
'true',
''),
170 (
"/DetectorComponent[@name='TOP']//BeamBackgroundStudy",
'1',
''),
171 (
"/DetectorComponent[@name='ARICH']//BeamBackgroundStudy",
'1',
''),
172 (
"/DetectorComponent[@name='ECL']//BeamBackgroundStudy",
'1',
''),
173 (
"/DetectorComponent[@name='KLM']//BKLM/BeamBackgroundStudy",
'1',
''),
174 (
"/DetectorComponent[@name='KLM']//EKLM/BeamBackgroundStudy",
'1',
''),
176main.add_module(gearbox)
179if generator ==
"bbbrem":
180 main.add_module(
"BBBremInput", MinPhotonEnergyFraction=0.000001, Unweighted=
True,
181 MaxWeight=1.57001e+07)
183 add_cut(
"at least one track below 0.5 degree", 0, 1, 0.5)
184elif generator ==
"bhwide":
185 main.add_module(
"BHWideInput", ScatteringAngleRangeElectron=[0.5, 179.5],
186 ScatteringAngleRangePositron=[0.5, 179.5])
187 add_cut(
"both tracks at least 0.5 degree", 2, 2, 0.5)
190 add_cut(
"max one track in 1-170", 0, 1, 1, 170)
191 add_cut(
"max one track in 10-179", 0, 1, 10, 179)
192elif generator ==
"bhwide_largeangle":
193 main.add_module(
"BHWideInput", ScatteringAngleRangeElectron=[0.5, 179.5],
194 ScatteringAngleRangePositron=[0.5, 179.5])
195 add_cut(
"both tracks at least 1 degree", 2, 2, 1)
196 add_cut(
"at least one 10 degree", 1, 2, 10)
198 print(
"unknown generation setting: {}".format(generator))
201geometry = b2.register_module(
'Geometry')
202geometry.param(
'useDB',
False)
203addComp = [
"MagneticField3dQuadBeamline"]
205if sampleType ==
'study' and (phase == 31
or phase == 32):
206 addComp.extend([
"BEAMABORT",
"MICROTPC",
"CLAWS",
"HE3TUBE"])
208geometry.param({
"excludedComponents": [
"MagneticField"],
209 "additionalComponents": addComp})
210main.add_module(geometry)
213fullsim = b2.register_module(
'FullSim')
214if sampleType ==
'study':
215 fullsim.param(
'PhysicsList',
'FTFP_BERT_HP')
216 fullsim.param(
'UICommandsAtIdle', [
'/process/inactivate nKiller'])
217 fullsim.param(
'StoreAllSecondaries',
True)
218 fullsim.param(
'SecondariesEnergyCut', 0.000001)
219main.add_module(fullsim)
222progress = b2.register_module(
'Progress')
223main.add_module(progress)
226if phase == 31
or phase == 32:
228add_output(main, bgType, realTime, sampleType, phase, fileName=outputFile)