ATLAS Offline Software
Functions
StripDefectsEmulatorPostInclude Namespace Reference

Functions

def poissonFractions (expectation=4, max_n=12)
 
def mergeFractions (probA, fractionA, probB, fractionB)
 
def expectationValue (fractions)
 
def 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)
 
def 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()

def 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 75 of file StripDefectsEmulatorPostInclude.py.

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

◆ emulateITkStripDefectsDefault()

def 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 248 of file StripDefectsEmulatorPostInclude.py.

249  cfg,
250  StripDefectProb: float=1e-2,
251  ModuleDefectProb: float=1e-2,
252  NoiseProb: float=0.,
253  RngPerDefectType=False,
254  DefectsInputFiles=[],
255  DefectsOutputFile=None,
256  HistogramFileName: str=None,
257  PropagateDefectsToStatus=True) :
258  emulateITkStripDefects(flags,cfg,
259  StripDefectProb=StripDefectProb,
260  ModuleDefectProb=ModuleDefectProb,
261  NoiseProb=NoiseProb,
262  RngPerDefectType=RngPerDefectType,
263  DefectsInputFiles=DefectsInputFiles,
264  DefectsOutputFile=DefectsOutputFile,
265  HistogramFileName=HistogramFileName,
266  PropagateDefectsToStatus=PropagateDefectsToStatus)

◆ expectationValue()

def StripDefectsEmulatorPostInclude.expectationValue (   fractions)

Definition at line 68 of file StripDefectsEmulatorPostInclude.py.

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

◆ mergeFractions()

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

Definition at line 46 of file StripDefectsEmulatorPostInclude.py.

46 def 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()

def 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.

33 def 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 
PixelDefectsEmulatorConfig.DefectsHistSvcCfg
ComponentAccumulator DefectsHistSvcCfg(flags, str HistogramGroup="PixelDefects", str FileName='pixel_defects.root')
Definition: PixelDefectsEmulatorConfig.py:23
StripDefectsEmulatorConfig.moduleDefect
def moduleDefect(bec=[-2, 2], layer=[0, 8], eta_range=[-99, 99], phi_range=[-99, 99], columns_or_strips=[0, 2000], column_or_strip_length=[0, 1000000], side_range=[0, 1], all_rows=True, probability=[1e-2], fractionsOfNDefects=[], noiseProbability=None, noiseShape=[], cornerDefectParam=None, cornerDefectNCornerFractions=None)
Definition: StripDefectsEmulatorConfig.py:56
PlotCalibFromCool.norm
norm
Definition: PlotCalibFromCool.py:100
StripDefectsEmulatorPostInclude.expectationValue
def expectationValue(fractions)
Definition: StripDefectsEmulatorPostInclude.py:68
StripDefectsEmulatorPostInclude.emulateITkStripDefects
def 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)
Definition: StripDefectsEmulatorPostInclude.py:75
StripDefectsEmulatorPostInclude.emulateITkStripDefectsDefault
def 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: StripDefectsEmulatorPostInclude.py:248
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
StripDefectsEmulatorPostInclude.poissonFractions
def poissonFractions(expectation=4, max_n=12)
Definition: StripDefectsEmulatorPostInclude.py:33
StripDefectsEmulatorConfig.combineModuleDefects
def combineModuleDefects(defects)
Definition: StripDefectsEmulatorConfig.py:151
StripDefectsEmulatorConfig.ITkStripDefectsEmulatorCondAlgCfg
ComponentAccumulator ITkStripDefectsEmulatorCondAlgCfg(flags, str name="ITkStripDefectsEmulatorCondAlg", **dict kwargs)
Definition: StripDefectsEmulatorConfig.py:217
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
Constants
some useful constants -------------------------------------------------—
StripDefectsEmulatorConfig.ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg
ComponentAccumulator ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg(flags, str name="ITkStripDefectsEmulatorToDetectorElementStatusCondAlgCfg", **dict kwargs)
Definition: StripDefectsEmulatorConfig.py:287
StripDefectsEmulatorPostInclude.mergeFractions
def mergeFractions(probA, fractionA, probB, fractionB)
Definition: StripDefectsEmulatorPostInclude.py:46
StripDefectsEmulatorConfig.ITkStripDefectsEmulatorAlgCfg
ComponentAccumulator ITkStripDefectsEmulatorAlgCfg(flags, str name="ITkStripDefectsEmulatorAlg", **dict kwargs)
Definition: StripDefectsEmulatorConfig.py:263