FairRoot/PandaRoot
LineTool.h
Go to the documentation of this file.
1 // ******************************************************
2 // DecayTreeFitter Package
3 // We thank the original author Wouter Hulsbergen
4 // (BaBar, LHCb) for providing the sources.
5 // http://arxiv.org/abs/physics/0503191v1 (2005)
6 // Adaptation & Development for PANDA: Ralf Kliemt (2015)
7 // ******************************************************
8 //
9 // LineTool.h
10 // TreeFitter
11 //
12 // Created by Ralf Kliemt on 26/01/15.
13 // Copyright (c) 2015 Ralf Kliemt. All rights reserved.
14 //
15 
16 #ifndef TreeFitter_LineTool_h
17 #define TreeFitter_LineTool_h 1
18 
19 #include "TVector3.h"
20 #include <iostream>
21 #include <cmath>
22 #include "Rtypes.h"
23 
24 namespace DecayTreeFitter
25 {
26  // ==========================================================================
27  class Line
28  {
29  public:
30  Line() {}
31  Line ( const TVector3& p0 , const TVector3& v0 ) : m_p0 ( p0 ) , m_v0 ( v0 ) {}
32  virtual ~Line(){};
33 
34  const TVector3& beginPoint() const { return m_p0 ; }
35  const TVector3& direction() const { return m_v0 ; }
36  TVector3 position ( const double mu ) const
37  { return beginPoint() + direction() * (float)mu ; }
38  TVector3 operator() ( const double mu ) const
39  { return beginPoint() + direction() * (float)mu ; }
40  public:
41  inline std::ostream& fillStream ( std::ostream& os ) const
42  {
43  os << "\np0 ("
44  << m_p0.x() << " " << m_p0.y() << " " << m_p0.z()
45  << ") direction ("
46  << m_v0.x()<< " " << m_v0.y() << " " << m_v0.z() << ")\n"
47  << std::endl;
48  return os;
49  }
50  private:
51  TVector3 m_p0; // the start point on the line
52  TVector3 m_v0; // the direction vector of the line
53  ClassDef(Line,1);
54  };
55 
56  // =========================================================================
57  inline std::ostream& operator<<
58  (std::ostream& os ,
59  const Line& rhs )
60  {
61  return rhs.fillStream(os);
62  }
63 
64  // ==========================================================================
65  // ==========================================================================
66  inline bool closestPointParams
67  (const Line& line0 ,
68  const Line& line1 ,
69  double& mu0 ,
70  double& mu1 )
71  {
72  // lhs:
73 
74  bool OK = true;
75 
76  // the matrix:
77  const double a00 = line0.direction().Mag2() ;
78  const double a10 = line0.direction().Dot( line1.direction() ) ;
79  const double a01 = -a10 ;
80  const double a11 = -line1.direction().Mag2() ;
81 
82  // the inverse determinant:
83  const double det = ( a00 * a11 - a01 * a10 ) ; // det = -sin^2(angle(line0.dir,line1.dir))
84  if ( std::fabs(det) < 1e-10 )
85  {
86  OK = false; // parallel
87  }
88  else
89  {
90 
91  const double detinv = 1.0 / det;
92 
93  // rhs:
94  const TVector3 p1_p0 = line1.beginPoint() - line0.beginPoint() ;
95 
96  const double b0 = p1_p0.Dot ( line0.direction() ) ;
97  const double b1 = p1_p0.Dot ( line1.direction() ) ;
98 
99  // get the Kramer solutions:
100 
101  mu0 = ( b0 * a11 - b1 * a01 ) * detinv ;
102  mu1 = ( a00 * b1 - a10 * b0 ) * detinv ;
103 
104  }
105 
106  return OK ;
107  }
108 
109  // ==========================================================================
110  // ==========================================================================
111 
112 } //
113 #endif
double mu1
Definition: reco_analys2.C:56
TVector3 operator()(const double mu) const
Definition: LineTool.h:38
const TVector3 & direction() const
Definition: LineTool.h:35
Line(const TVector3 &p0, const TVector3 &v0)
Definition: LineTool.h:31
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
std::ostream & fillStream(std::ostream &os) const
Definition: LineTool.h:41
TVector3 position(const double mu) const
Definition: LineTool.h:36
bool closestPointParams(const Line &line0, const Line &line1, double &mu0, double &mu1)
Definition: LineTool.h:67
const TVector3 & beginPoint() const
Definition: LineTool.h:34