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
44 A caf.framework.Calibration obj.
47 if global_tags
is None:
53 if not isinstance(run_type, str)
or run_type.lower()
not in run_types:
54 raise ValueError(
"run_type not found in run_types : {}".format(run_type))
55 activate_masking = kwargs.get(
"activate_masking",
False)
56 if not isinstance(activate_masking, bool):
57 raise ValueError(
"activate_masking is not a boolean!")
61 gearbox = register_module(
'Gearbox')
62 geometry = register_module(
'Geometry')
63 geometry.param(
'components', [
'PXD'])
64 pxdunpacker = register_module(
'PXDUnpacker')
65 pxdunpacker.param(
'SuppressErrorMask', 0xFFFFFFFFFFFFFFFF)
66 checker = register_module(
'PXDPostErrorChecker')
67 checker.param(
"CriticalErrorMask", 0)
70 main.add_module(gearbox)
71 main.add_module(geometry)
72 main.add_module(pxdunpacker)
73 main.add_module(checker)
75 main.add_module(
"ActivatePXDPixelMasker")
76 main.add_module(
"PXDRawHitSorter")
79 collector_name =
"PXDRawHotPixelMaskCollector"
81 collector_name =
"PXDHotPixelMaskCollector"
82 collector = register_module(collector_name)
83 collector.param(
"granularity",
"run")
87 algorithm = PXDHotPixelMaskCalibrationAlgorithm()
88 algorithm.forceContinueMasking =
False
89 algorithm.minEvents = 30000
90 algorithm.minHits = 15
91 algorithm.pixelMultiplier = 7
92 algorithm.maskDrains =
True
93 algorithm.drainMultiplier = 7
94 algorithm.maskRows =
True
95 algorithm.rowMultiplier = 7
96 algorithm.setPrefix(collector_name)
97 if run_type.lower() ==
'cosmic':
98 algorithm.forceContinueMasking =
True
105 algorithms=[algorithm],
106 input_files=input_files)
107 for global_tag
in global_tags:
108 cal.use_central_database(global_tag)
109 for local_db
in local_dbs:
110 cal.use_local_database(local_db)
111 cal.pre_collector_path = main
112 cal.strategies = SequentialRunByRun
116 if run_type.lower() ==
'cosmic':
117 cal.strategies = SimpleRunByRun
122 def gain_calibration(input_files, cal_name="PXDGainCalibration",
123 boundaries=None, global_tags=None, local_dbs=None,
124 gain_method="Analytic", validation=True, **kwargs):
127 input_files (list): A list of input files to be assigned to calibration.input_files
129 boundaries (c++ std::vector): boundaries for iov creation
131 global_tags (list): A list of global tags
133 local_dbs (list): A list of local databases
135 gain_method (str): A string of gain algorithm in
136 ['analytic', 'generic_mc', 'cluster_sim', '']. Empty str means to skip gain
137 calibration and validation has to be True otherwise no algorithm will be used.
138 Caveat: Only the analytic method is now implemented.
140 validation (bool): Adding validation algorithm if True (default)
142 **kwargs: Additional configuration to support extentions without changing scripts in calibration folder.
145 A caf.framework.Calibration obj.
148 if global_tags
is None:
150 if local_dbs
is None:
152 if gain_method
is None:
153 gain_method =
'analytic'
154 if not isinstance(gain_method, str)
or gain_method.lower()
not in gain_methods:
155 raise ValueError(
"gain_method not found in gain_methods : {}".format(gain_method))
159 gearbox = register_module(
'Gearbox')
160 geometry = register_module(
'Geometry', useDB=
True)
165 genFitExtrapolation = register_module(
'SetupGenfitExtrapolation')
166 roiFinder = register_module(
'PXDROIFinder')
171 main.add_module(gearbox)
172 main.add_module(geometry)
176 main.add_module(genFitExtrapolation)
177 main.add_module(roiFinder)
178 main.add_module(
"PXDPerformance")
182 collector = register_module(
"PXDPerformanceCollector")
183 collector.param(
"granularity",
"run")
184 collector.param(
"minClusterCharge", 8)
185 collector.param(
"minClusterSize", 1)
186 collector.param(
"maxClusterSize", 10)
187 collector.param(
"nBinsU", 4)
188 collector.param(
"nBinsV", 6)
189 collector.param(
"fillEventTree",
False)
190 collector.param(
"fillChargeRatioHistogram",
True)
195 validation_alg = PXDValidationAlgorithm()
196 validation_alg.setPrefix(
"PXDPerformanceCollector")
197 validation_alg.minTrackPoints = 10
198 validation_alg.save2DHists =
True
199 algorithms.append(validation_alg)
202 if (gain_method !=
''):
203 algorithm = PXDAnalyticGainCalibrationAlgorithm()
204 algorithm.minClusters = 200
205 algorithm.safetyFactor = 11
206 algorithm.forceContinue =
False
207 algorithm.strategy = 0
208 algorithm.correctForward =
True
209 algorithm.useChargeRatioHistogram =
True
210 algorithm.setPrefix(
"PXDPerformanceCollector")
212 algorithms.append(algorithm)
219 algorithms=algorithms,
220 input_files=input_files)
221 for global_tag
in global_tags:
222 cal.use_central_database(global_tag)
223 for local_db
in local_dbs:
224 cal.use_local_database(local_db)
225 cal.pre_collector_path = main
227 cal.strategies = SequentialRunByRun