Geant4-11
Rotation.icc
Go to the documentation of this file.
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is the definitions of the inline member functions of the
7// HepRotation class
8//
9
10namespace CLHEP {
11
12// Put commonly used accessors as early as possible to avoid inlining misses:
13
14inline double HepRotation::xx() const { return rxx; }
15inline double HepRotation::xy() const { return rxy; }
16inline double HepRotation::xz() const { return rxz; }
17inline double HepRotation::yx() const { return ryx; }
18inline double HepRotation::yy() const { return ryy; }
19inline double HepRotation::yz() const { return ryz; }
20inline double HepRotation::zx() const { return rzx; }
21inline double HepRotation::zy() const { return rzy; }
22inline double HepRotation::zz() const { return rzz; }
23
24inline HepRep3x3 HepRotation::rep3x3() const {
25 return HepRep3x3 ( rxx, rxy, rxz,
26 ryx, ryy, ryz,
27 rzx, rzy, rzz );
28}
29
30inline double HepRotation::xt() const { return 0.0; }
31inline double HepRotation::yt() const { return 0.0; }
32inline double HepRotation::zt() const { return 0.0; }
33inline double HepRotation::tx() const { return 0.0; }
34inline double HepRotation::ty() const { return 0.0; }
35inline double HepRotation::tz() const { return 0.0; }
36inline double HepRotation::tt() const { return 1.0; }
37
38inline HepRep4x4 HepRotation::rep4x4() const {
39 return HepRep4x4 ( rxx, rxy, rxz, 0.0,
40 ryx, ryy, ryz, 0.0,
41 rzx, rzy, rzz, 0.0,
42 0.0, 0.0, 0.0, 1.0 );
43}
44
45// Ctors etc:
46
47inline HepRotation::HepRotation() : rxx(1.0), rxy(0.0), rxz(0.0),
48 ryx(0.0), ryy(1.0), ryz(0.0),
49 rzx(0.0), rzy(0.0), rzz(1.0) {}
50
51inline HepRotation::HepRotation(const HepRotation & m1) :
52 rxx(m1.rxx), rxy(m1.rxy), rxz(m1.rxz),
53 ryx(m1.ryx), ryy(m1.ryy), ryz(m1.ryz),
54 rzx(m1.rzx), rzy(m1.rzy), rzz(m1.rzz) {}
55
56inline HepRotation::HepRotation
57 (double mxx, double mxy, double mxz,
58 double myx, double myy, double myz,
59 double mzx, double mzy, double mzz) :
60 rxx(mxx), rxy(mxy), rxz(mxz),
61 ryx(myx), ryy(myy), ryz(myz),
62 rzx(mzx), rzy(mzy), rzz(mzz) {}
63
64inline HepRotation::HepRotation ( const HepRep3x3 & m1 ) :
65 rxx(m1.xx_), rxy(m1.xy_), rxz(m1.xz_),
66 ryx(m1.yx_), ryy(m1.yy_), ryz(m1.yz_),
67 rzx(m1.zx_), rzy(m1.zy_), rzz(m1.zz_) {}
68
69inline HepRotation::HepRotation(const HepRotationX & rx) :
70 rxx(1.0), rxy(0.0), rxz(0.0),
71 ryx(0.0), ryy(rx.yy()), ryz(rx.yz()),
72 rzx(0.0), rzy(rx.zy()), rzz(rx.zz()) {}
73
74inline HepRotation::HepRotation(const HepRotationY & ry) :
75 rxx(ry.xx()), rxy(0.0), rxz(ry.xz()),
76 ryx(0.0), ryy(1.0), ryz(0.0),
77 rzx(ry.zx()), rzy(0.0), rzz(ry.zz()) {}
78
79inline HepRotation::HepRotation(const HepRotationZ & rz) :
80 rxx(rz.xx()), rxy(rz.xy()), rxz(0.0),
81 ryx(rz.yx()), ryy(rz.yy()), ryz(0.0),
82 rzx(0.0), rzy(0.0), rzz(1.0) {}
83
84inline HepRotation::~HepRotation() {}
85
86// More accessors:
87
88inline HepRotation::HepRotation_row::HepRotation_row
89(const HepRotation & r, int i) : rr(r), ii(i) {}
90
91inline double HepRotation::HepRotation_row::operator [] (int jj) const {
92 return rr(ii,jj);
93}
94
95inline
96const HepRotation::HepRotation_row HepRotation::operator [] (int i) const {
97 return HepRotation_row(*this, i);
98}
99
100inline Hep3Vector HepRotation::colX() const
101 { return Hep3Vector ( rxx, ryx, rzx ); }
102inline Hep3Vector HepRotation::colY() const
103 { return Hep3Vector ( rxy, ryy, rzy ); }
104inline Hep3Vector HepRotation::colZ() const
105 { return Hep3Vector ( rxz, ryz, rzz ); }
106
107inline Hep3Vector HepRotation::rowX() const
108 { return Hep3Vector ( rxx, rxy, rxz ); }
109inline Hep3Vector HepRotation::rowY() const
110 { return Hep3Vector ( ryx, ryy, ryz ); }
111inline Hep3Vector HepRotation::rowZ() const
112 { return Hep3Vector ( rzx, rzy, rzz ); }
113
114inline HepLorentzVector HepRotation::col1() const
115 { return HepLorentzVector (colX(), 0); }
116inline HepLorentzVector HepRotation::col2() const
117 { return HepLorentzVector (colY(), 0); }
118inline HepLorentzVector HepRotation::col3() const
119 { return HepLorentzVector (colZ(), 0); }
120inline HepLorentzVector HepRotation::col4() const
121 { return HepLorentzVector (0,0,0,1); }
122inline HepLorentzVector HepRotation::row1() const
123 { return HepLorentzVector (rowX(), 0); }
124inline HepLorentzVector HepRotation::row2() const
125 { return HepLorentzVector (rowY(), 0); }
126inline HepLorentzVector HepRotation::row3() const
127 { return HepLorentzVector (rowZ(), 0); }
128inline HepLorentzVector HepRotation::row4() const
129 { return HepLorentzVector (0,0,0,1); }
130
131inline double HepRotation::getPhi () const { return phi(); }
132inline double HepRotation::getTheta() const { return theta(); }
133inline double HepRotation::getPsi () const { return psi(); }
134inline double HepRotation::getDelta() const { return delta(); }
135inline Hep3Vector HepRotation::getAxis () const { return axis(); }
136
137inline HepRotation & HepRotation::operator = (const HepRotation & m1) {
138 rxx = m1.rxx;
139 rxy = m1.rxy;
140 rxz = m1.rxz;
141 ryx = m1.ryx;
142 ryy = m1.ryy;
143 ryz = m1.ryz;
144 rzx = m1.rzx;
145 rzy = m1.rzy;
146 rzz = m1.rzz;
147 return *this;
148}
149
150inline HepRotation & HepRotation::set(const HepRep3x3 & m1) {
151 rxx = m1.xx_;
152 rxy = m1.xy_;
153 rxz = m1.xz_;
154 ryx = m1.yx_;
155 ryy = m1.yy_;
156 ryz = m1.yz_;
157 rzx = m1.zx_;
158 rzy = m1.zy_;
159 rzz = m1.zz_;
160 return *this;
161}
162
163inline HepRotation & HepRotation::set(const HepRotationX & r) {
164 return (set (r.rep3x3()));
165}
166inline HepRotation & HepRotation::set(const HepRotationY & r) {
167 return (set (r.rep3x3()));
168}
169inline HepRotation & HepRotation::set(const HepRotationZ & r) {
170 return (set (r.rep3x3()));
171}
172
173inline HepRotation & HepRotation::operator= (const HepRotationX & r) {
174 return (set (r.rep3x3()));
175}
176inline HepRotation & HepRotation::operator= (const HepRotationY & r) {
177 return (set (r.rep3x3()));
178}
179inline HepRotation & HepRotation::operator= (const HepRotationZ & r) {
180 return (set (r.rep3x3()));
181}
182
183inline Hep3Vector HepRotation::operator * (const Hep3Vector & p) const {
184 return Hep3Vector(rxx*p.x() + rxy*p.y() + rxz*p.z(),
185 ryx*p.x() + ryy*p.y() + ryz*p.z(),
186 rzx*p.x() + rzy*p.y() + rzz*p.z());
187// This is identical to the code in the CLHEP 1.6 version
188}
189
190inline Hep3Vector HepRotation::operator () (const Hep3Vector & p) const {
191 double x = p.x();
192 double y = p.y();
193 double z = p.z();
194 return Hep3Vector(rxx*x + rxy*y + rxz*z,
195 ryx*x + ryy*y + ryz*z,
196 rzx*x + rzy*y + rzz*z);
197}
198
199inline HepLorentzVector
200HepRotation::operator () (const HepLorentzVector & w) const {
201 return HepLorentzVector( operator() (w.vect()), w.t() );
202}
203
204inline HepLorentzVector HepRotation::operator *
205 (const HepLorentzVector & p) const {
206 return operator()(p);
207}
208
209inline HepRotation HepRotation::operator* (const HepRotation & r) const {
210 return HepRotation(rxx*r.rxx + rxy*r.ryx + rxz*r.rzx,
211 rxx*r.rxy + rxy*r.ryy + rxz*r.rzy,
212 rxx*r.rxz + rxy*r.ryz + rxz*r.rzz,
213 ryx*r.rxx + ryy*r.ryx + ryz*r.rzx,
214 ryx*r.rxy + ryy*r.ryy + ryz*r.rzy,
215 ryx*r.rxz + ryy*r.ryz + ryz*r.rzz,
216 rzx*r.rxx + rzy*r.ryx + rzz*r.rzx,
217 rzx*r.rxy + rzy*r.ryy + rzz*r.rzy,
218 rzx*r.rxz + rzy*r.ryz + rzz*r.rzz );
219}
220
221inline HepRotation HepRotation::operator * (const HepRotationX & rx) const {
222 double yy1 = rx.yy();
223 double yz1 = rx.yz();
224 double zy1 = -yz1;
225 double zz1 = yy1;
226 return HepRotation(
227 rxx, rxy*yy1 + rxz*zy1, rxy*yz1 + rxz*zz1,
228 ryx, ryy*yy1 + ryz*zy1, ryy*yz1 + ryz*zz1,
229 rzx, rzy*yy1 + rzz*zy1, rzy*yz1 + rzz*zz1 );
230}
231
232inline HepRotation HepRotation::operator * (const HepRotationY & ry) const {
233 double xx1 = ry.xx();
234 double xz1 = ry.xz();
235 double zx1 = -xz1;
236 double zz1 = xx1;
237 return HepRotation(
238 rxx*xx1 + rxz*zx1, rxy, rxx*xz1 + rxz*zz1,
239 ryx*xx1 + ryz*zx1, ryy, ryx*xz1 + ryz*zz1,
240 rzx*xx1 + rzz*zx1, rzy, rzx*xz1 + rzz*zz1 );
241}
242
243inline HepRotation HepRotation::operator * (const HepRotationZ & rz) const {
244 double xx1 = rz.xx();
245 double xy1 = rz.xy();
246 double yx1 = -xy1;
247 double yy1 = xx1;
248 return HepRotation(
249 rxx*xx1 + rxy*yx1, rxx*xy1 + rxy*yy1, rxz,
250 ryx*xx1 + ryy*yx1, ryx*xy1 + ryy*yy1, ryz,
251 rzx*xx1 + rzy*yx1, rzx*xy1 + rzy*yy1, rzz );
252}
253
254
255inline HepRotation & HepRotation::operator *= (const HepRotation & r) {
256 return *this = (*this) * (r);
257}
258
259inline HepRotation & HepRotation::operator *= (const HepRotationX & r) {
260 return *this = (*this) * (r); }
261inline HepRotation & HepRotation::operator *= (const HepRotationY & r) {
262 return *this = (*this) * (r); }
263inline HepRotation & HepRotation::operator *= (const HepRotationZ & r) {
264 return *this = (*this) * (r); }
265
266inline HepRotation & HepRotation::transform(const HepRotation & r) {
267 return *this = r * (*this);
268}
269
270inline HepRotation & HepRotation::transform(const HepRotationX & r) {
271 return *this = r * (*this); }
272inline HepRotation & HepRotation::transform(const HepRotationY & r) {
273 return *this = r * (*this); }
274inline HepRotation & HepRotation::transform(const HepRotationZ & r) {
275 return *this = r * (*this); }
276
277inline HepRotation HepRotation::inverse() const {
278 return HepRotation( rxx, ryx, rzx,
279 rxy, ryy, rzy,
280 rxz, ryz, rzz );
281}
282
283inline HepRotation inverseOf (const HepRotation & r) {
284 return r.inverse();
285}
286
287inline HepRotation & HepRotation::invert() {
288 return *this=inverse();
289}
290
291inline HepRotation & HepRotation::rotate
292 (double ddelta, const Hep3Vector * p) {
293 return rotate(ddelta, *p);
294}
295
296inline bool HepRotation::operator== ( const HepRotation & r ) const {
297 return ( rxx==r.rxx && rxy==r.rxy && rxz==r.rxz &&
298 ryx==r.ryx && ryy==r.ryy && ryz==r.ryz &&
299 rzx==r.rzx && rzy==r.rzy && rzz==r.rzz );
300}
301inline bool HepRotation::operator!= ( const HepRotation & r ) const {
302 return ! operator==(r);
303}
304inline bool HepRotation::operator< ( const HepRotation & r ) const
305 { return compare(r)< 0; }
306inline bool HepRotation::operator<=( const HepRotation & r ) const
307 { return compare(r)<=0; }
308inline bool HepRotation::operator>=( const HepRotation & r ) const
309 { return compare(r)>=0; }
310inline bool HepRotation::operator> ( const HepRotation & r ) const
311 { return compare(r)> 0; }
312
313inline double HepRotation::getTolerance() {
314 return Hep4RotationInterface::tolerance;
315}
316inline double HepRotation::setTolerance(double tol) {
317 return Hep4RotationInterface::setTolerance(tol);
318}
319
320inline HepRotation operator * (const HepRotationX & rx, const HepRotation & r){
321 HepRep3x3 mmm = r.rep3x3();
322 double c = rx.yy();
323 double ss = rx.zy();
324 return HepRotation ( mmm.xx_, mmm.xy_, mmm.xz_,
325 c*mmm.yx_-ss*mmm.zx_, c*mmm.yy_-ss*mmm.zy_, c*mmm.yz_-ss*mmm.zz_,
326 ss*mmm.yx_+c*mmm.zx_, ss*mmm.yy_+c*mmm.zy_, ss*mmm.yz_+c*mmm.zz_ );
327}
328
329inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r){
330 HepRep3x3 mmm = r.rep3x3();
331 double c = ry.xx();
332 double ss = ry.xz();
333 return HepRotation ( c*mmm.xx_+ss*mmm.zx_, c*mmm.xy_+ss*mmm.zy_, c*mmm.xz_+ss*mmm.zz_,
334 mmm.yx_, mmm.yy_, mmm.yz_,
335 -ss*mmm.xx_+c*mmm.zx_,-ss*mmm.xy_+c*mmm.zy_,-ss*mmm.xz_+c*mmm.zz_ );
336}
337
338inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r){
339 HepRep3x3 mmm = r.rep3x3();
340 double c = rz.xx();
341 double ss = rz.yx();
342 return HepRotation ( c*mmm.xx_-ss*mmm.yx_, c*mmm.xy_-ss*mmm.yy_, c*mmm.xz_-ss*mmm.yz_,
343 ss*mmm.xx_+c*mmm.yx_, ss*mmm.xy_+c*mmm.yy_, ss*mmm.xz_+c*mmm.yz_,
344 mmm.zx_, mmm.zy_, mmm.zz_ );
345}
346
347} // namespace CLHEP