source: trunk/Mars/mbase/MQuaternion.h@ 19187

Last change on this file since 19187 was 18998, checked in by tbretz, 7 years ago
Switch off the workaround when compiling with clang -- it would not compile.
File size: 4.2 KB
Line 
1#ifndef MARS_MQuaternion
2#define MARS_MQuaternion
3
4#if 1
5
6// We prefer to derive from TQuaternion instead of TLorantzVector
7// because TQuaternion implements vector algebra with just the 3D vector
8
9#ifndef ROOT_TQuaternion
10#include <math.h>
11#ifndef __clang__
12#if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 8))
13#define sqrt ::sqrt
14#endif
15#endif
16#include <TQuaternion.h>
17//#undef sqrt
18#endif
19
20class MQuaternion : public TQuaternion
21{
22public:
23 MQuaternion(const TQuaternion &q) : TQuaternion(q) { }
24 MQuaternion(const TVector3 &v, Double_t t=0) : TQuaternion(v, t) { }
25 void operator*=(const TRotation &r)
26 {
27 fVectorPart *= r;
28 }
29 Double_t X() const { return fVectorPart.X(); }
30 Double_t Y() const { return fVectorPart.Y(); }
31 Double_t Z() const { return fVectorPart.Z(); }
32 Double_t T() const { return fRealPart; }
33
34 // It seems to be a little bit faster than X*X+Y*Y
35 Double_t R2() const { return XYvector().Mod2(); }
36 Double_t R() const { return XYvector().Mod(); }
37
38 void PropagateDz(const MQuaternion &w, const Double_t dz)
39 {
40 *this += dz/w.Z()*w;
41 }
42
43 // Propagates the particle by a distance f in z along
44 // its trajectory w, if f is positive, in the opposite
45 // direction otherwise.
46 void PropagateZ(const MQuaternion &w, const Double_t z)
47 {
48 PropagateDz(w, z-Z());
49
50 // z=3400, Z= 1700, t=0, c=1 -= 3400/-5*-5 -= 3400 Z=0, c>0
51 // += 1700/-5*-5 += 1700 Z=1700, c>0
52 // z=3400, Z=-1700, t=0, c=1 -= -3400/-5*-5 -= -1700 Z=0, c<0
53
54 // z=3400, Z= 1700, t=0, c=1 -= (3400-1700)/-5*-5 -= 3400 Z=0, c>0
55 }
56
57 // Move the photon along its trajectory to the x/y plane
58 // so that z=0. Therefor stretch the vector until
59 // its z-component vanishes.
60 //p -= p.Z()/u.Z()*u;
61 void PropagateZ0(const MQuaternion &w)
62 {
63 // If z>0 we still have to move by a distance of z.
64 // If z<0 we have to move in the opposite direction.
65 // --> z has the right sign for PropagateZ
66 PropagateDz(w, -Z());
67
68 // Z= 1700, t=0, c=1 -= 1700/-5*-5 -= 1700 +c Z=0, c>0
69 // Z=-1700, t=0, c=1 -= -1700/-5*-5 -= -1700 -c Z=0, c<0
70
71
72 // Z= 1700, t=0, c=1 -= 1700/ 5* 5 -= 1700 -c Z=0, c<0
73 // Z=-1700, t=0, c=1 -= -1700/ 5* 5 -= -1700 +c Z=0, c>0
74
75 //PropagateZ(w, Z());
76 }
77
78 TVector2 XYvector() const { return fVectorPart.XYvector(); }
79
80 //void Normalize() { fVectorPart *= TMath::Sqrt(1 - R2())/Z(); }
81
82 void NormalizeVector() { fVectorPart = fVectorPart.Unit(); }
83
84 ClassDef(MQuaternion, 1)
85};
86
87#else
88
89#ifndef ROOT_TLorentzVector
90#include <TLorentzVector.h>
91#endif
92
93class MQuaternion : public TLorentzVector
94{
95public:
96 //MQuaternion(const TLorentzVector &q) : TLorentzVector(q) { }
97 MQuaternion(const TVector3 &v, Double_t t=0) : TLorentzVector(v, t) { }
98 /*
99 void operator*=(const TRotation &r)
100 {
101 fVectorPart *= r;
102 }
103 Double_t X() const { return fVectorPart.X(); }
104 Double_t Y() const { return fVectorPart.Y(); }
105 Double_t Z() const { return fVectorPart.Z(); }
106 Double_t T() const { return fRealPart; }
107 */
108
109 // It seems to be a little bit faster than X*X+Y*Y
110 Double_t R2() const { return Perp2(); }
111 Double_t R() const { return Perp(); }
112
113 // Propagates the particle by a distance f in z along
114 // its trajectory w, if f is positive, in the opposite
115 // direction otherwise.
116 void PropagateZ(const MQuaternion &w, const Double_t f)
117 {
118 *this += f/TMath::Abs(w.Z())*w;
119 }
120
121 // Move the photon along its trajectory to the x/y plane
122 // so that z=0. Therefor stretch the vector until
123 // its z-component vanishes.
124 //p -= p.Z()/u.Z()*u;
125 void PropagateZ0(const MQuaternion &w)
126 {
127 // If z>0 we still have to move by a distance of z.
128 // If z<0 we have to move in th eopposite direction.
129 // --> z has the right sign for PropagateZ
130 PropagateZ(w, Z());
131 }
132
133 TVector2 XYvector() const { return Vect().XYvector(); }
134
135 //void Normalize() { fVectorPart *= TMath::Sqrt(1 - R2())/Z(); }
136
137 ClassDef(MQuaternion, 0)
138};
139
140#endif
141
142#endif
Note: See TracBrowser for help on using the repository browser.