8#include <tracking/kinkFinding/fitter/KinkFitter.h>
10#include <framework/logging/Logger.h>
11#include <framework/geometry/VectorUtil.h>
12#include <framework/geometry/BFieldManager.h>
13#include <framework/utilities/IOIntercept.h>
14#include <framework/geometry/B2Vector3.h>
16#include <tracking/trackFitting/trackBuilder/factories/TrackBuilder.h>
18#include <mdst/dataobjects/HitPatternVXD.h>
19#include <mdst/dataobjects/HitPatternCDC.h>
20#include <mdst/dataobjects/Track.h>
21#include <cdc/dataobjects/CDCRecoHit.h>
22#include <pxd/reconstruction/PXDRecoHit.h>
23#include <svd/reconstruction/SVDRecoHit.h>
24#include <svd/reconstruction/SVDRecoHit2D.h>
26#include <genfit/TrackPoint.h>
27#include <genfit/MeasuredStateOnPlane.h>
28#include <genfit/FieldManager.h>
29#include <genfit/MaterialEffects.h>
30#include <genfit/FitStatus.h>
31#include <genfit/KalmanFitStatus.h>
32#include <genfit/KalmanFitterInfo.h>
33#include <genfit/KalmanFitterRefTrack.h>
35#include <analysis/VertexFitting/KFit/VertexFitKFit.h>
36#include <analysis/utility/ROOTToCLHEP.h>
37#include <CLHEP/Matrix/Matrix.h>
38#include <CLHEP/Matrix/SymMatrix.h>
39#include <CLHEP/Vector/LorentzVector.h>
40#include <CLHEP/Geometry/Point3D.h>
45 const std::string& recoTracksName,
const std::string& copiedRecoTracksName)
46 : m_recoTracksName(recoTracksName), m_kinkFitterMode(1)
62 B2ASSERT(
"Material effects not set up. Please use SetupGenfitExtrapolationModule.",
63 genfit::MaterialEffects::getInstance()->isInitialized());
64 B2ASSERT(
"Magnetic field not set up. Please use SetupGenfitExtrapolationModule.",
65 genfit::FieldManager::getInstance()->isInitialized());
70 if (not(fitterMode <= 15)) {
71 B2FATAL(
"Invalid fitter mode!");
83 const double vertexChi2Cut,
84 const double precutDistance)
93 const ROOT::Math::XYZVector& vertexPos,
unsigned int& reassignHitStatus)
95 reassignHitStatus = 0;
99 double extralengthMother = stMother.extrapolateToPoint(
XYZToTVector(vertexPos));
100 double extralengthDaughter = stDaughter.extrapolateToPoint(
XYZToTVector(vertexPos));
101 if (extralengthMother > 0
102 && extralengthDaughter > 0) reassignHitStatus |= 0x1;
103 if (extralengthMother < 0
104 && extralengthDaughter < 0) reassignHitStatus |= 0x2;
105 B2DEBUG(29,
"extralengthMother=" << extralengthMother <<
", extralengthDaughter=" << extralengthDaughter);
108 B2DEBUG(29,
"Could not extrapolate track to vertex.");
116 const genfit::MeasuredStateOnPlane& msop,
125 =
m_trackFitResults.appendNew(ROOT::Math::XYZVector(msop.getPos()), ROOT::Math::XYZVector(msop.getMom()),
126 msop.get6DCov(), msop.getCharge(),
128 trackFitStatus->getPVal(),
129 Bz, hitPatternCDCInitializer, hitPatternVXDInitializer,
130 trackFitStatus->getNdf());
131 return kinkTrackFitResult;
136 ROOT::Math::XYZVector& vertexPos,
140 if (direction != 1 && direction != -1) {
141 B2WARNING(
"KinkFitter::findHitPositionForReassignment: the direction is not +-1, although should be. "
142 "Set to +1 (-1) for direction > 0 (< 0).");
150 double minimalDistance2 = std::numeric_limits<double>::max();
151 int minimalIndex = 0;
158 for (
int cdcHitIndex = 0; cdcHitIndex < static_cast<int>(cdcHits.size()); ++cdcHitIndex) {
162 riHit =
static_cast<int>(cdcHits.size()) - 1 - cdcHitIndex;
165 if (!recoHitInfo->useInFit())
continue;
169 const double currentDistance2 = (ROOT::Math::XYZVector(measuredStateOnPlane.getPos()) - vertexPos).Mag2();
171 if (currentDistance2 < minimalDistance2) {
172 minimalDistance2 = currentDistance2;
173 minimalIndex = cdcHitIndex;
176 if (cdcHitIndex - minimalIndex > 3)
break;
177 }
catch (
const NoTrackFitResult& exception) {
178 B2DEBUG(29,
"Can not get mSoP because of: " << exception.what());
180 }
catch (
const genfit::Exception& exception) {
181 B2DEBUG(29,
"Can not get mSoP because of: " << exception.what());
185 if (minimalIndex == 0)
186 return -1 * direction;
188 return -(minimalIndex * direction);
194 const bool motherFlag,
const int delta)
202 const int deltaMother = delta > 0 ? -delta : 0;
203 const int deltaDaughter = delta < 0 ? -delta : 0;
204 int sortingParameterOffset = 0;
209 recoTrackToCopy = motherRecoTrack;
211 recoTrackToCopy = daughterRecoTrack;
230 for (
const auto* pxdHit : recoTrackToCopy->
getPXDHitList()) {
232 recoTrack->
addPXDHit(pxdHit, recoHitInfo->getSortingParameter(),
233 recoHitInfo->getFoundByTrackFinder());
237 for (
const auto* svdHit : recoTrackToCopy->
getSVDHitList()) {
239 recoTrack->
addSVDHit(svdHit, recoHitInfo->getSortingParameter(),
240 recoHitInfo->getFoundByTrackFinder());
244 for (
size_t motherCDCHitIndex = 0; motherCDCHitIndex < motherCDCHit.size() + deltaMother; ++motherCDCHitIndex) {
246 recoTrack->
addCDCHit(motherCDCHit[motherCDCHitIndex],
247 recoHitInfo->getSortingParameter(),
248 recoHitInfo->getRightLeftInformation(),
249 recoHitInfo->getFoundByTrackFinder());
253 for (
size_t daughterCDCHitIndex = 0; daughterCDCHitIndex < static_cast<unsigned int>(deltaDaughter); ++daughterCDCHitIndex) {
255 recoTrack->
addCDCHit(daughterCDCHit[daughterCDCHitIndex],
256 recoHitInfo->getSortingParameter() + sortingParameterOffset,
257 recoHitInfo->getRightLeftInformation(),
258 recoHitInfo->getFoundByTrackFinder());
271 deltaMother])->getSortingParameter();
273 for (
size_t motherCDCHitIndex = motherCDCHit.size() + deltaMother; motherCDCHitIndex < motherCDCHit.size(); ++motherCDCHitIndex) {
275 recoTrack->
addCDCHit(motherCDCHit[motherCDCHitIndex],
276 recoHitInfo->getSortingParameter() - sortingParameterOffset,
277 recoHitInfo->getRightLeftInformation(),
278 recoHitInfo->getFoundByTrackFinder());
281 sortingParameterOffset = -deltaMother - deltaDaughter;
282 for (
size_t daughterCDCHitIndex = deltaDaughter; daughterCDCHitIndex < daughterCDCHit.size(); ++daughterCDCHitIndex) {
284 recoTrack->
addCDCHit(daughterCDCHit[daughterCDCHitIndex],
285 recoHitInfo->getSortingParameter() + sortingParameterOffset,
286 recoHitInfo->getRightLeftInformation(),
287 recoHitInfo->getFoundByTrackFinder());
294 recoTrack->
addBKLMHit(bklmHit, recoHitInfo->getSortingParameter() + sortingParameterOffset,
295 recoHitInfo->getFoundByTrackFinder());
301 recoTrack->
addEKLMHit(eklmHit, recoHitInfo->getSortingParameter() + sortingParameterOffset,
302 recoHitInfo->getFoundByTrackFinder());
318 trackFitterDAF.
fit(*recoTrackMotherRefit);
319 trackFitterDAF.
fit(*recoTrackDaughterRefit);
322 B2DEBUG(29,
"Refit of the tracks with reassigned hits failed ");
326 const genfit::FitStatus* motherTrackFitStatus = recoTrackMother->
getTrackFitStatus();
327 const genfit::FitStatus* daughterTrackFitStatus = recoTrackDaughter->
getTrackFitStatus();
328 const double chi2MotherInit = motherTrackFitStatus->getChi2();
329 const double chi2DaughterInit = daughterTrackFitStatus->getChi2();
330 const double ndfMotherInit = motherTrackFitStatus->getNdf();
331 const double ndfDaughterInit = daughterTrackFitStatus->getNdf();
332 B2DEBUG(29,
"Initial mother fit result, p-value: " << motherTrackFitStatus->getPVal() <<
", chi2: " <<
333 chi2MotherInit <<
", ndf: " << ndfMotherInit);
334 B2DEBUG(29,
"Initial daughter fit result, p-value: " << daughterTrackFitStatus->getPVal() <<
", chi2: " <<
335 chi2DaughterInit <<
", ndf: " << ndfDaughterInit);
337 const genfit::FitStatus* motherNewTrackFitStatus = recoTrackMotherRefit->
getTrackFitStatus();
338 const genfit::FitStatus* daughterNewTrackFitStatus = recoTrackDaughterRefit->
getTrackFitStatus();
339 const double chi2Mother = motherNewTrackFitStatus->getChi2();
340 const double chi2Daughter = daughterNewTrackFitStatus->getChi2();
341 const double ndfMother = motherNewTrackFitStatus->getNdf();
342 const double ndfDaughter = daughterNewTrackFitStatus->getNdf();
343 B2DEBUG(29,
"New mother fit result, p-value: " << motherNewTrackFitStatus->getPVal() <<
", chi2: " <<
344 chi2Mother <<
", ndf: " << ndfMother);
345 B2DEBUG(29,
"New daughter fit result, p-value: " << daughterNewTrackFitStatus->getPVal() <<
", chi2: " <<
346 chi2Daughter <<
", ndf: " << ndfDaughter);
349 if ((chi2Mother + chi2Daughter) / (ndfMother + ndfDaughter) < (chi2MotherInit + chi2DaughterInit) /
350 (ndfMotherInit + ndfDaughterInit))
359 const ROOT::Math::XYZVector& momentumSeed,
360 const ROOT::Math::XYZVector& positionSeed,
361 const double& timeSeed)
379 std::shared_ptr<genfit::KalmanFitterRefTrack> kalmanFitter = std::make_shared<genfit::KalmanFitterRefTrack>();
380 kalmanFitter->setMinIterations(
static_cast<unsigned int>(3));
381 kalmanFitter->setMaxIterations(
static_cast<unsigned int>(10));
382 kalmanFitter->setMaxFailedHits(
static_cast<unsigned int>(5));
385 trackFitterKF.
fit(*newRecoTrack);
392 const ROOT::Math::XYZVector& momentumSeed,
393 const ROOT::Math::XYZVector& positionSeed,
394 const double& timeSeed,
395 const bool blockInnerStereoHits,
const bool useAnotherFitter)
413 if (blockInnerStereoHits) {
414 bool passedStereo =
false;
416 for (
int daughterCDCHitIndex = 0; daughterCDCHitIndex < static_cast<int>(newCDCHitRefit.size()) - 6; ++daughterCDCHitIndex) {
417 if (!passedStereo && (newCDCHitRefit[daughterCDCHitIndex]->getISuperLayer() % 2 != 0))
419 if (passedStereo && (newCDCHitRefit[daughterCDCHitIndex]->getISuperLayer() % 2 == 0))
430 if (useAnotherFitter) {
431 std::shared_ptr<genfit::KalmanFitterRefTrack> kalmanFitter = std::make_shared<genfit::KalmanFitterRefTrack>();
432 kalmanFitter->setMinIterations(
static_cast<unsigned int>(3));
433 kalmanFitter->setMaxIterations(
static_cast<unsigned int>(10));
434 kalmanFitter->setMaxFailedHits(
static_cast<unsigned int>(5));
437 trackFitter.
fit(*newRecoTrack);
439 trackFitter.
fit(*newRecoTrack);
450 ROOT::Math::XYZVector daughterPosClosestToMotherPosLast = ROOT::Math::XYZVector(
452 ROOT::Math::XYZVector daughterMomClosestToMotherPosLast = ROOT::Math::XYZVector(
456 Helix daughterHelixClosestToMotherPosLast(daughterPosClosestToMotherPosLast,
457 daughterMomClosestToMotherPosLast,
460 daughterHelixClosestToMotherPosLast.passiveMoveBy(motherPosLast);
463 return ((daughterHelixClosestToMotherPosLast.getD0() * daughterHelixClosestToMotherPosLast.getD0() +
464 daughterHelixClosestToMotherPosLast.getZ0() * daughterHelixClosestToMotherPosLast.getZ0()) <
481 trackFitterDAF.
fit(*recoTrackCombinedRefit);
484 if (!recoTrackCombinedRefit->wasFitSuccessful()) {
485 B2DEBUG(29,
"Refit of the combined track failed ");
490 const genfit::FitStatus* motherTrackFitStatus = recoTrackMother->
getTrackFitStatus();
491 const genfit::FitStatus* daughterTrackFitStatus = recoTrackDaughter->getTrackFitStatus();
492 const genfit::FitStatus* combinedTrackFitStatus = recoTrackCombinedRefit->getTrackFitStatus();
494 B2DEBUG(29,
"Initial mother fit result, p-value: " << motherTrackFitStatus->getPVal() <<
", ndf: " <<
495 motherTrackFitStatus->getNdf());
496 B2DEBUG(29,
"Initial daughter fit result, p-value: " << daughterTrackFitStatus->getPVal() <<
", ndf: " <<
497 daughterTrackFitStatus->getNdf());
498 B2DEBUG(29,
"Combined track fit result, p-value: " << combinedTrackFitStatus->getPVal() <<
", ndf: " <<
499 combinedTrackFitStatus->getNdf());
502 if (combinedTrackFitStatus->getNdf() < motherTrackFitStatus->getNdf())
506 const int motherFlag = (combinedTrackFitStatus->getPVal() > motherTrackFitStatus->getPVal());
507 const int daughterFlag = 2 * (combinedTrackFitStatus->getPVal() > daughterTrackFitStatus->getPVal());
508 const int daughterNdfFlag = 4 * (combinedTrackFitStatus->getNdf() > daughterTrackFitStatus->getNdf());
509 const int pValueFlag = 8 * (combinedTrackFitStatus->getPVal() > 0.0000001);
511 return motherFlag + daughterFlag + daughterNdfFlag + pValueFlag;
516 const bool motherFlag,
const unsigned int delta)
523 ROOT::Math::XYZVector positionSeed(0, 0, 0);
524 ROOT::Math::XYZVector momentumSeed(0, 0, 0);
525 const short chargeSeed =
splitRecoTrack->getTrackFitStatus()->getCharge();
528 positionSeed = ROOT::Math::XYZVector(
splitRecoTrack->getMeasuredStateOnPlaneFromFirstHit().getPos());
529 momentumSeed = ROOT::Math::XYZVector(
splitRecoTrack->getMeasuredStateOnPlaneFromFirstHit().getMom());
533 positionSeed = ROOT::Math::XYZVector(
splitRecoTrack->getMeasuredStateOnPlaneFromLastHit().getPos());
534 momentumSeed = ROOT::Math::XYZVector(
splitRecoTrack->getMeasuredStateOnPlaneFromLastHit().getMom());
554 recoTrack->
addPXDHit(pxdHit, recoHitInfo->getSortingParameter(),
555 recoHitInfo->getFoundByTrackFinder());
561 recoTrack->
addSVDHit(svdHit, recoHitInfo->getSortingParameter(),
562 recoHitInfo->getFoundByTrackFinder());
567 for (
size_t splitCDCHitIndex = 0; splitCDCHitIndex < splitCDCHit.size() - delta; ++splitCDCHitIndex) {
568 auto recoHitInfo =
splitRecoTrack->getRecoHitInformation(splitCDCHit[splitCDCHitIndex]);
569 recoTrack->
addCDCHit(splitCDCHit[splitCDCHitIndex],
570 recoHitInfo->getSortingParameter(),
571 recoHitInfo->getRightLeftInformation(),
572 recoHitInfo->getFoundByTrackFinder());
581 int sortingParameterOffset =
splitRecoTrack->getRecoHitInformation(splitCDCHit[splitCDCHit.size()
582 - delta])->getSortingParameter();
583 for (
size_t splitCDCHitIndex = splitCDCHit.size() - delta; splitCDCHitIndex < splitCDCHit.size(); ++splitCDCHitIndex) {
584 auto recoHitInfo =
splitRecoTrack->getRecoHitInformation(splitCDCHit[splitCDCHitIndex]);
585 recoTrack->
addCDCHit(splitCDCHit[splitCDCHitIndex],
586 splitCDCHitIndex - sortingParameterOffset,
587 recoHitInfo->getRightLeftInformation(),
588 recoHitInfo->getFoundByTrackFinder());
594 auto recoHitInfo =
splitRecoTrack->getRecoHitInformation(bklmHit);
595 recoTrack->
addBKLMHit(bklmHit, recoHitInfo->getSortingParameter() - sortingParameterOffset,
596 recoHitInfo->getFoundByTrackFinder());
601 auto recoHitInfo =
splitRecoTrack->getRecoHitInformation(eklmHit);
602 recoTrack->
addEKLMHit(eklmHit, recoHitInfo->getSortingParameter() - sortingParameterOffset,
603 recoHitInfo->getFoundByTrackFinder());
618 constexpr double defaultChi2NdfRatio = std::numeric_limits<double>::max();
622 c_outerEdge, c_middlePoint, c_innerEdge
625 B2DEBUG(29,
"Start splitting");
628 const genfit::FitStatus* splitTrackFitStatus = recoTrackSplit->
getTrackFitStatus();
629 const double ndfSplit = splitTrackFitStatus->getNdf();
630 const double chi2Split = splitTrackFitStatus->getChi2();
631 const double chi2NdfRatioSplit = fabs(chi2Split / ndfSplit - 1);
632 B2DEBUG(29,
"Initial fit result, p-value: " << splitTrackFitStatus->getPVal() <<
", chi2: " <<
633 chi2Split <<
", ndf: " << ndfSplit);
645 std::array<unsigned int, 3> splitHitNumber = {
646 static_cast<unsigned int>(numberSVDCDCHitsSplit * 0.2),
647 static_cast<unsigned int>(numberSVDCDCHitsSplit * 0.5),
648 static_cast<unsigned int>(numberSVDCDCHitsSplit * 0.8)
653 std::array<RecoTrack*, 3> recoTrackMother = {
nullptr,
nullptr,
nullptr};
654 std::array<RecoTrack*, 3> recoTrackDaughter = {
nullptr,
nullptr,
nullptr};
655 std::array<double, 3> chi2NdfRatio = {defaultChi2NdfRatio, defaultChi2NdfRatio, defaultChi2NdfRatio};
658 for (
size_t splitHitNumberIndex = 0; splitHitNumberIndex < splitHitNumber.size(); ++splitHitNumberIndex) {
660 if (splitHitNumber[splitHitNumberIndex] < 5 ||
661 (numberSVDCDCHitsSplit - splitHitNumber[splitHitNumberIndex]) < 5)
continue;
668 B2DEBUG(29,
"Initial splitting hit number for point " << splitHitNumberIndex <<
": " <<
669 splitHitNumber[splitHitNumberIndex]);
672 recoTrackMother[splitHitNumberIndex] =
copyRecoTrackAndSplit(recoTrackSplit,
true, splitHitNumber[splitHitNumberIndex]);
673 recoTrackDaughter[splitHitNumberIndex] =
copyRecoTrackAndSplit(recoTrackSplit,
false, splitHitNumber[splitHitNumberIndex]);
676 trackFitterDAF.
fit(*(recoTrackMother[splitHitNumberIndex]));
677 trackFitterDAF.
fit(*(recoTrackDaughter[splitHitNumberIndex]));
680 if (!recoTrackMother[splitHitNumberIndex]->wasFitSuccessful() ||
681 !recoTrackDaughter[splitHitNumberIndex]->wasFitSuccessful())
continue;
684 const genfit::FitStatus* motherNewTrackFitStatus = recoTrackMother[splitHitNumberIndex]->getTrackFitStatus();
685 const genfit::FitStatus* daughterNewTrackFitStatus = recoTrackDaughter[splitHitNumberIndex]->getTrackFitStatus();
686 const double ndfMotherTmp = motherNewTrackFitStatus->getNdf();
687 const double ndfDaughterTmp = daughterNewTrackFitStatus->getNdf();
688 const double chi2MotherTmp = motherNewTrackFitStatus->getChi2();
689 const double chi2DaughterTmp = daughterNewTrackFitStatus->getChi2();
690 const double chi2NdfRatioTmp = fabs((chi2MotherTmp + chi2DaughterTmp) / (ndfMotherTmp + ndfDaughterTmp) - 1);
691 B2DEBUG(29,
"Mother fit result for initial point " << splitHitNumberIndex <<
", p-value: " <<
692 motherNewTrackFitStatus->getPVal() <<
", chi2: " << chi2MotherTmp <<
", ndf: " << ndfMotherTmp);
693 B2DEBUG(29,
"Daughter fit result for initial point " << splitHitNumberIndex <<
", p-value: " <<
694 daughterNewTrackFitStatus->getPVal() <<
", chi2: " << chi2DaughterTmp <<
", ndf: " << ndfDaughterTmp);
695 B2DEBUG(29,
"|Chi2/NDF - 1| for initial point " << splitHitNumberIndex <<
": " <<
696 chi2NdfRatioTmp <<
", and for initial track: " << chi2NdfRatioSplit);
699 if (chi2NdfRatioTmp > chi2NdfRatioSplit)
continue;
701 chi2NdfRatio[splitHitNumberIndex] = chi2NdfRatioTmp;
712 for (
unsigned int searchIteration = 0; searchIteration < 5; ++searchIteration) {
713 B2DEBUG(29,
"Splitting iteration " << searchIteration <<
"; hit numbers: " << splitHitNumber[c_outerEdge] <<
", " <<
714 splitHitNumber[c_middlePoint] <<
", " << splitHitNumber[c_innerEdge]);
716 if (chi2NdfRatio[c_outerEdge] < chi2NdfRatio[c_innerEdge]) {
719 splitHitNumber[c_innerEdge] = splitHitNumber[c_middlePoint];
720 chi2NdfRatio[c_innerEdge] = chi2NdfRatio[c_middlePoint];
721 recoTrackMother[c_innerEdge] = recoTrackMother[c_middlePoint];
722 recoTrackDaughter[c_innerEdge] = recoTrackDaughter[c_middlePoint];
724 splitHitNumber[c_middlePoint] = (splitHitNumber[c_innerEdge] + splitHitNumber[c_outerEdge]) / 2;
725 chi2NdfRatio[c_middlePoint] = defaultChi2NdfRatio;
726 recoTrackMother[c_middlePoint] =
nullptr;
727 recoTrackDaughter[c_middlePoint] =
nullptr;
729 B2DEBUG(29,
"Outer interval is chosen; hit numbers: " << splitHitNumber[c_outerEdge] <<
", " <<
730 splitHitNumber[c_middlePoint] <<
", " << splitHitNumber[c_innerEdge]);
732 }
else if (chi2NdfRatio[c_outerEdge] > chi2NdfRatio[c_innerEdge]) {
735 splitHitNumber[c_outerEdge] = splitHitNumber[c_middlePoint];
736 chi2NdfRatio[c_outerEdge] = chi2NdfRatio[c_middlePoint];
737 recoTrackMother[c_outerEdge] = recoTrackMother[c_middlePoint];
738 recoTrackDaughter[c_outerEdge] = recoTrackDaughter[c_middlePoint];
740 splitHitNumber[c_middlePoint] = (splitHitNumber[c_innerEdge] + splitHitNumber[c_outerEdge]) / 2;
741 chi2NdfRatio[c_middlePoint] = defaultChi2NdfRatio;
742 recoTrackMother[c_middlePoint] =
nullptr;
743 recoTrackDaughter[c_middlePoint] =
nullptr;
745 B2DEBUG(29,
"Inner interval is chosen; hit numbers: " << splitHitNumber[c_outerEdge] <<
", " <<
746 splitHitNumber[c_middlePoint] <<
", " << splitHitNumber[c_innerEdge]);
748 }
else if (chi2NdfRatio[c_middlePoint] == defaultChi2NdfRatio) {
750 B2DEBUG(29,
"Track splitting failed");
755 B2DEBUG(29,
"Middle point is chosen; hit numbers: " << splitHitNumber[c_outerEdge] <<
", " <<
756 splitHitNumber[c_middlePoint] <<
", " << splitHitNumber[c_innerEdge]);
758 recoTrackIndexMother = recoTrackMother[c_middlePoint]->getArrayIndex();
759 recoTrackIndexDaughter = recoTrackDaughter[c_middlePoint]->getArrayIndex();
765 if (splitHitNumber[c_middlePoint] == splitHitNumber[c_outerEdge] ||
766 splitHitNumber[c_middlePoint] == splitHitNumber[c_innerEdge])
break;
769 if (splitHitNumber[c_middlePoint] < 5 ||
770 (numberSVDCDCHitsSplit - splitHitNumber[c_middlePoint]) < 5)
continue;
773 recoTrackMother[c_middlePoint] =
copyRecoTrackAndSplit(recoTrackSplit,
true, splitHitNumber[c_middlePoint]);
774 recoTrackDaughter[c_middlePoint] =
copyRecoTrackAndSplit(recoTrackSplit,
false, splitHitNumber[c_middlePoint]);
777 trackFitterDAF.
fit(*(recoTrackMother[c_middlePoint]));
778 trackFitterDAF.
fit(*(recoTrackDaughter[c_middlePoint]));
781 if (!recoTrackMother[c_middlePoint]->wasFitSuccessful() ||
782 !recoTrackDaughter[c_middlePoint]->wasFitSuccessful())
continue;
785 const genfit::FitStatus* motherNewTrackFitStatus = recoTrackMother[c_middlePoint]->getTrackFitStatus();
786 const genfit::FitStatus* daughterNewTrackFitStatus = recoTrackDaughter[c_middlePoint]->getTrackFitStatus();
787 const double ndfMotherTmp = motherNewTrackFitStatus->getNdf();
788 const double ndfDaughterTmp = daughterNewTrackFitStatus->getNdf();
789 const double chi2MotherTmp = motherNewTrackFitStatus->getChi2();
790 const double chi2DaughterTmp = daughterNewTrackFitStatus->getChi2();
791 const double chi2NdfRatioTmp = fabs((chi2MotherTmp + chi2DaughterTmp) / (ndfMotherTmp + ndfDaughterTmp) - 1);
793 B2DEBUG(29,
"Mother fit result for approach " << searchIteration <<
", p-value: " <<
794 motherNewTrackFitStatus->getPVal() <<
", chi2: " << chi2MotherTmp <<
", ndf: " << ndfMotherTmp);
795 B2DEBUG(29,
"Daughter fit result for approach " << searchIteration <<
", p-value: " <<
796 daughterNewTrackFitStatus->getPVal() <<
", chi2: " << chi2DaughterTmp <<
", ndf: " << ndfDaughterTmp);
797 B2DEBUG(29,
"Chi2/NDF for approach " << searchIteration <<
": " <<
798 chi2NdfRatioTmp <<
", and for initial track: " << chi2NdfRatioSplit);
801 if (chi2NdfRatioTmp > chi2NdfRatioSplit)
continue;
803 chi2NdfRatio[c_middlePoint] = chi2NdfRatioTmp;
807 std::array<double, 3>::iterator minChi2NdfRatioResult = std::min_element(chi2NdfRatio.begin(), chi2NdfRatio.end());
808 const size_t minIndex = std::distance(chi2NdfRatio.begin(), minChi2NdfRatioResult);
811 B2DEBUG(29,
"End of splitting with |chi2/ndf - 1| for point 1:" << chi2NdfRatio[c_outerEdge] <<
812 "; 2:" << chi2NdfRatio[c_middlePoint] <<
"; 3:" << chi2NdfRatio[c_innerEdge]);
813 B2DEBUG(29,
"Hit numbers for point 1:" << splitHitNumber[c_outerEdge] <<
814 "; 2:" << splitHitNumber[c_middlePoint] <<
"; 3:" << splitHitNumber[c_innerEdge]);
815 B2DEBUG(29,
"Min index: " << minIndex);
818 recoTrackIndexMother = recoTrackMother[minIndex]->getArrayIndex();
819 recoTrackIndexDaughter = recoTrackDaughter[minIndex]->getArrayIndex();
836 if (filterFlag >= 7 && filterFlag <= 9) {
837 short recoTrackIndexMother = -1;
838 short recoTrackIndexDaughter = -1;
839 if (!
splitRecoTrack(recoTrackMother, recoTrackIndexMother, recoTrackIndexDaughter))
851 bool refitBadFlag =
false;
852 if (filterFlag == 4 || filterFlag == 6) {
853 B2DEBUG(29,
"Try to do initial refit of daughter track for filterFlag " << filterFlag);
862 ROOT::Math::XYZVector momSeedDaughterRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromFirstHit().getMom());
866 bool blockInnerStereoHits =
false;
867 if (filterFlag == 4) blockInnerStereoHits =
true;
869 bool anotherFitter =
false;
870 if (filterFlag == 6) anotherFitter =
true;
874 motherPosLast, timeSeedDaughterRefit,
875 blockInnerStereoHits, anotherFitter);
881 if (filterFlag == 4 ||
883 recoTrackDaughter = recoTrackDaughterRefit;
884 B2DEBUG(29,
"Initial refit successful");
891 B2DEBUG(29,
"Try to do initial flip and refit of daughter track for filterFlag " << filterFlag);
900 ROOT::Math::XYZVector momSeedDaughterFlipAndRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromLastHit().getMom());
904 motherPosLast, momSeedDaughterFlipAndRefit,
905 timeSeedDaughterFlipAndRefit);
909 recoTrackDaughter = recoTrackDaughterFlipAndRefit;
910 B2DEBUG(29,
"Initial flip and refit successful");
918 unsigned int reassignHitStatus = 0;
919 int finalHitPositionForReassignment = 0;
920 double distanceAtVertex = std::numeric_limits<double>::max();
925 bool failedFitFlag = !
vertexFitWithRecoTracks(recoTrackMother, recoTrackDaughter, reassignHitStatus, vertexPos, distanceAtVertex,
927 if (failedFitFlag && (filterFlag != 1 && filterFlag != 3))
932 if (failedFitFlag && filterFlag == 1) {
933 B2DEBUG(29,
"Try to do postVertexFit refit of daughter track for filterFlag " << filterFlag);
942 const ROOT::Math::XYZVector momSeedDaughterRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromFirstHit().getMom());
946 const bool blockInnerStereoHits =
true;
948 const bool anotherFitter =
false;
952 motherPosLast, timeSeedDaughterRefit,
953 blockInnerStereoHits, anotherFitter);
958 vertexFitWithRecoTracks(recoTrackMother, recoTrackDaughterRefit, reassignHitStatus, vertexPos, distanceAtVertex,
960 recoTrackDaughter = recoTrackDaughterRefit;
961 B2DEBUG(29,
"postVertexFit refit successful");
970 if ((filterFlag == 4 || (failedFitFlag && filterFlag == 1)) && (refitBadFlag) && (reassignHitStatus == 0))
971 reassignHitStatus |= 0x1;
985 (filterFlag == 1 || filterFlag == 4 ||
987 (reassignHitStatus != 0)) {
988 B2DEBUG(29,
"Start of the hits reassignment for filterFlag " << filterFlag);
991 unsigned short countReassignTries = 0;
994 int finalHitPositionForReassignmentTmp = 0;
995 double distanceAtVertexTmp = std::numeric_limits<double>::max();
996 ROOT::Math::XYZVector vertexPosTmp(vertexPos);
997 RecoTrack* recoTrackMotherRefit =
nullptr;
998 RecoTrack* recoTrackDaughterRefit =
nullptr;
999 RecoTrack* recoTrackMotherBuffer = recoTrackMother;
1000 RecoTrack* recoTrackDaughterBuffer = recoTrackDaughter;
1003 while (reassignHitStatus != 0 && countReassignTries < 3) {
1004 ++countReassignTries;
1005 B2DEBUG(29,
"Try number " << countReassignTries);
1008 unsigned short countBadReassignTries = 0;
1013 int hitPositionForReassignment = 0;
1014 if (reassignHitStatus & 0x1) {
1021 if (
static_cast<unsigned int>(-hitPositionForReassignment + 5) >
1025 }
else if (reassignHitStatus & 0x2) {
1032 if (
static_cast<unsigned int>(hitPositionForReassignment + 5) > recoTrackMotherBuffer->
getNumberOfCDCHits()) {
1042 B2DEBUG(29,
"Found hit index, starting from which hits are reassigned: " << hitPositionForReassignment);
1046 while (hitPositionForReassignment != 0) {
1050 recoTrackDaughterBuffer,
1051 true, hitPositionForReassignment);
1053 recoTrackDaughterBuffer,
1054 false, hitPositionForReassignment);
1060 recoTrackMother, recoTrackDaughter)) {
1061 if (hitPositionForReassignment > 0) {
1062 --hitPositionForReassignment;
1064 ++hitPositionForReassignment;
1066 ++countBadReassignTries;
1068 if (countBadReassignTries > 5) hitPositionForReassignment = 0;
1071 B2DEBUG(29,
"Refit of the tracks failed, try with smaller hit index: " << hitPositionForReassignment);
1075 if (hitPositionForReassignment == 0) {
1076 B2DEBUG(29,
"Reassigning of hits and refitting failed");
1082 vertexPosTmp, distanceAtVertexTmp, vertexPosTmp))
1084 recoTrackMotherBuffer = recoTrackMotherRefit;
1085 recoTrackDaughterBuffer = recoTrackDaughterRefit;
1086 finalHitPositionForReassignmentTmp += hitPositionForReassignment;
1090 distanceAtVertex = distanceAtVertexTmp;
1091 vertexPos = vertexPosTmp;
1097 finalHitPositionForReassignment = finalHitPositionForReassignmentTmp;
1105 B2DEBUG(29,
"Try to do postVertexFit flip and refit of daughter track for filterFlag " << filterFlag);
1108 double distanceAtVertexTmp = std::numeric_limits<double>::max();
1109 ROOT::Math::XYZVector vertexPosTmp(vertexPos);
1116 const ROOT::Math::XYZVector momSeedDaughterFlipAndRefit(stDaughter.getMom());
1120 vertexPos, momSeedDaughterFlipAndRefit,
1121 timeSeedDaughterFlipAndRefit);
1126 vertexPosTmp, distanceAtVertexTmp, vertexPosTmp))
1127 if (distanceAtVertexTmp < distanceAtVertex) {
1128 distanceAtVertex = distanceAtVertexTmp;
1129 vertexPos = vertexPosTmp;
1134 B2DEBUG(29,
"postVertexFit flip and refit successful");
1140 if (filterFlag == 3) {
1141 B2DEBUG(29,
"Try to do postVertexFit refit of daughter track for filterFlag " << filterFlag);
1150 const ROOT::Math::XYZVector momSeedDaughterRefit(recoTrackDaughter->getMeasuredStateOnPlaneFromFirstHit().getMom());
1153 double distanceAtVertexTmp = std::numeric_limits<double>::max();
1154 ROOT::Math::XYZVector vertexPosTmp(vertexPos);
1158 const bool blockInnerStereoHits =
false;
1160 const bool anotherFitter =
true;
1164 motherPosLast, timeSeedDaughterRefit,
1165 blockInnerStereoHits, anotherFitter);
1170 vertexPosTmp, distanceAtVertexTmp, vertexPosTmp)) {
1171 if ((distanceAtVertexTmp < distanceAtVertex) || failedFitFlag) {
1172 distanceAtVertex = distanceAtVertexTmp;
1173 vertexPos = vertexPosTmp;
1178 B2DEBUG(29,
"postVertexFit refit successful");
1180 }
else if (failedFitFlag)
return false;
1183 B2DEBUG(29,
"Distance between tracks at fitted kink vertex " << distanceAtVertex);
1184 B2DEBUG(29,
"Radius of the kink vertex " << vertexPos.Rho());
1185 B2DEBUG(29,
"Number of reassigned hits " << finalHitPositionForReassignment);
1194 short filterFlagToStore = 0;
1195 switch (filterFlag) {
1200 filterFlagToStore = 1;
1204 filterFlagToStore = 2;
1207 filterFlagToStore = 3;
1210 filterFlagToStore = 4;
1213 filterFlagToStore = 5;
1222 filterFlagToStore += 10;
1226 if (vertexPos.Rho() < 14)
1234 B2DEBUG(29,
"Could not extrapolate mother track to IP.");
1250 filterFlagToStore += combinedFitFlag * 10;
1257 if (abs(finalHitPositionForReassignment) < 32) {
1258 if (finalHitPositionForReassignment >= 0)
1259 filterFlagToStore += finalHitPositionForReassignment * 1000;
1261 filterFlagToStore *= -1;
1262 filterFlagToStore += finalHitPositionForReassignment * 1000;
1265 filterFlagToStore += 32 * 1000;
1269 m_kinks.appendNew(std::make_pair(trackMother, std::make_pair(tfrMotherIP, tfrMotherVtx)),
1270 std::make_pair(trackDaughter, tfrDaughterVtx),
1271 vertexPos.X(), vertexPos.Y(), vertexPos.Z(), filterFlagToStore);
1281 unsigned int& reassignHitStatus,
1282 ROOT::Math::XYZVector& vertexPos,
double& distance,
1283 ROOT::Math::XYZVector vertexPosSeed)
1288 if ((motherRepresentation ==
nullptr) || !(recoTrackMother->
wasFitSuccessful(motherRepresentation))) {
1289 B2ERROR(
"Cardinal representation is not available for track. Should never happen, but I can continue safely anyway.");
1293 const double motherMass = TDatabasePDG::Instance()->GetParticle(motherRepresentation->getPDG())->Mass();
1298 if ((daughterRepresentation ==
nullptr) || !(recoTrackDaughter->
wasFitSuccessful(daughterRepresentation))) {
1299 B2ERROR(
"Cardinal representation is not available for track. Should never happen, but I can continue safely anyway.");
1303 const double daughterMass = TDatabasePDG::Instance()->GetParticle(daughterRepresentation->getPDG())->Mass();
1304 const double daughterCharge = recoTrackDaughter->
getTrackFitStatus()->getCharge();
1309 daughterRepresentation);
1321 HepPoint3D vertexPosSeedHepPoint(vertexPosSeed.X(), vertexPosSeed.Y(), vertexPosSeed.Z());
1325 TVector3 motherPosition, motherMomentum;
1326 TMatrixDSym motherCovMatrix6(6, 6);
1327 stMother.getPosMomCov(motherPosition, motherMomentum, motherCovMatrix6);
1329 const double motherEnergy =
sqrt(motherMomentum.Mag2() + motherMass * motherMass);
1330 ROOT::Math::PxPyPzEVector motherFourMomentum(motherMomentum.X(), motherMomentum.Y(),
1331 motherMomentum.Z(), motherEnergy);
1333 TMatrixDSym motherErrMatrixForKFit(7);
1334 errMatrixForKFit(motherFourMomentum, motherCovMatrix6, motherErrMatrixForKFit);
1336 kvf.
addTrack(ROOTToCLHEP::getHepLorentzVector(motherFourMomentum),
1337 ROOTToCLHEP::getPoint3D(ROOT::Math::XYZVector(motherPosition)),
1338 ROOTToCLHEP::getHepSymMatrix(motherErrMatrixForKFit),
1342 TVector3 daughterPosition, daughterMomentum;
1343 TMatrixDSym daughterCovMatrix6(6, 6);
1344 stDaughter.getPosMomCov(daughterPosition, daughterMomentum, daughterCovMatrix6);
1346 const double daughterEnergy =
sqrt(daughterMomentum.Mag2() + daughterMass * daughterMass);
1347 ROOT::Math::PxPyPzEVector daughterFourMomentum(daughterMomentum.X(), daughterMomentum.Y(),
1348 daughterMomentum.Z(), daughterEnergy);
1350 TMatrixDSym daughterErrMatrixForKFit(7);
1351 errMatrixForKFit(daughterFourMomentum, daughterCovMatrix6, daughterErrMatrixForKFit);
1353 kvf.
addTrack(ROOTToCLHEP::getHepLorentzVector(daughterFourMomentum),
1354 ROOTToCLHEP::getPoint3D(ROOT::Math::XYZVector(daughterPosition)),
1355 ROOTToCLHEP::getHepSymMatrix(daughterErrMatrixForKFit),
1359 int err = kvf.
doFit();
1361 B2DEBUG(29,
"Vertex fit finished with error");
1367 B2DEBUG(29,
"Chi^2 of vertex fit is too large: " << kvf.
getCHIsq());
1373 vertexPos = ROOT::Math::XYZVector(vertexPosHepPoint.x(), vertexPosHepPoint.y(), vertexPosHepPoint.z());
1377 B2DEBUG(29,
"Failed to extrapolate one of the tracks to the fitted kink vertex");
1382 const ROOT::Math::XYZVector motherPos = ROOT::Math::XYZVector(stMother.getPos());
1383 const ROOT::Math::XYZVector motherMom = ROOT::Math::XYZVector(stMother.getMom());
1384 Helix motherHelix(motherPos,
1388 motherHelix.passiveMoveBy(vertexPos);
1391 const ROOT::Math::XYZVector daughterPos = ROOT::Math::XYZVector(stDaughter.getPos());
1392 const ROOT::Math::XYZVector daughterMom = ROOT::Math::XYZVector(stDaughter.getMom());
1393 Helix daughterHelix(daughterPos,
1397 daughterHelix.passiveMoveBy(vertexPos);
1400 distance =
sqrt(daughterHelix.getD0() * daughterHelix.getD0() + daughterHelix.getZ0() * daughterHelix.getZ0() +
1401 motherHelix.getD0() * motherHelix.getD0() + motherHelix.getZ0() * motherHelix.getZ0());
1407 B2DEBUG(29,
"Vertex fit with chi2 " << kvf.
getCHIsq() <<
" and distance between tracks " << distance);
1413 TMatrixDSym& errMatrix7)
1417 c_Px, c_Py, c_Pz, c_E, c_X, c_Y, c_Z
1419 constexpr unsigned order[] = {c_X, c_Y, c_Z, c_Px, c_Py, c_Pz};
1421 for (
int i = 0; i < 6; i++) {
1422 for (
int j = i; j < 6; j++) {
1423 errMatrix7(order[j], order[i]) = errMatrix7(order[i], order[j]) = covMatrix6(i, j);
1427 const double dEdp[] = {fourMomentum.X() / fourMomentum.E(),
1428 fourMomentum.Y() / fourMomentum.E(),
1429 fourMomentum.Z() / fourMomentum.E()
1431 constexpr unsigned componentMom[] = {c_Px, c_Py, c_Pz};
1432 constexpr unsigned componentPos[] = {c_X, c_Y, c_Z};
1436 for (
unsigned int comp : componentMom) {
1437 double covariance = 0;
1438 for (
int k = 0; k < 3; k++) {
1439 covariance += errMatrix7(comp, componentMom[k]) * dEdp[k];
1441 errMatrix7(comp, c_E) = covariance;
1445 for (
unsigned int comp : componentPos) {
1446 double covariance = 0;
1447 for (
int k = 0; k < 3; k++) {
1448 covariance += errMatrix7(comp, componentMom[k]) * dEdp[k];
1450 errMatrix7(c_E, comp) = covariance;
1454 double covariance = 0;
1455 for (
int i = 0; i < 3; i++) {
1456 covariance += errMatrix7(componentMom[i], componentMom[i]) * dEdp[i] * dEdp[i];
1458 for (
int i = 0; i < 3; i++) {
1459 int k = (i + 1) % 3;
1460 covariance += 2 * errMatrix7(componentMom[i], componentMom[k]) * dEdp[i] * dEdp[k];
1462 errMatrix7(c_E, c_E) = covariance;
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
The ParticleType class for identifying different particle types.
static const ChargedStable pion
charged pion particle
@ c_WriteOut
Object/array should be saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
bool splitRecoTrack(const RecoTrack *recoTrackSplit, short &recoTrackIndexMother, short &recoTrackIndexDaughter)
Split track into two based on |chi2/ndf - 1|.
bool refitRecoTrackAfterReassign(RecoTrack *recoTrackMotherRefit, RecoTrack *recoTrackDaughterRefit, const RecoTrack *recoTrackMother, const RecoTrack *recoTrackDaughter)
Try to fit new RecoTracks after hit reassignment.
StoreArray< RecoTrack > m_copiedRecoTracks
RecoTrack used to refit tracks.
genfit::MeasuredStateOnPlane m_stMotherBuffer
buffer for the MeasuredStateOnPlane of mother obtained in the vertex fit
bool vertexFitWithRecoTracks(RecoTrack *recoTrackMother, RecoTrack *recoTrackDaughter, unsigned int &reassignHitStatus, ROOT::Math::XYZVector &vertexPos, double &distance, ROOT::Math::XYZVector vertexPosSeed=ROOT::Math::XYZVector(0, 0, 0))
Fit kink vertex using RecoTrack's as inputs.
StoreArray< Kink > m_kinks
Kink (output).
bool m_kinkFitterModeCombineAndFit
fitter mode 3rd bit
RecoTrack * m_motherKinkRecoTrackCache
cache for the RecoTrack of mother used to find the best vertex
double m_vertexDistanceCut
cut on the distance at the found vertex.
RecoTrack * copyRecoTrackForRefit(const RecoTrack *recoTrack, const ROOT::Math::XYZVector &momentumSeed, const ROOT::Math::XYZVector &positionSeed, const double &timeSeed, const bool blockInnerStereoHits=false, const bool useAnotherFitter=false)
Refit the daughter track blocking hits if required.
double m_vertexChi2Cut
Chi2 cut.
bool fitAndStore(const Track *trackMother, const Track *trackDaughter, short filterFlag)
Fit kink with cardinal hypothesis and store it if the fit was successful.
StoreArray< TrackFitResult > m_trackFitResults
TrackFitResult (output).
int findHitPositionForReassignment(const RecoTrack *recoTrack, ROOT::Math::XYZVector &vertexPos, int direction)
Find hit position closest to the vertex.
RecoTrack * m_daughterKinkRecoTrackCache
cache for the RecoTrack of daughter used to find the best vertex
bool extrapolateToVertex(genfit::MeasuredStateOnPlane &stMother, genfit::MeasuredStateOnPlane &stDaughter, const ROOT::Math::XYZVector &vertexPosition, unsigned int &reassignHitStatus)
Extrapolate the fit results to the perigee to the kink vertex.
double m_precutDistance
Preselection cut on distance between ending points of two tracks used in prefilter.
KinkFitter(const std::string &trackFitResultsName="", const std::string &kinksName="", const std::string &recoTracksName="", const std::string &copiedRecoTracksName="RecoTracksKinkTmp")
Constructor for the KinkFitter.
std::string m_recoTracksName
RecoTrackColName (input).
TrackFitResult * buildTrackFitResult(RecoTrack *recoTrack, const genfit::MeasuredStateOnPlane &msop, const double Bz, const Const::ParticleType trackHypothesis)
Build TrackFitResult of the Kink Track.
bool m_kinkFitterModeSplitTrack
fitter mode 4th bit
bool m_kinkFitterModeHitsReassignment
fitter mode 1st bit
RecoTrack * copyRecoTrackAndSplit(const RecoTrack *splitRecoTrack, const bool motherFlag, const unsigned int delta)
Create a RecoTrack in a separate StoreArray based on one to be split.
StoreArray< RecoTrack > m_recoTracks
RecoTrack (input)
bool isRefitImproveFilter6(const RecoTrack *recoTrackDaughterRefit, const ROOT::Math::XYZVector &motherPosLast)
check if the refit of filter 6 daughter tracks improves the distance between mother and daughter
RecoTrack * copyRecoTrackForFlipAndRefit(const RecoTrack *recoTrack, const ROOT::Math::XYZVector &momentumSeed, const ROOT::Math::XYZVector &positionSeed, const double &timeSeed)
Flip and refit the daughter track.
RecoTrack * copyRecoTrackAndReassignCDCHits(RecoTrack *motherRecoTrack, RecoTrack *daughterRecoTrack, const bool motherFlag, const int delta)
Copy RecoTrack to a separate StoreArray and reassign CDC hits according to delta.
bool m_kinkFitterModeFlipAndRefit
fitter mode 2nd bit
unsigned char m_kinkFitterMode
fitter mode from 0 to 15 written in bits:
void initializeCuts(const double vertexDistanceCut, const double vertexChi2Cut, const double precutDistance)
Initialize the cuts which will be applied during the fit and store process.
void errMatrixForKFit(ROOT::Math::PxPyPzEVector &fourMomentum, TMatrixDSym &covMatrix6, TMatrixDSym &errMatrix7)
Prepare the error matrix for the kFit.
genfit::MeasuredStateOnPlane m_stDaughterBuffer
buffer for the MeasuredStateOnPlane of daughter obtained in the vertex fit
void setFitterMode(const unsigned char fitterMode)
set kink fitter mode.
unsigned int combineTracksAndFit(const Track *trackMother, const Track *trackDaughter)
Combine daughter and mother tracks in one and fit.
This is the Reconstruction Event-Data Model Track.
size_t addHitsFromRecoTrack(const RecoTrack *recoTrack, unsigned int sortingParameterOffset=0, bool reversed=false, std::optional< double > optionalMinimalWeight=std::nullopt)
Add all hits from another RecoTrack to this RecoTrack.
const TMatrixDSym & getSeedCovariance() const
Return the covariance matrix of the seed. ATTENTION: This is not the fitted covariance.
bool addBKLMHit(const UsedBKLMHit *bklmHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a bklm hit with the given information to the reco track.
bool addCDCHit(const UsedCDCHit *cdcHit, const unsigned int sortingParameter, RightLeftInformation rightLeftInformation=RightLeftInformation::c_undefinedRightLeftInformation, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a cdc hit with the given information to the reco track.
std::vector< Belle2::RecoTrack::UsedPXDHit * > getPXDHitList() const
Return an unsorted list of pxd hits.
const std::string & getStoreArrayNameOfEKLMHits() const
Name of the store array of the eklm hits.
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
std::vector< Belle2::RecoTrack::UsedSVDHit * > getSVDHitList() const
Return an unsorted list of svd hits.
bool addEKLMHit(const UsedEKLMHit *eklmHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds an eklm hit with the given information to the reco track.
bool addPXDHit(const UsedPXDHit *pxdHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a pxd hit with the given information to the reco track.
std::vector< Belle2::RecoTrack::UsedCDCHit * > getSortedCDCHitList() const
Return a sorted list of cdc hits. Sorted by the sortingParameter.
std::vector< Belle2::RecoTrack::UsedBKLMHit * > getBKLMHitList() const
Return an unsorted list of bklm hits.
const std::string & getStoreArrayNameOfSVDHits() const
Name of the store array of the svd hits.
ROOT::Math::XYZVector getPositionSeed() const
Return the position seed stored in the reco track. ATTENTION: This is not the fitted position.
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
const std::string & getStoreArrayNameOfPXDHits() const
Name of the store array of the pxd hits.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneClosestTo(const ROOT::Math::XYZVector &closestPoint, const genfit::AbsTrackRep *representation=nullptr)
Return genfit's MasuredStateOnPlane, that is closest to the given point useful for extrapolation of m...
unsigned int getNumberOfSVDHits() const
Return the number of svd hits.
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
std::vector< Belle2::RecoTrack::UsedEKLMHit * > getEKLMHitList() const
Return an unsorted list of eklm hits.
const std::string & getStoreArrayNameOfBKLMHits() const
Name of the store array of the bklm hits.
void setTimeSeed(const double timeSeed)
Set the time seed. ATTENTION: This is not the fitted time.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromLastHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the last hit in a fit useful for extrapolation of measuremen...
void setSeedCovariance(const TMatrixDSym &seedCovariance)
Set the covariance of the seed. ATTENTION: This is not the fitted covariance.
const std::string & getStoreArrayNameOfRecoHitInformation() const
Name of the store array of the reco hit information.
RecoHitInformation * getRecoHitInformation(HitType *hit) const
Return the reco hit information for a generic hit from the storeArray.
static void registerRequiredRelations(StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
const std::string & getStoreArrayNameOfCDCHits() const
Name of the store array of the cdc hits.
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the first hit in a fit useful for extrapolation of measureme...
ROOT::Math::XYZVector getMomentumSeed() const
Return the momentum seed stored in the reco track. ATTENTION: This is not the fitted momentum.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromRecoHit(const RecoHitInformation *recoHitInfo, const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane on plane for associated with one RecoHitInformation.
bool addSVDHit(const UsedSVDHit *svdHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a svd hit with the given information to the reco track.
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
double getTimeSeed() const
Return the time seed stored in the reco track. ATTENTION: This is not the fitted time.
unsigned int getNumberOfTotalHits() const
Return the number of cdc + svd + pxd + bklm + eklm hits.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
T * appendNew()
Construct a new T object at the end of the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
static uint32_t getHitPatternVXDInitializer(const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
Get the HitPattern in the VXD.
static uint64_t getHitPatternCDCInitializer(const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
Get the HitPattern in the CDC.
Values of the result of a track fit with a given particle hypothesis.
Algorithm class to handle the fitting of RecoTrack objects.
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation, bool resortHits=false) const
Fit a reco track with a given non-default track representation.
void resetFitter(const std::shared_ptr< genfit::AbsFitter > &fitter)
Set the internal storage of the fitter to a provided one, if you want to use non-default settings.
Class that bundles various TrackFitResults.
enum KFitError::ECode addTrack(const KFitTrack &kp)
Add a track to the fitter object.
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
VertexFitKFit is a derived class from KFitBase to perform vertex-constraint kinematical fit.
enum KFitError::ECode setInitialVertex(const HepPoint3D &v)
Set an initial vertex point for the vertex-vertex constraint fit.
double getCHIsq(void) const override
Get a chi-square of the fit.
enum KFitError::ECode doFit(void)
Perform a vertex-constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
B2Vector3< double > B2Vector3D
typedef for common usage with double
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.