]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/Ali4Vector.cxx
Introduction of the Copyright and cvs Log
[u/mrichter/AliRoot.git] / RALICE / Ali4Vector.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
18*/
19
d88f97cc 20#include "Ali4Vector.h"
21
22ClassImp(Ali4Vector) // Class implementation to enable ROOT I/O
23
24Ali4Vector::Ali4Vector()
25{
26// Creation of a contravariant 4-vector and initialisation of parameters
27 fV0=0;
28 Double_t a[3]={0,0,0};
29 fV.SetVector(a,"sph");
30}
31///////////////////////////////////////////////////////////////////////////
32Ali4Vector::~Ali4Vector()
33{
34// Destructor to delete dynamically allocated memory
35}
36///////////////////////////////////////////////////////////////////////////
37void Ali4Vector::SetVector(Double_t v0,Ali3Vector v)
38{
39// Store contravariant vector
40 fV0=v0;
41 fV=v;
42}
43///////////////////////////////////////////////////////////////////////////
44void Ali4Vector::SetVector(Double_t* v,TString f)
45{
46// Store vector according to reference frame f
47 fV0=v[0];
48 Double_t a[3];
49 for (Int_t i=0; i<3; i++)
50 {
51 a[i]=v[i+1];
52 }
53 fV.SetVector(a,f);
54}
55///////////////////////////////////////////////////////////////////////////
56void Ali4Vector::GetVector(Double_t* v,TString f)
57{
58// Provide vector according to reference frame f
59 v[0]=fV0;
60 Double_t a[3];
61 fV.GetVector(a,f);
62 for (Int_t i=0; i<3; i++)
63 {
64 v[i+1]=a[i];
65 }
66}
67///////////////////////////////////////////////////////////////////////////
68void Ali4Vector::SetVector(Float_t* v,TString f)
69{
70// Store vector according to reference frame f
71 Double_t vec[4];
72 for (Int_t i=0; i<4; i++)
73 {
74 vec[i]=v[i];
75 }
76 SetVector(vec,f);
77}
78///////////////////////////////////////////////////////////////////////////
79void Ali4Vector::GetVector(Float_t* v,TString f)
80{
81// Provide vector according to reference frame f
82 Double_t vec[4];
83 GetVector(vec,f);
84 for (Int_t i=0; i<4; i++)
85 {
86 v[i]=vec[i];
87 }
88}
89///////////////////////////////////////////////////////////////////////////
90Double_t Ali4Vector::GetScalar()
91{
92// Provide the scalar part
93 return fV0;
94}
95///////////////////////////////////////////////////////////////////////////
96Ali3Vector Ali4Vector::Get3Vector()
97{
98// Provide the 3-vector part
99 return fV;
100}
101///////////////////////////////////////////////////////////////////////////
102void Ali4Vector::Info(TString f)
103{
104// Print contravariant vector components according to reference frame f
105 if (f=="car" || f=="sph" || f=="cyl")
106 {
107 Double_t vec[4];
108 GetVector(vec,f);
109 cout << " Contravariant vector in " << f << " coordinates : "
110 << vec[0] << " " << vec[1] << " " << vec[2] << " " << vec[3] << endl;
111 }
112 else
113 {
114 cout << " *Ali4Vector::Info* Unsupported frame : " << f << endl
115 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
116 }
117}
118///////////////////////////////////////////////////////////////////////////
119Double_t Ali4Vector::Dot(Ali4Vector& q)
120{
121// Provide the dot product of the current vector with vector q
122 Double_t a[4],b[4];
123 Double_t dotpro;
124
125 GetVector(a,"car");
126 q.GetVector(b,"car");
127
128 dotpro=a[0]*b[0];
129 for (Int_t i=1; i<4; i++)
130 {
131 dotpro-=a[i]*b[i];
132 }
133
134 return dotpro;
135}
136///////////////////////////////////////////////////////////////////////////
137Ali4Vector Ali4Vector::operator+(Ali4Vector& q)
138{
139// Add vector q to the current vector
140 Double_t a[4],b[4];
141
142 GetVector(a,"car");
143 q.GetVector(b,"car");
144
145 for (Int_t i=0; i<4; i++)
146 {
147 a[i]+=b[i];
148 }
149
150 Ali4Vector v;
151 v.SetVector(a,"car");
152
153 return v;
154}
155///////////////////////////////////////////////////////////////////////////
156Ali4Vector Ali4Vector::operator-(Ali4Vector& q)
157{
158// Subtract vector q from the current vector
159 Double_t a[4],b[4];
160
161 GetVector(a,"car");
162 q.GetVector(b,"car");
163
164 for (Int_t i=0; i<4; i++)
165 {
166 a[i]-=b[i];
167 }
168
169 Ali4Vector v;
170 v.SetVector(a,"car");
171
172 return v;
173}
174///////////////////////////////////////////////////////////////////////////
175Ali4Vector Ali4Vector::operator*(Double_t s)
176{
177// Multiply the current vector with a scalar s
178 Double_t a[4];
179
180 GetVector(a,"car");
181
182 for (Int_t i=0; i<4; i++)
183 {
184 a[i]*=s;
185 }
186
187 Ali4Vector v;
188 v.SetVector(a,"car");
189
190 return v;
191}
192///////////////////////////////////////////////////////////////////////////
193Ali4Vector Ali4Vector::operator/(Double_t s)
194{
195// Divide the current vector by a scalar s
196
197 if (fabs(s)<1.e-20) // Protect against division by 0
198 {
199 cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl;
200 return *this;
201 }
202 else
203 {
204 Double_t a[4];
205
206 GetVector(a,"car");
207
208 for (Int_t i=0; i<4; i++)
209 {
210 a[i]/=s;
211 }
212
213 Ali4Vector v;
214 v.SetVector(a,"car");
215
216 return v;
217 }
218}
219///////////////////////////////////////////////////////////////////////////
220Ali4Vector& Ali4Vector::operator+=(Ali4Vector& q)
221{
222// Add vector q to the current vector
223 Double_t a[4],b[4];
224
225 GetVector(a,"car");
226 q.GetVector(b,"car");
227
228 for (Int_t i=0; i<4; i++)
229 {
230 a[i]+=b[i];
231 }
232
233 SetVector(a,"car");
234
235 return *this;
236}
237///////////////////////////////////////////////////////////////////////////
238Ali4Vector& Ali4Vector::operator-=(Ali4Vector& q)
239{
240// Subtract vector q from the current vector
241 Double_t a[4],b[4];
242
243 GetVector(a,"car");
244 q.GetVector(b,"car");
245
246 for (Int_t i=0; i<4; i++)
247 {
248 a[i]-=b[i];
249 }
250
251 SetVector(a,"car");
252
253 return *this;
254}
255///////////////////////////////////////////////////////////////////////////
256Ali4Vector& Ali4Vector::operator*=(Double_t s)
257{
258// Multiply the current vector with a scalar s
259 Double_t a[4];
260
261 GetVector(a,"car");
262
263 for (Int_t i=0; i<4; i++)
264 {
265 a[i]*=s;
266 }
267
268 SetVector(a,"car");
269
270 return *this;
271}
272///////////////////////////////////////////////////////////////////////////
273Ali4Vector& Ali4Vector::operator/=(Double_t s)
274{
275// Divide the current vector by a scalar s
276
277 if (fabs(s)<1.e-20) // Protect against division by 0
278 {
279 cout << " *Ali4Vector::/=* Division by 0 detected. No action taken." << endl;
280 return *this;
281 }
282 else
283 {
284 Double_t a[4];
285
286 GetVector(a,"car");
287
288 for (Int_t i=0; i<4; i++)
289 {
290 a[i]/=s;
291 }
292
293 SetVector(a,"car");
294
295 return *this;
296 }
297}
298///////////////////////////////////////////////////////////////////////////