forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathckf_tracks.py
More file actions
executable file
·210 lines (191 loc) · 5.72 KB
/
ckf_tracks.py
File metadata and controls
executable file
·210 lines (191 loc) · 5.72 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
from pathlib import Path
from typing import Optional
import acts
from acts import UnitConstants as u
from acts.examples import GenericDetector
from acts.examples.root import RootParticleReader
def runCKFTracks(
trackingGeometry,
decorators,
geometrySelection: Path,
digiConfigFile: Path,
field,
outputDir: Path,
outputCsv=True,
truthSmearedSeeded=False,
truthEstimatedSeeded=False,
inputParticlePath: Optional[Path] = None,
s=None,
):
from acts.examples.simulation import (
addParticleGun,
MomentumConfig,
EtaConfig,
PhiConfig,
ParticleConfig,
addFatras,
addDigitization,
ParticleSelectorConfig,
addDigiParticleSelection,
)
from acts.examples.reconstruction import (
addSeeding,
TrackSmearingSigmas,
SeedFinderConfigArg,
SeedFinderOptionsArg,
SeedingAlgorithm,
TruthEstimatedSeedingAlgorithmConfigArg,
addCKFTracks,
TrackSelectorConfig,
CkfConfig,
)
s = s or acts.examples.Sequencer(
events=100, numThreads=-1, logLevel=acts.logging.INFO
)
for d in decorators:
s.addContextDecorator(d)
rnd = acts.examples.RandomNumbers(seed=42)
outputDir = Path(outputDir)
if inputParticlePath is None:
addParticleGun(
s,
MomentumConfig(1 * u.GeV, 10 * u.GeV, transverse=True),
EtaConfig(-2.0, 2.0, uniform=True),
PhiConfig(0.0, 360.0 * u.degree),
ParticleConfig(4, acts.PdgParticle.eMuon, randomizeCharge=True),
multiplicity=2,
rnd=rnd,
)
else:
acts.getDefaultLogger("CKFExample", acts.logging.INFO).info(
"Reading particles from {}", inputParticlePath.resolve()
)
assert inputParticlePath.exists()
s.addReader(
RootParticleReader(
level=acts.logging.INFO,
filePath=str(inputParticlePath.resolve()),
outputParticles="particles_generated",
)
)
addFatras(
s,
trackingGeometry,
field,
rnd=rnd,
)
addDigitization(
s,
trackingGeometry,
field,
digiConfigFile=digiConfigFile,
rnd=rnd,
)
addDigiParticleSelection(
s,
ParticleSelectorConfig(
pt=(0.5 * u.GeV, None),
measurements=(9, None),
removeNeutral=True,
),
)
addSeeding(
s,
trackingGeometry,
field,
TrackSmearingSigmas( # only used by SeedingAlgorithm.TruthSmeared
# zero everything so the CKF has a chance to find the measurements
loc0=0,
loc0PtA=0,
loc0PtB=0,
loc1=0,
loc1PtA=0,
loc1PtB=0,
time=0,
phi=0,
theta=0,
ptRel=0,
),
SeedFinderConfigArg(
r=(None, 200 * u.mm), # rMin=default, 33mm
deltaR=(1 * u.mm, 300 * u.mm),
collisionRegion=(-250 * u.mm, 250 * u.mm),
z=(-2000 * u.mm, 2000 * u.mm),
maxSeedsPerSpM=1,
sigmaScattering=5,
radLengthPerSeed=0.1,
minPt=500 * u.MeV,
impactMax=3 * u.mm,
),
SeedFinderOptionsArg(bFieldInZ=2 * u.T, beamPos=(0.0, 0.0)),
TruthEstimatedSeedingAlgorithmConfigArg(deltaR=(10.0 * u.mm, None)),
seedingAlgorithm=(
SeedingAlgorithm.TruthSmeared
if truthSmearedSeeded
else (
SeedingAlgorithm.TruthEstimated
if truthEstimatedSeeded
else SeedingAlgorithm.GridTriplet
)
),
initialSigmas=[
1 * u.mm,
1 * u.mm,
1 * u.degree,
1 * u.degree,
0 * u.e / u.GeV,
1 * u.ns,
],
initialSigmaQoverPt=0.1 * u.e / u.GeV,
initialSigmaPtRel=0.1,
initialVarInflation=[1.0] * 6,
geoSelectionConfigFile=geometrySelection,
outputDirRoot=outputDir,
rnd=rnd, # only used by SeedingAlgorithm.TruthSmeared
)
addCKFTracks(
s,
trackingGeometry,
field,
TrackSelectorConfig(
pt=(500 * u.MeV, None),
absEta=(None, 3.0),
loc0=(-4.0 * u.mm, 4.0 * u.mm),
nMeasurementsMin=7,
maxHoles=2,
maxOutliers=2,
),
CkfConfig(
chi2CutOffMeasurement=15.0,
chi2CutOffOutlier=25.0,
numMeasurementsCutOff=10,
seedDeduplication=True if not truthSmearedSeeded else False,
stayOnSeed=True if not truthSmearedSeeded else False,
),
outputDirRoot=outputDir,
outputDirCsv=outputDir / "csv" if outputCsv else None,
writeTrackStates=True,
)
return s
if "__main__" == __name__:
srcdir = Path(__file__).resolve().parent.parent.parent.parent
detector = GenericDetector()
trackingGeometry = detector.trackingGeometry()
decorators = detector.contextDecorators()
field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
inputParticlePath = Path("particles.root")
if not inputParticlePath.exists():
inputParticlePath = None
runCKFTracks(
trackingGeometry,
decorators,
field=field,
geometrySelection=srcdir / "Examples/Configs/generic-seeding-config.json",
digiConfigFile=srcdir / "Examples/Configs/generic-digi-smearing-config.json",
truthSmearedSeeded=False,
truthEstimatedSeeded=False,
inputParticlePath=inputParticlePath,
outputDir=Path.cwd(),
outputCsv=True,
).run()