Belle II Software light-2406-ragdoll
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
15using namespace Belle2;
16
18 const std::string trackFitResultsName) const
19{
20 const auto trackFitResultArrayIndex = m_trackFitIndices[chargedStable.getIndex()];
21 if (trackFitResultArrayIndex < 0) {
22 B2DEBUG(20, "TrackFitResult for the requested hypothesis is not set. Returning a nullptr instead.");
23 return nullptr;
24 }
25
26 StoreArray<TrackFitResult> trackFitResults(trackFitResultsName);
27 return trackFitResults[trackFitResultArrayIndex];
28}
29
31{
32 return getTrackFitResultByName(chargedStable, "");
33}
34
35
37{
38 return getValidIndices().size();
39}
40
41
42std::vector<Track::ChargedStableTrackFitResultPair> Track::getTrackFitResultsByName(const std::string trackFitResultsName) const
43{
44 StoreArray<TrackFitResult> trackFitResults(trackFitResultsName);
45 std::vector<Track::ChargedStableTrackFitResultPair> result;
46
47 const auto validParticleIndices = getValidIndices();
48
49 // extract the particle class and trackfitresult pointer for each
50 // stored hypothesis
51 for (auto particleIndex : validParticleIndices) {
52 const auto indexInStoreArray = m_trackFitIndices[particleIndex];
53 result.emplace_back(std::make_pair(Const::ChargedStable(Const::chargedStableSet.at(particleIndex)),
54 trackFitResults[indexInStoreArray]));
55 }
56
57 return result;
58}
59
60std::vector<Track::ChargedStableTrackFitResultPair> Track::getTrackFitResults() const
61{
62 return getTrackFitResultsByName("");
63}
64
65std::vector < short int> Track::getValidIndices() const
66{
67 std::vector <short int> resultParticleIndex;
68
69 short int i = 0;
70 for (const auto& hyp : m_trackFitIndices) {
71 if (hyp != -1) {
72 resultParticleIndex.push_back(i);
73 }
74 i++;
75 }
76
77 return resultParticleIndex;
78}
79
81 const std::string trackFitResultsName) const
82{
83 // make sure at least one hypothesis exist. No B2 Track should exist which does not have at least
84 // one hypothesis
85 B2ASSERT("Belle2::Track must always have at least one successfully fitted hypothesis.", getNumberOfFittedHypotheses() > 0);
86
87 // find fitted hypothesis which is closest to the mass of our requested particle type
88 auto allFitRes = getTrackFitResultsByName(trackFitResultsName);
89
90 // sort so the closest mass hypothesis fit in the first entry of the vector
91 auto bestMassFit = std::min_element(allFitRes.begin(), allFitRes.end(), [requestedType](auto & a, auto & b) {
92 const auto massDiffA = std::abs(a.first.getMass() - requestedType.getMass());
93 const auto massDiffB = std::abs(b.first.getMass() - requestedType.getMass());
94
95 return massDiffA < massDiffB;
96 });
97
98 if (std::isnan(bestMassFit->second->getPValue())) {
99 return nullptr;
100 }
101 return bestMassFit->second;
102}
103
105{
106 return getTrackFitResultWithClosestMassByName(requestedType, "");
107}
108
109std::string Track::getInfoHTML() const
110{
111 std::stringstream out;
112 out << "<b>Number of Fitted Hypothesis</b>: " << getNumberOfFittedHypotheses() << "<br>";
113
114 // just output all the TrackFitResult infos.
115 size_t count = 1;
116 for (auto fitResults : getTrackFitResults()) {
117 out << "<p>";
118 out << "<br><b>-- Hypothesis " << count << " --</b><br>";
119 out << fitResults.second->getInfoHTML();
120 out << "</p>";
121 count++;
122 }
123 return out.str();
124}
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:461
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618
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
Deafult Access to all track fit results at the same time.
Definition: Track.cc:60
std::vector< ChargedStableTrackFitResultPair > getTrackFitResultsByName(const std::string trackFitResultsName) const
Access to all track fit results at the same time (from TrackFitResult with specified name)
Definition: Track.cc:42
const TrackFitResult * getTrackFitResultByName(const Const::ChargedStable &chargedStable, const std::string trackFitResultsName) const
Access to TrackFitResults with a specified Name.
Definition: Track.cc:17
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
Definition: Track.cc:109
const TrackFitResult * getTrackFitResult(const Const::ChargedStable &chargedStable) const
Default Access to TrackFitResults.
Definition: Track.cc:30
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:65
const TrackFitResult * getTrackFitResultWithClosestMassByName(const Const::ChargedStable &requestedType, const std::string trackFitResultsName) const
Return the track fit (from TrackFitResult with specified name) for a fit hypothesis with the closest ...
Definition: Track.cc:80
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
short int m_trackFitIndices[Const::ChargedStable::c_SetSize]
Index list of the TrackFitResults associated with this Track.
Definition: Track.h:230
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24