ATLAS Offline Software
Loading...
Searching...
No Matches
StripDefectsEmulatorPostInclude Namespace Reference

Functions

 poissonFractions (expectation=4, max_n=12)
 mergeFractions (probA, fractionA, probB, fractionB)
 expectationValue (fractions)
 emulateITkStripDefects (flags, cfg, float StripDefectProb=1e-2, float ModuleDefectProb=1e-2, float NoiseProb=0., int MaxRandomPositionAttempts=10, RngPerDefectType=False, DefectsInputFiles=[], DefectsOutputFile=None, float coldNoiseDefectProb=0., coldNoiseNDefectFractions=None, bool coldNoiseDefectsEvenOnly=False, bool FillHistogramsPerPattern=True, bool FillEtaPhiHistogramsPerPattern=True, str HistogramGroupName="ITkStripDefects", str HistogramFileName=None, PropagateDefectsToStatus=True)
 emulateITkStripDefectsDefault (flags, cfg, float StripDefectProb=1e-2, float ModuleDefectProb=1e-2, float NoiseProb=0., RngPerDefectType=False, DefectsInputFiles=[], DefectsOutputFile=None, str HistogramFileName=None, PropagateDefectsToStatus=True)

Function Documentation

◆ emulateITkStripDefects()

StripDefectsEmulatorPostInclude.emulateITkStripDefects ( flags,
cfg,
float StripDefectProb = 1e-2,
float ModuleDefectProb = 1e-2,
float NoiseProb = 0.,
int MaxRandomPositionAttempts = 10,
RngPerDefectType = False,
DefectsInputFiles = [],
DefectsOutputFile = None,
float coldNoiseDefectProb = 0.,
coldNoiseNDefectFractions = None,
bool coldNoiseDefectsEvenOnly = False,
bool FillHistogramsPerPattern = True,
bool FillEtaPhiHistogramsPerPattern = True,
str HistogramGroupName = "ITkStripDefects",
str HistogramFileName = None,
PropagateDefectsToStatus = True )
Schedule algorithms to create ITk strip defect conditions data and to emulate
defects by dropping ITk strip RDOs overlapping with such defects. ModuleDefectProb controls the number of
defect strip modules and DefectProb the number of defect strips. If a strip group is overlapping with
a single strip defect, the strip group will be split.

Definition at line 76 of file StripDefectsEmulatorPostInclude.py.

