9#include <analysis/variables/VertexVariables.h>
11#include <analysis/dataobjects/Particle.h>
12#include <analysis/utility/ReferenceFrame.h>
13#include <analysis/VariableManager/Manager.h>
15#include <framework/database/DBObjPtr.h>
16#include <framework/logging/Logger.h>
18#include <TMatrixFSym.h>
20#include <mdst/dbobjects/BeamSpot.h>
21#include <mdst/dataobjects/MCParticle.h>
22#include <mdst/dataobjects/TrackFitResult.h>
36 double mcDecayVertexX(
const Particle* part)
43 double mcDecayVertexY(
const Particle* part)
45 auto* mcparticle = part->getMCParticle();
47 return mcparticle->getDecayVertex().Y();
50 double mcDecayVertexZ(
const Particle* part)
52 auto* mcparticle = part->getMCParticle();
54 return mcparticle->getDecayVertex().Z();
57 double mcDecayVertexRho(
const Particle* part)
59 auto* mcparticle = part->getMCParticle();
61 return mcparticle->getDecayVertex().Rho();
64 ROOT::Math::XYZVector getMcDecayVertexFromIP(
const MCParticle* mcparticle)
66 static DBObjPtr<BeamSpot> beamSpotDB;
67 if (!beamSpotDB.isValid())
70 return frame.getVertex(mcparticle->getDecayVertex() - beamSpotDB->getIPPosition());
73 double mcDecayVertexFromIPX(
const Particle* part)
75 auto* mcparticle = part->getMCParticle();
77 return getMcDecayVertexFromIP(mcparticle).X();
80 double mcDecayVertexFromIPY(
const Particle* part)
82 auto* mcparticle = part->getMCParticle();
84 return getMcDecayVertexFromIP(mcparticle).Y();
87 double mcDecayVertexFromIPZ(
const Particle* part)
89 auto* mcparticle = part->getMCParticle();
91 return getMcDecayVertexFromIP(mcparticle).Z();
94 double mcDecayVertexFromIPRho(
const Particle* part)
96 auto* mcparticle = part->getMCParticle();
98 return getMcDecayVertexFromIP(mcparticle).Rho();
101 double mcDecayVertexFromIPDistance(
const Particle* part)
103 auto* mcparticle = part->getMCParticle();
105 return getMcDecayVertexFromIP(mcparticle).R();
108 double mcProductionVertexX(
const Particle* part)
110 auto* mcparticle = part->getMCParticle();
112 return mcparticle->getProductionVertex().X();
115 double mcProductionVertexY(
const Particle* part)
117 auto* mcparticle = part->getMCParticle();
119 return mcparticle->getProductionVertex().Y();
122 double mcProductionVertexZ(
const Particle* part)
124 auto* mcparticle = part->getMCParticle();
126 return mcparticle->getProductionVertex().Z();
129 ROOT::Math::XYZVector getMcProductionVertexFromIP(
const MCParticle* mcparticle)
131 static DBObjPtr<BeamSpot> beamSpotDB;
132 if (!beamSpotDB.isValid())
135 return frame.getVertex(mcparticle->getProductionVertex() - beamSpotDB->getIPPosition());
138 double mcProductionVertexFromIPX(
const Particle* part)
140 auto* mcparticle = part->getMCParticle();
142 return getMcProductionVertexFromIP(mcparticle).X();
145 double mcProductionVertexFromIPY(
const Particle* part)
147 auto* mcparticle = part->getMCParticle();
149 return getMcProductionVertexFromIP(mcparticle).Y();
152 double mcProductionVertexFromIPZ(
const Particle* part)
154 auto* mcparticle = part->getMCParticle();
156 return getMcProductionVertexFromIP(mcparticle).Z();
161 double particleX(
const Particle* part)
164 return frame.getVertex(part).X();
167 double particleY(
const Particle* part)
170 return frame.getVertex(part).Y();
173 double particleZ(
const Particle* part)
176 return frame.getVertex(part).Z();
179 inline double getParticleUncertaintyByIndex(
const Particle* part,
unsigned int index)
182 B2FATAL(
"The particle provide does not exist.");
184 const auto& errMatrix = part->getVertexErrorMatrix();
185 return std::sqrt(errMatrix(index, index));
188 double particleDXUncertainty(
const Particle* part)
191 return getParticleUncertaintyByIndex(part, 0);
194 double particleDYUncertainty(
const Particle* part)
197 return getParticleUncertaintyByIndex(part, 1);
200 double particleDZUncertainty(
const Particle* part)
203 return getParticleUncertaintyByIndex(part, 2);
209 ROOT::Math::XYZVector getVertexD(
const Particle* part)
211 static DBObjPtr<BeamSpot> beamSpotDB;
212 if (!beamSpotDB.isValid())
216 auto trackFit = part->getTrackFitResult();
218 return frame.getVertex(part->getVertex() - beamSpotDB->getIPPosition());
220 UncertainHelix helix = trackFit->getUncertainHelix();
221 helix.passiveMoveBy(beamSpotDB->getIPPosition());
222 return frame.getVertex(helix.getPerigee());
226 double particleDX(
const Particle* part)
228 return getVertexD(part).X();
231 double particleDY(
const Particle* part)
233 return getVertexD(part).Y();
236 double particleDZ(
const Particle* part)
238 return getVertexD(part).Z();
241 double particleDRho(
const Particle* part)
243 return getVertexD(part).Rho();
246 double particleDPhi(
const Particle* part)
248 return getVertexD(part).Phi();
251 double particleDCosTheta(
const Particle* part)
253 return std::cos(getVertexD(part).Theta());
256 double particleDistance(
const Particle* part)
258 return getVertexD(part).R();
261 double particleDistanceSignificance(
const Particle* part)
269 static DBObjPtr<BeamSpot> beamSpotDB;
270 if (!beamSpotDB.isValid())
273 const ROOT::Math::XYZVector& vertex = frame.getVertex(part->getVertex() - beamSpotDB->getIPPosition());
274 const TMatrixFSym& vertexErr = frame.getVertexErrorMatrix(
static_cast<TMatrixDSym
>(part->getVertexErrorMatrix()) +
275 beamSpotDB->getCovVertex());
276 ROOT::Math::XYZVector mv;
277 mv.SetX(vertexErr(0, 0) * vertex.X() + vertexErr(0, 1) * vertex.Y() + vertexErr(0, 2) * vertex.Z());
278 mv.SetY(vertexErr(1, 0) * vertex.X() + vertexErr(1, 1) * vertex.Y() + vertexErr(1, 2) * vertex.Z());
279 mv.SetZ(vertexErr(2, 0) * vertex.X() + vertexErr(2, 1) * vertex.Y() + vertexErr(2, 2) * vertex.Z());
280 const double denominator = vertex.Dot(mv);;
283 return vertex.Mag2() / std::sqrt(denominator);
288 double particleProductionX(
const Particle* part)
290 if (part->hasExtraInfo(
"prodVertX"))
return part->getExtraInfo(
"prodVertX");
291 else if (part->hasExtraInfo(
"prodVertexX"))
return part->getExtraInfo(
"prodVertexX");
295 double particleProductionY(
const Particle* part)
297 if (part->hasExtraInfo(
"prodVertY"))
return part->getExtraInfo(
"prodVertY");
298 else if (part->hasExtraInfo(
"prodVertexY"))
return part->getExtraInfo(
"prodVertexY");
302 double particleProductionZ(
const Particle* part)
304 if (part->hasExtraInfo(
"prodVertZ"))
return part->getExtraInfo(
"prodVertZ");
305 else if (part->hasExtraInfo(
"prodVertexZ"))
return part->getExtraInfo(
"prodVertexZ");
310 double particleProductionCovElement(
const Particle* part,
const std::vector<double>& indices)
312 if (indices.size() != 2) {
313 B2FATAL(
"Number of arguments of prodVertexCov function is incorrect!");
316 int ielement = std::lround(indices[0]);
317 int jelement = std::lround(indices[1]);
319 if (std::min(ielement, jelement) < 0 || std::max(ielement, jelement) > 2) {
320 B2ERROR(
"Range of indexes of prodVertexCov function is incorrect!");
323 const std::vector<char> names = {
'x',
'y',
'z'};
324 const std::string prodVertS = Form(
"prodVertS%c%c", names[ielement], names[jelement]);
327 return part->getExtraInfo(prodVertS);
330 double particleProductionXErr(
const Particle* part)
333 return std::sqrt(part->getExtraInfo(
"prodVertSxx"));
336 double particleProductionYErr(
const Particle* part)
339 return std::sqrt(part->getExtraInfo(
"prodVertSyy"));
342 double particleProductionZErr(
const Particle* part)
345 return std::sqrt(part->getExtraInfo(
"prodVertSzz"));
348 VARIABLE_GROUP(
"Vertex Information");
350 REGISTER_VARIABLE(
"mcDecayVertexX", mcDecayVertexX,
351 "Returns the x position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
353 REGISTER_VARIABLE(
"mcDecayVertexY", mcDecayVertexY,
354 "Returns the y position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
356 REGISTER_VARIABLE(
"mcDecayVertexZ", mcDecayVertexZ,
357 "Returns the z position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
359 REGISTER_VARIABLE(
"mcDecayVertexRho", mcDecayVertexRho,
360 "Returns the transverse position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
362 REGISTER_VARIABLE(
"mcDecayVertexFromIPX", mcDecayVertexFromIPX,
363 "Returns the x position of the decay vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
365 REGISTER_VARIABLE(
"mcDecayVertexFromIPY", mcDecayVertexFromIPY,
366 "Returns the y position of the decay vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
368 REGISTER_VARIABLE(
"mcDecayVertexFromIPZ", mcDecayVertexFromIPZ,
369 "Returns the z position of the decay vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
371 REGISTER_VARIABLE(
"mcDecayVertexFromIPRho", mcDecayVertexFromIPRho,
372 "Returns the transverse position of the decay vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
374 REGISTER_VARIABLE(
"mcDecayVertexFromIPDistance", mcDecayVertexFromIPDistance,
375 "Returns the distance of the decay vertex of the matched generated particle from the IP. Returns nan if the particle has no matched generated particle.\n\n",
377 REGISTER_VARIABLE(
"mcProductionVertexX", mcProductionVertexX,
378 "Returns the x position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
380 REGISTER_VARIABLE(
"mcProductionVertexY", mcProductionVertexY,
381 "Returns the y position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
383 REGISTER_VARIABLE(
"mcProductionVertexZ", mcProductionVertexZ,
384 "Returns the z position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
386 REGISTER_VARIABLE(
"mcProductionVertexFromIPX", mcProductionVertexFromIPX,
387 "Returns the x position of the production vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
389 REGISTER_VARIABLE(
"mcProductionVertexFromIPY", mcProductionVertexFromIPY,
390 "Returns the y position of the production vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
392 REGISTER_VARIABLE(
"mcProductionVertexFromIPZ", mcProductionVertexFromIPZ,
393 "Returns the z position of the production vertex of the matched generated particle wrt the IP. Returns nan if the particle has no matched generated particle.\n\n",
397 REGISTER_VARIABLE(
"distance", particleDistance,
398 R
"DOC(3D distance between the IP and the particle decay vertex, if available.
400In case the particle has been created from a track, the distance is defined between the POCA and IP.
401If the particle is built from an ECL cluster, the decay vertex is set to the nominal IP.
402If the particle is created from a KLM cluster, the distance is calculated between the IP and the cluster itself.
406 REGISTER_VARIABLE(
"significanceOfDistance", particleDistanceSignificance,
407 "significance of distance from vertex or POCA to interaction point(-1 in case of numerical problems)");
408 REGISTER_VARIABLE(
"dx", particleDX,
"vertex or POCA in case of tracks x with respect to IP\n\n",
"cm");
409 REGISTER_VARIABLE(
"dy", particleDY,
"vertex or POCA in case of tracks y with respect to IP\n\n",
"cm");
410 REGISTER_VARIABLE(
"dz", particleDZ,
"vertex or POCA in case of tracks z with respect to IP\n\n",
"cm");
411 REGISTER_VARIABLE(
"x", particleX,
412 "x coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
413 REGISTER_VARIABLE(
"y", particleY,
414 "y coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
415 REGISTER_VARIABLE(
"z", particleZ,
416 "z coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
417 REGISTER_VARIABLE(
"x_uncertainty", particleDXUncertainty,
"uncertainty on x (measured with respect to the origin)\n\n",
"cm");
418 REGISTER_VARIABLE(
"y_uncertainty", particleDYUncertainty,
"uncertainty on y (measured with respect to the origin)\n\n",
"cm");
419 REGISTER_VARIABLE(
"z_uncertainty", particleDZUncertainty,
"uncertainty on z (measured with respect to the origin)\n\n",
"cm");
420 REGISTER_VARIABLE(
"dr", particleDRho,
"transverse distance with respect to IP for a vertex; track abs(d0) relative to IP for a track.\n\n",
422 REGISTER_VARIABLE(
"dphi", particleDPhi,
"vertex azimuthal angle of the vertex or POCA in degrees with respect to IP\n\n",
"rad");
423 REGISTER_VARIABLE(
"dcosTheta", particleDCosTheta,
"vertex or POCA polar angle with respect to IP");
425 REGISTER_VARIABLE(
"prodVertexX", particleProductionX,
426 "Returns the x position of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
427 REGISTER_VARIABLE(
"prodVertexY", particleProductionY,
428 "Returns the y position of particle production vertex.\n\n",
"cm");
429 REGISTER_VARIABLE(
"prodVertexZ", particleProductionZ,
430 "Returns the z position of particle production vertex.\n\n",
"cm");
432 REGISTER_VARIABLE(
"prodVertexCov(i,j)", particleProductionCovElement,
433 "Returns the ij covariance matrix component of particle production vertex, arguments i,j should be 0, 1 or 2. Returns NaN if particle has no production covariance matrix.\n\n",
434 ":math:`\\text{cm}^2`");
435 REGISTER_VARIABLE(
"prodVertexXErr", particleProductionXErr,
436 "Returns the x position uncertainty of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
437 REGISTER_VARIABLE(
"prodVertexYErr", particleProductionYErr,
438 "Returns the y position uncertainty of particle production vertex.\n\n",
"cm");
439 REGISTER_VARIABLE(
"prodVertexZErr", particleProductionZErr,
440 "Returns the z position uncertainty of particle production vertex.\n\n",
"cm");
static const double doubleNaN
quiet_NaN
ROOT::Math::XYZVector getDecayVertex() const
Return decay vertex.
Class to store reconstructed particles.
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.
Abstract base class for different kinds of events.