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 
10  m_geos ( kLength, nullptr )
11 {
12 }
13 
14 unsigned int
16  int subdet ,
17  bool& ok ) const
18 {
19  const unsigned int idet ( det ) ;
20 
21  ok = ( kMinDet <= idet &&
22  kMaxDet >= idet &&
23  0 <= subdet &&
24  kMaxSub >= subdet ) ;
25  if (!ok)
26  edm::LogWarning("CaloGeometry") << "Det:Subdet " << idet << ":" << subdet
27  << " min|max Det " << kMinDet << ":"
28  << kMaxDet << " min|max subdet 0:" <<kMaxSub;
29 
30  return ( ( det - kMinDet ) * kNSubDets + subdet ) ;
31 }
32 
33 void
35  int subdet ,
36  const CaloSubdetectorGeometry* geom ) {
37  bool ok ;
38  const unsigned int index = makeIndex( det, subdet, ok ) ;
39  if( ok ) m_geos[index] = geom ;
40 
41  edm::LogVerbatim("CaloGeometry") << "Detector=" << (int)det << ", subset="
42  << subdet << ", index=" << index
43  << ", size=" << m_geos.size();
44 
45  assert( ok ) ;
46 }
47 
50 {
51  bool ok ;
52 
53  const unsigned int index ( makeIndex( id.det(),
54  id.subdetId(),
55  ok ) ) ;
56  return ( ok ? m_geos[ index ] : nullptr ) ;
57 }
58 
61  int subdet ) const
62 {
63  bool ok ;
64 
65  const unsigned int index ( makeIndex( det,
66  subdet,
67  ok ) ) ;
68  return ( ok ? m_geos[ index ] : nullptr ) ;
69 }
70 
71 static const GlobalPoint notFound(0,0,0);
72 
74 CaloGeometry::getPosition( const DetId& id ) const {
76  if (geom) {
77  GlobalPoint pos = geom->getGeometry(id)->getPosition();
78  return pos;
79  } else {
80  return notFound;
81  }
82 }
83 
84 std::shared_ptr<const CaloCellGeometry>
85 CaloGeometry::getGeometry( const DetId& id ) const {
87  if (geom) {
88  auto cell = geom->getGeometry(id);
89  return cell;
90  } else {
91  return std::shared_ptr<const CaloCellGeometry>();
92  }
93 }
94 
95 bool
96 CaloGeometry::present( const DetId& id ) const
97 {
99  return ( nullptr == geom ? false : geom->present( id ) ) ;
100 }
101 
102 std::vector<DetId> CaloGeometry::getValidDetIds() const
103 {
104  std::vector<DetId> returnValue ;
105  returnValue.reserve( kLength ) ;
106 
107  bool doneHcal ( false ) ;
108  for( unsigned int i ( 0 ) ; i != m_geos.size() ; ++i )
109  {
110  if( nullptr != m_geos[i] )
111  {
112  const std::vector< DetId >& aVec = m_geos[i]->getValidDetIds();
113  if( aVec.empty() ) {
114  edm::LogWarning("CaloGeometry") << "Valid det id list at index "
115  << i << " is empty!";
116  }
117  const bool isHcal ( !aVec.empty() && DetId::Hcal == aVec.front().det() ) ;
118  if( !doneHcal ||
119  !isHcal )
120  {
121  returnValue.insert( returnValue.end(), aVec.begin(), aVec.end() ) ;
122  if( !doneHcal &&
123  isHcal ) doneHcal = true ;
124  }
125  }
126  }
127  return returnValue ;
128 }
129 
130 const std::vector<DetId>&
132  int subdet ) const
133 {
134  bool ok ;
135 
136  const unsigned int index ( makeIndex( det,
137  subdet,
138  ok ) ) ;
139 
140  return ( ok && ( nullptr != m_geos[ index ] ) ?
141  m_geos[ index ]->getValidDetIds( det, subdet ) :
142  k_emptyVec ) ;
143 }
144 
145 
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
#define nullptr
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:74
static const std::vector< DetId > k_emptyVec
Definition: CaloGeometry.h:61
Definition: DetId.h:18
void setSubdetGeometry(DetId::Detector det, int subdet, const CaloSubdetectorGeometry *geom)
Register a subdetector geometry.
Definition: CaloGeometry.cc:34
std::vector< const CaloSubdetectorGeometry * > m_geos
Definition: CaloGeometry.h:63
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:26
bool present(const DetId &id) const
is this detid present in the geometry?
Definition: CaloGeometry.cc:96
static const GlobalPoint notFound(0, 0, 0)
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
unsigned int makeIndex(DetId::Detector det, int subdet, bool &ok) const
Definition: CaloGeometry.cc:15
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:85