Belle II Software development
KFitV0VertexFitter Class Reference

V0 vertex fitter using KFit. More...

#include <KFitV0VertexFitter.h>

Inheritance diagram for KFitV0VertexFitter:
V0VertexFitter

Public Member Functions

bool fit (genfit::Track &trackPlus, genfit::Track &trackMinus, const int pdgTrackPlus, const int pdgTrackMinus, genfit::GFRaveVertex &vertex) override
 Fit the V0 vertex. The PDG codes of the daughters are used to compute their energies.
 
std::string getName () const override
 Get the name this fitter is registered with in the V0VertexFitterFactory.
 

Detailed Description

V0 vertex fitter using KFit.

Definition at line 19 of file KFitV0VertexFitter.h.

Member Function Documentation

◆ fit()

bool fit ( genfit::Track & trackPlus,
genfit::Track & trackMinus,
const int pdgTrackPlus,
const int pdgTrackMinus,
genfit::GFRaveVertex & vertex )
overridevirtual

Fit the V0 vertex. The PDG codes of the daughters are used to compute their energies.

Implements V0VertexFitter.

Definition at line 103 of file KFitV0VertexFitter.cc.

105{
106 analysis::VertexFitKFit vertexFit;
107 // KFit defaults to KFitConst::kDefaultMagneticField:
108 // use instead the same magnetic field used elsewhere in the V0Fitter
109 vertexFit.setMagneticField(getMagneticField());
110
111 EvtGenDatabasePDG* pdgDB = EvtGenDatabasePDG::Instance();
112
113 auto addTrackToFit =
114 [&](const genfit::Track & track, const int pdg) {
115 const TParticlePDG* particle = pdgDB->GetParticle(pdg);
116 if (not particle) {
117 B2ERROR("Unknown PDG code of the daughter hypothesis." << LogVar("PDG code", pdg));
118 return false;
119 }
120 TVector3 pos;
121 TVector3 mom;
122 // KFit needs the 7x7 cov. matrix, not the 6x6 one:
123 // in the 6x6 one, correlations with E are missing.
124 TMatrixDSym cov6;
125 const genfit::MeasuredStateOnPlane state = track.getFittedState();
126 state.getPosMomCov(pos, mom, cov6);
127 // the mass is used only to complete the energy: the vertex fit itself drops it
128 const double mass = particle->Mass();
129 const CLHEP::HepLorentzVector clhepMom(mom.X(), mom.Y(), mom.Z(), std::sqrt(mom.Mag2() + mass * mass));
130 const HepGeom::Point3D<double> clhepPos(pos.X(), pos.Y(), pos.Z());
131 // This is now good for KFit
132 const CLHEP::HepSymMatrix clhepCov7 = makeCov7x7(cov6, clhepMom);
133 const int charge = track.getFitStatus()->getCharge();
134
135 vertexFit.addTrack(clhepMom, clhepPos, clhepCov7, charge);
136 return true;
137 };
138
139 try {
140 if (not addTrackToFit(trackPlus, pdgTrackPlus)) return false;
141 if (not addTrackToFit(trackMinus, pdgTrackMinus)) return false;
142 } catch (...) {
143 B2ERROR("Exception during vertex fit.");
144 return false;
145 }
146
147 const bool ok = (vertexFit.doFit() == analysis::KFitError::kNoError);
148 if (!ok) return false;
149
150 const HepGeom::Point3D<double> posVertex = vertexFit.getVertex();
151 const CLHEP::HepSymMatrix covVertex = vertexFit.getVertexError();
152 const TVector3 extrapolationTarget(posVertex.x(), posVertex.y(), posVertex.z());
153
154 std::vector<genfit::GFRaveTrackParameters*> trackParamsVertex;
155 trackParamsVertex.reserve(2);
156 for (int i = 0; i <= 1; ++i) {
157 const genfit::Track& daughter = i == 0 ? trackPlus : trackMinus;
158 // KFit gives back the daughter parameters at the reference point of the track:
159 // the momentum there points elsewhere than at the vertex. Transport the daughter
160 // to the vertex position with genfit instead.
161 TVector3 pos;
162 TVector3 mom;
163 TMatrixDSym cov6;
164 try {
165 genfit::MeasuredStateOnPlane daughterState = daughter.getFittedState();
166 daughterState.extrapolateToPoint(extrapolationTarget);
167 daughterState.getPosMomCov(pos, mom, cov6);
168 } catch (...) {
169 B2ERROR("Exception while extrapolating a daughter to the fitted vertex.");
170 for (auto* trackParams : trackParamsVertex) delete trackParams;
171 return false;
172 }
173 TVectorD state{6};
174 state[0] = pos.X();
175 state[1] = pos.Y();
176 state[2] = pos.Z();
177 state[3] = mom.X();
178 state[4] = mom.Y();
179 state[5] = mom.Z();
180 genfit::GFRaveTrackParameters* trackParams = new genfit::GFRaveTrackParameters(nullptr, nullptr, 1, state, cov6, true);
181 trackParamsVertex.push_back(trackParams);
182 }
183 const double ndfVertex = static_cast<double>(vertexFit.getNDF());
184 const double chisqVertex = vertexFit.getCHIsq();
185
186 vertex = genfit::GFRaveVertex{TVector3{posVertex.x(), posVertex.y(), posVertex.z()}, CLHEPToROOT::getTMatrixDSym(covVertex), trackParamsVertex, ndfVertex, chisqVertex};
187
188 return true;
189}
static EvtGenDatabasePDG * Instance()
Instance method that loads the EvtGen table.
enum KFitError::ECode addTrack(const KFitTrack &kp)
Add a track to the fitter object.
Definition KFitBase.cc:38
virtual double getCHIsq(void) const
Get a chi-square of the fit.
Definition KFitBase.cc:121
virtual int getNDF(void) const
Get an NDF of the fit.
Definition KFitBase.cc:114
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
Definition KFitBase.cc:93
const CLHEP::HepSymMatrix getVertexError(void) const
Get a fitted vertex error matrix.
enum KFitError::ECode doFit(void)
Perform a vertex-constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.

◆ getName()

std::string getName ( ) const
inlineoverridevirtual

Get the name this fitter is registered with in the V0VertexFitterFactory.

Implements V0VertexFitter.

Definition at line 29 of file KFitV0VertexFitter.h.

29{return "KFit";}

The documentation for this class was generated from the following files: