source: branches/MarsMoreSimulationTruth/mbase/MQuaternion.h@ 20115

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