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