Belle II Software  release-05-01-25
track.cc
1 #include <mdst/dataobjects/Track.h>
2 #include <mdst/dataobjects/TrackFitResult.h>
3 #include <framework/gearbox/Const.h>
4 #include <framework/datastore/StoreArray.h>
5 #include <gtest/gtest.h>
6 
7 #include <algorithm>
8 
9 using namespace std;
10 
11 namespace Belle2 {
21  class TrackTest : public ::testing::Test {
22  protected:
23  };
24 
29  {
30  const TVector3 dummyVector3;
31  const TMatrixDSym dummyMatrix(6);
32  const int charge = 1;
33  const float pValue = 1.;
34  const float bField = 1.5;
35 
36  const auto newFitRes = trackFitResults.appendNew(dummyVector3, dummyVector3, dummyMatrix, charge, particeType, pValue,
37  bField, 0, 0, 0);
38  return newFitRes;
39  }
40 
43  TEST_F(TrackTest, settersNGetters)
44  {
45  //Create some TrackFitResults in the the DataStore.
46  //PDGCode of the TrackFitResult will be used in the test to identify the TFR.
47  DataStore::Instance().setInitializeActive(true);
49  myResults.registerInDataStore();
50 
51  const auto myPion = addDummyTrack(myResults, Const::pion);
52  const auto myKaon = addDummyTrack(myResults, Const::kaon);
53  const auto myElectron = addDummyTrack(myResults, Const::electron);
54  const auto myMuon = addDummyTrack(myResults, Const::muon);
55 
56  EXPECT_EQ(myPion->getArrayIndex(), 0);
57  EXPECT_EQ(myKaon->getArrayIndex(), 1);
58  EXPECT_EQ(myElectron->getArrayIndex(), 2);
59  EXPECT_EQ(myMuon->getArrayIndex(), 3);
60 
61  Track mytrack1;
62  mytrack1.setTrackFitResultIndex(Const::pion, myPion->getArrayIndex());
63  mytrack1.setTrackFitResultIndex(Const::muon, myMuon->getArrayIndex());
64  mytrack1.setTrackFitResultIndex(Const::kaon, myKaon->getArrayIndex());
65 
66  EXPECT_EQ(mytrack1.getNumberOfFittedHypotheses(), 3);
67  // If the index of the corresponding particle is set, the correct particle should be returned.
68  EXPECT_EQ(mytrack1.getTrackFitResult(Const::pion)->getParticleType(), Const::pion);
69  EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getParticleType(), Const::kaon);
70  EXPECT_EQ(mytrack1.getTrackFitResult(Const::muon)->getParticleType(), Const::muon);
71  // If the index of the corresponding particle is *not* set, a nullptr should be returned.
72  EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron), nullptr);
73 
74  // If the index of the corresponding particle is set, the correct particle should be returned.
75  EXPECT_EQ(mytrack1.getTrackFitResult(Const::pion)->getArrayIndex(), myPion->getArrayIndex());
76  EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getArrayIndex(), myKaon->getArrayIndex());
77  EXPECT_EQ(mytrack1.getTrackFitResult(Const::muon)->getArrayIndex(), myMuon->getArrayIndex());
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  const auto allResults = mytrack1.getTrackFitResults();
82  // should return all hypothesis which were added before
83  EXPECT_EQ(allResults.size(), 3);
84 
85  // check that all correct hypothesis are returned and the electron is not
86  auto countPion = std::count_if(allResults.begin(), allResults.end(),
87  [myPion](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
88  {return (fitPair.first == Const::pion) && (fitPair.second->getArrayIndex() == myPion->getArrayIndex());});
89  auto countMuon = std::count_if(allResults.begin(), allResults.end(),
90  [myMuon](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
91  {return (fitPair.first == Const::muon) && (fitPair.second->getArrayIndex() == myMuon->getArrayIndex());});
92  auto countElectron = std::count_if(allResults.begin(), allResults.end(),
93  [](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
94  {return fitPair.first == Const::electron;});
95  auto countKaon = std::count_if(allResults.begin(), allResults.end(),
96  [myKaon](std::pair<Const::ChargedStable, const TrackFitResult*> fitPair)
97  {return (fitPair.first == Const::kaon) && (fitPair.second->getArrayIndex() == myKaon->getArrayIndex());});
98 
99  EXPECT_EQ(countPion, 1);
100  EXPECT_EQ(countMuon, 1);
101  EXPECT_EQ(countElectron, 0);
102  EXPECT_EQ(countKaon, 1);
103 
104  Track trackQITest;
105  EXPECT_EQ(trackQITest.getQualityIndicator(), 0.);
106  Track trackQITest1(0.5);
107  EXPECT_EQ(trackQITest1.getQualityIndicator(), 0.5);
108  }
109 
112  TEST_F(TrackTest, getTrackFitResultWithClosestMass)
113  {
114  //Create some TrackFitResults in the the DataStore.
115  //PDGCode of the TrackFitResult will be used in the test to identify the TFR.
116  DataStore::Instance().setInitializeActive(true);
117  StoreArray<TrackFitResult> myResults;
118  myResults.registerInDataStore();
119 
120  // add two fit results
121  const auto myKaon = addDummyTrack(myResults, Const::kaon);
122  const auto myElectron = addDummyTrack(myResults, Const::electron);
123 
124  Track mytrack1;
125  mytrack1.setTrackFitResultIndex(Const::electron, myElectron->getArrayIndex());
126  mytrack1.setTrackFitResultIndex(Const::kaon, myKaon->getArrayIndex());
127 
128  EXPECT_EQ(mytrack1.getNumberOfFittedHypotheses(), 2);
129 
130  // check for correct hypothesis if we request a fitted particle
131  const auto fitCloseToKaonMass = mytrack1.getTrackFitResultWithClosestMass(Const::kaon);
132  EXPECT_EQ(Const::kaon.getPDGCode(), fitCloseToKaonMass->getParticleType().getPDGCode());
133  EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getArrayIndex(), fitCloseToKaonMass->getArrayIndex());
134 
135  // check to get Pion fit
136  const auto wantPionButHaveElectronFit = mytrack1.getTrackFitResultWithClosestMass(Const::pion);
137  EXPECT_EQ(Const::electron.getPDGCode(), wantPionButHaveElectronFit->getParticleType().getPDGCode());
138  EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron)->getArrayIndex(), wantPionButHaveElectronFit->getArrayIndex());
139 
140  // check to get Electron fit
141  const auto wantMuonButHaveElectronFit = mytrack1.getTrackFitResultWithClosestMass(Const::muon);
142  EXPECT_EQ(Const::electron.getPDGCode(), wantMuonButHaveElectronFit->getParticleType().getPDGCode());
143  EXPECT_EQ(mytrack1.getTrackFitResult(Const::electron)->getArrayIndex(), wantMuonButHaveElectronFit->getArrayIndex());
144 
145  // check to get Proton fit
146  const auto wantProtonButHaveKaonFit = mytrack1.getTrackFitResultWithClosestMass(Const::proton);
147  EXPECT_EQ(Const::kaon.getPDGCode(), wantProtonButHaveKaonFit->getParticleType().getPDGCode());
148  EXPECT_EQ(mytrack1.getTrackFitResult(Const::kaon)->getArrayIndex(), wantProtonButHaveKaonFit->getArrayIndex());
149 
150  }
152 } // namespace
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::Track::getNumberOfFittedHypotheses
unsigned int getNumberOfFittedHypotheses() const
Returns the number of fitted hypothesis which are stored in this track.
Definition: Track.cc:31
Belle2::Track::getTrackFitResult
const TrackFitResult * getTrackFitResult(const Const::ChargedStable &chargedStable) const
Access to TrackFitResults.
Definition: Track.cc:19
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::Track::getTrackFitResults
std::vector< ChargedStableTrackFitResultPair > getTrackFitResults() const
Access to all track fit results at the same time.
Definition: Track.cc:37
Belle2::TrackFitResult::getParticleType
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
Definition: TrackFitResult.h:154
Belle2::Track::setTrackFitResultIndex
void setTrackFitResultIndex(const Const::ChargedStable &chargedStable, short index)
Set an index (for positive values) or unavailability-code (with negative values) for a specific mass ...
Definition: Track.h:104
Belle2::TrackTest
Test class for the Track object.
Definition: track.cc:21
Belle2::Track::getTrackFitResultWithClosestMass
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:70
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::addDummyTrack
TrackFitResult const * addDummyTrack(StoreArray< TrackFitResult > &trackFitResults, Const::ChargedStable particeType)
Utility function to create dummy TrackFitResults.
Definition: track.cc:28
Belle2::RelationsInterface::getArrayIndex
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Definition: RelationsObject.h:387
Belle2::Track::getQualityIndicator
float getQualityIndicator() const
Getter for quality indicator for classification of fake vs.
Definition: Track.h:128
Belle2::TEST_F
TEST_F(TrackTest, getTrackFitResultWithClosestMass)
Test simple Setters and Getters.
Definition: track.cc:112
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33