1 #include "Ali3Vector.h"
3 ClassImp(Ali3Vector) // Class implementation to enable ROOT I/O
5 Ali3Vector::Ali3Vector()
7 // Creation of an Ali3Vector object and initialisation of parameters
12 ///////////////////////////////////////////////////////////////////////////
13 Ali3Vector::~Ali3Vector()
15 // Destructor to delete dynamically allocated memory
17 ///////////////////////////////////////////////////////////////////////////
18 void Ali3Vector::SetVector(Double_t* v,TString f)
20 // Store vector according to reference frame f
21 Double_t pi=acos(-1.);
23 if (f == "car") frame=1;
24 if (f == "sph") frame=2;
25 if (f == "cyl") frame=3;
27 Double_t x,y,z,rho,phi;
31 case 1: // Cartesian coordinates
37 if (fV && fabs(z/fV)<=1.)
45 if (fTheta<0.) fTheta+=2.*pi;
47 if (x || y) fPhi=atan2(y,x);
48 if (fPhi<0.) fPhi+=2.*pi;
51 case 2: // Spherical coordinates
57 case 3: // Cylindrical coordinates
63 if (fPhi<0.) fPhi+=2.*pi;
65 if (fV && fabs(z/fV)<=1.)
73 if (fTheta<0.) fTheta+=2.*pi;
76 default: // Unsupported reference frame
77 cout << "*Ali3Vector::SetVector* Unsupported frame : " << f << endl
78 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
85 ///////////////////////////////////////////////////////////////////////////
86 void Ali3Vector::GetVector(Double_t* v,TString f)
88 // Provide vector according to reference frame f
90 if (f == "car") frame=1;
91 if (f == "sph") frame=2;
92 if (f == "cyl") frame=3;
96 case 1: // Cartesian coordinates
97 v[0]=fV*sin(fTheta)*cos(fPhi);
98 v[1]=fV*sin(fTheta)*sin(fPhi);
102 case 2: // Spherical coordinates
108 case 3: // Cylindrical coordinates
114 default: // Unsupported reference frame
115 cout << "*Ali3Vector::GetVector* Unsupported frame : " << f << endl
116 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
117 for (Int_t i=0; i<3; i++)
124 ///////////////////////////////////////////////////////////////////////////
125 void Ali3Vector::SetVector(Float_t* v,TString f)
127 // Store vector according to reference frame f
129 for (Int_t i=0; i<3; i++)
135 ///////////////////////////////////////////////////////////////////////////
136 void Ali3Vector::GetVector(Float_t* v,TString f)
138 // Provide vector according to reference frame f
141 for (Int_t i=0; i<3; i++)
146 ///////////////////////////////////////////////////////////////////////////
147 void Ali3Vector::Info(TString f)
149 // Print vector components according to reference frame f
150 if (f=="car" || f=="sph" || f=="cyl")
154 cout << " Vector in " << f << " coordinates : "
155 << vec[0] << " " << vec[1] << " " << vec[2] << endl;
159 cout << " *Ali3Vector::Info* Unsupported frame : " << f << endl
160 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
163 ///////////////////////////////////////////////////////////////////////////
164 Double_t Ali3Vector::GetNorm()
168 ///////////////////////////////////////////////////////////////////////////
169 Double_t Ali3Vector::Dot(Ali3Vector& q)
171 // Provide the dot product of the current vector with vector q
176 q.GetVector(b,"car");
177 for (Int_t i=0; i<3; i++)
184 ///////////////////////////////////////////////////////////////////////////
185 Ali3Vector Ali3Vector::Cross(Ali3Vector& q)
187 // Provide the cross product of the current vector with vector q
188 Double_t a[3],b[3],c[3];
191 q.GetVector(b,"car");
193 c[0]=a[1]*b[2]-a[2]*b[1];
194 c[1]=a[2]*b[0]-a[0]*b[2];
195 c[2]=a[0]*b[1]-a[1]*b[0];
198 v.SetVector(c,"car");
202 ///////////////////////////////////////////////////////////////////////////
203 Ali3Vector Ali3Vector::operator+(Ali3Vector& q)
205 // Add vector q to the current vector
209 q.GetVector(b,"car");
211 for (Int_t i=0; i<3; i++)
217 v.SetVector(a,"car");
221 ///////////////////////////////////////////////////////////////////////////
222 Ali3Vector Ali3Vector::operator-(Ali3Vector& q)
224 // Subtract vector q from the current vector
228 q.GetVector(b,"car");
230 for (Int_t i=0; i<3; i++)
236 v.SetVector(a,"car");
240 ///////////////////////////////////////////////////////////////////////////
241 Ali3Vector Ali3Vector::operator*(Double_t s)
243 // Multiply the current vector with a scalar s
248 for (Int_t i=0; i<3; i++)
254 v.SetVector(a,"car");
258 ///////////////////////////////////////////////////////////////////////////
259 Ali3Vector Ali3Vector::operator/(Double_t s)
261 // Divide the current vector by a scalar s
263 if (fabs(s)<1.e-20) // Protect against division by 0
265 cout << " *Ali3Vector::/* Division by 0 detected. No action taken." << endl;
274 for (Int_t i=0; i<3; i++)
280 v.SetVector(a,"car");
285 ///////////////////////////////////////////////////////////////////////////
286 Ali3Vector& Ali3Vector::operator+=(Ali3Vector& q)
288 // Add vector q to the current vector
292 q.GetVector(b,"car");
294 for (Int_t i=0; i<3; i++)
303 ///////////////////////////////////////////////////////////////////////////
304 Ali3Vector& Ali3Vector::operator-=(Ali3Vector& q)
306 // Subtract vector q from the current vector
310 q.GetVector(b,"car");
312 for (Int_t i=0; i<3; i++)
321 ///////////////////////////////////////////////////////////////////////////
322 Ali3Vector& Ali3Vector::operator*=(Double_t s)
324 // Multiply the current vector with a scalar s
329 for (Int_t i=0; i<3; i++)
338 ///////////////////////////////////////////////////////////////////////////
339 Ali3Vector& Ali3Vector::operator/=(Double_t s)
341 // Divide the current vector by a scalar s
343 if (fabs(s)<1.e-20) // Protect against division by 0
345 cout << " *Ali3Vector::/=* Division by 0 detected. No action taken." << endl;
354 for (Int_t i=0; i<3; i++)
364 ///////////////////////////////////////////////////////////////////////////