ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 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/MuonRecRTT/ATLAS-R4-MUONTEST.db"
10  return "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonRecRTT/ATLAS-R3-MUONTEST_v3.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("--geoTag", default="ATLAS-R3S-2021-03-02-00", help="Geometry tag to use", choices=["ATLAS-R3S-2021-03-02-00",
18  "ATLAS-P2-RUN4-01-00-00"])
19  parser.add_argument("--condTag", default="OFLCOND-MC23-SDR-RUN3-07", help="Conditions tag to use",
20  choices= ["OFLCOND-MC23-SDR-RUN3-07", "CONDBR2-BLKPA-2023-03", "OFLCOND-MC21-SDR-RUN4-01"])
21  parser.add_argument("--inputFile", "-i", default=[
22  #"/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/Tier0ChainTests/TCT_Run3/data22_13p6TeV.00431493.physics_Main.daq.RAW._lb0525._SFO-16._0001.data"
23  "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonRecRTT/EVGEN_ParticleGun_FourMuon_Pt10to500.root"
24  ],
25  help="Input file to run on ", nargs="+")
26  parser.add_argument("--geoModelFile", default = geoModelFileDefault(), help="GeoModel SqLite file containing the muon geometry.")
27  parser.add_argument("--chambers", default=["all"], nargs="+", help="Chambers to check. If string is all, all chambers will be checked")
28  parser.add_argument("--excludedChambers", default=["none"], 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.")
29  parser.add_argument("--outRootFile", default="NewGeoModelDump.root", help="Output ROOT file to dump the geomerty")
30  parser.add_argument("--nEvents", help="Number of events to run", type = int ,default = 1)
31  parser.add_argument("--skipEvents", help="Number of events to skip", type = int, default = 0)
32  parser.add_argument("--noMdt", help="Disable the Mdts from the geometry", action='store_true', default = False)
33  parser.add_argument("--noRpc", help="Disable the Rpcs from the geometry", action='store_true', default = False)
34  parser.add_argument("--noTgc", help="Disable the Tgcs from the geometry", action='store_true', default = False)
35  parser.add_argument("--noMM", help="Disable the MMs from the geometry", action='store_true', default = False)
36  parser.add_argument("--noSTGC", help="Disable the sTgcs from the geometry", action='store_true', default = False)
37  parser.add_argument("--eventPrintoutLevel", type=int, help="Interval of event heartbeat printouts from the loop manager", default = 1)
38  return parser
39 
40 def setupServicesCfg(flags):
41  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
42  result = MainServicesCfg(flags)
43 
44  from AthenaConfiguration.Enums import Format
45  if flags.Input.Format is Format.POOL:
46  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
47  result.merge(PoolReadCfg(flags))
48  elif flags.Input.Format == Format.BS:
49  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
50  result.merge(ByteStreamReadCfg(flags))
51 
52  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
53  result.merge(PerfMonMTSvcCfg(flags))
54  from MuonConfig.MuonGeometryConfig import MuonIdHelperSvcCfg
55  result.merge(MuonIdHelperSvcCfg(flags))
56  return result
57 
58 def setupHistSvcCfg(flags, outFile="MdtGeoDump.root", outStream="GEOMODELTESTER"):
59  result = ComponentAccumulator()
60  if len(outFile) == 0: return result
61  histSvc = CompFactory.THistSvc(Output=[f"{outStream} DATAFILE='{outFile}', OPT='RECREATE'"])
62  result.addService(histSvc, primary=True)
63  return result
64 
65 
66 def GeoModelMdtTestCfg(flags, name = "GeoModelMdtTest", **kwargs):
67  result = ComponentAccumulator()
68  the_alg = CompFactory.MuonGMR4.GeoModelMdtTest(name, **kwargs)
69  result.addEventAlgo(the_alg, primary = True)
70  return result
71 
72 def GeoModelRpcTestCfg(flags, name = "GeoModelRpcTest", **kwargs):
73  result = ComponentAccumulator()
74  the_alg = CompFactory.MuonGMR4.GeoModelRpcTest(name, **kwargs)
75  result.addEventAlgo(the_alg, primary = True)
76  return result
77 
78 def GeoModelTgcTestCfg(flags, name = "GeoModelTgcTest", **kwargs):
79  result = ComponentAccumulator()
80  the_alg = CompFactory.MuonGMR4.GeoModelTgcTest(name, **kwargs)
81  result.addEventAlgo(the_alg, primary = True)
82  return result
83 
84 def GeoModelsTgcTestCfg(flags, name = "GeoModelsTgcTest", **kwargs):
85  result = ComponentAccumulator()
86  the_alg = CompFactory.MuonGMR4.GeoModelsTgcTest(name, **kwargs)
87  result.addEventAlgo(the_alg, primary = True)
88  return result
89 
90 def GeoModelMmTestCfg(flags, name = "GeoModelMmTest", **kwargs):
91  result = ComponentAccumulator()
92  the_alg = CompFactory.MuonGMR4.GeoModelMmTest(name, **kwargs)
93  result.addEventAlgo(the_alg, primary = True)
94  return result
95 
96 def NswGeoPlottingAlgCfg(flags, name="NswGeoPlotting", **kwargs):
97  result = ComponentAccumulator()
98  kwargs.setdefault("TestActsSurface", False)
99  the_alg = CompFactory.MuonGMR4.NswGeoPlottingAlg(name, **kwargs)
100  result.addEventAlgo(the_alg, primary = True)
101  return result
102 
103 def setupGeoR4TestCfg(args, flags = None):
104 
105  if flags is None:
106  from AthenaConfiguration.AllConfigFlags import initConfigFlags
107  flags = initConfigFlags()
108  flags.Concurrency.NumThreads = args.threads
109  flags.Concurrency.NumConcurrentEvents = args.threads
110  flags.Exec.MaxEvents = args.nEvents
111  flags.Exec.SkipEvents = args.skipEvents
112  flags.Input.isMC = args.condTag.find("OFLCOND") != -1
113  from os import path, system, listdir
114  inFiles = [x for x in args.inputFile if not path.isdir(x)] + \
115  [ "{dir}/{file}".format(dir=x, file=y) for x in args.inputFile if path.isdir(x) for y in listdir(x) ]
116  flags.Input.Files = inFiles
117  flags.Exec.FPE= 500
118  flags.Exec.EventPrintoutInterval = args.eventPrintoutLevel
119 
120  if args.geoModelFile.startswith("root://"):
121  if not path.exists("Geometry/{geoTag}.db".format(geoTag=args.geoTag)):
122  print ("Copy geometry file from EOS {source}".format(source = args.geoModelFile))
123  system("mkdir Geometry/")
124  system("xrdcp {source} Geometry/{geoTag}.db".format(source = args.geoModelFile,
125  geoTag=args.geoTag))
126 
127  args.geoModelFile = "Geometry/{geoTag}.db".format(geoTag=args.geoTag)
128 
129  flags.GeoModel.AtlasVersion = args.geoTag
130  flags.IOVDb.GlobalTag = args.condTag
131  flags.GeoModel.SQLiteDB = True
132  from AtlasGeoModel import CommonGeoDB
133  CommonGeoDB.SetupLocalSqliteGeometryDb(args.geoModelFile,args.geoTag)
134 
135  flags.Detector.GeometryBpipe = False
136 
137  flags.Detector.GeometryBCM = False
138  flags.Detector.GeometryPixel = False
139  flags.Detector.GeometrySCT = False
140  flags.Detector.GeometryTRT = False
141 
142  flags.Detector.GeometryPLR = False
143  flags.Detector.GeometryBCMPrime = False
144  flags.Detector.GeometryITkPixel = False
145  flags.Detector.GeometryITkStrip = False
146 
147  flags.Detector.GeometryHGTD = False
148 
149  flags.Detector.GeometryLAr = False
150  flags.Detector.GeometryTile = False
151  flags.Detector.GeometryMBTS = False
152  flags.Detector.GeometryCalo = False
153 
154  flags.Detector.GeometryCSC = False
155  if args.noSTGC:
156  flags.Detector.GeometrysTGC = False
157  if args.noMM:
158  flags.Detector.GeometryMM = False
159  if args.noTgc:
160  flags.Detector.GeometryTGC = False
161  if args.noRpc:
162  flags.Detector.GeometryRPC = False
163  if args.noMdt:
164  flags.Detector.GeometryMDT = False
165 
166  flags.Scheduler.CheckDependencies = True
167  flags.Scheduler.ShowDataDeps = True
168  flags.Scheduler.ShowDataFlow = True
169  flags.Scheduler.ShowControlFlow = True
170  flags.Scheduler.EnableVerboseViews = True
171  flags.Scheduler.AutoLoadUnmetDependencies = True
172  #flags.PerfMon.doFullMonMT = True
173 
174  flags.lock()
175  flags.dump(evaluate = True)
176  if not flags.Muon.usePhaseIIGeoSetup:
177  print ("Please make sure that the file you're testing contains the Muon R4 geometry")
178  exit(1)
179 
180  cfg = setupServicesCfg(flags)
181 
182  from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
183  cfg.merge(MuonGeoModelCfg(flags))
184 
185  from ActsAlignmentAlgs.AlignmentAlgsConfig import ActsGeometryContextAlgCfg
186  cfg.merge(ActsGeometryContextAlgCfg(flags))
187 
188  cfg.getService("MessageSvc").verboseLimit = 10000000
189  cfg.getService("MessageSvc").debugLimit = 10000000
190 
191  return flags, cfg
192 
193 def executeTest(cfg):
194 
195  cfg.printConfig(withDetails=True, summariseProps=True)
196  if not cfg.run().isSuccess(): exit(1)
197 
198 if __name__=="__main__":
200  flags, cfg = setupGeoR4TestCfg(args)
201  cfg.merge(setupHistSvcCfg(flags, outFile = args.outRootFile))
202  chambToTest = args.chambers if len([x for x in args.chambers if x =="all"]) ==0 else []
203  chambToExclude = [] if "none" in args.excludedChambers else args.excludedChambers
204 
205  cfg.getCondAlgo("MuonDetectorManagerCondAlg").checkGeo = True
206  cfg.getService("MessageSvc").setVerbose = []
207 
208 
209  from TrackingGeometryCondAlg.AtlasTrackingGeometryCondAlgConfig import TrackingGeometryCondAlgCfg
210  cfg.merge(TrackingGeometryCondAlgCfg(flags))
211  if flags.Detector.GeometryMDT:
212  cfg.merge(GeoModelMdtTestCfg(flags,
213  TestStations = [ch for ch in chambToTest if ch[0] == "B" or ch[0] == "E"],
214  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B" or ch[0] == "E"],
215  ReadoutSideXML="ReadoutSides.xml",
216  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' ),
217  #( 'Trk::TrackingGeometry' , 'ConditionStore+AtlasTrackingGeometry' )
218  ]))
219 
220  if flags.Detector.GeometryRPC:
221  cfg.merge(GeoModelRpcTestCfg(flags, TestStations = [ch for ch in chambToTest if ch[0] == "B"],
222  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "B"],
223  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
224 
225  if flags.Detector.GeometryTGC:
226  cfg.merge(GeoModelTgcTestCfg(flags, TestStations = [ch for ch in chambToTest if ch[0] == "T"],
227  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "T"],
228  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
229 
230  if flags.Detector.GeometryMM:
231  cfg.merge(NswGeoPlottingAlgCfg(flags))
232  cfg.merge(GeoModelMmTestCfg(flags, TestStations = [ch for ch in chambToTest if ch[0] == "M"],
233  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "M"],
234  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
235 
236  if flags.Detector.GeometrysTGC:
237  cfg.merge(GeoModelsTgcTestCfg(flags, TestStations = [ch for ch in chambToTest if ch[0] == "S"],
238  ExcludeStations = [ch for ch in chambToExclude if ch[0] == "S"],
239  ExtraInputs=[( 'MuonGM::MuonDetectorManager' , 'ConditionStore+MuonDetectorManager' )]))
240 
241  executeTest(cfg)
python.testGeoModel.GeoModelMdtTestCfg
def GeoModelMdtTestCfg(flags, name="GeoModelMdtTest", **kwargs)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:66
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.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:40
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:58
python.MuonGeometryConfig.MuonIdHelperSvcCfg
def MuonIdHelperSvcCfg(flags)
Definition: MuonGeometryConfig.py:15
python.testGeoModel.executeTest
def executeTest(cfg)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:193
python.testGeoModel.GeoModelTgcTestCfg
def GeoModelTgcTestCfg(flags, name="GeoModelTgcTest", **kwargs)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:78
python.testGeoModel.setupGeoR4TestCfg
def setupGeoR4TestCfg(args, flags=None)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:103
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:96
python.testGeoModel.GeoModelRpcTestCfg
def GeoModelRpcTestCfg(flags, name="GeoModelRpcTest", **kwargs)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:72
python.testGeoModel.GeoModelsTgcTestCfg
def GeoModelsTgcTestCfg(flags, name="GeoModelsTgcTest", **kwargs)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:84
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:35
python.testGeoModel.GeoModelMmTestCfg
def GeoModelMmTestCfg(flags, name="GeoModelMmTest", **kwargs)
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py:90
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69