92 PropagateDefectsToStatus=True) :
93 """
94 Schedule algorithms to create ITk strip defect conditions data and to emulate
95 defects by dropping ITk strip RDOs overlapping with such defects. ModuleDefectProb controls the number of
96 defect strip modules and DefectProb the number of defect strips. If a strip group is overlapping with
97 a single strip defect, the strip group will be split.
98 """
99
100 from InDetDefectsEmulation.StripDefectsEmulatorConfig import (
101 ITkStripDefectsEmulatorCondAlgCfg,
102 ITkStripDefectsEmulatorAlgCfg,
103 ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg,
104 DefectsHistSvcCfg,
105 moduleDefect,
106 combineModuleDefects,
107 # ODD_INDEX,
108 EVEN_INDEX
109 )
110 from AthenaCommon.Constants import INFO
111
112 if HistogramFileName is None or len(HistogramFileName) ==0 :
113 HistogramGroupName = None
114 if HistogramGroupName is not None :
115 cfg.merge( DefectsHistSvcCfg(flags, HistogramGroup=HistogramGroupName, FileName=HistogramFileName))
116
117 # coldNoiseDefectFractions=poissonFractions(4,16)
118 fractions=mergeFractions(StripDefectProb,[1.],coldNoiseDefectProb,coldNoiseNDefectFractions)
119 if fractions is None :
120 fractions = [1.]
121 # total number of defects due to cold noise should be steered just by the coldNoiseDefectProb
122 # so in case of defect groups reduce this probability according to the defect group size created
123 # in average by each generated defect:
124 expectation_value = expectationValue(fractions)
125 coldNoiseDefectProb=coldNoiseDefectProb/expectation_value if expectation_value>0. else 0.
126
127 cold_noise_phi_range=EVEN_INDEX if coldNoiseDefectsEvenOnly else [-99,99]
128
129 # dummy "fractions" for strips, module pattern are just examples, and currently all
130 # modules get the same defect probabilities irrespectively of e.g. strip length.
131 if True :
132 module_pattern, module_defect_prob, fractions, ignore_NoiseProbability,ignore_NoiseShape, cornerDefectParam, cornerDefectFractions = combineModuleDefects([
133 # coldNoise defects show up in petal modules 4 and 5 (endcap eta index 14-17), and only on
134 # the lower module part which have even index in phi ?
135 moduleDefect(bec=[-2,-2],layer=[0,99], phi_range=cold_noise_phi_range,eta_range=[14,17],
136 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
137 all_rows=False, # if True all rows of the same un-split module are marked as defect
138 probability=[ModuleDefectProb, # probability of a module to be defect
139 StripDefectProb+coldNoiseDefectProb, # probability of a strip to be defect
140 ],
141 fractionsOfNDefects=[fractions]),
142 moduleDefect(bec=[2,2],layer=[0,99], phi_range=cold_noise_phi_range,eta_range=[14,17], # select endcap C4,5 even modules,
143 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
144 all_rows=False, # if True all rows of the same un-split module are marked as defect
145 probability=[ModuleDefectProb, # probability of a module to be defect
146 StripDefectProb+coldNoiseDefectProb # probability of a strip to be defect
147 ],
148 fractionsOfNDefects=[fractions]),
149 moduleDefect(bec=[-2,-2],layer=[0,99], phi_range=[-99,99],eta_range=[14,17], # select endcap A4,5 modules,
150 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
151 all_rows=False, # if True all rows of the same un-split module are marked as defect
152 probability=[ModuleDefectProb, # probability of a module to be defect
153 StripDefectProb # probability of a strip to be defect
154 ]),
155 moduleDefect(bec=[2,2],layer=[0,99], phi_range=[-99,99],eta_range=[14,17], # select endcap C4,5 modules,
156 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
157 all_rows=False, # if True all rows of the same un-split module are marked as defect
158 probability=[ModuleDefectProb, # probability of a module to be defect
159 StripDefectProb # probability of a strip to be defect
160 ]),
161 moduleDefect(bec=[-2,-2],layer=[0,99], phi_range=[-99,99],eta_range=[-99,99], # select all endcap A modules
162 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
163 all_rows=False, # if True all rows of the same un-split module are marked as defect
164 probability=[ModuleDefectProb, # probability of a module to be defect
165 StripDefectProb # probability of a strip to be defect
166 ]),
167 moduleDefect(bec=[-1,1],layer=[0,1], phi_range=[-99,99],eta_range=[-99,99], # select all barrel, layer 0,1 modules
168 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
169 all_rows=False, # if True all rows of the same un-split module are marked as defect
170 probability=[ModuleDefectProb, # probability of a module to be defect
171 StripDefectProb # probability of a strip to be defect
172 ]),
173 moduleDefect(bec=[-1,1],layer=[2,99], phi_range=[-99,99],eta_range=[-99,99], # select all other barrel layers
174 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
175 all_rows=False, # if True all rows of the same un-split module are marked as defect
176 probability=[ModuleDefectProb, # probability of a module to be defect
177 StripDefectProb # probability of a strip to be defect
178 ]),
179 moduleDefect(bec=[2,2],layer=[0,99], phi_range=[-99,99],eta_range=[-99,99], # select all endcap C modules
180 side_range=[0,0,1,1], # randomly mark sides as defect. With [0,1] Both sides are marked as defect
181 all_rows=False, # if True all rows of the same un-split module are marked as defect
182 probability=[ModuleDefectProb, # probability of a module to be defect
183 StripDefectProb # probability of a strip to be defect
184 ])])
185 NDefectFractionsPerPattern = fractions
186
187 if NoiseProb > 0. :
188 # strip noise
189 import math
190 def norm(dist) :
191 scale = sum(dist)
192 return [elm/scale if scale > 0. else 0. for elm in dist]
193 def gaussDist(mean, width, n) :
194 scale = -1./(2*width)
195 return norm([ math.exp( scale *math.pow(i - mean,2.) ) for i in range(0,n) ])
196 # Gaussian distribution between 1 and 2
197 time_bin_dist = gaussDist(1.51,0.03,3)
198
199 # different noise per module of different strip length
200 defects=[]
201 for length in [15093,18093,18981,23981,24092,24180,26223,27093,28980,30807,30808,31981,32223,40161,48360,54580,54581,60162] :
202 # assume noise scales with strip length but there is a constant noise
203 defects += [ moduleDefect(column_or_strip_length=[length-1,length+1],
204 probability=[],
205 noiseProbability=NoiseProb * 0.5*( 1 + length / 37627.5 ),
206 noiseShape=time_bin_dist)]
207 module_pattern_noise, ignore_module_defect_prob, ignore_fractions, NoiseProbability,NoiseShape,cornerDefectParam,cornerDefectFractions = combineModuleDefects(defects)
208 else :
209 module_pattern_noise=[]
210 NoiseProbability=[]
211 NoiseShape=[]
212
213 # schedule custom defects generating conditions alg
214 cfg.merge( ITkStripDefectsEmulatorCondAlgCfg(flags,
215 # to enable histogramming:
216 HistogramGroupName=f"/{HistogramGroupName}/StripEmulatedDefects/" if HistogramGroupName is not None else "",
217 MaxRandomPositionAttempts=MaxRandomPositionAttempts,
218 ModulePatterns=module_pattern,
219 DefectProbabilities=module_defect_prob,
220 NDefectFractionsPerPattern = NDefectFractionsPerPattern,
221 CornerDefectParamsPerPattern=[],
222 NCornerDefectFractionsPerPattern=[],
223 RngPerDefectType=RngPerDefectType,
224 DefectsInputFiles=DefectsInputFiles,
225 DefectsOutputFile=DefectsOutputFile,
226 FillHistogramsPerPattern=FillHistogramsPerPattern,
227 FillEtaPhiHistogramsPerPattern=FillEtaPhiHistogramsPerPattern,
228 WriteKey="ITkStripEmulatedDefects", # the default should match the key below
229 ))
230
231 # schedule the algorithm which drops elements from the ITk Pixel RDO collection
232 cfg.merge( ITkStripDefectsEmulatorAlgCfg(flags,
233 # prevent default cond alg from being scheduled :
234 EmulatedDefectsKey="ITkStripEmulatedDefects",
235 ModulePatterns=module_pattern_noise,
236 NoiseProbability = NoiseProbability,
237 NoiseShape = NoiseShape,
238 # to enable histogramming:
239 HistogramGroupName=f"/{HistogramGroupName}/StripRejectedRDOs/" if HistogramGroupName is not None else "",
240 OutputLevel=INFO))
241
242 if PropagateDefectsToStatus :
243 # propagate defects to detector element status
244 cfg.merge(ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg(flags,
245 name="ITkStripDefectsEmulatorToDetectorElementStatusCondAlg",
246 EmulatedDefectsKey="ITkStripEmulatedDefects",
247 WriteKey="ITkStripDetectorElementStatusFromEmulatedDefects"))
248 strip_det_el_status_cond_alg=cfg.getCondAlgo("ITkStripDetectorElementStatusCondAlgNoByteStreamErrors")
249 strip_det_el_status_cond_alg.ConditionsSummaryTool.SCTDetElStatusCondDataBaseKey="ITkStripDetectorElementStatusFromEmulatedDefects"
250

