ATLAS Offline Software
Loading...
Searching...
No Matches
MuonGeometryConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory import CompFactory
5from AthenaConfiguration.AccumulatorCache import AccumulatorCache
6from AthenaConfiguration.Enums import ProductionStep
7from AtlasGeoModel.GeoModelConfig import GeoModelCfg
8from AthenaConfiguration.Enums import LHCPeriod
9
10def TrackingVolumesSvcCfg(flags, name="TrackingVolumesSvc", **kwargs):
11 result = ComponentAccumulator()
12 trackingVolSvc = CompFactory.Trk.TrackingVolumesSvc(name=name, **kwargs)
13 result.addService(trackingVolSvc, primary=True)
14 return result
16 acc = ComponentAccumulator()
17 acc.merge(GeoModelCfg(flags))
18 acc.addService( CompFactory.Muon.MuonIdHelperSvc("MuonIdHelperSvc",
19 HasCSC=flags.Detector.GeometryCSC,
20 HasSTGC=flags.Detector.GeometrysTGC,
21 HasMM=flags.Detector.GeometryMM,
22 HasMDT=flags.Detector.GeometryMDT,
23 HasRPC=flags.Detector.GeometryRPC,
24 HasTGC=flags.Detector.GeometryTGC), primary=True )
25 return acc
26
27@AccumulatorCache
28def MuonGeoModelCfg(flags):
29 result = ComponentAccumulator()
30 result.merge(MuonIdHelperSvcCfg(flags))
31 if flags.Muon.usePhaseIIGeoSetup:
32 from MuonGeoModelR4.MuonGeoModelConfig import MuonGeoModelCfg as MuonGeoModelCfgR4
33 result.merge(MuonGeoModelCfgR4(flags))
34 from MuonGeoModelR4.MuonGeoModelConfig import MuonAlignStoreCfg
35 result.merge(MuonAlignStoreCfg(flags))
36 if flags.Common.ProductionStep != ProductionStep.Simulation:
37 from MuonGeometryCnv.MuonReadoutGeomCnvCfg import MuonReadoutGeometryCnvAlgCfg
38 result.merge(MuonReadoutGeometryCnvAlgCfg(flags))
39 return result
40
41 result.merge(MuonGeoModelToolCfg(flags))
42 result.merge(MuonDetectorCondAlgCfg(flags))
43 return result
44
45
46def MuonDetectorToolCfg(flags, name = "MuonDetectorTool", **kwargs):
47 acc = ComponentAccumulator()
48 kwargs.setdefault("HasCSC", flags.Detector.GeometryCSC)
49 kwargs.setdefault("HasSTgc", flags.Detector.GeometrysTGC)
50 kwargs.setdefault("HasMM", flags.Detector.GeometryMM)
51
52 kwargs.setdefault("UseConditionDb", flags.Muon.enableAlignment)
53 kwargs.setdefault("UseAsciiConditionData", flags.Muon.enableAlignment)
54
55 UseIlinesFromGM = False
56 EnableCscInternalAlignment = False
57
58 if flags.Muon.enableAlignment:
59 if not flags.Input.isMC:
60 kwargs.setdefault("BEENoShift", True)
61 # here define if I-lines (CSC internal alignment) are enabled
62 if flags.Muon.Align.UseILines and flags.Detector.GeometryCSC:
63 if 'HLT' in flags.IOVDb.GlobalTag:
64 #logMuon.info("Reading CSC I-Lines from layout - special configuration for COMP200 in HLT setup.")
65 UseIlinesFromGM = True
66 EnableCscInternalAlignment = False
67 else :
68 #logMuon.info("Reading CSC I-Lines from conditions database.")
69 if (flags.Common.isOnline and not flags.Input.isMC):
70 EnableCscInternalAlignment = True
71 else:
72 UseIlinesFromGM = False
73 EnableCscInternalAlignment = True
74
75 kwargs.setdefault("UseIlinesFromGM", UseIlinesFromGM)
76 kwargs.setdefault("EnableCscInternalAlignment", EnableCscInternalAlignment)
77
78 if not flags.GeoModel.SQLiteDB:
79
80 AGDD2Geo = CompFactory.AGDDtoGeoSvc()
81 muonAGDDTool = CompFactory.MuonAGDDTool("MuonSpectrometer", BuildNSW=False)
82 AGDD2Geo.Builders += [ muonAGDDTool ]
83 if (flags.Detector.GeometrysTGC and flags.Detector.GeometryMM):
84 nswAGDDTool = CompFactory.NSWAGDDTool("NewSmallWheel", Locked=False)
85 nswAGDDTool.Volumes = ["NewSmallWheel"]
86 nswAGDDTool.DefaultDetector = "Muon"
87 AGDD2Geo.Builders += [ nswAGDDTool ]
88
89 #create=True is needed for the service to be initialised in the new style
90 acc.addService(AGDD2Geo, create=True)
91
92
93 acc.merge(MuonIdHelperSvcCfg(flags))
94
95 detTool = CompFactory.MuonDetectorTool(name, **kwargs)
96 acc.setPrivateTools(detTool)
97 return acc
98
99
100def MuonAlignmentCondAlgCfg(flags, name="MuonAlignmentCondAlg", **kwargs):
101 acc = ComponentAccumulator()
102
103 # here define if I-lines (CSC internal alignment) are enabled
104 acc.merge(CscILineCondAlgCfg(flags))
105 # here define if As-Built (MDT chamber alignment) are enabled
106 if flags.Muon.Align.UseAsBuilt:
107 acc.merge(MdtAsBuiltCondAlgCfg(flags))
108 acc.merge(NswAsBuiltCondAlgCfg(flags))
109 if(flags.Muon.Align.UsesTGCAsBuild):
110 acc.merge(sTGCAsBuiltCondAlgCfg(flags))
111
112 if not flags.Muon.Align.UseALines and not flags.Muon.Align.UseBLines:
113 return acc
114 from IOVDbSvc.IOVDbSvcConfig import addFolders
115
116 onl = "/Onl" if ((flags.Common.isOnline or flags.IOVDb.GlobalTag.startswith("CONDBR2-HLTP")) and not flags.Input.isMC) else ""
117 ParlineFolders = [f"/MUONALIGN{onl}/MDT/BARREL",
118 f"/MUONALIGN{onl}/MDT/ENDCAP/SIDEA",
119 f"/MUONALIGN{onl}/MDT/ENDCAP/SIDEC",
120 f"/MUONALIGN{onl}/TGC/SIDEA",
121 f"/MUONALIGN{onl}/TGC/SIDEC"]
122 acc.merge(addFolders( flags, ParlineFolders, 'MUONALIGN' if len(onl) else 'MUONALIGN_OFL', className='CondAttrListCollection'))
123
124 if len(onl):
125 ParlineFolders = [ x[ :x.find(onl)] + x[x.find(onl) + len(onl): ] for x in ParlineFolders]
126
127 kwargs.setdefault("LoadALines", flags.Muon.Align.UseALines)
128 kwargs.setdefault("LoadBLines", flags.Muon.Align.UseBLines)
129
130 kwargs.setdefault("ParlineFolders", ParlineFolders)
131 MuonAlign = CompFactory.MuonAlignmentCondAlg(name, **kwargs)
132 acc.addCondAlgo(MuonAlign, primary = True)
133 return acc
134
135
137 acc = ComponentAccumulator()
138 from IOVDbSvc.IOVDbSvcConfig import addFolders
139 acc.merge(addFolders(flags, "/MUONALIGN/ERRS", "MUONALIGN_OFL", className="CondAttrListCollection"))
140 acc.addCondAlgo(CompFactory.MuonAlignmentErrorDbAlg("MuonAlignmentErrorDbAlg"))
141 return acc
142
143def NswAsBuiltCondAlgCfg(flags, name = "NswAsBuiltCondAlg", **kwargs):
144 result = ComponentAccumulator()
145
146 if flags.GeoModel.Run < LHCPeriod.Run3:
147 return result
148 kwargs.setdefault("MicroMegaJSON","")
149
150 kwargs.setdefault("ReadMmAsBuiltParamsKey","/MUONALIGN/ASBUILTPARAMS/MM")
151
152
153 from IOVDbSvc.IOVDbSvcConfig import addFolders
154 if(not (kwargs["MicroMegaJSON"] or not kwargs["ReadMmAsBuiltParamsKey"]) ) : # no need to add the folder if we are reading a json file anyhow
155 result.merge(addFolders( flags, kwargs["ReadMmAsBuiltParamsKey"] , 'MUONALIGN_OFL', className='CondAttrListCollection'))
156 the_alg = CompFactory.NswAsBuiltCondAlg(name, **kwargs)
157 result.addCondAlgo(the_alg, primary = True)
158 return result
159
160def sTGCAsBuiltCondAlgCfg(flags, name = "sTGCAsBuiltCondAlg", **kwargs):
161 result = ComponentAccumulator()
162
163 if flags.GeoModel.Run < LHCPeriod.Run3 or not flags.Muon.Align.UsesTGCAsBuild:
164 return result
165 kwargs.setdefault("readFromJSON","")
166 if not kwargs["readFromJSON"]:
167 kwargs.setdefault("ReadKey","/MUONALIGN/ASBUILTPARAMS/STGC")
168 from IOVDbSvc.IOVDbSvcConfig import addFolders
169 result.merge(addFolders( flags, kwargs["ReadKey"], 'MUONALIGN_OFL', className='CondAttrListCollection', tag = 'MUONALIGN_STG_IntAl_alCons_noQL3_v01'))
170 the_alg = CompFactory.sTGCAsBuiltCondAlg(name,**kwargs)
171 result.addCondAlgo(the_alg, primary=True)
172 return result
173
174# since the MM as built 2 corrections are not supossed to run in standart reco job just a fragment to activate them in a postExex is provided
175def activateMmAsBuilt2PostExec(flags, cfg, **kwargs):
176
177 name = "MmAsBuilt2CondAlg"
178 if flags.GeoModel.Run != LHCPeriod.Run3:
179 return
180 kwargs.setdefault("readFromJSON","")
181 kwargs.setdefault("WriteKey","MmAsBuilt2")
182 the_alg = CompFactory.sTGCAsBuiltCondAlg(name,**kwargs)
183 cfg.addCondAlgo(the_alg, primary=True)
184
185 cfg.getCondAlgo("MuonDetectorCondAlg").applyMmAsBuilt2=True
186 cfg.getCondAlgo("MuonDetectorCondAlg").ReadMmAsBuilt2Key = kwargs["WriteKey"]
187
188
189
190
191def MdtAsBuiltCondAlgCfg(flags, name="MdtAsBuiltCondAlg", **kwargs):
192 result = ComponentAccumulator()
193 if not flags.Detector.GeometryMDT:
194 return result
195 from IOVDbSvc.IOVDbSvcConfig import addFolders
196 if "readFromJSON" not in kwargs or not kwargs["readFromJSON"]:
197 result.merge(addFolders( flags, '/MUONALIGN/MDT/ASBUILTPARAMS' , 'MUONALIGN_OFL', className='CondAttrListCollection'))
198 the_alg = CompFactory.MdtAsBuiltCondAlg(name = name, **kwargs)
199 result.addCondAlgo(the_alg, primary = True)
200 return result
201
202def CscILineCondAlgCfg(flags, name="CscILinesCondAlg", **kwargs):
203 result = ComponentAccumulator()
204 if not flags.Muon.Align.UseILines:
205 return result
206 from IOVDbSvc.IOVDbSvcConfig import addFolders
207 if (flags.Common.isOnline and not flags.Input.isMC):
208 result.merge(addFolders( flags, ['/MUONALIGN/Onl/CSC/ILINES'], 'MUONALIGN', className='CondAttrListCollection'))
209 else:
210 result.merge(addFolders( flags, ['/MUONALIGN/CSC/ILINES'], 'MUONALIGN_OFL', className='CondAttrListCollection'))
211
212 the_alg = CompFactory.CscILinesCondAlg(name, **kwargs)
213 result.addCondAlgo(the_alg, primary = True)
214 return result
215
216
217@AccumulatorCache
218def MuonDetectorCondAlgCfg(flags, name = "MuonDetectorCondAlg", **kwargs):
219 result = ComponentAccumulator()
220
221 kwargs.setdefault("MuonDetectorTool", result.popToolsAndMerge(MuonDetectorToolCfg(flags)))
222 kwargs.setdefault("applyMmPassivation", flags.Muon.applyMMPassivation)
223
224 if kwargs["applyMmPassivation"]:
225 from MuonConfig.MuonCondAlgConfig import NswPassivationDbAlgCfg
226 result.merge(NswPassivationDbAlgCfg(flags))
227 if flags.Muon.enableAlignment:
228 result.merge(MuonAlignmentCondAlgCfg(flags))
229 kwargs.setdefault("applyALines", flags.Muon.Align.UseALines)
230 kwargs.setdefault("applyBLines", flags.Muon.Align.UseBLines)
231 kwargs.setdefault("applyILines", flags.Muon.Align.UseILines)
232 kwargs.setdefault("applyNswAsBuilt", len([alg for alg in result.getCondAlgos() if alg.name == "NswAsBuiltCondAlg"])>0)
233 kwargs.setdefault("applysTGCAsBuilt", len([alg for alg in result.getCondAlgos() if alg.name == "sTGCAsBuiltCondAlg"])>0)
234 kwargs.setdefault("applyMdtAsBuilt", len([alg for alg in result.getCondAlgos() if alg.name == "MdtAsBuiltCondAlg"])>0)
235
236
237
238 MuonDetectorManagerCond = CompFactory.MuonDetectorCondAlg(name, **kwargs)
239
240 result.addCondAlgo(MuonDetectorManagerCond, primary = True)
241 return result
242
243
245 result = ComponentAccumulator()
246 geoModelSvc = result.getPrimaryAndMerge(GeoModelCfg(flags))
247 geoModelSvc.DetectorTools+= [result.popToolsAndMerge(MuonDetectorToolCfg(flags))]
248 return result
if(febId1==febId2)
MuonDetectorCondAlgCfg(flags, name="MuonDetectorCondAlg", **kwargs)
CscILineCondAlgCfg(flags, name="CscILinesCondAlg", **kwargs)
sTGCAsBuiltCondAlgCfg(flags, name="sTGCAsBuiltCondAlg", **kwargs)
MdtAsBuiltCondAlgCfg(flags, name="MdtAsBuiltCondAlg", **kwargs)
MuonDetectorToolCfg(flags, name="MuonDetectorTool", **kwargs)
NswAsBuiltCondAlgCfg(flags, name="NswAsBuiltCondAlg", **kwargs)
TrackingVolumesSvcCfg(flags, name="TrackingVolumesSvc", **kwargs)
MuonAlignmentCondAlgCfg(flags, name="MuonAlignmentCondAlg", **kwargs)
activateMmAsBuilt2PostExec(flags, cfg, **kwargs)