Belle II Software  release-08-01-10
run_BS13d_calibration_bhabha.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration script: BS13d carrier shifts
14 # data type: cdst hlt_bhabha
15 #
16 # usage: basf2 run_BS13d_calibration_bhabha.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_cdst
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 = '/group/belle2/dataprod/Data/OfficialReco/proc10/'
31 skim_dir = 'skim/hlt_bhabha/cdst/sub00'
32 main_output_dir = 'top_calibration'
33 maxFiles = 10 # maximum number of input files per run (0 or negative means all)
34 time_offset = 0 # [ns], set to -66.8 for proc9 or older (processed w/ release-3)
35 new_cdst_format = False # set to True for input in new cdst format
36 #
37 # ---------------------------------------------------------------------------------------
38 
39 # Argument parsing
40 argvs = sys.argv
41 if len(argvs) < 4:
42  print("usage: basf2", argvs[0], "experiment runFirst runLast")
43  sys.exit()
44 experiment = int(argvs[1])
45 run_first = int(argvs[2])
46 run_last = int(argvs[3])
47 
48 # Make list of files
49 inputFiles = []
50 expNo = 'e' + '{:0=4d}'.format(experiment)
51 for run in range(run_first, run_last + 1):
52  runNo = 'r' + '{:0=5d}'.format(run)
53  filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
54  files = glob.glob(filename)
55  if maxFiles > 0:
56  for i in range(min(len(files), maxFiles)):
57  inputFiles.append(files[i])
58  else:
59  inputFiles += files
60 
61 if len(inputFiles) == 0:
62  B2ERROR('No cdst files found in ' + data_dir + ' for exp=' + str(experiment) +
63  ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
64  ' (skim_dir=' + skim_dir + ')')
65  sys.exit()
66 
67 # Output folder name
68 run_range = 'r' + '{:0=5d}'.format(run_first) + '-' + '{:0=5d}'.format(run_last)
69 output_dir = f"{main_output_dir}/BS13d-bhabha-{expNo}-{run_range}"
70 
71 # Define calibration
72 cal = BS13d_calibration_cdst(inputFiles, time_offset, globalTags, localDBs, new_cdst_format)
73 cal.backend_args = {"queue": "s"}
74 
75 # Add calibration to CAF
76 cal_fw = CAF()
77 cal_fw.add_calibration(cal)
78 cal_fw.output_dir = output_dir
79 cal_fw.backend = backends.LSF()
80 
81 # Run calibration
82 cal_fw.run()