CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

HcalGeometry Class Reference

#include <HcalGeometry.h>

Inheritance diagram for HcalGeometry:
CaloSubdetectorGeometry

List of all members.

Public Types

enum  { k_NumberOfCellsForCorners = HcalDetId::kSizeForDenseIndexing }
enum  { k_NumberOfShapes = 87 }
enum  { k_NumberOfParametersPerShape = 5 }
typedef HcalGeometryRecord AlignedRecord
typedef HcalAlignmentRcd AlignmentRecord
typedef HcalDetId DetIdType
typedef PHcalRcd PGeometryRecord

Public Member Functions

virtual
CaloSubdetectorGeometry::DetIdSet 
getCells (const GlobalPoint &r, double dR) const
 Get a list of all cells within a dR of the given cell.
virtual DetId getClosestCell (const GlobalPoint &r) const
virtual const std::vector
< DetId > & 
getValidDetIds (DetId::Detector det=DetId::Detector(0), int subdet=0) const
 Get a list of valid detector ids (for the given subdetector)
 HcalGeometry (const HcalTopology *topology)
 HcalGeometry ()
virtual unsigned int numberOfParametersPerShape () const
virtual unsigned int numberOfShapes () const
virtual ~HcalGeometry ()
 The HcalGeometry will delete all its cell geometries at destruction time.

Static Public Member Functions

static unsigned int alignmentTransformIndexGlobal (const DetId &id)
static unsigned int alignmentTransformIndexLocal (const DetId &id)
static std::string dbString ()
static std::vector
< HepGeom::Point3D< double > > 
localCorners (const double *pv, unsigned int i, HepGeom::Point3D< double > &ref)
static CaloCellGeometrynewCell (const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, CaloCellGeometry::CornersMgr *mgr, const double *parm, const DetId &detId)
static unsigned int numberOfAlignments ()
static unsigned int numberOfBarrelAlignments ()
static unsigned int numberOfEndcapAlignments ()
static unsigned int numberOfForwardAlignments ()
static unsigned int numberOfOuterAlignments ()
static std::string producerTag ()

Private Member Functions

int etaRing (HcalSubdetector bc, double abseta) const
 helper methods for getClosestCell
void fillDetIds () const
int phiBin (double phi, int etaring) const

Private Attributes

std::vector< DetIdm_emptyIds
std::vector< DetIdm_hbIds
std::vector< DetIdm_heIds
std::vector< DetIdm_hfIds
std::vector< DetIdm_hoIds
bool m_ownsTopology
const HcalTopologytheTopology

Detailed Description

Definition at line 10 of file HcalGeometry.h.


Member Typedef Documentation

Definition at line 15 of file HcalGeometry.h.

Definition at line 14 of file HcalGeometry.h.

Definition at line 17 of file HcalGeometry.h.

Definition at line 16 of file HcalGeometry.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
k_NumberOfCellsForCorners 

Definition at line 19 of file HcalGeometry.h.

anonymous enum
Enumerator:
k_NumberOfShapes 

Definition at line 21 of file HcalGeometry.h.

{ k_NumberOfShapes = 87 } ;
anonymous enum
Enumerator:
k_NumberOfParametersPerShape 

Definition at line 23 of file HcalGeometry.h.


Constructor & Destructor Documentation

HcalGeometry::HcalGeometry ( )

Definition at line 9 of file HcalGeometry.cc.

                           :
   theTopology    ( new HcalTopology ),
   m_ownsTopology ( true )
{
}
HcalGeometry::HcalGeometry ( const HcalTopology topology)

Definition at line 15 of file HcalGeometry.cc.

                                                         :
   theTopology    ( topology ) ,
   m_ownsTopology ( false ) 
{
}
HcalGeometry::~HcalGeometry ( ) [virtual]

The HcalGeometry will delete all its cell geometries at destruction time.

Definition at line 22 of file HcalGeometry.cc.

References m_ownsTopology, and theTopology.

{
   if( m_ownsTopology ) delete theTopology ;
}

Member Function Documentation

unsigned int HcalGeometry::alignmentTransformIndexGlobal ( const DetId id) [static]

Definition at line 326 of file HcalGeometry.cc.

References DetId::Hcal.

{
   return (unsigned int)DetId::Hcal - 1 ;
}
unsigned int HcalGeometry::alignmentTransformIndexLocal ( const DetId id) [static]

Definition at line 281 of file HcalGeometry.cc.

