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