10#include <analysis/variables/TimeDependentVariables.h>
12#include <framework/dbobjects/BeamParameters.h>
15#include <analysis/dataobjects/Particle.h>
16#include <analysis/dataobjects/TagVertex.h>
19#include <analysis/utility/DistanceTools.h>
20#include <analysis/utility/PCmsLabTransform.h>
21#include <analysis/utility/RotationTools.h>
22#include <analysis/utility/ReferenceFrame.h>
25#include <framework/gearbox/Const.h>
26#include <framework/geometry/B2Vector3.h>
27#include <mdst/dataobjects/MCParticle.h>
28#include <mdst/dataobjects/TrackFitResult.h>
46 using RotationTools::getUnitOrthogonal;
47 using RotationTools::toVec;
54 double particleTagVx(
const Particle* particle)
56 auto* vert = particle->getRelatedTo<TagVertex>();
58 return vert->getTagVertex().X();
61 double particleTagVy(
const Particle* particle)
63 auto* vert = particle->getRelatedTo<TagVertex>();
65 return vert->getTagVertex().Y();
68 double particleTagVz(
const Particle* particle)
70 auto* vert = particle->getRelatedTo<TagVertex>();
72 return vert->getTagVertex().Z();
75 double particleTruthTagVx(
const Particle* particle)
77 auto* vert = particle->getRelatedTo<TagVertex>();
79 return vert->getMCTagVertex().X();
82 double particleTruthTagVy(
const Particle* particle)
84 auto* vert = particle->getRelatedTo<TagVertex>();
86 return vert->getMCTagVertex().Y();
89 double particleTruthTagVz(
const Particle* particle)
91 auto* vert = particle->getRelatedTo<TagVertex>();
93 return vert->getMCTagVertex().Z();
96 double particleTagVCov(
const Particle* particle,
const std::vector<double>& element)
98 int elementI = int(std::lround(element[0]));
99 int elementJ = int(std::lround(element[1]));
101 if (elementI < 0 || elementI > 2) {
102 B2WARNING(
"Index is out of boundaries [0 - 2]:" <<
LogVar(
"i", elementI));
105 if (elementJ < 0 || elementJ > 2) {
106 B2WARNING(
"Index is out of boundaries [0 - 2]:" <<
LogVar(
"j", elementJ));
110 auto* vert = particle->getRelatedTo<TagVertex>();
112 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
113 return TagVErr(elementI, elementJ);
116 double particleTagVxErr(
const Particle* particle)
118 auto* vert = particle->getRelatedTo<TagVertex>();
120 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
121 return sqrt(TagVErr(0, 0));
124 double particleTagVyErr(
const Particle* particle)
126 auto* vert = particle->getRelatedTo<TagVertex>();
128 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
129 return sqrt(TagVErr(1, 1));
132 double particleTagVzErr(
const Particle* particle)
134 auto* vert = particle->getRelatedTo<TagVertex>();
136 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
137 return sqrt(TagVErr(2, 2));
140 double particleTagVpVal(
const Particle* particle)
142 auto* vert = particle->getRelatedTo<TagVertex>();
144 return vert->getTagVertexPval();
147 double particleTagVNTracks(
const Particle* particle)
149 auto* vert = particle->getRelatedTo<TagVertex>();
151 return vert->getNTracks();
154 double particleTagVNFitTracks(
const Particle* particle)
156 auto* vert = particle->getRelatedTo<TagVertex>();
158 return vert->getNFitTracks();
161 double particleTagVType(
const Particle* particle)
163 auto* vert = particle->getRelatedTo<TagVertex>();
165 return vert->getFitType();
168 double particleTagVNDF(
const Particle* particle)
170 auto* vert = particle->getRelatedTo<TagVertex>();
172 return vert->getTagVNDF();
175 double particleTagVChi2(
const Particle* particle)
177 auto* vert = particle->getRelatedTo<TagVertex>();
179 return vert->getTagVChi2();
182 double particleTagVChi2IP(
const Particle* particle)
184 auto* vert = particle->getRelatedTo<TagVertex>();
186 return vert->getTagVChi2IP();
191 double particleDeltaT(
const Particle* particle)
193 auto* vert = particle->getRelatedTo<TagVertex>();
195 return vert->getDeltaT();
198 double particleDeltaTErr(
const Particle* particle)
200 auto* vert = particle->getRelatedTo<TagVertex>();
202 return vert->getDeltaTErr();
205 double particleDeltaTRes(
const Particle* particle)
207 return particleDeltaT(particle) - particleMCDeltaT(particle);
210 double particleDeltaTBelle(
const Particle* particle)
212 double beta = PCmsLabTransform().getBoostVector().Mag();
213 double bg = beta /
sqrt(1 - beta * beta);
215 return particleDeltaZ(particle) / bg / c;
218 double particleMCDeltaTau(
const Particle* particle)
220 auto* vert = particle->getRelatedTo<TagVertex>();
222 return vert->getMCDeltaTau();
225 double particleMCDeltaT(
const Particle* particle)
227 auto* vert = particle->getRelatedTo<TagVertex>();
229 return vert->getMCDeltaT();
232 double particleMCDeltaBoost(
const Particle* particle)
234 auto* vert = particle->getRelatedTo<TagVertex>();
237 double beta = PCmsLabTransform().getBoostVector().Mag();
238 double bg = beta /
sqrt(1 - beta * beta);
240 return vert->getMCDeltaT() * bg * c;
243 double particleDeltaZ(
const Particle* particle)
245 auto* vert = particle->getRelatedTo<TagVertex>();
247 return particle->getZ() - vert->getTagVertex().Z();
250 double particleDeltaZErr(
const Particle* particle)
252 auto* vert = particle->getRelatedTo<TagVertex>();
255 double zVariance = particle->getVertexErrorMatrix()(2, 2);
256 double TagVZVariance = vert->getTagVertexErrMatrix()(2, 2);
257 double result =
sqrt(zVariance + TagVZVariance);
263 double particleDeltaB(
const Particle* particle)
265 auto* vert = particle->getRelatedTo<TagVertex>();
268 double beta = PCmsLabTransform().getBoostVector().Mag();
269 double bg = beta /
sqrt(1 - beta * beta);
271 return vert->getDeltaT() * bg * c;
274 double particleDeltaBErr(
const Particle* particle)
276 auto* vert = particle->getRelatedTo<TagVertex>();
279 double beta = PCmsLabTransform().getBoostVector().Mag();
280 double bg = beta /
sqrt(1 - beta * beta);
282 return vert->getDeltaTErr() * bg * c;
287 double vertexBoostDirection(
const Particle* part)
291 return pos.Dot(boostDir);
294 double vertexOrthogonalBoostDirection(
const Particle* part)
296 B2Vector3D boost = PCmsLabTransform().getBoostVector();
297 B2Vector3D orthBoostDir = getUnitOrthogonal(boost);
300 return pos.Dot(orthBoostDir);
303 double vertexTruthBoostDirection(
const Particle* part)
305 static DBObjPtr<BeamParameters> beamParamsDB;
306 B2Vector3D boostDir = -(beamParamsDB->getHER() + beamParamsDB->getLER()).BoostToCM().
Unit();
311 return pos.Dot(boostDir);
314 double vertexTruthOrthogonalBoostDirection(
const Particle* part)
316 static DBObjPtr<BeamParameters> beamParamsDB;
317 B2Vector3D boost = -(beamParamsDB->getHER() + beamParamsDB->getLER()).BoostToCM();
318 B2Vector3D orthBoostDir = getUnitOrthogonal(boost);
323 return pos.Dot(orthBoostDir);
326 double vertexErrBoostDirection(
const Particle* part)
328 TVectorD bDir = toVec(PCmsLabTransform().getBoostVector().Unit());
330 return sqrt(part->getVertexErrorMatrix().Similarity(bDir));
333 double vertexErrOrthBoostDirection(
const Particle* part)
335 TVectorD oDir = toVec(getUnitOrthogonal(PCmsLabTransform().getBoostVector()));
337 return sqrt(part->getVertexErrorMatrix().Similarity(oDir));
342 double tagVBoostDirection(
const Particle* part)
344 auto* vert = part->getRelatedTo<TagVertex>();
346 return vert->getTagVl();
349 double tagVOrthogonalBoostDirection(
const Particle* part)
351 auto* vert = part->getRelatedTo<TagVertex>();
353 return vert->getTagVol();
356 double tagVTruthBoostDirection(
const Particle* part)
358 auto* vert = part->getRelatedTo<TagVertex>();
360 return vert->getTruthTagVl();
363 double tagVTruthOrthogonalBoostDirection(
const Particle* part)
365 auto* vert = part->getRelatedTo<TagVertex>();
367 return vert->getTruthTagVol();
370 double tagVErrBoostDirection(
const Particle* part)
372 auto* vert = part->getRelatedTo<TagVertex>();
374 return vert->getTagVlErr();
377 double tagVErrOrthogonalBoostDirection(
const Particle* part)
379 auto* vert = part->getRelatedTo<TagVertex>();
381 return vert->getTagVolErr();
386 double particleCosThetaBoostDirection(
const Particle* part)
389 B2Vector3D boost = PCmsLabTransform().getBoostVector();
390 ROOT::Math::PxPyPzEVector pxpypze = frame.getMomentum(part);
391 B2Vector3D momentum(pxpypze.Px(), pxpypze.Py(), pxpypze.Pz());
392 return cos(momentum.Angle(boost));
395 double particleInternalTagVMCFlavor(
const Particle* part)
397 auto* vert = part->getRelatedTo<TagVertex>();
399 return vert->getMCTagBFlavor();
402 double tagTrackMomentum(
const Particle* part,
const std::vector<double>& trackIndex)
404 auto* vert = part->getRelatedTo<TagVertex>();
408 unsigned trackIndexInt = trackIndex.at(0);
410 return vert->getVtxFitTrackP(trackIndexInt).R();
413 double tagTrackMomentumX(
const Particle* part,
const std::vector<double>& trackIndex)
415 auto* vert = part->getRelatedTo<TagVertex>();
419 unsigned trackIndexInt = trackIndex.at(0);
421 return vert->getVtxFitTrackP(trackIndexInt).X();
424 double tagTrackMomentumY(
const Particle* part,
const std::vector<double>& trackIndex)
426 auto* vert = part->getRelatedTo<TagVertex>();
430 unsigned trackIndexInt = trackIndex.at(0);
432 return vert->getVtxFitTrackP(trackIndexInt).Y();
435 double tagTrackMomentumZ(
const Particle* part,
const std::vector<double>& trackIndex)
437 auto* vert = part->getRelatedTo<TagVertex>();
441 unsigned trackIndexInt = trackIndex.at(0);
443 return vert->getVtxFitTrackP(trackIndexInt).Z();
446 double tagTrackZ0(
const Particle* part,
const std::vector<double>& trackIndex)
448 auto* vert = part->getRelatedTo<TagVertex>();
452 unsigned trackIndexInt = trackIndex.at(0);
454 return vert->getVtxFitTrackZ0(trackIndexInt);
457 double tagTrackD0(
const Particle* part,
const std::vector<double>& trackIndex)
459 auto* vert = part->getRelatedTo<TagVertex>();
463 unsigned trackIndexInt = trackIndex.at(0);
465 return vert->getVtxFitTrackD0(trackIndexInt);
468 double tagTrackRaveWeight(
const Particle* part,
const std::vector<double>& trackIndex)
470 auto* vert = part->getRelatedTo<TagVertex>();
474 unsigned trackIndexInt = trackIndex.at(0);
476 return vert->getRaveWeight(trackIndexInt);
479 double tagTrackDistanceToConstraint(
const Particle* part,
const std::vector<double>& trackIndex)
481 auto* vert = part->getRelatedTo<TagVertex>();
485 unsigned trackIndexInt = trackIndex.at(0);
488 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
490 const TrackFitResult* tagTrackFitResult = tagParticle->getTrackFitResult();
494 tagParticle->getMomentum(),
495 vert->getConstraintCenter());
498 double getY4Sx(
const Particle* part)
500 auto* vert = part->getRelatedTo<TagVertex>();
502 return vert->getConstraintCenter().X();
505 double getY4Sy(
const Particle* part)
507 auto* vert = part->getRelatedTo<TagVertex>();
509 return vert->getConstraintCenter().Y();
512 double getY4Sz(
const Particle* part)
514 auto* vert = part->getRelatedTo<TagVertex>();
516 return vert->getConstraintCenter().Z();
519 double getSigBdecayTime(
const Particle* part)
521 auto* vert = part->getRelatedTo<TagVertex>();
523 B2Vector3D vtxY4S = vert->getConstraintCenter();
525 ROOT::Math::PxPyPzEVector p4Sig = part->get4Vector();
529 double betaSig = p4Sig.Beta();
530 double gammaSig = 1 /
sqrt(1 - betaSig * betaSig);
535 double tSig = (vtxSigB - vtxY4S).Dot(nSig) / (c * betaSig * gammaSig);
539 double getTagBdecayTime(
const Particle* part)
541 auto* vert = part->getRelatedTo<TagVertex>();
544 B2Vector3D vtxY4S = vert->getConstraintCenter();
546 ROOT::Math::PxPyPzEVector p4Sig = part->get4Vector();
547 ROOT::Math::PxPyPzEVector p4SigCms = PCmsLabTransform().labToCms(p4Sig);
549 ROOT::Math::PxPyPzEVector p4TagCms(-p4SigCms.px(), -p4SigCms.py(), -p4SigCms.pz(), p4SigCms.E());
550 ROOT::Math::PxPyPzEVector p4Tag = PCmsLabTransform().cmsToLab(p4TagCms);
554 double betaTag = p4Tag.Beta();
555 double gammaTag = 1 /
sqrt(1 - betaTag * betaTag);
560 double tTag = (vtxTagB - vtxY4S).Dot(nTag) / (c * betaTag * gammaTag);
564 double getDeltaT3D(
const Particle* part)
566 return getSigBdecayTime(part) - getTagBdecayTime(part);
569 double tagTrackDistanceToConstraintErr(
const Particle* part,
const std::vector<double>& trackIndex)
571 auto* vert = part->getRelatedTo<TagVertex>();
575 unsigned trackIndexInt = trackIndex.at(0);
578 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
580 const TrackFitResult* tagTrackFitResult = tagParticle->getTrackFitResult();
584 TMatrixDSym trackPosCovMat = tagParticle->getVertexErrorMatrix();
587 tagParticle->getMomentum(),
588 vert->getConstraintCenter(),
590 vert->getConstraintCov());
593 double tagTrackDistanceToConstraintSignificance(
const Particle* part,
const std::vector<double>& trackIndex)
595 double val = tagTrackDistanceToConstraint(part, trackIndex);
597 double err = tagTrackDistanceToConstraintErr(part, trackIndex);
603 double tagVDistanceToConstraint(
const Particle* part)
605 auto* vert = part->getRelatedTo<TagVertex>();
611 vert->getTagVertex());
614 double tagVDistanceToConstraintErr(
const Particle* part)
616 auto* vert = part->getRelatedTo<TagVertex>();
624 TMatrixDSym emptyMat(3);
627 vert->getTagVertex(),
628 vert->getConstraintCov(),
632 double tagVDistanceToConstraintSignificance(
const Particle* part)
634 double val = tagVDistanceToConstraint(part);
636 double err = tagVDistanceToConstraintErr(part);
642 double tagTrackDistanceToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
644 auto* vert = part->getRelatedTo<TagVertex>();
648 unsigned trackIndexInt = trackIndex.at(0);
650 const Particle* particle = vert->getVtxFitParticle(trackIndexInt);
652 const TrackFitResult* trackFitResult = particle->getTrackFitResult();
656 particle->getMomentum(),
657 vert->getTagVertex());
660 double tagTrackDistanceToTagVErr(
const Particle* part,
const std::vector<double>& trackIndex)
662 auto* vert = part->getRelatedTo<TagVertex>();
666 unsigned trackIndexInt = trackIndex.at(0);
668 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
670 const TrackFitResult* tagTrackFitResult = tagParticle->getTrackFitResult();
674 TMatrixDSym trackPosCovMat = tagParticle->getVertexErrorMatrix();
680 TMatrixDSym emptyMat(3);
683 tagParticle->getMomentum(),
684 vert->getTagVertex(),
690 double tagTrackDistanceToTagVSignificance(
const Particle* part,
const std::vector<double>& trackIndex)
692 double val = tagTrackDistanceToTagV(part, trackIndex);
694 double err = tagTrackDistanceToTagVErr(part, trackIndex);
700 double tagTrackTrueDistanceToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
702 auto* vert = part->getRelatedTo<TagVertex>();
706 unsigned trackIndexInt = trackIndex.at(0);
708 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
713 if (mcTagV(0) == 0 && mcTagV(1) == 0 && mcTagV(2) == 0)
return Const::doubleNaN;
716 mcParticle->getMomentum(),
720 B2Vector3D tagTrackTrueVecToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
722 auto* vert = part->getRelatedTo<TagVertex>();
723 if (!vert)
return vecNaN;
725 if (trackIndex.size() != 1)
return vecNaN;
726 unsigned trackIndexInt = trackIndex.
at(0);
728 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
729 if (!mcParticle)
return vecNaN;
733 if (mcTagV(0) == 0 && mcTagV(1) == 0 && mcTagV(2) == 0)
return vecNaN;
736 mcParticle->getMomentum(),
740 double tagTrackTrueVecToTagVX(
const Particle* part,
const std::vector<double>& trackIndex)
742 B2Vector3D result = tagTrackTrueVecToTagV(part, trackIndex);
746 double tagTrackTrueVecToTagVY(
const Particle* part,
const std::vector<double>& trackIndex)
748 B2Vector3D result = tagTrackTrueVecToTagV(part, trackIndex);
752 double tagTrackTrueVecToTagVZ(
const Particle* part,
const std::vector<double>& trackIndex)
754 B2Vector3D result = tagTrackTrueVecToTagV(part, trackIndex);
758 B2Vector3D tagTrackTrueMomentum(
const Particle* part,
const std::vector<double>& trackIndex)
760 auto* vert = part->getRelatedTo<TagVertex>();
761 if (!vert)
return vecNaN;
763 if (trackIndex.size() != 1)
return vecNaN;
764 unsigned trackIndexInt = trackIndex.
at(0);
766 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
767 if (!mcParticle)
return vecNaN;
769 return mcParticle->getMomentum();
772 double tagTrackTrueMomentumX(
const Particle* part,
const std::vector<double>& trackIndex)
774 B2Vector3D pTrue = tagTrackTrueMomentum(part, trackIndex);
778 double tagTrackTrueMomentumY(
const Particle* part,
const std::vector<double>& trackIndex)
780 B2Vector3D pTrue = tagTrackTrueMomentum(part, trackIndex);
784 double tagTrackTrueMomentumZ(
const Particle* part,
const std::vector<double>& trackIndex)
786 B2Vector3D pTrue = tagTrackTrueMomentum(part, trackIndex);
790 B2Vector3D tagTrackTrueOrigin(
const Particle* part,
const std::vector<double>& trackIndex)
792 auto* vert = part->getRelatedTo<TagVertex>();
793 if (!vert)
return vecNaN;
795 if (trackIndex.size() != 1)
return vecNaN;
796 unsigned trackIndexInt = trackIndex.
at(0);
798 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
799 if (!mcParticle)
return vecNaN;
801 return mcParticle->getProductionVertex();
804 double tagTrackTrueOriginX(
const Particle* part,
const std::vector<double>& trackIndex)
806 B2Vector3D origin = tagTrackTrueOrigin(part, trackIndex);
810 double tagTrackTrueOriginY(
const Particle* part,
const std::vector<double>& trackIndex)
812 B2Vector3D origin = tagTrackTrueOrigin(part, trackIndex);
816 double tagTrackTrueOriginZ(
const Particle* part,
const std::vector<double>& trackIndex)
818 B2Vector3D origin = tagTrackTrueOrigin(part, trackIndex);
822 int fitTruthStatus(
const Particle* part)
824 auto* vert = part->getRelatedTo<TagVertex>();
825 if (!vert)
return -1;
826 return vert->getFitTruthStatus();
829 int rollbackStatus(
const Particle* part)
831 auto* vert = part->getRelatedTo<TagVertex>();
832 if (!vert)
return -1;
833 return vert->getRollBackStatus();
845 TagTrFPtr getTagTrackFunctionFromName(
string const& name)
847 if (name ==
"TagTrackMomentum")
return tagTrackMomentum;
848 else if (name ==
"TagTrackMomentumX")
return tagTrackMomentumX;
849 else if (name ==
"TagTrackMomentumY")
return tagTrackMomentumY;
850 else if (name ==
"TagTrackMomentumZ")
return tagTrackMomentumZ;
851 else if (name ==
"TagTrackZ0")
return tagTrackZ0;
852 else if (name ==
"TagTrackD0")
return tagTrackD0;
853 else if (name ==
"TagTrackRaveWeight")
return tagTrackRaveWeight;
854 else if (name ==
"TagTrackDistanceToConstraint")
return tagTrackDistanceToConstraint;
855 else if (name ==
"TagTrackDistanceToConstraintErr")
return tagTrackDistanceToConstraintErr;
856 else if (name ==
"TagTrackDistanceToConstraintSignificance")
return tagTrackDistanceToConstraintSignificance;
857 else if (name ==
"TagTrackDistanceToTagV")
return tagTrackDistanceToTagV;
858 else if (name ==
"TagTrackDistanceToTagVErr")
return tagTrackDistanceToTagVErr;
859 else if (name ==
"TagTrackDistanceToTagVSignificance")
return tagTrackDistanceToTagVSignificance;
860 else if (name ==
"TagTrackTrueDistanceToTagV")
return tagTrackTrueDistanceToTagV;
861 else if (name ==
"TagTrackTrueVecToTagVX")
return tagTrackTrueVecToTagVX;
862 else if (name ==
"TagTrackTrueVecToTagVY")
return tagTrackTrueVecToTagVY;
863 else if (name ==
"TagTrackTrueVecToTagVZ")
return tagTrackTrueVecToTagVZ;
864 else if (name ==
"TagTrackTrueMomentumX")
return tagTrackTrueMomentumX;
865 else if (name ==
"TagTrackTrueMomentumY")
return tagTrackTrueMomentumY;
866 else if (name ==
"TagTrackTrueMomentumZ")
return tagTrackTrueMomentumZ;
867 else if (name ==
"TagTrackTrueOriginX")
return tagTrackTrueOriginX;
868 else if (name ==
"TagTrackTrueOriginY")
return tagTrackTrueOriginY;
869 else if (name ==
"TagTrackTrueOriginZ")
return tagTrackTrueOriginZ;
871 B2ERROR(
"From TimeDependentVariables: Trying to access unknown tagTrack function");
875 double cumulate(
const Particle* part,
const std::vector<std::string>& variable,
double start,
876 std::function<
double(
double,
double,
double)> fun)
878 TagTrFPtr fptr(getTagTrackFunctionFromName(variable.at(0)));
879 auto* vert = part->getRelatedTo<TagVertex>();
881 int nTracks = vert->getNFitTracks();
885 for (
int i = 0; i < nTracks; ++i) {
886 vector<double> indx(1, i);
887 double w = tagTrackRaveWeight(part, indx);
888 double f = (*fptr)(part, indx);
890 acum = fun(acum, f, w);
898 if (variable.size() != 1) {
899 B2FATAL(
"Wrong number of arguments for meta function tagTrackAverage");
903 return [variable](
const Particle * part) ->
double {
904 double sum = cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f;});
905 double tot = cumulate(part, variable, 0, [](
double s,
double,
double) {
return s + 1;});
912 if (variable.size() != 1) {
913 B2FATAL(
"Wrong number of arguments for meta function tagTrackAverageSquares");
917 return [variable](
const Particle * part) ->
double {
918 double sum = cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f * f;});
919 double tot = cumulate(part, variable, 0, [](
double s,
double,
double) {
return s + 1;});
927 if (variable.size() != 1) {
928 B2FATAL(
"Wrong number of arguments for meta function tagTrackMax");
932 return [variable](
const Particle * part) ->
double {
933 double Max = cumulate(part, variable, -DBL_MAX, [](
double s,
double f,
double) {
return std::max(s, f);});
940 if (variable.size() != 1) {
941 B2FATAL(
"Wrong number of arguments for meta function tagTrackMin");
945 return [variable](
const Particle * part) ->
double {
946 double Min = cumulate(part, variable, +DBL_MAX, [](
double s,
double f,
double) {
return std::min(s, f);});
953 if (variable.size() != 1) {
954 B2FATAL(
"Wrong number of arguments for meta function tagTrackWeightedAverage");
958 return [variable](
const Particle * part) ->
double {
959 double num = cumulate(part, variable, 0, [](
double s,
double f,
double w) {
return s + w * f;});
960 double den = cumulate(part, variable, 0, [](
double s,
double,
double w) {
return s + w;});
967 if (variable.size() != 1) {
968 B2FATAL(
"Wrong number of arguments for meta function tagTrackWeightedAverageSquares");
972 return [variable](
const Particle * part) ->
double {
973 double num = cumulate(part, variable, 0, [](
double s,
double f,
double w) {
return s + w * f * f;});
974 double den = cumulate(part, variable, 0, [](
double s,
double,
double w) {
return s + w;});
981 if (variable.size() != 1) {
982 B2FATAL(
"Wrong number of arguments for meta function tagTrackSum");
986 return [variable](
const Particle * part) ->
double {
987 return cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f;});
995 VARIABLE_GROUP(
"Time Dependent CPV Analysis Variables");
997 REGISTER_VARIABLE(
"TagVx", particleTagVx,
"Tag vertex X component\n\n",
"cm");
998 REGISTER_VARIABLE(
"TagVy", particleTagVy,
"Tag vertex Y component\n\n",
"cm");
999 REGISTER_VARIABLE(
"TagVz", particleTagVz,
"Tag vertex Z component\n\n",
"cm");
1000 REGISTER_VARIABLE(
"mcTagVx", particleTruthTagVx,
"Generated Tag vertex X component\n\n",
"cm");
1001 REGISTER_VARIABLE(
"mcTagVy", particleTruthTagVy,
"Generated Tag vertex Y component\n\n",
"cm");
1002 REGISTER_VARIABLE(
"mcTagVz", particleTruthTagVz,
"Generated Tag vertex Z component\n\n",
"cm");
1003 REGISTER_VARIABLE(
"TagVxErr", particleTagVxErr,
"Tag vertex X component uncertainty\n\n",
"cm");
1004 REGISTER_VARIABLE(
"TagVyErr", particleTagVyErr,
"Tag vertex Y component uncertainty\n\n",
"cm");
1005 REGISTER_VARIABLE(
"TagVzErr", particleTagVzErr,
"Tag vertex Z component uncertainty\n\n",
"cm");
1006 REGISTER_VARIABLE(
"TagVCov(i,j)", particleTagVCov,
1007 "returns the (i,j)-th element of the Tag vertex covariance matrix (3x3).\n"
1008 "Order of elements in the covariance matrix is: x, y, z.\n\n",
"cm, cm, cm");
1010 REGISTER_VARIABLE(
"TagVpVal", particleTagVpVal,
"Tag vertex p-Value");
1011 REGISTER_VARIABLE(
"TagVNTracks", particleTagVNTracks,
"Number of tracks in the tag vertex");
1012 REGISTER_VARIABLE(
"TagVType", particleTagVType,
1013 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");
1014 REGISTER_VARIABLE("TagVNDF", particleTagVNDF,
"Number of degrees of freedom in the tag vertex fit");
1015 REGISTER_VARIABLE(
"TagVChi2", particleTagVChi2,
"chi2 value of the tag vertex fit");
1016 REGISTER_VARIABLE(
"TagVChi2IP", particleTagVChi2IP,
"IP component of chi2 value of the tag vertex fit");
1018 REGISTER_VARIABLE(
"DeltaT", particleDeltaT, R
"DOC(
1019 Proper decay time difference :math:`\Delta t` between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`.
1022 REGISTER_VARIABLE(
"DeltaTErr", particleDeltaTErr, R
"DOC(
1023 Proper decay time difference :math:`\Delta t` uncertainty
1026 REGISTER_VARIABLE(
"DeltaTRes", particleDeltaTRes, R
"DOC(
1027 :math:`\Delta t` residual, to be used for resolution function studies
1030 REGISTER_VARIABLE(
"DeltaTBelle", particleDeltaTBelle, R
"DOC(
1031 [Legacy] :math:`\Delta t`, as it was used in Belle
1034 REGISTER_VARIABLE(
"mcDeltaTau", particleMCDeltaTau,
1035 R
"DOC(Generated proper decay time difference :math:`\Delta t`: :math:`\tau(B_{\rm rec})-\tau(B_{\rm tag})`
1038 REGISTER_VARIABLE(
"mcDeltaT", particleMCDeltaT,
1039 R
"DOC(Generated proper decay time difference (in z-difference approximation) :math:`\Delta t`:
1040 :math:`(l(B_{\rm rec}) - l(B_{\rm tag}))/\beta_{\Upsilon(4S)}\gamma_{\Upsilon(4S)}`
1043 REGISTER_VARIABLE("mcDeltaBoost", particleMCDeltaBoost,
1044 R"DOC(True difference of decay vertex boost-direction components between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`:
1045:math:`\Delta l = l(B_{rec}) - l(B_{tag})`
1048 REGISTER_VARIABLE(
"DeltaZ", particleDeltaZ,
1049 R
"DOC(Difference of decay vertex longitudinal components between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`:
1050:math:`\Delta z = z(B_{rec}) - z(B_{tag})`
1053 REGISTER_VARIABLE(
"DeltaZErr", particleDeltaZErr,
1054 R
"DOC(Uncertainty of the difference :math:`z(B_{rec}) - z(B_{tag})`
1057 REGISTER_VARIABLE(
"DeltaBoost", particleDeltaB, R
"DOC(:math:`\Delta z` in the boost direction
1060 REGISTER_VARIABLE(
"DeltaBoostErr", particleDeltaBErr, R
"DOC(Uncertainty of :math:`\Delta z` in the boost direction
1064 REGISTER_VARIABLE(
"LBoost", vertexBoostDirection,
1065 "Returns the vertex component in the boost direction\n\n",
"cm");
1066 REGISTER_VARIABLE(
"OBoost", vertexOrthogonalBoostDirection,
1067 "Returns the vertex component in the direction orthogonal to the boost\n\n",
"cm");
1068 REGISTER_VARIABLE(
"mcLBoost", vertexTruthBoostDirection,
1069 "Returns the MC vertex component in the boost direction\n\n",
"cm");
1070 REGISTER_VARIABLE(
"mcOBoost", vertexTruthOrthogonalBoostDirection,
1071 "Returns the MC vertex component in the direction orthogonal to the boost\n\n",
"cm");
1072 REGISTER_VARIABLE(
"LBoostErr", vertexErrBoostDirection,
1073 "Returns the error of the vertex in the boost direction\n\n",
"cm");
1074 REGISTER_VARIABLE(
"OBoostErr", vertexErrOrthBoostDirection,
1075 "Returns the error of the vertex in the direction orthogonal to the boost\n\n",
"cm");
1077 REGISTER_VARIABLE(
"Y4SvtxX", getY4Sx,
"Returns X component of Y4S vertex.\n"
1078 "The result is meaningful and nontrivial when the signal B vertex "
1079 "is determined by `vertex.treeFit` with ``ipConstraint=True`` and the `vertex.TagV` is called with the ``tube`` constraint.\n\n",
"cm");
1081 REGISTER_VARIABLE(
"Y4SvtxY", getY4Sy,
"Returns Y component of Y4S vertex.\n"
1082 "The result is meaningful and nontrivial when the signal B vertex "
1083 "is determined by `vertex.treeFit` with ``ipConstraint=True`` and the `vertex.TagV` is called with the ``tube`` constraint.\n\n",
"cm");
1085 REGISTER_VARIABLE(
"Y4SvtxZ", getY4Sz,
"Returns Z component of Y4S vertex.\n"
1086 "The result is meaningful and nontrivial when the signal B vertex "
1087 "is determined by `vertex.treeFit` with ``ipConstraint=True`` and the `vertex.TagV` is called with the ``tube`` constraint.\n\n",
"cm");
1090 REGISTER_VARIABLE(
"tSigB", getSigBdecayTime,
"Returns the proper decay time of the fully reconstructed signal B meson.\n"
1091 "The result is meaningful and nontrivial when the signal B vertex "
1092 "is determined by `vertex.treeFit` with ``ipConstraint=True`` and the `vertex.TagV` is called with the ``tube`` constraint.\n\n",
"ps");
1094 REGISTER_VARIABLE(
"tTagB", getTagBdecayTime,
"Returns the proper decay time of the tagged B meson.\n"
1095 "The result is meaningful and nontrivial when the signal B vertex "
1096 "is determined by `vertex.treeFit` with ``ipConstraint=True`` and the `vertex.TagV` is called with the ``tube`` constraint.\n\n",
"ps");
1098 REGISTER_VARIABLE(
"DeltaT3D", getDeltaT3D, R
"DOC(
1099 Returns the :math:`\Delta t` variable calculated as a difference of :b2:var:`tSigB` and :b2:var:`tTagB`, i.e. not from the projection along boost vector axis.
1101 The result is meaningful and nontrivial when the signal B vertex is determined by `vertex.treeFit` with ``ipConstraint=True`` and the `vertex.TagV` is called with the ``tube`` constraint.
1105 REGISTER_VARIABLE(
"TagVLBoost", tagVBoostDirection,
1106 "Returns the TagV component in the boost direction\n\n",
"cm");
1107 REGISTER_VARIABLE(
"TagVOBoost", tagVOrthogonalBoostDirection,
1108 "Returns the TagV component in the direction orthogonal to the boost\n\n",
"cm");
1109 REGISTER_VARIABLE(
"mcTagVLBoost", tagVTruthBoostDirection,
1110 "Returns the MC TagV component in the boost direction\n\n",
"cm");
1111 REGISTER_VARIABLE(
"mcTagVOBoost", tagVTruthOrthogonalBoostDirection,
1112 "Returns the MC TagV component in the direction orthogonal to the boost\n\n",
"cm");
1113 REGISTER_VARIABLE(
"TagVLBoostErr", tagVErrBoostDirection,
1114 "Returns the error of TagV in the boost direction\n\n",
"cm");
1115 REGISTER_VARIABLE(
"TagVOBoostErr", tagVErrOrthogonalBoostDirection,
1116 "Returns the error of TagV in the direction orthogonal to the boost\n\n",
"cm");
1118 REGISTER_VARIABLE(
"cosAngleBetweenMomentumAndBoostVector", particleCosThetaBoostDirection,
1119 "cosine of the angle between momentum and boost vector");
1121 REGISTER_VARIABLE(
"internalTagVMCFlavor", particleInternalTagVMCFlavor,
1122 "[Expert] [Debugging] This variable is only for internal checks of the TagV module by developers. \n"
1123 "It returns the internal mc flavor information of the tag-side B provided by the TagV module.");
1125 REGISTER_VARIABLE(
"TagTrackMomentum(i) ", tagTrackMomentum,
1126 "Returns the magnitude of the momentum of the ith track used in the tag vtx fit.\n\n",
"GeV/c");
1127 REGISTER_VARIABLE(
"TagTrackMomentumX(i) ", tagTrackMomentumX,
1128 "Returns the X component of the momentum of the ith track used in the tag vtx fit.\n\n",
"GeV/c");
1129 REGISTER_VARIABLE(
"TagTrackMomentumY(i) ", tagTrackMomentumY,
1130 "Returns the Y component of the momentum of the ith track used in the tag vtx fit.\n\n",
"GeV/c");
1131 REGISTER_VARIABLE(
"TagTrackMomentumZ(i) ", tagTrackMomentumZ,
1132 "Returns the Z component of the momentum of the ith track used in the tag vtx fit.\n\n",
"GeV/c");
1134 REGISTER_VARIABLE(
"TagTrackZ0(i)", tagTrackZ0,
"Returns the z0 parameter of the ith track used in the tag vtx fit\n\n",
"cm");
1135 REGISTER_VARIABLE(
"TagTrackD0(i)", tagTrackD0,
"Returns the d0 parameter of the ith track used in the tag vtx fit\n\n",
"cm");
1138 REGISTER_VARIABLE(
"TagTrackRaveWeight(i)", tagTrackRaveWeight,
"Returns the weight assigned by Rave to track i");
1140 REGISTER_VARIABLE(
"TagVNFitTracks", particleTagVNFitTracks,
1141 "returns the number of tracks used by rave to fit the vertex (not counting the ones coming from Kshorts)");
1143 REGISTER_VARIABLE(
"TagTrackDistanceToConstraint(i)", tagTrackDistanceToConstraint,
1144 "Returns the measured distance between the ith tag track and the centre of the constraint.\n\n",
"cm");
1146 REGISTER_VARIABLE(
"TagTrackDistanceToConstraintErr(i)", tagTrackDistanceToConstraintErr,
1147 "Returns the estimated error on the distance between the ith tag track and the centre of the constraint.\n\n",
"cm");
1149 REGISTER_VARIABLE(
"TagTrackDistanceToConstraintSignificance(i)", tagTrackDistanceToConstraintSignificance,
1150 "Returns the significance of the distance between the centre of the constraint and the tag track indexed by track index (computed as distance / uncertainty)");
1153 REGISTER_VARIABLE(
"TagVDistanceToConstraint", tagVDistanceToConstraint,
1154 "returns the measured distance between the tag vtx and the centre of the constraint.\n\n",
"cm");
1156 REGISTER_VARIABLE(
"TagVDistanceToConstraintErr", tagVDistanceToConstraintErr,
1157 "returns the estimated error on the distance between the tag vtx and the centre of the constraint.\n\n",
"cm");
1159 REGISTER_VARIABLE(
"TagVDistanceToConstraintSignificance", tagVDistanceToConstraintSignificance,
1160 "returns the significance of the distance between the tag vtx and the centre of the constraint (computed as distance / uncertainty)");
1162 REGISTER_VARIABLE(
"TagTrackDistanceToTagV(i)", tagTrackDistanceToTagV,
1163 "Returns the measured distance between the ith tag track and the tag vtx.\n\n",
"cm");
1165 REGISTER_VARIABLE(
"TagTrackDistanceToTagVErr(i)", tagTrackDistanceToTagVErr, R
"DOC(
1166Returns the estimated error on the distance between the ith tag track and the tag vtx.
1168.. warning:: Only the uncertainties on the track position parameters are taken into account.
1172 REGISTER_VARIABLE(
"TagTrackDistanceToTagVSignificance(i)", tagTrackDistanceToTagVSignificance,
1173 "Returns the significance of the distance between the tag vtx and the tag track indexed by trackIndex (computed as distance / uncertainty)");
1175 REGISTER_VARIABLE(
"TagTrackTrueDistanceToTagV(i)", tagTrackTrueDistanceToTagV,
1176 "Returns the true distance between the true B Tag decay vertex and the particle corresponding to the ith tag vtx track.\n\n",
"cm");
1178 REGISTER_VARIABLE(
"TagTrackTrueVecToTagVX(i)", tagTrackTrueVecToTagVX,
1179 "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.\n\n",
1182 REGISTER_VARIABLE(
"TagTrackTrueVecToTagVY(i)", tagTrackTrueVecToTagVY,
1183 "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.\n\n",
1186 REGISTER_VARIABLE(
"TagTrackTrueVecToTagVZ(i)", tagTrackTrueVecToTagVZ,
1187 "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.\n\n",
1190 REGISTER_VARIABLE(
"TagTrackTrueMomentumX(i)", tagTrackTrueMomentumX,
1191 "Returns the X component of the true momentum of the MC particle corresponding to the ith tag vtx track.\n\n",
"GeV/c");
1193 REGISTER_VARIABLE(
"TagTrackTrueMomentumY(i)", tagTrackTrueMomentumY,
1194 "Returns the Y component of the true momentum of the MC particle corresponding to the ith tag vtx track.\n\n",
"GeV/c");
1196 REGISTER_VARIABLE(
"TagTrackTrueMomentumZ(i)", tagTrackTrueMomentumZ,
1197 "Returns the Z component of the true momentum of the MC particle corresponding to the ith tag vtx track.\n\n",
"GeV/c");
1199 REGISTER_VARIABLE(
"TagTrackTrueOriginX(i)", tagTrackTrueOriginX,
1200 "Returns the X component of the true origin of the MC particle corresponding to the ith tag vtx track.\n\n",
"cm");
1202 REGISTER_VARIABLE(
"TagTrackTrueOriginY(i)", tagTrackTrueOriginY,
1203 "Returns the Y component of the true origin of the MC particle corresponding to the ith tag vtx track.\n\n",
"cm");
1205 REGISTER_VARIABLE(
"TagTrackTrueOriginZ(i)", tagTrackTrueOriginZ,
1206 "Returns the Z component of the true origin of the MC particle corresponding to the ith tag vtx track.\n\n",
"cm");
1208 REGISTER_VARIABLE(
"TagVFitTruthStatus", fitTruthStatus, R
"DOC(
1209Returns the status of the fit performed with the truth info. Possible values are:
1211- -1: no related TagVertex found
1212- 0: fit performed with measured parameters
1213- 1: fit performed with true parameters
1214- 2: unable to recover truth parameters
1217 REGISTER_VARIABLE("TagVRollBackStatus", rollbackStatus, R
"DOC(
1218Returns the status of the fit performed with rolled back tracks. Possible values are:
1220- -1: no related TagVertex found
1221- 0: fit performed with measured parameters
1222- 1: fit performed with true parameters
1223- 2: unable to recover truth parameters
1226 REGISTER_METAVARIABLE("TagTrackMax(var)", tagTrackMax,
1227 "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.",
1228 Manager::VariableDataType::c_double);
1230 REGISTER_METAVARIABLE(
"TagTrackMin(var)", tagTrackMin,
1231 "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.",
1232 Manager::VariableDataType::c_double);
1234 REGISTER_METAVARIABLE(
"TagTrackAverage(var)", tagTrackAverage,
1235 "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.",
1236 Manager::VariableDataType::c_double);
1238 REGISTER_METAVARIABLE(
"TagTrackAverageSquares(var)", tagTrackAverageSquares,
1239 "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.",
1240 Manager::VariableDataType::c_double);
1242 REGISTER_METAVARIABLE(
"TagTrackWeightedAverage(var)", tagTrackWeightedAverage,
1243 "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)``.",
1244 Manager::VariableDataType::c_double);
1246 REGISTER_METAVARIABLE(
"TagTrackWeightedAverageSquares(var)", tagTrackWeightedAverageSquares,
1247 "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)``.",
1248 Manager::VariableDataType::c_double);
1250 REGISTER_METAVARIABLE(
"TagTrackSum(var)", tagTrackSum,
1251 "Returns the sum of the provided variable for all tag tracks. The variable must be one of the TagTrackXXX variables, "
1252 "for example ``TagTrackSum(TagTrackD0)``. The tracks that are assigned a zero weight are ignored.",
1253 Manager::VariableDataType::c_double);
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
static const double speedOfLight
[cm/ns]
static const double doubleNaN
quiet_NaN
const MCParticle * getMCParticle() const
Returns the pointer to the MCParticle object that was used to create this Particle (ParticleType == c...
static const ReferenceFrame & GetCurrent()
Get current rest frame.
std::function< VarVariant(const Particle *)> FunctionPtr
functions stored take a const Particle* and return VarVariant.
Class to store variables with their name which were sent to the logging service.
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!)
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.