]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliStrLine.cxx
Call the MC QA only in case of debug
[u/mrichter/AliRoot.git] / STEER / AliStrLine.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, 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 // A straight line is coded as a point (3 Double_t) and           //
18 // 3 direction cosines                                           //
19 //                                                               //
20 ///////////////////////////////////////////////////////////////////
21 #include <Riostream.h>
22 #include <TTree.h>
23 #include "AliStrLine.h"
24
25 ClassImp(AliStrLine)
26
27 //________________________________________________________
28 AliStrLine::AliStrLine() :
29   TObject(),
30   fTpar(0),
31   fDebug(0)
32  {
33   // Default constructor
34   for(Int_t i=0;i<3;i++) {
35     fP0[i] = 0.;
36     fCd[i] = 0.;
37   }
38 }
39
40 //________________________________________________________
41 AliStrLine::AliStrLine(Double_t *point, Double_t *cd,Bool_t twopoints) :
42   TObject(),
43   fTpar(0),
44   fDebug(0)
45 {
46   // Standard constructor
47   // if twopoints is true:  point and cd are the 3D coordinates of
48   //                        two points defininig the straight line
49   // if twopoint is false: point represents the 3D coordinates of a point
50   //                       belonging to the straight line and cd is the
51   //                       direction in space
52   if(twopoints){
53     InitTwoPoints(point,cd);
54   }
55   else {
56     InitDirection(point,cd);
57   }
58 }
59
60
61 //________________________________________________________
62 void AliStrLine::InitDirection(Double_t *point, Double_t *cd){
63   // Initialization from a point and a direction
64   Double_t norm = 0.;
65   for(Int_t i=0;i<3;i++)norm+=cd[i]*cd[i];
66   if(norm) {
67     norm = TMath::Sqrt(norm);
68     for(Int_t i=0;i<3;i++) cd[i]/=norm;
69   }
70   else {
71     Error("AliStrLine","Null direction cosines!!!");
72   }
73   SetP0(point);
74   SetCd(cd);
75   fTpar = 0.;
76   SetDebug();
77 }
78
79 //________________________________________________________
80 void AliStrLine::InitTwoPoints(Double_t *pA, Double_t *pB){
81   // Initialization from the coordinates of two
82   // points in the space
83   Double_t cd[3];
84   for(Int_t i=0;i<3;i++)cd[i] = pB[i]-pA[i];
85   InitDirection(pA,cd);
86 }
87
88 //________________________________________________________
89 AliStrLine::~AliStrLine() {
90   // destructor
91 }
92
93 //________________________________________________________
94 void AliStrLine::PrintStatus() const {
95   // Print current status
96   cout <<"=======================================================\n";
97   cout <<"Direction cosines: ";
98   for(Int_t i=0;i<3;i++)cout <<fCd[i]<<"; ";
99   cout <<endl;
100   cout <<"Known point: ";
101   for(Int_t i=0;i<3;i++)cout <<fP0[i]<<"; ";
102   cout <<endl;
103   cout <<"Current value for the parameter: "<<fTpar<<endl;
104   cout <<" Debug flag: "<<fDebug<<endl;
105 }
106
107 //________________________________________________________
108 Int_t AliStrLine::IsParallelTo(AliStrLine *line) const {
109   // returns 1 if lines are parallel, 0 if not paralel
110   Double_t cd2[3];
111   line->GetCd(cd2);
112   Double_t vecpx=fCd[1]*cd2[2]-fCd[2]*cd2[1];
113   if(vecpx!=0) return 0;
114   Double_t vecpy=-fCd[0]*cd2[2]+fCd[2]*cd2[0];
115   if(vecpy!=0) return 0;
116   Double_t vecpz=fCd[0]*cd2[1]-fCd[1]*cd2[0];
117   if(vecpz!=0) return 0;
118   return 1;
119 }
120 //________________________________________________________
121 Int_t AliStrLine::Crossrphi(AliStrLine *line){
122   // Cross 2 lines in the X-Y plane
123   Double_t p2[3];
124   Double_t cd2[3];
125   line->GetP0(p2);
126   line->GetCd(cd2);
127   Double_t a=fCd[0];
128   Double_t b=-cd2[0];
129   Double_t c=p2[0]-fP0[0];
130   Double_t d=fCd[1];
131   Double_t e=-cd2[1];
132   Double_t f=p2[1]-fP0[1];
133   Double_t deno = a*e-b*d;
134   Int_t retcode = 0;
135   if(deno != 0.) {
136     fTpar = (c*e-b*f)/deno;
137   }
138   else {
139     retcode = -1;
140   }
141   return retcode;
142 }
143
144 //________________________________________________________
145 Int_t AliStrLine::CrossPoints(AliStrLine *line, Double_t *point1, Double_t *point2){
146   // Looks for the crossing point estimated starting from the
147   // DCA segment
148   Double_t p2[3];
149   Double_t cd2[3];
150   line->GetP0(p2);
151   line->GetCd(cd2);
152   Int_t i;
153   Double_t k1 = 0;
154   for(i=0;i<3;i++)k1+=(fP0[i]-p2[i])*fCd[i];
155   Double_t k2 = 0;
156   for(i=0;i<3;i++)k2+=(fP0[i]-p2[i])*cd2[i];
157   Double_t a11 = 0;
158   for(i=0;i<3;i++)a11+=fCd[i]*cd2[i];
159   Double_t a22 = -a11;
160   Double_t a21 = 0;
161   for(i=0;i<3;i++)a21+=cd2[i]*cd2[i];
162   Double_t a12 = 0;
163   for(i=0;i<3;i++)a12-=fCd[i]*fCd[i];
164   Double_t deno = a11*a22-a21*a12;
165   if(deno == 0.) return -1;
166   fTpar = (a11*k2-a21*k1) / deno;
167   Double_t par2 = (k1*a22-k2*a12) / deno;
168   line->SetPar(par2);
169   GetCurrentPoint(point1);
170   line->GetCurrentPoint(point2);
171   return 0;
172 }
173 //________________________________________________________________
174 Int_t AliStrLine::Cross(AliStrLine *line, Double_t *point){
175
176   //Finds intersection between lines
177   Double_t point1[3];
178   Double_t point2[3];
179   Int_t retcod=CrossPoints(line,point1,point2);
180   if(retcod==0){
181     for(Int_t i=0;i<3;i++)point[i]=(point1[i]+point2[i])/2.;
182     return 0;
183   }else{
184     return -1;
185   }
186 }
187
188 //___________________________________________________________
189 Double_t AliStrLine::GetDCA(AliStrLine *line){
190   //Returns the distance of closest approach between two lines
191   Double_t p2[3];
192   Double_t cd2[3];
193   line->GetP0(p2);
194   line->GetCd(cd2);
195   Int_t i;
196   Int_t ispar=IsParallelTo(line);
197   if(ispar){
198     Double_t dist1q=0,dist2=0,mod=0;
199     for(i=0;i<3;i++){
200       dist1q+=(fP0[i]-p2[i])*(fP0[i]-p2[i]);
201       dist2+=(fP0[i]-p2[i])*fCd[i];
202       mod+=fCd[i]*fCd[i];
203     }
204     if(mod!=0){
205       dist2/=mod;
206       return TMath::Sqrt(dist1q-dist2*dist2);
207     }else{return -1;}
208   }else{
209      Double_t perp[3];
210      perp[0]=fCd[1]*cd2[2]-fCd[2]*cd2[1];
211      perp[1]=-fCd[0]*cd2[2]+fCd[2]*cd2[0];
212      perp[2]=fCd[0]*cd2[1]-fCd[1]*cd2[0];
213      Double_t mod=0,dist=0;
214      for(i=0;i<3;i++){
215        mod+=perp[i]*perp[i];
216        dist+=(fP0[i]-p2[i])*perp[i];
217      }
218      mod=sqrt(mod);
219      if(mod!=0){
220        dist/=mod;
221        return TMath::Abs(dist);
222      }else{return -1;}
223   }
224 }
225 //________________________________________________________
226 void AliStrLine::GetCurrentPoint(Double_t *point) const {
227   // Fills the array point with the current value on the line
228   for(Int_t i=0;i<3;i++)point[i]=fP0[i]+fCd[i]*fTpar;
229 }