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