source: trunk/MagicSoft/Mars/mbase/MQuaternion.h@ 9432

Last change on this file since 9432 was 9370, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.0 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 ClassDef(MQuaternion, 1)
79};
80
81#else
82
83#ifndef ROOT_TLorentzVector
84#include <TLorentzVector.h>
85#endif
86
87class MQuaternion : public TLorentzVector
88{
89public:
90 //MQuaternion(const TLorentzVector &q) : TLorentzVector(q) { }
91 MQuaternion(const TVector3 &v, Double_t t=0) : TLorentzVector(v, t) { }
92 /*
93 void operator*=(const TRotation &r)
94 {
95 fVectorPart *= r;
96 }
97 Double_t X() const { return fVectorPart.X(); }
98 Double_t Y() const { return fVectorPart.Y(); }
99 Double_t Z() const { return fVectorPart.Z(); }
100 Double_t T() const { return fRealPart; }
101 */
102
103 // It seems to be a little bit faster than X*X+Y*Y
104 Double_t R2() const { return Perp2(); }
105 Double_t R() const { return Perp(); }
106
107 // Propagates the particle by a distance f in z along
108 // its trajectory w, if f is positive, in the opposite
109 // direction otherwise.
110 void PropagateZ(const MQuaternion &w, const Double_t f)
111 {
112 *this += f/TMath::Abs(w.Z())*w;
113 }
114
115 // Move the photon along its trajectory to the x/y plane
116 // so that z=0. Therefor stretch the vector until
117 // its z-component vanishes.
118 //p -= p.Z()/u.Z()*u;
119 void PropagateZ0(const MQuaternion &w)
120 {
121 // If z>0 we still have to move by a distance of z.
122 // If z<0 we have to move in th eopposite direction.
123 // --> z has the right sign for PropagateZ
124 PropagateZ(w, Z());
125 }
126
127 TVector2 XYvector() const { return Vect().XYvector(); }
128
129 //void Normalize() { fVectorPart *= TMath::Sqrt(1 - R2())/Z(); }
130
131 ClassDef(MQuaternion, 0)
132};
133
134#endif
135
136#endif
Note: See TracBrowser for help on using the repository browser.