CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCalGeometry.cc
Go to the documentation of this file.
1 /*
2  * Geometry for High Granularity Calorimeter
3  * This geometry is essentially driven by topology,
4  * which is thus encapsulated in this class.
5  * This makes this geometry not suitable to be loaded
6  * by regular CaloGeometryLoader<T>
7  */
13 
14 #include <cmath>
15 
16 //#define DebugLog
17 
19  : mTopology (topology_) {
22 #ifdef DebugLog
23  std::cout << "Expected total # of Geometry Modules "
24  << topology().totalGeomModules() << std::endl;
25 #endif
26 }
27 
29 
31 
33 }
34 
36  const GlobalPoint& f2 ,
37  const GlobalPoint& f3 ,
38  const CCGFloat* parm ,
39  const DetId& detId ) {
40  const uint32_t cellIndex (topology().detId2denseGeomId(detId));
41  DetId geomId = (detId.subdetId() == HGCEE ?
42  (DetId)(HGCEEDetId(detId).geometryCell()) :
43  (DetId)(HGCHEDetId(detId).geometryCell()));
44  if (cellIndex >= m_cellVec.size()) m_cellVec.resize (cellIndex+1);
45  if (cellIndex >= m_validGeomIds.size()) m_validGeomIds.resize (cellIndex+1);
46  m_cellVec [cellIndex] = FlatTrd( cornersMgr(), f1, f2, f3, parm ) ;
47  m_validGeomIds[cellIndex] = geomId ;
48 
50  int cells = topology().dddConstants().maxCells(id.iLay,true);
51  unsigned int nOld = m_validIds.size();
52  unsigned int nNew = nOld + (unsigned int)(m_halfType ? cells : 2*cells);
53  m_validIds.resize(nNew);
54  for (int cell = 0; cell < cells; ++cell) {
55  id.iCell = cell;
56  m_validIds[nOld+cell] = topology().encode(id);
57  if (!m_halfType) {
58  id.iSubSec = -id.iSubSec;
59  m_validIds[nOld+cells+cell] = topology().encode(id);
60  id.iSubSec = -id.iSubSec;
61  }
62  }
63 #ifdef DebugLog
64  std::cout << "HGCalGeometry::newCell-> [" << cellIndex << "]"
65  << " front:" << f1.x() << '/' << f1.y() << '/' << f1.z()
66  << " back:" << f2.x() << '/' << f2.y() << '/' << f2.z()
67  << " eta|phi " << m_cellVec[cellIndex].etaPos() << ":"
68  << m_cellVec[cellIndex].phiPos() << " id:";
69  if (m_subdet == HGCEE) std::cout << HGCEEDetId(detId);
70  else std::cout << HGCHEDetId(detId);
71  std::cout << " with valid DetId from " << nOld << " to " << nNew
72  << std::endl;
73  std::cout << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId()
74  << ":" << m_validGeomIds[cellIndex].rawId() << std::dec << " "
75  << m_cellVec[cellIndex];
76 #endif
77 }
78 
80  if (id == DetId()) return 0; // nothing to get
81  DetId geoId = (id.subdetId() == HGCEE ?
82  (DetId)(HGCEEDetId(id).geometryCell()) :
83  (DetId)(HGCHEDetId(id).geometryCell()));
84  const uint32_t cellIndex (topology().detId2denseGeomId(geoId));
85  /*
86  if (cellIndex < m_cellVec.size()) {
87  HGCalTopology::DecodedDetId id_ = topology().decode(id);
88  std::pair<float,float> xy = topology().dddConstants().locateCell(id_iCell,id_iLay,id_.iSubSec,true);
89  const HepGeom::Point3D<float> lcoord(xy.first,xy.second,0);
90  std::auto_ptr<FlatTrd> cellGeom(new FlatTrd(m_cellVec[cellIndex],lcoord));
91  return cellGeom.release();
92  }
93  */
94  return cellGeomPtr (cellIndex);
95 
96 }
97 
99 
100  unsigned int cellIndex = indexFor(id);
101  if (cellIndex < m_cellVec.size()) {
103  std::pair<float,float> xy = topology().dddConstants().locateCell(id_.iCell,id_.iLay,id_.iSubSec,true);
104  const HepGeom::Point3D<float> lcoord(xy.first,xy.second,0);
105 #ifdef DebugLog
106  std::cout << "getPosition:: index " << cellIndex << " Local " << xy.first
107  << ":" << xy.second << " ID " << id_.iCell << ":" << id_.iLay
108  << " Global " << m_cellVec[cellIndex].getPosition(lcoord)
109  << " Cell" << m_cellVec[cellIndex];
110 #endif
111  return m_cellVec[cellIndex].getPosition(lcoord);
112  }
113  return GlobalPoint();
114 }
115 
117 
118  HGCalGeometry::CornersVec co (8, GlobalPoint(0,0,0));
119  unsigned int cellIndex = indexFor(id);
120  if (cellIndex < m_cellVec.size()) {
122  std::pair<float,float> xy = topology().dddConstants().locateCell(id_.iCell,id_.iLay,id_.iSubSec,true);
123  float dz = m_cellVec[cellIndex].param()[0];
124  float dx = 0.5*m_cellVec[cellIndex].param()[11];
125  static const int signx[] = {-1,-1,1,1,-1,-1,1,1};
126  static const int signy[] = {-1,1,1,-1,-1,1,1,-1};
127  static const int signz[] = {-1,-1,-1,-1,1,1,1,1};
128  for (unsigned int i = 0; i != 8; ++i) {
129  const HepGeom::Point3D<float> lcoord(xy.first+signx[i]*dx,xy.second+signy[i]*dx,signz[i]*dz);
130  co[i] = m_cellVec[cellIndex].getPosition(lcoord);
131  }
132  }
133  return co;
134 }
135 
137  unsigned int cellIndex = getClosestCellIndex(r);
138  if (cellIndex < m_cellVec.size()) {
139  const HepGeom::Point3D<float> local = m_cellVec[cellIndex].getLocal(r);
141  std::pair<int,int> kxy =
142  topology().dddConstants().assignCell(local.x(),local.y(),id_.iLay,
143  id_.iSubSec,true);
144  id_.iCell = kxy.second;
145  id_.iSubSec = kxy.first;
146 #ifdef DebugLog
147  std::cout << "getClosestCell: local " << local << " Id " << id_.zside
148  << ":" << id_.iLay << ":" << id_.iSec << ":" << id_.iSubSec
149  << ":" << id_.iCell << " Cell " << m_cellVec[cellIndex];
150 #endif
151 
152  //check if returned cell is valid
153  if(id_.iCell>=0) return topology().encode(id_);
154  }
155 
156  //if not valid or out of bounds return a null DetId
157  return DetId();
158 }
159 
162  return dss;
163 }
165  if (m_subdet == HGCEE) return "HGCalEE";
166  else if (m_subdet == HGCHEF) return "HGCalHEFront";
167  else if (m_subdet == HGCHEB) return "HGCalHEBack";
168  else return "Unknown";
169 }
170 
171 unsigned int HGCalGeometry::indexFor(const DetId& id) const {
172  unsigned int cellIndex = m_cellVec.size();
173  if (id != DetId()) {
174  DetId geoId = (id.subdetId() == HGCEE ?
175  (DetId)(HGCEEDetId(id).geometryCell()) :
176  (DetId)(HGCHEDetId(id).geometryCell()));
177  cellIndex = topology().detId2denseGeomId(geoId);
178 #ifdef DebugLog
179  std::cout << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId()
180  << std::dec << " index " << cellIndex << std::endl;
181 #endif
182  }
183  return cellIndex;
184 }
185 
186 unsigned int HGCalGeometry::sizeForDenseIndex() const {
187  return topology().totalGeomModules();
188 }
189 
191  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
192  return 0;
193  const CaloCellGeometry* cell ( &m_cellVec[ index ] ) ;
194 #ifdef DebugLog
195  std::cout << "cellGeomPtr " << m_cellVec[index];
196 #endif
197  if (0 == cell->param()) return 0;
198  return cell;
199 }
200 
202  edm::LogError("HGCalGeom") << "HGCalGeometry::addValidID is not implemented";
203 }
204 
205 
206 unsigned int HGCalGeometry::getClosestCellIndex (const GlobalPoint& r) const {
207 
208  float phip = r.phi();
209  float zp = r.z();
210  unsigned int cellIndex = m_cellVec.size();
211  float dzmin(9999), dphimin(9999), dphi10(0.175);
212  for (unsigned int k=0; k<m_cellVec.size(); ++k) {
213  float dphi = phip-m_cellVec[k].phiPos();
214  while (dphi > M_PI) dphi -= 2*M_PI;
215  while (dphi <= -M_PI) dphi += 2*M_PI;
216  if (fabs(dphi) < dphi10) {
217  float dz = fabs(zp - m_cellVec[k].getPosition().z());
218  if (dz < (dzmin+0.001)) {
219  dzmin = dz;
220  if (fabs(dphi) < (dphimin+0.01)) {
221  cellIndex = k;
222  dphimin = fabs(dphi);
223  } else {
224  if (cellIndex >= m_cellVec.size()) cellIndex = k;
225  }
226  }
227  }
228  }
229 #ifdef DebugLog
230  std::cout << "getClosestCellIndex::Input " << zp << ":" << phip << " Index "
231  << cellIndex;
232  if (cellIndex < m_cellVec.size())
233  std::cout << " Cell z " << m_cellVec[cellIndex].getPosition().z() << ":"
234  << dzmin << " phi " << m_cellVec[cellIndex].phiPos() << ":"
235  << dphimin;
236  std::cout << std::endl;
237 
238 #endif
239  return cellIndex;
240 }
241 
243 
std::vector< DetId > m_validGeomIds
Definition: HGCalGeometry.h:95
int i
Definition: DBlmapReader.cc:9
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const
A base class to handle the particular shape of HGCal volumes.
Definition: FlatTrd.h:19
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
std::string cellElement() const
virtual unsigned int sizeForDenseIndex() const
unsigned int getClosestCellIndex(const GlobalPoint &r) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
std::vector< GlobalPoint > CornersVec
Definition: HGCalGeometry.h:36
GlobalPoint getPosition(const DetId &id) const
bool detectorType() const
CaloCellGeometry::CCGFloat CCGFloat
CornersVec getCorners(const DetId &id) const
Returns the corner points of this cell&#39;s volume.
virtual void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
unsigned int totalGeomModules() const
Definition: HGCalTopology.h:95
HGCalGeometry(const HGCalTopology &topology)
const CCGFloat * param() const
virtual uint32_t detId2denseGeomId(const DetId &id) const
HGCHEDetId geometryCell() const
Definition: HGCHEDetId.cc:46
DetId encode(const DecodedDetId &id_) const
std::vector< DetId > m_validIds
T z() const
Definition: PV3DBase.h:64
const HGCalTopology & topology() const
Definition: HGCalGeometry.h:79
std::set< DetId > DetIdSet
Definition: HGCalGeometry.h:35
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define M_PI
virtual unsigned int indexFor(const DetId &id) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
DecodedDetId decode(const DetId &id) const
Definition: DetId.h:18
ForwardSubdetector m_subdet
Definition: HGCalGeometry.h:97
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:97
HGCEEDetId geometryCell() const
Definition: HGCEEDetId.h:34
CaloCellGeometry::CornersMgr * cornersMgr()
ForwardSubdetector subDetector() const
virtual void fillNamedParams(DDFilteredView fv)
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
tuple cout
Definition: gather_cfg.py:121
virtual void initializeParms()
void addValidID(const DetId &id)
std::pair< float, float > locateCell(int cell, int lay, int subSec, bool reco) const
int maxCells(bool reco) const
T x() const
Definition: PV3DBase.h:62
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
CellVec m_cellVec
Definition: HGCalGeometry.h:94
virtual DetId getClosestCell(const GlobalPoint &r) const
virtual ~HGCalGeometry()