File indexing completed on 2025-08-05 08:10:09
0001
0002 import os
0003 import argparse
0004 from pathlib import Path
0005
0006 from acts.examples import Sequencer, RootMaterialTrackWriter
0007
0008 import acts
0009
0010
0011 def runMaterialValidation(
0012 trackingGeometry,
0013 decorators,
0014 field,
0015 outputDir,
0016 outputName="propagation-material",
0017 dumpPropagationSteps=False,
0018 s=None,
0019 ):
0020 s = s or Sequencer(events=1000, numThreads=-1)
0021
0022 for decorator in decorators:
0023 s.addContextDecorator(decorator)
0024
0025 nav = acts.Navigator(
0026 trackingGeometry=trackingGeometry,
0027 resolveSensitive=True,
0028 resolveMaterial=True,
0029 resolvePassive=True,
0030 )
0031
0032
0033 stepper = acts.EigenStepper(field)
0034
0035 prop = acts.examples.ConcretePropagator(acts.Propagator(stepper, nav))
0036
0037 alg = acts.examples.PropagationAlgorithm(
0038 propagatorImpl=prop,
0039 level=acts.logging.INFO,
0040 randomNumberSvc=acts.examples.RandomNumbers(),
0041 ntests=1000,
0042 sterileLogger=False,
0043 recordMaterialInteractions=True,
0044 d0Sigma=0,
0045 z0Sigma=0,
0046 )
0047
0048 s.addAlgorithm(alg)
0049
0050 s.addWriter(
0051 RootMaterialTrackWriter(
0052 level=acts.logging.INFO,
0053 inputMaterialTracks=alg.config.propagationMaterialCollection,
0054 filePath=os.path.join(outputDir, (outputName + ".root")),
0055 storeSurface=True,
0056 storeVolume=True,
0057 )
0058 )
0059
0060 if dumpPropagationSteps:
0061 s.addWriter(
0062 acts.examples.RootPropagationStepsWriter(
0063 level=acts.logging.INFO,
0064 collection=alg.config.propagationStepCollection,
0065 filePath=outputDir + "/propagation_steps.root",
0066 )
0067 )
0068
0069 return s
0070
0071
0072 if "__main__" == __name__:
0073 p = argparse.ArgumentParser(
0074 description="Script to run material validation on ITk geometry"
0075 )
0076 p.add_argument(
0077 "geo_dir",
0078 help="Input directory containing the ITk standalone geometry. Get in touch if you don't have this.",
0079 )
0080 p.add_argument("--material", type=str, default="", help="Material file")
0081
0082 args = p.parse_args()
0083
0084 geo_example_dir = Path(args.geo_dir)
0085 assert geo_example_dir.exists(), "Detector example input directory missing"
0086 assert os.path.exists(
0087 args.material
0088 ), "Invalid file path/name in --material. Please check your input!"
0089
0090 from acts.examples.itk import buildITkGeometry
0091
0092 detector, trackingGeometry, decorators = buildITkGeometry(
0093 geo_example_dir, customMaterialFile=args.material
0094 )
0095
0096 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * acts.UnitConstants.T))
0097
0098 runMaterialValidation(
0099 trackingGeometry, decorators, field, outputDir=os.getcwd()
0100 ).run()