Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjPropagationStepsWriter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ObjPropagationStepsWriter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 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 
9 #pragma once
10 
14 
15 #include <fstream>
16 
17 namespace ActsExamples {
18 
28 template <typename step_t>
30  : public WriterT<std::vector<std::vector<step_t>>> {
31  public:
32  struct Config {
35  double outputScalor = 1.0;
36  size_t outputPrecision = 6;
37  };
38 
45  : WriterT<std::vector<std::vector<step_t>>>(cfg.collection,
46  "ObjSpacePointWriter", level),
47  m_cfg(cfg) {
48  if (m_cfg.collection.empty()) {
49  throw std::invalid_argument("Missing input collection");
50  }
51  }
52 
54  ~ObjPropagationStepsWriter() override = default;
55 
58 
60  const Config& config() const { return m_cfg; }
61 
62  private:
64 
65  protected:
69  const AlgorithmContext& context,
70  const std::vector<std::vector<step_t>>& stepCollection) override {
71  // open per-event file
73  m_cfg.outputDir, "propagation-steps.obj", context.eventNumber);
74  std::ofstream os(path, std::ofstream::out | std::ofstream::trunc);
75  if (!os) {
76  throw std::ios_base::failure("Could not open '" + path + "' to write");
77  }
78 
79  // Initialize the vertex counter
80  unsigned int vCounter = 0;
81 
82  for (auto& steps : stepCollection) {
83  // At least three points to draw
84  if (steps.size() > 2) {
85  // We start from one
86  ++vCounter;
87  for (auto& step : steps) {
88  // Write the space point
89  os << "v " << m_cfg.outputScalor * step.position.x() << " "
90  << m_cfg.outputScalor * step.position.y() << " "
91  << m_cfg.outputScalor * step.position.z() << '\n';
92  }
93  // Write out the line - only if we have at least two points created
94  size_t vBreak = vCounter + steps.size() - 1;
95  for (; vCounter < vBreak; ++vCounter) {
96  os << "l " << vCounter << " " << vCounter + 1 << '\n';
97  }
98  }
99  }
101  }
102 };
103 
104 } // namespace ActsExamples