Belle II Software development
FitFacetVarSet.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/facet/FitFacetVarSet.h>
9
10#include <tracking/trackFindingCDC/fitting/FacetFitter.h>
11
12#include <tracking/trackingUtilities/eventdata/hits/CDCFacet.h>
13#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
14
15#include <tracking/trackingUtilities/numerics/Quadratic.h>
16
17using namespace Belle2;
18using namespace TrackFindingCDC;
19using namespace TrackingUtilities;
20
21bool FitFacetVarSet::extract(const CDCFacet* ptrFacet)
22{
23 if (not ptrFacet) return false;
24 const CDCFacet& facet = *ptrFacet;
25
26 const Vector2D startWirePos2D = facet.getStartWireHit().getRefPos2D();
27 const Vector2D middleWirePos2D = facet.getMiddleWireHit().getRefPos2D();
28 const Vector2D endWirePos2D = facet.getEndWireHit().getRefPos2D();
29
30 // 0 step fit
31 {
32 constexpr const int nSteps = 0;
33 const double chi2_0 = FacetFitter::fit(facet, nSteps);
34 const UncertainParameterLine2D& fitLine = facet.getFitLine();
35 const double s = fitLine->lengthOnCurve(startWirePos2D, endWirePos2D);
36
37 var<named("chi2_0")>() = chi2_0;
38 var<named("chi2_0_per_s")>() = chi2_0 / s;
39 var<named("fit_0_phi0")>() = fitLine->tangential().phi();
40 var<named("fit_0_phi0_sigma")>() = std::sqrt(fitLine.variance(ELineParameter::c_Phi0));
41 }
42
43 // 1 step fit
44 {
45 constexpr const int nSteps = 1;
46 const double chi2_1 = FacetFitter::fit(facet, nSteps);
47 const UncertainParameterLine2D& fitLine = facet.getFitLine();
48 const double s = fitLine->lengthOnCurve(startWirePos2D, endWirePos2D);
49
50 var<named("chi2_1")>() = chi2_1;
51 var<named("chi2_1_per_s")>() = chi2_1 / s;
52 var<named("fit_1_phi0")>() = fitLine->tangential().phi();
53 var<named("fit_1_phi0_sigma")>() = std::sqrt(fitLine.variance(ELineParameter::c_Phi0));
54 }
55
56 // N step fit
57 {
58 const double chi2 = FacetFitter::fit(facet);
59 const UncertainParameterLine2D& fitLine = facet.getFitLine();
60 const double s = fitLine->lengthOnCurve(startWirePos2D, endWirePos2D);
61
62 var<named("chi2")>() = chi2;
63 var<named("chi2_per_s")>() = chi2 / s;
64
65 // Heuristic flattening functions. Factor is chosen by hand for some experimentation here.
66 constexpr const double erfWidth = 120.0;
67 constexpr const double tanhWidth = 1.64 * erfWidth;
68
69 var<named("erf")>() = std::erf(chi2 / erfWidth);
70 var<named("tanh")>() = std::tanh(chi2 / tanhWidth);
71 var<named("fit_phi0")>() = fitLine->tangential().phi();
72 var<named("fit_phi0_sigma")>() = std::sqrt(fitLine.variance(ELineParameter::c_Phi0));
73
74 const CDCRLWireHit& startRLWireHit = facet.getStartRLWireHit();
75 const CDCRLWireHit& middleRLWireHit = facet.getMiddleRLWireHit();
76 const CDCRLWireHit& endRLWireHit = facet.getEndRLWireHit();
77
78 const double startL = startRLWireHit.getSignedRefDriftLength();
79 const double middleL = middleRLWireHit.getSignedRefDriftLength();
80 const double endL = endRLWireHit.getSignedRefDriftLength();
81
82 const double startDistance = fitLine->distance(startWirePos2D) - startL;
83 const double middleDistance = fitLine->distance(middleWirePos2D) - middleL;
84 const double endDistance = fitLine->distance(endWirePos2D) - endL;
85
86 var<named("start_distance")>() = startDistance;
87 var<named("middle_distance")>() = middleDistance;
88 var<named("end_distance")>() = endDistance;
89 var<named("d2")>() = square(startDistance) + square(middleDistance) + square(endDistance);
90 }
91 return true;
92}
static double fit(const TrackingUtilities::CDCFacet &facet, int nSteps=100)
Fits a proper line to facet and returns the chi2.
bool extract(const TrackingUtilities::CDCFacet *ptrFacet) final
Generate and assign the contained variables.
Class representing a triple of neighboring oriented wire with additional trajectory information.
Definition CDCFacet.h:32
const UncertainParameterLine2D & getFitLine() const
Getter for the contained line fit information.
Definition CDCFacet.h:61
const CDCWireHit & getMiddleWireHit() const
Getter for the hit wire of the second oriented wire hit.
CDCRLWireHit & getStartRLWireHit()
Getter for the first oriented wire hit.
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.
CDCRLWireHit & getEndRLWireHit()
Getter for the third oriented wire hit.
CDCRLWireHit & getMiddleRLWireHit()
Getter for the second oriented wire hit.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
double getSignedRefDriftLength() const
Getter for the drift length at the reference position of the wire.
const ROOT::Math::XYVector & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
double distance(const Vector2D &point) const
Gives the signed distance of a point to the line.
const Vector2D & tangential() const
Gives the tangential vector of the line.
double lengthOnCurve(const Vector2D &from, const Vector2D &to) const
Denotes the length on the line between the two points.
A parameter line including including an line covariance matrix which is interpreted as located in the...
double variance(const ELineParameter &i) const
Getter for individual diagonal elements of the covariance matrix.
static constexpr int named(const char *name)
Definition VarSet.h:78
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition Vector2D.h:36
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition Vector2D.h:600
Abstract base class for different kinds of events.