6from AthenaCommon.Logging
import log
7from argparse
import ArgumentParser
10 """Convert a 'key1=val1,key2=val2' string into a dictionary with typed values."""
13 items = arg.split(
',')
16 raise argparse.ArgumentTypeError(
17 f
"Invalid key=value pair: '{item}'. Use format 'key=value'."
19 key, value = item.split(
'=', 1)
23 raise argparse.ArgumentTypeError(f
"Key should be a string '{key}'")
25 dict[key.strip()] = int(value)
29 from argparse
import ArgumentParser
33 parser = ArgumentParser(
"RunMaterialMapping.py")
34 parser.add_argument(
"detectors", metavar=
"detectors", type=str, nargs=
"*",
35 help=
"Specify the list of detectors")
36 parser.add_argument(
"--localgeo", default=
False, action=
"store_true",
37 help=
"Use local geometry Xml files")
38 parser.add_argument(
"--geoModelSqLiteFile", default =
"", help=
"Read geometry from sqlite file")
39 parser.add_argument(
"-V",
"--verboseAccumulators", default=
False,
41 help=
"Print full details of the AlgSequence")
42 parser.add_argument(
"--storeTracks", default =
False, action=
"store_true",
43 help=
"Store the mapped and unmapped geantino tracks" )
44 parser.add_argument(
"--storeSurface", default =
False, action=
"store_true",
45 help=
"Store the surface info on the mapped/unmapped tracks" )
46 parser.add_argument(
"-S",
"--verboseStoreGate", default=
False,
48 help=
"Dump the StoreGate(s) each event iteration")
49 parser.add_argument(
"--maxEvents",default=-1, type=int,
50 help=
"The number of events to run. 0 skips execution")
51 parser.add_argument(
"--skipEvents",default=0, type=int,
52 help=
"The number of events to skip")
53 parser.add_argument(
"--batchSize", default=1000, type = int,
54 help=
"Number of Material events per host event")
55 parser.add_argument(
"--treeName", help=
"Name of the input tree in the file",
56 default=
"material-tracks", type=str)
57 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
58 parser.add_argument(
"--geometrytag",default=defaultGeometryTags.RUN4, type=str,
59 help=
"The geometry tag to use")
60 parser.add_argument(
"--inputFiles", type=str, nargs=
"+",
62 help=
"Input files to be used for the mapping procedure. They must contain the material track information, which was previously produced with the 'RunGeantinoMaterialTrackProduction.py'")
64 parser.add_argument(
"--materialBins", default=[], help =
"Binning on the surfaces for the material map as key value pairs in a single str (e.g --materialBins 'nPhiBIns=12 nZBins=10')",
65 type=dict_from_key_value)
69 from os
import path, listdir
71 for fileArg
in fileArgs:
72 if path.isdir(fileArg):
73 outList += [ f
"{fileArg}/{y}" for y
in listdir(fileArg) ]
75 if fileArg[fileArg.rfind(
".")+1 :]
not in [
"txt",
"conf"]:
78 with open(fileArg)
as inStream:
79 outList+=[ line.strip()
for line
in inStream
if line[0]!=
'#']
84if __name__ ==
"__main__":
88 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
89 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
92 print(
"----RunMaterialMapping for ITk geometry----")
94 print(
"Using Geometry Tag: "+args.geometrytag)
96 print(
"...overridden by local Geometry Xml files")
97 print(
"Input material track file:\n{files}".format(files =
" -- \n".join(args.inputFiles)))
98 if not args.detectors:
99 print(
"Running complete detector")
101 print(
"Running with: {}".format(
", ".join(args.detectors)))
104 if args.storeSurface
and not args.storeTracks:
105 print(
"Wrong configuration- I cannot store surface info without storing the geantino tracks!")
109 flags = initConfigFlags()
111 flags.ITk.Geometry.AllLocal =
True
112 from MuonGeoModelTestR4.testGeoModel
import MuonPhaseIITestDefaults, configureDefaultTagsCfg
113 flags.Input.Files = MuonPhaseIITestDefaults.EVGEN_PG
114 flags.Input.isMC=
True
115 flags.GeoModel.AtlasVersion = args.geometrytag
116 flags.IOVDb.GlobalTag =
"OFLCOND-SIM-00-00-00"
117 flags.GeoModel.Align.Dynamic =
False
120 flags.Concurrency.NumThreads = 1
121 flags.Concurrency.NumConcurrentEvents = 1
123 flags.Exec.EventPrintoutInterval = 500
124 if args.maxEvents > 0:
125 procHostEvents = int(args.maxEvents / args.batchSize) + 2
126 flags.Exec.MaxEvents = procHostEvents
127 from AthenaConfiguration.DetectorConfigFlags
import getEnabledDetectors, setupDetectorFlags
128 from AthenaConfiguration.AutoConfigFlags
import getDefaultDetectors
132 flags.Muon.trackGeometryActiveMaterial=
False
133 flags.Muon.trackGeometryPassiveMaterial=
True
135 if args.geoModelSqLiteFile:
136 flags.GeoModel.SQLiteDB =
True
137 flags.GeoModel.SQLiteDBFullPath = args.geoModelSqLiteFile
139 from AthenaConfiguration.Enums
import LHCPeriod
140 flags.GeoModel.Run = LHCPeriod.Run4
141 configureDefaultTagsCfg(flags)
143 defaultDetectors = [
'ITkPixel',
'ITkStrip']
144 detectors = args.detectors
if 'detectors' in args
and args.detectors
else defaultDetectors
145 detectors.append(
'Bpipe')
146 setupDetectorFlags(flags, detectors, toggle_geometry=
True)
148 flags.Acts.TrackingGeometry.UseBlueprint =
True
152 log.debug(
'Lock config flags now.')
156 acc = MainServicesCfg(flags)
158 acc.getService(
"MessageSvc").verboseLimit = 10000000
159 acc.getService(
"MessageSvc").debugLimit = 10000000
160 acc.getService(
"MessageSvc").errorLimit = 10000000
164 if args.verboseAccumulators: acc.printConfig(withDetails=
True)
165 if args.verboseStoreGate: acc.getService(
"StoreGateSvc").Dump =
True
167 log.debug(
'Dumping of ConfigFlags now.')
170 from ActsConfig.ActsMaterialConfig
import MaterialTrackReaderCfg, MaterialMappingCfg
173 acc.merge(MaterialTrackReaderCfg(flags,
174 maxEvents = args.maxEvents
if args.maxEvents > 0
else sys.maxsize,
175 skipEvents = args.skipEvents,
176 batchSize = args.batchSize,
178 TreeName=args.treeName))
180 acc.merge(MaterialMappingCfg(flags,
181 StoreTracks=args.storeTracks,
182 StoreSurfInfo=args.storeSurface))
184 from MuonConfig.MuonConfigUtils
import executeTest, setupHistSvcCfg
185 if flags.Detector.GeometryMuon:
186 builder = acc.getService(
"ActsTrackingGeometrySvc").BlueprintNodeBuilders[
"MuonBlueprintNodeBuilder"]
187 if args.materialBins:
188 bins_dict = args.materialBins
189 for key,value
in bins_dict.items():
190 setattr(builder, key, value)
void print(char *figname, TCanvas *c1)
dict dict_from_key_value(str arg)