124 {
125 static int nfound = 0;
126 static float sumprob = 0.0;
127
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); }
132
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;
138 double xc, yc;
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;
142 double x0g, y0g;
143 double fltAx, ztest, fltL_sl, ztest_sl;
144 int floop, trkCount= 0;
145
146
148
152
153 if(4 ==
m_debug) std::cout <<
" Test combo: ("<< axlay<<
","<<stUlay<<
","<<stVlay <<
")"<< std::endl;
154
157
158
159
160
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;
166
168 std::cout<< "---------1.Ax seg------ No."<<iAx<< std::endl;
169 segList[iAx]->printSegAll();
170 }
171
172
173 omegag = segList[iAx]->Omega();
175 if (4 ==
m_debug) std::cout<<
"SKIP by maxTrkOmega "<<fabs(omegag) << std::endl;
176 continue;
177 }
178 if(4 ==
m_debug) std::cout <<
" iAx omegag = " << omegag << std::endl;
180
182
183
184 d0g_sl = segList[iAx]->D0_sl_approx();
185 phi0g_sl = segList[iAx]->Phi0_sl_approx();
186 omegag_sl = 0.0;
187
188
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;
197 }
198
201 omegag = ohel.
Omega();
208 phiAx = atan2(y0g-yc, x0g-xc);
209 fltAx =
dlen(-2, phi0g,-1, segList[iAx]->Phi0(), omegag);
210
212 std::cout <<"--Ax :"<< " ohel ";
214 }
215 }
216
217
218
219
220
221 for (int iStU = -1; true; ) {
222 if(!b_useGood_stU && (iStU >= (nSeg-1))) break;
223 if(b_useGood_stU && (iStU >= (nSeg-1))){
224 iStU = -1;
225 b_useGood_stU = false;
226 }
227 iStU++;
228 if ((segList[iAx]->GetUsedOnHel() != 0)
229 || (segList[iStU]->GetUsedOnHel() != 0)
230 || (segList[iStU]->Fail() != 0)
232 || (segList[iStU]->Origin() != -1)
233
234 || (b_useGood_stU && (segList[iStU]->Nhits()< 4))
235 ){ continue;}
236
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;
242 }
243
244
246 double dPhiAU = fabs(hitsAx[0]->phiMid() - hitsStU[0]->phiMid());
249 if (dPhiAU > max_dPhiAU){
250 cout << "SKIP by dPhiAU " <<dPhiAU <<" > "<< max_dPhiAU << endl;
251 }else{
252 cout << "KEEP by dPhiAU " <<dPhiAU<< " <= " << max_dPhiAU << endl;
253 }
254 std::cout << " phi mid Ax "<<hitsAx[0]->phiMid()
255 <<" StU "<<hitsStU[0]->phiMid() << std::endl;
256 std::cout<< std::endl;
257 }
259
260 if (dPhiAU > max_dPhiAU){ continue; }
261
262
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);
275 } else {
276 zintAU = -9999.;
277 }
278
279
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);
285
286
290 continue;
291 }
295 continue;
296 }
297
298
299
300
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;
304 break;
305 }
306 if(b_useGood_stV && (iStV >= (nSeg-1))){
307 iStV = -1;
308 b_useGood_stV = false;
309 }
310 iStV++;
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)
317
318 || (b_useGood_stV && (segList[iStV]->Nhits()< 4))
319 ){ continue; }
320
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;
326 }
327
328
330 double dPhiAV = fabs(hitsAx[0]->phiMid() - hitsStV[0]->phiMid());
332
334 if (dPhiAV > max_dPhiAV){
335 cout << "SKIP by dPhiAV " <<dPhiAV <<" > "<< max_dPhiAV << endl;
336 }else{
337 cout << "KEEP by dPhiAV " <<dPhiAV<< " <= " << max_dPhiAV << endl;
338 }
339 std::cout << " phi mid Ax "<<hitsAx[0]->phiMid()
340 <<" StV "<<hitsStV[0]->phiMid() << std::endl;
341 std::cout<< std::endl;
342 }
344 if (dPhiAV > max_dPhiAV) { continue; }
345
346
347
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;
361 }
362 phiStV = atan2(yl2-yc, xl2-xc);
363 } else {
364 zintAV = -9999.;
365 }
366
367
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);
372
373
377 continue;
378 }
382 continue;
383 }
384
385
387
388 segList[iAx]->printSeg();
389 segList[iStU]->printSeg();
390 segList[iStV]->printSeg();
391 }
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()); }
400
401
402
403
404
405 floop = 1;
406 while (floop) {
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;
410 break;
411 }
415 break;
416 }
420 break;
421 }
422
423
424
425 if(4 ==
m_debug) cout<<
"dlen calc. slay U "<<segList[iStU]->SuperLayer()<<
" slay V "<<segList[iStV]->SuperLayer()<<endl;
427
429 cout
prt(fltLenUV)
prt(phiStU)
prt(phiStV)
prt(omegag)<< std::endl;
430 }
433 break;
434 }
435 tanlg = (zintAV - zintAU)/fltLenUV;
436 if(4 ==
m_debug) cout<<
"dlen calc. slay A "<<segList[iAx]->SuperLayer()<<
" slay U "<<segList[iStU]->SuperLayer()<<endl;
438
452 }
453
454 z0g = zintAU - fltLenAU*tanlg;
456
457
460 break;
461 }
462 ztest = z0g + fltAx*tanlg;
463 if (4 ==
m_debug) std::cout
prt(ztest)
prt(fltAx)<<std::endl;
464
465
466
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());
469
471 first_prob = firstfit.Prob();
473 std::cout<<" after first fit: "<<std::endl;
474 firstfit.FitPrint();
475 }
479 first_prob = nextfit.Prob();
480 fithel=nextfit;
482 }
484 if (4 ==
m_debug) cout <<
" prob after helix fitting = " << first_prob << endl;
485 floop = 0;
486 }
487
488
489
490
491
492 floop = 1;
493 while (floop) {
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;
498 break;
499 }
500
505
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;
515
518 break;
519 }
520
521 ztest_sl = z0g_sl + fltL_sl*tanlg_sl;
523
524
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());
527
529 first_prob = firstfit.Prob();
530
532 ghel.print();
533 std::cout <<"first_prob "<<first_prob << std::endl;
534 }
535
539 first_prob = nextfit.Prob();
540 fithel = nextfit;
542 cout << " three seg sl nextfit" << endl;
544 }
545 }
546 floop = 0;
547 }
548
549
550
551
552 floop = 1;
553 while (floop) {
554 floop = 0;
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;
559 break;
560 }
561 float bchisq = fithel.
Chisq()*helixFitSigma*helixFitSigma;
562 int bndof = fithel.
Nhits() - 5;
564 trkCount++;
565 segList[iAx]->SetUsedOnHel(trkCount);
566 segList[iStU]->SetUsedOnHel(trkCount);
567 segList[iStV]->SetUsedOnHel(trkCount);
568
570 cout << "in add seg to trail helix, klm seg:" << endl;
571 segList[iAx]->printSeg();
572 segList[iStU]->printSeg();
573 segList[iStV]->printSeg();
574 }
575
576
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();
587 }
588
589
590 float phiAxSeg = segList[iAx]->XHitList()[0]->phiMid();
591 float phiAddSeg = segList[iSeg]->XHitList()[0]->phiMid();
592 double phiKNSegDiff = fabs(phiAxSeg - phiAddSeg);
593
594
595
596
597 int t_same=-999;
599
613 }
614
616
617 {
618 if(4 ==
m_debug) std::cout<<
" SKIP by phi diff,same "<< t_same <<
" Ax "<<
619 phiAxSeg<<" iSeg "<<phiAddSeg<<" diff "<<phiKNSegDiff << std::endl;
620 continue;
621 }else{
622 if(4 ==
m_debug) std::cout<<
" phi diff OK, Ax "<<
623 phiAxSeg<<" added "<<phiAddSeg<<" diff="<<phiKNSegDiff << std::endl;
624 }
625
626
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 );
633
634
641 }
642
644
647 }
648 }else{
651 }
652 }
654
657 newhel.
Grow(fithel, hitsSegAdd);
658 if (newhel.
Nhits() != hitlist.length()) {
661 }
662
663
666 cout <<
" prob " << newhel.
Prob() <<
"<"<<
probmin<<
", ReFit" << endl;
667 }
669 }
671 cout<<
" refit prob "<<newhel.
Prob()<<
"<"<<
probmin<<
" Fail? "<<newhel.
Fail()<< endl;
672 }
673
675
676 fithel = newhel;
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;
685 }
686 }
687 else{
688 if(4 ==
m_debug)std::cout<<
" fit FAILED"<<std::endl;
689 }
690 } else {
691 segList[iSeg]->SetUsedOnHel(trkCount);
692 if (4 ==
m_debug) cout <<
" segment ADDED, but no new hits" << endl;
693 }
694 }
695 }
696 }
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); }
699 trkCount--;
700 break;
701 }
702
704 std::cout<< "Track after add segs" << std::endl;
706 }
707
708
709 if(4 ==
m_debug) std::cout<<
"---------6. flip------"<< std::endl;
711
712
713 int kki = 0;
714 int notduplicate = 1;
716 if (4 ==
m_debug)std::cout<<
"---------7. test saved track------"<< std::endl;
718 int overl = 0;
719 int kkj = 0;
720 while (junk[kkj]) {
721 int kkl = 0;
722 while (hitlist[kkl]) {
723 if (hitlist[kkl] == junk[kkj]) overl++;
724 kkl++;
725 }
726 kkj++;
727 }
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;
731
732
733 kki++;
734 }
735
737
738
739 if (notduplicate) {
740 if(4 ==
m_debug) std::cout<<
"---------8. test worth saving?------"<< std::endl;
742
744 std::cout<<__FILE__
745 <<
" finehel Prob>0.001 "<<finehel->
Prob()
746 <<
" nhits "<<finehel->
Nhits() <<
">=15? "
747 <<" bprob "<< bprob
749 <<
" Fail==0? "<< finehel->
Fail()
750 << std::endl;
752 }
753
755
756 ) && (finehel->
Fail() == 0) ) {
757 nfound++;
758 sumprob += finehel->
Prob();
759
760
761
762
763 int nodrop = 0;
764 if ((finehel->
Prob() > 0.05) || nodrop ) {
766
767 for (
int iHit=0; iHit<finehel->
Nhits(); iHit++){
769 }
770
771 } else {
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()
780 << endl;
781 if ((drophel->
Prob() > finehel->
Prob()) &&
782 (ratdrop > 0.50) && (drophel->
Fail() == 0)) {
783 if (4 ==
m_debug) cout <<
"append drop helix " << endl;
786 delete finehel;
787 } else {
788 if (4 ==
m_debug) cout <<
"append fine helix " << endl;
791 delete drophel;
792 }
793 }
794
795
797 if ((4 ==
m_debug) && (nwl > -1)) {
799 cout << endl << "found track " << trkCount<<std::endl;
802 }
803 }
804 } else {
805 for (int i = 0; i < nSeg; i++) {
806 if (segList[i]->GetUsedOnHel() == trkCount) segList[i]->SetUsedOnHel(0);
807 }
808 delete finehel;
809 trkCount--;
810 }
811 }
812 }
813 }
814 }
815 }
816 if(4==
m_debug) cout<<
"end of this combo"<<endl;
817 }
818 if(4==
m_debug) cout <<
" In MdcxFindTracks, found " << trkCount <<
" good tracks" << endl;
819}
AIDA::IHistogram1D * g_dPhiAV
NTuple::Item< double > m_addSegAddPhiLay
AIDA::IHistogram1D * g_trklappend2
NTuple::Item< double > m_addSegSeedPhi0
NTuple::Item< double > m_segCombDLenUV
AIDA::IHistogram1D * g_trklappend1
NTuple::Item< long > m_addSegSlayer
NTuple::Item< long > m_addSegSame
AIDA::IHistogram1D * g_trklproca
NTuple::Item< double > m_addSegSeedSl
NTuple::Tuple * m_xtupleAddSeg1
NTuple::Item< double > m_addSegLen
NTuple::Item< double > m_addSegSeedPhiLay
NTuple::Item< double > m_segCombSlV
NTuple::Item< double > m_addSegSeedD0
AIDA::IHistogram1D * g_trklappend3
AIDA::IHistogram1D * g_trklhelix
AIDA::IHistogram1D * g_trkllmk
NTuple::Item< double > m_segCombPhiA
NTuple::Item< double > m_segCombSlA
NTuple::Item< double > m_segCombDLenAU
AIDA::IHistogram1D * g_trklgood
NTuple::Item< double > m_segCombSlU
NTuple::Item< double > m_segCombPhiU
AIDA::IHistogram1D * g_dPhiAU
NTuple::Item< double > m_segCombSameUV
NTuple::Item< double > m_addSegAddPhi
NTuple::Item< double > m_addSegSeedPhi
NTuple::Item< double > m_segCombPhiV
NTuple::Item< double > m_addSegAddPhi0
NTuple::Tuple * m_xtupleSegComb
NTuple::Item< double > m_addSegAddSl
NTuple::Item< double > m_segCombOmega
NTuple::Item< double > m_addSegAddD0
NTuple::Item< double > m_segCombSameAU
AIDA::IHistogram1D * g_trklfirstProb
NTuple::Tuple * m_xtupleAddSeg2
AIDA::IHistogram1D * g_omegag
NTuple::Item< long > m_addSegEvtNo
NTuple::Item< double > m_addSegPoca
float Mdcxprobab(int &ndof, float &chisq)
unsigned SuperLayer(const AList< TMLink > &list)
returns super layer pattern.
static const double twoPi
static const int nSuperLayer
static const double epsilon
MdcxFittedHel drophits(MdcxFittedHel *f)
double findz_sl(int i1, int i2, const HepAList< MdcxSeg > &slclus)
double findz_cyl(int i1, int i2, const HepAList< MdcxSeg > &slclus)
bool testFromSameTrack(MdcxSeg *seg1, MdcxSeg *seg2)
double dlen(int slay1, double p1, int slay2, double p2, double om)
MdcxHel TakeToOrigin(MdcxHel &)
int Layer(int hitno=0) const
const HepAList< MdcxHit > & XHitList() const
int Fail(float Probmin=0.0) const
MdcxFittedHel & Grow(const MdcxFittedHel &, const HepAList< MdcxHit > &)
static const double maxMdcZLen
static const double maxDlen
static const int nSegCombo
relative to MdcxFindTracks
static const double maxTrkOmega
Track attribute.
static const float maxDp12[nSegCombo]
static const int layerSet2AddSeg[nSegCombo][11]
static const float maxDp13[nSegCombo]
static double maxRcsInAddSeg
static const int findTrkGroup[nSegCombo][3]
– relative to MdcxFindTracks
static double helixFitSigma