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