Belle II Software  release-05-01-25
run_commonT0_calibration.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # ---------------------------------------------------------------------------------------
5 # CAF calibration script: common T0
6 # data type: cdst (bhabha or dimuon)
7 #
8 # usage: basf2 run_commonT0_calibration.py expNo runFirst runLast [sample method]
9 # sample = bhabha/dimuon (D = bhabha)
10 # method = BF/LL (D = BF)
11 #
12 # author: M. Staric
13 # ---------------------------------------------------------------------------------------
14 
15 import sys
16 import os
17 import glob
18 from caf import backends
19 from caf.framework import CAF
20 from basf2 import B2ERROR
21 from top_calibration import commonT0_calibration_BF, commonT0_calibration_LL
22 
23 # ----- those parameters need to be adjusted before running -----------------------------
24 #
25 globalTags = ['Reco_master_patch', 'data_reprocessing_proc10'] # highest priority first
26 localDBs = [] # highest priority first, local DB's have higher priority than global tags
27 data_dir = '/group/belle2/dataprod/Data/OfficialReco/proc10/'
28 bhabha_skim_dir = 'skim/hlt_bhabha/cdst/sub00'
29 dimuon_skim_dir = 'offskim/offskim_mumutop/cdst/sub00'
30 main_output_dir = 'top_calibration'
31 default_sample = 'bhabha'
32 default_method = 'BF'
33 new_cdst_format = False # set to True for input in new cdst format
34 #
35 # ---------------------------------------------------------------------------------------
36 
37 # Argument parsing
38 argvs = sys.argv
39 if len(argvs) < 4:
40  print("usage: basf2", argvs[0], "experiment runFirst runLast [sample method]")
41  print(" sample = bhabha/dimuon (D = bhabha)")
42  print(" method = BF/LL (D = BF)")
43  sys.exit()
44 experiment = int(argvs[1])
45 run_first = int(argvs[2])
46 run_last = int(argvs[3])
47 sample = default_sample
48 method = default_method
49 
50 if len(argvs) == 5:
51  sample = argvs[4]
52 elif len(argvs) > 5:
53  sample = argvs[4]
54  method = argvs[5]
55 
56 if sample == 'bhabha':
57  skim_dir = bhabha_skim_dir
58 elif sample == 'dimuon':
59  skim_dir = dimuon_skim_dir
60 else:
61  B2ERROR("Invalid sample name: " + sample)
62  sys.exit()
63 
64 # Make list of files
65 inputFiles = []
66 expNo = 'e' + '{:0=4d}'.format(experiment)
67 for run in range(run_first, run_last + 1):
68  runNo = 'r' + '{:0=5d}'.format(run)
69  filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
70  inputFiles += glob.glob(filename)
71 
72 if len(inputFiles) == 0:
73  B2ERROR('No cdst files found in ' + data_dir + ' for exp=' + str(experiment) +
74  ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
75  ' (skim_dir=' + skim_dir + ')')
76  sys.exit()
77 
78 # Output folder name
79 run_range = 'r' + '{:0=5d}'.format(run_first) + '-' + '{:0=5d}'.format(run_last)
80 output_dir = f"{main_output_dir}/commonT0-{sample}-{method}-{expNo}-{run_range}"
81 
82 # Define calibration
83 if method == 'BF':
84  cal = commonT0_calibration_BF(inputFiles, globalTags, localDBs, new_cdst_format)
85 elif method == 'LL':
86  cal = commonT0_calibration_LL(inputFiles, sample, globalTags, localDBs, new_cdst_format)
87 else:
88  B2ERROR('Invalid method name: ' + method)
89  sys.exit()
90 cal.backend_args = {"queue": "s"}
91 
92 # Add calibration to CAF
93 cal_fw = CAF()
94 cal_fw.add_calibration(cal)
95 cal_fw.output_dir = output_dir
96 cal_fw.backend = backends.LSF()
97 
98 # Run calibration
99 cal_fw.run()
backends.LSF
Definition: backends.py:1567