Belle II Software development
__init__.py
1
8import basf2 as b2
9from ROOT import Belle2
10import ROOT
11from tracking.path_utils import add_cdc_cr_track_finding, add_cdc_track_finding
12
13# Propagation velocity of the light in the scinti.
14lightPropSpeed = 12.9925
15
16# Run range.
17run_range = {'201607': [787, 833],
18 '201608a': [885, 896],
19 '201608b': [917, 924],
20 '201609': [966, 973],
21 '201702': [1601, 9999],
22 'gcr2017': [3058, 100000],
23 'phase2': [0, 100000],
24 'phase3': [0, 100000],
25 'normal': [-1, -1]
26 }
27# Size of trigger counter.
28triggerSize = {'201607': [20.0, 6.0, 10.0],
29 '201608a': [100.0, 8.0, 10.0],
30 '201608b': [100.0, 8.0, 10.0],
31 '201609': [100.0, 8.0, 10.0],
32 '201702': [100.0, 8.0, 10.0],
33 'gcr2017': [100, 0, 8.0, 10.0],
34 'phase2': [100, 0, 8.0, 10.0],
35 'phase3': [100, 0, 8.0, 10.0],
36 'normal': [100.0, 8.0, 10.0]
37 }
38# Center position of trigger counter.
39triggerPosition = {'201607': [0.3744, 0.0, -1.284],
40 '201608a': [-1.87, -1.25, 18.7],
41 '201608b': [-1.87, -1.25, 11.0],
42 '201609': [0, 0, 11.0],
43 '201702': [0., -1.5, 21.0],
44 'gcr2017': [0.0, 0.0, 0.0],
45 'phase2': [0.0, 0.0, 0.0],
46 'phase3': [0.0, 0.0, 0.0],
47 'normal': [0.0, 0.0, 0.0]
48 }
49
50# Normal direction of the trigger plane.
51triggerPlaneDirection = {'201607': [1, -1, 0],
52 '201608a': [0, 1, 0],
53 '201608b': [0, 1, 0],
54 '201609': [0, 1, 0],
55 '201702': [0, 1, 0],
56 'gcr2017': [0, 1, 0],
57 'phase2': [0, 1, 0],
58 'phase3': [0, 1, 0],
59 'normal': [0, 1, 0]
60 }
61
62# PMT position.
63pmtPosition = {'201607': [0, 0, 0],
64 '201608a': [-1.87, 0, -25.0],
65 '201608b': [-1.87, 0, -42.0],
66 '201609': [0, 0, -42.0],
67 '201702': [0., -1.5, -31.0],
68 'gcr2017': [0.0, 0.0, -50.0],
69 'phase2': [0.0, 0.0, -50.0],
70 'phase3': [0.0, 0.0, -50.0],
71 'normal': [0, 0, -50.0]
72 }
73
74# Global phi rotation.
75globalPhiRotation = {'201607': 1.875,
76 '201608a': 1.875,
77 '201608b': 1.875,
78 '201609': 1.875,
79 '201702': 0.0,
80 'gcr2017': 0.0,
81 'phase2': 0.0,
82 'phase3': 0.0,
83 'normal': 0.0
84 }
85
86lengthOfCounter = 100.0
87widthOfCounter = 8.0
88triggerPos = []
89normTriggerPlaneDirection = []
90readOutPos = []
91globalPhi = 0.0
92cosmics_period = None
93
94
95def set_cdc_cr_parameters(period):
96
97 global lengthOfCounter
98 global widthOfCounter
99 global triggerPos
100 global normTriggerPlaneDirection
101 global readOutPos
102 global globalPhi
103 global cosmics_period
104
105 lengthOfCounter = triggerSize[period][0]
106 widthOfCounter = triggerSize[period][1]
107 triggerPos = triggerPosition[period]
108 normTriggerPlaneDirection = triggerPlaneDirection[period]
109 readOutPos = pmtPosition[period]
110 globalPhi = globalPhiRotation[period]
111 cosmics_period = period
112
113
114def add_cdc_cr_simulation(path,
115 components=None,
116 bkgfiles=None,
117 bkgcomponents=None,
118 bkgscale=1.0,
119 bkgOverlay=False,
120 generate_2nd_cdc_hits=False,
121 topInCounter=True):
122 """
123 Add CDC CR simulation.
124
125 """
126
127 # background mixing or overlay input before process forking
128 if bkgfiles:
129 if bkgOverlay:
130 bkginput = b2.register_module('BGOverlayInput')
131 bkginput.param('inputFileNames', bkgfiles)
132 path.add_module(bkginput)
133 else:
134 bkgmixer = b2.register_module('BeamBkgMixer')
135 bkgmixer.param('backgroundFiles', bkgfiles)
136 if bkgcomponents:
137 bkgmixer.param('components', bkgcomponents)
138 else:
139 if components:
140 bkgmixer.param('components', components)
141 bkgmixer.param('overallScaleFactor', bkgscale)
142 path.add_module(bkgmixer)
143
144 # geometry parameter database
145 if 'Gearbox' not in path:
146 gearbox = b2.register_module('Gearbox')
147 path.add_module(gearbox)
148
149 # detector geometry
150 if 'Geometry' not in path:
151 geometry = b2.register_module('Geometry', useDB=True)
152 if components:
153 geometry.param('components', components)
154 path.add_module(geometry)
155
156 # detector simulation
157 if 'FullSim' not in path:
158 g4sim = b2.register_module('FullSim',
159 ProductionCut=1000000.)
160 path.add_module(g4sim)
161
162 # path.add_module(RandomizeTrackTimeModule(8.0))
163
164 # CDC digitization
165 if components is None or 'CDC' in components:
166 cdc_digitizer = b2.register_module('CDCDigitizer')
167 cdc_digitizer.param("Output2ndHit", generate_2nd_cdc_hits)
168 path.add_module(cdc_digitizer)
169
170 # ECL digitization
171 if components is None or 'ECL' in components:
172 ecl_digitizer = b2.register_module('ECLDigitizer')
173 if bkgfiles is not None:
174 ecl_digitizer.param('Background', 1)
175 path.add_module(ecl_digitizer)
176
177
178def add_cdc_cr_reconstruction(path, eventTimingExtraction=True,
179 topInCounter=False,
180 pval2ndTrial=0.001):
181 """
182 Add CDC CR reconstruction
183 """
184
185 # Add cdc track finder
186 add_cdc_cr_track_finding(path, merge_tracks=False)
187
188 # Setup Genfit extrapolation
189 path.add_module("SetupGenfitExtrapolation")
190
191 # Time seed
192 path.add_module("PlaneTriggerTrackTimeEstimator",
193 pdgCodeToUseForEstimation=13,
194 triggerPlanePosition=triggerPos,
195 triggerPlaneDirection=normTriggerPlaneDirection,
196 useFittedInformation=False)
197
198 # Initial track fitting
199 path.add_module("DAFRecoFitter",
200 probCut=0.00001,
201 pdgCodesToUseForFitting=13,
202 )
203
204 # Correct time seed with TOP in counter.
205 path.add_module("PlaneTriggerTrackTimeEstimator",
206 pdgCodeToUseForEstimation=13,
207 triggerPlanePosition=triggerPos,
208 triggerPlaneDirection=normTriggerPlaneDirection,
209 useFittedInformation=True,
210 useReadoutPosition=topInCounter,
211 readoutPosition=readOutPos,
212 readoutPositionPropagationSpeed=lightPropSpeed
213 )
214
215 # Track fitting
216 path.add_module("DAFRecoFitter",
217 probCut=pval2ndTrial,
218 pdgCodesToUseForFitting=13
219 )
220
221 if eventTimingExtraction is True:
222 # Extract the time
223 path.add_module("FullGridChi2TrackTimeExtractor",
224 RecoTracksStoreArrayName="RecoTracks",
225 GridMaximalT0Value=40,
226 GridMinimalT0Value=-40,
227 GridGridSteps=6
228 )
229
230 # Track fitting
231 path.add_module("DAFRecoFitter",
232 probCut=pval2ndTrial,
233 pdgCodesToUseForFitting=13
234 )
235
236 # Create Belle2 Tracks from the genfit Tracks
237 path.add_module('TrackCreator',
238 pdgCodes=[13],
239 useClosestHitToIP=True,
240 useBFieldAtHit=True
241 )
242
243
244def add_cdc_reconstruction(path, eventTimingExtraction=True,
245 pval2ndTrial=0.001):
246 """
247 Add CDC CR reconstruction
248 """
249
250 # Add cdc track finder
251 add_cdc_track_finding(path)
252
253 # Setup Genfit extrapolation
254 path.add_module('SetupGenfitExtrapolation',
255 energyLossBrems=False, noiseBrems=False)
256
257 # Correct time seed
258 path.add_module("IPTrackTimeEstimator",
259 # recoTracksStoreArrayName=reco_tracks,
260 useFittedInformation=False)
261 # track fitting
262 path.add_module("DAFRecoFitter",
263 probCut=0.00001)
264
265 # Correct time seed
266 path.add_module("IPTrackTimeEstimator",
267 # recoTracksStoreArrayName=reco_tracks,
268 useFittedInformation=True)
269
270 # Track fitting
271 path.add_module("DAFRecoFitter",
272 probCut=pval2ndTrial,
273 )
274
275 if eventTimingExtraction is True:
276 # Extract the time
277 path.add_module("FullGridChi2TrackTimeExtractor",
278 RecoTracksStoreArrayName="RecoTracks",
279 GridMaximalT0Value=40,
280 GridMinimalT0Value=-40,
281 GridGridSteps=6
282 )
283
284 # Track fitting
285 path.add_module("DAFRecoFitter",
286 probCut=pval2ndTrial,
287 )
288
289 # Create Belle2 Tracks from the genfit Tracks
290 path.add_module('TrackCreator',
291 pdgCodes=[211, 321, 2212])
292
293
294def getExpRunNumber(fname):
295 """
296 Get expperimental number and run number from file name.
297 """
298 f = ROOT.TFile(fname)
299 t = f.Get('tree')
300 t.GetEntry(0)
301 e = t.EventMetaData
302 exp = e.getExperiment()
303 run = e.getRun()
304 f.Close()
305 return [exp, run]
306
307
308def getRunNumber(fname):
309 """
310 Get run number from file name.
311 """
312 f = ROOT.TFile(fname)
313 t = f.Get('tree')
314 t.GetEntry(0)
315 e = t.EventMetaData
316 run = e.getRun()
317 f.Close()
318 return run
319
320
321def getDataPeriod(exp=0, run=0):
322 """
323 Get data period from run number
324 It should be replaced the argument from run to (exp, run)!
325 """
326 period = None
327
328 if exp == 1: # GCR2017
329 return 'gcr2017'
330
331 if exp == 2: # GCR2
332 return 'phase2'
333
334 if exp == 3: # Phase2
335 return 'phase2'
336
337 if exp > 3: # Phase3?
338 return 'phase3'
339
340 # Pre global cosmics until March 2017
341 global run_range
342
343 for key in run_range:
344 if run_range[key][0] <= run <= run_range[key][1]:
345 period = key
346 print("Data period : " + key)
347 break
348
349 if period is None:
350 b2.B2WARNING("No valid data period is specified.")
351 b2.B2WARNING("Default configuration is loaded.")
352 period = 'normal'
353 return period
354
355
356def getPhiRotation():
357 global globalPhi
358 return(globalPhi)
359
360
361def getMapperAngle(exp=1, run=3118):
362 '''
363 Get B field mapper angle from exp and run number.
364 '''
365 if exp == 1:
366 if run < 3883:
367 return 16.7
368 else:
369 return 43.3
370 else:
371 return None
372
373
374def getTriggerType(exp=1, run=3118):
375 '''
376 Get trigger type from exp and run number.
377 '''
378 if exp == 1:
379 if run >= 3100 and run <= 3600:
380 return 'b2b'
381 elif run >= 3642 and run <= 4018:
382 return 'single'
383 else:
384 return None
385 else:
386 return None
387
388
389def add_GCR_Trigger_simulation(path, backToBack=False, skipEcl=True):
390 """
391 function to simulate trigger for GCR cosmics 2017. use CDC+ECL trigger
392 :param path: path want to add trigger simulation
393 :param backToBack: if true back to back TSF2; if false single TSF2
394 :param skipEcl: ignore ECL in trigger, just use CDC TSF2
395 """
396 empty_path = b2.create_path()
397 path.add_module('CDCTriggerTSF',
398 InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v2.2.coe"),
399 OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v2.2.coe"))
400 if not skipEcl:
401 path.add_module('TRGECLFAM',
402 TCWaveform=0,
403 FAMFitMethod=1,
404 TCThreshold=100,
405 BeamBkgTag=0,
406 ShapingFunction=1)
407 path.add_module('TRGECL',
408 Clustering=0,
409 EventTiming=1,
410 Bhabha=0,
411 EventSelect=0,
412 TimeWindow=375)
413
414 TSF = path.add_module('TRGGDLCosmicRun',
415 BackToBack=backToBack,
416 skipECL=skipEcl)
417 TSF.if_false(empty_path)
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151