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