CMS 3D CMS Logo

CaloSubdetectorGeometry.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00002 
00003 CaloSubdetectorGeometry::~CaloSubdetectorGeometry() 
00004 { 
00005    for( CellCont::iterator i ( m_cellG.begin() );
00006         i!=m_cellG.end(); ++i )
00007    {
00008       delete const_cast<CaloCellGeometry*>((*i).second) ;
00009    }
00010 
00011    delete m_cmgr ; // must delete after geometries!
00012    delete m_parMgr ; 
00013 }
00014 
00015 void 
00016 CaloSubdetectorGeometry::addCell( const DetId& id, 
00017                                   const CaloCellGeometry* ccg )
00018 {
00019    m_cellG.insert( std::make_pair( id, ccg ) ) ;
00020 }
00021 
00022 const CaloCellGeometry* 
00023 CaloSubdetectorGeometry::getGeometry( const DetId& id ) const
00024 {
00025    CellCont::const_iterator i ( m_cellG.find( id ) ) ;
00026    return ( i == m_cellG.end() ? 0 : i->second ) ;
00027 }
00028 
00029 bool 
00030 CaloSubdetectorGeometry::present( const DetId& id ) const 
00031 {
00032    return m_cellG.find( id ) != m_cellG.end() ;
00033 }
00034 
00035 
00036 const std::vector<DetId>& 
00037 CaloSubdetectorGeometry::getValidDetIds( DetId::Detector det,
00038                                          int             subdet ) const 
00039 {
00040    if( m_validIds.empty() ) 
00041    {
00042       m_validIds.reserve( m_cellG.size() ) ;
00043       for( CellCont::const_iterator i ( cellGeometries().begin() ); 
00044            i != cellGeometries().end() ; ++i )
00045       {
00046          m_validIds.push_back(i->first);
00047       }
00048       std::sort( m_validIds.begin(), m_validIds.end() ) ;
00049    }
00050    return m_validIds ;    
00051 }
00052 
00053 DetId 
00054 CaloSubdetectorGeometry::getClosestCell( const GlobalPoint& r ) const 
00055 {
00056    const double eta ( r.eta() ) ;
00057    const double phi ( r.phi() ) ;
00058    double closest ( 1e9 ) ;
00059    DetId retval(0);
00060    for( CellCont::const_iterator i ( m_cellG.begin() ); 
00061         i != m_cellG.end() ; ++i ) 
00062    {
00063       const GlobalPoint& p ( i->second->getPosition() ) ;
00064       const double eta0 ( p.eta() ) ;
00065       const double phi0 ( p.phi() ) ;
00066       const double dR2 ( reco::deltaR2( eta0, phi0, eta, phi ) ) ;
00067       if( dR2 < closest ) 
00068       {
00069          closest = dR2 ;
00070          retval  = i->first ;
00071       }
00072    }   
00073    return retval;
00074 }
00075 
00076 CaloSubdetectorGeometry::DetIdSet 
00077 CaloSubdetectorGeometry::getCells( const GlobalPoint& r, 
00078                                    double dR             ) const 
00079 {
00080    const double dR2 ( dR*dR ) ;
00081    const double eta ( r.eta() ) ;
00082    const double phi ( r.phi() ) ;
00083 
00084    DetIdSet dss;
00085    
00086    if( 0.000001 < dR )
00087    {
00088       for( CellCont::const_iterator i ( m_cellG.begin() ); 
00089            i != m_cellG.end() ; ++i ) 
00090       {
00091          const GlobalPoint& p ( i->second->getPosition() ) ;
00092          const double eta0 ( p.eta() ) ;
00093          if( fabs( eta - eta0 ) < dR )
00094          {
00095             const double phi0 ( p.phi() ) ;
00096             double delp ( fabs( phi - phi0 ) ) ;
00097             if( delp > M_PI ) delp = 2*M_PI - delp ;
00098             if( delp < dR )
00099             {
00100                const double dist2 ( reco::deltaR2( eta0, phi0, eta, phi ) ) ;
00101                if( dist2 < dR2 ) dss.insert( i->first ) ;
00102             }
00103          }
00104       }   
00105    }
00106    return dss;
00107 }
00108 
00109 void 
00110 CaloSubdetectorGeometry::allocateCorners( CaloCellGeometry::CornersVec::size_type n )
00111 {
00112    assert( 0 == m_cmgr ) ;
00113    m_cmgr = new CaloCellGeometry::CornersMgr( n*( CaloCellGeometry::k_cornerSize ),
00114                                               CaloCellGeometry::k_cornerSize        ) ; 
00115 }
00116 
00117 void 
00118 CaloSubdetectorGeometry::allocatePar( ParVec::size_type n,
00119                                       unsigned int      m     )
00120 {
00121    assert( 0 == m_parMgr ) ;
00122    m_parMgr = new ParMgr( n*m, m ) ;
00123 }
00124 

Generated on Tue Jun 9 17:37:16 2009 for CMSSW by  doxygen 1.5.4