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 
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  return cellGeomPtr (cellIndex);
93 }
94 
96 
97  FastTimeDetId id_ = FastTimeDetId(id);
98  auto pos = topology().dddConstants().getPosition(m_Type,id_.ieta(),id_.iphi(),id_.zside());
99  return GlobalPoint(0.1*pos.x(),0.1*pos.y(),0.1*pos.z());
100 }
101 
103 
104  FastTimeDetId id_ = FastTimeDetId(id);
105  auto corners = topology().dddConstants().getCorners(m_Type,id_.ieta(),id_.iphi(),id_.zside());
107  for( const auto& corner : corners ) {
108  out.emplace_back(0.1*corner.x(),0.1*corner.y(),0.1*corner.z());
109  }
110  return out;
111 }
112 
114  int zside = (r.z() > 0) ? 1 : -1;
115  std::pair<int,int> etaZPhi;
116  if (m_Type == 1) {
117  double zz = (zside > 0) ? r.z() : -r.z();
118  etaZPhi = topology().dddConstants().getZPhi(zz,r.phi());
119  } else {
120  double phi = (zside > 0) ? r.phi() : atan2(r.y(),-r.x());
121  etaZPhi = topology().dddConstants().getEtaPhi(r.perp(),phi);
122  }
123  FastTimeDetId id = FastTimeDetId(m_Type,etaZPhi.first,etaZPhi.second,zside);
124 #ifdef EDM_ML_DEBUG
125  std::cout << "getClosestCell: for (" << r.x() << ", " << r.y() << ", "
126  << r.z() << ") Id " << id.type() << ":" << id.zside() << ":"
127  << id.ieta() << ":" << id.iphi() << std::endl;
128 #endif
129 
130  return (topology().valid(id) ? DetId(id) : DetId());
131 }
132 
135  return dss;
136 }
137 
139  if (m_Type == 1) return "FastTimeBarrel";
140  else if (m_Type == 2) return "FastTimeEndcap";
141  else return "Unknown";
142 }
143 
144 unsigned int FastTimeGeometry::indexFor(const DetId& id) const {
145  unsigned int cellIndex = m_cellVec.size();
146  if (id != DetId()) {
147  DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
148  cellIndex = topology().detId2denseGeomId(geoId);
149 #ifdef EDM_ML_DEBUG
150  std::cout << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId()
151  << std::dec << " index " << cellIndex << std::endl;
152 #endif
153  }
154  return cellIndex;
155 }
156 
158  return topology().totalGeomModules();
159 }
160 
162  if ((index >= m_cellVec.size()) || (m_validGeomIds[index].rawId() == 0))
163  return nullptr;
164  const CaloCellGeometry* cell ( &m_cellVec[ index ] ) ;
165 #ifdef EDM_ML_DEBUG
166  // std::cout << "cellGeomPtr " << m_cellVec[index];
167 #endif
168  if (nullptr == cell->param()) return nullptr;
169  return cell;
170 }
171 
173  edm::LogError("FastTimeGeom") << "FastTimeGeometry::addValidID is not implemented";
174 }
175 
176 
177 // FIXME: Change sorting algorithm if needed
178 namespace {
179  struct rawIdSort {
180  bool operator()( const DetId& a, const DetId& b ) {
181  return( a.rawId() < b.rawId());
182  }
183  };
184 }
185 
187  m_validIds.shrink_to_fit();
188  std::sort( m_validIds.begin(), m_validIds.end(), rawIdSort());
189 }
190 
194  CaloSubdetectorGeometry::IVec& dinsVector ) const {
195 
196  unsigned int numberOfCells = topology().totalGeomModules(); // total Geom Modules both sides
199 
200  trVector.reserve( numberOfCells * numberOfTransformParms());
201  iVector.reserve( numberOfCells );
202  dimVector.reserve( numberOfShapes * numberOfParametersPerShape );
203  dinsVector.reserve( numberOfCells );
204 
205  for (unsigned int k=0; k <topology().totalGeomModules(); ++k) {
207  params[0] = topology().dddConstants().getZHalf(m_Type);
208  params[1] = params[2] = 0;
209  params[3] = params[7] = topology().dddConstants().getRin(m_Type);
210  params[4] = params[8] = topology().dddConstants().getRout(m_Type);
211  params[5] = params[9] = topology().dddConstants().getRout(m_Type);
212  params[6] = params[10]= 0;
213  params[11]= (k == 0) ? 1.0 : -1.0;
214  dimVector.insert( dimVector.end(), params.begin(), params.end());
215  }
216 
217  for (unsigned int i( 0 ); i < numberOfCells; ++i) {
218  DetId detId = m_validGeomIds[i];
219  dinsVector.emplace_back( topology().detId2denseGeomId( detId ));
220  iVector.emplace_back(1);
221 
222  Tr3D tr;
223  const CaloCellGeometry* ptr( cellGeomPtr( i ));
224  if ( nullptr != ptr ) {
225  ptr->getTransform( tr, ( Pt3DVec* ) nullptr );
226 
227  if( Tr3D() == tr ) { // there is no rotation
228  const GlobalPoint& gp( ptr->getPosition());
229  tr = HepGeom::Translate3D( gp.x(), gp.y(), gp.z());
230  }
231 
232  const CLHEP::Hep3Vector tt( tr.getTranslation());
233  trVector.emplace_back( tt.x());
234  trVector.emplace_back( tt.y());
235  trVector.emplace_back( tt.z());
236  if (6 == numberOfTransformParms()) {
237  const CLHEP::HepRotation rr( tr.getRotation());
238  const ROOT::Math::Transform3D rtr( rr.xx(), rr.xy(), rr.xz(), tt.x(),
239  rr.yx(), rr.yy(), rr.yz(), tt.y(),
240  rr.zx(), rr.zy(), rr.zz(), tt.z());
242  rtr.GetRotation( ea );
243  trVector.emplace_back( ea.Phi());
244  trVector.emplace_back( ea.Theta());
245  trVector.emplace_back( ea.Psi());
246  }
247  }
248  }
249 }
250 
252 
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
const CaloCellGeometry * getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
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
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
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 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:43
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
virtual void getTransform(Tr3D &tr, Pt3DVec *lptr) const
--------— only needed by specific utility; overloaded when needed -—
std::string cellElement() const
std::vector< DetId > m_validIds
T z() const
Definition: PV3DBase.h:64
def pv(vc)
Definition: MetAnalyzer.py:6
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:163
int k[5][pyjets_maxn]
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
Definition: DetId.h:18
AlgebraicVector EulerAngles
Definition: Definitions.h:36
const CaloCellGeometry * cellGeomPtr(uint32_t index) const override
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
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.