Belle II Software  release-08-01-10
top_calibration.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration functions
14 # ---------------------------------------------------------------------------------------
15 
16 import basf2
17 from rawdata import add_unpackers
18 from reconstruction import add_cosmics_reconstruction
19 from softwaretrigger.constants import ALWAYS_SAVE_OBJECTS, RAWDATA_OBJECTS
20 from caf.framework import Calibration, Collection
21 from caf.strategies import SequentialRunByRun, SingleIOV, SequentialBoundaries
22 from ROOT.Belle2 import TOP
23 
24 
25 def BS13d_calibration_local(inputFiles, look_back=28, globalTags=None, localDBs=None, sroot=False):
26  '''
27  Returns calibration object for carrier shift calibration of BS13d with local runs
28  (laser, single-pulse or double-pulse).
29  :param inputFiles: A list of input files
30  :param look_back: look-back window setting (set it to 0 to use the one from DB)
31  :param globalTags: a list of global tags, highest priority first
32  :param localDBs: a list of local databases, highest priority first
33  :param sroot: True if input files are in sroot format, False if in root format
34  '''
35 
36  # create path
37  main = basf2.create_path()
38 
39  # add basic modules
40  if sroot:
41  main.add_module('SeqRootInput')
42  else:
43  main.add_module('RootInput')
44  main.add_module('TOPGeometryParInitializer')
45  main.add_module('TOPUnpacker')
46  main.add_module('TOPRawDigitConverter', lookBackWindows=look_back,
47  useAsicShiftCalibration=False, useChannelT0Calibration=False)
48 
49  # collector module
50  collector = basf2.register_module('TOPAsicShiftsBS13dCollector')
51 
52  # algorithm
53  algorithm = TOP.TOPAsicShiftsBS13dAlgorithm()
54  algorithm.setWindowSize(0)
55 
56  # define calibration
57  cal = Calibration(name='TOP_BS13dCalibration', collector=collector,
58  algorithms=algorithm, input_files=inputFiles)
59  if globalTags:
60  for globalTag in reversed(globalTags):
61  cal.use_central_database(globalTag)
62  if localDBs:
63  for localDB in reversed(localDBs):
64  cal.use_local_database(localDB)
65  cal.pre_collector_path = main
66  cal.strategies = SequentialRunByRun
67 
68  return cal
69 
70 
71 def BS13d_calibration_rawdata(inputFiles, globalTags=None, localDBs=None):
72  '''
73  Returns calibration object for carrier shift calibration of BS13d with raw data.
74  :param inputFiles: A list of input files in raw data format
75  :param globalTags: a list of global tags, highest priority first
76  :param localDBs: a list of local databases, highest priority first
77  '''
78 
79  # create path
80  main = basf2.create_path()
81 
82  # add basic modules
83  main.add_module('RootInput')
84  main.add_module('TOPGeometryParInitializer')
85  main.add_module('TOPUnpacker')
86  main.add_module('TOPRawDigitConverter',
87  useAsicShiftCalibration=False, useChannelT0Calibration=False)
88 
89  # collector module
90  collector = basf2.register_module('TOPAsicShiftsBS13dCollector')
91 
92  # algorithm
93  algorithm = TOP.TOPAsicShiftsBS13dAlgorithm()
94 
95  # define calibration
96  cal = Calibration(name='TOP_BS13dCalibration', collector=collector,
97  algorithms=algorithm, input_files=inputFiles)
98  if globalTags:
99  for globalTag in reversed(globalTags):
100  cal.use_central_database(globalTag)
101  if localDBs:
102  for localDB in reversed(localDBs):
103  cal.use_local_database(localDB)
104  cal.pre_collector_path = main
105  cal.strategies = SequentialRunByRun
106 
107  return cal
108 
109 
110 def BS13d_calibration_cdst(inputFiles, time_offset=0, globalTags=None, localDBs=None,
111  new_cdst_format=True):
112  '''
113  Returns calibration object for carrier shift calibration of BS13d with processed data.
114  :param inputFiles: A list of input files in cdst data format
115  :param time_offset: time offset [ns]
116  :param globalTags: a list of global tags, highest priority first
117  :param localDBs: a list of local databases, highest priority first
118  :param new_cdst_format: True or False for new or old cdst format, respectively
119  '''
120 
121  # create path
122  main = basf2.create_path()
123 
124  # add basic modules
125  main.add_module('RootInput')
126  if new_cdst_format:
127  main.add_module('Gearbox')
128  main.add_module('Geometry')
129  main.add_module('Ext')
130  main.add_module('TOPUnpacker')
131  main.add_module('TOPRawDigitConverter')
132  main.add_module('TOPChannelMasker')
133  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False, subtractRunningOffset=False)
134  main.add_module('TOPTimeRecalibrator',
135  useAsicShiftCalibration=False, useChannelT0Calibration=True)
136  else:
137  main.add_module('TOPGeometryParInitializer')
138  main.add_module('TOPTimeRecalibrator',
139  useAsicShiftCalibration=False, useChannelT0Calibration=True)
140 
141  # collector module
142  collector = basf2.register_module('TOPAsicShiftsBS13dCollector',
143  timeOffset=time_offset, requireRecBunch=True)
144 
145  # algorithm
146  algorithm = TOP.TOPAsicShiftsBS13dAlgorithm()
147 
148  # define calibration
149  cal = Calibration(name='TOP_BS13dCalibration', collector=collector,
150  algorithms=algorithm, input_files=inputFiles)
151  if globalTags:
152  for globalTag in reversed(globalTags):
153  cal.use_central_database(globalTag)
154  if localDBs:
155  for localDB in reversed(localDBs):
156  cal.use_local_database(localDB)
157  cal.pre_collector_path = main
158  cal.strategies = SequentialRunByRun
159 
160  return cal
161 
162 
163 def moduleT0_calibration_DeltaT(inputFiles, globalTags=None, localDBs=None,
164  new_cdst_format=True):
165  '''
166  Returns calibration object for rough module T0 calibration with method DeltaT
167  :param inputFiles: A list of input files in cdst data format
168  :param globalTags: a list of global tags, highest priority first
169  :param localDBs: a list of local databases, highest priority first
170  :param new_cdst_format: True or False for new or old cdst format, respectively
171  '''
172 
173  # create path
174  main = basf2.create_path()
175 
176  # add basic modules
177  main.add_module('RootInput')
178  if new_cdst_format:
179  main.add_module('Gearbox')
180  main.add_module('Geometry')
181  main.add_module('Ext')
182  main.add_module('TOPUnpacker')
183  main.add_module('TOPRawDigitConverter')
184  main.add_module('TOPChannelMasker')
185  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False, subtractRunningOffset=False)
186  else:
187  main.add_module('TOPGeometryParInitializer')
188  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
189  main.add_module('TOPChannelMasker')
190  main.add_module('TOPBunchFinder', usePIDLikelihoods=True, autoRange=True, useTimeSeed=False, useFillPattern=False,
191  subtractRunningOffset=False)
192 
193  # collector module
194  collector = basf2.register_module('TOPModuleT0DeltaTCollector')
195  collector.param('granularity', 'run')
196 
197  # algorithm
198  algorithm = TOP.TOPModuleT0DeltaTAlgorithm()
199 
200  # define calibration
201  cal = Calibration(name='TOP_moduleT0_rough', collector=collector,
202  algorithms=algorithm, input_files=inputFiles)
203  if globalTags:
204  for globalTag in reversed(globalTags):
205  cal.use_central_database(globalTag)
206  if localDBs:
207  for localDB in reversed(localDBs):
208  cal.use_local_database(localDB)
209  cal.pre_collector_path = main
210  cal.strategies = SequentialBoundaries # Was SingleIOV before proc12
211 
212  return cal
213 
214 
215 def moduleT0_calibration_LL(inputFiles, sample='dimuon', globalTags=None, localDBs=None,
216  new_cdst_format=True):
217  '''
218  Returns calibration object for final module T0 calibration with method LL
219  :param inputFiles: A list of input files in cdst data format
220  :param sample: data sample ('dimuon' or 'bhabha')
221  :param globalTags: a list of global tags, highest priority first
222  :param localDBs: a list of local databases, highest priority first
223  :param new_cdst_format: True or False for new or old cdst format, respectively
224  '''
225 
226  # create path
227  main = basf2.create_path()
228 
229  # add basic modules
230  main.add_module('RootInput')
231  if new_cdst_format:
232  main.add_module('Gearbox')
233  main.add_module('Geometry')
234  main.add_module('Ext')
235  main.add_module('TOPUnpacker')
236  main.add_module('TOPRawDigitConverter')
237  main.add_module('TOPChannelMasker')
238  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False, subtractRunningOffset=False)
239  else:
240  main.add_module('TOPGeometryParInitializer')
241  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
242  main.add_module('TOPChannelMasker')
243  main.add_module('TOPBunchFinder', usePIDLikelihoods=True, autoRange=True, useTimeSeed=False, useFillPattern=False,
244  subtractRunningOffset=False)
245 
246  # collector module
247  collector = basf2.register_module('TOPModuleT0LLCollector')
248  collector.param('sample', sample)
249  collector.param('granularity', 'run')
250 
251  # algorithm
252  algorithm = TOP.TOPModuleT0LLAlgorithm()
253 
254  # define calibration
255  cal = Calibration(name='TOP_moduleT0_final', collector=collector,
256  algorithms=algorithm, input_files=inputFiles)
257  if globalTags:
258  for globalTag in reversed(globalTags):
259  cal.use_central_database(globalTag)
260  if localDBs:
261  for localDB in reversed(localDBs):
262  cal.use_local_database(localDB)
263  cal.pre_collector_path = main
264  cal.strategies = SequentialBoundaries # Was SingleIOV before proc12
265 
266  return cal
267 
268 
269 def moduleT0_calibration_cosmics(inputFiles, globalTags=None, localDBs=None,
270  data_format="raw", full_reco=True):
271  '''
272  Returns calibration object for module T0 calibration with cosmic data using DeltaT method.
273  Note: by default cdst is processed with merging incoming and outcoming track segments of a cosmic particle,
274  but we need here separate track segments in order to get ExtHits in incoming and outcoming module.
275  :param inputFiles: A list of input files in cdst data format
276  :param globalTags: a list of global tags, highest priority first
277  :param localDBs: a list of local databases, highest priority first
278  :param data_format: "raw" for raw data or "cdst" for the new cdst format
279  :param full_reco: on True, run full cosmics reconstruction also if data_format=="cdst"
280  '''
281 
282  # create path
283  main = basf2.create_path()
284 
285  # add basic modules
286  if data_format == "cdst" and full_reco:
287  main.add_module('RootInput', branchNames=ALWAYS_SAVE_OBJECTS + RAWDATA_OBJECTS)
288  else:
289  main.add_module('RootInput')
290 
291  main.add_module('Gearbox')
292  main.add_module('Geometry')
293  if data_format == "raw" or full_reco:
294  add_unpackers(main)
295  add_cosmics_reconstruction(main, merge_tracks=False, reconstruct_cdst=True)
296  else:
297  main.add_module('TOPUnpacker')
298  main.add_module('TOPRawDigitConverter')
299 
300  main.add_module('Ext')
301  main.add_module('TOPChannelMasker')
302  main.add_module('TOPCosmicT0Finder', useIncomingTrack=True, applyT0=False)
303  main.add_module('TOPCosmicT0Finder', useIncomingTrack=False, applyT0=False)
304 
305  # collector module
306  collector = basf2.register_module('TOPModuleT0DeltaTCollector')
307  collector.param('granularity', 'run')
308 
309  # algorithm
310  algorithm = TOP.TOPModuleT0DeltaTAlgorithm()
311 
312  # define calibration
313  cal = Calibration(name='TOP_moduleT0_cosmics', collector=collector,
314  algorithms=algorithm, input_files=inputFiles)
315  if globalTags:
316  for globalTag in reversed(globalTags):
317  cal.use_central_database(globalTag)
318  if localDBs:
319  for localDB in reversed(localDBs):
320  cal.use_local_database(localDB)
321  cal.pre_collector_path = main
322  cal.strategies = SingleIOV
323 
324  return cal
325 
326 
327 def commonT0_calibration_BF(inputFiles, globalTags=None, localDBs=None,
328  new_cdst_format=True):
329  '''
330  Returns calibration object for common T0 calibration with method BF
331  :param inputFiles: A list of input files in cdst data format
332  :param globalTags: a list of global tags, highest priority first
333  :param localDBs: a list of local databases, highest priority first
334  :param new_cdst_format: True or False for new or old cdst format, respectively
335  '''
336 
337  # create path
338  main = basf2.create_path()
339 
340  # add basic modules
341  main.add_module('RootInput')
342  if new_cdst_format:
343  main.add_module('Gearbox')
344  main.add_module('Geometry')
345  main.add_module('Ext')
346  main.add_module('TOPUnpacker')
347  main.add_module('TOPRawDigitConverter')
348  main.add_module('TOPChannelMasker')
349  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False, subtractRunningOffset=False)
350  else:
351  main.add_module('TOPGeometryParInitializer')
352  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
353  main.add_module('TOPChannelMasker')
354  main.add_module('TOPBunchFinder', usePIDLikelihoods=True, autoRange=True, useTimeSeed=False, useFillPattern=False,
355  subtractRunningOffset=False)
356 
357  # collector module
358  collector = basf2.register_module('TOPCommonT0BFCollector')
359 
360  # algorithm
361  algorithm = TOP.TOPCommonT0BFAlgorithm()
362 
363  # define calibration
364  cal = Calibration(name='TOP_commonT0Calibration', collector=collector,
365  algorithms=algorithm, input_files=inputFiles)
366  if globalTags:
367  for globalTag in reversed(globalTags):
368  cal.use_central_database(globalTag)
369  if localDBs:
370  for localDB in reversed(localDBs):
371  cal.use_local_database(localDB)
372  cal.pre_collector_path = main
373  cal.strategies = SequentialRunByRun
374 
375  return cal
376 
377 
378 def commonT0_calibration_LL(inputFiles, sample='dimuon', globalTags=None, localDBs=None,
379  new_cdst_format=True):
380  '''
381  Returns calibration object for common T0 calibration with method LL
382  :param inputFiles: A list of input files in cdst data format
383  :param sample: data sample ('dimuon' or 'bhabha')
384  :param globalTags: a list of global tags, highest priority first
385  :param localDBs: a list of local databases, highest priority first
386  :param new_cdst_format: True or False for new or old cdst format, respectively
387  '''
388 
389  # create path
390  main = basf2.create_path()
391 
392  # basic modules
393  main.add_module('RootInput')
394  if new_cdst_format:
395  main.add_module('Gearbox')
396  main.add_module('Geometry')
397  main.add_module('Ext')
398  main.add_module('TOPUnpacker')
399  main.add_module('TOPRawDigitConverter')
400  main.add_module('TOPChannelMasker')
401  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False, subtractRunningOffset=False)
402  else:
403  main.add_module('TOPGeometryParInitializer')
404  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
405  main.add_module('TOPChannelMasker')
406  main.add_module('TOPBunchFinder', usePIDLikelihoods=True, autoRange=True, useTimeSeed=False, useFillPattern=False,
407  subtractRunningOffset=False)
408 
409  # collector module
410  collector = basf2.register_module('TOPCommonT0LLCollector')
411  collector.param('sample', sample)
412 
413  # algorithm
414  algorithm = TOP.TOPCommonT0LLAlgorithm()
415 
416  # define calibration
417  cal = Calibration(name='TOP_commonT0Calibration', collector=collector,
418  algorithms=algorithm, input_files=inputFiles)
419  if globalTags:
420  for globalTag in reversed(globalTags):
421  cal.use_central_database(globalTag)
422  if localDBs:
423  for localDB in reversed(localDBs):
424  cal.use_local_database(localDB)
425  cal.pre_collector_path = main
426  cal.strategies = SequentialRunByRun
427 
428  return cal
429 
430 
431 def pulseHeight_calibration_laser(inputFiles, t_min=-50.0, t_max=0.0, look_back=28,
432  globalTags=None, localDBs=None, sroot=False):
433  '''
434  Returns calibration object for calibration of pulse-height distributions and
435  threshold efficiencies with local laser runs.
436  :param inputFiles: A list of input files
437  :param t_min: lower edge of time window to select laser signal [ns]
438  :param t_max: upper edge of time window to select laser signal [ns]
439  :param look_back: look-back window setting (set it to 0 to use the one from DB)
440  :param globalTags: a list of global tags, highest priority first
441  :param localDBs: a list of local databases, highest priority first
442  :param sroot: True if input files are in sroot format, False if in root format
443  '''
444 
445  # create path
446  main = basf2.create_path()
447 
448  # add basic modules
449  if sroot:
450  main.add_module('SeqRootInput')
451  else:
452  main.add_module('RootInput')
453  main.add_module('TOPGeometryParInitializer')
454  main.add_module('TOPUnpacker')
455  main.add_module('TOPRawDigitConverter', lookBackWindows=look_back)
456 
457  # collector module
458  collector = basf2.register_module('TOPPulseHeightCollector')
459  collector.param('timeWindow', [t_min, t_max])
460  collector.param('granularity', 'all')
461 
462  # algorithm
463  algorithm = TOP.TOPPulseHeightAlgorithm()
464 
465  # define calibration
466  cal = Calibration(name='TOP_pulseHeightCalibration', collector=collector,
467  algorithms=algorithm, input_files=inputFiles)
468  if globalTags:
469  for globalTag in reversed(globalTags):
470  cal.use_central_database(globalTag)
471  if localDBs:
472  for localDB in reversed(localDBs):
473  cal.use_local_database(localDB)
474  cal.pre_collector_path = main
475  cal.strategies = SingleIOV
476 
477  return cal
478 
479 
480 def pulseHeight_calibration_rawdata(inputFiles, globalTags=None, localDBs=None):
481  '''
482  Returns calibration object for calibration of pulse-height distributions and
483  threshold efficiencies with raw data
484  :param inputFiles: A list of input files in raw data format
485  :param globalTags: a list of global tags, highest priority first
486  :param localDBs: a list of local databases, highest priority first
487  '''
488 
489  # create path
490  main = basf2.create_path()
491 
492  # add basic modules
493  main.add_module('RootInput')
494  main.add_module('TOPGeometryParInitializer')
495  main.add_module('TOPUnpacker')
496  main.add_module('TOPRawDigitConverter')
497 
498  # collector module
499  collector = basf2.register_module('TOPPulseHeightCollector')
500  collector.param('granularity', 'all')
501 
502  # algorithm
503  algorithm = TOP.TOPPulseHeightAlgorithm()
504 
505  # define calibration
506  cal = Calibration(name='TOP_pulseHeightCalibration', collector=collector,
507  algorithms=algorithm, input_files=inputFiles)
508  if globalTags:
509  for globalTag in reversed(globalTags):
510  cal.use_central_database(globalTag)
511  if localDBs:
512  for localDB in reversed(localDBs):
513  cal.use_local_database(localDB)
514  cal.pre_collector_path = main
515  cal.strategies = SingleIOV
516 
517  return cal
518 
519 
520 def module_alignment(inputFiles, sample='dimuon', fixedParameters=None,
521  globalTags=None, localDBs=None, new_cdst_format=True,
522  backend_args=None):
523  '''
524  Returns calibration object for alignment of TOP modules.
525  :param inputFiles: A list of input files in cdst data format
526  :param sample: data sample ('dimuon' or 'bhabha')
527  :fixedParameters: a list of parameters to be fixed (parameter names: basf2 -m TOPAlignmentCollector)
528  :param globalTags: a list of global tags, highest priority first
529  :param localDBs: a list of local databases, highest priority first
530  :param new_cdst_format: True or False for new or old cdst format, respectively
531  :param backend_args: Dictionary of backend args for the Collection object to use
532  '''
533 
534  # define calibration
535  cal = Calibration(name='TOP_alignment')
536  if globalTags:
537  for globalTag in reversed(globalTags):
538  cal.use_central_database(globalTag)
539  if localDBs:
540  for localDB in reversed(localDBs):
541  cal.use_local_database(localDB)
542  cal.strategies = SingleIOV
543 
544  # add collections
545  for slot in range(1, 17):
546  # create path
547  main = basf2.create_path()
548 
549  # add basic modules
550  main.add_module('RootInput')
551  if new_cdst_format:
552  main.add_module('Gearbox')
553  main.add_module('Geometry')
554  main.add_module('Ext')
555  main.add_module('TOPUnpacker')
556  main.add_module('TOPRawDigitConverter')
557  main.add_module('TOPChannelMasker')
558  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False,
559  subtractRunningOffset=False)
560  else:
561  main.add_module('TOPGeometryParInitializer')
562  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
563  main.add_module('TOPChannelMasker')
564  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False,
565  usePIDLikelihoods=True, subtractRunningOffset=False)
566 
567  # collector module: executing iterative alignment method
568  collector = basf2.register_module('TOPAlignmentCollector')
569  collector.param('sample', sample)
570  if fixedParameters:
571  collector.param('parFixed', fixedParameters)
572  collector.param('targetModule', slot)
573  collector.param('granularity', 'all')
574 
575  # define collection:
576  # because of iterative nature of the method we must run exactly one job per collection
577  # which must process all the files from input list
578  collection = Collection(collector=collector, input_files=inputFiles,
579  pre_collector_path=main, max_collector_jobs=1)
580  if globalTags:
581  for globalTag in reversed(globalTags):
582  collection.use_central_database(globalTag)
583  if localDBs:
584  for localDB in reversed(localDBs):
585  collection.use_local_database(localDB)
586  if backend_args:
587  collection.backend_args = backend_args
588 
589  # add collection to calibration
590  cal.add_collection(name='slot_' + '{:0=2d}'.format(slot), collection=collection)
591 
592  # algorithm: it just greps the last iterations of collections and prepares the payload
593  algorithm = TOP.TOPAlignmentAlgorithm()
594  cal.algorithms = algorithm
595 
596  return cal
597 
598 
599 def channel_mask_calibration(inputFiles, globalTags=None, localDBs=None, unpack=True):
600  '''
601  Returns calibration object for channel masking
602  :param inputFiles: A list of input files in raw data or cdst format
603  :param globalTags: a list of global tags, highest priority first
604  :param localDBs: a list of local databases, highest priority first
605  :param unpack: True if data unpacking is required (i.e. for raw data or for new cdst format)
606  '''
607 
608  # create path
609  main = basf2.create_path()
610 
611  # add basic modules
612  main.add_module('RootInput')
613  main.add_module('TOPGeometryParInitializer')
614  if unpack:
615  main.add_module('TOPUnpacker')
616  main.add_module('TOPRawDigitConverter')
617 
618  # collector module
619  collector = basf2.register_module('TOPChannelMaskCollector')
620 
621  # algorithm
622  algorithm = TOP.TOPChannelMaskAlgorithm()
623 
624  # define calibration
625  cal = Calibration(name='TOP_ChannelMaskCalibration', collector=collector,
626  algorithms=algorithm, input_files=inputFiles)
627  if globalTags:
628  for globalTag in reversed(globalTags):
629  cal.use_central_database(globalTag)
630  if localDBs:
631  for localDB in reversed(localDBs):
632  cal.use_local_database(localDB)
633  cal.pre_collector_path = main
634  cal.strategies = SequentialRunByRun
635 
636  return cal
637 
638 
639 def offset_calibration(inputFiles, globalTags=None, localDBs=None,
640  new_cdst_format=True):
641  '''
642  Returns calibration object for the calibration of offsets
643  :param inputFiles: A list of input files in cdst data format
644  :param globalTags: a list of global tags, highest priority first
645  :param localDBs: a list of local databases, highest priority first
646  :param new_cdst_format: True or False for new or old cdst format, respectively
647  '''
648 
649  # create path
650  main = basf2.create_path()
651 
652  # add basic modules
653  main.add_module('RootInput')
654  if new_cdst_format:
655  main.add_module('Gearbox')
656  main.add_module('Geometry')
657  main.add_module('Ext')
658  main.add_module('TOPUnpacker')
659  main.add_module('TOPRawDigitConverter')
660  main.add_module('TOPChannelMasker')
661  main.add_module('TOPBunchFinder', autoRange=True, useTimeSeed=False, useFillPattern=False, subtractRunningOffset=False)
662  else:
663  main.add_module('TOPGeometryParInitializer')
664  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
665  main.add_module('TOPChannelMasker')
666  main.add_module('TOPBunchFinder', usePIDLikelihoods=True, autoRange=True, useTimeSeed=False, useFillPattern=False,
667  subtractRunningOffset=False)
668 
669  # collector module
670  collector = basf2.register_module('TOPOffsetCollector')
671 
672  # algorithms
673  algorithms = [TOP.TOPEventT0OffsetAlgorithm(), TOP.TOPFillPatternOffsetAlgorithm()]
674 
675  # define calibration
676  cal = Calibration(name='TOP_offsetCalibration', collector=collector,
677  algorithms=algorithms, input_files=inputFiles)
678  if globalTags:
679  for globalTag in reversed(globalTags):
680  cal.use_central_database(globalTag)
681  if localDBs:
682  for localDB in reversed(localDBs):
683  cal.use_local_database(localDB)
684  cal.pre_collector_path = main
685  cal.strategies = SequentialRunByRun
686 
687  return cal
688 
689 
690 def photonYields_calibration(inputFiles, sample='dimuon', globalTags=None, localDBs=None):
691  '''
692  Returns calibration object for photon pixel yields aimed for PMT ageing studies and for finding optically decoupled PMT's
693  :param inputFiles: A list of input files in cdst data format
694  :param sample: data sample ('dimuon' or 'bhabha')
695  :param globalTags: a list of global tags, highest priority first
696  :param localDBs: a list of local databases, highest priority first
697  '''
698 
699  # create path
700  main = basf2.create_path()
701 
702  # add basic modules
703  main.add_module('RootInput')
704  main.add_module('Gearbox')
705  main.add_module('Geometry')
706  main.add_module('Ext')
707  main.add_module('TOPUnpacker')
708  main.add_module('TOPRawDigitConverter')
709  main.add_module('TOPChannelMasker')
710  main.add_module('TOPBunchFinder')
711  if sample == 'bhabha':
712  main.add_module('TOPPDFDebugger', pdgCodes=[11])
713  else:
714  main.add_module('TOPPDFDebugger', pdgCodes=[13])
715 
716  # collector module
717  collector = basf2.register_module('TOPPhotonYieldsCollector')
718  collector.param('sample', sample)
719  collector.param('granularity', 'run')
720 
721  # algorithm
722  algorithm = TOP.TOPPhotonYieldsAlgorithm()
723 
724  # define calibration
725  cal = Calibration(name='TOP_photonYields', collector=collector,
726  algorithms=algorithm, input_files=inputFiles)
727  if globalTags:
728  for globalTag in reversed(globalTags):
729  cal.use_central_database(globalTag)
730  if localDBs:
731  for localDB in reversed(localDBs):
732  cal.use_local_database(localDB)
733  cal.pre_collector_path = main
734  cal.strategies = SequentialBoundaries # Was SingleIOV before proc12
735 
736  return cal
737 
738 
739 def calibration_validation(inputFiles, sample='dimuon', globalTags=None, localDBs=None, new_cdst_format=True):
740  '''
741  Returns calibration object for calibration validation
742  :param inputFiles: A list of input files in cdst data format
743  :param sample: data sample ('dimuon' or 'bhabha')
744  :param globalTags: a list of global tags, highest priority first
745  :param localDBs: a list of local databases, highest priority first
746  :param new_cdst_format: True or False for new or old cdst format, respectively
747  '''
748 
749  # create path
750  main = basf2.create_path()
751 
752  # add basic modules
753  main.add_module('RootInput')
754  if new_cdst_format:
755  main.add_module('Gearbox')
756  main.add_module('Geometry')
757  main.add_module('Ext')
758  main.add_module('TOPUnpacker')
759  main.add_module('TOPRawDigitConverter')
760  main.add_module('TOPChannelMasker')
761  main.add_module('TOPBunchFinder')
762  else:
763  main.add_module('TOPGeometryParInitializer')
764  main.add_module('TOPTimeRecalibrator', subtractBunchTime=False)
765  main.add_module('TOPChannelMasker')
766  main.add_module('TOPBunchFinder', usePIDLikelihoods=True)
767 
768  # collector module
769  collector = basf2.register_module('TOPValidationCollector')
770  collector.param('sample', sample)
771  collector.param('granularity', 'run')
772 
773  # algorithm
774  algorithm = TOP.TOPValidationAlgorithm()
775 
776  # define calibration
777  cal = Calibration(name='TOP_validation', collector=collector,
778  algorithms=algorithm, input_files=inputFiles)
779  if globalTags:
780  for globalTag in reversed(globalTags):
781  cal.use_central_database(globalTag)
782  if localDBs:
783  for localDB in reversed(localDBs):
784  cal.use_local_database(localDB)
785  cal.pre_collector_path = main
786  cal.strategies = SingleIOV
787 
788  return cal