FairRoot/PandaRoot
PndLineApproximation.cxx
Go to the documentation of this file.
1 /*
2  * PndLineApproximation.cxx
3  *
4  * Created on: Jun 6, 2016
5  * Author: kibellus
6  */
7 
8 #include <PndLineApproximation.h>
9 
10 
12  // TODO Auto-generated destructor stub
13 }
14 
15 PndLineApproximation::PndLineApproximation(PndLine lineApprox, vector<PndFtsHit*> ch1, vector<PndFtsHit*> ch2){
16  fLineApprox = lineApprox;
19 }
20 
21 void PndLineApproximation::correctHits3DAndAdd(vector<PndFtsHit*> ch){
22  for (size_t i = 0; i < ch.size(); i++) {
23  //check to duplicate hits
24  Bool_t duplicated = kFALSE;
25  for(size_t j=0;j<fCorrectedHits.size();j++){
26  Int_t id1 = fCorrectedHits[j]->GetTubeID();
27  Int_t id2 = ch[i]->GetTubeID();
28  if(id1==id2){
29  duplicated = kTRUE;
30  break;
31  }
32  }
33  if(duplicated) continue;
34  Int_t layer = (ch[i]->GetLayerID() - 1) / 2;
35  TVector3 base2;
36  ch[i]->Position(base2);
37  TVector3 dir2;
38  if (layer % 4 == 1) {
39  dir2 = TVector3(TMath::Sin(-5 * TMath::DegToRad()),
40  TMath::Cos(-5 * TMath::DegToRad()), 0);
41  } else if (layer % 4 == 2) {
42  dir2 = TVector3(TMath::Sin(5 * TMath::DegToRad()),
43  TMath::Cos(5 * TMath::DegToRad()), 0);
44  } else {
45  dir2 = TVector3(0, 1, 0);
46  }
47  PndLine line2(base2, dir2);
48  TVector3 newPos = line2.getPerpendicular(fLineApprox);
49  PndFtsHit* newHit = copyHitWithNewPosition(ch[i], newPos);
50  fCorrectedHits.push_back(newHit);
51  }
52 }
53 
55  vector<PndFtsHit*> hits;
56  for(size_t i=0;i<fCorrectedHits.size();i++)
57  hits.push_back(fCorrectedHits[i]);
58  for(size_t i=0;i<approx2.fCorrectedHits.size();i++){
59  hits.push_back(approx2.fCorrectedHits[i]);
60  }
61  PndLine newLine = linearRegression(hits);
63  vector<PndFtsHit*> hits2;
64  PndLineApproximation newApprox(newLine,hits2);
65  newApprox.correctHits3DAndAdd(hits);
66  return newApprox;
67 }
68 
70  PndLine zxLine = linearRegressionZX(hits);
71  PndLine zyLine = linearRegressionZY(hits);
72  PndPlane p1(zxLine.getP1(),zxLine.getDir(),TVector3(0,1,0));
73  PndPlane p2(zyLine.getP1(),zyLine.getDir(),TVector3(1,0,0));
74  PndLine newLine = p1.getIntersection(p2);
75  return newLine;
76 }
77 
79  Double_t sumX = 0;
80  Double_t sumX2 = 0;
81  Double_t sumZ = 0;
82  Double_t sumXZ = 0;
83  for(size_t i=0;i<hits.size();i++){
84  cout.precision(10);
85  sumX+=hits[i]->GetX();
86  sumX2+=hits[i]->GetX()*hits[i]->GetX();
87  sumZ+=hits[i]->GetZ();
88  sumXZ+=hits[i]->GetX()*hits[i]->GetZ();
89  }
90  Double_t matrix[2][3];
91  matrix[0][0]=hits.size();
92  matrix[1][0]=sumX;
93  matrix[0][1]=sumX;
94  matrix[1][1]=sumX2;
95  matrix[0][2]=sumZ;
96  matrix[1][2]=sumXZ;
97  TVector2 result = linearRegression(matrix);
98  TVector3 p1(20,0,result.X()+20*result.Y());
99  TVector3 p2(40,0,result.X()+40*result.Y());
100  //TVector3 p1(hits[0]->GetX(),0,result.X()+hits[0]->GetX()*result.Y());
101  //TVector3 p2(hits[0]->GetX()+20,0,result.X()+(hits[0]->GetX())+20*result.Y());
102  TVector3 dir = p1-p2;
103  return PndLine(p1,dir);
104 }
105 
107  Double_t sumZ = 0;
108  Double_t sumZ2 = 0;
109  Double_t sumX = 0;
110  Double_t sumZX = 0;
111  for(size_t i=0;i<hits.size();i++){
112  sumZ+=hits[i]->GetZ();
113  sumZ2+=hits[i]->GetZ()*hits[i]->GetZ();
114  sumX+=hits[i]->GetX();
115  sumZX+=hits[i]->GetZ()*hits[i]->GetX();
116  }
117  Double_t matrix[2][3];
118  matrix[0][0]=hits.size();
119  matrix[1][0]=sumZ;
120  matrix[0][1]=sumZ;
121  matrix[1][1]=sumZ2;
122  matrix[0][2]=sumX;
123  matrix[1][2]=sumZX;
124  TVector2 result = linearRegression(matrix);
125  TVector3 p1(result.X()+hits[0]->GetZ()*result.Y(),0,hits[0]->GetZ());
126  TVector3 p2(result.X()+(hits[0]->GetZ()+50)*result.Y(),0,hits[0]->GetZ()+50);
127  TVector3 dir = p1-p2;
128  return PndLine(p1,dir);
129 }
130 
132  Double_t sumY = 0;
133  Double_t sumY2 = 0;
134  Double_t sumZ = 0;
135  Double_t sumYZ = 0;
136  for(size_t i=0;i<hits.size();i++){
137  sumY+=hits[i]->GetY();
138  sumY2+=hits[i]->GetY()*hits[i]->GetY();
139  sumZ+=hits[i]->GetZ();
140  sumYZ+=hits[i]->GetY()*hits[i]->GetZ();
141  }
142  Double_t matrix[2][3];
143  matrix[0][0]=hits.size();
144  matrix[1][0]=sumY;
145  matrix[0][1]=sumY;
146  matrix[1][1]=sumY2;
147  matrix[0][2]=sumZ;
148  matrix[1][2]=sumYZ;
149  TVector2 result = linearRegression(matrix);
150  TVector3 p1(0,-20,result.X()-20*result.Y());
151  TVector3 p2(0,20,result.X()+20*result.Y());
152  TVector3 dir = p1-p2;
153  return PndLine(p1,dir);
154 }
155 
157  Double_t sumZ = 0;
158  Double_t sumZ2 = 0;
159  Double_t sumY = 0;
160  Double_t sumZY = 0;
161  for(size_t i=0;i<hits.size();i++){
162  sumZ+=hits[i]->GetZ();
163  sumZ2+=hits[i]->GetZ()*hits[i]->GetZ();
164  sumY+=hits[i]->GetY();
165  sumZY+=hits[i]->GetZ()*hits[i]->GetY();
166  }
167  Double_t matrix[2][3];
168  matrix[0][0]=hits.size();
169  matrix[1][0]=sumZ;
170  matrix[0][1]=sumZ;
171  matrix[1][1]=sumZ2;
172  matrix[0][2]=sumY;
173  matrix[1][2]=sumZY;
174  TVector2 result = linearRegression(matrix);
175  TVector3 p1(0,result.X()+hits[0]->GetZ()*result.Y(),hits[0]->GetZ());
176  TVector3 p2(0,result.X()+(hits[0]->GetZ()+300)*result.Y(),hits[0]->GetZ()+300);
177  TVector3 dir = p1-p2;
178  return PndLine(p1,dir);
179 }
180 
181 
183  Double_t fac = -matrix[1][0]/matrix[0][0];
184  for(int i=0;i<3;i++){
185  matrix[1][i]+= (fac*matrix[0][i]);
186  }
187  Double_t b = matrix[1][2]/matrix[1][1];
188  Double_t a = (matrix[0][2] - b*matrix[0][1])/matrix[0][0];
189  return TVector2(a,b);
190 }
191 
193  PndFtsHit* h2 = new PndFtsHit();
194  h2->SetDetectorID(h->GetDetectorID());
195  h2->SetTubeID(h->GetTubeID());
196  h2->SetChamberID(h->GetChamberID());
197  h2->SetLayerID(h->GetLayerID());
198  h2->SetXYZ(pos[0],pos[1],pos[2]);
199  h2->SetRefIndex(h->GetRefIndex());
200  h2->SetEntryNr(h->GetEntryNr());
201  return h2;
202 }
203 
204 PndTrack PndLineApproximation::plot(Double_t zVal1, Double_t zVal2, TClonesArray *hitArr){
205  FairTrackParP tp1 = fLineApprox.plot(zVal1,zVal2);
206  TVector3 v(1, 1, 1);
207  FairTrackParP tp2(v, 0 * v, v, v, 1, v, v, v);
208  PndTrackCand cand;
209  Int_t j = hitArr->GetEntries();
210  for(size_t i=0;i<fCorrectedHits.size();i++){
211  fCorrectedHits[i]->SetEntryNr(FairLink(-1, FairRootManager::Instance()->GetEntryNr(),FairRootManager::Instance()->GetBranchId("CorrectedHits"), j));
212  new ((*hitArr)[j++]) PndFtsHit(*fCorrectedHits[i]);//PndFtsHit* myHit = //[R.K.03/2017] unused variable
213  cand.AddHit(fCorrectedHits[i]->GetEntryNr(),i);
214  }
215  PndTrack t(tp1,tp2,cand);
216  return t;
217 }
TVector3 pos
TVector3 getPerpendicular(PndLine l2)
Definition: PndLine.cxx:76
PndLine linearRegression(vector< PndFtsHit * > hits)
PndLine linearRegressionZY(vector< PndFtsHit * > hits)
Int_t i
Definition: run_full.C:25
TTree * b
PndLineApproximation newApproximation(PndLineApproximation &approx2)
PndLine linearRegressionYZ(vector< PndFtsHit * > hits)
void SetChamberID(Int_t chamberid)
Definition: PndFtsHit.h:71
vector< PndFtsHit * > fCorrectedHits
static T Sin(const T &x)
Definition: PndCAMath.h:42
void SetTubeID(Int_t tubeid)
Definition: PndFtsHit.h:69
TVector3 getDir()
Definition: PndLine.h:34
static T Cos(const T &x)
Definition: PndCAMath.h:43
__m128 v
Definition: P4_F32vec4.h:4
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
Int_t GetLayerID() const
Definition: PndFtsHit.h:74
Int_t a
Definition: anaLmdDigi.C:126
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
Double_t
void setRating(Int_t r)
Definition: PndLine.h:44
PndTrack plot(Double_t zVal1, Double_t zVal2, TClonesArray *hitArr)
PndFtsHit * copyHitWithNewPosition(PndFtsHit *h, TVector3 pos)
Int_t getRating()
Definition: PndLine.h:42
TPad * p2
Definition: hist-t7.C:117
void correctHits3DAndAdd(vector< PndFtsHit * > correctedHits)
TPad * p1
Definition: hist-t7.C:116
void SetLayerID(Int_t layerid)
Definition: PndFtsHit.h:73
TTree * t
Definition: bump_analys.C:13
PndLine linearRegressionXZ(vector< PndFtsHit * > hits)
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
PndLine linearRegressionZX(vector< PndFtsHit * > hits)
TVector3 getP1()
Definition: PndLine.h:32
FairTrackParP plot(Double_t zVal1, Double_t zVal2)
Definition: PndLine.cxx:49
Int_t GetChamberID() const
Definition: PndFtsHit.h:72