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>
16#include <framework/utilities/Conversion.h>
18#include <TMatrixFSym.h>
20#include <mdst/dbobjects/BeamSpot.h>
21#include <mdst/dataobjects/MCParticle.h>
22#include <mdst/dataobjects/Track.h>
23#include <mdst/dataobjects/TrackFitResult.h>
37 double mcDecayVertexX(
const Particle* part)
39 auto* mcparticle = part->getMCParticle();
41 return mcparticle->getDecayVertex().X();
44 double mcDecayVertexY(
const Particle* part)
46 auto* mcparticle = part->getMCParticle();
48 return mcparticle->getDecayVertex().Y();
51 double mcDecayVertexZ(
const Particle* part)
53 auto* mcparticle = part->getMCParticle();
55 return mcparticle->getDecayVertex().Z();
58 double mcDecayVertexRho(
const Particle* part)
60 auto* mcparticle = part->getMCParticle();
62 return mcparticle->getDecayVertex().Rho();
65 B2Vector3D getMcDecayVertexFromIP(
const MCParticle* mcparticle)
67 static DBObjPtr<BeamSpot> beamSpotDB;
69 return frame.getVertex(mcparticle->getDecayVertex() - ROOT::Math::XYZVector(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).
Perp();
100 double mcDecayVertexFromIPDistance(
const Particle* part)
102 auto* mcparticle = part->getMCParticle();
104 return getMcDecayVertexFromIP(mcparticle).
Mag();
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 B2Vector3D getMcProductionVertexFromIP(
const MCParticle* mcparticle)
130 static DBObjPtr<BeamSpot> beamSpotDB;
132 return frame.getVertex(mcparticle->getProductionVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
135 double mcProductionVertexFromIPX(
const Particle* part)
137 auto* mcparticle = part->getMCParticle();
139 return getMcProductionVertexFromIP(mcparticle).
X();
142 double mcProductionVertexFromIPY(
const Particle* part)
144 auto* mcparticle = part->getMCParticle();
146 return getMcProductionVertexFromIP(mcparticle).
Y();
149 double mcProductionVertexFromIPZ(
const Particle* part)
151 auto* mcparticle = part->getMCParticle();
153 return getMcProductionVertexFromIP(mcparticle).
Z();
158 double particleX(
const Particle* part)
161 return frame.getVertex(part).X();
164 double particleY(
const Particle* part)
167 return frame.getVertex(part).Y();
170 double particleZ(
const Particle* part)
173 return frame.getVertex(part).Z();
176 inline double getParticleUncertaintyByIndex(
const Particle* part,
unsigned int index)
179 B2FATAL(
"The particle provide does not exist.");
181 const auto& errMatrix = part->getVertexErrorMatrix();
182 return std::sqrt(errMatrix(index, index));
185 double particleDXUncertainty(
const Particle* part)
188 return getParticleUncertaintyByIndex(part, 0);
191 double particleDYUncertainty(
const Particle* part)
194 return getParticleUncertaintyByIndex(part, 1);
197 double particleDZUncertainty(
const Particle* part)
200 return getParticleUncertaintyByIndex(part, 2);
208 static DBObjPtr<BeamSpot> beamSpotDB;
210 auto trackFit = part->getTrackFitResult();
212 return frame.getVertex(part->getVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
214 UncertainHelix helix = trackFit->getUncertainHelix();
215 helix.passiveMoveBy(ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
216 return frame.getVertex(helix.getPerigee());
220 double particleDX(
const Particle* part)
222 return getVertexD(part).
X();
225 double particleDY(
const Particle* part)
227 return getVertexD(part).
Y();
230 double particleDZ(
const Particle* part)
232 return getVertexD(part).
Z();
235 double particleDRho(
const Particle* part)
237 return getVertexD(part).
Perp();
240 double particleDPhi(
const Particle* part)
242 return getVertexD(part).
Phi();
245 double particleDCosTheta(
const Particle* part)
250 double particleDistance(
const Particle* part)
252 return getVertexD(part).
Mag();
255 double particleDistanceSignificance(
const Particle* part)
263 static DBObjPtr<BeamSpot> beamSpotDB;
265 const B2Vector3D& vertex = frame.getVertex(part->getVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
266 const TMatrixFSym& vertexErr = frame.getVertexErrorMatrix(
static_cast<TMatrixDSym
>(part->getVertexErrorMatrix()) +
267 beamSpotDB->getCovVertex());
268 const double denominator = vertex *
B2Vector3D(vertexErr * vertex);
271 return vertex.Mag2() / std::sqrt(denominator);
276 double particleProductionX(
const Particle* part)
279 return part->getExtraInfo(
"prodVertX");
282 double particleProductionY(
const Particle* part)
285 return part->getExtraInfo(
"prodVertY");
288 double particleProductionZ(
const Particle* part)
291 return part->getExtraInfo(
"prodVertZ");
295 double particleProductionCovElement(
const Particle* part,
const std::vector<double>& indices)
297 if (indices.size() != 2) {
298 B2FATAL(
"Number of arguments of prodVertexCov function is incorrect!");
301 int ielement = std::lround(indices[0]);
302 int jelement = std::lround(indices[1]);
304 if (std::min(ielement, jelement) < 0 || std::max(ielement, jelement) > 2) {
305 B2ERROR(
"Range of indexes of prodVertexCov function is incorrect!");
308 const std::vector<char> names = {
'x',
'y',
'z'};
309 const std::string prodVertS = Form(
"prodVertS%c%c", names[ielement], names[jelement]);
312 return part->getExtraInfo(prodVertS);
315 double particleProductionXErr(
const Particle* part)
318 return std::sqrt(part->getExtraInfo(
"prodVertSxx"));
321 double particleProductionYErr(
const Particle* part)
324 return std::sqrt(part->getExtraInfo(
"prodVertSyy"));
327 double particleProductionZErr(
const Particle* part)
330 return std::sqrt(part->getExtraInfo(
"prodVertSzz"));
333 VARIABLE_GROUP(
"Vertex Information");
335 REGISTER_VARIABLE(
"mcDecayVertexX", mcDecayVertexX,
336 "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",
338 REGISTER_VARIABLE(
"mcDecayVertexY", mcDecayVertexY,
339 "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",
341 REGISTER_VARIABLE(
"mcDecayVertexZ", mcDecayVertexZ,
342 "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",
344 REGISTER_VARIABLE(
"mcDecayVertexRho", mcDecayVertexRho,
345 "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",
347 REGISTER_VARIABLE(
"mcDecayVertexFromIPX", mcDecayVertexFromIPX,
348 "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",
350 REGISTER_VARIABLE(
"mcDecayVertexFromIPY", mcDecayVertexFromIPY,
351 "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",
353 REGISTER_VARIABLE(
"mcDecayVertexFromIPZ", mcDecayVertexFromIPZ,
354 "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",
356 REGISTER_VARIABLE(
"mcDecayVertexFromIPRho", mcDecayVertexFromIPRho,
357 "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",
359 REGISTER_VARIABLE(
"mcDecayVertexFromIPDistance", mcDecayVertexFromIPDistance,
360 "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",
362 REGISTER_VARIABLE(
"mcProductionVertexX", mcProductionVertexX,
363 "Returns the x position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
365 REGISTER_VARIABLE(
"mcProductionVertexY", mcProductionVertexY,
366 "Returns the y position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
368 REGISTER_VARIABLE(
"mcProductionVertexZ", mcProductionVertexZ,
369 "Returns the z position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
371 REGISTER_VARIABLE(
"mcProductionVertexFromIPX", mcProductionVertexFromIPX,
372 "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",
374 REGISTER_VARIABLE(
"mcProductionVertexFromIPY", mcProductionVertexFromIPY,
375 "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",
377 REGISTER_VARIABLE(
"mcProductionVertexFromIPZ", mcProductionVertexFromIPZ,
378 "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",
382 REGISTER_VARIABLE(
"distance", particleDistance,
383 R
"DOC(3D distance between the IP and the particle decay vertex, if available.
385In case the particle has been created from a track, the distance is defined between the POCA and IP.
386If the particle is built from an ECL cluster, the decay vertex is set to the nominal IP.
387If the particle is created from a KLM cluster, the distance is calculated between the IP and the cluster itself.
391 REGISTER_VARIABLE(
"significanceOfDistance", particleDistanceSignificance,
392 "significance of distance from vertex or POCA to interaction point(-1 in case of numerical problems)");
393 REGISTER_VARIABLE(
"dx", particleDX,
"vertex or POCA in case of tracks x with respect to IP\n\n",
"cm");
394 REGISTER_VARIABLE(
"dy", particleDY,
"vertex or POCA in case of tracks y with respect to IP\n\n",
"cm");
395 REGISTER_VARIABLE(
"dz", particleDZ,
"vertex or POCA in case of tracks z with respect to IP\n\n",
"cm");
396 REGISTER_VARIABLE(
"x", particleX,
397 "x coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
398 REGISTER_VARIABLE(
"y", particleY,
399 "y coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
400 REGISTER_VARIABLE(
"z", particleZ,
401 "z coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
402 REGISTER_VARIABLE(
"x_uncertainty", particleDXUncertainty,
"uncertainty on x (measured with respect to the origin)\n\n",
"cm");
403 REGISTER_VARIABLE(
"y_uncertainty", particleDYUncertainty,
"uncertainty on y (measured with respect to the origin)\n\n",
"cm");
404 REGISTER_VARIABLE(
"z_uncertainty", particleDZUncertainty,
"uncertainty on z (measured with respect to the origin)\n\n",
"cm");
405 REGISTER_VARIABLE(
"dr", particleDRho,
"transverse distance with respect to IP for a vertex; track abs(d0) relative to IP for a track.\n\n",
407 REGISTER_VARIABLE(
"dphi", particleDPhi,
"vertex azimuthal angle of the vertex or POCA in degrees with respect to IP\n\n",
"rad");
408 REGISTER_VARIABLE(
"dcosTheta", particleDCosTheta,
"vertex or POCA polar angle with respect to IP");
410 REGISTER_VARIABLE(
"prodVertexX", particleProductionX,
411 "Returns the x position of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
412 REGISTER_VARIABLE(
"prodVertexY", particleProductionY,
413 "Returns the y position of particle production vertex.\n\n",
"cm");
414 REGISTER_VARIABLE(
"prodVertexZ", particleProductionZ,
415 "Returns the z position of particle production vertex.\n\n",
"cm");
417 REGISTER_VARIABLE(
"prodVertexCov(i,j)", particleProductionCovElement,
418 "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",
419 ":math:`\\text{cm}^2`");
420 REGISTER_VARIABLE(
"prodVertexXErr", particleProductionXErr,
421 "Returns the x position uncertainty of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
422 REGISTER_VARIABLE(
"prodVertexYErr", particleProductionYErr,
423 "Returns the y position uncertainty of particle production vertex.\n\n",
"cm");
424 REGISTER_VARIABLE(
"prodVertexZErr", particleProductionZErr,
425 "Returns the z position uncertainty of particle production vertex.\n\n",
"cm");
DataType Phi() const
The azimuth angle.
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType CosTheta() const
Cosine of the polar angle.
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
DataType Mag() const
The magnitude (rho in spherical coordinate system).
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
static const double doubleNaN
quiet_NaN
static const ReferenceFrame & GetCurrent()
Get current rest frame.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Abstract base class for different kinds of events.