Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:39

0001 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0002 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0003 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 const std::vector<DetId> CaloGeometry::k_emptyVec(0);
0008 
0009 CaloGeometry::CaloGeometry() : m_geos(kLength, nullptr) {}
0010 
0011 unsigned int CaloGeometry::makeIndex(DetId::Detector det, int subdet, bool& ok) const {
0012   const unsigned int idet(det);
0013 
0014   ok = (kMinDet <= idet && kMaxDet >= idet && 0 <= subdet && kMaxSub >= subdet);
0015   if (!ok)
0016     edm::LogWarning("CaloGeometry") << "Det:Subdet " << idet << ":" << subdet << " min|max Det " << kMinDet << ":"
0017                                     << kMaxDet << " min|max subdet 0:" << kMaxSub;
0018 
0019   return ((det - kMinDet) * kNSubDets + subdet);
0020 }
0021 
0022 void CaloGeometry::setSubdetGeometry(DetId::Detector det, int subdet, const CaloSubdetectorGeometry* geom) {
0023   bool ok;
0024   const unsigned int index = makeIndex(det, subdet, ok);
0025   if (ok)
0026     m_geos[index] = geom;
0027 
0028   edm::LogVerbatim("CaloGeometry") << "Detector=" << (int)det << ", subset=" << subdet << ", index=" << index
0029                                    << ", size=" << m_geos.size();
0030 
0031   assert(ok);
0032 }
0033 
0034 const CaloSubdetectorGeometry* CaloGeometry::getSubdetectorGeometry(const DetId& id) const {
0035   bool ok;
0036 
0037   const unsigned int index(makeIndex(id.det(), id.subdetId(), ok));
0038   return (ok ? m_geos[index] : nullptr);
0039 }
0040 
0041 const CaloSubdetectorGeometry* CaloGeometry::getSubdetectorGeometry(DetId::Detector det, int subdet) const {
0042   bool ok;
0043 
0044   const unsigned int index(makeIndex(det, subdet, ok));
0045   return (ok ? m_geos[index] : nullptr);
0046 }
0047 
0048 static const GlobalPoint notFound(0, 0, 0);
0049 
0050 GlobalPoint CaloGeometry::getPosition(const DetId& id) const {
0051   const CaloSubdetectorGeometry* geom = getSubdetectorGeometry(id);
0052   if (geom) {
0053     GlobalPoint pos = geom->getGeometry(id)->getPosition();
0054     return pos;
0055   } else {
0056     return notFound;
0057   }
0058 }
0059 
0060 std::shared_ptr<const CaloCellGeometry> CaloGeometry::getGeometry(const DetId& id) const {
0061   const CaloSubdetectorGeometry* geom = getSubdetectorGeometry(id);
0062   if (geom) {
0063     auto cell = geom->getGeometry(id);
0064     return cell;
0065   } else {
0066     return std::shared_ptr<const CaloCellGeometry>();
0067   }
0068 }
0069 
0070 bool CaloGeometry::present(const DetId& id) const {
0071   const CaloSubdetectorGeometry* geom = getSubdetectorGeometry(id);
0072   return (nullptr == geom ? false : geom->present(id));
0073 }
0074 
0075 std::vector<DetId> CaloGeometry::getValidDetIds() const {
0076   std::vector<DetId> returnValue;
0077   returnValue.reserve(kLength);
0078 
0079   bool doneHcal(false);
0080   for (unsigned int i(0); i != m_geos.size(); ++i) {
0081     if (nullptr != m_geos[i]) {
0082       const std::vector<DetId>& aVec = m_geos[i]->getValidDetIds();
0083       if (aVec.empty()) {
0084         edm::LogWarning("CaloGeometry") << "Valid det id list at index " << i << " is empty!";
0085       }
0086       const bool isHcal(!aVec.empty() && DetId::Hcal == aVec.front().det());
0087       if (!doneHcal || !isHcal) {
0088         returnValue.insert(returnValue.end(), aVec.begin(), aVec.end());
0089         if (!doneHcal && isHcal)
0090           doneHcal = true;
0091       }
0092     }
0093   }
0094   return returnValue;
0095 }
0096 
0097 const std::vector<DetId>& CaloGeometry::getValidDetIds(DetId::Detector det, int subdet) const {
0098   bool ok;
0099 
0100   const unsigned int index(makeIndex(det, subdet, ok));
0101 
0102   return (ok && (nullptr != m_geos[index]) ? m_geos[index]->getValidDetIds(det, subdet) : k_emptyVec);
0103 }