00001 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00002 #include <CLHEP/Geometry/Plane3D.h>
00003
00004 typedef CaloCellGeometry::CCGFloat CCGFloat ;
00005 typedef CaloCellGeometry::Pt3D Pt3D ;
00006 typedef CaloCellGeometry::Pt3DVec Pt3DVec ;
00007 typedef CaloCellGeometry::Tr3D Tr3D ;
00008
00009 typedef HepGeom::Vector3D<CCGFloat> Vec3D ;
00010 typedef HepGeom::Plane3D<CCGFloat> Plane3D ;
00011
00012 typedef HepGeom::Vector3D<double> DVec3D ;
00013 typedef HepGeom::Plane3D<double> DPlane3D ;
00014 typedef HepGeom::Point3D<double> DPt3D ;
00015 typedef std::vector<DPt3D> DPt3DVec ;
00016
00017 const float CaloCellGeometry::k_ScaleFromDDDtoGeant ( 0.1 ) ;
00018
00019 CaloCellGeometry::CaloCellGeometry() :
00020 m_refPoint ( 0., 0., 0. ),
00021 m_corners ( ) ,
00022 m_parms ( (CCGFloat*) 0 )
00023 {}
00024
00025 CaloCellGeometry::CaloCellGeometry( const CaloCellGeometry& cell )
00026 {
00027 *this = cell ;
00028 }
00029
00030 CaloCellGeometry&
00031 CaloCellGeometry::operator=( const CaloCellGeometry& cell )
00032 {
00033 if( this != &cell )
00034 {
00035 m_refPoint = cell.m_refPoint ;
00036 m_corners = cell.m_corners ;
00037 m_parms = cell.m_parms ;
00038 }
00039 return *this ;
00040 }
00041
00042 CaloCellGeometry::~CaloCellGeometry()
00043 {}
00044
00045 const GlobalPoint&
00046 CaloCellGeometry::getPosition() const
00047 {
00048 return m_refPoint ;
00049 }
00050
00051 bool
00052 CaloCellGeometry::emptyCorners() const
00053 {
00054 return m_corners.empty() ;
00055 }
00056
00057 const CCGFloat*
00058 CaloCellGeometry::param() const
00059 {
00060 return m_parms ;
00061 }
00062
00063 CaloCellGeometry::CaloCellGeometry( CornersVec::const_reference gp ,
00064 const CornersMgr* mgr,
00065 const CCGFloat* par ) :
00066 m_refPoint ( gp ),
00067 m_corners ( mgr ),
00068 m_parms ( par )
00069 {}
00070
00071 CaloCellGeometry::CaloCellGeometry( const CornersVec& cv,
00072 const CCGFloat* par ) :
00073 m_refPoint ( 0.25*( cv[0].x() + cv[1].x() + cv[2].x() + cv[3].x() ),
00074 0.25*( cv[0].y() + cv[1].y() + cv[2].y() + cv[3].y() ),
00075 0.25*( cv[0].z() + cv[1].z() + cv[2].z() + cv[3].z() ) ),
00076 m_corners ( cv ),
00077 m_parms ( par )
00078 {}
00079
00080 CaloCellGeometry::CornersVec&
00081 CaloCellGeometry::setCorners() const
00082 {
00083 return m_corners ;
00084 }
00085
00086 const CaloCellGeometry::CornersVec&
00087 CaloCellGeometry::getCorners() const
00088 {
00089 return m_corners ;
00090 }
00091
00092 std::ostream& operator<<( std::ostream& s, const CaloCellGeometry& cell )
00093 {
00094 s << ", Center: " << cell.getPosition() << std::endl;
00095
00096 if( cell.emptyCorners() )
00097 {
00098 s << "Corners vector is empty." << std::endl ;
00099 }
00100 else
00101 {
00102 const CaloCellGeometry::CornersVec& corners ( cell.getCorners() ) ;
00103 for ( unsigned int i ( 0 ) ; i != corners.size() ; ++i )
00104 {
00105 s << "Corner: " << corners[ i ] << std::endl;
00106 }
00107 }
00108 return s ;
00109 }
00110
00111 void
00112 CaloCellGeometry::getTransform( Tr3D& tr , Pt3DVec* lptr ) const
00113 {
00114 const GlobalPoint& p ( CaloCellGeometry::getPosition() ) ;
00115 const Pt3D gFront ( p.x(), p.y(), p.z() ) ;
00116 const DPt3D dgFront ( p.x(), p.y(), p.z() ) ;
00117
00118 Pt3D lFront ;
00119 assert( 0 != param() ) ;
00120 Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
00121 vocalCorners( lc, param(), lFront ) ;
00122
00123 DPt3D dlFront ( lFront.x(), lFront.y(), lFront.z() ) ;
00124
00125 const Pt3D lBack ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7]) ) ;
00126 const DPt3D dlBack ( lBack.x(), lBack.y(), lBack.z() ) ;
00127
00128 const Pt3D dlOne ( lc[0].x(), lc[0].y(), lc[0].z() ) ;
00129
00130 const CornersVec& cor ( getCorners() ) ;
00131 DPt3DVec dkor ( 8, DPt3D(0,0,0) ) ;
00132 for( unsigned int i ( 0 ) ; i != 8 ; ++i )
00133 {
00134 dkor[i] = DPt3D ( cor[i].x(), cor[i].y(), cor[i].z() ) ;
00135 }
00136
00137 DPt3D dgBack ( 0.25*( dkor[4]+dkor[5]+dkor[6]+dkor[7] ) ) ;
00138
00139 const DVec3D dgAxis ( (dgBack-dgFront).unit() ) ;
00140
00141 dgBack = ( dgFront + (dlBack-dlFront).mag()*dgAxis ) ;
00142 const DPt3D dgOneT ( dgFront + ( dlOne - dlFront ).mag()*( dkor[0] - dgFront ).unit() ) ;
00143
00144 const double dlangle ( ( dlBack - dlFront).angle( dlOne - dlFront ) ) ;
00145 const double dgangle ( ( dgBack - dgFront).angle( dgOneT- dgFront ) ) ;
00146 const double ddangle ( dlangle - dgangle ) ;
00147
00148 const DPlane3D dgPl ( dgFront, dgOneT, dgBack ) ;
00149 const DPt3D dp2 ( dgFront + dgPl.normal().unit() ) ;
00150
00151 const DPt3D dgOne ( dgFront + HepGeom::Rotate3D( -ddangle, dgFront, dp2 )*
00152 DVec3D ( dgOneT - dgFront ) ) ;
00153
00154 tr = Tr3D( dlFront , dlBack , dlOne ,
00155 dgFront , dgBack , dgOne ) ;
00156
00157 if( 0 != lptr ) (*lptr) = lc ;
00158 }
00159
00160 const float*
00161 CaloCellGeometry::checkParmPtr(
00162 const std::vector<float>& vv ,
00163 CaloCellGeometry::ParVecVec& pvv )
00164 {
00165 const float* pP ( 0 ) ;
00166
00167 for( unsigned int ii ( 0 ) ; ii != pvv.size() ; ++ii )
00168 {
00169 const ParVec& v ( pvv[ii] ) ;
00170 assert( v.size() == vv.size() ) ;
00171
00172 bool same ( true ) ;
00173 for( unsigned int j ( 0 ) ; j != vv.size() ; ++j )
00174 {
00175 same = same && ( fabs( vv[j] - v[j] )<1.e-6 ) ;
00176 if( !same ) break ;
00177 }
00178 if( same )
00179 {
00180 pP = &(*v.begin()) ;
00181 break ;
00182 }
00183 }
00184 return pP ;
00185 }
00186
00187 const float*
00188 CaloCellGeometry::getParmPtr(
00189 const std::vector<float>& vv ,
00190 CaloCellGeometry::ParMgr* mgr ,
00191 CaloCellGeometry::ParVecVec& pvv )
00192 {
00193 const float* pP ( checkParmPtr( vv, pvv ) ) ;
00194
00195 if( 0 == pP )
00196 {
00197 pvv.push_back( ParVec( mgr ) ) ;
00198 ParVec& back ( pvv.back() ) ;
00199 for( unsigned int i ( 0 ) ; i != vv.size() ; ++i )
00200 {
00201 back[i] = vv[i] ;
00202 }
00203 pP = &(*back.begin()) ;
00204 }
00205 return pP ;
00206 }
00207
00208 bool
00209 CaloCellGeometry::inside( const GlobalPoint& point ) const
00210 {
00211 bool ans ( false ) ;
00212 const Pt3D p ( point.x(), point.y(), point.z() ) ;
00213 const CornersVec& cog ( getCorners() ) ;
00214 Pt3D co[8] ;
00215 for( unsigned int i ( 0 ) ; i != 8 ; ++i )
00216 {
00217 co[i] = Pt3D ( cog[i].x(), cog[i].y(), cog[i].z() ) ;
00218 }
00219
00220 const Plane3D AA ( co[0], co[1], co[2] ) ;
00221 const Plane3D BB ( co[6], co[5], co[4] ) ;
00222
00223 if( AA.distance(p)*BB.distance(p) >= 0 )
00224 {
00225 const Plane3D CC ( co[0], co[4], co[5] ) ;
00226 const Plane3D DD ( co[2], co[6], co[7] ) ;
00227 if( CC.distance(p)*DD.distance(p) >= 0 )
00228 {
00229 const Plane3D EE ( co[3], co[7], co[4] ) ;
00230 const Plane3D FF ( co[1], co[5], co[6] ) ;
00231 if( EE.distance(p)*FF.distance(p) >= 0 )
00232 {
00233 ans = true ;
00234 }
00235 }
00236 }
00237 return ans ;
00238 }