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 HcalDDDGeometry::HcalDDDGeometry() : lastReqDet_(DetId::Detector(0)),
00007 lastReqSubdet_(0), etaMax_(0),
00008 firstHFQuadRing_(40) {
00009 twopi = M_PI + M_PI;
00010 deg = M_PI/180.;
00011 }
00012
00013
00014 HcalDDDGeometry::~HcalDDDGeometry() {}
00015
00016
00017 std::vector<DetId> const & HcalDDDGeometry::getValidDetIds(DetId::Detector det,
00018 int subdet) const {
00019
00020 if (lastReqDet_!=det || lastReqSubdet_!=subdet) {
00021 lastReqDet_=det;
00022 lastReqSubdet_=subdet;
00023 m_validIds.clear();
00024 }
00025
00026 if (m_validIds.empty()) {
00027 m_validIds.reserve(cellGeometries().size());
00028 CaloSubdetectorGeometry::CellCont::const_iterator i;
00029 for (i=cellGeometries().begin(); i!=cellGeometries().end(); i++) {
00030 DetId id(i->first);
00031 if (id.det()==det && id.subdetId()==subdet)
00032 m_validIds.push_back(id);
00033 }
00034 std::sort(m_validIds.begin(),m_validIds.end());
00035 }
00036
00037 LogDebug("HCalGeom") << "HcalDDDGeometry::getValidDetIds: "
00038 << m_validIds.size() << " valid IDs found for detector "
00039 << det << " Sub-detector " << subdet;
00040 return m_validIds;
00041 }
00042
00043
00044 DetId HcalDDDGeometry::getClosestCell(const GlobalPoint& r) const {
00045
00046
00047
00048 double abseta = fabs(r.eta());
00049 double phi = r.phi();
00050 if (phi < 0) phi += twopi;
00051 double radius = r.mag();
00052 double z = fabs(r.z());
00053 LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
00054 << r.eta() << " phi " << phi/deg << " z " << r.z()
00055 << " radius " << radius;
00056
00057 HcalDetId bestId;
00058 if (abseta <= etaMax_) {
00059 for (unsigned int i=0; i<hcalCells_.size(); i++) {
00060 if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
00061 HcalSubdetector bc = hcalCells_[i].detType();
00062 int etaring = hcalCells_[i].etaBin();
00063 int phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
00064 hcalCells_[i].phiBinWidth()) + 1;
00065
00066
00067
00068
00069 if (etaring >= firstHFQuadRing_) {
00070 ++phibin;
00071 if (phibin > hcalCells_[i].nPhiBins())
00072 phibin -= hcalCells_[i].nPhiBins();
00073 }
00074
00075
00076
00077 phibin = (phibin-1)*(hcalCells_[i].nPhiModule()) + 1;
00078 int dbin = 1;
00079 int etabin = (r.z() > 0) ? etaring : -etaring;
00080 if (bc == HcalForward) {
00081 bestId = HcalDetId(bc, etabin, phibin, dbin);
00082 break;
00083 } else {
00084 double rz = z;
00085 if (hcalCells_[i].depthType()) rz = radius;
00086 if (rz < hcalCells_[i].depthMax()) {
00087 dbin = hcalCells_[i].depthSegment();
00088 bestId = HcalDetId(bc, etabin, phibin, dbin);
00089 break;
00090 }
00091 }
00092 }
00093 }
00094 }
00095 LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
00096
00097 return bestId;
00098 }
00099
00100
00101 int HcalDDDGeometry::insertCell(std::vector<HcalCellType::HcalCellType> const & cells){
00102
00103 hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
00104 int num = static_cast<int>(hcalCells_.size());
00105 for (unsigned int i=0; i<cells.size(); i++) {
00106 if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
00107 }
00108 LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
00109 << " cells inserted == Total " << num
00110 << " EtaMax = " << etaMax_;
00111 return num;
00112 }