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

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