ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgbRotationMatrix.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4tgbRotationMatrix.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //
29 // class G4tgbRotationMatrix
30 
31 // History:
32 // - Created. P.Arce, CIEMAT (November 2007)
33 // -------------------------------------------------------------------------
34 
35 #include "G4tgbRotationMatrix.hh"
36 #include "G4RotationMatrix.hh"
37 #include "G4tgrMessenger.hh"
38 #include "G4tgrUtils.hh"
39 #include "G4UIcommand.hh"
40 
41 // -------------------------------------------------------------------------
43  : theTgrRM(0)
44 {
45 }
46 
47 
48 // -------------------------------------------------------------------------
50 {
51 }
52 
53 
54 // -------------------------------------------------------------------------
56  : theTgrRM(tgr)
57 {
58 }
59 
60 
61 // -------------------------------------------------------------------------
63 {
64  std::vector<G4double> values = theTgrRM->GetValues();
65 
66  if( values.size() == 3 ) {
67  return BuildG4RotMatrixFrom3( values );
68  } else if( values.size() == 6 ) {
69  return BuildG4RotMatrixFrom6( values );
70  } else if( values.size() == 9 ) {
71  return BuildG4RotMatrixFrom9( values );
72  }
73  else
74  {
75  G4String ErrMessage = "Number of values is: "
76  + G4UIcommand::ConvertToString(G4int(values.size()))
77  + G4String(". It should be 3, 6, or 9 !");
78  G4Exception("G4tgbRotationMatrix::BuildG4RotMatrix()",
79  "InvalidData", FatalException, ErrMessage);
80  }
81  return 0;
82 }
83 
84 
85 // -------------------------------------------------------------------------
88 {
89  G4RotationMatrix* rotMat = new G4RotationMatrix();
90 
91  rotMat->rotateX( values[0] );
92  rotMat->rotateY( values[1] );
93  rotMat->rotateZ( values[2] );
94 
95 #ifdef G4VERBOSE
97  {
98  G4cout << " Constructing new G4RotationMatrix from 3 numbers "
99  << GetName() << " : " << *rotMat << G4endl;
100  }
101 #endif
102 
103  return rotMat;
104 }
105 
106 
107 // -------------------------------------------------------------------------
110 {
111  G4double thetaX = values[0];
112  G4double phiX = values[1];
113  G4double thetaY = values[2];
114  G4double phiY = values[3];
115  G4double thetaZ = values[4];
116  G4double phiZ = values[5];
117 
118  // build the 3 axis from the values
119  G4ThreeVector colx(std::sin(thetaX)*std::cos(phiX),
120  std::sin(thetaX)*std::sin(phiX),std::cos(thetaX));
121  G4ThreeVector coly(std::sin(thetaY)*std::cos(phiY),
122  std::sin(thetaY)*std::sin(phiY),std::cos(thetaY));
123  G4ThreeVector colz(std::sin(thetaZ)*std::cos(phiZ),
124  std::sin(thetaZ)*std::sin(phiZ),std::cos(thetaZ));
125 
126  // Now create a G4RotationMatrix (HepRotation), which can be left handed.
127  // This is not foreseen in CLHEP, but can be achieved using the
128  // constructor which does not check its input arguments!
129 
130  G4Rep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation
131  colx.y(),coly.y(),colz.y(), // (inverted)
132  colx.z(),coly.z(),colz.z());
133 
134  G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp);
135 
136 #ifdef G4VERBOSE
138  {
139  G4cout << " Constructing new G4RotationMatrix from 6 numbers "
140  << GetName() << " : " << *rotMat << G4endl;
141  }
142 #endif
143 
144  return rotMat;
145 }
146 
147 // -------------------------------------------------------------------------
150 {
151  // build the 3 axis from the values
152  G4ThreeVector colx(values[0],values[1],values[2]);
153  G4ThreeVector coly(values[3],values[4],values[5]);
154  G4ThreeVector colz(values[6],values[7],values[8]);
155 
156  // Now create a G4RotationMatrix (HepRotation), which can be left handed.
157  // This is not foreseen in CLHEP, but can be achieved using the
158  // constructor which does not check its input arguments!
159 
160  G4Rep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation
161  colx.y(),coly.y(),colz.y(), // (inverted)
162  colx.z(),coly.z(),colz.z());
163 
164  G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp);
165 
166 #ifdef G4VERBOSE
168  {
169  G4cout << " Constructing new G4RotationMatrix from 9 numbers "
170  << GetName() << " : " << *rotMat << G4endl;
171  }
172 #endif
173 
174  return rotMat;
175 }