CMS 3D CMS Logo

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