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