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