68 {
69
70
71
72
73
75
76 for(int iline=0;iline<8;iline++){
77 linefit[iline]._pointCol.push_back( *(_recStereoHit[0]) );
78 linefit[iline]._pointCol.push_back( *(_recStereoHit[1]) );
79 linefit[iline]._pointCol.push_back( *(_recStereoHit[2]) );
80 }
82 for(int i =0;i<3;i++){
83 cout<<" the first 3 hits ("<<i<<" "<< _recStereoHit[i]->getLayerId()<<","<<_recStereoHit[i]->getWireId()<<")"<<endl;
84 cout<<" left "<<(_recStereoHit[i])->getsAmb(0)<<" "<<(_recStereoHit[i])->getzAmb(0)<<endl;
85 cout<<" right "<<(_recStereoHit[i])->getsAmb(1)<<" "<<(_recStereoHit[i])->getzAmb(1)<<endl;
86 }
87 }
88
89 linefit[0]._pointCol[0].setAmb(0);
90 linefit[0]._pointCol[1].setAmb(0);
91 linefit[0]._pointCol[2].setAmb(0);
92
93 linefit[1]._pointCol[0].setAmb(0);
94 linefit[1]._pointCol[1].setAmb(0);
95 linefit[1]._pointCol[2].setAmb(1);
96
97 linefit[2]._pointCol[0].setAmb(0);
98 linefit[2]._pointCol[1].setAmb(1);
99 linefit[2]._pointCol[2].setAmb(0);
100
101 linefit[3]._pointCol[0].setAmb(0);
102 linefit[3]._pointCol[1].setAmb(1);
103 linefit[3]._pointCol[2].setAmb(1);
104
105
106 linefit[4]._pointCol[0].setAmb(1);
107 linefit[4]._pointCol[1].setAmb(0);
108 linefit[4]._pointCol[2].setAmb(0);
109
110 linefit[5]._pointCol[0].setAmb(1);
111 linefit[5]._pointCol[1].setAmb(0);
112 linefit[5]._pointCol[2].setAmb(1);
113
114 linefit[6]._pointCol[0].setAmb(1);
115 linefit[6]._pointCol[1].setAmb(1);
116 linefit[6]._pointCol[2].setAmb(0);
117
118 linefit[7]._pointCol[0].setAmb(1);
119 linefit[7]._pointCol[1].setAmb(1);
120 linefit[7]._pointCol[2].setAmb(1);
121
122 for(int i=0;i<8;i++){
123 linefit[i]._ambig.push_back( linefit[i]._pointCol[0].getAmbig() );
124 linefit[i]._ambig.push_back( linefit[i]._pointCol[1].getAmbig() );
125 linefit[i]._ambig.push_back( linefit[i]._pointCol[2].getAmbig() );
126 if(
m_debug>0) cout<<
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^begin line "<<i<<endl;
128
129 int line_size=3;
130 for(int j=3;j<_hitSize;j++){
131 double chi_last=linefit[i]._chi;
132 double k_last=linefit[i]._k;
133 double b_last=linefit[i]._b;
134 if(
m_debug>0) cout<<
"last "<<j<<
" chi k b "<<chi_last<<
" "<<k_last<<
" "<<b_last<<endl;
135 linefit[i]._pointCol.push_back( *(_recStereoHit[j]) );
136
137
138
139 linefit[i]._pointCol[line_size].setAmb(0);
140 if(
m_debug>0) cout<<
"Add point left "<<
"("<<linefit[i]._pointCol[line_size].getLayerId()<<
","<<linefit[i]._pointCol[line_size].getWireId()<<
") "<<linefit[i]._pointCol[line_size].getStyle()<<
" "<<linefit[i]._pointCol[line_size].getsPos()<<
" "<<linefit[i]._pointCol[line_size].getzPos()<<endl;
142 double chil=linefit[i]._chi;
143 double kl=linefit[i]._k;
144 double bl=linefit[i]._b;
145 if (linefit[i]._pointCol[line_size].getsPos()==-99) {
146 chil = 9999;
147 }
148 if(
m_debug>0) cout<<
"left "<<line_size<<
" chi k b "<<chil<<
" "<<kl<<
" "<<bl<<endl;
149
150 linefit[i]._pointCol[line_size].setAmb(1);
151 if(
m_debug>0) cout<<
"Add point right "<<
"("<<linefit[i]._pointCol[line_size].getLayerId()<<
","<<linefit[i]._pointCol[line_size].getWireId()<<
") "<<linefit[i]._pointCol[line_size].getStyle()<<
" "<<linefit[i]._pointCol[line_size].getsPos()<<
" "<<linefit[i]._pointCol[line_size].getzPos()<<endl;
153 double chir=linefit[i]._chi;
154 double kr=linefit[i]._k;
155 double br=linefit[i]._b;
156 if (linefit[i]._pointCol[line_size].getsPos()==-99) {
157 chir = 9999;
158 }
159 if(
m_debug>0) cout<<
"right "<<line_size<<
" chi k b "<<chir<<
" "<<kr<<
" "<<br<<endl;
160
161 if(chil<chir) {
162 linefit[i]._pointCol[line_size].setAmb(0);
163 linefit[i]._chi=chil;
164 linefit[i]._k=kl;
165 linefit[i]._b=bl;
166 linefit[i]._ambig.push_back(0);
167
168 }
169 else linefit[i]._ambig.push_back(1);
170 line_size++;
171
172
173 int same_ambig = 1;
174 for(int ihit=0;ihit<line_size;ihit++){
175 int ambighit = linefit[i]._pointCol[ihit].getAmbig();
176 int ambigTruth = linefit[i]._pointCol[ihit].getLrTruth();
177 int layer =linefit[i]._pointCol[ihit].getLayerId();
178 int wire=linefit[i]._pointCol[ihit].getWireId();
179
180
181
182
183
184 }
185
186
187
188 double dChi = chi_last-linefit[i]._chi;
189 double dChi_n = (linefit[i]._chi)/(line_size)-(chi_last/line_size-1);
190 if(
m_debug>0) cout<<
"Chi: "<<linefit[i]._chi<<endl;
191 if(
m_debug>0) cout<<
"dChi: "<<dChi<<endl;
192 if(
m_debug>0) cout<<
"dChi/n: "<<dChi_n<<endl;
194
195 if( fabs(dChi_n) > 25.)
196
197
198
199 {
200 linefit[i]._pointCol.pop_back();
201 linefit[i]._chi=chi_last;
202 linefit[i]._k=k_last;
203 linefit[i]._b=b_last;
204 linefit[i]._ambig.at(j)=-999;
205 line_size--;
206 }
207
208 }
209
210 bool find_best_cluster = false;
211 for(int ilayer=2;ilayer>=0;ilayer--){
212 int ncluster = _cgemCluster[ilayer].size();
213 if(ncluster==0)continue;
214 double chi_last=linefit[i]._chi;
215 double k_last=linefit[i]._k;
216 double b_last=linefit[i]._b;
217 if(
m_debug>0) cout<<
"last chi k b "<<chi_last<<
" "<<k_last<<
" "<<b_last<<endl;
218 double chi_temp=9999;
219 bool find_best_cluster = false;
221 for(int icluster=0;icluster<ncluster;icluster++){
222 _cgemCluster[ilayer][icluster]->setflag(-999);
223 Line linefit_temp = linefit[i];
224 linefit_temp._pointCol.push_back(*(_cgemCluster[ilayer][icluster]));
226 if(linefit_temp._chi<chi_temp){
227 chi_temp = linefit_temp._chi;
228 cluster_temp = _cgemCluster[ilayer][icluster];
229 find_best_cluster = true;
230 }
231 }
232 if(!find_best_cluster)continue;
233 linefit[i]._pointCol.push_back(*cluster_temp);
234 linefit[i]._clusterCol.push_back(cluster_temp);
236 line_size++;
237
238 double dChi = chi_last-linefit[i]._chi;
239 double dChi_n = (linefit[i]._chi)/(line_size-1)-(chi_last/line_size);
240 if(
m_debug>0) cout<<
"Chi: "<<linefit[i]._chi<<endl;
241 if(
m_debug>0) cout<<
"dChi: "<<dChi<<endl;
242 if(
m_debug>0) cout<<
"dChi/n: "<<dChi_n<<endl;
244 if( fabs(dChi_n) > 25.)
245 {
246 linefit[i]._pointCol.pop_back();
247 linefit[i]._clusterCol.pop_back();
248 linefit[i]._chi=chi_last;
249 linefit[i]._k=k_last;
250 linefit[i]._b=b_last;
251
252 line_size--;
253 }
254 }
255
256 if( (linefit[i]._pointCol[0].getsPos()==-99) || (linefit[i]._pointCol[1].getsPos()==-99) || (linefit[i]._pointCol[2].getsPos()==-99) ) {
257 linefit[i]._chi=99999;
258 }
259 }
261 for(int i=0;i<8;i++){
262 if(
m_debug>0) cout<<
"Line :"<<i<<
" chis: "<<linefit[i]._chi<<
" k,b: "<<linefit[i]._k<<
" "<<linefit[i]._b<<endl;
263 int ambig_correct = 0;
264 for(int j=0;j<_hitSize;j++){
265 int ambig = linefit[i]._ambig.at(j);
266 int layer= _recStereoHit.at(j)->getLayerId();
267 int wire= _recStereoHit.at(j)->getWireId();
268 int style= _recStereoHit.at(j)->getStyle();
269 double l=-99;
270 if (ambig!=-999) l= _recStereoHit.at(j)->getsAmb(ambig);
271 double z=-99;
272 if (ambig!=-999) z= _recStereoHit.at(j)->getzAmb(ambig);
273
274 if (l==-99 && z==-99) ambig=-999;
275 if(
m_debug>0) cout<<
"("<<layer<<
" ,"<<wire<<
") style "<<style<<
" ambig "<<ambig<<
" s "<<l<<
" z "<<z<<endl;
276 if(i==0) {
277 _recStereoHit[j]->setAmb(ambig);
278 if( ambig ==-999) _recStereoHit[j]->setflag(-999);
279 int ambigTruth = _recStereoHit.at(j)->getLrTruth();
280 if (ambigTruth == -1) ambigTruth=1;
281 else if (ambigTruth == 1) ambigTruth=0;
282 if(ambig ==ambigTruth) ambig_correct++;
283
284 _pro_correct = (double)ambig_correct/(double)_hitSize;
285
286 for(int icluster=0;icluster<linefit[i]._clusterCol.size();icluster++){
287 linefit[i]._clusterCol[icluster]->setflag(0);
288 }
289 }
290 }
291 }
292 _tanl=linefit[0]._k;
293 _z0=linefit[0]._b;
294 if(
m_debug>0) cout<<
"z0 tanl : "<<_z0<<
" "<<_tanl<<endl;
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377}
bool compare_zsfit(const HoughZsFit::Line &a, const HoughZsFit::Line &b)