FairRoot/PandaRoot
PndPlane.cxx
Go to the documentation of this file.
1 /*
2  * PndPlane.cpp
3  *
4  * Created on: Jun 14, 2016
5  * Author: kibellus
6  */
7 
8 #include <PndPlane.h>
9 
10 
12  base = line.getP1();
13  dir1 = line.getP2()-line.getP1();
14  if(layer%4==1){
15  dir2 = TVector3(TMath::Sin(-5*TMath::DegToRad()),TMath::Cos(-5*TMath::DegToRad()),0);
16  }else if(layer%4==2){
17  dir2 = TVector3(TMath::Sin(5*TMath::DegToRad()),TMath::Cos(5*TMath::DegToRad()),0);
18  } else {
19  dir2 = TVector3(0,1,0);
20  }
21 }
22 
24  // TODO Auto-generated destructor stub
25 }
26 
27 
29  //create the direction vector
30  TVector3 norm1 = dir1.Cross(dir2);
31  Double_t d1 = norm1.Dot(base);
32  TVector3 norm2 = p.dir1.Cross(p.dir2);
33  Double_t d2 = norm2.Dot(p.base);
34  TVector3 dirLine = norm1.Cross(norm2);
35  //create the base vector
36 
37  //init array
38  Double_t arr[2][3];
39  arr[0][0]=norm1[0];
40  arr[0][1]=norm1[1];
41  arr[0][2]=d1-norm1[2]*base[2];
42  arr[1][0]=norm2[0];
43  arr[1][1]=norm2[1];
44  arr[1][2]=d2-norm2[2]*base[2];
45 
46  //swap rows
47  if(arr[0][0]==0){
48  for(int i=0;i<3;i++){
49  //Double_t temp = arr[0][i]; //[R.K.03/2017] unused variable
50  arr[0][i]=arr[1][i];
51  arr[1][i]=arr[0][i];
52  }
53  }
54 
55  Double_t fac = -arr[1][0]/arr[0][0];
56  for(int i=0;i<3;i++){
57  arr[1][i]+=fac*arr[0][i];
58  }
59 
60  Double_t x2 = arr[1][2]/arr[1][1];
61  Double_t x1 = (arr[0][2]-x2*arr[0][1])/arr[0][0];
62 
63  //create the line
64  TVector3 lineBase;
65  lineBase.SetXYZ(x1,x2,base[2]);
66  PndLine l(lineBase,dirLine);
67  return l;
68 }
69 
71  cout << "Plane:";
72  cout << "(" << base[0] << "," << base[1] << "," << base[2] << ")";
73  cout << "+a*(" << dir1[0] << "," << dir1[1] << "," << dir1[2] << ")";
74  cout << "+b*(" << dir2[0] << "," << dir2[1] << "," << dir2[2] << ")";
75 }
76 
77 
79  //create the Matrix
80  TVector3 lineDir = l.getDir();
81  TVector3 lineBase = l.getP1();
82  Double_t matrix[3][4];
83  for(int i=0;i<3;i++){
84  matrix[i][0]=dir1[i];
85  matrix[i][1]=dir2[i];
86  matrix[i][2]=-lineDir[i];
87  matrix[i][3]=lineBase[i]-base[i];
88  }
89  //solve the Matrix
90  for(int i=0;i<3;i++){
91  if(TMath::Abs(matrix[i][i])<0.000000001){//equal 0
92  //search max element
93  Int_t max = i;
94  for(int j=i+1;j<3;j++){
95  if(TMath::Abs(matrix[j][i])>TMath::Abs(matrix[max][i]))max=j;
96  }
97  //no greater element found
98  if(max==i){
99  cout << "\033[1;31mNo Intersection from plane and line\033[0m" << endl;
100  return TVector3(0,0,0);
101  }
102  //swap lines
103  for(int j=i;j<4;j++){
104  Double_t temp = matrix[i][j];
105  matrix[i][j] = matrix[max][j];
106  matrix[max][j] = temp;
107  }
108  }
109  for(int j=i+1;j<3;j++){
110  Double_t fac = -matrix[j][i]/matrix[i][i];
111  for(int k=i;k<4;k++){
112  matrix[j][k]+=(fac*matrix[i][k]);
113  }
114  }
115  }
116  //create the result
117  Double_t lamp = matrix[2][3]/matrix[2][2];
118  return lineBase+lamp*lineDir;
119 }
120 
PndLine getIntersection(PndPlane &p)
Definition: PndPlane.cxx:28
Double_t p
Definition: anasim.C:58
void Print()
Definition: PndPlane.cxx:70
Int_t i
Definition: run_full.C:25
TVector3 dir2
Definition: PndPlane.h:35
static T Sin(const T &x)
Definition: PndCAMath.h:42
TVector3 getP2()
Definition: PndLine.h:33
TVector3 getDir()
Definition: PndLine.h:34
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
static T Cos(const T &x)
Definition: PndCAMath.h:43
static T Abs(const T &x)
Definition: PndCAMath.h:39
virtual ~PndPlane()
Definition: PndPlane.cxx:23
PndPlane(TVector3 b, TVector3 d1, TVector3 d2)
Definition: PndPlane.h:23
Double_t
TVector3 dir1
Definition: PndPlane.h:34
Int_t layer
Definition: reco_muo.C:36
TVector3 getP1()
Definition: PndLine.h:32
TVector3 base
Definition: PndPlane.h:33