Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:07

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // Local include(s).
0010 #include "ReadSeedFile.hpp"
0011 
0012 // System include(s).
0013 #include <cmath>
0014 #include <fstream>
0015 #include <iostream>
0016 #include <limits>
0017 #include <sstream>
0018 #include <stdexcept>
0019 
0020 std::vector<std::unique_ptr<TestSpacePoint> > readSeedFile(
0021     const std::string& fileName, bool filterDuplicates) {
0022   // The result object.
0023   std::vector<std::unique_ptr<TestSpacePoint> > result;
0024 
0025   // Open the input file.
0026   std::ifstream spFile(fileName);
0027   if (!spFile.is_open()) {
0028     throw std::runtime_error("Could not open file: " + fileName);
0029   }
0030 
0031   // Read the file's lines one by one, and create spacepoint objects out of
0032   // them.
0033   std::size_t duplicatesFound = 0;
0034   while (!spFile.eof()) {
0035     std::string line;
0036     std::getline(spFile, line);
0037     std::stringstream ss(line);
0038     std::string linetype;
0039 
0040     ss >> linetype;
0041     if (linetype != "lxyz") {
0042       continue;
0043     }
0044 
0045     int layer;
0046     float x, y, z, varianceR, varianceZ;
0047     ss >> layer >> x >> y >> z >> varianceR >> varianceZ;
0048     const float r = std::hypot(x, y);
0049     const float f22 = varianceR;
0050     const float wid = varianceZ;
0051     float cov = wid * wid * .08333;
0052 
0053     if (cov < f22) {
0054       cov = f22;
0055     }
0056     if (std::abs(z) > 450.) {
0057       varianceZ = 9. * cov;
0058       varianceR = .06;
0059     } else {
0060       varianceR = 9. * cov;
0061       varianceZ = .06;
0062     }
0063 
0064     // Create a new spacepoint object.
0065     std::unique_ptr<TestSpacePoint> sp(
0066         new TestSpacePoint{x, y, z, r, layer, varianceR, varianceZ});
0067 
0068     // Check if we already have another spacepoint with the same coordinates.
0069     if (filterDuplicates) {
0070       bool discardSP = false;
0071       for (const auto& otherSP : result) {
0072         if (*sp == *otherSP) {
0073           ++duplicatesFound;
0074           discardSP = true;
0075           break;
0076         }
0077       }
0078       if (discardSP) {
0079         continue;
0080       }
0081     }
0082 
0083     // Store the new spacepoint.
0084     result.push_back(std::move(sp));
0085   }
0086   // Tell the user how many duplicates were found.
0087   if (duplicatesFound) {
0088     std::cerr << duplicatesFound << " duplicates found in: " << fileName
0089               << std::endl;
0090   }
0091 
0092   return result;
0093 }