CMS 3D CMS Logo

FastTimeGeometry.cc
Go to the documentation of this file.
6 
7 #include <cmath>
8 
9 #include <Math/Transform3D.h>
10 #include <Math/EulerAngles.h>
11 
13 typedef std::vector<float> ParmVec;
14 
16  : m_topology(topology_),
17  m_cellVec(topology_.totalGeomModules()),
18  m_validGeomIds(topology_.totalGeomModules()),
19  m_Type(topology_.detectorType()),
20  m_subdet(topology_.subDetector()) {
21 
22  m_validIds.reserve(topology().totalModules());
23 #ifdef EDM_ML_DEBUG
24  std::cout << "Expected total # of Geometry Modules "
25  << topology().totalGeomModules() << std::endl;
26 #endif
27 }
28 
30 
32 
34 }
35 
37  const CCGFloat* pv,
38  unsigned int i,
39  Pt3D& ref) {
40  FlatTrd::localCorners( lc, pv, ref ) ;
41 }
42 
44  const GlobalPoint& f2 ,
45  const GlobalPoint& f3 ,
46  const CCGFloat* parm ,
47  const DetId& detId ) {
48 
50  DetId geomId = (DetId)(FastTimeDetId(detId).geometryCell());
51  int nEtaZ = topology().dddConstants().numberEtaZ(m_Type);
53 
54  const uint32_t cellIndex (topology().detId2denseGeomId(detId));
55 
56  m_cellVec.at( cellIndex ) = FlatTrd( cornersMgr(), f1, f2, f3, parm ) ;
57  m_validGeomIds.at( cellIndex ) = geomId ;
58 
59 #ifdef EDM_ML_DEBUG
60  unsigned int nOld = m_validIds.size();
61 #endif
62  for (int etaZ = 1; etaZ <= nEtaZ; ++etaZ) {
63  id.iEtaZ = etaZ;
64  for (int phi = 1; phi <= nPhi; ++phi) {
65  id.iPhi = phi;
66  DetId idc = topology().encode(id);
67  if (topology().valid(idc)) {
68  m_validIds.emplace_back(idc);
69  }
70  }
71  }
72 
73 #ifdef EDM_ML_DEBUG
74  std::cout << "FastTimeGeometry::newCell-> [" << cellIndex << "]"
75  << " front:" << f1.x() << '/' << f1.y() << '/' << f1.z()
76  << " back:" << f2.x() << '/' << f2.y() << '/' << f2.z()
77  << " eta|phi " << m_cellVec[cellIndex].etaPos() << ":"
78  << m_cellVec[cellIndex].phiPos() << " id:" << FastTimeDetId(detId)
79  << " with valid DetId from " << nOld << " to " << m_validIds.size()
80  << std::endl;
81  std::cout << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId()
82  << ":" << m_validGeomIds[cellIndex].rawId() << std::dec
83  << std::endl;
84 #endif
85 }
86 
87 std::shared_ptr<const CaloCellGeometry> FastTimeGeometry::getGeometry(const DetId& id) const {
88 
89  if (id == DetId()) return nullptr; // nothing to get
90  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
91  const uint32_t cellIndex (topology().detId2denseGeomId(geoId));
92  const GlobalPoint pos = (id != geoId) ? getPosition(id) : GlobalPoint();
93  return cellGeomPtr (cellIndex, pos);
94 }
95 
96 bool FastTimeGeometry::present(const DetId& id) const {
97  if (id == DetId()) return false;
98  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
99  const uint32_t index(topology().detId2denseGeomId(geoId));
100  return (nullptr != getGeometryRawPtr(index)) ;
101 }
102 
104 
105  FastTimeDetId id_ = FastTimeDetId(id);
106  auto pos = topology().dddConstants().getPosition(m_Type,id_.ieta(),id_.iphi(),id_.zside());
107  return GlobalPoint(0.1*pos.x(),0.1*pos.y(),0.1*pos.z());
108 }
109 
111 
112  FastTimeDetId id_ = FastTimeDetId(id);
113  auto corners = topology().dddConstants().getCorners(m_Type,id_.ieta(),id_.iphi(),id_.zside());
115  for( const auto& corner : corners ) {
116  out.emplace_back(0.1*corner.x(),0.1*corner.y(),0.1*corner.z());
117  }
118  return out;
119 }
120 
122  int zside = (r.z() > 0) ? 1 : -1;
123  std::pair<int,int> etaZPhi;
124  if (m_Type == 1) {
125  double zz = (zside > 0) ? r.z() : -r.z();
126  etaZPhi = topology().dddConstants().getZPhi(zz,r.phi());
127  } else {
128  double phi = (zside > 0) ? r.phi() : atan2(r.y(),-r.x());
129  etaZPhi = topology().dddConstants().getEtaPhi(r.perp(),phi);
130  }
131  FastTimeDetId id = FastTimeDetId(m_Type,etaZPhi.first,etaZPhi.second,zside);
132 #ifdef EDM_ML_DEBUG
133  std::cout << "getClosestCell: for (" << r.x() << ", " << r.y() << ", "
134  << r.z() << ") Id " << id.type() << ":" << id.zside() << ":"
135  << id.ieta() << ":" << id.iphi() << std::endl;
136 #endif
137 
138  return (topology().valid(id) ? DetId(id) : DetId());
139 }
140 
143  return dss;
144 }
145 
147  if (m_Type == 1) return "FastTimeBarrel";
148  else if (m_Type == 2) return "FastTimeEndcap";
149  else return "Unknown";
150 }
151 
152 unsigned int FastTimeGeometry::indexFor(const DetId& id) const {
153  unsigned int cellIndex = m_cellVec.size();
154  if (id != DetId()) {
155  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
156  cellIndex = topology().detId2denseGeomId(geoId);
157 #ifdef EDM_ML_DEBUG
158  std::cout << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId()
159  << std::dec << " index " << cellIndex << std::endl;
160 #endif
161  }
162  return cellIndex;
163 }
164 
166  return topology().totalGeomModules();
167 }
168 
170  // Modify the RawPtr class
171  const CaloCellGeometry* cell(&m_cellVec[index]);
172  return (m_cellVec.size() < index ||
173  nullptr == cell->param() ? nullptr : cell);
174 }
175 
176 std::shared_ptr<const CaloCellGeometry> FastTimeGeometry::cellGeomPtr(uint32_t index) const {
177  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
178  return nullptr;
179  static const auto do_not_delete = [](const void*){};
180  auto cell = std::shared_ptr<const CaloCellGeometry>(&m_cellVec[index],do_not_delete);
181  if (nullptr == cell->param()) return nullptr;
182  return cell;
183 }
184 
185 std::shared_ptr<const CaloCellGeometry> FastTimeGeometry::cellGeomPtr(uint32_t index, const GlobalPoint& pos) const {
186  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
187  return nullptr;
188  if (pos == GlobalPoint()) return cellGeomPtr(index);
189  auto cell = std::make_shared<FlatTrd>(m_cellVec[index]);
190  cell->setPosition(pos);
191 #ifdef EDM_ML_DEBUG
192 //std::cout << "cellGeomPtr " << newcell << ":" << cell << std::endl;
193 #endif
194  if (nullptr == cell->param()) return nullptr;
195  return cell;
196 }
197 
199  edm::LogError("FastTimeGeom") << "FastTimeGeometry::addValidID is not implemented";
200 }
201 
202 
203 // FIXME: Change sorting algorithm if needed
204 namespace {
205  struct rawIdSort {
206  bool operator()( const DetId& a, const DetId& b ) {
207  return( a.rawId() < b.rawId());
208  }
209  };
210 }
211 
213  m_validIds.shrink_to_fit();
214  std::sort( m_validIds.begin(), m_validIds.end(), rawIdSort());
215 }
216 
220  CaloSubdetectorGeometry::IVec& dinsVector ) const {
221 
222  unsigned int numberOfCells = topology().totalGeomModules(); // total Geom Modules both sides
225 
226  trVector.reserve( numberOfCells * numberOfTransformParms());
227  iVector.reserve( numberOfCells );
228  dimVector.reserve( numberOfShapes * numberOfParametersPerShape );
229  dinsVector.reserve( numberOfCells );
230 
231  for (unsigned int k=0; k <topology().totalGeomModules(); ++k) {
233  params[0] = topology().dddConstants().getZHalf(m_Type);
234  params[1] = params[2] = 0;
235  params[3] = params[7] = topology().dddConstants().getRin(m_Type);
236  params[4] = params[8] = topology().dddConstants().getRout(m_Type);
237  params[5] = params[9] = topology().dddConstants().getRout(m_Type);
238  params[6] = params[10]= 0;
239  params[11]= (k == 0) ? 1.0 : -1.0;
240  dimVector.insert( dimVector.end(), params.begin(), params.end());
241  }
242 
243  for (unsigned int i( 0 ); i < numberOfCells; ++i) {
244  DetId detId = m_validGeomIds[i];
245  dinsVector.emplace_back( topology().detId2denseGeomId( detId ));
246  iVector.emplace_back(1);
247 
248  Tr3D tr;
249  auto ptr( cellGeomPtr( i ));
250  if ( nullptr != ptr ) {
251  ptr->getTransform( tr, ( Pt3DVec* ) nullptr );
252 
253  if( Tr3D() == tr ) { // there is no rotation
254  const GlobalPoint& gp( ptr->getPosition());
255  tr = HepGeom::Translate3D( gp.x(), gp.y(), gp.z());
256  }
257 
258  const CLHEP::Hep3Vector tt( tr.getTranslation());
259  trVector.emplace_back( tt.x());
260  trVector.emplace_back( tt.y());
261  trVector.emplace_back( tt.z());
262  if (6 == numberOfTransformParms()) {
263  const CLHEP::HepRotation rr( tr.getRotation());
264  const ROOT::Math::Transform3D rtr( rr.xx(), rr.xy(), rr.xz(), tt.x(),
265  rr.yx(), rr.yy(), rr.yz(), tt.y(),
266  rr.zx(), rr.zy(), rr.zz(), tt.z());
268  rtr.GetRotation( ea );
269  trVector.emplace_back( ea.Phi());
270  trVector.emplace_back( ea.Theta());
271  trVector.emplace_back( ea.Psi());
272  }
273  }
274  }
275 }
276 
278 
void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
std::set< DetId > DetIdSet
DecodedDetId decode(const DetId &id) const
int ieta() const
get the absolute value of the cell #&#39;s along x-axis (EC) | z-axis (Barel)
Definition: FastTimeDetId.h:42
A base class to handle the particular shape of HGCal volumes.
Definition: FlatTrd.h:19
std::vector< CCGFloat > DimVec
unsigned int totalGeomModules() const
T perp() const
Definition: PV3DBase.h:72
virtual unsigned int numberOfParametersPerShape() const
std::pair< int, int > getEtaPhi(double r, double phi) const
DetId getClosestCell(const GlobalPoint &r) const override
std::vector< GlobalPoint > CornersVec
CaloCellGeometry::Pt3DVec Pt3DVec
void getSummary(CaloSubdetectorGeometry::TrVec &trVector, CaloSubdetectorGeometry::IVec &iVector, CaloSubdetectorGeometry::DimVec &dimVector, CaloSubdetectorGeometry::IVec &dinsVector) const override
int numberEtaZ(int type) const
FastTimeDetId geometryCell() const
Definition: FastTimeDetId.h:33
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< unsigned int > IVec
virtual void fillNamedParams(DDFilteredView fv)
const FastTimeTopology & topology() const
T y() const
Definition: PV3DBase.h:63
void addValidID(const DetId &id)
std::vector< float > ParmVec
std::vector< CCGFloat > TrVec
HepGeom::Transform3D Tr3D
int zside(DetId const &)
int iphi() const
get the absolute value of the cell #&#39;s along y-axis (EC) | phi (Barrel)
Definition: FastTimeDetId.h:46
int numberPhi(int type) const
int zside() const
get the z-side of the cell (1/-1)
Definition: FastTimeDetId.h:49
GlobalPoint getPosition(const DetId &id) const
CaloCellGeometry::CCGFloat CCGFloat
CaloCellGeometry::Pt3D Pt3D
FastTimeGeometry(const FastTimeTopology &topology)
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
std::pair< int, int > getZPhi(double z, double phi) const
CaloCellGeometry::Tr3D Tr3D
const CCGFloat * param() const
DetIdSet getCells(const GlobalPoint &r, double dR) const override
Get a list of all cells within a dR of the given cell.
~FastTimeGeometry() override
virtual unsigned int numberOfShapes() const
virtual uint32_t detId2denseGeomId(const DetId &id) const
std::string cellElement() const
std::vector< DetId > m_validIds
T z() const
Definition: PV3DBase.h:64
def pv(vc)
Definition: MetAnalyzer.py:6
bool present(const DetId &id) const override
is this detid present in the geometry?
std::vector< GlobalPoint > getCorners(int type, int izeta, int iphi, int zside) const
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: FlatTrd.cc:162
int k[5][pyjets_maxn]
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
Definition: DetId.h:18
AlgebraicVector EulerAngles
Definition: Definitions.h:36
unsigned int indexFor(const DetId &id) const override
void initializeParms() override
CaloCellGeometry::CornersMgr * cornersMgr()
double b
Definition: hdecay.h:120
double getRin(int type) const
void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId) override
CaloCellGeometry::Tr3D Tr3D
double getRout(int type) const
DetId encode(const DecodedDetId &id_) const
double a
Definition: hdecay.h:121
GlobalPoint getPosition(int type, int izeta, int iphi, int zside) const
double getZHalf(int type) const
std::shared_ptr< const CaloCellGeometry > cellGeomPtr(uint32_t index) const override
const CaloCellGeometry * getGeometryRawPtr(uint32_t index) const override
virtual unsigned int numberOfTransformParms() const
T x() const
Definition: PV3DBase.h:62
const FastTimeDDDConstants & dddConstants() const
std::vector< DetId > m_validGeomIds
unsigned int sizeForDenseIndex() const
CornersVec getCorners(const DetId &id) const
Returns the corner points of this cell&#39;s volume.