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