ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjSurfaceWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ObjSurfaceWriter.cpp
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 
10 
12 #include <Acts/Geometry/Layer.hpp>
17 #include <ios>
18 #include <iostream>
19 #include <stdexcept>
20 
23  : m_cfg(cfg) {
24  // Validate the configuration
25  if (!m_cfg.logger) {
26  throw std::invalid_argument("Missing logger");
27  } else if (m_cfg.name.empty()) {
28  throw std::invalid_argument("Missing algorithm name");
29  } else if (!m_cfg.outputStream) {
30  throw std::invalid_argument("Missing output stream");
31  }
32 
33  // Write down the file prefix
34  (*(m_cfg.outputStream)) << m_cfg.filePrefix << '\n';
35 }
36 
37 std::string FW::Obj::ObjSurfaceWriter::name() const {
38  return m_cfg.name;
39 }
40 
43  std::lock_guard<std::mutex> lock(m_write_mutex);
44 
45  ACTS_DEBUG(">>Obj: Writer for Surface object called.");
46 
47  auto scalor = m_cfg.outputScalor;
48  // let's get the bounds & the transform
49  const Acts::SurfaceBounds& surfaceBounds = surface.bounds();
50  auto sTransform = surface.transform(context.geoContext);
51 
52  // dynamic_cast to PlanarBounds
53  const Acts::PlanarBounds* planarBounds =
54  dynamic_cast<const Acts::PlanarBounds*>(&surfaceBounds);
55  // only continue if the cast worked
56  if (planarBounds && m_cfg.outputSensitive) {
57  ACTS_VERBOSE(">>Obj: Writing out a PlaneSurface");
58  // set the precision - just to be sure
59  (*(m_cfg.outputStream)) << '\n';
60  (*(m_cfg.outputStream)) << std::setprecision(m_cfg.outputPrecision);
61  // get the vertices
62  auto planarVertices = planarBounds->vertices();
63  // loop over the vertices
64  std::vector<Acts::Vector3D> vertices;
65  vertices.reserve(planarVertices.size());
66  for (auto pv : planarVertices) {
67  // get the point in 3D
68  Acts::Vector3D v3D(sTransform * Acts::Vector3D(pv.x(), pv.y(), 0.));
69  vertices.push_back(v3D);
70  }
71  // get the thickness and vertical faces
72  double thickness = 0.;
73  std::vector<unsigned int> vfaces;
74  if (surface.associatedDetectorElement() and m_cfg.outputThickness != 0.) {
75  // get the thickness form the detector element
76  thickness = surface.associatedDetectorElement()->thickness();
77  vfaces = {1, 1, 1, 1};
78  }
79  // output to file
80  Obj::writePlanarFace(*(m_cfg.outputStream), m_vtnCounter, scalor, vertices,
81  thickness, vfaces);
82  (*(m_cfg.outputStream)) << '\n';
83  }
84 
85  // check if you have layer and check what your have
86  // dynamic cast to CylinderBounds work the same
87  const Acts::CylinderBounds* cylinderBounds =
88  dynamic_cast<const Acts::CylinderBounds*>(&surfaceBounds);
89  if (cylinderBounds && m_cfg.outputLayerSurface) {
90  ACTS_VERBOSE(">>Obj: Writing out a CylinderSurface with r = "
91  << cylinderBounds->get(Acts::CylinderBounds::eR));
92  // name the object
93  auto layerID = surface.geoID().layer();
94  (*(m_cfg.outputStream))
95  << " o Cylinder_" << std::to_string(layerID) << '\n';
96  // output to the file
97  Obj::writeTube(*(m_cfg.outputStream), m_vtnCounter, scalor,
98  m_cfg.outputPhiSegemnts, sTransform,
99  cylinderBounds->get(Acts::CylinderBounds::eR),
100  cylinderBounds->get(Acts::CylinderBounds::eHalfLengthZ),
101  m_cfg.outputThickness);
102  (*(m_cfg.outputStream)) << '\n';
103  }
104 
106  const Acts::RadialBounds* radialBounds =
107  dynamic_cast<const Acts::RadialBounds*>(&surfaceBounds);
108  if (radialBounds && m_cfg.outputLayerSurface) {
109  ACTS_VERBOSE(">>Obj: Writing out a DiskSurface at z = "
110  << sTransform.translation().z());
111  // name the object
112  auto layerID = surface.geoID().layer();
113  (*(m_cfg.outputStream)) << "o Disk_" << std::to_string(layerID) << '\n';
114  // we use the tube writer in the other direction
115  double rMin = radialBounds->rMin();
116  double rMax = radialBounds->rMax();
117  double thickness = rMax - rMin;
118  // output to the file
119  Obj::writeTube(*(m_cfg.outputStream), m_vtnCounter, scalor,
120  m_cfg.outputPhiSegemnts, sTransform, 0.5 * (rMin + rMax),
121  m_cfg.outputThickness, thickness);
122  (*(m_cfg.outputStream)) << '\n';
123  }
124 
125  // return success
127 }