References getHLTprescales::index, CaloGenericDetId::isHB(), CaloGenericDetId::isHcal(), CaloGenericDetId::isHE(), CaloGenericDetId::isHF(), CaloGenericDetId::isHO(), numberOfAlignments(), numberOfBarrelAlignments(), numberOfEndcapAlignments(), numberOfForwardAlignments(), and relativeConstraints::ring.

{
   const CaloGenericDetId gid ( id ) ;

   assert( gid.isHcal() ) ;


   const HcalDetId hid ( id ) ;

   const int jz ( ( hid.zside() + 1 )/2 ) ;

   const int zoff ( jz*numberOfAlignments()/2 ) ;

   const int detoff ( zoff + 
                      ( gid.isHB() ? 0 :
                        ( gid.isHE() ? numberOfBarrelAlignments()/2 :
                          ( gid.isHF() ? ( numberOfBarrelAlignments() +
                                           numberOfEndcapAlignments() )/2 :
                            ( numberOfBarrelAlignments() +
                              numberOfEndcapAlignments() +
                              numberOfForwardAlignments() )/2 ) ) ) ) ; 

   const int iphi ( hid.iphi() ) ;

   unsigned int index ( numberOfAlignments() ) ;
   if( gid.isHO() )
   {
      const int ieta ( hid.ieta() ) ;
      const int ring ( ieta < -10 ? 0 :
                       ( ieta < -4 ? 1 :
                         ( ieta < 5 ? 2 :
                           ( ieta < 11 ? 3 : 4 ) ) ) ) ;

      index = detoff + 12*ring + ( iphi - 1 )%6 ;
   }
   else
   {
      index = detoff + ( iphi - 1 )%4 ;
   }

   assert( index < numberOfAlignments() ) ;
   return index ;
}
static std::string HcalGeometry::dbString ( ) [inline, static]

Definition at line 25 of file HcalGeometry.h.

{ return "PHcalRcd" ; }
int HcalGeometry::etaRing ( HcalSubdetector  bc,
double  abseta 
) const [private]

helper methods for getClosestCell

Definition at line 151 of file HcalGeometry.cc.

References HcalTopology::firstHFRing(), HcalForward, HcalTopology::lastHERing(), HcalTopology::lastHFRing(), theHBHEEtaBounds, theHFEtaBounds, and theTopology.

Referenced by getCells(), and getClosestCell().

{
  int etaring;
  if( bc == HcalForward ) {
    for(etaring = theTopology->firstHFRing();
        etaring <= theTopology->lastHFRing(); ++etaring)
    {
      if(theHFEtaBounds[etaring-theTopology->firstHFRing()+1] > abseta) break;
    }
  }
  else
  {
    for(etaring = 1;
        etaring <= theTopology->lastHERing(); ++etaring)
    {
      if(theHBHEEtaBounds[etaring] >= abseta) break;
    }
  }

  return etaring;
}
void HcalGeometry::fillDetIds ( ) const [private]

Definition at line 29 of file HcalGeometry.cc.

