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