CMS 3D CMS Logo

FlatTrd.cc
Go to the documentation of this file.
3 #include <algorithm>
4 #include <iostream>
5 
6 //#define DebugLog
7 
9 typedef FlatTrd::Pt3D Pt3D ;
12 
13 typedef HepGeom::Vector3D<CCGFloat> FVec3D ;
14 typedef HepGeom::Plane3D<CCGFloat> Plane3D ;
15 
16 typedef HepGeom::Vector3D<double> DVec3D ;
17 typedef HepGeom::Plane3D<double> DPlane3D ;
18 typedef HepGeom::Point3D<double> DPt3D ;
19 
20 //----------------------------------------------------------------------
21 
22 FlatTrd::FlatTrd() : CaloCellGeometry(), m_axis ( 0., 0., 0. ),
23  m_corOne ( 0., 0., 0. ), m_local (0., 0., 0.),
24  m_global ( 0., 0., 0. ) {
25 }
26 
28  *this = tr ;
29 }
30 
32  CaloCellGeometry::operator=( tr ) ;
33  if ( this != &tr ) {
34  m_axis = tr.m_axis ;
35  m_corOne = tr.m_corOne ;
36  m_local = tr.m_local;
37  m_global = tr.m_global;
38  m_tr = tr.m_tr;
39  }
40 #ifdef DebugLog
41  std::cout << "FlatTrd(Copy): Local " << m_local << " Global " << m_global
42  << " eta " << etaPos() << " phi " << phiPos() << " Translation "
43  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
44 #endif
45  return *this ;
46 }
47 
49  const GlobalPoint& fCtr ,
50  const GlobalPoint& bCtr ,
51  const GlobalPoint& cor1 ,
52  const CCGFloat* parV ) :
53  CaloCellGeometry ( fCtr, cMgr, parV ) ,
54  m_axis ( ( bCtr - fCtr ).unit() ) ,
55  m_corOne ( cor1.x(), cor1.y(), cor1.z() ),
56  m_local (0., 0., 0.) {
57  getTransform(m_tr,nullptr);
58  Pt3D glb = m_tr*m_local;
59  m_global = GlobalPoint(glb.x(),glb.y(),glb.z());
60 #ifdef DebugLog
61  std::cout << "FlatTrd: Local " << m_local << " Global " << glb << " eta "
62  << etaPos() << " phi " << phiPos() << " Translation "
63  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
64 #endif
65 }
66 
68  const CCGFloat* par ) :
69  CaloCellGeometry ( corn, par ) ,
70  m_corOne ( corn[0].x(), corn[0].y(), corn[0].z() ),
71  m_local (0., 0., 0.) {
72  getTransform(m_tr,nullptr);
73  m_axis = makeAxis();
74  Pt3D glb = m_tr*m_local;
75  m_global = GlobalPoint(glb.x(),glb.y(),glb.z());
76 #ifdef DebugLog
77  std::cout << "FlatTrd: Local " << m_local << " Global " << glb << " eta "
78  << etaPos() << " phi " << phiPos() << " Translation "
79  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
80 #endif
81 }
82 
83 FlatTrd::FlatTrd( const FlatTrd& tr, const Pt3D & local ) :
84  CaloCellGeometry( tr ), m_local(local) {
85  *this = tr;
86  Pt3D glb = m_tr*m_local;
87  m_global = GlobalPoint(glb.x(),glb.y(),glb.z());
88 #ifdef DebugLog
89  std::cout << "FlatTrd: Local " << m_local << " Global " << glb << " eta "
90  << etaPos() << " phi " << phiPos() << " Translation "
91  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
92 #endif
93 }
94 
96 
98  Pt3D glb = m_tr*local;
99 #ifdef DebugLog
100  std::cout << "FlatTrd::Local " << local.x() << ":" << local.y() << ":"
101  << local.z() << " Global " << glb.x() << ":" << glb.y() << ":"
102  << glb.z() << " TR " << m_tr.xx() << ":" << m_tr.xy() << ":"
103  << m_tr.xz() << ":" << m_tr.yx() << ":" << m_tr.yy() << ":"
104  << m_tr.yz() << ":" << m_tr.zx() << ":" << m_tr.zy() << ":"
105  << m_tr.zz() << ":" << m_tr.dx() << ":" << m_tr.dy() << ":"
106  << m_tr.dz() << std::endl;
107 #endif
108  return GlobalPoint(glb.x(),glb.y(),glb.z());
109 }
110 
111 Pt3D FlatTrd::getLocal(const GlobalPoint& global) const {
112  Pt3D local = m_tr.inverse()*Pt3D(global.x(),global.y(),global.z());
113 #ifdef DebugLog
114  std::cout << "FlatTrd::Global " << global.x() << ":" << global.y() << ":"
115  << global.z() << " Local " << local.x() << ":" << local.y() << ":"
116  << local.z() << std::endl;
117 #endif
118  return local;
119 }
120 
122  return m_axis.theta() ;
123 }
124 
126  return m_axis.phi() ;
127 }
128 
129 const GlobalVector& FlatTrd::axis() const {
130  return m_axis ;
131 }
132 
134  const CCGFloat* pv ,
135  Pt3D& ref ) const {
136  localCorners( vec, pv, ref ) ;
137 }
138 
139 void FlatTrd::createCorners( const std::vector<CCGFloat>& pv ,
140  const Tr3D& tr ,
141  std::vector<GlobalPoint>& co ) {
142 
143  assert( 11 <= pv.size() ) ;
144  assert( 8 == co.size() ) ;
145 
146  Pt3DVec ko ( 8, Pt3D(0,0,0) ) ;
147 
148  Pt3D tmp ;
149  Pt3DVec to ( 8, Pt3D(0,0,0) ) ;
150  localCorners( to, &pv.front(), tmp ) ;
151 
152  for( unsigned int i ( 0 ) ; i != 8 ; ++i ) {
153  ko[i] = tr * to[i] ; // apply transformation
154  const Pt3D & p ( ko[i] ) ;
155  co[ i ] = GlobalPoint( p.x(), p.y(), p.z() ) ;
156 #ifdef DebugLog
157  std::cout << "Corner[" << i << "] = " << co[i] << std::endl;
158 #endif
159  }
160 }
161 
163  const CCGFloat* pv ,
164  Pt3D& ref ) {
165  assert( nullptr != pv ) ;
166  assert( 8 == lc.size() ) ;
167 
168  const CCGFloat dz ( pv[0] ) ;
169  const CCGFloat h ( pv[3] ) ;
170  const CCGFloat bl ( pv[4] ) ;
171  const CCGFloat tl ( pv[5] ) ;
172  const CCGFloat a1 ( pv[6] ) ;
173 
174  const CCGFloat ta1 ( tan( a1 ) ) ;
175 
176  lc[0] = Pt3D ( - h*ta1 - bl, - h , -dz ); // (-,-,-)
177  lc[1] = Pt3D ( + h*ta1 - tl, + h , -dz ); // (-,+,-)
178  lc[2] = Pt3D ( + h*ta1 + tl, + h , -dz ); // (+,+,-)
179  lc[3] = Pt3D ( - h*ta1 + bl, - h , -dz ); // (+,-,-)
180  lc[4] = Pt3D ( - h*ta1 - bl, - h , dz ); // (-,-,+)
181  lc[5] = Pt3D ( + h*ta1 - tl, + h , dz ); // (-,+,+)
182  lc[6] = Pt3D ( + h*ta1 + tl, + h , dz ); // (+,+,+)
183  lc[7] = Pt3D ( - h*ta1 + bl, - h , dz ); // (+,-,+)
184 
185  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
186 #ifdef DebugLog
187  std::cout << "Ref " << ref << " Local Corners " << lc[0] << "|" << lc[1]
188  << "|" << lc[2] << "|" << lc[3] << "|" << lc[4] << "|" << lc[5]
189  << "|" << lc[6] << "|" << lc[7] << std::endl;
190 #endif
191 }
192 
193 void FlatTrd::getTransform( Tr3D& tr, Pt3DVec* lptr ) const {
195  const Pt3D gFront ( p.x(), p.y(), p.z() ) ;
196  const DPt3D dgFront ( p.x(), p.y(), p.z() ) ;
197 
198  Pt3D lFront ;
199  assert( nullptr != param() ) ;
200  std::vector<Pt3D > lc( 8, Pt3D(0,0,0) ) ;
201  localCorners( lc, param(), lFront ) ;
202 
203  // figure out if reflction volume or not
204 
205  Pt3D lBack ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7]) ) ;
206 
207  const DPt3D dlFront ( lFront.x(), lFront.y(), lFront.z() ) ;
208  const DPt3D dlBack ( lBack.x() , lBack.y() , lBack.z() ) ;
209  const DPt3D dlOne ( lc[0].x() , lc[0].y() , lc[0].z() ) ;
210 
211  const FVec3D dgAxis ( axis().x(), axis().y(), axis().z() ) ;
212 
213  const DPt3D dmOne ( m_corOne.x(), m_corOne.y(), m_corOne.z() ) ;
214 
215  const DPt3D dgBack ( dgFront + ( dlBack - dlFront ).mag()*dgAxis ) ;
216  DPt3D dgOne ( dgFront + ( dlOne - dlFront ).mag()*( dmOne - dgFront ).unit() ) ;
217 
218  const double dlangle ( ( dlBack - dlFront).angle( dlOne - dlFront ) ) ;
219  const double dgangle ( ( dgBack - dgFront).angle( dgOne - dgFront ) ) ;
220  const double dangle ( dlangle - dgangle ) ;
221 
222  if( 1.e-6 < fabs(dangle) ) {//guard against precision problems
223  const DPlane3D dgPl ( dgFront, dgOne, dgBack ) ;
224  const DPt3D dp2 ( dgFront + dgPl.normal().unit() ) ;
225 
226  DPt3D dgOld ( dgOne ) ;
227 
228  dgOne = ( dgFront + HepGeom::Rotate3D( -dangle, dgFront, dp2 )*
229  DVec3D( dgOld - dgFront ) ) ;
230  }
231 
232  tr = Tr3D( dlFront , dlBack , dlOne ,
233  dgFront , dgBack , dgOne ) ;
234 
235  if( nullptr != lptr ) (*lptr) = lc ;
236 }
237 
239 
240  if( co.uninitialized() ) {
241  CornersVec& corners ( co ) ;
242  Pt3DVec lc ;
243  Tr3D tr ;
244  getTransform( tr, &lc ) ;
245 
246  for (unsigned int i ( 0 ) ; i != 8 ; ++i ) {
247  const Pt3D corn ( tr*lc[i] ) ;
248  corners[i] = GlobalPoint( corn.x(), corn.y(), corn.z() ) ;
249  }
250  }
251 }
252 
254  return GlobalVector( backCtr() - getPosition() ).unit() ;
255 }
256 
258  float dz = (getCorners()[4].z() > getCorners()[0].z()) ?
259  param()[0] : -param()[0];
260  Pt3D local_b(m_local.x(),m_local.y(),m_local.z()+dz);
261  Pt3D global_b = m_tr*local_b;
262  GlobalPoint global(global_b.x(),global_b.y(),global_b.z());
263  return global;
264 }
265 
266 //----------------------------------------------------------------------
267 //----------------------------------------------------------------------
268 
269 std::ostream& operator<<( std::ostream& s, const FlatTrd& cell ) {
270  s << "Center: " << cell.getPosition() << " eta " << cell.etaPos()
271  << " phi " << cell.phiPos() << std::endl;
272  s << "Axis: " << cell.getThetaAxis() << " " << cell.getPhiAxis() <<std::endl;
273  const CaloCellGeometry::CornersVec& corners ( cell.getCorners() ) ;
274  for ( unsigned int i=0 ; i != corners.size() ; ++i ) {
275  s << "Corner: " << corners[i] << std::endl;
276  }
277  return s ;
278 }
279 
const GlobalVector & axis() const
Definition: FlatTrd.cc:129
A base class to handle the particular shape of HGCal volumes.
Definition: FlatTrd.h:19
HepGeom::Point3D< double > DPt3D
Definition: FlatTrd.cc:18
FlatTrd & operator=(const FlatTrd &tr)
Definition: FlatTrd.cc:31
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
CaloCellGeometry::Pt3D Pt3D
Definition: FlatTrd.h:23
HepGeom::Point3D< double > DPt3D
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
double glb
Definition: hdecay.h:105
GlobalPoint const & getPosition() const override
Returns the position of reference for this cell.
Definition: FlatTrd.h:46
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: FlatTrd.h:24
HepGeom::Transform3D Tr3D
FlatTrd::Pt3D Pt3D
Definition: FlatTrd.cc:9
std::vector< Pt3D > Pt3DVec
Tr3D m_tr
Definition: FlatTrd.h:86
FlatTrd::CCGFloat CCGFloat
Definition: FlatTrd.cc:8
HepGeom::Plane3D< CCGFloat > Plane3D
Definition: FlatTrd.cc:14
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
const CCGFloat * param() const
Pt3D m_local
Definition: FlatTrd.h:84
void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const override
Definition: FlatTrd.cc:133
CaloCellGeometry::CCGFloat CCGFloat
Definition: FlatTrd.h:22
T z() const
Definition: PV3DBase.h:64
HepGeom::Vector3D< CCGFloat > FVec3D
Definition: FlatTrd.cc:13
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
def pv(vc)
Definition: MetAnalyzer.py:6
GlobalPoint backCtr(void) const
Definition: FlatTrd.cc:257
FlatTrd::Tr3D Tr3D
Definition: FlatTrd.cc:11
HepGeom::Vector3D< double > DVec3D
Definition: FlatTrd.cc:16
Pt3D m_corOne
Definition: FlatTrd.h:84
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: FlatTrd.cc:162
void getTransform(Tr3D &tr, Pt3DVec *lptr) const override
--------— only needed by specific utility; overloaded when needed -—
Definition: FlatTrd.cc:193
HepGeom::Plane3D< double > DPlane3D
Definition: FlatTrd.cc:17
~FlatTrd() override
Definition: FlatTrd.cc:95
Vector3DBase unit() const
Definition: Vector3DBase.h:57
Pt3D getLocal(const GlobalPoint &global) const
Definition: FlatTrd.cc:111
GlobalVector makeAxis(void)
Definition: FlatTrd.cc:253
HepGeom::Plane3D< double > DPlane3D
void initCorners(CornersVec &) override
Definition: FlatTrd.cc:238
HepGeom::Point3D< CCGFloat > Pt3D
Definition: EZMgrFL.h:8
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatTrd.cc:139
CornersVec const & getCorners() const
Returns the corner points of this cell&#39;s volume.
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
FlatTrd::Pt3DVec Pt3DVec
Definition: FlatTrd.cc:10
bool uninitialized() const
Definition: EZArrayFL.h:77
GlobalPoint m_global
Definition: FlatTrd.h:85
CaloCellGeometry::Tr3D Tr3D
Definition: FlatTrd.h:25
CCGFloat getThetaAxis() const
Definition: FlatTrd.cc:121
virtual float phiPos() const
Definition: FlatTrd.h:49
std::ostream & operator<<(std::ostream &s, const FlatTrd &cell)
Definition: FlatTrd.cc:269
virtual float etaPos() const
Definition: FlatTrd.h:48
FlatTrd(void)
Definition: FlatTrd.cc:22
T x() const
Definition: PV3DBase.h:62
CCGFloat getPhiAxis() const
Definition: FlatTrd.cc:125
HepGeom::Vector3D< CCGFloat > FVec3D
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalVector m_axis
Definition: FlatTrd.h:83
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11