PandaRoot
LineTool.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 // ******************************************************
14 // DecayTreeFitter Package
15 // We thank the original author Wouter Hulsbergen
16 // (BaBar, LHCb) for providing the sources.
17 // http://arxiv.org/abs/physics/0503191v1 (2005)
18 // Adaptation & Development for PANDA: Ralf Kliemt (2015)
19 // ******************************************************
20 //
21 // LineTool.h
22 // TreeFitter
23 //
24 // Created by Ralf Kliemt on 26/01/15.
25 // Copyright (c) 2015 Ralf Kliemt. All rights reserved.
26 //
27 
28 #ifndef TreeFitter_LineTool_h
29 #define TreeFitter_LineTool_h 1
30 
31 #include "TVector3.h"
32 #include <iostream>
33 #include <cmath>
34 #include "Rtypes.h"
35 
36 namespace DecayTreeFitter {
37 // ==========================================================================
38 class Line {
39  public:
40  Line() {}
41  Line(const TVector3 &p0, const TVector3 &v0) : m_p0(p0), m_v0(v0) {}
42  virtual ~Line(){};
43 
44  const TVector3 &beginPoint() const { return m_p0; }
45  const TVector3 &direction() const { return m_v0; }
46  TVector3 position(const double mu) const { return beginPoint() + direction() * (float)mu; }
47  TVector3 operator()(const double mu) const { return beginPoint() + direction() * (float)mu; }
48 
49  public:
50  inline std::ostream &fillStream(std::ostream &os) const
51  {
52  os << "\np0 (" << m_p0.x() << " " << m_p0.y() << " " << m_p0.z() << ") direction (" << m_v0.x() << " " << m_v0.y() << " " << m_v0.z() << ")\n" << std::endl;
53  return os;
54  }
55 
56  private:
57  TVector3 m_p0; // the start point on the line
58  TVector3 m_v0; // the direction vector of the line
59  ClassDef(Line, 1);
60 };
61 
62 // =========================================================================
63 inline std::ostream &operator<<(std::ostream &os, const Line &rhs)
64 {
65  return rhs.fillStream(os);
66 }
67 
68 // ==========================================================================
69 // ==========================================================================
70 inline bool closestPointParams(const Line &line0, const Line &line1, double &mu0, 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  OK = false; // parallel
86  } else {
87 
88  const double detinv = 1.0 / det;
89 
90  // rhs:
91  const TVector3 p1_p0 = line1.beginPoint() - line0.beginPoint();
92 
93  const double b0 = p1_p0.Dot(line0.direction());
94  const double b1 = p1_p0.Dot(line1.direction());
95 
96  // get the Kramer solutions:
97 
98  mu0 = (b0 * a11 - b1 * a01) * detinv;
99  mu1 = (a00 * b1 - a10 * b0) * detinv;
100  }
101 
102  return OK;
103 }
104 
105 // ==========================================================================
106 // ==========================================================================
107 
108 } // namespace DecayTreeFitter
109 #endif
TVector3 position(const double mu) const
Definition: LineTool.h:46
std::ostream & fillStream(std::ostream &os) const
Definition: LineTool.h:50
std::ostream & operator<<(std::ostream &os, const Line &rhs)
Definition: LineTool.h:63
const TVector3 & beginPoint() const
Definition: LineTool.h:44
Line(const TVector3 &p0, const TVector3 &v0)
Definition: LineTool.h:41
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:58
const TVector3 & direction() const
Definition: LineTool.h:45
TVector3 operator()(const double mu) const
Definition: LineTool.h:47
bool closestPointParams(const Line &line0, const Line &line1, double &mu0, double &mu1)
Definition: LineTool.h:70