Belle II Software development
ParticleVertexFitterModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <analysis/modules/ParticleVertexFitter/ParticleVertexFitterModule.h>
11
12// framework aux
13#include <framework/gearbox/Unit.h>
14#include <framework/gearbox/Const.h>
15#include <framework/logging/Logger.h>
16#include <framework/particledb/EvtGenDatabasePDG.h>
17
18// dataobjects
19#include <analysis/dataobjects/Particle.h>
20#include <analysis/dataobjects/Btube.h>
21#include <mdst/dataobjects/V0.h>
22
23// utilities
24#include <analysis/utility/CLHEPToROOT.h>
25#include <analysis/utility/PCmsLabTransform.h>
26#include <analysis/utility/ParticleCopy.h>
27#include <analysis/utility/ROOTToCLHEP.h>
28
29// Magnetic field
30#include <framework/geometry/BFieldManager.h>
31
32// KFit
33#include <analysis/VertexFitting/KFit/KFitConst.h>
34#include <analysis/VertexFitting/KFit/MassFitKFit.h>
35#include <analysis/VertexFitting/KFit/FourCFitKFit.h>
36#include <analysis/VertexFitting/KFit/MassFourCFitKFit.h>
37#include <analysis/VertexFitting/KFit/MassPointingVertexFitKFit.h>
38#include <analysis/VertexFitting/KFit/MassVertexFitKFit.h>
39#include <analysis/VertexFitting/KFit/VertexFitKFit.h>
40#include <analysis/VertexFitting/KFit/MakeMotherKFit.h>
41#include <analysis/VertexFitting/KFit/RecoilMassKFit.h>
42
43// Rave
44#include <analysis/VertexFitting/RaveInterface/RaveSetup.h>
45#include <analysis/VertexFitting/RaveInterface/RaveVertexFitter.h>
46#include <analysis/VertexFitting/RaveInterface/RaveKinematicVertexFitter.h>
47
48#include <TVector.h>
49#include <TRotation.h>
50#include <TMath.h>
51
52using namespace std;
53using namespace Belle2;
54
55
56//-----------------------------------------------------------------
57// Register module
58//-----------------------------------------------------------------
59
60REG_MODULE(ParticleVertexFitter);
61
62//-----------------------------------------------------------------
63// Implementation
64//-----------------------------------------------------------------
65
67 m_Bfield(0)
68{
69 // set module description (e.g. insert text)
70 setDescription("Vertex fitter for modular analysis");
72
73 // Add parameters
74 addParam("listName", m_listName, "name of particle list", string(""));
75 addParam("confidenceLevel", m_confidenceLevel,
76 "Confidence level to accept the fit. Particle candidates with "
77 "p-value less than confidenceLevel are removed from the particle "
78 "list. If set to -1, all candidates are kept; if set to 0, "
79 "the candidates failing the fit are removed.",
80 0.001);
81 addParam("vertexFitter", m_vertexFitter, "KFit or Rave", string("KFit"));
82 addParam("fitType", m_fitType, "type of the kinematic fit (vertex, massvertex, mass)", string("vertex"));
83 addParam("withConstraint", m_withConstraint,
84 "additional constraint on vertex: ipprofile, iptube, mother, iptubecut, pointing, btube",
85 string(""));
86 addParam("decayString", m_decayString, "specifies which daughter particles are included in the kinematic fit", string(""));
87 addParam("updateDaughters", m_updateDaughters, "true: update the daughters after the vertex fit", false);
88 addParam("smearing", m_smearing, "smear IP tube width by given length", 0.002);
89 addParam("recoilMass", m_recoilMass, "recoil invariant mass (GeV)", 0.);
90 addParam("massConstraintList", m_massConstraintList,
91 "Type::[int]. List of daughter particles to mass constrain with int = pdg code. (only for MassFourCKFit)", {});
92}
93
95{
96 // Particle list with name m_listName has to exist
97 m_plist.isRequired(m_listName);
98
99 // magnetic field
100 m_Bfield = BFieldManager::getFieldInTesla(ROOT::Math::XYZVector(0, 0, 0)).Z();
101
102 // RAVE setup
103 if (m_vertexFitter == "Rave")
105
106 B2DEBUG(1, "ParticleVertexFitterModule : magnetic field = " << m_Bfield);
107
108
109 if (m_decayString != "")
111
112 B2INFO("ParticleVertexFitter: Performing " << m_fitType << " fit on " << m_listName << " using " << m_vertexFitter);
113 if (m_decayString != "")
114 B2INFO("ParticleVertexFitter: Using specified decay string: " << m_decayString);
115 if (m_withConstraint != "")
116 B2INFO("ParticleVertexFitter: Additional " << m_withConstraint << " will be applied");
117
118 if (m_fitType == "fourC")
119 B2WARNING("ParticleVertexFitter: The fourC fit results stored in extraInfo have been fixed. "
120 "FourCFitProb now holds the p-value of the fit (previously the chi2), "
121 "FourCFitChi2 holds the chi2 (previously the NDF), and the NDF is stored in the new FourCFitNDF.");
122
123}
124
126{
127 // TODO: set magnetic field for each run
128 // m_Bfield = BFieldManager::getFieldInTesla(ROOT::Math::XYZVector(0, 0, 0)).Z();
129 // TODO: set IP spot size for each run
130}
131
133{
134 if (m_vertexFitter == "Rave")
136
137 m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
138 m_beamSpotCov.ResizeTo(3, 3);
139 if (m_withConstraint == "ipprofile") m_beamSpotCov = m_beamSpotDB->getCovVertex();
140 if (m_withConstraint == "iptube") {
141 if (m_smearing > 0 && m_vertexFitter == "KFit") {
143 } else {
145 }
146 }
147 if (m_withConstraint == "iptubecut") { // for development purpose only
148 m_BeamSpotCenter = ROOT::Math::XYZVector(0.001, 0., .013);
150 }
151 if ((m_vertexFitter == "Rave") && (m_withConstraint == "ipprofile" || m_withConstraint == "iptube"
152 || m_withConstraint == "mother" || m_withConstraint == "iptubecut" || m_withConstraint == "btube"))
154
155 std::vector<unsigned int> toRemove;
156 unsigned int nParticles = m_plist->getListSize();
157
158 for (unsigned iPart = 0; iPart < nParticles; iPart++) {
159 Particle* particle = m_plist->getParticle(iPart);
160 m_hasCovMatrix = false;
161 if (m_updateDaughters == true) {
162 if (m_decayString.empty() || m_vertexFitter == "KFit")
164 else B2ERROR("Daughters update works only when all daughters are selected. Daughters will not be updated");
165 }
166
167 if (m_withConstraint == "mother") {
168 m_BeamSpotCenter = particle->getVertex();
169 m_beamSpotCov = particle->getVertexErrorMatrix();
170 }
171
172 TMatrixFSym mother_errMatrix(7);
173 mother_errMatrix = particle->getMomentumVertexErrorMatrix();
174 for (int k = 0; k < 7; k++) {
175 for (int j = 0; j < 7; j++) {
176 if (mother_errMatrix[k][j] > 0) {
177 m_hasCovMatrix = true;
178 }
179 }
180 }
181
182 bool hasTube = true;
183 if (m_withConstraint == "btube") {
184 Btube* Ver = particle->getRelatedTo<Btube>();
185 if (!Ver) {
186 hasTube = false;
187 toRemove.push_back(particle->getArrayIndex());
188 } else {
189 m_BeamSpotCenter.SetXYZ(Ver->getTubeCenter()(0, 0), Ver->getTubeCenter()(1, 0), Ver->getTubeCenter()(2, 0));
191 }
192 }
193 bool ok = false;
194 if (hasTube) {
195 ok = doVertexFit(particle);
196 }
197 if (!ok)
198 particle->setPValue(-1);
199 if (particle->getPValue() < m_confidenceLevel)
200 toRemove.push_back(particle->getArrayIndex());
201
202 }
203 m_plist->removeParticles(toRemove);
204
205 //free memory allocated by rave. initialize() would be enough, except that we must clean things up before program end...
206 if (m_vertexFitter == "Rave")
208}
209
211{
212 // steering starts here
213
214 if (m_Bfield == 0) {
215 B2FATAL("ParticleVertexFitter: No magnetic field");
216 }
217
218 if (m_withConstraint != "ipprofile" &&
219 m_withConstraint != "iptube" &&
220 m_withConstraint != "mother" &&
221 m_withConstraint != "iptubecut" &&
222 m_withConstraint != "pointing" &&
223 m_withConstraint != "btube" &&
224 m_withConstraint != "")
225 B2FATAL("ParticleVertexFitter: " << m_withConstraint << " ***invalid Constraint ");
226
227 bool ok = false;
228 // fits with KFit
229 if (m_vertexFitter == "KFit") {
230
231 if (m_decayString != "" and m_fitType != "vertex")
232 B2FATAL("ParticleVertexFitter: KFit does not support yet selection of daughters via decay string except for vertex fit!");
233
234 // vertex fit
235 if (m_fitType == "vertex") {
236 if (m_withConstraint == "ipprofile") {
237 ok = doKVertexFit(mother, true, false);
238 } else if (m_withConstraint == "iptube") {
239 ok = doKVertexFit(mother, false, true);
240 } else {
241 ok = doKVertexFit(mother, false, false);
242 }
243 }
244
245 // mass-constrained vertex fit
246 if (m_fitType == "massvertex") {
247 if (m_withConstraint == "ipprofile" || m_withConstraint == "iptube" || m_withConstraint == "iptubecut") {
248 B2FATAL("ParticleVertexFitter: Invalid options - mass-constrained fit using KFit does not work with iptube or ipprofile constraint.");
249 } else if (m_withConstraint == "pointing") {
250 ok = doKMassPointingVertexFit(mother);
251 } else {
252 ok = doKMassVertexFit(mother);
253 }
254 }
255
256 // mass fit
257 if (m_fitType == "mass") {
258 if (m_withConstraint == "ipprofile" || m_withConstraint == "iptube" || m_withConstraint == "iptubecut") {
259 B2FATAL("ParticleVertexFitter: Invalid options - mass fit using KFit does not work with iptube or ipprofile constraint.");
260 } else {
261 ok = doKMassFit(mother);
262 }
263 }
264
265 // four C fit
266 if (m_fitType == "fourC") {
267 if (m_withConstraint == "ipprofile" || m_withConstraint == "iptube" || m_withConstraint == "iptubecut") {
268 B2FATAL("ParticleVertexFitter: Invalid options - four C fit using KFit does not work with iptube or ipprofile constraint.");
269 } else {
270 ok = doKFourCFit(mother);
271 }
272 }
273
274 // four mass C fit
275 if (m_fitType == "massfourC") {
276 if (m_withConstraint == "ipprofile" || m_withConstraint == "iptube" || m_withConstraint == "iptubecut") {
277 B2FATAL("ParticleVertexFitter: Invalid options - four C fit using KFit does not work with iptube or ipprofile constraint.");
278 } else {
279 ok = doKMassFourCFit(mother);
280 }
281 }
282
283 // recoil mass C fit
284 if (m_fitType == "recoilmass") {
285 if (m_withConstraint == "ipprofile" || m_withConstraint == "iptube" || m_withConstraint == "iptubecut") {
286 B2FATAL("ParticleVertexFitter: Invalid options - recoil mass fit using KFit does not work with iptube or ipprofile constraint.");
287 } else {
288 ok = doKRecoilMassFit(mother);
289 }
290 }
291
292 // invalid KFit fit type
293 if (m_fitType != "vertex"
294 && m_fitType != "massvertex"
295 && m_fitType != "mass"
296 && m_fitType != "fourC"
297 && m_fitType != "massfourC"
298 && m_fitType != "recoilmass")
299 B2FATAL("ParticleVertexFitter: " << m_fitType << " ***invalid fit type for the vertex fitter ");
300 }
301
302 // fits using Rave
303 if (m_vertexFitter == "Rave") {
304 try {
305 ok = doRaveFit(mother);
306 } catch (const rave::CheckedFloatException&) {
307 B2ERROR("Invalid inputs (nan/inf)?");
308 ok = false;
309 }
310 }
311
312 // invalid fitter
313 if (m_vertexFitter != "KFit" && m_vertexFitter != "Rave")
314 B2FATAL("ParticleVertexFitter: " << m_vertexFitter << " ***invalid vertex fitter ");
315
316 if (!ok) return false;
317
318 // steering ends here
319
320 //if (mother->getPValue() < m_confidenceLevel) return false;
321 return true;
322
323}
324
325bool ParticleVertexFitterModule::fillFitParticles(const Particle* mother, std::vector<const Particle*>& fitChildren,
326 std::vector<const Particle*>& twoPhotonChildren)
327{
328 if (m_decayString.empty()) {
329 // if decayString is empty, just use all primary daughters
330 for (unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
331 const Particle* child = mother->getDaughter(ichild);
332 // This if allows to skip the daughters, which cannot be used in the fits, particularly K_L0 from KLM.
333 // Useful for fully-inclusive particles.
334 if (mother->getProperty() == Particle::PropertyFlags::c_IsUnspecified and child->getPValue() < 0) {
335 continue;
336 }
337 fitChildren.push_back(child);
338 }
339 } else {
340 fitChildren = m_decaydescriptor.getSelectionParticles(mother);
341 }
342
343 auto itr = fitChildren.begin();
344 while (itr != fitChildren.end()) {
345 const Particle* child = *itr;
346
347 if (child->getPValue() < 0) {
348 B2WARNING("Daughter with PDG code " << child->getPDGCode() << " does not have a valid error matrix.");
349 return false; // error matrix not valid
350 }
351 bool isTwoPhotonParticle = false;
352 if (m_hasCovMatrix == false) {
353 if (child->getPDGCode() == Const::pi0.getPDGCode() or child->getPDGCode() == 221) { // pi0 or eta
354 if (child->getNDaughters() == 2) {
355 if (child->getDaughter(0)->getPDGCode() == Const::photon.getPDGCode()
356 && child->getDaughter(1)->getPDGCode() == Const::photon.getPDGCode()) {
357 isTwoPhotonParticle = true;
358 }
359 }
360 }
361 }
362 if (isTwoPhotonParticle) {
363 // move children from fitChildren to twoPhotonChildren
364 twoPhotonChildren.push_back(child);
365 itr = fitChildren.erase(itr);
366 } else {
367 itr++;
368 }
369 }
370
371 return true;
372}
373
374bool ParticleVertexFitterModule::fillNotFitParticles(const Particle* mother, std::vector<const Particle*>& notFitChildren,
375 const std::vector<const Particle*>& fitChildren)
376{
377 if (fitChildren.empty())
378 B2WARNING("[ParticleVertexFitterModule::fillNotFitParticles] fitChildren is empty! Please call fillFitParticles firstly");
379 if (!notFitChildren.empty())
380 B2WARNING("[ParticleVertexFitterModule::fillNotFitParticles] notFitChildren is NOT empty!"
381 << " The function should be called only once");
382
383 if (m_decayString.empty())
384 // if decayString is empty, just use all primary daughters
385 return true;
386
387 std::function<bool(const Particle*)> funcCheckInFit =
388 [&funcCheckInFit, &notFitChildren, fitChildren](const Particle * part) {
389
390 // check if the given particle in fitChildren
391 // if it is included, return true
392 if (std::find(fitChildren.begin(), fitChildren.end(), part) != fitChildren.end())
393 return true;
394
395 // if not, firstly check if particle has children
396 if (part->getNDaughters() == 0)
397 // if it has no children (=final-state-particle), return false
398 return false;
399
400 // here, the given particle is not in fitChildren and has children
401 bool isAnyChildrenInFit = false;
402 vector<const Particle*> notFitChildren_tmp;
403 for (unsigned ichild = 0; ichild < part->getNDaughters(); ichild++) {
404 // call funcCheckInFit recursively for all children
405 const Particle* child = part->getDaughter(ichild);
406 bool isChildrenInFit = funcCheckInFit(child);
407 isAnyChildrenInFit = isChildrenInFit or isAnyChildrenInFit;
408
409 // if the child is not in fitChildren, fill the child in a temporary vector
410 if (!isChildrenInFit)
411 notFitChildren_tmp.push_back(child);
412 }
413
414 // if there are a sister in fitChildren, the children in the temporary vector will be filled in notFitChildren
415 if (isAnyChildrenInFit)
416 notFitChildren.insert(notFitChildren.end(), notFitChildren_tmp.begin(), notFitChildren_tmp.end());
417
418 // if no children in fitChildren, the given particle should be filled instead of all children.
419
420 return isAnyChildrenInFit;
421 };
422
423
424 // call funcCheckInFit for all primary children
425 for (unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
426 const Particle* child = mother->getDaughter(ichild);
427 bool isGivenParticleOrAnyChildrenInFit = funcCheckInFit(child);
428 if (!isGivenParticleOrAnyChildrenInFit)
429 notFitChildren.push_back(child);
430 }
431
432 return true;
433}
434
436 const analysis::VertexFitKFit& kv)
437{
438 // TODO: something like setGammaError is necessary
439 // this is just workaround for the moment
440
441 const Particle* g1Orig = preFit->getDaughter(0);
442 const Particle* g2Orig = preFit->getDaughter(1);
443 Particle g1Temp(g1Orig->get4Vector(), 22);
444 Particle g2Temp(g2Orig->get4Vector(), 22);
445
446 TMatrixFSym g1ErrMatrix = g1Orig->getMomentumVertexErrorMatrix();
447 TMatrixFSym g2ErrMatrix = g2Orig->getMomentumVertexErrorMatrix();
448
449 ROOT::Math::XYZVector pos(kv.getVertex().x(), kv.getVertex().y(), kv.getVertex().z());
450 CLHEP::HepSymMatrix posErrorMatrix = kv.getVertexError();
451
452 TMatrixFSym errMatrix(3);
453 for (int i = 0; i < 3; i++)
454 for (int j = 0; j < 3; j++)
455 errMatrix(i, j) = posErrorMatrix[i][j];
456
457 g1ErrMatrix.SetSub(4, errMatrix);
458 g2ErrMatrix.SetSub(4, errMatrix);
459
460 g1Temp.updateMomentum(g1Orig->get4Vector(), pos, g1ErrMatrix, 1.0);
461 g2Temp.updateMomentum(g2Orig->get4Vector(), pos, g2ErrMatrix, 1.0);
462
463 // perform the mass fit for the two-photon particle
466
467 km.addParticle(&g1Temp);
468 km.addParticle(&g2Temp);
469
470 km.setVertex(kv.getVertex());
472 km.setInvariantMass(preFit->getPDGMass());
473
474 int err = km.doFit();
475 if (err != 0) {
476 return false;
477 }
478
479 // The update of the daughters is disabled for this mass fit.
480 bool updateDaughters = m_updateDaughters;
481 m_updateDaughters = false;
482 bool ok = makeKMassMother(km, postFit);
483 m_updateDaughters = updateDaughters;
484
485 return ok;
486}
487
488bool ParticleVertexFitterModule::doKVertexFit(Particle* mother, bool ipProfileConstraint, bool ipTubeConstraint)
489{
490 if ((mother->getNDaughters() < 2 && !ipTubeConstraint) || mother->getNDaughters() < 1) return false;
491
492 std::vector<const Particle*> fitChildren;
493 std::vector<const Particle*> twoPhotonChildren;
494 bool validChildren = fillFitParticles(mother, fitChildren, twoPhotonChildren);
495
496 if (!validChildren)
497 return false;
498
499 std::vector<const Particle*> notFitChildren;
500 fillNotFitParticles(mother, notFitChildren, fitChildren);
501
502
503 if (twoPhotonChildren.size() > 1) {
504 B2FATAL("[ParticleVertexFitterModule::doKVertexFit] Vertex fit using KFit does not support fit with multiple particles decaying to two photons like pi0 (yet).");
505 }
506
507 if ((fitChildren.size() < 2 && !ipTubeConstraint) || fitChildren.size() < 1) {
508 B2WARNING("[ParticleVertexFitterModule::doKVertexFit] Number of particles with valid error matrix entering the vertex fit using KFit is too low.");
509 return false;
510 }
511
512 // Initialise the Fitter
515
516 if (mother->getV0()) {
518 }
519
520 for (auto& child : fitChildren)
521 kv.addParticle(child);
522
523 if (ipProfileConstraint)
525
526 if (ipTubeConstraint)
527 addIPTubeToKFit(kv);
528
529 // Perform vertex fit using only the particles with valid error matrices
530 int err = kv.doFit();
531 if (err != 0)
532 return false;
533
534 double chi2_track = getChi2TracksLBoost(kv);
535 unsigned track_count = kv.getTrackCount();
536 mother->writeExtraInfo("chiSquared_trackL", chi2_track);
537 mother->writeExtraInfo("kFit_nTracks", track_count);
538
539 bool ok = false;
540 if (twoPhotonChildren.size() == 0)
541 // in the case daughters do not include pi0 - this is it (fit done)
542 ok = makeKVertexMother(kv, mother);
543 else if (twoPhotonChildren.size() == 1) {
544 // there is a daughter reconstructed from two photons so without position information
545 // 1. determine vertex based on all other valid daughters
546 // 2. set position and error matrix of two-photon daughter to previously determined vertex
547 // 3. redo the fit using all particles (including two-photon particle this time)
548
549 const Particle* twoPhotonDaughter = twoPhotonChildren[0];
550 Particle fixedTwoPhotonDaughter(twoPhotonDaughter->get4Vector(), twoPhotonDaughter->getPDGCode());
551 ok = redoTwoPhotonDaughterMassFit(&fixedTwoPhotonDaughter, twoPhotonDaughter, kv);
552 if (!ok)
553 return false;
554
555 // finally perform the fit using all daughter particles
558
559 for (auto& child : fitChildren)
560 kv2.addParticle(child);
561
562 kv2.addParticle(&fixedTwoPhotonDaughter);
563
564 if (ipProfileConstraint)
566
567 err = kv2.doFit();
568
569 if (err != 0)
570 return false;
571
572 ok = makeKVertexMother(kv2, mother);
573 }
574
575 // update 4-vector using not-fit-particles
576 ROOT::Math::PxPyPzEVector total4Vector(mother->get4Vector());
577 for (auto& child : notFitChildren)
578 total4Vector += child->get4Vector();
579 mother->set4Vector(total4Vector);
580
581 return ok;
582}
583
585{
586 if (mother->getNDaughters() < 2) return false;
587
588 std::vector<const Particle*> fitChildren;
589 std::vector<const Particle*> twoPhotonChildren;
590 bool validChildren = fillFitParticles(mother, fitChildren, twoPhotonChildren);
591
592 if (!validChildren)
593 return false;
594
595 if (twoPhotonChildren.size() > 1) {
596 B2FATAL("[ParticleVertexFitterModule::doKVertexFit] MassVertex fit using KFit does not support fit with multiple particles decaying to two photons like pi0 (yet).");
597 }
598
599 if (fitChildren.size() < 2) {
600 B2WARNING("[ParticleVertexFitterModule::doKVertexFit] Number of particles with valid error matrix entering the vertex fit using KFit is less than 2.");
601 return false;
602 }
603
604 bool ok = false;
605 if (twoPhotonChildren.size() == 0) {
606 // Initialise the Fitter
609
610 if (mother->getV0()) {
611 HepPoint3D V0vertex_heppoint(mother->getV0()->getFittedVertexX(),
612 mother->getV0()->getFittedVertexY(),
613 mother->getV0()->getFittedVertexZ());
614 kmv.setInitialVertex(V0vertex_heppoint);
615 }
616
617 for (auto child : fitChildren)
618 kmv.addParticle(child);
619
620 kmv.setInvariantMass(mother->getPDGMass());
621 int err = kmv.doFit();
622 if (err != 0)
623 return false;
624
625 // in the case daughters do not include particles with two photon daughters like pi0 - this is it (fit done)
626 ok = makeKMassVertexMother(kmv, mother);
627 } else if (twoPhotonChildren.size() == 1) {
628 // there is a daughter reconstructed from two photons so without position information
629 // 1. determine vertex based on all other valid daughters
630 // 2. set position and error matrix of two-photon daughter to previously determined vertex
631 // 3. redo the fit using all particles (including two-photon particle this time)
632
635
636 for (auto child : fitChildren)
637 kv.addParticle(child);
638
639 // Perform vertex fit using only the particles with valid error matrices
640 int err = kv.doFit();
641 if (err != 0)
642 return false;
643
644 const Particle* twoPhotonDaughter = twoPhotonChildren[0];
645 Particle fixedTwoPhotonDaughter(twoPhotonDaughter->get4Vector(), twoPhotonDaughter->getPDGCode());
646 ok = redoTwoPhotonDaughterMassFit(&fixedTwoPhotonDaughter, twoPhotonDaughter, kv);
647 if (!ok)
648 return false;
649
650 // finally perform the fit using all daughter particles
653
654 for (auto child : fitChildren)
655 kmv2.addParticle(child);
656 kmv2.addParticle(&fixedTwoPhotonDaughter);
657
658 kmv2.setInvariantMass(mother->getPDGMass());
659 err = kmv2.doFit();
660
661 if (err != 0)
662 return false;
663
664 ok = makeKMassVertexMother(kmv2, mother);
665 }
666
667 return ok;
668
669}
670
672{
673 if (!(mother->hasExtraInfo("prodVertX") && mother->hasExtraInfo("prodVertY") && mother->hasExtraInfo("prodVertZ"))) {
674 return false;
675 }
676
677 if (mother->getNDaughters() < 2) return false;
678
679 std::vector<const Particle*> fitChildren;
680 std::vector<const Particle*> twoPhotonChildren;
681 bool validChildren = fillFitParticles(mother, fitChildren, twoPhotonChildren);
682
683 if (!validChildren)
684 return false;
685
686 if (twoPhotonChildren.size() > 0) {
687 B2FATAL("[ParticleVertexFitterModule::doKMassPointingVertexFit] MassPointingVertex fit using KFit does not support fit with two-photon daughters (yet).");
688 }
689
690 if (fitChildren.size() < 2) {
691 B2WARNING("[ParticleVertexFitterModule::doKMassPointingVertexFit] Number of particles with valid error matrix entering the vertex fit using KFit is less than 2.");
692 return false;
693 }
694
695 bool ok = false;
696 // Initialise the Fitter
699
700 for (auto child : fitChildren)
701 kmpv.addParticle(child);
702
703 kmpv.setInvariantMass(mother->getPDGMass());
704 HepPoint3D productionVertex(mother->getExtraInfo("prodVertX"),
705 mother->getExtraInfo("prodVertY"),
706 mother->getExtraInfo("prodVertZ"));
707 kmpv.setProductionVertex(productionVertex);
708 int err = kmpv.doFit();
709 if (err != 0) return false;
710
711 ok = makeKMassPointingVertexMother(kmpv, mother);
712
713 return ok;
714}
715
717{
718 if (mother->getNDaughters() < 2) return false;
719
722
723 for (unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
724 const Particle* child = mother->getDaughter(ichild);
725
726 if (child->getPValue() < 0) return false; // error matrix not valid
727
728 km.addParticle(child);
729 }
730
731 // apply mass constraint
732 km.setInvariantMass(mother->getPDGMass());
733
734 int err = km.doFit();
735
736 if (err != 0) return false;
737
738 bool ok = makeKMassMother(km, mother);
739
740 return ok;
741}
742
744{
745 if (mother->getNDaughters() < 2) return false;
746
749
750 for (unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
751 const Particle* child = mother->getDaughter(ichild);
752
753 if (child->getNDaughters() > 0) {
754 bool err = addChildofParticletoKFit(kf, child);
755 if (!err) return false;
756 } else {
757 if (child->getPValue() < 0) return false; // error matrix not valid
758
759 kf.addParticle(child);
760 }
761 }
762
763 // apply four momentum constraint
765 kf.setFourMomentum(T.getBeamFourMomentum());
766
767 int err = kf.doFit();
768
769 if (err != 0) return false;
770
771 bool ok = makeKFourCMother(kf, mother);
772
773 return ok;
774}
775
777{
778 if (mother->getNDaughters() < 2) return false;
779
782
783 for (unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
784 const Particle* child = mother->getDaughter(ichild);
785
786 if (child->getNDaughters() > 0) {
787 bool massconstraint = std::find(m_massConstraintList.begin(), m_massConstraintList.end(),
788 std::abs(child->getPDGCode())) != m_massConstraintList.end();
789 std::vector<unsigned> childId;
790 bool err = addChildofParticletoMassKFit(kf, child, childId);
791 if (massconstraint) kf.addMassConstraint(child->getPDGMass(), childId);
792 if (!err) return false;
793 } else {
794 if (child->getPValue() < 0) return false; // error matrix not valid
795 kf.addParticle(child);
796 }
797 }
798
799 // apply four momentum constraint
801 kf.setFourMomentum(T.getBeamFourMomentum());
802
803 int err = kf.doFit();
804
805 if (err != 0) return false;
806
807 bool ok = makeMassKFourCMother(kf, mother);
808
809 return ok;
810}
811
813{
816
817 for (unsigned ichild = 0; ichild < mother->getNDaughters(); ichild++) {
818 const Particle* child = mother->getDaughter(ichild);
819
820 if (child->getPValue() < 0) return false; // error matrix not valid
821
822 kf.addParticle(child);
823 }
824
825 // apply four momentum constraint
827 kf.setFourMomentum(T.getBeamFourMomentum());
828
829 // apply recoil mass constraint
831
832 int err = kf.doFit();
833
834 if (err != 0) return false;
835
836 bool ok = makeKRecoilMassMother(kf, mother);
837
838 return ok;
839}
840
842 Particle* mother)
843{
844 enum analysis::KFitError::ECode fitError;
845 fitError = kv.updateMother(mother);
846 if (fitError != analysis::KFitError::kNoError)
847 return false;
848 if (m_decayString.empty() && m_updateDaughters == true) {
849 // update daughter momenta as well
850 // the order of daughters in the *fitter is the same as in the mother Particle
851
852 std::vector<Particle*> daughters = mother->getDaughters();
853
854 unsigned track_count = kv.getTrackCount();
855 if (daughters.size() != track_count)
856 return false;
857
858 for (unsigned iChild = 0; iChild < track_count; iChild++) {
859 double a = -1 * Const::speedOfLight * 1e-4 * m_Bfield * daughters[iChild]->getCharge();
860 double dx = kv.getVertex().x() - kv.getTrackPosition(iChild).x();
861 double dy = kv.getVertex().y() - kv.getTrackPosition(iChild).y();
862
863 ROOT::Math::PxPyPzEVector i4Vector(kv.getTrackMomentum(iChild).x() - a * dy,
864 kv.getTrackMomentum(iChild).y() + a * dx,
865 kv.getTrackMomentum(iChild).z(),
866 kv.getTrackMomentum(iChild).t());
867 daughters[iChild]->set4VectorDividingByMomentumScaling(i4Vector);
868
869 daughters[iChild]->setVertex(
870 CLHEPToROOT::getXYZVector(kv.getTrackPosition(iChild)));
871 daughters[iChild]->setMomentumVertexErrorMatrix(
872 CLHEPToROOT::getTMatrixFSym(kv.getTrackError(iChild)));
873 }
874
875 } else if (m_updateDaughters == true) { // if decayString is not empty
876 // first, update only the fit children
877 std::vector<const Particle*> fitChildren = m_decaydescriptor.getSelectionParticles(mother);
878
879 unsigned track_count = kv.getTrackCount();
880 if (fitChildren.size() != track_count)
881 return false;
882
883 for (unsigned iChild = 0; iChild < track_count; iChild++) {
884 auto daughter = const_cast<Particle*>(fitChildren[iChild]);
885
886 double a = -1 * Const::speedOfLight * 1e-4 * m_Bfield * daughter->getCharge();
887 double dx = kv.getVertex().x() - kv.getTrackPosition(iChild).x();
888 double dy = kv.getVertex().y() - kv.getTrackPosition(iChild).y();
889
890 ROOT::Math::PxPyPzEVector i4Vector(kv.getTrackMomentum(iChild).x() - a * dy,
891 kv.getTrackMomentum(iChild).y() + a * dx,
892 kv.getTrackMomentum(iChild).z(),
893 kv.getTrackMomentum(iChild).t());
894 daughter->set4VectorDividingByMomentumScaling(i4Vector);
895
896 daughter->setVertex(CLHEPToROOT::getXYZVector(kv.getTrackPosition(iChild)));
897 daughter->setMomentumVertexErrorMatrix(CLHEPToROOT::getTMatrixFSym(kv.getTrackError(iChild)));
898 }
899
900 // then, update other particles that have a fit-child in decay
901 std::function<bool(Particle*)> funcUpdateMomentum =
902 [&funcUpdateMomentum, fitChildren](Particle * part) {
903
904 if (part->getNDaughters() == 0) {
905 // check if part is included in fitChildren
906 if (std::find(fitChildren.begin(), fitChildren.end(), part) != fitChildren.end())
907 return true;
908 else
909 return false;
910 }
911
912 bool includeFitChildren = false;
913
914 // Update daughters' momentum
915 for (auto daughter : part->getDaughters())
916 includeFitChildren = funcUpdateMomentum(daughter) || includeFitChildren;
917
918 if (includeFitChildren) {
919 // Using updated daughters, update part's momentum
920 ROOT::Math::PxPyPzEVector sum4Vector;
921 for (auto daughter : part->getDaughters())
922 sum4Vector += daughter->get4Vector();
923
924 part->set4VectorDividingByMomentumScaling(sum4Vector);
925 }
926
927 return includeFitChildren;
928 };
929
930 // Update all daughters
931 for (auto daughter : mother->getDaughters())
932 funcUpdateMomentum(daughter);
933
934 }
935
936
937 return true;
938}
939
941 Particle* mother)
942{
943 enum analysis::KFitError::ECode fitError;
944 fitError = kmv.updateMother(mother);
945 if (fitError != analysis::KFitError::kNoError)
946 return false;
947 if (m_decayString.empty() && m_updateDaughters == true) {
948 // update daughter momenta as well
949 // the order of daughters in the *fitter is the same as in the mother Particle
950
951 std::vector<Particle*> daughters = mother->getDaughters();
952
953 unsigned track_count = kmv.getTrackCount();
954 if (daughters.size() != track_count)
955 return false;
956
957 for (unsigned iChild = 0; iChild < track_count; iChild++) {
958 double a = -1 * Const::speedOfLight * 1e-4 * m_Bfield * daughters[iChild]->getCharge();
959 double dx = kmv.getVertex().x() - kmv.getTrackPosition(iChild).x();
960 double dy = kmv.getVertex().y() - kmv.getTrackPosition(iChild).y();
961
962 ROOT::Math::PxPyPzEVector i4Vector(kmv.getTrackMomentum(iChild).x() - a * dy,
963 kmv.getTrackMomentum(iChild).y() + a * dx,
964 kmv.getTrackMomentum(iChild).z(),
965 kmv.getTrackMomentum(iChild).t());
966 daughters[iChild]->set4VectorDividingByMomentumScaling(i4Vector);
967
968 daughters[iChild]->setVertex(
969 CLHEPToROOT::getXYZVector(kmv.getTrackPosition(iChild)));
970 daughters[iChild]->setMomentumVertexErrorMatrix(
971 CLHEPToROOT::getTMatrixFSym(kmv.getTrackError(iChild)));
972 }
973 }
974
975 return true;
976}
977
979 Particle* mother)
980{
981 enum analysis::KFitError::ECode fitError;
982 fitError = kmpv.updateMother(mother);
983 if (fitError != analysis::KFitError::kNoError) {
984 return false;
985 }
986
987 if (m_decayString.empty() && m_updateDaughters == true) {
988 // update daughter momenta as well
989 // the order of daughters in the *fitter is the same as in the mother Particle
990
991 std::vector<Particle*> daughters = mother->getDaughters();
992
993 unsigned track_count = kmpv.getTrackCount();
994 if (daughters.size() != track_count)
995 return false;
996
997 for (unsigned iChild = 0; iChild < track_count; iChild++) {
998 double a = -1 * Const::speedOfLight * 1e-4 * m_Bfield * daughters[iChild]->getCharge();
999 double dx = kmpv.getVertex().x() - kmpv.getTrackPosition(iChild).x();
1000 double dy = kmpv.getVertex().y() - kmpv.getTrackPosition(iChild).y();
1001
1002 ROOT::Math::PxPyPzEVector i4Vector(kmpv.getTrackMomentum(iChild).x() - a * dy,
1003 kmpv.getTrackMomentum(iChild).y() + a * dx,
1004 kmpv.getTrackMomentum(iChild).z(),
1005 kmpv.getTrackMomentum(iChild).t());
1006 daughters[iChild]->set4VectorDividingByMomentumScaling(i4Vector);
1007
1008 daughters[iChild]->setVertex(
1009 CLHEPToROOT::getXYZVector(kmpv.getTrackPosition(iChild)));
1010 daughters[iChild]->setMomentumVertexErrorMatrix(
1011 CLHEPToROOT::getTMatrixFSym(kmpv.getTrackError(iChild)));
1012 }
1013 }
1014
1015 return true;
1016}
1017
1018
1020 Particle* mother)
1021{
1022 enum analysis::KFitError::ECode fitError;
1023 fitError = km.updateMother(mother);
1024 if (fitError != analysis::KFitError::kNoError)
1025 return false;
1026 if (m_decayString.empty() && m_updateDaughters == true) {
1027 // update daughter momenta as well
1028 // the order of daughters in the *fitter is the same as in the mother Particle
1029
1030 std::vector<Particle*> daughters = mother->getDaughters();
1031
1032 unsigned track_count = km.getTrackCount();
1033 if (daughters.size() != track_count)
1034 return false;
1035
1036 for (unsigned iChild = 0; iChild < track_count; iChild++) {
1037 double a = -1 * Const::speedOfLight * 1e-4 * m_Bfield * daughters[iChild]->getCharge();
1038 double dx = km.getVertex().x() - km.getTrackPosition(iChild).x();
1039 double dy = km.getVertex().y() - km.getTrackPosition(iChild).y();
1040
1041 ROOT::Math::PxPyPzEVector i4Vector(km.getTrackMomentum(iChild).x() - a * dy,
1042 km.getTrackMomentum(iChild).y() + a * dx,
1043 km.getTrackMomentum(iChild).z(),
1044 km.getTrackMomentum(iChild).t());
1045 daughters[iChild]->set4VectorDividingByMomentumScaling(i4Vector);
1046
1047 daughters[iChild]->setVertex(
1048 CLHEPToROOT::getXYZVector(km.getTrackPosition(iChild)));
1049 daughters[iChild]->setMomentumVertexErrorMatrix(
1050 CLHEPToROOT::getTMatrixFSym(km.getTrackError(iChild)));
1051 }
1052 }
1053
1054 return true;
1055}
1056
1057
1058
1060{
1061 enum analysis::KFitError::ECode fitError;
1062 fitError = kf.updateMother(mother);
1063 if (fitError != analysis::KFitError::kNoError)
1064 return false;
1065 mother->addExtraInfo("FourCFitProb", TMath::Prob(kf.getCHIsq(), kf.getNDF()));
1066 mother->addExtraInfo("FourCFitChi2", kf.getCHIsq());
1067 mother->addExtraInfo("FourCFitNDF", kf.getNDF());
1068 if (m_decayString.empty() && m_updateDaughters == true) {
1069 // update daughter momenta as well
1070 // the order of daughters in the *fitter is the same as in the mother Particle
1071
1072 std::vector<Particle*> daughters = mother->getDaughters();
1073
1074 const unsigned nd = daughters.size();
1075 unsigned l = 0;
1076 std::vector<std::vector<unsigned>> pars;
1077 pars.reserve(nd);
1078 std::vector<Particle*> allparticles;
1079 allparticles.reserve(nd);
1080 for (unsigned ichild = 0; ichild < nd; ichild++) {
1081 const Particle* daughter = mother->getDaughter(ichild);
1082 std::vector<unsigned> pard;
1083 if (daughter->getNDaughters() > 0) {
1084 updateMapOfTrackAndDaughter(l, pars, pard, allparticles, daughter);
1085 pars.push_back(std::move(pard));
1086 allparticles.push_back(daughters[ichild]);
1087 } else {
1088 pard.push_back(l);
1089 pars.push_back(std::move(pard));
1090 allparticles.push_back(daughters[ichild]);
1091 l++;
1092 }
1093 }
1094
1095 unsigned track_count = kf.getTrackCount();
1096 if (l != track_count)
1097 return false;
1098
1099 for (unsigned iDaug = 0; iDaug < allparticles.size(); iDaug++) {
1100 ROOT::Math::PxPyPzEVector childMoms;
1101 ROOT::Math::XYZVector childPoss;
1102 TMatrixFSym childErrMatrixs(7);
1103 for (unsigned int iChild : pars[iDaug]) {
1104 childMoms = childMoms +
1105 CLHEPToROOT::getLorentzVector(
1106 kf.getTrackMomentum(iChild));
1107 childPoss = childPoss +
1108 CLHEPToROOT::getXYZVector(
1109 kf.getTrackPosition(iChild));
1110 TMatrixFSym childErrMatrix =
1111 CLHEPToROOT::getTMatrixFSym(kf.getTrackError(iChild));
1112 childErrMatrixs = childErrMatrixs + childErrMatrix;
1113 }
1114 allparticles[iDaug]->set4Vector(childMoms);
1115 allparticles[iDaug]->setVertex(childPoss);
1116 allparticles[iDaug]->setMomentumVertexErrorMatrix(childErrMatrixs);
1117 }
1118 }
1119
1120 return true;
1121}
1122
1124{
1125 enum analysis::KFitError::ECode fitError;
1126 fitError = kf.updateMother(mother);
1127 if (fitError != analysis::KFitError::kNoError)
1128 return false;
1129 mother->addExtraInfo("MassFourCFitProb", TMath::Prob(kf.getCHIsq(), kf.getNDF()));
1130 mother->addExtraInfo("MassFourCFitChi2", kf.getCHIsq());
1131 mother->addExtraInfo("MassFourCFitNDF", kf.getNDF());
1132 if (m_decayString.empty() && m_updateDaughters == true) {
1133 // update daughter momenta as well
1134 // the order of daughters in the *fitter is the same as in the mother Particle
1135
1136 std::vector<Particle*> daughters = mother->getDaughters();
1137
1138 const unsigned nd = daughters.size();
1139 unsigned l = 0;
1140 std::vector<std::vector<unsigned>> pars;
1141 pars.reserve(nd);
1142 std::vector<Particle*> allparticles;
1143 allparticles.reserve(nd);
1144 for (unsigned ichild = 0; ichild < nd; ichild++) {
1145 const Particle* daughter = mother->getDaughter(ichild);
1146 std::vector<unsigned> pard;
1147 if (daughter->getNDaughters() > 0) {
1148 updateMapOfTrackAndDaughter(l, pars, pard, allparticles, daughter);
1149 pars.push_back(std::move(pard));
1150 allparticles.push_back(daughters[ichild]);
1151 } else {
1152 pard.push_back(l);
1153 pars.push_back(std::move(pard));
1154 allparticles.push_back(daughters[ichild]);
1155 l++;
1156 }
1157 }
1158
1159 unsigned track_count = kf.getTrackCount();
1160 if (l != track_count)
1161 return false;
1162
1163 for (unsigned iDaug = 0; iDaug < allparticles.size(); iDaug++) {
1164 ROOT::Math::PxPyPzEVector childMoms;
1165 ROOT::Math::XYZVector childPoss;
1166 TMatrixFSym childErrMatrixs(7);
1167 for (unsigned int iChild : pars[iDaug]) {
1168 childMoms = childMoms +
1169 CLHEPToROOT::getLorentzVector(
1170 kf.getTrackMomentum(iChild));
1171 childPoss = childPoss +
1172 CLHEPToROOT::getXYZVector(
1173 kf.getTrackPosition(iChild));
1174 TMatrixFSym childErrMatrix =
1175 CLHEPToROOT::getTMatrixFSym(kf.getTrackError(iChild));
1176 childErrMatrixs = childErrMatrixs + childErrMatrix;
1177 }
1178 allparticles[iDaug]->set4Vector(childMoms);
1179 allparticles[iDaug]->setVertex(childPoss);
1180 allparticles[iDaug]->setMomentumVertexErrorMatrix(childErrMatrixs);
1181 }
1182 }
1183
1184 return true;
1185}
1186
1188{
1189 enum analysis::KFitError::ECode fitError;
1190 fitError = kf.updateMother(mother);
1191 if (fitError != analysis::KFitError::kNoError)
1192 return false;
1193 mother->addExtraInfo("RecoilMassFitProb", TMath::Prob(kf.getCHIsq(), kf.getNDF()));
1194 mother->addExtraInfo("RecoilMassFitChi2", kf.getCHIsq());
1195 mother->addExtraInfo("RecoilMassFitNDF", kf.getNDF());
1196 if (m_decayString.empty() && m_updateDaughters == true) {
1197 // update daughter momenta as well
1198 // the order of daughters in the *fitter is the same as in the mother Particle
1199
1200 std::vector<Particle*> daughters = mother->getDaughters();
1201
1202 unsigned track_count = kf.getTrackCount();
1203 if (daughters.size() != track_count)
1204 return false;
1205
1206 for (unsigned iChild = 0; iChild < track_count; iChild++) {
1207 double a = -1 * Const::speedOfLight * 1e-4 * m_Bfield * daughters[iChild]->getCharge();
1208 double dx = kf.getVertex().x() - kf.getTrackPosition(iChild).x();
1209 double dy = kf.getVertex().y() - kf.getTrackPosition(iChild).y();
1210
1211 ROOT::Math::PxPyPzEVector i4Vector(kf.getTrackMomentum(iChild).x() - a * dy,
1212 kf.getTrackMomentum(iChild).y() + a * dx,
1213 kf.getTrackMomentum(iChild).z(),
1214 kf.getTrackMomentum(iChild).t());
1215 daughters[iChild]->set4VectorDividingByMomentumScaling(i4Vector);
1216
1217 daughters[iChild]->setVertex(
1218 CLHEPToROOT::getXYZVector(kf.getTrackPosition(iChild)));
1219 daughters[iChild]->setMomentumVertexErrorMatrix(
1220 CLHEPToROOT::getTMatrixFSym(kf.getTrackError(iChild)));
1221 }
1222 }
1223
1224 return true;
1225}
1226
1227
1228void ParticleVertexFitterModule::updateMapOfTrackAndDaughter(unsigned& l, std::vector<std::vector<unsigned>>& pars,
1229 std::vector<unsigned>& parm, std::vector<Particle*>& allparticles, const Particle* daughter)
1230{
1231 std::vector <Particle*> daughters = daughter->getDaughters();
1232 for (unsigned ichild = 0; ichild < daughter->getNDaughters(); ichild++) {
1233 const Particle* child = daughter->getDaughter(ichild);
1234 std::vector<unsigned> pard;
1235 if (child->getNDaughters() > 0) {
1236 updateMapOfTrackAndDaughter(l, pars, pard, allparticles, child);
1237 parm.insert(parm.end(), pard.begin(), pard.end());
1238 pars.push_back(pard);
1239 allparticles.push_back(daughters[ichild]);
1240 } else {
1241 pard.push_back(l);
1242 parm.push_back(l);
1243 pars.push_back(pard);
1244 allparticles.push_back(daughters[ichild]);
1245 l++;
1246 }
1247 }
1248}
1249
1250
1252{
1253 if ((m_decayString.empty() ||
1254 (m_withConstraint == "" && m_fitType != "mass")) && mother->getNDaughters() < 2) return false;
1256 if (m_withConstraint == "ipprofile" || m_withConstraint == "iptube" || m_withConstraint == "mother"
1257 || m_withConstraint == "iptubecut" || m_withConstraint == "btube")
1259
1261 if (m_fitType == "mass") rf.setVertFit(false);
1262
1263 if (m_decayString.empty()) {
1264 rf.addMother(mother);
1265 } else {
1266 std::vector<const Particle*> tracksVertex = m_decaydescriptor.getSelectionParticles(mother);
1267 std::vector<std::string> tracksName = m_decaydescriptor.getSelectionNames();
1268
1269 if (allSelectedDaughters(mother, tracksVertex)) {
1270 for (auto& itrack : tracksVertex) {
1271 if (itrack != mother) rf.addTrack(itrack);
1272 }
1273 rf.setMother(mother);
1274 } else {
1275
1277 bool mothSel = false;
1278 int nTrk = 0;
1279 for (unsigned itrack = 0; itrack < tracksVertex.size(); itrack++) {
1280 if (tracksVertex[itrack] != mother) {
1281 rsf.addTrack(tracksVertex[itrack]);
1282 B2DEBUG(1, "ParticleVertexFitterModule: Adding particle " << tracksName[itrack] << " to vertex fit ");
1283 nTrk++;
1284 }
1285 if (tracksVertex[itrack] == mother) mothSel = true;
1286 }
1287
1288
1289 // Fit one particle constrained to originate from the beam spot
1290 bool mothIPfit = false;
1291 if (tracksVertex.size() == 1 && mothSel == true && m_withConstraint != "" && nTrk == 0) {
1292 rsf.addTrack(tracksVertex[0]);
1293 if (tracksVertex[0] != mother)
1294 B2FATAL("ParticleVertexFitterModule: FATAL Error in IP constrained mother fit");
1295 nTrk++;
1296 mothIPfit = true;
1297 }
1298
1299
1300 ROOT::Math::XYZVector pos;
1301 TMatrixDSym RerrMatrix(3);
1302 int nvert = 0;
1303
1304 // one track fit is not kinematic
1305 if (nTrk == 1) {
1307 for (auto& itrack : tracksVertex) {
1308 rsg.addTrack(itrack);
1309 nvert = rsg.fit("kalman");
1310 if (nvert > 0) {
1311 pos = rsg.getPos(0);
1312 RerrMatrix = rsg.getCov(0);
1313 double prob = rsg.getPValue(0);
1314 ROOT::Math::PxPyPzEVector mom(mother->get4Vector());
1315 TMatrixDSym errMatrix(7);
1316 for (int i = 0; i < 7; i++) {
1317 for (int j = 0; j < 7; j++) {
1318 if (i > 3 && j > 3) {errMatrix[i][j] = RerrMatrix[i - 4][j - 4];}
1319 else {errMatrix[i][j] = 0;}
1320 }
1321 }
1322 if (mothIPfit) {
1323 mother->writeExtraInfo("prodVertX", pos.X());
1324 mother->writeExtraInfo("prodVertY", pos.Y());
1325 mother->writeExtraInfo("prodVertZ", pos.Z());
1326 mother->writeExtraInfo("prodVertSxx", RerrMatrix[0][0]);
1327 mother->writeExtraInfo("prodVertSxy", RerrMatrix[0][1]);
1328 mother->writeExtraInfo("prodVertSxz", RerrMatrix[0][2]);
1329 mother->writeExtraInfo("prodVertSyx", RerrMatrix[1][0]);
1330 mother->writeExtraInfo("prodVertSyy", RerrMatrix[1][1]);
1331 mother->writeExtraInfo("prodVertSyz", RerrMatrix[1][2]);
1332 mother->writeExtraInfo("prodVertSzx", RerrMatrix[2][0]);
1333 mother->writeExtraInfo("prodVertSzy", RerrMatrix[2][1]);
1334 mother->writeExtraInfo("prodVertSzz", RerrMatrix[2][2]);
1335 } else {
1336 mother->updateMomentum(mom, pos, errMatrix, prob);
1337 }
1338 return true;
1339 } else {return false;}
1340 }
1341 } else {
1342 nvert = rsf.fit();
1343 }
1344
1345 if (nvert > 0) {
1346 pos = rsf.getPos();
1347 RerrMatrix = rsf.getVertexErrorMatrix();
1348 double prob = rsf.getPValue();
1349 ROOT::Math::PxPyPzEVector mom(mother->get4Vector());
1350 TMatrixDSym errMatrix(7);
1351 for (int i = 0; i < 7; i++) {
1352 for (int j = 0; j < 7; j++) {
1353 if (i > 3 && j > 3) {errMatrix[i][j] = RerrMatrix[i - 4][j - 4];}
1354 else {errMatrix[i][j] = 0;}
1355 }
1356 }
1357 mother->updateMomentum(mom, pos, errMatrix, prob);
1358 } else {return false;}
1359
1360
1361 if (mothSel && nTrk > 1) {
1363 rf.addMother(mother);
1364 int nKfit = rf.fit();
1365 rf.updateMother();
1367
1368 if (nKfit > 0) {return true;}
1369 else return false;
1370 } else return true;
1371 }
1372 }
1373
1374 bool okFT = false;
1375 if (m_fitType == "vertex") {
1376 okFT = true;
1377 int nVert = rf.fit();
1378 rf.updateMother();
1379 if (m_decayString.empty() && m_updateDaughters == true) rf.updateDaughters();
1380 if (nVert != 1) return false;
1381 }
1382 if (m_fitType == "mass") {
1383 // add protection
1384 okFT = true;
1385 rf.setMassConstFit(true);
1386 rf.setVertFit(false);
1387 int nVert = rf.fit();
1388 rf.updateMother();
1389 if (nVert != 1) return false;
1390 };
1391 if (m_fitType == "massvertex") {
1392 okFT = true;
1393 rf.setMassConstFit(true);
1394 int nVert = rf.fit();
1395 rf.updateMother();
1396 if (m_decayString.empty() && m_updateDaughters == true) rf.updateDaughters();
1397 if (nVert != 1) return false;
1398 };
1399 if (!okFT) {
1400 B2FATAL("fitType : " << m_fitType << " ***invalid fit type ");
1401 }
1402
1403 return true;
1404}
1405
1407 const std::vector<const Particle*>& tracksVertex)
1408{
1409 bool isAll = false;
1410 if (mother->getNDaughters() == 0) return false;
1411
1412 int nNotIncluded = mother->getNDaughters();
1413
1414 for (unsigned i = 0; i < mother->getNDaughters(); i++) {
1415 bool dauOk = false;
1416 for (auto& vi : tracksVertex) {
1417 if (vi == mother->getDaughter(i)) {
1418 nNotIncluded = nNotIncluded - 1;
1419 dauOk = true;
1420 }
1421 }
1422 if (!dauOk) {
1423 if (allSelectedDaughters(mother->getDaughter(i), tracksVertex)) nNotIncluded--;
1424 }
1425 }
1426 if (nNotIncluded == 0) isAll = true;
1427 return isAll;
1428}
1429
1431{
1432 for (unsigned ichild = 0; ichild < particle->getNDaughters(); ichild++) {
1433 const Particle* child = particle->getDaughter(ichild);
1434 if (child->getNDaughters() > 0) addChildofParticletoKFit(kf, child);
1435 else {
1436 if (child->getPValue() < 0) return false; // error matrix not valid
1437
1438 kf.addParticle(child);
1439 }
1440 }
1441 return true;
1442}
1443
1445 std::vector<unsigned>& particleId)
1446{
1447 for (unsigned ichild = 0; ichild < particle->getNDaughters(); ichild++) {
1448 const Particle* child = particle->getDaughter(ichild);
1449 if (child->getNDaughters() > 0) {
1450 bool massconstraint = std::find(m_massConstraintList.begin(), m_massConstraintList.end(),
1451 std::abs(child->getPDGCode())) != m_massConstraintList.end();
1452 std::vector<unsigned> childId;
1453 addChildofParticletoMassKFit(kf, child, childId);
1454 if (massconstraint) kf.addMassConstraint(child->getPDGMass(), childId);
1455 particleId.insert(particleId.end(), childId.begin(), childId.end());
1456 } else {
1457 if (child->getPValue() < 0) return false; // error matrix not valid
1458 kf.addParticle(child);
1459 particleId.push_back(kf.getTrackCount() - 1);
1460 }
1461 }
1462 return true;
1463}
1464
1466{
1467 HepPoint3D pos = ROOTToCLHEP::getPoint3D(m_BeamSpotCenter);
1468 CLHEP::HepSymMatrix covMatrix = ROOTToCLHEP::getHepSymMatrix(m_beamSpotCov);
1469
1470 kv.setIpProfile(pos, covMatrix);
1471}
1472
1474{
1475 CLHEP::HepSymMatrix err(7, 0);
1476
1477 for (int i = 0; i < 3; i++) {
1478 for (int j = 0; j < 3; j++) {
1479 err[i + 4][j + 4] = m_beamSpotCov(i, j);
1480 }
1481 }
1482
1484 ROOT::Math::PxPyPzEVector iptube_mom = T.getBeamFourMomentum();
1485
1487 ROOTToCLHEP::getHepLorentzVector(iptube_mom),
1488 ROOTToCLHEP::getPoint3D(m_BeamSpotCenter),
1489 err,
1490 0.);
1491}
1492
1494{
1496
1497 ROOT::Math::XYZVector boostDir = T.getBoostVector().Unit();
1498
1499 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
1500 beamSpotCov(2, 2) = cut * cut;
1501 double thetab = boostDir.Theta();
1502 double phib = boostDir.Phi();
1503
1504 double stb = TMath::Sin(thetab);
1505 double ctb = TMath::Cos(thetab);
1506 double spb = TMath::Sin(phib);
1507 double cpb = TMath::Cos(phib);
1508
1509
1510 TMatrix rz(3, 3); rz(2, 2) = 1;
1511 rz(0, 0) = cpb; rz(0, 1) = spb;
1512 rz(1, 0) = -1 * spb; rz(1, 1) = cpb;
1513
1514 TMatrix ry(3, 3); ry(1, 1) = 1;
1515 ry(0, 0) = ctb; ry(0, 2) = -1 * stb;
1516 ry(2, 0) = stb; ry(2, 2) = ctb;
1517
1518 TMatrix r(3, 3); r.Mult(rz, ry);
1519 TMatrix rt(3, 3); rt.Transpose(r);
1520
1521 TMatrix TubePart(3, 3); TubePart.Mult(rt, beamSpotCov);
1522 TMatrix Tube(3, 3); Tube.Mult(TubePart, r);
1523
1524 m_beamSpotCov(0, 0) = Tube(0, 0); m_beamSpotCov(0, 1) = Tube(0, 1); m_beamSpotCov(0, 2) = Tube(0, 2);
1525 m_beamSpotCov(1, 0) = Tube(1, 0); m_beamSpotCov(1, 1) = Tube(1, 1); m_beamSpotCov(1, 2) = Tube(1, 2);
1526 m_beamSpotCov(2, 0) = Tube(2, 0); m_beamSpotCov(2, 1) = Tube(2, 1); m_beamSpotCov(2, 2) = Tube(2, 2);
1527}
1528
1530{
1531 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
1532 for (int i = 0; i < 3; i++)
1533 beamSpotCov(i, i) += width * width;
1534
1535 m_beamSpotCov = beamSpotCov;
1536}
1537
1539{
1540 double chi2TrackL = 0;
1541
1542 for (int iTrack = 0; iTrack < kv.getTrackCount(); iTrack++) {
1543
1544 analysis::KFitTrack trk_i = kv.getTrack(iTrack); // KFitTrack contains parameters before/after fit.
1545
1546 TMatrixFSym err = CLHEPToROOT::getTMatrixFSym(trk_i.getError(analysis::KFitConst::kBeforeFit)); // px, py, pz, E, x, y, z
1547
1548 ROOT::Math::XYZVector x_before = CLHEPToROOT::getXYZVector(trk_i.getPosition(analysis::KFitConst::kBeforeFit));
1549 ROOT::Math::XYZVector x_after = CLHEPToROOT::getXYZVector(trk_i.getPosition());
1550 ROOT::Math::XYZVector dPos = x_after - x_before;
1551
1553 ROOT::Math::XYZVector boost3 = T.getBoostVector().Unit();
1554 TVectorD boostD(0, 6, 0., 0., 0., 0., boost3.X(), boost3.Y(), boost3.Z(), "END");
1555
1556 double dLBoost = dPos.Dot(boost3);
1557
1558 chi2TrackL += TMath::Power(dLBoost, 2) / err.Similarity(boostD);
1559 }
1560 return chi2TrackL;
1561}
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
For each MCParticle with hits in the CDC, this class stores some summarising information on those hit...
Definition Btube.h:22
TMatrixFSym getTubeMatrix() const
Returns Btube matrix.
Definition Btube.h:73
Eigen::Matrix< double, 3, 1 > getTubeCenter() const
Returns Btube center.
Definition Btube.h:59
static const ParticleType pi0
neutral pion particle
Definition Const.h:675
static const double speedOfLight
[cm/ns]
Definition Const.h:696
static const ParticleType photon
photon particle
Definition Const.h:674
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
Class to hold Lorentz transformations from/to CMS and boost vector.
ROOT::Math::PxPyPzEVector getBeamFourMomentum() const
Returns LAB four-momentum of e+e-, i.e.
ROOT::Math::XYZVector getBoostVector() const
Returns boost vector (beta=p/E)
TMatrixDSym m_beamSpotCov
Beam spot covariance matrix.
bool makeKMassMother(analysis::MassFitKFit &kv, Particle *p)
Update mother particle after mass fit using KFit.
std::string m_withConstraint
additional constraint on vertex
bool doKMassPointingVertexFit(Particle *p)
Mass-constrained vertex fit with additional pointing constraint using KFit.
void smearBeamSpot(double width)
smear beam spot covariance
bool makeMassKFourCMother(analysis::MassFourCFitKFit &kv, Particle *p)
Update mother particle after MassFourC fit using KFit.
void updateMapOfTrackAndDaughter(unsigned &l, std::vector< std::vector< unsigned > > &pars, std::vector< unsigned > &pard, std::vector< Particle * > &allparticles, const Particle *daughter)
update the map of daughter and tracks, find out which tracks belong to each daughter.
bool doKVertexFit(Particle *p, bool ipProfileConstraint, bool ipTubeConstraint)
Unconstrained vertex fit using KFit.
bool doKMassVertexFit(Particle *p)
Mass-constrained vertex fit using KFit.
virtual void initialize() override
Initialize the Module.
void addIPTubeToKFit(analysis::VertexFitKFit &kv)
Adds IPTube constraint to the vertex fit using KFit.
bool addChildofParticletoMassKFit(analysis::MassFourCFitKFit &kf, const Particle *particle, std::vector< unsigned > &particleId)
Adds given particle's child to the MassFourCFitKFit.
virtual void event() override
Event processor.
bool makeKMassPointingVertexMother(analysis::MassPointingVertexFitKFit &kv, Particle *p)
Update mother particle after mass-constrained vertex fit with additional pointing constraint using KF...
bool m_updateDaughters
flag for daughters update
std::string m_decayString
daughter particles selection
std::vector< int > m_massConstraintList
PDG codes of the particles to be mass constraint (massfourC)
bool m_hasCovMatrix
flag for mother covariance matrix (PseudoFitter)
bool makeKVertexMother(analysis::VertexFitKFit &kv, Particle *p)
Update mother particle after unconstrained vertex fit using KFit.
bool redoTwoPhotonDaughterMassFit(Particle *postFit, const Particle *preFit, const analysis::VertexFitKFit &kv)
Combines preFit particle and vertex information from vertex fit kv to create new postFit particle.
bool makeKMassVertexMother(analysis::MassVertexFitKFit &kv, Particle *p)
Update mother particle after mass-constrained vertex fit using KFit.
bool makeKFourCMother(analysis::FourCFitKFit &kv, Particle *p)
Update mother particle after FourC fit using KFit.
bool fillFitParticles(const Particle *mother, std::vector< const Particle * > &fitChildren, std::vector< const Particle * > &twoPhotonChildren)
Fills valid particle's children (with valid error matrix) in the vector of Particles that will enter ...
bool doKFourCFit(Particle *p)
FourC fit using KFit.
ROOT::Math::XYZVector m_BeamSpotCenter
Beam spot position.
virtual void beginRun() override
Called when entering a new run.
bool doKRecoilMassFit(Particle *p)
RecoilMass fit using KFit.
DBObjPtr< BeamSpot > m_beamSpotDB
Beam spot database object.
bool doVertexFit(Particle *p)
Main steering routine.
std::string m_vertexFitter
Vertex Fitter name.
bool doRaveFit(Particle *mother)
Fit using Rave.
bool makeKRecoilMassMother(analysis::RecoilMassKFit &kf, Particle *p)
Update mother particle after RecoilMass fit using KFit.
bool doKMassFit(Particle *p)
Mass fit using KFit.
double m_recoilMass
recoil mass for constraint
double m_confidenceLevel
required fit confidence level
bool doKMassFourCFit(Particle *p)
MassFourC fit using KFit.
DecayDescriptor m_decaydescriptor
Decay descriptor of decays to look for.
bool fillNotFitParticles(const Particle *mother, std::vector< const Particle * > &notFitChildren, const std::vector< const Particle * > &fitChildren)
Fills valid particle's children (with valid error matrix) in the vector of Particles that will not en...
void findConstraintBoost(double cut)
calculate iptube constraint (quasi cylinder along boost direction) for RAVE fit
double m_Bfield
magnetic field from data base
bool addChildofParticletoKFit(analysis::FourCFitKFit &kv, const Particle *particle)
Adds given particle's child to the FourCFitKFit.
double getChi2TracksLBoost(const analysis::VertexFitKFit &kv)
calculate the chi2 using only lboost information of tracks
double m_smearing
smearing width applied to IP tube
std::string m_fitType
type of the kinematic fit
void addIPProfileToKFit(analysis::VertexFitKFit &kv)
Adds IPProfile constraint to the vertex fit using KFit.
StoreObjPtr< ParticleList > m_plist
particle list
bool allSelectedDaughters(const Particle *mother, const std::vector< const Particle * > &tracksVertex)
check if all the Daughters (o grand-daughters) are selected for the vertex fit
Class to store reconstructed particles.
Definition Particle.h:76
void writeExtraInfo(const std::string &name, const double value)
Sets the user defined extraInfo.
Definition Particle.cc:1393
double getPValue() const
Returns chi^2 probability of fit if done or -1.
Definition Particle.h:687
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition Particle.cc:1351
const V0 * getV0() const
Returns the pointer to the V0 object that was used to create this Particle (if ParticleType == c_V0).
Definition Particle.cc:956
int getPDGCode(void) const
Returns PDG code.
Definition Particle.h:465
int getProperty() const
Returns particle property as a bit pattern The values are defined in the PropertyFlags enum and descr...
Definition Particle.h:518
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition Particle.h:747
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
Definition Particle.cc:635
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
Definition Particle.h:567
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition Particle.cc:1421
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition Particle.h:282
std::vector< Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
Definition Particle.cc:668
void updateMomentum(const ROOT::Math::PxPyPzEVector &p4, const ROOT::Math::XYZVector &vertex, const TMatrixFSym &errMatrix, double pValue)
Sets Lorentz vector, position, 7x7 error matrix and p-value.
Definition Particle.h:397
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
Definition Particle.cc:451
@ c_IsUnspecified
Ordinary particles.
Definition Particle.h:120
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition Particle.cc:662
double getExtraInfo(const std::string &name) const
Return given value if set.
Definition Particle.cc:1374
double getFittedVertexX() const
Get the X coordinate of the fitted vertex.
Definition V0.h:75
double getFittedVertexY() const
Get the Y coordinate of the fitted vertex.
Definition V0.h:78
double getFittedVertexZ() const
Get the Z coordinate of the fitted vertex.
Definition V0.h:81
ROOT::Math::XYZVector getFittedVertexPosition() const
Get the fitted vertex position.
Definition V0.h:84
FourCFitKFit is a derived class from KFitBase to perform 4 momentum-constraint kinematical fit.
enum KFitError::ECode setFourMomentum(const ROOT::Math::PxPyPzEVector &m)
Set an 4 Momentum for the FourC-constraint fit.
double getCHIsq(void) const override
Get a chi-square of the fit.
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
enum KFitError::ECode doFit(void)
Perform a four momentum-constraint fit.
const CLHEP::HepSymMatrix getTrackError(const int id) const
Get an error matrix of the track.
Definition KFitBase.cc:168
const CLHEP::HepLorentzVector getTrackMomentum(const int id) const
Get a Lorentz vector of the track.
Definition KFitBase.cc:154
const HepPoint3D getTrackPosition(const int id) const
Get a position of the track.
Definition KFitBase.cc:161
virtual int getNDF(void) const
Get an NDF of the fit.
Definition KFitBase.cc:114
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
Definition KFitBase.cc:93
const KFitTrack getTrack(const int id) const
Get a specified track object.
Definition KFitBase.cc:175
enum KFitError::ECode addParticle(const Particle *particle)
Add a particle to the fitter.
Definition KFitBase.cc:59
int getTrackCount(void) const
Get the number of added tracks.
Definition KFitBase.cc:107
ECode
ECode is a error code enumerate.
Definition KFitError.h:33
KFitTrack is a container of the track information (Lorentz vector, position, and error matrix),...
Definition KFitTrack.h:38
const CLHEP::HepSymMatrix getError(const int flag=KFitConst::kAfterFit) const
Get an error matrix of the track.
Definition KFitTrack.cc:171
const HepPoint3D getPosition(const int flag=KFitConst::kAfterFit) const
Get a position of the track.
Definition KFitTrack.cc:163
MassFitKFit is a derived class from KFitBase to perform mass-constraint kinematical fit.
Definition MassFitKFit.h:33
enum KFitError::ECode setVertex(const HepPoint3D &v)
Set an initial vertex position for the mass-constraint fit.
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
enum KFitError::ECode doFit(void)
Perform a mass-constraint fit.
enum KFitError::ECode setInvariantMass(const double m)
Set an invariant mass for the mass-constraint fit.
enum KFitError::ECode setVertexError(const CLHEP::HepSymMatrix &e)
Set an initial vertex error matrix for the mass-constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
MassFourCFitKFit is a derived class from KFitBase to perform mass and 4 momentum-constraint kinematic...
enum KFitError::ECode setFourMomentum(const ROOT::Math::PxPyPzEVector &m)
Set an 4 Momentum for the mass-four-constraint fit.
enum KFitError::ECode addMassConstraint(const double m, std::vector< unsigned > &childTrackId)
Set an invariant mass of daughter particle for the mass-four-momentum-constraint fit.
double getCHIsq(void) const override
Get a chi-square of the fit.
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
enum KFitError::ECode doFit(void)
Perform a mass-four-momentum-constraint fit.
MassPointingVertexFitKFit is a derived class from KFitBase It performs a kinematical fit with three c...
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
enum KFitError::ECode doFit(void)
Perform a mass-vertex-pointing constraint fit.
enum KFitError::ECode setInvariantMass(const double m)
Set an invariant mass for the mass-vertex-pointing constraint fit.
enum KFitError::ECode setProductionVertex(const HepPoint3D &v)
Set the production vertex of the particle.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
MassVertexFitKFit is a derived class from KFitBase to perform mass-vertex-constraint kinematical fit.
enum KFitError::ECode setInitialVertex(const HepPoint3D &v)
Set an initial vertex point for the mass-vertex constraint fit.
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
enum KFitError::ECode doFit(void)
Perform a mass-vertex-constraint fit.
enum KFitError::ECode setInvariantMass(const double m)
Set an invariant mass for the mass-vertex constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
The RaveKinematicVertexFitter class is part of the RaveInterface together with RaveSetup.
void addMother(const Particle *aMotherParticlePtr)
All daughters of the argument of this function will be used as input for the vertex fit.
ROOT::Math::XYZVector getPos()
get the position of the fitted vertex.
void addTrack(const Particle *aParticlePtr)
add a track (in the format of a Particle) to set of tracks that should be fitted to a vertex
void setMother(const Particle *aMotherParticlePtr)
Set Mother particle for Vertex/momentum update.
int fit()
do the kinematic vertex fit with all tracks previously added with the addTrack or addMother function.
void setVertFit(bool isVertFit=true)
Set vertex fit: set false in case of mass fit only.
void setMassConstFit(bool isConstFit=true)
Set mass constrained fit.
double getPValue()
get the p value of the fitted vertex.
TMatrixDSym getVertexErrorMatrix()
get the covariance matrix (3x3) of the of the fitted vertex position.
void updateDaughters()
update the Daughters particles
void unsetBeamSpot()
unset beam spot constraint
Definition RaveSetup.cc:83
static void initialize(int verbosity=1, double MagneticField=1.5)
Set everything up so everything needed for vertex fitting is there.
Definition RaveSetup.cc:35
static RaveSetup * getInstance()
get the pointer to the instance to get/set any of options stored in RaveSetup
Definition RaveSetup.h:40
void setBeamSpot(const ROOT::Math::XYZVector &beamSpot, const TMatrixDSym &beamSpotCov)
The beam spot position and covariance is known you can set it here so that and a vertex in the beam s...
Definition RaveSetup.cc:75
void reset()
frees memory allocated by initialize().
Definition RaveSetup.cc:61
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.
ROOT::Math::XYZVector getPos(VecSize vertexId=0) const
get the position of the fitted vertex.
void addTrack(const Particle *const aParticlePtr)
add a track (in the format of a Particle) to set of tracks that should be fitted to a vertex
double getPValue(VecSize vertexId=0) const
get the p value of the fitted vertex.
RecoilMassKFit is a derived class from KFitBase to perform a kinematical fit with a recoil mass const...
enum KFitError::ECode setFourMomentum(const ROOT::Math::PxPyPzEVector &m)
Set a recoil mass .
double getCHIsq(void) const override
Get a chi-square of the fit.
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
enum KFitError::ECode setRecoilMass(const double m)
Set an invariant mass for the four momentum-constraint fit.
enum KFitError::ECode doFit(void)
Perform a recoil-mass constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
VertexFitKFit is a derived class from KFitBase to perform vertex-constraint kinematical fit.
enum KFitError::ECode setIpTubeProfile(const CLHEP::HepLorentzVector &p, const HepPoint3D &x, const CLHEP::HepSymMatrix &e, const double q)
Set a virtual IP-tube track for the vertex constraint fit.
enum KFitError::ECode setInitialVertex(const HepPoint3D &v)
Set an initial vertex point for the vertex-vertex constraint fit.
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
const CLHEP::HepSymMatrix getVertexError(void) const
Get a fitted vertex error matrix.
enum KFitError::ECode doFit(void)
Perform a vertex-constraint fit.
enum KFitError::ECode setIpProfile(const HepPoint3D &ip, const CLHEP::HepSymMatrix &ipe)
Set an IP-ellipsoid shape for the vertex constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
void copyDaughters(Particle *mother)
Function copies all (grand-)^n-daughter particles of the argument mother Particle.
Abstract base class for different kinds of events.
STL namespace.
static const int kBeforeFit
Input parameter to specify before-fit when setting/getting a track attribute.
Definition KFitConst.h:33