12 #include <analysis/variables/TimeDependentVariables.h>
13 #include <analysis/VariableManager/Manager.h>
15 #include <analysis/utility/PCmsLabTransform.h>
16 #include <framework/dbobjects/BeamParameters.h>
19 #include <analysis/dataobjects/Particle.h>
20 #include <analysis/dataobjects/TagVertex.h>
21 #include <mdst/dataobjects/MCParticle.h>
24 #include <analysis/utility/DistanceTools.h>
25 #include <analysis/utility/RotationTools.h>
28 #include <framework/gearbox/Const.h>
47 using RotationTools::getUnitOrthogonal;
48 using RotationTools::toVec;
50 static const double realNaN = std::numeric_limits<double>::quiet_NaN();
57 double particleTagVx(
const Particle* particle)
59 auto* vert = particle->getRelatedTo<TagVertex>();
61 return vert->getTagVertex().X();
64 double particleTagVy(
const Particle* particle)
66 auto* vert = particle->getRelatedTo<TagVertex>();
68 return vert->getTagVertex().Y();
71 double particleTagVz(
const Particle* particle)
73 auto* vert = particle->getRelatedTo<TagVertex>();
75 return vert->getTagVertex().Z();
78 double particleTruthTagVx(
const Particle* particle)
80 auto* vert = particle->getRelatedTo<TagVertex>();
82 return vert->getMCTagVertex().X();
85 double particleTruthTagVy(
const Particle* particle)
87 auto* vert = particle->getRelatedTo<TagVertex>();
89 return vert->getMCTagVertex().Y();
92 double particleTruthTagVz(
const Particle* particle)
94 auto* vert = particle->getRelatedTo<TagVertex>();
96 return vert->getMCTagVertex().Z();
99 double particleTagVxErr(
const Particle* particle)
101 auto* vert = particle->getRelatedTo<TagVertex>();
103 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
104 return sqrt(TagVErr(0, 0));
107 double particleTagVyErr(
const Particle* particle)
109 auto* vert = particle->getRelatedTo<TagVertex>();
111 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
112 return sqrt(TagVErr(1, 1));
115 double particleTagVzErr(
const Particle* particle)
117 auto* vert = particle->getRelatedTo<TagVertex>();
119 TMatrixDSym TagVErr = vert->getTagVertexErrMatrix();
120 return sqrt(TagVErr(2, 2));
123 double particleTagVpVal(
const Particle* particle)
125 auto* vert = particle->getRelatedTo<TagVertex>();
127 return vert->getTagVertexPval();
130 double particleTagVNTracks(
const Particle* particle)
132 auto* vert = particle->getRelatedTo<TagVertex>();
134 return vert->getNTracks();
137 double particleTagVNFitTracks(
const Particle* particle)
139 auto* vert = particle->getRelatedTo<TagVertex>();
141 return vert->getNFitTracks();
144 double particleTagVType(
const Particle* particle)
146 auto* vert = particle->getRelatedTo<TagVertex>();
148 return vert->getFitType();
151 double particleTagVNDF(
const Particle* particle)
153 auto* vert = particle->getRelatedTo<TagVertex>();
155 return vert->getTagVNDF();
158 double particleTagVChi2(
const Particle* particle)
160 auto* vert = particle->getRelatedTo<TagVertex>();
162 return vert->getTagVChi2();
165 double particleTagVChi2IP(
const Particle* particle)
167 auto* vert = particle->getRelatedTo<TagVertex>();
169 return vert->getTagVChi2IP();
175 double particleDeltaT(
const Particle* particle)
177 auto* vert = particle->getRelatedTo<TagVertex>();
179 return vert->getDeltaT();
182 double particleDeltaTErr(
const Particle* particle)
184 auto* vert = particle->getRelatedTo<TagVertex>();
186 return vert->getDeltaTErr();
188 double particleDeltaTRes(
const Particle* particle)
190 return particleDeltaT(particle) - particleMCDeltaT(particle);
193 double particleDeltaTBelle(
const Particle* particle)
195 double beta = PCmsLabTransform().getBoostVector().Mag();
196 double bg = beta / sqrt(1 - beta * beta);
197 double c = Const::speedOfLight / 1000.;
198 return particleDeltaZ(particle) / (bg * c);
201 double particleMCDeltaTau(
const Particle* particle)
203 auto* vert = particle->getRelatedTo<TagVertex>();
205 return vert->getMCDeltaTau();
208 double particleMCDeltaT(
const Particle* particle)
210 auto* vert = particle->getRelatedTo<TagVertex>();
212 return vert->getMCDeltaT();
215 double particleMCDeltaBoost(
const Particle* particle)
217 auto* vert = particle->getRelatedTo<TagVertex>();
220 double beta = PCmsLabTransform().getBoostVector().Mag();
221 double bg = beta / sqrt(1 - beta * beta);
222 double c = Const::speedOfLight / 1000.;
223 return vert->getMCDeltaT() * bg * c;
227 double particleDeltaZ(
const Particle* particle)
229 auto* vert = particle->getRelatedTo<TagVertex>();
231 return particle->getZ() - vert->getTagVertex().Z();
234 double particleDeltaZErr(
const Particle* particle)
236 auto* vert = particle->getRelatedTo<TagVertex>();
239 double zVariance = particle->getVertexErrorMatrix()(2, 2);
240 double TagVZVariance = vert->getTagVertexErrMatrix()(2, 2);
241 double result = sqrt(zVariance + TagVZVariance);
242 if (!std::isfinite(result))
return realNaN;
247 double particleDeltaB(
const Particle* particle)
249 auto* vert = particle->getRelatedTo<TagVertex>();
252 double beta = PCmsLabTransform().getBoostVector().Mag();
253 double bg = beta / sqrt(1 - beta * beta);
254 double c = Const::speedOfLight / 1000.;
255 return vert->getDeltaT() * bg * c;
258 double particleDeltaBErr(
const Particle* particle)
260 auto* vert = particle->getRelatedTo<TagVertex>();
263 double beta = PCmsLabTransform().getBoostVector().Mag();
264 double bg = beta / sqrt(1 - beta * beta);
265 double c = Const::speedOfLight / 1000.;
266 return vert->getDeltaTErr() * bg * c;
271 double vertexBoostDirection(
const Particle* part)
273 TVector3 boostDir = PCmsLabTransform().getBoostVector().Unit();
274 TVector3 pos = part->getVertex();
275 return pos.Dot(boostDir);
278 double vertexOrthogonalBoostDirection(
const Particle* part)
280 TVector3 boost = PCmsLabTransform().getBoostVector();
281 TVector3 orthBoostDir = getUnitOrthogonal(boost);
283 TVector3 pos = part->getVertex();
284 return pos.Dot(orthBoostDir);
287 double vertexTruthBoostDirection(
const Particle* part)
289 static DBObjPtr<BeamParameters> beamParamsDB;
290 TVector3 boostDir = (beamParamsDB->getHER() + beamParamsDB->getLER()).BoostVector().Unit();
292 const MCParticle* mcPart = part->getRelated<MCParticle>();
294 TVector3 pos = mcPart->getDecayVertex();
295 return pos.Dot(boostDir);
298 double vertexTruthOrthogonalBoostDirection(
const Particle* part)
300 static DBObjPtr<BeamParameters> beamParamsDB;
301 TVector3 boost = (beamParamsDB->getHER() + beamParamsDB->getLER()).BoostVector();
302 TVector3 orthBoostDir = getUnitOrthogonal(boost);
304 const MCParticle* mcPart = part->getRelated<MCParticle>();
306 TVector3 pos = mcPart->getDecayVertex();
307 return pos.Dot(orthBoostDir);
311 double vertexErrBoostDirection(
const Particle* part)
313 TVectorD bDir = toVec(PCmsLabTransform().getBoostVector().Unit());
315 return sqrt(part->getVertexErrorMatrix().Similarity(bDir));
319 double vertexErrOrthBoostDirection(
const Particle* part)
321 TVectorD oDir = toVec(getUnitOrthogonal(PCmsLabTransform().getBoostVector()));
323 return sqrt(part->getVertexErrorMatrix().Similarity(oDir));
330 double tagVBoostDirection(
const Particle* part)
332 auto* vert = part->getRelatedTo<TagVertex>();
334 return vert->getTagVl();
338 double tagVOrthogonalBoostDirection(
const Particle* part)
340 auto* vert = part->getRelatedTo<TagVertex>();
342 return vert->getTagVol();
346 double tagVTruthBoostDirection(
const Particle* part)
348 auto* vert = part->getRelatedTo<TagVertex>();
350 return vert->getTruthTagVl();
354 double tagVTruthOrthogonalBoostDirection(
const Particle* part)
356 auto* vert = part->getRelatedTo<TagVertex>();
358 return vert->getTruthTagVol();
361 double tagVErrBoostDirection(
const Particle* part)
363 auto* vert = part->getRelatedTo<TagVertex>();
365 return vert->getTagVlErr();
369 double tagVErrOrthogonalBoostDirection(
const Particle* part)
371 auto* vert = part->getRelatedTo<TagVertex>();
373 return vert->getTagVolErr();
377 double particleInternalTagVMCFlavor(
const Particle* part)
379 auto* vert = part->getRelatedTo<TagVertex>();
381 return vert->getMCTagBFlavor();
384 double tagTrackMomentum(
const Particle* part,
const std::vector<double>& trackIndex)
386 auto* vert = part->getRelatedTo<TagVertex>();
389 if (trackIndex.size() != 1)
return realNaN;
390 unsigned trackIndexInt = trackIndex.at(0);
392 return vert->getVtxFitTrackP(trackIndexInt).Mag();
395 double tagTrackMomentumX(
const Particle* part,
const std::vector<double>& trackIndex)
397 auto* vert = part->getRelatedTo<TagVertex>();
400 if (trackIndex.size() != 1)
return realNaN;
401 unsigned trackIndexInt = trackIndex.at(0);
403 return vert->getVtxFitTrackPComponent(trackIndexInt, 0);
406 double tagTrackMomentumY(
const Particle* part,
const std::vector<double>& trackIndex)
408 auto* vert = part->getRelatedTo<TagVertex>();
411 if (trackIndex.size() != 1)
return realNaN;
412 unsigned trackIndexInt = trackIndex.at(0);
414 return vert->getVtxFitTrackPComponent(trackIndexInt, 1);
417 double tagTrackMomentumZ(
const Particle* part,
const std::vector<double>& trackIndex)
419 auto* vert = part->getRelatedTo<TagVertex>();
422 if (trackIndex.size() != 1)
return realNaN;
423 unsigned trackIndexInt = trackIndex.at(0);
425 return vert->getVtxFitTrackPComponent(trackIndexInt, 2);
428 double tagTrackZ0(
const Particle* part,
const std::vector<double>& trackIndex)
430 auto* vert = part->getRelatedTo<TagVertex>();
433 if (trackIndex.size() != 1)
return realNaN;
434 unsigned trackIndexInt = trackIndex.at(0);
436 return vert->getVtxFitTrackZ0(trackIndexInt);
439 double tagTrackD0(
const Particle* part,
const std::vector<double>& trackIndex)
441 auto* vert = part->getRelatedTo<TagVertex>();
444 if (trackIndex.size() != 1)
return realNaN;
445 unsigned trackIndexInt = trackIndex.at(0);
447 return vert->getVtxFitTrackD0(trackIndexInt);
450 double tagTrackRaveWeight(
const Particle* part,
const std::vector<double>& trackIndex)
452 auto* vert = part->getRelatedTo<TagVertex>();
455 if (trackIndex.size() != 1)
return realNaN;
456 unsigned trackIndexInt = trackIndex.at(0);
458 return vert->getRaveWeight(trackIndexInt);
461 double tagTrackDistanceToConstraint(
const Particle* part,
const std::vector<double>& trackIndex)
463 auto* vert = part->getRelatedTo<TagVertex>();
466 if (trackIndex.size() != 1)
return realNaN;
467 unsigned trackIndexInt = trackIndex.at(0);
469 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
470 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
471 if (!tagParticle)
return realNaN;
473 return DistanceTools::trackToVtxDist(tagParticle->getTrackFitResult()->getPosition(),
474 tagParticle->getMomentum(),
475 vert->getConstraintCenter());
478 double tagTrackDistanceToConstraintErr(
const Particle* part,
const std::vector<double>& trackIndex)
480 auto* vert = part->getRelatedTo<TagVertex>();
483 if (trackIndex.size() != 1)
return realNaN;
484 unsigned trackIndexInt = trackIndex.at(0);
486 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
487 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
488 if (!tagParticle)
return realNaN;
491 TMatrixDSym trackPosCovMat = tagParticle->getVertexErrorMatrix();
493 return DistanceTools::trackToVtxDistErr(tagParticle->getTrackFitResult()->getPosition(),
494 tagParticle->getMomentum(),
495 vert->getConstraintCenter(),
497 vert->getConstraintCov());
500 double tagTrackDistanceToConstraintSignificance(
const Particle* part,
const std::vector<double>& trackIndex)
502 double val = tagTrackDistanceToConstraint(part, trackIndex);
503 if (isinf(val) || isnan(val))
return realNaN;
504 double err = tagTrackDistanceToConstraintErr(part, trackIndex);
505 if (isinf(err) || isnan(err))
return realNaN;
510 double tagVDistanceToConstraint(
const Particle* part)
512 auto* vert = part->getRelatedTo<TagVertex>();
515 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
517 return DistanceTools::vtxToVtxDist(vert->getConstraintCenter(),
518 vert->getTagVertex());
521 double tagVDistanceToConstraintErr(
const Particle* part)
523 auto* vert = part->getRelatedTo<TagVertex>();
526 if (vert->getConstraintType() ==
"noConstraint")
return realNaN;
531 TMatrixDSym emptyMat(3);
533 return DistanceTools::vtxToVtxDistErr(vert->getConstraintCenter(),
534 vert->getTagVertex(),
535 vert->getConstraintCov(),
539 double tagVDistanceToConstraintSignificance(
const Particle* part)
541 double val = tagVDistanceToConstraint(part);
542 if (isinf(val) || isnan(val))
return realNaN;
543 double err = tagVDistanceToConstraintErr(part);
544 if (isinf(err) || isnan(err))
return realNaN;
549 double tagTrackDistanceToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
551 auto* vert = part->getRelatedTo<TagVertex>();
554 if (trackIndex.size() != 1)
return realNaN;
555 unsigned trackIndexInt = trackIndex.at(0);
557 const Particle* particle = vert->getVtxFitParticle(trackIndexInt);
560 return DistanceTools::trackToVtxDist(particle->getTrackFitResult()->getPosition(),
561 particle->getMomentum(),
562 vert->getTagVertex());
565 double tagTrackDistanceToTagVErr(
const Particle* part,
const std::vector<double>& trackIndex)
567 auto* vert = part->getRelatedTo<TagVertex>();
570 if (trackIndex.size() != 1)
return realNaN;
571 unsigned trackIndexInt = trackIndex.at(0);
573 const Particle* tagParticle(vert->getVtxFitParticle(trackIndexInt));
574 if (!tagParticle)
return realNaN;
577 TMatrixDSym trackPosCovMat = tagParticle->getVertexErrorMatrix();
583 TMatrixDSym emptyMat(3);
585 return DistanceTools::trackToVtxDistErr(tagParticle->getTrackFitResult()->getPosition(),
586 tagParticle->getMomentum(),
587 vert->getTagVertex(),
593 double tagTrackDistanceToTagVSignificance(
const Particle* part,
const std::vector<double>& trackIndex)
595 double val = tagTrackDistanceToTagV(part, trackIndex);
596 if (isinf(val) || isnan(val))
return realNaN;
597 double err = tagTrackDistanceToTagVErr(part, trackIndex);
598 if (isinf(err) || isnan(err))
return realNaN;
603 double tagTrackTrueDistanceToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
605 auto* vert = part->getRelatedTo<TagVertex>();
608 if (trackIndex.size() != 1)
return realNaN;
609 unsigned trackIndexInt = trackIndex.at(0);
611 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
612 if (!mcParticle)
return realNaN;
614 TVector3 mcTagV = vert->getMCTagVertex();
616 if (mcTagV(0) == 0 && mcTagV(1) == 0 && mcTagV(2) == 0)
return realNaN;
618 return DistanceTools::trackToVtxDist(mcParticle->getProductionVertex(),
619 mcParticle->getMomentum(),
623 TVector3 tagTrackTrueVecToTagV(
const Particle* part,
const std::vector<double>& trackIndex)
625 auto* vert = part->getRelatedTo<TagVertex>();
628 if (trackIndex.size() != 1)
return vecNaN;
629 unsigned trackIndexInt = trackIndex.at(0);
631 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
632 if (!mcParticle)
return vecNaN;
634 TVector3 mcTagV = vert->getMCTagVertex();
636 if (mcTagV(0) == 0 && mcTagV(1) == 0 && mcTagV(2) == 0)
return vecNaN;
638 return DistanceTools::trackToVtxVec(mcParticle->getProductionVertex(),
639 mcParticle->getMomentum(),
643 double tagTrackTrueVecToTagVX(
const Particle* part,
const std::vector<double>& trackIndex)
645 TVector3 result = tagTrackTrueVecToTagV(part, trackIndex);
649 double tagTrackTrueVecToTagVY(
const Particle* part,
const std::vector<double>& trackIndex)
651 TVector3 result = tagTrackTrueVecToTagV(part, trackIndex);
655 double tagTrackTrueVecToTagVZ(
const Particle* part,
const std::vector<double>& trackIndex)
657 TVector3 result = tagTrackTrueVecToTagV(part, trackIndex);
661 TVector3 tagTrackTrueMomentum(
const Particle* part,
const std::vector<double>& trackIndex)
663 auto* vert = part->getRelatedTo<TagVertex>();
666 if (trackIndex.size() != 1)
return vecNaN;
667 unsigned trackIndexInt = trackIndex.at(0);
669 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
670 if (!mcParticle)
return vecNaN;
672 return mcParticle->getMomentum();
675 double tagTrackTrueMomentumX(
const Particle* part,
const std::vector<double>& trackIndex)
677 TVector3 pTrue = tagTrackTrueMomentum(part, trackIndex);
681 double tagTrackTrueMomentumY(
const Particle* part,
const std::vector<double>& trackIndex)
683 TVector3 pTrue = tagTrackTrueMomentum(part, trackIndex);
687 double tagTrackTrueMomentumZ(
const Particle* part,
const std::vector<double>& trackIndex)
689 TVector3 pTrue = tagTrackTrueMomentum(part, trackIndex);
693 TVector3 tagTrackTrueOrigin(
const Particle* part,
const std::vector<double>& trackIndex)
695 auto* vert = part->getRelatedTo<TagVertex>();
698 if (trackIndex.size() != 1)
return vecNaN;
699 unsigned trackIndexInt = trackIndex.at(0);
701 const MCParticle* mcParticle(vert->getVtxFitMCParticle(trackIndexInt));
702 if (!mcParticle)
return vecNaN;
704 return mcParticle->getProductionVertex();
707 double tagTrackTrueOriginX(
const Particle* part,
const std::vector<double>& trackIndex)
709 TVector3 origin = tagTrackTrueOrigin(part, trackIndex);
713 double tagTrackTrueOriginY(
const Particle* part,
const std::vector<double>& trackIndex)
715 TVector3 origin = tagTrackTrueOrigin(part, trackIndex);
719 double tagTrackTrueOriginZ(
const Particle* part,
const std::vector<double>& trackIndex)
721 TVector3 origin = tagTrackTrueOrigin(part, trackIndex);
725 int fitTruthStatus(
const Particle* part)
727 auto* vert = part->getRelatedTo<TagVertex>();
728 if (!vert)
return std::numeric_limits<int>::quiet_NaN();
729 return vert->getFitTruthStatus();
732 int rollbackStatus(
const Particle* part)
734 auto* vert = part->getRelatedTo<TagVertex>();
735 if (!vert)
return std::numeric_limits<int>::quiet_NaN();
736 return vert->getRollBackStatus();
748 TagTrFPtr getTagTrackFunctionFromName(
string const& name)
750 if (name ==
"TagTrackMomentum")
return tagTrackMomentum;
751 else if (name ==
"TagTrackMomentumX")
return tagTrackMomentumX;
752 else if (name ==
"TagTrackMomentumY")
return tagTrackMomentumY;
753 else if (name ==
"TagTrackMomentumZ")
return tagTrackMomentumZ;
754 else if (name ==
"TagTrackZ0")
return tagTrackZ0;
755 else if (name ==
"TagTrackD0")
return tagTrackD0;
756 else if (name ==
"TagTrackRaveWeight")
return tagTrackRaveWeight;
757 else if (name ==
"TagTrackDistanceToConstraint")
return tagTrackDistanceToConstraint;
758 else if (name ==
"TagTrackDistanceToConstraintErr")
return tagTrackDistanceToConstraintErr;
759 else if (name ==
"TagTrackDistanceToConstraintSignificance")
return tagTrackDistanceToConstraintSignificance;
760 else if (name ==
"TagTrackDistanceToTagV")
return tagTrackDistanceToTagV;
761 else if (name ==
"TagTrackDistanceToTagVErr")
return tagTrackDistanceToTagVErr;
762 else if (name ==
"TagTrackDistanceToTagVSignificance")
return tagTrackDistanceToTagVSignificance;
763 else if (name ==
"TagTrackTrueDistanceToTagV")
return tagTrackTrueDistanceToTagV;
764 else if (name ==
"TagTrackTrueVecToTagVX")
return tagTrackTrueVecToTagVX;
765 else if (name ==
"TagTrackTrueVecToTagVY")
return tagTrackTrueVecToTagVY;
766 else if (name ==
"TagTrackTrueVecToTagVZ")
return tagTrackTrueVecToTagVZ;
767 else if (name ==
"TagTrackTrueMomentumX")
return tagTrackTrueMomentumX;
768 else if (name ==
"TagTrackTrueMomentumY")
return tagTrackTrueMomentumY;
769 else if (name ==
"TagTrackTrueMomentumZ")
return tagTrackTrueMomentumZ;
770 else if (name ==
"TagTrackTrueOriginX")
return tagTrackTrueOriginX;
771 else if (name ==
"TagTrackTrueOriginY")
return tagTrackTrueOriginY;
772 else if (name ==
"TagTrackTrueOriginZ")
return tagTrackTrueOriginZ;
774 B2ERROR(
"From TimeDependentVariables: Trying to access unknown tagTrack function");
779 double cumulate(
const Particle* part,
const std::vector<std::string>& variable,
double start,
780 std::function<
double(
double,
double,
double)> fun)
782 TagTrFPtr fptr(getTagTrackFunctionFromName(variable.at(0)));
783 auto* vert = part->getRelatedTo<TagVertex>();
785 int nTracks = vert->getNFitTracks();
789 for (
int i = 0; i < nTracks; ++i) {
790 vector<double> indx(1, i);
791 double w = tagTrackRaveWeight(part, indx);
792 double f = (*fptr)(part, indx);
794 acum = fun(acum, f, w);
800 Manager::FunctionPtr tagTrackAverage(
const std::vector<std::string>& variable)
802 if (variable.size() != 1) {
803 B2FATAL(
"Wrong number of arguments for meta function tagTrackAverage");
807 return [variable](
const Particle * part) {
808 double sum = cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f;});
809 double tot = cumulate(part, variable, 0, [](
double s,
double ,
double) {
return s + 1;});
810 return (tot > 0) ? sum / tot :
realNaN;
814 Manager::FunctionPtr tagTrackAverageSquares(
const std::vector<std::string>& variable)
816 if (variable.size() != 1) {
817 B2FATAL(
"Wrong number of arguments for meta function tagTrackAverageSquares");
821 return [variable](
const Particle * part) {
822 double sum = cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f * f;});
823 double tot = cumulate(part, variable, 0, [](
double s,
double ,
double) {
return s + 1;});
824 return (tot > 0) ? sum / tot :
realNaN;
829 Manager::FunctionPtr tagTrackMax(
const std::vector<std::string>& variable)
831 if (variable.size() != 1) {
832 B2FATAL(
"Wrong number of arguments for meta function tagTrackMax");
836 return [variable](
const Particle * part) {
837 double Max = cumulate(part, variable, -DBL_MAX, [](
double s,
double f,
double) {
return std::max(s, f);});
838 return (Max != -DBL_MAX) ? Max :
realNaN;
842 Manager::FunctionPtr tagTrackMin(
const std::vector<std::string>& variable)
844 if (variable.size() != 1) {
845 B2FATAL(
"Wrong number of arguments for meta function tagTrackMin");
849 return [variable](
const Particle * part) {
850 double Min = cumulate(part, variable, +DBL_MAX, [](
double s,
double f,
double) {
return std::min(s, f);});
851 return (Min != DBL_MAX) ? Min :
realNaN;
855 Manager::FunctionPtr tagTrackWeightedAverage(
const std::vector<std::string>& variable)
857 if (variable.size() != 1) {
858 B2FATAL(
"Wrong number of arguments for meta function tagTrackWeightedAverage");
862 return [variable](
const Particle * part) {
863 double num = cumulate(part, variable, 0, [](
double s,
double f,
double w) {
return s + w * f;});
864 double den = cumulate(part, variable, 0, [](
double s,
double ,
double w) {
return s + w;});
865 return (den > 0) ? num / den :
realNaN;
869 Manager::FunctionPtr tagTrackWeightedAverageSquares(
const std::vector<std::string>& variable)
871 if (variable.size() != 1) {
872 B2FATAL(
"Wrong number of arguments for meta function tagTrackWeightedAverageSquares");
876 return [variable](
const Particle * part) ->
double {
877 double num = cumulate(part, variable, 0, [](
double s,
double f,
double w) {
return s + w * f * f;});
878 double den = cumulate(part, variable, 0, [](
double s,
double ,
double w) {
return s + w;});
879 return (den > 0) ? num / den :
realNaN;
883 Manager::FunctionPtr tagTrackSum(
const std::vector<std::string>& variable)
885 if (variable.size() != 1) {
886 B2FATAL(
"Wrong number of arguments for meta function tagTrackSum");
890 return [variable](
const Particle * part) {
891 return cumulate(part, variable, 0, [](
double s,
double f,
double) {
return s + f;});
900 VARIABLE_GROUP(
"Time Dependent CPV Analysis Variables");
902 REGISTER_VARIABLE(
"TagVx", particleTagVx,
"Tag vertex X component");
903 REGISTER_VARIABLE(
"TagVy", particleTagVy,
"Tag vertex Y component");
904 REGISTER_VARIABLE(
"TagVz", particleTagVz,
"Tag vertex Z component");
905 REGISTER_VARIABLE(
"mcTagVx", particleTruthTagVx,
"Generated Tag vertex X component");
906 REGISTER_VARIABLE(
"mcTagVy", particleTruthTagVy,
"Generated Tag vertex Y component");
907 REGISTER_VARIABLE(
"mcTagVz", particleTruthTagVz,
"Generated Tag vertex Z component");
908 REGISTER_VARIABLE(
"TagVxErr", particleTagVxErr,
"Tag vertex X component uncertainty");
909 REGISTER_VARIABLE(
"TagVyErr", particleTagVyErr,
"Tag vertex Y component uncertainty");
910 REGISTER_VARIABLE(
"TagVzErr", particleTagVzErr,
"Tag vertex Z component uncertainty");
911 REGISTER_VARIABLE(
"TagVpVal", particleTagVpVal,
"Tag vertex p-Value");
912 REGISTER_VARIABLE(
"TagVNTracks", particleTagVNTracks,
"Number of tracks in the tag vertex");
913 REGISTER_VARIABLE(
"TagVType", particleTagVType,
914 R
"DOC(Type of algo for the tag vertex. -1: failed (1,2: single track, deprecated), 3: standard, 4: standard_PXD, 5: no constraint)DOC");
915 REGISTER_VARIABLE("TagVNDF", particleTagVNDF,
"Number of degrees of freedom in the tag vertex fit");
916 REGISTER_VARIABLE(
"TagVChi2", particleTagVChi2,
"chi2 value of the tag vertex fit");
917 REGISTER_VARIABLE(
"TagVChi2IP", particleTagVChi2IP,
"IP component of chi2 value of the tag vertex fit");
919 REGISTER_VARIABLE(
"DeltaT", particleDeltaT,
920 R
"DOC(Proper decay time difference :math:`\Delta t` between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})` in ps.)DOC");
921 REGISTER_VARIABLE("DeltaTErr", particleDeltaTErr,
922 R
"DOC(Proper decay time difference :math:`\Delta t` uncertainty in ps)DOC");
923 REGISTER_VARIABLE("DeltaTRes", particleDeltaTRes,
924 R
"DOC(:math:`\Delta t` residual in ps, to be used for resolution function studies)DOC");
925 REGISTER_VARIABLE("DeltaTBelle", particleDeltaTBelle,
926 R
"DOC([Legacy] :math:`\Delta t` in ps, as it was used in Belle)DOC");
927 REGISTER_VARIABLE("mcDeltaTau", particleMCDeltaTau,
928 R
"DOC(Generated proper decay time difference :math:`\Delta t` in ps: :math:`\tau(B_{\rm rec})-\tau(B_{\rm tag})`)DOC");
929 REGISTER_VARIABLE("mcDeltaT", particleMCDeltaT,
930 R
"DOC(Generated proper decay time difference (in z-difference approximation) :math:`\Delta t` in ps: :math:`(l(B_{\rm rec}) - l(B_{\rm tag}))/\beta_{\Upsilon(4S)}\gamma_{\Upsilon(4S)}`)DOC");
931 REGISTER_VARIABLE("mcDeltaBoost", particleMCDeltaBoost,
932 R
"DOC(True difference of decay vertex boost-direction components between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`:
933 :math:`\Delta l = l(B_{rec}) - l(B_{tag})`)DOC");
934 REGISTER_VARIABLE("DeltaZ", particleDeltaZ,
935 R
"DOC(Difference of decay vertex longitudinal components between signal B-meson :math:`(B_{rec})` and tag B-meson :math:`(B_{tag})`:
936 :math:`\Delta z = z(B_{rec}) - z(B_{tag})`)DOC");
937 REGISTER_VARIABLE("DeltaZErr", particleDeltaZErr,
938 R
"DOC(Uncertainty of the difference :math:`z(B_{rec}) - z(B_{tag})`)DOC");
939 REGISTER_VARIABLE("DeltaBoost", particleDeltaB, R
"DOC(:math:`\Delta z` in the boost direction)DOC");
940 REGISTER_VARIABLE("DeltaBoostErr", particleDeltaBErr, R
"DOC(Uncertanty of :math:`\Delta z` in the boost direction)DOC");
942 REGISTER_VARIABLE("LBoost", vertexBoostDirection,
943 "Returns the vertex component in the boost direction");
944 REGISTER_VARIABLE(
"OBoost", vertexOrthogonalBoostDirection,
945 "Returns the vertex component in the direction orthogonal to the boost");
946 REGISTER_VARIABLE(
"mcLBoost", vertexTruthBoostDirection,
947 "Returns the MC vertex component in the boost direction");
948 REGISTER_VARIABLE(
"mcOBoost", vertexTruthOrthogonalBoostDirection,
949 "Returns the MC vertex component in the direction orthogonal to the boost");
950 REGISTER_VARIABLE(
"LBoostErr", vertexErrBoostDirection,
951 "Returns the error of the vertex in the boost direction");
952 REGISTER_VARIABLE(
"OBoostErr", vertexErrOrthBoostDirection,
953 "Returns the error of the vertex in the direction orthogonal to the boost");
955 REGISTER_VARIABLE(
"TagVLBoost", tagVBoostDirection,
956 "Returns the TagV component in the boost direction");
957 REGISTER_VARIABLE(
"TagVOBoost", tagVOrthogonalBoostDirection,
958 "Returns the TagV component in the direction orthogonal to the boost");
959 REGISTER_VARIABLE(
"mcTagVLBoost", tagVTruthBoostDirection,
960 "Returns the MC TagV component in the boost direction");
961 REGISTER_VARIABLE(
"mcTagVOBoost", tagVTruthOrthogonalBoostDirection,
962 "Returns the MC TagV component in the direction orthogonal to the boost");
963 REGISTER_VARIABLE(
"TagVLBoostErr", tagVErrBoostDirection,
964 "Returns the error of TagV in the boost direction");
965 REGISTER_VARIABLE(
"TagVOBoostErr", tagVErrOrthogonalBoostDirection,
966 "Returns the error of TagV in the direction orthogonal to the boost");
968 REGISTER_VARIABLE(
"internalTagVMCFlavor", particleInternalTagVMCFlavor,
969 "[Expert] [Debugging] This variable is only for internal checks of the TagV module by developers. \n"
970 "It returns the internal mc flavor information of the tag-side B provided by the TagV module.");
972 REGISTER_VARIABLE(
"TagTrackMomentum(i) ", tagTrackMomentum,
973 "return the magnitude of the momentum of the ith track used in the tag vtx fit.");
974 REGISTER_VARIABLE(
"TagTrackMomentumX(i) ", tagTrackMomentumX,
975 "return the X component of the momentum of the ith track used in the tag vtx fit.");
976 REGISTER_VARIABLE(
"TagTrackMomentumY(i) ", tagTrackMomentumY,
977 "return the Y component of the momentum of the ith track used in the tag vtx fit.");
978 REGISTER_VARIABLE(
"TagTrackMomentumZ(i) ", tagTrackMomentumZ,
979 "return the Z component of the momentum of the ith track used in the tag vtx fit.");
981 REGISTER_VARIABLE(
"TagTrackZ0(i)", tagTrackZ0,
"return the z0 parameter of the ith track used in the tag vtx fit");
982 REGISTER_VARIABLE(
"TagTrackD0(i)", tagTrackD0,
"return the d0 parameter of the ith track used in the tag vtx fit");
985 REGISTER_VARIABLE(
"TagTrackRaveWeight(i)", tagTrackRaveWeight,
"returns the weight assigned by Rave to track i");
987 REGISTER_VARIABLE(
"TagVNFitTracks", particleTagVNFitTracks,
988 "returns the number of tracks used by rave to fit the vertex (not counting the ones coming from Kshorts)");
990 REGISTER_VARIABLE(
"TagTrackDistanceToConstraint(i)", tagTrackDistanceToConstraint,
991 "returns the measured distance between the ith tag track and the centre of the constraint.");
993 REGISTER_VARIABLE(
"TagTrackDistanceToConstraintErr(i)", tagTrackDistanceToConstraintErr,
994 "returns the estimated error on the distance between the ith tag track and the centre of the constraint.");
996 REGISTER_VARIABLE(
"TagTrackDistanceToConstraintSignificance(i)", tagTrackDistanceToConstraintSignificance,
997 "returns the significance of the distance between the centre of the constraint and the tag track indexed by track index (computed as distance / uncertainty)");
1000 REGISTER_VARIABLE(
"TagVDistanceToConstraint", tagVDistanceToConstraint,
1001 "returns the measured distance between the tag vtx and the centre of the constraint.");
1003 REGISTER_VARIABLE(
"TagVDistanceToConstraintErr", tagVDistanceToConstraintErr,
1004 "returns the estimated error on the distance between the tag vtx and the centre of the constraint.");
1006 REGISTER_VARIABLE(
"TagVDistanceToConstraintSignificance", tagVDistanceToConstraintSignificance,
1007 "returns the significance of the distance between the tag vtx and the centre of the constraint (computed as distance / uncertainty)");
1009 REGISTER_VARIABLE(
"TagTrackDistanceToTagV(i)", tagTrackDistanceToTagV,
1010 "returns the measured distance between the ith tag track and the tag vtx.");
1012 REGISTER_VARIABLE(
"TagTrackDistanceToTagVErr(i)", tagTrackDistanceToTagVErr,
1013 "returns the estimated error on the distance between the ith tag track and the tag vtx. Warning: only the uncertainties on the track position parameters are taken into account.");
1015 REGISTER_VARIABLE(
"TagTrackDistanceToTagVSignificance(i)", tagTrackDistanceToTagVSignificance,
1016 "returns the significance of the distance between the tag vtx and the tag track indexed by trackIndex (computed as distance / uncertainty)");
1018 REGISTER_VARIABLE(
"TagTrackTrueDistanceToTagV(i)", tagTrackTrueDistanceToTagV,
1019 "return the true distance between the true B Tag decay vertex and the p'cle corresponding to the ith tag vtx track.")
1021 REGISTER_VARIABLE("TagTrackTrueVecToTagVX(i)", tagTrackTrueVecToTagVX,
1022 "return the X coordinate of the vector between the mc particle corresponding to the ith tag vtx track and the true tag B decay vertex.")
1024 REGISTER_VARIABLE("TagTrackTrueVecToTagVY(i)", tagTrackTrueVecToTagVY,
1025 "return the Y coordinate of the vector between the mc particle corresponding to the ith tag vtx track and the true tag B decay vertex.")
1027 REGISTER_VARIABLE("TagTrackTrueVecToTagVZ(i)", tagTrackTrueVecToTagVZ,
1028 "return the Z coordinate of the vector between the mc particle corresponding to the ith tag vtx track and the true tag B decay vertex.")
1030 REGISTER_VARIABLE("TagTrackTrueMomentumX(i)", tagTrackTrueMomentumX,
1031 "return the X component of the true momentum of the MC particle corresponding to the ith tag vtx track.")
1033 REGISTER_VARIABLE("TagTrackTrueMomentumY(i)", tagTrackTrueMomentumY,
1034 "return the Y component of the true momentum of the MC particle corresponding to the ith tag vtx track.")
1036 REGISTER_VARIABLE("TagTrackTrueMomentumZ(i)", tagTrackTrueMomentumZ,
1037 "return the Z component of the true momentum of the MC particle corresponding to the ith tag vtx track.")
1039 REGISTER_VARIABLE("TagTrackTrueOriginX(i)", tagTrackTrueOriginX,
1040 "return the X component of the true origin of the MC particle corresponding to the ith tag vtx track.")
1042 REGISTER_VARIABLE("TagTrackTrueOriginY(i)", tagTrackTrueOriginY,
1043 "return the Y component of the true origin of the MC particle corresponding to the ith tag vtx track.")
1045 REGISTER_VARIABLE("TagTrackTrueOriginZ(i)", tagTrackTrueOriginZ,
1046 "return the Z component of the true origin of the MC particle corresponding to the ith tag vtx track.")
1048 REGISTER_VARIABLE("TagVFitTruthStatus", fitTruthStatus,
1049 "Returns the status of the fit performed with the truth info. Possible values are: 0: fit performed with measured parameters, 1: fit performed with true parameters, 2: unable to recover truth parameters")
1051 REGISTER_VARIABLE("TagVRollBackStatus", rollbackStatus,
1052 "Returns the status of the fit performed with rolled back tracks. Possible values are: 0: fit performed with measured parameters, 1: fit performed with rolled back tracks, 2: unable to recover truth parameters")
1054 REGISTER_VARIABLE("TagTrackMax(var)", tagTrackMax,
1055 "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.")
1057 REGISTER_VARIABLE("TagTrackMin(var)", tagTrackMin,
1058 "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.")
1060 REGISTER_VARIABLE("TagTrackAverage(var)", tagTrackAverage,
1061 "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.")
1063 REGISTER_VARIABLE("TagTrackAverageSquares(var)", tagTrackAverageSquares,
1064 "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.")
1066 REGISTER_VARIABLE("TagTrackWeightedAverage(var)", tagTrackWeightedAverage,
1067 "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)``.")
1069 REGISTER_VARIABLE("TagTrackWeightedAverageSquares(var)", tagTrackWeightedAverageSquares,
1070 "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)``.")