CMS 3D CMS Logo

TruncatedPyramid.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <iostream>
4 
9 
10 typedef HepGeom::Vector3D<CCGFloat> FVec3D;
11 typedef HepGeom::Plane3D<CCGFloat> Plane3D;
12 
13 typedef HepGeom::Vector3D<double> DVec3D;
14 typedef HepGeom::Plane3D<double> DPlane3D;
15 typedef HepGeom::Point3D<double> DPt3D;
16 
17 //----------------------------------------------------------------------
18 
19 TruncatedPyramid::TruncatedPyramid() : CaloCellGeometry(), m_axis(0., 0., 0.), m_corOne(0., 0., 0.) {}
20 
22 
24  CaloCellGeometry::operator=(tr);
25  if (this != &tr) {
26  m_axis = tr.m_axis;
27  m_corOne = tr.m_corOne;
28  }
29  return *this;
30 }
31 
33  CornersMgr* cMgr, const GlobalPoint& fCtr, const GlobalPoint& bCtr, const GlobalPoint& cor1, const CCGFloat* parV)
34  : CaloCellGeometry(fCtr, cMgr, parV), m_axis((bCtr - fCtr).unit()), m_corOne(cor1.x(), cor1.y(), cor1.z()) {
35  initSpan();
36 }
37 
39  : CaloCellGeometry(corn, par), m_axis(makeAxis()), m_corOne(corn[0].x(), corn[0].y(), corn[0].z()) {
40  initSpan();
41 }
42 
44 
47 }
48 
50 
52 
53 const GlobalVector& TruncatedPyramid::axis() const { return m_axis; }
54 
55 void TruncatedPyramid::vocalCorners(Pt3DVec& vec, const CCGFloat* pv, Pt3D& ref) const { localCorners(vec, pv, ref); }
56 
58 
60  return GlobalPoint(0.25 * (getCorners()[4].x() + getCorners()[5].x() + getCorners()[6].x() + getCorners()[7].x()),
61  0.25 * (getCorners()[4].y() + getCorners()[5].y() + getCorners()[6].y() + getCorners()[7].y()),
62  0.25 * (getCorners()[4].z() + getCorners()[5].z() + getCorners()[6].z() + getCorners()[7].z()));
63 }
64 
67  const Pt3D gFront(p.x(), p.y(), p.z());
68  const DPt3D dgFront(p.x(), p.y(), p.z());
69 
70  const double dz(param()[0]);
71 
72  Pt3D lFront;
73  assert(nullptr != param());
74  std::vector<Pt3D> lc(8, Pt3D(0, 0, 0));
75  if (11.2 > dz) {
76  localCorners(lc, param(), lFront);
77  } else {
78  localCornersSwap(lc, param(), lFront);
79  }
80 
81  // figure out if reflction volume or not
82 
83  Pt3D lBack(0.25 * (lc[4] + lc[5] + lc[6] + lc[7]));
84 
85  const double disl((lFront - lc[0]).mag());
86  const double disr((lFront - lc[3]).mag());
87  const double disg((gFront - m_corOne).mag());
88 
89  const double dell(fabs(disg - disl));
90  const double delr(fabs(disg - disr));
91 
92  if (11.2 < dz && delr < dell) // reflection volume if true
93  {
94  localCornersReflection(lc, param(), lFront);
95  lBack = 0.25 * (lc[4] + lc[5] + lc[6] + lc[7]);
96  }
97 
98  const DPt3D dlFront(lFront.x(), lFront.y(), lFront.z());
99  const DPt3D dlBack(lBack.x(), lBack.y(), lBack.z());
100  const DPt3D dlOne(lc[0].x(), lc[0].y(), lc[0].z());
101 
102  const FVec3D dgAxis(axis().x(), axis().y(), axis().z());
103 
104  const DPt3D dmOne(m_corOne.x(), m_corOne.y(), m_corOne.z());
105 
106  const DPt3D dgBack(dgFront + (dlBack - dlFront).mag() * dgAxis);
107  DPt3D dgOne(dgFront + (dlOne - dlFront).mag() * (dmOne - dgFront).unit());
108 
109  const double dlangle((dlBack - dlFront).angle(dlOne - dlFront));
110  const double dgangle((dgBack - dgFront).angle(dgOne - dgFront));
111  const double dangle(dlangle - dgangle);
112 
113  if (1.e-6 < fabs(dangle)) //guard against precision problems
114  {
115  const DPlane3D dgPl(dgFront, dgOne, dgBack);
116  const DPt3D dp2(dgFront + dgPl.normal().unit());
117 
118  DPt3D dgOld(dgOne);
119 
120  dgOne = (dgFront + HepGeom::Rotate3D(-dangle, dgFront, dp2) * DVec3D(dgOld - dgFront));
121  }
122 
123  tr = Tr3D(dlFront, dlBack, dlOne, dgFront, dgBack, dgOne);
124 
125  if (nullptr != lptr)
126  (*lptr) = lc;
127 }
128 
130  if (corners.uninitialized()) {
131  Pt3DVec lc;
132 
133  Tr3D tr;
134  getTransform(tr, &lc);
135 
136  for (unsigned int i(0); i != 8; ++i) {
137  const Pt3D corn(tr * lc[i]);
138  corners[i] = GlobalPoint(corn.x(), corn.y(), corn.z());
139  }
140  }
141 }
142 
143 namespace truncPyr {
144  Pt3D refl(const Pt3D& p) { return Pt3D(-p.x(), p.y(), p.z()); }
145 } // namespace truncPyr
146 
148  // using namespace truncPyr ;
149  localCorners(lc, pv, ref);
150  Pt3D tmp;
151  /*
152  tmp = lc[0] ;
153  lc[0] = refl( lc[2] ) ;
154  lc[2] = refl( tmp ) ;
155  tmp = lc[1] ;
156  lc[1] = refl( lc[3] ) ;
157  lc[3] = refl( tmp ) ;
158  tmp = lc[4] ;
159  lc[4] = refl( lc[6] ) ;
160  lc[6] = refl( tmp ) ;
161  tmp = lc[5] ;
162  lc[5] = refl( lc[7] ) ;
163  lc[7] = refl( tmp ) ;
164 */
165  lc[0] = truncPyr::refl(lc[0]);
166  lc[1] = truncPyr::refl(lc[1]);
167  lc[2] = truncPyr::refl(lc[2]);
168  lc[3] = truncPyr::refl(lc[3]);
169  lc[4] = truncPyr::refl(lc[4]);
170  lc[5] = truncPyr::refl(lc[5]);
171  lc[6] = truncPyr::refl(lc[6]);
172  lc[7] = truncPyr::refl(lc[7]);
173 
174  ref = 0.25 * (lc[0] + lc[1] + lc[2] + lc[3]);
175 }
176 
178  assert(nullptr != pv);
179  assert(8 == lc.size());
180 
192 
193  const CCGFloat ta1(tan(a1)); // lower plane
194  const CCGFloat ta2(tan(a2)); // upper plane
195 
196  const CCGFloat tth(tan(th));
197  const CCGFloat tthcp(tth * cos(ph));
198  const CCGFloat tthsp(tth * sin(ph));
199 
200  const unsigned int off(h1 < h2 ? 0 : 4);
201 
202  lc[0 + off] = Pt3D(-dz * tthcp - h1 * ta1 - b1, -dz * tthsp - h1, -dz); // (-,-,-)
203  lc[1 + off] = Pt3D(-dz * tthcp + h1 * ta1 - t1, -dz * tthsp + h1, -dz); // (-,+,-)
204  lc[2 + off] = Pt3D(-dz * tthcp + h1 * ta1 + t1, -dz * tthsp + h1, -dz); // (+,+,-)
205  lc[3 + off] = Pt3D(-dz * tthcp - h1 * ta1 + b1, -dz * tthsp - h1, -dz); // (+,-,-)
206  lc[4 - off] = Pt3D(dz * tthcp - h2 * ta2 - b2, dz * tthsp - h2, dz); // (-,-,+)
207  lc[5 - off] = Pt3D(dz * tthcp + h2 * ta2 - t2, dz * tthsp + h2, dz); // (-,+,+)
208  lc[6 - off] = Pt3D(dz * tthcp + h2 * ta2 + t2, dz * tthsp + h2, dz); // (+,+,+)
209  lc[7 - off] = Pt3D(dz * tthcp - h2 * ta2 + b2, dz * tthsp - h2, dz); // (+,-,+)
210 
211  ref = 0.25 * (lc[0] + lc[1] + lc[2] + lc[3]);
212 }
213 
215  localCorners(lc, pv, ref);
216 
217  Pt3D tmp;
218  tmp = lc[0];
219  lc[0] = lc[3];
220  lc[3] = tmp;
221  tmp = lc[1];
222  lc[1] = lc[2];
223  lc[2] = tmp;
224  tmp = lc[4];
225  lc[4] = lc[7];
226  lc[7] = tmp;
227  tmp = lc[5];
228  lc[5] = lc[6];
229  lc[6] = tmp;
230 
231  ref = 0.25 * (lc[0] + lc[1] + lc[2] + lc[3]);
232 }
233 
234 // the following function is static and a helper for the endcap & barrel loader classes
235 // when initializing from DDD: fills corners vector from trap params plus transform
236 
237 void TruncatedPyramid::createCorners(const std::vector<CCGFloat>& pv, const Tr3D& tr, std::vector<GlobalPoint>& co) {
238  assert(11 == pv.size());
239  assert(8 == co.size());
240  // to get the ordering right for fast sim, we have to use their convention
241  // which were based on the old static geometry. Some gymnastics required here.
242 
243  const CCGFloat dz(pv[0]);
244  const CCGFloat h1(pv[3]);
245  const CCGFloat h2(pv[7]);
246  Pt3DVec ko(8, Pt3D(0, 0, 0));
247 
248  // if reflection, different things for barrel and endcap
249  static const FVec3D x(1, 0, 0);
250  static const FVec3D y(0, 1, 0);
251  static const FVec3D z(0, 0, 1);
252  const bool refl(((tr * x).cross(tr * y)).dot(tr * z) < 0); // has reflection!
253 
254  Pt3D tmp;
255  Pt3DVec to(8, Pt3D(0, 0, 0));
256  localCorners(to, &pv.front(), tmp);
257 
258  for (unsigned int i(0); i != 8; ++i) {
259  ko[i] = tr * to[i]; // apply transformation
260  }
261 
262  if (refl || h1 > h2) {
263  if (11.2 < dz) //barrel
264  {
265  if (!refl) {
266  to[0] = ko[3];
267  to[1] = ko[2];
268  to[2] = ko[1];
269  to[3] = ko[0];
270  to[4] = ko[7];
271  to[5] = ko[6];
272  to[6] = ko[5];
273  to[7] = ko[4];
274  } else {
275  to[0] = ko[0];
276  to[1] = ko[1];
277  to[2] = ko[2];
278  to[3] = ko[3];
279  to[4] = ko[4];
280  to[5] = ko[5];
281  to[6] = ko[6];
282  to[7] = ko[7];
283  }
284  } else //endcap
285  {
286  to[0] = ko[0];
287  to[1] = ko[3];
288  to[2] = ko[2];
289  to[3] = ko[1];
290  to[4] = ko[4];
291  to[5] = ko[7];
292  to[6] = ko[6];
293  to[7] = ko[5];
294  }
295  copy(to.begin(), to.end(), ko.begin()); // faster than ko = to ? maybe.
296  }
297  for (unsigned int i(0); i != 8; ++i) {
298  const Pt3D& p(ko[i]);
299  co[i] = GlobalPoint(p.x(), p.y(), p.z());
300  }
301 }
302 //----------------------------------------------------------------------
303 //----------------------------------------------------------------------
304 
305 std::ostream& operator<<(std::ostream& s, const TruncatedPyramid& cell) {
306  s << "Center: " << ((const CaloCellGeometry&)cell).getPosition() << std::endl;
307  const float thetaaxis(cell.getThetaAxis());
308  const float phiaxis(cell.getPhiAxis());
309  s << "Axis: " << thetaaxis << " " << phiaxis << std::endl;
310  const CaloCellGeometry::CornersVec& corners(cell.getCorners());
311  for (unsigned int i = 0; i != corners.size(); ++i) {
312  s << "Corner: " << corners[i] << std::endl;
313  }
314  return s;
315 }
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
CaloCellGeometry::Tr3D Tr3D
CCGFloat getPhiAxis() const
HepGeom::Point3D< double > DPt3D
TruncatedPyramid::Pt3D Pt3D
HepGeom::Point3D< double > DPt3D
static constexpr uint32_t k_Dx4
static constexpr uint32_t k_Alp2
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
CaloCellGeometry::Pt3D Pt3D
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
HepGeom::Transform3D Tr3D
std::vector< Pt3D > Pt3DVec
void getTransform(Tr3D &tr, Pt3DVec *lptr) const override
--------— only needed by specific utility; overloaded when needed -—
assert(be >=bs)
__host__ __device__ VT * co
Definition: prefixScan.h:47
static constexpr uint32_t k_Dy2
float float float z
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
TruncatedPyramid::Pt3DVec Pt3DVec
static constexpr uint32_t k_Phi
static void localCornersSwap(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
static constexpr uint32_t k_Alp1
HepGeom::Vector3D< double > DVec3D
CaloCellGeometry::Pt3DVec Pt3DVec
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const GlobalVector & axis() const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
def pv(vc)
Definition: MetAnalyzer.py:7
static constexpr uint32_t k_Dx3
static constexpr uint32_t k_Dx2
TruncatedPyramid & operator=(const TruncatedPyramid &tr)
Basic3DVector unit() const
GlobalVector makeAxis(void)
CaloCellGeometry::Pt3D Pt3D
const GlobalPoint backCtr(void) const
CaloCellGeometry::CCGFloat CCGFloat
void initCorners(CornersVec &) override
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
HepGeom::Plane3D< double > DPlane3D
void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const override
TruncatedPyramid::CCGFloat CCGFloat
HepGeom::Point3D< CCGFloat > Pt3D
Definition: EZMgrFL.h:8
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
static constexpr uint32_t k_Theta
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
GlobalVector m_axis
static constexpr uint32_t k_Dy1
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
TruncatedPyramid::Tr3D Tr3D
std::ostream & operator<<(std::ostream &s, const TruncatedPyramid &cell)
float x
HepGeom::Plane3D< double > DPlane3D
Pt3D refl(const Pt3D &p)
HepGeom::Plane3D< CCGFloat > Plane3D
CornersVec const & getCorners() const
Returns the corner points of this cell&#39;s volume.
static constexpr uint32_t k_Dz
Vector3DBase unit() const
Definition: Vector3DBase.h:54
static constexpr float b2
tmp
align.sh
Definition: createJobs.py:716
~TruncatedPyramid() override
static void localCornersReflection(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
static constexpr uint32_t k_Dx1
HepGeom::Vector3D< CCGFloat > FVec3D
bool uninitialized() const
Definition: EZArrayFL.h:63
HepGeom::Vector3D< CCGFloat > FVec3D
const CCGFloat * param() const
static constexpr float b1
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
CCGFloat getThetaAxis() const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11