Belle II Software  release-06-02-00
TrackFitResult.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <mdst/dataobjects/TrackFitResult.h>
9 #include <framework/dataobjects/UncertainHelix.h>
10 #include <mdst/dataobjects/HitPatternCDC.h>
11 #include <mdst/dataobjects/HitPatternVXD.h>
12 
13 #include <framework/utilities/HTML.h>
14 
15 #include <boost/math/special_functions/gamma.hpp>
16 
17 #include <sstream>
18 #include <assert.h>
19 
20 using namespace Belle2;
21 
23  m_pdg(0), m_pValue(0),
24  m_hitPatternCDCInitializer(0),
25  m_hitPatternVXDInitializer(0),
26  m_NDF(c_NDFFlag)
27 {
28  memset(m_tau, 0, sizeof(m_tau));
29  memset(m_cov5, 0, sizeof(m_cov5));
30 }
31 
32 TrackFitResult::TrackFitResult(const TVector3& position, const TVector3& momentum,
33  const TMatrixDSym& covariance, const short int charge,
34  const Const::ParticleType& particleType, const float pValue,
35  const float bField,
36  const uint64_t hitPatternCDCInitializer,
37  const uint32_t hitPatternVXDInitializer,
38  const uint16_t NDF) :
39  m_pdg(std::abs(particleType.getPDGCode())), m_pValue(pValue),
40  m_hitPatternCDCInitializer(hitPatternCDCInitializer),
41  m_hitPatternVXDInitializer(hitPatternVXDInitializer),
42  m_NDF(NDF)
43 {
44  UncertainHelix h(position, momentum, charge, bField, covariance, pValue);
45 
46  m_tau[iD0] = h.getD0();
47  m_tau[iPhi0] = h.getPhi0();
48  m_tau[iOmega] = h.getOmega();
49  m_tau[iZ0] = h.getZ0();
50  m_tau[iTanLambda] = h.getTanLambda();
51 
52  // Upper half of the covariance matrix goes into m_cov5.
53  const TMatrixDSym& cov = h.getCovariance();
54  unsigned int counter = 0;
55  for (unsigned int i = 0; i < c_NPars; ++i) {
56  for (unsigned int j = i; j < c_NPars; ++j) {
57  m_cov5[counter++] = cov(i, j);
58  }
59  }
60  assert(counter == c_NCovEntries);
61 }
62 
63 TrackFitResult::TrackFitResult(const std::vector<float>& tau, const std::vector<float>& cov5,
64  const Const::ParticleType& particleType, const float pValue,
65  const uint64_t hitPatternCDCInitializer,
66  const uint32_t hitPatternVXDInitializer,
67  const uint16_t NDF) :
68  m_pdg(std::abs(particleType.getPDGCode())), m_pValue(pValue),
69  m_hitPatternCDCInitializer(hitPatternCDCInitializer),
70  m_hitPatternVXDInitializer(hitPatternVXDInitializer),
71  m_NDF(NDF)
72 {
73  if (tau.size() != c_NPars
74  || cov5.size() != c_NCovEntries)
75  B2FATAL("Invalid initializer for TrackFitResult.");
76 
77  for (unsigned int i = 0; i < c_NPars; ++i)
78  m_tau[i] = tau[i];
79  for (unsigned int i = 0; i < c_NCovEntries; ++i)
80  m_cov5[i] = cov5[i];
81 }
82 
84 {
85  if (m_NDF == c_NDFFlag) {
86  return -1;
87  }
88  return m_NDF;
89 }
90 
92 {
93  double pValue = getPValue();
94  int nDF = getNDF();
95  if (pValue == 0) {
96  return std::numeric_limits<double>::infinity();
97  }
98  if (nDF < 0) {
99  return std::numeric_limits<double>::quiet_NaN();
100  }
101  return 2 * boost::math::gamma_q_inv(nDF / 2., pValue);
102 }
103 
105 {
106  TMatrixDSym cov5(c_NPars);
107  unsigned int counter = 0;
108  for (unsigned int i = 0; i < c_NPars; ++i) {
109  for (unsigned int j = i; j < c_NPars; ++j) {
110  cov5(i, j) = cov5(j, i) = m_cov5[counter];
111  ++counter;
112  }
113  }
114  assert(counter == c_NCovEntries);
115  return cov5;
116 }
117 
119 {
121 }
122 
124 {
126 }
127 std::string TrackFitResult::getInfoHTML() const
128 {
129  std::stringstream out;
130  out << "<b>Fit Hypothesis (PDG)</b>: " << m_pdg << "<br>";
131  out << "<b>nPXDHits</b>: " << getHitPatternVXD().getNPXDHits() << "<br>";
132  out << "<b>nSVDHits</b>: " << getHitPatternVXD().getNSVDHits() << "<br>";
133  out << "<b>nCDCHits</b>: " << getHitPatternCDC().getNHits() << "<br>";
134  out << "<b>NDF</b>: " << getNDF() << "<br>";
135  out << " <br>";
136  out << "<b>d0</b>: " << m_tau[iD0] << " cm <br>";
137  out << "<b>phi0</b>: " << m_tau[iPhi0] << " rad <br>";
138  out << "<b>omega</b>: " << m_tau[iOmega] << " 1/GeV<br>";
139  out << "<b>z0</b>: " << m_tau[iZ0] << " cm <br>";
140  out << "<b>tanLambda</b>: " << m_tau[iTanLambda] << "<br>";
141  out << " <br>";
142  out << "<b>Covariance Matrix (d0, phi0, omega, z0, tanLambda)</b>: " << HTML::getString(getCovariance5()) << "<br>";
143  out << "<b>pValue</b>: " << m_pValue << "<br>";
144  return out.str();
145 }
The ParticleType class for identifying different particle types.
Definition: Const.h:289
Hit pattern of CDC hits within a track.
Definition: HitPatternCDC.h:35
unsigned short getNHits() const
Get the total Number of CDC hits in the fit.
Hit pattern of the VXD within a track.
Definition: HitPatternVXD.h:37
unsigned short getNPXDHits() const
Get total number of hits in the PXD.
unsigned short getNSVDHits() const
Get total number of hits in the SVD.
static const unsigned int c_NPars
Number of helix parameters.
TMatrixDSym getCovariance5() const
Getter for covariance matrix of perigee parameters in matrix form.
static const unsigned int iZ0
Index for z0.
static const unsigned int c_NCovEntries
Number of covariance entries.
Double32_t m_tau[c_NPars]
perigee helix parameters; tau = d0, phi0, omega, z0, tanLambda.
double getChi2() const
Get chi2 given NDF and p-value.
double getPValue() const
Getter for Chi2 Probability of the track fit.
const uint32_t m_hitPatternVXDInitializer
Member for initializing the information about hits in the VXD.
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
int getNDF() const
Getter for number of degrees of freedom of the track fit.
const Double32_t m_pValue
Chi2 Probability of the fit.
static const unsigned int iTanLambda
Index tan lambda.
TrackFitResult()
Constructor initializing everything to zero.
static const unsigned int iD0
Index for d0.
uint64_t m_hitPatternCDCInitializer
Member for initializing the information about hits in the CDC.
static const unsigned int iOmega
Index for omega.
static const uint16_t c_NDFFlag
backward compatibility initialisation for NDF
uint16_t m_NDF
Memeber for number of degrees of freedom.
Double32_t m_cov5[c_NCovEntries]
The 15 = 5*(5+1)/2 covariance matrix elements.
static const unsigned int iPhi0
Index for phi0.
HitPatternCDC getHitPatternCDC() const
Getter for the hit pattern in the CDC;.
const unsigned int m_pdg
PDG Code for hypothesis with which the corresponding fit was performed.
HitPatternVXD getHitPatternVXD() const
Getter for the hit pattern in the VXD;.
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
std::string getString(const TMatrixFBase &matrix, int precision=2, bool color=true)
get HTML table representing a matrix.
Definition: HTML.cc:25
Abstract base class for different kinds of events.