Belle II Software  release-06-00-14
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 // vertex fitting
33 #include <analysis/VertexFitting/KFit/VertexFitKFit.h>
34 
35 // mdst dataobject
36 #include <mdst/dataobjects/HitPatternVXD.h>
37 
38 // Magnetic field
39 #include <framework/geometry/BFieldManager.h>
40 
41 #include <TVector.h>
42 #include <TRotation.h>
43 
44 
45 using namespace std;
46 
47 namespace Belle2 {
54  static const double realNaN = std::numeric_limits<double>::quiet_NaN();
56  static const TVector3 vecNaN(realNaN, realNaN, realNaN);
58  static const TMatrixDSym matNaN(3, (double [])
59  {
63  });
64 
65  // import tools from RotationTools.h
66  using RotationTools::rotateTensor;
67  using RotationTools::rotateTensorInv;
68  using RotationTools::toSymMatrix;
69  using RotationTools::toVec;
70  using RotationTools::getUnitOrthogonal;
71 
72  //-----------------------------------------------------------------
73  // Register the Module
74  //-----------------------------------------------------------------
75  REG_MODULE(TagVertex)
76 
77  //-----------------------------------------------------------------
78  // Implementation
79  //-----------------------------------------------------------------
80 
82  m_Bfield(0), m_fitTruthStatus(0), m_rollbackStatus(0), m_fitPval(0), m_mcTagLifeTime(-1), m_mcPDG(0), m_mcLifeTimeReco(-1),
83  m_deltaT(0), m_deltaTErr(0), m_mcDeltaTau(0), m_mcDeltaT(0),
84  m_shiftZ(0), m_FitType(0), m_tagVl(0),
85  m_truthTagVl(0), m_tagVlErr(0), m_tagVol(0), m_truthTagVol(0), m_tagVolErr(0), m_tagVNDF(0), m_tagVChi2(0), m_tagVChi2IP(0),
86  m_verbose(true)
87  {
88  // Set module properties
89  setDescription("Tag side Vertex Fitter for modular analysis");
90 
91  // Parameter definitions
92  addParam("listName", m_listName, "name of particle list", string(""));
93  addParam("confidenceLevel", m_confidenceLevel,
94  "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",
95  0.001);
96  addParam("MCAssociation", m_useMCassociation,
97  "'': no MC association. breco: use standard Breco MC association. internal: use internal MC association", string("breco"));
98  addParam("constraintType", m_constraintType,
99  "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)",
100  string("IP"));
101  addParam("trackFindingType", m_trackFindingType,
102  "Choose how to reconstruct the tracks on the tag side: standard, standard_PXD",
103  string("standard_PXD"));
104  addParam("maskName", m_roeMaskName,
105  "Choose ROE mask to get particles from ", string(""));
106  addParam("askMCInformation", m_mcInfo,
107  "TRUE when requesting MC Information from the tracks performing the vertex fit", false);
108  addParam("reqPXDHits", m_reqPXDHits,
109  "Minimum number of PXD hits for a track to be used in the vertex fit", 0);
110  addParam("fitAlgorithm", m_fitAlgo,
111  "Fitter used for the tag vertex fit: Rave or KFit", string("Rave"));
112  addParam("useTruthInFit", m_useTruthInFit,
113  "Use the true track parameters in the vertex fit", false);
114  addParam("useRollBack", m_useRollBack,
115  "Use rolled back non-primary tracks", false);
116  }
117 
118  void TagVertexModule::initialize()
119  {
120  // magnetic field
121  m_Bfield = BFieldManager::getField(m_BeamSpotCenter).Z() / Unit::T;
122  // RAVE setup
123  analysis::RaveSetup::initialize(1, m_Bfield);
124  B2INFO("TagVertexModule : magnetic field = " << m_Bfield);
125  // truth fit status will be set to 2 only if the MC info cannot be recovered
126  if (m_useTruthInFit) m_fitTruthStatus = 1;
127  // roll back status will be set to 2 only if the MC info cannot be recovered
128  if (m_useRollBack) m_rollbackStatus = 1;
129 
130  //input
132  m_plist.isRequired(m_listName);
133  // output
134  m_verArray.registerInDataStore();
136  //check if the fitting algorithm name is set correctly
137  if (m_fitAlgo != "Rave" && m_fitAlgo != "KFit")
138  B2FATAL("TagVertexModule: invalid fitting algorithm (must be set to either Rave or KFit).");
139  if (m_useRollBack && m_useTruthInFit)
140  B2FATAL("TagVertexModule: invalid fitting option (useRollBack and useTruthInFit cannot be simultaneously set to true).");
141  //temporary while the one track fit is broken
142  if (m_trackFindingType == "singleTrack" || m_trackFindingType == "singleTrack_PXD")
143  B2FATAL("TagVertexModule : the singleTrack option is temporarily broken.");
144  }
145 
146  void TagVertexModule::beginRun()
147  {
148  //TODO: set magnetic field for each run
149  //m_Bfield = BFieldMap::Instance().getBField(m_BeamSpotCenter).Z();
150  }
151 
152  void TagVertexModule::event()
153  {
154  if (!m_plist) {
155  B2ERROR("TagVertexModule: ParticleList " << m_listName << " not found");
156  return;
157  }
158 
159  // output
160  analysis::RaveSetup::initialize(1, m_Bfield);
161 
162  std::vector<unsigned int> toRemove;
163 
164  for (unsigned i = 0; i < m_plist->getListSize(); ++i) {
165  resetReturnParams();
166 
167  Particle* particle = m_plist->getParticle(i);
168  if (m_useMCassociation == "breco" || m_useMCassociation == "internal") BtagMCVertex(particle);
169  bool ok = doVertexFit(particle);
170  if (ok) deltaT(particle);
171 
172  if ((m_fitPval < m_confidenceLevel && m_confidenceLevel != 0)
173  || (m_fitPval <= m_confidenceLevel && m_confidenceLevel == 0)) {
174  toRemove.push_back(particle->getArrayIndex());
175  } else {
176  // save information in the Vertex StoreArray
177  TagVertex* ver = m_verArray.appendNew();
178  // create relation: Particle <-> Vertex
179  particle->addRelationTo(ver);
180  // fill Vertex with content
181  if (ok) {
182  ver->setTagVertex(m_tagV);
183  ver->setTagVertexErrMatrix(m_tagVErrMatrix);
184  ver->setTagVertexPval(m_fitPval);
185  ver->setDeltaT(m_deltaT);
186  ver->setDeltaTErr(m_deltaTErr);
187  ver->setMCTagVertex(m_mcTagV);
188  ver->setMCTagBFlavor(m_mcPDG);
189  ver->setMCDeltaTau(m_mcDeltaTau);
190  ver->setMCDeltaT(m_mcDeltaT);
191  ver->setFitType(m_FitType);
192  ver->setNTracks(m_tagParticles.size());
193  ver->setTagVl(m_tagVl);
194  ver->setTruthTagVl(m_truthTagVl);
195  ver->setTagVlErr(m_tagVlErr);
196  ver->setTagVol(m_tagVol);
197  ver->setTruthTagVol(m_truthTagVol);
198  ver->setTagVolErr(m_tagVolErr);
199  ver->setTagVNDF(m_tagVNDF);
200  ver->setTagVChi2(m_tagVChi2);
201  ver->setTagVChi2IP(m_tagVChi2IP);
202  ver->setVertexFitParticles(m_raveParticles);
203  ver->setVertexFitMCParticles(m_raveMCParticles);
204  ver->setRaveWeights(m_raveWeights);
205  ver->setConstraintType(m_constraintType);
206  ver->setConstraintCenter(m_constraintCenter);
207  ver->setConstraintCov(m_constraintCov);
208  ver->setFitTruthStatus(m_fitTruthStatus);
209  ver->setRollBackStatus(m_rollbackStatus);
210  } else {
211  ver->setTagVertex(m_tagV);
212  ver->setTagVertexPval(-1.);
213  ver->setDeltaT(m_deltaT);
214  ver->setDeltaTErr(m_deltaTErr);
215  ver->setMCTagVertex(m_mcTagV);
216  ver->setMCTagBFlavor(0.);
217  ver->setMCDeltaTau(m_mcDeltaTau);
218  ver->setMCDeltaT(m_mcDeltaT);
219  ver->setFitType(m_FitType);
220  ver->setNTracks(m_tagParticles.size());
221  ver->setTagVl(m_tagVl);
222  ver->setTruthTagVl(m_truthTagVl);
223  ver->setTagVlErr(m_tagVlErr);
224  ver->setTagVol(m_tagVol);
225  ver->setTruthTagVol(m_truthTagVol);
226  ver->setTagVolErr(m_tagVolErr);
227  ver->setTagVNDF(-1111.);
228  ver->setTagVChi2(-1111.);
229  ver->setTagVChi2IP(-1111.);
230  ver->setVertexFitParticles(m_raveParticles);
231  ver->setVertexFitMCParticles(m_raveMCParticles);
232  ver->setRaveWeights(m_raveWeights);
233  ver->setConstraintType(m_constraintType);
234  ver->setConstraintCenter(m_constraintCenter);
235  ver->setConstraintCov(m_constraintCov);
236  ver->setFitTruthStatus(m_fitTruthStatus);
237  ver->setRollBackStatus(m_rollbackStatus);
238  }
239  }
240  }
241  m_plist->removeParticles(toRemove);
242 
243  //free memory allocated by rave. initialize() would be enough, except that we must clean things up before program end...
244  //
245  analysis::RaveSetup::getInstance()->reset();
246  }
247 
248  bool TagVertexModule::doVertexFit(const Particle* Breco)
249  {
250  //reset the fit truth status in case it was set to 2 in a previous fit
251 
252  if (m_useTruthInFit) m_fitTruthStatus = 1;
253 
254  //reset the roll back status in case it was set to 2 in a previous fit
255 
256  if (m_useRollBack) m_rollbackStatus = 1;
257 
258  //set constraint type, reset pVal and B field
259 
260  m_fitPval = 1;
261 
262  if (!(Breco->getRelatedTo<RestOfEvent>())) {
263  m_FitType = -1;
264  return false;
265  }
266 
267  if (m_Bfield == 0) {
268  B2ERROR("TagVertex: No magnetic field");
269  return false;
270  }
271 
272  // recover beam spot info
273 
274  m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
275  m_BeamSpotCov.ResizeTo(3, 3);
276  m_BeamSpotCov = m_beamSpotDB->getCovVertex();
277 
278  //make the beam spot bigger for the standard constraint
279 
280  double beta = PCmsLabTransform().getBoostVector().Mag();
281  double bg = beta / sqrt(1 - beta * beta);
282 
283  //TODO: What's the origin of these numbers?
284  double cut = 8.717575e-02 * bg;
285  m_shiftZ = 4.184436e+02 * bg * 0.0001;
286 
287  //tube length here set to 20 * 2 * c tau beta gamma ~= 0.5 cm, should be enough to not bias the decay
288  //time but should still help getting rid of some pions from kshorts
289  m_constraintCov.ResizeTo(3, 3);
290  if (m_constraintType == "IP") tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(cut);
291  else if (m_constraintType == "tube") tie(m_constraintCenter, m_constraintCov) = findConstraintBTube(Breco, 1000 * cut);
292  else if (m_constraintType == "boost") tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(cut * 200000.);
293  else if (m_constraintType == "breco") tie(m_constraintCenter, m_constraintCov) = findConstraint(Breco, cut * 2000.);
294  else if (m_constraintType == "noConstraint") m_constraintCenter = TVector3(); //zero vector
295  else {
296  B2ERROR("TagVertex: Invalid constraintType selected");
297  return false;
298  }
299 
300  if (m_constraintCenter == vecNaN) {
301  B2ERROR("TagVertex: No correct fit constraint");
302  return false;
303  }
304 
305  /* 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
306  high efficiency, the next algorithm less restrictive is used. I.e, if standard_PXD does not work, the program tries with standard.
307  */
308 
309  m_FitType = 0;
310  double minPVal = (m_fitAlgo != "KFit") ? 0.001 : 0.;
311  bool ok = false;
312 
313  if (m_trackFindingType == "standard_PXD") {
314  m_tagParticles = getTagTracks_standardAlgorithm(Breco, 1);
315  if (m_tagParticles.size() > 0) {
316  ok = makeGeneralFit();
317  m_FitType = 3;
318  }
319  }
320 
321  if (ok == false || m_fitPval < minPVal || m_trackFindingType == "standard") {
322  m_tagParticles = getTagTracks_standardAlgorithm(Breco, m_reqPXDHits);
323  ok = m_tagParticles.size() > 0;
324  if (ok) {
325  ok = makeGeneralFit();
326  m_FitType = 4;
327  }
328  }
329 
330  if ((ok == false || (m_fitPval <= 0. && m_fitAlgo == "Rave")) && m_constraintType != "noConstraint") {
331  tie(m_constraintCenter, m_constraintCov) = findConstraintBoost(cut * 200000.);
332  ok = (m_constraintCenter != vecNaN);
333  if (ok) {
334  m_tagParticles = getTagTracks_standardAlgorithm(Breco, m_reqPXDHits);
335  ok = (m_tagParticles.size() > 0);
336  }
337  if (ok) {
338  ok = makeGeneralFit();
339  m_FitType = 5;
340  }
341  }
342 
343  return ok;
344  }
345 
346 
351  static TLorentzVector flipVector(TLorentzVector vIn)
352  {
353  TLorentzVector vCMS = PCmsLabTransform::labToCms(vIn);
354  vCMS.SetVect(-vCMS.Vect());
355  return PCmsLabTransform::cmsToLab(vCMS);
356  }
357 
358 
359  pair<TVector3, TMatrixDSym> TagVertexModule::findConstraint(const Particle* Breco, double cut) const
360  {
361  if (Breco->getPValue() < 0.) return make_pair(vecNaN, matNaN);
362 
363  TMatrixDSym beamSpotCov(3);
364  beamSpotCov = m_beamSpotDB->getCovVertex();
365 
366  analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, beamSpotCov);
367 
368  double pmag = Breco->getMomentumMagnitude();
369  double xmag = (Breco->getVertex() - m_BeamSpotCenter).Mag();
370 
371 
372  TMatrixDSym TerrMatrix = Breco->getMomentumVertexErrorMatrix();
373  TMatrixDSym PerrMatrix(7);
374 
375  for (int i = 0; i < 3; ++i) {
376  for (int j = 0; j < 3; ++j) {
377  if (i == j) {
378  PerrMatrix(i, j) = (beamSpotCov(i, j) + TerrMatrix(i, j)) * pmag / xmag;
379  } else {
380  PerrMatrix(i, j) = TerrMatrix(i, j);
381  }
382  PerrMatrix(i + 4, j + 4) = TerrMatrix(i + 4, j + 4);
383  }
384  }
385 
386  PerrMatrix(3, 3) = 0.;
387 
388  //Copy Breco, but use errors as are in PerrMatrix
389  Particle* Breco2 = ParticleCopy::copyParticle(Breco);
390  Breco2->setMomentumVertexErrorMatrix(PerrMatrix);
391 
392 
393  const Particle* BRecoRes = doVertexFitForBTube(Breco2, "kalman");
394  if (BRecoRes->getPValue() < 0) return make_pair(vecNaN, matNaN); //problems
395 
396  // Overall error matrix
397  TMatrixDSym errFinal = TMatrixDSym(Breco->getVertexErrorMatrix() + BRecoRes->getVertexErrorMatrix());
398 
399  // TODO : to be developed the extraction of the momentum from the rave fitted track
400 
401  // Get expected pBtag 4-momentum using transverse-momentum conservation
402  TVector3 BvertDiff = Breco->getVertex() - BRecoRes->getVertex();
403  TLorentzVector pBrecEstimate(pmag / BvertDiff.Mag() * BvertDiff, Breco->getPDGMass());
404  TLorentzVector pBtagEstimate = flipVector(pBrecEstimate);
405 
406  // rotate err-matrix such that pBrecEstimate goes to eZ
407  TMatrixD TubeZ = rotateTensorInv(pBrecEstimate.Vect(), errFinal);
408 
409  TubeZ(2, 2) = cut * cut;
410  TubeZ(2, 0) = 0; TubeZ(0, 2) = 0;
411  TubeZ(2, 1) = 0; TubeZ(1, 2) = 0;
412 
413 
414  // rotate err-matrix such that eZ goes to pBtagEstimate
415  TMatrixD Tube = rotateTensor(pBtagEstimate.Vect(), TubeZ);
416 
417  // Standard algorithm needs no shift
418  return make_pair(m_BeamSpotCenter, toSymMatrix(Tube));
419  }
420 
421  pair<TVector3, TMatrixDSym> TagVertexModule::findConstraintBTube(const Particle* Breco, double cut)
422  {
423  //Use Breco as the creator of the B tube.
424  if ((Breco->getVertexErrorMatrix()(2, 2)) == 0.0) {
425  B2WARNING("In TagVertexModule::findConstraintBTube: cannot get a proper vertex for BReco. BTube constraint replaced by Boost.");
426  return findConstraintBoost(cut);
427  }
428 
429 
430  //vertex fit will give the intersection between the beam spot and the trajectory of the B
431  //(base of the BTube, or primary vtx cov matrix)
432  const Particle* tubecreatorBCopy = doVertexFitForBTube(Breco, "avf");
433  if (tubecreatorBCopy->getPValue() < 0) return make_pair(vecNaN, matNaN); //if problems
434 
435 
436  //get direction of B tag = opposite direction of B rec in CMF
437  TLorentzVector pBrec = tubecreatorBCopy->get4Vector();
438 
439  //if we want the true info, replace the 4vector by the true one
440  if (m_useTruthInFit) {
441  const MCParticle* mcBr = Breco->getRelated<MCParticle>();
442  if (mcBr)
443  pBrec = mcBr->get4Vector();
444  else
445  m_fitTruthStatus = 2;
446  }
447  TLorentzVector pBtag = flipVector(pBrec);
448 
449  //To create the B tube, strategy is: take the primary vtx cov matrix, and add to it a cov
450  //matrix corresponding to an very big error in the direction of the B tag
451  TMatrixDSym pv = tubecreatorBCopy->getVertexErrorMatrix();
452 
453  //print some stuff if wanted
454  if (m_verbose) {
455  B2DEBUG(10, "Brec decay vertex before fit: " << printVector(Breco->getVertex()));
456  B2DEBUG(10, "Brec decay vertex after fit: " << printVector(tubecreatorBCopy->getVertex()));
457  B2DEBUG(10, "Brec direction before fit: " << printVector((1. / Breco->getP()) * Breco->getMomentum()));
458  B2DEBUG(10, "Brec direction after fit: " << printVector((1. / tubecreatorBCopy->getP()) * tubecreatorBCopy->getMomentum()));
459  B2DEBUG(10, "IP position: " << printVector(m_BeamSpotCenter));
460  B2DEBUG(10, "IP covariance: " << printMatrix(m_BeamSpotCov));
461  B2DEBUG(10, "Brec primary vertex: " << printVector(tubecreatorBCopy->getVertex()));
462  B2DEBUG(10, "Brec PV covariance: " << printMatrix(pv));
463  B2DEBUG(10, "BTag direction: " << printVector((1. / pBtag.P())*pBtag.Vect()));
464  }
465 
466  //make a long error matrix along BTag direction
467  TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
468 
469 
470  // make rotation matrix from z axis to BTag line of flight
471  TMatrixD longerrorRotated = rotateTensor(pBtag.Vect(), longerror);
472 
473  //pvNew will correspond to the covariance matrix of the B tube
474  TMatrixD pvNew = TMatrixD(pv) + longerrorRotated;
475 
476  //set the constraint
477  TVector3 constraintCenter = tubecreatorBCopy->getVertex();
478 
479  //if we want the true info, set the centre of the constraint to the primary vertex
480  if (m_useTruthInFit) {
481  const MCParticle* mcBr = Breco->getRelated<MCParticle>();
482  if (mcBr) {
483  constraintCenter = mcBr->getProductionVertex();
484  }
485  }
486 
487  if (m_verbose) {
488  B2DEBUG(10, "IPTube covariance: " << printMatrix(pvNew));
489  }
490 
491  //The following is done to do the BTube constraint with a virtual track
492  //(ie KFit way)
493 
494  m_tagMomentum = pBtag;
495 
496  m_pvCov.ResizeTo(pv);
497  m_pvCov = pv;
498 
499  return make_pair(constraintCenter, toSymMatrix(pvNew));
500  }
501 
502  pair<TVector3, TMatrixDSym> TagVertexModule::findConstraintBoost(double cut, double shiftAlongBoost) const
503  {
504  //make a long error matrix along boost direction
505  TMatrixD longerror(3, 3); longerror(2, 2) = cut * cut;
506  TVector3 boostDir = PCmsLabTransform().getBoostVector().Unit();
507  TMatrixD longerrorRotated = rotateTensor(boostDir, longerror);
508 
509  //Extend error of BeamSpotCov matrix in the boost direction
510  TMatrixDSym beamSpotCov = m_beamSpotDB->getCovVertex();
511  TMatrixD Tube = TMatrixD(beamSpotCov) + longerrorRotated;
512 
513  // Standard algorithm needs no shift
514  TVector3 constraintCenter = m_BeamSpotCenter;
515 
516  // The constraint used in the Single Track Fit needs to be shifted in the boost direction.
517  if (shiftAlongBoost > -1000) {
518  constraintCenter += shiftAlongBoost * boostDir;
519  }
520 
521  return make_pair(constraintCenter, toSymMatrix(Tube));
522  }
523 
525  static double getProperLifeTime(const MCParticle* mc)
526  {
527  double beta = mc->getMomentum().Mag() / mc->getEnergy();
528  return 1e3 * mc->getLifetime() * sqrt(1 - pow(beta, 2));
529  }
530 
531  void TagVertexModule::BtagMCVertex(const Particle* Breco)
532  {
533  //fill vector with mcB (intended order: Reco, Tag)
534  vector<const MCParticle*> mcBs;
535  for (const MCParticle& mc : m_mcParticles) {
536  if (abs(mc.getPDG()) == abs(Breco->getPDGCode()))
537  mcBs.push_back(&mc);
538  }
539  //too few Bs
540  if (mcBs.size() < 2) return;
541 
542  if (mcBs.size() > 2) {
543  B2WARNING("TagVertexModule:: Too many Bs found in MC");
544  }
545 
546  auto isReco = [&](const MCParticle * mc) {
547  return (m_useMCassociation == "breco") ? (mc == Breco->getRelated<MCParticle>())
548  : compBrecoBgen(Breco, mc); //internal association
549  };
550 
551  //nothing matched?
552  if (!isReco(mcBs[0]) && !isReco(mcBs[1])) {
553  return;
554  }
555 
556  //first is Tag, second Reco -> swap the order
557  if (!isReco(mcBs[0]) && isReco(mcBs[1]))
558  swap(mcBs[0], mcBs[1]);
559 
560  //both matched -> use closest vertex dist as Reco
561  if (isReco(mcBs[0]) && isReco(mcBs[1])) {
562  double dist0 = (mcBs[0]->getDecayVertex() - Breco->getVertex()).Mag2();
563  double dist1 = (mcBs[1]->getDecayVertex() - Breco->getVertex()).Mag2();
564  if (dist0 > dist1)
565  swap(mcBs[0], mcBs[1]);
566  }
567 
568  m_mcVertReco = mcBs[0]->getDecayVertex();
569  m_mcLifeTimeReco = getProperLifeTime(mcBs[0]);
570  m_mcTagV = mcBs[1]->getDecayVertex();
571  m_mcTagLifeTime = getProperLifeTime(mcBs[1]);
572  m_mcPDG = mcBs[1]->getPDG();
573  }
574 
575  // static
576  bool TagVertexModule::compBrecoBgen(const Particle* Breco, const MCParticle* Bgen)
577  {
578 
579  bool isDecMode = true;
580 
581  const std::vector<Belle2::Particle*> recDau = Breco->getDaughters();
582  const std::vector<Belle2::MCParticle*> genDau = Bgen->getDaughters();
583 
584  if (recDau.size() > 0 && genDau.size() > 0) {
585  for (auto dauRec : recDau) {
586  bool isDau = false;
587  for (auto dauGen : genDau) {
588  if (dauGen->getPDG() == dauRec->getPDGCode())
589  isDau = compBrecoBgen(dauRec, dauGen) ;
590  }
591  if (!isDau) isDecMode = false;
592  }
593  } else {
594  if (recDau.size() == 0) { //&& genDau.size()==0){
595  if (Bgen->getPDG() != Breco->getPDGCode()) isDecMode = false;;
596  } else {isDecMode = false;}
597  }
598 
599  return isDecMode;
600  }
601 
602  // STANDARD FIT ALGORITHM
603  /* This algorithm basically takes all the tracks coming from the Rest Of Events and send them to perform a multi-track fit
604  The option to request PXD hits for the tracks can be chosen by the user.
605  */
606  std::vector<const Particle*> TagVertexModule::getTagTracks_standardAlgorithm(const Particle* Breco, int reqPXDHits) const
607  {
608  std::vector<const Particle*> fitParticles;
609  const RestOfEvent* roe = Breco->getRelatedTo<RestOfEvent>();
610  if (!roe) return fitParticles;
611  //load all particles from the ROE
612  std::vector<const Particle*> ROEParticles = roe->getChargedParticles(m_roeMaskName, 0 , false);
613  if (ROEParticles.size() == 0) return fitParticles;
614 
615  for (auto& ROEParticle : ROEParticles) {
616  HitPatternVXD roeTrackPattern = ROEParticle->getTrackFitResult()->getHitPatternVXD();
617 
618  if (roeTrackPattern.getNPXDHits() >= reqPXDHits) {
619  fitParticles.push_back(ROEParticle);
620  }
621  }
622  return fitParticles;
623  }
624 
625  vector<ParticleAndWeight> TagVertexModule::getParticlesWithoutKS(const vector<const Particle*>& tagParticles,
626  double massWindowWidth) const
627  {
628  vector<ParticleAndWeight> particleAndWeights;
629 
630  ParticleAndWeight particleAndWeight;
631  particleAndWeight.mcParticle = 0;
632  particleAndWeight.weight = -1111.;
633 
634  // remove tracks from KS
635  for (unsigned i = 0; i < tagParticles.size(); ++i) {
636  const Particle* particle1 = tagParticles.at(i);
637  if (!particle1) continue;
638  TLorentzVector mom1 = particle1->get4Vector();
639  if (!isfinite(mom1.Mag2())) continue;
640 
641  //is from Ks decay?
642  bool isKsDau = false;
643  for (unsigned j = 0; j < tagParticles.size(); ++j) {
644  if (i == j) continue;
645  const Particle* particle2 = tagParticles.at(j);
646  if (!particle2) continue;
647  TLorentzVector mom2 = particle2->get4Vector();
648  if (!isfinite(mom2.Mag2())) continue;
649  double mass = (mom1 + mom2).M();
650  if (abs(mass - Const::K0Mass) < massWindowWidth) {
651  isKsDau = true;
652  break;
653  }
654  }
655  //if from Ks decay, skip
656  if (isKsDau) continue;
657 
658  particleAndWeight.particle = particle1;
659 
660  if (m_useMCassociation == "breco" || m_useMCassociation == "internal")
661  particleAndWeight.mcParticle = particle1->getRelatedTo<MCParticle>();
662 
663  particleAndWeights.push_back(particleAndWeight);
664 
665  }
666 
667  return particleAndWeights;
668  }
669 
670  bool TagVertexModule::makeGeneralFit()
671  {
672  if (m_fitAlgo == "Rave") return makeGeneralFitRave();
673  else if (m_fitAlgo == "KFit") return makeGeneralFitKFit();
674  return false;
675  }
676 
677  void TagVertexModule::fillParticles(vector<ParticleAndWeight>& particleAndWeights)
678  {
679  unsigned n = particleAndWeights.size();
680  sort(particleAndWeights.begin(), particleAndWeights.end(),
681  [](const ParticleAndWeight & a, const ParticleAndWeight & b) { return a.weight > b.weight; });
682 
683  m_raveParticles.resize(n);
684  m_raveWeights.resize(n);
685  m_raveMCParticles.resize(n);
686 
687  for (unsigned i = 0; i < n; ++i) {
688  m_raveParticles.at(i) = particleAndWeights.at(i).particle;
689  m_raveMCParticles.at(i) = particleAndWeights.at(i).mcParticle;
690  m_raveWeights.at(i) = particleAndWeights.at(i).weight;
691  }
692  }
693 
694  void TagVertexModule::fillTagVinfo(const TVector3& tagVpos, const TMatrixDSym& tagVposErr)
695  {
696  m_tagV = tagVpos;
697 
698  if (m_constraintType != "noConstraint") {
699  TMatrixDSym tubeInv = m_constraintCov;
700  tubeInv.Invert();
701  TVectorD dV = toVec(m_tagV - m_BeamSpotCenter);
702  m_tagVChi2IP = tubeInv.Similarity(dV);
703  }
704 
705  m_tagVErrMatrix.ResizeTo(tagVposErr);
706  m_tagVErrMatrix = tagVposErr;
707  }
708 
709  bool TagVertexModule::makeGeneralFitRave()
710  {
711  // apply constraint
712  analysis::RaveSetup::getInstance()->unsetBeamSpot();
713  if (m_constraintType != "noConstraint")
714  analysis::RaveSetup::getInstance()->setBeamSpot(m_constraintCenter, m_constraintCov);
716 
717  //feed rave with tracks without Kshorts
718  vector<ParticleAndWeight> particleAndWeights = getParticlesWithoutKS(m_tagParticles);
719 
720  for (const auto& pw : particleAndWeights) {
721  try {
722  if (m_useTruthInFit) {
723  if (pw.mcParticle) {
724  TrackFitResult tfr(getTrackWithTrueCoordinates(pw));
725  rFit.addTrack(&tfr);
726  } else
727  m_fitTruthStatus = 2;
728  } else if (m_useRollBack) {
729  if (pw.mcParticle) {
730  TrackFitResult tfr(getTrackWithRollBackCoordinates(pw));
731  rFit.addTrack(&tfr);
732  } else
733  m_rollbackStatus = 2;
734  } else {
735  rFit.addTrack(pw.particle->getTrackFitResult());
736  }
737  } catch (const rave::CheckedFloatException&) {
738  B2ERROR("Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
739  }
740  }
741 
742  //perform fit
743 
744  int isGoodFit(-1);
745 
746  try {
747  isGoodFit = rFit.fit("avf");
748  // if problems
749  if (isGoodFit < 1) return false;
750  } catch (const rave::CheckedFloatException&) {
751  B2ERROR("Exception caught in TagVertexModule::makeGeneralFitRave(): Invalid inputs (nan/inf)?");
752  return false;
753  }
754 
755  //save the track info for later use
756 
757  for (unsigned int i(0); i < particleAndWeights.size() && isGoodFit >= 1; ++i)
758  particleAndWeights.at(i).weight = rFit.getWeight(i);
759 
760  //Tracks are sorted from highest rave weight to lowest
761 
762  fillParticles(particleAndWeights);
763 
764  //if the fit is good, save the infos related to the vertex
765  fillTagVinfo(rFit.getPos(0), rFit.getCov(0));
766 
767  //fill quality variables
768  m_tagVNDF = rFit.getNdf(0);
769  m_tagVChi2 = rFit.getChi2(0);
770  m_fitPval = rFit.getPValue();
771 
772  return true;
773  }
774 
775  bool TagVertexModule::makeGeneralFitKFit()
776  {
777  //initialize KFit
779  kFit.setMagneticField(m_Bfield);
780 
781  // apply constraint
782  if (m_constraintType != "noConstraint") {
783  if (m_constraintType == "tube") {
784  CLHEP::HepSymMatrix err(7, 0);
785  //copy m_pvCov to the end of err matrix
786  err.sub(5, ROOTToCLHEP::getHepSymMatrix(m_pvCov));
787  kFit.setIpTubeProfile(
788  ROOTToCLHEP::getHepLorentzVector(m_tagMomentum),
789  ROOTToCLHEP::getPoint3D(m_constraintCenter),
790  err,
791  0.);
792  } else {
793  kFit.setIpProfile(ROOTToCLHEP::getPoint3D(m_constraintCenter),
794  ROOTToCLHEP::getHepSymMatrix(m_constraintCov));
795  }
796  }
797 
798  //feed KFit with tracks without Kshorts
799  vector<ParticleAndWeight> particleAndWeights = getParticlesWithoutKS(m_tagParticles);
800 
801  int nTracksAdded = 0;
802  for (auto& pawi : particleAndWeights) {
803  int addedOK = 1;
804  if (m_useTruthInFit) {
805  if (pawi.mcParticle) {
806  addedOK = kFit.addTrack(
807  ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
808  ROOTToCLHEP::getPoint3D(getTruePoca(pawi)),
809  ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
810  pawi.particle->getCharge());
811  } else {
812  m_fitTruthStatus = 2;
813  }
814  } else if (m_useRollBack) {
815  if (pawi.mcParticle) {
816  addedOK = kFit.addTrack(
817  ROOTToCLHEP::getHepLorentzVector(pawi.mcParticle->get4Vector()),
818  ROOTToCLHEP::getPoint3D(getRollBackPoca(pawi)),
819  ROOTToCLHEP::getHepSymMatrix(pawi.particle->getMomentumVertexErrorMatrix()),
820  pawi.particle->getCharge());
821  } else {
822  m_rollbackStatus = 2;
823  }
824  } else {
825  addedOK = kFit.addParticle(pawi.particle);
826  }
827 
828  if (addedOK == 0) {
829  ++nTracksAdded;
830  pawi.weight = 1.;
831  } else {
832  B2WARNING("TagVertexModule::makeGeneralFitKFit: failed to add a track");
833  pawi.weight = 0.;
834  }
835  }
836 
837  //perform fit if there are enough tracks
838  if ((nTracksAdded < 2 && m_constraintType == "noConstraint") || nTracksAdded < 1)
839  return false;
840 
841  int isGoodFit = kFit.doFit();
842  if (isGoodFit != 0) return false;
843 
844  //save the track info for later use
845  //Tracks are sorted by weight, ie pushing the tracks with 0 weight (from KS) to the end of the list
846  fillParticles(particleAndWeights);
847 
848  //Save the infos related to the vertex
849  fillTagVinfo(CLHEPToROOT::getTVector3(kFit.getVertex()),
850  CLHEPToROOT::getTMatrixDSym(kFit.getVertexError()));
851 
852  m_tagVNDF = kFit.getNDF();
853  m_tagVChi2 = kFit.getCHIsq();
854  m_fitPval = TMath::Prob(m_tagVChi2, m_tagVNDF);
855 
856  return true;
857  }
858 
859  void TagVertexModule::deltaT(const Particle* Breco)
860  {
861 
862  TVector3 boost = PCmsLabTransform().getBoostVector();
863  TVector3 boostDir = boost.Unit();
864  double bg = boost.Mag() / sqrt(1 - boost.Mag2());
865  double c = Const::speedOfLight / 1000.; // cm ps-1
866 
867  //Reconstructed DeltaL & DeltaT in the boost direction
868  TVector3 dVert = Breco->getVertex() - m_tagV; //reconstructed vtxReco - vtxTag
869  double dl = dVert.Dot(boostDir);
870  m_deltaT = dl / (bg * c);
871 
872  //Truth DeltaL & approx DeltaT in the boost direction
873  TVector3 MCdVert = m_mcVertReco - m_mcTagV; //truth vtxReco - vtxTag
874  double MCdl = MCdVert.Dot(boostDir);
875  m_mcDeltaT = MCdl / (bg * c);
876 
877  // MCdeltaTau=tauRec-tauTag
878  m_mcDeltaTau = m_mcLifeTimeReco - m_mcTagLifeTime;
879  if (m_mcLifeTimeReco == -1 || m_mcTagLifeTime == -1)
880  m_mcDeltaTau = realNaN;
881 
882  TVectorD bVec = toVec(boostDir);
883 
884  //TagVertex error in boost dir
885  m_tagVlErr = sqrt(m_tagVErrMatrix.Similarity(bVec));
886 
887  //bReco error in boost dir
888  double bRecoErrL = sqrt(Breco->getVertexErrorMatrix().Similarity(bVec));
889 
890  //Delta t error
891  m_deltaTErr = hypot(m_tagVlErr, bRecoErrL) / (bg * c);
892 
893  m_tagVl = m_tagV.Dot(boostDir);
894  m_truthTagVl = m_mcTagV.Dot(boostDir);
895 
896  // calculate tagV component and error in the direction orthogonal to the boost
897  TVector3 oboost = getUnitOrthogonal(boostDir);
898  TVectorD oVec = toVec(oboost);
899 
900  //TagVertex error in boost-orthogonal dir
901  m_tagVolErr = sqrt(m_tagVErrMatrix.Similarity(oVec));
902 
903  m_tagVol = m_tagV.Dot(oboost);
904  m_truthTagVol = m_mcTagV.Dot(oboost);
905  }
906 
907  Particle* TagVertexModule::doVertexFitForBTube(const Particle* motherIn, std::string fitType) const
908  {
909  //make a copy of motherIn to not modify the original object
910  Particle* mother = ParticleCopy::copyParticle(motherIn);
911 
912  //Here rave is used to find the upsilon(4S) vtx as the intersection
913  //between the mother B trajectory and the beam spot
914  analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, m_BeamSpotCov);
915 
917  rsg.addTrack(mother);
918  int nvert = rsg.fit(fitType);
919  if (nvert != 1) {
920  mother->setPValue(-1); //error
921  return mother;
922  } else {
923  rsg.updateDaughters();
924  return mother;
925  }
926  }
927 
928 
929 
930  TrackFitResult TagVertexModule::getTrackWithTrueCoordinates(ParticleAndWeight const& paw) const
931  {
932  if (!paw.mcParticle) {
933  B2ERROR("In TagVertexModule::getTrackWithTrueCoordinate: no MC particle set");
934  return TrackFitResult();
935  }
936 
937  const TrackFitResult* tfr(paw.particle->getTrackFitResult());
938 
939  return TrackFitResult(getTruePoca(paw),
940  paw.mcParticle->getMomentum(),
941  tfr->getCovariance6(),
942  tfr->getChargeSign(),
943  tfr->getParticleType(),
944  tfr->getPValue(),
945  m_Bfield, 0, 0, tfr->getNDF());
946  }
947 
948  // static
949  TVector3 TagVertexModule::getTruePoca(ParticleAndWeight const& paw)
950  {
951  if (!paw.mcParticle) {
952  B2ERROR("In TagVertexModule::getTruePoca: no MC particle set");
953  return TVector3(0., 0., 0.);
954  }
955 
956  return DistanceTools::poca(paw.mcParticle->getProductionVertex(),
957  paw.mcParticle->getMomentum(),
959  }
960 
961  TrackFitResult TagVertexModule::getTrackWithRollBackCoordinates(ParticleAndWeight const& paw)
962  {
963  const TrackFitResult* tfr(paw.particle->getTrackFitResult());
964 
965  return TrackFitResult(getRollBackPoca(paw),
966  tfr->getMomentum(),
967  tfr->getCovariance6(),
968  tfr->getChargeSign(),
969  tfr->getParticleType(),
970  tfr->getPValue(),
971  m_Bfield, 0, 0, tfr->getNDF());
972  }
973 
974  TVector3 TagVertexModule::getRollBackPoca(ParticleAndWeight const& paw)
975  {
976  if (!paw.mcParticle) {
977  B2ERROR("In TagVertexModule::getTruePoca: no MC particle set");
978  return TVector3(0., 0., 0.);
979  }
980 
981  return paw.particle->getTrackFitResult()->getPosition() - paw.mcParticle->getProductionVertex() + m_mcTagV;
982  }
983 
984  void TagVertexModule::resetReturnParams()
985  {
986  m_raveParticles.resize(0);
987  m_raveMCParticles.resize(0);
988  m_tagParticles.resize(0);
989  m_raveWeights.resize(0);
990 
991  m_fitPval = realNaN;
992  m_tagV = vecNaN;
993  m_tagVErrMatrix.ResizeTo(matNaN);
994  m_tagVErrMatrix = matNaN;
995  m_mcTagV = vecNaN;
996  m_mcVertReco = vecNaN;
997  m_deltaT = realNaN;
998  m_deltaTErr = realNaN;
999  m_mcDeltaTau = realNaN;
1000  m_constraintCov.ResizeTo(matNaN);
1001  m_constraintCov = matNaN;
1002  m_constraintCenter = vecNaN;
1003  m_tagVl = realNaN;
1004  m_truthTagVl = realNaN;
1005  m_tagVlErr = realNaN;
1006  m_tagVol = realNaN;
1007  m_truthTagVol = realNaN;
1008  m_tagVolErr = realNaN;
1009  m_tagVNDF = realNaN;
1010  m_tagVChi2 = realNaN;
1011  m_tagVChi2IP = realNaN;
1012  m_pvCov.ResizeTo(matNaN);
1013  m_pvCov = matNaN;
1014  m_tagMomentum = TLorentzVector(vecNaN, realNaN);
1015  }
1016 
1017  //The following functions are just here to help printing stuff
1018 
1019  // static
1020  std::string TagVertexModule::printVector(const TVector3& vec)
1021  {
1022  std::ostringstream oss;
1023  int w = 14;
1024  oss << "(" << std::setw(w) << vec[0] << ", " << std::setw(w) << vec[1] << ", " << std::setw(w) << vec[2] << ")" << std::endl;
1025  return oss.str();
1026  }
1027 
1028  // static
1029  std::string TagVertexModule::printMatrix(const TMatrixD& mat)
1030  {
1031  std::ostringstream oss;
1032  int w = 14;
1033  for (int i = 0; i < mat.GetNrows(); ++i) {
1034  for (int j = 0; j < mat.GetNcols(); ++j) {
1035  oss << std::setw(w) << mat(i, j) << " ";
1036  }
1037  oss << endl;
1038  }
1039  return oss.str();
1040  }
1041 
1042  // static
1043  std::string TagVertexModule::printMatrix(const TMatrixDSym& mat)
1044  {
1045  std::ostringstream oss;
1046  int w = 14;
1047  for (int i = 0; i < mat.GetNrows(); ++i) {
1048  for (int j = 0; j < mat.GetNcols(); ++j) {
1049  oss << std::setw(w) << mat(i, j) << " ";
1050  }
1051  oss << endl;
1052  }
1053  return oss.str();
1054  }
1056 } // end Belle2 namespace
Hit pattern of the VXD within a track.
Definition: HitPatternVXD.h:37
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
TVector3 getMomentum() const
Return momentum.
Definition: MCParticle.h:198
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
TLorentzVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:207
TVector3 getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:189
Base class for Modules.
Definition: Module.h:72
Class to hold Lorentz transformations from/to CMS and boost vector.
TVector3 getBoostVector() const
Returns boost vector (beta=p/E)
Class to store reconstructed particles.
Definition: Particle.h:74
TMatrixFSym getVertexErrorMatrix() const
Returns the 3x3 position error sub-matrix.
Definition: Particle.cc:457
float getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
Definition: Particle.cc:621
TVector3 getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
Definition: Particle.h:551
float getPValue() const
Returns chi^2 probability of fit if done or -1.
Definition: Particle.h:587
TVector3 getMomentum() const
Returns momentum vector.
Definition: Particle.h:488
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:392
float getP() const
Returns momentum magnitude (same as getMomentumMagnitude but with shorter name)
Definition: Particle.h:506
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
Definition: Particle.cc:645
TLorentzVector get4Vector() const
Returns Lorentz vector.
Definition: Particle.h:477
void setMomentumVertexErrorMatrix(const TMatrixFSym &errMatrix)
Sets 7x7 error matrix.
Definition: Particle.cc:403
float getMomentumMagnitude() const
Returns momentum magnitude.
Definition: Particle.h:497
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
Definition: Particle.cc:430
const TrackFitResult * getTrackFitResult() const
Returns the pointer to the TrackFitResult that was used to create this Particle (ParticleType == c_Tr...
Definition: Particle.cc:823
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to 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:57
std::vector< const Particle * > getChargedParticles(const std::string &maskName="", unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
Definition: RestOfEvent.cc:109
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
Tag side Vertex Fitter module for modular analysis.
TagVertex data object: contains Btag Vertex and DeltaT.
Definition: TagVertex.h:34
void setConstraintType(const std::string &constraintType)
Set the type of the constraint for the tag fit.
Definition: TagVertex.cc:325
void setTagVlErr(float TagVlErr)
Set the error of the tagV component in the boost direction.
Definition: TagVertex.cc:263
void setTagVertex(const TVector3 &TagVertex)
Set BTag Vertex.
Definition: TagVertex.cc:198
void setTruthTagVl(float TruthTagVl)
Set the MC tagV component in the boost direction.
Definition: TagVertex.cc:258
void setTruthTagVol(float TruthTagVol)
Set the tagV component in the direction orthogonal to the boost.
Definition: TagVertex.cc:273
void setMCTagBFlavor(int mcTagBFlavor)
Set generated Btag PDG code.
Definition: TagVertex.cc:228
void setTagVolErr(float TagVolErr)
Set the error of the tagV component in the direction orthogonal to the boost.
Definition: TagVertex.cc:278
void setTagVNDF(float TagVNDF)
Set the number of degrees of freedom in the tag vertex fit.
Definition: TagVertex.cc:283
void setDeltaTErr(float DeltaTErr)
Set DeltaTErr.
Definition: TagVertex.cc:218
void setNTracks(int nTracks)
Set number of tracks used in the fit.
Definition: TagVertex.cc:248
void setTagVChi2(float TagVChi2)
Set the chi^2 value of the tag vertex fit result.
Definition: TagVertex.cc:288
void setMCDeltaT(float mcDeltaT)
Set generated DeltaT (in kin.
Definition: TagVertex.cc:238
void setRollBackStatus(int backStatus)
Set the status of the fit performed with the rolled back tracks.
Definition: TagVertex.cc:349
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:304
void setMCTagVertex(const TVector3 &mcTagVertex)
Set generated BTag Vertex.
Definition: TagVertex.cc:223
void setTagVol(float TagVol)
Set the tagV component in the direction orthogonal to the boost.
Definition: TagVertex.cc:268
void setDeltaT(float DeltaT)
Set DeltaT.
Definition: TagVertex.cc:213
void setRaveWeights(const std::vector< double > &raveWeights)
Set the weights used by Rave in the tag vtx fit.
Definition: TagVertex.cc:309
void setTagVertexPval(float TagVertexPval)
Set BTag Vertex P value.
Definition: TagVertex.cc:208
void setMCDeltaTau(float mcDeltaTau)
Set generated DeltaT.
Definition: TagVertex.cc:233
void setTagVl(float TagVl)
Set the tagV component in the boost direction.
Definition: TagVertex.cc:253
void setTagVertexErrMatrix(const TMatrixDSym &TagVertexErrMatrix)
Set BTag Vertex (3x3) error matrix.
Definition: TagVertex.cc:203
void setConstraintCenter(const TVector3 &constraintCenter)
Set the centre of the constraint for the tag fit.
Definition: TagVertex.cc:314
void setConstraintCov(const TMatrixDSym &constraintCov)
Set the covariance matrix of the constraint for the tag fit.
Definition: TagVertex.cc:319
void setFitType(float FitType)
Set fit algo type.
Definition: TagVertex.cc:243
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:298
void setTagVChi2IP(float TagVChi2IP)
Set the IP component of the chi^2 value of the tag vertex fit result.
Definition: TagVertex.cc:293
void setFitTruthStatus(int truthStatus)
Set the status of the fit performed with the truth info of the tracks.
Definition: TagVertex.cc:344
Values of the result of a track fit with a given particle hypothesis.
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.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
int getNDF() const
Getter for number of degrees of freedom of the track fit.
TVector3 getPosition() const
Getter for vector of position at closest approach of track in r/phi projection.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
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.
void addTrack(const Particle *const aParticlePtr)
add a track (in the format of a Belle2::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.
TVector3 getPos(VecSize vertexId=0) const
get the position 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.
Definition: VertexFitKFit.h:32
static const double realNaN
shortcut for NaN of double type
static TLorentzVector flipVector(TLorentzVector vIn)
Get vector which is opposite to vIn in CMS ref frame Be aware that input vIn and output are in the La...
static const TVector3 vecNaN(realNaN, realNaN, realNaN)
vector with NaN entries
static const TMatrixDSym matNaN(3,(double[]) { realNaN, realNaN, realNaN, realNaN, realNaN, realNaN, realNaN, realNaN, realNaN })
3x3 matrix with NaN entries
static double getProperLifeTime(const MCParticle *mc)
proper life time, i.e.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
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