2 from pathlib
import Path
3 from typing
import Optional
10 TrackParameterSelector,
18 u = acts.UnitConstants
24 outputRoot: bool =
True,
25 inputParticlePath: Optional[Path] =
None,
26 inputTrackSummary: Path =
None,
27 vertexFinder: VertexFinder = VertexFinder.Truth,
30 s = s
or Sequencer(events=100, numThreads=-1)
32 logger = acts.logging.getLogger(
"VertexFittingExample")
34 rnd = acts.examples.RandomNumbers(seed=42)
36 inputParticles =
"particles_input"
37 if inputParticlePath
is None:
38 logger.info(
"Generating particles using Pythia8")
41 logger.info(
"Reading particles from %s", inputParticlePath.resolve())
42 assert inputParticlePath.exists()
44 acts.examples.RootParticleReader(
45 level=acts.logging.INFO,
46 filePath=
str(inputParticlePath.resolve()),
47 particleCollection=inputParticles,
52 selectedParticles =
"particles_selected"
53 ptclSelector = ParticleSelector(
54 level=acts.logging.INFO,
55 inputParticles=inputParticles,
56 outputParticles=selectedParticles,
62 s.addAlgorithm(ptclSelector)
64 trackParameters =
"fittedTrackParameters"
66 if inputTrackSummary
is None or inputParticlePath
is None:
67 logger.info(
"Using smeared particles")
69 ptclSmearing = ParticleSmearing(
70 level=acts.logging.INFO,
71 inputParticles=selectedParticles,
72 outputTrackParameters=trackParameters,
75 s.addAlgorithm(ptclSmearing)
76 associatedParticles = selectedParticles
78 logger.info(
"Reading track summary from %s", inputTrackSummary.resolve())
79 assert inputTrackSummary.exists()
80 associatedParticles =
"associatedTruthParticles"
81 trackSummaryReader = acts.examples.RootTrajectorySummaryReader(
82 level=acts.logging.VERBOSE,
83 outputTracks=trackParameters,
84 outputParticles=associatedParticles,
85 filePath=
str(inputTrackSummary.resolve()),
88 s.addReader(trackSummaryReader)
90 trackParamSelector = TrackParameterSelector(
91 level=acts.logging.INFO,
92 inputTrackParameters=trackSummaryReader.config.outputTracks,
93 outputTrackParameters=
"selectedTrackParameters",
98 s.addAlgorithm(trackParamSelector)
99 trackParameters = trackParamSelector.config.outputTrackParameters
101 logger.info(
"Using vertex finder: %s", vertexFinder.name)
106 trackParameters=trackParameters,
107 associatedParticles=associatedParticles,
109 vertexFinder=vertexFinder,
110 outputDirRoot=outputDir
if outputRoot
else None,
116 if "__main__" == __name__:
117 detector, trackingGeometry, decorators = acts.examples.GenericDetector.create()
119 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
121 inputParticlePath = Path(
"particles.root")
122 if not inputParticlePath.exists():
123 inputParticlePath =
None
125 inputTrackSummary =
None
126 for p
in (
"tracksummary_fitter.root",
"tracksummary_ckf.root"):
129 inputTrackSummary = p
134 vertexFinder=VertexFinder.Truth,
135 inputParticlePath=inputParticlePath,
136 inputTrackSummary=inputTrackSummary,
137 outputDir=Path.cwd(),