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