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