18 #include <Math/Transform3D.h>
19 #include <Math/EulerAngles.h>
27 : m_topology(topology_),
28 m_validGeomIds(topology_.totalGeomModules()),
29 mode_(topology_.geomMode()),
31 m_subdet(topology_.subDetector()),
32 twoBysqrt3_(2.0 /
std::
sqrt(3.0)) {
95 for (
int cell = 0; cell <
cells; ++cell) {
118 unsigned int cellAll(0), cellSelect(0);
120 for (
int u = 0; u < 2 *
cells; ++u) {
121 for (
int v = 0;
v < 2 *
cells; ++
v) {
140 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalGeometry keeps " << cellSelect <<
" out of " << cellAll <<
" for wafer "
141 <<
id.iSec1 <<
":" <<
id.iSec2 <<
" in "
142 <<
" layer " <<
id.iLay;
147 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalGeometry::newCell-> [" << cellIndex <<
"]"
148 <<
" front:" <<
f1.x() <<
'/' <<
f1.y() <<
'/' <<
f1.z() <<
" back:" <<
f2.x() <<
'/'
149 <<
f2.y() <<
'/' <<
f2.z() <<
" eta|phi " <<
m_cellVec2[cellIndex].etaPos() <<
":"
152 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalGeometry::newCell-> [" << cellIndex <<
"]"
153 <<
" front:" <<
f1.x() <<
'/' <<
f1.y() <<
'/' <<
f1.z() <<
" back:" <<
f2.x() <<
'/'
154 <<
f2.y() <<
'/' <<
f2.z() <<
" eta|phi " <<
m_cellVec[cellIndex].etaPos() <<
":"
176 if (detId ==
DetId())
185 if (detId ==
DetId())
193 unsigned int cellIndex =
indexFor(detid);
198 std::pair<float, float>
xy;
201 const HepGeom::Point3D<float> lcoord(
xy.first,
xy.second, 0);
202 glob =
m_cellVec[cellIndex].getPosition(lcoord);
204 edm::LogVerbatim(
"HGCalGeom") <<
"getPosition:: index " << cellIndex <<
" Local " << lcoord.x() <<
":"
205 << lcoord.y() <<
" ID " <<
id.iCell1 <<
":" <<
id.iSec1 <<
" Global " << glob;
208 const HepGeom::Point3D<float> lcoord(0, 0, 0);
209 glob =
m_cellVec2[cellIndex].getPosition(lcoord);
211 edm::LogVerbatim(
"HGCalGeom") <<
"getPositionTrap:: index " << cellIndex <<
" Local " << lcoord.x() <<
":"
212 << lcoord.y() <<
" ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iCell1
213 <<
" Global " << glob;
217 const HepGeom::Point3D<float> lcoord(
xy.first,
xy.second, 0);
218 glob =
m_cellVec[cellIndex].getPosition(lcoord);
220 edm::LogVerbatim(
"HGCalGeom") <<
"getPositionWafer:: index " << cellIndex <<
" Local " << lcoord.x() <<
":"
221 << lcoord.y() <<
" ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":"
222 <<
id.iCell1 <<
":" <<
id.iCell2 <<
" Global " << glob;
230 unsigned int cellIndex =
indexFor(detid);
234 const HepGeom::Point3D<float> lcoord(0, 0, 0);
236 glob =
m_cellVec2[cellIndex].getPosition(lcoord);
238 glob =
m_cellVec[cellIndex].getPosition(lcoord);
242 << cellIndex <<
" Global " << glob;
251 if (corners.size() > 1) {
252 int n = corners.size() - 1;
254 for (
int i = 0;
i <
n; ++
i) {
255 area += ((corners[
j].x() + corners[
i].x()) * (corners[
i].
y() - corners[
j].y()));
265 unsigned int cellIndex =
indexFor(detid);
275 static const int signr[] = {1, 1, -1, -1, 1, 1, -1, -1};
276 static const int signf[] = {-1, 1, 1, -1, -1, 1, 1, -1};
277 static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
278 for (
unsigned int i = 0;
i < ncorner; ++
i) {
280 (
r + signr[
i] *
dr) *
sin(fi + signf[
i] * dfi),
281 (
v.z() + signz[
i] *
dz));
284 std::pair<float, float>
xy;
290 static const int signx[] = {0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1};
291 static const int signy[] = {-2, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1};
292 static const int signz[] = {-1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1};
293 for (
unsigned int i = 0;
i < ncorner; ++
i) {
294 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dy, signz[
i] *
dz);
302 static const int signx[] = {1, -1, -2, -1, 1, 2, 1, -1, -2, -1, 1, 2};
303 static const int signy[] = {1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0};
304 static const int signz[] = {-1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1};
305 for (
unsigned int i = 0;
i < ncorner; ++
i) {
306 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dy, signz[
i] *
dz);
317 unsigned int cellIndex =
indexFor(detid);
327 static const int signr[] = {1, 1, -1, -1, 1, 1, -1, -1};
328 static const int signf[] = {-1, 1, 1, -1, -1, 1, 1, -1};
329 static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
330 for (
unsigned int i = 0;
i < ncorner; ++
i) {
332 (
r + signr[
i] *
dr) *
sin(fi + signf[
i] * dfi),
333 (
v.z() + signz[
i] *
dz));
336 std::pair<float, float>
xy;
345 static const int signx[] = {-1, -1, 1, 1, -1, -1, 1, 1};
346 static const int signy[] = {-1, 1, 1, -1, -1, 1, 1, -1};
347 static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
349 for (
unsigned int i = 0;
i < ncorner; ++
i) {
350 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dx, signz[
i] *
dz);
360 unsigned int cellIndex =
indexFor(detid);
370 static const int signr[] = {1, 1, -1, -1};
371 static const int signf[] = {-1, 1, 1, -1};
372 for (
unsigned int i = 0;
i < ncorner - 1; ++
i) {
374 (
r + signr[
i] *
dr) *
cos(fi + signf[
i] * dfi), (
r + signr[
i] *
dr) *
sin(fi + signf[
i] * dfi), (
v.z() +
dz));
378 std::pair<float, float>
xy;
387 static const int signx[] = {1, -1, -2, -1, 1, 2};
388 static const int signy[] = {1, 1, 0, -1, -1, 0};
389 for (
unsigned int i = 0;
i < ncorner - 1; ++
i) {
390 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dy,
dz);
401 int lay = ((momentum.
z() *
id.zSide > 0) ? (
id.iLay + 1) : (
id.iLay - 1));
403 edm::LogVerbatim(
"HGCalGeom") <<
"neighborz1:: ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":"
404 <<
id.iCell1 <<
":" <<
id.iCell2 <<
" New Layer " << lay <<
" Range "
409 (momentum.
z() != 0.0)) {
412 double grad = (
z -
v.z()) / momentum.
z();
416 if (
r >= rlimit.first &&
r <= rlimit.second)
419 edm::LogVerbatim(
"HGCalGeom") <<
"neighborz1:: Position " <<
v <<
" New Z " <<
z <<
":" << grad <<
" new position "
420 <<
p <<
" r-limit " << rlimit.first <<
":" << rlimit.second;
432 int lay = ((momentum.
z() *
id.zSide > 0) ? (
id.iLay + 1) : (
id.iLay - 1));
434 edm::LogVerbatim(
"HGCalGeom") <<
"neighborz2:: ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":"
435 <<
id.iCell1 <<
":" <<
id.iCell2 <<
" New Layer " << lay <<
" Range "
440 (momentum.
z() != 0.0)) {
452 if (
r >= rlimit.first &&
r <= rlimit.second)
457 << tsos.
isValid() <<
" new position " <<
p <<
" r limits " << rlimit.first <<
":"
469 HepGeom::Point3D<float>
local;
471 local = HepGeom::Point3D<float>(
r.x(),
r.y(), 0);
474 local = HepGeom::Point3D<float>(-
r.x(),
r.y(), 0);
479 id.iCell1 = kxy.second;
480 id.iSec1 = kxy.first;
500 edm::LogVerbatim(
"HGCalGeom") <<
"getClosestCell: local " <<
local <<
" Id " <<
id.zSide <<
":" <<
id.iLay <<
":"
501 <<
id.iSec1 <<
":" <<
id.iSec2 <<
":" <<
id.iType <<
":" <<
id.iCell1 <<
":"
523 return "HGCalHEFront";
525 return "HGCalHEBack";
532 if (detId !=
DetId()) {
537 <<
" index " << cellIndex;
551 return (
nullptr == cell->
param() ? nullptr : cell);
556 return (
nullptr == cell->
param() ? nullptr : cell);
564 static const auto do_not_delete = [](
const void*) {};
566 auto cell = std::shared_ptr<const CaloCellGeometry>(&
m_cellVec2[
index], do_not_delete);
567 if (
nullptr == cell->param())
571 auto cell = std::shared_ptr<const CaloCellGeometry>(&
m_cellVec[
index], do_not_delete);
572 if (
nullptr == cell->param())
586 cell->setPosition(
pos);
590 if (
nullptr == cell->param())
595 cell->setPosition(
pos);
599 if (
nullptr == cell->param())
606 edm::LogError(
"HGCalGeom") <<
"HGCalGeometry::addValidID is not implemented";
615 float phip =
r.phi();
617 float dzmin(9999), dphimin(9999), dphi10(0.175);
618 unsigned int cellIndex = vec.size();
619 for (
unsigned int k = 0;
k < vec.size(); ++
k) {
620 float dphi = phip - vec[
k].phiPos();
623 while (dphi <= -
M_PI)
627 if (
dz < (dzmin + 0.001)) {
629 if (
std::abs(dphi) < (dphimin + 0.01)) {
633 if (cellIndex >= vec.size())
640 edm::LogVerbatim(
"HGCalGeom") <<
"getClosestCellIndex::Input " << zp <<
":" << phip <<
" Index " << cellIndex;
641 if (cellIndex < vec.size())
642 edm::LogVerbatim(
"HGCalGeom") <<
" Cell z " << vec[cellIndex].getPosition().z() <<
":" << dzmin <<
" phi "
643 << vec[cellIndex].phiPos() <<
":" << dphimin;
651 bool operator()(
const DetId&
a,
const DetId&
b) {
return (
a.rawId() <
b.rawId()); }
670 iVector.reserve(numberOfCells);
672 dinsVector.reserve(numberOfCells);
676 int layer = mytr.
lay;
686 dimVector.insert(dimVector.end(),
params.begin(),
params.end());
703 dimVector.insert(dimVector.end(),
params.begin(),
params.end());
713 dimVector.insert(dimVector.end(),
params.begin(),
params.end());
719 for (
unsigned int i(0);
i < numberOfCells; ++
i) {
732 iVector.emplace_back(layer);
736 if (
nullptr != ptr) {
737 ptr->getTransform(tr, (
Pt3DVec*)
nullptr);
741 tr = HepGeom::Translate3D(
gp.x(),
gp.y(),
gp.z());
744 const CLHEP::Hep3Vector
tt(tr.getTranslation());
745 trVector.emplace_back(
tt.x());
746 trVector.emplace_back(
tt.y());
747 trVector.emplace_back(
tt.z());
749 const CLHEP::HepRotation
rr(tr.getRotation());
750 const ROOT::Math::Transform3D rtr(
751 rr.xx(),
rr.xy(),
rr.xz(),
tt.x(),
rr.yx(),
rr.yy(),
rr.yz(),
tt.y(),
rr.zx(),
rr.zy(),
rr.zz(),
tt.z());
754 trVector.emplace_back(ea.Phi());
755 trVector.emplace_back(ea.Theta());
756 trVector.emplace_back(ea.Psi());
765 geomId = static_cast<DetId>(
HGCalDetId(detId).geometryCell());
769 geomId = static_cast<DetId>(
HFNoseDetId(detId).geometryCell());