]>
Commit | Line | Data |
---|---|---|
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 | ||
f531a546 | 16 | // $Id$ |
4c039060 | 17 | |
959fbac5 | 18 | /////////////////////////////////////////////////////////////////////////// |
19 | // Class Ali4Vector | |
20 | // Handling of Lorentz 4-vectors in various reference frames. | |
21 | // | |
22 | // This class is meant to serve as a base class for ALICE objects | |
23 | // that have Lorentz 4-vector characteristics. | |
24 | // Error propagation is performed automatically. | |
25 | // | |
26 | // All 4-vectors are treated in the contravariant form and the convention | |
27 | // for the metric and the 4-vector components is according to the one | |
28 | // used in the book "Classical Electrodynamics" by J.D. Jackson. | |
29 | // | |
30 | // A 4-vector is said to have a scalar part and a 3-vector part, | |
31 | // which is indicated by the notation | |
32 | // | |
33 | // x^i = (x^0,x^1,x^2,x^3) | |
34 | // | |
35 | // The scalar part = x^0 | |
36 | // The 3-vector part = (x^1,x^2,x^3) | |
37 | // | |
38 | // In view of accuracy and the fact that e.g. particle identity (mass) | |
39 | // is preserved in many physics processes, the Lorentz invariant | |
40 | // (x^i*x_i) is internally saved together with the scalar part. | |
41 | // | |
42 | // This allows the following two modes of functionality : | |
43 | // | |
44 | // Scalar mode : The scalar part and the 3-vector part are considered | |
45 | // as basic quantities and the invariant with its error | |
46 | // is derived from these. | |
47 | // Invariant mode : The invariant and the 3-vector part are considered | |
48 | // as basic quantities and the scalar with its error | |
49 | // is derived from these. | |
50 | // | |
51 | // The philosophy followed here is the following : | |
52 | // =============================================== | |
53 | // | |
54 | // 1) Invokation of SetVector() sets the scalar and 3-vector parts | |
55 | // and the invariant is calculated from these. | |
56 | // Automatically the scalar mode is selected and invokation of | |
57 | // SetErrors() will calculate the error on the invariant. | |
58 | // | |
59 | // 2) In case the scalar part is modified via SetScalar(), scalar mode is | |
60 | // automatically selected and the Lorentz invariant (x^i*x_i) and its | |
61 | // error are updated accordingly. | |
62 | // The 3-vector part is NOT modified. | |
63 | // This situation arises when one e.g. precisely determines the time | |
64 | // or energy (x^0). | |
65 | // | |
66 | // 3) In case the Lorentz invariant (x^i*x_i) is modified via SetInvariant(), | |
67 | // invariant mode is selected automatically and the scalar part and its | |
68 | // error are updated accordingly. | |
69 | // The 3-vector part is NOT modified. | |
70 | // This situation arises when one e.g. precisely determines the mass. | |
71 | // | |
72 | // 4) In case the vector part is modified via Set3Vector(), then the | |
73 | // current mode determines whether the scalar or the invariant is updated. | |
74 | // Scalar mode : The Lorentz invariant (x^i*x_i) and its error are updated; | |
75 | // the scalar part and its error are NOT modified. | |
76 | // This situation arises when one e.g. improves the 3-position | |
77 | // vector for a particle with a very precise timing. | |
78 | // Invariant mode : The scalar part and its error are updated; | |
79 | // the Lorentz invariant (x^i*x_i) and its error are NOT modified. | |
80 | // This situation arises when one e.g. improves the 3-momentum | |
81 | // vector for a particle with known mass. | |
82 | // | |
83 | // The dotproduct is defined such that p.Dot(p) yields the Lorentz invariant | |
84 | // scalar of the 4-vector p (i.e. m**2 in case p is a 4-momentum). | |
85 | // | |
86 | // Note : | |
87 | // ------ | |
88 | // Vectors (v), Errors (e) and reference frames (f) are specified via | |
89 | // SetVector(Float_t* v,TString f) | |
90 | // SetErrors(Float_t* e,TString f) | |
91 | // under the following conventions : | |
92 | // | |
93 | // f="car" ==> 3-vector part of v in Cartesian coordinates (x,y,z) | |
94 | // f="sph" ==> 3-vector part of v in Spherical coordinates (r,theta,phi) | |
95 | // f="cyl" ==> 3-vector part of v in Cylindrical coordinates (rho,phi,z) | |
96 | // | |
97 | // All angles are in radians. | |
98 | // | |
99 | // Example : | |
100 | // --------- | |
101 | // | |
102 | // Ali4Vector a; | |
103 | // | |
104 | // Float_t v[4]={25,-1,3,7}; | |
105 | // a.SetVector(v,"car"); | |
106 | // | |
107 | // Float_t vec[4]; | |
108 | // a.GetVector(vec,"sph"); | |
109 | // | |
110 | // Ali4Vector b; | |
111 | // Float_t v2[4]={33,6,-18,2}; | |
112 | // b.SetVector(v2,"car"); | |
113 | // | |
114 | // Float_t dotpro=a.Dot(b); | |
115 | // | |
116 | // Float_t x0=16; | |
117 | // Ali3Vector x; | |
118 | // Float_t vec2[3]={1,2,3}; | |
119 | // x.SetVector(vec2,"car"); | |
120 | // | |
121 | // Ali4Vector c; | |
122 | // c.SetVector(x0,x); | |
123 | // c.GetVector(vec,"car"); | |
84bb7c66 | 124 | // c.Data("cyl"); |
959fbac5 | 125 | // c=a+b; |
126 | // c=a-b; | |
127 | // c=a*5; | |
128 | // | |
129 | //--- Author: Nick van Eijndhoven 01-apr-1999 UU-SAP Utrecht | |
f531a546 | 130 | //- Modified: NvE $Date$ UU-SAP Utrecht |
959fbac5 | 131 | /////////////////////////////////////////////////////////////////////////// |
132 | ||
d88f97cc | 133 | #include "Ali4Vector.h" |
c72198f1 | 134 | #include "Riostream.h" |
d88f97cc | 135 | |
136 | ClassImp(Ali4Vector) // Class implementation to enable ROOT I/O | |
137 | ||
138 | Ali4Vector::Ali4Vector() | |
139 | { | |
959fbac5 | 140 | // Creation of a contravariant 4-vector and initialisation of parameters. |
141 | // All values are initialised to 0. | |
142 | // Scalar mode is initially selected. | |
c72198f1 | 143 | SetZero(); |
959fbac5 | 144 | fScalar=1; |
d88f97cc | 145 | } |
146 | /////////////////////////////////////////////////////////////////////////// | |
147 | Ali4Vector::~Ali4Vector() | |
148 | { | |
149 | // Destructor to delete dynamically allocated memory | |
150 | } | |
151 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 152 | Ali4Vector::Ali4Vector(const Ali4Vector& v) |
153 | { | |
154 | // Copy constructor | |
155 | fScalar=v.fScalar; | |
156 | fV2=v.fV2; | |
157 | fDv2=v.fDv2; | |
158 | fV0=v.fV0; | |
159 | fDv0=v.fDv0; | |
160 | fDresult=v.fDresult; | |
161 | fV=v.fV; | |
162 | } | |
163 | /////////////////////////////////////////////////////////////////////////// | |
1fbffa23 | 164 | void Ali4Vector::Load(Ali4Vector& q) |
165 | { | |
166 | // Load all attributes of the input Ali4Vector into this Ali4Vector object. | |
167 | Int_t temp1=q.GetScalarFlag(); | |
168 | Double_t temp2=q.GetResultError(); | |
169 | Double_t a[4]; | |
170 | q.GetVector(a,"sph"); | |
171 | SetVector(a,"sph"); | |
172 | q.GetErrors(a,"car"); | |
173 | SetErrors(a,"car"); | |
174 | fScalar=temp1; | |
175 | fDresult=temp2; | |
176 | } | |
177 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 178 | void Ali4Vector::SetZero() |
179 | { | |
180 | // (Re)set all attributes to zero. | |
181 | // Note : The (de)selection of the scalar mode is not modified. | |
182 | fV2=0; | |
183 | fDv2=0; | |
184 | fV0=0; | |
185 | fDv0=0; | |
186 | fDresult=0; | |
187 | fV.SetZero(); | |
188 | } | |
189 | /////////////////////////////////////////////////////////////////////////// | |
190 | void Ali4Vector::SetVector(Double_t v0,Ali3Vector& v) | |
d88f97cc | 191 | { |
959fbac5 | 192 | // Store contravariant vector. |
193 | // The error on the scalar part is initialised to 0. | |
194 | // The errors on the vector part are taken from the input Ali3Vector. | |
195 | // Scalar mode is automatically selected. | |
196 | // The error on scalar result operations is reset to 0. | |
197 | fScalar=1; | |
d88f97cc | 198 | fV0=v0; |
199 | fV=v; | |
959fbac5 | 200 | fV2=pow(v0,2)-fV.Dot(fV); |
201 | SetScalarError(0); | |
d88f97cc | 202 | } |
203 | /////////////////////////////////////////////////////////////////////////// | |
204 | void Ali4Vector::SetVector(Double_t* v,TString f) | |
205 | { | |
959fbac5 | 206 | // Store vector according to reference frame f. |
207 | // All errors are initialised to 0. | |
208 | // Scalar mode is automatically selected. | |
209 | // The error on scalar result operations is reset to 0. | |
210 | fScalar=1; | |
d88f97cc | 211 | Double_t a[3]; |
212 | for (Int_t i=0; i<3; i++) | |
213 | { | |
214 | a[i]=v[i+1]; | |
215 | } | |
959fbac5 | 216 | fV0=v[0]; |
d88f97cc | 217 | fV.SetVector(a,f); |
959fbac5 | 218 | fV2=pow(fV0,2)-fV.Dot(fV); |
219 | fDv2=0; | |
220 | fDv0=0; | |
221 | fDresult=0; | |
d88f97cc | 222 | } |
223 | /////////////////////////////////////////////////////////////////////////// | |
224 | void Ali4Vector::GetVector(Double_t* v,TString f) | |
225 | { | |
959fbac5 | 226 | // Provide 4-vector components according to reference frame f |
227 | // and according to the current mode. | |
228 | // Scalar mode : The scalar part is directly returned via v[0]. | |
229 | // Invariant mode : The scalar part is re-calculated via the value | |
230 | // of the Lorentz invariant and then returned via v[0]. | |
231 | if (fScalar) | |
232 | { | |
233 | v[0]=fV0; | |
234 | } | |
235 | else | |
236 | { | |
237 | v[0]=sqrt(fV.Dot(fV)+fV2); | |
238 | } | |
d88f97cc | 239 | Double_t a[3]; |
240 | fV.GetVector(a,f); | |
241 | for (Int_t i=0; i<3; i++) | |
242 | { | |
243 | v[i+1]=a[i]; | |
244 | } | |
245 | } | |
246 | /////////////////////////////////////////////////////////////////////////// | |
247 | void Ali4Vector::SetVector(Float_t* v,TString f) | |
248 | { | |
959fbac5 | 249 | // Store vector according to reference frame f. |
250 | // All errors are initialised to 0. | |
251 | // Scalar mode is automatically selected. | |
252 | // The error on scalar result operations is reset to 0. | |
d88f97cc | 253 | Double_t vec[4]; |
254 | for (Int_t i=0; i<4; i++) | |
255 | { | |
256 | vec[i]=v[i]; | |
257 | } | |
258 | SetVector(vec,f); | |
259 | } | |
260 | /////////////////////////////////////////////////////////////////////////// | |
261 | void Ali4Vector::GetVector(Float_t* v,TString f) | |
262 | { | |
959fbac5 | 263 | // Provide 4-vector components according to reference frame f |
264 | // and according to the current mode. | |
265 | // Scalar mode : The scalar part is directly returned via v[0]. | |
266 | // Invariant mode : The scalar part is re-calculated via the value | |
267 | // of the Lorentz invariant and then returned via v[0]. | |
d88f97cc | 268 | Double_t vec[4]; |
269 | GetVector(vec,f); | |
270 | for (Int_t i=0; i<4; i++) | |
271 | { | |
272 | v[i]=vec[i]; | |
273 | } | |
274 | } | |
275 | /////////////////////////////////////////////////////////////////////////// | |
276 | Double_t Ali4Vector::GetScalar() | |
277 | { | |
959fbac5 | 278 | // Provide the scalar part. |
279 | // The error on the scalar value is available via GetResultError() | |
280 | // after invokation of GetScalar(). | |
281 | if (fScalar) | |
282 | { | |
283 | fDresult=fDv0; | |
284 | return fV0; | |
285 | } | |
286 | else | |
287 | { | |
288 | Double_t dot=fV.Dot(fV); | |
289 | Double_t ddot=fV.GetResultError(); | |
290 | Double_t v02=dot+fV2; | |
291 | Double_t dv02=sqrt(pow(ddot,2)+pow(fDv2,2)); | |
292 | Double_t v0=sqrt(fabs(v02)); | |
293 | Double_t dv0=0; | |
294 | if (v0) dv0=dv02/(2.*v0); | |
295 | fDresult=dv0; | |
296 | return v0; | |
297 | } | |
298 | } | |
299 | /////////////////////////////////////////////////////////////////////////// | |
300 | Double_t Ali4Vector::GetResultError() | |
301 | { | |
302 | // Provide the error on the result of an operation yielding a scalar | |
303 | // E.g. GetScalar(), GetInvariant() or Dot() | |
304 | return fDresult; | |
305 | } | |
306 | /////////////////////////////////////////////////////////////////////////// | |
307 | void Ali4Vector::SetScalar(Double_t v0,Double_t dv0) | |
308 | { | |
309 | // Modify the scalar part (v0) and its error (dv0). | |
310 | // The default value for dv0 is 0. | |
311 | // The vector part is not modified. | |
312 | // Scalar mode is automatically selected | |
313 | // ==> Lorentz invariant and its error are updated. | |
314 | // The error on scalar result operations is reset to 0. | |
315 | fScalar=1; | |
316 | fV0=v0; | |
317 | fV2=pow(v0,2)-fV.Dot(fV); | |
318 | SetScalarError(dv0); | |
319 | } | |
320 | /////////////////////////////////////////////////////////////////////////// | |
321 | void Ali4Vector::SetScalarError(Double_t dv0) | |
322 | { | |
323 | // Set the error on the scalar part. | |
324 | // If in scalar mode, update error on the invariant accordingly. | |
325 | // The error on scalar result operations is reset to 0. | |
326 | fDv0=dv0; | |
327 | if (fScalar) | |
328 | { | |
329 | Double_t norm=fV.GetNorm(); | |
330 | Double_t dnorm=fV.GetResultError(); | |
331 | fDv2=sqrt(pow(2.*fV0*fDv0,2)+pow(2.*norm*dnorm,2)); | |
332 | } | |
333 | fDresult=0; | |
334 | } | |
335 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 336 | void Ali4Vector::Set3Vector(Ali3Vector& v) |
959fbac5 | 337 | { |
338 | // Set the 3-vector part, the errors are taken from the input Ali3Vector | |
339 | // Scalar mode : The scalar part and its error are not modified, | |
340 | // the Lorentz invariantand its error are re-calculated. | |
341 | // Invariant mode : The Lorentz invariant and its error are not modified, | |
342 | // the scalar part and its error are re-calculated. | |
343 | // The error on scalar result operations is reset to 0. | |
344 | fV=v; | |
345 | if (fScalar) | |
346 | { | |
347 | SetScalar(fV0,fDv0); | |
348 | } | |
349 | else | |
350 | { | |
351 | SetInvariant(fV2,fDv2); | |
352 | } | |
353 | } | |
354 | /////////////////////////////////////////////////////////////////////////// | |
355 | void Ali4Vector::Set3Vector(Double_t* v,TString f) | |
356 | { | |
357 | // Set the 3-vector part according to reference frame f | |
358 | // The errors on the vector part are initialised to 0 | |
359 | // Scalar mode : The scalar part and its error are not modified, | |
360 | // the Lorentz invariantand its error are re-calculated. | |
361 | // Invariant mode : The Lorentz invariant and its error are not modified, | |
362 | // the scalar part and its error are re-calculated. | |
363 | // The error on scalar result operations is reset to 0. | |
364 | Double_t a[3]; | |
365 | for (Int_t i=0; i<3; i++) | |
366 | { | |
367 | a[i]=v[i]; | |
368 | } | |
369 | fV.SetVector(a,f); | |
370 | ||
371 | if (fScalar) | |
372 | { | |
373 | SetScalar(fV0,fDv0); | |
374 | } | |
375 | else | |
376 | { | |
377 | SetInvariant(fV2,fDv2); | |
378 | } | |
379 | } | |
380 | /////////////////////////////////////////////////////////////////////////// | |
381 | void Ali4Vector::Set3Vector(Float_t* v,TString f) | |
382 | { | |
383 | // Set the 3-vector part according to reference frame f | |
384 | // The errors on the vector part are initialised to 0 | |
385 | // The Lorentz invariant is not modified | |
386 | // The error on scalar result operations is reset to 0. | |
387 | Double_t vec[3]; | |
388 | for (Int_t i=0; i<3; i++) | |
389 | { | |
390 | vec[i]=v[i]; | |
391 | } | |
392 | Set3Vector(vec,f); | |
393 | } | |
394 | /////////////////////////////////////////////////////////////////////////// | |
395 | void Ali4Vector::SetInvariant(Double_t v2,Double_t dv2) | |
396 | { | |
397 | // Modify the Lorentz invariant (v2) quantity v^i*v_i and its error (dv2). | |
398 | // The default value for the error dv2 is 0. | |
399 | // The vector part is not modified. | |
400 | // Invariant mode is automatically selected | |
401 | // ==> the scalar part and its error are updated. | |
402 | // The error on scalar result operations is reset to 0. | |
403 | // | |
404 | fScalar=0; | |
405 | fV2=v2; | |
406 | fDv2=dv2; | |
407 | fV0=GetScalar(); | |
408 | fDv0=GetResultError(); | |
409 | fDresult=0; | |
410 | } | |
411 | /////////////////////////////////////////////////////////////////////////// | |
412 | void Ali4Vector::SetInvariantError(Double_t dv2) | |
413 | { | |
414 | // Set the error on the Lorentz invariant. | |
415 | // If in invariant mode, update error on the scalar part accordingly. | |
416 | // The error on scalar result operations is reset to 0. | |
417 | fDv2=dv2; | |
418 | if (!fScalar) | |
419 | { | |
420 | fDv0=GetResultError(); | |
421 | } | |
422 | fDresult=0; | |
423 | } | |
424 | /////////////////////////////////////////////////////////////////////////// | |
425 | Double_t Ali4Vector::GetInvariant() | |
426 | { | |
427 | // Provide the Lorentz invariant v^i*v_i. | |
428 | // The error on the Lorentz invariant is available via GetResultError() | |
429 | // after invokation of GetInvariant(). | |
430 | if (!fScalar) | |
431 | { | |
432 | fDresult=fDv2; | |
433 | return fV2; | |
434 | } | |
435 | else | |
436 | { | |
437 | Double_t inv=Dot(*this); | |
438 | return inv; | |
439 | } | |
d88f97cc | 440 | } |
441 | /////////////////////////////////////////////////////////////////////////// | |
442 | Ali3Vector Ali4Vector::Get3Vector() | |
443 | { | |
444 | // Provide the 3-vector part | |
445 | return fV; | |
446 | } | |
447 | /////////////////////////////////////////////////////////////////////////// | |
959fbac5 | 448 | void Ali4Vector::SetErrors(Double_t* e,TString f) |
449 | { | |
450 | // Store errors for vector v^i according to reference frame f | |
451 | // If in scalar mode, update error on the invariant accordingly. | |
452 | // The error on scalar result operations is reset to 0. | |
453 | Double_t a[3]; | |
454 | for (Int_t i=0; i<3; i++) | |
455 | { | |
456 | a[i]=e[i+1]; | |
457 | } | |
458 | SetScalarError(e[0]); | |
459 | fV.SetErrors(a,f); | |
460 | } | |
461 | /////////////////////////////////////////////////////////////////////////// | |
462 | void Ali4Vector::SetErrors(Float_t* e,TString f) | |
463 | { | |
464 | // Store errors for vector v^i according to reference frame f | |
465 | // If in scalar mode, update error on the invariant accordingly. | |
466 | // The error on scalar result operations is reset to 0. | |
467 | Double_t a[4]; | |
468 | for (Int_t i=0; i<4; i++) | |
469 | { | |
470 | a[i]=e[i]; | |
471 | } | |
472 | SetErrors(a,f); | |
473 | } | |
474 | /////////////////////////////////////////////////////////////////////////// | |
475 | void Ali4Vector::GetErrors(Double_t* e,TString f) | |
476 | { | |
477 | // Provide errors for vector v^i according to reference frame f | |
478 | // and according to the current mode. | |
479 | // Scalar mode : The error on the scalar part is directly returned via e[0]. | |
480 | // Invariant mode : The error on the scalar part is re-calculated via the error | |
481 | // value on the Lorentz invariant and then returned via e[0]. | |
482 | Double_t a[3]; | |
483 | fV.GetErrors(a,f); | |
484 | ||
485 | e[0]=GetResultError(); | |
486 | for (Int_t i=0; i<3; i++) | |
487 | { | |
488 | e[i+1]=a[i]; | |
489 | } | |
490 | } | |
491 | /////////////////////////////////////////////////////////////////////////// | |
492 | void Ali4Vector::GetErrors(Float_t* e,TString f) | |
493 | { | |
494 | // Provide errors for vector v^i according to reference frame f | |
495 | // and according to the current mode. | |
496 | // Scalar mode : The error on the scalar part is directly returned via e[0]. | |
497 | // Invariant mode : The error on the scalar part is re-calculated via the error | |
498 | // value on the Lorentz invariant and then returned via e[0]. | |
499 | Double_t a[4]; | |
500 | GetErrors(a,f); | |
501 | for (Int_t i=0; i<4; i++) | |
502 | { | |
503 | e[i]=a[i]; | |
504 | } | |
505 | } | |
506 | /////////////////////////////////////////////////////////////////////////// | |
84bb7c66 | 507 | void Ali4Vector::Data(TString f) |
d88f97cc | 508 | { |
959fbac5 | 509 | // Print contravariant vector components and errors according to |
510 | // reference frame f and according to the current mode. | |
511 | // Scalar mode : The scalar part and its error are directly returned. | |
512 | // Invariant mode : The scalar part and its error are re-calculated via the | |
513 | // value (and error) of the Lorentz invariant. | |
514 | ||
d88f97cc | 515 | if (f=="car" || f=="sph" || f=="cyl") |
516 | { | |
959fbac5 | 517 | Double_t vec[4],err[4]; |
d88f97cc | 518 | GetVector(vec,f); |
959fbac5 | 519 | GetErrors(err,f); |
520 | Double_t inv=GetInvariant(); | |
521 | Double_t dinv=GetResultError(); | |
c72198f1 | 522 | cout << " Contravariant vector in " << f.Data() << " coordinates : " |
d88f97cc | 523 | << vec[0] << " " << vec[1] << " " << vec[2] << " " << vec[3] << endl; |
c72198f1 | 524 | cout << " ------------- Errors in " << f.Data() << " coordinates : " |
959fbac5 | 525 | << err[0] << " " << err[1] << " " << err[2] << " " << err[3] << endl; |
526 | cout << " --- Lorentz invariant (v^i*v_i) : " << inv << " error : " << dinv << endl; | |
d88f97cc | 527 | } |
528 | else | |
529 | { | |
c72198f1 | 530 | cout << " *Ali4Vector::Data* Unsupported frame : " << f.Data() << endl |
d88f97cc | 531 | << " Possible frames are 'car', 'sph' and 'cyl'." << endl; |
532 | } | |
533 | } | |
534 | /////////////////////////////////////////////////////////////////////////// | |
535 | Double_t Ali4Vector::Dot(Ali4Vector& q) | |
536 | { | |
537 | // Provide the dot product of the current vector with vector q | |
959fbac5 | 538 | Double_t dotpro=0; |
539 | Double_t a0=GetScalar(); | |
540 | Double_t da0=GetResultError(); | |
541 | if ((this) == &q) // Check for special case v.Dot(v) | |
542 | { | |
543 | Double_t norm=fV.GetNorm(); | |
544 | Double_t dnorm=fV.GetResultError(); | |
545 | dotpro=pow(a0,2)-pow(norm,2); | |
546 | fDresult=sqrt(pow(2.*a0*da0,2)+pow(2.*norm*dnorm,2)); | |
547 | } | |
548 | else | |
549 | { | |
550 | Double_t b0=q.GetScalar(); | |
551 | Double_t db0=q.GetResultError(); | |
552 | Ali3Vector b=q.Get3Vector(); | |
d88f97cc | 553 | |
959fbac5 | 554 | Double_t dot=fV.Dot(b); |
555 | Double_t ddot=fV.GetResultError(); | |
d88f97cc | 556 | |
959fbac5 | 557 | dotpro=a0*b0-dot; |
558 | ||
559 | fDresult=sqrt(pow(b0*da0,2)+pow(a0*db0,2)+pow(ddot,2)); | |
d88f97cc | 560 | } |
959fbac5 | 561 | |
d88f97cc | 562 | return dotpro; |
563 | } | |
564 | /////////////////////////////////////////////////////////////////////////// | |
565 | Ali4Vector Ali4Vector::operator+(Ali4Vector& q) | |
566 | { | |
959fbac5 | 567 | // Add 4-vector q to the current 4-vector |
568 | // Error propagation is performed automatically | |
569 | Double_t a0=GetScalar(); | |
570 | Double_t da0=GetResultError(); | |
571 | Ali3Vector a=Get3Vector(); | |
572 | Double_t b0=q.GetScalar(); | |
573 | Double_t db0=q.GetResultError(); | |
574 | Ali3Vector b=q.Get3Vector(); | |
d88f97cc | 575 | |
959fbac5 | 576 | Double_t c0=a0+b0; |
577 | Ali3Vector c=a+b; | |
578 | Double_t dc0=sqrt(pow(da0,2)+pow(db0,2)); | |
d88f97cc | 579 | |
580 | Ali4Vector v; | |
959fbac5 | 581 | v.SetVector(c0,c); |
582 | v.SetScalarError(dc0); | |
d88f97cc | 583 | return v; |
584 | } | |
585 | /////////////////////////////////////////////////////////////////////////// | |
586 | Ali4Vector Ali4Vector::operator-(Ali4Vector& q) | |
587 | { | |
959fbac5 | 588 | // Subtract 4-vector q from the current 4-vector |
589 | // Error propagation is performed automatically | |
590 | Double_t a0=GetScalar(); | |
591 | Double_t da0=GetResultError(); | |
592 | Ali3Vector a=Get3Vector(); | |
593 | Double_t b0=q.GetScalar(); | |
594 | Double_t db0=q.GetResultError(); | |
595 | Ali3Vector b=q.Get3Vector(); | |
d88f97cc | 596 | |
959fbac5 | 597 | Double_t c0=a0-b0; |
598 | Ali3Vector c=a-b; | |
599 | Double_t dc0=sqrt(pow(da0,2)+pow(db0,2)); | |
d88f97cc | 600 | |
601 | Ali4Vector v; | |
959fbac5 | 602 | v.SetVector(c0,c); |
603 | v.SetScalarError(dc0); | |
d88f97cc | 604 | return v; |
605 | } | |
606 | /////////////////////////////////////////////////////////////////////////// | |
607 | Ali4Vector Ali4Vector::operator*(Double_t s) | |
608 | { | |
959fbac5 | 609 | // Multiply the current 4-vector with a scalar s |
610 | // Error propagation is performed automatically | |
611 | Double_t a0=GetScalar(); | |
612 | Double_t da0=GetResultError(); | |
613 | Ali3Vector a=Get3Vector(); | |
d88f97cc | 614 | |
959fbac5 | 615 | a0*=s; |
616 | a*=s; | |
617 | da0*=s; | |
d88f97cc | 618 | |
619 | Ali4Vector v; | |
959fbac5 | 620 | v.SetVector(a0,a); |
621 | v.SetScalarError(da0); | |
d88f97cc | 622 | |
623 | return v; | |
624 | } | |
625 | /////////////////////////////////////////////////////////////////////////// | |
626 | Ali4Vector Ali4Vector::operator/(Double_t s) | |
627 | { | |
628 | // Divide the current vector by a scalar s | |
959fbac5 | 629 | // Error propagation is performed automatically |
d88f97cc | 630 | |
631 | if (fabs(s)<1.e-20) // Protect against division by 0 | |
632 | { | |
633 | cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl; | |
634 | return *this; | |
635 | } | |
636 | else | |
637 | { | |
959fbac5 | 638 | Double_t a0=GetScalar(); |
639 | Double_t da0=GetResultError(); | |
640 | Ali3Vector a=Get3Vector(); | |
d88f97cc | 641 | |
959fbac5 | 642 | a0/=s; |
643 | a/=s; | |
644 | da0/=s; | |
d88f97cc | 645 | |
646 | Ali4Vector v; | |
959fbac5 | 647 | v.SetVector(a0,a); |
648 | v.SetScalarError(da0); | |
d88f97cc | 649 | |
650 | return v; | |
651 | } | |
652 | } | |
653 | /////////////////////////////////////////////////////////////////////////// | |
654 | Ali4Vector& Ali4Vector::operator+=(Ali4Vector& q) | |
655 | { | |
959fbac5 | 656 | // Add 4-vector q to the current 4-vector |
657 | // Error propagation is performed automatically | |
658 | Double_t a0=GetScalar(); | |
659 | Double_t da0=GetResultError(); | |
660 | Ali3Vector a=Get3Vector(); | |
661 | Double_t b0=q.GetScalar(); | |
662 | Double_t db0=q.GetResultError(); | |
663 | Ali3Vector b=q.Get3Vector(); | |
d88f97cc | 664 | |
959fbac5 | 665 | Double_t c0=a0+b0; |
666 | Ali3Vector c=a+b; | |
667 | Double_t dc0=sqrt(pow(da0,2)+pow(db0,2)); | |
d88f97cc | 668 | |
959fbac5 | 669 | SetVector(c0,c); |
670 | SetScalarError(dc0); | |
d88f97cc | 671 | |
672 | return *this; | |
673 | } | |
674 | /////////////////////////////////////////////////////////////////////////// | |
675 | Ali4Vector& Ali4Vector::operator-=(Ali4Vector& q) | |
676 | { | |
959fbac5 | 677 | // Subtract 4-vector q from the current 4-vector |
678 | // Error propagation is performed automatically | |
679 | Double_t a0=GetScalar(); | |
680 | Double_t da0=GetResultError(); | |
681 | Ali3Vector a=Get3Vector(); | |
682 | Double_t b0=q.GetScalar(); | |
683 | Double_t db0=q.GetResultError(); | |
684 | Ali3Vector b=q.Get3Vector(); | |
d88f97cc | 685 | |
959fbac5 | 686 | Double_t c0=a0-b0; |
687 | Ali3Vector c=a-b; | |
688 | Double_t dc0=sqrt(pow(da0,2)+pow(db0,2)); | |
d88f97cc | 689 | |
959fbac5 | 690 | SetVector(c0,c); |
691 | SetScalarError(dc0); | |
d88f97cc | 692 | |
d88f97cc | 693 | return *this; |
694 | } | |
695 | /////////////////////////////////////////////////////////////////////////// | |
696 | Ali4Vector& Ali4Vector::operator*=(Double_t s) | |
697 | { | |
959fbac5 | 698 | // Multiply the current 4-vector with a scalar s |
699 | // Error propagation is performed automatically | |
700 | Double_t a0=GetScalar(); | |
701 | Double_t da0=GetResultError(); | |
702 | Ali3Vector a=Get3Vector(); | |
d88f97cc | 703 | |
959fbac5 | 704 | a0*=s; |
705 | a*=s; | |
706 | da0*=s; | |
d88f97cc | 707 | |
959fbac5 | 708 | SetVector(a0,a); |
709 | SetScalarError(da0); | |
d88f97cc | 710 | |
d88f97cc | 711 | return *this; |
712 | } | |
713 | /////////////////////////////////////////////////////////////////////////// | |
714 | Ali4Vector& Ali4Vector::operator/=(Double_t s) | |
715 | { | |
716 | // Divide the current vector by a scalar s | |
959fbac5 | 717 | // Error propagation is performed automatically |
d88f97cc | 718 | |
719 | if (fabs(s)<1.e-20) // Protect against division by 0 | |
720 | { | |
959fbac5 | 721 | cout << " *Ali4Vector::/* Division by 0 detected. No action taken." << endl; |
d88f97cc | 722 | return *this; |
723 | } | |
724 | else | |
725 | { | |
959fbac5 | 726 | Double_t a0=GetScalar(); |
727 | Double_t da0=GetResultError(); | |
728 | Ali3Vector a=Get3Vector(); | |
d88f97cc | 729 | |
959fbac5 | 730 | a0/=s; |
731 | a/=s; | |
732 | da0/=s; | |
d88f97cc | 733 | |
959fbac5 | 734 | SetVector(a0,a); |
735 | SetScalarError(da0); | |
d88f97cc | 736 | |
737 | return *this; | |
738 | } | |
739 | } | |
740 | /////////////////////////////////////////////////////////////////////////// | |
959fbac5 | 741 | Int_t Ali4Vector::GetScalarFlag() |
742 | { | |
743 | // Provide the value of the fScalar flag (for internal use only). | |
744 | return fScalar; | |
745 | } | |
746 | /////////////////////////////////////////////////////////////////////////// | |
d071d629 | 747 | Ali3Vector Ali4Vector::GetVecTrans() |
748 | { | |
749 | // Provide the transverse vector part w.r.t. z-axis. | |
750 | // Error propagation is performed automatically | |
751 | ||
752 | return fV.GetVecTrans(); | |
753 | } | |
754 | /////////////////////////////////////////////////////////////////////////// | |
755 | Ali3Vector Ali4Vector::GetVecLong() | |
756 | { | |
757 | // Provide the longitudinal vector part w.r.t. z-axis. | |
758 | // Error propagation is performed automatically | |
759 | ||
760 | return fV.GetVecLong(); | |
761 | } | |
762 | /////////////////////////////////////////////////////////////////////////// | |
763 | Double_t Ali4Vector::GetScaTrans() | |
764 | { | |
765 | // Provide the "transverse value" of the scalar part w.r.t. z-axis. | |
766 | // This provides a basis for e.g. E_trans calculation. | |
767 | // Note : the returned value is always positive or zero. | |
768 | // The error on the value is available via GetResultError() | |
769 | // after invokation of GetScaTrans(). | |
770 | Double_t a[3],ea[3]; | |
771 | ||
772 | fV.GetVector(a,"sph"); | |
773 | fV.GetErrors(ea,"sph"); | |
774 | ||
775 | Double_t s=GetScalar(); | |
776 | Double_t ds=GetResultError(); | |
777 | ||
778 | Double_t st,dst2; | |
779 | st=s*sin(a[1]); | |
780 | dst2=pow((sin(a[1])*ds),2)+pow((s*cos(a[1])*ea[1]),2); | |
781 | ||
782 | fDresult=sqrt(dst2); | |
783 | return fabs(st); | |
784 | } | |
785 | /////////////////////////////////////////////////////////////////////////// | |
786 | Double_t Ali4Vector::GetScaLong() | |
787 | { | |
788 | // Provide the "longitudinal value" of the scalar part w.r.t. z-axis. | |
789 | // This provides a basis for e.g. E_long calculation. | |
790 | // Note : the returned value can also be negative. | |
791 | // The error on the value is available via GetResultError() | |
792 | // after invokation of GetScaLong(). | |
793 | Double_t a[3],ea[3]; | |
794 | ||
795 | fV.GetVector(a,"sph"); | |
796 | fV.GetErrors(ea,"sph"); | |
797 | ||
798 | Double_t s=GetScalar(); | |
799 | Double_t ds=GetResultError(); | |
800 | ||
801 | Double_t sl,dsl2; | |
802 | sl=s*cos(a[1]); | |
803 | dsl2=pow((cos(a[1])*ds),2)+pow((s*sin(a[1])*ea[1]),2); | |
804 | ||
805 | fDresult=sqrt(dsl2); | |
806 | return sl; | |
807 | } | |
808 | /////////////////////////////////////////////////////////////////////////// | |
809 | Double_t Ali4Vector::GetPseudoRapidity() | |
810 | { | |
811 | // Provide the pseudorapidity value of the vector part w.r.t. z-axis. | |
812 | // The error on the value is available via GetResultError() | |
813 | // after invokation of GetPseudoRapidity(). | |
814 | Double_t eta=fV.GetPseudoRapidity(); | |
815 | fDresult=fV.GetResultError(); | |
816 | return eta; | |
817 | } | |
818 | /////////////////////////////////////////////////////////////////////////// |