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