forked from sPHENIX-Collaboration/acts
/
SeedfinderTest.cpp
201 lines (182 loc) · 6.49 KB
/
SeedfinderTest.cpp
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
// This file is part of the Acts project.
//
// Copyright (C) 2019 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 http://mozilla.org/MPL/2.0/.
#include "Acts/Seeding/BinFinder.hpp"
#include "Acts/Seeding/BinnedSPGroup.hpp"
#include "Acts/Seeding/InternalSeed.hpp"
#include "Acts/Seeding/InternalSpacePoint.hpp"
#include "Acts/Seeding/Seed.hpp"
#include "Acts/Seeding/SeedFilter.hpp"
#include "Acts/Seeding/Seedfinder.hpp"
#include "Acts/Seeding/SpacePointGrid.hpp"
#include <chrono>
#include <fstream>
#include <iostream>
#include <sstream>
#include <utility>
#include <boost/type_erasure/any_cast.hpp>
#include "ATLASCuts.hpp"
#include "SpacePoint.hpp"
std::vector<const SpacePoint*> readFile(std::string filename) {
std::string line;
int layer;
std::vector<const SpacePoint*> readSP;
std::ifstream spFile(filename);
if (spFile.is_open()) {
while (!spFile.eof()) {
std::getline(spFile, line);
std::stringstream ss(line);
std::string linetype;
ss >> linetype;
float x, y, z, r, varianceR, varianceZ;
if (linetype == "lxyz") {
ss >> layer >> x >> y >> z >> varianceR >> varianceZ;
r = std::sqrt(x * x + y * y);
float f22 = varianceR;
float wid = varianceZ;
float cov = wid * wid * .08333;
if (cov < f22)
cov = f22;
if (std::abs(z) > 450.) {
varianceZ = 9. * cov;
varianceR = .06;
} else {
varianceR = 9. * cov;
varianceZ = .06;
}
SpacePoint* sp =
new SpacePoint{x, y, z, r, layer, varianceR, varianceZ};
// if(r < 200.){
// sp->setClusterList(1,0);
// }
readSP.push_back(sp);
}
}
}
return readSP;
}
int main(int argc, char** argv) {
std::string file{"sp.txt"};
bool help(false);
bool quiet(false);
int opt;
while ((opt = getopt(argc, argv, "hf:q")) != -1) {
switch (opt) {
case 'f':
file = optarg;
break;
case 'q':
quiet = true;
break;
case 'h':
help = true;
[[fallthrough]];
default: /* '?' */
std::cerr << "Usage: " << argv[0] << " [-hq] [-f FILENAME]\n";
if (help) {
std::cout << " -h : this help" << std::endl;
std::cout
<< " -f FILE : read spacepoints from FILE. Default is \""
<< file << "\"" << std::endl;
std::cout << " -q : don't print out all found seeds"
<< std::endl;
}
exit(EXIT_FAILURE);
}
}
std::ifstream f(file);
if (!f.good()) {
std::cerr << "input file \"" << file << "\" does not exist\n";
exit(EXIT_FAILURE);
}
auto start_read = std::chrono::system_clock::now();
std::vector<const SpacePoint*> spVec = readFile(file);
auto end_read = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_read = end_read - start_read;
std::cout << "read " << spVec.size() << " SP from file " << file << " in "
<< elapsed_read.count() << "s" << std::endl;
Acts::SeedfinderConfig<SpacePoint> config;
// silicon detector max
config.rMax = 160.;
config.deltaRMin = 5.;
config.deltaRMax = 160.;
config.collisionRegionMin = -250.;
config.collisionRegionMax = 250.;
config.zMin = -2800.;
config.zMax = 2800.;
config.maxSeedsPerSpM = 5;
// 2.7 eta
config.cotThetaMax = 7.40627;
config.sigmaScattering = 1.00000;
config.minPt = 500.;
config.bFieldInZ = 0.00199724;
config.beamPos = {-.5, -.5};
config.impactMax = 10.;
auto bottomBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
Acts::BinFinder<SpacePoint>());
auto topBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
Acts::BinFinder<SpacePoint>());
Acts::SeedFilterConfig sfconf;
Acts::ATLASCuts<SpacePoint> atlasCuts = Acts::ATLASCuts<SpacePoint>();
config.seedFilter = std::make_unique<Acts::SeedFilter<SpacePoint>>(
Acts::SeedFilter<SpacePoint>(sfconf, &atlasCuts));
Acts::Seedfinder<SpacePoint> a(config);
// covariance tool, sets covariances per spacepoint as required
auto ct = [=](const SpacePoint& sp, float, float, float) -> Acts::Vector2D {
return {sp.varianceR, sp.varianceZ};
};
// setup spacepoint grid config
Acts::SpacePointGridConfig gridConf;
gridConf.bFieldInZ = config.bFieldInZ;
gridConf.minPt = config.minPt;
gridConf.rMax = config.rMax;
gridConf.zMax = config.zMax;
gridConf.zMin = config.zMin;
gridConf.deltaRMax = config.deltaRMax;
gridConf.cotThetaMax = config.cotThetaMax;
// create grid with bin sizes according to the configured geometry
std::unique_ptr<Acts::SpacePointGrid<SpacePoint>> grid =
Acts::SpacePointGridCreator::createGrid<SpacePoint>(gridConf);
auto spGroup = Acts::BinnedSPGroup<SpacePoint>(spVec.begin(), spVec.end(), ct,
bottomBinFinder, topBinFinder,
std::move(grid), config);
std::vector<std::vector<Acts::Seed<SpacePoint>>> seedVector;
auto start = std::chrono::system_clock::now();
auto groupIt = spGroup.begin();
auto endOfGroups = spGroup.end();
for (; !(groupIt == endOfGroups); ++groupIt) {
seedVector.push_back(a.createSeedsForGroup(
groupIt.bottom(), groupIt.middle(), groupIt.top()));
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "time to create seeds: " << elapsed_seconds.count() << std::endl;
std::cout << "Number of regions: " << seedVector.size() << std::endl;
int numSeeds = 0;
for (auto& outVec : seedVector) {
numSeeds += outVec.size();
}
std::cout << "Number of seeds generated: " << numSeeds << std::endl;
if (!quiet) {
for (auto& regionVec : seedVector) {
for (size_t i = 0; i < regionVec.size(); i++) {
const Acts::Seed<SpacePoint>* seed = ®ionVec[i];
const SpacePoint* sp = seed->sp()[0];
std::cout << " (" << sp->x() << ", " << sp->y() << ", " << sp->z()
<< ") ";
sp = seed->sp()[1];
std::cout << sp->surface << " (" << sp->x() << ", " << sp->y() << ", "
<< sp->z() << ") ";
sp = seed->sp()[2];
std::cout << sp->surface << " (" << sp->x() << ", " << sp->y() << ", "
<< sp->z() << ") ";
std::cout << std::endl;
}
}
}
return 0;
}