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/gearbox/Const.h>
10
11#include <TMatrixD.h>
12#include <TMatrixDSym.h>
13#include <TVector3.h>
14#include <TRandom3.h>
15
16#include <vector>
17
18#include <gtest/gtest.h>
19
20using namespace std;
21
22namespace Belle2 {
31 class TrackFitResultTest : public ::testing::Test {
32 protected:
33 };
34
36 TEST_F(TrackFitResultTest, Getters)
37 {
38 TRandom3 generator;
39 unsigned int nCases = 1;
40 double absError = 1e-6;
41 double bField = 1.5;
42
43 for (unsigned int i = 0; i < nCases; ++i) {
44
45 short int charge = generator.Uniform(-1, 1) > 0 ? 1 : -1;
47 float pValue = 0.45;
48
49 // Generate a random put orthogonal pair of vectors in the r-phi plane
50 TVector2 d(generator.Uniform(-1, 1), generator.Uniform(-1, 1));
51 TVector2 pt(generator.Uniform(-1, 1), generator.Uniform(-1, 1));
52 d.Set(d.X(), -(d.X()*pt.Px()) / pt.Py());
53 // Add a random z component
54 ROOT::Math::XYZVector position(d.X(), d.Y(), generator.Uniform(-1, 1));
55 ROOT::Math::XYZVector momentum(pt.Px(), pt.Py(), generator.Uniform(-1, 1));
56
57 TMatrixDSym cov6(6);
58
59 // Set up class for testing
60 TrackFitResult myResult(position, momentum, cov6, charge, pType, pValue, bField, 0, 0, 0);
61
62 // Test all vector elements
63 EXPECT_NEAR(position.X(), myResult.getPosition().X(), absError);
64 EXPECT_NEAR(position.Y(), myResult.getPosition().Y(), absError);
65 EXPECT_NEAR(position.Z(), myResult.getPosition().Z(), absError);
66 EXPECT_NEAR(momentum.X(), myResult.getMomentum().X(), absError);
67 EXPECT_NEAR(momentum.Y(), myResult.getMomentum().Y(), absError);
68 EXPECT_NEAR(momentum.Z(), myResult.getMomentum().Z(), absError);
69
70 // Test getter for transverse momentum
71 EXPECT_NEAR(momentum.Rho(), myResult.getTransverseMomentum(), absError);
72
73 // Test other variables
74 EXPECT_EQ(charge, myResult.getChargeSign());
75 EXPECT_EQ(pValue, myResult.getPValue());
76 EXPECT_EQ(pType, myResult.getParticleType());
77
78 }
79 } // Testcases for getters
80
82 TEST_F(TrackFitResultTest, ErrorPropagation)
83 {
84 TRandom3 generator;
85 unsigned int nCases = 1;
86 double absError = 1e-6;
87
88 for (unsigned int iCase = 0; iCase < nCases; ++iCase) {
89
90 auto bField = 1.5;
91 auto pType = Belle2::Const::electron;
92 auto pValue = 0.45;
93 std::vector<float> tau;
94 for (int i = 0; i < 5; ++i) {
95 // does not matter what is appended here, we only test the cov matrix
96 tau.push_back(1);
97 }
98 std::vector<float> cov(15);
99 for (auto& element : cov) {
100 element = generator.Gaus(1e-4);
101 }
102 Belle2::TrackFitResult myResult(tau, cov, pType, pValue, 0, 0, 0);
103 TMatrixDSym covariance(myResult.getCovariance6());
104
105 for (int i = 0; i < 5; ++i)
106 for (int j = i; j < 5; ++j)
107 EXPECT_EQ(covariance(i, j), covariance(j, i));
108
109 TMatrixDSym cov6(6);
110 for (unsigned int row = 0; row < 6; ++row) {
111 for (unsigned int col = 0; col < 6; ++col) {
112 cov6(row, col) = covariance(row, col);
113 }
114 }
115 Belle2::TrackFitResult myResult2(myResult.getPosition(), myResult.getMomentum(), cov6,
116 myResult.getChargeSign(), pType, pValue, bField, 0, 0, 0);
117
118 TMatrixDSym myResultCov5 = myResult.getCovariance5();
119 TMatrixDSym myResult2Cov5 = myResult2.getCovariance5();
120
121 EXPECT_NEAR(myResultCov5(0, 0), myResult2Cov5(0, 0), absError);
122 EXPECT_NEAR(myResultCov5(0, 1), myResult2Cov5(0, 1), absError);
123 EXPECT_NEAR(myResultCov5(0, 2), myResult2Cov5(0, 2), absError);
124 EXPECT_NEAR(myResultCov5(0, 3), myResult2Cov5(0, 3), absError);
125 EXPECT_NEAR(myResultCov5(0, 4), myResult2Cov5(0, 4), absError);
126 EXPECT_NEAR(myResultCov5(1, 0), myResult2Cov5(1, 0), absError);
127 EXPECT_NEAR(myResultCov5(1, 1), myResult2Cov5(1, 1), absError);
128 EXPECT_NEAR(myResultCov5(1, 2), myResult2Cov5(1, 2), absError);
129 EXPECT_NEAR(myResultCov5(1, 3), myResult2Cov5(1, 3), absError);
130 EXPECT_NEAR(myResultCov5(1, 4), myResult2Cov5(1, 4), absError);
131 EXPECT_NEAR(myResultCov5(2, 0), myResult2Cov5(2, 0), absError);
132 EXPECT_NEAR(myResultCov5(2, 1), myResult2Cov5(2, 1), absError);
133 EXPECT_NEAR(myResultCov5(2, 2), myResult2Cov5(2, 2), absError);
134 EXPECT_NEAR(myResultCov5(2, 3), myResult2Cov5(2, 3), absError);
135 EXPECT_NEAR(myResultCov5(2, 4), myResult2Cov5(2, 4), absError);
136 EXPECT_NEAR(myResultCov5(3, 0), myResult2Cov5(3, 0), absError);
137 EXPECT_NEAR(myResultCov5(3, 1), myResult2Cov5(3, 1), absError);
138 EXPECT_NEAR(myResultCov5(3, 2), myResult2Cov5(3, 2), absError);
139 EXPECT_NEAR(myResultCov5(3, 3), myResult2Cov5(3, 3), absError);
140 EXPECT_NEAR(myResultCov5(3, 4), myResult2Cov5(3, 4), absError);
141 EXPECT_NEAR(myResultCov5(4, 0), myResult2Cov5(4, 0), absError);
142 EXPECT_NEAR(myResultCov5(4, 1), myResult2Cov5(4, 1), absError);
143 EXPECT_NEAR(myResultCov5(4, 2), myResult2Cov5(4, 2), absError);
144 EXPECT_NEAR(myResultCov5(4, 3), myResult2Cov5(4, 3), absError);
145 EXPECT_NEAR(myResultCov5(4, 4), myResult2Cov5(4, 4), absError);
146
147 }
148 } // Testcases error propagation
149
151 TEST_F(TrackFitResultTest, Charge)
152 {
153 auto bField = 1.5;
154 auto pValue = 0.45;
155 ROOT::Math::XYZVector position(0., 0., 0.);
156 ROOT::Math::XYZVector momentum(1., 1., 1.);
157 TMatrixDSym cov6(6);
158 auto pType = Belle2::Const::electron;
159
160 auto charge = -1.0;
161 Belle2::TrackFitResult myResultMinus(position, momentum, cov6, charge, pType, pValue, bField, 0, 0, 0);
162 EXPECT_EQ(myResultMinus.getChargeSign(), charge);
163
164 charge = 0;
165 Belle2::TrackFitResult myResultNull(position, momentum, cov6, charge, pType, pValue, bField, 0, 0, 0);
166 EXPECT_EQ(myResultNull.getChargeSign(), charge);
167
168 charge = +1.0;
169 Belle2::TrackFitResult myResultPlus(position, momentum, cov6, charge, pType, pValue, bField, 0, 0, 0);
170 EXPECT_EQ(myResultPlus.getChargeSign(), charge);
171 }
172
173
175} // namespace
The ParticleType class for identifying different particle types.
Definition: Const.h:408
static const ChargedStable electron
electron particle
Definition: Const.h:659
Set up a few arrays and objects in the datastore.
Values of the result of a track fit with a given particle hypothesis.
TMatrixDSym getCovariance5() const
Getter for covariance matrix of perigee parameters in matrix form.
short getChargeSign() const
Return track charge (1 or -1).
double getPValue() const
Getter for Chi2 Probability of the track fit.
TMatrixDSym getCovariance6() const
Position and Momentum Covariance Matrix.
double getTransverseMomentum() const
Getter for the absolute value of the transverse momentum at the perigee.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
ROOT::Math::XYZVector getPosition() const
Getter for vector of position at closest approach of track in r/phi projection.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.