forked from sPHENIX-Collaboration/acts
/
VertexingDataHelper.hpp
151 lines (130 loc) · 5.53 KB
/
VertexingDataHelper.hpp
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
// This file is part of the Acts project.
//
// Copyright (C) 2020 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/.
#pragma once
#include "Acts/Tests/CommonHelpers/DataDirectory.hpp"
#include "Acts/Utilities/Definitions.hpp"
#include "Acts/Utilities/Units.hpp"
#include "Acts/Vertexing/Vertex.hpp"
#include <fstream>
#include <iterator>
#include <regex>
namespace Acts {
namespace Test {
using namespace Acts::UnitLiterals;
using Covariance = BoundSymMatrix;
// Create a test context
GeometryContext geoCtx = GeometryContext();
enum VertexCsvData { BeamSpotData, VerticesData, TracksData };
/// @brief Helper struct to store reference vertex related information
struct VertexInfo {
// The position
Vector3D position;
// The covariance
ActsSymMatrixD<3> covariance;
// Number of tracks
int nTracks;
// Weight of first track
double trk1Weight;
// Vertex compatibility value of first track
double trk1Comp;
// Chi2 of first track
double trk1Chi2;
};
inline std::tuple<Vertex<BoundTrackParameters>, std::vector<VertexInfo>,
std::vector<BoundTrackParameters>>
readTracksAndVertexCSV(std::string toolString,
std::string fileBase = "vertexing_event_mu20") {
const auto beamspotDataPath =
Acts::Test::getDataPath(fileBase + "_beamspot.csv");
const auto tracksDataPath = Acts::Test::getDataPath(fileBase + "_tracks.csv");
const auto verticesDataPath =
Acts::Test::getDataPath(fileBase + "_vertices_" + toolString + ".csv");
const std::regex comma(",");
// Open source files
std::ifstream beamspotData(beamspotDataPath);
std::ifstream tracksData(tracksDataPath);
std::ifstream verticesData(verticesDataPath);
// String to store the read lines
std::string line{};
std::shared_ptr<PerigeeSurface> perigeeSurface;
std::vector<BoundTrackParameters> tracks;
std::vector<VertexInfo> vertices;
Vertex<BoundTrackParameters> beamspotConstraint;
// Read in beamspot data
std::getline(beamspotData, line); // skip header
while (beamspotData && std::getline(beamspotData, line)) {
// Tokenize line and store result in vector
std::vector<std::string> row{
std::sregex_token_iterator(line.begin(), line.end(), comma, -1),
std::sregex_token_iterator()};
Vector3D beamspotPos;
ActsSymMatrixD<3> beamspotCov;
beamspotPos << std::stod(row[0]) * (1_mm), std::stod(row[1]) * (1_mm),
std::stod(row[2]) * (1_mm);
beamspotCov << std::stod(row[3]), 0, 0, 0, std::stod(row[4]), 0, 0, 0,
std::stod(row[5]);
beamspotConstraint.setPosition(beamspotPos);
beamspotConstraint.setCovariance(beamspotCov);
perigeeSurface = Surface::makeShared<PerigeeSurface>(beamspotPos);
}
// Read in track data
std::getline(tracksData, line); // skip header
while (tracksData && std::getline(tracksData, line)) {
// Tokenize line and store result in vector
std::vector<std::string> row{
std::sregex_token_iterator(line.begin(), line.end(), comma, -1),
std::sregex_token_iterator()};
BoundVector params;
params << std::stod(row[0]), std::stod(row[1]), std::stod(row[2]),
std::stod(row[3]), std::stod(row[4]) * 1. / (1_MeV), std::stod(row[5]);
Covariance covMat;
covMat << std::stod(row[6]), std::stod(row[7]), std::stod(row[8]),
std::stod(row[9]), std::stod(row[10]) * 1. / (1_MeV),
std::stod(row[11]), std::stod(row[7]), std::stod(row[12]),
std::stod(row[13]), std::stod(row[14]),
std::stod(row[15]) * 1. / (1_MeV), std::stod(row[16]),
std::stod(row[8]), std::stod(row[13]), std::stod(row[17]),
std::stod(row[18]), std::stod(row[19]) * 1. / (1_MeV),
std::stod(row[20]), std::stod(row[9]), std::stod(row[14]),
std::stod(row[18]), std::stod(row[21]),
std::stod(row[22]) * 1. / (1_MeV), std::stod(row[23]),
std::stod(row[10]) * 1. / (1_MeV), std::stod(row[15]) * 1. / (1_MeV),
std::stod(row[19]) * 1. / (1_MeV), std::stod(row[22]) * 1. / (1_MeV),
std::stod(row[24]) * 1. / (1_MeV * 1_MeV),
std::stod(row[25]) * 1. / (1_MeV), std::stod(row[11]),
std::stod(row[16]), std::stod(row[20]), std::stod(row[23]),
std::stod(row[25]) * 1. / (1_MeV), std::stod(row[26]);
tracks.emplace_back(perigeeSurface, params, std::move(covMat));
}
// Read in reference vertex data
std::getline(verticesData, line); // skip header
while (verticesData && std::getline(verticesData, line)) {
// Tokenize line and store result in vector
std::vector<std::string> row{
std::sregex_token_iterator(line.begin(), line.end(), comma, -1),
std::sregex_token_iterator()};
Vector3D pos;
pos << std::stod(row[0]) * (1_mm), std::stod(row[1]) * (1_mm),
std::stod(row[2]) * (1_mm);
ActsSymMatrixD<3> cov;
cov << std::stod(row[3]), std::stod(row[4]), std::stod(row[5]),
std::stod(row[6]), std::stod(row[7]), std::stod(row[8]),
std::stod(row[9]), std::stod(row[10]), std::stod(row[11]);
VertexInfo vertexInfo;
vertexInfo.position = pos;
vertexInfo.covariance = cov;
vertexInfo.nTracks = std::stoi(row[12]);
vertexInfo.trk1Weight = std::stod(row[13]);
vertexInfo.trk1Comp = std::stod(row[14]);
vertexInfo.trk1Chi2 = std::stod(row[15]);
vertices.push_back(vertexInfo);
}
return std::make_tuple(beamspotConstraint, vertices, tracks);
}
} // namespace Test
} // namespace Acts