ATLAS Offline Software
CombinedVolumeBounds.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 // CombinedVolumeBounds.cxx, (c) ATLAS Detector software
8 
9 // Trk
11 
16 // TrkSurfaces
20 #include "TrkSurfaces/DiscBounds.h"
25 #include "TrkSurfaces/Surface.h"
26 // Gaudi
27 #include "GaudiKernel/MsgStream.h"
28 // STD
29 #include <cmath>
30 #include <iostream>
31 #include <stdexcept>
32 #include <utility>
33 
35  : VolumeBounds()
36  , m_first(nullptr)
37  , m_second(nullptr)
38  , m_intersection(false)
39  , m_objectAccessor()
40  , m_boundsOrientation()
41 {}
42 
44  Volume* vol1,
45  Volume* vol2,
46  bool intersection)
47  : VolumeBounds()
48  , m_first(vol1)
49  , m_second(vol2)
50  , m_intersection(intersection)
51  , m_objectAccessor()
52  , m_boundsOrientation()
53 {}
54 
56  const Trk::CombinedVolumeBounds& bobo)
57  : VolumeBounds()
58  , m_first(bobo.m_first)
59  , m_second(bobo.m_second)
60  , m_intersection(bobo.m_intersection)
61  , m_objectAccessor(bobo.m_objectAccessor)
62  , m_boundsOrientation()
63 {
64  m_boundsOrientation.resize(bobo.m_boundsOrientation.size());
65  for (unsigned int i = 0; i < bobo.m_boundsOrientation.size(); i++)
67 }
68 
70 {
71  m_boundsOrientation.clear();
72  delete m_first;
73  delete m_second;
74 }
75 
78 {
79  if (this != &bobo) {
80  m_first = bobo.m_first;
81  m_second = bobo.m_second;
82  m_intersection = bobo.m_intersection;
83  m_objectAccessor = bobo.m_objectAccessor;
84  m_boundsOrientation = bobo.m_boundsOrientation;
85  m_boundsOrientation.resize(bobo.m_boundsOrientation.size());
86  for (unsigned int i = 0; i < bobo.m_boundsOrientation.size(); i++)
87  m_boundsOrientation[i] = bobo.m_boundsOrientation[i];
88  }
89  return *this;
90 }
91 
92 const std::vector<const Trk::Surface*>*
94  (const Amg::Transform3D& transf)
95 {
96  std::vector<const Trk::Surface*>* retsf =
97  new std::vector<const Trk::Surface*>;
98 
99  const Trk::CylinderVolumeBounds* cylVol =
100  dynamic_cast<const Trk::CylinderVolumeBounds*>(&(m_first->volumeBounds()));
101  const Trk::SimplePolygonBrepVolumeBounds* spbVol =
102  dynamic_cast<const Trk::SimplePolygonBrepVolumeBounds*>(
103  &(m_first->volumeBounds()));
104  const Trk::CombinedVolumeBounds* comVol =
105  dynamic_cast<const Trk::CombinedVolumeBounds*>(&(m_first->volumeBounds()));
106  const Trk::SubtractedVolumeBounds* subVol =
107  dynamic_cast<const Trk::SubtractedVolumeBounds*>(
108  &(m_first->volumeBounds()));
109 
110  // get surfaces for first boundaries
111  const std::vector<const Trk::Surface*>* firstSurfaces =
112  m_first->volumeBounds().decomposeToSurfaces(transf * m_first->transform());
113  // get surfaces for second boundaries
114  const std::vector<const Trk::Surface*>* secondSurfaces =
115  m_second->volumeBounds().decomposeToSurfaces(
116  transf * m_second->transform());
117  unsigned int nSurf = firstSurfaces->size() + secondSurfaces->size();
118  m_boundsOrientation.resize(nSurf);
119 
120  std::vector<unsigned int> subtrSecond;
121 
122  // loop over surfaces; convert disc surface to a plane surface using elliptic
123  // bounds
124  for (unsigned int out = 0; out < firstSurfaces->size(); out++) {
125  //
126  const SubtractedPlaneSurface* splo =
127  dynamic_cast<const SubtractedPlaneSurface*>((*firstSurfaces)[out]);
128  const PlaneSurface* plo =
129  dynamic_cast<const PlaneSurface*>((*firstSurfaces)[out]);
130  const SubtractedCylinderSurface* sclo =
131  dynamic_cast<const SubtractedCylinderSurface*>((*firstSurfaces)[out]);
132  const CylinderSurface* clo =
133  dynamic_cast<const CylinderSurface*>((*firstSurfaces)[out]);
134  const DiscSurface* dlo =
135  dynamic_cast<const DiscSurface*>((*firstSurfaces)[out]);
136 
137  // resolve bounds orientation : copy from combined/subtracted, swap inner
138  // cyl, swap bottom spb
139  if (comVol)
140  m_boundsOrientation[out] = comVol->boundsOrientation()[out];
141  else if (subVol)
142  m_boundsOrientation[out] = subVol->boundsOrientation()[out];
143  else if (cylVol && clo && out == 3)
144  m_boundsOrientation[out] = false;
145  else if (spbVol && out == 0)
146  m_boundsOrientation[out] = false;
147  else
148  m_boundsOrientation[out] = true;
149 
150  Trk::Volume* secondSub = createSubtractedVolume(
151  (*firstSurfaces)[out]->transform().inverse() * transf, m_second);
152 
153  if (sclo || splo) {
154  bool shared = false;
156  if (splo) {
157  vEx = splo->subtractedVolume();
158  shared = splo->shared();
159  }
160  if (sclo) {
161  vEx = sclo->subtractedVolume();
162  shared = sclo->shared();
163  }
164  const Trk::VolumeExcluder* volExcl =
165  dynamic_cast<const Trk::VolumeExcluder*>(vEx.get());
166  if (!volExcl)
167  throw std::logic_error("Not a VolumeExcluder");
168 
169  Trk::Volume* firstSub = new Trk::Volume(*volExcl->volume());
170 
171  Trk::Volume* comb_sub = nullptr;
172  if (!shared && !m_intersection)
173  comb_sub = new Trk::Volume(
174  nullptr,
175  new Trk::CombinedVolumeBounds(secondSub, firstSub, m_intersection));
176  if (!shared && m_intersection)
177  comb_sub = new Trk::Volume(
178  nullptr, new Trk::SubtractedVolumeBounds(secondSub, firstSub));
179  if (shared && m_intersection)
180  comb_sub = new Trk::Volume(
181  nullptr,
182  new Trk::CombinedVolumeBounds(secondSub, firstSub, m_intersection));
183  if (shared && !m_intersection)
184  comb_sub = new Trk::Volume(
185  nullptr, new Trk::SubtractedVolumeBounds(firstSub, secondSub));
186  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(comb_sub);
187  bool new_shared = shared;
188  if (m_intersection)
189  new_shared = true;
190  if (splo)
191  retsf->push_back(
192  new Trk::SubtractedPlaneSurface(*splo, volEx, new_shared));
193  if (sclo)
194  retsf->push_back(
195  new Trk::SubtractedCylinderSurface(*sclo, volEx, new_shared));
196 
197  } else if (plo || clo || dlo) {
198  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(secondSub);
199  if (plo)
200  retsf->push_back(
201  new Trk::SubtractedPlaneSurface(*plo, volEx, m_intersection));
202  if (clo)
203  retsf->push_back(
204  new Trk::SubtractedCylinderSurface(*clo, volEx, m_intersection));
205  if (dlo) {
206  const DiscBounds* db =
207  dynamic_cast<const DiscBounds*>(&(dlo->bounds()));
208  if (!db)
209  throw std::logic_error("Not DiscBounds");
210 
211  EllipseBounds* eb = new EllipseBounds(
212  db->rMin(), db->rMin(), db->rMax(), db->rMax(), db->halfPhiSector());
213  plo = new PlaneSurface(Amg::Transform3D(dlo->transform()), eb);
214  retsf->push_back(
215  new Trk::SubtractedPlaneSurface(*plo, volEx, m_intersection));
216  delete plo;
217  }
218  } else {
219  throw std::runtime_error(
220  "Unhandled surface in CombinedVolumeBounds::decomposeToSurfaces.");
221  }
222  }
223 
224  cylVol =
225  dynamic_cast<const Trk::CylinderVolumeBounds*>(&(m_second->volumeBounds()));
226  spbVol = dynamic_cast<const Trk::SimplePolygonBrepVolumeBounds*>(
227  &(m_second->volumeBounds()));
228  comVol =
229  dynamic_cast<const Trk::CombinedVolumeBounds*>(&(m_second->volumeBounds()));
230  subVol = dynamic_cast<const Trk::SubtractedVolumeBounds*>(
231  &(m_second->volumeBounds()));
232  unsigned int nOut = firstSurfaces->size();
233 
234  for (unsigned int in = 0; in < secondSurfaces->size(); in++) {
235  //
236  const SubtractedPlaneSurface* spli =
237  dynamic_cast<const SubtractedPlaneSurface*>((*secondSurfaces)[in]);
238  const PlaneSurface* pli =
239  dynamic_cast<const PlaneSurface*>((*secondSurfaces)[in]);
240  const SubtractedCylinderSurface* scli =
241  dynamic_cast<const SubtractedCylinderSurface*>((*secondSurfaces)[in]);
242  const CylinderSurface* cli =
243  dynamic_cast<const CylinderSurface*>((*secondSurfaces)[in]);
244  const DiscSurface* dli =
245  dynamic_cast<const DiscSurface*>((*secondSurfaces)[in]);
246 
247  // resolve bounds orientation : copy from combined/subtracted, swap inner
248  // cyl, swap bottom spb
249  if (comVol)
250  m_boundsOrientation[nOut + in] = comVol->boundsOrientation()[in];
251  else if (subVol)
252  m_boundsOrientation[nOut + in] = subVol->boundsOrientation()[in];
253  else if (cylVol && cli && in == 3)
254  m_boundsOrientation[nOut + in] = false;
255  else if (spbVol && in == 0)
256  m_boundsOrientation[nOut + in] = false;
257  else
258  m_boundsOrientation[nOut + in] = true;
259 
260  Trk::Volume* firstSub = createSubtractedVolume(
261  (*secondSurfaces)[in]->transform().inverse() * transf, m_first);
262  if (scli || spli) {
263  bool shared = false;
265  if (spli) {
266  vEx = spli->subtractedVolume();
267  shared = spli->shared();
268  }
269  if (scli) {
270  vEx = scli->subtractedVolume();
271  shared = scli->shared();
272  }
273  const Trk::VolumeExcluder* volExcl =
274  dynamic_cast<const Trk::VolumeExcluder*>(vEx.get());
275  if (!volExcl)
276  throw std::logic_error("Not a VolumeExcluder");
277  Trk::Volume* secondSub = new Trk::Volume(*volExcl->volume());
278 
279  Trk::Volume* comb_sub = nullptr;
280  if (!shared && !m_intersection)
281  comb_sub = new Trk::Volume(
282  nullptr,
283  new Trk::CombinedVolumeBounds(firstSub, secondSub, m_intersection));
284  if (!shared && m_intersection)
285  comb_sub = new Trk::Volume(
286  nullptr, new Trk::SubtractedVolumeBounds(firstSub, secondSub));
287  if (shared && m_intersection)
288  comb_sub = new Trk::Volume(
289  nullptr,
290  new Trk::CombinedVolumeBounds(firstSub, secondSub, m_intersection));
291  if (shared && !m_intersection)
292  comb_sub = new Trk::Volume(
293  nullptr, new Trk::SubtractedVolumeBounds(secondSub, firstSub));
294  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(comb_sub);
295  bool new_shared = shared;
296  if (m_intersection)
297  new_shared = true;
298  if (spli)
299  retsf->push_back(
300  new Trk::SubtractedPlaneSurface(*spli, volEx, new_shared));
301  if (scli)
302  retsf->push_back(
303  new Trk::SubtractedCylinderSurface(*scli, volEx, new_shared));
304 
305  } else if (pli || cli || dli) {
306  Trk::VolumeExcluder* volEx = new Trk::VolumeExcluder(firstSub);
307  if (pli)
308  retsf->push_back(
309  new Trk::SubtractedPlaneSurface(*pli, volEx, m_intersection));
310  if (cli)
311  retsf->push_back(
312  new Trk::SubtractedCylinderSurface(*cli, volEx, m_intersection));
313  if (dli) {
314  const DiscBounds* db =
315  dynamic_cast<const DiscBounds*>(&(dli->bounds()));
316  if (!db)
317  throw std::logic_error("Not DiscBounds");
318 
319  EllipseBounds* eb = new EllipseBounds(
320  db->rMin(), db->rMin(), db->rMax(), db->rMax(), db->halfPhiSector());
321  pli = new PlaneSurface(Amg::Transform3D(dli->transform()), eb);
322  retsf->push_back(
323  new Trk::SubtractedPlaneSurface(*pli, volEx, m_intersection));
324  delete pli;
325  }
326  } else {
327  throw std::runtime_error(
328  "Unhandled surface in CombinedVolumeBounds::decomposeToSurfaces.");
329  }
330  }
331 
332  for (const auto *firstSurface : *firstSurfaces) {
333  delete firstSurface;
334  }
335  for (const auto *secondSurface : *secondSurfaces) {
336  delete secondSurface;
337  }
338  delete firstSurfaces;
339  delete secondSurfaces;
340 
341  return retsf;
342 }
343 
344 // ostream operator overload
345 
346 MsgStream&
348 {
349  std::stringstream temp_sl;
350  temp_sl << std::setiosflags(std::ios::fixed);
351  temp_sl << std::setprecision(7);
352  temp_sl << "Trk::CombinedVolumeBounds: first,second ";
353  sl << temp_sl.str();
354  std::as_const(*m_first).volumeBounds().dump(sl);
355  std::as_const(*m_second).volumeBounds().dump(sl);
356  return sl;
357 }
358 
359 std::ostream&
360 Trk::CombinedVolumeBounds::dump(std::ostream& sl) const
361 {
362  std::stringstream temp_sl;
363  temp_sl << std::setiosflags(std::ios::fixed);
364  temp_sl << std::setprecision(7);
365  temp_sl << "Trk::CombinedVolumeBounds: first,second ";
366  sl << temp_sl.str();
367  std::as_const(*m_first).volumeBounds().dump(sl);
368  std::as_const(*m_second).volumeBounds().dump(sl);
369  return sl;
370 }
371 
374  const Amg::Transform3D& transf,
375  Trk::Volume* subtrVol)
376 {
377  Trk::Volume* subVol = nullptr;
378  if (!subtrVol)
379  return subVol;
380 
381  subVol = new Trk::Volume(*subtrVol, transf);
382 
383  return subVol;
384 }
385 
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
Trk::CombinedVolumeBounds::m_second
Volume * m_second
Definition: CombinedVolumeBounds.h:98
Trk::CombinedVolumeBounds::m_boundsOrientation
std::vector< bool > m_boundsOrientation
Definition: CombinedVolumeBounds.h:101
Trk::CombinedVolumeBounds::operator=
CombinedVolumeBounds & operator=(const CombinedVolumeBounds &bobo)
Assignment operator.
Definition: CombinedVolumeBounds.cxx:77
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
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
Trk::CombinedVolumeBounds::m_intersection
bool m_intersection
Definition: CombinedVolumeBounds.h:99
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::DiscSurface
Definition: DiscSurface.h:54
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
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
SubtractedPlaneSurface.h
Trk::SubtractedPlaneSurface
Definition: SubtractedPlaneSurface.h:32
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::CombinedVolumeBounds::~CombinedVolumeBounds
virtual ~CombinedVolumeBounds()
Destructor.
Definition: CombinedVolumeBounds.cxx:69
Trk::CombinedVolumeBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override final
Output Method for MsgStream.
Definition: CombinedVolumeBounds.cxx:347
Trk::CombinedVolumeBounds::createSubtractedVolume
static Trk::Volume * createSubtractedVolume(const Amg::Transform3D &transf, Trk::Volume *subtrVol)
Definition: CombinedVolumeBounds.cxx:373
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
SubtractedCylinderSurface.h
Trk::CombinedVolumeBounds::m_objectAccessor
EightObjectsAccessor m_objectAccessor
Definition: CombinedVolumeBounds.h:100
Trk::CombinedVolumeBounds::CombinedVolumeBounds
CombinedVolumeBounds()
Default Constructor.
Definition: CombinedVolumeBounds.cxx:34
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::CombinedVolumeBounds::m_first
Volume * m_first
Definition: CombinedVolumeBounds.h:97
Trk::SubtractedPlaneSurface::subtractedVolume
SharedObject< AreaExcluder > subtractedVolume() const
This method allows access to the subtracted part.
CombinedVolumeBounds.h
DiscSurface.h
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::CombinedVolumeBounds::decomposeToSurfaces
virtual const std::vector< const Trk::Surface * > * decomposeToSurfaces(const Amg::Transform3D &transform) override final
Method to decompose the Bounds into boundarySurfaces.
Definition: CombinedVolumeBounds.cxx:94
Trk::DiscBounds
Definition: DiscBounds.h:44
SubtractedVolumeBounds.h