Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4tgbRotationMatrix.cc
Go to the documentation of this file.
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// $Id$
28//
29//
30// class G4tgbRotationMatrix
31
32// History:
33// - Created. P.Arce, CIEMAT (November 2007)
34// -------------------------------------------------------------------------
35
37#include "G4RotationMatrix.hh"
38#include "G4tgrMessenger.hh"
39#include "G4tgrUtils.hh"
40#include "G4UIcommand.hh"
41
42// -------------------------------------------------------------------------
44 : theTgrRM(0), theG4RM(0)
45{
46}
47
48
49// -------------------------------------------------------------------------
51{
52}
53
54
55// -------------------------------------------------------------------------
57 : theTgrRM(tgr), theG4RM(0)
58{
59}
60
61
62// -------------------------------------------------------------------------
64{
65 std::vector<G4double> values = theTgrRM->GetValues();
66
67 if( values.size() == 3 ) {
68 return BuildG4RotMatrixFrom3( values );
69 } else if( values.size() == 6 ) {
70 return BuildG4RotMatrixFrom6( values );
71 } else if( values.size() == 9 ) {
72 return BuildG4RotMatrixFrom9( values );
73 }
74 else
75 {
76 G4String ErrMessage = "Number of values is: "
77 + G4UIcommand::ConvertToString(G4int(values.size()))
78 + G4String(". It should be 3, 6, or 9 !");
79 G4Exception("G4tgbRotationMatrix::BuildG4RotMatrix()",
80 "InvalidData", FatalException, ErrMessage);
81 }
82 return 0;
83}
84
85
86// -------------------------------------------------------------------------
88G4tgbRotationMatrix::BuildG4RotMatrixFrom3( std::vector<G4double>& values )
89{
90 G4RotationMatrix* rotMat = new G4RotationMatrix();
91
92 rotMat->rotateX( values[0] );
93 rotMat->rotateY( values[1] );
94 rotMat->rotateZ( values[2] );
95
96#ifdef G4VERBOSE
98 {
99 G4cout << " Constructing new G4RotationMatrix from 3 numbers "
100 << GetName() << " : " << *rotMat << G4endl;
101 }
102#endif
103
104 return rotMat;
105}
106
107
108// -------------------------------------------------------------------------
110G4tgbRotationMatrix::BuildG4RotMatrixFrom6( std::vector<G4double>& values )
111{
112 G4double thetaX = values[0];
113 G4double phiX = values[1];
114 G4double thetaY = values[2];
115 G4double phiY = values[3];
116 G4double thetaZ = values[4];
117 G4double phiZ = values[5];
118
119 // build the 3 axis from the values
120 G4ThreeVector colx(std::sin(thetaX)*std::cos(phiX),
121 std::sin(thetaX)*std::sin(phiX),std::cos(thetaX));
122 G4ThreeVector coly(std::sin(thetaY)*std::cos(phiY),
123 std::sin(thetaY)*std::sin(phiY),std::cos(thetaY));
124 G4ThreeVector colz(std::sin(thetaZ)*std::cos(phiZ),
125 std::sin(thetaZ)*std::sin(phiZ),std::cos(thetaZ));
126
127 // Now create a G4RotationMatrix (HepRotation), which can be left handed.
128 // This is not foreseen in CLHEP, but can be achieved using the
129 // constructor which does not check its input arguments!
130
131 G4Rep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation
132 colx.y(),coly.y(),colz.y(), // (inverted)
133 colx.z(),coly.z(),colz.z());
134
135 G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp);
136
137#ifdef G4VERBOSE
139 {
140 G4cout << " Constructing new G4RotationMatrix from 6 numbers "
141 << GetName() << " : " << *rotMat << G4endl;
142 }
143#endif
144
145 return rotMat;
146}
147
148// -------------------------------------------------------------------------
150G4tgbRotationMatrix::BuildG4RotMatrixFrom9( std::vector<G4double>& values )
151{
152 // build the 3 axis from the values
153 G4ThreeVector colx(values[0],values[1],values[2]);
154 G4ThreeVector coly(values[3],values[4],values[5]);
155 G4ThreeVector colz(values[6],values[7],values[8]);
156
157 // Now create a G4RotationMatrix (HepRotation), which can be left handed.
158 // This is not foreseen in CLHEP, but can be achieved using the
159 // constructor which does not check its input arguments!
160
161 G4Rep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation
162 colx.y(),coly.y(),colz.y(), // (inverted)
163 colx.z(),coly.z(),colz.z());
164
165 G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp);
166
167#ifdef G4VERBOSE
169 {
170 G4cout << " Constructing new G4RotationMatrix from 9 numbers "
171 << GetName() << " : " << *rotMat << G4endl;
172 }
173#endif
174
175 return rotMat;
176}
@ FatalException
CLHEP::HepRotation G4RotationMatrix
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
double z() const
double x() const
double y() const
HepRotation & rotateX(double delta)
Definition: Rotation.cc:66
HepRotation & rotateZ(double delta)
Definition: Rotation.cc:92
HepRotation & rotateY(double delta)
Definition: Rotation.cc:79
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:349
G4RotationMatrix * BuildG4RotMatrix()
G4RotationMatrix * BuildG4RotMatrixFrom9(std::vector< G4double > &values)
G4RotationMatrix * BuildG4RotMatrixFrom6(std::vector< G4double > &values)
G4RotationMatrix * BuildG4RotMatrixFrom3(std::vector< G4double > &values)
static G4int GetVerboseLevel()
std::vector< G4double > & GetValues()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41