]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FEMTOSCOPY/AliFemto/Infrastructure/AliFemtoThreeVector.h
This commit was generated by cvs2svn to compensate for changes in r18145,
[u/mrichter/AliRoot.git] / PWG2 / FEMTOSCOPY / AliFemto / Infrastructure / AliFemtoThreeVector.h
CommitLineData
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)
90using std::out_of_range;
91# endif
92#endif
93#endif // __CINT__
94
95#ifdef WIN32
96#include "gcc2vs.h"
97#endif
98
99class TRootIOCtor;//nic nie rozumiem
100using namespace std;
101
102
103template<class T> class AliFmThreeVector {
104public:
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;
205protected:
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//
216template<class T>
217inline AliFmThreeVector<T>::AliFmThreeVector(T x, T y, T z)
218 : mX1(x), mX2(y), mX3(z) {/* nop */}
219template<class T>
220inline AliFmThreeVector<T>::~AliFmThreeVector() {/* nop */}
221
222template<class T>
223inline void AliFmThreeVector<T>::setX(T x) {mX1 = x;}
224
225template<class T>
226inline void AliFmThreeVector<T>::setY(T y) {mX2 = y;}
227
228template<class T>
229inline void AliFmThreeVector<T>::setZ(T z) {mX3 = z;}
230
231template<class T>
232void 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
241template <class T>
242void 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
252template <class T>
253void 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
263template <class T>
264void AliFmThreeVector<T>::setMag(T mag)
265{
266 setMagnitude(mag);
267}
268
269template<class T>
270inline T AliFmThreeVector<T>::x() const {return mX1;}
271
272template<class T>
273inline T AliFmThreeVector<T>::y() const {return mX2;}
274
275template<class T>
276inline T AliFmThreeVector<T>::z() const {return mX3;}
277
278template<class T>
279inline T AliFmThreeVector<T>::theta() const
280{
281 return acos(cosTheta());
282}
283
284template<class T>
285inline T AliFmThreeVector<T>::cosTheta() const
286{
287 return mX3/(mag()+1e-20);
288}
289
290template<class T>
291inline T AliFmThreeVector<T>::phi() const
292{
293 return atan2(mX2,mX1);
294}
295
296template<class T>
297inline 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
307template<class T>
308inline AliFmThreeVector<T> AliFmThreeVector<T>::unit() const
309{
310 double tmp = mag(); if (tmp<=0.) tmp = 1e-20;
311 return *this/tmp;
312}
313
314template <class T>
315T AliFmThreeVector<T>::massHypothesis(T mass) const
316{
317 return ::sqrt((*this)*(*this) + mass*mass);
318}
319
320template <class T>
321AliFmThreeVector<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
335template <class T>
336void 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
346template <class T>
347void 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
357template <class T>
358void 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
368template<class T>
369inline T AliFmThreeVector<T>::perp() const
370{
371 return ::sqrt(mX1*mX1+mX2*mX2);
372}
373
374template<class T>
375inline T AliFmThreeVector<T>::perp2() const
376{
377 return mX1*mX1+mX2*mX2;
378}
379
380template<class T>
381inline T AliFmThreeVector<T>::magnitude() const
382{
383 return mag();
384}
385
386template<class T>
387inline T AliFmThreeVector<T>::mag() const
388{
389 return ::sqrt(mX1*mX1+mX2*mX2+mX3*mX3);
390}
391
392template<class T>
393inline T AliFmThreeVector<T>::mag2() const
394{
395 return mX1*mX1+mX2*mX2+mX3*mX3;
396}
397
398template<class T>
399inline 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
410template<class T>
411inline 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
422template<class T>
423inline 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
434template<class T>
435inline 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
446template<class T>
447inline AliFmThreeVector<T>& AliFmThreeVector<T>::operator*= (double c)
448{
449 mX1 *= c; mX2 *= c; mX3 *= c;
450 return *this;
451}
452
453template<class T>
454inline AliFmThreeVector<T>& AliFmThreeVector<T>::operator/= (double c)
455{
456 mX1 /= c; mX2 /= c; mX3 /= c;
457 return *this;
458}
459
460template<class T>
461inline AliFmThreeVector<T>
462AliFmThreeVector<T>::pseudoProduct(double x,double y,double z) const
463{
464 return AliFmThreeVector<T>(mX1*x,mX2*y,mX3*z);
465}
466
467template<class T>
468AliFmThreeVector<T> AliFmThreeVector<T>::operator- ()
469{
470 return AliFmThreeVector<T>(-mX1, -mX2, -mX3);
471}
472
473template<class T>
474AliFmThreeVector<T> AliFmThreeVector<T>::operator+ ()
475{
476 return *this;
477}
478
479#ifndef ST_NO_MEMBER_TEMPLATES
480#ifndef WIN32
481
482template<class T>
483template<class X>
484inline AliFmThreeVector<T>::AliFmThreeVector(const AliFmThreeVector<X>& v)
485 : mX1(v.x()), mX2(v.y()), mX3(v.z()) {/* nop */}
486
487template<class T>
488template<class X>
489inline AliFmThreeVector<T>::AliFmThreeVector(const X *a)
490{
491 mX1 = a[0];
492 mX2 = a[1];
493 mX3 = a[2];
494}
495
496template<class T>
497template<class X>
498inline AliFmThreeVector<T>&
499AliFmThreeVector<T>::operator=(const AliFmThreeVector<X>& v)
500{
501 mX1 = v.x(); mX2 = v.y(); mX3 = v.z();
502 return *this;
503}
504
505template<class T>
506template<class X>
507inline bool AliFmThreeVector<T>::operator== (const AliFmThreeVector<X>& v) const
508{
509 return mX1 == v.x() && mX2 == v.y() && mX3 == v.z();
510}
511
512template<class T>
513template<class X>
514inline bool AliFmThreeVector<T>::operator!= (const AliFmThreeVector<X>& v) const
515{
516 return !(*this == v);
517}
518
519template<class T>
520template<class X>
521inline AliFmThreeVector<T>&
522AliFmThreeVector<T>::operator+= (const AliFmThreeVector<X>& v)
523{
524 mX1 += v.x(); mX2 += v.y(); mX3 += v.z();
525 return *this;
526}
527
528template<class T>
529template<class X>
530inline AliFmThreeVector<T>&
531AliFmThreeVector<T>::operator-= (const AliFmThreeVector<X>& v)
532{
533 mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z();
534 return *this;
535}
536
537template<class T>
538template<class X>
539inline T AliFmThreeVector<T>::dot(const AliFmThreeVector<X>& v) const
540{
541 return mX1*v.x() + mX2*v.y() + mX3*v.z();
542}
543
544template<class T>
545template<class X>
546inline AliFmThreeVector<T>
547AliFmThreeVector<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
554template<class T>
555template<class X>
556inline 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
563template<class T>
564template<class X>
565inline AliFmThreeVector<T>
566AliFmThreeVector<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
574template<class T>
575inline AliFmThreeVector<T>::AliFmThreeVector(const AliFmThreeVector<float>& v)
576 : mX1(v.x()), mX2(v.y()), mX3(v.z()) {/* nop */}
577
578template<class T>
579inline AliFmThreeVector<T>::AliFmThreeVector(const AliFmThreeVector<double>& v)
580 : mX1(v.x()), mX2(v.y()), mX3(v.z()) {/* nop */}
581
582template<class T>
583inline AliFmThreeVector<T>::AliFmThreeVector(const float *a)
584{
585 mX1 = a[0];
586 mX2 = a[1];
587 mX3 = a[2];
588}
589
590template<class T>
591inline AliFmThreeVector<T>::AliFmThreeVector(const double *a)
592{
593 mX1 = a[0];
594 mX2 = a[1];
595 mX3 = a[2];
596}
597
598template<class T>
599inline AliFmThreeVector<T>&
600AliFmThreeVector<T>::operator=(const AliFmThreeVector<float>& v)
601{
602 mX1 = v.x(); mX2 = v.y(); mX3 = v.z();
603 return *this;
604}
605
606template<class T>
607inline AliFmThreeVector<T>&
608AliFmThreeVector<T>::operator=(const AliFmThreeVector<double>& v)
609{
610 mX1 = v.x(); mX2 = v.y(); mX3 = v.z();
611 return *this;
612}
613
614template<class T>
615inline bool
616AliFmThreeVector<T>::operator== (const AliFmThreeVector<float>& v) const
617{
618 return mX1 == v.x() && mX2 == v.y() && mX3 == v.z();
619}
620
621template<class T>
622inline bool
623AliFmThreeVector<T>::operator== (const AliFmThreeVector<double>& v) const
624{
625 return mX1 == v.x() && mX2 == v.y() && mX3 == v.z();
626}
627
628template<class T>
629inline bool
630AliFmThreeVector<T>::operator!= (const AliFmThreeVector<float>& v) const
631{
632 return !(*this == v);
633}
634
635template<class T>
636inline bool
637AliFmThreeVector<T>::operator!= (const AliFmThreeVector<double>& v) const
638{
639 return !(*this == v);
640}
641
642template<class T>
643inline AliFmThreeVector<T>&
644AliFmThreeVector<T>::operator+= (const AliFmThreeVector<float>& v)
645{
646 mX1 += v.x(); mX2 += v.y(); mX3 += v.z();
647 return *this;
648}
649
650template<class T>
651inline AliFmThreeVector<T>&
652AliFmThreeVector<T>::operator+= (const AliFmThreeVector<double>& v)
653{
654 mX1 += v.x(); mX2 += v.y(); mX3 += v.z();
655 return *this;
656}
657
658template<class T>
659inline AliFmThreeVector<T>&
660AliFmThreeVector<T>::operator-= (const AliFmThreeVector<float>& v)
661{
662 mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z();
663 return *this;
664}
665
666template<class T>
667inline AliFmThreeVector<T>&
668AliFmThreeVector<T>::operator-= (const AliFmThreeVector<double>& v)
669{
670 mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z();
671 return *this;
672}
673
674template<class T>
675inline T AliFmThreeVector<T>::dot(const AliFmThreeVector<float>& v) const
676{
677 return mX1*v.x() + mX2*v.y() + mX3*v.z();
678}
679
680template<class T>
681inline T AliFmThreeVector<T>::dot(const AliFmThreeVector<double>& v) const
682{
683 return mX1*v.x() + mX2*v.y() + mX3*v.z();
684}
685
686template<class T>
687inline AliFmThreeVector<T>
688AliFmThreeVector<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
695template<class T>
696inline AliFmThreeVector<T>
697AliFmThreeVector<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
704template<class T>
705inline 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
711template<class T>
712inline 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
718template<class T>
719inline AliFmThreeVector<T>
720AliFmThreeVector<T>::pseudoProduct(const AliFmThreeVector<float>& v) const
721{
722 return this->pseudoProduct(v.x(),v.y(),v.z());
723}
724
725template<class T>
726inline AliFmThreeVector<T>
727AliFmThreeVector<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
732template<class T>
733inline int
734AliFmThreeVector<T>::valid(double world) const {return !bad(world);}
735
736template<class T>
737inline int
738AliFmThreeVector<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__
748template<> float abs(const AliFmThreeVector<float>& v);
749template<> double abs(const AliFmThreeVector<double>& v);
750template<> AliFmThreeVector<double> cross_product(const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2);
751template<> AliFmThreeVector<float> cross_product(const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2);
752template<> AliFmThreeVector<double> cross_product(const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2);
753template<> AliFmThreeVector<double> cross_product(const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2);
754template<> AliFmThreeVector<double> operator+ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2);
755template<> AliFmThreeVector<float> operator+ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2);
756template<> AliFmThreeVector<double> operator+ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2);
757template<> AliFmThreeVector<double> operator+ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2);
758template<> AliFmThreeVector<double> operator- (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2);
759template<> AliFmThreeVector<float> operator- (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2);
760template<> AliFmThreeVector<double> operator- (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2);
761template<> AliFmThreeVector<double> operator- (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2);
762template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2);
763template<> AliFmThreeVector<float> operator* (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2);
764template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2);
765template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2);
766template<> AliFmThreeVector<double> operator* (const double v1, const AliFmThreeVector<float>& v2);
767template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<float>& v1, const double v2);
768template<> AliFmThreeVector<double> operator* (const double v1, const AliFmThreeVector<double>& v2);
769template<> AliFmThreeVector<double> operator* (const AliFmThreeVector<double>& v1, const double v2);
770template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<double>& v2);
771template<> AliFmThreeVector<float> operator/ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<float>& v2);
772template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<double>& v1, const AliFmThreeVector<float>& v2);
773template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<float>& v1, const AliFmThreeVector<double>& v2);
774template<> AliFmThreeVector<double> operator/ (const double v1, const AliFmThreeVector<double>& v2);
775template<> AliFmThreeVector<float> operator/ (const double v1, const AliFmThreeVector<float>& v2);
776template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<double>& v1, const double v2);
777template<> AliFmThreeVector<double> operator/ (const AliFmThreeVector<float>& v1, const double v2);
778template<> istream& operator>>(istream& is,const AliFmThreeVector<double>& v);
779template<> istream& operator>>(istream& is,const AliFmThreeVector<float>& v);
780template<> ostream& operator<<(ostream& os,const AliFmThreeVector<double>& v);
781template<> ostream& operator<<(ostream& os,const AliFmThreeVector<float>& v);
782#else
783//
784// Non-member functions
785//
786template<class T>
787inline T abs(const AliFmThreeVector<T>& v) {return v.mag();}
788
789template<class T, class X>
790inline AliFmThreeVector<T>
791cross_product(const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2)
792{
793 return v1.cross(v2);
794}
795
796
797//
798// Non-member operators
799//
800template<class T, class X>
801inline AliFmThreeVector<T>
802operator+ (const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2)
803{
804 return AliFmThreeVector<T>(v1) += v2;
805}
806
807template<class T, class X>
808inline AliFmThreeVector<T>
809operator- (const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2)
810{
811 return AliFmThreeVector<T>(v1) -= v2;
812}
813
814template<class T, class X>
815inline T operator* (const AliFmThreeVector<T>& v1, const AliFmThreeVector<X>& v2)
816{
817 return AliFmThreeVector<T>(v1).dot(v2);
818}
819
820template<class T>
821inline AliFmThreeVector<T> operator* (const AliFmThreeVector<T>& v, double c)
822{
823 return AliFmThreeVector<T>(v) *= c;
824}
825
826template<class T>
827inline AliFmThreeVector<T> operator* (double c, const AliFmThreeVector<T>& v)
828{
829 return AliFmThreeVector<T>(v) *= c;
830}
831
832template<class T, class X>
833inline AliFmThreeVector<T> operator/ (const AliFmThreeVector<T>& v, X c)
834{
835 return AliFmThreeVector<T>(v) /= c;
836}
837
838template<class T>
839ostream& operator<<(ostream& os, const AliFmThreeVector<T>& v)
840{
841 return os << v.x() << '\t' << v.y() << '\t' << v.z();
842}
843
844template<class T>
845istream& 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