Belle II Software  release-08-01-10
run_validation.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration script: calibration validation
14 # data type: cdst (dimuon or bhabha)
15 #
16 # usage: basf2 run_validation.py expNo runFirst runLast [sample]
17 # sample = bhabha/dimuon (D = dimuon)
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 calibration_validation
26 
27 # ----- those parameters need to be adjusted before running -----------------------------
28 #
29 globalTags = ['data_reprocessing_prompt', 'dp_recon_release6_patch', 'online'] # highest priority first
30 localDBs = [] # highest priority first, local DB's have higher priority than global tags
31 data_dir = '/gpfs/group/belle2/dataprod/Data/PromptReco/bucket16_calib/'
32 bhabha_skim_dir = 'skim/bhabha_all_calib/cdst/sub00/'
33 dimuon_skim_dir = 'skim/mumutight_calib/cdst/sub00'
34 main_output_dir = 'top_calibration'
35 default_sample = 'dimuon'
36 new_cdst_format = True # 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 = dimuon)")
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) >= 5:
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}/validation-{sample}-{expNo}-{run_range}"
79 
80 # Define calibration
81 cal = calibration_validation(inputFiles, sample, globalTags, localDBs, new_cdst_format)
82 cal.backend_args = {"queue": "s"}
83 
84 # Add calibration to CAF
85 cal_fw = CAF()
86 cal_fw.add_calibration(cal)
87 cal_fw.output_dir = output_dir
88 cal_fw.backend = backends.LSF()
89 
90 # Run calibration
91 cal_fw.run()