4 Emulating strip defects by dropping elements from the RDO input container
6 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
7 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory
import CompFactory
18 Return True if every two elements in a_list form a pair whose two elements are
19 in ascending order. The element pairs themselves may have an arbitrary order.
21 for i
in range(0,len(a_list),2) :
22 if a_list[i]>a_list[i+1] :
23 if a_list != ODD_INDEX
and a_list != EVEN_INDEX :
36 Convenience method to create a parameter set for module corner defects.
37 The corner defects have a circular shape and intersect the sensor edges at certain
38 points in x and y direction. The line between these two intersection points forms
39 a sagitta of the circle.
40 probability: Probability of a module to have one or more corner defects.
41 min_rx: minimum position from the corner in local x-direction of possible intersection points.
42 max_rx: maximum position from the corner in local x-direction of possible intersection points.
43 min_ry: minimum position from the corner in local y-direction of possible intersection points.
44 max_ry: maximum position from the corner in local x-direction of possible intersection points.
45 min_sagitta: minimum size of the sagitta (upper limit of circle radius)
46 max_sagitta: maximum size of the sagitta (lower limit of circle radius)
50 assert min_sagitta<max_sagitta
52 min_rx, max_rx-min_rx,
53 min_ry, max_ry-min_ry,
54 min_sagitta, max_sagitta-min_sagitta]
60 columns_or_strips=[0,2000],
61 column_or_strip_length=[0,1000000],
65 fractionsOfNDefects=[],
66 noiseProbability=None,
68 cornerDefectParam=None,
69 cornerDefectNCornerFractions=None,
72 Convenience function to create parameters for strip or pixel defects emulation conditions data
73 bec: range to select the bec identifier part (range is inclusive)
74 layer: range to select the layer/disc identifier part (range is inclusive)
75 eta_range: range to select the eta index identifier part (range is inclusive)
76 phi_range: range to select the phi index identifier part (range is inclusive)
77 columns_or_strips: match only modules with number of columns or strips in this range (range is inclusive)
78 column_or_strip_length: match the strip lengths in microns (range is inclusive)
79 side_range: to select both sides of a sensor [0,1], to select either side [0,0,1,1]
80 all_rows: to select individal modules (0), or all modules associated to the same physical sensor (1)
81 probabilities: module-defect, strip/pixel defect (for pixel additionally group defect probabilities:
82 at least one core-column defect, at least one defect circuit)
83 fractions: per group defect, fractions to have exactly 1..n group defects under the condition that there is
84 at least one such group defect. The first element are the fractions to have consecutive cell
85 defects of 1,2, ... n rows.
86 noiseProbability: None or probability of a strip (or pixel) to produce a spurious hit.
87 noiseShape: empty list or binned pdf used to compute one random number per spurious hit (time bin for strips, tot for pixel).
88 cornerDefectParam: None or parameters e.g. created with makeCornerDefectParam to create defects at module corners.
89 cornerDefectNCornerFractions: if cornerDefectParam is not None the fractions of 1 to 4 corners to have a defect if the module
92 if len(fractionsOfNDefects)+2==len(probability)
or len(fractionsOfNDefects) == 0:
96 fractionsOfNDefects = [[1.]] + fractionsOfNDefects
100 assert len(layer)%2==0
and len(layer) >= 2
and ordered_pairs(layer)
101 assert len(eta_range)%2==0
and len(eta_range) >= 2
and ordered_pairs(eta_range)
102 assert len(phi_range)%2==0
and len(phi_range) >= 2
and ordered_pairs(phi_range)
103 assert len(side_range)%2==0
and len(side_range) >= 2
and ordered_pairs(side_range)
104 assert len(columns_or_strips)%2==0
and len(columns_or_strips) >= 2
and ordered_pairs(columns_or_strips)
105 assert len(column_or_strip_length)%2==0
and len(column_or_strip_length) >= 2
and ordered_pairs(column_or_strip_length)
106 assert len(fractionsOfNDefects)==0
or len(fractionsOfNDefects)+1==len(probability)
108 assert cornerDefectParam
is not None or cornerDefectNCornerFractions
is None
109 assert cornerDefectParam
is None or cornerDefectNCornerFractions
is not None
111 length=[ l
for l
in set([len(bec),len(layer),len(eta_range),len(phi_range),len(side_range),len(columns_or_strips)]) ]
113 for i
in range(1,len(length)) :
114 for j
in range(0,i) :
115 assert max(length[i],length[j])%
min(length[i],length[j])==0
123 cornerDefectCornerFractionList=[]
124 if noiseProbability
is not None and noiseProbability>0. :
126 shape_sum =
sum(noiseShape)
127 noiseShape = [ elm/shape_sum
for elm
in noiseShape ]
129 noiseProbability=
None
132 module_pattern+=[ [bec[i%len(bec)], bec[(i+1)%len(bec)],
133 layer[i%len(layer)], layer[(i+1)%len(layer)],
134 eta_range[i%len(eta_range)], eta_range[(i+1)%len(eta_range)],
135 phi_range[i%len(phi_range)], phi_range[(i+1)%len(phi_range)],
136 columns_or_strips[i%len(columns_or_strips)], columns_or_strips[(i+1)%len(columns_or_strips)],
137 column_or_strip_length[i%len(column_or_strip_length)], column_or_strip_length[(i+1)%len(column_or_strip_length)],
138 side_range[i%len(side_range)], side_range[(i+1)%len(side_range)],
139 1
if all_rows
else 0] ]
140 prob += [ probability ]
141 fractions += [ [fraction
for per_pattern
in fractionsOfNDefects
for fraction
in per_pattern + [-1] ] ]
142 if noiseProbability
is not None:
143 noiseProbList+=[noiseProbability]
144 noiseShapeList+=[noiseShape]
145 if cornerDefectParam
is not None:
146 cornerDefectList+=[ cornerDefectParam ]
147 cornerDefectCornerFractionList+=[ cornerDefectNCornerFractions ]
149 return module_pattern, prob, fractions, noiseProbList, noiseShapeList, cornerDefectList, cornerDefectCornerFractionList
153 Convenience function to combine a list of outputs of calls of moduleDefect, to produce lists to
154 set the ModulePatterns, DefectProbabilities, and NDefectFractionsPerPattern etc. properties of the
155 pixel or strip DefectsEmulatorCondAlg.
158 for i
in range(0,len(defects[0])) :
159 result.append( [ elm
for sublist
in defects
for elm
in sublist[i] ] )
164 Remapping service to rename the input strip RDO collection
168 from SGComps.AddressRemappingConfig
import AddressRemappingCfg
169 renames = [
'%s#%s->%s' % (
'SCT_RDO_Container', InputKey, f
"{InputKey}_ORIG") ]
175 Remapping service to rename the input ITk strip RDO collection
179 def DefectsHistSvcCfg(flags, HistogramGroup: str=
"StripDefects", FileName: str=
'strip_defects.root') -> ComponentAccumulator:
181 THistSvc to histogram some properties of emulated defects.
184 if HistogramGroup
is not None and len(HistogramGroup) > 0
and FileName
is not None and len(FileName) > 0 :
185 histSvc = CompFactory.THistSvc(Output = [f
"{HistogramGroup} DATAFILE='{FileName}', OPT='RECREATE'"] )
186 acc.addService(histSvc)
194 name: str =
"StripDefectsEmulatorCondAlg",
195 **kwargs: dict) -> ComponentAccumulator:
197 Schedule conditions algorithm to create emulated strip defect conditions data
200 kwargs.setdefault(
"ModulePatterns", [[-2,2,0,99,-99,99,-99,99,0,9999,0,1,0]])
202 kwargs.setdefault(
"DefectProbabilities", [[0.,1.e-4]])
203 kwargs.setdefault(
"DetEleCollKey",
"StripDetectorElementCollection")
204 kwargs.setdefault(
"WriteKey",
"StripEmulatedDefects")
205 kwargs.setdefault(
"IDName",
"SCT_ID")
206 kwargs.setdefault(
"HistogramGroupName",
"")
208 kwargs.setdefault(
"RngPerDefectType",
False)
209 kwargs.setdefault(
"DefectsInputFiles",[])
210 kwargs.setdefault(
"DefectsOutputFile",
"")
211 if "DefectsOutputFile" in kwargs
and kwargs[
"DefectsOutputFile"]
is None :
212 kwargs[
"DefectsOutputFile"]=
""
214 acc.addCondAlgo(CompFactory.InDet.StripDefectsEmulatorCondAlg(name,**kwargs))
218 name: str =
"ITkStripDefectsEmulatorCondAlg",
219 **kwargs: dict) -> ComponentAccumulator:
221 Schedule conditions algorithm to create emulated ITk strip defect conditions data
223 kwargs.setdefault(
"ModulePatterns", [[-2,2,0,99,-99,99,-99,99,0,9999,0,1,0]])
225 kwargs.setdefault(
"DefectProbabilities", [[0.,1.e-4]])
226 kwargs.setdefault(
"DetEleCollKey",
"ITkStripDetectorElementCollection")
227 kwargs.setdefault(
"IDName",
"SCT_ID")
228 kwargs.setdefault(
"WriteKey",
"ITkStripEmulatedDefects")
230 kwargs.setdefault(
"RngPerDefectType",
False)
231 kwargs.setdefault(
"DefectsInputFiles",[])
232 kwargs.setdefault(
"DefectsOutputFile",
"")
233 if "DefectsOutputFile" in kwargs
and kwargs[
"DefectsOutputFile"]
is None :
234 kwargs[
"DefectsOutputFile"]=
""
240 name: str =
"ITkStripDefectsEmulatorAlg",
241 **kwargs: dict) -> ComponentAccumulator:
243 Schedule algorithm to emulate strip defects by dropping RDOs overlapping with emulated
244 defects conditions data.
248 if "InputKey" not in kwargs :
251 kwargs.setdefault(
"InputKey",
"StripRDOs_ORIG")
253 if "EmulatedDefectsKey" not in kwargs :
256 kwargs.setdefault(
"EmulatedDefectsKey",
"StripEmulatedDefects")
257 kwargs.setdefault(
"OutputKey",
"StripRDOs")
258 kwargs.setdefault(
"HistogramGroupName",
"")
260 acc.addEventAlgo(CompFactory.InDet.StripDefectsEmulatorAlg(name,**kwargs))
264 name: str =
"ITkStripDefectsEmulatorAlg",
265 **kwargs: dict) -> ComponentAccumulator:
267 Schedule algorithm to emulate ITk strip defects by dropping RDOs overlapping with emulated
268 defects conditions data.
271 if "InputKey" not in kwargs :
274 kwargs.setdefault(
"InputKey",
"ITkStripRDOs_ORIG")
276 if "EmulatedDefectsKey" not in kwargs :
279 kwargs.setdefault(
"EmulatedDefectsKey",
"ITkStripEmulatedDefects")
280 kwargs.setdefault(
"OutputKey",
"ITkStripRDOs")
282 kwargs.setdefault(
"HistogramGroupName",
"")
284 acc.addEventAlgo(CompFactory.InDet.StripDefectsEmulatorAlg(name,**kwargs))
288 name: str =
"ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg",
289 **kwargs: dict) -> ComponentAccumulator:
291 kwargs.setdefault(
"EmulatedDefectsKey",
"ITkStripEmulatedDefects")
292 kwargs.setdefault(
"WriteKey",
"ITkStripDetectorElementStatusFromEmulatedDefects")
293 acc.addCondAlgo(CompFactory.InDet.StripEmulatedDefectsToDetectorElementStatusCondAlg(name,**kwargs))
297 if __name__ ==
"__main__":
303 from AthenaConfiguration.Enums
import ProductionStep
304 flags.Common.ProductionStep = ProductionStep.Simulation
305 from AthenaConfiguration.TestDefaults
import defaultGeometryTags, defaultConditionsTags
306 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
307 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
308 flags.GeoModel.Align.Dynamic =
False
309 flags.Input.Files = [
'/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/PhaseIIUpgrade/RDO/ATLAS-P2-RUN4-03-00-00/mc21_14TeV.601229.PhPy8EG_A14_ttbar_hdamp258p75_SingleLep.recon.RDO.e8481_s4149_r14700/RDO.33629020._000047.pool.root.1']
311 flags.Detector.GeometryITkStrip =
True
312 flags.Detector.GeometryITkStrip =
True
313 flags.Detector.GeometryBpipe =
True
314 flags.Detector.GeometryCalo =
False
316 flags.Concurrency.NumThreads = 8
317 flags.Concurrency.NumConcurrentEvents = 8
319 flags.Exec.MaxEvents = 10
324 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
326 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
330 from ActsConfig.ActsGeometryConfig
import ActsTrackingGeometrySvcCfg
333 RunConsistencyChecks=
False,
334 ObjDebugOutput=
False))
336 from SCT_ConditionsAlgorithms.ITkStripConditionsAlgorithmsConfig
import ITkStripDetectorElementStatusCondAlgNoByteStreamErrorsCfg
340 from StripDefectsEmulatorPostInclude
import emulateITkStripDefects
343 acc.printConfig(withDetails=
True, summariseProps=
True,printDefaults=
True)