Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvTrackParameterReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvTrackParameterReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
10 
18 
19 #include <algorithm>
20 #include <stdexcept>
21 #include <string>
22 
23 #include <dfe/dfe_io_dsv.hpp>
24 
25 #include "CsvOutputData.hpp"
26 
30  : m_cfg(config),
31  m_eventsRange(
32  determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
33  m_logger(Acts::getDefaultLogger("CsvTrackParameterReader", level)) {
34  if (m_cfg.inputStem.empty()) {
35  throw std::invalid_argument("Missing input filename stem");
36  }
37  if (m_cfg.outputTrackParameters.empty()) {
38  throw std::invalid_argument("Missing output collection");
39  }
40 
42 }
43 
46  return "CsvTrackParameterReader";
47 }
48 
49 std::pair<size_t, size_t>
51  return m_eventsRange;
52 }
53 
55  const ActsExamples::AlgorithmContext& ctx) {
56  TrackParametersContainer trackParameters;
57 
58  auto surface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
59  Acts::Vector3(m_cfg.beamspot[0], m_cfg.beamspot[1], m_cfg.beamspot[2]));
60 
61  auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
62  ctx.eventNumber);
63  dfe::NamedTupleCsvReader<TrackParameterData> reader(path);
65 
66  while (reader.read(d)) {
67  Acts::BoundVector params = Acts::BoundVector::Zero();
68  params[Acts::eBoundLoc0] = d.d0;
69  params[Acts::eBoundLoc1] = d.z0;
70  params[Acts::eBoundPhi] = d.phi;
71  params[Acts::eBoundTheta] = d.theta;
72  params[Acts::eBoundQOverP] = d.qop;
73 
74  Acts::BoundSquareMatrix cov = Acts::BoundSquareMatrix::Zero();
77  cov(Acts::eBoundPhi, Acts::eBoundPhi) = d.var_phi;
78  cov(Acts::eBoundTheta, Acts::eBoundTheta) = d.var_theta;
81 
82  cov(Acts::eBoundLoc0, Acts::eBoundLoc1) = d.cov_d0z0;
83  cov(Acts::eBoundLoc0, Acts::eBoundPhi) = d.cov_d0phi;
84  cov(Acts::eBoundLoc0, Acts::eBoundTheta) = d.cov_d0theta;
85  cov(Acts::eBoundLoc0, Acts::eBoundQOverP) = d.cov_d0qop;
86 
87  cov(Acts::eBoundLoc1, Acts::eBoundLoc0) = d.cov_z0d0;
88  cov(Acts::eBoundLoc1, Acts::eBoundPhi) = d.cov_z0phi;
89  cov(Acts::eBoundLoc1, Acts::eBoundTheta) = d.cov_z0theta;
90  cov(Acts::eBoundLoc1, Acts::eBoundQOverP) = d.cov_z0qop;
91 
92  cov(Acts::eBoundPhi, Acts::eBoundLoc0) = d.cov_phid0;
93  cov(Acts::eBoundPhi, Acts::eBoundLoc1) = d.cov_phiz0;
94  cov(Acts::eBoundPhi, Acts::eBoundTheta) = d.cov_phitheta;
95  cov(Acts::eBoundPhi, Acts::eBoundQOverP) = d.cov_phiqop;
96 
97  cov(Acts::eBoundTheta, Acts::eBoundLoc0) = d.cov_thetad0;
98  cov(Acts::eBoundTheta, Acts::eBoundLoc1) = d.cov_thetaz0;
99  cov(Acts::eBoundTheta, Acts::eBoundPhi) = d.cov_thetaphi;
100  cov(Acts::eBoundTheta, Acts::eBoundQOverP) = d.cov_thetaqop;
101 
102  cov(Acts::eBoundQOverP, Acts::eBoundLoc0) = d.cov_qopd0;
103  cov(Acts::eBoundQOverP, Acts::eBoundLoc1) = d.cov_qopz0;
104  cov(Acts::eBoundQOverP, Acts::eBoundPhi) = d.cov_qopphi;
105  cov(Acts::eBoundQOverP, Acts::eBoundTheta) = d.cov_qoptheta;
106 
107  // TODO we do not have a hypothesis at hand here. defaulting to pion
108  trackParameters.emplace_back(surface, params, cov,
110  }
111 
112  m_outputTrackParameters(ctx, std::move(trackParameters));
113 
114  return ProcessCode::SUCCESS;
115 }