forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrack_finding_python_only.py
More file actions
166 lines (132 loc) · 5.08 KB
/
track_finding_python_only.py
File metadata and controls
166 lines (132 loc) · 5.08 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
#!/usr/bin/env python3
# This file is part of the ACTS project.
#
# Copyright (C) 2016 CERN for the benefit of the ACTS project
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import os
from pathlib import Path
os.environ["ACTS_SEQUENCER_DISABLE_FPEMON"] = "1"
import acts
import acts.examples
from acts import UnitConstants as u
def runTrackFindingPythonOnly(
trackingGeometry,
field,
digiConfigFile,
geoSelectionConfigFile,
outputDir,
decorators=[],
s=None,
):
from acts.examples.simulation import (
addParticleGun,
MomentumConfig,
EtaConfig,
PhiConfig,
ParticleConfig,
addFatras,
addDigitization,
)
s = s or acts.examples.Sequencer(events=1, numThreads=1, logLevel=acts.logging.INFO)
outputDir = Path(outputDir)
rnd = acts.examples.RandomNumbers(seed=42)
for d in decorators:
s.addContextDecorator(d)
addParticleGun(
s,
MomentumConfig(1.0 * u.GeV, 10.0 * u.GeV, transverse=True),
EtaConfig(-2.0, 2.0, uniform=True),
PhiConfig(0.0, 360.0 * u.degree),
ParticleConfig(1, acts.PdgParticle.eMuon, randomizeCharge=True),
rnd=rnd,
)
addFatras(
s,
trackingGeometry,
field,
rnd=rnd,
)
addDigitization(
s,
trackingGeometry,
field,
digiConfigFile=digiConfigFile,
rnd=rnd,
)
s.addAlgorithm(
acts.examples.SpacePointMaker(
level=acts.logging.INFO,
trackingGeometry=trackingGeometry,
inputMeasurements="measurements",
outputSpacePoints="spacepoints",
geometrySelection=acts.examples.json.readJsonGeometryList(
str(geoSelectionConfigFile)
),
)
)
class PythonTrackFinder(acts.examples.IAlgorithm):
def __init__(self, name, level):
acts.examples.IAlgorithm.__init__(self, name, level)
self.spacepoints = acts.examples.ReadDataHandle(
self, acts.SpacePointContainer2, "Spacepoints"
)
self.spacepoints.initialize("spacepoints")
self.prototracks = acts.examples.WriteDataHandle(
self, acts.examples.ProtoTrackContainer, "Prototracks"
)
self.prototracks.initialize("prototracks")
def execute(self, context):
spacepoints = self.spacepoints(context.eventStore)
track = acts.examples.ProtoTrack()
for sp in sorted(spacepoints, key=lambda sp: sp.r):
for sl in sp.sourceLinks:
isl = acts.examples.IndexSourceLink.FromSourceLink(sl)
track.append(isl.index())
prototracks = acts.examples.ProtoTrackContainer()
prototracks.append(track)
self.prototracks(context, prototracks)
return acts.examples.ProcessCode.SUCCESS
s.addAlgorithm(PythonTrackFinder("PythonTrackFinder", acts.logging.INFO))
class PythonTrackFitter(acts.examples.IAlgorithm):
def __init__(self, name, level):
acts.examples.IAlgorithm.__init__(self, name, level)
self.prototracks = acts.examples.ReadDataHandle(
self, acts.examples.ProtoTrackContainer, "Prototracks"
)
self.prototracks.initialize("prototracks")
self.tracks = acts.examples.WriteDataHandle(
self, acts.examples.ConstTrackContainer, "Tracks"
)
self.tracks.initialize("fitted_tracks")
def execute(self, context):
prototracks = self.prototracks(context.eventStore)
container = acts.examples.TrackContainer()
for prototrack in prototracks:
track = container.makeTrack()
track.parameters = acts.BoundVector(1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
track.nMeasurements = len(prototrack)
self.tracks(context, container.makeConst())
return acts.examples.ProcessCode.SUCCESS
s.addAlgorithm(PythonTrackFitter("PythonTrackFitter", acts.logging.INFO))
return s
if __name__ == "__main__":
srcdir = Path(__file__).resolve().parent.parent.parent.parent
detector = acts.examples.GenericDetector(acts.examples.GenericDetector.Config())
trackingGeometry = detector.trackingGeometry()
decorators = detector.contextDecorators()
field = acts.ConstantBField(acts.Vector3(0.0, 0.0, 2.0 * u.T))
digiConfigFile = srcdir / "Examples/Configs/generic-digi-smearing-config.json"
geoSelectionConfigFile = srcdir / "Examples/Configs/generic-seeding-config.json"
outputDir = Path.cwd() / "output_track_finding_python_only"
outputDir.mkdir(exist_ok=True)
runTrackFindingPythonOnly(
trackingGeometry=trackingGeometry,
field=field,
digiConfigFile=digiConfigFile,
geoSelectionConfigFile=geoSelectionConfigFile,
outputDir=outputDir,
decorators=decorators,
).run()