00078 {
00079 static int nfound = 0;
00080 static float sumprob = 0.0;
00081
00082 MdcxHel thel(0., 0., 0., 0., 0.);
00083 mhel = thel;
00084 int nSeg = segList.length();
00085 for (int i = 0; i < nSeg ; i++) { segList[i]->SetUsedOnHel(0); }
00086
00087 double xp, yp, xl1, yl1, rl1, xl2, yl2, rl2;
00088 double d0g, phi0g, omegag, z0g, tanlg;
00089 double d0g_sl, phi0g_sl, omegag_sl, z0g_sl, tanlg_sl;
00090 double zintAU, zintAV, zintAU_sl, zintAV_sl = 9999.;
00091 double rl1_sl, rl2_sl;
00092 double xc, yc;
00093 double sinPhi0g_sl, cosPhi0g_sl, xp_sl, yp_sl;
00094 double phiAx, phiStU, phiStV, xl1_sl, yl1_sl, xl2_sl, yl2_sl, xl1_0, yl1_0, xl2_0, yl2_0;
00095 double sx1, sy1, sx2, sy2;
00096 double x0g, y0g;
00097 double fltAx, ztest, fltL_sl, ztest_sl;
00098 int floop, trkCount= 0;
00099
00100
00101 for (int iSegCombo = 0; iSegCombo < MdcxParameters::nSegCombo; iSegCombo++) {
00102
00103 int axlay = MdcxParameters::findTrkGroup[iSegCombo][0];
00104 int stUlay = MdcxParameters::findTrkGroup[iSegCombo][1];
00105 int stVlay = MdcxParameters::findTrkGroup[iSegCombo][2];
00106
00107 if(4 == m_debug) std::cout <<" Test combo: ("<< axlay<<","<<stUlay<<","<<stVlay <<")"<< std::endl;
00108
00109 float max_dPhiAU = MdcxParameters::maxDp12[iSegCombo];
00110 float max_dPhiAV = MdcxParameters::maxDp13[iSegCombo];
00111
00112
00113
00114
00115 for (int iAx = 0; iAx < nSeg; iAx++) {
00116 bool b_useGood_stU = true;
00117 bool b_useGood_stV = true;
00118 if ((segList[iAx]->GetUsedOnHel() != 0) || (segList[iAx]->Fail() != 0)
00119 || (segList[iAx]->SuperLayer(0) != axlay) || (segList[iAx]->Origin() != -1) ) continue;
00120
00121 if (4 == m_debug){
00122 std::cout<< "---------1.Ax seg------ No."<<iAx<< std::endl;
00123 segList[iAx]->printSegAll();
00124 }
00125
00126
00127 omegag = segList[iAx]->Omega();
00128 if (fabs(omegag) > MdcxParameters::maxTrkOmega) {
00129 if (4 == m_debug) std::cout<< "SKIP by maxTrkOmega "<<fabs(omegag) << std::endl;
00130 continue;
00131 }
00132 if(4 == m_debug) std::cout << " iAx omegag = " << omegag << std::endl;
00133 if(g_omegag) g_omegag->fill(omegag);
00134
00135 const HepAList<MdcxHit>& hitsAx = segList[iAx]->XHitList();
00136
00137
00138 d0g_sl = segList[iAx]->D0_sl_approx();
00139 phi0g_sl = segList[iAx]->Phi0_sl_approx();
00140 omegag_sl = 0.0;
00141
00142
00143 sinPhi0g_sl = -sin(phi0g_sl);
00144 cosPhi0g_sl = cos(phi0g_sl);
00145 xp_sl = segList[iAx]->Xref() + sinPhi0g_sl*d0g_sl;
00146 yp_sl = segList[iAx]->Yref() + cosPhi0g_sl*d0g_sl;
00147 d0g_sl = yp_sl*cosPhi0g_sl + xp_sl*sinPhi0g_sl;
00148 fltL_sl = segList[iAx]->Xref()*cosPhi0g_sl - segList[iAx]->Yref()*sinPhi0g_sl;
00149 if(4 == m_debug) {
00150 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;
00151 }
00152
00153 if (fabs(omegag) > Constants::epsilon) {
00154 MdcxHel ohel = TakeToOrigin(*segList[iAx]);
00155 omegag = ohel.Omega();
00156 phi0g = ohel.Phi0();
00157 d0g = ohel.D0();
00158 xc = ohel.Xc();
00159 yc = ohel.Yc();
00160 x0g = ohel.X0();
00161 y0g = ohel.Y0();
00162 phiAx = atan2(y0g-yc, x0g-xc);
00163 fltAx = dlen(phi0g,segList[iAx]->Phi0(), omegag);
00164 if(4 == m_debug) {
00165 std::cout <<"--Ax :"<< " ohel ";
00166 ohel.print();
00167 }
00168 }
00169
00170
00171
00172
00173
00174 for (int iStU = -1; true; ) {
00175 if(!b_useGood_stU && (iStU >= (nSeg-1))) break;
00176 if(b_useGood_stU && (iStU >= (nSeg-1))){
00177 iStU = -1;
00178 b_useGood_stU = false;
00179 }
00180 iStU++;
00181 if ((segList[iAx]->GetUsedOnHel() != 0)
00182 || (segList[iStU]->GetUsedOnHel() != 0)
00183 || (segList[iStU]->Fail() != 0)
00184 || (segList[iStU]->SuperLayer(0) != stUlay)
00185 || (segList[iStU]->Origin() != -1)
00186
00187 || (b_useGood_stU && (segList[iStU]->Nhits()< 4))
00188 ){ continue;}
00189
00190 if (4 == m_debug){
00191 std::cout <<" Test combo: AUV "<< axlay<<","<<stUlay<<","<<stVlay << std::endl;
00192 std::cout<< "---------2.St U seg ------No."<<iStU<< std::endl;
00193 segList[iStU]->printSeg();
00194 std::cout<<" omega of seg iStU = "<<segList[iStU]->Omega()<<std::endl;
00195 }
00196
00197
00198 const HepAList<MdcxHit>& hitsStU = segList[iStU]->XHitList();
00199 double dPhiAU = fabs(hitsAx[0]->phiMid() - hitsStU[0]->phiMid());
00200 if (dPhiAU > Constants::pi) dPhiAU = Constants::twoPi - dPhiAU;
00201 if(4 == m_debug) {
00202 if (dPhiAU > max_dPhiAU){
00203 cout << "SKIP by dPhiAU " <<dPhiAU <<" > "<< max_dPhiAU << endl;
00204 }else{
00205 cout << "KEEP by dPhiAU " <<dPhiAU<< " <= " << max_dPhiAU << endl;
00206 }
00207 std::cout << " phi mid Ax "<<hitsAx[0]->phiMid()
00208 <<" StU "<<hitsStU[0]->phiMid() << std::endl;
00209 std::cout<< std::endl;
00210 }
00211 if (g_dPhiAU) g_dPhiAU->fill(dPhiAU,segList[iStU]->SuperLayer());
00212
00213 if (dPhiAU > max_dPhiAU){ continue; }
00214
00215
00216 xl1_0 = segList[iStU]->Xline_bbrrf();
00217 yl1_0 = segList[iStU]->Yline_bbrrf();
00218 sx1 = segList[iStU]->Xline_slope();
00219 sy1 = segList[iStU]->Yline_slope();
00220 if (4 == m_debug) std::cout prt(xl1_0) prt(yl1_0) prt(sx1) prt(sy1) prt(omegag) << std::endl;
00221 if (fabs(omegag) >Constants::epsilon) {
00222 zintAU = findz_cyl(iAx, iStU, segList);
00223 xl1 = xl1_0 + sx1*zintAU;
00224 yl1 = yl1_0 + sy1*zintAU;
00225 rl1 = sqrt(xl1*xl1 + yl1*yl1);
00226 phiStU = atan2(yl1-yc, xl1-xc);
00227 if (4 == m_debug) cout prt(zintAU) prt(xl1) prt(yl1) prt(rl1) prt(phiStU) <<endl;
00228 } else {
00229 zintAU = -9999.;
00230 }
00231
00232
00233 zintAU_sl = findz_sl(iAx, iStU, segList);
00234 xl1_sl = xl1_0 + sx1*zintAU_sl;
00235 yl1_sl = yl1_0 + sy1*zintAU_sl;
00236 rl1_sl = sqrt(xl1_sl*xl1_sl + yl1_sl*yl1_sl);
00237 if (4 == m_debug) cout prt(zintAU_sl) prt(xl1_sl) prt(yl1_sl) prt(rl1_sl) <<endl;
00238
00239
00240 if ( (zintAU < -MdcxParameters::maxMdcZLen) &&
00241 (zintAU_sl < -MdcxParameters::maxMdcZLen) ) {
00242 if (4 == m_debug) std::cout << " SKIP by zintAU < max MdcZLen "<<MdcxParameters::maxMdcZLen << std::endl;
00243 continue;
00244 }
00245 if ( (zintAU > MdcxParameters::maxMdcZLen) &&
00246 (zintAU_sl > MdcxParameters::maxMdcZLen) ) {
00247 if (4 == m_debug) std::cout << " SKIP by zintAU > max MdcZLen "<<MdcxParameters::maxMdcZLen << std::endl;
00248 continue;
00249 }
00250
00251
00252
00253
00254 for (int iStV = -1; true; ) {
00255 if(!b_useGood_stV && (iStV >= (nSeg-1))) break;
00256 if(b_useGood_stV && (iStV >= (nSeg-1))){
00257 iStV = -1;
00258 b_useGood_stV = false;
00259 }
00260 iStV++;
00261 if ((segList[iStV]->GetUsedOnHel()!=0)
00262 || (segList[iStU]->GetUsedOnHel()!=0)
00263 || (segList[iAx]->GetUsedOnHel()!=0)
00264 || (segList[iStV]->Fail() != 0)
00265 || (segList[iStV]->SuperLayer(0) != stVlay)
00266 || (segList[iStV]->Origin() != -1)
00267
00268 || (b_useGood_stV && (segList[iStV]->Nhits()< 4))
00269 ){ continue; }
00270
00271 if (4 == m_debug){
00272 std::cout <<" Test combo: AUV "<< axlay<<","<<stUlay<<","<<stVlay << std::endl;
00273 std::cout<< "---------3.St V seg ------No."<<iStV<< std::endl;
00274 segList[iStV]->printSeg();
00275 std::cout<<" omega of seg iStV = "<<segList[iStV]->Omega()<<std::endl;
00276 }
00277
00278
00279 const HepAList<MdcxHit>& hitsStV = segList[iStV]->XHitList();
00280 double dPhiAV = fabs(hitsAx[0]->phiMid() - hitsStV[0]->phiMid());
00281 if (dPhiAV > Constants::pi) dPhiAV = Constants::twoPi - dPhiAV;
00282
00283 if(4 == m_debug) {
00284 if (dPhiAV > max_dPhiAV){
00285 cout << "SKIP by dPhiAV " <<dPhiAV <<" > "<< max_dPhiAV << endl;
00286 }else{
00287 cout << "KEEP by dPhiAV " <<dPhiAV<< " <= " << max_dPhiAV << endl;
00288 }
00289 std::cout << " phi mid Ax "<<hitsAx[0]->phiMid()
00290 <<" StV "<<hitsStV[0]->phiMid() << std::endl;
00291 std::cout<< std::endl;
00292 }
00293 if (g_dPhiAV) g_dPhiAV->fill(dPhiAV,segList[iStV]->SuperLayer());
00294 if (dPhiAV > max_dPhiAV) { continue; }
00295
00296
00297
00298 xl2_0 = segList[iStV]->Xline_bbrrf();
00299 yl2_0 = segList[iStV]->Yline_bbrrf();
00300 sx2 = segList[iStV]->Xline_slope();
00301 sy2 = segList[iStV]->Yline_slope();
00302 if (fabs(omegag) > Constants::epsilon) {
00303 zintAV = findz_cyl(iAx, iStV, segList);
00304 xl2 = xl2_0 + sx2*zintAV;
00305 yl2 = yl2_0 + sy2*zintAV;
00306 rl2 = sqrt(xl2*xl2 + yl2*yl2);
00307 if (4 == m_debug){
00308 segList[iAx]->printSeg();
00309 segList[iStV]->printSeg();
00310 cout << "zintAV " << zintAV << endl;
00311 }
00312 phiStV = atan2(yl2-yc, xl2-xc);
00313 } else {
00314 zintAV = -9999.;
00315 }
00316
00317
00318 zintAV_sl = findz_sl(iAx, iStV, segList);
00319 xl2_sl = xl2_0 + sx2*zintAV_sl;
00320 yl2_sl = yl2_0 + sy2*zintAV_sl;
00321 rl2_sl = sqrt(xl2_sl*xl2_sl + yl2_sl*yl2_sl);
00322
00323
00324 if ( (zintAV < -MdcxParameters::maxMdcZLen) &&
00325 (zintAV_sl < -MdcxParameters::maxMdcZLen) ) {
00326 if (4 == m_debug) std::cout << " SKIP by zintAV < max MdcZLen "<<MdcxParameters::maxMdcZLen << std::endl;
00327 continue;
00328 }
00329 if ( (zintAV > MdcxParameters::maxMdcZLen) &&
00330 (zintAV_sl > MdcxParameters::maxMdcZLen) ) {
00331 if (4 == m_debug) std::cout << " SKIP by zintAV > max MdcZLen "<<MdcxParameters::maxMdcZLen << std::endl;
00332 continue;
00333 }
00334
00335
00336 if (4 == m_debug) {
00337
00338 segList[iAx]->printSeg();
00339 segList[iStU]->printSeg();
00340 segList[iStV]->printSeg();
00341 }
00342 MdcxFittedHel fithel;
00343 double helixFitSigma = MdcxParameters::helixFitSigma;
00344 double first_prob = 0.0;
00345 HepAList<MdcxHit> hitlist;
00346 hitlist.append(hitsAx);
00347 hitlist.append(hitsStU);
00348 hitlist.append(hitsStV);
00349 if(g_trkllmk) for (int i=0; i<hitlist.length(); i++ ){ g_trkllmk->fill(hitlist[i]->Layer()); }
00350
00351
00352
00353
00354
00355 floop = 1;
00356 while (floop) {
00357 if(4 == m_debug) std::cout<< "---------4.Ax circle fit------"<< std::endl;
00358 if (fabs(omegag) < Constants::epsilon) {
00359 if(4 == m_debug) std::cout<<"SKIP by omegag==0 "<<std::endl;
00360 break;
00361 }
00362 if ( (zintAU < -MdcxParameters::maxMdcZLen) ||
00363 (zintAU > MdcxParameters::maxMdcZLen) ){
00364 if(4 == m_debug) std::cout<<"SKIP by zintAU out of range "<<zintAU<<" "<<MdcxParameters::maxMdcZLen<<std::endl;
00365 break;
00366 }
00367 if ( (zintAV < -MdcxParameters::maxMdcZLen) ||
00368 (zintAV > MdcxParameters::maxMdcZLen) ){
00369 if(4 == m_debug) std::cout<<"SKIP by zintAU out of range "<<zintAU<<" "<<MdcxParameters::maxMdcZLen<<std::endl;
00370 break;
00371 }
00372
00373
00374
00375 double fltLenUV = dlen(phiStU, phiStV, omegag);
00376 if(4 == m_debug){
00377 std::cout << "MdcxFindTracks " prt(fltLenUV) prt(phiStU) prt(phiStV) prt(omegag)<< std::endl;
00378 }
00379 if (fltLenUV > MdcxParameters::maxDlen) {
00380 if(4 == m_debug) std::cout<<"SKIP by fltLenUV > "<<MdcxParameters::maxDlen<<std::endl;
00381 break;
00382 }
00383 tanlg = (zintAV - zintAU)/fltLenUV;
00384 double fltLenAU = dlen(phiAx, phiStU, omegag);
00385 z0g = zintAU - fltLenAU*tanlg;
00386 if (4 == m_debug) cout prt(z0g) prt(tanlg) prt(fltLenUV) prt(zintAU) prt(zintAV)<< endl;
00387
00388
00389 if ((z0g < -MdcxParameters::maxMdcZLen) || (z0g > MdcxParameters::maxMdcZLen)) {
00390 if (4 == m_debug) std::cout<<"SKIP by z0g out of range "<<z0g<<">"<<MdcxParameters::maxMdcZLen<<std::endl;
00391 break;
00392 }
00393 ztest = z0g + fltAx*tanlg;
00394 if (4 == m_debug) std::cout prt(ztest) prt(fltAx)<<std::endl;
00395
00396
00397
00398 MdcxHel ghel(segList[iAx]->D0(), segList[iAx]->Phi0(), segList[iAx]->Omega(),
00399 ztest, tanlg, 0.0, 11111, 0, segList[iAx]->Xref(), segList[iAx]->Yref());
00400
00401 MdcxFittedHel firstfit(hitlist,ghel,helixFitSigma);
00402 first_prob = firstfit.Prob();
00403 if (4 == m_debug) {
00404 std::cout<<" after first fit: "<<std::endl;
00405 firstfit.FitPrint();
00406 }
00407 if (first_prob >= probmin) {
00408 MdcxHel helixOrigin= TakeToOrigin(firstfit);
00409 MdcxFittedHel nextfit(hitlist,helixOrigin,helixFitSigma);
00410 first_prob = nextfit.Prob();
00411 fithel=nextfit;
00412 if (g_trklgood) for (int i=0; i<nextfit.Nhits(); i++){ g_trklgood->fill(nextfit.Layer(i));}
00413 }
00414 if ( g_trklfirstProb) g_trklfirstProb->fill(first_prob);
00415 if (4 == m_debug) cout << " prob after helix fitting = " << first_prob << endl;
00416 floop = 0;
00417 }
00418
00419
00420
00421
00422
00423 floop = 1;
00424 while (floop) {
00425 if (4 == m_debug) std::cout<< "---------4.2 straight line fit------"<< std::endl;
00426 if (4 == m_debug) cout << " zintAU_sl " << zintAU_sl << " zintAV_sl " << zintAV_sl << endl;
00427 if (first_prob > probmin) {
00428 if (4 == m_debug) cout << " helix fit good , exit straight line fit." << endl;
00429 break;
00430 }
00431
00432 if ( (zintAU_sl < -MdcxParameters::maxMdcZLen) ||
00433 (zintAU_sl > MdcxParameters::maxMdcZLen) ) break;
00434 if ( (zintAV_sl < -MdcxParameters::maxMdcZLen) ||
00435 (zintAV_sl > MdcxParameters::maxMdcZLen) ) break;
00436
00437 double dx = xl2_sl - xl1_sl;
00438 double dy = yl2_sl - yl1_sl;
00439 double dl = sqrt(dx*dx + dy*dy);
00440 tanlg_sl = (zintAV_sl - zintAU_sl)/dl;
00441 dx = xl1_sl + d0g_sl*sin(phi0g_sl);
00442 dy = yl1_sl - d0g_sl*cos(phi0g_sl);
00443 dl = sqrt(dx*dx + dy*dy);
00444 z0g_sl = zintAU_sl - dl*tanlg_sl;
00445 if (4 == m_debug) cout prt(d0g_sl) prt(phi0g_sl) prt(z0g_sl) prt(tanlg_sl)<< endl;
00446
00447 if ((z0g_sl < -MdcxParameters::maxMdcZLen) || (z0g_sl > MdcxParameters::maxMdcZLen)){
00448 if(4 == m_debug) std::cout << "SKIP by z0g_sl:"<<z0g_sl<<" > "<<MdcxParameters::maxMdcZLen << std::endl;
00449 break;
00450 }
00451
00452 ztest_sl = z0g_sl + fltL_sl*tanlg_sl;
00453 if (4 == m_debug) cout prt(ztest_sl) << endl;
00454
00455
00456 MdcxHel ghel(segList[iAx]->D0_sl_approx(), segList[iAx]->Phi0_sl_approx(), omegag_sl,
00457 ztest_sl, tanlg_sl, 0.0, 11111, 0, segList[iAx]->Xref(), segList[iAx]->Yref());
00458
00459 MdcxFittedHel firstfit(hitlist, ghel, helixFitSigma);
00460 first_prob = firstfit.Prob();
00461
00462 if(4 == m_debug){
00463 ghel.print();
00464 std::cout <<"first_prob "<<first_prob << std::endl;
00465 }
00466
00467 if (first_prob >= probmin) {
00468 MdcxHel helixOrigin = TakeToOrigin(firstfit);
00469 MdcxFittedHel nextfit(hitlist, helixOrigin, helixFitSigma);
00470 first_prob = nextfit.Prob();
00471 fithel = nextfit;
00472 if (4 == m_debug) {
00473 cout << " three seg sl nextfit" << endl;
00474 nextfit.FitPrint();
00475 }
00476 }
00477 floop = 0;
00478 }
00479
00480
00481
00482
00483 floop = 1;
00484 while (floop) {
00485 floop = 0;
00486 if(4 == m_debug)std::cout<< "---------5. try add seg to helix------"<< std::endl;
00487 if (first_prob < probmin) {
00488 if(4 == m_debug) std::cout<< "prob"<<first_prob<< " "
00489 <<probmin<<" fit NOT good, exit add segs "<< std::endl;
00490 break;
00491 }
00492 float bchisq = fithel.Chisq()*helixFitSigma*helixFitSigma;
00493 int bndof = fithel.Nhits() - 5;
00494 float bprob = Mdcxprobab(bndof, bchisq);
00495 trkCount++;
00496 segList[iAx]->SetUsedOnHel(trkCount);
00497 segList[iStU]->SetUsedOnHel(trkCount);
00498 segList[iStV]->SetUsedOnHel(trkCount);
00499
00500 if (4 == m_debug){
00501 cout << "in add seg to trail helix, klm seg:" << endl;
00502 segList[iAx]->printSeg();
00503 segList[iStU]->printSeg();
00504 segList[iStV]->printSeg();
00505 }
00506
00507
00508 for (int iSlay = 0; iSlay < Constants::nSuperLayer; iSlay++) {
00509 int ilay = MdcxParameters::layerSet2AddSeg[iSegCombo][iSlay];
00510 for (int iSeg = 0; iSeg < nSeg; iSeg++) {
00511 if ((segList[iSeg]->SuperLayer(0) != ilay)
00512 ||(segList[iSeg]->GetUsedOnHel() != 0)
00513 || (segList[iSeg]->Fail() != 0)
00514 || (segList[iSeg]->Origin() != -1)) continue;
00515 if(4 == m_debug) {
00516 std::cout<< "try to add seg No."<< iSeg<<" to track "<< std::endl;
00517 segList[iSeg]->printSeg();
00518 }
00519
00520
00521 float phiAxSeg = segList[iAx]->XHitList()[0]->phiMid();
00522 float phiAddSeg = segList[iSeg]->XHitList()[0]->phiMid();
00523 double phiKNSegDiff = fabs(phiAxSeg - phiAddSeg);
00524 if (phiKNSegDiff > 0.5*Constants::pi && phiKNSegDiff < 1.5*Constants::pi ) {
00525 if(4 == m_debug)std::cout<< " SKIP by seg phi diff of phi ,iAx:"<<
00526 phiAxSeg<<" iSeg:"<<phiAddSeg<<" diff:"<<phiKNSegDiff << std::endl;
00527 continue;
00528 }
00529
00530
00531 xp = segList[iSeg]->Xref() - segList[iSeg]->SinPhi0()*segList[iSeg]->D0();
00532 yp = segList[iSeg]->Yref() + segList[iSeg]->CosPhi0()*segList[iSeg]->D0();
00533 const HepAList<MdcxHit>& hitsSegAdd= segList[iSeg]->XHitList();
00534 double proca = fithel.Doca( hitsSegAdd[0]->wx(), hitsSegAdd[0]->wy(),
00535 hitsSegAdd[0]->wz(), xp, yp );
00536 if (g_trklproca) g_trklproca->fill(proca);
00537
00538
00539 if (!((fabs(proca) < MdcxParameters::maxProca) &&(fithel.Doca_Len() < fithel.Lmax())) ){
00540
00541 if(4 == m_debug){
00542 std::cout<< "SKIP by fabs(proca):"<< fabs(proca)<< " maxProca:"<<MdcxParameters::maxProca <<" Doca_Len:"<<fithel.Doca_Len() <<"<Lmax:"<<fithel.Lmax()<< std::endl;
00543 }
00544 }
00545
00546 if ((fabs(proca) < MdcxParameters::maxProca) && (fithel.Doca_Len() < fithel.Lmax())) {
00547 MdcxFittedHel newhel;
00548 newhel.Grow(fithel, hitsSegAdd);
00549 if (newhel.Nhits() != hitlist.length()) {
00550 if (4 == m_debug){
00551 cout << "try to add seg " << iSeg
00552 << ": prob " << newhel.Prob()
00553 <<" rcs "<<newhel.Rcs()<<" <=? "
00554 <<MdcxParameters::maxRcsInAddSeg << endl;
00555 }
00556
00557
00558 if (newhel.Prob() < probmin){
00559 if(4 == m_debug){ cout << "helix.prob " << newhel.Prob()
00560 << "<? "<<probmin<<" Fail=" << newhel.Fail()
00561 <<". and Call ReFit()"<< endl;
00562 }
00563 newhel.ReFit();
00564 }
00565 if(4 == m_debug) {
00566 cout << "newhel.prob " << newhel.Prob()
00567 << "<probmin "<<probmin<<" Fail=" << newhel.Fail() << endl;
00568 }
00569
00570 if ( (newhel.Prob() >= probmin) && (newhel.Fail() == 0) ) {
00571
00572 fithel = newhel;
00573 hitlist = newhel.XHitList();
00574 segList[iSeg]->SetUsedOnHel(trkCount);
00575 bchisq = fithel.Chisq()*helixFitSigma*helixFitSigma;
00576 bndof = fithel.Nhits() - 5;
00577 float tprob = Mdcxprobab(bndof, bchisq);
00578 if (tprob > bprob) bprob = tprob;
00579 if (4 == m_debug) {
00580 cout << "add seg " << iSeg << " with new hits; prob now " << newhel.Prob() << endl;
00581 cout << " add "; segList[iSeg]->printSeg();
00582 }
00583 }
00584 else{
00585 if(4 == m_debug)std::cout<<" helix fit failed"<<std::endl;
00586 }
00587 } else {
00588 segList[iSeg]->SetUsedOnHel(trkCount);
00589 if (4 == m_debug) cout << "segment " << iSeg << " added but no new hits" << endl;
00590 }
00591 }
00592 }
00593 }
00594 if (((fithel.Prob() < 0.90) && (fithel.Nhits() == 12)) || (fithel.Fail() != 0)) {
00595 for (int i = 0; i < nSeg; i++) { if (segList[i]->GetUsedOnHel() == trkCount) segList[i]->SetUsedOnHel(0); }
00596 trkCount--;
00597 break;
00598 }
00599
00600 if(4 == m_debug){
00601 std::cout<< "After add segs" << std::endl;
00602
00603 }
00604
00605
00606 if(4 == m_debug) std::cout<< "---------6. flip------"<< std::endl;
00607 fithel.flip();
00608
00609
00610 int kki = 0;
00611 int notduplicate = 1;
00612 while(MdcxTrklist[kki]) {
00613 if (4 == m_debug)std::cout<< "---------7. test saved track------"<< std::endl;
00614 const HepAList<MdcxHit>& junk=MdcxTrklist[kki]->XHitList();
00615 int overl = 0;
00616 int kkj = 0;
00617 while (junk[kkj]) {
00618 int kkl = 0;
00619 while (hitlist[kkl]) {
00620 if (hitlist[kkl] == junk[kkj]) overl++;
00621 kkl++;
00622 }
00623 kkj++;
00624 }
00625 if (4 == m_debug) cout << "overlap with track # " << kki << " is "
00626 << junk.length() << " hitList " << hitlist.length() << " overlap " << overl << endl;
00627 if ( (hitlist.length()/4.) <= overl) notduplicate = 0;
00628
00629
00630 kki++;
00631 }
00632
00633 if(g_trklhelix) for (int iHit=0; iHit<fithel.Nhits(); iHit++){ g_trklhelix->fill(fithel.Layer(iHit)); }
00634
00635
00636 if (notduplicate) {
00637 if(4 == m_debug) std::cout<< "---------8. test worth saving?------"<< std::endl;
00638 MdcxFittedHel *finehel = new MdcxFittedHel(hitlist, fithel);
00639
00640 if(4 == m_debug) {
00641 std::cout<<__FILE__
00642 <<" finehel Prob "<<finehel->Prob()
00643 <<" nhits "<<finehel->Nhits()
00644 <<" bprob "<< bprob
00645 <<" probmin "<< probmin
00646 <<" Fail "<< finehel->Fail()
00647 << std::endl;
00648 finehel->FitPrint();
00649 }
00650
00651 if (( (finehel->Prob()>0.001) || (finehel->Nhits()>=15) || (bprob>probmin)
00652
00653 ) && (finehel->Fail() == 0) ) {
00654 nfound++;
00655 sumprob += finehel->Prob();
00656
00657
00658
00659
00660 int nodrop = 0;
00661 if ((finehel->Prob() > 0.05) || nodrop ) {
00662 MdcxTrklist.append(finehel);
00663
00664 for (int iHit=0; iHit<finehel->Nhits(); iHit++){
00665 if(g_trklappend1) g_trklappend1->fill(finehel->Layer(iHit));
00666 }
00667
00668 } else {
00669 MdcxFittedHel* drophel = new MdcxFittedHel( drophits(finehel) );
00670 float ratdrop = float(drophel->Nhits()) / float(finehel->Nhits());
00671 if ((drophel->Prob() > finehel->Prob()) &&
00672 (ratdrop > 0.50) && (drophel->Fail() == 0)) {
00673 if (4 == m_debug) cout << "Track " << trkCount << " drops "
00674 << finehel->Nhits()-drophel->Nhits() << " hits" << endl;
00675 MdcxTrklist.append(drophel);
00676 if(g_trklappend2) for (int iHit=0;iHit<drophel->Nhits();iHit++){g_trklappend2->fill(drophel->Layer(iHit));}
00677 delete finehel;
00678 } else {
00679 MdcxTrklist.append(finehel);
00680 if(g_trklappend3)for(int iHit=0;iHit<finehel->Nhits();iHit++){g_trklappend3->fill(finehel->Layer(iHit));}
00681 delete drophel;
00682 }
00683 }
00684
00685
00686 int nwl = MdcxTrklist.length() - 1;
00687 if ((4 == m_debug) && (nwl > -1)) {
00688 if (4 == m_debug) {
00689 cout << endl << "found track " << trkCount<<std::endl;
00690 MdcxTrklist[nwl]->print();
00691 MdcxTrklist[nwl]->FitPrint();
00692 }
00693 }
00694 } else {
00695 for (int i = 0; i < nSeg; i++) {
00696 if (segList[i]->GetUsedOnHel() == trkCount) segList[i]->SetUsedOnHel(0);
00697 }
00698 delete finehel;
00699 trkCount--;
00700 }
00701 }
00702 }
00703 }
00704 }
00705 }
00706 if(4==m_debug) cout<< "end of this combo"<<endl;
00707 }
00708 if(4== m_debug) cout << " In MdcxFindTracks, found " << trkCount << " good tracks" << endl;
00709 }