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
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
37def 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
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
79def 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
87def 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
93def 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
99def 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
105def 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
111def 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
145def 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.Acts.TrackingGeometry.UseBlueprint = True
227
228 flags.Scheduler.CheckDependencies = True
229 flags.Scheduler.ShowDataDeps = True
230 flags.Scheduler.ShowDataFlow = True
231 flags.Scheduler.ShowControlFlow = True
232 flags.Scheduler.EnableVerboseViews = True
233 flags.Scheduler.AutoLoadUnmetDependencies = True
234 #flags.PerfMon.doFullMonMT = True
235 flags.lock()
236 flags.dump(evaluate = True)
237 cfg = setupServicesCfg(flags)
238
239 from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
240 cfg.merge(MuonGeoModelCfg(flags))
241
242
243 if not flags.Muon.usePhaseIIGeoSetup:
244 print ("WARNING: New Muon plugin is not part of the Geometry file {geoDBFile}".format(geoDBFile=args.geoModelFile))
245 else:
246 from ActsAlignmentAlgs.AlignmentAlgsConfig import ActsGeometryContextAlgCfg
247 cfg.merge(ActsGeometryContextAlgCfg(flags))
248
249 cfg.getService("MessageSvc").verboseLimit = 10000000
250 cfg.getService("MessageSvc").debugLimit = 10000000
251
252 return flags, cfg
253
254def executeTest(cfg):
255 cfg.printConfig(withDetails=True, summariseProps=True)
256 if not cfg.run().isSuccess(): exit(1)
257
258if __name__=="__main__":
259 args = SetupArgParser().parse_args()
260 flags, cfg = setupGeoR4TestCfg(args)
261 from MuonConfig.MuonConfigUtils import setupHistSvcCfg
262 cfg.merge(setupHistSvcCfg(flags, outFile = args.outRootFile, outStream="GEOMODELTESTER"))
263 chambToTest = args.chambers if len([x for x in args.chambers if x =="all"]) ==0 else []
264 chambToExclude = args.excludedChambers
265
266
267 if flags.Muon.usePhaseIIGeoSetup:
268 cfg.getCondAlgo("MuonDetectorCondAlg").checkGeo = True
269 cfg.getCondAlgo("MuonDetectorCondAlg").dumpGeo = True
270 from TrackingGeometryCondAlg.AtlasTrackingGeometryCondAlgConfig import TrackingGeometryCondAlgCfg
271 cfg.merge(TrackingGeometryCondAlgCfg(flags))
272
273
274 cfg.getService("MessageSvc").setVerbose = []
275
276 if flags.Detector.GeometryMDT:
277 if not flags.Muon.usePhaseIIGeoSetup:
278 from MuonGeoModelTest.testGeoModel import GeoModelMdtTestCfg as LegacyTestCfg
279 cfg.merge(LegacyTestCfg(flags,
280 TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
281 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"]))
282 else:
283 cfg.merge(GeoModelMdtTestCfg(flags,
284 TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
285 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"],
286 ReadoutSideXML="ReadoutSides.xml",
287 ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
288
289 if flags.Detector.GeometryRPC:
290 if not flags.Muon.usePhaseIIGeoSetup:
291 from MuonGeoModelTest.testGeoModel import GeoModelRpcTestCfg as LegacyTestCfg
292 cfg.merge(LegacyTestCfg(flags,
293 TestStations = [ch for ch in chambToTest if ch[0] == "B"],
294 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"]))
295 else:
296 cfg.merge(GeoModelRpcTestCfg(flags,
297 TestStations = [ch for ch in chambToTest if ch[0] == "B"],
298 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"],
299 ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
300
301 if flags.Detector.GeometryTGC:
302 if not flags.Muon.usePhaseIIGeoSetup:
303 from MuonGeoModelTest.testGeoModel import GeoModelTgcTestCfg as LegacyTestCfg
304 cfg.merge(LegacyTestCfg(flags,
305 TestStations = [ch for ch in chambToTest if ch[0] == "T"],
306 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"]))
307 else:
308 cfg.merge(GeoModelTgcTestCfg(flags,
309 TestStations = [ch for ch in chambToTest if ch[0] == "T"],
310 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"],
311 ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
312
313 if flags.Detector.GeometryMM:
314 if not flags.Muon.usePhaseIIGeoSetup:
315 from MuonGeoModelTest.testGeoModel import GeoModelMmTestCfg as LegacyTestCfg
316 cfg.merge(LegacyTestCfg(flags,
317 TestStations = [ch for ch in chambToTest if ch[0] == "M"],
318 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"]))
319 else:
320 cfg.merge(GeoModelMmTestCfg(flags,
321 TestStations = [ch for ch in chambToTest if ch[0] == "M"],
322 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"],
323 ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
324
325 if flags.Detector.GeometrysTGC:
326 if not flags.Muon.usePhaseIIGeoSetup:
327 from MuonGeoModelTest.testGeoModel import GeoModelsTgcTestCfg as LegacyTestCfg
328 cfg.merge(LegacyTestCfg(flags,
329 TestStations = [ch for ch in chambToTest if ch[0] == "S"],
330 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"]))
331 else:
332 cfg.merge(GeoModelsTgcTestCfg(flags,
333 TestStations = [ch for ch in chambToTest if ch[0] == "S"],
334 ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"],
335 ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
336
337 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)