4 from pathlib
import Path
12 RootMaterialTrackReader,
13 RootMaterialTrackWriter,
23 SurfaceMaterialMapper,
28 MaterialMapJsonConverter,
30 from common
import getOpenDataDetectorDirectory
40 mapName=
"material-map",
42 readCachedSurfaceInformation=
False,
43 dumpMaterialTracks=
False,
46 s = s
or Sequencer(numThreads=1)
48 for decorator
in decorators:
49 s.addContextDecorator(decorator)
51 wb = WhiteBoard(acts.logging.INFO)
53 context = AlgorithmContext(0, 0, wb)
55 for decorator
in decorators:
56 assert decorator.decorate(context) == ProcessCode.SUCCESS
60 RootMaterialTrackReader(
61 level=acts.logging.INFO,
62 collection=
"material-tracks",
69 readCachedSurfaceInformation=readCachedSurfaceInformation,
73 stepper = StraightLineStepper()
75 mmAlgCfg = MaterialMapping.Config(context.geoContext, context.magFieldContext)
76 mmAlgCfg.trackingGeometry = trackingGeometry
77 mmAlgCfg.collection =
"material-tracks"
80 navigator = Navigator(
81 trackingGeometry=trackingGeometry,
82 resolveSensitive=
False,
87 mapper = SurfaceMaterialMapper(level=acts.logging.INFO, propagator=propagator)
88 mmAlgCfg.materialSurfaceMapper = mapper
90 jmConverterCfg = MaterialMapJsonConverter.Config(
91 processSensitives=
False,
92 processNonMaterial=
False,
93 processApproaches=
True,
94 processRepresenting=
True,
95 processBoundaries=
True,
97 context=context.geoContext,
100 jmw = JsonMaterialWriter(
101 level=acts.logging.VERBOSE,
102 converterCfg=jmConverterCfg,
103 fileName=os.path.join(outputDir, mapName),
104 writeFormat=JsonFormat.Json,
107 if dumpMaterialTracks:
109 RootMaterialTrackWriter(
110 level=acts.logging.INFO,
111 collection=mmAlgCfg.collection,
112 filePath=os.path.join(
114 mapName +
"_tracks.root",
121 mmAlgCfg.materialWriters = [jmw]
123 s.addAlgorithm(MaterialMapping(level=acts.logging.INFO, config=mmAlgCfg))
128 if "__main__" == __name__:
129 p = argparse.ArgumentParser(
130 description=
"Script to run material mapping on ITk geometry"
134 help=
"Input directory containing the ITk standalone geometry. Get in touch if you don't have this.",
140 help=
"Input file containing material steps.",
146 help=
"Geometry file to define layers used in material mapping",
149 args = p.parse_args()
151 geo_example_dir = Path(args.geo_dir)
152 assert geo_example_dir.exists(),
"Detector example input directory missing"
153 assert os.path.exists(
155 ),
"Invalid file in --inputFile. Please check your input!"
156 assert os.path.exists(
158 ),
"Invalid file path/name in --material. Please check your input!"
163 geo_example_dir, customMaterialFile=args.material
169 materialStepsFile=args.inputFile,
170 outputDir=os.getcwd(),
171 inputDir=os.getcwd(),
172 readCachedSurfaceInformation=
False,