* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
+
+/* $Id$ */
+
///////////////////////////////////////////////////////////////////
// //
// A straight line is coded as a point (3 Double_t) and //
// 3 direction cosines //
// //
///////////////////////////////////////////////////////////////////
+
#include <Riostream.h>
#include <TTree.h>
+#include <TMath.h>
+
#include "AliStrLine.h"
ClassImp(AliStrLine)
//________________________________________________________
AliStrLine::AliStrLine() :
TObject(),
- fTpar(0),
- fDebug(0)
+ fWMatrix(0),
+ fTpar(0)
{
// Default constructor
for(Int_t i=0;i<3;i++) {
fP0[i] = 0.;
+ fSigma2P0[i] = 0.;
fCd[i] = 0.;
}
}
//________________________________________________________
AliStrLine::AliStrLine(Double_t *point, Double_t *cd,Bool_t twopoints) :
TObject(),
- fTpar(0),
- fDebug(0)
+ fWMatrix(0),
+ fTpar(0)
{
// Standard constructor
// if twopoints is true: point and cd are the 3D coordinates of
// if twopoint is false: point represents the 3D coordinates of a point
// belonging to the straight line and cd is the
// direction in space
+ for(Int_t i=0;i<3;i++){
+ fSigma2P0[i] = 0.;
+ }
if(twopoints){
InitTwoPoints(point,cd);
}
}
}
+//________________________________________________________
+AliStrLine::AliStrLine(Float_t *pointf, Float_t *cdf,Bool_t twopoints) :
+ TObject(),
+ fWMatrix(0),
+ fTpar(0)
+{
+ // Standard constructor - with float arguments
+ // if twopoints is true: point and cd are the 3D coordinates of
+ // two points defininig the straight line
+ // if twopoint is false: point represents the 3D coordinates of a point
+ // belonging to the straight line and cd is the
+ // direction in space
+ Double_t point[3];
+ Double_t cd[3];
+ for(Int_t i=0;i<3;i++){
+ point[i] = pointf[i];
+ cd[i] = cdf[i];
+ fSigma2P0[i] = 0.;
+ }
+ if(twopoints){
+ InitTwoPoints(point,cd);
+ }
+ else {
+ InitDirection(point,cd);
+ }
+}
+
+//________________________________________________________
+AliStrLine::AliStrLine(Double_t *point, Double_t *sig2point, Double_t *cd,Bool_t twopoints) :
+ TObject(),
+ fWMatrix(0),
+ fTpar(0)
+{
+ // Standard constructor
+ // if twopoints is true: point and cd are the 3D coordinates of
+ // two points defininig the straight line
+ // if twopoint is false: point represents the 3D coordinates of a point
+ // belonging to the straight line and cd is the
+ // direction in space
+ for(Int_t i=0;i<3;i++){
+ fSigma2P0[i] = sig2point[i];
+ }
+ if(twopoints){
+ InitTwoPoints(point,cd);
+ }
+ else {
+ InitDirection(point,cd);
+ }
+}
+
+//________________________________________________________
+AliStrLine::AliStrLine(Float_t *pointf, Float_t *sig2point, Float_t *cdf,Bool_t twopoints) :
+ TObject(),
+ fWMatrix(0),
+ fTpar(0)
+{
+ // Standard constructor - with float arguments
+ // if twopoints is true: point and cd are the 3D coordinates of
+ // two points defininig the straight line
+ // if twopoint is false: point represents the 3D coordinates of a point
+ // belonging to the straight line and cd is the
+ // direction in space
+ Double_t point[3];
+ Double_t cd[3];
+ for(Int_t i=0;i<3;i++){
+ point[i] = pointf[i];
+ cd[i] = cdf[i];
+ fSigma2P0[i] = sig2point[i];
+ }
+ if(twopoints){
+ InitTwoPoints(point,cd);
+ }
+ else {
+ InitDirection(point,cd);
+ }
+}
+//________________________________________________________
+AliStrLine::AliStrLine(Double_t *point, Double_t *sig2point, Double_t *wmat, Double_t *cd,Bool_t twopoints) :
+ TObject(),
+ fWMatrix(0),
+ fTpar(0)
+{
+ // Standard constructor
+ // if twopoints is true: point and cd are the 3D coordinates of
+ // two points defininig the straight line
+ // if twopoint is false: point represents the 3D coordinates of a point
+ // belonging to the straight line and cd is the
+ // direction in space
+ Int_t k = 0;
+ fWMatrix = new Double_t [6];
+ for(Int_t i=0;i<3;i++){
+ fSigma2P0[i] = sig2point[i];
+ for(Int_t j=0;j<3;j++)if(j>=i)fWMatrix[k++]=wmat[3*i+j];
+ }
+ if(twopoints){
+ InitTwoPoints(point,cd);
+ }
+ else {
+ InitDirection(point,cd);
+ }
+}
+
+//________________________________________________________
+AliStrLine::AliStrLine(Float_t *pointf, Float_t *sig2point, Float_t *wmat, Float_t *cdf,Bool_t twopoints) :
+ TObject(),
+ fWMatrix(0),
+ fTpar(0)
+{
+ // Standard constructor - with float arguments
+ // if twopoints is true: point and cd are the 3D coordinates of
+ // two points defininig the straight line
+ // if twopoint is false: point represents the 3D coordinates of a point
+ // belonging to the straight line and cd is the
+ // direction in space
+ Double_t point[3];
+ Double_t cd[3];
+ fWMatrix = new Double_t [6];
+ Int_t k = 0;
+ for(Int_t i=0;i<3;i++){
+ point[i] = pointf[i];
+ cd[i] = cdf[i];
+ fSigma2P0[i] = sig2point[i];
+ for(Int_t j=0;j<3;j++)if(j>=i)fWMatrix[k++]=wmat[3*i+j];
+ }
+ if(twopoints){
+ InitTwoPoints(point,cd);
+ }
+ else {
+ InitDirection(point,cd);
+ }
+}
+
+//________________________________________________________
+AliStrLine::AliStrLine(const AliStrLine &source):TObject(source),
+fWMatrix(0),
+fTpar(source.fTpar){
+ // copy constructor
+ if(source.fWMatrix)fWMatrix = new Double_t [6];
+ for(Int_t i=0;i<3;i++){
+ fP0[i]=source.fP0[i];
+ fSigma2P0[i]=source.fSigma2P0[i];
+ fCd[i]=source.fCd[i];
+ }
+ for(Int_t i=0;i<6;i++)fWMatrix[i]=source.fWMatrix[i];
+}
+
+//________________________________________________________
+AliStrLine& AliStrLine::operator=(const AliStrLine& source){
+ // Assignment operator
+ if(this !=&source){
+ this->~AliStrLine();
+ new(this)AliStrLine(source);
+ }
+ return *this;
+}
+
+//________________________________________________________
+void AliStrLine::GetWMatrix(Double_t *wmat)const {
+// Getter for weighting matrix, as a [9] dim. array
+ if(!fWMatrix)return;
+ Int_t k = 0;
+ for(Int_t i=0;i<3;i++){
+ for(Int_t j=0;j<3;j++){
+ if(j>=i){
+ wmat[3*i+j]=fWMatrix[k++];
+ }
+ else{
+ wmat[3*i+j]=wmat[3*j+i];
+ }
+ }
+ }
+}
+
+//________________________________________________________
+void AliStrLine::SetWMatrix(const Double_t *wmat) {
+// Setter for weighting matrix, strating from a [9] dim. array
+ if(fWMatrix)delete [] fWMatrix;
+ fWMatrix = new Double_t [6];
+ Int_t k = 0;
+ for(Int_t i=0;i<3;i++){
+ for(Int_t j=0;j<3;j++)if(j>=i)fWMatrix[k++]=wmat[3*i+j];
+ }
+}
//________________________________________________________
void AliStrLine::InitDirection(Double_t *point, Double_t *cd){
SetP0(point);
SetCd(cd);
fTpar = 0.;
- SetDebug();
}
//________________________________________________________
//________________________________________________________
AliStrLine::~AliStrLine() {
// destructor
+ if(fWMatrix)delete [] fWMatrix;
}
//________________________________________________________
cout <<"Known point: ";
for(Int_t i=0;i<3;i++)cout <<fP0[i]<<"; ";
cout <<endl;
+ cout <<"Error on known point: ";
+ for(Int_t i=0;i<3;i++)cout <<TMath::Sqrt(fSigma2P0[i])<<"; ";
+ cout <<endl;
cout <<"Current value for the parameter: "<<fTpar<<endl;
- cout <<" Debug flag: "<<fDebug<<endl;
}
//________________________________________________________
line->GetCd(cd2);
Int_t i;
Double_t k1 = 0;
- for(i=0;i<3;i++)k1+=(fP0[i]-p2[i])*fCd[i];
Double_t k2 = 0;
- for(i=0;i<3;i++)k2+=(fP0[i]-p2[i])*cd2[i];
Double_t a11 = 0;
- for(i=0;i<3;i++)a11+=fCd[i]*cd2[i];
+ for(i=0;i<3;i++){
+ k1+=(fP0[i]-p2[i])*fCd[i];
+ k2+=(fP0[i]-p2[i])*cd2[i];
+ a11+=fCd[i]*cd2[i];
+ }
Double_t a22 = -a11;
Double_t a21 = 0;
- for(i=0;i<3;i++)a21+=cd2[i]*cd2[i];
Double_t a12 = 0;
- for(i=0;i<3;i++)a12-=fCd[i]*fCd[i];
+ for(i=0;i<3;i++){
+ a21+=cd2[i]*cd2[i];
+ a12-=fCd[i]*fCd[i];
+ }
Double_t deno = a11*a22-a21*a12;
if(deno == 0.) return -1;
fTpar = (a11*k2-a21*k1) / deno;
}
//___________________________________________________________
-Double_t AliStrLine::GetDCA(AliStrLine *line){
+Double_t AliStrLine::GetDCA(AliStrLine *line) const{
//Returns the distance of closest approach between two lines
Double_t p2[3];
Double_t cd2[3];
// Fills the array point with the current value on the line
for(Int_t i=0;i<3;i++)point[i]=fP0[i]+fCd[i]*fTpar;
}
+
+//________________________________________________________
+Double_t AliStrLine::GetDistFromPoint(Double_t *point) const {
+ // computes distance from point
+ AliStrLine tmp(point,(Double_t *)fCd,kFALSE);
+ return this->GetDCA(&tmp);
+}