ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 
5 def geoModelFileDefault(useR4Layout = False):
6  # If this is changed, remember to also test with other dependent tests
7  # e.g. run ctest with ActsEventCnv
8  if useR4Layout:
9  return "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonGeomRTT/GeoDB/ATLAS-P2-RUN4-01-00-00.db"
10  return "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonGeomRTT/GeoDB/ATLAS-R3S-2021-03-02-00.db"
11 
12 def SetupArgParser():
13  from argparse import ArgumentParser
14 
15  parser = ArgumentParser()
16  parser.add_argument("--threads", type=int, help="number of threads", default=1)
17  parser.add_argument("--inputFile", "-i", default=[
18  #"/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/Tier0ChainTests/TCT_Run3/data22_13p6TeV.00431493.physics_Main.daq.RAW._lb0525._SFO-16._0001.data"
19  "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonRecRTT/EVGEN_ParticleGun_FourMuon_Pt10to500.root"
20  ],
21  help="Input file to run on ", nargs="+")
22  parser.add_argument("--geoModelFile", default = geoModelFileDefault(), help="GeoModel SqLite file containing the muon geometry.")
23  parser.add_argument("--defaultGeoFile", help="Use the predefined GeoModel files on cvmfs", choices=["NONE", "RUN3", "RUN4" ], default="NONE")
24  parser.add_argument("--chambers", default=["all"], nargs="+", help="Chambers to check. If string is all, all chambers will be checked")
25  parser.add_argument("--excludedChambers", default=[], nargs="+", help="Chambers to exclude. If string contains 'none', all chambers will be checked. Note: adding a chamber to --excludedChambers will overwrite it being in --chambers.")
26  parser.add_argument("--outRootFile", default="NewGeoModelDump.root", help="Output ROOT file to dump the geomerty")
27  parser.add_argument("--nEvents", help="Number of events to run", type = int ,default = 1)
28  parser.add_argument("--skipEvents", help="Number of events to skip", type = int, default = 0)
29  parser.add_argument("--noMdt", help="Disable the Mdts from the geometry", action='store_true', default = False)
30  parser.add_argument("--noRpc", help="Disable the Rpcs from the geometry", action='store_true', default = False)
31  parser.add_argument("--noTgc", help="Disable the Tgcs from the geometry", action='store_true', default = False)
32  parser.add_argument("--noMM", help="Disable the MMs from the geometry", action='store_true', default = False)
33  parser.add_argument("--noSTGC", help="Disable the sTgcs from the geometry", action='store_true', default = False)
34  parser.add_argument("--eventPrintoutLevel", type=int, help="Interval of event heartbeat printouts from the loop manager", default = 1)
35  return parser
36 
37 def setupServicesCfg(flags):
38  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
39  result = MainServicesCfg(flags)
40 
41  from AthenaConfiguration.Enums import Format
42  if flags.Input.Format is Format.POOL:
43  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
44  result.merge(PoolReadCfg(flags))
45  elif flags.Input.Format == Format.BS:
46  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
47  result.merge(ByteStreamReadCfg(flags))
48 
49  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
50  result.merge(PerfMonMTSvcCfg(flags))
51  from MuonConfig.MuonGeometryConfig import MuonIdHelperSvcCfg
52  result.merge(MuonIdHelperSvcCfg(flags))
53  return result
54 
55 def GeoModelMdtTestCfg(flags, name = "GeoModelMdtTest", **kwargs):
56  result = ComponentAccumulator()
57  the_alg = CompFactory.MuonGMR4.GeoModelMdtTest(name, **kwargs)
58  result.addEventAlgo(the_alg, primary = True)
59  return result
60 
61 def GeoModelRpcTestCfg(flags, name = "GeoModelRpcTest", **kwargs):
62  result = ComponentAccumulator()
63  the_alg = CompFactory.MuonGMR4.GeoModelRpcTest(name, **kwargs)
64  result.addEventAlgo(the_alg, primary = True)
65  return result
66 
67 def GeoModelTgcTestCfg(flags, name = "GeoModelTgcTest", **kwargs):
68  result = ComponentAccumulator()
69  the_alg = CompFactory.MuonGMR4.GeoModelTgcTest(name, **kwargs)
70  result.addEventAlgo(the_alg, primary = True)
71  return result
72 
73 def GeoModelsTgcTestCfg(flags, name = "GeoModelsTgcTest", **kwargs):
74  result = ComponentAccumulator()
75  the_alg = CompFactory.MuonGMR4.GeoModelsTgcTest(name, **kwargs)
76  result.addEventAlgo(the_alg, primary = True)
77  return result
78 
79 def GeoModelMmTestCfg(flags, name = "GeoModelMmTest", **kwargs):
80  result = ComponentAccumulator()
81  the_alg = CompFactory.MuonGMR4.GeoModelMmTest(name, **kwargs)
82  result.addEventAlgo(the_alg, primary = True)
83  return result
84 
85 def NswGeoPlottingAlgCfg(flags, name="NswGeoPlotting", **kwargs):
86  result = ComponentAccumulator()
87  kwargs.setdefault("TestActsSurface", True)
88  kwargs.setdefault("plotTgc", flags.Detector.GeometryTGC)
89  kwargs.setdefault("plotStgc", flags.Detector.GeometrysTGC)
90  kwargs.setdefault("plotMm", flags.Detector.GeometryMM)
91 
92  the_alg = CompFactory.MuonGMR4.NswGeoPlottingAlg(name, **kwargs)
93  result.addEventAlgo(the_alg, primary = True)
94  return result
95 
97  from AthenaCommon.Logging import logging
98  log = logging.getLogger('GeometryConfiguration')
99 
100  if not flags.GeoModel.SQLiteDB:
101  raise ValueError("Default tag configuration only works for SQLite")
102 
103  from AthenaConfiguration.TestDefaults import defaultGeometryTags
104  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
105  from AthenaConfiguration.Enums import LHCPeriod
106  if flags.GeoModel.Run == LHCPeriod.Run3:
107  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
108  elif flags.GeoModel.Run == LHCPeriod.Run4:
109  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
110  else:
111  raise ValueError(f"Invalid run period {flags.GeoModel.Run}")
112  from MuonConfig.MuonConfigUtils import configureCondTag
113  configureCondTag(flags)
114 
115  log.info(f"Setup {flags.GeoModel.AtlasVersion} geometry loading {flags.GeoModel.SQLiteDBFullPath}")
116  log.info(f"Use conditions tag {flags.IOVDb.GlobalTag}")
117 
118 
119 def setupGeoR4TestCfg(args, flags = None):
120 
121  if flags is None:
122  from AthenaConfiguration.AllConfigFlags import initConfigFlags
123  flags = initConfigFlags()
124  flags.Concurrency.NumThreads = args.threads
125  flags.Concurrency.NumConcurrentEvents = args.threads
126  flags.Exec.MaxEvents = args.nEvents
127  flags.Exec.SkipEvents = args.skipEvents
128  from os import path, system, listdir
129  flags.Input.Files = []
130 
132  for fileArg in args.inputFile:
133  if path.isdir(fileArg):
134  flags.Input.Files += [ "{dir}/{file}".format(dir=fileArg, file=y) for y in listdir(fileArg) ]
135  else:
136  if fileArg[fileArg.rfind(".")+1 :]not in ["txt", "conf"]:
137  flags.Input.Files+=[fileArg]
138  else:
139  with open(fileArg) as inStream:
140  flags.Input.Files+=[ line.strip() for line in inStream if line[0]!='#']
141 
142  flags.Exec.FPE= 500
143  flags.Exec.EventPrintoutInterval = 500
144 
145  if args.defaultGeoFile == "RUN3":
146  flags.GeoModel.SQLiteDBFullPath = geoModelFileDefault(useR4Layout = False)
147  elif args.defaultGeoFile == "RUN4":
148  flags.GeoModel.SQLiteDBFullPath = geoModelFileDefault(useR4Layout = True)
149  elif args.geoModelFile.startswith("root://"):
150  if not path.exists("Geometry/{geoTag}.db".format(geoTag=args.geoTag)):
151  print ("Copy geometry file from EOS {source}".format(source = args.geoModelFile))
152  system("mkdir Geometry/")
153  system("xrdcp {source} Geometry/{geoTag}.db".format(source = args.geoModelFile,
154  geoTag=args.geoTag))
155 
156  args.geoModelFile = "Geometry/{geoTag}.db".format(geoTag=args.geoTag)
157  else:
158  flags.GeoModel.SQLiteDBFullPath = args.geoModelFile
159 
160  flags.GeoModel.SQLiteDB = True
162 
163  flags.Detector.GeometryBpipe = False
164 
165  flags.Detector.GeometryBCM = False
166  flags.Detector.GeometryPixel = False
167  flags.Detector.GeometrySCT = False
168  flags.Detector.GeometryTRT = False
169 
170  flags.Detector.GeometryPLR = False
171  flags.Detector.GeometryBCMPrime = False
172  flags.Detector.GeometryITkPixel = False
173  flags.Detector.GeometryITkStrip = False
174 
175  flags.Detector.GeometryHGTD = False
176 
177  flags.Detector.GeometryLAr = False
178  flags.Detector.GeometryTile = False
179  flags.Detector.GeometryMBTS = False
180  flags.Detector.GeometryCalo = False
181 
182  flags.Detector.GeometryCSC = False
183  if args.noSTGC:
184  flags.Detector.GeometrysTGC = False
185  if args.noMM:
186  flags.Detector.GeometryMM = False
187  if args.noTgc:
188  flags.Detector.GeometryTGC = False
189  if args.noRpc:
190  flags.Detector.GeometryRPC = False
191  if args.noMdt:
192  flags.Detector.GeometryMDT = False
193 
194  flags.Scheduler.CheckDependencies = True
195  flags.Scheduler.ShowDataDeps = True
196  flags.Scheduler.ShowDataFlow = True
197  flags.Scheduler.ShowControlFlow = True
198  flags.Scheduler.EnableVerboseViews = True
199  flags.Scheduler.AutoLoadUnmetDependencies = True
200  #flags.PerfMon.doFullMonMT = True
201  flags.lock()
202  flags.dump(evaluate = True)
203  cfg = setupServicesCfg(flags)
204 
205  from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
206  cfg.merge(MuonGeoModelCfg(flags))
207 
208 
209  if not flags.Muon.usePhaseIIGeoSetup:
210  print ("WARNING: New Muon plugin is not part of the Geometry file {geoDBFile}".format(geoDBFile=args.geoModelFile))
211  else:
212  from ActsAlignmentAlgs.AlignmentAlgsConfig import ActsGeometryContextAlgCfg
213  cfg.merge(ActsGeometryContextAlgCfg(flags))
214 
215  cfg.getService("MessageSvc").verboseLimit = 10000000
216  cfg.getService("MessageSvc").debugLimit = 10000000
217 
218  return flags, cfg
219 
220 def executeTest(cfg):
221  cfg.printConfig(withDetails=True, summariseProps=True)
222  if not cfg.run().isSuccess(): exit(1)
223 
224 if __name__=="__main__":
225  args = SetupArgParser().parse_args()
226  flags, cfg = setupGeoR4TestCfg(args)
227  from MuonConfig.MuonConfigUtils import setupHistSvcCfg
228  cfg.merge(setupHistSvcCfg(flags, outFile = args.outRootFile, outStream="GEOMODELTESTER"))
229  chambToTest = args.chambers if len([x for x in args.chambers if x =="all"]) ==0 else []
230  chambToExclude = args.excludedChambers
231 
232 
233  if flags.Muon.usePhaseIIGeoSetup:
234  cfg.getCondAlgo("MuonDetectorCondAlg").checkGeo = True
235  from TrackingGeometryCondAlg.AtlasTrackingGeometryCondAlgConfig import TrackingGeometryCondAlgCfg
236  cfg.merge(TrackingGeometryCondAlgCfg(flags))
237 
238 
239  cfg.getService("MessageSvc").setVerbose = []
240 
241  if flags.Detector.GeometryMDT:
242  if not flags.Muon.usePhaseIIGeoSetup:
243  from MuonGeoModelTest.testGeoModel import GeoModelMdtTestCfg as LegacyTestCfg
244  cfg.merge(LegacyTestCfg(flags,
245  TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
246  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"]))
247  else:
248  cfg.merge(GeoModelMdtTestCfg(flags,
249  TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
250  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"],
251  ReadoutSideXML="ReadoutSides.xml",
252  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
253 
254  if flags.Detector.GeometryRPC:
255  if not flags.Muon.usePhaseIIGeoSetup:
256  from MuonGeoModelTest.testGeoModel import GeoModelRpcTestCfg as LegacyTestCfg
257  cfg.merge(LegacyTestCfg(flags,
258  TestStations = [ch for ch in chambToTest if ch[0] == "B"],
259  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"]))
260  else:
261  cfg.merge(GeoModelRpcTestCfg(flags,
262  TestStations = [ch for ch in chambToTest if ch[0] == "B"],
263  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"],
264  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
265 
266  if flags.Detector.GeometryTGC:
267  if not flags.Muon.usePhaseIIGeoSetup:
268  from MuonGeoModelTest.testGeoModel import GeoModelTgcTestCfg as LegacyTestCfg
269  cfg.merge(LegacyTestCfg(flags,
270  TestStations = [ch for ch in chambToTest if ch[0] == "T"],
271  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"]))
272  else:
273  cfg.merge(GeoModelTgcTestCfg(flags,
274  TestStations = [ch for ch in chambToTest if ch[0] == "T"],
275  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"],
276  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
277 
278  if flags.Detector.GeometryMM:
279  if not flags.Muon.usePhaseIIGeoSetup:
280  from MuonGeoModelTest.testGeoModel import GeoModelMmTestCfg as LegacyTestCfg
281  cfg.merge(LegacyTestCfg(flags,
282  TestStations = [ch for ch in chambToTest if ch[0] == "M"],
283  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"]))
284  else:
285  cfg.merge(GeoModelMmTestCfg(flags,
286  TestStations = [ch for ch in chambToTest if ch[0] == "M"],
287  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"],
288  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
289 
290  if flags.Detector.GeometrysTGC:
291  if not flags.Muon.usePhaseIIGeoSetup:
292  from MuonGeoModelTest.testGeoModel import GeoModelsTgcTestCfg as LegacyTestCfg
293  cfg.merge(LegacyTestCfg(flags,
294  TestStations = [ch for ch in chambToTest if ch[0] == "S"],
295  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"]))
296  else:
297  cfg.merge(GeoModelsTgcTestCfg(flags,
298  TestStations = [ch for ch in chambToTest if ch[0] == "S"],
299  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"],
300  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
301 
302  executeTest(cfg)
testGeoModel.setupServicesCfg
def setupServicesCfg(flags)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:37
testGeoModel.GeoModelMmTestCfg
def GeoModelMmTestCfg(flags, name="GeoModelMmTest", **kwargs)
Definition: MuonDetDescr/MuonGeoModelTest/python/testGeoModel.py:60
testGeoModel.GeoModelTgcTestCfg
def GeoModelTgcTestCfg(flags, name="GeoModelTgcTest", **kwargs)
Definition: MuonDetDescr/MuonGeoModelTest/python/testGeoModel.py:54
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
MuonGeometryConfig.MuonIdHelperSvcCfg
def MuonIdHelperSvcCfg(flags)
Definition: MuonGeometryConfig.py:15
testGeoModel.geoModelFileDefault
def geoModelFileDefault(useR4Layout=False)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:5
AtlasTrackingGeometryCondAlgConfig.TrackingGeometryCondAlgCfg
def TrackingGeometryCondAlgCfg(flags, name='AtlasTrackingGeometryCondAlg', doMaterialValidation=False, **kwargs)
Definition: AtlasTrackingGeometryCondAlgConfig.py:131
python.dummyaccess.listdir
def listdir(dirname)
Definition: dummyaccess.py:6
testGeoModel.NswGeoPlottingAlgCfg
def NswGeoPlottingAlgCfg(flags, name="NswGeoPlotting", **kwargs)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:85
testGeoModel.GeoModelMdtTestCfg
def GeoModelMdtTestCfg(flags, name="GeoModelMdtTest", **kwargs)
Definition: MuonDetDescr/MuonGeoModelTest/python/testGeoModel.py:38
testGeoModel.GeoModelRpcTestCfg
def GeoModelRpcTestCfg(flags, name="GeoModelRpcTest", **kwargs)
Definition: MuonDetDescr/MuonGeoModelTest/python/testGeoModel.py:47
testGeoModel.SetupArgParser
def SetupArgParser()
Definition: MuonDetDescr/MuonGeoModelTest/python/testGeoModel.py:6
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
python.PerfMonCompsConfig.PerfMonMTSvcCfg
def PerfMonMTSvcCfg(flags, **kwargs)
A minimal new-style configuration for PerfMonMTSvc.
Definition: PerfMonCompsConfig.py:10
testGeoModel.executeTest
def executeTest(cfg)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:220
MuonGeometryConfig.MuonGeoModelCfg
def MuonGeoModelCfg(flags)
Definition: MuonGeometryConfig.py:28
testGeoModel.setupGeoR4TestCfg
def setupGeoR4TestCfg(args, flags=None)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:119
AlignmentAlgsConfig.ActsGeometryContextAlgCfg
def ActsGeometryContextAlgCfg(flags, name="GeometryContextAlg", **kwargs)
Setup the Geometry context algorithm.
Definition: AlignmentAlgsConfig.py:125
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
testGeoModel.GeoModelsTgcTestCfg
def GeoModelsTgcTestCfg(flags, name="GeoModelsTgcTest", **kwargs)
Definition: MuonDetDescr/MuonGeoModelTest/python/testGeoModel.py:67
calibdata.exit
exit
Definition: calibdata.py:235
MuonConfigUtils.configureCondTag
def configureCondTag(flags)
Definition: MuonConfigUtils.py:19
Trk::open
@ open
Definition: BinningType.h:40
testGeoModel.configureDefaultTagsCfg
def configureDefaultTagsCfg(flags)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:96
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
confTool.parse_args
def parse_args()
Definition: confTool.py:36
MuonConfigUtils.setupHistSvcCfg
def setupHistSvcCfg(flags, str outFile, str outStream)
Configuration snippet to setup the THistSvc.
Definition: MuonConfigUtils.py:5
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71