Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvSpacePointWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvSpacePointWriter.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 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 
20 
21 #include <string>
22 #include <vector>
23 
24 #include <dfe/dfe_io_dsv.hpp>
25 
26 #include "CsvOutputData.hpp"
27 
31  : WriterT(config.inputSpacepoints, "CsvSpacepointWriter", level),
32  m_cfg(config) {}
33 
35 
37  // Write the tree
38  return ProcessCode::SUCCESS;
39 }
40 
42  const AlgorithmContext& ctx, const SimSpacePointContainer& spacepoints) {
43  // Open per-event file for all components
44  std::string pathSP =
45  perEventFilepath(m_cfg.outputDir, "spacepoint.csv", ctx.eventNumber);
46 
47  dfe::NamedTupleCsvWriter<SpacepointData> writerSP(pathSP,
48  m_cfg.outputPrecision);
49 
50  SpacepointData spData{};
51  for (const auto& sp : spacepoints) {
52  const auto slink = sp.sourceLinks()[0].get<IndexSourceLink>();
53 
54  spData.measurement_id = slink.index();
55  spData.geometry_id = slink.geometryId().value();
56  spData.x = sp.x();
57  spData.y = sp.y();
58  spData.z = sp.z();
59  spData.var_r = sp.varianceR();
60  spData.var_z = sp.varianceZ();
61  writerSP.append(spData);
62  }
64 }