Belle II Software development
track.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/Track.h>
9#include <mdst/dataobjects/TrackFitResult.h>
10#include <framework/gearbox/Const.h>
11#include <framework/datastore/StoreArray.h>
12#include <gtest/gtest.h>
13
14#include <algorithm>
15
16using namespace std;
17
18namespace Belle2 {
28 class TrackTest : public ::testing::Test {
29 protected:
30 };
31
36 {
37 const ROOT::Math::XYZVector dummyVector3;
38 const TMatrixDSym dummyMatrix(6);
39 const int charge = 1;
40 const float pValue = 1.;
41 const float bField = 1.5;
42
43 const auto newFitRes = trackFitResults.appendNew(dummyVector3, dummyVector3, dummyMatrix, charge, particeType, pValue,
44 bField, 0, 0, 0);
45 return newFitRes;
46 }
47
50 TEST_F(TrackTest, settersNGetters)
51 {
52 //Create some TrackFitResults in the the DataStore.
53 //PDGCode of the TrackFitResult will be used in the test to identify the TFR.
56 myResults.registerInDataStore();
57
58 const auto myPion = addDummyTrack(myResults, Const::pion);
59 const auto myKaon = addDummyTrack(myResults, Const::kaon);
60 const auto myElectron = addDummyTrack(myResults, Const::electron);
61 const auto myMuon = addDummyTrack(myResults, Const::muon);
62
63 EXPECT_EQ(myPion->getArrayIndex(), 0);
64 EXPECT_EQ(myKaon->getArrayIndex(), 1);
65 EXPECT_EQ(myElectron->getArrayIndex(), 2);
66 EXPECT_EQ(myMuon->getArrayIndex(), 3);
67
68 Track mytrack1;
69 mytrack1.setTrackFitResultIndex(Const::pion, myPion->getArrayIndex());
70 mytrack1.setTrackFitResultIndex(Const::muon, myMuon->getArrayIndex());
71 mytrack1.setTrackFitResultIndex(Const::kaon, myKaon->getArrayIndex());
72
73 EXPECT_EQ(mytrack1.getNumberOfFittedHypotheses(), 3);
74 // If the index of the corresponding particle is set, the correct particle should be returned.
78 // If the index of the corresponding particle is *not* set, a nullptr should be returned.
79 EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron), nullptr);
80
81 // If the index of the corresponding particle is set, the correct particle should be returned.
82 EXPECT_EQ(mytrack1.getTrackFitResult(Const::pion)->getArrayIndex(), myPion->getArrayIndex());
83 EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getArrayIndex(), myKaon->getArrayIndex());
84 EXPECT_EQ(mytrack1.getTrackFitResult(Const::muon)->getArrayIndex(), myMuon->getArrayIndex());
85 // If the index of the corresponding particle is *not* set, a nullptr should be returned.
86 EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron), nullptr);
87
88 const auto allResults = mytrack1.getTrackFitResults();
89 // should return all hypothesis which were added before
90 EXPECT_EQ(allResults.size(), 3);
91
92 // check that all correct hypothesis are returned and the electron is not
93 auto countPion = std::count_if(allResults.begin(), allResults.end(),
94 [myPion](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
95 {return (fitPair.first == Const::pion) && (fitPair.second->getArrayIndex() == myPion->getArrayIndex());});
96 auto countMuon = std::count_if(allResults.begin(), allResults.end(),
97 [myMuon](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
98 {return (fitPair.first == Const::muon) && (fitPair.second->getArrayIndex() == myMuon->getArrayIndex());});
99 auto countElectron = std::count_if(allResults.begin(), allResults.end(),
100 [](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
101 {return fitPair.first == Const::electron;});
102 auto countKaon = std::count_if(allResults.begin(), allResults.end(),
103 [myKaon](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
104 {return (fitPair.first == Const::kaon) && (fitPair.second->getArrayIndex() == myKaon->getArrayIndex());});
105
106 EXPECT_EQ(countPion, 1);
107 EXPECT_EQ(countMuon, 1);
108 EXPECT_EQ(countElectron, 0);
109 EXPECT_EQ(countKaon, 1);
110
111 Track trackQITest;
112 EXPECT_EQ(trackQITest.getQualityIndicator(), 0.);
113 Track trackQITest1(0.5);
114 EXPECT_EQ(trackQITest1.getQualityIndicator(), 0.5);
115 }
116
119 TEST_F(TrackTest, getTrackFitResultWithClosestMass)
120 {
121 //Create some TrackFitResults in the the DataStore.
122 //PDGCode of the TrackFitResult will be used in the test to identify the TFR.
125 myResults.registerInDataStore();
126
127 // add two fit results
128 const auto myKaon = addDummyTrack(myResults, Const::kaon);
129 const auto myElectron = addDummyTrack(myResults, Const::electron);
130
131 Track mytrack1;
132 mytrack1.setTrackFitResultIndex(Const::electron, myElectron->getArrayIndex());
133 mytrack1.setTrackFitResultIndex(Const::kaon, myKaon->getArrayIndex());
134
135 EXPECT_EQ(mytrack1.getNumberOfFittedHypotheses(), 2);
136
137 // check for correct hypothesis if we request a fitted particle
138 const auto fitCloseToKaonMass = mytrack1.getTrackFitResultWithClosestMass(Const::kaon);
139 EXPECT_EQ(Const::kaon.getPDGCode(), fitCloseToKaonMass->getParticleType().getPDGCode());
140 EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getArrayIndex(), fitCloseToKaonMass->getArrayIndex());
141
142 // check to get Pion fit
143 const auto wantPionButHaveElectronFit = mytrack1.getTrackFitResultWithClosestMass(Const::pion);
144 EXPECT_EQ(Const::electron.getPDGCode(), wantPionButHaveElectronFit->getParticleType().getPDGCode());
145 EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron)->getArrayIndex(), wantPionButHaveElectronFit->getArrayIndex());
146
147 // check to get Electron fit
148 const auto wantMuonButHaveElectronFit = mytrack1.getTrackFitResultWithClosestMass(Const::muon);
149 EXPECT_EQ(Const::electron.getPDGCode(), wantMuonButHaveElectronFit->getParticleType().getPDGCode());
150 EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron)->getArrayIndex(), wantMuonButHaveElectronFit->getArrayIndex());
151
152 // check to get Proton fit
153 const auto wantProtonButHaveKaonFit = mytrack1.getTrackFitResultWithClosestMass(Const::proton);
154 EXPECT_EQ(Const::kaon.getPDGCode(), wantProtonButHaveKaonFit->getParticleType().getPDGCode());
155 EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getArrayIndex(), wantProtonButHaveKaonFit->getArrayIndex());
156
157 }
159} // namespace
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ChargedStable muon
muon particle
Definition: Const.h:660
static const ChargedStable pion
charged pion particle
Definition: Const.h:661
static const ChargedStable proton
proton particle
Definition: Const.h:663
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:662
static const ChargedStable electron
electron particle
Definition: Const.h:659
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
Values of the result of a track fit with a given particle hypothesis.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
Test class for the Track object.
Definition: track.cc:28
Class that bundles various TrackFitResults.
Definition: Track.h:25
std::vector< ChargedStableTrackFitResultPair > getTrackFitResults() const
Deafult Access to all track fit results at the same time.
Definition: Track.cc:60
const TrackFitResult * getTrackFitResult(const Const::ChargedStable &chargedStable) const
Default Access to TrackFitResults.
Definition: Track.cc:30
float getQualityIndicator() const
Getter for quality indicator for classification of fake vs.
Definition: Track.h:198
void setTrackFitResultIndex(const Const::ChargedStable &chargedStable, short index)
Set an index (for positive values) or unavailability-code (index = -1) for a specific mass hypothesis...
Definition: Track.h:174
unsigned int getNumberOfFittedHypotheses() const
Returns the number of fitted hypothesis which are stored in this track.
Definition: Track.cc:36
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:104
TrackFitResult const * addDummyTrack(StoreArray< TrackFitResult > &trackFitResults, Const::ChargedStable particeType)
Utility function to create dummy TrackFitResults.
Definition: track.cc:35
Abstract base class for different kinds of events.
STL namespace.