CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Geometry/HcalTowerAlgo/src/HcalDDDGeometry.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00002 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00003 #include "Geometry/HcalTowerAlgo/interface/HcalDDDGeometry.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include <algorithm>
00007 
00008 //#define DebugLog
00009 
00010 HcalDDDGeometry::HcalDDDGeometry() : lastReqDet_(DetId::Detector(0)), 
00011                                      lastReqSubdet_(0), etaMax_(0),
00012                                      firstHFQuadRing_(40) {
00013   twopi = M_PI + M_PI;
00014   deg   = M_PI/180.;
00015 }
00016 
00017 
00018 HcalDDDGeometry::~HcalDDDGeometry() {}
00019 
00020 
00021 std::vector<DetId> const & HcalDDDGeometry::getValidDetIds(DetId::Detector det,
00022                                                            int subdet) const {
00023 
00024   const std::vector<DetId>& baseIds(CaloSubdetectorGeometry::getValidDetIds());
00025   if (det    == DetId::Detector( 0 ) && subdet == 0) {
00026     return baseIds ;
00027   }
00028    
00029   if (lastReqDet_  != det || lastReqSubdet_ != subdet ) {
00030     lastReqDet_     = det    ;
00031     lastReqSubdet_  = subdet ;
00032     m_validIds.clear();
00033     m_validIds.reserve( baseIds.size() ) ;
00034   }
00035 
00036   if (m_validIds.empty() ) {
00037     for (unsigned int i = 0 ; i != baseIds.size() ; ++i ) {
00038       const DetId id ( baseIds[i] );
00039       if (id.det()      == det   && id.subdetId() == subdet ) { 
00040         m_validIds.push_back( id ) ;
00041       }
00042     }
00043     std::sort(m_validIds.begin(),m_validIds.end());
00044   }
00045   
00046 #ifdef DebugLog
00047   LogDebug("HCalGeom") << "HcalDDDGeometry::getValidDetIds: "
00048                        << m_validIds.size() << " valid IDs found for detector "
00049                        << det << " Sub-detector " << subdet;
00050 #endif
00051   return m_validIds;
00052 }
00053 
00054 
00055 DetId HcalDDDGeometry::getClosestCell(const GlobalPoint& r) const {
00056 
00057   // Now find the closest eta_bin, eta value of a bin i is average
00058   // of eta[i] and eta[i-1]
00059   double abseta = fabs(r.eta());
00060   double phi    = r.phi();
00061   if (phi < 0) phi += twopi;
00062   double radius = r.mag();
00063   double z      = fabs(r.z());
00064 #ifdef DebugLog
00065   LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
00066                        << r.eta() << " phi " << phi/deg << " z " << r.z()
00067                        << " radius " << radius;
00068 #endif
00069 
00070   HcalDetId bestId;
00071   if (abseta <= etaMax_) {
00072     for (unsigned int i=0; i<hcalCells_.size(); i++) {
00073       if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
00074         HcalSubdetector bc = hcalCells_[i].detType();
00075         int etaring = hcalCells_[i].etaBin();
00076         int phibin  = 0;
00077         if (hcalCells_[i].unitPhi() == 4) {
00078           // rings 40 and 41 are offset wrt the other phi numbering
00079           //  1        1         1         2
00080           //  ------------------------------
00081           //  72       36        36        1
00082           phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset()+
00083                                      0.5*hcalCells_[i].phiBinWidth())/
00084                                     hcalCells_[i].phiBinWidth());
00085           if (phibin == 0) phibin = hcalCells_[i].nPhiBins();
00086           phibin = phibin*4 - 1; 
00087         } else {
00088           phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
00089                                     hcalCells_[i].phiBinWidth()) + 1;
00090           // convert to the convention of numbering 1,3,5, in 36 phi bins
00091           phibin = (phibin-1)*(hcalCells_[i].unitPhi()) + 1;
00092         }
00093 
00094         int dbin   = 1;
00095         int etabin = (r.z() > 0) ? etaring : -etaring;
00096         if (bc == HcalForward) {
00097           bestId   = HcalDetId(bc, etabin, phibin, dbin);
00098           break;
00099         } else {
00100           double rz = z;
00101           if (hcalCells_[i].depthType()) rz = radius;
00102           if (rz < hcalCells_[i].depthMax()) {
00103             dbin   = hcalCells_[i].depthSegment();
00104             bestId = HcalDetId(bc, etabin, phibin, dbin);
00105             break;
00106           }
00107         }
00108       }
00109     }
00110   }
00111 #ifdef DebugLog
00112   LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
00113 #endif
00114   return bestId;
00115 }
00116 
00117 
00118 int HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells){
00119 
00120   hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
00121   int num = static_cast<int>(hcalCells_.size());
00122   for (unsigned int i=0; i<cells.size(); i++) {
00123     if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
00124   }
00125 #ifdef DebugLog
00126   LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
00127                        << " cells inserted == Total " << num
00128                        << " EtaMax = " << etaMax_;
00129 #endif
00130   return num;
00131 }