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> Vec3D ;
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 {
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 {}
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 {}
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 Vec3D 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 
187 {
188  const CornersVec& co ( CaloCellGeometry::getCorners() ) ;
189  if( co.uninitialized() )
190  {
191  CornersVec& corners ( setCorners() ) ;
192 
193  Pt3DVec lc ;
194 
195  Tr3D tr ;
196  getTransform( tr, &lc ) ;
197 
198  for( unsigned int i ( 0 ) ; i != 8 ; ++i )
199  {
200  const Pt3D corn ( tr*lc[i] ) ;
201  corners[i] = GlobalPoint( corn.x(), corn.y(), corn.z() ) ;
202  }
203  }
204  return co ;
205 }
206 
207 namespace truncPyr
208 {
209  Pt3D refl( const Pt3D & p )
210  {
211  return Pt3D ( -p.x(), p.y(), p.z() ) ;
212  }
213 }
214 
215 void
217  const CCGFloat* pv ,
218  Pt3D& ref )
219 {
220 // using namespace truncPyr ;
221  localCorners( lc, pv, ref ) ;
222  Pt3D tmp ;
223 /*
224  tmp = lc[0] ;
225  lc[0] = refl( lc[2] ) ;
226  lc[2] = refl( tmp ) ;
227  tmp = lc[1] ;
228  lc[1] = refl( lc[3] ) ;
229  lc[3] = refl( tmp ) ;
230  tmp = lc[4] ;
231  lc[4] = refl( lc[6] ) ;
232  lc[6] = refl( tmp ) ;
233  tmp = lc[5] ;
234  lc[5] = refl( lc[7] ) ;
235  lc[7] = refl( tmp ) ;
236 */
237  lc[0] = truncPyr::refl( lc[0] ) ;
238  lc[1] = truncPyr::refl( lc[1] ) ;
239  lc[2] = truncPyr::refl( lc[2] ) ;
240  lc[3] = truncPyr::refl( lc[3] ) ;
241  lc[4] = truncPyr::refl( lc[4] ) ;
242  lc[5] = truncPyr::refl( lc[5] ) ;
243  lc[6] = truncPyr::refl( lc[6] ) ;
244  lc[7] = truncPyr::refl( lc[7] ) ;
245 
246  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
247 }
248 
249 void
251  const CCGFloat* pv ,
252  Pt3D& ref )
253 {
254  assert( 0 != pv ) ;
255  assert( 8 == lc.size() ) ;
256 
257  const CCGFloat dz ( pv[0] ) ;
258  const CCGFloat th ( pv[1] ) ;
259  const CCGFloat ph ( pv[2] ) ;
260  const CCGFloat h1 ( pv[3] ) ;
261  const CCGFloat b1 ( pv[4] ) ;
262  const CCGFloat t1 ( pv[5] ) ;
263  const CCGFloat a1 ( pv[6] ) ;
264  const CCGFloat h2 ( pv[7] ) ;
265  const CCGFloat b2 ( pv[8] ) ;
266  const CCGFloat t2 ( pv[9] ) ;
267  const CCGFloat a2 ( pv[10]) ;
268 
269  const CCGFloat ta1 ( tan( a1 ) ) ; // lower plane
270  const CCGFloat ta2 ( tan( a2 ) ) ; // upper plane
271 
272  const CCGFloat tth ( tan( th ) ) ;
273  const CCGFloat tthcp ( tth * cos( ph ) ) ;
274  const CCGFloat tthsp ( tth * sin( ph ) ) ;
275 
276  const unsigned int off ( h1<h2 ? 0 : 4 ) ;
277 
278  lc[0+off] = Pt3D ( -dz*tthcp - h1*ta1 - b1, -dz*tthsp - h1 , -dz ); // (-,-,-)
279  lc[1+off] = Pt3D ( -dz*tthcp + h1*ta1 - t1, -dz*tthsp + h1 , -dz ); // (-,+,-)
280  lc[2+off] = Pt3D ( -dz*tthcp + h1*ta1 + t1, -dz*tthsp + h1 , -dz ); // (+,+,-)
281  lc[3+off] = Pt3D ( -dz*tthcp - h1*ta1 + b1, -dz*tthsp - h1 , -dz ); // (+,-,-)
282  lc[4-off] = Pt3D ( dz*tthcp - h2*ta2 - b2, dz*tthsp - h2 , dz ); // (-,-,+)
283  lc[5-off] = Pt3D ( dz*tthcp + h2*ta2 - t2, dz*tthsp + h2 , dz ); // (-,+,+)
284  lc[6-off] = Pt3D ( dz*tthcp + h2*ta2 + t2, dz*tthsp + h2 , dz ); // (+,+,+)
285  lc[7-off] = Pt3D ( dz*tthcp - h2*ta2 + b2, dz*tthsp - h2 , dz ); // (+,-,+)
286 
287  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
288 }
289 
290 void
292  const CCGFloat* pv ,
293  Pt3D& ref )
294 {
295  localCorners( lc, pv, ref ) ;
296 
297  Pt3D tmp ;
298  tmp = lc[0] ;
299  lc[0] = lc[3] ;
300  lc[3] = tmp ;
301  tmp = lc[1] ;
302  lc[1] = lc[2] ;
303  lc[2] = tmp ;
304  tmp = lc[4] ;
305  lc[4] = lc[7] ;
306  lc[7] = tmp ;
307  tmp = lc[5] ;
308  lc[5] = lc[6] ;
309  lc[6] = tmp ;
310 
311  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
312 }
313 
314 
315 // the following function is static and a helper for the endcap & barrel loader classes
316 // when initializing from DDD: fills corners vector from trap params plus transform
317 
318 void
319 TruncatedPyramid::createCorners( const std::vector<CCGFloat>& pv ,
320  const Tr3D& tr ,
321  std::vector<GlobalPoint>& co )
322 {
323  assert( 11 == pv.size() ) ;
324  assert( 8 == co.size() ) ;
325  // to get the ordering right for fast sim, we have to use their convention
326  // which were based on the old static geometry. Some gymnastics required here.
327 
328  const CCGFloat dz ( pv[0] ) ;
329  const CCGFloat h1 ( pv[3] ) ;
330  const CCGFloat h2 ( pv[7] ) ;
331  Pt3DVec ko ( 8, Pt3D(0,0,0) ) ;
332 
333  // if reflection, different things for barrel and endcap
334  static const Vec3D x ( 1, 0, 0 ) ;
335  static const Vec3D y ( 0, 1, 0 ) ;
336  static const Vec3D z ( 0, 0, 1 ) ;
337  const bool refl ( ( ( tr*x ).cross( tr*y ) ).dot( tr*z ) < 0 ) ; // has reflection!
338 
339  Pt3D tmp ;
340  Pt3DVec to ( 8, Pt3D(0,0,0) ) ;
341  localCorners( to, &pv.front(), tmp ) ;
342 
343  for( unsigned int i ( 0 ) ; i != 8 ; ++i )
344  {
345  ko[i] = tr * to[i] ; // apply transformation
346  }
347 
348  if( refl ||
349  h1>h2 )
350  {
351  if( 11.2 < dz ) //barrel
352  {
353  if( !refl )
354  {
355  to[0] = ko[3] ;
356  to[1] = ko[2] ;
357  to[2] = ko[1] ;
358  to[3] = ko[0] ;
359  to[4] = ko[7] ;
360  to[5] = ko[6] ;
361  to[6] = ko[5] ;
362  to[7] = ko[4] ;
363  }
364  else
365  {
366  to[0] = ko[0] ;
367  to[1] = ko[1] ;
368  to[2] = ko[2] ;
369  to[3] = ko[3] ;
370  to[4] = ko[4] ;
371  to[5] = ko[5] ;
372  to[6] = ko[6] ;
373  to[7] = ko[7] ;
374  }
375  }
376  else //endcap
377  {
378  to[0] = ko[0] ;
379  to[1] = ko[3] ;
380  to[2] = ko[2] ;
381  to[3] = ko[1] ;
382  to[4] = ko[4] ;
383  to[5] = ko[7] ;
384  to[6] = ko[6] ;
385  to[7] = ko[5] ;
386  }
387  copy( to.begin(), to.end(), ko.begin() ) ; // faster than ko = to ? maybe.
388  }
389  for( unsigned int i ( 0 ) ; i != 8 ; ++i )
390  {
391  const Pt3D & p ( ko[i] ) ;
392  co[ i ] = GlobalPoint( p.x(), p.y(), p.z() ) ;
393  }
394 }
395 //----------------------------------------------------------------------
396 //----------------------------------------------------------------------
397 
398 std::ostream& operator<<( std::ostream& s, const TruncatedPyramid& cell )
399 {
400  s << "Center: " << ( (const CaloCellGeometry&) cell).getPosition() << std::endl;
401  const float thetaaxis ( cell.getThetaAxis() ) ;
402  const float phiaxis ( cell.getPhiAxis() ) ;
403  s << "Axis: " << thetaaxis << " " << phiaxis << std::endl ;
404  const CaloCellGeometry::CornersVec& corners ( cell.getCorners() ) ;
405  for ( unsigned int i=0 ; i != corners.size() ; ++i )
406  {
407  s << "Corner: " << corners[i] << std::endl;
408  }
409  return s ;
410 }
411 
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:68
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:62
HepGeom::Transform3D Tr3D
std::vector< Pt3D > Pt3DVec
CCGFloat getPhiAxis() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
double double double z
const CCGFloat * param() const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:74
virtual ~TruncatedPyramid()
static void localCornersSwap(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
virtual void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const
string unit
Definition: csvLumiCalc.py:46
T z() const
Definition: PV3DBase.h:63
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
Vec4< double > Vec3D
Definition: SSEVec.h:566
CCGFloat getThetaAxis() const
TruncatedPyramid & operator=(const TruncatedPyramid &tr)
GlobalVector makeAxis(void)
CaloCellGeometry::Pt3D Pt3D
CaloCellGeometry::CCGFloat CCGFloat
Vector3DBase unit() const
Definition: Vector3DBase.h:57
virtual const CornersVec & getCorners() const
Returns the corner points of this cell&#39;s volume.
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)
CornersVec & setCorners() const
bool uninitialized() const
Definition: EZArrayFL.h:77
Pt3D refl(const Pt3D &p)
HepGeom::Vector3D< CCGFloat > Vec3D
x
Definition: VDTMath.h:216
const GlobalPoint backCtr(void) const
T x() const
Definition: PV3DBase.h:61
static void localCornersReflection(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
ROOT::Math::Plane3D Plane3D
virtual const CornersVec & getCorners() const =0
Returns the corner points of this cell&#39;s volume.
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
CaloCellGeometry & operator=(const CaloCellGeometry &cell)