From c94b4872a8aab6e831ee2fa13cca0a9dfa46c302 Mon Sep 17 00:00:00 2001
From: John Chapman <jchapman@cern.ch>
Date: Wed, 30 Jan 2019 15:42:27 +0100
Subject: [PATCH] Extend MuonGeoModelCfg to support geometry building for
 simulation jobs

---
 .../MuonConfig/python/MuonGeometryConfig.py   | 37 +++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/MuonSpectrometer/MuonConfig/python/MuonGeometryConfig.py b/MuonSpectrometer/MuonConfig/python/MuonGeometryConfig.py
index d3c05941d48..378db9f7990 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonGeometryConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonGeometryConfig.py
@@ -1,10 +1,13 @@
-# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 
 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
-from AtlasGeoModel.GeoModelConfig import GeoModelCfg    
+from AtlasGeoModel.GeoModelConfig import GeoModelCfg
 from MuonGeoModel.MuonGeoModelConf import MuonDetectorTool
 from MuonIdHelpers.MuonIdHelpersConf import Muon__MuonIdHelperTool
+from AGDD2GeoSvc.AGDD2GeoSvcConf import AGDDtoGeoSvc
+from MuonAGDD.MuonAGDDConf import MuonAGDDTool, NSWAGDDTool
 from StoreGate.StoreGateConf import StoreGateSvc
+import os
 
 def MuonGeoModelCfg(flags):
     acc = ComponentAccumulator()
@@ -15,7 +18,35 @@ def MuonGeoModelCfg(flags):
 
     detTool = MuonDetectorTool()
     detTool.UseConditionDb = 1
-    detTool.UseIlinesFromGM = 1    
+    detTool.UseIlinesFromGM = 1
+    if ( ( not flags.Detector.SimulateMuon or flags.Detector.OverlayMuon ) and "AthSimulation_DIR" not in os.environ ):
+        # Needs configuration from MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonAlignConfig.py to be migrated
+        #detTool.TheMuonAlignmentTool = "MuonAlignmentDbTool/MGM_AlignmentDbTool"
+        pass
+    else:
+        detTool.TheMuonAlignmentTool = ""
+        detTool.UseConditionDb = 0
+        detTool.UseAsciiConditionData = 0
+        if flags.Detector.SimulateMuon:
+            detTool.FillCacheInitTime = 0
+            if flags.GeoModel.Run=="RUN3" or flags.GeoModel.Run=="RUN4":
+                MuonDetectorTool.StationSelection  = 2
+                MuonDetectorTool.SelectedStations  = [ "EIL1", "EIL2", "EIL6", "EIL7",
+                                                       "EIS*", "EIL10", "EIL11", "EIL12",
+                                                       "EIL17", "CSS*", "CSL*", "T4E*",
+                                                       "T4F*" ]
+            ## Additional material in the muon system
+            AGDD2Geo = AGDDtoGeoSvc()
+            muonAGDDTool = MuonAGDDTool("MuonSpectrometer", BuildNSW=False)
+            acc.addPublicTool(muonAGDDTool)
+            AGDD2Geo.Builders += [ muonAGDDTool ]
+            if flags.GeoModel.Run=="RUN3" or flags.GeoModel.Run=="RUN4":
+                nswAGDDTool = NSWAGDDTool("NewSmallWheel", Locked=False)
+                nswAGDDTool.Volumes = ["NewSmallWheel"]
+                nswAGDDTool.DefaultDetector = "Muon"
+                acc.addPublicTool(nswAGDDTool)
+            acc.addService(AGDD2Geo)
+
     gms.DetectorTools += [ detTool ]
     acc.addService(gms)
 
-- 
GitLab