Belle II Software prerelease-10-00-00a
ReferenceFrame.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <analysis/utility/ReferenceFrame.h>
10
11#include <TMatrixD.h>
12
13using namespace Belle2;
14
15std::stack<const ReferenceFrame*> ReferenceFrame::m_reference_frames;
16
17
19 m_momentum(particle->get4Vector()),
20 m_displacement(particle->getVertex()),
21 m_boost(-m_momentum.BoostToCM()),
23{
24}
25
27{
28 if (m_reference_frames.empty()) {
29 static LabFrame _default;
30 return _default;
31 } else {
32 return *m_reference_frames.top();
33 }
34}
35
36ROOT::Math::XYZVector RestFrame::getVertex(const ROOT::Math::XYZVector& vector) const
37{
38 // Transform Vertex from lab into rest frame:
39 // 1. Subtract displacement of rest frame origin in the lab frame
40 // 2. Use Lorentz Transformation to Boost Vertex vector into rest frame
41 // 3. Subtract movement of vertex end due to the time difference between
42 // the former simultaneous measured vertex points (see derivation of Lorentz contraction)
43 ROOT::Math::XYZVector v(vector - m_displacement);
44 ROOT::Math::PxPyPzEVector a = m_lab2restframe * ROOT::Math::PxPyPzEVector(v.X(), v.Y(), v.Z(), 0);
45 return a.Vect() - m_boost * a.T();
46}
47
48ROOT::Math::PxPyPzEVector RestFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
49{
50 // 1. Boost momentum into rest frame
51 return m_lab2restframe * vector;
52}
53
54TMatrixFSym RestFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
55{
56 double lorentzrotationvalues[16];
57 m_lab2restframe.GetLorentzRotation(lorentzrotationvalues);
58 TMatrixD lorentzrot(4, 4, lorentzrotationvalues);
59
60 TMatrixFSym tmp_matrix(matrix);
61
62 return tmp_matrix.Similarity(lorentzrot);
63}
64
65TMatrixFSym RestFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
66{
67 double lorentzrotationvalues[16];
68 m_lab2restframe.GetLorentzRotation(lorentzrotationvalues);
69 TMatrixD lorentzrot(4, 3);
70
71 for (int i = 0; i < 4; ++i)
72 for (int j = 0; j < 3; ++j)
73 lorentzrot(i, j) = lorentzrotationvalues[4 * i + j];
74
75 TMatrixFSym tmp_matrix(matrix);
76 auto rotated_error_matrix = tmp_matrix.Similarity(lorentzrot);
77
78 TMatrixD timeshift(3, 4);
79 timeshift.Zero();
80 timeshift(0, 0) = 1;
81 timeshift(1, 1) = 1;
82 timeshift(2, 2) = 1;
83 timeshift(0, 3) = m_boost.X();
84 timeshift(1, 3) = m_boost.Y();
85 timeshift(2, 3) = m_boost.Z();
86
87 return rotated_error_matrix.Similarity(timeshift);
88}
89
90ROOT::Math::XYZVector LabFrame::getVertex(const ROOT::Math::XYZVector& vector) const
91{
92 return vector;
93}
94
95ROOT::Math::PxPyPzEVector LabFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
96{
97 return vector;
98}
99
100TMatrixFSym LabFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
101{
102 return matrix;
103}
104
105TMatrixFSym LabFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
106{
107 return matrix;
108}
109
110ROOT::Math::XYZVector CMSFrame::getVertex(const ROOT::Math::XYZVector& vector) const
111{
112 // Transform Vertex from lab into cms frame:
113 // TODO 0: Subtract fitted IP similar to RestFrame
114 // 1. Use Lorentz Transformation to Boost Vertex vector into cms frame
115 // 2. Subtract movement of vertex end due to the time difference between
116 // the former simultaneous measured vertex points (see derivation of Lorentz contraction)
117 ROOT::Math::PxPyPzEVector a = m_transform.rotateLabToCms() * ROOT::Math::PxPyPzEVector(vector.X(), vector.Y(), vector.Z(), 0);
118 return a.Vect() - m_transform.getBoostVector() * a.T();
119}
120
121ROOT::Math::PxPyPzEVector CMSFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
122{
123 // 1. Boost momentum into cms frame
124 return m_transform.rotateLabToCms() * vector;
125}
126
127TMatrixFSym CMSFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
128{
129 TMatrixD lorentzrot(4, 4);
130
131 m_transform.rotateLabToCms().GetRotationMatrix(lorentzrot);
132
133 TMatrixFSym tmp_matrix(matrix);
134 return tmp_matrix.Similarity(lorentzrot);
135}
136
137TMatrixFSym CMSFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
138{
139 TMatrixD lorentzrot(4, 3);
140
141 TMatrixD labToCmsFrame(4, 4);
142 m_transform.rotateLabToCms().GetRotationMatrix(labToCmsFrame);
143 for (int i = 0; i < 4; ++i)
144 for (int j = 0; j < 3; ++j)
145 lorentzrot(i, j) = labToCmsFrame(i, j);
146
147 TMatrixFSym tmp_matrix(matrix);
148 auto rotated_error_matrix = tmp_matrix.Similarity(lorentzrot);
149
150 TMatrixD timeshift(3, 4);
151 timeshift.Zero();
152 auto boost_vector = m_transform.getBoostVector();
153 timeshift(0, 0) = 1;
154 timeshift(1, 1) = 1;
155 timeshift(2, 2) = 1;
156 timeshift(0, 3) = boost_vector.X();
157 timeshift(1, 3) = boost_vector.Y();
158 timeshift(2, 3) = boost_vector.Z();
159
160 return rotated_error_matrix.Similarity(timeshift);
161}
162
163RotationFrame::RotationFrame(const ROOT::Math::XYZVector& newX, const ROOT::Math::XYZVector& newY,
164 const ROOT::Math::XYZVector& newZ) :
165 m_rotation(newX.Unit(), newY.Unit(), newZ.Unit())
166{
167 m_rotation.Invert();
168}
169
170ROOT::Math::XYZVector RotationFrame::getVertex(const ROOT::Math::XYZVector& vector) const
171{
172 return m_rotation * vector;
173}
174
175ROOT::Math::PxPyPzEVector RotationFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
176{
177 return m_rotation * vector;
178}
179
180TMatrixFSym RotationFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
181{
182 TMatrixD extendedrot(4, 4);
183 extendedrot.Zero();
184 m_rotation.GetRotationMatrix(extendedrot);
185 extendedrot(3, 3) = 1;
186
187 TMatrixFSym tmp_matrix(matrix);
188 return tmp_matrix.Similarity(extendedrot);
189}
190
191TMatrixFSym RotationFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
192{
193 TMatrixD rotmatrix(3, 3);
194 m_rotation.GetRotationMatrix(rotmatrix);
195
196 TMatrixFSym tmp_matrix(matrix);
197 return tmp_matrix.Similarity(rotmatrix);
198}
199
200CMSRotationFrame::CMSRotationFrame(const ROOT::Math::XYZVector& newX, const ROOT::Math::XYZVector& newY,
201 const ROOT::Math::XYZVector& newZ) :
202 rotationframe(newX, newY, newZ)
203{
204
205}
206
207ROOT::Math::XYZVector CMSRotationFrame::getVertex(const ROOT::Math::XYZVector& vector) const
208{
209 return rotationframe.getVertex(cmsframe.getVertex(vector));
210}
211
212ROOT::Math::PxPyPzEVector CMSRotationFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
213{
214 return rotationframe.getMomentum(cmsframe.getMomentum(vector));
215}
216
217TMatrixFSym CMSRotationFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
218{
219 return rotationframe.getMomentumErrorMatrix(cmsframe.getMomentumErrorMatrix(matrix));
220}
221
222TMatrixFSym CMSRotationFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
223{
224 return rotationframe.getVertexErrorMatrix(cmsframe.getVertexErrorMatrix(matrix));
225}
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in cms frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in cms frame.
virtual ROOT::Math::XYZVector getVertex(const ROOT::Math::XYZVector &vector) const override
Get vertex 3-vector in cms frame.
PCmsLabTransform m_transform
Lab to CMS Transform.
virtual ROOT::Math::PxPyPzEVector getMomentum(const ROOT::Math::PxPyPzEVector &vector) const override
Get Lorentz vector in cms frame.
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in rotation frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in rotation frame.
virtual ROOT::Math::XYZVector getVertex(const ROOT::Math::XYZVector &vector) const override
Get vertex 3-vector in rotation frame.
CMSRotationFrame(const ROOT::Math::XYZVector &newX, const ROOT::Math::XYZVector &newY, const ROOT::Math::XYZVector &newZ)
Create new rotation frame.
RotationFrame rotationframe
Rotationframe.
CMSFrame cmsframe
CMSFrame.
virtual ROOT::Math::PxPyPzEVector getMomentum(const ROOT::Math::PxPyPzEVector &vector) const override
Get Lorentz vector in rotation frame.
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in lab frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in lab frame.
virtual ROOT::Math::XYZVector getVertex(const ROOT::Math::XYZVector &vector) const override
Get vertex 3-vector in lab frame.
virtual ROOT::Math::PxPyPzEVector getMomentum(const ROOT::Math::PxPyPzEVector &vector) const override
Get Lorentz vector in lab frame.
Class to store reconstructed particles.
Definition Particle.h:76
Abstract base class of all reference frames.
static std::stack< const ReferenceFrame * > m_reference_frames
Stack of current rest frames.
static const ReferenceFrame & GetCurrent()
Get current rest frame.
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in rest frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in rest frame.
ROOT::Math::PxPyPzEVector m_momentum
momentum of RF in the lab frame
ROOT::Math::XYZVector m_displacement
displacement of RF origin in th lab frame
virtual ROOT::Math::XYZVector getVertex(const ROOT::Math::XYZVector &vector) const override
Get vertex 3-vector in rest frame system.
RestFrame(const Particle *particle)
Create new rest frame.
ROOT::Math::XYZVector m_boost
boost of RF relative to the lab frame
virtual ROOT::Math::PxPyPzEVector getMomentum(const ROOT::Math::PxPyPzEVector &vector) const override
Get Lorentz vector in rest frame System.
ROOT::Math::Boost m_lab2restframe
Lorentz transformation connecting lab and rest frame.
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in rotation frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in rotation frame.
virtual ROOT::Math::XYZVector getVertex(const ROOT::Math::XYZVector &vector) const override
Get vertex 3-vector in rotation frame.
RotationFrame(const ROOT::Math::XYZVector &newX, const ROOT::Math::XYZVector &newY, const ROOT::Math::XYZVector &newZ)
Create new rotation frame.
ROOT::Math::Rotation3D m_rotation
Rotation.
virtual ROOT::Math::PxPyPzEVector getMomentum(const ROOT::Math::PxPyPzEVector &vector) const override
Get Lorentz vector in rotation frame.
The Unit class.
Definition Unit.h:40
STL class.
Abstract base class for different kinds of events.