CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CaloCellCrossing.cc
Go to the documentation of this file.
4 
6  const GlobalVector& gv,
7  const CaloCellCrossing::DetIds* di,
8  const CaloSubdetectorGeometry* sg,
9  DetId::Detector det,
10  int subdet,
11  double small,
12  bool onewayonly)
13  : m_gp(gp), m_gv(gv) {
14  const double eps(fabs(small) > 1.e-15 ? fabs(small) : 1.e-10);
15  static unsigned int k_rlen(30);
16  m_detId.reserve(k_rlen);
17  m_ctr.reserve(k_rlen);
18  m_entr.reserve(k_rlen);
19  m_exit.reserve(k_rlen);
20  //------------------------------------------------------------
21  const HepLine3D line(
22  HepGeom::Point3D<double>(gp.x(), gp.y(), gp.z()), HepGeom::Vector3D<double>(gv.x(), gv.y(), gv.z()), eps);
23 
24  LogDebug("CaloCellCrossing") << "*** Line: pt=" << line.pt() << ", unitvec=" << line.uv();
25 
26  const DetIds& ids(nullptr == di ? sg->getValidDetIds(det, subdet) : *di);
27  //------------------------------------------------------------
28  for (auto dId : ids) {
29  unsigned int found(0);
30  auto cg = sg->getGeometry(dId);
31  const CaloCellGeometry::CornersVec& gc(cg->getCorners());
32  const HepGeom::Point3D<double> fr(cg->getPosition().x(), cg->getPosition().y(), cg->getPosition().z());
33  const double bCut2((gc[0] - gc[6]).mag2());
34 
35  if ((!onewayonly || eps < HepGeom::Vector3D<double>(fr - line.pt()).dot(line.uv())) &&
36  bCut2 > line.dist2(fr)) // first loose cut
37  {
38  LogDebug("CaloCellCrossing") << "*** fr=" << fr << ", bCut =" << sqrt(bCut2) << ", dis=" << line.dist(fr);
39  const HepGeom::Point3D<double> cv[8] = {HepGeom::Point3D<double>(gc[0].x(), gc[0].y(), gc[0].z()),
40  HepGeom::Point3D<double>(gc[1].x(), gc[1].y(), gc[1].z()),
41  HepGeom::Point3D<double>(gc[2].x(), gc[2].y(), gc[2].z()),
42  HepGeom::Point3D<double>(gc[3].x(), gc[3].y(), gc[3].z()),
43  HepGeom::Point3D<double>(gc[4].x(), gc[4].y(), gc[4].z()),
44  HepGeom::Point3D<double>(gc[5].x(), gc[5].y(), gc[5].z()),
45  HepGeom::Point3D<double>(gc[6].x(), gc[6].y(), gc[6].z()),
46  HepGeom::Point3D<double>(gc[7].x(), gc[7].y(), gc[7].z())};
47  const HepGeom::Point3D<double> ctr(0.125 * (cv[0] + cv[1] + cv[2] + cv[3] + cv[4] + cv[5] + cv[6] + cv[7]));
48  const double dCut2(bCut2 / 4.);
49  if (dCut2 > line.dist2(ctr)) // tighter cut
50  {
51  LogDebug("CaloCellCrossing") << "** 2nd cut: ctr=" << ctr << ", dist=" << line.dist(ctr);
52  static const unsigned int nc[6][4] = {
53  {0, 1, 2, 3}, {0, 4, 5, 1}, {0, 4, 7, 3}, {6, 7, 4, 5}, {6, 2, 3, 7}, {6, 2, 1, 5}};
54  for (unsigned int face(0); face != 6; ++face) {
55  const unsigned int* ic(&nc[face][0]);
56  const HepGeom::Plane3D<double> pl(cv[ic[0]], cv[ic[1]], cv[ic[2]]);
57  bool parallel;
58  const HepGeom::Point3D<double> pt(line.point(pl, parallel));
59  LogDebug("CaloCellCrossing") << "***Face: " << face << ", pt=" << pt;
60  if (!parallel) {
61  LogDebug("CaloCellCrossing") << "Not parallel";
62  const HepLine3D la(cv[ic[0]], cv[ic[1]], eps);
63  const HepLine3D lb(cv[ic[2]], cv[ic[3]], eps);
64  LogDebug("CaloCellCrossing") << "la.point=" << la.point(pt);
65 
66  // const double dot ( ( la.point( pt ) - pt ).dot( ( lb.point( pt ) - pt ) ) ) ;
67  // LogDebug("CaloCellCrossing")<<"***Dot1="<<dot;
68  if (eps > (la.point(pt) - pt).dot((lb.point(pt) - pt))) {
69  const HepLine3D lc(cv[ic[0]], cv[ic[3]], eps);
70  const HepLine3D ld(cv[ic[1]], cv[ic[2]], eps);
71  // const double dot ( ( lc.point( pt ) - pt ).dot( ( ld.point( pt ) - pt ) ) ) ;
72  // LogDebug("CaloCellCrossing")<<"***Dot2="<<dot;
73  if (eps > (lc.point(pt) - pt).dot((ld.point(pt) - pt))) {
74  if (0 == found) {
75  ++found;
76  m_detId.emplace_back(dId);
77  m_ctr.emplace_back(GlobalPoint(ctr.x(), ctr.y(), ctr.z()));
78  m_entr.emplace_back(GlobalPoint(pt.x(), pt.y(), pt.z()));
79  } else {
80  if (1 == found) {
81  ++found;
82  m_exit.emplace_back(GlobalPoint(pt.x(), pt.y(), pt.z()));
83  } else {
84  const double dist1(
85  (pt - HepGeom::Point3D<double>(m_entr.back().x(), m_entr.back().y(), m_entr.back().z())).mag());
86  const double dist2(
87  (pt - HepGeom::Point3D<double>(m_exit.back().x(), m_exit.back().y(), m_exit.back().z())).mag());
88  if (eps < dist1 && eps < dist2) {
89  edm::LogWarning("CaloCellCrossing")
90  << "********For DetId = " << dId << " distances too big: " << dist1 << ", " << dist2;
91  }
92  }
93  }
94  }
95  }
96  }
97  }
98  }
99  }
100  assert(2 >= found);
101  if (1 == found)
102  m_exit.emplace_back(m_entr.back());
103  }
104  //------------------------------------------------------------
105  assert(m_detId.size() == m_entr.size() && m_detId.size() == m_ctr.size() && m_detId.size() == m_exit.size());
106 
107  m_len.reserve(m_entr.size());
108  for (unsigned int i(0); i != m_entr.size(); ++i) {
109  m_len.emplace_back((m_exit[i] - m_entr[i]).mag());
110  }
111 }
double dist2(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:65
WorkSpace int float eps
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:60
const HepGeom::Vector3D< double > & uv() const
Definition: Line3D.h:50
assert(be >=bs)
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
dictionary cv
Definition: cuy.py:363
double dist(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:66
CaloCellCrossing(const GlobalPoint &gp, const GlobalVector &gv, const DetIds *di, const CaloSubdetectorGeometry *sg, DetId::Detector det, int subdet, double small=1.e-10, bool onewayonly=false)
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Detector
Definition: DetId.h:24
HepGeom::Point3D< double > point(const HepGeom::Plane3D< double > &pl, bool &parallel) const
Definition: Line3D.h:52
std::vector< DetId > DetIds
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
const HepGeom::Point3D< double > & pt() const
Definition: Line3D.h:48
Log< level::Warning, false > LogWarning
T x() const
Definition: PV3DBase.h:59
#define LogDebug(id)