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::Tr3D
HepGeom::Transform3D Tr3D
Definition: CaloCellGeometry.h:53
CaloCellGeometry::Pt3DVec
std::vector< Pt3D > Pt3DVec
Definition: CaloCellGeometry.h:55
CaloGenericDetId.h
CaloSubdetectorGeometry::numberOfParametersPerShape
virtual unsigned int numberOfParametersPerShape() const
Definition: CaloSubdetectorGeometry.h:93
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
CaloSubdetectorGeometry::m_cmgr
CaloCellGeometry::CornersMgr * m_cmgr
Definition: CaloSubdetectorGeometry.h:120
CaloGenericDetId
Definition: CaloGenericDetId.h:12
CaloSubdetectorGeometry::DetIdSet
std::set< DetId > DetIdSet
Definition: CaloSubdetectorGeometry.h:27
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
CaloCellGeometry::k_cornerSize
static constexpr unsigned int k_cornerSize
Definition: CaloCellGeometry.h:64
CaloSubdetectorGeometry::DimVec
std::vector< CCGFloat > DimVec
Definition: CaloSubdetectorGeometry.h:35
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
pos
Definition: PixelAliasList.h:18
CaloSubdetectorGeometry::TrVec
std::vector< CCGFloat > TrVec
Definition: CaloSubdetectorGeometry.h:33
cells
const caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple cms::cuda::AtomicPairCounter const GPUCACell *__restrict__ cells
Definition: CAHitNtupletGeneratorKernelsImpl.h:43
cms::cuda::assert
assert(be >=bs)
CaloSubdetectorGeometry::numberOfTransformParms
virtual unsigned int numberOfTransformParms() const
Definition: CaloSubdetectorGeometry.h:94
CaloSubdetectorGeometry::IVec
std::vector< unsigned int > IVec
Definition: CaloSubdetectorGeometry.h:34
CaloSubdetectorGeometry::allocatePar
void allocatePar(ParVec::size_type n, unsigned int m)
Definition: CaloSubdetectorGeometry.cc:113
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
Pt3D
CaloCellGeometry::Pt3D Pt3D
Definition: CaloSubdetectorGeometry.cc:9
CaloSubdetectorGeometry::numberOfShapes
virtual unsigned int numberOfShapes() const
Definition: CaloSubdetectorGeometry.h:92
EZArrayFL< GlobalPoint >::size_type
MgrType::size_type size_type
Definition: EZArrayFL.h:27
DetId
Definition: DetId.h:17
CaloSubdetectorGeometry::CCGFloat
CaloCellGeometry::CCGFloat CCGFloat
Definition: CaloSubdetectorGeometry.h:25
CaloSubdetectorGeometry::getCells
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
Definition: CaloSubdetectorGeometry.cc:66
CaloSubdetectorGeometry::deltaPhi
CCGFloat deltaPhi(const DetId &detId) const
Definition: CaloSubdetectorGeometry.cc:180
PVValHelper::eta
Definition: PVValidationHelpers.h:70
CaloSubdetectorGeometry::CellSet
std::vector< std::shared_ptr< const CaloCellGeometry > > CellSet
Definition: CaloSubdetectorGeometry.h:24
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
CaloSubdetectorGeometry::m_validIds
std::vector< DetId > m_validIds
Definition: CaloSubdetectorGeometry.h:115
CaloSubdetectorGeometry::m_deltaPhi
std::atomic< std::vector< CCGFloat > * > m_deltaPhi
Definition: CaloSubdetectorGeometry.h:125
Tr3D
CaloCellGeometry::Tr3D Tr3D
Definition: CaloCellGeometry.cc:7
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< float, GlobalTag >
CaloGenericDetId::sizeForDenseIndexing
uint32_t sizeForDenseIndexing() const
Definition: CaloGenericDetId.cc:40
CaloCellGeometry::Pt3D
HepGeom::Point3D< CCGFloat > Pt3D
Definition: CaloCellGeometry.h:54
CaloSubdetectorGeometry::getValidDetIds
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)
Definition: CaloSubdetectorGeometry.cc:32
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
CaloSubdetectorGeometry.h
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CaloSubdetectorGeometry::present
virtual bool present(const DetId &id) const
is this detid present in the geometry?
Definition: CaloSubdetectorGeometry.cc:40
CaloCellGeometry::CornersMgr
EZMgrFL< GlobalPoint > CornersMgr
Definition: CaloCellGeometry.h:58
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
CaloSubdetectorGeometry::addValidID
void addValidID(const DetId &id)
Definition: CaloSubdetectorGeometry.cc:27
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
CaloSubdetectorGeometry::m_parMgr
ParMgr * m_parMgr
Definition: CaloSubdetectorGeometry.h:118
DetId::Detector
Detector
Definition: DetId.h:24
CaloSubdetectorGeometry::getGeometry
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.
Definition: CaloSubdetectorGeometry.cc:36
CaloSubdetectorGeometry::getClosestCell
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: CaloSubdetectorGeometry.cc:44
CaloSubdetectorGeometry::CaloSubdetectorGeometry
CaloSubdetectorGeometry()
Definition: CaloSubdetectorGeometry.cc:15
align::EulerAngles
AlgebraicVector EulerAngles
Definition: Definitions.h:34
CaloSubdetectorGeometry::indexFor
virtual unsigned int indexFor(const DetId &id) const
Definition: CaloSubdetectorGeometry.cc:254
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Pt3DVec
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: CaloSubdetectorGeometry.cc:10
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
DDAxes::phi
CaloSubdetectorGeometry::~CaloSubdetectorGeometry
virtual ~CaloSubdetectorGeometry()
The base class DOES assume that it owns the CaloCellGeometry objects.
Definition: CaloSubdetectorGeometry.cc:18
CaloSubdetectorGeometry::getSummary
virtual void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector, IVec &dinsVector) const
Definition: CaloSubdetectorGeometry.cc:118
CaloGenericDetId::denseIndex
uint32_t denseIndex() const
Definition: CaloGenericDetId.cc:24
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Tr3D
CaloCellGeometry::Tr3D Tr3D
Definition: CaloSubdetectorGeometry.cc:11
CaloSubdetectorGeometry::ParMgr
CaloCellGeometry::ParMgr ParMgr
Definition: CaloSubdetectorGeometry.h:29
CaloSubdetectorGeometry::getCellSet
virtual CellSet getCellSet(const GlobalPoint &r, double dR) const
Definition: CaloSubdetectorGeometry.cc:96
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
Pt3DVec
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: CaloCellGeometry.cc:6
CaloSubdetectorGeometry::getGeometryRawPtr
virtual const CaloCellGeometry * getGeometryRawPtr(uint32_t index) const =0
CaloSubdetectorGeometry::deltaEta
CCGFloat deltaEta(const DetId &detId) const
Definition: CaloSubdetectorGeometry.cc:220
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
CaloSubdetectorGeometry::allocateCorners
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
Definition: CaloSubdetectorGeometry.cc:106
CaloSubdetectorGeometry::parVecVec
ParVecVec & parVecVec()
Definition: CaloSubdetectorGeometry.h:89
CaloSubdetectorGeometry::cellGeomPtr
virtual std::shared_ptr< const CaloCellGeometry > cellGeomPtr(uint32_t index) const
Definition: CaloSubdetectorGeometry.cc:260
CaloSubdetectorGeometry::m_deltaEta
std::atomic< std::vector< CCGFloat > * > m_deltaEta
Definition: CaloSubdetectorGeometry.h:126
CaloSubdetectorGeometry::sizeForDenseIndex
virtual unsigned int sizeForDenseIndex(const DetId &id) const
Definition: CaloSubdetectorGeometry.cc:256
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
CCGFloat
CaloSubdetectorGeometry::CCGFloat CCGFloat
Definition: CaloSubdetectorGeometry.cc:13