ATLAS Offline Software
MuonGeometryConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 from AthenaConfiguration.AccumulatorCache import AccumulatorCache
6 from AthenaConfiguration.Enums import ProductionStep
7 from AtlasGeoModel.GeoModelConfig import GeoModelCfg
8 from AthenaConfiguration.Enums import LHCPeriod
9 
10 def 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
15 def MuonIdHelperSvcCfg(flags):
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
28 def 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 
46 def 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 
100 def MuonAlignmentCondAlgCfg(flags, name="MuonAlignmentCondAlg", **kwargs):
101  acc = ComponentAccumulator()
102  # here define if I-lines (CSC internal alignment) are enabled
103  acc.merge(CscILineCondAlgCfg(flags))
104  # here define if As-Built (MDT chamber alignment) are enabled
105  if flags.Muon.Align.UseAsBuilt:
106  acc.merge(MdtAsBuiltCondAlgCfg(flags))
107  acc.merge(NswAsBuiltCondAlgCfg(flags))
108 
109  if not flags.Muon.Align.UseALines and not flags.Muon.Align.UseBLines:
110  return acc
111  from IOVDbSvc.IOVDbSvcConfig import addFolders
112 
113  onl = "/Onl" if flags.Common.isOnline and not flags.Input.isMC else ""
114  ParlineFolders = [f"/MUONALIGN{onl}/MDT/BARREL",
115  f"/MUONALIGN{onl}/MDT/ENDCAP/SIDEA",
116  f"/MUONALIGN{onl}/MDT/ENDCAP/SIDEC",
117  f"/MUONALIGN{onl}/TGC/SIDEA",
118  f"/MUONALIGN{onl}/TGC/SIDEC"]
119  acc.merge(addFolders( flags, ParlineFolders, 'MUONALIGN' if len(onl) else 'MUONALIGN_OFL', className='CondAttrListCollection'))
120 
121  if len(onl):
122  ParlineFolders = [ x[ :x.find(onl)] + x[x.find(onl) + len(onl): ] for x in ParlineFolders]
123 
124  kwargs.setdefault("LoadALines",flags.Muon.Align.UseALines)
125  kwargs.setdefault("LoadBLines",flags.Muon.Align.UseBLines)
126 
127  kwargs.setdefault("ParlineFolders", ParlineFolders)
128  MuonAlign = CompFactory.MuonAlignmentCondAlg(name, **kwargs)
129  acc.addCondAlgo(MuonAlign, primary = True)
130  return acc
131 
132 
134  acc = ComponentAccumulator()
135  from IOVDbSvc.IOVDbSvcConfig import addFolders
136  acc.merge(addFolders(flags, "/MUONALIGN/ERRS", "MUONALIGN_OFL", className="CondAttrListCollection"))
137  acc.addCondAlgo(CompFactory.MuonAlignmentErrorDbAlg("MuonAlignmentErrorDbAlg"))
138  return acc
139 
140 def NswAsBuiltCondAlgCfg(flags, name = "NswAsBuiltCondAlg", **kwargs):
141  result = ComponentAccumulator()
142 
143  if flags.GeoModel.Run < LHCPeriod.Run3:
144  return result
145  kwargs.setdefault("MicroMegaJSON","")
146  kwargs.setdefault("sTgcJSON","")
147 
148  kwargs.setdefault("ReadMmAsBuiltParamsKey","/MUONALIGN/ASBUILTPARAMS/MM")
149  #kwargs.setdefault("ReadSTgcAsBuiltParamsKey","/MUONALIGN/ASBUILTPARAMS/STGC") # This is the folder that sould be used once the as builts are validated, so keep it here but commented out
150  kwargs.setdefault("ReadSTgcAsBuiltParamsKey","") # for now diable the reading of sTGC as build from the conditions database
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', tag='MuonAlignAsBuiltParamsMm-RUN3-01-00'))
156 
157  if(not (kwargs["sTgcJSON"] or not kwargs["ReadSTgcAsBuiltParamsKey"])): # no need to add the folder if we are reading a json file anyhow
158  result.merge(addFolders( flags, kwargs["ReadSTgcAsBuiltParamsKey"], 'MUONALIGN_OFL', className='CondAttrListCollection', tag='MUONALIGN_STG_ASBUILT-001-03'))
159  the_alg = CompFactory.NswAsBuiltCondAlg(name, **kwargs)
160  result.addCondAlgo(the_alg, primary = True)
161  return result
162 
163 def sTGCAsBuiltCondAlg2Cfg(flags, name = "sTGCAsBuiltCondAlg2", **kwargs):
164  result = ComponentAccumulator()
165 
166  if flags.GeoModel.Run < LHCPeriod.Run3 or not flags.Muon.Align.UsesTGCAsBuild2:
167  return result
168  kwargs.setdefault("readFromJSON","")
169  if not kwargs["readFromJSON"] and False: # for now only allow reading from json since there is no database content available
170  kwargs.setdefault("ReadKey","/MUONALIGN/ASBUILTPARAMS/STGC") # This is the folder that sould be used once the as builts are validated, so keep it here but commented out
171  from IOVDbSvc.IOVDbSvcConfig import addFolders
172  result.merge(addFolders( flags, kwargs["ReadKey"], 'MUONALIGN_OFL', className='CondAttrListCollection', tag=''))
173  the_alg = CompFactory.sTGCAsBuiltCondAlg2(name,**kwargs)
174  result.addCondAlgo(the_alg, primary=True)
175  return result
176 
177 
178 
179 
180 def MdtAsBuiltCondAlgCfg(flags, name="MdtAsBuiltCondAlg", **kwargs):
181  result = ComponentAccumulator()
182  from IOVDbSvc.IOVDbSvcConfig import addFolders
183  if "readFromJSON" not in kwargs or not kwargs["readFromJSON"]:
184  result.merge(addFolders( flags, '/MUONALIGN/MDT/ASBUILTPARAMS' , 'MUONALIGN_OFL', className='CondAttrListCollection'))
185  the_alg = CompFactory.MdtAsBuiltCondAlg(name = name, **kwargs)
186  result.addCondAlgo(the_alg, primary = True)
187  return result
188 
189 def CscILineCondAlgCfg(flags, name="CscILinesCondAlg", **kwargs):
190  result = ComponentAccumulator()
191  if not flags.Muon.Align.UseILines:
192  return result
193  from IOVDbSvc.IOVDbSvcConfig import addFolders
194  if (flags.Common.isOnline and not flags.Input.isMC):
195  result.merge(addFolders( flags, ['/MUONALIGN/Onl/CSC/ILINES'], 'MUONALIGN', className='CondAttrListCollection'))
196  else:
197  result.merge(addFolders( flags, ['/MUONALIGN/CSC/ILINES'], 'MUONALIGN_OFL', className='CondAttrListCollection'))
198 
199  the_alg = CompFactory.CscILinesCondAlg(name, **kwargs)
200  result.addCondAlgo(the_alg, primary = True)
201  return result
202 
203 
204 @AccumulatorCache
205 def MuonDetectorCondAlgCfg(flags, name = "MuonDetectorCondAlg", **kwargs):
206  result = ComponentAccumulator()
207 
208  kwargs.setdefault("MuonDetectorTool", result.popToolsAndMerge(MuonDetectorToolCfg(flags)))
209  kwargs.setdefault("applyMmPassivation", flags.Muon.applyMMPassivation)
210 
211  if kwargs["applyMmPassivation"]:
212  from MuonConfig.MuonCondAlgConfig import NswPassivationDbAlgCfg
213  result.merge(NswPassivationDbAlgCfg(flags))
214  if flags.Muon.enableAlignment:
215  result.merge(MuonAlignmentCondAlgCfg(flags))
216  kwargs.setdefault("applyALines", flags.Muon.Align.UseALines)
217  kwargs.setdefault("applyBLines", flags.Muon.Align.UseBLines)
218  kwargs.setdefault("applyILines", flags.Muon.Align.UseILines)
219  kwargs.setdefault("applyNswAsBuilt", len([alg for alg in result.getCondAlgos() if alg.name == "NswAsBuiltCondAlg"])>0)
220  kwargs.setdefault("applysTGCAsBuilt2", len([alg for alg in result.getCondAlgos() if alg.name == "sTGCAsBuiltCondAlg2"])>0)
221  kwargs.setdefault("applyMdtAsBuilt", len([alg for alg in result.getCondAlgos() if alg.name == "MdtAsBuiltCondAlg"])>0)
222 
223 
224 
225  MuonDetectorManagerCond = CompFactory.MuonDetectorCondAlg(name, **kwargs)
226 
227  result.addCondAlgo(MuonDetectorManagerCond, primary = True)
228  return result
229 
230 
232  result = ComponentAccumulator()
233  geoModelSvc = result.getPrimaryAndMerge(GeoModelCfg(flags))
234  geoModelSvc.DetectorTools+= [result.popToolsAndMerge(MuonDetectorToolCfg(flags))]
235  return result
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
MuonGeoModelConfig.MuonAlignStoreCfg
def MuonAlignStoreCfg(flags)
Definition: MuonGeoModelConfig.py:84
python.MuonGeometryConfig.MuonAlignmentCondAlgCfg
def MuonAlignmentCondAlgCfg(flags, name="MuonAlignmentCondAlg", **kwargs)
Definition: MuonGeometryConfig.py:100
python.MuonGeometryConfig.MdtAsBuiltCondAlgCfg
def MdtAsBuiltCondAlgCfg(flags, name="MdtAsBuiltCondAlg", **kwargs)
Definition: MuonGeometryConfig.py:180
python.MuonGeometryConfig.sTGCAsBuiltCondAlg2Cfg
def sTGCAsBuiltCondAlg2Cfg(flags, name="sTGCAsBuiltCondAlg2", **kwargs)
Definition: MuonGeometryConfig.py:163
python.MuonCondAlgConfig.NswPassivationDbAlgCfg
def NswPassivationDbAlgCfg(flags, **kwargs)
Definition: MuonCondAlgConfig.py:326
python.MuonGeometryConfig.NswAsBuiltCondAlgCfg
def NswAsBuiltCondAlgCfg(flags, name="NswAsBuiltCondAlg", **kwargs)
Definition: MuonGeometryConfig.py:140
MuonReadoutGeomCnvCfg.MuonReadoutGeometryCnvAlgCfg
def MuonReadoutGeometryCnvAlgCfg(flags, name="MuonDetectorManagerCondAlg", **kwargs)
Definition: MuonReadoutGeomCnvCfg.py:7
python.MuonGeometryConfig.MuonIdHelperSvcCfg
def MuonIdHelperSvcCfg(flags)
Definition: MuonGeometryConfig.py:15
python.MuonGeometryConfig.TrackingVolumesSvcCfg
def TrackingVolumesSvcCfg(flags, name="TrackingVolumesSvc", **kwargs)
Definition: MuonGeometryConfig.py:10
python.MuonGeometryConfig.MuonDetectorToolCfg
def MuonDetectorToolCfg(flags, name="MuonDetectorTool", **kwargs)
Definition: MuonGeometryConfig.py:46
python.IOVDbSvcConfig.addFolders
def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:72
python.MuonGeometryConfig.CscILineCondAlgCfg
def CscILineCondAlgCfg(flags, name="CscILinesCondAlg", **kwargs)
Definition: MuonGeometryConfig.py:189
python.MuonGeometryConfig.MuonDetectorCondAlgCfg
def MuonDetectorCondAlgCfg(flags, name="MuonDetectorCondAlg", **kwargs)
Definition: MuonGeometryConfig.py:205
python.MuonGeometryConfig.MuonAlignmentErrorDbAlgCfg
def MuonAlignmentErrorDbAlgCfg(flags)
Definition: MuonGeometryConfig.py:133
python.MuonGeometryConfig.MuonGeoModelCfg
def MuonGeoModelCfg(flags)
Definition: MuonGeometryConfig.py:28
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
python.MuonGeometryConfig.MuonGeoModelToolCfg
def MuonGeoModelToolCfg(flags)
Definition: MuonGeometryConfig.py:231
python.GeoModelConfig.GeoModelCfg
def GeoModelCfg(flags)
Definition: GeoModelConfig.py:16