ATLAS Offline Software
PixelDefectsEmulatorConfig.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2024 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 
13 def PixelRDORemappingCfg(flags, InputKey="PixelRDOs") :
14  acc = ComponentAccumulator()
15 
16  from SGComps.AddressRemappingConfig import AddressRemappingCfg
17  renames = [ '%s#%s->%s' % ('PixelRDO_Container', InputKey, f"{InputKey}_ORIG") ]
18  acc.merge(AddressRemappingCfg( renameMaps = renames ))
19  return acc
20 
22  return PixelRDORemappingCfg(flags,"ITkPixelRDOs")
23 
24 def DefectsHistSvcCfg(flags, HistogramGroup: str="PixelDefects", FileName: str='pixel_defects.root') -> ComponentAccumulator:
25  acc = ComponentAccumulator()
26  if HistogramGroup is not None and len(HistogramGroup) > 0 and FileName is not None and len(FileName) > 0 :
27  print("DEBUG DefectsHistSvcCfg",HistogramGroup,FileName,[f"{HistogramGroup} DATAFILE='{FileName}', OPT='RECREATE'"])
28  histSvc = CompFactory.THistSvc(Output = [f"{HistogramGroup} DATAFILE='{FileName}', OPT='RECREATE'"] )
29  acc.addService(histSvc)
30  return acc
31 
32 def ITkDefectsHistSvcCfg(flags, HistogramGroup="ITkPixelDefects") -> ComponentAccumulator:
33  return DefectsHistSvcCfg(flags,HistogramGroup)
34 
35 
37  name: str = "PixelDefectsEmulatorCondAlg",
38  **kwargs: dict) -> ComponentAccumulator:
39  acc = ComponentAccumulator()
40  kwargs.setdefault("DefectProbability", 1e-4)
41  kwargs.setdefault("CoreColumnDefectProbability", 0.) # there are no core columns for run3 pixel modules
42  kwargs.setdefault("PixelDetEleCollKey", "PixelDetectorElementCollection")
43  kwargs.setdefault("WriteKey", "PixelEmulatedDefects")
44  kwargs.setdefault("HistogramGroupName","") # disable histogramming; enable: e.g. /PixelDefects/EmulatedDefects/
45 
46  acc.addCondAlgo(CompFactory.InDet.PixelDefectsEmulatorCondAlg(name,**kwargs))
47  return acc
48 
50  name: str = "ITkPixelDefectsEmulatorCondAlg",
51  **kwargs: dict) -> ComponentAccumulator:
52  kwargs.setdefault("DefectProbability", 1e-4)
53 
54  # 1-(1-prob_col_def )**n_col_groups
55  def probColGroupDefect(prob_col_group_defect_per_mod, n_col_groups) :
56  # prob of at least one defects per module : prob of not no defect per module
57  return 1. - pow( (1-prob_col_group_defect_per_mod), 1/(n_col_groups))
58  kwargs.setdefault("CoreColumnDefectProbability", probColGroupDefect(.1, 400/8.) ) # ~20 % prob / chip for 400/8. core groups / chip
59  kwargs.setdefault("PixelDetEleCollKey", "ITkPixelDetectorElementCollection")
60  kwargs.setdefault("WriteKey", "ITkPixelEmulatedDefects")
61 
62  return PixelDefectsEmulatorCondAlgCfg(flags,name,**kwargs)
63 
64 
66  name: str = "ITkPixelDefectsEmulatorAlg",
67  **kwargs: dict) -> ComponentAccumulator:
68  acc = ComponentAccumulator()
69 
70  if "InputKey" not in kwargs :
71  # rename original RDO collection
72  acc.merge(PixelRDORemappingCfg(flags))
73  kwargs.setdefault("InputKey","PixelRDOs_ORIG")
74 
75  if "EmulatedDefectsKey" not in kwargs :
76  # create defects conditions data
77  acc.merge( ITkPixelDefectsEmulatorCondAlgCfg(flags))
78  kwargs.setdefault("EmulatedDefectsKey", "PixelEmulatedDefects")
79  kwargs.setdefault("OutputKey","PixelRDOs")
80  kwargs.setdefault("HistogramGroupName","") # disable histogramming, enable e.g. /PixelDefects/RejectedRDOs/
81 
82  acc.addEventAlgo(CompFactory.InDet.PixelDefectsEmulatorAlg(name,**kwargs))
83  return acc
84 
86  name: str = "ITkPixelDefectsEmulatorAlg",
87  **kwargs: dict) -> ComponentAccumulator:
88  acc = ComponentAccumulator()
89  if "InputKey" not in kwargs :
90  # rename original RDO collection
91  acc.merge(ITkPixelRDORemappingCfg(flags))
92  kwargs.setdefault("InputKey","ITkPixelRDOs_ORIG")
93 
94  if "EmulatedDefectsKey" not in kwargs :
95  # create defects conditions data
96  acc.merge( ITkPixelDefectsEmulatorCondAlgCfg(flags))
97  kwargs.setdefault("EmulatedDefectsKey", "ITkPixelEmulatedDefects")
98  kwargs.setdefault("OutputKey","ITkPixelRDOs")
99 
100  kwargs.setdefault("HistogramGroupName","") # disable histogramming, enable e.g. /PixelDefects/RejectedRDOs/
101 
102  acc.addEventAlgo(CompFactory.InDet.PixelDefectsEmulatorAlg(name,**kwargs))
103  return acc
104 
105 
106 if __name__ == "__main__":
107 
108  flags = initConfigFlags()
109 
110  from AthenaConfiguration.Enums import ProductionStep
111  flags.Common.ProductionStep = ProductionStep.Simulation
112  from AthenaConfiguration.TestDefaults import defaultGeometryTags, defaultConditionsTags
113  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
114  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
115  flags.GeoModel.Align.Dynamic = False
116  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']
117 
118  flags.Detector.GeometryITkPixel = True
119  flags.Detector.GeometryITkStrip = True
120  flags.Detector.GeometryBpipe = True
121  flags.Detector.GeometryCalo = False
122 
123  flags.Concurrency.NumThreads = 8
124  flags.Concurrency.NumConcurrentEvents = 8
125 
126  flags.Exec.MaxEvents = 10
127 
128  flags.lock()
129  flags.dump()
130 
131  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
132  acc = MainServicesCfg( flags )
133  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
134  acc.merge(PoolReadCfg(flags))
135 
136  # Need geometry
137  from ActsConfig.ActsGeometryConfig import ActsTrackingGeometrySvcCfg
138  acc.merge( ActsTrackingGeometrySvcCfg(flags,
139  OutputLevel=INFO,
140  RunConsistencyChecks=False,
141  ObjDebugOutput=False))
142 
143  acc.merge( ITkPixelDefectsEmulatorAlgCfg(flags,
144  OutputLevel=INFO))
145 
146  acc.printConfig(withDetails=True, summariseProps=True,printDefaults=True)
147  sc = acc.run()
148 
149  if sc.isFailure():
150  import sys
151  sys.exit(1)
PixelDefectsEmulatorConfig.DefectsHistSvcCfg
ComponentAccumulator DefectsHistSvcCfg(flags, str HistogramGroup="PixelDefects", str FileName='pixel_defects.root')
Definition: PixelDefectsEmulatorConfig.py:24
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:36
AddressRemappingConfig.AddressRemappingCfg
def AddressRemappingCfg(renameMaps=[], overwriteMaps=[])
Definition: AddressRemappingConfig.py:10
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
PixelDefectsEmulatorConfig.PixelDefectsEmulatorAlgCfg
ComponentAccumulator PixelDefectsEmulatorAlgCfg(flags, str name="ITkPixelDefectsEmulatorAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:65
PixelDefectsEmulatorConfig.ITkPixelDefectsEmulatorCondAlgCfg
ComponentAccumulator ITkPixelDefectsEmulatorCondAlgCfg(flags, str name="ITkPixelDefectsEmulatorCondAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:49
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
PixelDefectsEmulatorConfig.ITkPixelDefectsEmulatorAlgCfg
ComponentAccumulator ITkPixelDefectsEmulatorAlgCfg(flags, str name="ITkPixelDefectsEmulatorAlg", **dict kwargs)
Definition: PixelDefectsEmulatorConfig.py:85
Constants
some useful constants -------------------------------------------------—
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
PixelDefectsEmulatorConfig.ITkDefectsHistSvcCfg
ComponentAccumulator ITkDefectsHistSvcCfg(flags, HistogramGroup="ITkPixelDefects")
Definition: PixelDefectsEmulatorConfig.py:32
PixelDefectsEmulatorConfig.PixelRDORemappingCfg
def PixelRDORemappingCfg(flags, InputKey="PixelRDOs")
Definition: PixelDefectsEmulatorConfig.py:13
PixelDefectsEmulatorConfig.ITkPixelRDORemappingCfg
def ITkPixelRDORemappingCfg(flags)
Definition: PixelDefectsEmulatorConfig.py:21
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15