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