Belle II Software  release-05-01-25
SVDOccupancyAndHotStripsCalibrationsCAF.py
1 
8 
9 from basf2 import *
10 
11 set_log_level(LogLevel.INFO)
12 
13 import os
14 import sys
15 import multiprocessing
16 import datetime
17 import glob
18 
19 import ROOT
20 from ROOT import Belle2, TFile
21 from ROOT.Belle2 import SVDOccupancyCalibrationsAlgorithm
22 from ROOT.Belle2 import SVDHotStripsCalibrationsAlgorithm
23 
24 from caf.framework import Calibration, CAF, Collection, LocalDatabase, CentralDatabase
25 from caf import backends
26 from caf import strategies
27 
28 import rawdata as raw
29 import reconstruction as reco
30 import modularAnalysis as ana
31 # import vertex as vx
32 
33 now = datetime.datetime.now()
34 uniqueID_occup = ''
35 uniqueID_hotStrips = ''
36 
37 input_branches = [
38  'RawSVDs'
39 ]
40 
41 set_log_level(LogLevel.INFO)
42 
43 
44 def SVDOccupancyAndHotStripsCalibrations(files, tags):
45 
46  # Set-up re-processing path
47  path = create_path()
48 
49  # logging.log_level = LogLevel.WARNING
50 
51  path.add_module('Progress')
52  # Remove all non-raw data to run the full reco again
53  path.add_module('RootInput', branchNames=input_branches)
54 
55  path.add_module("Gearbox")
56  path.add_module("Geometry", useDB=True)
57  raw.add_unpackers(path, components=['SVD'])
58  path.add_module(
59  'SVDZeroSuppressionEmulator',
60  SNthreshold=5,
61  ShaperDigits='SVDShaperDigits',
62  ShaperDigitsIN='SVDShaperDigitsZS5',
63  FADCmode=True)
64 
65  collector = register_module('SVDOccupancyCalibrationsCollector')
66  collector.param("SVDShaperDigitsName", "SVDShaperDigitsZS5")
67  algorithm1 = SVDOccupancyCalibrationsAlgorithm(uniqueID_occup)
68  algorithm2 = SVDHotStripsCalibrationsAlgorithm(uniqueID_hotStrips)
69 # algorithm1 = SVDOccupancyCalibrationsAlgorithm("SVDOccupancyCAF")
70 # algorithm2 = SVDHotStripsCalibrationsAlgorithm("SVDHotStripsCAF")
71 
72  calibration = Calibration('SVDOccupancyAndHotStrips',
73  collector=collector,
74  algorithms=[algorithm1, algorithm2],
75  input_files=files,
76  pre_collector_path=path,
77  database_chain=[CentralDatabase(tag) for tag in tags],
78  output_patterns=None,
79  max_files_per_collector_job=1,
80  backend_args=None
81  )
82 
83  calibration.strategies = strategies.SequentialRunByRun
84 
85  return calibration
86 
87 
88 if __name__ == "__main__":
89  # use by default raw data from cdst of exp12, run 2324 (shaperDigits need to be unpacked, not available in cdst format)
90  # input_files = ["/group/belle2/dataprod/Data/Raw/e0012/r02324/sub00/*"]
91  # comment it out to not hardcode the input path:
92 
93  input_files = [os.path.abspath(file) for file in Belle2.Environment.Instance()
94  .getInputFilesOverride()]
95  print(" ")
96  print("INPUT FILES")
97  print(" ")
98  print(input_files)
99  print(" ")
100 
101  good_input_files = []
102  runs = []
103  expNum = int()
104  for i in input_files:
105  file_list = glob.glob(i)
106  for f in file_list:
107  tf = TFile.Open(f)
108  tree = tf.Get("tree")
109  if tree.GetEntries() != 0:
110  good_input_files.append(f)
111  print(str(f))
112  inputStringSplit = f.split("/")
113  s_run = str(inputStringSplit[7])
114  s_exp = str(inputStringSplit[6])
115  print(str(s_run) + " " + str(s_exp))
116  runNum = runs.append(int(s_run[1:6]))
117  runNum = int(s_run[1:6])
118  expNum = int(s_exp[1:5])
119  runs.sort()
120 
121  firstRun = runs[0]
122  lastRun = runs[-1]
123 
124  if not len(input_files):
125  print("You have to specify some input file(s)\n"
126  "using the standard basf2 command line option - i")
127  print("See: basf2 -h")
128  sys.exit(1)
129 
130  uniqueID_occup = "SVDOccupancyCalibrations_" + \
131  str(now.isoformat()) + "_INFO:_ZS5_Exp" + str(expNum) + "_runsFrom" + \
132  str(firstRun) + "to" + str(lastRun)
133 
134  print("UniqueID for SVDccupancyCalibrations")
135  print("")
136  print(str(uniqueID_occup))
137  print("")
138 
139  uniqueID_hotStrips = "SVDHotStripsCalibrations_" + \
140  str(now.isoformat()) + "_INFO:_ZS5_base=-1_relOccPrec=5_absOccThr=0.2_Exp"\
141  + str(expNum) + "_runsFrom" + str(firstRun) + "to" + str(lastRun)
142  print("UniqueID for SVDHotStripsCalibrations")
143  print("")
144  print(str(uniqueID_hotStrips))
145  print("")
146 
147  svdOccupAndHotStripsCAF = SVDOccupancyAndHotStripsCalibrations(input_files,
148  ['data_reprocessing_prompt', 'svd_basic', 'svd_loadedOnFADC'])
149 
150  cal_fw = CAF()
151  cal_fw.add_calibration(svdOccupAndHotStripsCAF)
152 
153  cal_fw.backend = backends.LSF()
154 
155 # Try to guess if we are at KEKCC and change the backend to Local if not
156  if multiprocessing.cpu_count() < 10:
157  cal_fw.backend = backends.Local(8)
158 
159  cal_fw.run()
strategies.SequentialRunByRun
Definition: strategies.py:251
backends.LSF
Definition: backends.py:1567
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
Calibration
Definition: Calibration.py:1
backends.Local
Definition: backends.py:878