Warning, file /acts/Examples/Scripts/Python/material_validation_core.py was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003 import os
0004 import argparse
0005 from pathlib import Path
0006
0007 import acts
0008 from acts import (
0009 MaterialValidater,
0010 IntersectionMaterialAssigner,
0011 logging,
0012 GeometryContext,
0013 DetectorBuilder,
0014 GeometryIdGenerator,
0015 )
0016
0017 from acts.examples import (
0018 Sequencer,
0019 WhiteBoard,
0020 AlgorithmContext,
0021 MaterialValidation,
0022 )
0023
0024 from acts.examples.root import (
0025 RootMaterialTrackWriter,
0026 )
0027
0028
0029 def runMaterialValidation(s, ntracks, surfaces, outputFile, seed, loglevel):
0030
0031 wb = WhiteBoard(acts.logging.INFO)
0032
0033 rnd = acts.examples.RandomNumbers(seed=seed)
0034
0035
0036 materialAssingerConfig = IntersectionMaterialAssigner.Config()
0037 materialAssingerConfig.surfaces = surfaces
0038 materialAssinger = IntersectionMaterialAssigner(materialAssingerConfig, loglevel)
0039
0040
0041 materialValidaterConfig = MaterialValidater.Config()
0042 materialValidaterConfig.materialAssigner = materialAssinger
0043 materialValidater = MaterialValidater(materialValidaterConfig, loglevel)
0044
0045
0046 materialValidationConfig = MaterialValidation.Config()
0047 materialValidationConfig.materialValidater = materialValidater
0048 materialValidationConfig.outputMaterialTracks = "recorded-material-tracks"
0049 materialValidationConfig.ntracks = ntracks
0050 materialValidationConfig.randomNumberSvc = rnd
0051 materialValidation = MaterialValidation(materialValidationConfig, loglevel)
0052 s.addAlgorithm(materialValidation)
0053
0054
0055 s.addWriter(
0056 RootMaterialTrackWriter(
0057 level=acts.logging.INFO,
0058 inputMaterialTracks=materialValidationConfig.outputMaterialTracks,
0059 filePath=outputFile + ".root",
0060 storeSurface=True,
0061 storeVolume=True,
0062 )
0063 )
0064
0065 return s
0066
0067
0068 if "__main__" == __name__:
0069 p = argparse.ArgumentParser()
0070
0071 p.add_argument(
0072 "-n", "--events", type=int, default=1000, help="Number of events to process"
0073 )
0074 p.add_argument(
0075 "-t", "--tracks", type=int, default=100, help="Number of tracks per event"
0076 )
0077 p.add_argument(
0078 "-j", "--threads", type=int, default=-1, help="Number of threads in parallel"
0079 )
0080 p.add_argument(
0081 "-m", "--map", type=str, default="", help="Input file for the material map"
0082 )
0083 p.add_argument("-o", "--output", type=str, default="", help="Output file name")
0084
0085 p.add_argument(
0086 "--experimental",
0087 action=argparse.BooleanOptionalAction,
0088 help="Construct experimental geometry",
0089 )
0090
0091 p.add_argument(
0092 "--geomodel-input",
0093 type=str,
0094 default="",
0095 help="Construct experimental geometry from GeoModel",
0096 )
0097
0098 p.add_argument(
0099 "--geomodel-name-list",
0100 type=str,
0101 nargs="+",
0102 default=[],
0103 help="List of Name List for the Surface Factory",
0104 )
0105
0106 p.add_argument(
0107 "--geomodel-material-list",
0108 type=str,
0109 nargs="+",
0110 default=[],
0111 help="List of Material List for the Surface Factory",
0112 )
0113
0114 p.add_argument(
0115 "--geomodel-convert-subvols",
0116 help="Convert the children of the top level full phys vol",
0117 action="store_true",
0118 default=False,
0119 )
0120
0121 p.add_argument(
0122 "--geomodel-top-node",
0123 type=str,
0124 default="",
0125 help="Top node definition of the GeoModel tree",
0126 )
0127
0128 p.add_argument(
0129 "--geomodel-table-name",
0130 type=str,
0131 default="ActsBlueprint",
0132 help="Name of the blueprint table",
0133 )
0134
0135 p.add_argument(
0136 "--geomodel-queries",
0137 nargs="+",
0138 type=str,
0139 default=[],
0140 help="Queries for published GeoModel nodes",
0141 )
0142
0143 args = p.parse_args()
0144 gContext = GeometryContext()
0145 logLevel = acts.logging.INFO
0146
0147 materialDecorator = None
0148 if args.map != "":
0149 materialDecorator = acts.IMaterialDecorator.fromFile(args.map)
0150
0151 if args.experimental:
0152 if len(args.geomodel_input) > 0:
0153 from acts import geomodel as gm
0154
0155
0156 gmTree = acts.geomodel.readFromDb(args.geomodel_input)
0157
0158 gmFactoryConfig = gm.GeoModelDetectorObjectFactory.Config()
0159 gmFactoryConfig.materialList = args.geomodel_material_list
0160 gmFactoryConfig.nameList = args.geomodel_name_list
0161 gmFactoryConfig.convertSubVolumes = args.geomodel_convert_subvols
0162 gmFactory = gm.GeoModelDetectorObjectFactory(gmFactoryConfig, logLevel)
0163
0164 gmFactoryOptions = gm.GeoModelDetectorObjectFactory.Options()
0165 gmFactoryOptions.queries = args.geomodel_queries
0166
0167 gmFactoryCache = gm.GeoModelDetectorObjectFactory.Cache()
0168 gmFactory.construct(gmFactoryCache, gContext, gmTree, gmFactoryOptions)
0169
0170
0171 gmSurfaces = [ss[1] for ss in gmFactoryCache.sensitiveSurfaces]
0172
0173
0174 gmBlueprintConfig = gm.GeoModelBlueprintCreater.Config()
0175 gmBlueprintConfig.detectorSurfaces = gmSurfaces
0176 gmBlueprintConfig.kdtBinning = [
0177 acts.AxisDirection.AxisZ,
0178 acts.AxisDirection.AxisR,
0179 ]
0180
0181 gmBlueprintOptions = gm.GeoModelBlueprintCreater.Options()
0182 gmBlueprintOptions.table = args.geomodel_table_name
0183 gmBlueprintOptions.topEntry = args.geomodel_top_node
0184 gmBlueprintCreater = gm.GeoModelBlueprintCreater(
0185 gmBlueprintConfig, logLevel
0186 )
0187 gmBlueprint = gmBlueprintCreater.create(
0188 gContext, gmTree, gmBlueprintOptions
0189 )
0190
0191 gmCylindricalBuilder = gmBlueprint.convertToBuilder(logLevel)
0192
0193
0194 gmGeoIdConfig = GeometryIdGenerator.Config()
0195 gmGeoIdGenerator = GeometryIdGenerator(
0196 gmGeoIdConfig, "GeoModelGeoIdGenerator", logging.INFO
0197 )
0198
0199
0200 gmDetectorConfig = DetectorBuilder.Config()
0201 gmDetectorConfig.name = args.geomodel_top_node + "_DetectorBuilder"
0202 gmDetectorConfig.builder = gmCylindricalBuilder
0203 gmDetectorConfig.geoIdGenerator = gmGeoIdGenerator
0204 gmDetectorConfig.materialDecorator = materialDecorator
0205 gmDetectorConfig.auxiliary = (
0206 "GeoModel based Acts::Detector from '" + args.geomodel_input + "'"
0207 )
0208
0209 gmDetectorBuilder = DetectorBuilder(
0210 gmDetectorConfig, args.geomodel_top_node, logLevel
0211 )
0212 detector = gmDetectorBuilder.construct(gContext)
0213
0214 materialSurfaces = detector.extractMaterialSurfaces()
0215 else:
0216 from acts.examples.dd4hep import (
0217 DD4hepDetector,
0218 DD4hepDetectorOptions,
0219 DD4hepGeometryService,
0220 )
0221
0222 from acts.examples.odd import (
0223 getOpenDataDetector,
0224 getOpenDataDetectorDirectory,
0225 )
0226
0227 odd_xml = getOpenDataDetectorDirectory() / "xml" / "OpenDataDetector.xml"
0228
0229
0230 dd4hepConfig = DD4hepGeometryService.Config()
0231 dd4hepConfig.logLevel = acts.logging.INFO
0232 dd4hepConfig.xmlFileNames = [str(odd_xml)]
0233 dd4hepGeometryService = DD4hepGeometryService(dd4hepConfig)
0234 dd4hepDetector = DD4hepDetector(dd4hepGeometryService)
0235
0236 cOptions = DD4hepDetectorOptions(
0237 logLevel=acts.logging.INFO, emulateToGraph=""
0238 )
0239 cOptions.materialDecorator = materialDecorator
0240
0241
0242 geoContext = acts.GeometryContext()
0243 [detector, contextors, store] = dd4hepDetector.finalize(
0244 geoContext, cOptions
0245 )
0246
0247 materialSurfaces = detector.extractMaterialSurfaces()
0248
0249 else:
0250 detector = getOpenDataDetector(materialDecorator)
0251 trackingGeometry = detector.trackingGeometry()
0252
0253 materialSurfaces = trackingGeometry.extractMaterialSurfaces()
0254
0255 s = acts.examples.Sequencer(events=args.events, numThreads=args.threads)
0256
0257 runMaterialValidation(
0258 s, args.tracks, materialSurfaces, args.output, 42, acts.logging.INFO
0259 ).run()