125 static int nfound = 0;
126 static float sumprob = 0.0;
128 MdcxHel thel(0., 0., 0., 0., 0.);
130 int nSeg = segList.length();
131 for (
int i = 0; i < nSeg ; i++) { segList[i]->SetUsedOnHel(0); }
133 double xp, yp, xl1, yl1, rl1, xl2, yl2, rl2;
134 double d0g, phi0g, omegag, z0g, tanlg;
135 double d0g_sl, phi0g_sl, omegag_sl, z0g_sl, tanlg_sl;
136 double zintAU, zintAV, zintAU_sl, zintAV_sl = 9999.;
137 double rl1_sl, rl2_sl;
139 double sinPhi0g_sl, cosPhi0g_sl, xp_sl, yp_sl;
140 double phiAx, phiStU, phiStV, xl1_sl, yl1_sl, xl2_sl, yl2_sl, xl1_0, yl1_0, xl2_0, yl2_0;
141 double sx1, sy1, sx2, sy2;
143 double fltAx, ztest, fltL_sl, ztest_sl;
144 int floop, trkCount= 0;
153 if(4 ==
m_debug) std::cout <<
" Test combo: ("<< axlay<<
","<<stUlay<<
","<<stVlay <<
")"<< std::endl;
161 for (
int iAx = 0; iAx < nSeg; iAx++) {
162 bool b_useGood_stU =
true;
163 bool b_useGood_stV =
true;
164 if ((segList[iAx]->GetUsedOnHel() != 0) || (segList[iAx]->Fail() != 0)
165 || (segList[iAx]->
SuperLayer(0) != axlay) || (segList[iAx]->Origin() != -1) )
continue;
168 std::cout<<
"---------1.Ax seg------ No."<<iAx<< std::endl;
169 segList[iAx]->printSegAll();
173 omegag = segList[iAx]->Omega();
175 if (4 ==
m_debug) std::cout<<
"SKIP by maxTrkOmega "<<fabs(omegag) << std::endl;
178 if(4 ==
m_debug) std::cout <<
" iAx omegag = " << omegag << std::endl;
184 d0g_sl = segList[iAx]->D0_sl_approx();
185 phi0g_sl = segList[iAx]->Phi0_sl_approx();
189 sinPhi0g_sl = -
sin(phi0g_sl);
190 cosPhi0g_sl =
cos(phi0g_sl);
191 xp_sl = segList[iAx]->Xref() + sinPhi0g_sl*d0g_sl;
192 yp_sl = segList[iAx]->Yref() + cosPhi0g_sl*d0g_sl;
193 d0g_sl = yp_sl*cosPhi0g_sl + xp_sl*sinPhi0g_sl;
194 fltL_sl = segList[iAx]->Xref()*cosPhi0g_sl - segList[iAx]->Yref()*sinPhi0g_sl;
196 std::cout <<
"--Ax :" prt(d0g_sl)
prt(phi0g_sl)
prt(omegag_sl)
prt(sinPhi0g_sl)
prt(xp_sl)
prt(yp_sl)
prt(fltL_sl) << std::endl;
201 omegag = ohel.
Omega();
208 phiAx = atan2(y0g-yc, x0g-xc);
209 fltAx =
dlen(-2, phi0g,-1, segList[iAx]->Phi0(), omegag);
212 std::cout <<
"--Ax :"<<
" ohel ";
221 for (
int iStU = -1;
true; ) {
222 if(!b_useGood_stU && (iStU >= (nSeg-1)))
break;
223 if(b_useGood_stU && (iStU >= (nSeg-1))){
225 b_useGood_stU =
false;
228 if ((segList[iAx]->GetUsedOnHel() != 0)
229 || (segList[iStU]->GetUsedOnHel() != 0)
230 || (segList[iStU]->Fail() != 0)
232 || (segList[iStU]->Origin() != -1)
234 || (b_useGood_stU && (segList[iStU]->Nhits()< 4))
238 std::cout <<
" Test combo: AUV "<< axlay<<
","<<stUlay<<
","<<stVlay << std::endl;
239 std::cout<<
"---------2.St U seg ------No."<<iStU<< std::endl;
240 segList[iStU]->printSeg();
241 std::cout<<
" omega of seg iStU = "<<segList[iStU]->Omega()<<std::endl;
246 double dPhiAU = fabs(hitsAx[0]->phiMid() - hitsStU[0]->phiMid());
249 if (dPhiAU > max_dPhiAU){
250 cout <<
"SKIP by dPhiAU " <<dPhiAU <<
" > "<< max_dPhiAU << endl;
252 cout <<
"KEEP by dPhiAU " <<dPhiAU<<
" <= " << max_dPhiAU << endl;
254 std::cout <<
" phi mid Ax "<<hitsAx[0]->phiMid()
255 <<
" StU "<<hitsStU[0]->phiMid() << std::endl;
256 std::cout<< std::endl;
260 if (dPhiAU > max_dPhiAU){
continue; }
263 xl1_0 = segList[iStU]->Xline_bbrrf();
264 yl1_0 = segList[iStU]->Yline_bbrrf();
265 sx1 = segList[iStU]->Xline_slope();
266 sy1 = segList[iStU]->Yline_slope();
270 xl1 = xl1_0 + sx1*zintAU;
271 yl1 = yl1_0 + sy1*zintAU;
272 rl1 = sqrt(xl1*xl1 + yl1*yl1);
273 phiStU = atan2(yl1-yc, xl1-xc);
280 zintAU_sl =
findz_sl(iAx, iStU, segList);
281 xl1_sl = xl1_0 + sx1*zintAU_sl;
282 yl1_sl = yl1_0 + sy1*zintAU_sl;
283 rl1_sl = sqrt(xl1_sl*xl1_sl + yl1_sl*yl1_sl);
301 for (
int iStV = -1;
true; ) {
302 if(!b_useGood_stV && (iStV >= (nSeg-1))) {
303 if (4 ==
m_debug) std::cout << iStV <<
" no segments in V slayer "<< std::endl;
306 if(b_useGood_stV && (iStV >= (nSeg-1))){
308 b_useGood_stV =
false;
311 if ((segList[iStV]->GetUsedOnHel()!=0)
312 || (segList[iStU]->GetUsedOnHel()!=0)
313 || (segList[iAx]->GetUsedOnHel()!=0)
314 || (segList[iStV]->Fail() != 0)
316 || (segList[iStV]->Origin() != -1)
318 || (b_useGood_stV && (segList[iStV]->Nhits()< 4))
322 std::cout <<
" Test combo: AUV "<< axlay<<
","<<stUlay<<
","<<stVlay << std::endl;
323 std::cout<<
"---------3.St V seg ------No."<<iStV<< std::endl;
324 segList[iStV]->printSeg();
325 std::cout<<
" omega of seg iStV = "<<segList[iStV]->Omega()<<std::endl;
330 double dPhiAV = fabs(hitsAx[0]->phiMid() - hitsStV[0]->phiMid());
334 if (dPhiAV > max_dPhiAV){
335 cout <<
"SKIP by dPhiAV " <<dPhiAV <<
" > "<< max_dPhiAV << endl;
337 cout <<
"KEEP by dPhiAV " <<dPhiAV<<
" <= " << max_dPhiAV << endl;
339 std::cout <<
" phi mid Ax "<<hitsAx[0]->phiMid()
340 <<
" StV "<<hitsStV[0]->phiMid() << std::endl;
341 std::cout<< std::endl;
344 if (dPhiAV > max_dPhiAV) {
continue; }
348 xl2_0 = segList[iStV]->Xline_bbrrf();
349 yl2_0 = segList[iStV]->Yline_bbrrf();
350 sx2 = segList[iStV]->Xline_slope();
351 sy2 = segList[iStV]->Yline_slope();
354 xl2 = xl2_0 + sx2*zintAV;
355 yl2 = yl2_0 + sy2*zintAV;
356 rl2 = sqrt(xl2*xl2 + yl2*yl2);
358 segList[iAx]->printSeg();
359 segList[iStV]->printSeg();
360 cout <<
"zintAV " << zintAV << endl;
362 phiStV = atan2(yl2-yc, xl2-xc);
368 zintAV_sl =
findz_sl(iAx, iStV, segList);
369 xl2_sl = xl2_0 + sx2*zintAV_sl;
370 yl2_sl = yl2_0 + sy2*zintAV_sl;
371 rl2_sl = sqrt(xl2_sl*xl2_sl + yl2_sl*yl2_sl);
388 segList[iAx]->printSeg();
389 segList[iStU]->printSeg();
390 segList[iStV]->printSeg();
394 double first_prob = 0.0;
396 hitlist.append(hitsAx);
397 hitlist.append(hitsStU);
398 hitlist.append(hitsStV);
399 if(
g_trkllmk)
for (
int i=0; i<hitlist.length(); i++ ){
g_trkllmk->fill(hitlist[i]->Layer()); }
407 if(4 ==
m_debug) std::cout<<
"---------4.Ax circle fit------"<< std::endl;
409 if(4 ==
m_debug) std::cout<<
"SKIP by omegag==0 "<<std::endl;
425 if(4 ==
m_debug) cout<<
"dlen calc. slay U "<<segList[iStU]->SuperLayer()<<
" slay V "<<segList[iStV]->SuperLayer()<<endl;
429 cout
prt(fltLenUV)
prt(phiStU)
prt(phiStV)
prt(omegag)<< std::endl;
435 tanlg = (zintAV - zintAU)/fltLenUV;
436 if(4 ==
m_debug) cout<<
"dlen calc. slay A "<<segList[iAx]->SuperLayer()<<
" slay U "<<segList[iStU]->SuperLayer()<<endl;
454 z0g = zintAU - fltLenAU*tanlg;
462 ztest = z0g + fltAx*tanlg;
463 if (4 ==
m_debug) std::cout
prt(ztest)
prt(fltAx)<<std::endl;
467 MdcxHel ghel(segList[iAx]->D0(), segList[iAx]->Phi0(), segList[iAx]->Omega(),
468 ztest, tanlg, 0.0, 11111, 0, segList[iAx]->Xref(), segList[iAx]->Yref());
471 first_prob = firstfit.
Prob();
473 std::cout<<
" after first fit: "<<std::endl;
479 first_prob = nextfit.
Prob();
484 if (4 ==
m_debug) cout <<
" prob after helix fitting = " << first_prob << endl;
494 if (4 ==
m_debug) std::cout<<
"---------4.2 straight line fit------"<< std::endl;
495 if (4 ==
m_debug) cout <<
" zintAU_sl " << zintAU_sl <<
" zintAV_sl " << zintAV_sl << endl;
497 if (4 ==
m_debug) cout <<
" helix fit good , exit straight line fit." << endl;
506 double dx = xl2_sl - xl1_sl;
507 double dy = yl2_sl - yl1_sl;
508 double dl = sqrt(dx*dx + dy*dy);
509 tanlg_sl = (zintAV_sl - zintAU_sl)/dl;
510 dx = xl1_sl + d0g_sl*
sin(phi0g_sl);
511 dy = yl1_sl - d0g_sl*
cos(phi0g_sl);
512 dl = sqrt(dx*dx + dy*dy);
513 z0g_sl = zintAU_sl - dl*tanlg_sl;
521 ztest_sl = z0g_sl + fltL_sl*tanlg_sl;
525 MdcxHel ghel(segList[iAx]->D0_sl_approx(), segList[iAx]->Phi0_sl_approx(), omegag_sl,
526 ztest_sl, tanlg_sl, 0.0, 11111, 0, segList[iAx]->Xref(), segList[iAx]->Yref());
529 first_prob = firstfit.
Prob();
533 std::cout <<
"first_prob "<<first_prob << std::endl;
539 first_prob = nextfit.
Prob();
542 cout <<
" three seg sl nextfit" << endl;
555 if(4 ==
m_debug)std::cout<<
"---------5. try add seg to helix------"<< std::endl;
557 if(4 ==
m_debug) std::cout<<
"prob"<<first_prob<<
" "
558 <<
probmin<<
" fit NOT good, exit add segs "<< std::endl;
561 float bchisq = fithel.
Chisq()*helixFitSigma*helixFitSigma;
562 int bndof = fithel.
Nhits() - 5;
565 segList[iAx]->SetUsedOnHel(trkCount);
566 segList[iStU]->SetUsedOnHel(trkCount);
567 segList[iStV]->SetUsedOnHel(trkCount);
570 cout <<
"in add seg to trail helix, klm seg:" << endl;
571 segList[iAx]->printSeg();
572 segList[iStU]->printSeg();
573 segList[iStV]->printSeg();
579 for (
int iSeg = 0; iSeg < nSeg; iSeg++) {
581 ||(segList[iSeg]->GetUsedOnHel() != 0)
582 || (segList[iSeg]->Fail() != 0)
583 || (segList[iSeg]->Origin() != -1))
continue;
585 std::cout<< endl<<
"== add seg "<< iSeg<<
" ";
586 segList[iSeg]->printSeg();
590 float phiAxSeg = segList[iAx]->XHitList()[0]->phiMid();
591 float phiAddSeg = segList[iSeg]->XHitList()[0]->phiMid();
592 double phiKNSegDiff = fabs(phiAxSeg - phiAddSeg);
618 if(4 ==
m_debug) std::cout<<
" SKIP by phi diff,same "<< t_same <<
" Ax "<<
619 phiAxSeg<<
" iSeg "<<phiAddSeg<<
" diff "<<phiKNSegDiff << std::endl;
622 if(4 ==
m_debug) std::cout<<
" phi diff OK, Ax "<<
623 phiAxSeg<<
" added "<<phiAddSeg<<
" diff="<<phiKNSegDiff << std::endl;
627 xp = segList[iSeg]->Xref() - segList[iSeg]->SinPhi0()*segList[iSeg]->D0();
628 yp = segList[iSeg]->Yref() + segList[iSeg]->CosPhi0()*segList[iSeg]->D0();
630 double proca = fithel.
Doca( hitsSegAdd[0]->wx(), hitsSegAdd[0]->wy(),
631 hitsSegAdd[0]->wz(), xp, yp );
657 newhel.
Grow(fithel, hitsSegAdd);
658 if (newhel.
Nhits() != hitlist.length()) {
666 cout <<
" prob " << newhel.
Prob() <<
"<"<<
probmin<<
", ReFit" << endl;
671 cout<<
" refit prob "<<newhel.
Prob()<<
"<"<<
probmin<<
" Fail? "<<newhel.
Fail()<< endl;
678 segList[iSeg]->SetUsedOnHel(trkCount);
679 bchisq = fithel.
Chisq()*helixFitSigma*helixFitSigma;
680 bndof = fithel.
Nhits() - 5;
682 if (tprob > bprob) bprob = tprob;
684 cout <<
" segment ADDED, prob=" << newhel.
Prob() << endl;
688 if(4 ==
m_debug)std::cout<<
" fit FAILED"<<std::endl;
691 segList[iSeg]->SetUsedOnHel(trkCount);
692 if (4 ==
m_debug) cout <<
" segment ADDED, but no new hits" << endl;
697 if (((fithel.
Prob() < 0.90) && (fithel.
Nhits() == 12)) || (fithel.
Fail() != 0)) {
698 for (
int i = 0; i < nSeg; i++) {
if (segList[i]->GetUsedOnHel() == trkCount) segList[i]->SetUsedOnHel(0); }
704 std::cout<<
"Track after add segs" << std::endl;
709 if(4 ==
m_debug) std::cout<<
"---------6. flip------"<< std::endl;
714 int notduplicate = 1;
716 if (4 ==
m_debug)std::cout<<
"---------7. test saved track------"<< std::endl;
722 while (hitlist[kkl]) {
723 if (hitlist[kkl] == junk[kkj]) overl++;
728 if (4 ==
m_debug) cout <<
"overlap with track # " << kki <<
" is "
729 << junk.length() <<
" hitList " << hitlist.length() <<
" overlap " << overl << endl;
730 if ( (hitlist.length()/4.) <= overl) notduplicate = 0;
740 if(4 ==
m_debug) std::cout<<
"---------8. test worth saving?------"<< std::endl;
745 <<
" finehel Prob>0.001 "<<finehel->
Prob()
746 <<
" nhits "<<finehel->
Nhits() <<
">=15? "
749 <<
" Fail==0? "<< finehel->
Fail()
756 ) && (finehel->
Fail() == 0) ) {
758 sumprob += finehel->
Prob();
764 if ((finehel->
Prob() > 0.05) || nodrop ) {
767 for (
int iHit=0; iHit<finehel->
Nhits(); iHit++){
773 float ratdrop = float(drophel->
Nhits()) / float(finehel->
Nhits());
774 if (4 ==
m_debug) cout <<
"APPEND track " << trkCount <<
", drops "
776 <<
" helixnhit "<<finehel->
Nhits()<<
" drophit "<<drophel->
Nhits()
777 <<
" hits, drop rate="<<ratdrop <<
">?"<<0.5
778 <<
" prob "<<drophel->
Prob() <<
" >?"<<finehel->
Prob()
779 <<
" fail==0? "<<drophel->
Fail()
781 if ((drophel->
Prob() > finehel->
Prob()) &&
782 (ratdrop > 0.50) && (drophel->
Fail() == 0)) {
783 if (4 ==
m_debug) cout <<
"append drop helix " << endl;
788 if (4 ==
m_debug) cout <<
"append fine helix " << endl;
797 if ((4 ==
m_debug) && (nwl > -1)) {
799 cout << endl <<
"found track " << trkCount<<std::endl;
805 for (
int i = 0; i < nSeg; i++) {
806 if (segList[i]->GetUsedOnHel() == trkCount) segList[i]->SetUsedOnHel(0);
816 if(4==
m_debug) cout<<
"end of this combo"<<endl;
818 if(4==
m_debug) cout <<
" In MdcxFindTracks, found " << trkCount <<
" good tracks" << endl;