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 class Line {
27  public:
28  Line() {}
29  Line(const TVector3 &p0, const TVector3 &v0) : m_p0(p0), m_v0(v0) {}
30  virtual ~Line(){};
31 
32  const TVector3 &beginPoint() const { return m_p0; }
33  const TVector3 &direction() const { return m_v0; }
34  TVector3 position(const double mu) const { return beginPoint() + direction() * (float)mu; }
35  TVector3 operator()(const double mu) const { return beginPoint() + direction() * (float)mu; }
36 
37  public:
38  inline std::ostream &fillStream(std::ostream &os) const
39  {
40  os << "\np0 (" << m_p0.x() << " " << m_p0.y() << " " << m_p0.z() << ") direction (" << m_v0.x() << " " << m_v0.y() << " " << m_v0.z() << ")\n" << std::endl;
41  return os;
42  }
43 
44  private:
45  TVector3 m_p0; // the start point on the line
46  TVector3 m_v0; // the direction vector of the line
47  ClassDef(Line, 1);
48 };
49 
50 // =========================================================================
51 inline std::ostream &operator<<(std::ostream &os, const Line &rhs)
52 {
53  return rhs.fillStream(os);
54 }
55 
56 // ==========================================================================
57 // ==========================================================================
58 inline bool closestPointParams(const Line &line0, const Line &line1, double &mu0, double &mu1)
59 {
60  // lhs:
61 
62  bool OK = true;
63 
64  // the matrix:
65  const double a00 = line0.direction().Mag2();
66  const double a10 = line0.direction().Dot(line1.direction());
67  const double a01 = -a10;
68  const double a11 = -line1.direction().Mag2();
69 
70  // the inverse determinant:
71  const double det = (a00 * a11 - a01 * a10); // det = -sin^2(angle(line0.dir,line1.dir))
72  if (std::fabs(det) < 1e-10) {
73  OK = false; // parallel
74  } else {
75 
76  const double detinv = 1.0 / det;
77 
78  // rhs:
79  const TVector3 p1_p0 = line1.beginPoint() - line0.beginPoint();
80 
81  const double b0 = p1_p0.Dot(line0.direction());
82  const double b1 = p1_p0.Dot(line1.direction());
83 
84  // get the Kramer solutions:
85 
86  mu0 = (b0 * a11 - b1 * a01) * detinv;
87  mu1 = (a00 * b1 - a10 * b0) * detinv;
88  }
89 
90  return OK;
91 }
92 
93 // ==========================================================================
94 // ==========================================================================
95 
96 } // namespace DecayTreeFitter
97 #endif
TVector3 position(const double mu) const
Definition: LineTool.h:34
std::ostream & fillStream(std::ostream &os) const
Definition: LineTool.h:38
std::ostream & operator<<(std::ostream &os, const Line &rhs)
Definition: LineTool.h:51
const TVector3 & beginPoint() const
Definition: LineTool.h:32
Line(const TVector3 &p0, const TVector3 &v0)
Definition: LineTool.h:29
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:46
const TVector3 & direction() const
Definition: LineTool.h:33
TVector3 operator()(const double mu) const
Definition: LineTool.h:35
bool closestPointParams(const Line &line0, const Line &line1, double &mu0, double &mu1)
Definition: LineTool.h:58