]>
Commit | Line | Data |
---|---|---|
67427ff7 | 1 | /*************************************************************************** |
2 | * | |
3 | * $Id$ | |
4 | * | |
5 | * Author: Brian Lasiuk, Thomas Ullrich, April 1998 | |
6 | *************************************************************************** | |
7 | * | |
8 | * Description: | |
9 | * | |
10 | * Remarks: Since not all compilers support member templates | |
11 | * we have to specialize the templated member on these | |
12 | * platforms. If member templates are not supported the | |
13 | * ST_NO_MEMBER_TEMPLATES flag has to be set. tu. | |
14 | * | |
15 | *************************************************************************** | |
16 | * | |
17 | * $Log$ | |
18 | * Revision 1.1.1.1 2007/03/07 10:14:49 mchojnacki | |
19 | * First version on CVS | |
20 | * | |
21 | * Revision 1.15 2005/09/22 20:09:20 fisyak | |
22 | * Make AliFmLorentzVector persistent | |
23 | * | |
24 | * Revision 1.14 2005/07/19 22:27:11 perev | |
25 | * Cleanup | |
26 | * | |
27 | * Revision 1.13 2005/07/06 18:49:57 fisyak | |
28 | * Replace AliFmHelixD, AliFmLorentzVectorD,AliFmLorentzVectorF,AliFmMatrixD,AliFmMatrixF,AliFmPhysicalHelixD,AliFmThreeVectorD,AliFmThreeVectorF by templated version | |
29 | * | |
30 | * Revision 1.12 2005/03/28 06:03:41 perev | |
31 | * Defence FPE added | |
32 | * | |
33 | * Revision 1.11 2004/12/02 20:07:32 fine | |
34 | * define the valid method for both flavor of AliFmThreeVector | |
35 | * | |
36 | * Revision 1.10 2003/10/30 20:06:46 perev | |
37 | * Check of quality added | |
38 | * | |
39 | * Revision 1.9 2003/09/02 17:59:35 perev | |
40 | * gcc 3.2 updates + WarnOff | |
41 | * | |
42 | * Revision 1.8 2002/06/21 17:47:37 genevb | |
43 | * Added pseudoProduct | |
44 | * | |
45 | * Revision 1.7 2000/01/04 19:56:05 ullrich | |
46 | * Added cpp macro for CINT. | |
47 | * | |
48 | * Revision 1.6 1999/12/21 15:14:31 ullrich | |
49 | * Modified to cope with new compiler version on Sun (CC5.0). | |
50 | * | |
51 | * Revision 1.5 1999/10/15 15:46:54 ullrich | |
52 | * Changed output format in operator<< | |
53 | * | |
54 | * Revision 1.4 1999/06/04 18:00:05 ullrich | |
55 | * Added new constructor which takes C-style array as argument. | |
56 | * New operators operator() and operator[] which can be used | |
57 | * as lvalues. | |
58 | * | |
59 | * Revision 1.3 1999/02/17 11:42:19 ullrich | |
60 | * Removed specialization for 'long double'. | |
61 | * | |
62 | * Revision 1.2 1999/02/14 23:11:48 fisyak | |
63 | * Fixes for Rootcint | |
64 | * | |
65 | * Revision 1.1 1999/01/30 03:59:05 fisyak | |
66 | * Root Version of AliFmarClassLibrary | |
67 | * | |
68 | * Revision 1.1 1999/01/23 00:28:04 ullrich | |
69 | * Initial Revision | |
70 | * | |
71 | **************************************************************************/ | |
72 | #ifndef ST_THREE_VECTOR_HH | |
73 | #define ST_THREE_VECTOR_HH | |
74 | #ifdef __ROOT__ | |
75 | #include "Rtypes.h" | |
76 | #endif | |
77 | #ifndef __CINT__ | |
78 | #include <iostream> | |
79 | #include <fstream> | |
80 | #include <math.h> | |
81 | #ifdef GNU_GCC | |
82 | # include <stddef.h> | |
83 | #endif | |
84 | #if defined (__SUNPRO_CC) && __SUNPRO_CC < 0x500 | |
85 | # include <stdcomp.h> | |
86 | #endif | |
87 | #ifndef ST_NO_EXCEPTIONS | |
88 | # include <stdexcept> | |
89 | # if !defined(ST_NO_NAMESPACES) | |
90 | using std::out_of_range; | |
91 | # endif | |
92 | #endif | |
93 | #endif // __CINT__ | |
94 | ||
95 | #ifdef WIN32 | |
96 | #include "gcc2vs.h" | |
97 | #endif | |
98 | ||
99 | class TRootIOCtor;//nic nie rozumiem | |
100 | using namespace std; | |
101 | ||
102 | ||
103 | template<class T> class AliFmThreeVector { | |
104 | public: | |
105 | AliFmThreeVector(T = 0, T = 0, T = 0); | |
106 | // ROOT_VERSION(5,03,01) | |
107 | #if ROOT_VERSION_CODE >= 328449 | |
108 | AliFmThreeVector(TRootIOCtor*) : mX1(0), mX2(0), mX3(0) {} | |
109 | #endif | |
110 | virtual ~AliFmThreeVector(); | |
111 | ||
112 | #ifndef ST_NO_MEMBER_TEMPLATES | |
113 | template<class X> AliFmThreeVector(const AliFmThreeVector<X>&); | |
114 | template<class X> AliFmThreeVector(const X*); | |
115 | template<class X> AliFmThreeVector<T>& operator=(const AliFmThreeVector<X>&); | |
116 | // AliFmThreeVector(const AliFmThreeVector<T>&); use default | |
117 | // AliFmThreeVector<T>& operator=(const AliFmThreeVector<T>&); use default | |
118 | #else | |
119 | AliFmThreeVector(const AliFmThreeVector<float>&); | |
120 | AliFmThreeVector(const AliFmThreeVector<double>&); | |
121 | ||
122 | AliFmThreeVector(const float*); | |
123 | AliFmThreeVector(const double*); | |
124 | ||
125 | AliFmThreeVector<T>& operator=(const AliFmThreeVector<float>&); | |
126 | AliFmThreeVector<T>& operator=(const AliFmThreeVector<double>&); | |
127 | #endif | |
128 | ||
129 | void setX(T); | |
130 | void setY(T); | |
131 | void setZ(T); | |
132 | ||
133 | void setPhi(T); | |
134 | void setTheta(T); | |
135 | void setMag(T); | |
136 | void setMagnitude(T); | |
137 | ||
138 | T x() const; | |
139 | T y() const; | |
140 | T z() const; | |
141 | T theta() const; | |
142 | T cosTheta() const; | |
143 | T phi() const; | |
144 | T perp() const; | |
145 | T perp2() const; | |
146 | T magnitude() const; | |
147 | T mag() const; | |
148 | T mag2() const; | |
149 | T pseudoRapidity() const; | |
150 | T operator() (size_t) const; | |
151 | T operator[] (size_t) const; | |
152 | ||
153 | T& operator() (size_t); | |
154 | T& operator[] (size_t); | |
155 | ||
156 | T massHypothesis(T mass) const; | |
157 | ||
158 | AliFmThreeVector<T> unit() const; | |
159 | AliFmThreeVector<T> orthogonal() const; | |
160 | ||
161 | void rotateX(T); | |
162 | void rotateY(T); | |
163 | void rotateZ(T); | |
164 | ||
165 | AliFmThreeVector<T> operator- (); | |
166 | AliFmThreeVector<T> operator+ (); | |
167 | AliFmThreeVector<T>& operator*= (double); | |
168 | AliFmThreeVector<T>& operator/= (double); | |
169 | AliFmThreeVector<T> pseudoProduct(double,double,double) const; | |
170 | ||
171 | #ifndef ST_NO_MEMBER_TEMPLATES | |
172 | template<class X> T angle(const AliFmThreeVector<X>&) const; | |
173 | template<class X> AliFmThreeVector<T> cross(const AliFmThreeVector<X>&) const; | |
174 | template<class X> T dot (const AliFmThreeVector<X>&) const; | |
175 | template<class X> AliFmThreeVector<T> pseudoProduct(const AliFmThreeVector<X>&) const; | |
176 | ||
177 | template<class X> bool operator == (const AliFmThreeVector<X>& v) const; | |
178 | template<class X> bool operator != (const AliFmThreeVector<X>& v) const; | |
179 | ||
180 | template<class X> AliFmThreeVector<T>& operator+= (const AliFmThreeVector<X>&); | |
181 | template<class X> AliFmThreeVector<T>& operator-= (const AliFmThreeVector<X>&); | |
182 | #else | |
183 | T angle(const AliFmThreeVector<float>&) const; | |
184 | AliFmThreeVector<T> cross(const AliFmThreeVector<float>&) const; | |
185 | T dot (const AliFmThreeVector<float>&) const; | |
186 | AliFmThreeVector<T> pseudoProduct(const AliFmThreeVector<float>&) const; | |
187 | ||
188 | T angle(const AliFmThreeVector<double>&) const; | |
189 | T dot (const AliFmThreeVector<double>&) const; | |
190 | AliFmThreeVector<T> cross(const AliFmThreeVector<double>&) const; | |
191 | AliFmThreeVector<T> pseudoProduct(const AliFmThreeVector<double>&) const; | |
192 | ||
193 | bool operator == (const AliFmThreeVector<float>& v) const; | |
194 | bool operator != (const AliFmThreeVector<float>& v) const; | |
195 | AliFmThreeVector<T>& operator+= (const AliFmThreeVector<float>&); | |
196 | AliFmThreeVector<T>& operator-= (const AliFmThreeVector<float>&); | |
197 | ||
198 | bool operator == (const AliFmThreeVector<double>& v) const; | |
199 | bool operator != (const AliFmThreeVector<double>& v) const; | |
200 | AliFmThreeVector<T>& operator+= (const AliFmThreeVector<double>&); | |
201 | AliFmThreeVector<T>& operator-= (const AliFmThreeVector<double>&); | |
202 | #endif | |
203 | int valid(double world = 1.e+5) const; | |
204 | int bad(double world = 1.e+5) const; | |
205 | protected: | |
206 | T mX1, mX2, mX3; | |
207 | #ifdef __ROOT__ | |
208 | ClassDef(AliFmThreeVector,3) | |
209 | #endif /* __ROOT__ */ | |
210 | }; | |
211 | ||
212 | #ifndef __CINT__ | |
213 | // | |
214 | // Implementation of member functions | |
215 | // | |
216 | template<class T> | |
217 | inline AliFmThreeVector<T>::AliFmThreeVector(T x, T y, T z) | |
218 | : mX1(x), mX2(y), mX3(z) {/* nop */} | |
219 | template<class T> | |
220 | inline AliFmThreeVector<T>::~AliFmThreeVector() {/* nop */} | |
221 | ||
222 | template<class T> | |
223 | inline void AliFmThreeVector<T>::setX(T x) {mX1 = x;} | |
224 | ||
225 | template<class T> | |
226 | inline void AliFmThreeVector<T>::setY(T y) {mX2 = y;} | |
227 | ||
228 | template<class T> | |
229 | inline void AliFmThreeVector<T>::setZ(T z) {mX3 = z;} | |
230 | ||
231 | template<class T> | |
232 | void AliFmThreeVector<T>::setPhi(T angle) | |
233 | { | |
234 | double r = magnitude(); | |
235 | double th = theta(); | |
236 | ||
237 | mX1 = r*sin(th)*cos(angle); | |
238 | mX2 = r*sin(th)*sin(angle); | |
239 | } | |
240 | ||
241 | template <class T> | |
242 | void AliFmThreeVector<T>::setTheta(T angle) | |
243 | { | |
244 | double r = magnitude(); | |
245 | double ph = phi(); | |
246 | ||
247 | mX1 = r*sin(angle)*cos(ph); | |
248 | mX2 = r*sin(angle)*sin(ph); | |
249 | mX3 = r*cos(angle); | |
250 | } | |
251 | ||
252 | template <class T> | |
253 | void AliFmThreeVector<T>::setMagnitude(T r) | |
254 | { | |
255 | double th = theta(); | |
256 | double ph = phi(); | |
257 | ||
258 | mX1 = r*sin(th)*cos(ph); | |
259 | mX2 = r*sin(th)*sin(ph); | |
260 | mX3 = r*cos(th); | |
261 | } | |
262 | ||
263 | template <class T> | |
264 | void AliFmThreeVector<T>::setMag(T mag) | |
265 | { | |
266 | setMagnitude(mag); | |
267 | } | |
268 | ||
269 | template<class T> | |
270 | inline T AliFmThreeVector<T>::x() const {return mX1;} | |
271 | ||
272 | template<class T> | |
273 | inline T AliFmThreeVector<T>::y() const {return mX2;} | |
274 | ||
275 | template<class T> | |
276 | inline T AliFmThreeVector<T>::z() const {return mX3;} | |
277 | ||
278 | template<class T> | |
279 | inline T AliFmThreeVector<T>::theta() const | |
280 | { | |
281 | return acos(cosTheta()); | |
282 | } | |
283 | ||
284 | template<class T> | |
285 | inline T AliFmThreeVector<T>::cosTheta() const | |
286 | { | |
287 | return mX3/(mag()+1e-20); | |
288 | } | |
289 | ||
290 | template<class T> | |
291 | inline T AliFmThreeVector<T>::phi() const | |
292 | { | |
293 | return atan2(mX2,mX1); | |
294 | } | |
295 | ||
296 | template<class T> | |
297 | inline T AliFmThreeVector<T>::pseudoRapidity() const | |
298 | { | |
299 | // | |
300 | // change code to more optimal: | |
301 | // double m = mag(); | |
302 | // return 0.5*::log( (m+z())/(m-z()) ); | |
303 | double tmp = tan(theta()/2.); if (tmp <=0.) return 1e20; | |
304 | return -::log(tmp); | |
305 | } | |
306 | ||
307 | template<class T> | |
308 | inline AliFmThreeVector<T> AliFmThreeVector<T>::unit() const | |
309 | { | |
310 | double tmp = mag(); if (tmp<=0.) tmp = 1e-20; | |
311 | return *this/tmp; | |
312 | } | |
313 | ||
314 | template <class T> | |
315 | T AliFmThreeVector<T>::massHypothesis(T mass) const | |
316 | { | |
317 | return ::sqrt((*this)*(*this) + mass*mass); | |
318 | } | |
319 | ||
320 | template <class T> | |
321 | AliFmThreeVector<T> AliFmThreeVector<T>::orthogonal() const | |
322 | { | |
323 | // Direct copy from CLHEP--it is probably better to | |
324 | // use your own dot/cross product code... | |
325 | double x = (mX1 < 0.0) ? -mX1 : mX1; | |
326 | double y = (mX2 < 0.0) ? -mX2 : mX2; | |
327 | double z = (mX3 < 0.0) ? -mX3 : mX3; | |
328 | ||
329 | if(x<y) | |
330 | return x < z ? AliFmThreeVector<T>(0,mX3,-mX2) : AliFmThreeVector<T>(mX2,-mX1,0); | |
331 | else | |
332 | return mX2 < mX3 ? AliFmThreeVector<T>(-mX3,0,mX1) : AliFmThreeVector<T>(mX2,-mX1,0); | |
333 | } | |
334 | ||
335 | template <class T> | |
336 | void AliFmThreeVector<T>::rotateX(T angle) | |
337 | { | |
338 | // may in the future make use of the AliFmRotation class! | |
339 | double yPrime = cos(angle)*mX2 - sin(angle)*mX3; | |
340 | double zPrime = sin(angle)*mX2 + cos(angle)*mX3; | |
341 | ||
342 | mX2 = yPrime; | |
343 | mX3 = zPrime; | |
344 | } | |
345 | ||
346 | template <class T> | |
347 | void AliFmThreeVector<T>::rotateY(T angle) | |
348 | { | |
349 | // may in the future make use of the AliFmRotation class! | |
350 | double zPrime = cos(angle)*mX3 - sin(angle)*mX1; | |
351 | double xPrime = sin(angle)*mX3 + cos(angle)*mX1; | |
352 | ||
353 | mX1 = xPrime; | |
354 | mX3 = zPrime; | |
355 | } | |
356 | ||
357 | template <class T> | |
358 | void AliFmThreeVector<T>::rotateZ(T angle) | |
359 | { | |
360 | // may in the future make use of the AliFmRotation class! | |
361 | double xPrime = cos(angle)*mX1 - sin(angle)*mX2; | |
362 | double yPrime = sin(angle)*mX1 + cos(angle)*mX2; | |
363 | ||
364 | mX1 = xPrime; | |
365 | mX2 = yPrime; | |
366 | } | |
367 | ||
368 | template<class T> | |
369 | inline T AliFmThreeVector<T>::perp() const | |
370 | { | |
371 | return ::sqrt(mX1*mX1+mX2*mX2); | |
372 | } | |
373 | ||
374 | template<class T> | |
375 | inline T AliFmThreeVector<T>::perp2() const | |
376 | { | |
377 | return mX1*mX1+mX2*mX2; | |
378 | } | |
379 | ||
380 | template<class T> | |
381 | inline T AliFmThreeVector<T>::magnitude() const | |
382 | { | |
383 | return mag(); | |
384 | } | |
385 | ||
386 | template<class T> | |
387 | inline T AliFmThreeVector<T>::mag() const | |
388 | { | |
389 | return ::sqrt(mX1*mX1+mX2*mX2+mX3*mX3); | |
390 | } | |
391 | ||
392 | template<class T> | |
393 | inline T AliFmThreeVector<T>::mag2() const | |
394 | { | |
395 | return mX1*mX1+mX2*mX2+mX3*mX3; | |
396 | } | |
397 | ||
398 | template<class T> | |
399 | inline T AliFmThreeVector<T>::operator() (size_t i) const | |
400 | { | |
401 | if (0 <=i && i <= 2) return (&mX1)[i]; | |
402 | #ifndef ST_NO_EXCEPTIONS | |
403 | throw out_of_range("AliFmThreeVector<T>::operator(): bad index"); | |
404 | #else | |
405 | cerr << "AliFmThreeVector<T>::operator(): bad index" << endl; | |
406 | #endif | |
407 | return 0; | |
408 | } | |
409 | ||
410 | template<class T> | |
411 | inline T& AliFmThreeVector<T>::operator() (size_t i) | |
412 | { | |
413 | if (0 <=i && i <= 2) return (&mX1)[i]; | |
414 | #ifndef ST_NO_EXCEPTIONS | |
415 | throw out_of_range("AliFmThreeVector<T>::operator(): bad index"); | |
416 | #else | |
417 | cerr << "AliFmThreeVector<T>::operator(): bad index" << endl; | |
418 | #endif | |
419 | return mX1; | |
420 | } | |
421 | ||
422 | template<class T> | |
423 | inline T AliFmThreeVector<T>::operator[] (size_t i) const | |
424 | { | |
425 | if (0 <=i && i <= 2) return (&mX1)[i]; | |
426 | #ifndef ST_NO_EXCEPTIONS | |
427 | throw out_of_range("AliFmThreeVector<T>::operator[]: bad index"); | |
428 | #else | |
429 | cerr << "AliFmThreeVector<T>::operator[]: bad index" << endl; | |
430 | #endif | |
431 | return 0; | |
432 | } | |
433 | ||
434 | template<class T> | |
435 | inline T &AliFmThreeVector<T>::operator[] (size_t i) | |
436 | { | |
437 | if (0 <=i && i <= 2) return (&mX1)[i]; | |
438 | #ifndef ST_NO_EXCEPTIONS | |
439 | throw out_of_range("AliFmThreeVector<T>::operator[]: bad index"); | |
440 | #else | |
441 | cerr << "AliFmThreeVector<T>::operator[]: bad index" << endl; | |
442 | #endif | |
443 | return mX1; | |
444 | } | |
445 | ||
446 | template<class T> | |
447 | inline AliFmThreeVector<T>& AliFmThreeVector<T>::operator*= (double c) | |
448 | { | |
449 | mX1 *= c; mX2 *= c; mX3 *= c; | |
450 | return *this; | |
451 | } | |
452 | ||
453 | template<class T> | |
454 | inline AliFmThreeVector<T>& AliFmThreeVector<T>::operator/= (double c) | |
455 | { | |
456 | mX1 /= c; mX2 /= c; mX3 /= c; | |
457 | return *this; | |
458 | } | |
459 | ||
460 | template<class T> | |
461 | inline AliFmThreeVector<T> | |
462 | AliFmThreeVector<T>::pseudoProduct(double x,double y,double z) const | |
463 | { | |
464 | return AliFmThreeVector<T>(mX1*x,mX2*y,mX3*z); | |
465 | } | |
466 | ||
467 | template<class T> | |
468 | AliFmThreeVector<T> AliFmThreeVector<T>::operator- () | |
469 | { | |
470 | return AliFmThreeVector<T>(-mX1, -mX2, -mX3); | |
471 | } | |
472 | ||
473 | template<class T> | |
474 | AliFmThreeVector<T> AliFmThreeVector<T>::operator+ () | |
475 | { | |
476 | return *this; | |
477 | } | |
478 | ||
479 | #ifndef ST_NO_MEMBER_TEMPLATES | |
480 | #ifndef WIN32 | |
481 | ||
482 | template<class T> | |
483 | template<class X> | |
484 | inline AliFmThreeVector<T>::AliFmThreeVector(const AliFmThreeVector<X>& v) | |
485 | : mX1(v.x()), mX2(v.y()), mX3(v.z()) {/* nop */} | |
486 | ||
487 | template<class T> | |
488 | template<class X> | |
489 | inline AliFmThreeVector<T>::AliFmThreeVector(const X *a) | |
490 | { | |
491 | mX1 = a[0]; | |
492 | mX2 = a[1]; | |
493 | mX3 = a[2]; | |
494 | } | |
495 | ||
496 | template<class T> | |
497 | template<class X> | |
498 | inline AliFmThreeVector<T>& | |
499 | AliFmThreeVector<T>::operator=(const AliFmThreeVector<X>& v) | |
500 | { | |
501 | mX1 = v.x(); mX2 = v.y(); mX3 = v.z(); | |
502 | return *this; | |
503 | } | |
504 | ||
505 | template<class T> | |
506 | template<class X> | |
507 | inline bool AliFmThreeVector<T>::operator== (const AliFmThreeVector<X>& v) const | |
508 | { | |
509 | return mX1 == v.x() && mX2 == v.y() && mX3 == v.z(); | |
510 | } | |
511 | ||
512 | template<class T> | |
513 | template<class X> | |
514 | inline bool AliFmThreeVector<T>::operator!= (const AliFmThreeVector<X>& v) const | |
515 | { | |
516 | return !(*this == v); | |
517 | } | |
518 | ||
519 | template<class T> | |
520 | template<class X> | |
521 | inline AliFmThreeVector<T>& | |
522 | AliFmThreeVector<T>::operator+= (const AliFmThreeVector<X>& v) | |
523 | { | |
524 | mX1 += v.x(); mX2 += v.y(); mX3 += v.z(); | |
525 | return *this; | |
526 | } | |
527 | ||
528 | template<class T> | |
529 | template<class X> | |
530 | inline AliFmThreeVector<T>& | |
531 | AliFmThreeVector<T>::operator-= (const AliFmThreeVector<X>& v) | |
532 | { | |
533 | mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z(); | |
534 | return *this; | |
535 | } | |
536 | ||
537 | template<class T> | |
538 | template<class X> | |
539 | inline T AliFmThreeVector<T>::dot(const AliFmThreeVector<X>& v) const | |
540 | { | |
541 | return mX1*v.x() + mX2*v.y() + mX3*v.z(); | |
542 | } | |
543 | ||
544 | template<class T> | |
545 | template<class X> | |
546 | inline AliFmThreeVector<T> | |
547 | AliFmThreeVector<T>::cross(const AliFmThreeVector<X>& v) const | |
548 | { | |
549 | return AliFmThreeVector<T>(mX2*v.z() - mX3*v.y(), | |
550 | mX3*v.x() - mX1*v.z(), | |
551 | mX1*v.y() - mX2*v.x()); | |
552 | } | |
553 | ||
554 | template<class T> | |
555 | template<class X> | |
556 | inline T AliFmThreeVector<T>::angle(const AliFmThreeVector<X>& vec) const | |
557 | { | |
558 | double norm = this->mag2()*vec.mag2(); | |
559 | ||
560 | return norm > 0 ? acos(this->dot(vec)/(::sqrt(norm))) : 0; | |
561 | } | |
562 | ||
563 | template<class T> | |
564 | template<class X> | |
565 | inline AliFmThreeVector<T> | |
566 | AliFmThreeVector<T>::pseudoProduct(const AliFmThreeVector<X>& v) const | |
567 | { | |
568 | return this->pseudoProduct(v.x(),v.y(),v.z()); | |
569 | } | |
570 | ||
571 | #endif | |
572 | #else | |
573 | ||
574 | template<class T> | |
575 | inline AliFmThreeVector<T>::AliFmThreeVector(const AliFmThreeVector<float>& v) | |
576 | : mX1(v.x()), mX2(v.y()), mX3(v.z()) {/* nop */} | |
577 | ||
578 | template<class T> | |
579 | inline AliFmThreeVector<T>::AliFmThreeVector(const AliFmThreeVector<double>& v) | |
580 | : mX1(v.x()), mX2(v.y()), mX3(v.z()) {/* nop */} | |
581 | ||
582 | template<class T> | |
583 | inline AliFmThreeVector<T>::AliFmThreeVector(const float *a) | |
584 | { | |
585 | mX1 = a[0]; | |
586 | mX2 = a[1]; | |
587 | mX3 = a[2]; | |
588 | } | |
589 | ||
590 | template<class T> | |
591 | inline AliFmThreeVector<T>::AliFmThreeVector(const double *a) | |
592 | { | |
593 | mX1 = a[0]; | |
594 | mX2 = a[1]; | |
595 | mX3 = a[2]; | |
596 | } | |
597 | ||
598 | template<class T> | |
599 | inline AliFmThreeVector<T>& | |
600 | AliFmThreeVector<T>::operator=(const AliFmThreeVector<float>& v) | |
601 | { | |
602 | mX1 = v.x(); mX2 = v.y(); mX3 = v.z(); | |
603 | return *this; | |
604 | } | |
605 | ||
606 | template<class T> | |
607 | inline AliFmThreeVector<T>& | |
608 | AliFmThreeVector<T>::operator=(const AliFmThreeVector<double>& v) | |
609 | { | |
610 | mX1 = v.x(); mX2 = v.y(); mX3 = v.z(); | |
611 | return *this; | |
612 | } | |
613 | ||
614 | template<class T> | |
615 | inline bool | |
616 | AliFmThreeVector<T>::operator== (const AliFmThreeVector<float>& v) const | |
617 | { | |
618 | return mX1 == v.x() && mX2 == v.y() && mX3 == v.z(); | |
619 | } | |
620 | ||
621 | template<class T> | |
622 | inline bool | |
623 | AliFmThreeVector<T>::operator== (const AliFmThreeVector<double>& v) const | |
624 | { | |
625 | return mX1 == v.x() && mX2 == v.y() && mX3 == v.z(); | |
626 | } | |
627 | ||
628 | template<class T> | |
629 | inline bool | |
630 | AliFmThreeVector<T>::operator!= (const AliFmThreeVector<float>& v) const | |
631 | { | |
632 | return !(*this == v); | |
633 | } | |
634 | ||
635 | template<class T> | |
636 | inline bool | |
637 | AliFmThreeVector<T>::operator!= (const AliFmThreeVector<double>& v) const | |
638 | { | |
639 | return !(*this == v); | |
640 | } | |
641 | ||
642 | template<class T> | |
643 | inline AliFmThreeVector<T>& | |
644 | AliFmThreeVector<T>::operator+= (const AliFmThreeVector<float>& v) | |
645 | { | |
646 | mX1 += v.x(); mX2 += v.y(); mX3 += v.z(); | |
647 | return *this; | |
648 | } | |
649 | ||
650 | template<class T> | |
651 | inline AliFmThreeVector<T>& | |
652 | AliFmThreeVector<T>::operator+= (const AliFmThreeVector<double>& v) | |
653 | { | |
654 | mX1 += v.x(); mX2 += v.y(); mX3 += v.z(); | |
655 | return *this; | |
656 | } | |
657 | ||
658 | template<class T> | |
659 | inline AliFmThreeVector<T>& | |
660 | AliFmThreeVector<T>::operator-= (const AliFmThreeVector<float>& v) | |
661 | { | |
662 | mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z(); | |
663 | return *this; | |
664 | } | |
665 | ||
666 | template<class T> | |
667 | inline AliFmThreeVector<T>& | |
668 | AliFmThreeVector<T>::operator-= (const AliFmThreeVector<double>& v) | |
669 | { | |
670 | mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z(); | |
671 | return *this; | |
672 | } | |
673 | ||
674 | template<class T> | |
675 | inline T AliFmThreeVector<T>::dot(const AliFmThreeVector<float>& v) const | |
676 | { | |
677 | return mX1*v.x() + mX2*v.y() + mX3*v.z(); | |
678 | } | |
679 | ||
680 | template<class T> | |
681 | inline T AliFmThreeVector<T>::dot(const AliFmThreeVector<double>& v) const | |
682 | { | |
683 | return mX1*v.x() + mX2*v.y() + mX3*v.z(); | |
684 | } | |
685 | ||
686 | template<class T> | |
687 | inline AliFmThreeVector<T> | |
688 | AliFmThreeVector<T>::cross(const AliFmThreeVector<float>& v) const | |
689 | { | |
690 | return AliFmThreeVector<T>(mX2*v.z() - mX3*v.y(), | |
691 | mX3*v.x() - mX1*v.z(), | |
692 | mX1*v.y() - mX2*v.x()); | |
693 | } | |
694 | ||
695 | template<class T> | |
696 | inline AliFmThreeVector<T> | |
697 | AliFmThreeVector<T>::cross(const AliFmThreeVector<double>& v) const | |
698 | { | |
699 | return AliFmThreeVector<T>(mX2*v.z() - mX3*v.y(), | |
700 | mX3*v.x() - mX1*v.z(), | |
701 | mX1*v.y() - mX2*v.x()); | |
702 | } | |
703 | ||
704 | template<class T> | |
705 | inline T AliFmThreeVector<T>::angle(const AliFmThreeVector<float>& v) const | |
706 | { | |
707 | double tmp = mag()*v.mag(); if (tmp <=0) tmp = 1e-20; | |
708 | return acos(this->dot(v)/tmp); | |
709 | } | |
710 | ||
711 | template<class T> | |
712 | inline T AliFmThreeVector<T>::angle(const AliFmThreeVector<double>& v) const | |
713 | { | |
714 | double tmp = mag()*v.mag(); if (tmp <=0) tmp = 1e-20; | |
715 | return acos(this->dot(v)/tmp); | |
716 | } | |
717 | ||
718 | template<class T> | |
719 | inline AliFmThreeVector<T> | |
720 | AliFmThreeVector<T>::pseudoProduct(const AliFmThreeVector<float>& v) const | |
721 | { | |
722 | return this->pseudoProduct(v.x(),v.y(),v.z()); | |
723 | } | |
724 | ||
725 | template<class T> | |
726 | inline AliFmThreeVector<T> | |
727 | AliFmThreeVector<T>::pseudoProduct(const AliFmThreeVector<double>& v) const | |
728 | { | |
729 | return this->pseudoProduct(v.x(),v.y(),v.z()); | |
730 | } | |
731 | #endif // ST_NO_MEMBER_TEMPLATES | |
732 | template<class T> | |
733 | inline int | |
734 | AliFmThreeVector<T>::valid(double world) const {return !bad(world);} | |
735 | ||
736 | template<class T> | |
737 | inline int | |
738 | AliFmThreeVector<T>::bad(double world) const | |
739 | { | |
740 | for (int i=0;i<3;i++) { | |
741 | if (!finite((&mX1)[i]) ) return 10+i; | |
742 | if ( fabs ((&mX1)[i])>world) return 20+i; | |
743 | } | |
744 | return 0; | |
745 | } | |
746 | #endif /*! __CINT__ */ | |
747 | #ifdef __CINT__ | |
748 | template<> float abs(const AliFmThreeVector<float>& v); | |
749 | template<> double abs(const AliFmThreeVector<double>& v); | |
750 | template<> AliFmThreeVector<double> cross_product(const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2); | |
751 | template<> AliFmThreeVector<float> cross_product(const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2); | |
752 | template<> AliFmThreeVector<double> cross_product(const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2); | |
753 | template<> AliFmThreeVector<double> cross_product(const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2); | |
754 | template<> AliFmThreeVector<double> operator+ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2); | |
755 | template<> AliFmThreeVector<float> operator+ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2); | |
756 | template<> AliFmThreeVector<double> operator+ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2); | |
757 | template<> AliFmThreeVector<double> operator+ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2); | |
758 | template<> AliFmThreeVector<double> operator- (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2); | |
759 | template<> AliFmThreeVector<float> operator- (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2); | |
760 | template<> AliFmThreeVector<double> operator- (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2); | |
761 | template<> AliFmThreeVector<double> operator- (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2); | |
762 | template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2); | |
763 | template<> AliFmThreeVector<float> operator* (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2); | |
764 | template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2); | |
765 | template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2); | |
766 | template<> AliFmThreeVector<double> operator* (const double v1, const AliFmThreeVector<float>& v2); | |
767 | template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<float>& v1, const double v2); | |
768 | template<> AliFmThreeVector<double> operator* (const double v1, const AliFmThreeVector<double>& v2); | |
769 | template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<double>& v1, const double v2); | |
770 | template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2); | |
771 | template<> AliFmThreeVector<float> operator/ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2); | |
772 | template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2); | |
773 | template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2); | |
774 | template<> AliFmThreeVector<double> operator/ (const double v1, const AliFmThreeVector<double>& v2); | |
775 | template<> AliFmThreeVector<float> operator/ (const double v1, const AliFmThreeVector<float>& v2); | |
776 | template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<double>& v1, const double v2); | |
777 | template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<float>& v1, const double v2); | |
778 | template<> istream& operator>>(istream& is,const AliFmThreeVector<double>& v); | |
779 | template<> istream& operator>>(istream& is,const AliFmThreeVector<float>& v); | |
780 | template<> ostream& operator<<(ostream& os,const AliFmThreeVector<double>& v); | |
781 | template<> ostream& operator<<(ostream& os,const AliFmThreeVector<float>& v); | |
782 | #else | |
783 | // | |
784 | // Non-member functions | |
785 | // | |
786 | template<class T> | |
787 | inline T abs(const AliFmThreeVector<T>& v) {return v.mag();} | |
788 | ||
789 | template<class T, class X> | |
790 | inline AliFmThreeVector<T> | |
791 | cross_product(const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2) | |
792 | { | |
793 | return v1.cross(v2); | |
794 | } | |
795 | ||
796 | ||
797 | // | |
798 | // Non-member operators | |
799 | // | |
800 | template<class T, class X> | |
801 | inline AliFmThreeVector<T> | |
802 | operator+ (const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2) | |
803 | { | |
804 | return AliFmThreeVector<T>(v1) += v2; | |
805 | } | |
806 | ||
807 | template<class T, class X> | |
808 | inline AliFmThreeVector<T> | |
809 | operator- (const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2) | |
810 | { | |
811 | return AliFmThreeVector<T>(v1) -= v2; | |
812 | } | |
813 | ||
814 | template<class T, class X> | |
815 | inline T operator* (const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2) | |
816 | { | |
817 | return AliFmThreeVector<T>(v1).dot(v2); | |
818 | } | |
819 | ||
820 | template<class T> | |
821 | inline AliFmThreeVector<T> operator* (const AliFmThreeVector<T>& v, double c) | |
822 | { | |
823 | return AliFmThreeVector<T>(v) *= c; | |
824 | } | |
825 | ||
826 | template<class T> | |
827 | inline AliFmThreeVector<T> operator* (double c, const AliFmThreeVector<T>& v) | |
828 | { | |
829 | return AliFmThreeVector<T>(v) *= c; | |
830 | } | |
831 | ||
832 | template<class T, class X> | |
833 | inline AliFmThreeVector<T> operator/ (const AliFmThreeVector<T>& v, X c) | |
834 | { | |
835 | return AliFmThreeVector<T>(v) /= c; | |
836 | } | |
837 | ||
838 | template<class T> | |
839 | ostream& operator<<(ostream& os, const AliFmThreeVector<T>& v) | |
840 | { | |
841 | return os << v.x() << '\t' << v.y() << '\t' << v.z(); | |
842 | } | |
843 | ||
844 | template<class T> | |
845 | istream& operator>>(istream& is, AliFmThreeVector<T>& v) | |
846 | { | |
847 | T x, y, z; | |
848 | is >> x >> y >> z; | |
849 | v.setX(x); | |
850 | v.setY(y); | |
851 | v.setZ(z); | |
852 | return is; | |
853 | } | |
854 | #endif /* ! __CINT__ */ | |
855 | #endif |