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