ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Surface.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Surface.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 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 
11 #include <iomanip>
12 #include <iostream>
13 #include <utility>
14 
15 Acts::Surface::Surface(std::shared_ptr<const Transform3D> tform)
16  : GeometryObject(), m_transform(std::move(tform)) {}
17 
19  : GeometryObject(),
20  m_transform(nullptr),
21  m_associatedDetElement(&detelement) {}
22 
24  : GeometryObject(other),
26  m_transform(other.m_transform),
27  m_surfaceMaterial(other.m_surfaceMaterial) {}
28 
30  const Transform3D& shift)
31  : GeometryObject(),
32  m_transform(std::make_shared<const Transform3D>(
33  Transform3D(shift * other.transform(gctx)))),
34  m_associatedLayer(nullptr),
35  m_surfaceMaterial(other.m_surfaceMaterial) {}
36 
37 Acts::Surface::~Surface() = default;
38 
40  const Vector3D& position,
41  const Vector3D& momentum,
42  const BoundaryCheck& bcheck) const {
43  // create the local position
44  Vector2D lposition{0., 0.};
45  // global to local transformation
46  bool gtlSuccess = globalToLocal(gctx, position, momentum, lposition);
47  if (gtlSuccess) {
48  return bcheck ? bounds().inside(lposition, bcheck) : true;
49  }
50  // did not succeed
51  return false;
52 }
53 
54 std::shared_ptr<Acts::Surface> Acts::Surface::getSharedPtr() {
55  return shared_from_this();
56 }
57 
58 std::shared_ptr<const Acts::Surface> Acts::Surface::getSharedPtr() const {
59  return shared_from_this();
60 }
61 
63  if (&other != this) {
65  // detector element, identifier & layer association are unique
66  m_transform = other.m_transform;
67  m_associatedLayer = other.m_associatedLayer;
68  m_surfaceMaterial = other.m_surfaceMaterial;
69  m_associatedDetElement = other.m_associatedDetElement;
70  }
71  return *this;
72 }
73 
74 bool Acts::Surface::operator==(const Surface& other) const {
75  // (a) fast exit for pointer comparison
76  if (&other == this) {
77  return true;
78  }
79  // (b) fast exit for type
80  if (other.type() != type()) {
81  return false;
82  }
83  // (c) fast exit for bounds
84  if (other.bounds() != bounds()) {
85  return false;
86  }
87  // (d) compare detector elements
88  if (m_associatedDetElement != other.m_associatedDetElement) {
89  return false;
90  }
91  // (e) compare transform values
92  if (m_transform != nullptr && other.m_transform != nullptr) {
93  if (!m_transform->isApprox(*other.m_transform, 1e-9)) {
94  return false;
95  }
96  }
97  // (f) compare material
98  if (m_surfaceMaterial != other.m_surfaceMaterial) {
99  return false;
100  }
101 
102  // we should be good
103  return true;
104 }
105 
106 // overload dump for stream operator
108  std::ostream& sl) const {
109  sl << std::setiosflags(std::ios::fixed);
110  sl << std::setprecision(4);
111  sl << name() << std::endl;
112  const Vector3D& sfcenter = center(gctx);
113  sl << " Center position (x, y, z) = (" << sfcenter.x() << ", "
114  << sfcenter.y() << ", " << sfcenter.z() << ")" << std::endl;
115  Acts::RotationMatrix3D rot(transform(gctx).matrix().block<3, 3>(0, 0));
116  Acts::Vector3D rotX(rot.col(0));
117  Acts::Vector3D rotY(rot.col(1));
118  Acts::Vector3D rotZ(rot.col(2));
119  sl << std::setprecision(6);
120  sl << " Rotation: colX = (" << rotX(0) << ", " << rotX(1)
121  << ", " << rotX(2) << ")" << std::endl;
122  sl << " colY = (" << rotY(0) << ", " << rotY(1)
123  << ", " << rotY(2) << ")" << std::endl;
124  sl << " colZ = (" << rotZ(0) << ", " << rotZ(1)
125  << ", " << rotZ(2) << ")" << std::endl;
126  sl << " Bounds : " << bounds();
127  sl << std::setprecision(-1);
128  return sl;
129 }
130 
132  return !(operator==(sf));
133 }