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>
36 double mcDecayVertexX(
const Particle* part)
38 auto* mcparticle = part->getMCParticle();
40 return mcparticle->getDecayVertex().X();
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 B2Vector3D getMcDecayVertexFromIP(
const MCParticle* mcparticle)
66 static DBObjPtr<BeamSpot> beamSpotDB;
68 return frame.getVertex(mcparticle->getDecayVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
71 double mcDecayVertexFromIPX(
const Particle* part)
73 auto* mcparticle = part->getMCParticle();
75 return getMcDecayVertexFromIP(mcparticle).
X();
78 double mcDecayVertexFromIPY(
const Particle* part)
80 auto* mcparticle = part->getMCParticle();
82 return getMcDecayVertexFromIP(mcparticle).
Y();
85 double mcDecayVertexFromIPZ(
const Particle* part)
87 auto* mcparticle = part->getMCParticle();
89 return getMcDecayVertexFromIP(mcparticle).
Z();
92 double mcDecayVertexFromIPRho(
const Particle* part)
94 auto* mcparticle = part->getMCParticle();
96 return getMcDecayVertexFromIP(mcparticle).
Perp();
99 double mcDecayVertexFromIPDistance(
const Particle* part)
101 auto* mcparticle = part->getMCParticle();
103 return getMcDecayVertexFromIP(mcparticle).
Mag();
106 double mcProductionVertexX(
const Particle* part)
108 auto* mcparticle = part->getMCParticle();
110 return mcparticle->getProductionVertex().X();
113 double mcProductionVertexY(
const Particle* part)
115 auto* mcparticle = part->getMCParticle();
117 return mcparticle->getProductionVertex().Y();
120 double mcProductionVertexZ(
const Particle* part)
122 auto* mcparticle = part->getMCParticle();
124 return mcparticle->getProductionVertex().Z();
127 B2Vector3D getMcProductionVertexFromIP(
const MCParticle* mcparticle)
129 static DBObjPtr<BeamSpot> beamSpotDB;
131 return frame.getVertex(mcparticle->getProductionVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
134 double mcProductionVertexFromIPX(
const Particle* part)
136 auto* mcparticle = part->getMCParticle();
138 return getMcProductionVertexFromIP(mcparticle).
X();
141 double mcProductionVertexFromIPY(
const Particle* part)
143 auto* mcparticle = part->getMCParticle();
145 return getMcProductionVertexFromIP(mcparticle).
Y();
148 double mcProductionVertexFromIPZ(
const Particle* part)
150 auto* mcparticle = part->getMCParticle();
152 return getMcProductionVertexFromIP(mcparticle).
Z();
157 double particleX(
const Particle* part)
160 return frame.getVertex(part).X();
163 double particleY(
const Particle* part)
166 return frame.getVertex(part).Y();
169 double particleZ(
const Particle* part)
172 return frame.getVertex(part).Z();
175 inline double getParticleUncertaintyByIndex(
const Particle* part,
unsigned int index)
178 B2FATAL(
"The particle provide does not exist.");
180 const auto& errMatrix = part->getVertexErrorMatrix();
181 return std::sqrt(errMatrix(index, index));
184 double particleDXUncertainty(
const Particle* part)
187 return getParticleUncertaintyByIndex(part, 0);
190 double particleDYUncertainty(
const Particle* part)
193 return getParticleUncertaintyByIndex(part, 1);
196 double particleDZUncertainty(
const Particle* part)
199 return getParticleUncertaintyByIndex(part, 2);
207 static DBObjPtr<BeamSpot> beamSpotDB;
209 auto trackFit = part->getTrackFitResult();
211 return frame.getVertex(part->getVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
213 UncertainHelix helix = trackFit->getUncertainHelix();
214 helix.passiveMoveBy(ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
215 return frame.getVertex(helix.getPerigee());
219 double particleDX(
const Particle* part)
221 return getVertexD(part).
X();
224 double particleDY(
const Particle* part)
226 return getVertexD(part).
Y();
229 double particleDZ(
const Particle* part)
231 return getVertexD(part).
Z();
234 double particleDRho(
const Particle* part)
236 return getVertexD(part).
Perp();
239 double particleDPhi(
const Particle* part)
241 return getVertexD(part).
Phi();
244 double particleDCosTheta(
const Particle* part)
249 double particleDistance(
const Particle* part)
251 return getVertexD(part).
Mag();
254 double particleDistanceSignificance(
const Particle* part)
262 static DBObjPtr<BeamSpot> beamSpotDB;
264 const B2Vector3D& vertex = frame.getVertex(part->getVertex() - ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
265 const TMatrixFSym& vertexErr = frame.getVertexErrorMatrix(
static_cast<TMatrixDSym
>(part->getVertexErrorMatrix()) +
266 beamSpotDB->getCovVertex());
267 const double denominator = vertex *
B2Vector3D(vertexErr * vertex);
270 return vertex.Mag2() /
std::sqrt(denominator);
275 double particleProductionX(
const Particle* part)
278 return part->getExtraInfo(
"prodVertX");
281 double particleProductionY(
const Particle* part)
284 return part->getExtraInfo(
"prodVertY");
287 double particleProductionZ(
const Particle* part)
290 return part->getExtraInfo(
"prodVertZ");
294 double particleProductionCovElement(
const Particle* part,
const std::vector<double>& indices)
296 if (indices.size() != 2) {
297 B2FATAL(
"Number of arguments of prodVertexCov function is incorrect!");
300 int ielement = std::lround(indices[0]);
301 int jelement = std::lround(indices[1]);
303 if (std::min(ielement, jelement) < 0 || std::max(ielement, jelement) > 2) {
304 B2ERROR(
"Range of indexes of prodVertexCov function is incorrect!");
307 const std::vector<char> names = {
'x',
'y',
'z'};
308 const std::string prodVertS = Form(
"prodVertS%c%c", names[ielement], names[jelement]);
311 return part->getExtraInfo(prodVertS);
314 double particleProductionXErr(
const Particle* part)
317 return std::sqrt(part->getExtraInfo(
"prodVertSxx"));
320 double particleProductionYErr(
const Particle* part)
323 return std::sqrt(part->getExtraInfo(
"prodVertSyy"));
326 double particleProductionZErr(
const Particle* part)
329 return std::sqrt(part->getExtraInfo(
"prodVertSzz"));
332 VARIABLE_GROUP(
"Vertex Information");
334 REGISTER_VARIABLE(
"mcDecayVertexX", mcDecayVertexX,
335 "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",
337 REGISTER_VARIABLE(
"mcDecayVertexY", mcDecayVertexY,
338 "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",
340 REGISTER_VARIABLE(
"mcDecayVertexZ", mcDecayVertexZ,
341 "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",
343 REGISTER_VARIABLE(
"mcDecayVertexRho", mcDecayVertexRho,
344 "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",
346 REGISTER_VARIABLE(
"mcDecayVertexFromIPX", mcDecayVertexFromIPX,
347 "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",
349 REGISTER_VARIABLE(
"mcDecayVertexFromIPY", mcDecayVertexFromIPY,
350 "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",
352 REGISTER_VARIABLE(
"mcDecayVertexFromIPZ", mcDecayVertexFromIPZ,
353 "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",
355 REGISTER_VARIABLE(
"mcDecayVertexFromIPRho", mcDecayVertexFromIPRho,
356 "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",
358 REGISTER_VARIABLE(
"mcDecayVertexFromIPDistance", mcDecayVertexFromIPDistance,
359 "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",
361 REGISTER_VARIABLE(
"mcProductionVertexX", mcProductionVertexX,
362 "Returns the x position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
364 REGISTER_VARIABLE(
"mcProductionVertexY", mcProductionVertexY,
365 "Returns the y position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
367 REGISTER_VARIABLE(
"mcProductionVertexZ", mcProductionVertexZ,
368 "Returns the z position of production vertex of matched generated particle. Returns nan if the particle has no matched generated particle.\n\n",
370 REGISTER_VARIABLE(
"mcProductionVertexFromIPX", mcProductionVertexFromIPX,
371 "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",
373 REGISTER_VARIABLE(
"mcProductionVertexFromIPY", mcProductionVertexFromIPY,
374 "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",
376 REGISTER_VARIABLE(
"mcProductionVertexFromIPZ", mcProductionVertexFromIPZ,
377 "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",
381 REGISTER_VARIABLE(
"distance", particleDistance,
382 R
"DOC(3D distance between the IP and the particle decay vertex, if available.
384 In case the particle has been created from a track, the distance is defined between the POCA and IP.
385 If the particle is built from an ECL cluster, the decay vertex is set to the nominal IP.
386 If the particle is created from a KLM cluster, the distance is calculated between the IP and the cluster itself.
390 REGISTER_VARIABLE(
"significanceOfDistance", particleDistanceSignificance,
391 "significance of distance from vertex or POCA to interaction point(-1 in case of numerical problems)");
392 REGISTER_VARIABLE(
"dx", particleDX,
"vertex or POCA in case of tracks x with respect to IP\n\n",
"cm");
393 REGISTER_VARIABLE(
"dy", particleDY,
"vertex or POCA in case of tracks y with respect to IP\n\n",
"cm");
394 REGISTER_VARIABLE(
"dz", particleDZ,
"vertex or POCA in case of tracks z with respect to IP\n\n",
"cm");
395 REGISTER_VARIABLE(
"x", particleX,
396 "x coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track\n\n",
"cm");
397 REGISTER_VARIABLE(
"y", particleY,
398 "y 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(
"z", particleZ,
400 "z 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(
"x_uncertainty", particleDXUncertainty,
"uncertainty on x (measured with respect to the origin)\n\n",
"cm");
402 REGISTER_VARIABLE(
"y_uncertainty", particleDYUncertainty,
"uncertainty on y (measured with respect to the origin)\n\n",
"cm");
403 REGISTER_VARIABLE(
"z_uncertainty", particleDZUncertainty,
"uncertainty on z (measured with respect to the origin)\n\n",
"cm");
404 REGISTER_VARIABLE(
"dr", particleDRho,
"transverse distance with respect to IP for a vertex; track abs(d0) relative to IP for a track.\n\n",
406 REGISTER_VARIABLE(
"dphi", particleDPhi,
"vertex azimuthal angle of the vertex or POCA in degrees with respect to IP\n\n",
"rad");
407 REGISTER_VARIABLE(
"dcosTheta", particleDCosTheta,
"vertex or POCA polar angle with respect to IP");
409 REGISTER_VARIABLE(
"prodVertexX", particleProductionX,
410 "Returns the x position of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
411 REGISTER_VARIABLE(
"prodVertexY", particleProductionY,
412 "Returns the y position of particle production vertex.\n\n",
"cm");
413 REGISTER_VARIABLE(
"prodVertexZ", particleProductionZ,
414 "Returns the z position of particle production vertex.\n\n",
"cm");
416 REGISTER_VARIABLE(
"prodVertexCov(i,j)", particleProductionCovElement,
417 "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",
418 ":math:`\\text{cm}^2`");
419 REGISTER_VARIABLE(
"prodVertexXErr", particleProductionXErr,
420 "Returns the x position uncertainty of particle production vertex. Returns NaN if particle has no production vertex.\n\n",
"cm");
421 REGISTER_VARIABLE(
"prodVertexYErr", particleProductionYErr,
422 "Returns the y position uncertainty of particle production vertex.\n\n",
"cm");
423 REGISTER_VARIABLE(
"prodVertexZErr", particleProductionZErr,
424 "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
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.