forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathitk_seeding.py
More file actions
executable file
·151 lines (125 loc) · 9.66 KB
/
itk_seeding.py
File metadata and controls
executable file
·151 lines (125 loc) · 9.66 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
#!/usr/bin/env python3
# Example script to run ITk seed finding based on CSV space points
import os
import tempfile
import pathlib, acts, acts.root
from acts.examples import (
CsvSpacePointReader,
TrackParamsEstimationAlgorithm,
)
from acts.examples.reconstruction import (
addStandardSeeding,
)
from acts.examples.itk import InputSpacePointsType
u = acts.UnitConstants
rnd = acts.examples.RandomNumbers(seed=42)
def runITkSeedingFromCsv(detector, trackingGeometry, field, outputDir):
# create temporary file with pixel SPs and run the seeding
with tempfile.TemporaryDirectory() as tmpdirname:
temp = open(tmpdirname + "/event000000000-spacepoints_pixel.csv", "w+t")
print(
"created temporary file: "
+ tmpdirname
+ "/event000000000-spacepoints_pixel.csv"
)
temp.write(
"measurement_id,sp_type,module_idhash,sp_x,sp_y,sp_z,sp_radius,sp_covr,sp_covz,sp_topHalfStripLength,sp_bottomHalfStripLength,sp_topStripDirection[0],sp_topStripDirection[1],sp_topStripDirection[2],sp_bottomStripDirection[0],sp_bottomStripDirection[1],sp_bottomStripDirection[2],sp_stripCenterDistance[0],sp_stripCenterDistance[1],sp_stripCenterDistance[2],sp_topStripCenterPosition[0],sp_topStripCenterPosition[1],sp_topStripCenterPosition[2]\n 1,0,3139,32.67557144165039,-5.311902523040771,-47.65000152587891,33.10452270507812,0.05999999865889549,0.02999880164861679,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n 2,0,3422,95.14442443847656,-15.46361255645752,-52.125,96.39286804199219,0.05999999865889549,0.01687432639300823,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n 3,0,3650,102.8257064819336,-16.71612739562988,-52.67499923706055,104.1755981445312,0.05999999865889549,0.001875000074505806,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n 4,0,4223,159.4266204833984,-25.91166687011719,-56.75,161.5186157226562,0.05999999865889549,0.02999880164861679,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n 5,0,5015,224.07958984375,-36.37123107910156,-61.40000152587891,227.0121765136719,0.05999999865889549,0.007499700412154198,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n 6,0,6023,284.1485595703125,-46.0638542175293,-65.72499847412109,287.8580932617188,0.05999999865889549,0.001875000074505806,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
)
temp.read()
s = acts.examples.Sequencer(events=1, numThreads=-1, logLevel=acts.logging.INFO)
# Read input space points from input csv files
evReader = CsvSpacePointReader(
level=acts.logging.INFO,
inputStem="spacepoints",
inputCollection="pixel",
inputDir=os.path.dirname(temp.name),
outputSpacePoints="PixelSpacePoint",
extendCollection=False,
)
# add csv reader
s.addReader(evReader)
spacePoints = evReader.config.outputSpacePoints
# run seeding
inputSeeds = addStandardSeeding(
s,
spacePoints,
*acts.examples.itk.itkSeedingAlgConfig(
InputSpacePointsType.PixelSpacePoints
),
)
protoTracks = "seed-protoTracks"
s.addAlgorithm(
acts.examples.SeedsToProtoTracks(
level=acts.logging.INFO,
inputSeeds=inputSeeds,
outputProtoTracks=protoTracks,
)
)
# estimate seeding performance
parEstimateAlg = TrackParamsEstimationAlgorithm(
level=acts.logging.INFO,
inputSeeds=inputSeeds,
outputTrackParameters="estimatedparameters",
trackingGeometry=trackingGeometry,
magneticField=field,
)
s.addAlgorithm(parEstimateAlg)
s.run()
# create temporary file with strips SPs and run the seeding
with tempfile.TemporaryDirectory() as tmpdirname:
temp = open(tmpdirname + "/event000000000-spacepoints_strip.csv", "w+t")
print(
"created temporary file: "
+ tmpdirname
+ "/event000000000-spacepoints_strip.csv"
)
temp.write(
"measurement_id,sp_type,module_idhash,sp_x,sp_y,sp_z,sp_radius,sp_covr,sp_covz,sp_topHalfStripLength,sp_bottomHalfStripLength,sp_topStripDirection[0],sp_topStripDirection[1],sp_topStripDirection[2],sp_bottomStripDirection[0],sp_bottomStripDirection[1],sp_bottomStripDirection[2],sp_stripCenterDistance[0],sp_stripCenterDistance[1],sp_stripCenterDistance[2],sp_topStripCenterPosition[0],sp_topStripCenterPosition[1],sp_topStripCenterPosition[2]\n 0,1,0,386.77178955078125,-62.579288482666015625,-72.66841888427734375,391.801727294921875,0.100000001490116119384765625,5.11999988555908203125,12.08999919891357421875,12.08999919891357421875,-0.00864744372665882110595703125,-0.02451671846210956573486328125,0.999662101268768310546875,0.00864744372665882110595703125,0.02451671846210956573486328125,0.999662101268768310546875,-6.43960094451904296875,1.04346692562103271484375,23.157070159912109375,386.6771240234375,-62.847682952880859375,-61.724697113037109375\n 1,1,0,543.9947509765625,-87.7279205322265625,-82.09113311767578125,551.02313232421875,0.100000001490116119384765625,5.11999988555908203125,12.08999919891357421875,12.08999919891357421875,-0.0073835677467286586761474609375,-0.024926505982875823974609375,0.999662101268768310546875,0.0073835677467286586761474609375,0.024926505982875823974609375,0.999662101268768310546875,-6.34883975982666015625,1.17108881473541259765625,-2.3926274776458740234375,544.0279541015625,-87.6157989501953125,-86.58742523193359375\n 2,1,0,544.00189208984375,-87.70365142822265625,-83.064239501953125,551.02630615234375,0.100000001490116119384765625,5.11999988555908203125,12.08999919891357421875,12.08999919891357421875,-0.0073835677467286586761474609375,-0.024926505982875823974609375,0.999662101268768310546875,0.011192028410732746124267578125,0.02346457540988922119140625,0.999662101268768310546875,-24.83704376220703125,4.08867168426513671875,-0.0274789035320281982421875,544.0279541015625,-87.6157989501953125,-86.58742523193359375\n 3,1,0,562.2547607421875,-90.650543212890625,-83.99970245361328125,569.5155029296875,0.100000001490116119384765625,5.11999988555908203125,12.08999919891357421875,12.08999919891357421875,-0.011192028410732746124267578125,-0.02346457540988922119140625,0.999662101268768310546875,0.0073835677467286586761474609375,0.024926505982875823974609375,0.999662101268768310546875,11.8808460235595703125,-1.85768926143646240234375,-0.0588833652436733245849609375,562.25762939453125,-90.6445770263671875,-84.2536773681640625\n 4,1,0,562.26605224609375,-90.62686920166015625,-85.00818634033203125,569.52288818359375,0.100000001490116119384765625,5.11999988555908203125,12.08999919891357421875,12.08999919891357421875,-0.011192028410732746124267578125,-0.02346457540988922119140625,0.999662101268768310546875,0.011192028410732746124267578125,0.02346457540988922119140625,0.999662101268768310546875,-6.60735797882080078125,1.05989348888397216796875,2.3062651157379150390625,562.25762939453125,-90.6445770263671875,-84.2536773681640625\n 5,1,0,750.5875244140625,-120.5648040771484375,-98.9385986328125,760.2088623046875,0.100000001490116119384765625,5.11999988555908203125,24.1799983978271484375,24.1799983978271484375,-0.009588238783180713653564453125,-0.02416430227458477020263671875,0.999662101268768310546875,0.009588238783180713653564453125,0.02416430227458477020263671875,0.999662101268768310546875,-6.041371822357177734375,2.1813886165618896484375,0.3670396506786346435546875,750.81573486328125,-119.98968505859375,-122.7309112548828125\n 6,1,0,979.34979248046875,-156.5580291748046875,-114.63397979736328125,991.78448486328125,0.100000001490116119384765625,5.11999988555908203125,24.1799983978271484375,24.1799983978271484375,-0.00824898667633533477783203125,-0.02465364150702953338623046875,0.999662101268768310546875,0.00824898667633533477783203125,0.02465364150702953338623046875,0.999662101268768310546875,-6.2955722808837890625,1.417438507080078125,-1.45441913604736328125,979.4241943359375,-156.335723876953125,-123.64752960205078125"
)
temp.read()
s = acts.examples.Sequencer(events=1, numThreads=-1, logLevel=acts.logging.INFO)
# Read input space points from input csv files
evReader = CsvSpacePointReader(
level=acts.logging.INFO,
inputStem="spacepoints",
inputCollection="strip",
inputDir=os.path.dirname(temp.name),
outputSpacePoints="StripSpacePoint",
extendCollection=True,
)
# add csv reader
s.addReader(evReader)
spacePoints = evReader.config.outputSpacePoints
# run seeding
inputSeeds = addStandardSeeding(
s,
spacePoints,
*acts.examples.itk.itkSeedingAlgConfig(
InputSpacePointsType.StripSpacePoints
),
)
protoTracks = "seed-protoTracks"
s.addAlgorithm(
acts.examples.SeedsToProtoTracks(
level=acts.logging.INFO,
inputSeeds=inputSeeds,
outputProtoTracks=protoTracks,
)
)
# estimate seeding performance
parEstimateAlg = TrackParamsEstimationAlgorithm(
level=acts.logging.INFO,
inputSeeds=inputSeeds,
outputTrackParameters="estimatedparameters",
trackingGeometry=trackingGeometry,
magneticField=field,
)
s.addAlgorithm(parEstimateAlg)
s.run()
if "__main__" == __name__:
geo_dir = pathlib.Path("acts-itk")
outputDir = pathlib.Path.cwd() / "itk_output"
detector = acts.examples.itk.buildITkGeometry(geo_dir)
trackingGeometry = detector.trackingGeometry()
field = acts.root.MagneticFieldMapXyz(str(geo_dir / "bfield/ATLAS-BField-xyz.root"))
runITkSeedingFromCsv(detector, trackingGeometry, field, outputDir)