Belle II Software  release-06-02-00
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 
9 #include <mdst/dataobjects/Track.h>
10 #include <framework/datastore/StoreArray.h>
11 #include <framework/logging/Logger.h>
12 
13 #include <sstream>
14 
15 using namespace Belle2;
16 
18 {
19  const auto trackFitResultArrayIndex = m_trackFitIndices[chargedStable.getIndex()];
20  if (trackFitResultArrayIndex < 0) {
21  B2DEBUG(20, "TrackFitResult for the requested hypothesis is not set. Returning a nullptr instead.");
22  return nullptr;
23  }
24 
25  StoreArray<TrackFitResult> trackFitResults{};
26  return trackFitResults[trackFitResultArrayIndex];
27 }
28 
30 {
31  return getValidIndices().size();
32 }
33 
34 
35 std::vector<Track::ChargedStableTrackFitResultPair> Track::getTrackFitResults() const
36 {
37  StoreArray<TrackFitResult> trackFitResults;
38  std::vector<Track::ChargedStableTrackFitResultPair> result;
39 
40  const auto validParticleIndices = getValidIndices();
41 
42  // extract the particle class and trackfitresult pointer for each
43  // stored hypothesis
44  for (auto particleIndex : validParticleIndices) {
45  const auto indexInStoreArray = m_trackFitIndices[particleIndex];
46  result.emplace_back(std::make_pair(Const::ChargedStable(Const::chargedStableSet.at(particleIndex)),
47  trackFitResults[indexInStoreArray]));
48  }
49 
50  return result;
51 }
52 
53 std::vector < short int> Track::getValidIndices() const
54 {
55  std::vector <short int> resultParticleIndex;
56 
57  short int i = 0;
58  for (const auto& hyp : m_trackFitIndices) {
59  if (hyp != -1) {
60  resultParticleIndex.push_back(i);
61  }
62  i++;
63  }
64 
65  return resultParticleIndex;
66 }
67 
69 {
70  // make sure at least one hypothesis exist. No B2 Track should exist which does not have at least
71  // one hypothesis
72  B2ASSERT("Belle2::Track must always have at least one successfully fitted hypothesis.", getNumberOfFittedHypotheses() > 0);
73 
74  // find fitted hypothesis which is closest to the mass of our requested particle type
75  auto allFitRes = getTrackFitResults();
76 
77  // sort so the closest mass hypothesis fit in the first entry of the vector
78  auto bestMassFit = std::min_element(allFitRes.begin(), allFitRes.end(), [requestedType](auto & a, auto & b) {
79  const auto massDiffA = std::abs(a.first.getMass() - requestedType.getMass());
80  const auto massDiffB = std::abs(b.first.getMass() - requestedType.getMass());
81 
82  return massDiffA < massDiffB;
83  });
84 
85  return bestMassFit->second;
86 }
87 
88 std::string Track::getInfoHTML() const
89 {
90  std::stringstream out;
91  out << "<b>Number of Fitted Hypothesis</b>: " << getNumberOfFittedHypotheses() << "<br>";
92 
93  // just output all the TrackFitResult infos.
94  size_t count = 1;
95  for (auto fitResults : getTrackFitResults()) {
96  out << "<p>";
97  out << "<br><b>-- Hypothesis " << count << " --</b><br>";
98  out << fitResults.second->getInfoHTML();
99  out << "</p>";
100  count++;
101  }
102  return out.str();
103 }
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:342
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:499
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Values of the result of a track fit with a given particle hypothesis.
std::vector< ChargedStableTrackFitResultPair > getTrackFitResults() const
Access to all track fit results at the same time.
Definition: Track.cc:35
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
Definition: Track.cc:88
const TrackFitResult * getTrackFitResult(const Const::ChargedStable &chargedStable) const
Access to TrackFitResults.
Definition: Track.cc:17
std::vector< short int > getValidIndices() const
Returns a vector of all fit hypothesis indices in m_trackFitIndices which have been set (meaning are ...
Definition: Track.cc:53
unsigned int getNumberOfFittedHypotheses() const
Returns the number of fitted hypothesis which are stored in this track.
Definition: Track.cc:29
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:68
short int m_trackFitIndices[Const::ChargedStable::c_SetSize]
Index list of the TrackFitResults associated with this Track.
Definition: Track.h:128
Abstract base class for different kinds of events.