9#include <analysis/modules/DistanceCalculator/DistanceCalculatorModule.h>
17const float eps = 1
E-6;
29 m_distanceCovMatrix(3)
32 setDescription(
"Calculates distance between two vertices, distance of closest approach between a vertex and a track, distance of closest approach between two tracks, distance of closest approach between a vertex/track and Btube");
38 "Specifies how the distance is calculated:\n"
39 "vertextrack: calculate the distance of closest approach between a track and a vertex, taking the first candidate as vertex, default\n"
40 "trackvertex: calculate the distance of closest approach between a track and a vertex, taking the first candidate as track,\n"
41 "2tracks: calculates the distance of closest approach between two tracks,\n"
42 "2vertices: calculates the distance between two vertices,\n"
43 "vertexbtube: calculates the distance of closest approach between a vertex and a Btube,\n"
44 "trackbtube: calculates the distance of closest approach between a track and a Btube",
45 std::string(
"vertextrack"));
47 m_distance = Eigen::Matrix<double, Eigen::Dynamic, 1>::Zero(3);
59 B2FATAL(
"Please provide a decay string for DistanceCalculatorModule");
64Eigen::Vector3d getDocaTrackVertex(
const Particle* pTrack,
const Particle* pVertex)
67 Eigen::Vector3d p_ray(pTrack->
getX(), pTrack->
getY(), pTrack->
getZ());
68 Eigen::Vector3d p(pVertex->
getX(), pVertex->
getY(), pVertex->
getZ());
69 Eigen::Vector3d v_dir = v.normalized();
70 Eigen::Vector3d r = p - p_ray;
71 return r.dot(v_dir) * v_dir - r;
74TMatrixFSym getDocaTrackVertexError(
const Particle* pTrack,
const Particle* pVertex)
79 Eigen::Vector3d v = V.normalized();
84 TMatrixFSym Jacobian(3);
87 for (
int i = 0; i < 3; i++)
88 for (
int j = 0; j < 3; j++)
89 Jacobian(i, j) = -v(i) * v(j);
90 for (
int i = 0; i < 3; i++)
93 return err_r.Similarity(Jacobian);
105 Eigen::Vector3d
v1(p1->getPx(), p1->getPy(), p1->getPz());
106 Eigen::Vector3d
v2(p2->getPx(), p2->getPy(), p2->getPz());
107 Eigen::Vector3d n =
v1.cross(v2);
108 if (n.norm() < eps) {
111 return getDocaTrackVertex(p1, p2);
113 Eigen::Vector3d n_dir = n.normalized();
114 Eigen::Vector3d p1v(p1->getX(), p1->getY(), p1->getZ());
115 Eigen::Vector3d p2v(p2->getX(), p2->getY(), p2->getZ());
116 Eigen::Vector3d r = p1v - p2v;
117 return r.dot(n_dir) * n_dir;
123 TMatrixFSym err_r = p1->getVertexErrorMatrix() + p2->getVertexErrorMatrix();
124 Eigen::Vector3d p1p(p1->getPx(), p1->getPy(), p1->getPz());
125 Eigen::Vector3d p2p(p2->getPx(), p2->getPy(), p2->getPz());
126 Eigen::Vector3d n = p1p.cross(p2p);
127 if (n.norm() < eps) {
128 return getDocaTrackVertexError(p1, p2);
130 Eigen::Vector3d n_dir = n.normalized();
135 TMatrixFSym Jacobian(3);
138 for (
int i = 0; i < 3; i++)
139 for (
int j = 0; j < 3; j++)
140 Jacobian(i, j) = n_dir(i) * n_dir(j);
141 return err_r.Similarity(Jacobian);
146 Eigen::Vector3d p1v(p1->getX(), p1->getY(), p1->getZ());
147 Eigen::Vector3d p2v(p2->getX(), p2->getY(), p2->getZ());
148 Eigen::Vector3d r = p2v - p1v;
152TMatrixFSym getDistanceVerticesErrors(
const Particle* p1,
const Particle* p2)
154 TMatrixFSym err_r = p1->getVertexErrorMatrix() + p2->getVertexErrorMatrix();
160 if (
m_mode ==
"2tracks") {
163 if (
m_mode ==
"2vertices") {
166 if (
m_mode ==
"vertextrack") {
169 if (
m_mode ==
"trackvertex") {
176 if (
m_mode ==
"2tracks") {
179 if (
m_mode ==
"2vertices") {
182 if (
m_mode ==
"vertextrack") {
185 if (
m_mode ==
"trackvertex") {
190Eigen::Vector3d getDocaBtubeVertex(
const Particle* pVertex,
const Btube* tube)
194 Eigen::Vector3d p(pVertex->
getX(), pVertex->
getY(), pVertex->
getZ());
195 Eigen::Vector3d v_dir = v.normalized();
196 Eigen::Vector3d r = p - p_ray;
197 return r.dot(v_dir) * v_dir - r;
200TMatrixFSym getDocaBtubeVertexError(
const Particle* pVertex,
const Btube* tube)
204 Eigen::Vector3d v = V.normalized();
205 TMatrixFSym Jacobian(3);
206 for (
int i = 0; i < 3; i++)
207 for (
int j = 0; j < 3; j++)
208 Jacobian(i, j) = -v(i) * v(j);
209 for (
int i = 0; i < 3; i++)
212 return err_r.Similarity(Jacobian);
215Eigen::Vector3d getDocaBtubeTrack(
const Particle* pTrack,
const Btube* tube)
219 Eigen::Vector3d n =
v1.cross(v2);
220 if (n.norm() < eps) {
223 return getDocaBtubeVertex(pTrack, tube);
225 Eigen::Vector3d n_dir = n.normalized();
226 Eigen::Vector3d pv(pTrack->
getX(), pTrack->
getY(), pTrack->
getZ());
228 Eigen::Vector3d r = pv - p2v;
229 return r.dot(n_dir) * n_dir;
232TMatrixFSym getDocaBtubeTrackError(
const Particle* pTrack,
const Btube* tube)
235 Eigen::Vector3d p1p(pTrack->
getPx(), pTrack->
getPy(), pTrack->
getPz());
237 Eigen::Vector3d n = p1p.cross(p2p);
238 if (n.norm() < eps) {
239 return getDocaBtubeVertexError(pTrack, tube);
241 Eigen::Vector3d n_dir = n.normalized();
242 TMatrixFSym Jacobian(3);
243 for (
int i = 0; i < 3; i++)
244 for (
int j = 0; j < 3; j++)
245 Jacobian(i, j) = n_dir(i) * n_dir(j);
246 return err_r.Similarity(Jacobian);
251 if (
m_mode ==
"vertexbtube") {
254 if (
m_mode ==
"trackbtube") {
261 if (
m_mode ==
"vertexbtube") {
264 if (
m_mode ==
"trackbtube") {
271 unsigned int n =
m_plist->getListSize();
272 for (
unsigned int i = 0; i < n; i++) {
275 if ((
m_mode ==
"vertexbtube") || (
m_mode ==
"trackbtube")) {
276 if (selectedParticles.size() == 1) {
277 const Btube* t = particle->getRelatedTo<
Btube>();
279 B2FATAL(
"No associated Btube found");
281 const Particle* p0 = selectedParticles[0];
286 if (selectedParticles.size() == 2) {
287 const Particle* p1 = selectedParticles[0];
288 const Particle* p2 = selectedParticles[1];
293 Eigen::Matrix3d DistanceCovMatrix_eigen;
294 DistanceCovMatrix_eigen.resize(3, 3);
295 for (
int row = 0; row < 3; row++) {
296 for (
int column = 0; column < 3; column++) {
302 if (DistanceMag != 0) {
303 Eigen::Vector3d dist_dir =
m_distance.normalized();
304 dist_err =
sqrt(((dist_dir.transpose()) * (DistanceCovMatrix_eigen * dist_dir)).norm());
306 particle->writeExtraInfo(
"CalculatedDistance", DistanceMag);
307 particle->writeExtraInfo(
"CalculatedDistanceError", dist_err);
309 particle->writeExtraInfo(
"CalculatedDistanceVector_X",
m_distance(0));
310 particle->writeExtraInfo(
"CalculatedDistanceVector_Y",
m_distance(1));
311 particle->writeExtraInfo(
"CalculatedDistanceVector_Z",
m_distance(2));
For each MCParticle with hits in the CDC, this class stores some summarising information on those hit...
TMatrixFSym getTubeCenterErrorMatrix() const
Returns Btube Center Error Matrix.
Eigen::Matrix< double, 3, 1 > getTubeDirection() const
Returns Btube direction.
Eigen::Matrix< double, 3, 1 > getTubeCenter() const
Returns Btube center.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
std::vector< const Particle * > getSelectionParticles(const Particle *particle)
Get a vector of pointers with selected daughters in the decay tree.
TMatrixFSym m_distanceCovMatrix
covariance matrix of distance
virtual void initialize() override
declare data store elements
virtual void event() override
process event
std::string m_decayString
decay string
std::string m_listName
name of particle list
void getBtubeDistanceErrors(const Particle *p, const Btube *t)
returns the error on the distance between the btube and the object (depending on m_mode)
DistanceCalculatorModule()
Constructor: Sets the description, the properties and the parameters of the module.
void getDistanceErrors(const Particle *p1, const Particle *p2)
returns the error on the distance between tracks or vertex objects (depending on the m_mode)
Eigen::Vector3d m_distance
distance between two objects (track/vertex/Btube and vertex/track)
DecayDescriptor m_decayDescriptor
decay descriptor which specifies which particles are used to calculate the distance
virtual ~DistanceCalculatorModule()
Destructor.
void getDistance(const Particle *p1, const Particle *p2)
returns the distance between tracks or vertex objects (depending on the m_mode)
void getBtubeDistance(const Particle *p, const Btube *t)
returns the distance between the btube and the object (depending on m_mode)
StoreObjPtr< ParticleList > m_plist
input particle list
std::string m_mode
option string
void setDescription(const std::string &description)
Sets the description of the module.
Class to store reconstructed particles.
double getPx() const
Returns x component of momentum.
TMatrixFSym getVertexErrorMatrix() const
Returns the 3x3 position error sub-matrix.
double getPz() const
Returns z component of momentum.
double getX() const
Returns x component of vertex position.
double getPy() const
Returns y component of momentum.
double getZ() const
Returns z component of vertex position.
double getY() const
Returns y component of vertex position.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.
const std::vector< double > v2
MATLAB generated random vector.
const std::vector< double > v1
MATLAB generated random vector.