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