Belle II Software development
run_photonYields_calibration.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------
12# CAF calibration script: photon yields
13# data type: cdst (bhabha or dimuon)
14#
15# usage: basf2 run_photonYields_calibration.py expNo runFirst runLast [sample]
16# sample = bhabha/dimuon (D = dimuon)
17# ---------------------------------------------------------------------------------------
18
19import sys
20import glob
21from caf import backends
22from caf.framework import CAF
23from basf2 import B2ERROR
24from top_calibration import photonYields_calibration
25from caf.strategies import SingleIOV
26
27# ----- those parameters need to be adjusted before running -----------------------------
28#
29globalTags = ['patch_main_release-08', 'patch_main_release-07_noTOP',
30 'data_reprocessing_proc13', 'online'] # highest priority first
31localDBs = [] # highest priority first, local DB's have higher priority than global tags
32data_dir = '/gpfs/group/belle2/dataprod/Data/PromptReco/bucket16_calib/'
33bhabha_skim_dir = 'skim/bhabha_all_calib/cdst/sub00'
34dimuon_skim_dir = 'skim/mumutight_calib/cdst/sub00/'
35main_output_dir = 'top_calibration'
36default_sample = 'dimuon'
37#
38# ---------------------------------------------------------------------------------------
39
40# Argument parsing
41argvs = sys.argv
42if len(argvs) < 4:
43 print("usage: basf2", argvs[0], "experiment runFirst runLast [sample]")
44 print(" sample = bhabha/dimuon (D = dimuon)")
45 sys.exit()
46experiment = int(argvs[1])
47run_first = int(argvs[2])
48run_last = int(argvs[3])
49sample = default_sample
50
51if len(argvs) > 4:
52 sample = argvs[4]
53
54if sample == 'bhabha':
55 skim_dir = bhabha_skim_dir
56elif sample == 'dimuon':
57 skim_dir = dimuon_skim_dir
58else:
59 B2ERROR("Invalid sample name: " + sample)
60 sys.exit()
61
62# Make list of files
63inputFiles = []
64expNo = 'e' + f'{experiment:04d}'
65for run in range(run_first, run_last + 1):
66 runNo = 'r' + f'{run:05d}'
67 filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
68 inputFiles += glob.glob(filename)
69
70if 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
77run_range = 'r' + f'{run_first:05d}' + '-' + f'{run_last:05d}'
78output_dir = f"{main_output_dir}/photonYields-{sample}-{expNo}-{run_range}"
79
80# Define calibration
81cal = photonYields_calibration(inputFiles, sample, globalTags, localDBs)
82cal.strategies = SingleIOV
83cal.backend_args = {"queue": "s"}
84
85# Add calibration to CAF
86cal_fw = CAF()
87cal_fw.add_calibration(cal)
88cal_fw.output_dir = output_dir
89cal_fw.backend = backends.LSF()
90
91# Run calibration
92cal_fw.run()