18 #include <Math/Transform3D.h>
19 #include <Math/EulerAngles.h>
27 : m_topology(topology_),
28 m_validGeomIds(topology_.totalGeomModules()),
30 m_subdet(topology_.subDetector()),
31 twoBysqrt3_(2.0 /
std::
sqrt(3.0)) {
94 for (
int cell = 0; cell <
cells; ++cell) {
117 unsigned int cellAll(0), cellSelect(0);
119 for (
int u = 0; u < 2 *
cells; ++u) {
120 for (
int v = 0;
v < 2 *
cells; ++
v) {
139 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalGeometry keeps " << cellSelect <<
" out of " << cellAll <<
" for wafer "
140 <<
id.iSec1 <<
":" <<
id.iSec2 <<
" in "
141 <<
" layer " <<
id.iLay;
146 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalGeometry::newCell-> [" << cellIndex <<
"]"
147 <<
" front:" <<
f1.x() <<
'/' <<
f1.y() <<
'/' <<
f1.z() <<
" back:" <<
f2.x() <<
'/'
148 <<
f2.y() <<
'/' <<
f2.z() <<
" eta|phi " <<
m_cellVec2[cellIndex].etaPos() <<
":"
151 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalGeometry::newCell-> [" << cellIndex <<
"]"
152 <<
" front:" <<
f1.x() <<
'/' <<
f1.y() <<
'/' <<
f1.z() <<
" back:" <<
f2.x() <<
'/'
153 <<
f2.y() <<
'/' <<
f2.z() <<
" eta|phi " <<
m_cellVec[cellIndex].etaPos() <<
":"
175 if (detId ==
DetId())
184 if (detId ==
DetId())
192 unsigned int cellIndex =
indexFor(detid);
197 std::pair<float, float>
xy;
200 const HepGeom::Point3D<float> lcoord(
xy.first,
xy.second, 0);
201 glob =
m_cellVec[cellIndex].getPosition(lcoord);
203 edm::LogVerbatim(
"HGCalGeom") <<
"getPosition:: index " << cellIndex <<
" Local " << lcoord.x() <<
":"
204 << lcoord.y() <<
" ID " <<
id.iCell1 <<
":" <<
id.iSec1 <<
" Global " << glob;
207 const HepGeom::Point3D<float> lcoord(0, 0, 0);
208 glob =
m_cellVec2[cellIndex].getPosition(lcoord);
210 edm::LogVerbatim(
"HGCalGeom") <<
"getPositionTrap:: index " << cellIndex <<
" Local " << lcoord.x() <<
":"
211 << lcoord.y() <<
" ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iCell1
212 <<
" Global " << glob;
216 const HepGeom::Point3D<float> lcoord(
xy.first,
xy.second, 0);
217 glob =
m_cellVec[cellIndex].getPosition(lcoord);
219 edm::LogVerbatim(
"HGCalGeom") <<
"getPositionWafer:: index " << cellIndex <<
" Local " << lcoord.x() <<
":"
220 << lcoord.y() <<
" ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":"
221 <<
id.iCell1 <<
":" <<
id.iCell2 <<
" Global " << glob;
229 unsigned int cellIndex =
indexFor(detid);
233 const HepGeom::Point3D<float> lcoord(0, 0, 0);
235 glob =
m_cellVec2[cellIndex].getPosition(lcoord);
237 glob =
m_cellVec[cellIndex].getPosition(lcoord);
241 << cellIndex <<
" Global " << glob;
250 if (corners.size() > 1) {
251 int n = corners.size() - 1;
253 for (
int i = 0;
i <
n; ++
i) {
254 area += ((corners[
j].x() + corners[
i].x()) * (corners[
i].
y() - corners[
j].y()));
264 unsigned int cellIndex =
indexFor(detid);
274 static const int signr[] = {1, 1, -1, -1, 1, 1, -1, -1};
275 static const int signf[] = {-1, 1, 1, -1, -1, 1, 1, -1};
276 static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
277 for (
unsigned int i = 0;
i < ncorner; ++
i) {
279 (
r + signr[
i] *
dr) *
sin(fi + signf[
i] * dfi),
280 (
v.z() + signz[
i] *
dz));
283 std::pair<float, float>
xy;
289 static const int signx[] = {0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1};
290 static const int signy[] = {-2, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1};
291 static const int signz[] = {-1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1};
292 for (
unsigned int i = 0;
i < ncorner; ++
i) {
293 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dy, signz[
i] *
dz);
301 static const int signx[] = {1, -1, -2, -1, 1, 2, 1, -1, -2, -1, 1, 2};
302 static const int signy[] = {1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0};
303 static const int signz[] = {-1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1};
304 for (
unsigned int i = 0;
i < ncorner; ++
i) {
305 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dy, signz[
i] *
dz);
316 unsigned int cellIndex =
indexFor(detid);
326 static const int signr[] = {1, 1, -1, -1, 1, 1, -1, -1};
327 static const int signf[] = {-1, 1, 1, -1, -1, 1, 1, -1};
328 static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
329 for (
unsigned int i = 0;
i < ncorner; ++
i) {
331 (
r + signr[
i] *
dr) *
sin(fi + signf[
i] * dfi),
332 (
v.z() + signz[
i] *
dz));
335 std::pair<float, float>
xy;
344 static const int signx[] = {-1, -1, 1, 1, -1, -1, 1, 1};
345 static const int signy[] = {-1, 1, 1, -1, -1, 1, 1, -1};
346 static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
348 for (
unsigned int i = 0;
i < ncorner; ++
i) {
349 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dx, signz[
i] *
dz);
359 unsigned int cellIndex =
indexFor(detid);
369 static const int signr[] = {1, 1, -1, -1};
370 static const int signf[] = {-1, 1, 1, -1};
371 for (
unsigned int i = 0;
i < ncorner - 1; ++
i) {
373 (
r + signr[
i] *
dr) *
cos(fi + signf[
i] * dfi), (
r + signr[
i] *
dr) *
sin(fi + signf[
i] * dfi), (
v.z() +
dz));
377 std::pair<float, float>
xy;
386 static const int signx[] = {1, -1, -2, -1, 1, 2};
387 static const int signy[] = {1, 1, 0, -1, -1, 0};
388 for (
unsigned int i = 0;
i < ncorner - 1; ++
i) {
389 const HepGeom::Point3D<float> lcoord(
xy.first + signx[
i] *
dx,
xy.second + signy[
i] *
dy,
dz);
400 int lay = ((momentum.
z() *
id.zSide > 0) ? (
id.iLay + 1) : (
id.iLay - 1));
402 edm::LogVerbatim(
"HGCalGeom") <<
"neighborz1:: ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":"
403 <<
id.iCell1 <<
":" <<
id.iCell2 <<
" New Layer " << lay <<
" Range "
408 (momentum.
z() != 0.0)) {
411 double grad = (
z -
v.z()) / momentum.
z();
415 if (
r >= rlimit.first &&
r <= rlimit.second)
418 edm::LogVerbatim(
"HGCalGeom") <<
"neighborz1:: Position " <<
v <<
" New Z " <<
z <<
":" << grad <<
" new position "
419 <<
p <<
" r-limit " << rlimit.first <<
":" << rlimit.second;
431 int lay = ((momentum.
z() *
id.zSide > 0) ? (
id.iLay + 1) : (
id.iLay - 1));
433 edm::LogVerbatim(
"HGCalGeom") <<
"neighborz2:: ID " <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":"
434 <<
id.iCell1 <<
":" <<
id.iCell2 <<
" New Layer " << lay <<
" Range "
439 (momentum.
z() != 0.0)) {
451 if (
r >= rlimit.first &&
r <= rlimit.second)
456 << tsos.
isValid() <<
" new position " <<
p <<
" r limits " << rlimit.first <<
":"
470 HepGeom::Point3D<float>
local;
472 local = HepGeom::Point3D<float>(
r.x(),
r.y(), 0);
475 local = HepGeom::Point3D<float>(-
r.x(),
r.y(), 0);
480 id.iCell1 = kxy.second;
481 id.iSec1 = kxy.first;
501 edm::LogVerbatim(
"HGCalGeom") <<
"getClosestCell: local " <<
local <<
" Id " <<
id.det <<
":" <<
id.zSide <<
":"
502 <<
id.iLay <<
":" <<
id.iSec1 <<
":" <<
id.iSec2 <<
":" <<
id.iType <<
":"
503 <<
id.iCell1 <<
":" <<
id.iCell2;
524 return "HGCalHEFront";
526 return "HGCalHEBack";
533 if (detId !=
DetId()) {
538 <<
" index " << cellIndex;
552 return (
nullptr == cell->
param() ? nullptr : cell);
557 return (
nullptr == cell->
param() ? nullptr : cell);
565 static const auto do_not_delete = [](
const void*) {};
567 auto cell = std::shared_ptr<const CaloCellGeometry>(&
m_cellVec2[
index], do_not_delete);
568 if (
nullptr == cell->param())
572 auto cell = std::shared_ptr<const CaloCellGeometry>(&
m_cellVec[
index], do_not_delete);
573 if (
nullptr == cell->param())
587 cell->setPosition(
pos);
591 if (
nullptr == cell->param())
596 cell->setPosition(
pos);
600 if (
nullptr == cell->param())
607 edm::LogError(
"HGCalGeom") <<
"HGCalGeometry::addValidID is not implemented";
616 float phip =
r.phi();
618 float dzmin(9999), dphimin(9999), dphi10(0.175);
619 unsigned int cellIndex = vec.size();
620 for (
unsigned int k = 0;
k < vec.size(); ++
k) {
621 float dphi = phip - vec[
k].phiPos();
624 while (dphi <= -
M_PI)
628 if (
dz < (dzmin + 0.001)) {
630 if (
std::abs(dphi) < (dphimin + 0.01)) {
634 if (cellIndex >= vec.size())
641 edm::LogVerbatim(
"HGCalGeom") <<
"getClosestCellIndex::Input " << zp <<
":" << phip <<
" Index " << cellIndex;
642 if (cellIndex < vec.size())
643 edm::LogVerbatim(
"HGCalGeom") <<
" Cell z " << vec[cellIndex].getPosition().z() <<
":" << dzmin <<
" phi "
644 << vec[cellIndex].phiPos() <<
":" << dphimin;
652 bool operator()(
const DetId&
a,
const DetId&
b) {
return (
a.rawId() <
b.rawId()); }
671 iVector.reserve(numberOfCells);
673 dinsVector.reserve(numberOfCells);
677 int layer = mytr.
lay;
687 dimVector.insert(dimVector.end(),
params.begin(),
params.end());
704 dimVector.insert(dimVector.end(),
params.begin(),
params.end());
714 dimVector.insert(dimVector.end(),
params.begin(),
params.end());
720 for (
unsigned int i(0);
i < numberOfCells; ++
i) {
733 iVector.emplace_back(layer);
737 if (
nullptr != ptr) {
738 ptr->getTransform(tr, (
Pt3DVec*)
nullptr);
742 tr = HepGeom::Translate3D(
gp.x(),
gp.y(),
gp.z());
745 const CLHEP::Hep3Vector
tt(tr.getTranslation());
746 trVector.emplace_back(
tt.x());
747 trVector.emplace_back(
tt.y());
748 trVector.emplace_back(
tt.z());
750 const CLHEP::HepRotation
rr(tr.getRotation());
751 const ROOT::Math::Transform3D rtr(
752 rr.xx(),
rr.xy(),
rr.xz(),
tt.x(),
rr.yx(),
rr.yy(),
rr.yz(),
tt.y(),
rr.zx(),
rr.zy(),
rr.zz(),
tt.z());
755 trVector.emplace_back(ea.Phi());
756 trVector.emplace_back(ea.Theta());
757 trVector.emplace_back(ea.Psi());
766 geomId = static_cast<DetId>(
HGCalDetId(detId).geometryCell());
770 geomId = static_cast<DetId>(
HFNoseDetId(detId).geometryCell());