FairRoot/PandaRoot
PndTrackCombiner.cxx
Go to the documentation of this file.
1 /*
2  * PndTrackCombiner.cxx
3  *
4  * Created on: Jun 7, 2016
5  * Author: kibellus
6  */
7 
8 #include <PndTrackCombiner.h>
9 
13 
15  // TODO Auto-generated destructor stubPndTrack*
16 }
17 
18 vector<PndLineApproximation> PndTrackCombiner::combine(Int_t bigLayer){
19  Int_t l1 = 4*bigLayer+0;
20  Int_t l2 = 4*bigLayer+1;
21  Int_t l3 = 4*bigLayer+2;
22  Int_t l4 = 4*bigLayer+3;
23 
24  vector<PndFtsExpandedTrackCand> layer1a4 = compareAndRefit(l1,l4);
25  vector<PndLineApproximation> arr[3];
26  arr[0] = combine(layer1a4,fExpandedTrackCands[l2],0,1);
27  arr[1] = combine(layer1a4,fExpandedTrackCands[l3],0,2);
28  arr[2] = combine(fExpandedTrackCands[l2],fExpandedTrackCands[l3],1,2);
29 
30 // cout << "firstAndLast=" << layer1a4.size() << endl;
31 // cout << "arr[0]=" << arr[0].size() << endl;
32 // cout << "arr[1]=" << arr[1].size() << endl;
33 // cout << "arr[2]=" << arr[2].size() << endl;
34 
35  //new implementation
36  vector<PndLineCombination> combindedLines;
37  //add the tracks of the first layer
38  for(size_t i=0;i<arr[0].size();i++){
39  PndLineApproximation newApprox(arr[0][i]);
40  combindedLines.push_back(newApprox);
41  }
42 
43  //firstRun = combindedLines.size();
44  for(int i=1;i<3;i++){
45  vector<PndLineApproximation> lines = arr[i];
46  fComparator.setZValue(ftsPos[bigLayer]+5*i);
47  Int_t maxVal = combindedLines.size(); //tracks in layers before -> no combination in same layer
48  for(size_t j=0;j<lines.size();j++){
49  addLine(combindedLines,lines[j],maxVal);
50  }
51  refitLines(combindedLines);
52  }
53  //get all lines with a high quality
54  vector<PndLineApproximation> result;
55  for(size_t i=0;i<combindedLines.size();i++){
56  PndLineCombination combi = combindedLines[i];
57  PndLineApproximation approx = combi.getApprox1();
58  if(approx.getLine().getRating()>2){
59  result.push_back(approx);
60  }
61  }
62  //combine similar tracks
63  vector<PndLineApproximation> result2;
64  fComparator.setZValue(ftsPos[bigLayer]);
65  Bool_t used[result.size()];
66  for(size_t i=0;i<result.size();i++)used[i]=kFALSE;
67  for(size_t i=0;i<result.size();i++){
68  if(used[i])continue;
69  PndLineApproximation a = result[i];
70  for(size_t j=i+1;j<result.size();j++){
71  if(used[j])continue;
72  PndLineApproximation b = result[j];
74  a=a.newApproximation(b);
75  used[j]=kTRUE;
76  }
77  }
78  used[i]=kTRUE;
79  result2.push_back(a);
80  }
81  return result2;
82 }
83 
84 vector<PndLineApproximation> PndTrackCombiner::combine
85  (vector<PndFtsExpandedTrackCand> cands1, vector<PndFtsExpandedTrackCand> cands2, Int_t layer1, Int_t layer2){
86  vector<PndLineApproximation> result;
87  for(size_t i=0;i<cands1.size();i++){
88  size_t resultSizeBefore = result.size();
89  PndFtsExpandedTrackCand cand1 = cands1[i];
90  for(size_t j=0;j<cands2.size();j++){
91  PndFtsExpandedTrackCand cand2 = cands2[j];
92  vector<PndLineApproximation> lines = combine(cand1,cand2,layer1,layer2);
93  result.insert(result.begin(),lines.begin(),lines.end());
94  }
95  //layer1 track not used?
96  if(layer1==0 && result.size()==resultSizeBefore){
98  la.getLine().setRating(3);
99  la.setYInfo(kFALSE);
100  result.push_back(la);
101  }
102  }
103  return result;
104 }
105 
106 vector<PndLineApproximation> PndTrackCombiner::combine(PndFtsExpandedTrackCand c1, PndFtsExpandedTrackCand c2, Int_t layer1, Int_t layer2){
107  vector<PndLineApproximation> approx1 = c1.getLineApproximations();
108  vector<PndLineApproximation> approx2 = c2.getLineApproximations();
109  vector<PndLineApproximation> result;
110  for(size_t i=0;i<approx1.size();i++){
111  for(size_t j=0;j<approx2.size();j++){
112  PndLine line1 = approx1[i].getLine();
113  PndLine line2 = approx2[j].getLine();
114  PndPlane p1(line1,layer1);
115  PndPlane p2(line2,layer2);
116  PndLine l = p1.getIntersection(p2);
117 
118  Double_t angle = l.getZAngle();
119  if(TMath::Min(angle,180-angle)>angleLimit){
120  vector<PndFtsHit*> cHits1 = approx1[i].getHits();
121  vector<PndFtsHit*> cHits2 = approx2[j].getHits();
122  l.setRating(TMath::Max(line1.getRating(),line2.getRating()));
123  PndLineApproximation newApprox(l,cHits1,cHits2);
124  result.push_back(newApprox);
125  }
126  }
127  }
128  return result;
129 }
130 
131 void PndTrackCombiner::addLine(vector<PndLineCombination> &lines, PndLineApproximation& la, Int_t max){
132  PndLine &l = la.getLine();
133  Bool_t inUse = kFALSE;
134  for(int i=0;i<max;i++){
135  PndLine& l2=lines[i].getApprox1().getLine();
136  //compare with the line of other layer
137  Double_t quality = fComparator.getQuality(l,l2);
138  if(quality>compQuali)continue;
139  //is this line better as the current best line
140  if(lines[i].getQuality()>quality){
141  //better line found
142  lines[i].setApprox2(&la);
143  lines[i].setQuality(quality);
144  }
145  inUse = kTRUE;
146  }
147  if(!inUse){
148  PndLineCombination newCom(la);
149  lines.push_back(newCom);
150  }
151 }
152 
153 void PndTrackCombiner::refitLines(vector<PndLineCombination> &lines){
154  for(size_t i=0;i<lines.size();i++){
155  PndLineApproximation *a2 = lines[i].getApprox2();
156  if(a2!=0){
157  PndLineApproximation a1 = lines[i].getApprox1();
158  PndLineApproximation newApprox = a1.newApproximation(*a2);
159  lines[i].setApprox1(newApprox);
160  lines[i].setApprox2(0);
161  }
162  }
163 }
164 
165 void PndTrackCombiner::addLineOld(vector<PndLineApproximation> &lines, PndLineApproximation &la,Int_t end){
166  PndLine &l = la.getLine();
167  for(int i=0;i<end;i++){
168  PndLine &l2 = lines[i].getLine();
169  if(fComparator.areEqual2D(l,l2)){
170  l.incrementRating();
171  l2.incrementRating();
172  }
173  }
174  lines.push_back(la);
175 }
176 
177 vector<PndFtsExpandedTrackCand> PndTrackCombiner::compareAndRefit(Int_t layer1, Int_t layer2){
178  vector<PndFtsExpandedTrackCand> cands1 = fExpandedTrackCands[layer1];
179  vector<PndFtsExpandedTrackCand> cands2 = fExpandedTrackCands[layer2];
180  vector<PndFtsExpandedTrackCand> result;
181  Bool_t used2[cands2.size()]; //second cand is used
182  for(size_t j=0;j<cands2.size();j++)used2[j]=kFALSE;
183 
184  for(size_t i=0;i<cands1.size();i++){
185  Bool_t used = kFALSE;
186  for(size_t j=0;j<cands2.size();j++){
187  PndFtsExpandedTrackCand cand1 = cands1[i];
188  PndFtsExpandedTrackCand cand2 = cands2[j];
189  vector<PndLineApproximation> a1 = cand1.getLineApproximations();
190  vector<PndLineApproximation> a2 = cand2.getLineApproximations();
191  vector<PndLineApproximation> lines = compareAndRefit(a1,a2);
192  if(lines.size()==0)continue;
193  used = kTRUE;
194  used2[j]=kTRUE;
195  PndFtsExpandedTrackCand etc(cand1.getSourceHits(),cand2.getSourceHits(),lines);
196  result.push_back(etc);
197  }
198  if(!used)result.push_back(cands1[i]);
199  }
200  for(size_t j=0;j<cands2.size();j++){
201  if(!used2[j])result.push_back(cands2[j]);
202  }
203  return result;
204 }
205 
206 vector<PndLineApproximation> PndTrackCombiner::compareAndRefit
207  (vector<PndLineApproximation> l1, vector<PndLineApproximation> l2){
208  vector<PndLineApproximation> result;
209  for(size_t i=0;i<l1.size();i++){
210  PndLineApproximation approx1 = l1[i];
211  PndLine line1 = approx1.getLine();
212  fComparator.setZValue(line1.getP1()[2]);
213  for(size_t j=0;j<l2.size();j++){
214  PndLineApproximation approx2 = l2[j];
215  PndLine line2 = approx2.getLine();
216  if(fComparator.areEqual2D(line1,line2)){
217  PndLineApproximation newApprox = approx1.newApproximation(approx2);
218  result.push_back(newApprox);
219  return result;
220  }
221  }
222  }
223  return result;
224 }
225 
PndLine getIntersection(PndPlane &p)
Definition: PndPlane.cxx:28
Double_t ftsPos[6]
Double_t getZAngle()
Definition: PndLine.h:39
void addLineOld(vector< PndLineApproximation > &lines, PndLineApproximation &l, Int_t end)
Int_t i
Definition: run_full.C:25
TTree * b
vector< PndFtsHit * > getSourceHits()
PndLineApproximation newApproximation(PndLineApproximation &approx2)
void addLine(vector< PndLineCombination > &lines, PndLineApproximation &l, Int_t max)
vector< PndFtsExpandedTrackCand > compareAndRefit(Int_t layer1, Int_t layer2)
void refitLines(vector< PndLineCombination > &lines)
c2
Definition: plot_dirc.C:39
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
int combine(CandList &l1, CandList &l2, CandList &out, int matchPdg=0)
static Double_t compDist
static Double_t compAngle
void setZValue(Double_t z)
Double_t getQuality(PndLine l1, PndLine l2)
void incrementRating()
Definition: PndLine.h:43
Int_t a
Definition: anaLmdDigi.C:126
static T Min(const T &x, const T &y)
Definition: PndCAMath.h:35
virtual ~PndTrackCombiner()
Double_t
void setRating(Int_t r)
Definition: PndLine.h:44
PndLineApproximation getApprox1()
vector< PndLineApproximation > getLineApproximations()
TGeoCombiTrans * combi
Int_t getRating()
Definition: PndLine.h:42
c1
Definition: plot_dirc.C:35
TPad * p2
Definition: hist-t7.C:117
static T Max(const T &x, const T &y)
Definition: PndCAMath.h:36
vector< PndLineApproximation > combine(Int_t bigLayer)
Bool_t areEqual2D(PndLine l1, PndLine l2)
TPad * p1
Definition: hist-t7.C:116
static Double_t compQuali
Double_t angle
TVector3 getP1()
Definition: PndLine.h:32
map< Int_t, vector< PndFtsExpandedTrackCand > > fExpandedTrackCands
PndFtsLineComparator fComparator