Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvTrackParameterWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvTrackParameterWriter.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 
16 
17 #include <optional>
18 #include <stdexcept>
19 
20 #include <dfe/dfe_io_dsv.hpp>
21 
22 #include "CsvOutputData.hpp"
23 
27  : m_cfg(config),
28  m_logger(Acts::getDefaultLogger("CsvTrackParameterWriter", level)) {
29  if (m_cfg.inputTrackParameters.empty() == m_cfg.inputTrajectories.empty()) {
30  throw std::invalid_argument(
31  "You have to either provide track parameters or trajectories");
32  }
33 
36 }
37 
39 
41  return "CsvTrackParameterWriter";
42 }
43 
45  // Write the tree
46  return ProcessCode::SUCCESS;
47 }
48 
50  const AlgorithmContext& ctx) {
51  std::vector<Acts::BoundTrackParameters> inputTrackParameters;
52 
53  if (!m_cfg.inputTrackParameters.empty()) {
54  const auto& tmp = m_inputTrackParameters(ctx);
55  inputTrackParameters = tmp;
56  } else {
57  const auto& inputTrajectories = m_inputTrajectories(ctx);
58 
59  for (const auto& trajectories : inputTrajectories) {
60  for (auto tip : trajectories.tips()) {
61  if (!trajectories.hasTrackParameters(tip)) {
62  continue;
63  }
64  const auto& trackParam = trajectories.trackParameters(tip);
65  inputTrackParameters.push_back(trackParam);
66  }
67  }
68  }
69 
71  perEventFilepath(m_cfg.outputDir, m_cfg.outputStem, ctx.eventNumber);
72 
73  dfe::NamedTupleCsvWriter<TrackParameterData> writer(path,
74  m_cfg.outputPrecision);
75 
77  for (const auto& tp : inputTrackParameters) {
78  const auto& params = tp.parameters();
79  const auto& cov = tp.covariance().value();
80 
81  data.d0 = params[Acts::eBoundLoc0];
82  data.z0 = params[Acts::eBoundLoc1];
83  data.phi = params[Acts::eBoundPhi];
84  data.theta = params[Acts::eBoundTheta];
85  data.qop = params[Acts::eBoundQOverP];
86 
92 
97 
100  data.cov_z0theta = cov(Acts::eBoundLoc1, Acts::eBoundTheta);
102 
105  data.cov_phitheta = cov(Acts::eBoundPhi, Acts::eBoundTheta);
107 
108  data.cov_thetad0 = cov(Acts::eBoundTheta, Acts::eBoundLoc0);
109  data.cov_thetaz0 = cov(Acts::eBoundTheta, Acts::eBoundLoc1);
110  data.cov_thetaphi = cov(Acts::eBoundTheta, Acts::eBoundPhi);
111  data.cov_thetaqop = cov(Acts::eBoundTheta, Acts::eBoundQOverP);
112 
116  data.cov_qoptheta = cov(Acts::eBoundQOverP, Acts::eBoundTheta);
117 
118  writer.append(data);
119  }
120 
122 }