Belle II Software development
TagVertexModule.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#include <analysis/modules/TagVertex/TagVertexModule.h>
10
11//to help printing out stuff
12#include<sstream>
13
14// framework aux
15#include <framework/gearbox/Unit.h>
16#include <framework/gearbox/Const.h>
17#include <framework/logging/Logger.h>
18
19// dataobjects
20#include <analysis/dataobjects/RestOfEvent.h>
21#include <analysis/dataobjects/FlavorTaggerInfo.h>
22
23// utilities
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>
31
32// rave
33#include <analysis/VertexFitting/RaveInterface/RaveSetup.h>
34#include <analysis/VertexFitting/RaveInterface/RaveVertexFitter.h>
35
36#include <CLHEP/Geometry/Point3D.h>
37#include <CLHEP/Matrix/SymMatrix.h>
38#include <CLHEP/Vector/LorentzVector.h>
39
40// mdst dataobject
41#include <mdst/dataobjects/HitPatternVXD.h>
42
43// Magnetic field
44#include <framework/geometry/BFieldManager.h>
45
46#include <TVector.h>
47#include <TRotation.h>
48#include <Math/Vector4D.h>
49
50using namespace std;
51using namespace Belle2;
52
54static const double realNaN = std::numeric_limits<double>::quiet_NaN();
55
57static const ROOT::Math::XYZVector vecNaN(realNaN, realNaN, realNaN);
58
60static const double arrayNaN[] = {
61 realNaN, realNaN, realNaN,
62 realNaN, realNaN, realNaN,
63 realNaN, realNaN, realNaN,
64};
65
67static const TMatrixDSym matNaN(3, arrayNaN);
68
69// import tools from RotationTools.h
70using RotationTools::rotateTensor;
71using RotationTools::rotateTensorInv;
72using RotationTools::toSymMatrix;
73using RotationTools::toVec;
74using RotationTools::getUnitOrthogonal;
75
76//-----------------------------------------------------------------
77// Register the Module
78//-----------------------------------------------------------------
80
81//-----------------------------------------------------------------
82// Implementation
83//-----------------------------------------------------------------
84
88 m_FitType(0), m_tagVl(0),
91 m_verbose(true)
92{
93 // Set module properties
94 setDescription("Tag side Vertex Fitter for modular analysis");
96
97 // Parameter definitions
98 addParam("listName", m_listName, "name of particle list", string(""));
99 addParam("confidenceLevel", m_confidenceLevel,
100 "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",
101 0.001);
102 addParam("MCAssociation", m_useMCassociation,
103 "'': no MC association. breco: use standard Breco MC association. internal: use internal MC association", string("breco"));
104 addParam("constraintType", m_constraintType,
105 "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)",
106 string("tube"));
107 addParam("trackFindingType", m_trackFindingType,
108 "Choose how to reconstruct the tracks on the tag side: standard, standard_PXD",
109 string("standard_PXD"));
110 addParam("maskName", m_roeMaskName,
111 "Choose ROE mask to get particles from ", string(RestOfEvent::c_defaultMaskName));
112 addParam("askMCInformation", m_mcInfo,
113 "TRUE when requesting MC Information from the tracks performing the vertex fit", false);
114 addParam("reqPXDHits", m_reqPXDHits,
115 "Minimum number of PXD hits for a track to be used in the vertex fit", 0);
116 addParam("fitAlgorithm", m_fitAlgo,
117 "Fitter used for the tag vertex fit: Rave or KFit", string("KFit"));
118 addParam("kFitReqReducedChi2", m_kFitReqReducedChi2,
119 "The required chi2/ndf to accept the kFit result, if it is higher, iteration procedure is applied", 5.0);
120 addParam("useTruthInFit", m_useTruthInFit,
121 "Use the true track parameters in the vertex fit", false);
122 addParam("useRollBack", m_useRollBack,
123 "Use rolled back non-primary tracks", false);
124}
125
127{
128 // magnetic field
130 // RAVE setup
132 B2INFO("TagVertexModule : magnetic field = " << m_Bfield);
133 // truth fit status will be set to 2 only if the MC info cannot be recovered
135 // roll back status will be set to 2 only if the MC info cannot be recovered
137
138 //input
140 m_plist.isRequired(m_listName);
141 // output
142 m_verArray.registerInDataStore();
144 //check if the fitting algorithm name is set correctly
145 if (m_fitAlgo != "Rave" && m_fitAlgo != "KFit")
146 B2FATAL("TagVertexModule: invalid fitting algorithm (must be set to either Rave or KFit).");
148 B2FATAL("TagVertexModule: invalid fitting option (useRollBack and useTruthInFit cannot be simultaneously set to true).");
149 //temporary while the one track fit is broken
150 if (m_trackFindingType == "singleTrack" || m_trackFindingType == "singleTrack_PXD")
151 B2FATAL("TagVertexModule : the singleTrack option is temporarily broken.");
152}
153
155{
156 //TODO: set magnetic field for each run
157 //m_Bfield = BFieldMap::Instance().getBField(m_BeamSpotCenter).Z();
158}
159
161{
162 if (!m_plist) {
163 B2ERROR("TagVertexModule: ParticleList " << m_listName << " not found");
164 return;
165 }
166
167 // output
169
170 std::vector<unsigned int> toRemove;
171
172 for (unsigned i = 0; i < m_plist->getListSize(); ++i) {
174
175 Particle* particle = m_plist->getParticle(i);
176 if (m_useMCassociation == "breco" || m_useMCassociation == "internal") BtagMCVertex(particle);
177 bool ok = doVertexFit(particle);
178 if (ok) deltaT(particle);
179
182 toRemove.push_back(particle->getArrayIndex());
183 } else {
184 // save information in the Vertex StoreArray
185 TagVertex* ver = m_verArray.appendNew();
186 // create relation: Particle <-> Vertex
187 particle->addRelationTo(ver);
188 // fill Vertex with content
189 if (ok) {
190 ver->setTagVertex(m_tagV);
193 ver->setDeltaT(m_deltaT);
199 ver->setFitType(m_FitType);
200 ver->setNTracks(m_tagParticles.size());
201 ver->setTagVl(m_tagVl);
204 ver->setTagVol(m_tagVol);
207 ver->setTagVNDF(m_tagVNDF);
218 } else {
219 ver->setTagVertex(m_tagV);
220 ver->setTagVertexPval(-1.);
221 ver->setDeltaT(m_deltaT);
224 ver->setMCTagBFlavor(0.);
227 ver->setFitType(m_FitType);
228 ver->setNTracks(m_tagParticles.size());
229 ver->setTagVl(m_tagVl);
232 ver->setTagVol(m_tagVol);
235 ver->setTagVNDF(-1111.);
236 ver->setTagVChi2(-1111.);
237 ver->setTagVChi2IP(-1111.);
246 }
247 }
248 }
249 m_plist->removeParticles(toRemove);
250
251 //free memory allocated by rave. initialize() would be enough, except that we must clean things up before program end...
252 //
254}
255
257{
258 //reset the fit truth status in case it was set to 2 in a previous fit
259
261
262 //reset the roll back status in case it was set to 2 in a previous fit
263
265
266 //set constraint type, reset pVal and B field
267
268 m_fitPval = 1;
269
270 if (!(Breco->getRelatedTo<RestOfEvent>())) {
271 m_FitType = -1;
272 return false;
273 }
274
275 if (m_Bfield == 0) {
276 B2ERROR("TagVertex: No magnetic field");
277 return false;
278 }
279
280 // recover beam spot info
281
282 m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
283 m_BeamSpotCov.ResizeTo(3, 3);
284 m_BeamSpotCov = m_beamSpotDB->getCovVertex();
285
286 //make the beam spot bigger for the standard constraint
287
288 double beta = PCmsLabTransform().getBoostVector().R();
289 double bg = beta / sqrt(1 - beta * beta);
290
291 //TODO: What's the origin of these numbers?
292 double tauB = 1.519; //B0 lifetime in ps
293 double c = Const::speedOfLight / 1000.; // cm ps-1
294 double lB0 = tauB * bg * c;
295
296 //tube length here set to 20 * 2 * c tau beta gamma ~= 0.5 cm, should be enough to not bias the decay
297 //time but should still help getting rid of some pions from kshorts
298 m_constraintCov.ResizeTo(3, 3);
300 else if (m_constraintType == "tube") tie(m_constraintCenter, m_constraintCov) = findConstraintBTube(Breco, 200 * lB0);
301 else if (m_constraintType == "boost") tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(200 * lB0);
302 else if (m_constraintType == "breco") tie(m_constraintCenter, m_constraintCov) = findConstraint(Breco, 200 * lB0);
303 else if (m_constraintType == "noConstraint") m_constraintCenter = ROOT::Math::XYZVector(); //zero vector
304 else {
305 B2ERROR("TagVertex: Invalid constraintType selected");
306 return false;
307 }
308
309 if (m_constraintCenter == vecNaN) {
310 B2ERROR("TagVertex: No correct fit constraint");
311 return false;
312 }
313
314 /* Depending on the user's choice, one of the possible algorithms is chosen for the fit. In case the algorithm does not converge, in order to assure
315 high efficiency, the next algorithm less restrictive is used. I.e, if standard_PXD does not work, the program tries with standard.
316 */
317
318 m_FitType = 0;
319 double minPVal = (m_fitAlgo != "KFit") ? 0.001 : 0.;
320 bool ok = false;
321
322 if (m_trackFindingType == "standard_PXD") {
324 if (m_tagParticles.size() > 0) {
325 ok = makeGeneralFit();
326 m_FitType = 3;
327 }
328 }
329
330 if (ok == false || m_fitPval < minPVal || m_trackFindingType == "standard") {
332 ok = m_tagParticles.size() > 0;
333 if (ok) {
334 ok = makeGeneralFit();
335 m_FitType = 4;
336 }
337 }
338
339 if ((ok == false || (m_fitPval <= 0. && m_fitAlgo == "Rave")) && m_constraintType != "noConstraint") {
341 ok = (m_constraintCenter != vecNaN);
342 if (ok) {
344 ok = (m_tagParticles.size() > 0);
345 }
346 if (ok) {
347 ok = makeGeneralFit();
348 m_FitType = 5;
349 }
350 }
351
352 return ok;
353}
354
355pair<ROOT::Math::XYZVector, TMatrixDSym> TagVertexModule::findConstraint(const Particle* Breco, double cut) const
356{
357 if (Breco->getPValue() < 0.) return make_pair(vecNaN, matNaN);
358
359 TMatrixDSym beamSpotCov(3);
360 beamSpotCov = m_beamSpotDB->getCovVertex();
361
363
364 double pmag = Breco->getMomentumMagnitude();
365 double xmag = (Breco->getVertex() - m_BeamSpotCenter).R();
366
367
368 TMatrixDSym TerrMatrix = Breco->getMomentumVertexErrorMatrix();
369 TMatrixDSym PerrMatrix(7);
370
371 for (int i = 0; i < 3; ++i) {
372 for (int j = 0; j < 3; ++j) {
373 if (i == j) {
374 PerrMatrix(i, j) = (beamSpotCov(i, j) + TerrMatrix(i, j)) * pmag / xmag;
375 } else {
376 PerrMatrix(i, j) = TerrMatrix(i, j);
377 }
378 PerrMatrix(i + 4, j + 4) = TerrMatrix(i + 4, j + 4);
379 }
380 }
381
382 PerrMatrix(3, 3) = 0.;
383
384 //Copy Breco, but use errors as are in PerrMatrix
385 Particle* Breco2 = ParticleCopy::copyParticle(Breco);
386 Breco2->setMomentumVertexErrorMatrix(PerrMatrix);
387
388
389 const Particle* BRecoRes = doVertexFitForBTube(Breco2, "kalman");
390 if (BRecoRes->getPValue() < 0) return make_pair(vecNaN, matNaN); //problems
391
392 // Overall error matrix
393 TMatrixDSym errFinal = TMatrixDSym(Breco->getVertexErrorMatrix() + BRecoRes->getVertexErrorMatrix());
394
395 // TODO : to be developed the extraction of the momentum from the rave fitted track
396
397 // Get expected pBtag 4-momentum using transverse-momentum conservation
398 ROOT::Math::XYZVector BvertDiff = pmag * (Breco->getVertex() - BRecoRes->getVertex()).Unit();
399 ROOT::Math::PxPyPzMVector pBrecEstimate(BvertDiff.X(), BvertDiff.Y(), BvertDiff.Z(), Breco->getPDGMass());
400 ROOT::Math::PxPyPzMVector pBtagEstimate = PCmsLabTransform::labToCms(pBrecEstimate);
401 pBtagEstimate.SetPxPyPzE(-pBtagEstimate.px(), -pBtagEstimate.py(), -pBtagEstimate.pz(), pBtagEstimate.E());
402 pBtagEstimate = PCmsLabTransform::cmsToLab(pBtagEstimate);
403
404 // rotate err-matrix such that pBrecEstimate goes to eZ
405 TMatrixD TubeZ = rotateTensorInv(pBrecEstimate.Vect(), errFinal);
406
407 TubeZ(2, 2) = cut * cut;
408 TubeZ(2, 0) = 0; TubeZ(0, 2) = 0;
409 TubeZ(2, 1) = 0; TubeZ(1, 2) = 0;
410
411
412 // rotate err-matrix such that eZ goes to pBtagEstimate
413 TMatrixD Tube = rotateTensor(pBtagEstimate.Vect(), TubeZ);
414
415 // Standard algorithm needs no shift
416 return make_pair(m_BeamSpotCenter, toSymMatrix(Tube));
417}
418
419pair<ROOT::Math::XYZVector, TMatrixDSym> TagVertexModule::findConstraintBTube(const Particle* Breco, double cut)
420{
421 //Use Breco as the creator of the B tube.
422 if ((Breco->getVertexErrorMatrix()(2, 2)) == 0.0) {
423 B2WARNING("In TagVertexModule::findConstraintBTube: cannot get a proper vertex for BReco. BTube constraint replaced by Boost.");
424 return findConstraintBoost(cut);
425 }
426
427
428 //vertex fit will give the intersection between the beam spot and the trajectory of the B
429 //(base of the BTube, or primary vtx cov matrix)
430 const Particle* tubecreatorBCopy = doVertexFitForBTube(Breco, "avf");
431 if (tubecreatorBCopy->getPValue() < 0) return make_pair(vecNaN, matNaN); //if problems
432
433
434 //get direction of B tag = opposite direction of B rec in CMF
435 ROOT::Math::PxPyPzEVector pBrec = tubecreatorBCopy->get4Vector();
436
437 //if we want the true info, replace the 4vector by the true one
438 if (m_useTruthInFit) {
439 const MCParticle* mcBr = Breco->getRelated<MCParticle>();
440 if (mcBr)
441 pBrec = mcBr->get4Vector();
442 else
444 }
445 ROOT::Math::PxPyPzEVector pBtag = PCmsLabTransform::labToCms(pBrec);
446 pBtag.SetPxPyPzE(-pBtag.px(), -pBtag.py(), -pBtag.pz(), pBtag.E());
447 pBtag = PCmsLabTransform::cmsToLab(pBtag);
448
449 //To create the B tube, strategy is: take the primary vtx cov matrix, and add to it a cov
450 //matrix corresponding to an very big error in the direction of the B tag
451 TMatrixDSym pv = tubecreatorBCopy->getVertexErrorMatrix();
452
453 //print some stuff if wanted
454 if (m_verbose) {
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(float(1. / Breco->getP()) * Breco->getMomentum()));
458 B2DEBUG(10, "Brec direction after fit: " << printVector(float(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()));
464 }
465
466 //make a long error matrix along BTag direction
467 TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
468
469
470 // make rotation matrix from z axis to BTag line of flight
471 TMatrixD longerrorRotated = rotateTensor(pBtag.Vect(), longerror);
472
473 //pvNew will correspond to the covariance matrix of the B tube
474 TMatrixD pvNew = TMatrixD(pv) + longerrorRotated;
475
476 //set the constraint
477 ROOT::Math::XYZVector constraintCenter = tubecreatorBCopy->getVertex();
478
479 //if we want the true info, set the centre of the constraint to the primary vertex
480 if (m_useTruthInFit) {
481 const MCParticle* mcBr = Breco->getRelated<MCParticle>();
482 if (mcBr) {
483 constraintCenter = mcBr->getProductionVertex();
484 }
485 }
486
487 if (m_verbose) {
488 B2DEBUG(10, "IPTube covariance: " << printMatrix(pvNew));
489 }
490
491 //The following is done to do the BTube constraint with a virtual track
492 //(ie KFit way)
493
494 m_tagMomentum = pBtag;
495
496 m_pvCov.ResizeTo(pv);
497 m_pvCov = pv;
498
499 return make_pair(constraintCenter, toSymMatrix(pvNew));
500}
501
502pair<ROOT::Math::XYZVector, TMatrixDSym> TagVertexModule::findConstraintBoost(double cut) const
503{
504 double d = 20e-4; //average transverse distance flown by B0
505
506 //make a long error matrix along boost direction
507 TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
508 longerror(0, 0) = longerror(1, 1) = d * d;
509
510 ROOT::Math::XYZVector boostDir = PCmsLabTransform().getBoostVector().Unit();
511
512 TMatrixD longerrorRotated = rotateTensor(boostDir, longerror);
513
514 //Extend error of BeamSpotCov matrix in the boost direction
515 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
516 TMatrixD Tube = TMatrixD(beamSpotCov) + longerrorRotated;
517
518 // Standard algorithm needs no shift
519 ROOT::Math::XYZVector constraintCenter = m_BeamSpotCenter;
520
521 return make_pair(constraintCenter, toSymMatrix(Tube));
522}
523
525static double getProperLifeTime(const MCParticle* mc)
526{
527 double beta = mc->getMomentum().R() / mc->getEnergy();
528 return 1e3 * mc->getLifetime() * sqrt(1 - pow(beta, 2));
529}
530
532{
533 //fill vector with mcB (intended order: Reco, Tag)
534 vector<const MCParticle*> mcBs;
535 for (const MCParticle& mc : m_mcParticles) {
536 if (abs(mc.getPDG()) == abs(Breco->getPDGCode()))
537 mcBs.push_back(&mc);
538 }
539 //too few Bs
540 if (mcBs.size() < 2) return;
541
542 if (mcBs.size() > 2) {
543 B2WARNING("TagVertexModule:: Too many Bs found in MC");
544 }
545
546 auto isReco = [&](const MCParticle * mc) {
547 return (m_useMCassociation == "breco") ? (mc == Breco->getRelated<MCParticle>())
548 : compBrecoBgen(Breco, mc); //internal association
549 };
550
551 //nothing matched?
552 if (!isReco(mcBs[0]) && !isReco(mcBs[1])) {
553 return;
554 }
555
556 //first is Tag, second Reco -> swap the order
557 if (!isReco(mcBs[0]) && isReco(mcBs[1]))
558 swap(mcBs[0], mcBs[1]);
559
560 //both matched -> use closest vertex dist as Reco
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();
564 if (dist0 > dist1)
565 swap(mcBs[0], mcBs[1]);
566 }
567
568 m_mcVertReco = mcBs[0]->getDecayVertex();
569 m_mcLifeTimeReco = getProperLifeTime(mcBs[0]);
570 m_mcTagV = mcBs[1]->getDecayVertex();
571 m_mcTagLifeTime = getProperLifeTime(mcBs[1]);
572 m_mcPDG = mcBs[1]->getPDG();
573}
574
575// static
577{
578
579 bool isDecMode = true;
580
581 const std::vector<Particle*> recDau = Breco->getDaughters();
582 const std::vector<MCParticle*> genDau = Bgen->getDaughters();
583
584 if (recDau.size() > 0 && genDau.size() > 0) {
585 for (auto dauRec : recDau) {
586 bool isDau = false;
587 for (auto dauGen : genDau) {
588 if (dauGen->getPDG() == dauRec->getPDGCode())
589 isDau = compBrecoBgen(dauRec, dauGen) ;
590 }
591 if (!isDau) isDecMode = false;
592 }
593 } else {
594 if (recDau.size() == 0) { //&& genDau.size()==0){
595 if (Bgen->getPDG() != Breco->getPDGCode()) isDecMode = false;;
596 } else {isDecMode = false;}
597 }
598
599 return isDecMode;
600}
601
602// STANDARD FIT ALGORITHM
603/* This algorithm basically takes all the tracks coming from the Rest Of Events and send them to perform a multi-track fit
604 The option to request PXD hits for the tracks can be chosen by the user.
605 */
606std::vector<const Particle*> TagVertexModule::getTagTracks_standardAlgorithm(const Particle* Breco, int reqPXDHits) const
607{
608 std::vector<const Particle*> fitParticles;
609 const RestOfEvent* roe = Breco->getRelatedTo<RestOfEvent>();
610 if (!roe) return fitParticles;
611 //load all particles from the ROE
612 std::vector<const Particle*> ROEParticles = roe->getChargedParticles(m_roeMaskName, 0, false);
613 if (ROEParticles.size() == 0) return fitParticles;
614
615 for (auto& ROEParticle : ROEParticles) {
616 HitPatternVXD roeTrackPattern = ROEParticle->getTrackFitResult()->getHitPatternVXD();
617
618 if (roeTrackPattern.getNPXDHits() >= reqPXDHits) {
619 fitParticles.push_back(ROEParticle);
620 }
621 }
622 return fitParticles;
623}
624
625
626vector<ParticleAndWeight> TagVertexModule::getParticlesAndWeights(const vector<const Particle*>& tagParticles) const
627{
628 vector<ParticleAndWeight> particleAndWeights;
629
630 for (const Particle* particle : tagParticles) {
631 ROOT::Math::PxPyPzEVector mom = particle->get4Vector();
632 if (!isfinite(mom.mag2())) continue;
633
634 ParticleAndWeight particleAndWeight;
635 particleAndWeight.mcParticle = 0;
636 particleAndWeight.weight = -1111.;
637 particleAndWeight.particle = particle;
638
639 if (m_useMCassociation == "breco" || m_useMCassociation == "internal")
640 particleAndWeight.mcParticle = particle->getRelatedTo<MCParticle>();
641
642 particleAndWeights.push_back(particleAndWeight);
643 }
644
645 return particleAndWeights;
646}
647
649{
650 if (m_fitAlgo == "Rave") return makeGeneralFitRave();
651 else if (m_fitAlgo == "KFit") return makeGeneralFitKFit();
652 return false;
653}
654
655void TagVertexModule::fillParticles(vector<ParticleAndWeight>& particleAndWeights)
656{
657 unsigned n = particleAndWeights.size();
658 sort(particleAndWeights.begin(), particleAndWeights.end(),
659 [](const ParticleAndWeight & a, const ParticleAndWeight & b) { return a.weight > b.weight; });
660
661 m_raveParticles.resize(n);
662 m_raveWeights.resize(n);
663 m_raveMCParticles.resize(n);
664
665 for (unsigned i = 0; i < n; ++i) {
666 m_raveParticles.at(i) = particleAndWeights.at(i).particle;
667 m_raveMCParticles.at(i) = particleAndWeights.at(i).mcParticle;
668 m_raveWeights.at(i) = particleAndWeights.at(i).weight;
669 }
670}
671
672void TagVertexModule::fillTagVinfo(const ROOT::Math::XYZVector& tagVpos, const TMatrixDSym& tagVposErr)
673{
674 m_tagV = tagVpos;
675
676 if (m_constraintType != "noConstraint") {
677 TMatrixDSym tubeInv = m_constraintCov;
678 tubeInv.Invert();
679 TVectorD dV = toVec(m_tagV - m_BeamSpotCenter);
680 m_tagVChi2IP = tubeInv.Similarity(dV);
681 }
682
683 m_tagVErrMatrix.ResizeTo(tagVposErr);
684 m_tagVErrMatrix = tagVposErr;
685}
686
688{
689 // apply constraint
691 if (m_constraintType != "noConstraint")
694
695 //feed rave with tracks without Kshorts
696 vector<ParticleAndWeight> particleAndWeights = getParticlesAndWeights(m_tagParticles);
697
698 for (const auto& pw : particleAndWeights) {
699 try {
700 if (m_useTruthInFit) {
701 if (pw.mcParticle) {
703 rFit.addTrack(&tfr);
704 } else
706 } else if (m_useRollBack) {
707 if (pw.mcParticle) {
709 rFit.addTrack(&tfr);
710 } else
712 } else {
713 rFit.addTrack(pw.particle->getTrackFitResult());
714 }
715 } catch (const rave::CheckedFloatException&) {
716 B2ERROR("Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
717 }
718 }
719
720 //perform fit
721
722 int isGoodFit(-1);
723
724 try {
725 isGoodFit = rFit.fit("avf");
726 // if problems
727 if (isGoodFit < 1) return false;
728 } catch (const rave::CheckedFloatException&) {
729 B2ERROR("Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
730 return false;
731 }
732
733 //save the track info for later use
734
735 for (unsigned int i(0); i < particleAndWeights.size() && isGoodFit >= 1; ++i)
736 particleAndWeights.at(i).weight = rFit.getWeight(i);
737
738 //Tracks are sorted from highest rave weight to lowest
739
740 fillParticles(particleAndWeights);
741
742 //if the fit is good, save the infos related to the vertex
743 fillTagVinfo(ROOT::Math::XYZVector(rFit.getPos(0)), rFit.getCov(0));
744
745 //fill quality variables
746 m_tagVNDF = rFit.getNdf(0);
747 m_tagVChi2 = rFit.getChi2(0);
748 m_fitPval = rFit.getPValue();
749
750 return true;
751}
752
753
754analysis::VertexFitKFit TagVertexModule::doSingleKfit(vector<ParticleAndWeight>& particleAndWeights)
755{
756 //initialize KFit
758 kFit.setMagneticField(m_Bfield);
759
760 // apply constraint
761 if (m_constraintType != "noConstraint") {
762 if (m_constraintType == "tube") {
763 CLHEP::HepSymMatrix err(7, 0);
764 //copy m_pvCov to the end of err matrix
765 err.sub(5, ROOTToCLHEP::getHepSymMatrix(m_pvCov));
766 kFit.setIpTubeProfile(
767 ROOTToCLHEP::getHepLorentzVector(m_tagMomentum),
768 ROOTToCLHEP::getPoint3D(m_constraintCenter),
769 err,
770 0.);
771 } else {
772 kFit.setIpProfile(ROOTToCLHEP::getPoint3D(m_constraintCenter),
773 ROOTToCLHEP::getHepSymMatrix(m_constraintCov));
774 }
775 }
776
777
778 for (auto& pawi : particleAndWeights) {
779 int addedOK = 1;
780 if (m_useTruthInFit) {
781 if (pawi.mcParticle) {
782 addedOK = kFit.addTrack(
783 ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
784 ROOTToCLHEP::getPoint3D(getTruePoca(pawi)),
785 ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
786 pawi.particle->getCharge());
787 } else {
789 }
790 } else if (m_useRollBack) {
791 if (pawi.mcParticle) {
792 addedOK = kFit.addTrack(
793 ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
794 ROOTToCLHEP::getPoint3D(getRollBackPoca(pawi)),
795 ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
796 pawi.particle->getCharge());
797 } else {
799 }
800 } else {
801 addedOK = kFit.addParticle(pawi.particle);
802 }
803
804 if (addedOK == 0) {
805 pawi.weight = 1.;
806 } else {
807 B2WARNING("TagVertexModule::makeGeneralFitKFit: failed to add a track");
808 pawi.weight = 0.;
809 }
810 }
811
812
813 int nTracksAdded = kFit.getTrackCount();
814
815 //perform fit if there are enough tracks
816 if ((nTracksAdded < 2 && m_constraintType == "noConstraint") || nTracksAdded < 1)
818
819 int isGoodFit = kFit.doFit();
820 if (isGoodFit != 0) return analysis::VertexFitKFit();
821
822 return kFit;
823}
824
825
826static int getLargestChi2ID(const analysis::VertexFitKFit& kFit)
827{
828 int largest_chi2_trackid = -1;
829 double largest_track_chi2 = -1;
830 for (int i = 0; i < kFit.getTrackCount(); ++i) {
831 double track_chi2 = kFit.getTrackCHIsq(i);
832 if (track_chi2 > largest_track_chi2) {
833 largest_track_chi2 = track_chi2;
834 largest_chi2_trackid = i;
835 }
836 }
837 return largest_chi2_trackid;
838}
839
840
841
842//uses m_tagMomentum, m_constraintCenter, m_constraintCov, m_tagParticles
844{
845 //feed KFit with tracks without Kshorts
846 vector<ParticleAndWeight> particleAndWeights = getParticlesAndWeights(m_tagParticles);
847
849
850
851 // iterative procedure which removes tracks with high chi2
852 for (int iteration_counter = 0; iteration_counter < 100; ++iteration_counter) {
853 analysis::VertexFitKFit kFitTemp = doSingleKfit(particleAndWeights);
854 if (!kFitTemp.isFitted() || isnan(kFitTemp.getCHIsq()))
855 return false;
856
857 double reduced_chi2 = kFitTemp.getCHIsq() / kFitTemp.getNDF();
858 int nTracks = kFitTemp.getTrackCount();
859
860 if (nTracks != int(particleAndWeights.size()))
861 B2ERROR("TagVertexModule: Different number of tracks in kFit and particles");
862
863 if (reduced_chi2 <= m_kFitReqReducedChi2 || nTracks <= 1 || (nTracks <= 2 && m_constraintType == "noConstraint")) {
864 kFit = kFitTemp;
865 break;
866 } else { // remove particle with highest chi2/ndf and continue
867 int badTrackID = getLargestChi2ID(kFitTemp);
868 if (0 <= badTrackID && badTrackID < int(particleAndWeights.size()))
869 particleAndWeights.erase(particleAndWeights.begin() + badTrackID);
870 else
871 B2ERROR("TagVertexModule: Obtained badTrackID is not within limits");
872 }
873
874 }
875
876 //save the track info for later use
877 //Tracks are sorted by weight, i.e. pushing the tracks with 0 weight (from KS) to the end of the list
878 fillParticles(particleAndWeights);
879
880 //Save the infos related to the vertex
881 fillTagVinfo(CLHEPToROOT::getXYZVector(kFit.getVertex()),
882 CLHEPToROOT::getTMatrixDSym(kFit.getVertexError()));
883
884 m_tagVNDF = kFit.getNDF();
885 m_tagVChi2 = kFit.getCHIsq();
886 m_fitPval = TMath::Prob(m_tagVChi2, m_tagVNDF);
887
888 return true;
889}
890
892{
893
894 ROOT::Math::XYZVector boost = PCmsLabTransform().getBoostVector();
895 ROOT::Math::XYZVector boostDir = boost.Unit();
896 double bg = boost.R() / sqrt(1 - boost.Mag2());
897 double c = Const::speedOfLight / 1000.; // cm ps-1
898
899 //Reconstructed DeltaL & DeltaT in the boost direction
900 ROOT::Math::XYZVector dVert = Breco->getVertex() - m_tagV; //reconstructed vtxReco - vtxTag
901 double dl = dVert.Dot(boostDir);
902 m_deltaT = dl / (bg * c);
903
904 //Truth DeltaL & approx DeltaT in the boost direction
905 ROOT::Math::XYZVector MCdVert = m_mcVertReco - m_mcTagV; //truth vtxReco - vtxTag
906 double MCdl = MCdVert.Dot(boostDir);
907 m_mcDeltaT = MCdl / (bg * c);
908
909 // MCdeltaTau=tauRec-tauTag
911 if (m_mcLifeTimeReco == -1 || m_mcTagLifeTime == -1)
913
914 TVectorD bVec = toVec(boostDir);
915
916 //TagVertex error in boost dir
917 m_tagVlErr = sqrt(m_tagVErrMatrix.Similarity(bVec));
918
919 //bReco error in boost dir
920 double bRecoErrL = sqrt(Breco->getVertexErrorMatrix().Similarity(bVec));
921
922 //Delta t error
923 m_deltaTErr = hypot(m_tagVlErr, bRecoErrL) / (bg * c);
924
925 m_tagVl = m_tagV.Dot(boostDir);
926 m_truthTagVl = m_mcTagV.Dot(boostDir);
927
928 // calculate tagV component and error in the direction orthogonal to the boost
929 ROOT::Math::XYZVector oboost = getUnitOrthogonal(boostDir);
930 TVectorD oVec = toVec(oboost);
931
932 //TagVertex error in boost-orthogonal dir
933 m_tagVolErr = sqrt(m_tagVErrMatrix.Similarity(oVec));
934
935 m_tagVol = m_tagV.Dot(oboost);
936 m_truthTagVol = m_mcTagV.Dot(oboost);
937}
938
939Particle* TagVertexModule::doVertexFitForBTube(const Particle* motherIn, std::string fitType) const
940{
941 //make a copy of motherIn to not modify the original object
942 Particle* mother = ParticleCopy::copyParticle(motherIn);
943
944 //Here rave is used to find the upsilon(4S) vtx as the intersection
945 //between the mother B trajectory and the beam spot
947
949 rsg.addTrack(mother);
950 int nvert = rsg.fit(fitType);
951 if (nvert != 1) {
952 mother->setPValue(-1); //error
953 return mother;
954 } else {
955 rsg.updateDaughters();
956 return mother;
957 }
958}
959
960
961
963{
964 if (!paw.mcParticle) {
965 B2ERROR("In TagVertexModule::getTrackWithTrueCoordinate: no MC particle set");
966 return TrackFitResult();
967 }
968
969 const TrackFitResult* tfr(paw.particle->getTrackFitResult());
970
971 return TrackFitResult(getTruePoca(paw),
972 paw.mcParticle->getMomentum(),
973 tfr->getCovariance6(),
974 tfr->getChargeSign(),
975 tfr->getParticleType(),
976 tfr->getPValue(),
977 m_Bfield, 0, 0, tfr->getNDF());
978}
979
980// static
981ROOT::Math::XYZVector TagVertexModule::getTruePoca(ParticleAndWeight const& paw)
982{
983 if (!paw.mcParticle) {
984 B2ERROR("In TagVertexModule::getTruePoca: no MC particle set");
985 return ROOT::Math::XYZVector(0., 0., 0.);
986 }
987
989 paw.mcParticle->getMomentum(),
991}
992
994{
995 const TrackFitResult* tfr(paw.particle->getTrackFitResult());
996
998 tfr->getMomentum(),
999 tfr->getCovariance6(),
1000 tfr->getChargeSign(),
1001 tfr->getParticleType(),
1002 tfr->getPValue(),
1003 m_Bfield, 0, 0, tfr->getNDF());
1004}
1005
1007{
1008 if (!paw.mcParticle) {
1009 B2ERROR("In TagVertexModule::getTruePoca: no MC particle set");
1010 return ROOT::Math::XYZVector(0., 0., 0.);
1011 }
1012
1014}
1015
1017{
1018 m_raveParticles.resize(0);
1019 m_raveMCParticles.resize(0);
1020 m_tagParticles.resize(0);
1021 m_raveWeights.resize(0);
1022
1024 m_tagV = vecNaN;
1025 m_tagVErrMatrix.ResizeTo(matNaN);
1026 m_tagVErrMatrix = matNaN;
1027 m_mcTagV = vecNaN;
1028 m_mcVertReco = vecNaN;
1029 m_deltaT = realNaN;
1032 m_constraintCov.ResizeTo(matNaN);
1033 m_constraintCov = matNaN;
1034 m_constraintCenter = vecNaN;
1035 m_tagVl = realNaN;
1038 m_tagVol = realNaN;
1044 m_pvCov.ResizeTo(matNaN);
1045 m_pvCov = matNaN;
1046 m_tagMomentum = ROOT::Math::PxPyPzEVector(realNaN, realNaN, realNaN, realNaN);
1047}
1048
1049//The following functions are just here to help printing stuff
1050
1051// static
1052std::string TagVertexModule::printVector(const ROOT::Math::XYZVector& vec)
1053{
1054 std::ostringstream oss;
1055 int w = 14;
1056 oss << "(" << std::setw(w) << vec.X() << ", " << std::setw(w) << vec.Y() << ", " << std::setw(w) << vec.Z() << ")" << std::endl;
1057 return oss.str();
1058}
1059
1060// static
1061std::string TagVertexModule::printMatrix(const TMatrixD& mat)
1062{
1063 std::ostringstream oss;
1064 int w = 14;
1065 for (int i = 0; i < mat.GetNrows(); ++i) {
1066 for (int j = 0; j < mat.GetNcols(); ++j) {
1067 oss << std::setw(w) << mat(i, j) << " ";
1068 }
1069 oss << endl;
1070 }
1071 return oss.str();
1072}
1073
1074// static
1075std::string TagVertexModule::printMatrix(const TMatrixDSym& mat)
1076{
1077 std::ostringstream oss;
1078 int w = 14;
1079 for (int i = 0; i < mat.GetNrows(); ++i) {
1080 for (int j = 0; j < mat.GetNcols(); ++j) {
1081 oss << std::setw(w) << mat(i, j) << " ";
1082 }
1083 oss << endl;
1084 }
1085 return oss.str();
1086}
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
static const double speedOfLight
[cm/ns]
Definition Const.h:695
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.
Definition MCParticle.h:32
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
Definition MCParticle.cc:52
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
Definition MCParticle.h:178
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
Definition MCParticle.h:196
int getPDG() const
Return PDG code of particle.
Definition MCParticle.h:101
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition MCParticle.h:187
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.
static ROOT::Math::PxPyPzMVector labToCms(const ROOT::Math::PxPyPzMVector &vec)
Transforms Lorentz vector into CM System.
static ROOT::Math::PxPyPzMVector cmsToLab(const ROOT::Math::PxPyPzMVector &vec)
Transforms Lorentz vector into Laboratory System.
ROOT::Math::XYZVector getBoostVector() const
Returns boost vector (beta=p/E)
Class to store reconstructed particles.
Definition Particle.h:76
TMatrixFSym getVertexErrorMatrix() const
Returns the 3x3 position error sub-matrix.
Definition Particle.cc:478
double getPValue() const
Returns chi^2 probability of fit if done or -1.
Definition Particle.h:687
ROOT::Math::XYZVector getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
Definition Particle.h:651
int getPDGCode(void) const
Returns PDG code.
Definition Particle.h:465
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
std::vector< Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
Definition Particle.cc:668
void setMomentumVertexErrorMatrix(const TMatrixFSym &errMatrix)
Sets 7x7 error matrix.
Definition Particle.cc:424
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
Definition Particle.h:580
void setPValue(double pValue)
Sets chi^2 probability of fit.
Definition Particle.h:377
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
Definition Particle.cc:451
const TrackFitResult * getTrackFitResult() const
Returns the pointer to the TrackFitResult that was used to create this Particle (ParticleType == c_Tr...
Definition Particle.cc:925
double getMomentumMagnitude() const
Returns momentum magnitude.
Definition Particle.h:589
double getP() const
Returns momentum magnitude (same as getMomentumMagnitude but with shorter name)
Definition Particle.h:598
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
Definition RestOfEvent.h:55
std::vector< const Particle * > getChargedParticles(const std::string &maskName=c_defaultMaskName, unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
static constexpr const char * c_defaultMaskName
Default mask name.
Definition RestOfEvent.h:58
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
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.
Definition StoreArray.h:140
int m_fitTruthStatus
Store info about whether the fit was performed with the truth info 0 fit performed with measured para...
TMatrixDSym m_constraintCov
constraint to be used in the tag vertex fit
double m_truthTagVol
MC tagV component in the direction orthogonal to the boost.
std::vector< const Particle * > m_tagParticles
tracks of the rest of the event
double m_tagVl
tagV component in the boost direction
bool doVertexFit(const Particle *Breco)
central method for the tag side vertex fit
std::vector< const Particle * > getTagTracks_standardAlgorithm(const Particle *Breco, int nPXDHits) const
performs the fit using the standard algorithm - using all tracks in RoE The user can specify a reques...
double m_truthTagVl
MC tagV component in the boost direction.
std::pair< ROOT::Math::XYZVector, TMatrixDSym > findConstraintBoost(double cut) const
calculate the standard constraint for the vertex fit on the tag side
bool m_useTruthInFit
Set to true if the tag fit is to be made with the TRUE tag track momentum and position.
std::vector< double > m_raveWeights
Store the weights used by Rave in the vtx fit so that they can be accessed later.
TrackFitResult getTrackWithRollBackCoordinates(ParticleAndWeight const &paw)
If the fit has to be done with the rolled back tracks, Rave or KFit is fed with a track where the pos...
virtual void initialize() override
Initialize the Module.
void fillTagVinfo(const ROOT::Math::XYZVector &tagVpos, const TMatrixDSym &tagVposErr)
Fill tagV vertex info.
ROOT::Math::XYZVector m_mcVertReco
generated Breco decay vertex
TMatrixDSym m_pvCov
covariance matrix of the PV (useful with tube and KFit)
double m_mcDeltaT
generated DeltaT with boost-direction approximation
static std::string printVector(const ROOT::Math::XYZVector &vec)
Print a XYZVector (useful for debugging)
ROOT::Math::XYZVector m_tagV
tag side fit result
virtual void event() override
Event processor.
std::pair< ROOT::Math::XYZVector, TMatrixDSym > findConstraintBTube(const Particle *Breco, double cut)
calculate constraint for the vertex fit on the tag side using the B tube (cylinder along the expected...
Particle * doVertexFitForBTube(const Particle *mother, std::string fitType) const
it returns an intersection between B rec and beam spot (= origin of BTube)
std::string m_listName
Breco particle list name.
std::vector< ParticleAndWeight > getParticlesAndWeights(const std::vector< const Particle * > &tagParticles) const
Get a list of particles with attached weight and associated MC particle.
bool m_useRollBack
Set to true if the tag fit is to be made with the tag track position rolled back to mother B.
double m_tagVlErr
Error of the tagV component in the boost direction.
std::string m_roeMaskName
ROE particles from this mask will be used for vertex fitting.
double m_tagVChi2
chi^2 value of the tag vertex fit result
static ROOT::Math::XYZVector getTruePoca(ParticleAndWeight const &paw)
This finds the point on the true particle trajectory closest to the measured track position.
void BtagMCVertex(const Particle *Breco)
get the vertex of the MC B particle associated to Btag.
std::pair< ROOT::Math::XYZVector, TMatrixDSym > findConstraint(const Particle *Breco, double cut) const
calculate the constraint for the vertex fit on the tag side using Breco information
bool m_mcInfo
true if user wants to retrieve MC information out from the tracks used in the fit
double m_kFitReqReducedChi2
The required chi2/ndf to accept the kFit result, if it is higher, iteration procedure is applied.
std::string m_useMCassociation
No MC association or standard Breco particle or internal MCparticle association.
ROOT::Math::XYZVector m_constraintCenter
centre position of the constraint for the tag Vertex fit
double m_tagVolErr
Error of the tagV component in the direction orthogonal to the boost.
double m_mcTagLifeTime
generated tag side life time of B-decay
ROOT::Math::XYZVector m_BeamSpotCenter
Beam spot position.
double m_tagVNDF
Number of degrees of freedom in the tag vertex fit.
double m_deltaTErr
reconstructed DeltaT error
std::string m_fitAlgo
Algorithm used for the tag fit (Rave or KFit)
bool makeGeneralFit()
TO DO: tag side vertex fit in the case of semileptonic tag side decay.
ROOT::Math::XYZVector getRollBackPoca(ParticleAndWeight const &paw)
This shifts the position of tracks by the vector difference of mother B and production point of track...
virtual void beginRun() override
Called when entering a new run.
double m_mcDeltaTau
generated DeltaT
double m_fitPval
P value of the tag side fit result.
StoreArray< TagVertex > m_verArray
StoreArray of TagVertexes.
DBObjPtr< BeamSpot > m_beamSpotDB
Beam spot database object.
void deltaT(const Particle *Breco)
calculate DeltaT and MC-DeltaT (rec - tag) in ps from Breco and Btag vertices DT = Dl / gamma beta c ...
std::vector< const Particle * > m_raveParticles
tracks given to rave for the track fit (after removing Kshorts
void fillParticles(std::vector< ParticleAndWeight > &particleAndWeights)
Fill sorted list of particles into external variable.
int m_reqPXDHits
N of PXD hits for a track to be used.
double m_confidenceLevel
required fit confidence level
double m_tagVChi2IP
IP component of the chi^2 of the tag vertex fit result.
double m_tagVol
tagV component in the direction orthogonal to the boost
analysis::VertexFitKFit doSingleKfit(std::vector< ParticleAndWeight > &particleAndWeights)
performs single KFit on particles stored in particleAndWeights this function can be iterated several ...
std::string m_constraintType
Choose constraint: noConstraint, IP, tube, boost, (breco)
void resetReturnParams()
Reset all parameters that are computed in each event and then used to compute tuple variables.
ROOT::Math::PxPyPzEVector m_tagMomentum
B tag momentum computed from fully reconstructed B sig.
bool makeGeneralFitRave()
make the vertex fit on the tag side: RAVE AVF tracks coming from Ks removed all other tracks used
TrackFitResult getTrackWithTrueCoordinates(ParticleAndWeight const &paw) const
If the fit has to be done with the truth info, Rave is fed with a track where the momentum is replace...
StoreArray< MCParticle > m_mcParticles
StoreArray of MCParticles.
double m_mcLifeTimeReco
generated Breco life time
static bool compBrecoBgen(const Particle *Breco, const MCParticle *Bgen)
compare Breco with the two MC B particles
double m_Bfield
magnetic field from data base
TMatrixDSym m_tagVErrMatrix
Error matrix of the tag side fit result.
int m_mcPDG
generated tag side B flavor
StoreObjPtr< ParticleList > m_plist
input particle list
static std::string printMatrix(const TMatrixD &mat)
Print a TMatrix (useful for debugging)
ROOT::Math::XYZVector m_mcTagV
generated tag side vertex
int m_rollbackStatus
Store info about whether the fit was performed with the rolled back tracks 0 fit performed with measu...
std::string m_trackFindingType
Choose how to find the tag tracks: standard, standard_PXD.
bool m_verbose
choose if you want to print extra infos
int m_FitType
fit algo used
bool makeGeneralFitKFit()
make the vertex fit on the tag side: KFit tracks coming from Ks removed all other tracks used
std::vector< const MCParticle * > m_raveMCParticles
Store the MC particles corresponding to each track used by Rave in the vtx fit.
TMatrixDSym m_BeamSpotCov
size of the beam spot == covariance matrix on the beam spot position
double m_deltaT
reconstructed DeltaT
TagVertex data object: contains Btag Vertex and DeltaT.
Definition TagVertex.h:29
void setConstraintType(const std::string &constraintType)
Set the type of the constraint for the tag fit.
Definition TagVertex.cc:316
void setTagVlErr(float TagVlErr)
Set the error of the tagV component in the boost direction.
Definition TagVertex.cc:254
void setTruthTagVl(float TruthTagVl)
Set the MC tagV component in the boost direction.
Definition TagVertex.cc:249
void setTruthTagVol(float TruthTagVol)
Set the tagV component in the direction orthogonal to the boost.
Definition TagVertex.cc:264
void setMCTagBFlavor(int mcTagBFlavor)
Set generated Btag PDG code.
Definition TagVertex.cc:219
void setTagVolErr(float TagVolErr)
Set the error of the tagV component in the direction orthogonal to the boost.
Definition TagVertex.cc:269
void setTagVNDF(float TagVNDF)
Set the number of degrees of freedom in the tag vertex fit.
Definition TagVertex.cc:274
void setDeltaTErr(float DeltaTErr)
Set DeltaTErr.
Definition TagVertex.cc:209
void setConstraintCenter(const ROOT::Math::XYZVector &constraintCenter)
Set the centre of the constraint for the tag fit.
Definition TagVertex.cc:305
void setNTracks(int nTracks)
Set number of tracks used in the fit.
Definition TagVertex.cc:239
void setTagVChi2(float TagVChi2)
Set the chi^2 value of the tag vertex fit result.
Definition TagVertex.cc:279
void setMCDeltaT(float mcDeltaT)
Set generated DeltaT (in kin.
Definition TagVertex.cc:229
void setRollBackStatus(int backStatus)
Set the status of the fit performed with the rolled back tracks.
Definition TagVertex.cc:340
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.
Definition TagVertex.cc:295
void setTagVol(float TagVol)
Set the tagV component in the direction orthogonal to the boost.
Definition TagVertex.cc:259
void setDeltaT(float DeltaT)
Set DeltaT.
Definition TagVertex.cc:204
void setRaveWeights(const std::vector< double > &raveWeights)
Set the weights used by Rave in the tag vtx fit.
Definition TagVertex.cc:300
void setTagVertexPval(float TagVertexPval)
Set BTag Vertex P value.
Definition TagVertex.cc:199
void setTagVertex(const ROOT::Math::XYZVector &TagVertex)
Set BTag Vertex.
Definition TagVertex.cc:189
void setMCDeltaTau(float mcDeltaTau)
Set generated DeltaT.
Definition TagVertex.cc:224
void setTagVl(float TagVl)
Set the tagV component in the boost direction.
Definition TagVertex.cc:244
void setTagVertexErrMatrix(const TMatrixDSym &TagVertexErrMatrix)
Set BTag Vertex (3x3) error matrix.
Definition TagVertex.cc:194
void setConstraintCov(const TMatrixDSym &constraintCov)
Set the covariance matrix of the constraint for the tag fit.
Definition TagVertex.cc:310
void setFitType(float FitType)
Set fit algo type.
Definition TagVertex.cc:234
void setVertexFitParticles(const std::vector< const Particle * > &vtxFitParticles)
Set a vector of pointers to the tracks used in the tag vtx fit.
Definition TagVertex.cc:289
void setMCTagVertex(const ROOT::Math::XYZVector &mcTagVertex)
Set generated BTag Vertex.
Definition TagVertex.cc:214
void setTagVChi2IP(float TagVChi2IP)
Set the IP component of the chi^2 value of the tag vertex fit result.
Definition TagVertex.cc:284
void setFitTruthStatus(int truthStatus)
Set the status of the fit performed with the truth info of the tracks.
Definition TagVertex.cc:335
Values of the result of a track fit with a given particle hypothesis.
float getNDF() const
Getter for number of degrees of freedom of the track fit.
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.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
ROOT::Math::XYZVector getPosition() const
Getter for vector of position at closest approach of track in r/phi projection.
virtual int getNDF(void) const
Get an NDF of the fit.
Definition KFitBase.cc:114
bool isFitted(void) const
Return false if fit is not performed yet or performed fit is failed; otherwise true.
Definition KFitBase.cc:728
int getTrackCount(void) const
Get the number of added tracks.
Definition KFitBase.cc:107
void unsetBeamSpot()
unset beam spot constraint
Definition RaveSetup.cc:82
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:74
void reset()
frees memory allocated by initialize().
Definition RaveSetup.cc:60
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 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.
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.
double getCHIsq(void) const override
Get a chi-square of the fit.
static const double realNaN
This collects the B-meson properties in the hadronic B-decays It is used for the Ecms calibration in ...
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
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
ROOT::Math::XYZVector poca(ROOT::Math::XYZVector const &trackPos, ROOT::Math::XYZVector const &trackP, ROOT::Math::XYZVector const &vtxPos)
Returns the Point Of Closest Approach of a track to a vertex.
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Abstract base class for different kinds of events.
STL namespace.
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