CMS 3D CMS Logo

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