CMS 3D CMS Logo

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