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
154// cppcheck-suppress uselessOverride
156{
157 //TODO: set magnetic field for each run
158 //m_Bfield = BFieldMap::Instance().getBField(m_BeamSpotCenter).Z();
159}
160
162{
163 if (!m_plist) {
164 B2ERROR("TagVertexModule: ParticleList " << m_listName << " not found");
165 return;
166 }
167
168 // output
170
171 std::vector<unsigned int> toRemove;
172
173 for (unsigned i = 0; i < m_plist->getListSize(); ++i) {
175
176 const Particle* particle = m_plist->getParticle(i);
177 if (m_useMCassociation == "breco" || m_useMCassociation == "internal") BtagMCVertex(particle);
178 bool ok = doVertexFit(particle);
179 if (ok) deltaT(particle);
180
183 toRemove.push_back(particle->getArrayIndex());
184 } else {
185 // save information in the Vertex StoreArray
186 TagVertex* ver = m_verArray.appendNew();
187 // create relation: Particle <-> Vertex
188 particle->addRelationTo(ver);
189 // fill Vertex with content
190 if (ok) {
191 ver->setTagVertex(m_tagV);
194 ver->setDeltaT(m_deltaT);
200 ver->setFitType(m_FitType);
201 ver->setNTracks(m_tagParticles.size());
202 ver->setTagVl(m_tagVl);
205 ver->setTagVol(m_tagVol);
208 ver->setTagVNDF(m_tagVNDF);
219 } else {
220 ver->setTagVertex(m_tagV);
221 ver->setTagVertexPval(-1.);
222 ver->setDeltaT(m_deltaT);
225 ver->setMCTagBFlavor(0.);
228 ver->setFitType(m_FitType);
229 ver->setNTracks(m_tagParticles.size());
230 ver->setTagVl(m_tagVl);
233 ver->setTagVol(m_tagVol);
236 ver->setTagVNDF(-1111.);
237 ver->setTagVChi2(-1111.);
238 ver->setTagVChi2IP(-1111.);
247 }
248 }
249 }
250 m_plist->removeParticles(toRemove);
251
252 //free memory allocated by rave. initialize() would be enough, except that we must clean things up before program end...
253 //
255}
256
258{
259 //reset the fit truth status in case it was set to 2 in a previous fit
260
262
263 //reset the roll back status in case it was set to 2 in a previous fit
264
266
267 //set constraint type, reset pVal and B field
268
269 m_fitPval = 1;
270
271 if (!(Breco->getRelatedTo<RestOfEvent>())) {
272 m_FitType = -1;
273 return false;
274 }
275
276 if (m_Bfield == 0) {
277 B2ERROR("TagVertex: No magnetic field");
278 return false;
279 }
280
281 // recover beam spot info
282
283 m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
284 m_BeamSpotCov.ResizeTo(3, 3);
285 m_BeamSpotCov = m_beamSpotDB->getCovVertex();
286
287 //make the beam spot bigger for the standard constraint
288
289 double beta = PCmsLabTransform().getBoostVector().R();
290 double bg = beta / sqrt(1 - beta * beta);
291
292 //TODO: What's the origin of these numbers?
293 double tauB = 1.519; //B0 lifetime in ps
294 double c = Const::speedOfLight / 1000.; // cm ps-1
295 double lB0 = tauB * bg * c;
296
297 //tube length here set to 20 * 2 * c tau beta gamma ~= 0.5 cm, should be enough to not bias the decay
298 //time but should still help getting rid of some pions from kshorts
299 m_constraintCov.ResizeTo(3, 3);
301 else if (m_constraintType == "tube") tie(m_constraintCenter, m_constraintCov) = findConstraintBTube(Breco, 200 * lB0);
302 else if (m_constraintType == "boost") tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(200 * lB0);
303 else if (m_constraintType == "breco") tie(m_constraintCenter, m_constraintCov) = findConstraint(Breco, 200 * lB0);
304 else if (m_constraintType == "noConstraint") m_constraintCenter = ROOT::Math::XYZVector(); //zero vector
305 else {
306 B2ERROR("TagVertex: Invalid constraintType selected");
307 return false;
308 }
309
310 if (m_constraintCenter == vecNaN) {
311 B2ERROR("TagVertex: No correct fit constraint");
312 return false;
313 }
314
315 /* 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
316 high efficiency, the next algorithm less restrictive is used. I.e, if standard_PXD does not work, the program tries with standard.
317 */
318
319 m_FitType = 0;
320 double minPVal = (m_fitAlgo != "KFit") ? 0.001 : 0.;
321 bool ok = false;
322
323 if (m_trackFindingType == "standard_PXD") {
325 if (m_tagParticles.size() > 0) {
326 ok = makeGeneralFit();
327 m_FitType = 3;
328 }
329 }
330
331 if (ok == false || m_fitPval < minPVal || m_trackFindingType == "standard") {
333 ok = m_tagParticles.size() > 0;
334 if (ok) {
335 ok = makeGeneralFit();
336 m_FitType = 4;
337 }
338 }
339
340 if ((ok == false || (m_fitPval <= 0. && m_fitAlgo == "Rave")) && m_constraintType != "noConstraint") {
342 ok = (m_constraintCenter != vecNaN);
343 if (ok) {
345 ok = (m_tagParticles.size() > 0);
346 }
347 if (ok) {
348 ok = makeGeneralFit();
349 m_FitType = 5;
350 }
351 }
352
353 return ok;
354}
355
356pair<ROOT::Math::XYZVector, TMatrixDSym> TagVertexModule::findConstraint(const Particle* Breco, double cut) const
357{
358 if (Breco->getPValue() < 0.) return make_pair(vecNaN, matNaN);
359
360 TMatrixDSym beamSpotCov(3);
361 beamSpotCov = m_beamSpotDB->getCovVertex();
362
364
365 double pmag = Breco->getMomentumMagnitude();
366 double xmag = (Breco->getVertex() - m_BeamSpotCenter).R();
367
368
369 TMatrixDSym TerrMatrix = Breco->getMomentumVertexErrorMatrix();
370 TMatrixDSym PerrMatrix(7);
371
372 for (int i = 0; i < 3; ++i) {
373 for (int j = 0; j < 3; ++j) {
374 if (i == j) {
375 PerrMatrix(i, j) = (beamSpotCov(i, j) + TerrMatrix(i, j)) * pmag / xmag;
376 } else {
377 PerrMatrix(i, j) = TerrMatrix(i, j);
378 }
379 PerrMatrix(i + 4, j + 4) = TerrMatrix(i + 4, j + 4);
380 }
381 }
382
383 PerrMatrix(3, 3) = 0.;
384
385 //Copy Breco, but use errors as are in PerrMatrix
386 Particle* Breco2 = ParticleCopy::copyParticle(Breco);
387 Breco2->setMomentumVertexErrorMatrix(PerrMatrix);
388
389
390 const Particle* BRecoRes = doVertexFitForBTube(Breco2, "kalman");
391 if (BRecoRes->getPValue() < 0) return make_pair(vecNaN, matNaN); //problems
392
393 // Overall error matrix
394 TMatrixDSym errFinal = TMatrixDSym(Breco->getVertexErrorMatrix() + BRecoRes->getVertexErrorMatrix());
395
396 // TODO : to be developed the extraction of the momentum from the rave fitted track
397
398 // Get expected pBtag 4-momentum using transverse-momentum conservation
399 ROOT::Math::XYZVector BvertDiff = pmag * (Breco->getVertex() - BRecoRes->getVertex()).Unit();
400 ROOT::Math::PxPyPzMVector pBrecEstimate(BvertDiff.X(), BvertDiff.Y(), BvertDiff.Z(), Breco->getPDGMass());
401 ROOT::Math::PxPyPzMVector pBtagEstimate = PCmsLabTransform::labToCms(pBrecEstimate);
402 pBtagEstimate.SetPxPyPzE(-pBtagEstimate.px(), -pBtagEstimate.py(), -pBtagEstimate.pz(), pBtagEstimate.E());
403 pBtagEstimate = PCmsLabTransform::cmsToLab(pBtagEstimate);
404
405 // rotate err-matrix such that pBrecEstimate goes to eZ
406 TMatrixD TubeZ = rotateTensorInv(pBrecEstimate.Vect(), errFinal);
407
408 TubeZ(2, 2) = cut * cut;
409 TubeZ(2, 0) = 0; TubeZ(0, 2) = 0;
410 TubeZ(2, 1) = 0; TubeZ(1, 2) = 0;
411
412
413 // rotate err-matrix such that eZ goes to pBtagEstimate
414 TMatrixD Tube = rotateTensor(pBtagEstimate.Vect(), TubeZ);
415
416 // Standard algorithm needs no shift
417 return make_pair(m_BeamSpotCenter, toSymMatrix(Tube));
418}
419
420pair<ROOT::Math::XYZVector, TMatrixDSym> TagVertexModule::findConstraintBTube(const Particle* Breco, double cut)
421{
422 //Use Breco as the creator of the B tube.
423 if ((Breco->getVertexErrorMatrix()(2, 2)) == 0.0) {
424 B2WARNING("In TagVertexModule::findConstraintBTube: cannot get a proper vertex for BReco. BTube constraint replaced by Boost.");
425 return findConstraintBoost(cut);
426 }
427
428
429 //vertex fit will give the intersection between the beam spot and the trajectory of the B
430 //(base of the BTube, or primary vtx cov matrix)
431 const Particle* tubecreatorBCopy = doVertexFitForBTube(Breco, "avf");
432 if (tubecreatorBCopy->getPValue() < 0) return make_pair(vecNaN, matNaN); //if problems
433
434
435 //get direction of B tag = opposite direction of B rec in CMF
436 ROOT::Math::PxPyPzEVector pBrec = tubecreatorBCopy->get4Vector();
437
438 //if we want the true info, replace the 4vector by the true one
439 if (m_useTruthInFit) {
440 const MCParticle* mcBr = Breco->getRelated<MCParticle>();
441 if (mcBr)
442 pBrec = mcBr->get4Vector();
443 else
445 }
446 ROOT::Math::PxPyPzEVector pBtag = PCmsLabTransform::labToCms(pBrec);
447 pBtag.SetPxPyPzE(-pBtag.px(), -pBtag.py(), -pBtag.pz(), pBtag.E());
448 pBtag = PCmsLabTransform::cmsToLab(pBtag);
449
450 //To create the B tube, strategy is: take the primary vtx cov matrix, and add to it a cov
451 //matrix corresponding to an very big error in the direction of the B tag
452 TMatrixDSym pv = tubecreatorBCopy->getVertexErrorMatrix();
453
454 //print some stuff if wanted
455 if (m_verbose) {
456 B2DEBUG(10, "Brec decay vertex before fit: " << printVector(Breco->getVertex()));
457 B2DEBUG(10, "Brec decay vertex after fit: " << printVector(tubecreatorBCopy->getVertex()));
458 B2DEBUG(10, "Brec direction before fit: " << printVector(float(1. / Breco->getP()) * Breco->getMomentum()));
459 B2DEBUG(10, "Brec direction after fit: " << printVector(float(1. / tubecreatorBCopy->getP()) * tubecreatorBCopy->getMomentum()));
460 B2DEBUG(10, "IP position: " << printVector(m_BeamSpotCenter));
461 B2DEBUG(10, "IP covariance: " << printMatrix(m_BeamSpotCov));
462 B2DEBUG(10, "Brec primary vertex: " << printVector(tubecreatorBCopy->getVertex()));
463 B2DEBUG(10, "Brec PV covariance: " << printMatrix(pv));
464 B2DEBUG(10, "BTag direction: " << printVector((1. / pBtag.P())*pBtag.Vect()));
465 }
466
467 //make a long error matrix along BTag direction
468 TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
469
470
471 // make rotation matrix from z axis to BTag line of flight
472 TMatrixD longerrorRotated = rotateTensor(pBtag.Vect(), longerror);
473
474 //pvNew will correspond to the covariance matrix of the B tube
475 TMatrixD pvNew = TMatrixD(pv) + longerrorRotated;
476
477 //set the constraint
478 ROOT::Math::XYZVector constraintCenter = tubecreatorBCopy->getVertex();
479
480 //if we want the true info, set the centre of the constraint to the primary vertex
481 if (m_useTruthInFit) {
482 const MCParticle* mcBr = Breco->getRelated<MCParticle>();
483 if (mcBr) {
484 constraintCenter = mcBr->getProductionVertex();
485 }
486 }
487
488 if (m_verbose) {
489 B2DEBUG(10, "IPTube covariance: " << printMatrix(pvNew));
490 }
491
492 //The following is done to do the BTube constraint with a virtual track
493 //(ie KFit way)
494
495 m_tagMomentum = pBtag;
496
497 m_pvCov.ResizeTo(pv);
498 m_pvCov = pv;
499
500 return make_pair(constraintCenter, toSymMatrix(pvNew));
501}
502
503pair<ROOT::Math::XYZVector, TMatrixDSym> TagVertexModule::findConstraintBoost(double cut) const
504{
505 double d = 20e-4; //average transverse distance flown by B0
506
507 //make a long error matrix along boost direction
508 TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
509 longerror(0, 0) = longerror(1, 1) = d * d;
510
511 ROOT::Math::XYZVector boostDir = PCmsLabTransform().getBoostVector().Unit();
512
513 TMatrixD longerrorRotated = rotateTensor(boostDir, longerror);
514
515 //Extend error of BeamSpotCov matrix in the boost direction
516 TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
517 TMatrixD Tube = TMatrixD(beamSpotCov) + longerrorRotated;
518
519 // Standard algorithm needs no shift
520 ROOT::Math::XYZVector constraintCenter = m_BeamSpotCenter;
521
522 return make_pair(constraintCenter, toSymMatrix(Tube));
523}
524
526static double getProperLifeTime(const MCParticle* mc)
527{
528 double beta = mc->getMomentum().R() / mc->getEnergy();
529 return 1e3 * mc->getLifetime() * sqrt(1 - pow(beta, 2));
530}
531
533{
534 //fill vector with mcB (intended order: Reco, Tag)
535 vector<const MCParticle*> mcBs;
536 for (const MCParticle& mc : m_mcParticles) {
537 if (abs(mc.getPDG()) == abs(Breco->getPDGCode()))
538 mcBs.push_back(&mc);
539 }
540 //too few Bs
541 if (mcBs.size() < 2) return;
542
543 if (mcBs.size() > 2) {
544 B2WARNING("TagVertexModule:: Too many Bs found in MC");
545 }
546
547 auto isReco = [&](const MCParticle * mc) {
548 return (m_useMCassociation == "breco") ? (mc == Breco->getRelated<MCParticle>())
549 : compBrecoBgen(Breco, mc); //internal association
550 };
551
552 //nothing matched?
553 if (!isReco(mcBs[0]) && !isReco(mcBs[1])) {
554 return;
555 }
556
557 //first is Tag, second Reco -> swap the order
558 if (!isReco(mcBs[0]) && isReco(mcBs[1]))
559 swap(mcBs[0], mcBs[1]);
560
561 //both matched -> use closest vertex dist as Reco
562 if (isReco(mcBs[0]) && isReco(mcBs[1])) {
563 double dist0 = (mcBs[0]->getDecayVertex() - Breco->getVertex()).Mag2();
564 double dist1 = (mcBs[1]->getDecayVertex() - Breco->getVertex()).Mag2();
565 if (dist0 > dist1)
566 swap(mcBs[0], mcBs[1]);
567 }
568
569 m_mcVertReco = mcBs[0]->getDecayVertex();
570 m_mcLifeTimeReco = getProperLifeTime(mcBs[0]);
571 m_mcTagV = mcBs[1]->getDecayVertex();
572 m_mcTagLifeTime = getProperLifeTime(mcBs[1]);
573 m_mcPDG = mcBs[1]->getPDG();
574}
575
576// static
578{
579
580 bool isDecMode = true;
581
582 const std::vector<Particle*> recDau = Breco->getDaughters();
583 const std::vector<MCParticle*> genDau = Bgen->getDaughters();
584
585 if (recDau.size() > 0 && genDau.size() > 0) {
586 for (auto dauRec : recDau) {
587 bool isDau = false;
588 for (auto dauGen : genDau) {
589 if (dauGen->getPDG() == dauRec->getPDGCode())
590 isDau = compBrecoBgen(dauRec, dauGen) ;
591 }
592 if (!isDau) isDecMode = false;
593 }
594 } else {
595 if (recDau.size() == 0) { //&& genDau.size()==0){
596 if (Bgen->getPDG() != Breco->getPDGCode()) isDecMode = false;;
597 } else {isDecMode = false;}
598 }
599
600 return isDecMode;
601}
602
603// STANDARD FIT ALGORITHM
604/* This algorithm basically takes all the tracks coming from the Rest Of Events and send them to perform a multi-track fit
605 The option to request PXD hits for the tracks can be chosen by the user.
606 */
607std::vector<const Particle*> TagVertexModule::getTagTracks_standardAlgorithm(const Particle* Breco, int reqPXDHits) const
608{
609 std::vector<const Particle*> fitParticles;
610 const RestOfEvent* roe = Breco->getRelatedTo<RestOfEvent>();
611 if (!roe) return fitParticles;
612 //load all particles from the ROE
613 std::vector<const Particle*> ROEParticles = roe->getChargedParticles(m_roeMaskName, 0, false);
614 if (ROEParticles.size() == 0) return fitParticles;
615
616 for (auto& ROEParticle : ROEParticles) {
617 HitPatternVXD roeTrackPattern = ROEParticle->getTrackFitResult()->getHitPatternVXD();
618
619 if (roeTrackPattern.getNPXDHits() >= reqPXDHits) {
620 fitParticles.push_back(ROEParticle);
621 }
622 }
623 return fitParticles;
624}
625
626
627vector<ParticleAndWeight> TagVertexModule::getParticlesAndWeights(const vector<const Particle*>& tagParticles) const
628{
629 vector<ParticleAndWeight> particleAndWeights;
630
631 for (const Particle* particle : tagParticles) {
632 ROOT::Math::PxPyPzEVector mom = particle->get4Vector();
633 if (!isfinite(mom.mag2())) continue;
634
635 ParticleAndWeight particleAndWeight;
636 particleAndWeight.mcParticle = 0;
637 particleAndWeight.weight = -1111.;
638 particleAndWeight.particle = particle;
639
640 if (m_useMCassociation == "breco" || m_useMCassociation == "internal")
641 particleAndWeight.mcParticle = particle->getRelatedTo<MCParticle>();
642
643 particleAndWeights.push_back(particleAndWeight);
644 }
645
646 return particleAndWeights;
647}
648
650{
651 if (m_fitAlgo == "Rave") return makeGeneralFitRave();
652 else if (m_fitAlgo == "KFit") return makeGeneralFitKFit();
653 return false;
654}
655
656void TagVertexModule::fillParticles(vector<ParticleAndWeight>& particleAndWeights)
657{
658 unsigned n = particleAndWeights.size();
659 sort(particleAndWeights.begin(), particleAndWeights.end(),
660 [](const ParticleAndWeight & a, const ParticleAndWeight & b) { return a.weight > b.weight; });
661
662 m_raveParticles.resize(n);
663 m_raveWeights.resize(n);
664 m_raveMCParticles.resize(n);
665
666 for (unsigned i = 0; i < n; ++i) {
667 m_raveParticles.at(i) = particleAndWeights.at(i).particle;
668 m_raveMCParticles.at(i) = particleAndWeights.at(i).mcParticle;
669 m_raveWeights.at(i) = particleAndWeights.at(i).weight;
670 }
671}
672
673void TagVertexModule::fillTagVinfo(const ROOT::Math::XYZVector& tagVpos, const TMatrixDSym& tagVposErr)
674{
675 m_tagV = tagVpos;
676
677 if (m_constraintType != "noConstraint") {
678 TMatrixDSym tubeInv = m_constraintCov;
679 tubeInv.Invert();
680 TVectorD dV = toVec(m_tagV - m_BeamSpotCenter);
681 m_tagVChi2IP = tubeInv.Similarity(dV);
682 }
683
684 m_tagVErrMatrix.ResizeTo(tagVposErr);
685 m_tagVErrMatrix = tagVposErr;
686}
687
689{
690 // apply constraint
692 if (m_constraintType != "noConstraint")
695
696 //feed rave with tracks without Kshorts
697 vector<ParticleAndWeight> particleAndWeights = getParticlesAndWeights(m_tagParticles);
698
699 for (const auto& pw : particleAndWeights) {
700 try {
701 if (m_useTruthInFit) {
702 if (pw.mcParticle) {
704 rFit.addTrack(&tfr);
705 } else
707 } else if (m_useRollBack) {
708 if (pw.mcParticle) {
710 rFit.addTrack(&tfr);
711 } else
713 } else {
714 rFit.addTrack(pw.particle->getTrackFitResult());
715 }
716 } catch (const rave::CheckedFloatException&) {
717 B2ERROR("Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
718 }
719 }
720
721 //perform fit
722
723 int isGoodFit(-1);
724
725 try {
726 isGoodFit = rFit.fit("avf");
727 // if problems
728 if (isGoodFit < 1) return false;
729 } catch (const rave::CheckedFloatException&) {
730 B2ERROR("Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
731 return false;
732 }
733
734 //save the track info for later use
735
736 for (unsigned int i(0); i < particleAndWeights.size() && isGoodFit >= 1; ++i)
737 particleAndWeights.at(i).weight = rFit.getWeight(i);
738
739 //Tracks are sorted from highest rave weight to lowest
740
741 fillParticles(particleAndWeights);
742
743 //if the fit is good, save the infos related to the vertex
744 fillTagVinfo(ROOT::Math::XYZVector(rFit.getPos(0)), rFit.getCov(0));
745
746 //fill quality variables
747 m_tagVNDF = rFit.getNdf(0);
748 m_tagVChi2 = rFit.getChi2(0);
749 m_fitPval = rFit.getPValue();
750
751 return true;
752}
753
754
755analysis::VertexFitKFit TagVertexModule::doSingleKfit(vector<ParticleAndWeight>& particleAndWeights)
756{
757 //initialize KFit
759 kFit.setMagneticField(m_Bfield);
760
761 // apply constraint
762 if (m_constraintType != "noConstraint") {
763 if (m_constraintType == "tube") {
764 CLHEP::HepSymMatrix err(7, 0);
765 //copy m_pvCov to the end of err matrix
766 err.sub(5, ROOTToCLHEP::getHepSymMatrix(m_pvCov));
767 kFit.setIpTubeProfile(
768 ROOTToCLHEP::getHepLorentzVector(m_tagMomentum),
769 ROOTToCLHEP::getPoint3D(m_constraintCenter),
770 err,
771 0.);
772 } else {
773 kFit.setIpProfile(ROOTToCLHEP::getPoint3D(m_constraintCenter),
774 ROOTToCLHEP::getHepSymMatrix(m_constraintCov));
775 }
776 }
777
778
779 for (auto& pawi : particleAndWeights) {
780 int addedOK = 1;
781 if (m_useTruthInFit) {
782 if (pawi.mcParticle) {
783 addedOK = kFit.addTrack(
784 ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
785 ROOTToCLHEP::getPoint3D(getTruePoca(pawi)),
786 ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
787 pawi.particle->getCharge());
788 } else {
790 }
791 } else if (m_useRollBack) {
792 if (pawi.mcParticle) {
793 addedOK = kFit.addTrack(
794 ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
795 ROOTToCLHEP::getPoint3D(getRollBackPoca(pawi)),
796 ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
797 pawi.particle->getCharge());
798 } else {
800 }
801 } else {
802 addedOK = kFit.addParticle(pawi.particle);
803 }
804
805 if (addedOK == 0) {
806 pawi.weight = 1.;
807 } else {
808 B2WARNING("TagVertexModule::makeGeneralFitKFit: failed to add a track");
809 pawi.weight = 0.;
810 }
811 }
812
813
814 int nTracksAdded = kFit.getTrackCount();
815
816 //perform fit if there are enough tracks
817 if ((nTracksAdded < 2 && m_constraintType == "noConstraint") || nTracksAdded < 1)
819
820 int isGoodFit = kFit.doFit();
821 if (isGoodFit != 0) return analysis::VertexFitKFit();
822
823 return kFit;
824}
825
826
827static int getLargestChi2ID(const analysis::VertexFitKFit& kFit)
828{
829 int largest_chi2_trackid = -1;
830 double largest_track_chi2 = -1;
831 for (int i = 0; i < kFit.getTrackCount(); ++i) {
832 double track_chi2 = kFit.getTrackCHIsq(i);
833 if (track_chi2 > largest_track_chi2) {
834 largest_track_chi2 = track_chi2;
835 largest_chi2_trackid = i;
836 }
837 }
838 return largest_chi2_trackid;
839}
840
841
842
843//uses m_tagMomentum, m_constraintCenter, m_constraintCov, m_tagParticles
845{
846 //feed KFit with tracks without Kshorts
847 vector<ParticleAndWeight> particleAndWeights = getParticlesAndWeights(m_tagParticles);
848
850
851
852 // iterative procedure which removes tracks with high chi2
853 for (int iteration_counter = 0; iteration_counter < 100; ++iteration_counter) {
854 analysis::VertexFitKFit kFitTemp = doSingleKfit(particleAndWeights);
855 if (!kFitTemp.isFitted() || isnan(kFitTemp.getCHIsq()))
856 return false;
857
858 double reduced_chi2 = kFitTemp.getCHIsq() / kFitTemp.getNDF();
859 int nTracks = kFitTemp.getTrackCount();
860
861 if (nTracks != int(particleAndWeights.size()))
862 B2ERROR("TagVertexModule: Different number of tracks in kFit and particles");
863
864 if (reduced_chi2 <= m_kFitReqReducedChi2 || nTracks <= 1 || (nTracks <= 2 && m_constraintType == "noConstraint")) {
865 kFit = kFitTemp;
866 break;
867 } else { // remove particle with highest chi2/ndf and continue
868 int badTrackID = getLargestChi2ID(kFitTemp);
869 if (0 <= badTrackID && badTrackID < int(particleAndWeights.size()))
870 particleAndWeights.erase(particleAndWeights.begin() + badTrackID);
871 else
872 B2ERROR("TagVertexModule: Obtained badTrackID is not within limits");
873 }
874
875 }
876
877 //save the track info for later use
878 //Tracks are sorted by weight, i.e. pushing the tracks with 0 weight (from KS) to the end of the list
879 fillParticles(particleAndWeights);
880
881 //Save the infos related to the vertex
882 fillTagVinfo(CLHEPToROOT::getXYZVector(kFit.getVertex()),
883 CLHEPToROOT::getTMatrixDSym(kFit.getVertexError()));
884
885 m_tagVNDF = kFit.getNDF();
886 m_tagVChi2 = kFit.getCHIsq();
887 m_fitPval = TMath::Prob(m_tagVChi2, m_tagVNDF);
888
889 return true;
890}
891
893{
894
895 ROOT::Math::XYZVector boost = PCmsLabTransform().getBoostVector();
896 ROOT::Math::XYZVector boostDir = boost.Unit();
897 double bg = boost.R() / sqrt(1 - boost.Mag2());
898 double c = Const::speedOfLight / 1000.; // cm ps-1
899
900 //Reconstructed DeltaL & DeltaT in the boost direction
901 ROOT::Math::XYZVector dVert = Breco->getVertex() - m_tagV; //reconstructed vtxReco - vtxTag
902 double dl = dVert.Dot(boostDir);
903 m_deltaT = dl / (bg * c);
904
905 //Truth DeltaL & approx DeltaT in the boost direction
906 ROOT::Math::XYZVector MCdVert = m_mcVertReco - m_mcTagV; //truth vtxReco - vtxTag
907 double MCdl = MCdVert.Dot(boostDir);
908 m_mcDeltaT = MCdl / (bg * c);
909
910 // MCdeltaTau=tauRec-tauTag
912 if (m_mcLifeTimeReco == -1 || m_mcTagLifeTime == -1)
914
915 TVectorD bVec = toVec(boostDir);
916
917 //TagVertex error in boost dir
918 m_tagVlErr = sqrt(m_tagVErrMatrix.Similarity(bVec));
919
920 //bReco error in boost dir
921 double bRecoErrL = sqrt(Breco->getVertexErrorMatrix().Similarity(bVec));
922
923 //Delta t error
924 m_deltaTErr = hypot(m_tagVlErr, bRecoErrL) / (bg * c);
925
926 m_tagVl = m_tagV.Dot(boostDir);
927 m_truthTagVl = m_mcTagV.Dot(boostDir);
928
929 // calculate tagV component and error in the direction orthogonal to the boost
930 ROOT::Math::XYZVector oboost = getUnitOrthogonal(boostDir);
931 TVectorD oVec = toVec(oboost);
932
933 //TagVertex error in boost-orthogonal dir
934 m_tagVolErr = sqrt(m_tagVErrMatrix.Similarity(oVec));
935
936 m_tagVol = m_tagV.Dot(oboost);
937 m_truthTagVol = m_mcTagV.Dot(oboost);
938}
939
940Particle* TagVertexModule::doVertexFitForBTube(const Particle* motherIn, const std::string& fitType) const
941{
942 //make a copy of motherIn to not modify the original object
943 Particle* mother = ParticleCopy::copyParticle(motherIn);
944
945 //Here rave is used to find the upsilon(4S) vtx as the intersection
946 //between the mother B trajectory and the beam spot
948
950 rsg.addTrack(mother);
951 int nvert = rsg.fit(fitType);
952 if (nvert != 1) {
953 mother->setPValue(-1); //error
954 return mother;
955 } else {
956 rsg.updateDaughters();
957 return mother;
958 }
959}
960
961
962
964{
965 if (!paw.mcParticle) {
966 B2ERROR("In TagVertexModule::getTrackWithTrueCoordinate: no MC particle set");
967 return TrackFitResult();
968 }
969
970 const TrackFitResult* tfr(paw.particle->getTrackFitResult());
971
972 return TrackFitResult(getTruePoca(paw),
973 paw.mcParticle->getMomentum(),
974 tfr->getCovariance6(),
975 tfr->getChargeSign(),
976 tfr->getParticleType(),
977 tfr->getPValue(),
978 m_Bfield, 0, 0, tfr->getNDF());
979}
980
981// static
982ROOT::Math::XYZVector TagVertexModule::getTruePoca(ParticleAndWeight const& paw)
983{
984 if (!paw.mcParticle) {
985 B2ERROR("In TagVertexModule::getTruePoca: no MC particle set");
986 return ROOT::Math::XYZVector(0., 0., 0.);
987 }
988
990 paw.mcParticle->getMomentum(),
992}
993
995{
996 const TrackFitResult* tfr(paw.particle->getTrackFitResult());
997
999 tfr->getMomentum(),
1000 tfr->getCovariance6(),
1001 tfr->getChargeSign(),
1002 tfr->getParticleType(),
1003 tfr->getPValue(),
1004 m_Bfield, 0, 0, tfr->getNDF());
1005}
1006
1008{
1009 if (!paw.mcParticle) {
1010 B2ERROR("In TagVertexModule::getTruePoca: no MC particle set");
1011 return ROOT::Math::XYZVector(0., 0., 0.);
1012 }
1013
1015}
1016
1018{
1019 m_raveParticles.resize(0);
1020 m_raveMCParticles.resize(0);
1021 m_tagParticles.resize(0);
1022 m_raveWeights.resize(0);
1023
1025 m_tagV = vecNaN;
1026 m_tagVErrMatrix.ResizeTo(matNaN);
1027 m_tagVErrMatrix = matNaN;
1028 m_mcTagV = vecNaN;
1029 m_mcVertReco = vecNaN;
1030 m_deltaT = realNaN;
1033 m_constraintCov.ResizeTo(matNaN);
1034 m_constraintCov = matNaN;
1035 m_constraintCenter = vecNaN;
1036 m_tagVl = realNaN;
1039 m_tagVol = realNaN;
1045 m_pvCov.ResizeTo(matNaN);
1046 m_pvCov = matNaN;
1047 m_tagMomentum = ROOT::Math::PxPyPzEVector(realNaN, realNaN, realNaN, realNaN);
1048}
1049
1050//The following functions are just here to help printing stuff
1051
1052// static
1053std::string TagVertexModule::printVector(const ROOT::Math::XYZVector& vec)
1054{
1055 std::ostringstream oss;
1056 int w = 14;
1057 oss << "(" << std::setw(w) << vec.X() << ", " << std::setw(w) << vec.Y() << ", " << std::setw(w) << vec.Z() << ")" << std::endl;
1058 return oss.str();
1059}
1060
1061// static
1062std::string TagVertexModule::printMatrix(const TMatrixD& mat)
1063{
1064 std::ostringstream oss;
1065 int w = 14;
1066 for (int i = 0; i < mat.GetNrows(); ++i) {
1067 for (int j = 0; j < mat.GetNcols(); ++j) {
1068 oss << std::setw(w) << mat(i, j) << " ";
1069 }
1070 oss << endl;
1071 }
1072 return oss.str();
1073}
1074
1075// static
1076std::string TagVertexModule::printMatrix(const TMatrixDSym& mat)
1077{
1078 std::ostringstream oss;
1079 int w = 14;
1080 for (int i = 0; i < mat.GetNrows(); ++i) {
1081 for (int j = 0; j < mat.GetNcols(); ++j) {
1082 oss << std::setw(w) << mat(i, j) << " ";
1083 }
1084 oss << endl;
1085 }
1086 return oss.str();
1087}
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...
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.
Particle * doVertexFitForBTube(const Particle *mother, const std::string &fitType) const
it returns an intersection between B rec and beam spot (= origin of BTube)
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 double getCHIsq(void) const
Get a chi-square of the fit.
Definition KFitBase.cc:121
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: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 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.
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