Belle II Software  release-08-01-10
run_moduleT0_calibration.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration script: module T0
14 # data type: cdst (bhabha or dimuon)
15 #
16 # usage: basf2 run_moduleT0_calibration.py expNo runFirst runLast [sample]
17 # sample = bhabha/dimuon (D = bhabha)
18 # ---------------------------------------------------------------------------------------
19 
20 import sys
21 import glob
22 from caf import backends
23 from caf.framework import CAF
24 from basf2 import B2ERROR
25 from top_calibration import moduleT0_calibration_DeltaT, moduleT0_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 new_cdst_format = False # set to True for input in new cdst format
37 #
38 # ---------------------------------------------------------------------------------------
39 
40 # Argument parsing
41 argvs = sys.argv
42 if len(argvs) < 4:
43  print("usage: basf2", argvs[0], "experiment runFirst runLast [sample]")
44  print(" sample = bhabha/dimuon (D = bhabha)")
45  sys.exit()
46 experiment = int(argvs[1])
47 run_first = int(argvs[2])
48 run_last = int(argvs[3])
49 sample = default_sample
50 
51 if len(argvs) > 4:
52  sample = argvs[4]
53 
54 if sample == 'bhabha':
55  skim_dir = bhabha_skim_dir
56 elif sample == 'dimuon':
57  skim_dir = dimuon_skim_dir
58 else:
59  B2ERROR("Invalid sample name: " + sample)
60  sys.exit()
61 
62 # Make list of files
63 inputFiles = []
64 expNo = 'e' + '{:0=4d}'.format(experiment)
65 for run in range(run_first, run_last + 1):
66  runNo = 'r' + '{:0=5d}'.format(run)
67  filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
68  inputFiles += glob.glob(filename)
69 
70 if len(inputFiles) == 0:
71  B2ERROR('No cdst files found in ' + data_dir + ' for exp=' + str(experiment) +
72  ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
73  ' (skim_dir=' + skim_dir + ')')
74  sys.exit()
75 
76 # Output folder name
77 run_range = 'r' + '{:0=5d}'.format(run_first) + '-' + '{:0=5d}'.format(run_last)
78 output_dir = f"{main_output_dir}/moduleT0-{sample}-{expNo}-{run_range}"
79 
80 # Define calibrations
81 cal1 = moduleT0_calibration_DeltaT(inputFiles, globalTags, localDBs, new_cdst_format)
82 cal2 = moduleT0_calibration_LL(inputFiles, sample, globalTags, localDBs, new_cdst_format)
83 cal1.backend_args = {"queue": "s"}
84 cal2.backend_args = {"queue": "s"}
85 cal2.depends_on(cal1)
86 
87 # Add calibrations to CAF
88 cal_fw = CAF()
89 cal_fw.add_calibration(cal1)
90 cal_fw.add_calibration(cal2)
91 cal_fw.output_dir = output_dir
92 cal_fw.backend = backends.LSF()
93 
94 # Run calibration
95 cal_fw.run()