Belle II Software light-2406-ragdoll
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()),
22 m_lab2restframe(-m_boost)
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() - ROOT::Math::XYZVector(m_transform.getBoostVector().X(), m_transform.getBoostVector().Y(),
119 m_transform.getBoostVector().Z()) * a.T();
120}
121
122ROOT::Math::PxPyPzEVector CMSFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
123{
124 // 1. Boost momentum into cms frame
125 return m_transform.rotateLabToCms() * vector;
126}
127
128TMatrixFSym CMSFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
129{
130 TMatrixD lorentzrot(4, 4);
131
132 m_transform.rotateLabToCms().GetRotationMatrix(lorentzrot);
133
134 TMatrixFSym tmp_matrix(matrix);
135 return tmp_matrix.Similarity(lorentzrot);
136}
137
138TMatrixFSym CMSFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
139{
140 TMatrixD lorentzrot(4, 3);
141
142 TMatrixD labToCmsFrame(4, 4);
143 m_transform.rotateLabToCms().GetRotationMatrix(labToCmsFrame);
144 for (int i = 0; i < 4; ++i)
145 for (int j = 0; j < 3; ++j)
146 lorentzrot(i, j) = labToCmsFrame(i, j);
147
148 TMatrixFSym tmp_matrix(matrix);
149 auto rotated_error_matrix = tmp_matrix.Similarity(lorentzrot);
150
151 TMatrixD timeshift(3, 4);
152 timeshift.Zero();
153 auto boost_vector = m_transform.getBoostVector();
154 timeshift(0, 0) = 1;
155 timeshift(1, 1) = 1;
156 timeshift(2, 2) = 1;
157 timeshift(0, 3) = boost_vector(0);
158 timeshift(1, 3) = boost_vector(1);
159 timeshift(2, 3) = boost_vector(2);
160
161 return rotated_error_matrix.Similarity(timeshift);
162}
163
164RotationFrame::RotationFrame(const ROOT::Math::XYZVector& newX, const ROOT::Math::XYZVector& newY,
165 const ROOT::Math::XYZVector& newZ) :
166 m_rotation(newX.Unit(), newY.Unit(), newZ.Unit())
167{
168 m_rotation.Invert();
169}
170
171ROOT::Math::XYZVector RotationFrame::getVertex(const ROOT::Math::XYZVector& vector) const
172{
173 return m_rotation * vector;
174}
175
176ROOT::Math::PxPyPzEVector RotationFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
177{
178 return m_rotation * vector;
179}
180
181TMatrixFSym RotationFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
182{
183 TMatrixD extendedrot(4, 4);
184 extendedrot.Zero();
185 m_rotation.GetRotationMatrix(extendedrot);
186 extendedrot(3, 3) = 1;
187
188 TMatrixFSym tmp_matrix(matrix);
189 return tmp_matrix.Similarity(extendedrot);
190}
191
192TMatrixFSym RotationFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
193{
194 TMatrixD rotmatrix(3, 3);
195 m_rotation.GetRotationMatrix(rotmatrix);
196
197 TMatrixFSym tmp_matrix(matrix);
198 return tmp_matrix.Similarity(rotmatrix);
199}
200
201CMSRotationFrame::CMSRotationFrame(const ROOT::Math::XYZVector& newX, const ROOT::Math::XYZVector& newY,
202 const ROOT::Math::XYZVector& newZ) :
203 rotationframe(newX, newY, newZ)
204{
205
206}
207
208ROOT::Math::XYZVector CMSRotationFrame::getVertex(const ROOT::Math::XYZVector& vector) const
209{
211}
212
213ROOT::Math::PxPyPzEVector CMSRotationFrame::getMomentum(const ROOT::Math::PxPyPzEVector& vector) const
214{
216}
217
218TMatrixFSym CMSRotationFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
219{
221}
222
223TMatrixFSym CMSRotationFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
224{
226}
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:433
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.
const ROOT::Math::LorentzRotation rotateLabToCms() const
Returns Lorentz transformation from Lab to CMS.
B2Vector3D getBoostVector() const
Returns boost vector (beta=p/E)
Class to store reconstructed particles.
Definition: Particle.h:75
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::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
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24