ATLAS Offline Software
TrapezoidVolumeBounds.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TrapezoidVolumeBounds.cxx, (c) ATLAS Detector software
8 
9 // Trk
11 
13 
14 // TrkSurfaces
18 // Gaudi
19 #include "GaudiKernel/MsgStream.h"
20 #include "GaudiKernel/SystemOfUnits.h"
21 // STD
22 #include <cmath>
23 #include <iomanip>
24 #include <iostream>
25 
27  : VolumeBounds()
28  , m_minHalfX(0.)
29  , m_maxHalfX(0.)
30  , m_halfY(0.)
31  , m_halfZ(0.)
32  , m_alpha(0.)
33  , m_beta(0.)
34  , m_objectAccessor()
35 {}
36 
38  double minhalex,
39  double maxhalex,
40  double haley,
41  double halez)
42  : VolumeBounds()
43  , m_minHalfX(minhalex)
44  , m_maxHalfX(maxhalex)
45  , m_halfY(haley)
46  , m_halfZ(halez)
47  , m_alpha(0.)
48  , m_beta(0.)
49  , m_objectAccessor()
50 {
51  m_alpha = atan((m_maxHalfX - m_minHalfX) / 2 / m_halfY) + 0.5 * M_PI;
52  m_beta = m_alpha;
53 }
54 
56  double minhalex,
57  double haley,
58  double halez,
59  double alpha,
60  double beta)
61  : VolumeBounds()
62  , m_minHalfX(minhalex)
63  , m_maxHalfX(0.)
64  , m_halfY(haley)
65  , m_halfZ(halez)
66  , m_alpha(alpha)
67  , m_beta(beta)
68  , m_objectAccessor()
69 {
70  double gamma = (alpha > beta) ? (alpha - 0.5 * M_PI) : (beta - 0.5 * M_PI);
71  m_maxHalfX = m_minHalfX + (2. * m_halfY) * tan(gamma);
72 }
73 
75  const Trk::TrapezoidVolumeBounds& trabo)
76  : VolumeBounds()
77  , m_minHalfX(trabo.m_minHalfX)
78  , m_maxHalfX(trabo.m_maxHalfX)
79  , m_halfY(trabo.m_halfY)
80  , m_halfZ(trabo.m_halfZ)
81  , m_alpha(trabo.m_alpha)
82  , m_beta(trabo.m_beta)
83  , m_objectAccessor(trabo.m_objectAccessor)
84 {}
85 
87 
90 {
91  if (this != &trabo) {
92  m_minHalfX = trabo.m_minHalfX;
93  m_maxHalfX = trabo.m_maxHalfX;
94  m_halfY = trabo.m_halfY;
95  m_halfZ = trabo.m_halfZ;
96  m_alpha = trabo.m_alpha;
97  m_beta = trabo.m_beta;
98  m_objectAccessor = trabo.m_objectAccessor;
99  }
100  return *this;
101 }
102 
103 const std::vector<const Trk::Surface*>*
105  (const Amg::Transform3D& transform)
106 {
107  std::vector<const Trk::Surface*>* retsf =
108  new std::vector<const Trk::Surface*>;
109 
110  // face surfaces xy
111  Amg::RotationMatrix3D trapezoidRotation(transform.rotation());
112  Amg::Vector3D trapezoidX(trapezoidRotation.col(0));
113  Amg::Vector3D trapezoidY(trapezoidRotation.col(1));
114  Amg::Vector3D trapezoidZ(trapezoidRotation.col(2));
115  Amg::Vector3D trapezoidCenter(transform.translation());
116 
117  // (1) - at negative local z
118  retsf->push_back(new Trk::PlaneSurface(
120  transform *
121  Amg::AngleAxis3D(180 * Gaudi::Units::deg, Amg::Vector3D(0., 1., 0.)) *
122  Amg::Translation3D(Amg::Vector3D(0., 0., this->halflengthZ()))),
123  this->faceXYTrapezoidBounds()));
124  // (2) - at positive local z
125  retsf->push_back(new Trk::PlaneSurface(
127  transform *
128  Amg::Translation3D(Amg::Vector3D(0., 0., this->halflengthZ()))),
129  this->faceXYTrapezoidBounds()));
130  // face surfaces yz
131  // transmute cyclical
132  // (3) - at point A, attached to alpha opening angle
133  // the yz bound are created in such a way that the surface y-direction has to
134  // become the z-direction. The resulting surface normal has to point in
135  // y-direction. This is achieved by rotating the plane surface by -90
136  // degrees around the x-axis.
137  // Then, the plane has to be rotated around the z-axis by alpha.
138  //
139  // double c=cos(M_PI/2);
140  // double s=sin(M_PI/2);
141  // Amg::RotationMatrix3D rotate_to_xz;
142  // rotate_to_xz << 1.f, 0.f, 0.f, // 1 0 0
143  // 0.f, c, -s, // 0 0 -1
144  // 0.f, s, c; // 0 1 0
145  //
146  // s=sin(-alpha());
147  // c=cos(-alpha());
148  // Amg::RotationMatrix3D rotate_left;
149  // rotate_left << c, s, 0.f,
150  // -s, c, 0.f,
151  // 0.f, 0.f, 1.f;
152  //
153  // Amg::RotationMatrix3D rotateToFaceAlpha( rotate_left * rotate_to_xz);
154  Amg::RotationMatrix3D rotateToFaceAlpha;
155  {
156  double s=sin(-alpha());
157  double c=cos(-alpha());
158  rotateToFaceAlpha << c, 0.f, s,
159  -s, 0.f, c,
160  0.f, -1.f, 0.f;
161  }
162 
163  RectangleBounds* faceAlphaBounds = this->faceAlphaRectangleBounds();
164  Amg::Vector3D faceAlphaPosition0(
165  -0.5 * (this->minHalflengthX() + this->maxHalflengthX()), 0., 0.);
166  Amg::Vector3D faceAlphaPosition = transform * faceAlphaPosition0;
167  retsf->push_back(new Trk::PlaneSurface( Amg::Translation3D(faceAlphaPosition)
168  * Amg::Transform3D(trapezoidRotation * rotateToFaceAlpha),
169  faceAlphaBounds));
170  // (4) - at point B, attached to beta opening angle
171  // same as above but rotate to the right by beta
172  Amg::RotationMatrix3D rotateToFaceBeta;
173  {
174  double s=sin(beta());
175  double c=cos(beta());
176  rotateToFaceBeta << c, 0.f, s,
177  -s, 0.f, c,
178  0.f, -1.f, 0.f;
179  }
180 
181  RectangleBounds* faceBetaBounds = this->faceBetaRectangleBounds();
182  // Amg::Vector3D
183  // faceBetaPosition(B+faceBetaRotation.colX()*faceBetaBounds->halflengthX());
184  Amg::Vector3D faceBetaPosition0(
185  0.5 * (this->minHalflengthX() + this->maxHalflengthX()), 0., 0.);
186  Amg::Vector3D faceBetaPosition = transform * faceBetaPosition0;
187  retsf->push_back(new Trk::PlaneSurface( Amg::Translation3D(faceBetaPosition)
188  * Amg::Transform3D(trapezoidRotation * rotateToFaceBeta),
189  faceBetaBounds));
190  retsf->push_back(new Trk::PlaneSurface(
192  transform *
193  Amg::AngleAxis3D(180. * Gaudi::Units::deg, Amg::Vector3D(1., 0., 0.)) *
194  Amg::Translation3D(Amg::Vector3D(0., this->halflengthY(), 0.)) *
195  Amg::AngleAxis3D(-90 * Gaudi::Units::deg, Amg::Vector3D(0., 1., 0.)) *
196  Amg::AngleAxis3D(-90. * Gaudi::Units::deg, Amg::Vector3D(1., 0., 0.))),
197  this->faceZXRectangleBoundsBottom()));
198  // (6) - at positive local x
199  retsf->push_back(new Trk::PlaneSurface(
201  transform *
202  Amg::Translation3D(Amg::Vector3D(0., this->halflengthY(), 0.)) *
203  Amg::AngleAxis3D(-90 * Gaudi::Units::deg, Amg::Vector3D(0., 1., 0.)) *
204  Amg::AngleAxis3D(-90. * Gaudi::Units::deg, Amg::Vector3D(1., 0., 0.))),
205  this->faceZXRectangleBoundsTop()));
206 
207  return retsf;
208 }
209 
210 // faces in xy
213 {
214  // return new Trk::TrapezoidBounds(m_minHalfX,m_halfY, m_alpha, m_beta);
215  return new Trk::TrapezoidBounds(m_minHalfX, m_maxHalfX, m_halfY);
216 }
217 
220 {
221  return new Trk::RectangleBounds(m_halfY / cos(m_alpha - 0.5 * M_PI), m_halfZ);
222 }
223 
226 {
227  return new Trk::RectangleBounds(m_halfY / cos(m_beta - 0.5 * M_PI), m_halfZ);
228 }
229 
232 {
233  return new Trk::RectangleBounds(m_halfZ, m_minHalfX);
234 }
235 
238 {
239  // double delta = (m_alpha < m_beta) ? m_alpha - M_PI/2. : m_beta - M_PI/2.;
240  // return new Trk::RectangleBounds(m_halfZ,
241  // 0.5*(m_minHalfX+m_minHalfX+2.*m_halfY/cos(delta)));
242  return new Trk::RectangleBounds(m_halfZ, m_maxHalfX);
243 }
244 
245 bool
247 {
248  if (std::abs(pos.z()) > m_halfZ + tol)
249  return false;
250  if (std::abs(pos.y()) > m_halfY + tol)
251  return false;
252  Trk::TrapezoidBounds* faceXYBounds = this->faceXYTrapezoidBounds();
253  Amg::Vector2D locp(pos.x(), pos.y());
254  bool inside(faceXYBounds->inside(locp, tol, tol));
255  delete faceXYBounds;
256  return inside;
257 }
258 
259 // ostream operator overload
260 MsgStream&
262 {
263  std::stringstream temp_sl;
264  temp_sl << std::setiosflags(std::ios::fixed);
265  temp_sl << std::setprecision(7);
266  temp_sl
267  << "Trk::TrapezoidVolumeBounds: (minhalfX, halfY, halfZ, alpha, beta) = ";
268  temp_sl << "(" << m_minHalfX << ", " << m_halfY << ", " << m_halfZ;
269  temp_sl << ", " << m_alpha << ", " << m_beta << ")";
270  sl << temp_sl.str();
271  return sl;
272 }
273 
274 std::ostream&
275 Trk::TrapezoidVolumeBounds::dump(std::ostream& sl) const
276 {
277  std::stringstream temp_sl;
278  temp_sl << std::setiosflags(std::ios::fixed);
279  temp_sl << std::setprecision(7);
280  temp_sl
281  << "Trk::TrapezoidVolumeBounds: (minhalfX, halfY, halfZ, alpha, beta) = ";
282  temp_sl << "(" << m_minHalfX << ", " << m_halfY << ", " << m_halfZ;
283  temp_sl << ", " << m_alpha << ", " << m_beta << ")";
284  sl << temp_sl.str();
285  return sl;
286 }
287 
TrapezoidBounds.h
Trk::RectangleBounds
Definition: RectangleBounds.h:38
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Trk::TrapezoidVolumeBounds::m_alpha
double m_alpha
opening angle alpha (in point A)
Definition: TrapezoidVolumeBounds.h:145
RectangleBounds.h
Trk::TrapezoidVolumeBounds::faceBetaRectangleBounds
RectangleBounds * faceBetaRectangleBounds() const
This method returns the associated RecantleBounds of the face PlaneSurface attached to beta (positive...
Definition: TrapezoidVolumeBounds.cxx:225
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::TrapezoidVolumeBounds::m_objectAccessor
SixObjectsAccessor m_objectAccessor
There's only one single object Acessor for the moment has to be implemented if Cuboids are used more ...
Definition: TrapezoidVolumeBounds.h:150
M_PI
#define M_PI
Definition: ActiveFraction.h:11
deg
#define deg
Definition: SbPolyhedron.cxx:17
Trk::TrapezoidVolumeBounds::faceAlphaRectangleBounds
RectangleBounds * faceAlphaRectangleBounds() const
This method returns the associated RecantleBounds of the face PlaneSurface attached to alpha (negativ...
Definition: TrapezoidVolumeBounds.cxx:219
Trk::TrapezoidBounds::inside
virtual bool inside(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const override
The orientation of the Trapezoid is according to the figure above, in words: the shorter of the two p...
Definition: TrapezoidBounds.cxx:139
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::TrapezoidVolumeBounds::faceZXRectangleBoundsBottom
RectangleBounds * faceZXRectangleBoundsBottom() const
This method returns the associated RecantleBounds of the face PlaneSurface parallel to local zx plane...
Definition: TrapezoidVolumeBounds.cxx:231
TrapezoidVolumeBounds.h
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
Trk::TrapezoidVolumeBounds::m_beta
double m_beta
opening angle beta (in point B)
Definition: TrapezoidVolumeBounds.h:146
GeometryStatics.h
Trk::VolumeBounds
Definition: VolumeBounds.h:45
Trk::TrapezoidVolumeBounds::~TrapezoidVolumeBounds
virtual ~TrapezoidVolumeBounds()
Destructor.
TrigVtx::gamma
@ gamma
Definition: TrigParticleTable.h:26
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Trk::TrapezoidVolumeBounds::TrapezoidVolumeBounds
TrapezoidVolumeBounds()
Default Constructor.
Definition: TrapezoidVolumeBounds.cxx:26
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
Trk::TrapezoidVolumeBounds::m_halfY
double m_halfY
halflength in y
Definition: TrapezoidVolumeBounds.h:142
Trk::TrapezoidVolumeBounds::m_minHalfX
double m_minHalfX
minimal halflength in x
Definition: TrapezoidVolumeBounds.h:140
Trk::TrapezoidVolumeBounds::inside
bool inside(const Amg::Vector3D &, double tol=0.) const override final
This method checks if position in the 3D volume frame is inside the cylinder.
Definition: TrapezoidVolumeBounds.cxx:246
Trk::TrapezoidVolumeBounds::faceZXRectangleBoundsTop
RectangleBounds * faceZXRectangleBoundsTop() const
This method returns the associated RecantleBounds of the face PlaneSurface parallel to local zx plane...
Definition: TrapezoidVolumeBounds.cxx:237
Trk::TrapezoidVolumeBounds::faceXYTrapezoidBounds
TrapezoidBounds * faceXYTrapezoidBounds() const
This method returns the associated TrapezoidBounds of the face PlaneSurface parallel to local xy plan...
Definition: TrapezoidVolumeBounds.cxx:212
Trk::TrapezoidVolumeBounds
Definition: TrapezoidVolumeBounds.h:57
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::TrapezoidBounds
Definition: TrapezoidBounds.h:43
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::TrapezoidVolumeBounds::alpha
double alpha() const
This method returns the opening angle in point A (negative local x)
Definition: TrapezoidVolumeBounds.h:165
Trk::TrapezoidVolumeBounds::m_maxHalfX
double m_maxHalfX
maximal halflength in x
Definition: TrapezoidVolumeBounds.h:141
Trk::inside
@ inside
Definition: PropDirection.h:29
Trk::TrapezoidVolumeBounds::operator=
TrapezoidVolumeBounds & operator=(const TrapezoidVolumeBounds &bobo)
Assignment operator.
Definition: TrapezoidVolumeBounds.cxx:89
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
PlaneSurface.h
Trk::TrapezoidVolumeBounds::beta
double beta() const
This method returns the opening angle in point B (negative local x)
Definition: TrapezoidVolumeBounds.h:166
Trk::TrapezoidVolumeBounds::decomposeToSurfaces
const std::vector< const Trk::Surface * > * decomposeToSurfaces(const Amg::Transform3D &transform) override final
Method to decompose the Bounds into Surfaces.
Definition: TrapezoidVolumeBounds.cxx:105
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
Trk::TrapezoidVolumeBounds::dump
MsgStream & dump(MsgStream &sl) const override final
Output Method for MsgStream.
Definition: TrapezoidVolumeBounds.cxx:261
Amg::AngleAxis3D
Eigen::AngleAxisd AngleAxis3D
Definition: GeoPrimitives.h:45
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
MuonParameters::beta
@ beta
Definition: MuonParamDefs.h:144
python.compressB64.c
def c
Definition: compressB64.py:93
Trk::TrapezoidVolumeBounds::m_halfZ
double m_halfZ
halflength in z
Definition: TrapezoidVolumeBounds.h:143