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