Belle II Software light-2406-ragdoll
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
20using namespace Belle2;
21
23 m_pdg(0), m_pValue(0),
24 m_hitPatternCDCInitializer(0),
25 m_hitPatternVXDInitializer(0),
26 m_NDF100(c_NDFFlag)
27{
28 memset(m_tau, 0, sizeof(m_tau));
29 memset(m_cov5, 0, sizeof(m_cov5));
30}
31
32TrackFitResult::TrackFitResult(const ROOT::Math::XYZVector& position, const ROOT::Math::XYZVector& 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 float NDF) :
39 m_pdg(std::abs(particleType.getPDGCode())), m_pValue(pValue),
40 m_hitPatternCDCInitializer(hitPatternCDCInitializer),
41 m_hitPatternVXDInitializer(hitPatternVXDInitializer),
42 m_NDF100(int(NDF * 100.))
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
63TrackFitResult::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 float NDF) :
68 m_pdg(std::abs(particleType.getPDGCode())), m_pValue(pValue),
69 m_hitPatternCDCInitializer(hitPatternCDCInitializer),
70 m_hitPatternVXDInitializer(hitPatternVXDInitializer),
71 m_NDF100(int(NDF * 100.))
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 // skip self-assigns
86 if (this == &input) return;
87 m_pdg = input.m_pdg;
88 m_pValue = input.m_pValue;
89 m_NDF100 = input.m_NDF100;
90 m_hitPatternCDCInitializer = input.m_hitPatternCDCInitializer;
91 m_hitPatternVXDInitializer = input.m_hitPatternVXDInitializer;
92
93 std::copy(std::begin(input.m_tau), std::end(input.m_tau), std::begin(this->m_tau));
94
95 std::copy(std::begin(input.m_cov5), std::end(input.m_cov5), std::begin(this->m_cov5));
96
97}
98
100{
101 if (m_NDF100 == c_NDFFlag) {
102 return -1;
103 }
104 return (float)m_NDF100 / 100;
105}
106
108{
109 double pValue = getPValue();
110 float nDF = getNDF();
111 if (pValue == 0) {
112 return std::numeric_limits<double>::infinity();
113 }
114 if (nDF <= 0) {
115 return std::numeric_limits<double>::quiet_NaN();
116 }
117 return 2 * boost::math::gamma_q_inv(nDF / 2., pValue);
118}
119
121{
122 TMatrixDSym cov5(c_NPars);
123 unsigned int counter = 0;
124 for (unsigned int i = 0; i < c_NPars; ++i) {
125 for (unsigned int j = i; j < c_NPars; ++j) {
126 cov5(i, j) = cov5(j, i) = m_cov5[counter];
127 ++counter;
128 }
129 }
130 assert(counter == c_NCovEntries);
131 return cov5;
132}
133
135{
137}
138
140{
142}
144{
145 std::stringstream out;
146 out << "<b>Fit Hypothesis (PDG)</b>: " << m_pdg << "<br>";
147 out << "<b>nPXDHits</b>: " << getHitPatternVXD().getNPXDHits() << "<br>";
148 out << "<b>nSVDHits</b>: " << getHitPatternVXD().getNSVDHits() << "<br>";
149 out << "<b>nCDCHits</b>: " << getHitPatternCDC().getNHits() << "<br>";
150 out << "<b>NDF</b>: " << getNDF() << "<br>";
151 out << " <br>";
152 out << "<b>d0</b>: " << m_tau[iD0] << " cm <br>";
153 out << "<b>phi0</b>: " << m_tau[iPhi0] << " rad <br>";
154 out << "<b>omega</b>: " << m_tau[iOmega] << " 1/GeV<br>";
155 out << "<b>z0</b>: " << m_tau[iZ0] << " cm <br>";
156 out << "<b>tanLambda</b>: " << m_tau[iTanLambda] << "<br>";
157 out << " <br>";
158 out << "<b>Covariance Matrix (d0, phi0, omega, z0, tanLambda)</b>: " << HTML::getString(getCovariance5()) << "<br>";
159 out << "<b>pValue</b>: " << m_pValue << "<br>";
160 return out.str();
161}
The ParticleType class for identifying different particle types.
Definition: Const.h:408
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.
Values of the result of a track fit with a given particle hypothesis.
static const unsigned int c_NPars
Number of helix parameters.
TMatrixDSym getCovariance5() const
Getter for covariance matrix of perigee parameters in matrix form.
uint32_t m_hitPatternVXDInitializer
Member for initializing the information about hits in the VXD.
static const unsigned int iZ0
Index for z0.
static const unsigned int c_NCovEntries
Number of covariance entries.
float getNDF() const
Getter for number of degrees of freedom of the track fit.
unsigned int m_pdg
PDG Code for hypothesis with which the corresponding fit was performed.
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.
Double32_t m_pValue
Chi2 Probability of the fit.
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
uint16_t m_NDF100
Member for number of degrees of freedom multiplied by 100 in order to store inside an int a float wit...
void updateTrackFitResult(const TrackFitResult &input)
update the TrackFitResults
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
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;.
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:24
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.