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