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