12 #include <analysis/modules/ParticleVertexFitter/ParticleVertexFitterModule.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
19 #include <framework/gearbox/Unit.h>
20 #include <framework/gearbox/Const.h>
21 #include <framework/logging/Logger.h>
24 #include <analysis/dataobjects/Particle.h>
25 #include <analysis/dataobjects/ParticleList.h>
26 #include <analysis/dataobjects/Btube.h>
28 #include <analysis/utility/CLHEPToROOT.h>
29 #include <analysis/utility/PCmsLabTransform.h>
30 #include <analysis/utility/ParticleCopy.h>
31 #include <analysis/utility/ROOTToCLHEP.h>
34 #include <framework/geometry/BFieldManager.h>
61 setDescription(
"Vertex fitter for modular analysis");
62 setPropertyFlags(c_ParallelProcessingCertified);
65 addParam(
"listName", m_listName,
"name of particle list",
string(
""));
66 addParam(
"confidenceLevel", m_confidenceLevel,
67 "Confidence level to accept the fit. Particle candidates with "
68 "p-value less than confidenceLevel are removed from the particle "
69 "list. If set to -1, all candidates are kept; if set to 0, "
70 "the candidates failing the fit are removed.",
72 addParam(
"vertexFitter", m_vertexFitter,
"KFit or Rave",
string(
"KFit"));
73 addParam(
"fitType", m_fitType,
"type of the kinematic fit (vertex, massvertex, mass)",
string(
"vertex"));
74 addParam(
"withConstraint", m_withConstraint,
75 "additional constraint on vertex: ipprofile, iptube, mother, iptubecut, pointing, btube",
77 addParam(
"decayString", m_decayString,
"specifies which daughter particles are included in the kinematic fit",
string(
""));
78 addParam(
"updateDaughters", m_updateDaughters,
"true: update the daughters after the vertex fit",
false);
79 addParam(
"smearing", m_smearing,
"smear IP tube width by given length", 0.002);
82 void ParticleVertexFitterModule::initialize()
85 m_Bfield = BFieldManager::getField(TVector3(0, 0, 0)).Z() / Unit::T;
88 if (m_vertexFitter ==
"Rave")
89 analysis::RaveSetup::initialize(1, m_Bfield);
91 B2DEBUG(1,
"ParticleVertexFitterModule : magnetic field = " << m_Bfield);
94 if (m_decayString !=
"")
95 m_decaydescriptor.init(m_decayString);
97 B2INFO(
"ParticleVertexFitter: Performing " << m_fitType <<
" fit on " << m_listName <<
" using " << m_vertexFitter);
98 if (m_decayString !=
"")
99 B2INFO(
"ParticleVertexFitter: Using specified decay string: " << m_decayString);
100 if (m_withConstraint !=
"")
101 B2INFO(
"ParticleVertexFitter: Additional " << m_withConstraint <<
" will be applied");
105 void ParticleVertexFitterModule::beginRun()
112 void ParticleVertexFitterModule::event()
117 B2ERROR(
"ParticleList " << m_listName <<
" not found");
121 if (m_vertexFitter ==
"Rave")
122 analysis::RaveSetup::initialize(1, m_Bfield);
124 m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
125 m_beamSpotCov.ResizeTo(3, 3);
126 TMatrixDSym beamSpotCov(3);
127 if (m_withConstraint ==
"ipprofile") m_beamSpotCov = m_beamSpotDB->getCovVertex();
128 if (m_withConstraint ==
"iptube") {
129 if (m_smearing > 0 && m_vertexFitter ==
"KFit") {
130 ParticleVertexFitterModule::smearBeamSpot(m_smearing);
132 ParticleVertexFitterModule::findConstraintBoost(2.);
135 if (m_withConstraint ==
"iptubecut") {
136 m_BeamSpotCenter = TVector3(0.001, 0., .013);
137 findConstraintBoost(0.03);
139 if ((m_vertexFitter ==
"Rave") && (m_withConstraint ==
"ipprofile" || m_withConstraint ==
"iptube"
140 || m_withConstraint ==
"mother" || m_withConstraint ==
"iptubecut" || m_withConstraint ==
"btube"))
141 analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, m_beamSpotCov);
142 std::vector<unsigned int> toRemove;
143 unsigned int n = plist->getListSize();
144 for (
unsigned i = 0; i < n; i++) {
145 Particle* particle = plist->getParticle(i);
146 m_hasCovMatrix =
false;
147 if (m_updateDaughters ==
true) {
148 if (m_decayString.empty()) ParticleCopy::copyDaughters(particle);
149 else B2ERROR(
"Daughters update works only when all daughters are selected. Daughters will not be updated");
152 if (m_withConstraint ==
"mother") {
153 m_BeamSpotCenter = particle->getVertex();
154 m_beamSpotCov = particle->getVertexErrorMatrix();
157 TMatrixFSym mother_errMatrix(7);
158 mother_errMatrix = particle->getMomentumVertexErrorMatrix();
159 for (
int k = 0; k < 7; k++) {
160 for (
int j = 0; j < 7; j++) {
161 if (mother_errMatrix[k][j] > 0) {
162 m_hasCovMatrix =
true;
167 if (m_withConstraint ==
"btube") {
171 toRemove.push_back(particle->getArrayIndex());
179 ok = doVertexFit(particle);
182 particle->setPValue(-1);
183 if (particle->getPValue() < m_confidenceLevel)
184 toRemove.push_back(particle->getArrayIndex());
186 plist->removeParticles(toRemove);
189 if (m_vertexFitter ==
"Rave")
190 analysis::RaveSetup::getInstance()->reset();
193 bool ParticleVertexFitterModule::doVertexFit(
Particle* mother)
198 B2FATAL(
"ParticleVertexFitter: No magnetic field");
201 if (m_withConstraint !=
"ipprofile" &&
202 m_withConstraint !=
"iptube" &&
203 m_withConstraint !=
"mother" &&
204 m_withConstraint !=
"iptubecut" &&
205 m_withConstraint !=
"pointing" &&
206 m_withConstraint !=
"btube" &&
207 m_withConstraint !=
"")
208 B2FATAL(
"ParticleVertexFitter: " << m_withConstraint <<
" ***invalid Constraint ");
212 if (m_vertexFitter ==
"KFit") {
215 if (m_fitType ==
"vertex") {
216 if (m_withConstraint ==
"ipprofile") {
217 ok = doKVertexFit(mother,
true,
false);
218 }
else if (m_withConstraint ==
"iptube") {
219 ok = doKVertexFit(mother,
false,
true);
221 ok = doKVertexFit(mother,
false,
false);
226 if (m_fitType ==
"massvertex") {
227 if (m_withConstraint ==
"ipprofile" || m_withConstraint ==
"iptube" || m_withConstraint ==
"iptubecut") {
228 B2FATAL(
"ParticleVertexFitter: Invalid options - mass-constrained fit using KFit does not work with iptube or ipprofile constraint.");
229 }
else if (m_withConstraint ==
"pointing") {
230 ok = doKMassPointingVertexFit(mother);
232 ok = doKMassVertexFit(mother);
237 if (m_fitType ==
"mass") {
238 if (m_withConstraint ==
"ipprofile" || m_withConstraint ==
"iptube" || m_withConstraint ==
"iptubecut") {
239 B2FATAL(
"ParticleVertexFitter: Invalid options - mass fit using KFit does not work with iptube or ipprofile constraint.");
241 ok = doKMassFit(mother);
246 if (m_fitType ==
"fourC") {
247 if (m_withConstraint ==
"ipprofile" || m_withConstraint ==
"iptube" || m_withConstraint ==
"iptubecut") {
248 B2FATAL(
"ParticleVertexFitter: Invalid options - four C fit using KFit does not work with iptube or ipprofile constraint.");
250 ok = doKFourCFit(mother);
255 if (m_fitType !=
"vertex"
256 && m_fitType !=
"massvertex"
257 && m_fitType !=
"mass"
258 && m_fitType !=
"fourC")
259 B2FATAL(
"ParticleVertexFitter: " << m_fitType <<
" ***invalid fit type for the vertex fitter ");
263 if (m_vertexFitter ==
"Rave") {
265 ok = doRaveFit(mother);
266 }
catch (
const rave::CheckedFloatException&) {
267 B2ERROR(
"Invalid inputs (nan/inf)?");
273 if (m_vertexFitter !=
"KFit" && m_vertexFitter !=
"Rave")
274 B2FATAL(
"ParticleVertexFitter: " << m_vertexFitter <<
" ***invalid vertex fitter ");
276 if (!ok)
return false;
285 bool ParticleVertexFitterModule::fillFitParticles(
const Particle* mother, std::vector<const Particle*>& fitChildren,
286 std::vector<const Particle*>& pi0Children)
288 if (m_decayString.empty()) {
290 for (
unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
291 const Particle* child = mother->getDaughter(ichild);
294 if (mother->getProperty() == Particle::PropertyFlags::c_IsUnspecified and child->getPValue() < 0) {
297 fitChildren.push_back(child);
300 fitChildren = m_decaydescriptor.getSelectionParticles(mother);
303 auto itr = fitChildren.begin();
304 while (itr != fitChildren.end()) {
307 if (child->getPValue() < 0) {
308 B2WARNING(
"Daughter with PDG code " << child->getPDGCode() <<
" does not have a valid error matrix.");
312 if (m_hasCovMatrix ==
false) {
313 if (child->getPDGCode() == Const::pi0.getPDGCode() && child->getNDaughters() == 2) {
314 if (child->getDaughter(0)->getPDGCode() == Const::photon.getPDGCode()
315 && child->getDaughter(1)->getPDGCode() == Const::photon.getPDGCode()) {
322 pi0Children.push_back(child);
323 itr = fitChildren.erase(itr);
348 TMatrixFSym errMatrix(3);
349 for (
int i = 0; i < 3; i++)
350 for (
int j = 0; j < 3; j++)
351 errMatrix(i, j) = posErrorMatrix[i][j];
353 g1ErrMatrix.SetSub(4, errMatrix);
354 g2ErrMatrix.SetSub(4, errMatrix);
370 int err = km.
doFit();
376 bool updateDaughters = m_updateDaughters;
377 m_updateDaughters =
false;
378 bool ok = makeKMassMother(km, pi0Temp);
379 m_updateDaughters = updateDaughters;
384 bool ParticleVertexFitterModule::doKVertexFit(
Particle* mother,
bool ipProfileConstraint,
bool ipTubeConstraint)
386 if ((mother->getNDaughters() < 2 && !ipTubeConstraint) || mother->getNDaughters() < 1)
return false;
388 std::vector<const Particle*> fitChildren;
389 std::vector<const Particle*> pi0Children;
390 bool validChildren = fillFitParticles(mother, fitChildren, pi0Children);
395 if (pi0Children.size() > 1) {
396 B2FATAL(
"[ParticleVertexFitterModule::doKVertexFit] Vertex fit using KFit does not support fit with multiple pi0s (yet).");
399 if ((fitChildren.size() < 2 && !ipTubeConstraint) || fitChildren.size() < 1) {
400 B2WARNING(
"[ParticleVertexFitterModule::doKVertexFit] Number of particles with valid error matrix entering the vertex fit using KFit is too low.");
408 for (
auto& child : fitChildren)
411 if (ipProfileConstraint)
412 addIPProfileToKFit(kv);
414 if (ipTubeConstraint)
418 int err = kv.
doFit();
423 if (pi0Children.size() == 0)
425 ok = makeKVertexMother(kv, mother);
426 else if (pi0Children.size() == 1) {
431 const Particle* pi0 = pi0Children[0];
433 ok = redoPi0MassFit(&pi0Temp, pi0, kv) ;
441 for (
auto& child : fitChildren)
446 if (ipProfileConstraint)
447 addIPProfileToKFit(kv2);
454 ok = makeKVertexMother(kv2, mother);
460 bool ParticleVertexFitterModule::doKMassVertexFit(
Particle* mother)
462 if (mother->getNDaughters() < 2)
return false;
464 std::vector<const Particle*> fitChildren;
465 std::vector<const Particle*> pi0Children;
466 bool validChildren = fillFitParticles(mother, fitChildren, pi0Children);
471 if (pi0Children.size() > 1) {
472 B2FATAL(
"[ParticleVertexFitterModule::doKVertexFit] MassVertex fit using KFit does not support fit with multiple pi0s (yet).");
475 if (fitChildren.size() < 2) {
476 B2WARNING(
"[ParticleVertexFitterModule::doKVertexFit] Number of particles with valid error matrix entering the vertex fit using KFit is less than 2.");
481 if (pi0Children.size() == 0) {
486 for (
auto child : fitChildren)
490 int err = kmv.
doFit();
495 ok = makeKMassVertexMother(kmv, mother);
496 }
else if (pi0Children.size() == 1) {
504 for (
auto child : fitChildren)
508 int err = kv.
doFit();
512 const Particle* pi0 = pi0Children[0];
514 ok = redoPi0MassFit(&pi0Temp, pi0, kv) ;
522 for (
auto child : fitChildren)
532 ok = makeKMassVertexMother(kmv2, mother);
539 bool ParticleVertexFitterModule::doKMassPointingVertexFit(
Particle* mother)
541 if (!(mother->hasExtraInfo(
"prodVertX") && mother->hasExtraInfo(
"prodVertY") && mother->hasExtraInfo(
"prodVertZ"))) {
545 if (mother->getNDaughters() < 2)
return false;
547 std::vector<const Particle*> fitChildren;
548 std::vector<const Particle*> pi0Children;
549 bool validChildren = fillFitParticles(mother, fitChildren, pi0Children);
554 if (pi0Children.size() > 0) {
555 B2FATAL(
"[ParticleVertexFitterModule::doKMassPointingVertexFit] MassPointingVertex fit using KFit does not support fit with pi0s (yet).");
558 if (fitChildren.size() < 2) {
559 B2WARNING(
"[ParticleVertexFitterModule::doKMassPointingVertexFit] Number of particles with valid error matrix entering the vertex fit using KFit is less than 2.");
568 for (
auto child : fitChildren)
572 HepPoint3D productionVertex(mother->getExtraInfo(
"prodVertX"),
573 mother->getExtraInfo(
"prodVertY"),
574 mother->getExtraInfo(
"prodVertZ"));
576 int err = kmpv.
doFit();
577 if (err != 0)
return false;
579 ok = makeKMassPointingVertexMother(kmpv, mother);
584 bool ParticleVertexFitterModule::doKMassFit(
Particle* mother)
586 if (mother->getNDaughters() < 2)
return false;
591 for (
unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
592 const Particle* child = mother->getDaughter(ichild);
594 if (child->getPValue() < 0)
return false;
602 int err = km.
doFit();
604 if (err != 0)
return false;
606 bool ok = makeKMassMother(km, mother);
611 bool ParticleVertexFitterModule::doKFourCFit(
Particle* mother)
613 if (mother->getNDaughters() < 2)
return false;
618 for (
unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
619 const Particle* child = mother->getDaughter(ichild);
621 if (child->getNDaughters() > 0) {
622 bool err = addChildofParticletoKFit(kf, child);
623 if (!err)
return false;
625 if (child->getPValue() < 0)
return false;
635 int err = kf.
doFit();
637 if (err != 0)
return false;
639 bool ok = makeKFourCMother(kf, mother);
649 if (fitError != analysis::KFitError::kNoError)
651 if (m_decayString.empty() && m_updateDaughters ==
true) {
655 std::vector<Particle*> daughters = mother->getDaughters();
658 if (daughters.size() != track_count)
661 for (
unsigned iChild = 0; iChild < track_count; iChild++) {
662 daughters[iChild]->set4Vector(
664 daughters[iChild]->setVertex(
666 daughters[iChild]->setMomentumVertexErrorMatrix(
679 if (fitError != analysis::KFitError::kNoError)
681 if (m_decayString.empty() && m_updateDaughters ==
true) {
685 std::vector<Particle*> daughters = mother->getDaughters();
688 if (daughters.size() != track_count)
691 for (
unsigned iChild = 0; iChild < track_count; iChild++) {
692 daughters[iChild]->set4Vector(
694 daughters[iChild]->setVertex(
696 daughters[iChild]->setMomentumVertexErrorMatrix(
709 if (fitError != analysis::KFitError::kNoError) {
713 if (m_decayString.empty() && m_updateDaughters ==
true) {
717 std::vector<Particle*> daughters = mother->getDaughters();
720 if (daughters.size() != track_count)
723 for (
unsigned iChild = 0; iChild < track_count; iChild++) {
724 daughters[iChild]->set4Vector(
726 daughters[iChild]->setVertex(
728 daughters[iChild]->setMomentumVertexErrorMatrix(
742 if (fitError != analysis::KFitError::kNoError)
744 if (m_decayString.empty() && m_updateDaughters ==
true) {
748 std::vector<Particle*> daughters = mother->getDaughters();
751 if (daughters.size() != track_count)
754 for (
unsigned iChild = 0; iChild < track_count; iChild++) {
755 daughters[iChild]->set4Vector(
757 daughters[iChild]->setVertex(
759 daughters[iChild]->setMomentumVertexErrorMatrix(
773 if (fitError != analysis::KFitError::kNoError)
775 mother->addExtraInfo(
"FourCFitProb", kf.
getCHIsq());
776 mother->addExtraInfo(
"FourCFitChi2", kf.
getNDF());
777 if (m_decayString.empty() && m_updateDaughters ==
true) {
781 std::vector<Particle*> daughters = mother->getDaughters();
783 const unsigned nd = daughters.size();
785 std::vector<std::vector<unsigned>> pars;
786 std::vector<Particle*> allparticles;
787 for (
unsigned ichild = 0; ichild < nd; ichild++) {
788 const Particle* daughter = mother->getDaughter(ichild);
789 std::vector<unsigned> pard;
790 if (daughter->getNDaughters() > 0) {
791 updateMapOfTrackAndDaughter(l, pars, pard, allparticles, daughter);
792 pars.push_back(pard);
793 allparticles.push_back(daughters[ichild]);
796 pars.push_back(pard);
797 allparticles.push_back(daughters[ichild]);
803 if (l != track_count)
806 for (
unsigned iDaug = 0; iDaug < allparticles.size(); iDaug++) {
807 TLorentzVector childMoms;
809 TMatrixFSym childErrMatrixs(7);
810 for (
unsigned int iChild : pars[iDaug]) {
811 childMoms = childMoms +
812 CLHEPToROOT::getTLorentzVector(
814 childPoss = childPoss +
815 CLHEPToROOT::getTVector3(
817 TMatrixFSym childErrMatrix =
819 childErrMatrixs = childErrMatrixs + childErrMatrix;
821 allparticles[iDaug]->set4Vector(childMoms);
822 allparticles[iDaug]->setVertex(childPoss);
823 allparticles[iDaug]->setMomentumVertexErrorMatrix(childErrMatrixs);
830 void ParticleVertexFitterModule::updateMapOfTrackAndDaughter(
unsigned& l, std::vector<std::vector<unsigned>>& pars,
831 std::vector<unsigned>& parm, std::vector<Particle*>& allparticles,
const Particle* daughter)
833 std::vector <Belle2::Particle*> childs = daughter->getDaughters();
834 for (
unsigned ichild = 0; ichild < daughter->getNDaughters(); ichild++) {
835 const Particle* child = daughter->getDaughter(ichild);
836 std::vector<unsigned> pard;
837 if (child->getNDaughters() > 0) {
838 updateMapOfTrackAndDaughter(l, pars, pard, allparticles, child);
839 parm.insert(parm.end(), pard.begin(), pard.end());
840 pars.push_back(pard);
841 allparticles.push_back(childs[ichild]);
845 pars.push_back(pard);
846 allparticles.push_back(childs[ichild]);
853 bool ParticleVertexFitterModule::doRaveFit(
Particle* mother)
855 if ((m_decayString.empty() ||
856 (m_withConstraint ==
"" && m_fitType !=
"mass")) && mother->getNDaughters() < 2)
return false;
857 if (m_withConstraint ==
"") analysis::RaveSetup::getInstance()->unsetBeamSpot();
858 if (m_withConstraint ==
"ipprofile" || m_withConstraint ==
"iptube" || m_withConstraint ==
"mother"
859 || m_withConstraint ==
"iptubecut" || m_withConstraint ==
"btube")
860 analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, m_beamSpotCov);
863 if (m_fitType ==
"mass") rf.
setVertFit(
false);
865 if (m_decayString.empty()) {
868 std::vector<const Particle*> tracksVertex = m_decaydescriptor.getSelectionParticles(mother);
869 std::vector<std::string> tracksName = m_decaydescriptor.getSelectionNames();
871 if (allSelectedDaughters(mother, tracksVertex)) {
872 for (
auto& itrack : tracksVertex) {
873 if (itrack != mother) rf.
addTrack(itrack);
879 bool mothSel =
false;
881 for (
unsigned itrack = 0; itrack < tracksVertex.size(); itrack++) {
882 if (tracksVertex[itrack] != mother) {
884 B2DEBUG(1,
"ParticleVertexFitterModule: Adding particle " << tracksName[itrack] <<
" to vertex fit ");
887 if (tracksVertex[itrack] == mother) mothSel =
true;
892 bool mothIPfit =
false;
893 if (tracksVertex.size() == 1 && mothSel ==
true && m_withConstraint !=
"" && nTrk == 0) {
895 if (tracksVertex[0] != mother)
896 B2FATAL(
"ParticleVertexFitterModule: FATAL Error in IP constrained mother fit");
903 TMatrixDSym RerrMatrix(3);
909 for (
auto& itrack : tracksVertex) {
911 nvert = rsg.
fit(
"kalman");
914 RerrMatrix = rsg.
getCov(0);
916 TLorentzVector mom(mother->getMomentum(), mother->getEnergy());
917 TMatrixDSym errMatrix(7);
918 for (
int i = 0; i < 7; i++) {
919 for (
int j = 0; j < 7; j++) {
920 if (i > 3 && j > 3) {errMatrix[i][j] = RerrMatrix[i - 4][j - 4];}
921 else {errMatrix[i][j] = 0;}
925 mother->writeExtraInfo(
"prodVertX", pos.X());
926 mother->writeExtraInfo(
"prodVertY", pos.Y());
927 mother->writeExtraInfo(
"prodVertZ", pos.Z());
928 mother->writeExtraInfo(
"prodVertSxx", RerrMatrix[0][0]);
929 mother->writeExtraInfo(
"prodVertSxy", RerrMatrix[0][1]);
930 mother->writeExtraInfo(
"prodVertSxz", RerrMatrix[0][2]);
931 mother->writeExtraInfo(
"prodVertSyx", RerrMatrix[1][0]);
932 mother->writeExtraInfo(
"prodVertSyy", RerrMatrix[1][1]);
933 mother->writeExtraInfo(
"prodVertSyz", RerrMatrix[1][2]);
934 mother->writeExtraInfo(
"prodVertSzx", RerrMatrix[2][0]);
935 mother->writeExtraInfo(
"prodVertSzy", RerrMatrix[2][1]);
936 mother->writeExtraInfo(
"prodVertSzz", RerrMatrix[2][2]);
938 mother->updateMomentum(mom, pos, errMatrix, prob);
941 }
else {
return false;}
951 TLorentzVector mom(mother->getMomentum(), mother->getEnergy());
952 TMatrixDSym errMatrix(7);
953 for (
int i = 0; i < 7; i++) {
954 for (
int j = 0; j < 7; j++) {
955 if (i > 3 && j > 3) {errMatrix[i][j] = RerrMatrix[i - 4][j - 4];}
956 else {errMatrix[i][j] = 0;}
959 mother->updateMomentum(mom, pos, errMatrix, prob);
960 }
else {
return false;}
963 if (mothSel && nTrk > 1) {
964 analysis::RaveSetup::getInstance()->setBeamSpot(pos, RerrMatrix);
966 int nKfit = rf.
fit();
968 analysis::RaveSetup::getInstance()->unsetBeamSpot();
970 if (nKfit > 0) {
return true;}
977 if (m_fitType ==
"vertex") {
979 int nVert = rf.
fit();
981 if (m_decayString.empty() && m_updateDaughters ==
true) rf.
updateDaughters();
982 if (nVert != 1)
return false;
984 if (m_fitType ==
"mass") {
989 int nVert = rf.
fit();
991 if (nVert != 1)
return false;
993 if (m_fitType ==
"massvertex") {
996 int nVert = rf.
fit();
998 if (m_decayString.empty() && m_updateDaughters ==
true) rf.
updateDaughters();
999 if (nVert != 1)
return false;
1002 B2FATAL(
"fitType : " << m_fitType <<
" ***invalid fit type ");
1008 bool ParticleVertexFitterModule::allSelectedDaughters(
const Particle* mother,
1009 const std::vector<const Particle*>& tracksVertex)
1012 if (mother->getNDaughters() == 0)
return false;
1014 int nNotIncluded = mother->getNDaughters();
1016 for (
unsigned i = 0; i < mother->getNDaughters(); i++) {
1018 for (
auto& vi : tracksVertex) {
1019 if (vi == mother->getDaughter(i)) {
1020 nNotIncluded = nNotIncluded - 1;
1025 if (allSelectedDaughters(mother->getDaughter(i), tracksVertex)) nNotIncluded--;
1028 if (nNotIncluded == 0) isAll =
true;
1034 for (
unsigned ichild = 0; ichild < particle->getNDaughters(); ichild++) {
1035 const Particle* child = particle->getDaughter(ichild);
1036 if (child->getNDaughters() > 0) addChildofParticletoKFit(kf, child);
1038 if (child->getPValue() < 0)
return false;
1049 CLHEP::HepSymMatrix covMatrix(3, 0);
1051 for (
int i = 0; i < 3; i++) {
1052 pos[i] = m_BeamSpotCenter(i);
1053 for (
int j = 0; j < 3; j++) {
1054 covMatrix[i][j] = m_beamSpotCov(i, j);
1063 CLHEP::HepSymMatrix err(7, 0);
1065 for (
int i = 0; i < 3; i++) {
1066 for (
int j = 0; j < 3; j++) {
1067 err[i + 4][j + 4] = m_beamSpotCov(i, j);
1075 ROOTToCLHEP::getHepLorentzVector(iptube_mom),
1076 ROOTToCLHEP::getPoint3D(m_BeamSpotCenter),
1081 void ParticleVertexFitterModule::findConstraintBoost(
double cut)
1086 TVector3 boostDir = boost.Unit();
1088 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
1089 beamSpotCov(2, 2) = cut * cut;
1090 double thetab = boostDir.Theta();
1091 double phib = boostDir.Phi();
1093 double stb = TMath::Sin(thetab);
1094 double ctb = TMath::Cos(thetab);
1095 double spb = TMath::Sin(phib);
1096 double cpb = TMath::Cos(phib);
1099 TMatrix rz(3, 3); rz(2, 2) = 1;
1100 rz(0, 0) = cpb; rz(0, 1) = spb;
1101 rz(1, 0) = -1 * spb; rz(1, 1) = cpb;
1103 TMatrix ry(3, 3); ry(1, 1) = 1;
1104 ry(0, 0) = ctb; ry(0, 2) = -1 * stb;
1105 ry(2, 0) = stb; ry(2, 2) = ctb;
1107 TMatrix r(3, 3); r.Mult(rz, ry);
1108 TMatrix rt(3, 3); rt.Transpose(r);
1110 TMatrix TubePart(3, 3); TubePart.Mult(rt, beamSpotCov);
1111 TMatrix Tube(3, 3); Tube.Mult(TubePart, r);
1113 m_beamSpotCov(0, 0) = Tube(0, 0); m_beamSpotCov(0, 1) = Tube(0, 1); m_beamSpotCov(0, 2) = Tube(0, 2);
1114 m_beamSpotCov(1, 0) = Tube(1, 0); m_beamSpotCov(1, 1) = Tube(1, 1); m_beamSpotCov(1, 2) = Tube(1, 2);
1115 m_beamSpotCov(2, 0) = Tube(2, 0); m_beamSpotCov(2, 1) = Tube(2, 1); m_beamSpotCov(2, 2) = Tube(2, 2);
1118 void ParticleVertexFitterModule::smearBeamSpot(
double width)
1120 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
1121 for (
int i = 0; i < 3; i++)
1122 beamSpotCov(i, i) += width * width;
1124 m_beamSpotCov = beamSpotCov;