FairRoot/PandaRoot
PndSttTube.cxx
Go to the documentation of this file.
1 #include "PndSttTube.h"
2 
3 #include <iostream>
4 #include <math.h>
5 #include "TVector3.h"
6 
8  :fTubeParms(new PndSttTubeParameters()),
9  fCenPosition(TVector3(0,0,0)),
10  fRotationMatrix(TMatrixT<double>(3,3)),
11  fRadIn(-1),
12  fRadOut(-1),
13  fSectorID(-1),
14  fLayerID(-1),
15  fLayerLimit(kFALSE),
16  fSectorLimit(kFALSE)
17 {
18  fRotationMatrix[0][0] = -1.;
19  fRotationMatrix[0][1] = -1.;
20  fRotationMatrix[0][2] = -1.;
21 
22  fRotationMatrix[1][0] = -1.;
23  fRotationMatrix[1][1] = -1.;
24  fRotationMatrix[1][2] = -1.;
25 
26  fRotationMatrix[2][0] = -1.;
27  fRotationMatrix[2][1] = -1.;
28  fRotationMatrix[2][2] = -1.;
29 }
30 
32  :TObject(tube),
33  fTubeParms(tube.GetTubeParameters()),
34  fCenPosition(tube.GetPosition()),
35  fRotationMatrix(TMatrixT<double>(3,3)),
36  fRadIn(tube.GetRadIn()),
37  fRadOut(tube.GetRadOut()),
38  fSectorID(tube.GetSectorID()),
39  fLayerID(tube.GetLayerID()),
40  fLayerLimit(tube.IsLayerLimit()),
41  fSectorLimit(tube.IsSectorLimit())
42 {
43  fRotationMatrix.ResizeTo(3,3);
45 }
46 
49  Double_t r11, Double_t r12, Double_t r13,
50  Double_t r21, Double_t r22, Double_t r23,
51  Double_t r31, Double_t r32, Double_t r33,
52  Double_t radin, Double_t radout)
53  :fTubeParms(parms),
54  fCenPosition(TVector3(x,y,z)),
55  fRotationMatrix(TMatrixT<double>(3,3)),
56  fRadIn(radin),
57  fRadOut(radout),
58  fSectorID(-1),
59  fLayerID(-1),
60  fLayerLimit(kFALSE),
61  fSectorLimit(kFALSE)
62 {
63 
64  // fCenPosition.SetXYZ(x,y,z);
65 
66  fRotationMatrix.ResizeTo(3,3);
67  fRotationMatrix[0][0] = r11;
68  fRotationMatrix[0][1] = r12;
69  fRotationMatrix[0][2] = r13;
70 
71  fRotationMatrix[1][0] = r21;
72  fRotationMatrix[1][1] = r22;
73  fRotationMatrix[1][2] = r23;
74 
75  fRotationMatrix[2][0] = r31;
76  fRotationMatrix[2][1] = r32;
77  fRotationMatrix[2][2] = r33;
78 
79 }
80 
81 
83 // fCenPosition.Delete();
84 // fRotationMatrix.Delete();
85 }
86 
88  return fCenPosition; }
89 
90 TMatrixT<Double_t> PndSttTube::GetRotationMatrix() {
91  return fRotationMatrix; }
92 
94  return fRadIn; }
95 
97  return fRadOut; }
98 
100  return fTubeParms->GetHalfLength();
101 }
102 
104  return fTubeParms->GetTubeID();
105 }
106 
108  return TVector3(fRotationMatrix[0][2],
109  fRotationMatrix[1][2],
110  fRotationMatrix[2][2]);
111 }
112 
114  return fTubeParms;
115 }
116 
118  fSectorID = id;
119 }
121  fLayerID = id;
122 }
123 
125  return fSectorID;
126 }
127 
129  return fLayerID;
130 }
131 
132 
133 void PndSttTube::SetNeighborings(TArrayI neighborings) {
134  fNeighborings = neighborings;
135 }
136 
138  return fNeighborings;
139 }
140 
142  return fNeighborings.At(i);
143 }
144 
146  for(int itube = 0; itube < fNeighborings.GetSize(); itube++) {
147  if(GetNeighboring(itube) == tubeID) return kTRUE;
148  }
149  return kFALSE;
150 }
151 
152 // CHECK this can be written in a better way
154 
155 
156  TVector3 extr1 = fCenPosition - GetHalfLength() * TVector3(fRotationMatrix[0][2], fRotationMatrix[1][2], fRotationMatrix[2][2]);
157  TVector3 extr2 = fCenPosition + GetHalfLength() * TVector3(fRotationMatrix[0][2], fRotationMatrix[1][2], fRotationMatrix[2][2]);
158  TVector3 tubeextr1 = tube->GetPosition() - tube->GetHalfLength() * tube->GetWireDirection();
159  TVector3 tubeextr2 = tube->GetPosition() + tube->GetHalfLength() * tube->GetWireDirection();
160 
161  double distance = -1;
162  if(TVector3(fRotationMatrix[0][2], fRotationMatrix[1][2], fRotationMatrix[2][2]).Cross(tube->GetWireDirection()).Mag() == 0) {
163  distance = ((fCenPosition - tubeextr1).Cross(fCenPosition - tubeextr2)).Mag()/(tubeextr2 - tubeextr1).Mag();
164  return distance;
165  }
166  else {
167  distance = fabs((tubeextr1 - extr1).Dot((extr2 - extr1).Cross(tubeextr2 - tubeextr1)))/((extr2 - extr1).Cross(tubeextr2 - tubeextr1)).Mag();
168 
169  double s = (( (extr2 - extr1).Dot(tubeextr2 - tubeextr1)) * ( (tubeextr2 - tubeextr1).Dot(extr1 - tubeextr1)) - ( (tubeextr2 - tubeextr1).Dot(tubeextr2 - tubeextr1)) * ( (extr2 - extr1).Dot(extr1 - tubeextr1))) / (((extr2 - extr1).Dot(extr2 - extr1)) * ((tubeextr2 - tubeextr1).Dot(tubeextr2 - tubeextr1)) - ( (extr2 - extr1).Dot(tubeextr2 - tubeextr1)) *( (extr2 - extr1).Dot(tubeextr2 - tubeextr1)) );
170  double t = (( (extr2 - extr1).Dot(extr2 - extr1)) * ( (tubeextr2 - tubeextr1).Dot(extr1 - tubeextr1)) - ( (extr2 - extr1).Dot(tubeextr2 - tubeextr1)) * ( (extr2 - extr1).Dot(extr1 - tubeextr1)) )/ (((extr2 - extr1).Dot(extr2 - extr1)) * ((tubeextr2 - tubeextr1).Dot(tubeextr2 - tubeextr1)) - ( (extr2 - extr1).Dot(tubeextr2 - tubeextr1)) *( (extr2 - extr1).Dot(tubeextr2 - tubeextr1)) );
171 
172  TVector3 point1 = extr1 + s * (extr2 - extr1);
173  TVector3 point2 = tubeextr1 + t * (tubeextr2 - tubeextr1);
174 
175  // std::cout << "GET DISTANCE " << distance << " " << (point1 - point2).Mag() << std::endl;
176  // point1.Print();
177  // point2.Print();
178 
179  if(point1.Z() < extr1.Z() || point1.Z() > extr2.Z()|| point2.Z() < tubeextr1.Z() || point2.Z() > tubeextr2.Z()) {
180  // std::cout << "point outside limits" << std::endl;
181  distance = (extr1 - tubeextr1).Mag() < (extr2 - tubeextr2).Mag() ? (extr1 - tubeextr1).Mag() : (extr2 - tubeextr2).Mag();
182 
183  }
184  // std::cout << "DISTANCE " << distance << std::endl;
185  return distance;
186  }
187 
188 }
189 
190 
191 
192 
194 
void SetSectorID(int id)
Definition: PndSttTube.cxx:117
Int_t i
Definition: run_full.C:25
TArrayI fNeighborings
Definition: PndSttTube.h:80
Double_t GetHalfLength()
Definition: PndSttTube.cxx:99
TLorentzVector s
Definition: Pnd2DStar.C:50
TVector3 fCenPosition
Definition: PndSttTube.h:76
Int_t fLayerID
Definition: PndSttTube.h:79
Double_t GetDistance(PndSttTube *tube)
Definition: PndSttTube.cxx:153
void SetNeighborings(TArrayI neighborings)
Definition: PndSttTube.cxx:133
Double_t GetRadIn()
Definition: PndSttTube.cxx:93
int GetLayerID()
Definition: PndSttTube.cxx:128
PndSttTubeParameters * GetTubeParameters()
Definition: PndSttTube.cxx:113
Bool_t IsNeighboring(int tubeID)
Definition: PndSttTube.cxx:145
Int_t GetTubeID()
Definition: PndSttTube.cxx:103
Double_t
Double_t fRadIn
Definition: PndSttTube.h:78
TArrayI GetNeighborings()
Definition: PndSttTube.cxx:137
TVector3 GetPosition()
Definition: PndSttTube.cxx:87
Double_t z
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
Double_t fRadOut
Definition: PndSttTube.h:78
TMatrixT< double > fRotationMatrix
Definition: PndSttTube.h:77
Double_t x
ClassImp(PndAnaContFact)
TTree * t
Definition: bump_analys.C:13
PndSttTubeParameters * fTubeParms
Definition: PndSttTube.h:75
Double_t y
Int_t fSectorID
Definition: PndSttTube.h:79
Int_t GetNeighboring(int i)
Definition: PndSttTube.cxx:141
cout<<"the mcX, mcY, mcZ are "<< mcX<<","<< mcY<<","<< mcZ<< endl;vecmc.SetXYZ(mcX, mcY, mcZ);vecrc=hit-> GetPosition()
int GetSectorID()
Definition: PndSttTube.cxx:124
Double_t GetRadOut()
Definition: PndSttTube.cxx:96
TMatrixT< Double_t > GetRotationMatrix()
Definition: PndSttTube.cxx:90
TVector3 GetWireDirection()
Definition: PndSttTube.cxx:107
void SetLayerID(int id)
Definition: PndSttTube.cxx:120