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