CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FlatHexagon.cc
Go to the documentation of this file.
4 #include <algorithm>
5 #include <iostream>
6 
7 //#define EDM_ML_DEBUG
8 
13 
14 typedef HepGeom::Vector3D<CCGFloat> FVec3D;
15 typedef HepGeom::Plane3D<CCGFloat> Plane3D;
16 
17 typedef HepGeom::Vector3D<double> DVec3D;
18 typedef HepGeom::Plane3D<double> DPlane3D;
19 typedef HepGeom::Point3D<double> DPt3D;
20 
21 static const float tolmin = 1.e-12;
22 
23 //----------------------------------------------------------------------
24 
26  : CaloCellGeometry(), m_axis(0., 0., 0.), m_corOne(0., 0., 0.), m_local(0., 0., 0.), m_global(0., 0., 0.) {}
27 
28 FlatHexagon::FlatHexagon(const FlatHexagon& tr) : CaloCellGeometry(tr) { *this = tr; }
29 
31  CaloCellGeometry::operator=(tr);
32  if (this != &tr) {
33  m_axis = tr.m_axis;
34  m_corOne = tr.m_corOne;
35  m_local = tr.m_local;
36  m_global = tr.m_global;
37  m_tr = tr.m_tr;
38  }
39 #ifdef EDM_ML_DEBUG
40  edm::LogVerbatim("CaloGeometry") << "FlatHexagon(Copy): Local " << m_local << " Global " << m_global << " eta "
41  << etaPos() << " phi " << phiPos() << " Translation " << m_tr.getTranslation()
42  << " and rotation " << m_tr.getRotation();
43 #endif
44  return *this;
45 }
46 
48  CornersMgr* cMgr, const GlobalPoint& fCtr, const GlobalPoint& bCtr, const GlobalPoint& cor1, const CCGFloat* parV)
49  : CaloCellGeometry(fCtr, cMgr, parV),
50  m_axis((bCtr - fCtr).unit()),
51  m_corOne(cor1.x(), cor1.y(), cor1.z()),
52  m_local(0., 0., 0.) {
53  getTransform(m_tr, nullptr);
54  Pt3D glb = m_tr * m_local;
55  m_global = GlobalPoint(glb.x(), glb.y(), glb.z());
56 #ifdef EDM_ML_DEBUG
57  edm::LogVerbatim("CaloGeometry") << "FlatHexagon: Local " << m_local << " Global " << glb << " eta " << etaPos()
58  << " phi " << phiPos() << " Translation " << m_tr.getTranslation()
59  << " and rotation " << m_tr.getRotation();
60 #endif
61 }
62 
64  : CaloCellGeometry(corn, par), m_corOne(corn[0].x(), corn[0].y(), corn[0].z()), m_local(0., 0., 0.) {
65  getTransform(m_tr, nullptr);
66  m_axis = makeAxis();
67  Pt3D glb = m_tr * m_local;
68  m_global = GlobalPoint(glb.x(), glb.y(), glb.z());
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("CaloGeometry") << "FlatHexagon: Local " << m_local << " Global " << glb << " eta " << etaPos()
71  << " phi " << phiPos() << " Translation " << m_tr.getTranslation()
72  << " and rotation " << m_tr.getRotation();
73 #endif
74 }
75 
76 FlatHexagon::FlatHexagon(const FlatHexagon& tr, const Pt3D& local) : CaloCellGeometry(tr), m_local(local) {
77  *this = tr;
78  Pt3D glb = m_tr * m_local;
79  m_global = GlobalPoint(glb.x(), glb.y(), glb.z());
80 #ifdef EDM_ML_DEBUG
81  edm::LogVerbatim("CaloGeometry") << "FlatHexagon: Local " << m_local << " Global " << glb << " eta " << etaPos()
82  << " phi " << phiPos() << " Translation " << m_tr.getTranslation()
83  << " and rotation " << m_tr.getRotation();
84 #endif
85 }
86 
88 
90  Pt3D glb = m_tr * local;
91 #ifdef EDM_ML_DEBUG
92  edm::LogVerbatim("CaloGeometry") << "FlatHexagon::Local " << local.x() << ":" << local.y() << ":" << local.z()
93  << " Global " << glb.x() << ":" << glb.y() << ":" << glb.z() << " TR " << m_tr.xx()
94  << ":" << m_tr.xy() << ":" << m_tr.xz() << ":" << m_tr.yx() << ":" << m_tr.yy()
95  << ":" << m_tr.yz() << ":" << m_tr.zx() << ":" << m_tr.zy() << ":" << m_tr.zz()
96  << ":" << m_tr.dx() << ":" << m_tr.dy() << ":" << m_tr.dz();
97 #endif
98  return GlobalPoint(glb.x(), glb.y(), glb.z());
99 }
100 
101 float FlatHexagon::etaSpan() const {
102  assert(param() != nullptr);
103  float eta1 =
104  -std::log(std::tan(0.5 * std::atan((m_global.perp() + param()[k_R]) / std::max(tolmin, std::abs(m_global.z())))));
105  float eta2 =
106  -std::log(std::tan(0.5 * std::atan((m_global.perp() - param()[k_R]) / std::max(tolmin, std::abs(m_global.z())))));
107  float dEta = std::abs(eta1 - eta2);
108  return dEta;
109 }
110 
111 float FlatHexagon::phiSpan() const {
112  assert(param() != nullptr);
113  float dPhi = 2.0 * std::atan(param()[k_r] / std::max(tolmin, m_global.perp()));
114  return dPhi;
115 }
116 
117 Pt3D FlatHexagon::getLocal(const GlobalPoint& global) const {
118  Pt3D local = m_tr.inverse() * Pt3D(global.x(), global.y(), global.z());
119 #ifdef EDM_ML_DEBUG
120  edm::LogVerbatim("CaloGeometry") << "FlatHexagon::Global " << global.x() << ":" << global.y() << ":" << global.z()
121  << " Local " << local.x() << ":" << local.y() << ":" << local.z();
122 #endif
123  return local;
124 }
125 
127 
129 
130 const GlobalVector& FlatHexagon::axis() const { return m_axis; }
131 
132 void FlatHexagon::vocalCorners(Pt3DVec& vec, const CCGFloat* pv, Pt3D& ref) const { localCorners(vec, pv, ref); }
133 
134 void FlatHexagon::createCorners(const std::vector<CCGFloat>& pv, const Tr3D& tr, std::vector<GlobalPoint>& co) {
135  assert(3 == pv.size());
136  assert(ncorner_ == co.size());
137 
138  Pt3DVec ko(ncorner_, Pt3D(0, 0, 0));
139 
140  Pt3D tmp;
141  Pt3DVec to(ncorner_, Pt3D(0, 0, 0));
142  localCorners(to, &pv.front(), tmp);
143 
144  for (unsigned int i(0); i != ncorner_; ++i) {
145  ko[i] = tr * to[i]; // apply transformation
146  const Pt3D& p(ko[i]);
147  co[i] = GlobalPoint(p.x(), p.y(), p.z());
148 #ifdef EDM_ML_DEBUG
149  edm::LogVerbatim("CaloGeometry") << "Corner[" << i << "] = " << co[i];
150 #endif
151  }
152 }
153 
155  assert(nullptr != pv);
156  assert(ncorner_ == lc.size());
157 
158  const CCGFloat dz(pv[FlatHexagon::k_dZ]);
159  const CCGFloat r(pv[FlatHexagon::k_r]);
160  const CCGFloat R(pv[FlatHexagon::k_R]);
161 
162  lc[0] = Pt3D(0, -2 * R, -dz); // (0,-,-)
163  lc[1] = Pt3D(-r, -R, -dz); // (-,-,-)
164  lc[2] = Pt3D(-r, R, -dz); // (-,+,-)
165  lc[3] = Pt3D(0, 2 * R, -dz); // (0,+,-)
166  lc[4] = Pt3D(r, R, -dz); // (+,+,-)
167  lc[5] = Pt3D(r, -R, -dz); // (+,-,-)
168  lc[6] = Pt3D(0, -2 * R, dz); // (0,-,+)
169  lc[7] = Pt3D(-r, -R, dz); // (-,-,+)
170  lc[8] = Pt3D(-r, R, dz); // (-,+,+)
171  lc[9] = Pt3D(0, 2 * R, dz); // (0,+,+)
172  lc[10] = Pt3D(r, R, dz); // (+,+,+)
173  lc[11] = Pt3D(r, -R, dz); // (+,-,+)
174 
175  ref = oneBySix_ * (lc[0] + lc[1] + lc[2] + lc[3] + lc[4] + lc[5]);
176 #ifdef EDM_ML_DEBUG
177  edm::LogVerbatim("CaloGeometry") << "Ref " << ref << " Local Corners " << lc[0] << "|" << lc[1] << "|" << lc[2] << "|"
178  << lc[3] << "|" << lc[4] << "|" << lc[5] << "|" << lc[6] << "|" << lc[7] << "|"
179  << lc[8] << "|" << lc[9] << "|" << lc[10] << "|" << lc[11];
180 #endif
181 }
182 
183 void FlatHexagon::getTransform(Tr3D& tr, Pt3DVec* lptr) const {
185  const Pt3D gFront(p.x(), p.y(), p.z());
186  const DPt3D dgFront(p.x(), p.y(), p.z());
187 
188  Pt3D lFront;
189  assert(nullptr != param());
190  std::vector<Pt3D> lc(ncorner_, Pt3D(0, 0, 0));
191  localCorners(lc, param(), lFront);
192 
193  // figure out if reflction volume or not
194 
195  Pt3D lBack((lc[6] + lc[7] + lc[8] + lc[9] + lc[10] + lc[11]) / 6.0);
196 
197  const DPt3D dlFront(lFront.x(), lFront.y(), lFront.z());
198  const DPt3D dlBack(lBack.x(), lBack.y(), lBack.z());
199  const DPt3D dlOne(lc[0].x(), lc[0].y(), lc[0].z());
200 
201  const FVec3D dgAxis(axis().x(), axis().y(), axis().z());
202 
203  const DPt3D dmOne(m_corOne.x(), m_corOne.y(), m_corOne.z());
204 
205  const DPt3D dgBack(dgFront + (dlBack - dlFront).mag() * dgAxis);
206  DPt3D dgOne(dgFront + (dlOne - dlFront).mag() * (dmOne - dgFront).unit());
207 
208  const double dlangle((dlBack - dlFront).angle(dlOne - dlFront));
209  const double dgangle((dgBack - dgFront).angle(dgOne - dgFront));
210  const double dangle(dlangle - dgangle);
211 
212  if (1.e-6 < fabs(dangle)) { //guard against precision problems
213  const DPlane3D dgPl(dgFront, dgOne, dgBack);
214  const DPt3D dp2(dgFront + dgPl.normal().unit());
215 
216  DPt3D dgOld(dgOne);
217 
218  dgOne = (dgFront + HepGeom::Rotate3D(-dangle, dgFront, dp2) * DVec3D(dgOld - dgFront));
219  }
220 
221  tr = Tr3D(dlFront, dlBack, dlOne, dgFront, dgBack, dgOne);
222 
223  if (nullptr != lptr)
224  (*lptr) = lc;
225 }
226 
228  if (co.uninitialized()) {
229  CornersVec& corners(co);
230  Pt3DVec lc;
231  Tr3D tr;
232  getTransform(tr, &lc);
233 
234  for (unsigned int i(0); i != ncorner_; ++i) {
235  const Pt3D corn(tr * lc[i]);
236  corners[i] = GlobalPoint(corn.x(), corn.y(), corn.z());
237  }
238  }
239 }
240 
242 
244  float dz =
246  Pt3D local_b(m_local.x(), m_local.y(), m_local.z() + dz);
247  Pt3D global_b = m_tr * local_b;
248  GlobalPoint global(global_b.x(), global_b.y(), global_b.z());
249  return global;
250 }
251 
252 //----------------------------------------------------------------------
253 //----------------------------------------------------------------------
254 
255 std::ostream& operator<<(std::ostream& s, const FlatHexagon& cell) {
256  s << "Center: " << cell.getPosition() << " eta " << cell.etaPos() << " phi " << cell.phiPos() << std::endl;
257  s << "Axis: " << cell.getThetaAxis() << " " << cell.getPhiAxis() << std::endl;
258  const CaloCellGeometry::CornersVec& corners(cell.getCorners());
259  for (unsigned int i = 0; i != corners.size(); ++i) {
260  s << "Corner: " << corners[i] << std::endl;
261  }
262  return s;
263 }
float phiSpan() const override
Definition: FlatHexagon.cc:111
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatHexagon.cc:134
Log< level::Info, true > LogVerbatim
Pt3D m_corOne
Definition: FlatHexagon.h:91
static std::vector< std::string > checklist log
T perp() const
Definition: PV3DBase.h:69
HepGeom::Point3D< double > DPt3D
void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const override
Definition: FlatHexagon.cc:132
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
double glb
Definition: hdecay.h:103
float phiPos() const override
Definition: FlatHexagon.h:52
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalVector makeAxis(void)
Definition: FlatHexagon.cc:241
T y() const
Definition: PV3DBase.h:60
float etaSpan() const override
Definition: FlatHexagon.cc:101
float etaPos() const override
Definition: FlatHexagon.h:51
CaloCellGeometry::Tr3D Tr3D
Definition: FlatHexagon.h:25
HepGeom::Transform3D Tr3D
GlobalVector m_axis
Definition: FlatHexagon.h:90
std::vector< Pt3D > Pt3DVec
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
const GlobalVector & axis() const
Definition: FlatHexagon.cc:130
assert(be >=bs)
__host__ __device__ VT * co
Definition: prefixScan.h:47
Pt3D m_local
Definition: FlatHexagon.h:91
float float float z
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: FlatHexagon.cc:154
static constexpr unsigned int ncorner_
Definition: FlatHexagon.h:81
CaloCellGeometry::Pt3D Pt3D
Definition: FlatHexagon.h:23
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
static constexpr uint32_t k_R
Definition: FlatHexagon.h:29
CaloCellGeometry::CCGFloat CCGFloat
Definition: FlatHexagon.h:22
const CCGFloat * param() const
static constexpr uint32_t k_r
Definition: FlatHexagon.h:28
void getTransform(Tr3D &tr, Pt3DVec *lptr) const override
--------— only needed by specific utility; overloaded when needed -—
Definition: FlatHexagon.cc:183
static const float tolmin
Definition: FlatHexagon.cc:21
FlatHexagon(void)
Definition: FlatHexagon.cc:25
T z() const
Definition: PV3DBase.h:61
FlatHexagon & operator=(const FlatHexagon &tr)
Definition: FlatHexagon.cc:30
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
A base class to handle the hexagonal shape of HGCal silicon volumes.
Definition: FlatHexagon.h:20
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HepGeom::Vector3D< double > DVec3D
uint16_t const *__restrict__ x
Definition: gpuClustering.h:43
CaloCellGeometry::CCGFloat CCGFloat
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: FlatHexagon.h:24
Pt3D getLocal(const GlobalPoint &global) const
Definition: FlatHexagon.cc:117
void initCorners(CornersVec &) override
Definition: FlatHexagon.cc:227
GlobalPoint const & getPosition() const override
Returns the position of reference for this cell.
Definition: FlatHexagon.h:49
CaloCellGeometry::Pt3D Pt3D
Vector3DBase unit() const
Definition: Vector3DBase.h:54
static constexpr unsigned int ncornerBy2_
Definition: FlatHexagon.h:82
static constexpr uint32_t k_dZ
Definition: FlatHexagon.h:27
HepGeom::Plane3D< double > DPlane3D
float dz() const
Definition: FlatHexagon.h:56
CCGFloat getPhiAxis() const
Definition: FlatHexagon.cc:128
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
Definition: EZMgrFL.h:8
CornersVec const & getCorners() const
Returns the corner points of this cell&#39;s volume.
CaloCellGeometry::Tr3D Tr3D
bool uninitialized() const
Definition: EZArrayFL.h:63
GlobalPoint backCtr(void) const
Definition: FlatHexagon.cc:243
tmp
align.sh
Definition: createJobs.py:716
T x() const
Definition: PV3DBase.h:59
~FlatHexagon() override
Definition: FlatHexagon.cc:87
HepGeom::Vector3D< CCGFloat > FVec3D
ROOT::Math::Plane3D Plane3D
static constexpr double oneBySix_
Definition: FlatHexagon.h:80
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalPoint m_global
Definition: FlatHexagon.h:92
Basic3DVector unit() const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
CCGFloat getThetaAxis() const
Definition: FlatHexagon.cc:126