Belle II Software  release-08-01-10
run_moduleT0_with_cosmics.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # CAF calibration script: module T0 with cosmics
14 # data type: raw or cdst
15 #
16 # usage: basf2 run_moduleT0_with_cosmics.py expNo runFirst runLast
17 # ---------------------------------------------------------------------------------------
18 
19 import sys
20 import glob
21 from caf import backends
22 from caf.framework import CAF
23 from basf2 import B2ERROR
24 from top_calibration import moduleT0_calibration_cosmics
25 
26 # ----- those parameters need to be adjusted before running -----------------------------
27 #
28 globalTags = ['patch_main_release-08',
29  'patch_main_release-07_noTOP',
30  'data_reprocessing_prompt',
31  'online'] # highest priority first
32 localDBs = [] # highest priority first, local DB's have higher priority than global tags
33 data_dir = '/gpfs/group/belle2/dataprod/Data/PromptSkim'
34 skim_dir = 'skim/cosmic_calib'
35 data_format = 'raw' # raw or cdst
36 full_reco = True # run full cosmic reconstruction if data_format == 'cdst' (we need separate track segments!)
37 main_output_dir = 'top_calibration'
38 #
39 # ---------------------------------------------------------------------------------------
40 
41 # Argument parsing
42 argvs = sys.argv
43 if len(argvs) < 4:
44  print("usage: basf2", argvs[0], "experiment runFirst runLast")
45  sys.exit()
46 experiment = int(argvs[1])
47 run_first = int(argvs[2])
48 run_last = int(argvs[3])
49 
50 # Make list of files
51 inputFiles = []
52 expNo = 'e' + '{:0=4d}'.format(experiment)
53 for run in range(run_first, run_last + 1):
54  runNo = 'r' + '{:0=5d}'.format(run)
55  filename = f"{data_dir}/{expNo}/*/{runNo}/{skim_dir}/{data_format}/sub00/*.root"
56  inputFiles += glob.glob(filename)
57 
58 if len(inputFiles) == 0:
59  B2ERROR('No files found in ' + data_dir + ' for exp=' + str(experiment) +
60  ' runFirst=' + str(run_first) + ' runLast=' + str(run_last) +
61  ' (skim_dir=' + skim_dir + ')')
62  sys.exit()
63 
64 # Output folder name
65 run_range = 'r' + '{:0=5d}'.format(run_first) + '-' + '{:0=5d}'.format(run_last)
66 output_dir = f"{main_output_dir}/moduleT0-cosmics-{expNo}-{run_range}"
67 
68 # Define calibrations
69 cal = moduleT0_calibration_cosmics(inputFiles, globalTags, localDBs, data_format, full_reco)
70 if data_format == 'raw' or full_reco:
71  cal.backend_args = {"queue": "l"}
72 else:
73  cal.backend_args = {"queue": "s"}
74 
75 # Add calibrations to CAF
76 cal_fw = CAF()
77 cal_fw.add_calibration(cal)
78 cal_fw.output_dir = output_dir
79 cal_fw.backend = backends.LSF()
80 
81 # Run calibration
82 cal_fw.run()