Belle II Software development
run_BS13d_calibration_bhabha.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------
12# CAF calibration script: BS13d carrier shifts
13# data type: cdst hlt_bhabha
14#
15# usage: basf2 run_BS13d_calibration_bhabha.py expNo runFirst runLast
16# ---------------------------------------------------------------------------------------
17
18import sys
19import glob
20from caf import backends
21from caf.framework import CAF
22from basf2 import B2ERROR
23from top_calibration import BS13d_calibration_cdst
24
25# ----- those parameters need to be adjusted before running -----------------------------
26#
27globalTags = ['Reco_master_patch', 'data_reprocessing_proc10'] # highest priority first
28localDBs = [] # highest priority first, local DB's have higher priority than global tags
29data_dir = '/group/belle2/dataprod/Data/OfficialReco/proc10/'
30skim_dir = 'skim/hlt_bhabha/cdst/sub00'
31main_output_dir = 'top_calibration'
32maxFiles = 10 # maximum number of input files per run (0 or negative means all)
33time_offset = 0 # [ns], set to -66.8 for proc9 or older (processed w/ release-3)
34new_cdst_format = False # set to True for input in new cdst format
35#
36# ---------------------------------------------------------------------------------------
37
38# Argument parsing
39argvs = sys.argv
40if len(argvs) < 4:
41 print("usage: basf2", argvs[0], "experiment runFirst runLast")
42 sys.exit()
43experiment = int(argvs[1])
44run_first = int(argvs[2])
45run_last = int(argvs[3])
46
47# Make list of files
48inputFiles = []
49expNo = 'e' + f'{experiment:04d}'
50for run in range(run_first, run_last + 1):
51 runNo = 'r' + f'{run:05d}'
52 filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
53 files = glob.glob(filename)
54 if maxFiles > 0:
55 for i in range(min(len(files), maxFiles)):
56 inputFiles.append(files[i])
57 else:
58 inputFiles += files
59
60if len(inputFiles) == 0:
61 B2ERROR('No cdst files found in ' + data_dir + ' for exp=' + str(experiment) +
62 ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
63 ' (skim_dir=' + skim_dir + ')')
64 sys.exit()
65
66# Output folder name
67run_range = 'r' + f'{run_first:05d}' + '-' + f'{run_last:05d}'
68output_dir = f"{main_output_dir}/BS13d-bhabha-{expNo}-{run_range}"
69
70# Define calibration
71cal = BS13d_calibration_cdst(inputFiles, time_offset, globalTags, localDBs, new_cdst_format)
72cal.backend_args = {"queue": "s"}
73
74# Add calibration to CAF
75cal_fw = CAF()
76cal_fw.add_calibration(cal)
77cal_fw.output_dir = output_dir
78cal_fw.backend = backends.LSF()
79
80# Run calibration
81cal_fw.run()