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