10 #include <analysis/variables/TimeDependentVariables.h>
12 #include <framework/dbobjects/BeamParameters.h>
15 #include <analysis/dataobjects/Particle.h>
16 #include <analysis/dataobjects/TagVertex.h>
17 #include <mdst/dataobjects/MCParticle.h>
20 #include <analysis/utility/DistanceTools.h>
21 #include <analysis/utility/PCmsLabTransform.h>
22 #include <analysis/utility/RotationTools.h>
23 #include <analysis/utility/ReferenceFrame.h>
26 #include <framework/gearbox/Const.h>
27 #include <framework/geometry/B2Vector3.h>
45 using RotationTools::getUnitOrthogonal;
46 using RotationTools::toVec;
48 static const double realNaN = std::numeric_limits<double>::quiet_NaN();
49 static const B2Vector3D vecNaN(realNaN, realNaN, realNaN);
54 double particleTagVx(
const Particle* particle)
56 auto* vert = particle->getRelatedTo<TagVertex>();
57 if (!vert)
return realNaN;
58 return vert->getTagVertex().X();
61 double particleTagVy(
const Particle* particle)
63 auto* vert = particle->getRelatedTo<TagVertex>();
64 if (!vert)
return realNaN;
65 return vert->getTagVertex().Y();
68 double particleTagVz(
const Particle* particle)
70 auto* vert = particle->getRelatedTo<TagVertex>();
71 if (!vert)
return realNaN;
72 return vert->getTagVertex().Z();
75 double particleTruthTagVx(
const Particle* particle)
77 auto* vert = particle->getRelatedTo<TagVertex>();
78 if (!vert)
return realNaN;
79 return vert->getMCTagVertex().X();
82 double particleTruthTagVy(
const Particle* particle)
84 auto* vert = particle->getRelatedTo<TagVertex>();
85 if (!vert)
return realNaN;
86 return vert->getMCTagVertex().Y();
89 double particleTruthTagVz(
const Particle* particle)
91 auto* vert = particle->getRelatedTo<TagVertex>();
92 if (!vert)
return realNaN;
93 return vert->getMCTagVertex().Z();
96 double particleTagVxErr(
const Particle* particle)
98 auto* vert = particle->getRelatedTo<TagVertex>();
99 if (!vert)
return realNaN;
100 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
101 return sqrt(TagVErr(0, 0));
104 double particleTagVyErr(
const Particle* particle)
106 auto* vert = particle->getRelatedTo<TagVertex>();
107 if (!vert)
return realNaN;
108 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
109 return sqrt(TagVErr(1, 1));
112 double particleTagVzErr(
const Particle* particle)
114 auto* vert = particle->getRelatedTo<TagVertex>();
115 if (!vert)
return realNaN;
116 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
117 return sqrt(TagVErr(2, 2));
120 double particleTagVpVal(
const Particle* particle)
122 auto* vert = particle->getRelatedTo<TagVertex>();
123 if (!vert)
return realNaN;
124 return vert->getTagVertexPval();
127 double particleTagVNTracks(
const Particle* particle)
129 auto* vert = particle->getRelatedTo<TagVertex>();
130 if (!vert)
return realNaN;
131 return vert->getNTracks();
134 double particleTagVNFitTracks(
const Particle* particle)
136 auto* vert = particle->getRelatedTo<TagVertex>();
137 if (!vert)
return realNaN;
138 return vert->getNFitTracks();
141 double particleTagVType(
const Particle* particle)
143 auto* vert = particle->getRelatedTo<TagVertex>();
144 if (!vert)
return realNaN;
145 return vert->getFitType();
148 double particleTagVNDF(
const Particle* particle)
150 auto* vert = particle->getRelatedTo<TagVertex>();
151 if (!vert)
return realNaN;
152 return vert->getTagVNDF();
155 double particleTagVChi2(
const Particle* particle)
157 auto* vert = particle->getRelatedTo<TagVertex>();
158 if (!vert)
return realNaN;
159 return vert->getTagVChi2();
162 double particleTagVChi2IP(
const Particle* particle)
164 auto* vert = particle->getRelatedTo<TagVertex>();
165 if (!vert)
return realNaN;
166 return vert->getTagVChi2IP();
171 double particleDeltaT(
const Particle* particle)
173 auto* vert = particle->getRelatedTo<TagVertex>();
174 if (!vert)
return realNaN;
175 return vert->getDeltaT();
178 double particleDeltaTErr(
const Particle* particle)
180 auto* vert = particle->getRelatedTo<TagVertex>();
181 if (!vert)
return realNaN;
182 return vert->getDeltaTErr();
185 double particleDeltaTRes(
const Particle* particle)
187 return particleDeltaT(particle) - particleMCDeltaT(particle);
190 double particleDeltaTBelle(
const Particle* particle)
192 double beta = PCmsLabTransform().getBoostVector().Mag();
193 double bg = beta / sqrt(1 - beta * beta);
194 double c = Const::speedOfLight / 1000.;
195 return particleDeltaZ(particle) / bg / c;
198 double particleMCDeltaTau(
const Particle* particle)
200 auto* vert = particle->getRelatedTo<TagVertex>();
201 if (!vert)
return realNaN;
202 return vert->getMCDeltaTau();
205 double particleMCDeltaT(
const Particle* particle)
207 auto* vert = particle->getRelatedTo<TagVertex>();
208 if (!vert)
return realNaN;
209 return vert->getMCDeltaT();
212 double particleMCDeltaBoost(
const Particle* particle)
214 auto* vert = particle->getRelatedTo<TagVertex>();
215 if (!vert)
return realNaN;
217 double beta = PCmsLabTransform().getBoostVector().Mag();
218 double bg = beta / sqrt(1 - beta * beta);
219 double c = Const::speedOfLight / 1000.;
220 return vert->getMCDeltaT() * bg * c;
223 double particleDeltaZ(
const Particle* particle)
225 auto* vert = particle->getRelatedTo<TagVertex>();
226 if (!vert)
return realNaN;
227 return particle->getZ() - vert->getTagVertex().Z();
230 double particleDeltaZErr(
const Particle* particle)
232 auto* vert = particle->getRelatedTo<TagVertex>();
233 if (!vert)
return realNaN;
235 double zVariance = particle->getVertexErrorMatrix()(2, 2);
236 double TagVZVariance = vert->getTagVertexErrMatrix()(2, 2);
237 double result = sqrt(zVariance + TagVZVariance);
238 if (!std::isfinite(result))
return realNaN;
243 double particleDeltaB(
const Particle* particle)
245 auto* vert = particle->getRelatedTo<TagVertex>();
246 if (!vert)
return realNaN;
248 double beta = PCmsLabTransform().getBoostVector().Mag();
249 double bg = beta / sqrt(1 - beta * beta);
250 double c = Const::speedOfLight / 1000.;
251 return vert->getDeltaT() * bg * c;
254 double particleDeltaBErr(
const Particle* particle)
256 auto* vert = particle->getRelatedTo<TagVertex>();
257 if (!vert)
return realNaN;
259 double beta = PCmsLabTransform().getBoostVector().Mag();
260 double bg = beta / sqrt(1 - beta * beta);
261 double c = Const::speedOfLight / 1000.;
262 return vert->getDeltaTErr() * bg * c;
267 double vertexBoostDirection(
const Particle* part)
271 return pos.
Dot(boostDir);
274 double vertexOrthogonalBoostDirection(
const Particle* part)
276 B2Vector3D boost = PCmsLabTransform().getBoostVector();
277 B2Vector3D orthBoostDir = getUnitOrthogonal(boost);
280 return pos.
Dot(orthBoostDir);
283 double vertexTruthBoostDirection(
const Particle* part)
285 static DBObjPtr<BeamParameters> beamParamsDB;
286 B2Vector3D boostDir = -(beamParamsDB->getHER() + beamParamsDB->getLER()).BoostToCM().
Unit();
289 if (!mcPart)
return realNaN;
291 return pos.
Dot(boostDir);
294 double vertexTruthOrthogonalBoostDirection(
const Particle* part)
296 static DBObjPtr<BeamParameters> beamParamsDB;
297 B2Vector3D boost = -(beamParamsDB->getHER() + beamParamsDB->getLER()).BoostToCM();
298 B2Vector3D orthBoostDir = getUnitOrthogonal(boost);
301 if (!mcPart)
return realNaN;
303 return pos.
Dot(orthBoostDir);
306 double vertexErrBoostDirection(
const Particle* part)
308 TVectorD bDir = toVec(PCmsLabTransform().getBoostVector().Unit());
310 return sqrt(part->getVertexErrorMatrix().Similarity(bDir));
313 double vertexErrOrthBoostDirection(
const Particle* part)
315 TVectorD oDir = toVec(getUnitOrthogonal(PCmsLabTransform().getBoostVector()));
317 return sqrt(part->getVertexErrorMatrix().Similarity(oDir));
322 double tagVBoostDirection(
const Particle* part)
324 auto* vert = part->getRelatedTo<TagVertex>();
325 if (!vert)
return realNaN;
326 return vert->getTagVl();
329 double tagVOrthogonalBoostDirection(
const Particle* part)
331 auto* vert = part->getRelatedTo<TagVertex>();
332 if (!vert)
return realNaN;
333 return vert->getTagVol();
336 double tagVTruthBoostDirection(
const Particle* part)
338 auto* vert = part->getRelatedTo<TagVertex>();
339 if (!vert)
return realNaN;
340 return vert->getTruthTagVl();
343 double tagVTruthOrthogonalBoostDirection(
const Particle* part)
345 auto* vert = part->getRelatedTo<TagVertex>();
346 if (!vert)
return realNaN;
347 return vert->getTruthTagVol();
350 double tagVErrBoostDirection(
const Particle* part)
352 auto* vert = part->getRelatedTo<TagVertex>();
353 if (!vert)
return realNaN;
354 return vert->getTagVlErr();
357 double tagVErrOrthogonalBoostDirection(
const Particle* part)
359 auto* vert = part->getRelatedTo<TagVertex>();
360 if (!vert)
return realNaN;
361 return vert->getTagVolErr();
366 double particleCosThetaBoostDirection(
const Particle* part)
368 const auto& frame = ReferenceFrame::GetCurrent();
369 B2Vector3D boost = PCmsLabTransform().getBoostVector();
370 ROOT::Math::PxPyPzEVector pxpypze = frame.getMomentum(part);
371 B2Vector3D momentum(pxpypze.Px(), pxpypze.Py(), pxpypze.Pz());
372 return cos(momentum.Angle(boost));
375 double particleInternalTagVMCFlavor(
const Particle* part)
377 auto* vert = part->getRelatedTo<TagVertex>();
378 if (!vert)
return realNaN;
379 return vert->getMCTagBFlavor();
382 double tagTrackMomentum(
const Particle* part,
const std::vector<double>& trackIndex)
384 auto* vert = part->getRelatedTo<TagVertex>();
385 if (!vert)
return realNaN;
387 if (trackIndex.size() != 1)
return realNaN;
388 unsigned trackIndexInt = trackIndex.at(0);
390 return vert->getVtxFitTrackP(trackIndexInt).R();
393 double tagTrackMomentumX(
const Particle* part,
const std::vector<double>& trackIndex)
395 auto* vert = part->getRelatedTo<TagVertex>();
396 if (!vert)
return realNaN;
398 if (trackIndex.size() != 1)
return realNaN;
399 unsigned trackIndexInt = trackIndex.at(0);
401 return vert->getVtxFitTrackP(trackIndexInt).X();
404 double tagTrackMomentumY(
const Particle* part,
const std::vector<double>& trackIndex)
406 auto* vert = part->getRelatedTo<TagVertex>();
407 if (!vert)
return realNaN;
409 if (trackIndex.size() != 1)
return realNaN;
410 unsigned trackIndexInt = trackIndex.at(0);
412 return vert->getVtxFitTrackP(trackIndexInt).Y();
415 double tagTrackMomentumZ(
const Particle* part,
const std::vector<double>& trackIndex)
417 auto* vert = part->getRelatedTo<TagVertex>();
418 if (!vert)
return realNaN;
420 if (trackIndex.size() != 1)
return realNaN;
421 unsigned trackIndexInt = trackIndex.at(0);
423 return vert->getVtxFitTrackP(trackIndexInt).Z();
426 double tagTrackZ0(
const Particle* part,
const std::vector<double>& trackIndex)
428 auto* vert = part->getRelatedTo<TagVertex>();
429 if (!vert)
return realNaN;
431 if (trackIndex.size() != 1)
return realNaN;
432 unsigned trackIndexInt = trackIndex.at(0);
434 return vert->getVtxFitTrackZ0(trackIndexInt);
437 double tagTrackD0(
const Particle* part,
const std::vector<double>& trackIndex)
439 auto* vert = part->getRelatedTo<TagVertex>();
440 if (!vert)
return realNaN;
442 if (trackIndex.size() != 1)
return realNaN;
443 unsigned trackIndexInt = trackIndex.at(0);
445 return vert->getVtxFitTrackD0(trackIndexInt);
448 double tagTrackRaveWeight(
const Particle* part,
const std::vector<double>& trackIndex)
450 auto* vert = part->getRelatedTo<TagVertex>();
451 if (!vert)
return realNaN;
453 if (trackIndex.size() != 1)
return realNaN;
454 unsigned trackIndexInt = trackIndex.at(0);
456 return vert->getRaveWeight(trackIndexInt);
459 double tagTrackDistanceToConstraint(
const Particle* part,
const std::vector<double>& trackIndex)
461 auto* vert = part->getRelatedTo<TagVertex>();
462 if (!vert)
return realNaN;
464 if (trackIndex.size() != 1)
return realNaN;
465 unsigned trackIndexInt = trackIndex.at(0);
467 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
468 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
469 if (!tagParticle)
return realNaN;
471 return DistanceTools::trackToVtxDist(tagParticle->getTrackFitResult()->getPosition(),
472 tagParticle->getMomentum(),
473 vert->getConstraintCenter());
476 double tagTrackDistanceToConstraintErr(
const Particle* part,
const std::vector<double>& trackIndex)
478 auto* vert = part->getRelatedTo<TagVertex>();
479 if (!vert)
return realNaN;
481 if (trackIndex.size() != 1)
return realNaN;
482 unsigned trackIndexInt = trackIndex.at(0);
484 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
485 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
486 if (!tagParticle)
return realNaN;
489 TMatrixDSym trackPosCovMat = tagParticle->getVertexErrorMatrix();
491 return DistanceTools::trackToVtxDistErr(tagParticle->getTrackFitResult()->getPosition(),
492 tagParticle->getMomentum(),
493 vert->getConstraintCenter(),
495 vert->getConstraintCov());
498 double tagTrackDistanceToConstraintSignificance(
const Particle* part,
const std::vector<double>& trackIndex)
500 double val = tagTrackDistanceToConstraint(part, trackIndex);
501 if (isinf(val) || isnan(val))
return realNaN;
502 double err = tagTrackDistanceToConstraintErr(part, trackIndex);
503 if (isinf(err) || isnan(err))
return realNaN;
508 double tagVDistanceToConstraint(
const Particle* part)
510 auto* vert = part->getRelatedTo<TagVertex>();
511 if (!vert)
return realNaN;
513 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
515 return DistanceTools::vtxToVtxDist(vert->getConstraintCenter(),
516 vert->getTagVertex());
519 double tagVDistanceToConstraintErr(
const Particle* part)
521 auto* vert = part->getRelatedTo<TagVertex>();
522 if (!vert)
return realNaN;
524 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
529 TMatrixDSym emptyMat(3);
531 return DistanceTools::vtxToVtxDistErr(vert->getConstraintCenter(),
532 vert->getTagVertex(),
533 vert->getConstraintCov(),
537 double tagVDistanceToConstraintSignificance(
const Particle* part)
539 double val = tagVDistanceToConstraint(part);
540 if (isinf(val) || isnan(val))
return realNaN;
541 double err = tagVDistanceToConstraintErr(part);
542 if (isinf(err) || isnan(err))
return realNaN;
547 double tagTrackDistanceToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
549 auto* vert = part->getRelatedTo<TagVertex>();
550 if (!vert)
return realNaN;
552 if (trackIndex.size() != 1)
return realNaN;
553 unsigned trackIndexInt = trackIndex.at(0);
555 const Particle* particle = vert->getVtxFitParticle(trackIndexInt);
556 if (!particle)
return realNaN;
558 return DistanceTools::trackToVtxDist(particle->getTrackFitResult()->getPosition(),
559 particle->getMomentum(),
560 vert->getTagVertex());
563 double tagTrackDistanceToTagVErr(
const Particle* part,
const std::vector<double>& trackIndex)
565 auto* vert = part->getRelatedTo<TagVertex>();
566 if (!vert)
return realNaN;
568 if (trackIndex.size() != 1)
return realNaN;
569 unsigned trackIndexInt = trackIndex.at(0);
571 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
572 if (!tagParticle)
return realNaN;
575 TMatrixDSym trackPosCovMat = tagParticle->getVertexErrorMatrix();
581 TMatrixDSym emptyMat(3);
583 return DistanceTools::trackToVtxDistErr(tagParticle->getTrackFitResult()->getPosition(),
584 tagParticle->getMomentum(),
585 vert->getTagVertex(),
591 double tagTrackDistanceToTagVSignificance(
const Particle* part,
const std::vector<double>& trackIndex)
593 double val = tagTrackDistanceToTagV(part, trackIndex);
594 if (isinf(val) || isnan(val))
return realNaN;
595 double err = tagTrackDistanceToTagVErr(part, trackIndex);
596 if (isinf(err) || isnan(err))
return realNaN;
601 double tagTrackTrueDistanceToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
603 auto* vert = part->getRelatedTo<TagVertex>();
604 if (!vert)
return realNaN;
606 if (trackIndex.size() != 1)
return realNaN;
607 unsigned trackIndexInt = trackIndex.at(0);
609 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
610 if (!mcParticle)
return realNaN;
613 if (mcTagV(0) == realNaN)
return realNaN;
614 if (mcTagV(0) == 0 && mcTagV(1) == 0 && mcTagV(2) == 0)
return realNaN;
616 return DistanceTools::trackToVtxDist(mcParticle->getProductionVertex(),
617 mcParticle->getMomentum(),
621 B2Vector3D tagTrackTrueVecToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
623 auto* vert = part->getRelatedTo<TagVertex>();
624 if (!vert)
return vecNaN;
626 if (trackIndex.size() != 1)
return vecNaN;
627 unsigned trackIndexInt = trackIndex.
at(0);
629 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
630 if (!mcParticle)
return vecNaN;
633 if (mcTagV(0) == realNaN)
return vecNaN;
634 if (mcTagV(0) == 0 && mcTagV(1) == 0 && mcTagV(2) == 0)
return vecNaN;
636 return DistanceTools::trackToVtxVec(mcParticle->getProductionVertex(),
637 mcParticle->getMomentum(),
641 double tagTrackTrueVecToTagVX(
const Particle* part,
const std::vector<double>& trackIndex)
643 B2Vector3D result = tagTrackTrueVecToTagV(part, trackIndex);
647 double tagTrackTrueVecToTagVY(
const Particle* part,
const std::vector<double>& trackIndex)
649 B2Vector3D result = tagTrackTrueVecToTagV(part, trackIndex);
653 double tagTrackTrueVecToTagVZ(
const Particle* part,
const std::vector<double>& trackIndex)
655 B2Vector3D result = tagTrackTrueVecToTagV(part, trackIndex);
659 B2Vector3D tagTrackTrueMomentum(
const Particle* part,
const std::vector<double>& trackIndex)
661 auto* vert = part->getRelatedTo<TagVertex>();
662 if (!vert)
return vecNaN;
664 if (trackIndex.size() != 1)
return vecNaN;
665 unsigned trackIndexInt = trackIndex.
at(0);
667 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
668 if (!mcParticle)
return vecNaN;
670 return mcParticle->getMomentum();
673 double tagTrackTrueMomentumX(
const Particle* part,
const std::vector<double>& trackIndex)
675 B2Vector3D pTrue = tagTrackTrueMomentum(part, trackIndex);
679 double tagTrackTrueMomentumY(
const Particle* part,
const std::vector<double>& trackIndex)
681 B2Vector3D pTrue = tagTrackTrueMomentum(part, trackIndex);
685 double tagTrackTrueMomentumZ(
const Particle* part,
const std::vector<double>& trackIndex)
687 B2Vector3D pTrue = tagTrackTrueMomentum(part, trackIndex);
691 B2Vector3D tagTrackTrueOrigin(
const Particle* part,
const std::vector<double>& trackIndex)
693 auto* vert = part->getRelatedTo<TagVertex>();
694 if (!vert)
return vecNaN;
696 if (trackIndex.size() != 1)
return vecNaN;
697 unsigned trackIndexInt = trackIndex.
at(0);
699 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
700 if (!mcParticle)
return vecNaN;
702 return mcParticle->getProductionVertex();
705 double tagTrackTrueOriginX(
const Particle* part,
const std::vector<double>& trackIndex)
707 B2Vector3D origin = tagTrackTrueOrigin(part, trackIndex);
711 double tagTrackTrueOriginY(
const Particle* part,
const std::vector<double>& trackIndex)
713 B2Vector3D origin = tagTrackTrueOrigin(part, trackIndex);
717 double tagTrackTrueOriginZ(
const Particle* part,
const std::vector<double>& trackIndex)
719 B2Vector3D origin = tagTrackTrueOrigin(part, trackIndex);
723 int fitTruthStatus(
const Particle* part)
725 auto* vert = part->getRelatedTo<TagVertex>();
726 if (!vert)
return -1;
727 return vert->getFitTruthStatus();
730 int rollbackStatus(
const Particle* part)
732 auto* vert = part->getRelatedTo<TagVertex>();
733 if (!vert)
return -1;
734 return vert->getRollBackStatus();
746 TagTrFPtr getTagTrackFunctionFromName(
string const& name)
748 if (name ==
"TagTrackMomentum")
return tagTrackMomentum;
749 else if (name ==
"TagTrackMomentumX")
return tagTrackMomentumX;
750 else if (name ==
"TagTrackMomentumY")
return tagTrackMomentumY;
751 else if (name ==
"TagTrackMomentumZ")
return tagTrackMomentumZ;
752 else if (name ==
"TagTrackZ0")
return tagTrackZ0;
753 else if (name ==
"TagTrackD0")
return tagTrackD0;
754 else if (name ==
"TagTrackRaveWeight")
return tagTrackRaveWeight;
755 else if (name ==
"TagTrackDistanceToConstraint")
return tagTrackDistanceToConstraint;
756 else if (name ==
"TagTrackDistanceToConstraintErr")
return tagTrackDistanceToConstraintErr;
757 else if (name ==
"TagTrackDistanceToConstraintSignificance")
return tagTrackDistanceToConstraintSignificance;
758 else if (name ==
"TagTrackDistanceToTagV")
return tagTrackDistanceToTagV;
759 else if (name ==
"TagTrackDistanceToTagVErr")
return tagTrackDistanceToTagVErr;
760 else if (name ==
"TagTrackDistanceToTagVSignificance")
return tagTrackDistanceToTagVSignificance;
761 else if (name ==
"TagTrackTrueDistanceToTagV")
return tagTrackTrueDistanceToTagV;
762 else if (name ==
"TagTrackTrueVecToTagVX")
return tagTrackTrueVecToTagVX;
763 else if (name ==
"TagTrackTrueVecToTagVY")
return tagTrackTrueVecToTagVY;
764 else if (name ==
"TagTrackTrueVecToTagVZ")
return tagTrackTrueVecToTagVZ;
765 else if (name ==
"TagTrackTrueMomentumX")
return tagTrackTrueMomentumX;
766 else if (name ==
"TagTrackTrueMomentumY")
return tagTrackTrueMomentumY;
767 else if (name ==
"TagTrackTrueMomentumZ")
return tagTrackTrueMomentumZ;
768 else if (name ==
"TagTrackTrueOriginX")
return tagTrackTrueOriginX;
769 else if (name ==
"TagTrackTrueOriginY")
return tagTrackTrueOriginY;
770 else if (name ==
"TagTrackTrueOriginZ")
return tagTrackTrueOriginZ;
772 B2ERROR(
"From TimeDependentVariables: Trying to access unknown tagTrack function");
776 double cumulate(
const Particle* part,
const std::vector<std::string>& variable,
double start,
777 std::function<
double(
double,
double,
double)> fun)
779 TagTrFPtr fptr(getTagTrackFunctionFromName(variable.at(0)));
780 auto* vert = part->getRelatedTo<TagVertex>();
781 if (!vert)
return realNaN;
782 int nTracks = vert->getNFitTracks();
786 for (
int i = 0; i < nTracks; ++i) {
787 vector<double> indx(1, i);
788 double w = tagTrackRaveWeight(part, indx);
789 double f = (*fptr)(part, indx);
791 acum = fun(acum, f, w);
797 Manager::FunctionPtr tagTrackAverage(
const std::vector<std::string>& variable)
799 if (variable.size() != 1) {
800 B2FATAL(
"Wrong number of arguments for meta function tagTrackAverage");
804 return [variable](
const Particle * part) ->
double {
805 double sum = cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f;});
806 double tot = cumulate(part, variable, 0, [](
double s,
double,
double) {
return s + 1;});
807 return (tot > 0) ? sum / tot : realNaN;
811 Manager::FunctionPtr tagTrackAverageSquares(
const std::vector<std::string>& variable)
813 if (variable.size() != 1) {
814 B2FATAL(
"Wrong number of arguments for meta function tagTrackAverageSquares");
818 return [variable](
const Particle * part) ->
double {
819 double sum = cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f * f;});
820 double tot = cumulate(part, variable, 0, [](
double s,
double,
double) {
return s + 1;});
821 return (tot > 0) ? sum / tot : realNaN;
826 Manager::FunctionPtr tagTrackMax(
const std::vector<std::string>& variable)
828 if (variable.size() != 1) {
829 B2FATAL(
"Wrong number of arguments for meta function tagTrackMax");
833 return [variable](
const Particle * part) ->
double {
834 double Max = cumulate(part, variable, -DBL_MAX, [](
double s,
double f,
double) {
return std::max(s, f);});
835 return (Max != -DBL_MAX) ? Max : realNaN;
839 Manager::FunctionPtr tagTrackMin(
const std::vector<std::string>& variable)
841 if (variable.size() != 1) {
842 B2FATAL(
"Wrong number of arguments for meta function tagTrackMin");
846 return [variable](
const Particle * part) ->
double {
847 double Min = cumulate(part, variable, +DBL_MAX, [](
double s,
double f,
double) {
return std::min(s, f);});
848 return (Min != DBL_MAX) ? Min : realNaN;
852 Manager::FunctionPtr tagTrackWeightedAverage(
const std::vector<std::string>& variable)
854 if (variable.size() != 1) {
855 B2FATAL(
"Wrong number of arguments for meta function tagTrackWeightedAverage");
859 return [variable](
const Particle * part) ->
double {
860 double num = cumulate(part, variable, 0, [](
double s,
double f,
double w) {
return s + w * f;});
861 double den = cumulate(part, variable, 0, [](
double s,
double,
double w) {
return s + w;});
862 return (den > 0) ? num / den : realNaN;
866 Manager::FunctionPtr tagTrackWeightedAverageSquares(
const std::vector<std::string>& variable)
868 if (variable.size() != 1) {
869 B2FATAL(
"Wrong number of arguments for meta function tagTrackWeightedAverageSquares");
873 return [variable](
const Particle * part) ->
double {
874 double num = cumulate(part, variable, 0, [](
double s,
double f,
double w) {
return s + w * f * f;});
875 double den = cumulate(part, variable, 0, [](
double s,
double,
double w) {
return s + w;});
876 return (den > 0) ? num / den : realNaN;
880 Manager::FunctionPtr tagTrackSum(
const std::vector<std::string>& variable)
882 if (variable.size() != 1) {
883 B2FATAL(
"Wrong number of arguments for meta function tagTrackSum");
887 return [variable](
const Particle * part) ->
double {
888 return cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f;});
896 VARIABLE_GROUP(
"Time Dependent CPV Analysis Variables");
898 REGISTER_VARIABLE(
"TagVx", particleTagVx,
"Tag vertex X component",
"cm");
899 REGISTER_VARIABLE(
"TagVy", particleTagVy,
"Tag vertex Y component",
"cm");
900 REGISTER_VARIABLE(
"TagVz", particleTagVz,
"Tag vertex Z component",
"cm");
901 REGISTER_VARIABLE(
"mcTagVx", particleTruthTagVx,
"Generated Tag vertex X component",
"cm");
902 REGISTER_VARIABLE(
"mcTagVy", particleTruthTagVy,
"Generated Tag vertex Y component",
"cm");
903 REGISTER_VARIABLE(
"mcTagVz", particleTruthTagVz,
"Generated Tag vertex Z component",
"cm");
904 REGISTER_VARIABLE(
"TagVxErr", particleTagVxErr,
"Tag vertex X component uncertainty",
"cm");
905 REGISTER_VARIABLE(
"TagVyErr", particleTagVyErr,
"Tag vertex Y component uncertainty",
"cm");
906 REGISTER_VARIABLE(
"TagVzErr", particleTagVzErr,
"Tag vertex Z component uncertainty",
"cm");
907 REGISTER_VARIABLE(
"TagVpVal", particleTagVpVal,
"Tag vertex p-Value");
908 REGISTER_VARIABLE(
"TagVNTracks", particleTagVNTracks,
"Number of tracks in the tag vertex");
909 REGISTER_VARIABLE(
"TagVType", particleTagVType,
910 R
"DOC(Type of algorithm for the tag vertex. -1: failed (1,2: single track, deprecated), 3: standard, 4: standard_PXD, 5: no constraint)DOC");
911 REGISTER_VARIABLE("TagVNDF", particleTagVNDF,
"Number of degrees of freedom in the tag vertex fit");
912 REGISTER_VARIABLE(
"TagVChi2", particleTagVChi2,
"chi2 value of the tag vertex fit");
913 REGISTER_VARIABLE(
"TagVChi2IP", particleTagVChi2IP,
"IP component of chi2 value of the tag vertex fit");
915 REGISTER_VARIABLE(
"DeltaT", particleDeltaT,
916 R
"DOC(Proper decay time difference :math:`\Delta t` between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`.)DOC",
918 REGISTER_VARIABLE(
"DeltaTErr", particleDeltaTErr,
919 R
"DOC(Proper decay time difference :math:`\Delta t` uncertainty)DOC", "ps");
920 REGISTER_VARIABLE(
"DeltaTRes", particleDeltaTRes,
921 R
"DOC(:math:`\Delta t` residual, to be used for resolution function studies)DOC", "ps");
922 REGISTER_VARIABLE(
"DeltaTBelle", particleDeltaTBelle,
923 R
"DOC([Legacy] :math:`\Delta t`, as it was used in Belle)DOC", "ps");
924 REGISTER_VARIABLE(
"mcDeltaTau", particleMCDeltaTau,
925 R
"DOC(Generated proper decay time difference :math:`\Delta t`: :math:`\tau(B_{\rm rec})-\tau(B_{\rm tag})`)DOC", "ps");
926 REGISTER_VARIABLE(
"mcDeltaT", particleMCDeltaT,
927 R
"DOC(Generated proper decay time difference (in z-difference approximation) :math:`\Delta t`: :math:`(l(B_{\rm rec}) - l(B_{\rm tag}))/\beta_{\Upsilon(4S)}\gamma_{\Upsilon(4S)}`)DOC",
929 REGISTER_VARIABLE(
"mcDeltaBoost", particleMCDeltaBoost,
930 R
"DOC(True difference of decay vertex boost-direction components between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`:
931 :math:`\Delta l = l(B_{rec}) - l(B_{tag})`)DOC", "cm");
932 REGISTER_VARIABLE(
"DeltaZ", particleDeltaZ,
933 R
"DOC(Difference of decay vertex longitudinal components between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`:
934 :math:`\Delta z = z(B_{rec}) - z(B_{tag})`)DOC", "cm");
935 REGISTER_VARIABLE(
"DeltaZErr", particleDeltaZErr,
936 R
"DOC(Uncertainty of the difference :math:`z(B_{rec}) - z(B_{tag})`)DOC", "cm");
937 REGISTER_VARIABLE(
"DeltaBoost", particleDeltaB, R
"DOC(:math:`\Delta z` in the boost direction)DOC", "cm");
938 REGISTER_VARIABLE(
"DeltaBoostErr", particleDeltaBErr, R
"DOC(Uncertainty of :math:`\Delta z` in the boost direction)DOC", "cm");
940 REGISTER_VARIABLE(
"LBoost", vertexBoostDirection,
941 "Returns the vertex component in the boost direction",
"cm");
942 REGISTER_VARIABLE(
"OBoost", vertexOrthogonalBoostDirection,
943 "Returns the vertex component in the direction orthogonal to the boost",
"cm");
944 REGISTER_VARIABLE(
"mcLBoost", vertexTruthBoostDirection,
945 "Returns the MC vertex component in the boost direction",
"cm");
946 REGISTER_VARIABLE(
"mcOBoost", vertexTruthOrthogonalBoostDirection,
947 "Returns the MC vertex component in the direction orthogonal to the boost",
"cm");
948 REGISTER_VARIABLE(
"LBoostErr", vertexErrBoostDirection,
949 "Returns the error of the vertex in the boost direction",
"cm");
950 REGISTER_VARIABLE(
"OBoostErr", vertexErrOrthBoostDirection,
951 "Returns the error of the vertex in the direction orthogonal to the boost",
"cm");
953 REGISTER_VARIABLE(
"TagVLBoost", tagVBoostDirection,
954 "Returns the TagV component in the boost direction",
"cm");
955 REGISTER_VARIABLE(
"TagVOBoost", tagVOrthogonalBoostDirection,
956 "Returns the TagV component in the direction orthogonal to the boost",
"cm");
957 REGISTER_VARIABLE(
"mcTagVLBoost", tagVTruthBoostDirection,
958 "Returns the MC TagV component in the boost direction",
"cm");
959 REGISTER_VARIABLE(
"mcTagVOBoost", tagVTruthOrthogonalBoostDirection,
960 "Returns the MC TagV component in the direction orthogonal to the boost",
"cm");
961 REGISTER_VARIABLE(
"TagVLBoostErr", tagVErrBoostDirection,
962 "Returns the error of TagV in the boost direction",
"cm");
963 REGISTER_VARIABLE(
"TagVOBoostErr", tagVErrOrthogonalBoostDirection,
964 "Returns the error of TagV in the direction orthogonal to the boost",
"cm");
966 REGISTER_VARIABLE(
"cosAngleBetweenMomentumAndBoostVector", particleCosThetaBoostDirection,
967 "cosine of the angle between momentum and boost vector");
969 REGISTER_VARIABLE(
"internalTagVMCFlavor", particleInternalTagVMCFlavor,
970 "[Expert] [Debugging] This variable is only for internal checks of the TagV module by developers. \n"
971 "It returns the internal mc flavor information of the tag-side B provided by the TagV module.");
973 REGISTER_VARIABLE(
"TagTrackMomentum(i) ", tagTrackMomentum,
974 "Returns the magnitude of the momentum of the ith track used in the tag vtx fit.",
"GeV/c");
975 REGISTER_VARIABLE(
"TagTrackMomentumX(i) ", tagTrackMomentumX,
976 "Returns the X component of the momentum of the ith track used in the tag vtx fit.",
"GeV/c");
977 REGISTER_VARIABLE(
"TagTrackMomentumY(i) ", tagTrackMomentumY,
978 "Returns the Y component of the momentum of the ith track used in the tag vtx fit.",
"GeV/c");
979 REGISTER_VARIABLE(
"TagTrackMomentumZ(i) ", tagTrackMomentumZ,
980 "Returns the Z component of the momentum of the ith track used in the tag vtx fit.",
"GeV/c");
982 REGISTER_VARIABLE(
"TagTrackZ0(i)", tagTrackZ0,
"Returns the z0 parameter of the ith track used in the tag vtx fit",
"cm");
983 REGISTER_VARIABLE(
"TagTrackD0(i)", tagTrackD0,
"Returns the d0 parameter of the ith track used in the tag vtx fit",
"cm");
986 REGISTER_VARIABLE(
"TagTrackRaveWeight(i)", tagTrackRaveWeight,
"Returns the weight assigned by Rave to track i");
988 REGISTER_VARIABLE(
"TagVNFitTracks", particleTagVNFitTracks,
989 "returns the number of tracks used by rave to fit the vertex (not counting the ones coming from Kshorts)");
991 REGISTER_VARIABLE(
"TagTrackDistanceToConstraint(i)", tagTrackDistanceToConstraint,
992 "Returns the measured distance between the ith tag track and the centre of the constraint.",
"cm");
994 REGISTER_VARIABLE(
"TagTrackDistanceToConstraintErr(i)", tagTrackDistanceToConstraintErr,
995 "Returns the estimated error on the distance between the ith tag track and the centre of the constraint.",
"cm");
997 REGISTER_VARIABLE(
"TagTrackDistanceToConstraintSignificance(i)", tagTrackDistanceToConstraintSignificance,
998 "Returns the significance of the distance between the centre of the constraint and the tag track indexed by track index (computed as distance / uncertainty)");
1001 REGISTER_VARIABLE(
"TagVDistanceToConstraint", tagVDistanceToConstraint,
1002 "returns the measured distance between the tag vtx and the centre of the constraint.",
"cm");
1004 REGISTER_VARIABLE(
"TagVDistanceToConstraintErr", tagVDistanceToConstraintErr,
1005 "returns the estimated error on the distance between the tag vtx and the centre of the constraint.",
"cm");
1007 REGISTER_VARIABLE(
"TagVDistanceToConstraintSignificance", tagVDistanceToConstraintSignificance,
1008 "returns the significance of the distance between the tag vtx and the centre of the constraint (computed as distance / uncertainty)");
1010 REGISTER_VARIABLE(
"TagTrackDistanceToTagV(i)", tagTrackDistanceToTagV,
1011 "Returns the measured distance between the ith tag track and the tag vtx.",
"cm");
1013 REGISTER_VARIABLE(
"TagTrackDistanceToTagVErr(i)", tagTrackDistanceToTagVErr, R
"DOC(
1014 "Returns the estimated error on the distance between the ith tag track and the tag vtx.
1016 .. warning:: Only the uncertainties on the track position parameters are taken into account.
1019 REGISTER_VARIABLE(
"TagTrackDistanceToTagVSignificance(i)", tagTrackDistanceToTagVSignificance,
1020 "Returns the significance of the distance between the tag vtx and the tag track indexed by trackIndex (computed as distance / uncertainty)");
1022 REGISTER_VARIABLE(
"TagTrackTrueDistanceToTagV(i)", tagTrackTrueDistanceToTagV,
1023 "Returns the true distance between the true B Tag decay vertex and the particle corresponding to the ith tag vtx track.",
"cm");
1025 REGISTER_VARIABLE(
"TagTrackTrueVecToTagVX(i)", tagTrackTrueVecToTagVX,
1026 "Returns the X coordinate of the vector between the mc particle corresponding to the ith tag vtx track and the true tag B decay vertex.",
1029 REGISTER_VARIABLE(
"TagTrackTrueVecToTagVY(i)", tagTrackTrueVecToTagVY,
1030 "Returns the Y coordinate of the vector between the mc particle corresponding to the ith tag vtx track and the true tag B decay vertex.",
1033 REGISTER_VARIABLE(
"TagTrackTrueVecToTagVZ(i)", tagTrackTrueVecToTagVZ,
1034 "Returns the Z coordinate of the vector between the mc particle corresponding to the ith tag vtx track and the true tag B decay vertex.",
1037 REGISTER_VARIABLE(
"TagTrackTrueMomentumX(i)", tagTrackTrueMomentumX,
1038 "Returns the X component of the true momentum of the MC particle corresponding to the ith tag vtx track.",
"GeV/c");
1040 REGISTER_VARIABLE(
"TagTrackTrueMomentumY(i)", tagTrackTrueMomentumY,
1041 "Returns the Y component of the true momentum of the MC particle corresponding to the ith tag vtx track.",
"GeV/c");
1043 REGISTER_VARIABLE(
"TagTrackTrueMomentumZ(i)", tagTrackTrueMomentumZ,
1044 "Returns the Z component of the true momentum of the MC particle corresponding to the ith tag vtx track.",
"GeV/c");
1046 REGISTER_VARIABLE(
"TagTrackTrueOriginX(i)", tagTrackTrueOriginX,
1047 "Returns the X component of the true origin of the MC particle corresponding to the ith tag vtx track.",
"cm");
1049 REGISTER_VARIABLE(
"TagTrackTrueOriginY(i)", tagTrackTrueOriginY,
1050 "Returns the Y component of the true origin of the MC particle corresponding to the ith tag vtx track.",
"cm");
1052 REGISTER_VARIABLE(
"TagTrackTrueOriginZ(i)", tagTrackTrueOriginZ,
1053 "Returns the Z component of the true origin of the MC particle corresponding to the ith tag vtx track.",
"cm");
1055 REGISTER_VARIABLE(
"TagVFitTruthStatus", fitTruthStatus, R
"DOC(
1056 Returns the status of the fit performed with the truth info. Possible values are:
1058 - -1: no related TagVertex found
1059 - 0: fit performed with measured parameters
1060 - 1: fit performed with true parameters
1061 - 2: unable to recover truth parameters
1064 REGISTER_VARIABLE("TagVRollBackStatus", rollbackStatus, R
"DOC(
1065 Returns the status of the fit performed with rolled back tracks. Possible values are:
1067 - -1: no related TagVertex found
1068 - 0: fit performed with measured parameters
1069 - 1: fit performed with true parameters
1070 - 2: unable to recover truth parameters
1073 REGISTER_METAVARIABLE("TagTrackMax(var)", tagTrackMax,
1074 "return the maximum value of the variable ``var`` evaluated for each tag track. ``var`` must be one of the TagTrackXXX variables, for example: ``TagTrackMax(TagTrackDistanceToConstraint)``. The tracks that are assigned a zero weight are ignored.",
1075 Manager::VariableDataType::c_double);
1077 REGISTER_METAVARIABLE(
"TagTrackMin(var)", tagTrackMin,
1078 "return the minimum value of the variable ``var`` evaluated for each tag track. ``var`` must be one of the TagTrackXXX variables, for example: ``TagTrackMin(TagTrackDistanceToConstraint)``. The tracks that are assigned a zero weight are ignored.",
1079 Manager::VariableDataType::c_double);
1081 REGISTER_METAVARIABLE(
"TagTrackAverage(var)", tagTrackAverage,
1082 "return the average over the tag tracks of the variable ``var``. ``var`` must be one of the TagTrackXXX variables, for example: ``TagTrackAverage(TagTrackDistanceToConstraint)``. The tracks that are assigned a zero weight are ignored.",
1083 Manager::VariableDataType::c_double);
1085 REGISTER_METAVARIABLE(
"TagTrackAverageSquares(var)", tagTrackAverageSquares,
1086 "return the average over the tag tracks of the square of the variable ``var``. ``var`` must be one of the TagTrackXXX variables, for example: ``TagTrackAverageSquares(TagTrackDistanceToConstraint)``. The tracks that are assigned a zero weight are ignored.",
1087 Manager::VariableDataType::c_double);
1089 REGISTER_METAVARIABLE(
"TagTrackWeightedAverage(var)", tagTrackWeightedAverage,
1090 "return the average over the tag tracks of the variable ``var``, weighted by weights of the tag vertex fitter. ``var`` must be one of the TagTrackXXX variables, for example: ``TagTrackWeightedAverage(TagTrackDistanceToConstraint)``.",
1091 Manager::VariableDataType::c_double);
1093 REGISTER_METAVARIABLE(
"TagTrackWeightedAverageSquares(var)", tagTrackWeightedAverageSquares,
1094 "return the average over the tag tracks of the variable ``var``, weighted by weights of the tag vertex fitter. ``var`` must be one of the TagTrackXXX variables, for example: ``TagTrackWeightedAverageSquares(TagTrackDistanceToConstraint)``.",
1095 Manager::VariableDataType::c_double);
1097 REGISTER_METAVARIABLE(
"TagTrackSum(var)", tagTrackSum,
1098 "Returns the sum of the provided variable for all tag tracks. The variable must be one of the TagTrackXXX variables, "
1099 "for example ``TagTrackSum(TagTrackD0)``. The tracks that are assigned a zero weight are ignored.",
1100 Manager::VariableDataType::c_double);
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
const MCParticle * getMCParticle() const
Returns the pointer to the MCParticle object that was used to create this Particle (ParticleType == c...
B2Vector3< float > B2Vector3F
typedef for common usage with float
B2Vector3< double > B2Vector3D
typedef for common usage with double
DataType at(unsigned i) const
safe member access (with boundary check!)
Abstract base class for different kinds of events.