Belle II Software  release-06-01-15
RotationTools.h
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 #pragma once
10 
11 /* External headers. */
12 #include <TMatrixDSym.h>
13 #include <TMatrixD.h>
14 #include <TVectorD.h>
15 #include <TRotation.h>
16 
17 namespace Belle2 {
23  namespace RotationTools {
24 
29  inline TMatrixD toMatrix(TRotation r)
30  {
31  TMatrixD rM(3, 3);
32  for (int i = 0; i < 3; ++i)
33  for (int j = 0; j < 3; ++j)
34  rM(i, j) = r(i, j);
35  return rM;
36  }
37 
38 
45  inline TMatrixD getRotationMatrixYZ(double angleY, double angleZ)
46  {
47  TRotation r;
48  r.RotateY(angleY);
49  r.RotateZ(angleZ);
50  return toMatrix(r);
51  }
52 
53 
60  inline TMatrixD getRotationMatrixXY(double angleX, double angleY)
61  {
62  TRotation r;
63  r.RotateX(angleX);
64  r.RotateY(angleY);
65  return toMatrix(r);
66  }
67 
68 
69 
76  inline TMatrixD rotateTensor(const TVector3& vTo, const TMatrixD& orgMat)
77  {
78  TMatrixD r = getRotationMatrixYZ(vTo.Theta(), vTo.Phi());
79  TMatrixD rT = r; rT.T();
80  return r * orgMat * rT;
81  }
82 
89  inline TMatrixD rotateTensorInv(const TVector3& vTo, const TMatrixD& orgMat)
90  {
91  TMatrixD r = getRotationMatrixYZ(vTo.Theta(), vTo.Phi());
92  TMatrixD rT = r; rT.T();
93  return rT * orgMat * r;
94  }
95 
96 
103  inline TMatrixDSym toSymMatrix(const TMatrixD& m)
104  {
105  TMatrixDSym mS(m.GetNrows());
106  for (int i = 0; i < m.GetNrows(); ++i)
107  for (int j = 0; j < m.GetNcols(); ++j) {
108  mS(i, j) = (m(i, j) + m(j, i)) / 2;
109  }
110  return mS;
111  }
112 
113 
118  inline TVectorD toVec(TVector3 v)
119  {
120  return TVectorD(0, 2, v.X(), v.Y(), v.Z(), "END");
121  }
122 
127  TVector3 getUnitOrthogonal(TVector3 v)
128  {
129  return TVector3(v.Z(), 0, -v.X()).Unit();
130  }
131 
132  }
133 
135 }
Abstract base class for different kinds of events.