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