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