CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloCellCrossing.cc
Go to the documentation of this file.
3 
5  const GlobalVector& gv ,
6  const CaloCellCrossing::DetIds* di ,
7  const CaloSubdetectorGeometry* sg ,
8  DetId::Detector det ,
9  int subdet,
10  double small,
11  bool onewayonly ) :
12  m_gp ( gp ) ,
13  m_gv ( gv )
14 {
15  const double eps ( fabs( small ) > 1.e-15 ? fabs( small ) : 1.e-10 ) ;
16  static unsigned int k_rlen ( 30 ) ;
17  m_detId.reserve( k_rlen ) ;
18  m_ctr .reserve( k_rlen ) ;
19  m_entr .reserve( k_rlen ) ;
20  m_exit .reserve( k_rlen ) ;
21 //------------------------------------------------------------
22  const HepLine3D line ( HepGeom::Point3D<double> ( gp.x(), gp.y(), gp.z() ),
23  HepGeom::Vector3D<double> ( gv.x(), gv.y(), gv.z() ), eps ) ;
24 
25 // std::cout<<"*** Line: pt="<<line.pt()<<", unitvec="<<line.uv()<<std::endl ;
26 
27  const DetIds& ids ( 0 == di ? sg->getValidDetIds( det, subdet ) : *di ) ;
28 //------------------------------------------------------------
29  for( DetIds::const_iterator id ( ids.begin() ) ; id != ids.end() ; ++id )
30  {
31  const DetId dId ( *id ) ;
32  unsigned int found ( 0 ) ;
33  const CaloCellGeometry& 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 // std::cout<<"*** fr="<<fr<<", bCut ="<<sqrt(bCut2)<<", dis="<<line.dist(fr)<<std::endl ;
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 // if( 1 > line.dist2( ctr ) ) // tighter cut
59  {
60 // std::cout<<"** 2nd cut: ctr="<<ctr
61 // <<", dist="<<line.dist(ctr)<<std::endl ;
62  static const unsigned int nc[6][4] =
63  { { 0,1,2,3 }, { 0,4,5,1 }, { 0,4,7,3 },
64  { 6,7,4,5 }, { 6,2,3,7 }, { 6,2,1,5 } } ;
65  for( unsigned int face ( 0 ) ; face != 6 ; ++face )
66  {
67  const unsigned int* ic ( &nc[face][0] ) ;
68  const HepGeom::Plane3D<double> pl ( cv[ic[0]], cv[ic[1]], cv[ic[2]] ) ;
69  bool parallel ;
70  const HepGeom::Point3D<double> pt ( line.point( pl, parallel ) ) ;
71 // std::cout<<"***Face: "<<face<<", pt="<<pt<<std::endl ;
72  if( !parallel )
73  {
74 // std::cout<<"Not parallel"<<std::endl ;
75  const HepLine3D la ( cv[ic[0]], cv[ic[1]], eps ) ;
76  const HepLine3D lb ( cv[ic[2]], cv[ic[3]], eps ) ;
77 
78 // std::cout<<"la.point="<<la.point(pt)<<std::endl ;
79 
80 // const double dot ( ( la.point( pt ) - pt ).dot( ( lb.point( pt ) - pt ) ) ) ;
81 // std::cout<<"***Dot1="<<dot<<std::endl;
82  if( eps > ( la.point( pt ) - pt ).dot( ( lb.point( pt ) - pt ) ) )
83  {
84  const HepLine3D lc ( cv[ic[0]], cv[ic[3]], eps ) ;
85  const HepLine3D ld ( cv[ic[1]], cv[ic[2]], eps ) ;
86 // const double dot ( ( lc.point( pt ) - pt ).dot( ( ld.point( pt ) - pt ) ) ) ;
87 // std::cout<<"***Dot2="<<dot<<std::endl;
88  if( eps > ( lc.point( pt ) - pt ).dot( ( ld.point( pt ) - pt ) ) )
89  {
90  if( 0 == found )
91  {
92  ++found ;
93  m_detId.push_back( dId ) ;
94  m_ctr .push_back( GlobalPoint( ctr.x(), ctr.y(), ctr.z() ) ) ;
95  m_entr.push_back( GlobalPoint( pt.x(), pt.y(), pt.z() ) ) ;
96  }
97  else
98  {
99  if( 1 == found )
100  {
101  ++found ;
102  m_exit.push_back( GlobalPoint( pt.x(), pt.y(), pt.z() ) ) ;
103  }
104  else
105  {
106  const double dist1 (
107  ( pt - HepGeom::Point3D<double> ( m_entr.back().x(),
108  m_entr.back().y(),
109  m_entr.back().z() ) ).mag() ) ;
110  const double dist2 (
111  ( pt - HepGeom::Point3D<double> ( m_exit.back().x(),
112  m_exit.back().y(),
113  m_exit.back().z() ) ).mag() ) ;
114  if( eps < dist1 &&
115  eps < dist2 )
116  {
117  std::cout << "********For DetId = " << dId
118  << " distances too big: "
119  << dist1 << ", " << dist2
120  << std::endl ;
121  }
122  }
123  }
124  }
125  }
126  }
127  }
128  }
129  }
130  assert( 2 >= found ) ;
131  if( 1 == found ) m_exit.push_back( m_entr.back() ) ;
132  }
133 //------------------------------------------------------------
134  assert( m_detId.size() == m_entr.size() &&
135  m_detId.size() == m_ctr .size() &&
136  m_detId.size() == m_exit.size() ) ;
137 
138  m_len.reserve( m_entr.size() ) ;
139  for( unsigned int i ( 0 ) ; i != m_entr.size() ; ++i )
140  {
141  m_len.push_back( ( m_exit[i] - m_entr[i] ).mag() ) ;
142  }
143 }
144 
int i
Definition: DBlmapReader.cc:9
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:62
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)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
T z() const
Definition: PV3DBase.h:63
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: DetId.h:20
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)
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 &quot;dot&quot; product, with a vector of same type.
const HepGeom::Point3D< double > & pt() const
Definition: Line3D.h:69
tuple cout
Definition: gather_cfg.py:121
x
Definition: VDTMath.h:216
T x() const
Definition: PV3DBase.h:61
std::vector< DetId > DetIds