Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VertexingDataHelper.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VertexingDataHelper.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 #pragma once
9 
14 
15 #include <fstream>
16 #include <iterator>
17 #include <regex>
18 
19 namespace Acts {
20 namespace Test {
21 
22 using namespace Acts::UnitLiterals;
24 
25 // Create a test context
27 
29 
31 struct VertexInfo {
32  // The position
34  // The covariance
36  // Number of tracks
37  int nTracks = 0;
38  // Weight of first track
39  double trk1Weight = 0;
40  // Vertex compatibility value of first track
41  double trk1Comp = 0;
42  // Chi2 of first track
43  double trk1Chi2 = 0;
44 };
45 
46 inline std::tuple<Vertex<BoundTrackParameters>, std::vector<VertexInfo>,
47  std::vector<BoundTrackParameters>>
49  const std::string& fileBase = "vertexing_event_mu20") {
50  const auto beamspotDataPath =
51  Acts::Test::getDataPath(fileBase + "_beamspot.csv");
52  const auto tracksDataPath = Acts::Test::getDataPath(fileBase + "_tracks.csv");
53  const auto verticesDataPath =
54  Acts::Test::getDataPath(fileBase + "_vertices_" + toolString + ".csv");
55 
56  const std::regex comma(",");
57 
58  // Open source files
59  std::ifstream beamspotData(beamspotDataPath);
60  std::ifstream tracksData(tracksDataPath);
61  std::ifstream verticesData(verticesDataPath);
62 
63  // String to store the read lines
64  std::string line{};
65 
66  std::shared_ptr<PerigeeSurface> perigeeSurface;
67  std::vector<BoundTrackParameters> tracks;
68  std::vector<VertexInfo> vertices;
69  Vertex<BoundTrackParameters> beamspotConstraint;
70 
71  // Read in beamspot data
72  std::getline(beamspotData, line); // skip header
73  while (beamspotData && std::getline(beamspotData, line)) {
74  // Tokenize line and store result in vector
75  std::vector<std::string> row{
76  std::sregex_token_iterator(line.begin(), line.end(), comma, -1),
77  std::sregex_token_iterator()};
78 
79  Vector3 beamspotPos;
80  SquareMatrix3 beamspotCov;
81  beamspotPos << std::stod(row[0]) * (1_mm), std::stod(row[1]) * (1_mm),
82  std::stod(row[2]) * (1_mm);
83  beamspotCov << std::stod(row[3]), 0, 0, 0, std::stod(row[4]), 0, 0, 0,
84  std::stod(row[5]);
85  beamspotConstraint.setPosition(beamspotPos);
86  beamspotConstraint.setCovariance(beamspotCov);
87  perigeeSurface = Surface::makeShared<PerigeeSurface>(beamspotPos);
88  }
89 
90  // Read in track data
91  std::getline(tracksData, line); // skip header
92  while (tracksData && std::getline(tracksData, line)) {
93  // Tokenize line and store result in vector
94  std::vector<std::string> row{
95  std::sregex_token_iterator(line.begin(), line.end(), comma, -1),
96  std::sregex_token_iterator()};
97 
98  BoundVector params;
99  params << std::stod(row[0]), std::stod(row[1]), std::stod(row[2]),
100  std::stod(row[3]), std::stod(row[4]) * 1. / (1_MeV), std::stod(row[5]);
101  Covariance covMat;
102  covMat << std::stod(row[6]), std::stod(row[7]), std::stod(row[8]),
103  std::stod(row[9]), std::stod(row[10]) * 1. / (1_MeV),
104  std::stod(row[11]), std::stod(row[7]), std::stod(row[12]),
105  std::stod(row[13]), std::stod(row[14]),
106  std::stod(row[15]) * 1. / (1_MeV), std::stod(row[16]),
107  std::stod(row[8]), std::stod(row[13]), std::stod(row[17]),
108  std::stod(row[18]), std::stod(row[19]) * 1. / (1_MeV),
109  std::stod(row[20]), std::stod(row[9]), std::stod(row[14]),
110  std::stod(row[18]), std::stod(row[21]),
111  std::stod(row[22]) * 1. / (1_MeV), std::stod(row[23]),
112  std::stod(row[10]) * 1. / (1_MeV), std::stod(row[15]) * 1. / (1_MeV),
113  std::stod(row[19]) * 1. / (1_MeV), std::stod(row[22]) * 1. / (1_MeV),
114  std::stod(row[24]) * 1. / (1_MeV * 1_MeV),
115  std::stod(row[25]) * 1. / (1_MeV), std::stod(row[11]),
116  std::stod(row[16]), std::stod(row[20]), std::stod(row[23]),
117  std::stod(row[25]) * 1. / (1_MeV), std::stod(row[26]);
118 
119  // TODO we do not have a hypothesis at hand here. defaulting to pion
120  tracks.emplace_back(perigeeSurface, params, std::move(covMat),
122  }
123 
124  // Read in reference vertex data
125  std::getline(verticesData, line); // skip header
126  while (verticesData && std::getline(verticesData, line)) {
127  // Tokenize line and store result in vector
128  std::vector<std::string> row{
129  std::sregex_token_iterator(line.begin(), line.end(), comma, -1),
130  std::sregex_token_iterator()};
131 
132  Vector3 pos;
133  pos << std::stod(row[0]) * (1_mm), std::stod(row[1]) * (1_mm),
134  std::stod(row[2]) * (1_mm);
136  cov << std::stod(row[3]), std::stod(row[4]), std::stod(row[5]),
137  std::stod(row[6]), std::stod(row[7]), std::stod(row[8]),
138  std::stod(row[9]), std::stod(row[10]), std::stod(row[11]);
139  VertexInfo vertexInfo;
140  vertexInfo.position = pos;
141  vertexInfo.covariance = cov;
142  vertexInfo.nTracks = std::stoi(row[12]);
143  vertexInfo.trk1Weight = std::stod(row[13]);
144  vertexInfo.trk1Comp = std::stod(row[14]);
145  vertexInfo.trk1Chi2 = std::stod(row[15]);
146  vertices.push_back(vertexInfo);
147  }
148 
149  return std::make_tuple(beamspotConstraint, vertices, tracks);
150 }
151 
152 } // namespace Test
153 } // namespace Acts