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 ACTS Tracking 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 MuonConfig.MuonConfigUtils
import configureDefaultTags
113 from MuonGeoModelTestR4.testGeoModel
import MuonPhaseIITestDefaults
114 flags.Input.Files = MuonPhaseIITestDefaults.EVGEN_PG
117 flags.Input.isMC=
True
118 flags.GeoModel.AtlasVersion = args.geometrytag
119 from AthenaConfiguration.TestDefaults
import defaultConditionsTags
120 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
121 flags.GeoModel.Align.Dynamic =
False
124 flags.Concurrency.NumThreads = 1
125 flags.Concurrency.NumConcurrentEvents = 1
127 flags.Exec.EventPrintoutInterval = 500
128 if args.maxEvents > 0:
129 procHostEvents = int(args.maxEvents / args.batchSize) + 2
130 flags.Exec.MaxEvents = procHostEvents
131 from AthenaConfiguration.DetectorConfigFlags
import getEnabledDetectors, setupDetectorFlags
132 from AthenaConfiguration.AutoConfigFlags
import getDefaultDetectors
137 flags.Muon.trackGeometryActiveMaterial=
False
138 flags.Muon.trackGeometryPassiveMaterial=
True
140 if args.geoModelSqLiteFile:
141 flags.GeoModel.SQLiteDB =
True
142 flags.GeoModel.SQLiteDBFullPath = args.geoModelSqLiteFile
144 from AthenaConfiguration.Enums
import LHCPeriod
145 flags.GeoModel.Run = LHCPeriod.Run4
146 configureDefaultTags(flags)
148 defaultDetectors = [
'ITkPixel',
'ITkStrip',
'HGTD']
149 detectors = args.detectors
if 'detectors' in args
and args.detectors
else defaultDetectors
150 detectors.append(
'Bpipe')
151 setupDetectorFlags(flags, detectors, toggle_geometry=
True)
153 flags.Acts.TrackingGeometry.UseBlueprint =
True
154 flags.Acts.TrackingGeometry.ITkHgtdMaterialSource =
"None"
156 log.debug(
'Lock config flags now.')
160 acc = MainServicesCfg(flags)
162 acc.getService(
"MessageSvc").verboseLimit = 10000000
163 acc.getService(
"MessageSvc").debugLimit = 10000000
164 acc.getService(
"MessageSvc").errorLimit = 10000000
168 if args.verboseAccumulators:
169 acc.printConfig(withDetails=
True)
170 if args.verboseStoreGate:
171 acc.getService(
"StoreGateSvc").Dump =
True
173 log.debug(
'Dumping of ConfigFlags now.')
176 from ActsConfig.ActsMaterialConfig
import MaterialTrackReaderCfg, MaterialMappingCfg
179 acc.merge(MaterialTrackReaderCfg(flags,
180 maxEvents = args.maxEvents
if args.maxEvents > 0
else sys.maxsize,
181 skipEvents = args.skipEvents,
182 batchSize = args.batchSize,
184 TreeName=args.treeName))
186 acc.merge(MaterialMappingCfg(flags,
187 StoreTracks=args.storeTracks,
188 StoreSurfInfo=args.storeSurface))
190 from MuonConfig.MuonConfigUtils
import executeTest, setupHistSvcCfg
191 if flags.Detector.GeometryMuon:
192 builder = acc.getService(
"ActsTrackingGeometrySvc").BlueprintNodeBuilders[
"MuonBlueprintNodeBuilder"]
193 if args.materialBins:
194 bins_dict = args.materialBins
195 for key,value
in bins_dict.items():
196 setattr(builder, key, value)
void print(char *figname, TCanvas *c1)
dict dict_from_key_value(str arg)