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