CMS 3D CMS Logo

CaloSubdetectorGeometry.cc
Go to the documentation of this file.
3 
4 #include <Math/Transform3D.h>
5 #include <Math/EulerAngles.h>
6 
7 #include <algorithm>
8 
12 
14 
16  : m_parMgr(nullptr), m_cmgr(nullptr), m_deltaPhi(nullptr), m_deltaEta(nullptr) {}
17 
19  delete m_cmgr;
20  delete m_parMgr;
21  if (m_deltaPhi)
22  delete m_deltaPhi.load();
23  if (m_deltaEta)
24  delete m_deltaEta.load();
25 }
26 
28  auto pos = std::lower_bound(m_validIds.begin(), m_validIds.end(), id);
29  m_validIds.insert(pos, id);
30 }
31 
32 const std::vector<DetId>& CaloSubdetectorGeometry::getValidDetIds(DetId::Detector /*det*/, int /*subdet*/) const {
33  return m_validIds;
34 }
35 
36 std::shared_ptr<const CaloCellGeometry> CaloSubdetectorGeometry::getGeometry(const DetId& id) const {
37  return cellGeomPtr(CaloGenericDetId(id).denseIndex());
38 }
39 
40 bool CaloSubdetectorGeometry::present(const DetId& id) const {
41  return std::find(m_validIds.begin(), m_validIds.end(), id) != m_validIds.end();
42 }
43 
45  const CCGFloat eta(r.eta());
46  const CCGFloat phi(r.phi());
47  uint32_t index(~0);
48  CCGFloat closest(1e9);
49 
50  for (uint32_t i(0); i != m_validIds.size(); ++i) {
51  std::shared_ptr<const CaloCellGeometry> cell(getGeometry(m_validIds[i]));
52  if (nullptr != cell) {
53  const GlobalPoint& p(cell->getPosition());
54  const CCGFloat eta0(p.eta());
55  const CCGFloat phi0(p.phi());
56  const CCGFloat dR2(reco::deltaR2(eta0, phi0, eta, phi));
57  if (dR2 < closest) {
58  closest = dR2;
59  index = i;
60  }
61  }
62  }
63  return (closest > 0.9e9 || (uint32_t)(~0) == index ? DetId(0) : m_validIds[index]);
64 }
65 
67  const double dR2(dR * dR);
68  const double eta(r.eta());
69  const double phi(r.phi());
70 
71  DetIdSet dss;
72 
73  if (0.000001 < dR) {
74  for (uint32_t i(0); i != m_validIds.size(); ++i) {
75  std::shared_ptr<const CaloCellGeometry> cell(getGeometry(m_validIds[i]));
76  if (nullptr != cell) {
77  const GlobalPoint& p(cell->getPosition());
78  const CCGFloat eta0(p.eta());
79  if (fabs(eta - eta0) < dR) {
80  const CCGFloat phi0(p.phi());
81  CCGFloat delp(fabs(phi - phi0));
82  if (delp > M_PI)
83  delp = 2 * M_PI - delp;
84  if (delp < dR) {
85  const CCGFloat dist2(reco::deltaR2(eta0, phi0, eta, phi));
86  if (dist2 < dR2)
87  dss.insert(m_validIds[i]);
88  }
89  }
90  }
91  }
92  }
93  return dss;
94 }
95 
97  // stupid implementation not to be really used...
98  DetIdSet ids = getCells(r, dR);
99  CellSet cells;
100  cells.reserve(ids.size());
101  for (auto id : ids)
102  cells.emplace_back(getGeometry(id));
103  return cells;
104 }
105 
107  assert(nullptr == m_cmgr);
109 
110  m_validIds.reserve(n);
111 }
112 
114  assert(nullptr == m_parMgr);
115  m_parMgr = new ParMgr(n * m, m);
116 }
117 
121  CaloSubdetectorGeometry::IVec& /*dins*/) const {
122  tVec.reserve(m_validIds.size() * numberOfTransformParms());
123  iVec.reserve(numberOfShapes() == 1 ? 1 : m_validIds.size());
124  dVec.reserve(numberOfShapes() * numberOfParametersPerShape());
125 
126  for (const auto& pv : parVecVec()) {
127  for (float iv : pv) {
128  dVec.emplace_back(iv);
129  }
130  }
131 
132  for (uint32_t i(0); i != m_validIds.size(); ++i) {
133  Tr3D tr;
134  std::shared_ptr<const CaloCellGeometry> ptr(cellGeomPtr(i));
135  assert(nullptr != ptr);
136  ptr->getTransform(tr, (Pt3DVec*)nullptr);
137 
138  if (Tr3D() == tr) { // for preshower there is no rotation
139  const GlobalPoint& gp(ptr->getPosition());
140  tr = HepGeom::Translate3D(gp.x(), gp.y(), gp.z());
141  }
142 
143  const CLHEP::Hep3Vector tt(tr.getTranslation());
144  tVec.emplace_back(tt.x());
145  tVec.emplace_back(tt.y());
146  tVec.emplace_back(tt.z());
147  if (6 == numberOfTransformParms()) {
148  const CLHEP::HepRotation rr(tr.getRotation());
149  const ROOT::Math::Transform3D rtr(
150  rr.xx(), rr.xy(), rr.xz(), tt.x(), rr.yx(), rr.yy(), rr.yz(), tt.y(), rr.zx(), rr.zy(), rr.zz(), tt.z());
152  rtr.GetRotation(ea);
153  tVec.emplace_back(ea.Phi());
154  tVec.emplace_back(ea.Theta());
155  tVec.emplace_back(ea.Psi());
156  }
157 
158  const CCGFloat* par(ptr->param());
159 
160  unsigned int ishape(9999);
161  for (unsigned int ivv(0); ivv != parVecVec().size(); ++ivv) {
162  bool ok(true);
163  const CCGFloat* pv(&(*parVecVec()[ivv].begin()));
164  for (unsigned int k(0); k != numberOfParametersPerShape(); ++k) {
165  ok = ok && (fabs(par[k] - pv[k]) < 1.e-6);
166  }
167  if (ok) {
168  ishape = ivv;
169  break;
170  }
171  }
172  assert(9999 != ishape);
173 
174  const unsigned int nn((numberOfShapes() == 1) ? (unsigned int)1 : m_validIds.size());
175  if (iVec.size() < nn)
176  iVec.emplace_back(ishape);
177  }
178 }
179 
181  const CaloGenericDetId cgId(detId);
182 
183  if (!m_deltaPhi.load(std::memory_order_acquire)) {
184  const uint32_t kSize(sizeForDenseIndex(detId));
185  auto ptr = new std::vector<CCGFloat>(kSize);
186  for (uint32_t i(0); i != kSize; ++i) {
187  std::shared_ptr<const CaloCellGeometry> cellPtr(cellGeomPtr(i));
188  if (nullptr != cellPtr) {
189  CCGFloat dPhi1(fabs(GlobalPoint((cellPtr->getCorners()[0].x() + cellPtr->getCorners()[1].x()) / 2.,
190  (cellPtr->getCorners()[0].y() + cellPtr->getCorners()[1].y()) / 2.,
191  (cellPtr->getCorners()[0].z() + cellPtr->getCorners()[1].z()) / 2.)
192  .phi() -
193  GlobalPoint((cellPtr->getCorners()[2].x() + cellPtr->getCorners()[3].x()) / 2.,
194  (cellPtr->getCorners()[2].y() + cellPtr->getCorners()[3].y()) / 2.,
195  (cellPtr->getCorners()[2].z() + cellPtr->getCorners()[3].z()) / 2.)
196  .phi()));
197  CCGFloat dPhi2(fabs(GlobalPoint((cellPtr->getCorners()[0].x() + cellPtr->getCorners()[3].x()) / 2.,
198  (cellPtr->getCorners()[0].y() + cellPtr->getCorners()[3].y()) / 2.,
199  (cellPtr->getCorners()[0].z() + cellPtr->getCorners()[3].z()) / 2.)
200  .phi() -
201  GlobalPoint((cellPtr->getCorners()[2].x() + cellPtr->getCorners()[1].x()) / 2.,
202  (cellPtr->getCorners()[2].y() + cellPtr->getCorners()[1].y()) / 2.,
203  (cellPtr->getCorners()[2].z() + cellPtr->getCorners()[1].z()) / 2.)
204  .phi()));
205  if (M_PI < dPhi1)
206  dPhi1 = fabs(dPhi1 - 2. * M_PI);
207  if (M_PI < dPhi2)
208  dPhi2 = fabs(dPhi2 - 2. * M_PI);
209  (*ptr)[i] = dPhi1 > dPhi2 ? dPhi1 : dPhi2;
210  }
211  }
212  std::vector<CCGFloat>* expect = nullptr;
213  bool exchanged = m_deltaPhi.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
214  if (!exchanged)
215  delete ptr;
216  }
217  return (*m_deltaPhi.load(std::memory_order_acquire))[indexFor(detId)];
218 }
219 
221  if (!m_deltaEta.load(std::memory_order_acquire)) {
222  const uint32_t kSize(sizeForDenseIndex(detId));
223  auto ptr = new std::vector<CCGFloat>(kSize);
224  for (uint32_t i(0); i != kSize; ++i) {
225  std::shared_ptr<const CaloCellGeometry> cellPtr(cellGeomPtr(i));
226  if (nullptr != cellPtr) {
227  const CCGFloat dEta1(fabs(GlobalPoint((cellPtr->getCorners()[0].x() + cellPtr->getCorners()[1].x()) / 2.,
228  (cellPtr->getCorners()[0].y() + cellPtr->getCorners()[1].y()) / 2.,
229  (cellPtr->getCorners()[0].z() + cellPtr->getCorners()[1].z()) / 2.)
230  .eta() -
231  GlobalPoint((cellPtr->getCorners()[2].x() + cellPtr->getCorners()[3].x()) / 2.,
232  (cellPtr->getCorners()[2].y() + cellPtr->getCorners()[3].y()) / 2.,
233  (cellPtr->getCorners()[2].z() + cellPtr->getCorners()[3].z()) / 2.)
234  .eta()));
235  const CCGFloat dEta2(fabs(GlobalPoint((cellPtr->getCorners()[0].x() + cellPtr->getCorners()[3].x()) / 2.,
236  (cellPtr->getCorners()[0].y() + cellPtr->getCorners()[3].y()) / 2.,
237  (cellPtr->getCorners()[0].z() + cellPtr->getCorners()[3].z()) / 2.)
238  .eta() -
239  GlobalPoint((cellPtr->getCorners()[2].x() + cellPtr->getCorners()[1].x()) / 2.,
240  (cellPtr->getCorners()[2].y() + cellPtr->getCorners()[1].y()) / 2.,
241  (cellPtr->getCorners()[2].z() + cellPtr->getCorners()[1].z()) / 2.)
242  .eta()));
243  (*ptr)[i] = dEta1 > dEta2 ? dEta1 : dEta2;
244  }
245  }
246  std::vector<CCGFloat>* expect = nullptr;
247  bool exchanged = m_deltaEta.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
248  if (!exchanged)
249  delete ptr;
250  }
251  return (*m_deltaEta.load(std::memory_order_acquire))[indexFor(detId)];
252 }
253 
254 unsigned int CaloSubdetectorGeometry::indexFor(const DetId& id) const { return CaloGenericDetId(id).denseIndex(); }
255 
256 unsigned int CaloSubdetectorGeometry::sizeForDenseIndex(const DetId& id) const {
258 }
259 
260 std::shared_ptr<const CaloCellGeometry> CaloSubdetectorGeometry::cellGeomPtr(uint32_t index) const {
261  // Default version
262  auto ptr = getGeometryRawPtr(index);
263  static const auto do_not_delete = [](const void*) {};
264  return ptr == nullptr ? nullptr : std::shared_ptr<const CaloCellGeometry>(ptr, do_not_delete);
265 }
CaloCellGeometry::CornersMgr * m_cmgr
std::vector< CCGFloat > DimVec
int32_t *__restrict__ iv
virtual unsigned int numberOfTransformParms() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
int closest(std::vector< int > const &vec, int value)
T eta() const
Definition: PV3DBase.h:73
MgrType::size_type size_type
Definition: EZArrayFL.h:27
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< unsigned int > IVec
uint32_t denseIndex() const
std::vector< CCGFloat > TrVec
CaloCellGeometry::Tr3D Tr3D
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Transform3D Tr3D
virtual unsigned int numberOfShapes() const
std::vector< Pt3D > Pt3DVec
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
EZMgrFL< GlobalPoint > CornersMgr
CaloCellGeometry::CCGFloat CCGFloat
void allocatePar(ParVec::size_type n, unsigned int m)
CCGFloat deltaPhi(const DetId &detId) const
std::vector< std::shared_ptr< const CaloCellGeometry > > CellSet
static constexpr unsigned int k_cornerSize
Definition: TTTypes.h:54
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
std::vector< DetId > m_validIds
std::atomic< std::vector< CCGFloat > * > m_deltaPhi
virtual bool present(const DetId &id) const
is this detid present in the geometry?
def pv(vc)
Definition: MetAnalyzer.py:7
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
CaloSubdetectorGeometry::CCGFloat CCGFloat
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
virtual DetId getClosestCell(const GlobalPoint &r) const
#define M_PI
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
Definition: DetId.h:17
AlgebraicVector EulerAngles
Definition: Definitions.h:34
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void addValidID(const DetId &id)
virtual void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector, IVec &dinsVector) const
Detector
Definition: DetId.h:24
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
virtual unsigned int indexFor(const DetId &id) const
CaloCellGeometry::Pt3D Pt3D
CaloCellGeometry::ParMgr ParMgr
CaloCellGeometry::Tr3D Tr3D
virtual ~CaloSubdetectorGeometry()
The base class DOES assume that it owns the CaloCellGeometry objects.
virtual CellSet getCellSet(const GlobalPoint &r, double dR) const
virtual const CaloCellGeometry * getGeometryRawPtr(uint32_t index) const =0
CCGFloat deltaEta(const DetId &detId) const
uint32_t sizeForDenseIndexing() const
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
virtual std::shared_ptr< const CaloCellGeometry > cellGeomPtr(uint32_t index) const
std::atomic< std::vector< CCGFloat > * > m_deltaEta
virtual unsigned int numberOfParametersPerShape() const
virtual unsigned int sizeForDenseIndex(const DetId &id) const