Belle II Software development
run_BS13d_calibration_localruns.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------
12# CAF calibration script: BS13d carrier shifts
13# data type: local runs (laser, singe-pulse or double-pulse)
14#
15# usage: basf2 run_BS13d_calibration_localruns.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_local
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 = '/ghi/fs01/belle2/bdata/group/detector/TOP/2019-*/data_sroot_global/'
30main_output_dir = 'top_calibration'
31maxFiles = 1 # maximum number of input files per run (0 or negative means all)
32look_back = 28 # look-back window setting (set to 0 if look-back setting available in DB)
33#
34# ---------------------------------------------------------------------------------------
35
36# Argument parsing
37argvs = sys.argv
38if len(argvs) < 4:
39 print("usage: basf2", argvs[0], "experiment runFirst runLast")
40 sys.exit()
41experiment = int(argvs[1])
42run_first = int(argvs[2])
43run_last = int(argvs[3])
44
45# Make list of files
46inputFiles = []
47expNo = 'e' + f'{experiment:04d}'
48for run in range(run_first, run_last + 1):
49 expRun = f'{experiment:04d}' + '.' + f'{run:05d}'
50 filename = f"{data_dir}/top.{expRun}.*.sroot"
51 files = glob.glob(filename)
52 if maxFiles > 0:
53 for i in range(min(len(files), maxFiles)):
54 inputFiles.append(files[i])
55 else:
56 inputFiles += files
57
58if len(inputFiles) == 0:
59 B2ERROR('No sroot files found in ' + data_dir + ' for exp=' + str(experiment) +
60 ' runFirst=' + str(run_first) + ' runLast=' + str(run_last))
61 sys.exit()
62
63# Output folder name
64run_range = 'r' + f'{run_first:05d}' + '-' + f'{run_last:05d}'
65output_dir = f"{main_output_dir}/BS13d-local-{expNo}-{run_range}"
66
67# Define calibration
68cal = BS13d_calibration_local(inputFiles, look_back, globalTags, localDBs)
69cal.backend_args = {"queue": "s"}
70
71# Add calibration to CAF
72cal_fw = CAF()
73cal_fw.add_calibration(cal)
74cal_fw.output_dir = output_dir
75cal_fw.backend = backends.LSF()
76
77# Run calibration
78cal_fw.run()