EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SeedfinderTest.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SeedfinderTest.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
13 #include "Acts/Seeding/Seed.hpp"
17 
18 #include <chrono>
19 #include <fstream>
20 #include <iostream>
21 #include <sstream>
22 #include <utility>
23 
24 #include <boost/type_erasure/any_cast.hpp>
25 
26 #include "ATLASCuts.hpp"
27 #include "SpacePoint.hpp"
28 
29 std::vector<const SpacePoint*> readFile(std::string filename) {
30  std::string line;
31  int layer;
32  std::vector<const SpacePoint*> readSP;
33 
34  std::ifstream spFile(filename);
35  if (spFile.is_open()) {
36  while (!spFile.eof()) {
37  std::getline(spFile, line);
38  std::stringstream ss(line);
39  std::string linetype;
40  ss >> linetype;
41  float x, y, z, r, varianceR, varianceZ;
42  if (linetype == "lxyz") {
43  ss >> layer >> x >> y >> z >> varianceR >> varianceZ;
44  r = std::sqrt(x * x + y * y);
45  float f22 = varianceR;
46  float wid = varianceZ;
47  float cov = wid * wid * .08333;
48  if (cov < f22)
49  cov = f22;
50  if (std::abs(z) > 450.) {
51  varianceZ = 9. * cov;
52  varianceR = .06;
53  } else {
54  varianceR = 9. * cov;
55  varianceZ = .06;
56  }
57  SpacePoint* sp =
58  new SpacePoint{x, y, z, r, layer, varianceR, varianceZ};
59  // if(r < 200.){
60  // sp->setClusterList(1,0);
61  // }
62  readSP.push_back(sp);
63  }
64  }
65  }
66  return readSP;
67 }
68 
69 int main(int argc, char** argv) {
70  std::string file{"sp.txt"};
71  bool help(false);
72  bool quiet(false);
73 
74  int opt;
75  while ((opt = getopt(argc, argv, "hf:q")) != -1) {
76  switch (opt) {
77  case 'f':
78  file = optarg;
79  break;
80  case 'q':
81  quiet = true;
82  break;
83  case 'h':
84  help = true;
85  [[fallthrough]];
86  default: /* '?' */
87  std::cerr << "Usage: " << argv[0] << " [-hq] [-f FILENAME]\n";
88  if (help) {
89  std::cout << " -h : this help" << std::endl;
90  std::cout
91  << " -f FILE : read spacepoints from FILE. Default is \""
92  << file << "\"" << std::endl;
93  std::cout << " -q : don't print out all found seeds"
94  << std::endl;
95  }
96 
97  exit(EXIT_FAILURE);
98  }
99  }
100 
101  std::ifstream f(file);
102  if (!f.good()) {
103  std::cerr << "input file \"" << file << "\" does not exist\n";
104  exit(EXIT_FAILURE);
105  }
106 
107  auto start_read = std::chrono::system_clock::now();
108  std::vector<const SpacePoint*> spVec = readFile(file);
109  auto end_read = std::chrono::system_clock::now();
110  std::chrono::duration<double> elapsed_read = end_read - start_read;
111 
112  std::cout << "read " << spVec.size() << " SP from file " << file << " in "
113  << elapsed_read.count() << "s" << std::endl;
114 
116  // silicon detector max
117  config.rMax = 160.;
118  config.deltaRMin = 5.;
119  config.deltaRMax = 160.;
120  config.collisionRegionMin = -250.;
121  config.collisionRegionMax = 250.;
122  config.zMin = -2800.;
123  config.zMax = 2800.;
124  config.maxSeedsPerSpM = 5;
125  // 2.7 eta
126  config.cotThetaMax = 7.40627;
127  config.sigmaScattering = 1.00000;
128 
129  config.minPt = 500.;
130  config.bFieldInZ = 0.00199724;
131 
132  config.beamPos = {-.5, -.5};
133  config.impactMax = 10.;
134 
135  auto bottomBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
137  auto topBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
139  Acts::SeedFilterConfig sfconf;
141  config.seedFilter = std::make_unique<Acts::SeedFilter<SpacePoint>>(
142  Acts::SeedFilter<SpacePoint>(sfconf, &atlasCuts));
144 
145  // covariance tool, sets covariances per spacepoint as required
146  auto ct = [=](const SpacePoint& sp, float, float, float) -> Acts::Vector2D {
147  return {sp.varianceR, sp.varianceZ};
148  };
149 
150  // setup spacepoint grid config
152  gridConf.bFieldInZ = config.bFieldInZ;
153  gridConf.minPt = config.minPt;
154  gridConf.rMax = config.rMax;
155  gridConf.zMax = config.zMax;
156  gridConf.zMin = config.zMin;
157  gridConf.deltaRMax = config.deltaRMax;
158  gridConf.cotThetaMax = config.cotThetaMax;
159  // create grid with bin sizes according to the configured geometry
160  std::unique_ptr<Acts::SpacePointGrid<SpacePoint>> grid =
161  Acts::SpacePointGridCreator::createGrid<SpacePoint>(gridConf);
162  auto spGroup = Acts::BinnedSPGroup<SpacePoint>(spVec.begin(), spVec.end(), ct,
163  bottomBinFinder, topBinFinder,
164  std::move(grid), config);
165 
166  std::vector<std::vector<Acts::Seed<SpacePoint>>> seedVector;
167  auto start = std::chrono::system_clock::now();
168  auto groupIt = spGroup.begin();
169  auto endOfGroups = spGroup.end();
170  for (; !(groupIt == endOfGroups); ++groupIt) {
171  seedVector.push_back(a.createSeedsForGroup(
172  groupIt.bottom(), groupIt.middle(), groupIt.top()));
173  }
174  auto end = std::chrono::system_clock::now();
175  std::chrono::duration<double> elapsed_seconds = end - start;
176  std::cout << "time to create seeds: " << elapsed_seconds.count() << std::endl;
177  std::cout << "Number of regions: " << seedVector.size() << std::endl;
178  int numSeeds = 0;
179  for (auto& outVec : seedVector) {
180  numSeeds += outVec.size();
181  }
182  std::cout << "Number of seeds generated: " << numSeeds << std::endl;
183  if (!quiet) {
184  for (auto& regionVec : seedVector) {
185  for (size_t i = 0; i < regionVec.size(); i++) {
186  const Acts::Seed<SpacePoint>* seed = &regionVec[i];
187  const SpacePoint* sp = seed->sp()[0];
188  std::cout << " (" << sp->x() << ", " << sp->y() << ", " << sp->z()
189  << ") ";
190  sp = seed->sp()[1];
191  std::cout << sp->surface << " (" << sp->x() << ", " << sp->y() << ", "
192  << sp->z() << ") ";
193  sp = seed->sp()[2];
194  std::cout << sp->surface << " (" << sp->x() << ", " << sp->y() << ", "
195  << sp->z() << ") ";
196  std::cout << std::endl;
197  }
198  }
199  }
200  return 0;
201 }