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