105{
106 analysis::VertexFitKFit vertexFit;
107
108
110
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
123
124 TMatrixDSym cov6;
125 const genfit::MeasuredStateOnPlane state = track.getFittedState();
126 state.getPosMomCov(pos, mom, cov6);
127
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
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
148 if (!ok) return false;
149
150 const HepGeom::Point3D<double> posVertex = vertexFit.
getVertex();
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
159
160
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.
virtual double getCHIsq(void) const
Get a chi-square of the fit.
virtual int getNDF(void) const
Get an NDF of the fit.
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
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.