◆ emulateITkStripDefectsDefault()

StripDefectsEmulatorPostInclude.emulateITkStripDefectsDefault ( flags,
cfg,
float StripDefectProb = 1e-2,
float ModuleDefectProb = 1e-2,
float NoiseProb = 0.,
RngPerDefectType = False,
DefectsInputFiles = [],
DefectsOutputFile = None,
str HistogramFileName = None,
PropagateDefectsToStatus = True )

Definition at line 251 of file StripDefectsEmulatorPostInclude.py.

260 PropagateDefectsToStatus=True) :
261 emulateITkStripDefects(flags,cfg,
262 StripDefectProb=StripDefectProb,
263 ModuleDefectProb=ModuleDefectProb,
264 NoiseProb=NoiseProb,
265 RngPerDefectType=RngPerDefectType,
266 DefectsInputFiles=DefectsInputFiles,
267 DefectsOutputFile=DefectsOutputFile,
268 HistogramFileName=HistogramFileName,
269 PropagateDefectsToStatus=PropagateDefectsToStatus)

◆ expectationValue()

StripDefectsEmulatorPostInclude.expectationValue ( fractions)

Definition at line 68 of file StripDefectsEmulatorPostInclude.py.

68def expectationValue(fractions) :
69 expectation_value=0
70 if fractions is not None :
71 for idx in range(0,len(fractions)) :
72 expectation_value += (idx+1)*fractions[idx]
73 return expectation_value
74
75

◆ mergeFractions()

StripDefectsEmulatorPostInclude.mergeFractions ( probA,
fractionA,
probB,
fractionB )

Definition at line 46 of file StripDefectsEmulatorPostInclude.py.

46def mergeFractions(probA,fractionA, probB, fractionB) :
47 if probA <= 0. :
48 return fractionB
49 if probB <= 0. :
50 return fractionA
51
52 if len(fractionA) < len(fractionB) :
53 min_n=len(fractionA)
54 scaleA = probA/probB
55 scaleB = 1.
56 fraction=fractionB
57 else :
58 min_n=len(fractionA)
59 scaleB = probA/probB
60 scaleA = 1.
61 fraction=fractionA
62 for idx in range(0,min_n) :
63 fraction[idx]=fractionA[idx]*scaleA + fractionB[idx]*scaleB
64 norm=1./sum(fraction)
65 fraction = [elm*norm for elm in fraction]
66 return fraction
67

◆ poissonFractions()

StripDefectsEmulatorPostInclude.poissonFractions ( expectation = 4,
max_n = 12 )
Create fractions for exactly 1..max_n defects, assuming a Poisson
distribution with an expected value of expect_n.

Definition at line 33 of file StripDefectsEmulatorPostInclude.py.

33def poissonFractions(expectation=4, max_n=12) :
34 """
35 Create fractions for exactly 1..max_n defects, assuming a Poisson
36 distribution with an expected value of expect_n.
37 """
38 def PoissonProb(expected, n) :
39 return math.pow(expected,n)*math.exp(-expected)/math.gamma(n+1)
40 def norm(fractions) :
41 Norm = 1./sum (fractions)
42 return [Norm*elm for elm in fractions ]
43 return norm([ PoissonProb(expectation,i) for i in range(1,max_n+1) ])
44
45