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
14 Return True if every two elements in a_list form a pair whose two elements are
15 in ascending order. The element pairs themselves may have an arbitrary order.
17 for i
in range(0,len(a_list),2) :
18 if a_list[i]>a_list[i+1] :
30 Convenience method to create a parameter set for module corner defects.
31 The corner defects have a circular shape and intersect the sensor edges at certain
32 points in x and y direction. The line between these two intersection points forms
33 a sagitta of the circle.
34 probability: Probability of a module to have one or more corner defects.
35 min_rx: minimum position from the corner in local x-direction of possible intersection points.
36 max_rx: maximum position from the corner in local x-direction of possible intersection points.
37 min_ry: minimum position from the corner in local y-direction of possible intersection points.
38 max_ry: maximum position from the corner in local x-direction of possible intersection points.
39 min_sagitta: minimum size of the sagitta (upper limit of circle radius)
40 max_sagitta: maximum size of the sagitta (lower limit of circle radius)
44 assert min_sagitta<max_sagitta
46 min_rx, max_rx-min_rx,
47 min_ry, max_ry-min_ry,
48 min_sagitta, max_sagitta-min_sagitta]
54 columns_or_strips=[0,2000],
55 column_or_strip_length=[0,1000000],
59 fractionsOfNDefects=[],
60 noiseProbability=None,
62 cornerDefectParam=None,
63 cornerDefectNCornerFractions=None,
66 Convenience function to create parameters for strip or pixel defects emulation conditions data
67 bec: range to select the bec identifier part (range is inclusive)
68 layer: range to select the layer/disc identifier part (range is inclusive)
69 eta_range: range to select the eta index identifier part (range is inclusive)
70 phi_range: range to select the phi index identifier part (range is inclusive)
71 columns_or_strips: match only modules with number of columns or strips in this range (range is inclusive)
72 column_or_strip_length: match the strip lengths in microns (range is inclusive)
73 side_range: to select both sides of a sensor [0,1], to select either side [0,0,1,1]
74 all_rows: to select individal modules (0), or all modules associated to the same physical sensor (1)
75 probabilities: module-defect, strip/pixel defect (for pixel additionally group defect probabilities:
76 at least one core-column defect, at least one defect circuit)
77 fractions: per group defect, fractions to have exactly 1..n group defects under the condition that there is
78 at least one such group defect.
79 noiseProbability: None or probability of a strip (or pixel) to produce a spurious hit.
80 noiseShape: empty list or binned pdf used to compute one random number per spurious hit (time bin for strips, tot for pixel).
81 cornerDefectParam: None or parameters e.g. created with makeCornerDefectParam to create defects at module corners.
82 cornerDefectNCornerFractions: if cornerDefectParam is not None the fractions of 1 to 4 corners to have a defect if the module
87 assert len(layer)%2==0
and len(layer) >= 2
and ordered_pairs(layer)
88 assert len(eta_range)%2==0
and len(eta_range) >= 2
and ordered_pairs(eta_range)
89 assert len(phi_range)%2==0
and len(phi_range) >= 2
and ordered_pairs(phi_range)
90 assert len(side_range)%2==0
and len(side_range) >= 2
and ordered_pairs(side_range)
91 assert len(columns_or_strips)%2==0
and len(columns_or_strips) >= 2
and ordered_pairs(columns_or_strips)
92 assert len(column_or_strip_length)%2==0
and len(column_or_strip_length) >= 2
and ordered_pairs(column_or_strip_length)
93 assert len(fractionsOfNDefects)==0
or len(fractionsOfNDefects)+2==len(probability)
95 assert cornerDefectParam
is not None or cornerDefectNCornerFractions
is None
96 assert cornerDefectParam
is None or cornerDefectNCornerFractions
is not None
98 length=[ l
for l
in set([len(bec),len(layer),len(eta_range),len(phi_range),len(side_range),len(columns_or_strips)]) ]
100 for i
in range(1,len(length)) :
101 for j
in range(0,i) :
102 assert max(length[i],length[j])%
min(length[i],length[j])==0
110 cornerDefectCornerFractionList=[]
111 if noiseProbability
is not None and noiseProbability>0. :
113 shape_sum =
sum(noiseShape)
114 noiseShape = [ elm/shape_sum
for elm
in noiseShape ]
116 noiseProbability=
None
119 module_pattern+=[ [bec[i%len(bec)], bec[(i+1)%len(bec)],
120 layer[i%len(layer)], layer[(i+1)%len(layer)],
121 eta_range[i%len(eta_range)], eta_range[(i+1)%len(eta_range)],
122 phi_range[i%len(phi_range)], phi_range[(i+1)%len(phi_range)],
123 columns_or_strips[i%len(columns_or_strips)], columns_or_strips[(i+1)%len(columns_or_strips)],
124 column_or_strip_length[i%len(column_or_strip_length)], column_or_strip_length[(i+1)%len(column_or_strip_length)],
125 side_range[i%len(side_range)], side_range[(i+1)%len(side_range)],
126 1
if all_rows
else 0] ]
127 prob += [ probability ]
128 fractions += [ [fraction
for per_pattern
in fractionsOfNDefects
for fraction
in per_pattern + [-1] ] ]
129 if noiseProbability
is not None:
130 noiseProbList+=[noiseProbability]
131 noiseShapeList+=[noiseShape]
132 if cornerDefectParam
is not None:
133 cornerDefectList+=[ cornerDefectParam ]
134 cornerDefectCornerFractionList+=[ cornerDefectNCornerFractions ]
136 return module_pattern, prob, fractions, noiseProbList, noiseShapeList, cornerDefectList, cornerDefectCornerFractionList
140 Convenience function to combine a list of outputs of calls of moduleDefect, to produce lists to
141 set the ModulePatterns, DefectProbabilities, and NDefectFractionsPerPattern etc. properties of the
142 pixel or strip DefectsEmulatorCondAlg.
145 for i
in range(0,len(defects[0])) :
146 result.append( [ elm
for sublist
in defects
for elm
in sublist[i] ] )
151 Remapping service to rename the input strip RDO collection
155 from SGComps.AddressRemappingConfig
import AddressRemappingCfg
156 renames = [
'%s#%s->%s' % (
'SCT_RDO_Container', InputKey, f
"{InputKey}_ORIG") ]
162 Remapping service to rename the input ITk strip RDO collection
166 def DefectsHistSvcCfg(flags, HistogramGroup: str=
"StripDefects", FileName: str=
'strip_defects.root') -> ComponentAccumulator:
168 THistSvc to histogram some properties of emulated defects.
171 if HistogramGroup
is not None and len(HistogramGroup) > 0
and FileName
is not None and len(FileName) > 0 :
172 histSvc = CompFactory.THistSvc(Output = [f
"{HistogramGroup} DATAFILE='{FileName}', OPT='RECREATE'"] )
173 acc.addService(histSvc)
181 name: str =
"StripDefectsEmulatorCondAlg",
182 **kwargs: dict) -> ComponentAccumulator:
184 Schedule conditions algorithm to create emulated strip defect conditions data
187 kwargs.setdefault(
"ModulePatterns", [[-2,2,0,99,-99,99,-99,99,0,9999,0,1,0]])
189 kwargs.setdefault(
"DefectProbabilities", [[0.,1.e-4]])
190 kwargs.setdefault(
"DetEleCollKey",
"StripDetectorElementCollection")
191 kwargs.setdefault(
"WriteKey",
"StripEmulatedDefects")
192 kwargs.setdefault(
"IDName",
"SCT_ID")
193 kwargs.setdefault(
"HistogramGroupName",
"")
195 kwargs.setdefault(
"RngPerDefectType",
False)
196 kwargs.setdefault(
"DefectsInputFiles",[])
197 kwargs.setdefault(
"DefectsOutputFile",
"")
198 if "DefectsOutputFile" in kwargs
and kwargs[
"DefectsOutputFile"]
is None :
199 kwargs[
"DefectsOutputFile"]=
""
201 acc.addCondAlgo(CompFactory.InDet.StripDefectsEmulatorCondAlg(name,**kwargs))
205 name: str =
"ITkStripDefectsEmulatorCondAlg",
206 **kwargs: dict) -> ComponentAccumulator:
208 Schedule conditions algorithm to create emulated ITk strip defect conditions data
210 kwargs.setdefault(
"ModulePatterns", [[-2,2,0,99,-99,99,-99,99,0,9999,0,1,0]])
212 kwargs.setdefault(
"DefectProbabilities", [[0.,1.e-4]])
213 kwargs.setdefault(
"DetEleCollKey",
"ITkStripDetectorElementCollection")
214 kwargs.setdefault(
"IDName",
"SCT_ID")
215 kwargs.setdefault(
"WriteKey",
"ITkStripEmulatedDefects")
217 kwargs.setdefault(
"RngPerDefectType",
False)
218 kwargs.setdefault(
"DefectsInputFiles",[])
219 kwargs.setdefault(
"DefectsOutputFile",
"")
220 if "DefectsOutputFile" in kwargs
and kwargs[
"DefectsOutputFile"]
is None :
221 kwargs[
"DefectsOutputFile"]=
""
227 name: str =
"ITkStripDefectsEmulatorAlg",
228 **kwargs: dict) -> ComponentAccumulator:
230 Schedule algorithm to emulate strip defects by dropping RDOs overlapping with emulated
231 defects conditions data.
235 if "InputKey" not in kwargs :
238 kwargs.setdefault(
"InputKey",
"StripRDOs_ORIG")
240 if "EmulatedDefectsKey" not in kwargs :
243 kwargs.setdefault(
"EmulatedDefectsKey",
"StripEmulatedDefects")
244 kwargs.setdefault(
"OutputKey",
"StripRDOs")
245 kwargs.setdefault(
"HistogramGroupName",
"")
247 acc.addEventAlgo(CompFactory.InDet.StripDefectsEmulatorAlg(name,**kwargs))
251 name: str =
"ITkStripDefectsEmulatorAlg",
252 **kwargs: dict) -> ComponentAccumulator:
254 Schedule algorithm to emulate ITk strip defects by dropping RDOs overlapping with emulated
255 defects conditions data.
258 if "InputKey" not in kwargs :
261 kwargs.setdefault(
"InputKey",
"ITkStripRDOs_ORIG")
263 if "EmulatedDefectsKey" not in kwargs :
266 kwargs.setdefault(
"EmulatedDefectsKey",
"ITkStripEmulatedDefects")
267 kwargs.setdefault(
"OutputKey",
"ITkStripRDOs")
269 kwargs.setdefault(
"HistogramGroupName",
"")
271 acc.addEventAlgo(CompFactory.InDet.StripDefectsEmulatorAlg(name,**kwargs))
275 name: str =
"ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg",
276 **kwargs: dict) -> ComponentAccumulator:
278 kwargs.setdefault(
"EmulatedDefectsKey",
"ITkStripEmulatedDefects")
279 kwargs.setdefault(
"WriteKey",
"ITkStripDetectorElementStatusFromEmulatedDefects")
280 acc.addCondAlgo(CompFactory.InDet.StripEmulatedDefectsToDetectorElementStatusCondAlg(name,**kwargs))
284 if __name__ ==
"__main__":
290 from AthenaConfiguration.Enums
import ProductionStep
291 flags.Common.ProductionStep = ProductionStep.Simulation
292 from AthenaConfiguration.TestDefaults
import defaultGeometryTags, defaultConditionsTags
293 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
294 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
295 flags.GeoModel.Align.Dynamic =
False
296 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']
298 flags.Detector.GeometryITkStrip =
True
299 flags.Detector.GeometryITkStrip =
True
300 flags.Detector.GeometryBpipe =
True
301 flags.Detector.GeometryCalo =
False
303 flags.Concurrency.NumThreads = 8
304 flags.Concurrency.NumConcurrentEvents = 8
306 flags.Exec.MaxEvents = 10
311 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
313 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
317 from ActsConfig.ActsGeometryConfig
import ActsTrackingGeometrySvcCfg
320 RunConsistencyChecks=
False,
321 ObjDebugOutput=
False))
323 from SCT_ConditionsAlgorithms.ITkStripConditionsAlgorithmsConfig
import ITkStripDetectorElementStatusCondAlgNoByteStreamErrorsCfg
327 from StripDefectsEmulatorPostInclude
import emulateITkStripDefects
330 acc.printConfig(withDetails=
True, summariseProps=
True,printDefaults=
True)