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