Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoundarySurfaceT.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BoundarySurfaceT.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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 
15 #include "Acts/Geometry/Volume.hpp"
18 
19 #include <memory>
20 
21 namespace Acts {
22 
36 
37 template <class volume_t>
39 #ifndef DOXYGEN
40  friend volume_t;
41 #endif
42 
43  using VolumePtr = std::shared_ptr<const volume_t>;
45 
46  public:
48  : m_surface(nullptr),
49  m_oppositeVolume(nullptr),
50  m_alongVolume(nullptr),
51  m_oppositeVolumeArray(nullptr),
52  m_alongVolumeArray(nullptr) {}
53 
60  BoundarySurfaceT(std::shared_ptr<const Surface> surface,
61  const volume_t* inside, const volume_t* outside)
62  : m_surface(std::move(surface)),
63  m_oppositeVolume(inside),
64  m_alongVolume(outside),
65  m_oppositeVolumeArray(nullptr),
66  m_alongVolumeArray(nullptr) {}
67 
74  BoundarySurfaceT(std::shared_ptr<const Surface> surface, VolumePtr inside,
75  VolumePtr outside)
76  : m_surface(std::move(surface)),
77  m_oppositeVolume(inside.get()),
78  m_alongVolume(outside.get()),
79  m_oppositeVolumeArray(nullptr),
80  m_alongVolumeArray(nullptr) {}
81 
89  BoundarySurfaceT(std::shared_ptr<const Surface> surface,
90  std::shared_ptr<const VolumeArray> insideArray,
91  std::shared_ptr<const VolumeArray> outsideArray)
92  : m_surface(std::move(surface)),
93  m_oppositeVolume(nullptr),
94  m_alongVolume(nullptr),
95  m_oppositeVolumeArray(insideArray),
96  m_alongVolumeArray(outsideArray) {}
97 
98  virtual ~BoundarySurfaceT() = default;
99 
109  virtual const volume_t* attachedVolume(const GeometryContext& gctx,
110  const Vector3& pos, const Vector3& mom,
111  Direction dir) const;
112 
119  template <class parameters_t>
120  bool onBoundary(const GeometryContext& gctx, const parameters_t& pars) const {
121  return surfaceRepresentation().isOnSurface(gctx, pars);
122  }
123 
125  virtual const Surface& surfaceRepresentation() const;
126 
132  void attachVolume(const volume_t* volume, Direction dir);
133 
139  void attachVolumeArray(std::shared_ptr<const VolumeArray> volumes,
140  Direction dir);
141 
142  protected:
144  std::shared_ptr<const Surface> m_surface;
150  std::shared_ptr<const VolumeArray> m_oppositeVolumeArray;
152  std::shared_ptr<const VolumeArray> m_alongVolumeArray;
153 };
154 
155 template <class volume_t>
157  const {
158  return (*(m_surface.get()));
159 }
160 
161 template <class volume_t>
162 void BoundarySurfaceT<volume_t>::attachVolume(const volume_t* volume,
163  Direction dir) {
164  if (dir == Direction::Backward) {
165  m_oppositeVolume = volume;
166  } else {
167  m_alongVolume = volume;
168  }
169 }
170 
171 template <class volume_t>
173  const std::shared_ptr<const VolumeArray> volumes, Direction dir) {
174  if (dir == Direction::Backward) {
175  m_oppositeVolumeArray = volumes;
176  } else {
177  m_alongVolumeArray = volumes;
178  }
179 }
180 
181 template <class volume_t>
183  const GeometryContext& gctx, const Vector3& pos, const Vector3& mom,
184  Direction dir) const {
185  const volume_t* attVolume = nullptr;
186  // dot product with normal vector to distinguish inside/outside
187  if ((surfaceRepresentation().normal(gctx, pos)).dot(dir * mom) > 0.) {
188  attVolume = m_alongVolumeArray ? m_alongVolumeArray->object(pos).get()
189  : m_alongVolume;
190  } else {
191  attVolume = m_oppositeVolumeArray ? m_oppositeVolumeArray->object(pos).get()
192  : m_oppositeVolume;
193  }
194  return attVolume;
195 }
196 
197 } // namespace Acts