CMS 3D CMS Logo

TruncatedPyramid.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <iostream>
4 
5 
10 
11 typedef HepGeom::Vector3D<CCGFloat> FVec3D ;
12 typedef HepGeom::Plane3D<CCGFloat> Plane3D ;
13 
14 typedef HepGeom::Vector3D<double> DVec3D ;
15 typedef HepGeom::Plane3D<double> DPlane3D ;
16 typedef HepGeom::Point3D<double> DPt3D ;
17 
18 //----------------------------------------------------------------------
19 
22  m_axis ( 0., 0., 0. ),
23  m_corOne ( 0., 0., 0. )
24 {}
25 
27  : CaloCellGeometry( tr )
28 {
29  *this = tr ;
30 }
31 
34 {
35  CaloCellGeometry::operator=( tr ) ;
36  if( this != &tr )
37  {
38  m_axis = tr.m_axis ;
39  m_corOne = tr.m_corOne ;
40  }
41  return *this ;
42 }
43 
45  const GlobalPoint& fCtr ,
46  const GlobalPoint& bCtr ,
47  const GlobalPoint& cor1 ,
48  const CCGFloat* parV ) :
49  CaloCellGeometry ( fCtr, cMgr, parV ) ,
50  m_axis ( ( bCtr - fCtr ).unit() ) ,
51  m_corOne ( cor1.x(), cor1.y(), cor1.z() )
52 {initSpan();}
53 
55  const CCGFloat* par ) :
56  CaloCellGeometry ( corn, par ) ,
57  m_axis ( makeAxis() ) ,
58  m_corOne ( corn[0].x(), corn[0].y(), corn[0].z() )
59 {initSpan();}
60 
62 {}
63 
65 {
66  return CaloCellGeometry::getPosition() + depth*m_axis ;
67 }
68 
69 CCGFloat
71 {
72  return m_axis.theta() ;
73 }
74 
75 CCGFloat
77 {
78  return m_axis.phi() ;
79 }
80 
81 const GlobalVector&
83 {
84  return m_axis ;
85 }
86 
87 void
89  const CCGFloat* pv ,
90  Pt3D& ref ) const
91 {
92  localCorners( vec, pv, ref ) ;
93 }
94 
97 {
98  return GlobalVector( backCtr() -
100 }
101 
102 const GlobalPoint
104 {
105  return GlobalPoint( 0.25*( getCorners()[4].x() + getCorners()[5].x() +
106  getCorners()[6].x() + getCorners()[7].x() ),
107  0.25*( getCorners()[4].y() + getCorners()[5].y() +
108  getCorners()[6].y() + getCorners()[7].y() ),
109  0.25*( getCorners()[4].z() + getCorners()[5].z() +
110  getCorners()[6].z() + getCorners()[7].z() ) ) ;
111 }
112 
113 void
115 {
117  const Pt3D gFront ( p.x(), p.y(), p.z() ) ;
118  const DPt3D dgFront ( p.x(), p.y(), p.z() ) ;
119 
120  const double dz ( param()[0] ) ;
121 
122  Pt3D lFront ;
123  assert( nullptr != param() ) ;
124  std::vector<Pt3D > lc( 8, Pt3D(0,0,0) ) ;
125  if( 11.2 > dz )
126  {
127  localCorners( lc, param(), lFront ) ;
128  }
129  else
130  {
131  localCornersSwap( lc, param(), lFront ) ;
132  }
133 
134  // figure out if reflction volume or not
135 
136  Pt3D lBack ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7]) ) ;
137 
138  const double disl ( ( lFront - lc[0] ).mag() ) ;
139  const double disr ( ( lFront - lc[3] ).mag() ) ;
140  const double disg ( ( gFront - m_corOne ).mag() ) ;
141 
142  const double dell ( fabs( disg - disl ) ) ;
143  const double delr ( fabs( disg - disr ) ) ;
144 
145  if( 11.2<dz &&
146  delr < dell ) // reflection volume if true
147  {
148  localCornersReflection( lc, param(), lFront ) ;
149  lBack = 0.25*( lc[4] + lc[5] + lc[6] + lc[7] ) ;
150  }
151 
152  const DPt3D dlFront ( lFront.x(), lFront.y(), lFront.z() ) ;
153  const DPt3D dlBack ( lBack.x() , lBack.y() , lBack.z() ) ;
154  const DPt3D dlOne ( lc[0].x() , lc[0].y() , lc[0].z() ) ;
155 
156  const FVec3D dgAxis ( axis().x(), axis().y(), axis().z() ) ;
157 
158  const DPt3D dmOne ( m_corOne.x(), m_corOne.y(), m_corOne.z() ) ;
159 
160  const DPt3D dgBack ( dgFront + ( dlBack - dlFront ).mag()*dgAxis ) ;
161  DPt3D dgOne ( dgFront + ( dlOne - dlFront ).mag()*( dmOne - dgFront ).unit() ) ;
162 
163  const double dlangle ( ( dlBack - dlFront).angle( dlOne - dlFront ) ) ;
164  const double dgangle ( ( dgBack - dgFront).angle( dgOne - dgFront ) ) ;
165  const double dangle ( dlangle - dgangle ) ;
166 
167  if( 1.e-6 < fabs(dangle) )//guard against precision problems
168  {
169  const DPlane3D dgPl ( dgFront, dgOne, dgBack ) ;
170  const DPt3D dp2 ( dgFront + dgPl.normal().unit() ) ;
171 
172  DPt3D dgOld ( dgOne ) ;
173 
174  dgOne = ( dgFront + HepGeom::Rotate3D( -dangle, dgFront, dp2 )*
175  DVec3D( dgOld - dgFront ) ) ;
176  }
177 
178  tr = Tr3D( dlFront , dlBack , dlOne ,
179  dgFront , dgBack , dgOne ) ;
180 
181  if( nullptr != lptr ) (*lptr) = lc ;
182 }
183 
184 void
186 {
187  if( corners.uninitialized() )
188  {
189  Pt3DVec lc ;
190 
191  Tr3D tr ;
192  getTransform( tr, &lc ) ;
193 
194  for( unsigned int i ( 0 ) ; i != 8 ; ++i )
195  {
196  const Pt3D corn ( tr*lc[i] ) ;
197  corners[i] = GlobalPoint( corn.x(), corn.y(), corn.z() ) ;
198  }
199  }
200 }
201 
202 namespace truncPyr
203 {
204  Pt3D refl( const Pt3D & p )
205  {
206  return Pt3D ( -p.x(), p.y(), p.z() ) ;
207  }
208 }
209 
210 void
212  const CCGFloat* pv ,
213  Pt3D& ref )
214 {
215 // using namespace truncPyr ;
216  localCorners( lc, pv, ref ) ;
217  Pt3D tmp ;
218 /*
219  tmp = lc[0] ;
220  lc[0] = refl( lc[2] ) ;
221  lc[2] = refl( tmp ) ;
222  tmp = lc[1] ;
223  lc[1] = refl( lc[3] ) ;
224  lc[3] = refl( tmp ) ;
225  tmp = lc[4] ;
226  lc[4] = refl( lc[6] ) ;
227  lc[6] = refl( tmp ) ;
228  tmp = lc[5] ;
229  lc[5] = refl( lc[7] ) ;
230  lc[7] = refl( tmp ) ;
231 */
232  lc[0] = truncPyr::refl( lc[0] ) ;
233  lc[1] = truncPyr::refl( lc[1] ) ;
234  lc[2] = truncPyr::refl( lc[2] ) ;
235  lc[3] = truncPyr::refl( lc[3] ) ;
236  lc[4] = truncPyr::refl( lc[4] ) ;
237  lc[5] = truncPyr::refl( lc[5] ) ;
238  lc[6] = truncPyr::refl( lc[6] ) ;
239  lc[7] = truncPyr::refl( lc[7] ) ;
240 
241  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
242 }
243 
244 void
246  const CCGFloat* pv ,
247  Pt3D& ref )
248 {
249  assert( nullptr != pv ) ;
250  assert( 8 == lc.size() ) ;
251 
252  const CCGFloat dz ( pv[TruncatedPyramid::k_Dz] ) ;
253  const CCGFloat th ( pv[TruncatedPyramid::k_Theta] ) ;
254  const CCGFloat ph ( pv[TruncatedPyramid::k_Phi] ) ;
255  const CCGFloat h1 ( pv[TruncatedPyramid::k_Dy1] ) ;
256  const CCGFloat b1 ( pv[TruncatedPyramid::k_Dx1] ) ;
257  const CCGFloat t1 ( pv[TruncatedPyramid::k_Dx2] ) ;
258  const CCGFloat a1 ( pv[TruncatedPyramid::k_Alp1] ) ;
259  const CCGFloat h2 ( pv[TruncatedPyramid::k_Dy2] ) ;
260  const CCGFloat b2 ( pv[TruncatedPyramid::k_Dx3] ) ;
261  const CCGFloat t2 ( pv[TruncatedPyramid::k_Dx4] ) ;
262  const CCGFloat a2 ( pv[TruncatedPyramid::k_Alp2] ) ;
263 
264  const CCGFloat ta1 ( tan( a1 ) ) ; // lower plane
265  const CCGFloat ta2 ( tan( a2 ) ) ; // upper plane
266 
267  const CCGFloat tth ( tan( th ) ) ;
268  const CCGFloat tthcp ( tth * cos( ph ) ) ;
269  const CCGFloat tthsp ( tth * sin( ph ) ) ;
270 
271  const unsigned int off ( h1<h2 ? 0 : 4 ) ;
272 
273  lc[0+off] = Pt3D ( -dz*tthcp - h1*ta1 - b1, -dz*tthsp - h1 , -dz ); // (-,-,-)
274  lc[1+off] = Pt3D ( -dz*tthcp + h1*ta1 - t1, -dz*tthsp + h1 , -dz ); // (-,+,-)
275  lc[2+off] = Pt3D ( -dz*tthcp + h1*ta1 + t1, -dz*tthsp + h1 , -dz ); // (+,+,-)
276  lc[3+off] = Pt3D ( -dz*tthcp - h1*ta1 + b1, -dz*tthsp - h1 , -dz ); // (+,-,-)
277  lc[4-off] = Pt3D ( dz*tthcp - h2*ta2 - b2, dz*tthsp - h2 , dz ); // (-,-,+)
278  lc[5-off] = Pt3D ( dz*tthcp + h2*ta2 - t2, dz*tthsp + h2 , dz ); // (-,+,+)
279  lc[6-off] = Pt3D ( dz*tthcp + h2*ta2 + t2, dz*tthsp + h2 , dz ); // (+,+,+)
280  lc[7-off] = Pt3D ( dz*tthcp - h2*ta2 + b2, dz*tthsp - h2 , dz ); // (+,-,+)
281 
282  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
283 }
284 
285 void
287  const CCGFloat* pv ,
288  Pt3D& ref )
289 {
290  localCorners( lc, pv, ref ) ;
291 
292  Pt3D tmp ;
293  tmp = lc[0] ;
294  lc[0] = lc[3] ;
295  lc[3] = tmp ;
296  tmp = lc[1] ;
297  lc[1] = lc[2] ;
298  lc[2] = tmp ;
299  tmp = lc[4] ;
300  lc[4] = lc[7] ;
301  lc[7] = tmp ;
302  tmp = lc[5] ;
303  lc[5] = lc[6] ;
304  lc[6] = tmp ;
305 
306  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
307 }
308 
309 
310 // the following function is static and a helper for the endcap & barrel loader classes
311 // when initializing from DDD: fills corners vector from trap params plus transform
312 
313 void
314 TruncatedPyramid::createCorners( const std::vector<CCGFloat>& pv ,
315  const Tr3D& tr ,
316  std::vector<GlobalPoint>& co )
317 {
318  assert( 11 == pv.size() ) ;
319  assert( 8 == co.size() ) ;
320  // to get the ordering right for fast sim, we have to use their convention
321  // which were based on the old static geometry. Some gymnastics required here.
322 
323  const CCGFloat dz ( pv[0] ) ;
324  const CCGFloat h1 ( pv[3] ) ;
325  const CCGFloat h2 ( pv[7] ) ;
326  Pt3DVec ko ( 8, Pt3D(0,0,0) ) ;
327 
328  // if reflection, different things for barrel and endcap
329  static const FVec3D x ( 1, 0, 0 ) ;
330  static const FVec3D y ( 0, 1, 0 ) ;
331  static const FVec3D z ( 0, 0, 1 ) ;
332  const bool refl ( ( ( tr*x ).cross( tr*y ) ).dot( tr*z ) < 0 ) ; // has reflection!
333 
334  Pt3D tmp ;
335  Pt3DVec to ( 8, Pt3D(0,0,0) ) ;
336  localCorners( to, &pv.front(), tmp ) ;
337 
338  for( unsigned int i ( 0 ) ; i != 8 ; ++i )
339  {
340  ko[i] = tr * to[i] ; // apply transformation
341  }
342 
343  if( refl ||
344  h1>h2 )
345  {
346  if( 11.2 < dz ) //barrel
347  {
348  if( !refl )
349  {
350  to[0] = ko[3] ;
351  to[1] = ko[2] ;
352  to[2] = ko[1] ;
353  to[3] = ko[0] ;
354  to[4] = ko[7] ;
355  to[5] = ko[6] ;
356  to[6] = ko[5] ;
357  to[7] = ko[4] ;
358  }
359  else
360  {
361  to[0] = ko[0] ;
362  to[1] = ko[1] ;
363  to[2] = ko[2] ;
364  to[3] = ko[3] ;
365  to[4] = ko[4] ;
366  to[5] = ko[5] ;
367  to[6] = ko[6] ;
368  to[7] = ko[7] ;
369  }
370  }
371  else //endcap
372  {
373  to[0] = ko[0] ;
374  to[1] = ko[3] ;
375  to[2] = ko[2] ;
376  to[3] = ko[1] ;
377  to[4] = ko[4] ;
378  to[5] = ko[7] ;
379  to[6] = ko[6] ;
380  to[7] = ko[5] ;
381  }
382  copy( to.begin(), to.end(), ko.begin() ) ; // faster than ko = to ? maybe.
383  }
384  for( unsigned int i ( 0 ) ; i != 8 ; ++i )
385  {
386  const Pt3D & p ( ko[i] ) ;
387  co[ i ] = GlobalPoint( p.x(), p.y(), p.z() ) ;
388  }
389 }
390 //----------------------------------------------------------------------
391 //----------------------------------------------------------------------
392 
393 std::ostream& operator<<( std::ostream& s, const TruncatedPyramid& cell )
394 {
395  s << "Center: " << ( (const CaloCellGeometry&) cell).getPosition() << std::endl;
396  const float thetaaxis ( cell.getThetaAxis() ) ;
397  const float phiaxis ( cell.getPhiAxis() ) ;
398  s << "Axis: " << thetaaxis << " " << phiaxis << std::endl ;
399  const CaloCellGeometry::CornersVec& corners ( cell.getCorners() ) ;
400  for ( unsigned int i=0 ; i != corners.size() ; ++i )
401  {
402  s << "Corner: " << corners[i] << std::endl;
403  }
404  return s ;
405 }
406 
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
CaloCellGeometry::Tr3D Tr3D
def copy(args, dbName)
HepGeom::Point3D< double > DPt3D
TruncatedPyramid::Pt3D Pt3D
HepGeom::Point3D< double > DPt3D
static constexpr uint32_t k_Dx4
static constexpr uint32_t k_Alp2
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
CaloCellGeometry::Pt3D Pt3D
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
HepGeom::Transform3D Tr3D
std::vector< Pt3D > Pt3DVec
CCGFloat getPhiAxis() const
static constexpr uint32_t k_Dy2
TruncatedPyramid::Pt3DVec Pt3DVec
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
static constexpr uint32_t k_Phi
static void localCornersSwap(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
static constexpr uint32_t k_Alp1
const CCGFloat * param() const
HepGeom::Vector3D< double > DVec3D
T z() const
Definition: PV3DBase.h:64
CaloCellGeometry::Pt3DVec Pt3DVec
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
def pv(vc)
Definition: MetAnalyzer.py:7
static constexpr uint32_t k_Dx3
static constexpr uint32_t k_Dx2
CCGFloat getThetaAxis() const
TruncatedPyramid & operator=(const TruncatedPyramid &tr)
GlobalVector makeAxis(void)
CaloCellGeometry::Pt3D Pt3D
CaloCellGeometry::CCGFloat CCGFloat
void initCorners(CornersVec &) override
Vector3DBase unit() const
Definition: Vector3DBase.h:57
void getTransform(Tr3D &tr, Pt3DVec *lptr) const override
--------— only needed by specific utility; overloaded when needed -—
HepGeom::Plane3D< double > DPlane3D
TruncatedPyramid::CCGFloat CCGFloat
HepGeom::Point3D< CCGFloat > Pt3D
Definition: EZMgrFL.h:8
void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const override
CornersVec const & getCorners() const
Returns the corner points of this cell&#39;s volume.
static constexpr uint32_t k_Theta
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
GlobalVector m_axis
static constexpr uint32_t k_Dy1
const GlobalVector & axis() const
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
TruncatedPyramid::Tr3D Tr3D
bool uninitialized() const
Definition: EZArrayFL.h:77
std::ostream & operator<<(std::ostream &s, const TruncatedPyramid &cell)
HepGeom::Plane3D< double > DPlane3D
Pt3D refl(const Pt3D &p)
HepGeom::Plane3D< CCGFloat > Plane3D
static constexpr uint32_t k_Dz
~TruncatedPyramid() override
const GlobalPoint backCtr(void) const
T x() const
Definition: PV3DBase.h:62
static void localCornersReflection(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
static constexpr uint32_t k_Dx1
HepGeom::Vector3D< CCGFloat > FVec3D
HepGeom::Vector3D< CCGFloat > FVec3D
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11