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