]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RALICE/AliPosition.cxx
Return the most probable momentum if the magnetic field is too weak and the momentum...
[u/mrichter/AliRoot.git] / RALICE / AliPosition.cxx
index bec52b28d478312565512324d7c6cce7e1b63546..ac3e1ff49ea6a33403f0f972faa04e8c7cc92322 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-*/
+// $Id$
+
+///////////////////////////////////////////////////////////////////////////
+// Class AliPosition
+// Handling of positions in various reference frames.
+//
+// This class is meant to serve as a base class for ALICE objects
+// that have a unique position in 3-dimensional space.
+//
+// Note :
+// ------
+// Positions (r), errors (e), reference frames (f) and angular units (u)
+// are specified via
+//
+//    SetPosition(Float_t* r,TString f,TString u)
+//    SetPositionErrors(Float_t* e,TString f,TString u)
+//
+// under the following conventions :
+//
+// f="car" ==> r in Cartesian coordinates   (x,y,z)
+// f="sph" ==> r in Spherical coordinates   (r,theta,phi)
+// f="cyl" ==> r in Cylindrical coordinates (rho,phi,z)
+//
+// u="rad" ==> angles in radians
+// u="deg" ==> angles in degrees
+//
+// The "f" and "u" facilities only serve as a convenient user interface.
+// Internally the actual storage of the various components is performed
+// in a unique way. This allows setting/retrieval of vector components in a
+// user selected frame/unit convention at any time. 
+//
+// The metric unit scale for the coordinates can be defined by the user
+// via the SetUnitScale() memberfunction.
+// This enables standardised expressions using numerical values of
+// physical constants by means of the GetUnitScale() memberfunction.
+// By default the unit scale is set to cm, corresponding to invokation
+// of SetUnitScale(0.01).
+//   
+//
+// Example :
+// ---------
+//
+// AliPosition q;
+// Float_t pos[3]={-1,25,7};
+// Float_t err[3]={0.08,1.85,0.5};
+// q.SetPosition(pos,"car");
+// q.SetPositionErrors(pos,"car");
+// Float_t loc[3],dloc[3];
+// q.GetPosition(loc,"sph","deg");
+// q.GetPositionErrors(dloc,"sph","deg");
+//
+//--- Author: Nick van Eijndhoven 06-feb-1999 UU-SAP Utrecht
+//- Modified: NvE $Date$ UU-SAP Utrecht
+///////////////////////////////////////////////////////////////////////////
 
 #include "AliPosition.h"
