9 #include <analysis/modules/TagVertex/TagVertexModule.h>
15 #include <framework/gearbox/Unit.h>
16 #include <framework/gearbox/Const.h>
17 #include <framework/logging/Logger.h>
20 #include <analysis/dataobjects/RestOfEvent.h>
21 #include <analysis/dataobjects/FlavorTaggerInfo.h>
24 #include <analysis/utility/PCmsLabTransform.h>
25 #include <analysis/variables/TrackVariables.h>
26 #include <analysis/utility/ParticleCopy.h>
27 #include <analysis/utility/CLHEPToROOT.h>
28 #include <analysis/utility/ROOTToCLHEP.h>
29 #include <analysis/utility/DistanceTools.h>
30 #include <analysis/utility/RotationTools.h>
33 #include <analysis/VertexFitting/KFit/VertexFitKFit.h>
36 #include <mdst/dataobjects/HitPatternVXD.h>
39 #include <framework/geometry/BFieldManager.h>
42 #include <TRotation.h>
54 static const double realNaN = std::numeric_limits<double>::quiet_NaN();
58 static const TMatrixDSym
matNaN(3, (
double [])
66 using RotationTools::rotateTensor;
67 using RotationTools::rotateTensorInv;
68 using RotationTools::toSymMatrix;
69 using RotationTools::toVec;
70 using RotationTools::getUnitOrthogonal;
82 m_Bfield(0), m_fitTruthStatus(0), m_rollbackStatus(0), m_fitPval(0), m_mcTagLifeTime(-1), m_mcPDG(0), m_mcLifeTimeReco(-1),
83 m_deltaT(0), m_deltaTErr(0), m_mcDeltaTau(0), m_mcDeltaT(0),
84 m_shiftZ(0), m_FitType(0), m_tagVl(0),
85 m_truthTagVl(0), m_tagVlErr(0), m_tagVol(0), m_truthTagVol(0), m_tagVolErr(0), m_tagVNDF(0), m_tagVChi2(0), m_tagVChi2IP(0),
89 setDescription(
"Tag side Vertex Fitter for modular analysis");
92 addParam(
"listName", m_listName,
"name of particle list",
string(
""));
93 addParam(
"confidenceLevel", m_confidenceLevel,
94 "required confidence level of fit to keep particles in the list. Note that even with confidenceLevel == 0.0, errors during the fit might discard Particles in the list. confidenceLevel = -1 if an error occurs during the fit",
96 addParam(
"MCAssociation", m_useMCassociation,
97 "'': no MC association. breco: use standard Breco MC association. internal: use internal MC association",
string(
"breco"));
98 addParam(
"constraintType", m_constraintType,
99 "Choose the type of the constraint: noConstraint, IP (tag tracks constrained to be within the beam spot), tube (long tube along the BTag line of flight, only for fully reconstruced B rec), boost (long tube along the Upsilon(4S) boost direction), (breco)",
101 addParam(
"trackFindingType", m_trackFindingType,
102 "Choose how to reconstruct the tracks on the tag side: standard, standard_PXD",
103 string(
"standard_PXD"));
104 addParam(
"maskName", m_roeMaskName,
105 "Choose ROE mask to get particles from ",
string(
""));
106 addParam(
"askMCInformation", m_mcInfo,
107 "TRUE when requesting MC Information from the tracks performing the vertex fit",
false);
108 addParam(
"reqPXDHits", m_reqPXDHits,
109 "Minimum number of PXD hits for a track to be used in the vertex fit", 0);
110 addParam(
"fitAlgorithm", m_fitAlgo,
111 "Fitter used for the tag vertex fit: Rave or KFit",
string(
"Rave"));
112 addParam(
"useTruthInFit", m_useTruthInFit,
113 "Use the true track parameters in the vertex fit",
false);
114 addParam(
"useRollBack", m_useRollBack,
115 "Use rolled back non-primary tracks",
false);
118 void TagVertexModule::initialize()
121 m_Bfield = BFieldManager::getField(m_BeamSpotCenter).Z() / Unit::T;
123 analysis::RaveSetup::initialize(1, m_Bfield);
124 B2INFO(
"TagVertexModule : magnetic field = " << m_Bfield);
126 if (m_useTruthInFit) m_fitTruthStatus = 1;
128 if (m_useRollBack) m_rollbackStatus = 1;
132 m_plist.isRequired(m_listName);
134 m_verArray.registerInDataStore();
137 if (m_fitAlgo !=
"Rave" && m_fitAlgo !=
"KFit")
138 B2FATAL(
"TagVertexModule: invalid fitting algorithm (must be set to either Rave or KFit).");
139 if (m_useRollBack && m_useTruthInFit)
140 B2FATAL(
"TagVertexModule: invalid fitting option (useRollBack and useTruthInFit cannot be simultaneously set to true).");
142 if (m_trackFindingType ==
"singleTrack" || m_trackFindingType ==
"singleTrack_PXD")
143 B2FATAL(
"TagVertexModule : the singleTrack option is temporarily broken.");
146 void TagVertexModule::beginRun()
152 void TagVertexModule::event()
155 B2ERROR(
"TagVertexModule: ParticleList " << m_listName <<
" not found");
160 analysis::RaveSetup::initialize(1, m_Bfield);
162 std::vector<unsigned int> toRemove;
164 for (
unsigned i = 0; i < m_plist->getListSize(); ++i) {
167 Particle* particle = m_plist->getParticle(i);
168 if (m_useMCassociation ==
"breco" || m_useMCassociation ==
"internal") BtagMCVertex(particle);
169 bool ok = doVertexFit(particle);
170 if (ok) deltaT(particle);
172 if ((m_fitPval < m_confidenceLevel && m_confidenceLevel != 0)
173 || (m_fitPval <= m_confidenceLevel && m_confidenceLevel == 0)) {
174 toRemove.push_back(particle->getArrayIndex());
179 particle->addRelationTo(ver);
241 m_plist->removeParticles(toRemove);
245 analysis::RaveSetup::getInstance()->reset();
248 bool TagVertexModule::doVertexFit(
const Particle* Breco)
252 if (m_useTruthInFit) m_fitTruthStatus = 1;
256 if (m_useRollBack) m_rollbackStatus = 1;
268 B2ERROR(
"TagVertex: No magnetic field");
274 m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
275 m_BeamSpotCov.ResizeTo(3, 3);
276 m_BeamSpotCov = m_beamSpotDB->getCovVertex();
281 double bg = beta / sqrt(1 - beta * beta);
284 double cut = 8.717575e-02 * bg;
285 m_shiftZ = 4.184436e+02 * bg * 0.0001;
289 m_constraintCov.ResizeTo(3, 3);
290 if (m_constraintType ==
"IP") tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(cut);
291 else if (m_constraintType ==
"tube") tie(m_constraintCenter, m_constraintCov) = findConstraintBTube(Breco, 1000 * cut);
292 else if (m_constraintType ==
"boost") tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(cut * 200000.);
293 else if (m_constraintType ==
"breco") tie(m_constraintCenter, m_constraintCov) = findConstraint(Breco, cut * 2000.);
294 else if (m_constraintType ==
"noConstraint") m_constraintCenter = TVector3();
296 B2ERROR(
"TagVertex: Invalid constraintType selected");
300 if (m_constraintCenter ==
vecNaN) {
301 B2ERROR(
"TagVertex: No correct fit constraint");
310 double minPVal = (m_fitAlgo !=
"KFit") ? 0.001 : 0.;
313 if (m_trackFindingType ==
"standard_PXD") {
314 m_tagParticles = getTagTracks_standardAlgorithm(Breco, 1);
315 if (m_tagParticles.size() > 0) {
316 ok = makeGeneralFit();
321 if (ok ==
false || m_fitPval < minPVal || m_trackFindingType ==
"standard") {
322 m_tagParticles = getTagTracks_standardAlgorithm(Breco, m_reqPXDHits);
323 ok = m_tagParticles.size() > 0;
325 ok = makeGeneralFit();
330 if ((ok ==
false || (m_fitPval <= 0. && m_fitAlgo ==
"Rave")) && m_constraintType !=
"noConstraint") {
331 tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(cut * 200000.);
332 ok = (m_constraintCenter !=
vecNaN);
334 m_tagParticles = getTagTracks_standardAlgorithm(Breco, m_reqPXDHits);
335 ok = (m_tagParticles.size() > 0);
338 ok = makeGeneralFit();
353 TLorentzVector vCMS = PCmsLabTransform::labToCms(vIn);
354 vCMS.SetVect(-vCMS.Vect());
355 return PCmsLabTransform::cmsToLab(vCMS);
359 pair<TVector3, TMatrixDSym> TagVertexModule::findConstraint(
const Particle* Breco,
double cut)
const
363 TMatrixDSym beamSpotCov(3);
364 beamSpotCov = m_beamSpotDB->getCovVertex();
366 analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, beamSpotCov);
369 double xmag = (Breco->
getVertex() - m_BeamSpotCenter).Mag();
373 TMatrixDSym PerrMatrix(7);
375 for (
int i = 0; i < 3; ++i) {
376 for (
int j = 0; j < 3; ++j) {
378 PerrMatrix(i, j) = (beamSpotCov(i, j) + TerrMatrix(i, j)) * pmag / xmag;
380 PerrMatrix(i, j) = TerrMatrix(i, j);
382 PerrMatrix(i + 4, j + 4) = TerrMatrix(i + 4, j + 4);
386 PerrMatrix(3, 3) = 0.;
389 Particle* Breco2 = ParticleCopy::copyParticle(Breco);
393 const Particle* BRecoRes = doVertexFitForBTube(Breco2,
"kalman");
403 TLorentzVector pBrecEstimate(pmag / BvertDiff.Mag() * BvertDiff, Breco->
getPDGMass());
404 TLorentzVector pBtagEstimate =
flipVector(pBrecEstimate);
407 TMatrixD TubeZ = rotateTensorInv(pBrecEstimate.Vect(), errFinal);
409 TubeZ(2, 2) = cut * cut;
410 TubeZ(2, 0) = 0; TubeZ(0, 2) = 0;
411 TubeZ(2, 1) = 0; TubeZ(1, 2) = 0;
415 TMatrixD Tube = rotateTensor(pBtagEstimate.Vect(), TubeZ);
418 return make_pair(m_BeamSpotCenter, toSymMatrix(Tube));
421 pair<TVector3, TMatrixDSym> TagVertexModule::findConstraintBTube(
const Particle* Breco,
double cut)
425 B2WARNING(
"In TagVertexModule::findConstraintBTube: cannot get a proper vertex for BReco. BTube constraint replaced by Boost.");
426 return findConstraintBoost(cut);
432 const Particle* tubecreatorBCopy = doVertexFitForBTube(Breco,
"avf");
437 TLorentzVector pBrec = tubecreatorBCopy->
get4Vector();
440 if (m_useTruthInFit) {
445 m_fitTruthStatus = 2;
455 B2DEBUG(10,
"Brec decay vertex before fit: " << printVector(Breco->
getVertex()));
456 B2DEBUG(10,
"Brec decay vertex after fit: " << printVector(tubecreatorBCopy->
getVertex()));
457 B2DEBUG(10,
"Brec direction before fit: " << printVector((1. / Breco->
getP()) * Breco->
getMomentum()));
458 B2DEBUG(10,
"Brec direction after fit: " << printVector((1. / tubecreatorBCopy->
getP()) * tubecreatorBCopy->
getMomentum()));
459 B2DEBUG(10,
"IP position: " << printVector(m_BeamSpotCenter));
460 B2DEBUG(10,
"IP covariance: " << printMatrix(m_BeamSpotCov));
461 B2DEBUG(10,
"Brec primary vertex: " << printVector(tubecreatorBCopy->
getVertex()));
462 B2DEBUG(10,
"Brec PV covariance: " << printMatrix(pv));
463 B2DEBUG(10,
"BTag direction: " << printVector((1. / pBtag.P())*pBtag.Vect()));
467 TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
471 TMatrixD longerrorRotated = rotateTensor(pBtag.Vect(), longerror);
474 TMatrixD pvNew = TMatrixD(pv) + longerrorRotated;
477 TVector3 constraintCenter = tubecreatorBCopy->
getVertex();
480 if (m_useTruthInFit) {
488 B2DEBUG(10,
"IPTube covariance: " << printMatrix(pvNew));
494 m_tagMomentum = pBtag;
496 m_pvCov.ResizeTo(pv);
499 return make_pair(constraintCenter, toSymMatrix(pvNew));
502 pair<TVector3, TMatrixDSym> TagVertexModule::findConstraintBoost(
double cut,
double shiftAlongBoost)
const
505 TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
507 TMatrixD longerrorRotated = rotateTensor(boostDir, longerror);
510 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
511 TMatrixD Tube = TMatrixD(beamSpotCov) + longerrorRotated;
514 TVector3 constraintCenter = m_BeamSpotCenter;
517 if (shiftAlongBoost > -1000) {
518 constraintCenter += shiftAlongBoost * boostDir;
521 return make_pair(constraintCenter, toSymMatrix(Tube));
527 double beta = mc->getMomentum().Mag() / mc->getEnergy();
528 return 1e3 * mc->getLifetime() * sqrt(1 - pow(beta, 2));
531 void TagVertexModule::BtagMCVertex(
const Particle* Breco)
534 vector<const MCParticle*> mcBs;
536 if (abs(mc.getPDG()) == abs(Breco->
getPDGCode()))
540 if (mcBs.size() < 2)
return;
542 if (mcBs.size() > 2) {
543 B2WARNING(
"TagVertexModule:: Too many Bs found in MC");
548 : compBrecoBgen(Breco, mc);
552 if (!isReco(mcBs[0]) && !isReco(mcBs[1])) {
557 if (!isReco(mcBs[0]) && isReco(mcBs[1]))
558 swap(mcBs[0], mcBs[1]);
561 if (isReco(mcBs[0]) && isReco(mcBs[1])) {
562 double dist0 = (mcBs[0]->getDecayVertex() - Breco->
getVertex()).Mag2();
563 double dist1 = (mcBs[1]->getDecayVertex() - Breco->
getVertex()).Mag2();
565 swap(mcBs[0], mcBs[1]);
568 m_mcVertReco = mcBs[0]->getDecayVertex();
570 m_mcTagV = mcBs[1]->getDecayVertex();
572 m_mcPDG = mcBs[1]->getPDG();
579 bool isDecMode =
true;
581 const std::vector<Belle2::Particle*> recDau = Breco->
getDaughters();
582 const std::vector<Belle2::MCParticle*> genDau = Bgen->
getDaughters();
584 if (recDau.size() > 0 && genDau.size() > 0) {
585 for (
auto dauRec : recDau) {
587 for (
auto dauGen : genDau) {
588 if (dauGen->getPDG() == dauRec->getPDGCode())
589 isDau = compBrecoBgen(dauRec, dauGen) ;
591 if (!isDau) isDecMode =
false;
594 if (recDau.size() == 0) {
596 }
else {isDecMode =
false;}
606 std::vector<const Particle*> TagVertexModule::getTagTracks_standardAlgorithm(
const Particle* Breco,
int reqPXDHits)
const
608 std::vector<const Particle*> fitParticles;
610 if (!roe)
return fitParticles;
612 std::vector<const Particle*> ROEParticles = roe->
getChargedParticles(m_roeMaskName, 0 ,
false);
613 if (ROEParticles.size() == 0)
return fitParticles;
615 for (
auto& ROEParticle : ROEParticles) {
616 HitPatternVXD roeTrackPattern = ROEParticle->getTrackFitResult()->getHitPatternVXD();
619 fitParticles.push_back(ROEParticle);
625 vector<ParticleAndWeight> TagVertexModule::getParticlesWithoutKS(
const vector<const Particle*>& tagParticles,
626 double massWindowWidth)
const
628 vector<ParticleAndWeight> particleAndWeights;
632 particleAndWeight.
weight = -1111.;
635 for (
unsigned i = 0; i < tagParticles.size(); ++i) {
636 const Particle* particle1 = tagParticles.at(i);
637 if (!particle1)
continue;
638 TLorentzVector mom1 = particle1->
get4Vector();
639 if (!isfinite(mom1.Mag2()))
continue;
642 bool isKsDau =
false;
643 for (
unsigned j = 0; j < tagParticles.size(); ++j) {
644 if (i == j)
continue;
645 const Particle* particle2 = tagParticles.at(j);
646 if (!particle2)
continue;
647 TLorentzVector mom2 = particle2->
get4Vector();
648 if (!isfinite(mom2.Mag2()))
continue;
649 double mass = (mom1 + mom2).M();
650 if (abs(mass - Const::K0Mass) < massWindowWidth) {
656 if (isKsDau)
continue;
658 particleAndWeight.
particle = particle1;
660 if (m_useMCassociation ==
"breco" || m_useMCassociation ==
"internal")
663 particleAndWeights.push_back(particleAndWeight);
667 return particleAndWeights;
670 bool TagVertexModule::makeGeneralFit()
672 if (m_fitAlgo ==
"Rave")
return makeGeneralFitRave();
673 else if (m_fitAlgo ==
"KFit")
return makeGeneralFitKFit();
677 void TagVertexModule::fillParticles(vector<ParticleAndWeight>& particleAndWeights)
679 unsigned n = particleAndWeights.size();
680 sort(particleAndWeights.begin(), particleAndWeights.end(),
683 m_raveParticles.resize(n);
684 m_raveWeights.resize(n);
685 m_raveMCParticles.resize(n);
687 for (
unsigned i = 0; i < n; ++i) {
688 m_raveParticles.at(i) = particleAndWeights.at(i).particle;
689 m_raveMCParticles.at(i) = particleAndWeights.at(i).mcParticle;
690 m_raveWeights.at(i) = particleAndWeights.at(i).weight;
694 void TagVertexModule::fillTagVinfo(
const TVector3& tagVpos,
const TMatrixDSym& tagVposErr)
698 if (m_constraintType !=
"noConstraint") {
699 TMatrixDSym tubeInv = m_constraintCov;
701 TVectorD dV = toVec(m_tagV - m_BeamSpotCenter);
702 m_tagVChi2IP = tubeInv.Similarity(dV);
705 m_tagVErrMatrix.ResizeTo(tagVposErr);
706 m_tagVErrMatrix = tagVposErr;
709 bool TagVertexModule::makeGeneralFitRave()
712 analysis::RaveSetup::getInstance()->unsetBeamSpot();
713 if (m_constraintType !=
"noConstraint")
714 analysis::RaveSetup::getInstance()->setBeamSpot(m_constraintCenter, m_constraintCov);
718 vector<ParticleAndWeight> particleAndWeights = getParticlesWithoutKS(m_tagParticles);
720 for (
const auto& pw : particleAndWeights) {
722 if (m_useTruthInFit) {
727 m_fitTruthStatus = 2;
728 }
else if (m_useRollBack) {
733 m_rollbackStatus = 2;
735 rFit.
addTrack(pw.particle->getTrackFitResult());
737 }
catch (
const rave::CheckedFloatException&) {
738 B2ERROR(
"Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
747 isGoodFit = rFit.
fit(
"avf");
749 if (isGoodFit < 1)
return false;
750 }
catch (
const rave::CheckedFloatException&) {
751 B2ERROR(
"Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
757 for (
unsigned int i(0); i < particleAndWeights.size() && isGoodFit >= 1; ++i)
758 particleAndWeights.at(i).weight = rFit.
getWeight(i);
762 fillParticles(particleAndWeights);
768 m_tagVNDF = rFit.
getNdf(0);
775 bool TagVertexModule::makeGeneralFitKFit()
779 kFit.setMagneticField(m_Bfield);
782 if (m_constraintType !=
"noConstraint") {
783 if (m_constraintType ==
"tube") {
784 CLHEP::HepSymMatrix err(7, 0);
786 err.sub(5, ROOTToCLHEP::getHepSymMatrix(m_pvCov));
787 kFit.setIpTubeProfile(
788 ROOTToCLHEP::getHepLorentzVector(m_tagMomentum),
789 ROOTToCLHEP::getPoint3D(m_constraintCenter),
793 kFit.setIpProfile(ROOTToCLHEP::getPoint3D(m_constraintCenter),
794 ROOTToCLHEP::getHepSymMatrix(m_constraintCov));
799 vector<ParticleAndWeight> particleAndWeights = getParticlesWithoutKS(m_tagParticles);
801 int nTracksAdded = 0;
802 for (
auto& pawi : particleAndWeights) {
804 if (m_useTruthInFit) {
805 if (pawi.mcParticle) {
806 addedOK = kFit.addTrack(
807 ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
808 ROOTToCLHEP::getPoint3D(getTruePoca(pawi)),
809 ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
810 pawi.particle->getCharge());
812 m_fitTruthStatus = 2;
814 }
else if (m_useRollBack) {
815 if (pawi.mcParticle) {
816 addedOK = kFit.addTrack(
817 ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
818 ROOTToCLHEP::getPoint3D(getRollBackPoca(pawi)),
819 ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
820 pawi.particle->getCharge());
822 m_rollbackStatus = 2;
825 addedOK = kFit.addParticle(pawi.particle);
832 B2WARNING(
"TagVertexModule::makeGeneralFitKFit: failed to add a track");
838 if ((nTracksAdded < 2 && m_constraintType ==
"noConstraint") || nTracksAdded < 1)
841 int isGoodFit = kFit.doFit();
842 if (isGoodFit != 0)
return false;
846 fillParticles(particleAndWeights);
849 fillTagVinfo(CLHEPToROOT::getTVector3(kFit.getVertex()),
850 CLHEPToROOT::getTMatrixDSym(kFit.getVertexError()));
852 m_tagVNDF = kFit.getNDF();
853 m_tagVChi2 = kFit.getCHIsq();
854 m_fitPval = TMath::Prob(m_tagVChi2, m_tagVNDF);
859 void TagVertexModule::deltaT(
const Particle* Breco)
863 TVector3 boostDir = boost.Unit();
864 double bg = boost.Mag() / sqrt(1 - boost.Mag2());
865 double c = Const::speedOfLight / 1000.;
868 TVector3 dVert = Breco->
getVertex() - m_tagV;
869 double dl = dVert.Dot(boostDir);
870 m_deltaT = dl / (bg * c);
873 TVector3 MCdVert = m_mcVertReco - m_mcTagV;
874 double MCdl = MCdVert.Dot(boostDir);
875 m_mcDeltaT = MCdl / (bg * c);
878 m_mcDeltaTau = m_mcLifeTimeReco - m_mcTagLifeTime;
879 if (m_mcLifeTimeReco == -1 || m_mcTagLifeTime == -1)
882 TVectorD bVec = toVec(boostDir);
885 m_tagVlErr = sqrt(m_tagVErrMatrix.Similarity(bVec));
891 m_deltaTErr = hypot(m_tagVlErr, bRecoErrL) / (bg * c);
893 m_tagVl = m_tagV.Dot(boostDir);
894 m_truthTagVl = m_mcTagV.Dot(boostDir);
897 TVector3 oboost = getUnitOrthogonal(boostDir);
898 TVectorD oVec = toVec(oboost);
901 m_tagVolErr = sqrt(m_tagVErrMatrix.Similarity(oVec));
903 m_tagVol = m_tagV.Dot(oboost);
904 m_truthTagVol = m_mcTagV.Dot(oboost);
907 Particle* TagVertexModule::doVertexFitForBTube(
const Particle* motherIn, std::string fitType)
const
910 Particle* mother = ParticleCopy::copyParticle(motherIn);
914 analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, m_BeamSpotCov);
918 int nvert = rsg.
fit(fitType);
920 mother->setPValue(-1);
933 B2ERROR(
"In TagVertexModule::getTrackWithTrueCoordinate: no MC particle set");
945 m_Bfield, 0, 0, tfr->
getNDF());
952 B2ERROR(
"In TagVertexModule::getTruePoca: no MC particle set");
953 return TVector3(0., 0., 0.);
971 m_Bfield, 0, 0, tfr->
getNDF());
977 B2ERROR(
"In TagVertexModule::getTruePoca: no MC particle set");
978 return TVector3(0., 0., 0.);
984 void TagVertexModule::resetReturnParams()
986 m_raveParticles.resize(0);
987 m_raveMCParticles.resize(0);
988 m_tagParticles.resize(0);
989 m_raveWeights.resize(0);
993 m_tagVErrMatrix.ResizeTo(
matNaN);
1000 m_constraintCov.ResizeTo(
matNaN);
1001 m_constraintCov =
matNaN;
1002 m_constraintCenter =
vecNaN;
1012 m_pvCov.ResizeTo(
matNaN);
1020 std::string TagVertexModule::printVector(
const TVector3& vec)
1022 std::ostringstream oss;
1024 oss <<
"(" << std::setw(w) << vec[0] <<
", " << std::setw(w) << vec[1] <<
", " << std::setw(w) << vec[2] <<
")" << std::endl;
1029 std::string TagVertexModule::printMatrix(
const TMatrixD& mat)
1031 std::ostringstream oss;
1033 for (
int i = 0; i < mat.GetNrows(); ++i) {
1034 for (
int j = 0; j < mat.GetNcols(); ++j) {
1035 oss << std::setw(w) << mat(i, j) <<
" ";
1043 std::string TagVertexModule::printMatrix(
const TMatrixDSym& mat)
1045 std::ostringstream oss;
1047 for (
int i = 0; i < mat.GetNrows(); ++i) {
1048 for (
int j = 0; j < mat.GetNcols(); ++j) {
1049 oss << std::setw(w) << mat(i, j) <<
" ";
Hit pattern of the VXD within a track.
unsigned short getNPXDHits() const
Get total number of hits in the PXD.
A Class to store the Monte Carlo particle information.
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
TVector3 getMomentum() const
Return momentum.
int getPDG() const
Return PDG code of particle.
TLorentzVector get4Vector() const
Return 4Vector of particle.
TVector3 getProductionVertex() const
Return production vertex position.
Class to store reconstructed particles.
TMatrixFSym getVertexErrorMatrix() const
Returns the 3x3 position error sub-matrix.
float getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
TVector3 getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
float getPValue() const
Returns chi^2 probability of fit if done or -1.
TVector3 getMomentum() const
Returns momentum vector.
int getPDGCode(void) const
Returns PDG code.
float getP() const
Returns momentum magnitude (same as getMomentumMagnitude but with shorter name)
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
TLorentzVector get4Vector() const
Returns Lorentz vector.
void setMomentumVertexErrorMatrix(const TMatrixFSym &errMatrix)
Sets 7x7 error matrix.
float getMomentumMagnitude() const
Returns momentum magnitude.
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
const TrackFitResult * getTrackFitResult() const
Returns the pointer to the TrackFitResult that was used to create this Particle (ParticleType == c_Tr...
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
std::vector< const Particle * > getChargedParticles(const std::string &maskName="", unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
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.
Tag side Vertex Fitter module for modular analysis.
TagVertex data object: contains Btag Vertex and DeltaT.
void setConstraintType(const std::string &constraintType)
Set the type of the constraint for the tag fit.
void setTagVlErr(float TagVlErr)
Set the error of the tagV component in the boost direction.
void setTagVertex(const TVector3 &TagVertex)
Set BTag Vertex.
void setTruthTagVl(float TruthTagVl)
Set the MC tagV component in the boost direction.
void setTruthTagVol(float TruthTagVol)
Set the tagV component in the direction orthogonal to the boost.
void setMCTagBFlavor(int mcTagBFlavor)
Set generated Btag PDG code.
void setTagVolErr(float TagVolErr)
Set the error of the tagV component in the direction orthogonal to the boost.
void setTagVNDF(float TagVNDF)
Set the number of degrees of freedom in the tag vertex fit.
void setDeltaTErr(float DeltaTErr)
Set DeltaTErr.
void setNTracks(int nTracks)
Set number of tracks used in the fit.
void setTagVChi2(float TagVChi2)
Set the chi^2 value of the tag vertex fit result.
void setMCDeltaT(float mcDeltaT)
Set generated DeltaT (in kin.
void setRollBackStatus(int backStatus)
Set the status of the fit performed with the rolled back tracks.
void setVertexFitMCParticles(const std::vector< const MCParticle * > &vtxFitMCParticles)
Set a vector of pointers to the MC p'cles corresponding to the tracks in the tag vtx fit.
void setMCTagVertex(const TVector3 &mcTagVertex)
Set generated BTag Vertex.
void setTagVol(float TagVol)
Set the tagV component in the direction orthogonal to the boost.
void setDeltaT(float DeltaT)
Set DeltaT.
void setRaveWeights(const std::vector< double > &raveWeights)
Set the weights used by Rave in the tag vtx fit.
void setTagVertexPval(float TagVertexPval)
Set BTag Vertex P value.
void setMCDeltaTau(float mcDeltaTau)
Set generated DeltaT.
void setTagVl(float TagVl)
Set the tagV component in the boost direction.
void setTagVertexErrMatrix(const TMatrixDSym &TagVertexErrMatrix)
Set BTag Vertex (3x3) error matrix.
void setConstraintCenter(const TVector3 &constraintCenter)
Set the centre of the constraint for the tag fit.
void setConstraintCov(const TMatrixDSym &constraintCov)
Set the covariance matrix of the constraint for the tag fit.
void setFitType(float FitType)
Set fit algo type.
void setVertexFitParticles(const std::vector< const Particle * > &vtxFitParticles)
Set a vector of pointers to the tracks used in the tag vtx fit.
void setTagVChi2IP(float TagVChi2IP)
Set the IP component of the chi^2 value of the tag vertex fit result.
void setFitTruthStatus(int truthStatus)
Set the status of the fit performed with the truth info of the tracks.
Values of the result of a track fit with a given particle hypothesis.
short getChargeSign() const
Return track charge (1 or -1).
double getPValue() const
Getter for Chi2 Probability of the track fit.
TMatrixDSym getCovariance6() const
Position and Momentum Covariance Matrix.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
int getNDF() const
Getter for number of degrees of freedom of the track fit.
TVector3 getPosition() const
Getter for vector of position at closest approach of track in r/phi projection.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
The RaveVertexFitter class is part of the RaveInterface together with RaveSetup.
TMatrixDSym getCov(VecSize vertexId=0) const
get the covariance matrix (3x3) of the of the fitted vertex position.
int fit(std::string options="default")
do the vertex fit with all tracks previously added with the addTrack or addMother function.
void addTrack(const Particle *const aParticlePtr)
add a track (in the format of a Belle2::Particle) to set of tracks that should be fitted to a vertex
double getNdf(VecSize vertexId=0) const
get the number of degrees of freedom (NDF) of the fitted vertex.
double getChi2(VecSize vertexId=0) const
get the χ² of the fitted vertex.
TVector3 getPos(VecSize vertexId=0) const
get the position of the fitted vertex.
void updateDaughters()
update the Daughters particles
double getWeight(int trackId, VecSize vertexId=0) const
get the weight Rave assigned to a specific input track.
double getPValue(VecSize vertexId=0) const
get the p value of the fitted vertex.
VertexFitKFit is a derived class from KFitBase to perform vertex-constraint kinematical fit.
static const double realNaN
shortcut for NaN of double type
static TLorentzVector flipVector(TLorentzVector vIn)
Get vector which is opposite to vIn in CMS ref frame Be aware that input vIn and output are in the La...
static const TVector3 vecNaN(realNaN, realNaN, realNaN)
vector with NaN entries
static const TMatrixDSym matNaN(3,(double[]) { realNaN, realNaN, realNaN, realNaN, realNaN, realNaN, realNaN, realNaN, realNaN })
3x3 matrix with NaN entries
static double getProperLifeTime(const MCParticle *mc)
proper life time, i.e.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
this struct is used to store and sort the tag tracks
const Particle * particle
tag track fit result with pion mass hypo, for sorting purposes
const MCParticle * mcParticle
mc particle matched to the tag track, for sorting purposes
double weight
rave weight associated to the track, for sorting purposes