CMS 3D CMS Logo

CaloGeometry.cc
Go to the documentation of this file.
4 
6 
7 const std::vector<DetId> CaloGeometry::k_emptyVec(0);
8 
9 CaloGeometry::CaloGeometry() : m_geos(kLength, nullptr) {}
10 
11 unsigned int CaloGeometry::makeIndex(DetId::Detector det, int subdet, bool& ok) const {
12  const unsigned int idet(det);
13 
14  ok = (kMinDet <= idet && kMaxDet >= idet && 0 <= subdet && kMaxSub >= subdet);
15  if (!ok)
16  edm::LogWarning("CaloGeometry") << "Det:Subdet " << idet << ":" << subdet << " min|max Det " << kMinDet << ":"
17  << kMaxDet << " min|max subdet 0:" << kMaxSub;
18 
19  return ((det - kMinDet) * kNSubDets + subdet);
20 }
21 
23  bool ok;
24  const unsigned int index = makeIndex(det, subdet, ok);
25  if (ok)
26  m_geos[index] = geom;
27 
28  edm::LogVerbatim("CaloGeometry") << "Detector=" << (int)det << ", subset=" << subdet << ", index=" << index
29  << ", size=" << m_geos.size();
30 
31  assert(ok);
32 }
33 
35  bool ok;
36 
37  const unsigned int index(makeIndex(id.det(), id.subdetId(), ok));
38  return (ok ? m_geos[index] : nullptr);
39 }
40 
42  bool ok;
43 
44  const unsigned int index(makeIndex(det, subdet, ok));
45  return (ok ? m_geos[index] : nullptr);
46 }
47 
48 static const GlobalPoint notFound(0, 0, 0);
49 
52  if (geom) {
53  GlobalPoint pos = geom->getGeometry(id)->getPosition();
54  return pos;
55  } else {
56  return notFound;
57  }
58 }
59 
60 std::shared_ptr<const CaloCellGeometry> CaloGeometry::getGeometry(const DetId& id) const {
62  if (geom) {
63  auto cell = geom->getGeometry(id);
64  return cell;
65  } else {
66  return std::shared_ptr<const CaloCellGeometry>();
67  }
68 }
69 
70 bool CaloGeometry::present(const DetId& id) const {
72  return (nullptr == geom ? false : geom->present(id));
73 }
74 
75 std::vector<DetId> CaloGeometry::getValidDetIds() const {
76  std::vector<DetId> returnValue;
77  returnValue.reserve(kLength);
78 
79  bool doneHcal(false);
80  for (unsigned int i(0); i != m_geos.size(); ++i) {
81  if (nullptr != m_geos[i]) {
82  const std::vector<DetId>& aVec = m_geos[i]->getValidDetIds();
83  if (aVec.empty()) {
84  edm::LogWarning("CaloGeometry") << "Valid det id list at index " << i << " is empty!";
85  }
86  const bool isHcal(!aVec.empty() && DetId::Hcal == aVec.front().det());
87  if (!doneHcal || !isHcal) {
88  returnValue.insert(returnValue.end(), aVec.begin(), aVec.end());
89  if (!doneHcal && isHcal)
90  doneHcal = true;
91  }
92  }
93  }
94  return returnValue;
95 }
96 
97 const std::vector<DetId>& CaloGeometry::getValidDetIds(DetId::Detector det, int subdet) const {
98  bool ok;
99 
100  const unsigned int index(makeIndex(det, subdet, ok));
101 
102  return (ok && (nullptr != m_geos[index]) ? m_geos[index]->getValidDetIds(det, subdet) : k_emptyVec);
103 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
#define nullptr
std::vector< const CaloSubdetectorGeometry * > m_geos
Definition: CaloGeometry.h:57
virtual bool present(const DetId &id) const
is this detid present in the geometry?
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
static const std::vector< DetId > k_emptyVec
Definition: CaloGeometry.h:55
Definition: DetId.h:17
void setSubdetGeometry(DetId::Detector det, int subdet, const CaloSubdetectorGeometry *geom)
Register a subdetector geometry.
Definition: CaloGeometry.cc:22
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Detector
Definition: DetId.h:24
bool present(const DetId &id) const
is this detid present in the geometry?
Definition: CaloGeometry.cc:70
static const GlobalPoint notFound(0, 0, 0)
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
unsigned int makeIndex(DetId::Detector det, int subdet, bool &ok) const
Definition: CaloGeometry.cc:11
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:60