+#include "Riostream.h"
  
 ClassImp(AliPosition) // Class implementation to enable ROOT I/O
  
 AliPosition::AliPosition()
 {
-// Creation of an AliPosition object and initialisation of parameters
+// Creation of an AliPosition object and initialisation of parameters.
+// The unit scale for position coordinates is initialised to cm.
+ fScale=0.01;
+ fTstamp=0;
 }
 ///////////////////////////////////////////////////////////////////////////
 AliPosition::~AliPosition()
 {
 // Destructor to delete dynamically allocated memory
+ if (fTstamp)
+ {
+  delete fTstamp;
+  fTstamp=0;
+ }
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliPosition::SetPosition(Double_t* r,TString f)
+AliPosition::AliPosition(const AliPosition& p) : Ali3Vector(p)
+{
+// Copy constructor
+ fScale=p.fScale;
+ fTstamp=0;
+ if (p.fTstamp) fTstamp=new AliTimestamp(*(p.fTstamp));
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::SetPosition(Double_t* r,TString f,TString u)
 {
 // Store position according to reference frame f
- SetVector(r,f);
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ SetVector(r,f,u);
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliPosition::GetPosition(Double_t* r,TString f)
+void AliPosition::GetPosition(Double_t* r,TString f,TString u) const
 {
 // Provide position according to reference frame f
- GetVector(r,f);
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ GetVector(r,f,u);
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliPosition::SetPosition(Float_t* r,TString f)
+void AliPosition::SetPosition(Float_t* r,TString f,TString u)
 {
 // Store position according to reference frame f
- SetVector(r,f);
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ SetVector(r,f,u);
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliPosition::GetPosition(Float_t* r,TString f)
+void AliPosition::GetPosition(Float_t* r,TString f,TString u) const
 {
 // Provide position according to reference frame f
- GetVector(r,f);
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ GetVector(r,f,u);
 }
 ///////////////////////////////////////////////////////////////////////////
 AliPosition& AliPosition::GetPosition()
@@ -67,5 +167,164 @@ void AliPosition::SetPosition(Ali3Vector& r)
  Double_t a[3];
  r.GetVector(a,"sph");
  SetVector(a,"sph");
+ r.GetErrors(a,"car");
+ SetErrors(a,"car");
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::SetPositionErrors(Double_t* r,TString f,TString u)
+{
+// Store position errors according to reference frame f
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ SetErrors(r,f,u);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::GetPositionErrors(Double_t* r,TString f,TString u) const
+{
+// Provide position errors according to reference frame f
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ GetErrors(r,f,u);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::SetPositionErrors(Float_t* r,TString f,TString u)
+{
+// Store position errors according to reference frame f
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ SetErrors(r,f,u);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::GetPositionErrors(Float_t* r,TString f,TString u) const
+{
+// Provide position errors according to reference frame f
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The default is u="rad".
+
+ GetErrors(r,f,u);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::ResetPosition()
+{
+// Reset the position and corresponding errors to 0.
+ Double_t r[3]={0,0,0};
+ SetVector(r,"sph");
+ SetErrors(r,"car");
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliPosition::GetDistance(AliPosition& p)
+{
+// Provide distance of the current AliPosition to position p.
+// The error on the result can be obtained as usual by invoking
+// GetResultError() afterwards. 
+//
+// In the case of two positions with different unit scales, the distance
+// will be provided in the unit scale of the current AliPosition.
+// This implies that in such cases the results of r.GetDistance(q) and
+// q.GetDistance(r) will be numerically different.
+// As such it is possible to obtain a correctly computed distance between
+// positions which have different unit scales.
+// However, it is recommended to work always with one single unit scale.
+//
+ Ali3Vector d=(Ali3Vector)p;
+ Float_t pscale=p.GetUnitScale();
+ if ((pscale/fScale > 1.1) || (fScale/pscale > 1.1)) d=d*(pscale/fScale);
+ Ali3Vector q=(Ali3Vector)(*this);
+ d=d-q;
+ Double_t dist=d.GetNorm();
+ fDresult=d.GetResultError();
+ return dist;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::SetUnitScale(Float_t s)
+{
+// Set the unit scale for the position coordinates.
+// The scale is normalised w.r.t. the meter, so setting the unit scale
+// to 0.01 means that all position coordinates are in cm.
+// By default the unit scale is set to cm in the AliPosition constructor.
+// It is recommended to use one single unit scale throughout a complete
+// analysis and/or simulation project.
+//
+// Note : This memberfunction does not modify the numerical values of
+//        the position coordinates.
+//        It only specifies their numerical meaning.
+// 
+ if (s>0.)
+ {
+  fScale=s;
+ }
+ else
+ {
+  cout << " *AliPosition::SetUnitScale* Invalid argument s = " << s << endl;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+Float_t AliPosition::GetUnitScale() const
+{
+// Provide the unit scale for the position coordinates.
+// The scale is normalised w.r.t. the meter, so a unit scale of 0.01
+// means that all position coordinates are in cm.
+ return fScale;
 }
 ///////////////////////////////////////////////////////////////////////////
+void AliPosition::SetTimestamp(AliTimestamp& t)
+{
+// Store the timestamp for this position.
+ if (fTstamp) delete fTstamp;
+ fTstamp=new AliTimestamp(t);
+}
+///////////////////////////////////////////////////////////////////////////
+AliTimestamp* AliPosition::GetTimestamp()
+{
+// Provide the timestamp of this position.
+ return fTstamp;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::RemoveTimestamp()
+{
+// Remove the timestamp from this postion.
+ if (fTstamp)
+ {
+  delete fTstamp;
+  fTstamp=0;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+void AliPosition::Data(TString f,TString u) const
+{
+// Provide all position/time information within the coordinate frame f.
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The defaults are f="car" and u="rad".
+
+ Ali3Vector::Data(f,u);
+ if (fTstamp) fTstamp->Date(1);
+} 
+///////////////////////////////////////////////////////////////////////////