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 }
CaloCellGeometry::Tr3D
HepGeom::Transform3D Tr3D
Definition: CaloCellGeometry.h:53
dot
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: Basic3DVectorLD.h:212
Vector3DBase
Definition: Vector3DBase.h:8
CaloCellGeometry::Pt3DVec
std::vector< Pt3D > Pt3DVec
Definition: CaloCellGeometry.h:55
TruncatedPyramid::initCorners
void initCorners(CornersVec &) override
Definition: TruncatedPyramid.cc:129
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
TruncatedPyramid::getTransform
void getTransform(Tr3D &tr, Pt3DVec *lptr) const override
--------— only needed by specific utility; overloaded when needed -—
Definition: TruncatedPyramid.cc:65
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:355
CaloCellGeometry::CCGFloat
float CCGFloat
Definition: CaloCellGeometry.h:52
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
TruncatedPyramid::k_Alp1
static constexpr uint32_t k_Alp1
Definition: TruncatedPyramid.h:36
TruncatedPyramid::k_Dy1
static constexpr uint32_t k_Dy1
Definition: TruncatedPyramid.h:31
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
TruncatedPyramid::k_Dx3
static constexpr uint32_t k_Dx3
Definition: TruncatedPyramid.h:39
TruncatedPyramid::m_corOne
Pt3D m_corOne
Definition: TruncatedPyramid.h:92
TruncatedPyramid::k_Dx1
static constexpr uint32_t k_Dx1
Definition: TruncatedPyramid.h:32
to
cms::cuda::assert
assert(be >=bs)
CaloCellGeometry::getCorners
CornersVec const & getCorners() const
Returns the corner points of this cell's volume.
Definition: CaloCellGeometry.h:73
TruncatedPyramid::Pt3DVec
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: TruncatedPyramid.h:23
TruncatedPyramid
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code.
Definition: TruncatedPyramid.h:19
truncPyr
Definition: TruncatedPyramid.cc:143
DDAxes::x
TruncatedPyramid::axis
const GlobalVector & axis() const
Definition: TruncatedPyramid.cc:53
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
EZArrayFL< GlobalPoint >
cms::cuda::co
T *__restrict__ co
Definition: prefixScan.h:46
b2
static constexpr float b2
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
TruncatedPyramid::localCornersReflection
static void localCornersReflection(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: TruncatedPyramid.cc:147
TruncatedPyramid::CCGFloat
CaloCellGeometry::CCGFloat CCGFloat
Definition: TruncatedPyramid.h:21
CCGFloat
TruncatedPyramid::CCGFloat CCGFloat
Definition: TruncatedPyramid.cc:5
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
TruncatedPyramid::operator=
TruncatedPyramid & operator=(const TruncatedPyramid &tr)
Definition: TruncatedPyramid.cc:23
Pt3D
CaloCellGeometry::Pt3D Pt3D
Definition: CaloCellGeometry.cc:5
b1
static constexpr float b1
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
alignCSCRings.s
s
Definition: alignCSCRings.py:92
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
Vector3DBase::unit
Vector3DBase unit() const
Definition: Vector3DBase.h:54
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
TruncatedPyramid::vocalCorners
void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const override
Definition: TruncatedPyramid.cc:55
DPlane3D
HepGeom::Plane3D< double > DPlane3D
Definition: TruncatedPyramid.cc:14
TruncatedPyramid.h
vertices_cff.x
x
Definition: vertices_cff.py:29
TruncatedPyramid::k_Theta
static constexpr uint32_t k_Theta
Definition: TruncatedPyramid.h:27
Tr3D
TruncatedPyramid::Tr3D Tr3D
Definition: TruncatedPyramid.cc:8
DDAxes::z
TruncatedPyramid::m_axis
GlobalVector m_axis
Definition: TruncatedPyramid.h:91
TruncatedPyramid::TruncatedPyramid
TruncatedPyramid(void)
Definition: TruncatedPyramid.cc:19
TruncatedPyramid::createCorners
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: TruncatedPyramid.cc:237
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
CaloCellGeometry::Pt3D
HepGeom::Point3D< CCGFloat > Pt3D
Definition: CaloCellGeometry.h:54
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
CaloCellGeometry::initSpan
void initSpan()
Definition: CaloCellGeometry.h:120
CaloCellGeometry::getPosition
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
Definition: CaloCellGeometry.h:80
cross
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Definition: Basic3DVectorLD.h:225
DPt3D
HepGeom::Point3D< double > DPt3D
Definition: CaloCellGeometry.cc:14
DPlane3D
HepGeom::Plane3D< double > DPlane3D
Definition: CaloCellGeometry.cc:13
CaloCellGeometry
Definition: CaloCellGeometry.h:50
Pt3D
TruncatedPyramid::Pt3D Pt3D
Definition: TruncatedPyramid.cc:6
FVec3D
HepGeom::Vector3D< CCGFloat > FVec3D
Definition: TruncatedPyramid.cc:10
TruncatedPyramid::k_Dz
static constexpr uint32_t k_Dz
Definition: TruncatedPyramid.h:26
CaloCellGeometry::param
const CCGFloat * param() const
Definition: CaloCellGeometry.h:99
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
TruncatedPyramid::getThetaAxis
CCGFloat getThetaAxis() const
Definition: TruncatedPyramid.cc:49
FVec3D
HepGeom::Vector3D< CCGFloat > FVec3D
Definition: CaloCellGeometry.cc:9
TruncatedPyramid::~TruncatedPyramid
~TruncatedPyramid() override
Definition: TruncatedPyramid.cc:43
operator<<
std::ostream & operator<<(std::ostream &s, const TruncatedPyramid &cell)
Definition: TruncatedPyramid.cc:305
unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:162
TruncatedPyramid::k_Phi
static constexpr uint32_t k_Phi
Definition: TruncatedPyramid.h:29
DVec3D
HepGeom::Vector3D< double > DVec3D
Definition: TruncatedPyramid.cc:13
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
TruncatedPyramid::Tr3D
CaloCellGeometry::Tr3D Tr3D
Definition: TruncatedPyramid.h:24
TruncatedPyramid::localCorners
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: TruncatedPyramid.cc:177
TruncatedPyramid::localCornersSwap
static void localCornersSwap(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: TruncatedPyramid.cc:214
PVValHelper::dz
Definition: PVValidationHelpers.h:50
TruncatedPyramid::k_Dx2
static constexpr uint32_t k_Dx2
Definition: TruncatedPyramid.h:34
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
DPt3D
HepGeom::Point3D< double > DPt3D
Definition: TruncatedPyramid.cc:15
angle
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
Plane3D
HepGeom::Plane3D< CCGFloat > Plane3D
Definition: TruncatedPyramid.cc:11
TruncatedPyramid::makeAxis
GlobalVector makeAxis(void)
Definition: TruncatedPyramid.cc:57
TruncatedPyramid::getPhiAxis
CCGFloat getPhiAxis() const
Definition: TruncatedPyramid.cc:51
EZMgrFL
Definition: EZMgrFL.h:8
TruncatedPyramid::k_Alp2
static constexpr uint32_t k_Alp2
Definition: TruncatedPyramid.h:43
TruncatedPyramid::k_Dx4
static constexpr uint32_t k_Dx4
Definition: TruncatedPyramid.h:41
TruncatedPyramid::Pt3D
CaloCellGeometry::Pt3D Pt3D
Definition: TruncatedPyramid.h:22
truncPyr::refl
Pt3D refl(const Pt3D &p)
Definition: TruncatedPyramid.cc:144
TruncatedPyramid::k_Dy2
static constexpr uint32_t k_Dy2
Definition: TruncatedPyramid.h:38
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
EZArrayFL::uninitialized
bool uninitialized() const
Definition: EZArrayFL.h:63
Pt3DVec
TruncatedPyramid::Pt3DVec Pt3DVec
Definition: TruncatedPyramid.cc:7
TruncatedPyramid::backCtr
const GlobalPoint backCtr(void) const
Definition: TruncatedPyramid.cc:59
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37