Belle II Software development
run_moduleT0_calibration.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------
12# CAF calibration script: module T0
13# data type: cdst (bhabha or dimuon)
14#
15# usage: basf2 run_moduleT0_calibration.py expNo runFirst runLast [sample]
16# sample = bhabha/dimuon (D = bhabha)
17# ---------------------------------------------------------------------------------------
18
19import sys
20import glob
21from caf import backends
22from caf.framework import CAF
23from basf2 import B2ERROR
24from top_calibration import moduleT0_calibration_DeltaT, moduleT0_calibration_LL
25
26# ----- those parameters need to be adjusted before running -----------------------------
27#
28globalTags = ['Reco_master_patch', 'data_reprocessing_proc10'] # highest priority first
29localDBs = [] # highest priority first, local DB's have higher priority than global tags
30data_dir = '/group/belle2/dataprod/Data/OfficialReco/proc10/'
31bhabha_skim_dir = 'skim/hlt_bhabha/cdst/sub00'
32dimuon_skim_dir = 'offskim/offskim_mumutop/cdst/sub00'
33main_output_dir = 'top_calibration'
34default_sample = 'bhabha'
35new_cdst_format = False # set to True for input in new cdst format
36#
37# ---------------------------------------------------------------------------------------
38
39# Argument parsing
40argvs = sys.argv
41if len(argvs) < 4:
42 print("usage: basf2", argvs[0], "experiment runFirst runLast [sample]")
43 print(" sample = bhabha/dimuon (D = bhabha)")
44 sys.exit()
45experiment = int(argvs[1])
46run_first = int(argvs[2])
47run_last = int(argvs[3])
48sample = default_sample
49
50if len(argvs) > 4:
51 sample = argvs[4]
52
53if sample == 'bhabha':
54 skim_dir = bhabha_skim_dir
55elif sample == 'dimuon':
56 skim_dir = dimuon_skim_dir
57else:
58 B2ERROR("Invalid sample name: " + sample)
59 sys.exit()
60
61# Make list of files
62inputFiles = []
63expNo = 'e' + f'{experiment:04d}'
64for run in range(run_first, run_last + 1):
65 runNo = 'r' + f'{run:05d}'
66 filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
67 inputFiles += glob.glob(filename)
68
69if len(inputFiles) == 0:
70 B2ERROR('No cdst files found in ' + data_dir + ' for exp=' + str(experiment) +
71 ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
72 ' (skim_dir=' + skim_dir + ')')
73 sys.exit()
74
75# Output folder name
76run_range = 'r' + f'{run_first:05d}' + '-' + f'{run_last:05d}'
77output_dir = f"{main_output_dir}/moduleT0-{sample}-{expNo}-{run_range}"
78
79# Define calibrations
80cal1 = moduleT0_calibration_DeltaT(inputFiles, globalTags, localDBs, new_cdst_format)
81cal2 = moduleT0_calibration_LL(inputFiles, sample, globalTags, localDBs, new_cdst_format)
82cal1.backend_args = {"queue": "s"}
83cal2.backend_args = {"queue": "s"}
84cal2.depends_on(cal1)
85
86# Add calibrations to CAF
87cal_fw = CAF()
88cal_fw.add_calibration(cal1)
89cal_fw.add_calibration(cal2)
90cal_fw.output_dir = output_dir
91cal_fw.backend = backends.LSF()
92
93# Run calibration
94cal_fw.run()