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