Belle II Software development
readB2L.py
1#!/usr/bin/env python3
2
3
10
11#
12# 2012/10/11 : param_cdcdigi, Threshold added
13# 2013/11/05 : Updated for release-00-03-00
14# 2014/02/12 : Updated for build-2014-01-19 //JB
15# 2015/01/28 : Updated for build-2015-01-03 //JB
16# 2015/02/02 : Added KKGen, Background, RootInput/RootOutput //JB
17# 2015/05/18 : Fixed background file issue. //JB
18# 2015/06/09 : Updated for release-00-05-00 //JB
19# 2015/07/12 : Updated for 2D trgcdc update //JB
20# 2016/04/08 : Added NeuroTrigger. Updated for head //JB
21
22import basf2 as b2
23import os
24import glob
25
26# ...suppress messages and warnings during processing...
27b2.set_log_level(b2.LogLevel.ERROR)
28# 0 means using different seed every time.
29b2.set_random_seed(1)
30basf2datadir = os.path.join(os.environ.get('BELLE2_LOCAL_DIR', None), 'data')
31
32
33
35evtmetagen = b2.register_module('EventInfoSetter')
36evtmetainfo = b2.register_module('Progress')
37paramloader = b2.register_module('Gearbox')
38geobuilder = b2.register_module('Geometry')
39particlegun = b2.register_module('ParticleGun')
40evtgeninput = b2.register_module('EvtGenInput')
41kkgeninput = b2.register_module('KKGenInput')
42mcparticleprinter = b2.register_module('PrintMCParticles')
43g4sim = b2.register_module('FullSim')
44bkgmixer = b2.register_module('BeamBkgMixer')
45cdcdigitizer = b2.register_module('CDCDigitizer')
46cdctrg = b2.register_module("TRGCDC")
47rootOut = b2.register_module('RootOutput')
48rootIn = b2.register_module('RootInput')
49srootIn = b2.register_module('SeqRootInput')
50neuro = b2.register_module('NeuroTrigger')
51
52
53
55
56# ...Global settings...
57# simulatedComponents = ['MagneticField', 'CDC'
58# ,'PXD', 'SVD', 'BeamPipe'
59# ]
60# To speed things up but not precise.
61simulatedComponents = ['MagneticFieldConstant4LimitedRCDC', 'CDC',
62 ]
63
64# ...EventInfoSetter...
65# Set number of events and runs
66evtmetagen.param({'evtNumList': [1000], 'runList': [1]})
67
68# ...Geometry...
69# Set what dectectors to simulate.
70geobuilder.param('components', simulatedComponents)
71# Set verbose of geometry simulation
72# geobuilder.log_level = LogLevel.INFO
73
74# ...ParticleGun...
75particlegun.param('pdgCodes', [13, -13])
76particlegun.param('nTracks', 5)
77particlegun.param('momentumGeneration', 'inversePt')
78# particlegun.param('momentumGeneration', 'uniformPt')
79# particlegun.param('momentumGeneration', 'uniform')
80particlegun.param('momentumParams', [0.2, 8.0])
81# particlegun.param('momentumParams', [0.9, 0.9])
82# particlegun.param('thetaGeneration', 'uniform')
83# particlegun.param('thetaParams', [35, 127])
84# particlegun.param('thetaParams', [90, 90])
85particlegun.param('phiGeneration', 'uniform')
86particlegun.param('phiParams', [0, 360])
87# particlegun.param('vertexGeneration', 'fixed')
88# particlegun.param('vertexGeneration', 'normal')
89particlegun.param('vertexGeneration', 'uniform')
90particlegun.param('xVertexParams', [0, 0])
91particlegun.param('yVertexParams', [0, 0])
92particlegun.param('zVertexParams', [-20.0, 20.0])
93# particlegun.param('zVertexParams', [0, 0])
94
95# ...EvtGenInput...
96# evtgeninput.param('userDECFile', 'USER.DEC')
97
98# ...KKGenInput...
99# You need to copy mu.input.dat to the current directory, that is
100# found in "data/generators/kkmc".
101kkdir = os.path.join(os.environ.get('BELLE2_LOCAL_DIR', None), 'generators')
102kkgeninput.param('tauinputFile', kkdir + 'kkmc/data/mu.input.dat')
103kkgeninput.param('KKdefaultFile', kkdir + 'kkmc/data/KK2f_defaults.dat')
104kkgeninput.param('taudecaytableFile', '')
105
106# ...PrintMCParticles...
107mcparticleprinter.param('maxLevel', -1)
108
109# ...FullSim...
110# Turn off physics processes
111# "physics.mac" is located at "trg/examples/".
112# g4sim.param('UICommandsAtIdle',['/control/execute physics.mac'])
113# or below line can be used when trgcdc.py is not in trg/examples directory //JB
114# g4sim.param('UICommandsAtIdle', ['/control/execute ' +
115# os.path.join(os.environ.get('BELLE2_LOCAL_DIR', None), "trg/cdc/examples/physics.mac")])
116
117# ...BeamBkgMixer...
118# Mix background (From beamBkgMixer.py)
119dir = '/sw/belle2/bkg/' # change the directory name if you don't run on KEKCC
120# bkg_files = [
121# dir + 'Coulomb_HER_100us.root',
122# dir + 'Coulomb_LER_100us.root',
123# dir + 'RBB_HER_100us.root',
124# dir + 'RBB_LER_100us.root',
125# dir + 'Touschek_HER_100us.root',
126# dir + 'Touschek_LER_100us.root',
127# ]
128bkg_files = glob.glob(dir + '/*.root')
129bkgScaleFactor = 1
130bkgmixer.param('backgroundFiles', bkg_files)
131bkgmixer.param('components', simulatedComponents)
132bkgmixer.param('scaleFactors', [
133 ('Coulomb_LER', bkgScaleFactor),
134 ('Coulomb_HER', bkgScaleFactor),
135 ('RBB_LER', bkgScaleFactor),
136 ('RBB_HER', bkgScaleFactor),
137 ('Touschek_LER', bkgScaleFactor),
138 ('Touschek_HER', bkgScaleFactor)
139])
140
141# ...CDCDigitizer...
142# set digitizer to no smearing
143# param_cdcdigi = {'Fraction': 1,
144# 'Resolution1': 0.,
145# 'Resolution2': 0.,
146# 'Threshold': -10.0}
147# cdcdigitizer.param(param_cdcdigi)
148# cdcdigitizer.param('AddInWirePropagationDelay', True)
149# cdcdigitizer.param('AddTimeOfFlight', True)
150# cdcdigitizer.param('UseSimpleDigitization', True)
151
152# ...CDC Trigger...
153# ---General settings---
154cdctrg.param('ConfigFile', os.path.join(basf2datadir, "trg/cdc/TRGCDCConfig_0_20101111.dat"))
155# cdctrg.param('DebugLevel', 1)
156cdctrg.param('CurlBackStop', 1)
157cdctrg.param('SimulationMode', 1) # 1:fast, 2:firm, 3:fast and firm
158cdctrg.param('FastSimulationMode', 0)
159# cdctrg.param('SimulationMode',0x11)
160# cdctrg.param('TRGCDCRootFile',1)
161# cdctrg.param('RootTRGCDCFile', 'TRGCDC.root')
162# ---TSF settings---
163# TSLUT (latest version @ 2014.07)
164cdctrg.param('InnerTSLUTFile', os.path.join(basf2datadir, "trg/cdc/innerLUT_v3.0.coe"))
165cdctrg.param('OuterTSLUTFile', os.path.join(basf2datadir, "trg/cdc/outerLUT_v3.0.coe"))
166# 0: Logic TSF, 1: (Default) LUT TSF
167# cdctrg.param('TSFLogicLUT', 0)
168# cdctrg.param('TSFRootFile',1)
169# ---2D finder settings---
170cdctrg.param('HoughFinderMappingFileMinus', os.path.join(basf2datadir, "trg/cdc/HoughMappingMinus20160223.dat"))
171cdctrg.param('HoughFinderMappingFilePlus', os.path.join(basf2datadir, "trg/cdc/HoughMappingPlus20160223.dat"))
172# cdctrg.param('2DFinderPerfect', 1)
173# cdctrg.param('HoughFinderPeakMin',4)
174# cdctrg.param('HoughFinderDoit', 2)
175# ---3D finder settings---
176# cdctrg.param('Hough3DRootFile',1)
177# 0: perfect finder, 1: Hough3DFinder, 2: (Default) GeoFinder, 3: VHDL GeoFinder
178# cdctrg.param('Finder3DMode',2)
179# ---3D fitter settings---
180# cdctrg.param('Fitter3DRootFile',1)
181# cdctrg.param('RootFitter3DFile', 'Fitter3D.root')
182# cdctrg.param('Fitter3DsMcLR', 0)
183# cdctrg.param('Fitter3Ds2DFit', 1)
184# cdctrg.param('Fitter3Ds2DFitDrift', 0)
185# cdctrg.param('Fitter3DsXtSimple', 0)
186# cdctrg.param('Fitter3DsLRLUT', 0)
187cdctrg.param('TRGCDCDataInputMode', 2)
188
189# ...NeuroTrigger...
190# define parameters
191neuro.param('filename', os.path.join(basf2datadir, "trg/cdc/Neuro20160309Nonlin.root"))
192# output warnings, info and some debug output for neurotrigger module
193# neuro.logging.log_level = b2.LogLevel.DEBUG
194# neuro.logging.debug_level = 80
195# b2.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
196
197# ...RootOutput...
198rootOut.param('outputFileName', 'basf2.root')
199
200# ...RootInput...
201rootIn.param('inputFileName', 'basf2.root')
202# rootIn.param('skipNEvents', 0);
203
204
205
207
208# For full simulation.
209fullMain = b2.create_path()
210# Add modules to paths
211fullMain.add_module(evtmetagen)
212fullMain.add_module(evtmetainfo)
213fullMain.add_module(paramloader)
214fullMain.add_module(geobuilder)
215fullMain.add_module(particlegun)
216# fullMain.add_module(evtgeninput)
217# fullMain.add_module(kkgeninput)
218fullMain.add_module(mcparticleprinter)
219fullMain.add_module(g4sim)
220fullMain.add_module(bkgmixer)
221fullMain.add_module(cdcdigitizer)
222fullMain.add_module(cdctrg)
223fullMain.add_module(neuro)
224
225# For only generator+G4Sim and save file. (To save time)
226g4SimMain = b2.create_path()
227# Add modules to paths
228g4SimMain.add_module(evtmetagen)
229g4SimMain.add_module(evtmetainfo)
230g4SimMain.add_module(paramloader)
231g4SimMain.add_module(geobuilder)
232g4SimMain.add_module(particlegun)
233# g4SimMain.add_module(evtgeninput)
234# g4SimMain.add_module(kkgeninput)
235g4SimMain.add_module(mcparticleprinter)
236g4SimMain.add_module(g4sim)
237g4SimMain.add_module(bkgmixer)
238g4SimMain.add_module(cdcdigitizer)
239g4SimMain.add_module(rootOut)
240
241# For TSIM with generator+G4Sim saved file. (To save time)
242savedG4SimMain = b2.create_path()
243# Add modules to paths
244savedG4SimMain.add_module(rootIn)
245savedG4SimMain.add_module(evtmetainfo)
246savedG4SimMain.add_module(paramloader)
247savedG4SimMain.add_module(geobuilder)
248savedG4SimMain.add_module(cdctrg)
249
250# For only generator and save file.
251generatorMain = b2.create_path()
252# Add modules to paths
253generatorMain.add_module(evtmetagen)
254generatorMain.add_module(evtmetainfo)
255generatorMain.add_module(paramloader)
256generatorMain.add_module(geobuilder)
257generatorMain.add_module(particlegun)
258# generatorMain.add_module(evtgeninput)
259# generatorMain.add_module(kkgeninput)
260generatorMain.add_module(mcparticleprinter)
261generatorMain.add_module(g4sim)
262generatorMain.add_module(rootOut)
263
264# For TSIM with generator saved file.
265savedGeneratorMain = b2.create_path()
266# Add modules to paths
267savedGeneratorMain.add_module(rootIn)
268savedGeneratorMain.add_module(evtmetainfo)
269savedGeneratorMain.add_module(paramloader)
270savedGeneratorMain.add_module(geobuilder)
271savedGeneratorMain.add_module(bkgmixer)
272savedGeneratorMain.add_module(cdcdigitizer)
273savedGeneratorMain.add_module(cdctrg)
274
275# For reading B2L
276readB2LMain = b2.create_path()
277# Add modules to paths
278readB2LMain.add_module(srootIn)
279readB2LMain.add_module(paramloader)
280readB2LMain.add_module(geobuilder)
281readB2LMain.add_module(cdcdigitizer)
282readB2LMain.add_module(evtmetainfo)
283readB2LMain.add_module(cdctrg)
284
285
297
298# read B2L data
299b2.process(readB2LMain)
300
301# Print call statistics
302print(b2.statistics)