Belle II Software  release-08-01-10
run_BS13d_calibration_localruns.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration script: BS13d carrier shifts
14 # data type: local runs (laser, singe-pulse or double-pulse)
15 #
16 # usage: basf2 run_BS13d_calibration_localruns.py expNo runFirst runLast
17 # ---------------------------------------------------------------------------------------
18 
19 import sys
20 import glob
21 from caf import backends
22 from caf.framework import CAF
23 from basf2 import B2ERROR
24 from top_calibration import BS13d_calibration_local
25 
26 # ----- those parameters need to be adjusted before running -----------------------------
27 #
28 globalTags = ['Reco_master_patch', 'data_reprocessing_proc10'] # highest priority first
29 localDBs = [] # highest priority first, local DB's have higher priority than global tags
30 data_dir = '/ghi/fs01/belle2/bdata/group/detector/TOP/2019-*/data_sroot_global/'
31 main_output_dir = 'top_calibration'
32 maxFiles = 1 # maximum number of input files per run (0 or negative means all)
33 look_back = 28 # look-back window setting (set to 0 if look-back setting available in DB)
34 #
35 # ---------------------------------------------------------------------------------------
36 
37 # Argument parsing
38 argvs = sys.argv
39 if len(argvs) < 4:
40  print("usage: basf2", argvs[0], "experiment runFirst runLast")
41  sys.exit()
42 experiment = int(argvs[1])
43 run_first = int(argvs[2])
44 run_last = int(argvs[3])
45 
46 # Make list of files
47 inputFiles = []
48 expNo = 'e' + '{:0=4d}'.format(experiment)
49 for run in range(run_first, run_last + 1):
50  expRun = '{:0=4d}'.format(experiment) + '.' + '{:0=5d}'.format(run)
51  filename = f"{data_dir}/top.{expRun}.*.sroot"
52  files = glob.glob(filename)
53  if maxFiles > 0:
54  for i in range(min(len(files), maxFiles)):
55  inputFiles.append(files[i])
56  else:
57  inputFiles += files
58 
59 if len(inputFiles) == 0:
60  B2ERROR('No sroot files found in ' + data_dir + ' for exp=' + str(experiment) +
61  ' runFirst=' + str(run_first) + ' runLast=' + str(run_last))
62  sys.exit()
63 
64 # Output folder name
65 run_range = 'r' + '{:0=5d}'.format(run_first) + '-' + '{:0=5d}'.format(run_last)
66 output_dir = f"{main_output_dir}/BS13d-local-{expNo}-{run_range}"
67 
68 # Define calibration
69 cal = BS13d_calibration_local(inputFiles, look_back, globalTags, localDBs)
70 cal.backend_args = {"queue": "s"}
71 
72 # Add calibration to CAF
73 cal_fw = CAF()
74 cal_fw.add_calibration(cal)
75 cal_fw.output_dir = output_dir
76 cal_fw.backend = backends.LSF()
77 
78 # Run calibration
79 cal_fw.run()