Belle II Software development
FitFacetRelationVarSet.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#include <tracking/trackFindingCDC/filters/facetRelation/FitFacetRelationVarSet.h>
9
10#include <tracking/trackFindingCDC/fitting/FacetFitter.h>
11#include <tracking/trackFindingCDC/fitting/CDCKarimakiFitter.h>
12#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
13
14#include <tracking/trackingUtilities/eventdata/hits/CDCFacet.h>
15#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
16#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
17
18#include <tracking/trackingUtilities/geometry/UncertainParameterLine2D.h>
19#include <tracking/trackingUtilities/geometry/LineParameters.h>
20#include <tracking/trackingUtilities/geometry/VectorUtil.h>
21
22#include <framework/geometry/VectorUtil.h>
23
24#include <tracking/trackingUtilities/numerics/Angle.h>
25
26#include <Math/Vector2D.h>
27
28using namespace Belle2;
29using namespace TrackFindingCDC;
30using namespace TrackingUtilities;
31
33{
34 if (not ptrFacetRelation) return false;
35
36 const CDCFacet* fromFacet = ptrFacetRelation->first;
37 const CDCFacet* toFacet = ptrFacetRelation->second;
38
39 const UncertainParameterLine2D& fromFitLine = fromFacet->getFitLine();
40 const UncertainParameterLine2D& toFitLine = toFacet->getFitLine();
41
42 LineCovariance fromCov = fromFitLine.lineCovariance();
43 LineParameters fromPar = fromFitLine.lineParameters();
44
45 LineCovariance toCov = toFitLine.lineCovariance();
46 LineParameters toPar = toFitLine.lineParameters();
47
48 ROOT::Math::XYVector fromTangential = fromFacet->getStartToEndLine().tangential();
49 ROOT::Math::XYVector toTangential = toFacet->getStartToEndLine().tangential();
50
51 ROOT::Math::XYVector tangential = VectorUtil::average(fromTangential, toTangential);
52
53 double fromMiddleCos = VectorUtil::CosPhi(fromFacet->getStartToMiddleLine().tangential(), toTangential);
54 double toMiddleCos = VectorUtil::CosPhi(fromTangential, toFacet->getMiddleToEndLine().tangential());
55
56 var<named("cos_delta")>() = VectorUtil::CosPhi(fromTangential, toTangential);
57
58 var<named("from_middle_cos_delta")>() = fromMiddleCos;
59 var<named("to_middle_cos_delta")>() = toMiddleCos;
60
61 ROOT::Math::XYVector frontWirePos2D = fromFacet->getStartWireHit().getRefPos2D();
62 ROOT::Math::XYVector backWirePos2D = toFacet->getEndWireHit().getRefPos2D();
63 {
64 int nSteps = 0;
65 UncertainParameterLine2D fitLine = FacetFitter::fit(*fromFacet, *toFacet, nSteps);
66 double s = fitLine->lengthOnCurve(frontWirePos2D, backWirePos2D);
67 double alpha = ROOT::Math::VectorUtil::DeltaPhi(fitLine->support(), fitLine->tangential());
68 var<named("alpha_0")>() = alpha;
69 var<named("chi2_0")>() = fitLine.chi2();
70 var<named("chi2_0_per_s")>() = fitLine.chi2() / s;
71 var<named("erf_0")>() = std::erf(fitLine.chi2() / 800);
72 var<named("fit_0_phi0")>() = fitLine->tangential().Phi();
73 var<named("fit_0_cos_delta")>() = VectorUtil::CosPhi(fitLine->tangential(), tangential);
74 }
75
76 {
77 int nSteps = 1;
78 UncertainParameterLine2D fitLine = FacetFitter::fit(*fromFacet, *toFacet, nSteps);
79 double s = fitLine->lengthOnCurve(frontWirePos2D, backWirePos2D);
80 var<named("chi2_1")>() = fitLine.chi2();
81 var<named("chi2_1_per_s")>() = fitLine.chi2() / s;
82 var<named("fit_1_phi0")>() = fitLine->tangential().Phi();
83 var<named("fit_1_cos_delta")>() = VectorUtil::CosPhi(fitLine->tangential(), tangential);
84 }
85
86 {
87 UncertainParameterLine2D fitLine = FacetFitter::fit(*fromFacet, *toFacet);
88 double s = fitLine->lengthOnCurve(frontWirePos2D, backWirePos2D);
89 var<named("chi2")>() = fitLine.chi2();
90 var<named("chi2_per_s")>() = fitLine.chi2() / s;
91 var<named("fit_phi0")>() = fitLine->tangential().Phi();
92 var<named("fit_cos_delta")>() = VectorUtil::CosPhi(fitLine->tangential(), tangential);
93 }
94
95 // Combination fit
96 {
97 using namespace NLineParameterIndices;
98 {
99 double phi0_var = fromFacet->getFitLine().lineCovariance()(c_Phi0, c_Phi0);
100 if (not std::isfinite(phi0_var)) {
101 B2INFO("from addr " << *fromFacet);
102 B2INFO("From cov " << std::endl << fromFacet->getFitLine().lineCovariance());
103 B2INFO("From cov " << std::endl << fromFitLine.lineCovariance());
104 }
105 }
106 {
107 double phi0_var = toFacet->getFitLine().lineCovariance()(c_Phi0, c_Phi0);
108 if (not std::isfinite(phi0_var)) {
109 B2INFO("to addr " << *toFacet);
110 B2INFO("To cov " << std::endl << toFacet->getFitLine().lineCovariance());
111 B2INFO("To cov " << std::endl << toFitLine.lineCovariance());
112 }
113 }
114
115 var<named("phi0_from_sigma")>() = std::sqrt(fromCov(c_Phi0, c_Phi0));
116 var<named("phi0_to_sigma")>() = std::sqrt(toCov(c_Phi0, c_Phi0));
117 var<named("phi0_ref_sigma")>() = std::sqrt(fromCov(c_Phi0, c_Phi0) + toCov(c_Phi0, c_Phi0));
118 var<named("phi0_ref_diff")>() = AngleUtil::normalised(toPar(c_Phi0) - fromPar(c_Phi0));
119 var<named("phi0_ref_pull")>() =
120 std::fabs(AngleUtil::normalised(toPar(c_Phi0) - fromPar(c_Phi0)) /
121 std::sqrt((toCov(c_Phi0, c_Phi0) + fromCov(c_Phi0, c_Phi0))));
122
123 LineParameters avgPar;
124 LineCovariance avgCov;
125 double chi2 = LineUtil::average(fromPar, fromCov, toPar, toCov, avgPar, avgCov);
126
127 LineParameters meanPar = (fromPar + toPar) / 2.0;
128 meanPar(c_Phi0) = AngleUtil::average(fromPar(c_Phi0), toPar(c_Phi0));
129
130 LineParameters relAvgPar = avgPar - meanPar;
131 relAvgPar(c_Phi0) = AngleUtil::normalised(relAvgPar(c_Phi0));
132
133 var<named("chi2_comb")>() = chi2;
134 var<named("phi0_comb_pull")>() =
135 std::fabs(relAvgPar(c_Phi0) / std::sqrt(avgCov(c_Phi0, c_Phi0)));
136 var<named("phi0_comb_diff")>() = relAvgPar(c_Phi0);
137 var<named("phi0_comb_sigma")>() = std::sqrt(avgCov(c_Phi0, c_Phi0));
138 }
139
140 // Fitter
141 {
142 CDCObservations2D observations2D(EFitPos::c_RecoPos, EFitVariance::c_Unit);
143 observations2D.append(*fromFacet);
144 observations2D.append(*toFacet);
145
146 CDCTrajectory2D fittedTrajectory = CDCKarimakiFitter::getFitter().fit(std::move(observations2D));
147 var<named("chi2_kari_unit")>() = fittedTrajectory.getChi2();
148 var<named("abs_curv_unit")>() = std::fabs(fittedTrajectory.getCurvature());
149 }
150
151 {
152 CDCObservations2D observations2D(EFitPos::c_RecoPos, EFitVariance::c_DriftLength);
153 observations2D.append(*fromFacet);
154 observations2D.append(*toFacet);
155
156 CDCTrajectory2D fittedTrajectory = CDCKarimakiFitter::getFitter().fit(std::move(observations2D));
157 var<named("chi2_kari_l")>() = fittedTrajectory.getChi2();
158 var<named("abs_curv_l")>() = std::fabs(fittedTrajectory.getCurvature());
159 }
160
161 {
162 CDCObservations2D observations2D(EFitPos::c_RecoPos, EFitVariance::c_Pseudo);
163 observations2D.append(*fromFacet);
164 observations2D.append(*toFacet);
165
166 CDCTrajectory2D fittedTrajectory = CDCKarimakiFitter::getFitter().fit(std::move(observations2D));
167 var<named("chi2_kari_pseudo")>() = fittedTrajectory.getChi2();
168 var<named("abs_curv_pseudo")>() = std::fabs(fittedTrajectory.getCurvature());
169 }
170
171 {
172 CDCObservations2D observations2D(EFitPos::c_RecoPos, EFitVariance::c_Proper);
173 observations2D.append(*fromFacet);
174 observations2D.append(*toFacet);
175
176 CDCTrajectory2D fittedTrajectory = CDCKarimakiFitter::getFitter().fit(std::move(observations2D));
177 var<named("chi2_kari_proper")>() = fittedTrajectory.getChi2();
178 var<named("abs_curv_proper")>() = std::fabs(fittedTrajectory.getCurvature());
179 }
180
181 return true;
182}
TrackingUtilities::CDCTrajectory2D fit(const CDCObservations2D &observations2D) const
Fits a collection of observation drift circles.
static const CDCKarimakiFitter & getFitter()
Static getter for a general fitter instance with Karimakis method.
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t append(const TrackingUtilities::CDCWireHit &wireHit, TrackingUtilities::ERightLeft rlInfo=TrackingUtilities::ERightLeft::c_Unknown)
Appends the hit circle at wire reference position without a right left passage hypotheses.
static double fit(const TrackingUtilities::CDCFacet &facet, int nSteps=100)
Fits a proper line to facet and returns the chi2.
bool extract(const TrackingUtilities::Relation< const TrackingUtilities::CDCFacet > *ptrFacetRelation) final
Generate and assign the contained variables.
Class representing a triple of neighboring oriented wire with additional trajectory information.
Definition CDCFacet.h:33
ParameterLine2D getStartToEndLine() const
Getter for the tangential line from the first to the third hit.
Definition CDCFacet.cc:94
const UncertainParameterLine2D & getFitLine() const
Getter for the contained line fit information.
Definition CDCFacet.h:62
ParameterLine2D getStartToMiddleLine() const
Getter for the tangential line from the first to the second hit.
Definition CDCFacet.cc:86
ParameterLine2D getMiddleToEndLine() const
Getter for the tangential line from the second to the third hit.
Definition CDCFacet.cc:102
const CDCWireHit & getEndWireHit() const
Getter for the hit wire of the third oriented wire hit.
const CDCWireHit & getStartWireHit() const
Getter for the hit wire of the first oriented wire hit.
Particle trajectory as it is seen in xy projection represented as a circle.
double getChi2() const
Getter for the chi2 value of the circle fit.
double getCurvature() const
Getter for the curvature as seen from the xy projection.
const ROOT::Math::XYVector & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
const ROOT::Math::XYVector & support() const
Gives the support vector of the line.
const ROOT::Math::XYVector & tangential() const
Gives the tangential vector of the line.
double lengthOnCurve(const ROOT::Math::XYVector &from, const ROOT::Math::XYVector &to) const
Denotes the length on the line between the two points.
Type for two related objects.
Definition Relation.h:21
A parameter line including including an line covariance matrix which is interpreted as located in the...
const LineCovariance & lineCovariance() const
Getter for the whole covariance matrix of the line parameters.
double chi2() const
Getter for the chi square value of the line fit.
LineParameters lineParameters() const
Getter for the three perigee parameters in the order defined by EPerigeeParameter....
static constexpr int named(const char *name)
Definition VarSet.h:78
Namespace to hide the contained enum constants.
Abstract base class for different kinds of events.
static double average(const double angle1, double angle2)
Combines two angular values to the one that lies half way between them on the short arc.
Definition Angle.h:27
static double normalised(const double angle)
Normalise an angle to lie in the range from [-pi, pi].
Definition Angle.h:33
static double average(const LineUtil::ParameterVector &fromPar, const LineUtil::CovarianceMatrix &fromCov, const LineUtil::ParameterVector &toPar, const LineUtil::CovarianceMatrix &toCov, LineUtil::ParameterVector &avgPar, LineUtil::CovarianceMatrix &avgCov)
Calculates the weighted average between two line parameter sets with their respective covariance matr...