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