5 PXD calibration APIs for CAF
6 Author: qingyuan.liu@desy.de
9 from basf2
import register_module, create_path
10 from ROOT.Belle2
import PXDHotPixelMaskCalibrationAlgorithm, PXDAnalyticGainCalibrationAlgorithm
11 from ROOT.Belle2
import PXDValidationAlgorithm
12 from caf.framework
import Calibration
13 from caf.strategies
import SequentialRunByRun, SimpleRunByRun, SequentialBoundaries
15 run_types = [
'beam',
'physics',
'cosmic',
'all']
16 gain_methods = [
'analytic',
'generic_mc',
'cluster_sim',
'']
19 def hot_pixel_mask_calibration(
21 cal_name="PXDHotPixelMaskCalibration",
28 input_files (list): A list of input files to be assigned to calibration.input_files
30 run_type ( str): The run type which will define different calibration parameters.
31 Should be in ['beam', 'physics', 'cosmic', 'all']
33 global_tags (list): A list of global tags
35 local_dbs (list): A list of local databases
37 **kwargs: Additional configuration to support extentions without changing scripts in calibration folder.
38 Supported options are listed below:
40 "activate_masking" is a boolean to activate existing masking in the payload.
41 PXDHotPixelMaskCollector will be used then instead of PXDRawHotPixelMaskCollector
43 "debug_hist" is the flag to save a ROOT file for debug histograms.
46 A caf.framework.Calibration obj.
49 if global_tags
is None:
55 if not isinstance(run_type, str)
or run_type.lower()
not in run_types:
56 raise ValueError(
"run_type not found in run_types : {}".format(run_type))
57 activate_masking = kwargs.get(
"activate_masking",
False)
58 if not isinstance(activate_masking, bool):
59 raise ValueError(
"activate_masking is not a boolean!")
60 debug_hist = kwargs.get(
"debug_hist",
True)
61 if not isinstance(debug_hist, bool):
62 raise ValueError(
"debug_hist is not a boolean!")
66 gearbox = register_module(
'Gearbox')
67 geometry = register_module(
'Geometry')
68 geometry.param(
'components', [
'PXD'])
69 pxdunpacker = register_module(
'PXDUnpacker')
70 pxdunpacker.param(
'SuppressErrorMask', 0xFFFFFFFFFFFFFFFF)
71 checker = register_module(
'PXDPostErrorChecker')
72 checker.param(
"CriticalErrorMask", 0)
75 main.add_module(gearbox)
76 main.add_module(geometry)
77 main.add_module(pxdunpacker)
78 main.add_module(checker)
80 main.add_module(
"ActivatePXDPixelMasker")
81 main.add_module(
"PXDRawHitSorter")
84 collector_name =
"PXDRawHotPixelMaskCollector"
86 collector_name =
"PXDHotPixelMaskCollector"
87 collector = register_module(collector_name)
88 collector.param(
"granularity",
"run")
92 algorithm = PXDHotPixelMaskCalibrationAlgorithm()
93 algorithm.forceContinueMasking =
False
94 algorithm.minEvents = 30000
95 algorithm.minHits = 15
96 algorithm.pixelMultiplier = 7
97 algorithm.maskDrains =
True
98 algorithm.drainMultiplier = 7
99 algorithm.maskRows =
True
100 algorithm.rowMultiplier = 7
101 algorithm.setDebugHisto(debug_hist)
102 algorithm.setPrefix(collector_name)
103 if run_type.lower() ==
'cosmic':
104 algorithm.forceContinueMasking =
True
111 algorithms=[algorithm],
112 input_files=input_files)
113 for global_tag
in global_tags:
114 cal.use_central_database(global_tag)
115 for local_db
in local_dbs:
116 cal.use_local_database(local_db)
117 cal.pre_collector_path = main
118 cal.strategies = SequentialRunByRun
122 if run_type.lower() ==
'cosmic':
123 cal.strategies = SimpleRunByRun
128 def gain_calibration(input_files, cal_name="PXDGainCalibration",
129 boundaries=None, global_tags=None, local_dbs=None,
130 gain_method="Analytic", validation=True, **kwargs):
133 input_files (list): A list of input files to be assigned to calibration.input_files
135 boundaries (c++ std::vector): boundaries for iov creation
137 global_tags (list): A list of global tags
139 local_dbs (list): A list of local databases
141 gain_method (str): A string of gain algorithm in
142 ['analytic', 'generic_mc', 'cluster_sim', '']. Empty str means to skip gain
143 calibration and validation has to be True otherwise no algorithm will be used.
144 Caveat: Only the analytic method is now implemented.
146 validation (bool): Adding validation algorithm if True (default)
148 **kwargs: Additional configuration to support extentions without changing scripts in calibration folder.
151 A caf.framework.Calibration obj.
154 if global_tags
is None:
156 if local_dbs
is None:
158 if gain_method
is None:
159 gain_method =
'analytic'
160 if not isinstance(gain_method, str)
or gain_method.lower()
not in gain_methods:
161 raise ValueError(
"gain_method not found in gain_methods : {}".format(gain_method))
165 gearbox = register_module(
'Gearbox')
166 geometry = register_module(
'Geometry', useDB=
True)
171 genFitExtrapolation = register_module(
'SetupGenfitExtrapolation')
172 roiFinder = register_module(
'PXDROIFinder')
177 main.add_module(gearbox)
178 main.add_module(geometry)
182 main.add_module(genFitExtrapolation)
183 main.add_module(roiFinder)
184 main.add_module(
"PXDPerformance")
188 collector = register_module(
"PXDPerformanceCollector")
189 collector.param(
"granularity",
"run")
190 collector.param(
"minClusterCharge", 8)
191 collector.param(
"minClusterSize", 1)
192 collector.param(
"maxClusterSize", 10)
193 collector.param(
"nBinsU", 4)
194 collector.param(
"nBinsV", 6)
195 collector.param(
"fillEventTree",
False)
196 collector.param(
"fillChargeRatioHistogram",
True)
201 validation_alg = PXDValidationAlgorithm()
202 validation_alg.setPrefix(
"PXDPerformanceCollector")
203 validation_alg.minTrackPoints = 10
204 validation_alg.save2DHists =
True
205 algorithms.append(validation_alg)
208 if (gain_method !=
''):
209 algorithm = PXDAnalyticGainCalibrationAlgorithm()
210 algorithm.minClusters = 200
211 algorithm.safetyFactor = 11
212 algorithm.forceContinue =
False
213 algorithm.strategy = 0
214 algorithm.correctForward =
True
215 algorithm.useChargeRatioHistogram =
True
216 algorithm.setPrefix(
"PXDPerformanceCollector")
218 algorithms.append(algorithm)
225 algorithms=algorithms,
226 input_files=input_files)
227 for global_tag
in global_tags:
228 cal.use_central_database(global_tag)
229 for local_db
in local_dbs:
230 cal.use_local_database(local_db)
231 cal.pre_collector_path = main
233 cal.strategies = SequentialRunByRun