NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcPosition.cxx
Go to the documentation of this file.
1
31
33
43// Positions (r), errors (e), reference frames (f) and angular units (u)
44// are specified via
45//
46// SetPosition(Float_t* r,TString f,TString u)
47// SetPositionErrors(Float_t* e,TString f,TString u)
48//
49// under the following conventions :
50//
51// f="car" ==> r in Cartesian coordinates (x,y,z)
52// f="sph" ==> r in Spherical coordinates (r,theta,phi)
53// f="cyl" ==> r in Cylindrical coordinates (rho,phi,z)
54//
55// u="rad" ==> angles in radians
56// u="deg" ==> angles in degrees
57//
58// The "f" and "u" facilities only serve as a convenient user interface.
59// Internally the actual storage of the various components is performed
60// in a unique way. This allows setting/retrieval of vector components in a
61// user selected frame/unit convention at any time.
62//
63// The metric unit scale for the coordinates can be defined by the user
64// via the SetUnitScale() memberfunction.
65// This enables standardised expressions using numerical values of
66// physical constants by means of the GetUnitScale() memberfunction.
67// By default the unit scale is set to meter, corresponding to invokation
68// of SetUnitScale(1).
69// The user can specify a certain required metric unit scale in retreiving
70// position components and/or distances.
71// Please refer to the corresponding member functions for further details.
72//
73//
74// Example :
75// ---------
76//
77// NcPosition q;
78// Float_t pos[3]={-1,25,7};
79// Float_t err[3]={0.08,1.85,0.5};
80// q.SetPosition(pos,"car");
81// q.SetPositionErrors(pos,"car");
82// Float_t loc[3],dloc[3];
83// q.GetPosition(loc,"sph","deg");
84// q.GetPositionErrors(dloc,"sph","deg");
85//
86//--- Author: Nick van Eijndhoven 06-feb-1999 Utrecht University
87//- Modified: Nick van Eijndhoven, IIHE-VUB, Brussel, May 4, 2021 10:49Z
88~~~
89**/
91
92#include "NcPosition.h"
93#include "Riostream.h"
94
95ClassImp(NcPosition); // Class implementation to enable ROOT I/O
96
99{
106
107 fScale=1;
108 fTstamp=0;
109}
110
112{
118
119 if (fTstamp)
120 {
121 delete fTstamp;
122 fTstamp=0;
123 }
124}
125
127{
133
134 fScale=p.fScale;
135 fTstamp=0;
136 if (p.fTstamp) fTstamp=new NcTimestamp(*(p.fTstamp));
137}
138
139void NcPosition::SetPosition(Double_t* r,TString f,TString u)
140{
153
154 SetVector(r,f,u);
155}
156
157void NcPosition::SetPosition(Double_t r1,Double_t r2,Double_t r3,TString f,TString u)
158{
171
172 SetVector(r1,r2,r3,f,u);
173}
174
175void NcPosition::GetPosition(Double_t* r,TString f,TString u,Float_t scale) const
176{
196
197 Nc3Vector v=(Nc3Vector)(*this);
198 if (scale>0) v*=fScale/scale;
199 v.GetVector(r,f,u);
200}
201
202void NcPosition::SetPosition(Float_t* r,TString f,TString u)
203{
216
217 SetVector(r,f,u);
218}
219
220void NcPosition::GetPosition(Float_t* r,TString f,TString u,Float_t scale) const
221{
241
242 Nc3Vector v=(Nc3Vector)(*this);
243 if (scale>0) v*=fScale/scale;
244 v.GetVector(r,f,u);
245}
246
248{
254
255 return (*this);
256}
257
259{
265
266 Double_t a[3];
267 r.GetVector(a,"sph");
268 SetVector(a,"sph");
269 r.GetErrors(a,"car");
270 SetErrors(a,"car");
271}
272
273void NcPosition::SetPositionErrors(Double_t* e,TString f,TString u)
274{
287
288 SetErrors(e,f,u);
289}
290
291void NcPosition::SetPositionErrors(Double_t e1,Double_t e2,Double_t e3,TString f,TString u)
292{
305
306 SetErrors(e1,e2,e3,f,u);
307}
308
309void NcPosition::GetPositionErrors(Double_t* e,TString f,TString u,Float_t scale) const
310{
330
331 Nc3Vector v=(Nc3Vector)(*this);
332 if (scale>0) v*=fScale/scale;
333 v.GetErrors(e,f,u);
334}
335
336void NcPosition::SetPositionErrors(Float_t* e,TString f,TString u)
337{
350
351 SetErrors(e,f,u);
352}
353
354void NcPosition::GetPositionErrors(Float_t* e,TString f,TString u,Float_t scale) const
355{
375
376 Nc3Vector v=(Nc3Vector)(*this);
377 if (scale>0) v*=fScale/scale;
378 v.GetErrors(e,f,u);
379}
380
382{
389
390 SetZero();
391}
392
393Double_t NcPosition::GetDistance(NcPosition& p,Float_t scale)
394{
414
415 Nc3Vector d=(Nc3Vector)p;
416 Float_t pscale=p.GetUnitScale();
417 if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale);
418 Nc3Vector q=(Nc3Vector)(*this);
419 d=d-q;
420 Double_t dist=d.GetNorm();
422
423 if (scale>0)
424 {
425 dist*=fScale/scale;
426 fDresult*=fScale/scale;
427 }
428 return dist;
429}
430
432{
447
448 if (s>0.)
449 {
450 fScale=s;
451 }
452 else
453 {
454 cout << " *NcPosition::SetUnitScale* Invalid argument s = " << s << endl;
455 }
456}
457
459{
467
468 return fScale;
469}
470
472{
478
479 if (fTstamp) delete fTstamp;
480 fTstamp=new NcTimestamp(t);
481}
482
484{
490
491 return fTstamp;
492}
493
495{
501
502 if (fTstamp)
503 {
504 delete fTstamp;
505 fTstamp=0;
506 }
507}
508
509void NcPosition::Data(TString f,TString u) const
510{
523
524 Nc3Vector::Data(f,u);
525 if (fNv) cout << " Metric unit : " << fScale << " meter" << endl;
526 if (fTstamp) fTstamp->Date(1);
527}
528
529
ClassImp(NcPosition)
Double32_t fDresult
! Error on scalar result (e.g. norm or dotproduct)
Definition Nc3Vector.h:61
void GetErrors(Double_t *e, TString f, TString u="rad") const
void SetVector(Double_t *v, TString f, TString u="rad")
virtual void SetZero()
virtual void Data(TString f="car", TString u="rad") const
void SetErrors(Double_t *e, TString f, TString u="rad")
Int_t fNv
Definition Nc3Vector.h:59
Double_t GetResultError() const
void GetVector(Double_t *v, TString f, TString u="rad") const
Double_t GetNorm()
Handling of positions (with timestamps) in various reference frames.
Definition NcPosition.h:18
virtual ~NcPosition()
NcPosition & GetPosition()
void RemoveTimestamp()
NcTimestamp * fTstamp
Definition NcPosition.h:47
void SetUnitScale(Float_t s)
Float_t fScale
Definition NcPosition.h:46
Double_t GetDistance(NcPosition &p, Float_t scale=-1)
void SetPositionErrors(Double_t *e, TString f, TString u="rad")
Float_t GetUnitScale() const
void GetPositionErrors(Double_t *e, TString f, TString u="rad", Float_t s=-1) const
virtual void Data(TString f="car", TString u="rad") const
void SetPosition(Double_t *r, TString f, TString u="rad")
void ResetPosition()
NcTimestamp * GetTimestamp()
void SetTimestamp(NcTimestamp &t)
Handling of timestamps for (astro)particle physics research.
Definition NcTimestamp.h:20