CMS 3D CMS Logo

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