Belle II Software development
run_alignment.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------
12# CAF calibration script: module alignment
13# data type: cdst (dimuon or bhabha)
14#
15# usage: basf2 run_alignment.py expNo runFirst runLast [sample]
16# sample = dimuon/bhabha (D = dimuon)
17#
18# Note: input data or databases must be well calibrated (including moduleT0 and commonT0)
19# ---------------------------------------------------------------------------------------
20
21import sys
22import glob
23from caf import backends
24from caf.framework import CAF
25from basf2 import B2ERROR
26from top_calibration import module_alignment
27
28# ----- those parameters need to be adjusted before running -----------------------------
29#
30globalTags = ['Reco_master_patch', 'data_reprocessing_proc10'] # highest priority first
31localDBs = [] # highest priority first, local DB's have higher priority than global tags
32data_dir = '/group/belle2/dataprod/Data/OfficialReco/proc10/'
33dimuon_skim_dir = 'offskim/offskim_mumutop/cdst/sub00'
34bhabha_skim_dir = 'skim/hlt_bhabha/cdst/sub00'
35main_output_dir = 'top_calibration'
36default_sample = 'dimuon'
37fixedParameters = None # list of parameters to be fixed, for the names see: basf2 -m TOPAlignmentCollector
38new_cdst_format = False # set to True for input in new cdst format
39#
40# ---------------------------------------------------------------------------------------
41
42# Argument parsing
43argvs = sys.argv
44if len(argvs) < 4:
45 print("usage: basf2", argvs[0], "experiment runFirst runLast [sample]")
46 print(" sample = dimuon/bhabha (D = dimuon)")
47 sys.exit()
48experiment = int(argvs[1])
49run_first = int(argvs[2])
50run_last = int(argvs[3])
51sample = default_sample
52
53if len(argvs) > 4:
54 sample = argvs[4]
55
56if sample == 'dimuon':
57 skim_dir = dimuon_skim_dir
58elif sample == 'bhabha':
59 skim_dir = bhabha_skim_dir
60else:
61 B2ERROR("Invalid sample name: " + sample)
62 sys.exit()
63
64# Make list of files
65inputFiles = []
66expNo = 'e' + f'{experiment:04d}'
67for run in range(run_first, run_last + 1):
68 runNo = 'r' + f'{run:05d}'
69 filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/cdst*.root"
70 inputFiles += glob.glob(filename)
71
72if len(inputFiles) == 0:
73 B2ERROR('No cdst files found in ' + data_dir + ' for exp=' + str(experiment) +
74 ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
75 ' (skim_dir=' + skim_dir + ')')
76 sys.exit()
77
78# Output folder
79run_range = 'r' + f'{run_first:05d}' + '-' + f'{run_last:05d}'
80output_dir = f"{main_output_dir}/alignment-{sample}-{expNo}-{run_range}"
81
82# Define calibration
83backend_args = {"queue": "l"}
84cal = module_alignment(inputFiles, sample, fixedParameters,
85 globalTags, localDBs, new_cdst_format, backend_args)
86
87# Add calibrations to CAF
88cal_fw = CAF()
89cal_fw.add_calibration(cal)
90cal_fw.output_dir = output_dir
91cal_fw.backend = backends.LSF()
92
93# Run calibration
94cal_fw.run()