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