ATLAS Offline Software
PixelDefectsEmulatorConfig.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 """
4  Emulating pixel defects by dropping elements from the RDO input container
5 """
6 from AthenaConfiguration.AllConfigFlags import initConfigFlags
7 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory import CompFactory
9 
10 from AthenaCommon.Constants import INFO
11 
12 def PixelRDORemappingCfg(flags, InputKey="PixelRDOs") :
13  acc = ComponentAccumulator()
14 
15  from SGComps.AddressRemappingConfig import AddressRemappingCfg
16  renames = [ '%s#%s->%s' % ('PixelRDO_Container', InputKey, f"{InputKey}_ORIG") ]
17  acc.merge(AddressRemappingCfg( renameMaps = renames ))
18  return acc
19 
21  return PixelRDORemappingCfg(flags,"ITkPixelRDOs")
22 
23 def DefectsHistSvcCfg(flags, HistogramGroup: str="PixelDefects", FileName: str='pixel_defects.root') -> ComponentAccumulator:
24  acc = ComponentAccumulator()
25  if HistogramGroup is not None and len(HistogramGroup) > 0 and FileName is not None and len(FileName) > 0 :
26  histSvc = CompFactory.THistSvc(Output = [f"{HistogramGroup} DATAFILE='{FileName}', OPT='RECREATE'"] )
27  acc.addService(histSvc)
28  return acc
29 
30 def ITkDefectsHistSvcCfg(flags, HistogramGroup="ITkPixelDefects") -> ComponentAccumulator:
31  return DefectsHistSvcCfg(flags,HistogramGroup)
32 
33 
35  name: str = "PixelDefectsEmulatorCondAlg",
36  **kwargs: dict) -> ComponentAccumulator:
37  acc = ComponentAccumulator()
38  kwargs.setdefault("ModulePatterns", [[-2,2,0,99,-99,99,-99,99,0,9999,0,0,0]]) # ranges: barrel/ec, all layers, all eta, all phi, all column counts,
39  # all sides, don't auto-match connected rows
40  kwargs.setdefault("DefectProbabilities", [[0.,1e-3,0.,0.]]) # probabilities: module, pixel, core-column, circuit
41  kwargs.setdefault("NDefectFractionsPerPattern",[[1.,-1, 1.]]) # fractions for exactly 1..N core-column, circuit defects
42  kwargs.setdefault("DetEleCollKey", "PixelDetectorElementCollection")
43  kwargs.setdefault("WriteKey", "PixelEmulatedDefects")
44  kwargs.setdefault("HistogramGroupName","") # disable histogramming; enable: e.g. /PixelDefects/EmulatedDefects/
45 
46  kwargs.setdefault("RngPerDefectType",False) # If True use one RNG per defect type (module, chip-defects, core-column, pixel-defects, corner-defects)
47  kwargs.setdefault("DefectsInputFiles",[]) # If not empty read defects from input files and merge defects (root RNTuple/json; extension: .root .json")
48  kwargs.setdefault("DefectsOutputFile","") # If not empty write defects to a output file (root RNTuple/json; (extension: .root .json")
49  if "DefectsOutputFile" in kwargs and kwargs["DefectsOutputFile"] is None :
50  kwargs["DefectsOutputFile"]=""
51 
52  acc.addCondAlgo(CompFactory.InDet.PixelDefectsEmulatorCondAlg(name,**kwargs))
53  return acc
54 
56  name: str = "ITkPixelDefectsEmulatorCondAlg",
57  **kwargs: dict) -> ComponentAccumulator:
58  kwargs.setdefault("ModulePatterns", [[-2,2,0,99,-99,99,-99,99,0,9999,0,0,0]]) # range-pairs+flag: barrel/ec, all layers, all eta, all phi, all column counts,
59  # all sides, don't auto-match connected rows
60  kwargs.setdefault("DefectProbabilities", [[0.,1e-2, 1e-1,0.]]) # probabilities: module, pixel, core-column, circuit
61  kwargs.setdefault("NDefectFractionsPerPattern",[[1.,-1, 1.]]) # fractions for exactly 1..N core-column, circuit defects
62 
63  kwargs.setdefault("DetEleCollKey", "ITkPixelDetectorElementCollection")
64  kwargs.setdefault("WriteKey", "ITkPixelEmulatedDefects")
65 
66  kwargs.setdefault("RngPerDefectType",False) # If True use one RNG per defect type (module, chip-defects, core-column, pixel-defects, corner-defects)
67  kwargs.setdefault("DefectsInputFiles",[]) # If not empty read defects from input files and merge defects (root RNTuple/json; extension: .root .json")
68  kwargs.setdefault("DefectsOutputFile","") # If not empty write defects to a output file (root RNTuple/json; (extension: .root .json")
69  if "DefectsOutputFile" in kwargs and kwargs["DefectsOutputFile"] is None :
70  kwargs["DefectsOutputFile"]=""
71 
72  return PixelDefectsEmulatorCondAlgCfg(flags,name,**kwargs)
73 
74 
76  name: str = "PixelDefectsEmulatorAlg",
77  **kwargs: dict) -> ComponentAccumulator:
78  acc = ComponentAccumulator()
79 
80  if "InputKey" not in kwargs :
81  # rename original RDO collection
82  acc.merge(PixelRDORemappingCfg(flags))
83  kwargs.setdefault("InputKey","PixelRDOs_ORIG")
84 
85  if "EmulatedDefectsKey" not in kwargs :
86  # create defects conditions data
87  acc.merge( PixelDefectsEmulatorCondAlgCfg(flags))
88  kwargs.setdefault("EmulatedDefectsKey", "PixelEmulatedDefects")
89  kwargs.setdefault("OutputKey","PixelRDOs")
90  kwargs.setdefault("HistogramGroupName","") # disable histogramming, enable e.g. /PixelDefects/RejectedRDOs/
91 
92  acc.addEventAlgo(CompFactory.InDet.PixelDefectsEmulatorAlg(name,**kwargs))
93  return acc
94 
96  name: str = "ITkPixelDefectsEmulatorAlg",
97  **kwargs: dict) -> ComponentAccumulator:
98  acc = ComponentAccumulator()
99  if "InputKey" not in kwargs :
100  # rename original RDO collection
101  acc.merge(ITkPixelRDORemappingCfg(flags))
102  kwargs.setdefault("InputKey","ITkPixelRDOs_ORIG")
103 
104  if "EmulatedDefectsKey" not in kwargs :
105  # create defects conditions data
106  acc.merge( ITkPixelDefectsEmulatorCondAlgCfg(flags))
107  kwargs.setdefault("EmulatedDefectsKey", "ITkPixelEmulatedDefects")
108  kwargs.setdefault("OutputKey","ITkPixelRDOs")
109 
110  kwargs.setdefault("HistogramGroupName","") # disable histogramming, enable e.g. /PixelDefects/RejectedRDOs/
111 
112  acc.addEventAlgo(CompFactory.InDet.PixelDefectsEmulatorAlg(name,**kwargs))
113  return acc
114 
116  name: str = "ITkPixelDefectsEmulatorToDetectorElementStatusCondAlgCfg",
117  **kwargs: dict) -> ComponentAccumulator:
118  acc = ComponentAccumulator()
119  kwargs.setdefault("EmulatedDefectsKey","ITkPixelEmulatedDefects")
120  kwargs.setdefault("WriteKey","ITkPixelDetectorElementStatusFromEmulatedDefects")
121  acc.addCondAlgo(CompFactory.InDet.PixelEmulatedDefectsToDetectorElementStatusCondAlg(name,**kwargs))
122  return acc
123 
124 if __name__ == "__main__":
125 
126  flags = initConfigFlags()
127 
128  from AthenaConfiguration.Enums import ProductionStep
129  flags.Common.ProductionStep = ProductionStep.Simulation
130  from AthenaConfiguration.TestDefaults import defaultGeometryTags, defaultConditionsTags
131  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
132  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
133  flags.GeoModel.Align.Dynamic = False
134  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']
135 
136  flags.Detector.GeometryITkPixel = True
137  flags.Detector.GeometryITkStrip = True
138  flags.Detector.GeometryBpipe = True
139  flags.Detector.GeometryCalo = False
140 
141  flags.Concurrency.NumThreads = 8
142  flags.Concurrency.NumConcurrentEvents = 8
143 
144  flags.Exec.MaxEvents = 10
145 
146  flags.lock()
147  flags.dump()
148 
149  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
150  acc = MainServicesCfg( flags )
151  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
152  acc.merge(PoolReadCfg(flags))
153 
154  # Need geometry
155  from ActsConfig.ActsGeometryConfig import ActsTrackingGeometrySvcCfg
156  acc.merge( ActsTrackingGeometrySvcCfg(flags,
157  OutputLevel=INFO,
158  RunConsistencyChecks=False,
159  ObjDebugOutput=False))
160 
161  from PixelConditionsAlgorithms.ITkPixelConditionsConfig import ITkPixelDetectorElementStatusCondAlgNoByteStreamErrorsCfg
163 
164  from PixelDefectsEmulatorPostInclude import emulateITkPixelDefectsPoisson
166 
167  acc.printConfig(withDetails=True, summariseProps=True,printDefaults=True)
168  sc = acc.run()
169 
170  if sc.isFailure():
171  import sys
172  sys.exit(1)
PixelDefectsEmulatorConfig.ITkPixelDefectsEmulatorToDetectorElementStatusCondAlgCfg
ComponentAccumulator ITkPixelDefectsEmulatorToDetectorElementStatusCondAlgCfg(flags, str name="ITkPixelDefectsEmulatorToDetectorElementStatusCondAlgCfg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:115
PixelDefectsEmulatorConfig.DefectsHistSvcCfg
ComponentAccumulator DefectsHistSvcCfg(flags, str HistogramGroup="PixelDefects", str FileName='pixel_defects.root')
Definition: PixelDefectsEmulatorConfig.py:23
ActsGeometryConfig.ActsTrackingGeometrySvcCfg
ComponentAccumulator ActsTrackingGeometrySvcCfg(flags, str name="ActsTrackingGeometrySvc", **kwargs)
Definition: ActsGeometryConfig.py:6
PixelDefectsEmulatorConfig.PixelDefectsEmulatorCondAlgCfg
ComponentAccumulator PixelDefectsEmulatorCondAlgCfg(flags, str name="PixelDefectsEmulatorCondAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:34
AddressRemappingConfig.AddressRemappingCfg
def AddressRemappingCfg(renameMaps=[], overwriteMaps=[])
Definition: AddressRemappingConfig.py:10
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
PixelDefectsEmulatorConfig.ITkPixelDefectsEmulatorCondAlgCfg
ComponentAccumulator ITkPixelDefectsEmulatorCondAlgCfg(flags, str name="ITkPixelDefectsEmulatorCondAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:55
PixelDefectsEmulatorConfig.PixelDefectsEmulatorAlgCfg
ComponentAccumulator PixelDefectsEmulatorAlgCfg(flags, str name="PixelDefectsEmulatorAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:75
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
PixelDefectsEmulatorConfig.ITkPixelDefectsEmulatorAlgCfg
ComponentAccumulator ITkPixelDefectsEmulatorAlgCfg(flags, str name="ITkPixelDefectsEmulatorAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:95
Constants
some useful constants -------------------------------------------------—
PixelDefectsEmulatorPostInclude.emulateITkPixelDefectsPoisson
def emulateITkPixelDefectsPoisson(flags, cfg, FrontEndCCDefectProb=0.1, PixelDefectProb=1e-2, ModuleDefectProb=0., CornerDefectProb=0., NoiseProb=0., RngPerDefectType=False, DefectsInputFiles=[], DefectsOutputFile=None, PropagateDefectsToStatus=True, HistogramFileName=None)
Definition: PixelDefectsEmulatorPostInclude.py:377
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
PixelDefectsEmulatorConfig.ITkDefectsHistSvcCfg
ComponentAccumulator ITkDefectsHistSvcCfg(flags, HistogramGroup="ITkPixelDefects")
Definition: PixelDefectsEmulatorConfig.py:30
ITkPixelConditionsConfig.ITkPixelDetectorElementStatusCondAlgNoByteStreamErrorsCfg
def ITkPixelDetectorElementStatusCondAlgNoByteStreamErrorsCfg(flags, name="ITkPixelDetectorElementStatusCondAlgNoByteStreamErrors", **kwargs)
Definition: ITkPixelConditionsConfig.py:165
PixelDefectsEmulatorConfig.PixelRDORemappingCfg
def PixelRDORemappingCfg(flags, InputKey="PixelRDOs")
Definition: PixelDefectsEmulatorConfig.py:12
PixelDefectsEmulatorConfig.ITkPixelRDORemappingCfg
def ITkPixelRDORemappingCfg(flags)
Definition: PixelDefectsEmulatorConfig.py:20
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71