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

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