References CaloSubdetectorGeometry::getValidDetIds(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, i, m_emptyIds, m_hbIds, m_heIds, m_hfIds, m_hoIds, and python::multivaluedict::sort().

Referenced by getValidDetIds().

{
   const std::vector<DetId>& baseIds ( CaloSubdetectorGeometry::getValidDetIds() ) ;
   for( unsigned int i ( 0 ) ; i != baseIds.size() ; ++i ) 
   {
      const DetId id ( baseIds[i] );
      if( id.subdetId() == HcalBarrel )
      { 
         m_hbIds.push_back( id ) ;
      }
      else
      {
         if( id.subdetId() == HcalEndcap )
         { 
            m_heIds.push_back( id ) ;
         }
         else
         {
            if( id.subdetId() == HcalOuter )
            { 
               m_hoIds.push_back( id ) ;
            }
            else
            {
               if( id.subdetId() == HcalForward )
               { 
                  m_hfIds.push_back( id ) ;
               }
            }
         }
      }
   }
   std::sort( m_hbIds.begin(), m_hbIds.end() ) ;   
   std::sort( m_heIds.begin(), m_heIds.end() ) ;   
   std::sort( m_hoIds.begin(), m_hoIds.end() ) ;   
   std::sort( m_hfIds.begin(), m_hfIds.end() ) ;   
   m_emptyIds.resize( 0 ) ;
}
CaloSubdetectorGeometry::DetIdSet HcalGeometry::getCells ( const GlobalPoint r,
double  dR 
) const [virtual]

Get a list of all cells within a dR of the given cell.

The default implementation makes a loop over all cell geometries. Cleverer implementations are suggested to use rough conversions between eta/phi and ieta/iphi and test on the boundaries.

Reimplemented from CaloSubdetectorGeometry.

Definition at line 203 of file HcalGeometry.cc.

References reco::deltaR2(), eta(), PV3DBase< T, PVType, FrameType >::eta(), etaRing(), HcalTopology::firstHFRing(), CaloSubdetectorGeometry::getGeometry(), CaloCellGeometry::getPosition(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, HcalTopology::lastHFRing(), M_PI, L1TEmulatorMonitor_cff::p, PV3DBase< T, PVType, FrameType >::phi(), phi, phiBin(), theHFEtaBounds, theTopology, and HcalDetId::validDetId().

{
   CaloSubdetectorGeometry::DetIdSet dis;  // this is the return object

   if( 0.000001 < dR )
   {
      if( dR > M_PI/2. ) // this version needs "small" dR
      {
         dis = CaloSubdetectorGeometry::getCells( r, dR ) ; // base class version
      }
      else
      {
         const double dR2     ( dR*dR ) ;
         const double reta    ( r.eta() ) ;
         const double rphi    ( r.phi() ) ;
         const double lowEta  ( reta - dR ) ;
         const double highEta ( reta + dR ) ;
         const double lowPhi  ( rphi - dR ) ;
         const double highPhi ( rphi + dR ) ;
         
         const double hfEtaHi ( theHFEtaBounds[ theTopology->lastHFRing() -
                                                theTopology->firstHFRing() + 1 ] ) ;
         
         if( highEta > -hfEtaHi &&
             lowEta  <  hfEtaHi    ) // in hcal
         {
            const HcalSubdetector hs[] = { HcalBarrel, HcalOuter, HcalEndcap, HcalForward } ;

            for( unsigned int is ( 0 ) ; is != 4 ; ++is )
            {
               const int sign        (  reta>0 ? 1 : -1 ) ;
               const int ieta_center ( sign*etaRing( hs[is], fabs( reta ) ) ) ;
               const int ieta_lo     ( ( 0 < lowEta*sign ? sign : -sign )*etaRing( hs[is], fabs( lowEta ) ) ) ;
               const int ieta_hi     ( ( 0 < highEta*sign ? sign : -sign )*etaRing( hs[is], fabs( highEta ) ) ) ;
               const int iphi_lo     ( phiBin( lowPhi , ieta_center ) ) ;
               const int iphi_hi     ( phiBin( highPhi, ieta_center ) ) ;
               const int jphi_lo     ( iphi_lo>iphi_hi ? iphi_lo - 72 : iphi_lo ) ;
               const int jphi_hi     ( iphi_hi ) ;

               const int idep_lo     ( 1 == is ? 4 : 1 ) ;
               const int idep_hi     ( 1 == is ? 4 :
                                       ( 2 == is ? 3 : 2 ) ) ;
               for( int ieta ( ieta_lo ) ; ieta <= ieta_hi ; ++ieta ) // over eta limits
               {
                  if( ieta != 0 )
                  {
                     for( int jphi ( jphi_lo ) ; jphi <= jphi_hi ; ++jphi )  // over phi limits
                     {
                        const int iphi ( 1 > jphi ? jphi+72 : jphi ) ;

                        for( int idep ( idep_lo ) ; idep <= idep_hi ; ++idep )
                        {
                           if( HcalDetId::validDetId( hs[is], ieta, iphi, idep ) )
                           {
                              const HcalDetId did ( hs[is], ieta, iphi, idep ) ;
                              const CaloCellGeometry* cell ( getGeometry( did ) );
                              if( 0 != cell )
                              {
                                 const GlobalPoint& p   ( cell->getPosition() ) ;
                                 const double       eta ( p.eta() ) ;
                                 const double       phi ( p.phi() ) ;
                                 if( reco::deltaR2( eta, phi, reta, rphi ) < dR2 ) dis.insert( did ) ;
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
   return dis;
}
DetId HcalGeometry::getClosestCell ( const GlobalPoint r) const [virtual]

Reimplemented from CaloSubdetectorGeometry.

Definition at line 81 of file HcalGeometry.cc.

References abs, PV3DBase< T, PVType, FrameType >::eta(), etaRing(), CaloSubdetectorGeometry::getGeometry(), CaloCellGeometry::getPosition(), HcalBarrel, HcalEmpty, HcalEndcap, HcalForward, HcalTopology::incrementDepth(), HcalTopology::lastHBRing(), HcalTopology::lastHERing(), HcalTopology::lastHFRing(), PV3DBase< T, PVType, FrameType >::mag(), PV3DBase< T, PVType, FrameType >::phi(), phiBin(), theHBHEEtaBounds, theTopology, and PV3DBase< T, PVType, FrameType >::z().

                                                             {

  // Now find the closest eta_bin, eta value of a bin i is average
  // of eta[i] and eta[i-1]
  double abseta = fabs(r.eta());
  
  // figure out subdetector, giving preference to HE in HE/HF overlap region
  HcalSubdetector bc= HcalEmpty;
  if (abseta <= theHBHEEtaBounds[theTopology->lastHBRing()] ) {
    bc = HcalBarrel;
  } else if (abseta <= theHBHEEtaBounds[theTopology->lastHERing()] ) {
    bc = HcalEndcap;
  } else {
    bc = HcalForward;
  }

  if (bc == HcalForward) {
    static const double z_short=1137.0;
    int etaring = etaRing(bc, abseta);  // This is safer
    /*
      static const double z_long=1115.0;
      // determine front-face eta
      double radius=sqrt(pow(r.x(),2)+pow(r.y(),2));
      double trueAeta=asinh(z_long/radius);
      // find eta bin
      int etaring = etaRing(bc, trueAeta);
    */
    if (etaring>theTopology->lastHFRing()) etaring=theTopology->lastHFRing(); 
  
    int phibin = phiBin(r.phi(), etaring);

    // add a sign to the etaring
    int etabin = (r.z() > 0) ? etaring : -etaring;
    // Next line is premature depth 1 and 2 can coexist for large z-extent
    HcalDetId bestId(bc,etabin,phibin,((fabs(r.z())>=z_short)?(2):(1)));
    return bestId;
  } else {

    // find eta bin
    int etaring = etaRing(bc, abseta);
    
    int phibin = phiBin(r.phi(), etaring);
    
    // add a sign to the etaring
    int etabin = (r.z() > 0) ? etaring : -etaring;
    
    //Now do depth if required
    int dbin = 1;
    double pointrz=0, drz=99999.;
    HcalDetId currentId(bc, etabin, phibin, dbin);
    if (bc == HcalBarrel) pointrz = r.mag();
    else                  pointrz = std::abs(r.z());
    HcalDetId bestId;
    for ( ; currentId != HcalDetId(); theTopology->incrementDepth(currentId)) {
      const CaloCellGeometry * cell = getGeometry(currentId);
      assert(cell != 0);
      double rz;
      if (bc == HcalEndcap) rz = std::abs(cell->getPosition().z());
      else                  rz = cell->getPosition().mag();
      if (std::abs(pointrz-rz)<drz) {
        bestId = currentId;
        drz    = std::abs(pointrz-rz);
      }
    }
    
    return bestId;
  }
}
const std::vector< DetId > & HcalGeometry::getValidDetIds ( DetId::Detector  det = DetId::Detector ( 0 ),
int  subdet = 0 
) const [virtual]

Get a list of valid detector ids (for the given subdetector)

Note:
The implementation in this class is relevant for SubdetectorGeometries which handle only a single subdetector at a time. It does not look at the det and subdet arguments.

Reimplemented from CaloSubdetectorGeometry.

Definition at line 69 of file HcalGeometry.cc.

References fillDetIds(), CaloSubdetectorGeometry::getValidDetIds(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, m_emptyIds, m_hbIds, m_heIds, m_hfIds, and m_hoIds.

{
   if( 0 != subdet &&
       0 == m_hbIds.size() ) fillDetIds() ;
   return ( 0 == subdet ? CaloSubdetectorGeometry::getValidDetIds() :
            ( HcalBarrel == subdet ? m_hbIds :
              ( HcalEndcap == subdet ? m_heIds :
                ( HcalOuter == subdet ? m_hoIds :
                  ( HcalForward == subdet ? m_hfIds : m_emptyIds ) ) ) ) ) ;
}
std::vector< HepGeom::Point3D< double > > HcalGeometry::localCorners ( const double *  pv,
unsigned int  i,
HepGeom::Point3D< double > &  ref 
) [static]
CaloCellGeometry * HcalGeometry::newCell ( const GlobalPoint f1,
const GlobalPoint f2,
const GlobalPoint f3,
CaloCellGeometry::CornersMgr mgr,
const double *  parm,
const DetId detId 
) [static]

Definition at line 349 of file HcalGeometry.cc.

References CaloGenericDetId::isHcal(), and CaloGenericDetId::isHF().

{
   const CaloGenericDetId cgid ( detId ) ;

   assert( cgid.isHcal() ) ;

   if( cgid.isHF() )
   {
      return ( new calogeom::IdealZPrism( f1, mgr, parm ) ) ;
   }
   else
   {
      return ( new calogeom::IdealObliquePrism( f1, mgr, parm ) ) ;
   }
}
static unsigned int HcalGeometry::numberOfAlignments ( ) [inline, static]
static unsigned int HcalGeometry::numberOfBarrelAlignments ( ) [inline, static]
static unsigned int HcalGeometry::numberOfEndcapAlignments ( ) [inline, static]
static unsigned int HcalGeometry::numberOfForwardAlignments ( ) [inline, static]
static unsigned int HcalGeometry::numberOfOuterAlignments ( ) [inline, static]
virtual unsigned int HcalGeometry::numberOfParametersPerShape ( ) const [inline, virtual]

Reimplemented from CaloSubdetectorGeometry.

Definition at line 28 of file HcalGeometry.h.

References k_NumberOfParametersPerShape.

virtual unsigned int HcalGeometry::numberOfShapes ( ) const [inline, virtual]

Reimplemented from CaloSubdetectorGeometry.

Definition at line 27 of file HcalGeometry.h.

References k_NumberOfShapes.

{ return k_NumberOfShapes ; }
int HcalGeometry::phiBin ( double  phi,
int  etaring 
) const [private]

Definition at line 174 of file HcalGeometry.cc.

References HcalTopology::firstHFQuadPhiRing(), M_PI, HcalTopology::nPhiBins(), and theTopology.

Referenced by getCells(), and getClosestCell().

{
   static const double twopi = M_PI+M_PI;
  //put phi in correct range (0->2pi)
  if(phi<0.0) phi += twopi;
  if(phi>twopi) phi -= twopi;
  int nphibins = theTopology->nPhiBins(etaring);
  int phibin= static_cast<int>(phi/twopi*nphibins)+1;
  int iphi;

  // rings 40 and 41 are offset wrt the other phi numbering
  //  1        1         1         2
  //  ------------------------------
  //  72       36        36        1
  if(etaring >= theTopology->firstHFQuadPhiRing())
  {
    phi+=(twopi/36); //shift by half tower.    
    phibin=static_cast<int>(phi/twopi*nphibins);
    if (phibin==0) phibin=18;
    iphi=phibin*4-1; // 71,3,5,
  } else {
    // convert to the convention of numbering 1,3,5, in 36 phi bins
    iphi=(phibin-1)*(72/nphibins) + 1;
  }

  return iphi;
}
static std::string HcalGeometry::producerTag ( ) [inline, static]

Member Data Documentation

std::vector<DetId> HcalGeometry::m_emptyIds [mutable, private]

Definition at line 95 of file HcalGeometry.h.

Referenced by fillDetIds(), and getValidDetIds().

std::vector<DetId> HcalGeometry::m_hbIds [mutable, private]

Definition at line 91 of file HcalGeometry.h.

Referenced by fillDetIds(), and getValidDetIds().

std::vector<DetId> HcalGeometry::m_heIds [mutable, private]

Definition at line 92 of file HcalGeometry.h.

Referenced by fillDetIds(), and getValidDetIds().

std::vector<DetId> HcalGeometry::m_hfIds [mutable, private]

Definition at line 94 of file HcalGeometry.h.

Referenced by fillDetIds(), and getValidDetIds().

std::vector<DetId> HcalGeometry::m_hoIds [mutable, private]

Definition at line 93 of file HcalGeometry.h.

Referenced by fillDetIds(), and getValidDetIds().

Definition at line 96 of file HcalGeometry.h.

Referenced by ~HcalGeometry().

Definition at line 89 of file HcalGeometry.h.

Referenced by etaRing(), getCells(), getClosestCell(), phiBin(), and ~HcalGeometry().