ATLAS Offline Software
SubtractedVolumeBounds.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SubtractedVolumeBounds.cxx, (c) ATLAS Detector software
8 
9 // Trk
14 // TrkSurfaces
18 #include "TrkSurfaces/DiscBounds.h"
23 #include "TrkSurfaces/Surface.h"
25 #include "TrkVolumes/Volume.h"
26 // Gaudi
27 #include "GaudiKernel/MsgStream.h"
28 // STD
29 #include <cmath>
30 #include <iostream>
31 #include <utility>
32 
34  : VolumeBounds()
35  , m_outer(nullptr)
36  , m_inner(nullptr)
37  , m_objectAccessor()
38  , m_boundsOrientation()
39 {}
40 
42  : VolumeBounds()
43  , m_outer(vol1)
44  , m_inner(vol2)
45  , m_objectAccessor()
46  , m_boundsOrientation()
47 {}
48 
50  const Trk::SubtractedVolumeBounds& bobo)
51  : VolumeBounds()
52  , m_outer(bobo.m_outer)
53  , m_inner(bobo.m_inner)
54  , m_objectAccessor(bobo.m_objectAccessor)
55  , m_boundsOrientation()
56 {
57  m_boundsOrientation.resize(bobo.m_boundsOrientation.size());
58  for (unsigned int i = 0; i < bobo.m_boundsOrientation.size(); i++)
60 }
61 
63 {
64  m_boundsOrientation.clear();
65  delete m_outer;
66  delete m_inner;
67 }
68 
71 {
72  if (this != &bobo) {
73  m_outer = bobo.m_outer;
74  m_inner = bobo.m_inner;
75  m_objectAccessor = bobo.m_objectAccessor;
76  m_boundsOrientation = bobo.m_boundsOrientation;
77  m_boundsOrientation.resize(bobo.m_boundsOrientation.size());
78  for (unsigned int i = 0; i < bobo.m_boundsOrientation.size(); i++)
79  m_boundsOrientation[i] = bobo.m_boundsOrientation[i];
80  }
81  return *this;
82 }
83 
84 const std::vector<const Trk::Surface*>*
86  (const Amg::Transform3D& transf)
87 {
88  // double tol=0.001;
89  // get surfaces for outer boundaries
90  const std::vector<const Trk::Surface*>* outerSurfaces =
91  m_outer->volumeBounds().decomposeToSurfaces(transf * m_outer->transform());
92  // get surfaces for inner boundaries
93  const std::vector<const Trk::Surface*>* innerSurfaces =
94  m_inner->volumeBounds().decomposeToSurfaces(transf * m_inner->transform());
95  std::vector<unsigned int> subtrInner;
96  std::vector<const Trk::Surface*>* retsf =
97  new std::vector<const Trk::Surface*>;
98 
99  unsigned int nSurf = outerSurfaces->size() + innerSurfaces->size();
100  m_boundsOrientation.resize(nSurf);
101 
102  const Trk::CylinderVolumeBounds* cylVol =
103  dynamic_cast<const Trk::CylinderVolumeBounds*>(&(m_outer->volumeBounds()));
104  const Trk::SimplePolygonBrepVolumeBounds* spbVol =
105  dynamic_cast<const Trk::SimplePolygonBrepVolumeBounds*>(
106  &(m_outer->volumeBounds()));
107  const Trk::CombinedVolumeBounds* comVol =
108  dynamic_cast<const Trk::CombinedVolumeBounds*>(&(m_outer->volumeBounds()));
109  const Trk::SubtractedVolumeBounds* subVol =
110  dynamic_cast<const Trk::SubtractedVolumeBounds*>(
111  &(m_outer->volumeBounds()));
112 
113  // loop over 'outer' boundary surfaces; modified by subtracted volume
114  for (unsigned int out = 0; out < outerSurfaces->size(); out++) {
115  const SubtractedPlaneSurface* splo =
116  dynamic_cast<const SubtractedPlaneSurface*>((*outerSurfaces)[out]);
117  const PlaneSurface* plo =
118  dynamic_cast<const PlaneSurface*>((*outerSurfaces)[out]);
119  const SubtractedCylinderSurface* sclo =
120  dynamic_cast<const SubtractedCylinderSurface*>((*outerSurfaces)[out]);
121  const CylinderSurface* clo =
122  dynamic_cast<const CylinderSurface*>((*outerSurfaces)[out]);
123  const DiscSurface* dlo =
124  dynamic_cast<const DiscSurface*>((*outerSurfaces)[out]);
125  if (!(splo || plo || sclo || clo || dlo)) {
126  throw std::runtime_error("Unhandled surface.");
127  }
128  // resolve bounds orientation : copy from combined/subtracted, swap inner
129  // cyl, swap bottom spb
130  if (comVol)
131  m_boundsOrientation[out] = comVol->boundsOrientation()[out];
132  else if (subVol)
133  m_boundsOrientation[out] = subVol->boundsOrientation()[out];
134  else if (cylVol && clo && out == 3)
135  m_boundsOrientation[out] = false;
136  else if (spbVol && out == 0)
137  m_boundsOrientation[out] = false;
138  else
139  m_boundsOrientation[out] = true;
140  //
141  Trk::Volume* innerSub = createSubtractedVolume(
142  (*outerSurfaces)[out]->transform().inverse() * transf, m_inner);
143 
144  if (splo || sclo) { // multiple subtraction
146  bool shared = false;
147  if (splo) {
148  vEx = splo->subtractedVolume();
149  shared = splo->shared();
150  }
151  if (sclo) {
152  vEx = sclo->subtractedVolume();
153  shared = sclo->shared();
154  }
155  const Trk::VolumeExcluder* volExcl =
156  dynamic_cast<const Trk::VolumeExcluder*>(vEx.get());
157  if (!volExcl)
158  throw std::logic_error("Not a VolumeExcluder");
159  Trk::Volume* outerSub = new Trk::Volume(*volExcl->volume());
160 
161  Trk::Volume* comb_sub = nullptr;
162  if (!shared)
163  comb_sub = new Trk::Volume(
164  nullptr, new Trk::CombinedVolumeBounds(innerSub, outerSub, false));
165  else
166  comb_sub = new Trk::Volume(
167  nullptr, new Trk::SubtractedVolumeBounds(outerSub, innerSub));
168  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(comb_sub);
169  if (splo)
170  retsf->push_back(new Trk::SubtractedPlaneSurface(*splo, volEx, shared));
171  if (sclo)
172  retsf->push_back(
173  new Trk::SubtractedCylinderSurface(*sclo, volEx, shared));
174  } else {
175  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(innerSub);
176  if (plo)
177  retsf->push_back(new Trk::SubtractedPlaneSurface(*plo, volEx, false));
178  if (clo)
179  retsf->push_back(
180  new Trk::SubtractedCylinderSurface(*clo, volEx, false));
181  if (dlo) {
182  // turn disc into ellipse for simplification
183  const DiscBounds* db =
184  dynamic_cast<const DiscBounds*>(&(dlo->bounds()));
185  if (!db)
186  throw std::logic_error("Not DiscBounds");
187  EllipseBounds* eb = new EllipseBounds(
188  db->rMin(), db->rMin(), db->rMax(), db->rMax(), db->halfPhiSector());
189  plo = new PlaneSurface(Amg::Transform3D(dlo->transform()), eb);
190  retsf->push_back(new Trk::SubtractedPlaneSurface(*plo, volEx, false));
191  delete plo;
192  }
193  }
194  }
195 
196  // loop over 'inner' boundary surfaces; include only if represent a new
197  // surface change: include allways otherwise orientation messed up bonus :
198  // solves 'double boundary' problem
199 
200  cylVol =
201  dynamic_cast<const Trk::CylinderVolumeBounds*>(&(m_inner->volumeBounds()));
202  spbVol = dynamic_cast<const Trk::SimplePolygonBrepVolumeBounds*>(
203  &(m_inner->volumeBounds()));
204  comVol =
205  dynamic_cast<const Trk::CombinedVolumeBounds*>(&(m_inner->volumeBounds()));
206  subVol = dynamic_cast<const Trk::SubtractedVolumeBounds*>(
207  &(m_inner->volumeBounds()));
208  unsigned int nOut = outerSurfaces->size();
209 
210  for (unsigned int in = 0; in < innerSurfaces->size(); in++) {
211  const SubtractedPlaneSurface* spli =
212  dynamic_cast<const SubtractedPlaneSurface*>((*innerSurfaces)[in]);
213  const PlaneSurface* pli =
214  dynamic_cast<const PlaneSurface*>((*innerSurfaces)[in]);
215  const SubtractedCylinderSurface* scli =
216  dynamic_cast<const SubtractedCylinderSurface*>((*innerSurfaces)[in]);
217  const CylinderSurface* cli =
218  dynamic_cast<const CylinderSurface*>((*innerSurfaces)[in]);
219  const DiscSurface* dli =
220  dynamic_cast<const DiscSurface*>((*innerSurfaces)[in]);
221  // resolve bounds orientation : copy from combined/subtracted, swap inner
222  // cyl, swap bottom spb, swap all
223  if (comVol)
224  m_boundsOrientation[nOut + in] = !comVol->boundsOrientation()[in];
225  else if (subVol)
226  m_boundsOrientation[nOut + in] = !subVol->boundsOrientation()[in];
227  else if (cylVol && cli && in == 3)
228  m_boundsOrientation[nOut + in] = true;
229  else if (spbVol && in == 0)
230  m_boundsOrientation[nOut + in] = true;
231  else
232  m_boundsOrientation[nOut + in] = false;
233  //
234  Trk::Volume* outerSub = createSubtractedVolume(
235  (*innerSurfaces)[in]->transform().inverse() * transf, m_outer);
236 
237  if (spli || scli) {
238  bool shared = false;
240  if (spli) {
241  vEx = spli->subtractedVolume();
242  shared = spli->shared();
243  }
244  if (scli) {
245  vEx = scli->subtractedVolume();
246  shared = scli->shared();
247  }
248  const Trk::VolumeExcluder* volExcl =
249  dynamic_cast<const Trk::VolumeExcluder*>(vEx.get());
250  if (!volExcl)
251  throw std::logic_error("Not a VolumeExcluder");
252  Trk::Volume* innerSub = new Trk::Volume(*volExcl->volume());
253 
254  // combined volume
255  Trk::Volume* comb_sub = nullptr;
256  if (!shared)
257  comb_sub = new Trk::Volume(
258  nullptr, new Trk::SubtractedVolumeBounds(outerSub, innerSub));
259  else
260  comb_sub = new Trk::Volume(
261  nullptr, new Trk::CombinedVolumeBounds(innerSub, outerSub, true));
262  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(comb_sub);
263  if (spli)
264  retsf->push_back(new Trk::SubtractedPlaneSurface(*spli, volEx, true));
265  if (scli)
266  retsf->push_back(
267  new Trk::SubtractedCylinderSurface(*scli, volEx, true));
268 
269  } else if (pli || cli) {
270  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(outerSub);
271  if (pli)
272  retsf->push_back(new Trk::SubtractedPlaneSurface(*pli, volEx, true));
273  if (cli)
274  retsf->push_back(new Trk::SubtractedCylinderSurface(*cli, volEx, true));
275  } else if (dli) {
276  // turn disc into ellipse for simplification
277  const DiscBounds* db = dynamic_cast<const DiscBounds*>(&(dli->bounds()));
278  if (!db)
279  throw std::logic_error("Not DiscBounds");
280  EllipseBounds* eb = new EllipseBounds(
281  db->rMin(), db->rMin(), db->rMax(), db->rMax(), db->halfPhiSector());
282  PlaneSurface pla(Amg::Transform3D(dli->transform()), eb);
283  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(outerSub);
284  retsf->push_back(new Trk::SubtractedPlaneSurface(pla, volEx, true));
285  } else {
286  throw std::runtime_error(
287  "Unhandled surface in "
288  "Trk::SubtractedVolumeBounds::decomposeToSurfaces.");
289  }
290  }
291 
292  for (const auto *outerSurface : *outerSurfaces)
293  delete outerSurface;
294  for (const auto *innerSurface : *innerSurfaces)
295  delete innerSurface;
296  delete outerSurfaces;
297  delete innerSurfaces;
298 
299  return retsf;
300 }
301 
302 // ostream operator overload
303 
304 MsgStream&
306 {
307  std::stringstream temp_sl;
308  temp_sl << std::setiosflags(std::ios::fixed);
309  temp_sl << std::setprecision(7);
310  temp_sl << "Trk::SubtractedVolumeBounds: outer,inner ";
311  sl << temp_sl.str();
312  std::as_const(*m_outer).volumeBounds().dump(sl);
313  std::as_const(*m_inner).volumeBounds().dump(sl);
314  return sl;
315 }
316 
317 std::ostream&
318 Trk::SubtractedVolumeBounds::dump(std::ostream& sl) const
319 {
320  std::stringstream temp_sl;
321  temp_sl << std::setiosflags(std::ios::fixed);
322  temp_sl << std::setprecision(7);
323  temp_sl << "Trk::SubtractedVolumeBounds: outer,inner ";
324  sl << temp_sl.str();
325  std::as_const(*m_outer).volumeBounds().dump(sl);
326  std::as_const(*m_inner).volumeBounds().dump(sl);
327  return sl;
328 }
329 
332  const Amg::Transform3D& transf,
333  Trk::Volume* subtrVol)
334 {
335  Trk::Volume* subVol = nullptr;
336  if (!subtrVol)
337  return subVol;
338 
339  subVol = new Trk::Volume(*subtrVol, transf);
340 
341  return subVol;
342 }
343 
Trk::SubtractedVolumeBounds::m_inner
Volume * m_inner
Definition: SubtractedVolumeBounds.h:95
EllipseBounds.h
Trk::SubtractedCylinderSurface::shared
bool shared() const
This method indicates the subtraction mode.
Trk::SubtractedVolumeBounds::boundsOrientation
const std::vector< bool > & boundsOrientation() const
This method returns bounds orientation.
Definition: SubtractedVolumeBounds.h:124
DiscBounds.h
RectangleBounds.h
Trk::SimplePolygonBrepVolumeBounds
Definition: SimplePolygonBrepVolumeBounds.h:44
Surface.h
Trk::SubtractedCylinderSurface
Definition: SubtractedCylinderSurface.h:33
Trk::EllipseBounds
Definition: EllipseBounds.h:38
CaloCondBlobAlgs_fillNoiseFromASCII.db
db
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:43
Trk::SubtractedVolumeBounds::dump
MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition: SubtractedVolumeBounds.cxx:305
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
Trk::SubtractedVolumeBounds::decomposeToSurfaces
const std::vector< const Trk::Surface * > * decomposeToSurfaces(const Amg::Transform3D &transform) override final
Method to decompose the Bounds into boundarySurfaces.
Definition: SubtractedVolumeBounds.cxx:86
Trk::SubtractedVolumeBounds::m_outer
Volume * m_outer
Definition: SubtractedVolumeBounds.h:94
Trk::DiscSurface
Definition: DiscSurface.h:54
Trk::CombinedVolumeBounds::boundsOrientation
const std::vector< bool > & boundsOrientation() const
This method returns bounds orientation.
Definition: CombinedVolumeBounds.h:128
VolumeExcluder.h
Trk::VolumeBounds
Definition: VolumeBounds.h:45
CylinderVolumeBounds.h
Volume.h
Trk::SubtractedVolumeBounds::createSubtractedVolume
static Trk::Volume * createSubtractedVolume(const Amg::Transform3D &transf, Trk::Volume *subtrVol)
Definition: SubtractedVolumeBounds.cxx:331
SubtractedPlaneSurface.h
Trk::SubtractedPlaneSurface
Definition: SubtractedPlaneSurface.h:32
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonR4::inverse
CalibratedSpacePoint::Covariance_t inverse(const CalibratedSpacePoint::Covariance_t &mat)
Inverts the parsed matrix.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx:65
Trk::CylinderSurface
Definition: CylinderSurface.h:55
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::DiscSurface::bounds
const SurfaceBounds & bounds() const override final
This method returns the bounds by reference.
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
CylinderSurface.h
Trk::SubtractedVolumeBounds::operator=
SubtractedVolumeBounds & operator=(const SubtractedVolumeBounds &bobo)
Assignment operator.
Definition: SubtractedVolumeBounds.cxx:70
SubtractedCylinderSurface.h
Trk::CylinderVolumeBounds
Definition: CylinderVolumeBounds.h:70
Trk::SubtractedPlaneSurface::shared
bool shared() const
This method indicates the subtraction mode.
SimplePolygonBrepVolumeBounds.h
Trk::VolumeExcluder::volume
const Volume * volume() const
Acces the subtracted volume.
Definition: VolumeExcluder.h:70
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::PlaneSurface
Definition: PlaneSurface.h:64
PlaneSurface.h
Trk::SubtractedVolumeBounds
Definition: SubtractedVolumeBounds.h:40
Trk::SubtractedPlaneSurface::subtractedVolume
SharedObject< AreaExcluder > subtractedVolume() const
This method allows access to the subtracted part.
Trk::SubtractedVolumeBounds::m_objectAccessor
EightObjectsAccessor m_objectAccessor
There's only one single object Acessor for the moment has to be implemented if Subtracteds are used m...
Definition: SubtractedVolumeBounds.h:99
CombinedVolumeBounds.h
DiscSurface.h
Trk::SubtractedVolumeBounds::SubtractedVolumeBounds
SubtractedVolumeBounds()
Default Constructor.
Definition: SubtractedVolumeBounds.cxx:33
Trk::SubtractedVolumeBounds::~SubtractedVolumeBounds
virtual ~SubtractedVolumeBounds()
Destructor.
Definition: SubtractedVolumeBounds.cxx:62
Trk::SubtractedVolumeBounds::m_boundsOrientation
std::vector< bool > m_boundsOrientation
Definition: SubtractedVolumeBounds.h:101
Trk::VolumeExcluder
Definition: VolumeExcluder.h:29
Trk::CombinedVolumeBounds
Definition: CombinedVolumeBounds.h:42
Trk::Volume
Definition: Volume.h:35
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::SubtractedCylinderSurface::subtractedVolume
SharedObject< AreaExcluder > subtractedVolume() const
This method allows access to the subtracted part.
Trk::DiscBounds
Definition: DiscBounds.h:44
SubtractedVolumeBounds.h