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