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)
37 auto* mcparticle = part->getMCParticle();
39 return mcparticle->getDecayVertex().X();
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 B2Vector3D getMcDecayVertexFromIP(
const MCParticle* mcparticle)
65 static DBObjPtr<BeamSpot> beamSpotDB;
67 return frame.getVertex(mcparticle->getDecayVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
70 double mcDecayVertexFromIPX(
const Particle* part)
72 auto* mcparticle = part->getMCParticle();
74 return getMcDecayVertexFromIP(mcparticle).
X();
77 double mcDecayVertexFromIPY(
const Particle* part)
79 auto* mcparticle = part->getMCParticle();
81 return getMcDecayVertexFromIP(mcparticle).
Y();
84 double mcDecayVertexFromIPZ(
const Particle* part)
86 auto* mcparticle = part->getMCParticle();
88 return getMcDecayVertexFromIP(mcparticle).
Z();
91 double mcDecayVertexFromIPRho(
const Particle* part)
93 auto* mcparticle = part->getMCParticle();
95 return getMcDecayVertexFromIP(mcparticle).
Perp();
98 double mcDecayVertexFromIPDistance(
const Particle* part)
100 auto* mcparticle = part->getMCParticle();
102 return getMcDecayVertexFromIP(mcparticle).
Mag();
105 double mcProductionVertexX(
const Particle* part)
107 auto* mcparticle = part->getMCParticle();
109 return mcparticle->getProductionVertex().X();
112 double mcProductionVertexY(
const Particle* part)
114 auto* mcparticle = part->getMCParticle();
116 return mcparticle->getProductionVertex().Y();
119 double mcProductionVertexZ(
const Particle* part)
121 auto* mcparticle = part->getMCParticle();
123 return mcparticle->getProductionVertex().Z();
126 B2Vector3D getMcProductionVertexFromIP(
const MCParticle* mcparticle)
128 static DBObjPtr<BeamSpot> beamSpotDB;
130 return frame.getVertex(mcparticle->getProductionVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
133 double mcProductionVertexFromIPX(
const Particle* part)
135 auto* mcparticle = part->getMCParticle();
137 return getMcProductionVertexFromIP(mcparticle).
X();
140 double mcProductionVertexFromIPY(
const Particle* part)
142 auto* mcparticle = part->getMCParticle();
144 return getMcProductionVertexFromIP(mcparticle).
Y();
147 double mcProductionVertexFromIPZ(
const Particle* part)
149 auto* mcparticle = part->getMCParticle();
151 return getMcProductionVertexFromIP(mcparticle).
Z();
156 double particleX(
const Particle* part)
159 return frame.getVertex(part).X();
162 double particleY(
const Particle* part)
165 return frame.getVertex(part).Y();
168 double particleZ(
const Particle* part)
171 return frame.getVertex(part).Z();
174 inline double getParticleUncertaintyByIndex(
const Particle* part,
unsigned int index)
177 B2FATAL(
"The particle provide does not exist.");
179 const auto& errMatrix = part->getVertexErrorMatrix();
180 return std::sqrt(errMatrix(index, index));
183 double particleDXUncertainty(
const Particle* part)
186 return getParticleUncertaintyByIndex(part, 0);
189 double particleDYUncertainty(
const Particle* part)
192 return getParticleUncertaintyByIndex(part, 1);
195 double particleDZUncertainty(
const Particle* part)
198 return getParticleUncertaintyByIndex(part, 2);
206 static DBObjPtr<BeamSpot> beamSpotDB;
208 auto trackFit = part->getTrackFitResult();
210 return frame.getVertex(part->getVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
212 UncertainHelix helix = trackFit->getUncertainHelix();
213 helix.passiveMoveBy(ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
214 return frame.getVertex(helix.getPerigee());
218 double particleDX(
const Particle* part)
220 return getVertexD(part).
X();
223 double particleDY(
const Particle* part)
225 return getVertexD(part).
Y();
228 double particleDZ(
const Particle* part)
230 return getVertexD(part).
Z();
233 double particleDRho(
const Particle* part)
235 return getVertexD(part).
Perp();
238 double particleDPhi(
const Particle* part)
240 return getVertexD(part).
Phi();
243 double particleDCosTheta(
const Particle* part)
248 double particleDistance(
const Particle* part)
250 return getVertexD(part).
Mag();
253 double particleDistanceSignificance(
const Particle* part)
261 static DBObjPtr<BeamSpot> beamSpotDB;
263 const B2Vector3D& vertex = frame.getVertex(part->getVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
264 const TMatrixFSym& vertexErr = frame.getVertexErrorMatrix(
static_cast<TMatrixDSym
>(part->getVertexErrorMatrix()) +
265 beamSpotDB->getCovVertex());
266 const double denominator = vertex *
B2Vector3D(vertexErr * vertex);
269 return vertex.Mag2() / std::sqrt(denominator);
274 double particleProductionX(
const Particle* part)
276 if (part->hasExtraInfo(
"prodVertX"))
return part->getExtraInfo(
"prodVertX");
277 else if (part->hasExtraInfo(
"prodVertexX"))
return part->getExtraInfo(
"prodVertexX");
281 double particleProductionY(
const Particle* part)
283 if (part->hasExtraInfo(
"prodVertY"))
return part->getExtraInfo(
"prodVertY");
284 else if (part->hasExtraInfo(
"prodVertexY"))
return part->getExtraInfo(
"prodVertexY");
288 double particleProductionZ(
const Particle* part)
290 if (part->hasExtraInfo(
"prodVertZ"))
return part->getExtraInfo(
"prodVertZ");
291 else if (part->hasExtraInfo(
"prodVertexZ"))
return part->getExtraInfo(
"prodVertexZ");
296 double particleProductionCovElement(
const Particle* part,
const std::vector<double>& indices)
298 if (indices.size() != 2) {
299 B2FATAL(
"Number of arguments of prodVertexCov function is incorrect!");
302 int ielement = std::lround(indices[0]);
303 int jelement = std::lround(indices[1]);
305 if (std::min(ielement, jelement) < 0 || std::max(ielement, jelement) > 2) {
306 B2ERROR(
"Range of indexes of prodVertexCov function is incorrect!");
309 const std::vector<char> names = {
'x',
'y',
'z'};
310 const std::string prodVertS = Form(
"prodVertS%c%c", names[ielement], names[jelement]);
313 return part->getExtraInfo(prodVertS);
316 double particleProductionXErr(
const Particle* part)
319 return std::sqrt(part->getExtraInfo(
"prodVertSxx"));
322 double particleProductionYErr(
const Particle* part)
325 return std::sqrt(part->getExtraInfo(
"prodVertSyy"));
328 double particleProductionZErr(
const Particle* part)
331 return std::sqrt(part->getExtraInfo(
"prodVertSzz"));
334 VARIABLE_GROUP(
"Vertex Information");
336 REGISTER_VARIABLE(
"mcDecayVertexX", mcDecayVertexX,
337 "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",
339 REGISTER_VARIABLE(
"mcDecayVertexY", mcDecayVertexY,
340 "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",
342 REGISTER_VARIABLE(
"mcDecayVertexZ", mcDecayVertexZ,
343 "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",
345 REGISTER_VARIABLE(
"mcDecayVertexRho", mcDecayVertexRho,
346 "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",
348 REGISTER_VARIABLE(
"mcDecayVertexFromIPX", mcDecayVertexFromIPX,
349 "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",
351 REGISTER_VARIABLE(
"mcDecayVertexFromIPY", mcDecayVertexFromIPY,
352 "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",
354 REGISTER_VARIABLE(
"mcDecayVertexFromIPZ", mcDecayVertexFromIPZ,
355 "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",
357 REGISTER_VARIABLE(
"mcDecayVertexFromIPRho", mcDecayVertexFromIPRho,
358 "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",
360 REGISTER_VARIABLE(
"mcDecayVertexFromIPDistance", mcDecayVertexFromIPDistance,
361 "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",
363 REGISTER_VARIABLE(
"mcProductionVertexX", mcProductionVertexX,
364 "Returns the x position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
366 REGISTER_VARIABLE(
"mcProductionVertexY", mcProductionVertexY,
367 "Returns the y position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
369 REGISTER_VARIABLE(
"mcProductionVertexZ", mcProductionVertexZ,
370 "Returns the z position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
372 REGISTER_VARIABLE(
"mcProductionVertexFromIPX", mcProductionVertexFromIPX,
373 "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",
375 REGISTER_VARIABLE(
"mcProductionVertexFromIPY", mcProductionVertexFromIPY,
376 "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",
378 REGISTER_VARIABLE(
"mcProductionVertexFromIPZ", mcProductionVertexFromIPZ,
379 "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",
383 REGISTER_VARIABLE(
"distance", particleDistance,
384 R
"DOC(3D distance between the IP and the particle decay vertex, if available.
386In case the particle has been created from a track, the distance is defined between the POCA and IP.
387If the particle is built from an ECL cluster, the decay vertex is set to the nominal IP.
388If the particle is created from a KLM cluster, the distance is calculated between the IP and the cluster itself.
392 REGISTER_VARIABLE(
"significanceOfDistance", particleDistanceSignificance,
393 "significance of distance from vertex or POCA to interaction point(-1 in case of numerical problems)");
394 REGISTER_VARIABLE(
"dx", particleDX,
"vertex or POCA in case of tracks x with respect to IP\n\n",
"cm");
395 REGISTER_VARIABLE(
"dy", particleDY,
"vertex or POCA in case of tracks y with respect to IP\n\n",
"cm");
396 REGISTER_VARIABLE(
"dz", particleDZ,
"vertex or POCA in case of tracks z with respect to IP\n\n",
"cm");
397 REGISTER_VARIABLE(
"x", particleX,
398 "x coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
399 REGISTER_VARIABLE(
"y", particleY,
400 "y coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
401 REGISTER_VARIABLE(
"z", particleZ,
402 "z coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
403 REGISTER_VARIABLE(
"x_uncertainty", particleDXUncertainty,
"uncertainty on x (measured with respect to the origin)\n\n",
"cm");
404 REGISTER_VARIABLE(
"y_uncertainty", particleDYUncertainty,
"uncertainty on y (measured with respect to the origin)\n\n",
"cm");
405 REGISTER_VARIABLE(
"z_uncertainty", particleDZUncertainty,
"uncertainty on z (measured with respect to the origin)\n\n",
"cm");
406 REGISTER_VARIABLE(
"dr", particleDRho,
"transverse distance with respect to IP for a vertex; track abs(d0) relative to IP for a track.\n\n",
408 REGISTER_VARIABLE(
"dphi", particleDPhi,
"vertex azimuthal angle of the vertex or POCA in degrees with respect to IP\n\n",
"rad");
409 REGISTER_VARIABLE(
"dcosTheta", particleDCosTheta,
"vertex or POCA polar angle with respect to IP");
411 REGISTER_VARIABLE(
"prodVertexX", particleProductionX,
412 "Returns the x position of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
413 REGISTER_VARIABLE(
"prodVertexY", particleProductionY,
414 "Returns the y position of particle production vertex.\n\n",
"cm");
415 REGISTER_VARIABLE(
"prodVertexZ", particleProductionZ,
416 "Returns the z position of particle production vertex.\n\n",
"cm");
418 REGISTER_VARIABLE(
"prodVertexCov(i,j)", particleProductionCovElement,
419 "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",
420 ":math:`\\text{cm}^2`");
421 REGISTER_VARIABLE(
"prodVertexXErr", particleProductionXErr,
422 "Returns the x position uncertainty of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
423 REGISTER_VARIABLE(
"prodVertexYErr", particleProductionYErr,
424 "Returns the y position uncertainty of particle production vertex.\n\n",
"cm");
425 REGISTER_VARIABLE(
"prodVertexZErr", particleProductionZErr,
426 "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.