10 #include <tracking/trackFindingVXD/variableExtractors/VariableExtractor.h>
11 #include <tracking/dataobjects/RecoTrack.h>
12 #include <tracking/dataobjects/RecoHitInformation.h>
14 #include <genfit/KalmanFitterInfo.h>
15 #include <genfit/TrackPoint.h>
34 addVariable(
"N_TrackPoints_without_KalmanFitterInfo", variableSet);
35 addVariable(
"N_Hits_without_TrackPoint", variableSet);
46 std::vector<const genfit::KalmanFitterInfo*> kalmanFitterInfos;
47 kalmanFitterInfos.reserve(recoHitInformations.size());
49 int n_no_trackPoint = 0;
50 int n_no_KalmanFitterInfo = 0;
55 if (kalmanFitterInfo) {
56 kalmanFitterInfos.push_back(kalmanFitterInfo);
58 n_no_KalmanFitterInfo++;
64 m_variables.at(
"N_Hits_without_TrackPoint") = n_no_trackPoint;
65 m_variables.at(
"N_TrackPoints_without_KalmanFitterInfo") = n_no_KalmanFitterInfo;
69 const auto hitHasKalmanInfoAndIsFromDetector =
70 [&recoTrack,
this](
const auto & recoHitInformation,
73 and (recoHitInformation->getTrackingDetector() == trackingDetector));
75 const auto hitHasKalmanInfoAndIsFromCDC = std::bind(hitHasKalmanInfoAndIsFromDetector,
76 std::placeholders::_1,
77 RecoHitInformation::c_CDC);
78 const auto hitHasKalmanInfoAndIsFromSVD = std::bind(hitHasKalmanInfoAndIsFromDetector,
79 std::placeholders::_1,
80 RecoHitInformation::c_SVD);
83 const auto firstHitWithCDCKalmanInfoIter = std::find_if(recoHitInformations.begin(),
84 recoHitInformations.end(),
85 hitHasKalmanInfoAndIsFromCDC);
86 std::optional<float> weight_firstCDCHit;
87 std::optional<float> smoothedChi2_firstCDCHit;
88 if (firstHitWithCDCKalmanInfoIter != recoHitInformations.end()) {
90 weight_firstCDCHit = kalmanFitterInfo->
getWeights().front();
97 const auto lastHitWithSVDKalmanInfoIter = std::find_if(recoHitInformations.rbegin(),
98 recoHitInformations.rend(),
99 hitHasKalmanInfoAndIsFromSVD);
100 std::optional<float> weight_lastSVDHit;
101 std::optional<float> smoothedChi2_lastSVDHit;
102 if (lastHitWithSVDKalmanInfoIter != recoHitInformations.rend()) {
104 weight_lastSVDHit = kalmanFitterInfo->
getWeights().front();
110 std::vector<float> fitWeights;
111 std::vector<float> chi2Values;
112 fitWeights.reserve(kalmanFitterInfos.size());
113 chi2Values.reserve(kalmanFitterInfos.size());
114 for (
const auto& kalmanFitterInfo : kalmanFitterInfos) {
115 fitWeights.push_back(kalmanFitterInfo->getWeights().front());
119 setStats(
"smoothedChi2", chi2Values);
132 addVariable(identifier +
"_firstCDCHit", variables);
133 addVariable(identifier +
"_lastSVDHit", variables);
138 (
const std::string& identifier, std::vector<float>& values)
140 int size = values.size();
141 if (values.size() == 0) {
153 std::sort(values.begin(), values.end());
155 float sum = std::accumulate(values.begin(), values.end(), 0.0);
156 float mean = sum / size;
160 for (
float value : values) {
161 variance += (value - mean) * (value - mean);
166 variance /= size - 1;
169 m_variables.at(identifier +
"_min") = values.front();
170 m_variables.at(identifier +
"_max") = values.back();
173 float median = (size % 2) ? values[size / 2] : 0.5 * (values[size / 2] + values[size / 2 - 1]);
194 return kalmanFitterInfo->getSmoothedChi2();
195 }
catch (
const std::exception& e) {
196 B2WARNING(
"HitInfoExtractor: Caught exception in kalmanFitterInfos[i]->getSmoothedChi2() \n"
197 <<
"-->" << e.what());
This is the Reconstruction Event-Data Model Track.
const genfit::TrackPoint * getCreatedTrackPoint(const RecoHitInformation *recoHitInformation) const
Get a pointer to the TrackPoint that was created from this hit.
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
std::vector< double > getWeights() const
Get weights of measurements.
Object containing AbsMeasurement and AbsFitterInfo objects.
KalmanFitterInfo * getKalmanFitterInfo(const AbsTrackRep *rep=nullptr) const
Helper to avoid casting.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.