CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Geometry/EcalAlgo/src/EcalPreshowerGeometry.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloGeometry/interface/PreshowerStrip.h"
00002 #include "Geometry/CaloGeometry/interface/CaloGenericDetId.h"
00003 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00004 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include <iostream>
00007 
00008 EcalPreshowerGeometry::EcalPreshowerGeometry() :
00009    m_xWidWaf      ( 6.3  ) ,
00010    m_xInterLadGap ( 0.05 ) , // additional gap between wafers in adj ladders
00011    m_xIntraLadGap ( 0.04 ) , // gap between wafers in same ladder
00012    m_yWidAct      ( 6.1  ) ,
00013    m_yCtrOff      ( 0.05 )   // gap at center
00014 {
00015 }
00016 
00017 
00018 EcalPreshowerGeometry::~EcalPreshowerGeometry() {}
00019 
00020 unsigned int
00021 EcalPreshowerGeometry::alignmentTransformIndexLocal( const DetId& id )
00022 {
00023    const CaloGenericDetId gid ( id ) ;
00024 
00025    assert( gid.isES() ) ;
00026 
00027 // plane 2 is split into 2 dees along x=0 for both signs of z
00028 
00029 // plane 1 at zsign=-1 is split into 2 dees between six=19 and six=20 for siy<=20,
00030 //                                             and six=21 and 22 for siy>=21
00031 
00032 // plane 1 at zsign=+1 is split into 2 dees between six=20 and six=21 for siy<=20,
00033 //                                             and six=19 and 20 for siy>=21
00034 
00035 
00036 // Desired numbering 
00037 //                LEFT    RIGHT (as one faces the Dee from the IP)
00038 //  ES-  pl=2     0       1
00039 //       pl=1     2       3    the reversal of pl=2 and pl=1 is intentional here (CM Kuo)
00040 //  ES+  pl=1     4       5
00041 //       pl=2     6       7
00042 
00043    const ESDetId esid ( id ) ;
00044    const int jx ( esid.six() - 1 ) ;
00045    const int jy ( esid.siy() - 1 ) ;
00046    const int jz ( esid.zside() + 1 ) ;
00047    const int pl ( esid.plane() - 1 ) ;
00048    const bool second ( 1 == pl ) ;
00049    const bool top   ( 19 < jy ) ;
00050    const bool negz  ( 0 == jz ) ;
00051    const int lrl    ( 20>jx ? 0 : 1 ) ;
00052    const int lrr    ( 22>jx ? 0 : 1 ) ;
00053 
00054    return ( second ? jx/20 + 3*jz :  // 2nd plane split along middle
00055             ( negz && !top ? lrl + 2 :  // 1st plane at neg z and bottom half split at six=19&20
00056               ( negz && top ? lrr + 2 : // 1st plane at neg z and top half split at six=21&22
00057                 ( !negz && !top ? lrr + 4 : lrl + 4 ) ) ) ) ; // opposite at positive z
00058 }
00059 
00060 DetId 
00061 EcalPreshowerGeometry::detIdFromLocalAlignmentIndex( unsigned int iLoc )
00062 {
00063    return ESDetId( 1, 10 + 20*( iLoc%2 ), 10, 2>iLoc || 5<iLoc ? 2 : 1, 2*( iLoc/4 ) - 1 ) ;
00064 }
00065 
00066 unsigned int
00067 EcalPreshowerGeometry::alignmentTransformIndexGlobal( const DetId& id )
00068 {
00069    return (unsigned int)DetId::Ecal - 1 ;
00070 }
00071 
00072 
00073 void 
00074 EcalPreshowerGeometry::initializeParms() 
00075 {
00076    typedef CaloSubdetectorGeometry::CellCont Cont ;
00077    unsigned int n1minus ( 0 ) ;
00078    unsigned int n2minus ( 0 ) ;
00079    unsigned int n1plus ( 0 ) ;
00080    unsigned int n2plus ( 0 ) ;
00081    double z1minus ( 0 ) ;
00082    double z2minus ( 0 ) ;
00083    double z1plus ( 0 ) ;
00084    double z2plus ( 0 ) ;
00085    const Cont& con ( cellGeometries() ) ;
00086    for( unsigned int i ( 0 ) ; i != con.size() ; ++i )
00087    {
00088       const ESDetId esid ( getValidDetIds()[i] ) ;
00089       if( 1 == esid.plane() )
00090       {
00091          if( 0 > esid.zside() )
00092          {
00093             z1minus += con[i]->getPosition().z() ;
00094             ++n1minus ;
00095          }
00096          else
00097          {
00098             z1plus += con[i]->getPosition().z() ;
00099             ++n1plus ;
00100          }
00101       }
00102       if( 2 == esid.plane() )
00103       {
00104          if( 0 > esid.zside() )
00105          {
00106             z2minus += con[i]->getPosition().z() ;
00107             ++n2minus ;
00108          }
00109          else
00110          {
00111             z2plus += con[i]->getPosition().z() ;
00112             ++n2plus ;
00113          }
00114       }
00115 //      if( 0 == z1 && 1 == esid.plane() ) z1 = fabs( i->second->getPosition().z() ) ;
00116 //      if( 0 == z2 && 2 == esid.plane() ) z2 = fabs( i->second->getPosition().z() ) ;
00117 //      if( 0 != z1 && 0 != z2 ) break ;
00118    }
00119    assert( 0 != n1minus &&
00120            0 != n2minus &&
00121            0 != n1plus  &&
00122            0 != n2plus     ) ;
00123    z1minus /= (1.*n1minus) ;
00124    z2minus /= (1.*n2minus) ;
00125    z1plus /= (1.*n1plus) ;
00126    z2plus /= (1.*n2plus) ;
00127    assert( 0 != z1minus &&
00128            0 != z2minus &&
00129            0 != z1plus  &&
00130            0 != z2plus     ) ;
00131    setzPlanes( z1minus, z2minus, z1plus, z2plus ) ;
00132 }
00133 
00134 
00135 void 
00136 EcalPreshowerGeometry::setzPlanes( float z1minus, 
00137                                    float z2minus,
00138                                    float z1plus, 
00139                                    float z2plus ) 
00140 {
00141    assert( 0 > z1minus &&
00142            0 > z2minus &&
00143            0 < z1plus  &&
00144            0 < z2plus     ) ;
00145 
00146    m_zplane[0] = z1minus ;
00147    m_zplane[1] = z2minus ;
00148    m_zplane[2] = z1plus ;
00149    m_zplane[3] = z2plus ;
00150 }
00151 
00152 
00153 // Get closest cell, etc...
00154 DetId 
00155 EcalPreshowerGeometry::getClosestCell( const GlobalPoint& point ) const
00156 {
00157   return getClosestCellInPlane( point, 2 );
00158 } 
00159 
00160 DetId 
00161 EcalPreshowerGeometry::getClosestCellInPlane( const GlobalPoint& point,
00162                                               int                plane          ) const
00163 {
00164    const double x ( point.x() ) ;
00165    const double y ( point.y() ) ;
00166    const double z ( point.z() ) ;
00167 
00168    if( 0 == z    ||
00169        1 > plane ||
00170        2 < plane    ) return DetId( 0 ) ;
00171 
00172    const unsigned int iz ( ( 0>z ? 0 : 2 ) + plane - 1 ) ;
00173 
00174    const double ze ( m_zplane[iz] ) ;
00175    const double xe ( x * ze/z ) ;
00176    const double ye ( y * ze/z ) ;
00177 
00178    const double x0 ( 1 == plane ? xe : ye ) ;
00179    const double y0 ( 1 == plane ? ye : xe ) ;
00180 
00181    static const double xWid ( m_xWidWaf + m_xIntraLadGap + m_xInterLadGap ) ;
00182 
00183    const int row ( 1 + int( y0 + 20.*m_yWidAct - m_yCtrOff )/m_yWidAct ) ;
00184    const int col ( 1 + int( ( x0 + 20.*xWid )/xWid ) ) ;
00185 
00186    double closest ( 1e9 ) ; 
00187 
00188    DetId detId ( 0 ) ;
00189 
00190    const int jz ( 0 > ze ? -1 : 1 ) ;
00191 
00192 
00193 //   std::cout<<"** p="<<point<<", ("<<xe<<", "<<ye<<", "<<ze<<"), row="<<row<<", col="<<col<<std::endl;
00194 
00195    for( int ix ( -1 ); ix != 2 ; ++ix ) // search within +-1 in row and col
00196    {
00197       for( int iy ( -1 ); iy != 2 ; ++iy )
00198       {
00199          for( int jstrip ( ESDetId::ISTRIP_MIN ) ; jstrip <= ESDetId::ISTRIP_MAX ; ++jstrip )
00200          {
00201             const int jx ( 1 == plane ? col + ix : row + iy ) ;
00202             const int jy ( 1 == plane ? row + iy : col + ix ) ;
00203             if( ESDetId::validDetId( jstrip, jx, jy, plane, jz ) )
00204             {
00205                const ESDetId esId ( jstrip, jx, jy, plane, jz ) ;
00206                const unsigned int index ( esId.denseIndex() ) ;
00207                const GlobalPoint& p ( cellGeometries()[ index ]->getPosition() ) ;
00208                const double dist2 ( (p.x()-xe)*(p.x()-xe) + (p.y()-ye)*(p.y()-ye) ) ;
00209                if( dist2 < closest && present( esId ) )
00210                {
00211                   closest = dist2 ;
00212                   detId   = esId  ;
00213                }
00214             }
00215          }
00216       }
00217    }
00218    return detId ;
00219 }
00220 
00221 std::vector<HepGeom::Point3D<double> > 
00222 EcalPreshowerGeometry::localCorners( const double* pv,
00223                                      unsigned int  i,
00224                                      HepGeom::Point3D<double> &   ref )
00225 {
00226    return ( PreshowerStrip::localCorners( pv, ref ) ) ;
00227 }
00228 
00229 CaloCellGeometry* 
00230 EcalPreshowerGeometry::newCell( const GlobalPoint& f1 ,
00231                                 const GlobalPoint& f2 ,
00232                                 const GlobalPoint& f3 ,
00233                                 CaloCellGeometry::CornersMgr* mgr,
00234                                 const double*      parm ,
00235                                 const DetId&       detId    ) 
00236 {
00237    return ( new PreshowerStrip( f1, mgr , parm ) ) ;
00238 }