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 setupHistSvcCfg(flags, outFile="MdtGeoDump.root", outStream="GEOMODELTESTER"):
56  result = ComponentAccumulator()
57  if len(outFile) == 0: return result
58  histSvc = CompFactory.THistSvc(Output=[f"{outStream} DATAFILE='{outFile}', OPT='RECREATE'"])
59  result.addService(histSvc, primary=True)
60  return result
61 
62 
63 def GeoModelMdtTestCfg(flags, name = "GeoModelMdtTest", **kwargs):
64  result = ComponentAccumulator()
65  the_alg = CompFactory.MuonGMR4.GeoModelMdtTest(name, **kwargs)
66  result.addEventAlgo(the_alg, primary = True)
67  return result
68 
69 def GeoModelRpcTestCfg(flags, name = "GeoModelRpcTest", **kwargs):
70  result = ComponentAccumulator()
71  the_alg = CompFactory.MuonGMR4.GeoModelRpcTest(name, **kwargs)
72  result.addEventAlgo(the_alg, primary = True)
73  return result
74 
75 def GeoModelTgcTestCfg(flags, name = "GeoModelTgcTest", **kwargs):
76  result = ComponentAccumulator()
77  the_alg = CompFactory.MuonGMR4.GeoModelTgcTest(name, **kwargs)
78  result.addEventAlgo(the_alg, primary = True)
79  return result
80 
81 def GeoModelsTgcTestCfg(flags, name = "GeoModelsTgcTest", **kwargs):
82  result = ComponentAccumulator()
83  the_alg = CompFactory.MuonGMR4.GeoModelsTgcTest(name, **kwargs)
84  result.addEventAlgo(the_alg, primary = True)
85  return result
86 
87 def GeoModelMmTestCfg(flags, name = "GeoModelMmTest", **kwargs):
88  result = ComponentAccumulator()
89  the_alg = CompFactory.MuonGMR4.GeoModelMmTest(name, **kwargs)
90  result.addEventAlgo(the_alg, primary = True)
91  return result
92 
93 def NswGeoPlottingAlgCfg(flags, name="NswGeoPlotting", **kwargs):
94  result = ComponentAccumulator()
95  kwargs.setdefault("TestActsSurface", True)
96  kwargs.setdefault("plotTgc", flags.Detector.GeometryTGC)
97  kwargs.setdefault("plotStgc", flags.Detector.GeometrysTGC)
98  kwargs.setdefault("plotMm", flags.Detector.GeometryMM)
99 
100  the_alg = CompFactory.MuonGMR4.NswGeoPlottingAlg(name, **kwargs)
101  result.addEventAlgo(the_alg, primary = True)
102  return result
103 
105  from AthenaCommon.Logging import logging
106  log = logging.getLogger('GeometryConfiguration')
107 
108  if not flags.GeoModel.SQLiteDB:
109  raise ValueError("Default tag configuration only works for SQLite")
110 
111  from AthenaConfiguration.TestDefaults import defaultConditionsTags, defaultGeometryTags
112  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
113  from AthenaConfiguration.Enums import LHCPeriod
114  if flags.GeoModel.Run == LHCPeriod.Run3:
115  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_MC if flags.Input.isMC else defaultConditionsTags.RUN3_DATA
116  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
117  elif flags.GeoModel.Run == LHCPeriod.Run4:
118  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
119  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
120  else:
121  raise ValueError(f"Invalid run period {flags.GeoModel.Run}")
122  log.info(f"Setup {flags.GeoModel.AtlasVersion} geometry loading {flags.GeoModel.SQLiteDBFullPath}")
123  log.info(f"Use conditions tag {flags.IOVDb.GlobalTag}")
124 
125 
126 def setupGeoR4TestCfg(args, flags = None):
127 
128  if flags is None:
129  from AthenaConfiguration.AllConfigFlags import initConfigFlags
130  flags = initConfigFlags()
131  flags.Concurrency.NumThreads = args.threads
132  flags.Concurrency.NumConcurrentEvents = args.threads
133  flags.Exec.MaxEvents = args.nEvents
134  flags.Exec.SkipEvents = args.skipEvents
135  from os import path, system, listdir
136  flags.Input.Files = []
137 
139  for fileArg in args.inputFile:
140  if path.isdir(fileArg):
141  flags.Input.Files += [ "{dir}/{file}".format(dir=fileArg, file=y) for y in listdir(fileArg) ]
142  else:
143  if fileArg[fileArg.rfind(".")+1 :]not in ["txt", "conf"]:
144  flags.Input.Files+=[fileArg]
145  else:
146  with open(fileArg) as inStream:
147  flags.Input.Files+=[ line.strip() for line in inStream if line[0]!='#']
148 
149  flags.Exec.FPE= 500
150  flags.Exec.EventPrintoutInterval = 500
151 
152  if args.defaultGeoFile == "RUN3":
153  flags.GeoModel.SQLiteDBFullPath = geoModelFileDefault(useR4Layout = False)
154  elif args.defaultGeoFile == "RUN4":
155  flags.GeoModel.SQLiteDBFullPath = geoModelFileDefault(useR4Layout = True)
156  elif args.geoModelFile.startswith("root://"):
157  if not path.exists("Geometry/{geoTag}.db".format(geoTag=args.geoTag)):
158  print ("Copy geometry file from EOS {source}".format(source = args.geoModelFile))
159  system("mkdir Geometry/")
160  system("xrdcp {source} Geometry/{geoTag}.db".format(source = args.geoModelFile,
161  geoTag=args.geoTag))
162 
163  args.geoModelFile = "Geometry/{geoTag}.db".format(geoTag=args.geoTag)
164  else:
165  flags.GeoModel.SQLiteDBFullPath = args.geoModelFile
166 
167  flags.GeoModel.SQLiteDB = True
169 
170  flags.Detector.GeometryBpipe = False
171 
172  flags.Detector.GeometryBCM = False
173  flags.Detector.GeometryPixel = False
174  flags.Detector.GeometrySCT = False
175  flags.Detector.GeometryTRT = False
176 
177  flags.Detector.GeometryPLR = False
178  flags.Detector.GeometryBCMPrime = False
179  flags.Detector.GeometryITkPixel = False
180  flags.Detector.GeometryITkStrip = False
181 
182  flags.Detector.GeometryHGTD = False
183 
184  flags.Detector.GeometryLAr = False
185  flags.Detector.GeometryTile = False
186  flags.Detector.GeometryMBTS = False
187  flags.Detector.GeometryCalo = False
188 
189  flags.Detector.GeometryCSC = False
190  if args.noSTGC:
191  flags.Detector.GeometrysTGC = False
192  if args.noMM:
193  flags.Detector.GeometryMM = False
194  if args.noTgc:
195  flags.Detector.GeometryTGC = False
196  if args.noRpc:
197  flags.Detector.GeometryRPC = False
198  if args.noMdt:
199  flags.Detector.GeometryMDT = False
200 
201  flags.Scheduler.CheckDependencies = True
202  flags.Scheduler.ShowDataDeps = True
203  flags.Scheduler.ShowDataFlow = True
204  flags.Scheduler.ShowControlFlow = True
205  flags.Scheduler.EnableVerboseViews = True
206  flags.Scheduler.AutoLoadUnmetDependencies = True
207  #flags.PerfMon.doFullMonMT = True
208  flags.lock()
209  flags.dump(evaluate = True)
210  cfg = setupServicesCfg(flags)
211 
212  from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
213  cfg.merge(MuonGeoModelCfg(flags))
214 
215 
216  if not flags.Muon.usePhaseIIGeoSetup:
217  print ("WARNING: New Muon plugin is not part of the Geometry file {geoDBFile}".format(geoDBFile=args.geoModelFile))
218  else:
219  from ActsAlignmentAlgs.AlignmentAlgsConfig import ActsGeometryContextAlgCfg
220  cfg.merge(ActsGeometryContextAlgCfg(flags))
221 
222  cfg.getService("MessageSvc").verboseLimit = 10000000
223  cfg.getService("MessageSvc").debugLimit = 10000000
224 
225  return flags, cfg
226 
227 def executeTest(cfg):
228  cfg.printConfig(withDetails=True, summariseProps=True)
229  if not cfg.run().isSuccess(): exit(1)
230 
231 if __name__=="__main__":
232  args = SetupArgParser().parse_args()
233  flags, cfg = setupGeoR4TestCfg(args)
234  cfg.merge(setupHistSvcCfg(flags, outFile = args.outRootFile))
235  chambToTest = args.chambers if len([x for x in args.chambers if x =="all"]) ==0 else []
236  chambToExclude = args.excludedChambers
237 
238 
239  if flags.Muon.usePhaseIIGeoSetup:
240  cfg.getCondAlgo("MuonDetectorCondAlg").checkGeo = True
241  from TrackingGeometryCondAlg.AtlasTrackingGeometryCondAlgConfig import TrackingGeometryCondAlgCfg
242  cfg.merge(TrackingGeometryCondAlgCfg(flags))
243 
244 
245  cfg.getService("MessageSvc").setVerbose = []
246 
247  if flags.Detector.GeometryMDT:
248  if not flags.Muon.usePhaseIIGeoSetup:
249  from MuonGeoModelTest.testGeoModel import GeoModelMdtTestCfg as LegacyTestCfg
250  cfg.merge(LegacyTestCfg(flags,
251  TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
252  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"]))
253  else:
254  cfg.merge(GeoModelMdtTestCfg(flags,
255  TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
256  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"],
257  ReadoutSideXML="ReadoutSides.xml",
258  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
259 
260  if flags.Detector.GeometryRPC:
261  if not flags.Muon.usePhaseIIGeoSetup:
262  from MuonGeoModelTest.testGeoModel import GeoModelRpcTestCfg as LegacyTestCfg
263  cfg.merge(LegacyTestCfg(flags,
264  TestStations = [ch for ch in chambToTest if ch[0] == "B"],
265  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"]))
266  else:
267  cfg.merge(GeoModelRpcTestCfg(flags,
268  TestStations = [ch for ch in chambToTest if ch[0] == "B"],
269  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"],
270  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
271 
272  if flags.Detector.GeometryTGC:
273  if not flags.Muon.usePhaseIIGeoSetup:
274  from MuonGeoModelTest.testGeoModel import GeoModelTgcTestCfg as LegacyTestCfg
275  cfg.merge(LegacyTestCfg(flags,
276  TestStations = [ch for ch in chambToTest if ch[0] == "T"],
277  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"]))
278  else:
279  cfg.merge(GeoModelTgcTestCfg(flags,
280  TestStations = [ch for ch in chambToTest if ch[0] == "T"],
281  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"],
282  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
283 
284  if flags.Detector.GeometryMM:
285  if not flags.Muon.usePhaseIIGeoSetup:
286  from MuonGeoModelTest.testGeoModel import GeoModelMmTestCfg as LegacyTestCfg
287  cfg.merge(LegacyTestCfg(flags,
288  TestStations = [ch for ch in chambToTest if ch[0] == "M"],
289  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"]))
290  else:
291  cfg.merge(NswGeoPlottingAlgCfg(flags))
292  cfg.merge(GeoModelMmTestCfg(flags,
293  TestStations = [ch for ch in chambToTest if ch[0] == "M"],
294  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"],
295  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
296 
297  if flags.Detector.GeometrysTGC:
298  if not flags.Muon.usePhaseIIGeoSetup:
299  from MuonGeoModelTest.testGeoModel import GeoModelsTgcTestCfg as LegacyTestCfg
300  cfg.merge(LegacyTestCfg(flags,
301  TestStations = [ch for ch in chambToTest if ch[0] == "S"],
302  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"]))
303  else:
304  cfg.merge(GeoModelsTgcTestCfg(flags,
305  TestStations = [ch for ch in chambToTest if ch[0] == "S"],
306  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"],
307  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
308 
309  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:93
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
testGeoModel.setupHistSvcCfg
def setupHistSvcCfg(flags, outFile="MdtGeoDump.root", outStream="GEOMODELTESTER")
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:55
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:227
MuonGeometryConfig.MuonGeoModelCfg
def MuonGeoModelCfg(flags)
Definition: MuonGeometryConfig.py:28
testGeoModel.setupGeoR4TestCfg
def setupGeoR4TestCfg(args, flags=None)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:126
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
Trk::open
@ open
Definition: BinningType.h:40
testGeoModel.configureDefaultTagsCfg
def configureDefaultTagsCfg(flags)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:104
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
confTool.parse_args
def parse_args()
Definition: confTool.py:36
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71