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