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 #include <Math/Transform3D.h>
17 #include <Math/EulerAngles.h>
18 
20 typedef std::vector<float> ParmVec;
21 
22 //#define DebugLog
23 
25  : m_topology( topology_ ),
26  m_cellVec( topology_.totalGeomModules()),
27  m_validGeomIds( topology_.totalGeomModules()),
28  m_halfType( topology_.detectorType()),
29  m_subdet( topology_.subDetector()) {
30 
31  m_validIds.reserve( topology().totalModules());
32 #ifdef DebugLog
33  std::cout << "Expected total # of Geometry Modules "
34  << topology().totalGeomModules() << std::endl;
35 #endif
36 }
37 
39 
41 
43 }
44 
46  const CCGFloat* pv,
47  unsigned int i,
48  Pt3D& ref) {
49  FlatTrd::localCorners( lc, pv, ref ) ;
50 }
51 
53  const GlobalPoint& f2 ,
54  const GlobalPoint& f3 ,
55  const CCGFloat* parm ,
56  const DetId& detId ) {
57 
58  DetId geomId;
59  int cells;
61  if (topology().dddConstants().geomMode() == HGCalGeometryMode::Square) {
62  geomId = (detId.subdetId() == HGCEE ?
63  (DetId)(HGCEEDetId(detId).geometryCell()) :
64  (DetId)(HGCHEDetId(detId).geometryCell()));
65  cells = topology().dddConstants().maxCells(id.iLay,true);
66  } else {
67  geomId = (DetId)(HGCalDetId(detId).geometryCell());
68  cells = topology().dddConstants().numberCellsHexagon(id.iSec);
69  }
70  const uint32_t cellIndex (topology().detId2denseGeomId(detId));
71 
72  m_cellVec.at( cellIndex ) = FlatTrd( cornersMgr(), f1, f2, f3, parm ) ;
73  m_validGeomIds.at( cellIndex ) = geomId ;
74 
75 #ifdef DebugLog
76  unsigned int nOld = m_validIds.size();
77 #endif
78  for (int cell = 0; cell < cells; ++cell) {
79  id.iCell = cell;
80  m_validIds.push_back( topology().encode(id));
81  if ((topology().dddConstants().geomMode() == HGCalGeometryMode::Square) &&
82  (!m_halfType)) {
83  id.iSubSec = -id.iSubSec;
84  m_validIds.push_back( topology().encode(id));
85  id.iSubSec = -id.iSubSec;
86  }
87  }
88 
89 #ifdef DebugLog
90  std::cout << "HGCalGeometry::newCell-> [" << cellIndex << "]"
91  << " front:" << f1.x() << '/' << f1.y() << '/' << f1.z()
92  << " back:" << f2.x() << '/' << f2.y() << '/' << f2.z()
93  << " eta|phi " << m_cellVec[cellIndex].etaPos() << ":"
94  << m_cellVec[cellIndex].phiPos() << " id:";
95  if (topology().dddConstants().geomMode() != HGCalGeometryMode::Square) {
96  std::cout << HGCalDetId(detId);
97  } else if (m_subdet == HGCEE) {
98  std::cout << HGCEEDetId(detId);
99  } else {
100  std::cout << HGCHEDetId(detId);
101  }
102  unsigned int nNew = m_validIds.size();
103  std::cout << " with valid DetId from " << nOld << " to " << nNew
104  << std::endl;
105  std::cout << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId()
106  << ":" << m_validGeomIds[cellIndex].rawId() << std::dec
107  << std::endl;
108 #endif
109 }
110 
112  if (id == DetId()) return 0; // nothing to get
113  DetId geoId;
114  if (topology().dddConstants().geomMode() == HGCalGeometryMode::Square) {
115  geoId = (id.subdetId() == HGCEE ?
116  (DetId)(HGCEEDetId(id).geometryCell()) :
117  (DetId)(HGCHEDetId(id).geometryCell()));
118  } else {
119  geoId = (DetId)(HGCalDetId(id).geometryCell());
120  }
121  const uint32_t cellIndex (topology().detId2denseGeomId(geoId));
122  /*
123  if (cellIndex < m_cellVec.size()) {
124  HGCalTopology::DecodedDetId id_ = topology().decode(id);
125  std::pair<float,float> xy = topology().dddConstants().locateCell(id_iCell,id_iLay,id_.iSubSec,true);
126  const HepGeom::Point3D<float> lcoord(xy.first,xy.second,0);
127  std::auto_ptr<FlatTrd> cellGeom(new FlatTrd(m_cellVec[cellIndex],lcoord));
128  return cellGeom.release();
129  }
130  */
131  return cellGeomPtr (cellIndex);
132 
133 }
134 
136 
137  unsigned int cellIndex = indexFor(id);
138  GlobalPoint glob;
139  if (cellIndex < m_cellVec.size()) {
141  std::pair<float,float> xy;
142  if (topology().dddConstants().geomMode() == HGCalGeometryMode::Square) {
143  xy = topology().dddConstants().locateCell(id_.iCell,id_.iLay,id_.iSubSec,true);
144  } else {
145  xy = topology().dddConstants().locateCellHex(id_.iCell,id_.iSec,true);
146  }
147  const HepGeom::Point3D<float> lcoord(xy.first,xy.second,0);
148  glob = m_cellVec[cellIndex].getPosition(lcoord);
149 #ifdef DebugLog
150  std::cout << "getPosition:: index " << cellIndex << " Local " << lcoord.x()
151  << ":" << lcoord.y() << " ID " << id_.iCell << ":" << id_.iLay
152  << " Global " << glob << std::endl;
153 #endif
154  }
155  return glob;
156 }
157 
159 
160  HGCalGeometry::CornersVec co (8, GlobalPoint(0,0,0));
161  unsigned int cellIndex = indexFor(id);
162  if (cellIndex < m_cellVec.size()) {
164  std::pair<float,float> xy;
165  if (topology().dddConstants().geomMode() == HGCalGeometryMode::Square) {
166  xy = topology().dddConstants().locateCell(id_.iCell,id_.iLay,id_.iSubSec,true);
167  } else {
168  xy = topology().dddConstants().locateCellHex(id_.iCell,id_.iSec,true);
169  }
170  float dz = m_cellVec[cellIndex].param()[0];
171  float dx = 0.5*m_cellVec[cellIndex].param()[11];
172  static const int signx[] = {-1,-1,1,1,-1,-1,1,1};
173  static const int signy[] = {-1,1,1,-1,-1,1,1,-1};
174  static const int signz[] = {-1,-1,-1,-1,1,1,1,1};
175  for (unsigned int i = 0; i != 8; ++i) {
176  const HepGeom::Point3D<float> lcoord(xy.first+signx[i]*dx,xy.second+signy[i]*dx,signz[i]*dz);
177  co[i] = m_cellVec[cellIndex].getPosition(lcoord);
178  }
179  }
180  return co;
181 }
182 
184  unsigned int cellIndex = getClosestCellIndex(r);
185  if (cellIndex < m_cellVec.size()) {
187  HepGeom::Point3D<float> local;
188  if (topology().dddConstants().geomMode() == HGCalGeometryMode::Square) {
189  local = m_cellVec[cellIndex].getLocal(r);
190  } else {
191  if (r.z() > 0) local = HepGeom::Point3D<float>(r.x(),r.y(),0);
192  else local = HepGeom::Point3D<float>(-r.x(),r.y(),0);
193  }
194  std::pair<int,int> kxy =
195  topology().dddConstants().assignCell(local.x(),local.y(),id_.iLay,
196  id_.iSubSec,true);
197  id_.iCell = kxy.second;
199  id_.iSubSec = kxy.first;
200  } else {
201  id_.iSec = kxy.first;
202  id_.iSubSec = topology().dddConstants().waferTypeT(kxy.first);
203  if (id_.iSubSec != 1) id_.iSubSec = -1;
204  }
205 #ifdef DebugLog
206  std::cout << "getClosestCell: local " << local << " Id " << id_.zside
207  << ":" << id_.iLay << ":" << id_.iSec << ":" << id_.iSubSec
208  << ":" << id_.iCell << std::endl;
209 #endif
210 
211  //check if returned cell is valid
212  if (id_.iCell>=0) return topology().encode(id_);
213  }
214 
215  //if not valid or out of bounds return a null DetId
216  return DetId();
217 }
218 
221  return dss;
222 }
224  if (m_subdet == HGCEE) return "HGCalEE";
225  else if (m_subdet == HGCHEF) return "HGCalHEFront";
226  else if (m_subdet == HGCHEB) return "HGCalHEBack";
227  else return "Unknown";
228 }
229 
230 unsigned int HGCalGeometry::indexFor(const DetId& id) const {
231  unsigned int cellIndex = m_cellVec.size();
232  if (id != DetId()) {
233  DetId geoId;
234  if (topology().dddConstants().geomMode() == HGCalGeometryMode::Square) {
235  geoId = (id.subdetId() == HGCEE ?
236  (DetId)(HGCEEDetId(id).geometryCell()) :
237  (DetId)(HGCHEDetId(id).geometryCell()));
238  } else {
239  geoId = (DetId)(HGCalDetId(id).geometryCell());
240  }
241  cellIndex = topology().detId2denseGeomId(geoId);
242 #ifdef DebugLog
243  std::cout << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId()
244  << std::dec << " index " << cellIndex << std::endl;
245 #endif
246  }
247  return cellIndex;
248 }
249 
250 unsigned int HGCalGeometry::sizeForDenseIndex() const {
251  return topology().totalGeomModules();
252 }
253 
255  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
256  return 0;
257  const CaloCellGeometry* cell ( &m_cellVec[ index ] ) ;
258 #ifdef DebugLog
259  // std::cout << "cellGeomPtr " << m_cellVec[index];
260 #endif
261  if (0 == cell->param()) return 0;
262  return cell;
263 }
264 
266  edm::LogError("HGCalGeom") << "HGCalGeometry::addValidID is not implemented";
267 }
268 
269 
270 unsigned int HGCalGeometry::getClosestCellIndex (const GlobalPoint& r) const {
271 
272  float phip = r.phi();
273  float zp = r.z();
274  unsigned int cellIndex = m_cellVec.size();
275  float dzmin(9999), dphimin(9999), dphi10(0.175);
276  for (unsigned int k=0; k<m_cellVec.size(); ++k) {
277  float dphi = phip-m_cellVec[k].phiPos();
278  while (dphi > M_PI) dphi -= 2*M_PI;
279  while (dphi <= -M_PI) dphi += 2*M_PI;
280  if (fabs(dphi) < dphi10) {
281  float dz = fabs(zp - m_cellVec[k].getPosition().z());
282  if (dz < (dzmin+0.001)) {
283  dzmin = dz;
284  if (fabs(dphi) < (dphimin+0.01)) {
285  cellIndex = k;
286  dphimin = fabs(dphi);
287  } else {
288  if (cellIndex >= m_cellVec.size()) cellIndex = k;
289  }
290  }
291  }
292  }
293 #ifdef DebugLog
294  std::cout << "getClosestCellIndex::Input " << zp << ":" << phip << " Index "
295  << cellIndex;
296  if (cellIndex < m_cellVec.size())
297  std::cout << " Cell z " << m_cellVec[cellIndex].getPosition().z() << ":"
298  << dzmin << " phi " << m_cellVec[cellIndex].phiPos() << ":"
299  << dphimin;
300  std::cout << std::endl;
301 
302 #endif
303  return cellIndex;
304 }
305 
306 // FIXME: Change sorting algorithm if needed
307 namespace
308 {
309  struct rawIdSort
310  {
311  bool operator()( const DetId& a, const DetId& b )
312  {
313  return( a.rawId() < b.rawId());
314  }
315  };
316 }
317 
319  m_validIds.shrink_to_fit();
320  std::sort( m_validIds.begin(), m_validIds.end(), rawIdSort());
321 }
322 
323 void
327  CaloSubdetectorGeometry::IVec& dinsVector ) const {
328 
329  unsigned int numberOfCells = topology().totalGeomModules(); // total Geom Modules both sides
332 
333  trVector.reserve( numberOfCells * numberOfTransformParms());
334  iVector.reserve( numberOfCells );
335  dimVector.reserve( numberOfShapes * numberOfParametersPerShape );
336  dinsVector.reserve( numberOfCells );
337 
338  if (topology().geomMode() == HGCalGeometryMode::Square) {
339  for (unsigned int k=0; k <topology().dddConstants().volumes(); ++k) {
342  params[0] = vol.dz;
343  params[1] = params[2] = 0;
344  params[3] = params[7] = vol.h;
345  params[4] = params[8] = vol.bl;
346  params[5] = params[9] = vol.tl;
347  params[6] = params[10]= vol.alpha;
348  params[11]= vol.cellSize;
349  dimVector.insert( dimVector.end(), params.begin(), params.end());
350  }
351  } else {
352  for (unsigned itr=0; itr<topology().dddConstants().getTrFormN(); ++itr) {
354  int layer = mytr.lay;
355  for (int wafer=0; wafer<topology().dddConstants().sectors(); ++wafer) {
356  if (topology().dddConstants().waferInLayer(wafer,layer,true)) {
357  HGCalParameters::hgtrap vol = topology().dddConstants().getModule(wafer, true, true);
359  params[0] = vol.dz;
360  params[1] = params[2] = 0;
361  params[3] = params[7] = vol.h;
362  params[4] = params[8] = vol.bl;
363  params[5] = params[9] = vol.tl;
364  params[6] = params[10]= vol.alpha;
365  params[11]= vol.cellSize;
366  dimVector.insert( dimVector.end(), params.begin(), params.end());
367  }
368  }
369  }
370  }
371 
372  for( unsigned int i( 0 ); i < numberOfCells; ++i )
373  {
374  DetId detId = m_validGeomIds[i];
375  int layer = ((detId.subdetId() == ForwardSubdetector::HGCEE) ?
376  (HGCEEDetId(detId).layer()) :
377  (HGCHEDetId(detId).layer()));
378  dinsVector.push_back( topology().detId2denseGeomId( detId ));
379  iVector.push_back( layer );
380 
381  Tr3D tr;
382  const CaloCellGeometry* ptr( cellGeomPtr( i ));
383  if( 0 != ptr )
384  {
385  ptr->getTransform( tr, ( Pt3DVec* ) 0 );
386 
387  if( Tr3D() == tr ) // there is no rotation
388  {
389  const GlobalPoint& gp( ptr->getPosition());
390  tr = HepGeom::Translate3D( gp.x(), gp.y(), gp.z());
391  }
392 
393  const CLHEP::Hep3Vector tt( tr.getTranslation());
394  trVector.push_back( tt.x());
395  trVector.push_back( tt.y());
396  trVector.push_back( tt.z());
397  if( 6 == numberOfTransformParms())
398  {
399  const CLHEP::HepRotation rr( tr.getRotation());
400  const ROOT::Math::Transform3D rtr( rr.xx(), rr.xy(), rr.xz(), tt.x(),
401  rr.yx(), rr.yy(), rr.yz(), tt.y(),
402  rr.zx(), rr.zy(), rr.zz(), tt.z());
404  rtr.GetRotation( ea );
405  trVector.push_back( ea.Phi());
406  trVector.push_back( ea.Theta());
407  trVector.push_back( ea.Psi());
408  }
409  }
410  }
411 }
412 
414 
std::vector< DetId > m_validGeomIds
int i
Definition: DBlmapReader.cc:9
A base class to handle the particular shape of HGCal volumes.
Definition: FlatTrd.h:19
std::vector< CCGFloat > DimVec
virtual unsigned int numberOfParametersPerShape() const
std::string cellElement() const
unsigned int sizeForDenseIndex() const
HGCalParameters::hgtrform getTrForm(unsigned int k) const
unsigned int getClosestCellIndex(const GlobalPoint &r) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< unsigned int > IVec
T y() const
Definition: PV3DBase.h:63
virtual void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId) override
std::vector< GlobalPoint > CornersVec
Definition: HGCalGeometry.h:37
std::vector< CCGFloat > TrVec
GlobalPoint getPosition(const DetId &id) const
int layer() const
get the layer #
Definition: HGCHEDetId.h:50
HepGeom::Transform3D Tr3D
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
CaloCellGeometry::CCGFloat CCGFloat
CornersVec getCorners(const DetId &id) const
Returns the corner points of this cell&#39;s volume.
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: HGCalGeometry.h:34
std::pair< float, float > locateCellHex(int cell, int wafer, bool reco) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
unsigned int totalGeomModules() const
HGCalGeometry(const HGCalTopology &topology)
HGCalDetId geometryCell() const
Definition: HGCalDetId.h:36
virtual DetId getClosestCell(const GlobalPoint &r) const override
virtual void initializeParms() override
unsigned int getTrFormN() const
const CCGFloat * param() const
virtual uint32_t detId2denseGeomId(const DetId &id) const
int numberCellsHexagon(int wafer) const
virtual unsigned int numberOfShapes() const
virtual void getTransform(Tr3D &tr, Pt3DVec *lptr) const
--------— only needed by specific utility; overloaded when needed -—
HGCHEDetId geometryCell() const
Definition: HGCHEDetId.cc:46
std::vector< float > ParmVec
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:96
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const override
Get a list of all cells within a dR of the given cell.
virtual unsigned int indexFor(const DetId &id) const override
std::set< DetId > DetIdSet
Definition: HGCalGeometry.h:36
virtual void getSummary(CaloSubdetectorGeometry::TrVec &trVector, CaloSubdetectorGeometry::IVec &iVector, CaloSubdetectorGeometry::DimVec &dimVector, CaloSubdetectorGeometry::IVec &dinsVector) const
HGCalGeometryMode geomMode() const
int sectors() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: FlatTrd.cc:159
void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
#define M_PI
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
DecodedDetId decode(const DetId &id) const
Definition: DetId.h:18
AlgebraicVector EulerAngles
Definition: Definitions.h:36
int layer() const
get the layer #
Definition: HGCEEDetId.h:49
ForwardSubdetector m_subdet
const HGCalDDDConstants & dddConstants() const
HGCEEDetId geometryCell() const
Definition: HGCEEDetId.h:34
CaloCellGeometry::CornersMgr * cornersMgr()
double b
Definition: hdecay.h:120
CaloCellGeometry::Tr3D Tr3D
CaloCellGeometry::Pt3D Pt3D
Definition: HGCalGeometry.h:33
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const override
double a
Definition: hdecay.h:121
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:145
virtual const CaloCellGeometry * getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
void addValidID(const DetId &id)
virtual unsigned int numberOfTransformParms() const
HGCalParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const
int maxCells(bool reco) const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
T x() const
Definition: PV3DBase.h:62
int waferTypeT(int wafer) const
CellVec m_cellVec
bool waferInLayer(int wafer, int lay, bool reco) const
unsigned int volumes() const
virtual ~HGCalGeometry()