Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
processes
hadronic
models
inclxx
utils
include
G4INCLThreeVector.hh
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
// INCL++ intra-nuclear cascade model
27
// Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28
// Davide Mancusi, CEA
29
// Alain Boudard, CEA
30
// Sylvie Leray, CEA
31
// Joseph Cugnon, University of Liege
32
//
33
#define INCLXX_IN_GEANT4_MODE 1
34
35
#include "
globals.hh
"
36
37
/*
38
* ThreeVector.hh
39
*
40
* \date 4 June 2009
41
* \author Pekka Kaitaniemi
42
*/
43
44
#ifndef G4INCLThreeVector_hh
45
#define G4INCLThreeVector_hh 1
46
47
#include <string>
48
#include <sstream>
49
#include <cmath>
50
51
namespace
G4INCL {
52
53
class
ThreeVector
{
54
public
:
55
ThreeVector
()
56
:x(0.0), y(0.0), z(0.0)
57
{}
58
59
ThreeVector
(
G4double
ax,
G4double
ay,
G4double
az)
60
:x(ax), y(ay), z(az)
61
{}
62
63
inline
G4double
getX
()
const
{
return
x; }
64
inline
G4double
getY
()
const
{
return
y; }
65
inline
G4double
getZ
()
const
{
return
z; }
66
67
inline
G4double
perp
()
const
{
return
std::sqrt(x*x + y*y); }
68
inline
G4double
perp2
()
const
{
return
x*x + y*y; }
72
inline
G4double
mag
()
const
{
return
std::sqrt(x*x + y*y + z*z); }
73
77
inline
G4double
mag2
()
const
{
return
(x*x + y*y + z*z); }
78
82
inline
G4double
theta
()
const
{
83
return
x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(
perp
(),z);
84
}
85
89
inline
G4double
phi
()
const
{
90
return
x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
91
}
92
96
inline
G4double
dot
(
const
ThreeVector
&
v
)
const
{
97
return
(x*v.x + y*v.y + z*v.z);
98
}
99
103
ThreeVector
vector
(
const
ThreeVector
&
v
)
const
{
104
return
ThreeVector
(
105
y*v.z - z*v.y,
106
z*v.x - x*v.z,
107
x*v.y - y*v.x
108
);
109
}
110
112
inline
void
setX
(
G4double
ax) { x = ax; }
113
115
inline
void
setY
(
G4double
ay) { y = ay; }
116
118
inline
void
setZ
(
G4double
az) { z = az; }
119
120
inline
void
operator+=
(
const
ThreeVector
&
v
) {
121
x += v.x;
122
y += v.y;
123
z += v.z;
124
}
125
127
inline
ThreeVector
operator-
()
const
{
128
return
ThreeVector
(-x,-y,-z);
129
}
130
131
inline
void
operator-=
(
const
ThreeVector
&
v
) {
132
x -= v.x;
133
y -= v.y;
134
z -= v.z;
135
}
136
137
template
<
typename
T>
138
inline
void
operator*=
(
const
T
c
) {
139
x *=
c
;
140
y *=
c
;
141
z *=
c
;
142
}
143
144
template
<
typename
T>
145
inline
void
operator/=
(
const
T
c
) {
146
x /=
c
;
147
y /=
c
;
148
z /=
c
;
149
}
150
151
inline
ThreeVector
operator-
(
const
ThreeVector
&
v
)
const
{
152
return
ThreeVector
(x-v.x, y-v.y, z-v.z);
153
}
154
155
inline
ThreeVector
operator+
(
const
ThreeVector
&
v
)
const
{
156
return
ThreeVector
(x+v.x, y+v.y, z+v.z);
157
}
158
162
inline
ThreeVector
operator/
(
const
G4double
C)
const
{
163
return
ThreeVector
(x/C, y/C, z/C);
164
}
165
166
inline
ThreeVector
operator*
(
const
G4double
C)
const
{
167
return
ThreeVector
(x*C, y*C, z*C);
168
}
169
175
inline
void
rotate
(
const
G4double
angle,
const
ThreeVector
&axis) {
176
// Use Rodrigues' formula
177
const
G4double
cos = std::cos(angle);
178
const
G4double
sin = std::sin(angle);
179
(*this) = (*this) * cos + axis.
vector
(*
this
) * sin + axis * (axis.
dot
(*
this
)*(1.-cos));
180
}
181
182
std::string
print
()
const
{
183
std::stringstream ss;
184
ss <<
"(x = "
<< x <<
" y = "
<< y <<
" z = "
<< z <<
")"
;
185
return
ss.str();
186
}
187
188
std::string
dump
()
const
{
189
std::stringstream ss;
190
ss <<
"(vector3 "
<< x <<
" "
<< y <<
" "
<< z <<
")"
;
191
return
ss.str();
192
}
193
194
private
:
195
G4double
x, y, z;
//> Vector components
196
};
197
198
}
199
200
#endif
Generated on Sat May 25 2013 14:34:00 for Geant4 by
1.8.4