forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvertex_fitting.py
More file actions
executable file
·148 lines (126 loc) · 4.37 KB
/
vertex_fitting.py
File metadata and controls
executable file
·148 lines (126 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
from pathlib import Path
from typing import Optional
import acts
from acts.examples import (
Sequencer,
ParticleSelector,
TrackParameterSmearing,
TrackParameterSelector,
)
from acts.examples.simulation import addPythia8
from acts.examples.reconstruction import (
addVertexFitting,
VertexFinder,
)
from acts.examples.root import (
RootParticleReader,
RootTrackSummaryReader,
)
u = acts.UnitConstants
def runVertexFitting(
field,
outputDir: Path,
outputRoot: bool = True,
inputParticlePath: Optional[Path] = None,
inputTrackSummary: Path = None,
vertexFinder: VertexFinder = VertexFinder.Truth,
s=None,
):
s = s or Sequencer(events=100, numThreads=-1)
logger = acts.getDefaultLogger("VertexFittingExample", acts.logging.INFO)
rnd = acts.examples.RandomNumbers(seed=42)
inputParticles = "particles_generated"
if inputParticlePath is None:
logger.info("Generating particles using Pythia8")
addPythia8(s, rnd)
else:
logger.info("Reading particles from {}", inputParticlePath.resolve())
assert inputParticlePath.exists()
s.addReader(
RootParticleReader(
level=acts.logging.INFO,
filePath=str(inputParticlePath.resolve()),
outputParticles=inputParticles,
)
)
selectedParticles = "particles_selected"
ptclSelector = ParticleSelector(
level=acts.logging.INFO,
inputParticles=inputParticles,
outputParticles=selectedParticles,
removeNeutral=True,
absEtaMax=2.5,
rhoMax=4.0 * u.mm,
ptMin=500 * u.MeV,
)
s.addAlgorithm(ptclSelector)
trackParameters = "fittedTrackParameters"
if inputTrackSummary is None or inputParticlePath is None:
logger.info("Using smeared particles")
trkParamExtractor = acts.examples.ParticleTrackParamExtractor(
level=acts.logging.WARNING,
inputParticles=selectedParticles,
outputTrackParameters="params_particles_generated",
)
s.addAlgorithm(trkParamExtractor)
ptclSmearing = TrackParameterSmearing(
level=acts.logging.INFO,
inputTrackParameters="params_particles_generated",
outputTrackParameters=trackParameters,
randomNumbers=rnd,
)
s.addAlgorithm(ptclSmearing)
associatedParticles = selectedParticles
else:
logger.info("Reading track summary from %s", inputTrackSummary.resolve())
assert inputTrackSummary.exists()
associatedParticles = "associatedTruthParticles"
trackSummaryReader = RootTrackSummaryReader(
level=acts.logging.VERBOSE,
outputTracks=trackParameters,
outputParticles=associatedParticles,
filePath=str(inputTrackSummary.resolve()),
)
s.addReader(trackSummaryReader)
trackParamSelector = TrackParameterSelector(
level=acts.logging.INFO,
inputTrackParameters=trackSummaryReader.config.outputTracks,
outputTrackParameters="selectedTrackParameters",
absEtaMax=2.5,
loc0Max=4.0 * u.mm, # rho max
ptMin=500 * u.MeV,
)
s.addAlgorithm(trackParamSelector)
trackParameters = trackParamSelector.config.outputTrackParameters
logger.info("Using vertex finder: %s", vertexFinder.name)
addVertexFitting(
s,
field,
trackParameters=trackParameters,
associatedParticles=associatedParticles,
trajectories=None,
vertexFinder=vertexFinder,
outputDirRoot=outputDir if outputRoot else None,
)
return s
if "__main__" == __name__:
detector = acts.examples.GenericDetector()
trackingGeometry = detector.trackingGeometry()
field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
inputParticlePath = Path("particles.root")
if not inputParticlePath.exists():
inputParticlePath = None
inputTrackSummary = None
for p in ("tracksummary_fitter.root", "tracksummary_ckf.root"):
p = Path(p)
if p.exists():
inputTrackSummary = p
break
runVertexFitting(
field,
vertexFinder=VertexFinder.Truth,
inputParticlePath=inputParticlePath,
inputTrackSummary=inputTrackSummary,
outputDir=Path.cwd(),
).run()