source: huonglan/MYSIMULATION/MyVector4.C @ 15

Last change on this file since 15 was 15, checked in by huonglan, 13 years ago

fast simulation of t't'bar pair production from my stage

File size: 3.6 KB
Line 
1#include <iostream>
2#include <cstdio>
3#include <math.h>
4
5#include "MyVector4.h"
6
7//using namespace std;
8
9
10MyVector4::MyVector4()
11{
12  MyVector3 v3(0.,0.,0.);
13  this->mv3 = v3;
14  this->mt = 0.;
15}
16
17MyVector4::MyVector4(MyVector3 v3, double t)
18{
19  this->mv3 = v3;
20  this->mt = t;
21}
22
23MyVector3 MyVector4::vector3() const
24{
25  return this->mv3;
26}
27
28double MyVector4::perp() const
29{
30 return sqrt((this->mv3.X())*(this->mv3.X())+ (this->mv3.Y())*(this->mv3.Y()) + (this->mv3.Z())*(this->mv3.Z()));
31}
32
33double MyVector4::time() const
34{
35  return this->mt;
36}
37
38double MyVector4::E() const
39{
40  return this->mt;
41}
42
43double MyVector4::mass() const
44{
45  double mass = pow((this->mt),2)-pow((this->mv3.mag()),2);
46  if (mass<0){
47    //cout << "Tachyon!" << endl;
48    return -sqrt(-mass);}
49  else
50    return sqrt(mass);
51}
52
53double MyVector4::phi() const
54{
55  double phi4 = atan2(this->mv3.Y(),this->mv3.X());
56  if (phi4 < - M_PI && phi4 > M_PI){
57    cout << " Incorrect value of phi ! " << endl;
58    return 0.;
59  }
60  else
61    return phi4;
62}
63
64double MyVector4::Pt() const
65{
66  return this->mv3.perp();
67}
68
69double MyVector4::eta() const
70{
71  return this->mv3.eta();
72}
73
74double MyVector4::deltaR(MyVector4 &vec4) const
75{
76  MyVector3 vec3 = this -> mv3;
77  MyVector3 vec33 = vec4.vector3();
78  double delta_R = vec3.deltaR(vec33);
79  return delta_R;
80}
81
82void MyVector4::SetPtEtaPhiM(double Pt, double eta, double phi, double M)
83{
84  MyVector3 v3(Pt*cos(phi),Pt*sin(phi),Pt*sinh(eta));
85  this->mv3 = v3;
86  this->mt = sqrt(M*M+v3.mag()*v3.mag()); 
87}
88
89//###### OPERATEURS ##############
90
91MyVector4& MyVector4::operator=(MyVector4 &vec)
92{
93  MyVector3 vec3 = vec.vector3();
94  this->mv3 = vec3;
95  this->mt = vec.time();
96
97  return *this;
98}
99
100//Add 10 June !!!
101bool MyVector4::operator==(MyVector4 &vec)
102{
103  MyVector3 vec1 = this->mv3;
104  MyVector3 vec2 = vec.mv3;
105  double t1 = this->mt;
106  double t2 = vec.mt;
107  if ((vec1 == vec2) && (t1 == t2))
108    return true;
109  else
110    return false;
111}
112//***************
113
114MyVector4& MyVector4::operator+=(MyVector4 &vec)
115{
116  MyVector3 vec3 = vec.vector3();
117  this->mv3 += vec3;
118  this->mt += vec.time();
119
120  return *this;
121}
122
123MyVector4 operator+ (MyVector4 &vec1, MyVector4 &vec2)
124{
125  MyVector3 vec31 = vec1.vector3();
126  MyVector3 vec32 = vec2.vector3();
127  MyVector3 vec3_final = vec31 + vec32;
128
129  double t1 = vec1.time();
130  double t2 = vec2.time();
131
132  double t_final = t1 + t2;
133
134  return MyVector4(vec3_final,t_final);
135}
136
137MyVector4 operator- (MyVector4 &vec1, MyVector4 &vec2)
138{
139  MyVector3 vec31 = vec1.vector3();
140  MyVector3 vec32 = vec2.vector3();
141  MyVector3 vec3_final = vec31 - vec32;
142
143  double t1 = vec1.time();
144  double t2 = vec2.time();
145
146  double t_final = t1 - t2;
147
148  return MyVector4(vec3_final,t_final);
149}
150
151//####### BOOST #########
152
153void MyVector4::boost(MyVector3 beta_vect)
154{
155  double beta = beta_vect.mag();
156
157  if (beta>1)
158    {
159      cout <<"Beta > 1 : Forbidden! Do nothing !!!" << endl;
160    }
161 
162  double gamma = 1./sqrt(1. - beta*beta);
163  MyVector3 unit = beta_vect*(double)(1./beta);
164  MyVector3 v3 = this->mv3;
165  double time = this->mt;
166
167  double scala = (double)(v3*unit);
168
169  MyVector3 v3_paral = unit*scala;
170  MyVector3 v3_perpen = v3 - v3_paral;
171
172  MyVector3 v3_perpen_boost = v3_perpen;
173  MyVector3 v3_paral_boost = unit*((scala + beta*time)*gamma);
174
175  MyVector3 v3_boost = v3_perpen_boost + v3_paral_boost;       
176  double t_boost = (double)gamma*(time + beta*scala);
177
178  this->mv3 = v3_boost;
179  this->mt = t_boost;
180}
181
182//********************* Print operator ************************
183std::ostream& operator<<(std::ostream& out, const MyVector4& vec) 
184{
185  out << vec.vector3()
186     << " " << vec.time()
187     << " " << vec.mass()
188     << std::endl;
189
190 return out;
191}
Note: See TracBrowser for help on using the repository browser.