CMS 3D CMS Logo

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 ) ,
14  m_gv ( gv )
15 {
16  const double eps ( fabs( small ) > 1.e-15 ? fabs( small ) : 1.e-10 ) ;
17  static unsigned int k_rlen ( 30 ) ;
18  m_detId.reserve( k_rlen ) ;
19  m_ctr .reserve( k_rlen ) ;
20  m_entr .reserve( k_rlen ) ;
21  m_exit .reserve( k_rlen ) ;
22 //------------------------------------------------------------
23  const HepLine3D line ( HepGeom::Point3D<double> ( gp.x(), gp.y(), gp.z() ),
24  HepGeom::Vector3D<double> ( gv.x(), gv.y(), gv.z() ), eps ) ;
25 
26  LogDebug("CaloCellCrossing") << "*** Line: pt=" << line.pt() << ", unitvec=" << line.uv();
27 
28  const DetIds& ids ( nullptr == di ? sg->getValidDetIds( det, subdet ) : *di ) ;
29 //------------------------------------------------------------
30  for(auto dId : ids)
31  {
32  unsigned int found ( 0 ) ;
33  auto cg = sg->getGeometry( dId );
34  const CaloCellGeometry::CornersVec& gc ( cg->getCorners() ) ;
35  const HepGeom::Point3D<double> fr ( cg->getPosition().x(),
36  cg->getPosition().y(),
37  cg->getPosition().z() ) ;
38  const double bCut2 ( ( gc[0] - gc[6] ).mag2() ) ;
39 
40  if( ( !onewayonly ||
41  eps < HepGeom::Vector3D<double> ( fr - line.pt() ).dot( line.uv() ) ) &&
42  bCut2 > line.dist2( fr ) ) // first loose cut
43  {
44  LogDebug("CaloCellCrossing") << "*** fr=" << fr << ", bCut =" << sqrt(bCut2) << ", dis=" << line.dist(fr);
45  const HepGeom::Point3D<double> cv[8] =
46  { HepGeom::Point3D<double> ( gc[0].x(), gc[0].y(), gc[0].z() ) ,
47  HepGeom::Point3D<double> ( gc[1].x(), gc[1].y(), gc[1].z() ) ,
48  HepGeom::Point3D<double> ( gc[2].x(), gc[2].y(), gc[2].z() ) ,
49  HepGeom::Point3D<double> ( gc[3].x(), gc[3].y(), gc[3].z() ) ,
50  HepGeom::Point3D<double> ( gc[4].x(), gc[4].y(), gc[4].z() ) ,
51  HepGeom::Point3D<double> ( gc[5].x(), gc[5].y(), gc[5].z() ) ,
52  HepGeom::Point3D<double> ( gc[6].x(), gc[6].y(), gc[6].z() ) ,
53  HepGeom::Point3D<double> ( gc[7].x(), gc[7].y(), gc[7].z() ) } ;
54  const HepGeom::Point3D<double> ctr ( 0.125*(cv[0]+cv[1]+cv[2]+cv[3]+
55  cv[4]+cv[5]+cv[6]+cv[7]) ) ;
56  const double dCut2 ( bCut2/4. ) ;
57  if( dCut2 > line.dist2( ctr ) ) // tighter cut
58  {
59  LogDebug("CaloCellCrossing") << "** 2nd cut: ctr=" << ctr
60  << ", dist=" << line.dist(ctr);
61  static const unsigned int nc[6][4] =
62  { { 0,1,2,3 }, { 0,4,5,1 }, { 0,4,7,3 },
63  { 6,7,4,5 }, { 6,2,3,7 }, { 6,2,1,5 } } ;
64  for( unsigned int face ( 0 ) ; face != 6 ; ++face )
65  {
66  const unsigned int* ic ( &nc[face][0] ) ;
67  const HepGeom::Plane3D<double> pl ( cv[ic[0]], cv[ic[1]], cv[ic[2]] ) ;
68  bool parallel ;
69  const HepGeom::Point3D<double> pt ( line.point( pl, parallel ) ) ;
70  LogDebug("CaloCellCrossing")<<"***Face: "<<face<<", pt="<<pt;
71  if( !parallel )
72  {
73  LogDebug("CaloCellCrossing")<<"Not parallel";
74  const HepLine3D la ( cv[ic[0]], cv[ic[1]], eps ) ;
75  const HepLine3D lb ( cv[ic[2]], cv[ic[3]], eps ) ;
76  LogDebug("CaloCellCrossing")<<"la.point="<<la.point(pt);
77 
78 // const double dot ( ( la.point( pt ) - pt ).dot( ( lb.point( pt ) - pt ) ) ) ;
79 // LogDebug("CaloCellCrossing")<<"***Dot1="<<dot;
80  if( eps > ( la.point( pt ) - pt ).dot( ( lb.point( pt ) - pt ) ) )
81  {
82  const HepLine3D lc ( cv[ic[0]], cv[ic[3]], eps ) ;
83  const HepLine3D ld ( cv[ic[1]], cv[ic[2]], eps ) ;
84 // const double dot ( ( lc.point( pt ) - pt ).dot( ( ld.point( pt ) - pt ) ) ) ;
85 // LogDebug("CaloCellCrossing")<<"***Dot2="<<dot;
86  if( eps > ( lc.point( pt ) - pt ).dot( ( ld.point( pt ) - pt ) ) )
87  {
88  if( 0 == found )
89  {
90  ++found ;
91  m_detId.emplace_back( dId ) ;
92  m_ctr .emplace_back( GlobalPoint( ctr.x(), ctr.y(), ctr.z() ) ) ;
93  m_entr.emplace_back( GlobalPoint( pt.x(), pt.y(), pt.z() ) ) ;
94  }
95  else
96  {
97  if( 1 == found )
98  {
99  ++found ;
100  m_exit.emplace_back( GlobalPoint( pt.x(), pt.y(), pt.z() ) ) ;
101  }
102  else
103  {
104  const double dist1 (
105  ( pt - HepGeom::Point3D<double> ( m_entr.back().x(),
106  m_entr.back().y(),
107  m_entr.back().z() ) ).mag() ) ;
108  const double dist2 (
109  ( pt - HepGeom::Point3D<double> ( m_exit.back().x(),
110  m_exit.back().y(),
111  m_exit.back().z() ) ).mag() ) ;
112  if( eps < dist1 &&
113  eps < dist2 )
114  {
115  edm::LogWarning("CaloCellCrossing") << "********For DetId = " << dId
116  << " distances too big: "
117  << dist1 << ", " << dist2;
118 
119  }
120  }
121  }
122  }
123  }
124  }
125  }
126  }
127  }
128  assert( 2 >= found ) ;
129  if( 1 == found ) m_exit.emplace_back( m_entr.back() ) ;
130  }
131 //------------------------------------------------------------
132  assert( m_detId.size() == m_entr.size() &&
133  m_detId.size() == m_ctr .size() &&
134  m_detId.size() == m_exit.size() ) ;
135 
136  m_len.reserve( m_entr.size() ) ;
137  for( unsigned int i ( 0 ) ; i != m_entr.size() ; ++i )
138  {
139  m_len.emplace_back( ( m_exit[i] - m_entr[i] ).mag() ) ;
140  }
141 }
142 
#define LogDebug(id)
double dist2(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:90
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
cv
Definition: cuy.py:363
const HepGeom::Vector3D< double > & uv() const
Definition: Line3D.h:71
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:18
T z() const
Definition: PV3DBase.h:64
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
double dist(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:91
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:26
HepGeom::Point3D< double > point(const HepGeom::Plane3D< double > &pl, bool &parallel) const
Definition: Line3D.h:73
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
const HepGeom::Point3D< double > & pt() const
Definition: Line3D.h:69
T x() const
Definition: PV3DBase.h:62
std::vector< DetId > DetIds