Belle II Software  release-08-01-10
run_pulseHeight_calibration_laser.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration script: pulse height distributions and threshold efficiencies
14 # data type: local runs with laser
15 #
16 # usage: basf2 run_pulseHeight_calibration_laser.py expNo run_1 run_2 ... run_n
17 # ---------------------------------------------------------------------------------------
18 
19 import sys
20 import glob
21 from caf import backends
22 from caf.framework import CAF
23 from basf2 import B2ERROR
24 from top_calibration import pulseHeight_calibration_laser
25 
26 # ----- those parameters need to be adjusted before running -----------------------
27 #
28 globalTags = ['Reco_master_patch', 'data_reprocessing_proc10'] # highest priority first
29 localDBs = [] # highest priority first, local DB's have higher priority than global tags
30 data_dir = '/ghi/fs01/belle2/bdata/group/detector/TOP/2019-*/data_sroot_global/'
31 main_output_dir = 'top_calibration'
32 look_back = 28 # look-back window setting (set to 0 if look-back setting available in DB)
33 t_min = -50.0 # lower edge of time window to select laser signal [ns]
34 t_max = 0.0 # upper edge of time window to select laser signal [ns]
35 #
36 # ---------------------------------------------------------------------------------------
37 
38 # Argument parsing
39 argvs = sys.argv
40 if len(argvs) < 3:
41  print("usage: basf2", argvs[0], "experiment run_1 run_2 ... run_n")
42  sys.exit()
43 experiment = int(argvs[1])
44 run_numbers = sorted([int(r) for r in argvs[2:]])
45 run_first = run_numbers[0]
46 run_last = run_numbers[-1]
47 
48 # Make list of files
49 inputFiles = []
50 expNo = 'e' + '{:0=4d}'.format(experiment)
51 for run in run_numbers:
52  expRun = '{:0=4d}'.format(experiment) + '.' + '{:0=5d}'.format(run)
53  filename = f"{data_dir}/top.{expRun}.*.sroot"
54  inputFiles += glob.glob(filename)
55 
56 if len(inputFiles) == 0:
57  runs = "".join([str(r) + "," for r in run_numbers])[:-1]
58  B2ERROR(f'No sroot files found in {data_dir} for exp={str(experiment)} runs={runs}')
59  sys.exit()
60 
61 # Output folder name
62 run_range = 'r' + '{:0=5d}'.format(run_first) + '-' + '{:0=5d}'.format(run_last)
63 output_dir = f"{main_output_dir}/pulseHeight-laser-{expNo}-{run_range}"
64 
65 # Define calibration
66 cal = pulseHeight_calibration_laser(inputFiles, t_min, t_max, look_back,
67  globalTags, localDBs)
68 cal.backend_args = {"queue": "s"}
69 
70 # Add calibration to CAF
71 cal_fw = CAF()
72 cal_fw.add_calibration(cal)
73 cal_fw.output_dir = output_dir
74 cal_fw.backend = backends.LSF()
75 
76 # Run calibration
77 cal_fw.run()