File indexing completed on 2025-12-13 09:22:15
0001
0002
0003 from pathlib import Path
0004 from typing import Optional
0005
0006 import acts
0007 import acts.examples
0008
0009 u = acts.UnitConstants
0010
0011
0012 def createStripSpacepoints(
0013 trackingGeometry: acts.TrackingGeometry,
0014 field: acts.MagneticFieldProvider,
0015 digiConfigFile: Path,
0016 geoSelection: Path,
0017 outputDir: Path,
0018 inputParticlePath: Optional[Path] = None,
0019 inputHitsPath: Optional[Path] = None,
0020 decorators=[],
0021 reverseFilteringMomThreshold=0 * u.GeV,
0022 s: acts.examples.Sequencer = None,
0023 ):
0024 from acts.examples.simulation import (
0025 addParticleGun,
0026 ParticleConfig,
0027 EtaConfig,
0028 PhiConfig,
0029 MomentumConfig,
0030 addFatras,
0031 addDigitization,
0032 )
0033
0034 from acts.examples.root import (
0035 RootParticleReader,
0036 RootSimHitReader,
0037 RootSpacepointWriter,
0038 )
0039
0040 s = s or acts.examples.Sequencer(
0041 events=100, numThreads=1, logLevel=acts.logging.INFO
0042 )
0043
0044 for d in decorators:
0045 s.addContextDecorator(d)
0046
0047 rnd = acts.examples.RandomNumbers(seed=42)
0048 outputDir = Path(outputDir)
0049
0050 logger = acts.logging.getLogger("Truth tracking example")
0051
0052 if inputParticlePath is None:
0053
0054 addParticleGun(
0055 s,
0056 ParticleConfig(num=1, pdg=acts.PdgParticle.eMuon, randomizeCharge=True),
0057 EtaConfig(-2.0, 2.0, uniform=True),
0058 MomentumConfig(1.0 * u.GeV, 100.0 * u.GeV, transverse=True),
0059 PhiConfig(0.0, 360.0 * u.degree),
0060 vtxGen=acts.examples.GaussianVertexGenerator(
0061 mean=acts.Vector4(0, 0, 0, 0),
0062 stddev=acts.Vector4(0, 0, 0, 0),
0063 ),
0064 multiplicity=1,
0065 rnd=rnd,
0066 )
0067 else:
0068 logger.info("Reading particles from %s", inputParticlePath.resolve())
0069 assert inputParticlePath.exists()
0070 s.addReader(
0071 RootParticleReader(
0072 level=acts.logging.INFO,
0073 filePath=str(inputParticlePath.resolve()),
0074 outputParticles="particles_generated",
0075 )
0076 )
0077 s.addWhiteboardAlias("particles", "particles_generated")
0078
0079 if inputHitsPath is None:
0080 addFatras(
0081 s,
0082 trackingGeometry,
0083 field,
0084 rnd=rnd,
0085 enableInteractions=True,
0086 )
0087 else:
0088 logger.info("Reading hits from %s", inputHitsPath.resolve())
0089 assert inputHitsPath.exists()
0090 s.addReader(
0091 RootSimHitReader(
0092 level=acts.logging.INFO,
0093 filePath=str(inputHitsPath.resolve()),
0094 outputSimHits="simhits",
0095 )
0096 )
0097
0098 addDigitization(
0099 s,
0100 trackingGeometry,
0101 field,
0102 digiConfigFile=digiConfigFile,
0103 rnd=rnd,
0104 )
0105
0106
0107 s.addAlgorithm(
0108 acts.examples.SpacePointMaker(
0109 level=acts.logging.INFO,
0110 trackingGeometry=trackingGeometry,
0111 inputMeasurements="measurements",
0112 outputSpacePoints="spacepoints",
0113 stripGeometrySelection=acts.examples.json.readJsonGeometryList(
0114 str(geoSelection)
0115 ),
0116 )
0117 )
0118
0119 s.addWriter(
0120 RootSpacepointWriter(
0121 level=acts.logging.INFO,
0122 inputSpacepoints="spacepoints",
0123 inputMeasurementParticlesMap="measurement_particles_map",
0124 filePath=str(outputDir / "strip_spacepoints.root"),
0125 )
0126 )
0127
0128 return s
0129
0130
0131 if "__main__" == __name__:
0132 srcdir = Path(__file__).resolve().parent.parent.parent.parent
0133
0134
0135 from acts.examples.odd import (
0136 getOpenDataDetector,
0137 getOpenDataDetectorDirectory,
0138 )
0139
0140 detector = getOpenDataDetector()
0141 trackingGeometry = detector.trackingGeometry()
0142 digiConfigFile = (
0143 getOpenDataDetectorDirectory() / "config/odd-digi-smearing-config.json"
0144 )
0145
0146 geoSelection = srcdir / "Examples/Configs/odd-strip-spacepoint-selection.json"
0147 print(geoSelection.resolve())
0148 assert geoSelection.exists()
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
0159
0160 createStripSpacepoints(
0161 trackingGeometry=trackingGeometry,
0162 field=field,
0163 digiConfigFile=digiConfigFile,
0164 geoSelection=geoSelection,
0165 outputDir=Path.cwd(),
0166 ).run()