Belle II Software  release-06-02-00
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 
13 using namespace Belle2;
14 
15 std::stack<const ReferenceFrame*> ReferenceFrame::m_reference_frames;
16 
17 
18 RestFrame::RestFrame(const Particle* particle) :
19  m_momentum(particle->get4Vector()),
20  m_displacement(particle->getVertex()),
21  m_boost(m_momentum.BoostVector()),
22  m_lab2restframe(TLorentzRotation(-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 
36 TVector3 RestFrame::getVertex(const TVector3& 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  TLorentzVector a = m_lab2restframe * TLorentzVector(vector - m_displacement, 0);
44  return a.Vect() - m_boost * a.T();
45 }
46 
47 TLorentzVector RestFrame::getMomentum(const TLorentzVector& vector) const
48 {
49  // 1. Boost momentum into rest frame
50  return m_lab2restframe * vector;
51 }
52 
53 TMatrixFSym RestFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
54 {
55  TMatrixD lorentzrot(4, 4);
56 
57  for (int i = 0; i < 4; ++i)
58  for (int j = 0; j < 4; ++j)
59  lorentzrot(i, j) = m_lab2restframe(i, j);
60 
61  TMatrixFSym tmp_matrix(matrix);
62 
63  return tmp_matrix.Similarity(lorentzrot);
64 }
65 
66 TMatrixFSym RestFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
67 {
68  TMatrixD lorentzrot(4, 3);
69 
70  for (int i = 0; i < 4; ++i)
71  for (int j = 0; j < 3; ++j)
72  lorentzrot(i, j) = m_lab2restframe(i, j);
73 
74  TMatrixFSym tmp_matrix(matrix);
75  auto rotated_error_matrix = tmp_matrix.Similarity(lorentzrot);
76 
77  TMatrixD timeshift(3, 4);
78  timeshift.Zero();
79  timeshift(0, 0) = 1;
80  timeshift(1, 1) = 1;
81  timeshift(2, 2) = 1;
82  timeshift(0, 3) = m_boost(0);
83  timeshift(1, 3) = m_boost(1);
84  timeshift(2, 3) = m_boost(2);
85 
86  return rotated_error_matrix.Similarity(timeshift);
87 }
88 
89 TVector3 LabFrame::getVertex(const TVector3& vector) const
90 {
91  return vector;
92 }
93 
94 TLorentzVector LabFrame::getMomentum(const TLorentzVector& vector) const
95 {
96  return vector;
97 }
98 
99 TMatrixFSym LabFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
100 {
101  return matrix;
102 }
103 
104 TMatrixFSym LabFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
105 {
106  return matrix;
107 }
108 
109 TVector3 CMSFrame::getVertex(const TVector3& vector) const
110 {
111  // Transform Vertex from lab into cms frame:
112  // TODO 0: Subtract fitted IP similar to RestFrame
113  // 1. Use Lorentz Transformation to Boost Vertex vector into cms frame
114  // 2. Subtract movement of vertex end due to the time difference between
115  // the former simultaneous measured vertex points (see derivation of Lorentz contraction)
116  TLorentzVector a = m_transform.rotateLabToCms() * TLorentzVector(vector, 0);
117  return a.Vect() - m_transform.getBoostVector() * a.T();
118 }
119 
120 TLorentzVector CMSFrame::getMomentum(const TLorentzVector& vector) const
121 {
122  // 1. Boost momentum into cms frame
123  return m_transform.rotateLabToCms() * vector;
124 }
125 
126 TMatrixFSym CMSFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
127 {
128  TMatrixD lorentzrot(4, 4);
129 
130  auto labToCmsFrame = m_transform.rotateLabToCms();
131  for (int i = 0; i < 4; ++i)
132  for (int j = 0; j < 4; ++j)
133  lorentzrot(i, j) = labToCmsFrame(i, j);
134 
135  TMatrixFSym tmp_matrix(matrix);
136  return tmp_matrix.Similarity(lorentzrot);
137 }
138 
139 TMatrixFSym CMSFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
140 {
141  TMatrixD lorentzrot(4, 3);
142 
143  auto labToCmsFrame = m_transform.rotateLabToCms();
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 
164 RotationFrame::RotationFrame(const TVector3& newX, const TVector3& newY, const TVector3& newZ)
165 {
166  m_rotation.RotateAxes(newX.Unit(), newY.Unit(), newZ.Unit());
167  m_rotation.Invert();
168 }
169 
170 TVector3 RotationFrame::getVertex(const TVector3& vector) const
171 {
172  return m_rotation * vector;
173 }
174 
175 TLorentzVector RotationFrame::getMomentum(const TLorentzVector& vector) const
176 {
177  TVector3 rotated_vector = m_rotation * vector.Vect();
178 
179  return TLorentzVector(rotated_vector, vector[3]);
180 }
181 
182 TMatrixFSym RotationFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
183 {
184  TMatrixD extendedrot(4, 4);
185  extendedrot.Zero();
186  for (int i = 0; i < 3; ++i)
187  for (int j = 0; j < 3; ++j)
188  extendedrot(i, j) = m_rotation(i, j);
189  extendedrot(3, 3) = 1;
190 
191  TMatrixFSym tmp_matrix(matrix);
192  return tmp_matrix.Similarity(extendedrot);
193 }
194 
195 TMatrixFSym RotationFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
196 {
197  TMatrixD rotmatrix(3, 3);
198  for (int i = 0; i < 3; ++i)
199  for (int j = 0; j < 3; ++j)
200  rotmatrix(i, j) = m_rotation(i, j);
201 
202  TMatrixFSym tmp_matrix(matrix);
203  return tmp_matrix.Similarity(rotmatrix);
204 }
205 
206 CMSRotationFrame::CMSRotationFrame(const TVector3& newX, const TVector3& newY, const TVector3& newZ) :
207  rotationframe(newX, newY, newZ)
208 {
209 
210 }
211 
212 TVector3 CMSRotationFrame::getVertex(const TVector3& vector) const
213 {
214  return rotationframe.getVertex(cmsframe.getVertex(vector));
215 }
216 
217 TLorentzVector CMSRotationFrame::getMomentum(const TLorentzVector& vector) const
218 {
220 }
221 
222 TMatrixFSym CMSRotationFrame::getMomentumErrorMatrix(const TMatrixFSym& matrix) const
223 {
225 }
226 
227 TMatrixFSym CMSRotationFrame::getVertexErrorMatrix(const TMatrixFSym& matrix) const
228 {
230 }
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in cms frame.
virtual TLorentzVector getMomentum(const TLorentzVector &vector) const override
Get Lorentz vector in cms frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in cms frame.
virtual TVector3 getVertex(const TVector3 &vector) const override
Get vertex 3-vector in cms frame.
PCmsLabTransform m_transform
Lab to CMS Transform.
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in rotation frame.
virtual TLorentzVector getMomentum(const TLorentzVector &vector) const override
Get Lorentz vector in rotation frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in rotation frame.
CMSRotationFrame(const TVector3 &newX, const TVector3 &newY, const TVector3 &newZ)
Create new rotation frame.
RotationFrame rotationframe
Rotationframe.
CMSFrame cmsframe
CMSFrame.
virtual TVector3 getVertex(const TVector3 &vector) const override
Get vertex 3-vector in rotation frame.
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in lab frame.
virtual TLorentzVector getMomentum(const TLorentzVector &vector) const override
Get Lorentz vector in lab frame.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in lab frame.
virtual TVector3 getVertex(const TVector3 &vector) const override
Get vertex 3-vector in lab frame.
const TLorentzRotation rotateLabToCms() const
Returns Lorentz transformation from Lab to CMS.
TVector3 getBoostVector() const
Returns boost vector (beta=p/E)
Class to store reconstructed particles.
Definition: Particle.h:74
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 TLorentzVector getMomentum(const TLorentzVector &vector) const override
Get Lorentz vector in rest frame System.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in rest frame.
TVector3 m_boost
boost of RF relative to the lab frame
TLorentzRotation m_lab2restframe
Lorentz transformation connecting lab and rest frame.
RestFrame(const Particle *particle)
Create new rest frame.
virtual TVector3 getVertex(const TVector3 &vector) const override
Get vertex 3-vector in rest frame system.
TVector3 m_displacement
displacement of RF origin in th lab frame
virtual TMatrixFSym getVertexErrorMatrix(const TMatrixFSym &matrix) const override
Get Vertex error matrix in rotation frame.
virtual TLorentzVector getMomentum(const TLorentzVector &vector) const override
Get Lorentz vector in rotation frame.
RotationFrame(const TVector3 &newX, const TVector3 &newY, const TVector3 &newZ)
Create new rotation frame.
TRotation m_rotation
Rotation.
virtual TMatrixFSym getMomentumErrorMatrix(const TMatrixFSym &matrix) const override
Get Momentum error matrix in rotation frame.
virtual TVector3 getVertex(const TVector3 &vector) const override
Get vertex 3-vector in rotation frame.
Abstract base class for different kinds of events.