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
00009
00010 HcalDDDGeometry::HcalDDDGeometry(const HcalTopology& topo) : topo_(topo),
00011 lastReqDet_(DetId::Detector(0)),
00012 lastReqSubdet_(0),
00013 etaMax_(0),
00014 firstHFQuadRing_(40) ,
00015 m_hbCellVec ( topo.getHBSize() ) ,
00016 m_heCellVec ( topo.getHESize() ) ,
00017 m_hoCellVec ( topo.getHOSize() ) ,
00018 m_hfCellVec ( topo.getHFSize() )
00019 {
00020 twopi = M_PI + M_PI;
00021 deg = M_PI/180.;
00022 }
00023
00024
00025 HcalDDDGeometry::~HcalDDDGeometry()
00026 {
00027 }
00028
00029
00030 std::vector<DetId> const & HcalDDDGeometry::getValidDetIds(DetId::Detector det,
00031 int subdet) const {
00032
00033 const std::vector<DetId>& baseIds(CaloSubdetectorGeometry::getValidDetIds());
00034 if (det == DetId::Detector( 0 ) && subdet == 0) {
00035 return baseIds ;
00036 }
00037
00038 if (lastReqDet_ != det || lastReqSubdet_ != subdet ) {
00039 lastReqDet_ = det ;
00040 lastReqSubdet_ = subdet ;
00041 m_validIds.clear();
00042 m_validIds.reserve( baseIds.size() ) ;
00043 }
00044
00045 if (m_validIds.empty() ) {
00046 for (unsigned int i = 0 ; i != baseIds.size() ; ++i ) {
00047 const DetId id ( baseIds[i] );
00048 if (id.det() == det && id.subdetId() == subdet ) {
00049 m_validIds.push_back( id ) ;
00050 }
00051 }
00052 std::sort(m_validIds.begin(),m_validIds.end());
00053 }
00054
00055 #ifdef DebugLog
00056 LogDebug("HCalGeom") << "HcalDDDGeometry::getValidDetIds: "
00057 << m_validIds.size() << " valid IDs found for detector "
00058 << det << " Sub-detector " << subdet;
00059 #endif
00060 return m_validIds;
00061 }
00062
00063
00064 DetId HcalDDDGeometry::getClosestCell(const GlobalPoint& r) const {
00065
00066
00067
00068 double abseta = fabs(r.eta());
00069 double phi = r.phi();
00070 if (phi < 0) phi += twopi;
00071 double radius = r.mag();
00072 double z = fabs(r.z());
00073 #ifdef DebugLog
00074 LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
00075 << r.eta() << " phi " << phi/deg << " z " << r.z()
00076 << " radius " << radius;
00077 #endif
00078
00079 HcalDetId bestId;
00080 if (abseta <= etaMax_) {
00081 for (unsigned int i=0; i<hcalCells_.size(); i++) {
00082 if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
00083 HcalSubdetector bc = hcalCells_[i].detType();
00084 int etaring = hcalCells_[i].etaBin();
00085 int phibin = 0;
00086 if (hcalCells_[i].unitPhi() == 4) {
00087
00088
00089
00090
00091 phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset()+
00092 0.5*hcalCells_[i].phiBinWidth())/
00093 hcalCells_[i].phiBinWidth());
00094 if (phibin == 0) phibin = hcalCells_[i].nPhiBins();
00095 phibin = phibin*4 - 1;
00096 } else {
00097 phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
00098 hcalCells_[i].phiBinWidth()) + 1;
00099
00100 phibin = (phibin-1)*(hcalCells_[i].unitPhi()) + 1;
00101 }
00102
00103 int dbin = 1;
00104 int etabin = (r.z() > 0) ? etaring : -etaring;
00105 if (bc == HcalForward) {
00106 bestId = HcalDetId(bc, etabin, phibin, dbin);
00107 break;
00108 } else {
00109 double rz = z;
00110 if (hcalCells_[i].depthType()) rz = radius;
00111 if (rz < hcalCells_[i].depthMax()) {
00112 dbin = hcalCells_[i].depthSegment();
00113 bestId = HcalDetId(bc, etabin, phibin, dbin);
00114 break;
00115 }
00116 }
00117 }
00118 }
00119 }
00120 #ifdef DebugLog
00121 LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
00122 #endif
00123 return bestId;
00124 }
00125
00126
00127 int HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells){
00128
00129 hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
00130 int num = static_cast<int>(hcalCells_.size());
00131 for (unsigned int i=0; i<cells.size(); i++) {
00132 if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
00133 }
00134 #ifdef DebugLog
00135 LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
00136 << " cells inserted == Total " << num
00137 << " EtaMax = " << etaMax_;
00138 #endif
00139 return num;
00140 }
00141
00142 void
00143 HcalDDDGeometry::newCell( const GlobalPoint& f1 ,
00144 const GlobalPoint& f2 ,
00145 const GlobalPoint& f3 ,
00146 const CCGFloat* parm ,
00147 const DetId& detId )
00148 {
00149
00150 assert( detId.det()==DetId::Hcal );
00151
00152 const unsigned int din(topo_.detId2denseId(detId));
00153
00154 HcalDetId hId(detId);
00155
00156 if( hId.subdet()==HcalBarrel )
00157 {
00158 m_hbCellVec[ din ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
00159 }
00160 else
00161 {
00162 if( hId.subdet()==HcalEndcap )
00163 {
00164 const unsigned int index ( din - m_hbCellVec.size() ) ;
00165 m_heCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
00166 }
00167 else
00168 {
00169 if( hId.subdet()==HcalOuter )
00170 {
00171 const unsigned int index ( din
00172 - m_hbCellVec.size()
00173 - m_heCellVec.size() ) ;
00174 m_hoCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
00175 }
00176 else
00177 {
00178 const unsigned int index ( din
00179 - m_hbCellVec.size()
00180 - m_heCellVec.size()
00181 - m_hoCellVec.size() ) ;
00182 m_hfCellVec[ index ] = IdealZPrism( f1, cornersMgr(), parm ) ;
00183 }
00184 }
00185 }
00186 m_validIds.push_back( detId ) ;
00187 }
00188
00189 const CaloCellGeometry*
00190 HcalDDDGeometry::cellGeomPtr( uint32_t din ) const
00191 {
00192 const CaloCellGeometry* cell ( 0 ) ;
00193 if( m_hbCellVec.size() > din )
00194 {
00195 cell = &m_hbCellVec[ din ] ;
00196 }
00197 else
00198 {
00199 if( m_hbCellVec.size() +
00200 m_heCellVec.size() > din )
00201 {
00202 const unsigned int index ( din - m_hbCellVec.size() ) ;
00203 cell = &m_heCellVec[ index ] ;
00204 }
00205 else
00206 {
00207 if( m_hbCellVec.size() +
00208 m_heCellVec.size() +
00209 m_hoCellVec.size() > din )
00210 {
00211 const unsigned int index ( din
00212 - m_hbCellVec.size()
00213 - m_heCellVec.size() ) ;
00214 cell = &m_hoCellVec[ index ] ;
00215 }
00216 else
00217 {
00218 if( m_hbCellVec.size() +
00219 m_heCellVec.size() +
00220 m_hoCellVec.size() +
00221 m_hfCellVec.size() > din )
00222 {
00223 const unsigned int index ( din
00224 - m_hbCellVec.size()
00225 - m_heCellVec.size()
00226 - m_hoCellVec.size() ) ;
00227 cell = &m_hfCellVec[ index ] ;
00228 }
00229 }
00230 }
00231 }
00232 return ( 0 == cell || 0 == cell->param() ? 0 : cell ) ;
00233 }