RotationTransformation.cxx
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <cmath>
5 #include <limits>
6 
8 
9 namespace gar {
10  namespace gar_pandora {
11 
12  const int RotationTransformation::kAxisX = 0;
13  const int RotationTransformation::kAxisY = 1;
14  const int RotationTransformation::kAxisZ = 2;
15 
16  //------------------------------------------------------------------------------------------------------------------------------------------
17 
19  : m_RotationSet(false),
20  m_RotationAngle(angle * CLHEP::pi /180.)
21  {
22  switch (axis)
23  {
24  case kAxisX:
25  this->SetRotationX();
26  MF_LOG_INFO("RotationTransformation")
27  << "Rotation set around the x axis with angle " << m_RotationAngle << " rad";
28  m_RotationSet = true;
29  break;
30  case kAxisY:
31  this->SetRotationY();
32  MF_LOG_INFO("RotationTransformation")
33  << "Rotation set around the y axis with angle " << m_RotationAngle << " rad";
34  m_RotationSet = true;
35  break;
36  case kAxisZ:
37  this->SetRotationZ();
38  MF_LOG_INFO("RotationTransformation")
39  << "Rotation set around the z axis with angle " << m_RotationAngle << " rad";
40  m_RotationSet = true;
41  break;
42  default:
43  throw;
44  break;
45  }
46  }
47 
48  //------------------------------------------------------------------------------------------------------------------------------------------
49 
51 
52  //------------------------------------------------------------------------------------------------------------------------------------------
53 
54  const pandora::CartesianVector RotationTransformation::MakeRotation(const pandora::CartesianVector &initialVec) const
55  {
56  if(m_RotationSet) {
57  return pandora::CartesianVector( initialVec.GetX() * fRotMatrix[0] + initialVec.GetY() * fRotMatrix[3] + initialVec.GetZ() * fRotMatrix[6], initialVec.GetX() * fRotMatrix[1] + initialVec.GetY() * fRotMatrix[4] + initialVec.GetZ() * fRotMatrix[7], initialVec.GetX() * fRotMatrix[2] + initialVec.GetY() * fRotMatrix[5] + initialVec.GetZ() * fRotMatrix[8] );
58  } else {
59  MF_LOG_INFO("RotationTransformation")
60  << "No rotation axis was defined - operation aborted!";
61  return pandora::CartesianVector(initialVec.GetX(), initialVec.GetY(), initialVec.GetZ());
62  }
63  }
64 
65  //------------------------------------------------------------------------------------------------------------------------------------------
66 
68  {
69  //col x
70  fRotMatrix[0] = 1.;
71  fRotMatrix[1] = 0.;
72  fRotMatrix[2] = 0.;
73 
74  //col y
75  fRotMatrix[3] = 0.;
76  fRotMatrix[4] = std::cos(m_RotationAngle);
77  fRotMatrix[5] = std::sin(m_RotationAngle);
78 
79  //col z
80  fRotMatrix[6] = 0.;
81  fRotMatrix[7] = -std::sin(m_RotationAngle);
82  fRotMatrix[8] = std::cos(m_RotationAngle);
83  }
84 
85  //------------------------------------------------------------------------------------------------------------------------------------------
86 
88  {
89  //col x
90  fRotMatrix[0] = std::cos(m_RotationAngle);
91  fRotMatrix[1] = 0.;
92  fRotMatrix[2] = -std::sin(m_RotationAngle);
93 
94  //col y
95  fRotMatrix[3] = 0.;
96  fRotMatrix[4] = 1.;
97  fRotMatrix[5] = 0.;
98 
99  //col z
100  fRotMatrix[6] = std::sin(m_RotationAngle);
101  fRotMatrix[7] = 0.;
102  fRotMatrix[8] = std::cos(m_RotationAngle);
103  }
104 
105  //------------------------------------------------------------------------------------------------------------------------------------------
106 
108  {
109  //col x
110  fRotMatrix[0] = std::cos(m_RotationAngle);
111  fRotMatrix[1] = std::sin(m_RotationAngle);
112  fRotMatrix[2] = 0.;
113 
114  //col y
115  fRotMatrix[3] = -std::sin(m_RotationAngle);
116  fRotMatrix[4] = std::cos(m_RotationAngle);
117  fRotMatrix[5] = 0.;
118 
119  //col z
120  fRotMatrix[6] = 0.;
121  fRotMatrix[7] = 0.;
122  fRotMatrix[8] = 1.;
123  }
124  }
125 }
#define MF_LOG_INFO(category)
const pandora::CartesianVector MakeRotation(const pandora::CartesianVector &initialVec) const
General GArSoft Utilities.
float pi
Definition: units.py:11