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