9#include <analysis/variables/VertexVariables.h>
11#include <analysis/dataobjects/Particle.h>
12#include <analysis/utility/ReferenceFrame.h>
14#include <framework/database/DBObjPtr.h>
15#include <framework/logging/Logger.h>
17#include <TMatrixFSym.h>
19#include <mdst/dbobjects/BeamSpot.h>
20#include <mdst/dataobjects/MCParticle.h>
21#include <mdst/dataobjects/TrackFitResult.h>
35 double mcDecayVertexX(
const Particle* part)
42 double mcDecayVertexY(
const Particle* part)
44 auto* mcparticle = part->getMCParticle();
46 return mcparticle->getDecayVertex().Y();
49 double mcDecayVertexZ(
const Particle* part)
51 auto* mcparticle = part->getMCParticle();
53 return mcparticle->getDecayVertex().Z();
56 double mcDecayVertexRho(
const Particle* part)
58 auto* mcparticle = part->getMCParticle();
60 return mcparticle->getDecayVertex().Rho();
63 ROOT::Math::XYZVector getMcDecayVertexFromIP(
const MCParticle* mcparticle)
65 static DBObjPtr<BeamSpot> beamSpotDB;
66 if (!beamSpotDB.isValid())
69 return frame.getVertex(mcparticle->getDecayVertex() - beamSpotDB->getIPPosition());
72 double mcDecayVertexFromIPX(
const Particle* part)
74 auto* mcparticle = part->getMCParticle();
76 return getMcDecayVertexFromIP(mcparticle).X();
79 double mcDecayVertexFromIPY(
const Particle* part)
81 auto* mcparticle = part->getMCParticle();
83 return getMcDecayVertexFromIP(mcparticle).Y();
86 double mcDecayVertexFromIPZ(
const Particle* part)
88 auto* mcparticle = part->getMCParticle();
90 return getMcDecayVertexFromIP(mcparticle).Z();
93 double mcDecayVertexFromIPRho(
const Particle* part)
95 auto* mcparticle = part->getMCParticle();
97 return getMcDecayVertexFromIP(mcparticle).Rho();
100 double mcDecayVertexFromIPDistance(
const Particle* part)
102 auto* mcparticle = part->getMCParticle();
104 return getMcDecayVertexFromIP(mcparticle).R();
107 double mcProductionVertexX(
const Particle* part)
109 auto* mcparticle = part->getMCParticle();
111 return mcparticle->getProductionVertex().X();
114 double mcProductionVertexY(
const Particle* part)
116 auto* mcparticle = part->getMCParticle();
118 return mcparticle->getProductionVertex().Y();
121 double mcProductionVertexZ(
const Particle* part)
123 auto* mcparticle = part->getMCParticle();
125 return mcparticle->getProductionVertex().Z();
128 ROOT::Math::XYZVector getMcProductionVertexFromIP(
const MCParticle* mcparticle)
130 static DBObjPtr<BeamSpot> beamSpotDB;
131 if (!beamSpotDB.isValid())
134 return frame.getVertex(mcparticle->getProductionVertex() - beamSpotDB->getIPPosition());
137 double mcProductionVertexFromIPX(
const Particle* part)
139 auto* mcparticle = part->getMCParticle();
141 return getMcProductionVertexFromIP(mcparticle).X();
144 double mcProductionVertexFromIPY(
const Particle* part)
146 auto* mcparticle = part->getMCParticle();
148 return getMcProductionVertexFromIP(mcparticle).Y();
151 double mcProductionVertexFromIPZ(
const Particle* part)
153 auto* mcparticle = part->getMCParticle();
155 return getMcProductionVertexFromIP(mcparticle).Z();
160 double particleX(
const Particle* part)
163 return frame.getVertex(part).X();
166 double particleY(
const Particle* part)
169 return frame.getVertex(part).Y();
172 double particleZ(
const Particle* part)
175 return frame.getVertex(part).Z();
178 inline double getParticleUncertaintyByIndex(
const Particle* part,
unsigned int index)
181 B2FATAL(
"The particle provide does not exist.");
183 const auto& errMatrix = part->getVertexErrorMatrix();
184 return std::sqrt(errMatrix(index, index));
187 double particleDXUncertainty(
const Particle* part)
190 return getParticleUncertaintyByIndex(part, 0);
193 double particleDYUncertainty(
const Particle* part)
196 return getParticleUncertaintyByIndex(part, 1);
199 double particleDZUncertainty(
const Particle* part)
202 return getParticleUncertaintyByIndex(part, 2);
208 ROOT::Math::XYZVector getVertexD(
const Particle* part)
210 static DBObjPtr<BeamSpot> beamSpotDB;
211 if (!beamSpotDB.isValid())
215 auto trackFit = part->getTrackFitResult();
217 return frame.getVertex(part->getVertex() - beamSpotDB->getIPPosition());
219 UncertainHelix helix = trackFit->getUncertainHelix();
220 helix.passiveMoveBy(beamSpotDB->getIPPosition());
221 return frame.getVertex(helix.getPerigee());
225 double particleDX(
const Particle* part)
227 return getVertexD(part).X();
230 double particleDY(
const Particle* part)
232 return getVertexD(part).Y();
235 double particleDZ(
const Particle* part)
237 return getVertexD(part).Z();
240 double particleDRho(
const Particle* part)
242 return getVertexD(part).Rho();
245 double particleDPhi(
const Particle* part)
247 return getVertexD(part).Phi();
250 double particleDCosTheta(
const Particle* part)
252 return std::cos(getVertexD(part).Theta());
255 double particleDistance(
const Particle* part)
257 return getVertexD(part).R();
260 double particleDistanceSignificance(
const Particle* part)
268 static DBObjPtr<BeamSpot> beamSpotDB;
269 if (!beamSpotDB.isValid())
272 const ROOT::Math::XYZVector& vertex = frame.getVertex(part->getVertex() - beamSpotDB->getIPPosition());
273 const TMatrixFSym& vertexErr = frame.getVertexErrorMatrix(
static_cast<TMatrixDSym
>(part->getVertexErrorMatrix()) +
274 beamSpotDB->getCovVertex());
275 ROOT::Math::XYZVector mv;
276 mv.SetX(vertexErr(0, 0) * vertex.X() + vertexErr(0, 1) * vertex.Y() + vertexErr(0, 2) * vertex.Z());
277 mv.SetY(vertexErr(1, 0) * vertex.X() + vertexErr(1, 1) * vertex.Y() + vertexErr(1, 2) * vertex.Z());
278 mv.SetZ(vertexErr(2, 0) * vertex.X() + vertexErr(2, 1) * vertex.Y() + vertexErr(2, 2) * vertex.Z());
279 const double denominator = vertex.Dot(mv);;
282 return vertex.Mag2() / std::sqrt(denominator);
287 double particleProductionX(
const Particle* part)
289 if (part->hasExtraInfo(
"prodVertX"))
return part->getExtraInfo(
"prodVertX");
290 else if (part->hasExtraInfo(
"prodVertexX"))
return part->getExtraInfo(
"prodVertexX");
294 double particleProductionY(
const Particle* part)
296 if (part->hasExtraInfo(
"prodVertY"))
return part->getExtraInfo(
"prodVertY");
297 else if (part->hasExtraInfo(
"prodVertexY"))
return part->getExtraInfo(
"prodVertexY");
301 double particleProductionZ(
const Particle* part)
303 if (part->hasExtraInfo(
"prodVertZ"))
return part->getExtraInfo(
"prodVertZ");
304 else if (part->hasExtraInfo(
"prodVertexZ"))
return part->getExtraInfo(
"prodVertexZ");
309 double particleProductionCovElement(
const Particle* part,
const std::vector<double>& indices)
311 if (indices.size() != 2) {
312 B2FATAL(
"Number of arguments of prodVertexCov function is incorrect!");
315 int ielement = std::lround(indices[0]);
316 int jelement = std::lround(indices[1]);
318 if (std::min(ielement, jelement) < 0 || std::max(ielement, jelement) > 2) {
319 B2ERROR(
"Range of indexes of prodVertexCov function is incorrect!");
322 const std::vector<char> names = {
'x',
'y',
'z'};
323 const std::string prodVertS = Form(
"prodVertS%c%c", names[ielement], names[jelement]);
326 return part->getExtraInfo(prodVertS);
329 double particleProductionXErr(
const Particle* part)
332 return std::sqrt(part->getExtraInfo(
"prodVertSxx"));
335 double particleProductionYErr(
const Particle* part)
338 return std::sqrt(part->getExtraInfo(
"prodVertSyy"));
341 double particleProductionZErr(
const Particle* part)
344 return std::sqrt(part->getExtraInfo(
"prodVertSzz"));
347 VARIABLE_GROUP(
"Vertex Information");
349 REGISTER_VARIABLE(
"mcDecayVertexX", mcDecayVertexX,
350 "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",
352 REGISTER_VARIABLE(
"mcDecayVertexY", mcDecayVertexY,
353 "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",
355 REGISTER_VARIABLE(
"mcDecayVertexZ", mcDecayVertexZ,
356 "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",
358 REGISTER_VARIABLE(
"mcDecayVertexRho", mcDecayVertexRho,
359 "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",
361 REGISTER_VARIABLE(
"mcDecayVertexFromIPX", mcDecayVertexFromIPX,
362 "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",
364 REGISTER_VARIABLE(
"mcDecayVertexFromIPY", mcDecayVertexFromIPY,
365 "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",
367 REGISTER_VARIABLE(
"mcDecayVertexFromIPZ", mcDecayVertexFromIPZ,
368 "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",
370 REGISTER_VARIABLE(
"mcDecayVertexFromIPRho", mcDecayVertexFromIPRho,
371 "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",
373 REGISTER_VARIABLE(
"mcDecayVertexFromIPDistance", mcDecayVertexFromIPDistance,
374 "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",
376 REGISTER_VARIABLE(
"mcProductionVertexX", mcProductionVertexX,
377 "Returns the x position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
379 REGISTER_VARIABLE(
"mcProductionVertexY", mcProductionVertexY,
380 "Returns the y position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
382 REGISTER_VARIABLE(
"mcProductionVertexZ", mcProductionVertexZ,
383 "Returns the z position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
385 REGISTER_VARIABLE(
"mcProductionVertexFromIPX", mcProductionVertexFromIPX,
386 "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",
388 REGISTER_VARIABLE(
"mcProductionVertexFromIPY", mcProductionVertexFromIPY,
389 "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",
391 REGISTER_VARIABLE(
"mcProductionVertexFromIPZ", mcProductionVertexFromIPZ,
392 "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",
396 REGISTER_VARIABLE(
"distance", particleDistance,
397 R
"DOC(3D distance between the IP and the particle decay vertex, if available.
399In case the particle has been created from a track, the distance is defined between the POCA and IP.
400If the particle is built from an ECL cluster, the decay vertex is set to the nominal IP.
401If the particle is created from a KLM cluster, the distance is calculated between the IP and the cluster itself.
405 REGISTER_VARIABLE(
"significanceOfDistance", particleDistanceSignificance,
406 "significance of distance from vertex or POCA to interaction point(-1 in case of numerical problems)");
407 REGISTER_VARIABLE(
"dx", particleDX,
"vertex or POCA in case of tracks x with respect to IP\n\n",
"cm");
408 REGISTER_VARIABLE(
"dy", particleDY,
"vertex or POCA in case of tracks y with respect to IP\n\n",
"cm");
409 REGISTER_VARIABLE(
"dz", particleDZ,
"vertex or POCA in case of tracks z with respect to IP\n\n",
"cm");
410 REGISTER_VARIABLE(
"x", particleX,
411 "x coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
412 REGISTER_VARIABLE(
"y", particleY,
413 "y coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
414 REGISTER_VARIABLE(
"z", particleZ,
415 "z coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
416 REGISTER_VARIABLE(
"x_uncertainty", particleDXUncertainty,
"uncertainty on x (measured with respect to the origin)\n\n",
"cm");
417 REGISTER_VARIABLE(
"y_uncertainty", particleDYUncertainty,
"uncertainty on y (measured with respect to the origin)\n\n",
"cm");
418 REGISTER_VARIABLE(
"z_uncertainty", particleDZUncertainty,
"uncertainty on z (measured with respect to the origin)\n\n",
"cm");
419 REGISTER_VARIABLE(
"dr", particleDRho,
"transverse distance with respect to IP for a vertex; track abs(d0) relative to IP for a track.\n\n",
421 REGISTER_VARIABLE(
"dphi", particleDPhi,
"vertex azimuthal angle of the vertex or POCA in degrees with respect to IP\n\n",
"rad");
422 REGISTER_VARIABLE(
"dcosTheta", particleDCosTheta,
"vertex or POCA polar angle with respect to IP");
424 REGISTER_VARIABLE(
"prodVertexX", particleProductionX,
425 "Returns the x position of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
426 REGISTER_VARIABLE(
"prodVertexY", particleProductionY,
427 "Returns the y position of particle production vertex.\n\n",
"cm");
428 REGISTER_VARIABLE(
"prodVertexZ", particleProductionZ,
429 "Returns the z position of particle production vertex.\n\n",
"cm");
431 REGISTER_VARIABLE(
"prodVertexCov(i,j)", particleProductionCovElement,
432 "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",
433 ":math:`\\text{cm}^2`");
434 REGISTER_VARIABLE(
"prodVertexXErr", particleProductionXErr,
435 "Returns the x position uncertainty of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
436 REGISTER_VARIABLE(
"prodVertexYErr", particleProductionYErr,
437 "Returns the y position uncertainty of particle production vertex.\n\n",
"cm");
438 REGISTER_VARIABLE(
"prodVertexZErr", particleProductionZErr,
439 "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.