#include <MdcSegGrouper.h>
Inheritance diagram for MdcSegGrouper:
Public Member Functions | |
int | combineSegs (MdcTrack *&, MdcSeg *seed, TrkContext &, double trackT0, double maxSegChisqO) |
int | combineSegs (MdcTrack *&, MdcSeg *seed, TrkContext &, double trackT0, double maxSegChisqO) |
void | dumpSegList () |
void | dumpSegList () |
virtual int | incompWithGroup (MdcSeg **segGroup, const MdcSeg *testSeg, int iply)=0 |
virtual int | incompWithGroup (MdcSeg **segGroup, const MdcSeg *testSeg, int iply)=0 |
virtual int | incompWithSeg (const MdcSeg *refSeg, const MdcSeg *testSeg)=0 |
virtual int | incompWithSeg (const MdcSeg *refSeg, const MdcSeg *testSeg)=0 |
int | nextGroup (MdcSeg **segGroup, bool printit) |
int | nextGroup (MdcSeg **segGroup, bool printit) |
int | nPly () const |
int | nPly () const |
virtual void | resetComb (const MdcSeg *seed)=0 |
virtual void | resetComb (const MdcSeg *seed)=0 |
void | resetGap (int nGap) |
void | resetGap (int nGap) |
virtual MdcTrack * | storePar (MdcTrack *trk, double parms[2], double chisq, TrkContext &, double trackT0)=0 |
virtual MdcTrack * | storePar (MdcTrack *trk, double parms[2], double chisq, TrkContext &, double trackT0)=0 |
void | transferHits (MdcTrack *track, int nSegs, MdcSeg **segGroup) |
void | transferHits (MdcTrack *track, int nSegs, MdcSeg **segGroup) |
int | updateGap () |
int | updateGap () |
virtual | ~MdcSegGrouper () |
virtual | ~MdcSegGrouper () |
Protected Member Functions | |
MdcSegGrouper (const MdcDetector *gm, int nDeep, int debug) | |
MdcSegGrouper (const MdcDetector *gm, int nDeep, int debug) | |
void | resetSegCounters () |
void | resetSegCounters () |
Protected Attributes | |
int | _debug |
const MdcDetector * | _gm |
const MdcDetector * | _gm |
HepAList< MdcSeg > ** | combList |
HepAList< MdcSeg > ** | combList |
int * | currentSeg |
int * | currentSeg |
int * | firstBad |
int * | firstBad |
int * | firstGood |
int * | firstGood |
int * | gapCounter |
int * | gapCounter |
bool ** | isValid |
bool ** | isValid |
bool * | leaveGap |
bool * | leaveGap |
bool | lTestGroup |
bool | lTestSingle |
int | maxNull |
int | nDeep |
int | nNull |
int | nPlyFilled |
HepAList< MdcSeg > * | segList |
HepAList< MdcSeg > * | segList |
Private Member Functions | |
MdcSegGrouper (const MdcSegGrouper &) | |
MdcSegGrouper (const MdcSegGrouper &) | |
MdcSegGrouper & | operator= (const MdcSegGrouper &) |
MdcSegGrouper & | operator= (const MdcSegGrouper &) |
|
00041 { 00042 //------------------------------------------------------------------------ 00043 delete [] segList; 00044 delete [] combList; 00045 delete [] currentSeg; 00046 delete [] leaveGap; 00047 delete [] gapCounter; 00048 delete [] firstGood; 00049 delete [] firstBad; 00050 if (isValid != 0) { 00051 for (int i = 0; i < nDeep; i++) { 00052 delete [] isValid[i]; 00053 } 00054 delete [] isValid; 00055 } 00056 00057 }
|
|
00059 { 00060 //------------------------------------------------------------------------ 00061 nDeep = nd; 00062 int nsuper = gm->nSuper(); 00063 segList = new HepAList<MdcSeg>[nsuper]; 00064 currentSeg = new int[nDeep]; 00065 leaveGap = new bool[nDeep]; 00066 gapCounter = new int[nDeep]; 00067 combList = new HepAList<MdcSeg> * [nDeep]; 00068 _gm = gm; 00069 firstGood = new int[nDeep]; 00070 firstBad = new int[nDeep]; 00071 lTestGroup = false; 00072 lTestSingle = false; 00073 _debug = debug; 00074 }
|
|
|
|
|
|
|
|
|
|
|
|
00248 { 00249 //************************************************************************/ 00250 // forms track from list of segs; does 2-param fit (either r-phi from origin 00251 // or s-z) and picks best combination. 00252 bool lSeed = (seed != 0); 00253 00254 double wgtmat[3], wgtinv[3]; 00255 double wgtpar[2]; 00256 double temvec[2], param[2], diff[2]; 00257 int success = 0; 00258 double qualBest = -1000.; 00259 int nSegBest = 0; 00260 int nHitBest = 0; 00261 double paramBest[2]; 00262 double chiBest = 9999.; 00263 int nToUse = nPly(); 00264 if (lSeed) nToUse++; // seed isn't included in the segs list 00265 MdcSeg **segGroup; 00266 MdcSeg **segGroupBest; 00267 segGroup = new MdcSeg * [nToUse]; 00268 segGroupBest = new MdcSeg * [nToUse]; 00269 // static int counter = 0; 00270 // counter++; 00271 // cout << counter << endl; 00272 00273 // Loop over all combinations of segs consistent with seed (including gaps) 00274 if ((3 == _debug)&&lSeed) { 00275 std::cout<<"seed segment: "<< std::endl; 00276 seed->plotSeg(); 00277 } 00278 resetComb(seed); 00279 00280 // Save seed params (if angles) for later use as reference angle in 00281 // mdcWrapAng (don't really have to test whether it's an angle, but I do) 00282 double seedAngle[2] = {0.,0.}; 00283 if (lSeed) { 00284 if (seed->info()->parIsAngle(0)) seedAngle[0] = seed->info()->par(0); 00285 if (seed->info()->parIsAngle(1)) seedAngle[1] = seed->info()->par(1); 00286 } 00287 00288 int iprint = (3 == _debug); 00289 int nInGroup = 0; 00290 while ( (nInGroup = nextGroup(segGroup, iprint)) != 0) { 00291 if (lSeed) { 00292 segGroup[nToUse-1] = seed; 00293 nInGroup++; 00294 } 00295 00296 if (nInGroup < 0) continue; 00297 if (nInGroup < 2) break; 00298 if (nInGroup < nSegBest) break; 00299 00300 // Calculate track & chisq for this group 00301 int nSegFit = 0; 00302 int nhit = 0; 00303 wgtmat[0] = wgtmat[1] = wgtmat[2] = wgtpar[0] = wgtpar[1] = 0.0; 00304 00305 if (3 == _debug) { 00306 cout << endl <<"--parameters of "<<nInGroup<<" segment in this group"<<endl; 00307 } 00308 int iPly; 00309 for (iPly = 0; iPly < nToUse; iPly++) { 00310 if (3 == _debug) { 00311 //if (!lSeed) //if (segGroup[iPly] == 0) cout << "ply empty: " << iPly << "\n"; 00312 } 00313 if (segGroup[iPly] == 0) continue; // skipping this slayer 00314 nSegFit++; 00315 MdcSegInfo *segInfo = segGroup[iPly]->info(); 00316 // Accumulate sums 00317 for (int i = 0; i < 3; i++) wgtmat[i] += (segInfo->inverr())[i]; 00318 for (int k = 0; k < 2; k++) { 00319 param[k] = segInfo->par(k); 00320 //zhangy add 00321 if (segInfo->parIsAngle(k)) { 00322 param[k] = mdcWrapAng(seedAngle[k], param[k]); 00323 } 00324 } 00325 // Multiply by weight matrix. 00326 mdcTwoVec( segInfo->inverr(), param, temvec ); 00327 wgtpar[0] += temvec[0]; 00328 wgtpar[1] += temvec[1]; 00329 if(3 == _debug) { 00330 std::cout<<" par * W "<<temvec[0]<<" "<<temvec[1]<< std::endl; 00331 } 00332 nhit += segGroup[iPly]->nHit(); 00333 } 00334 00335 // And the fitted parameters are . . . 00336 int error = mdcTwoInv(wgtmat,wgtinv); 00337 if (error && (3 == _debug)) { 00338 cout << "ErrMsg(warning) " 00339 << "failed matrix inversion in MdcTrackList::combineSegs" << endl; 00340 continue; 00341 } 00342 mdcTwoVec( wgtinv, wgtpar, param ); 00343 00344 if(_debug==3)cout<<endl<<"-- Calculate track & chisq for this group "<<endl; 00345 00346 // Calc. chisq. = sum( (Vi - V0) * W * (Vi - V0) ) 00347 // W = weight, Vi = measurement, V0 = fitted param. 00348 double chisq = 0.0; 00349 for (iPly = 0; iPly < nToUse; iPly++) { 00350 if (segGroup[iPly] == 0) continue; // skipping this slayer 00351 MdcSegInfo *segInfo = segGroup[iPly]->info(); 00352 for (int j = 0; j < 2; j++) { 00353 double temPar; 00354 if (segInfo->parIsAngle(j)) { 00355 temPar = mdcWrapAng(seedAngle[j], segInfo->par(j)); 00356 } 00357 else { 00358 temPar = segInfo->par(j); 00359 } 00360 if(3 == _debug) { 00361 std::cout<<" segPar"<<j<<" "<<temPar<< std::endl; 00362 } 00363 diff[j] = temPar - param[j]; 00364 } 00365 00366 if(3 == _debug) { 00367 std::cout<<"inverr " <<segInfo->inverr()[0]<<" " 00368 <<segInfo->inverr()[1] <<" "<<segInfo->inverr()[2] << std::endl; 00369 std::cout<<"errmat " <<segInfo->errmat()[0]<< " " 00370 <<segInfo->errmat()[1] << " "<<segInfo->errmat()[2] << std::endl; 00371 std::cout<< std::endl; 00372 } 00373 mdcTwoVec( segInfo->inverr(), diff, temvec); 00374 00375 chisq += diff[0] * temvec[0] + diff[1] * temvec[1]; 00376 00377 if(3 == _debug){ 00378 std::cout<<iPly<<" chi2Add:"<<diff[0] * temvec[0] + diff[1] * temvec[1]<<" diff0 "<<setw(10) << diff[0]<< " vec0 "<<setw(10)<<temvec[0]<<" diff1 "<<setw(10) 00379 << diff[1]<< " vec1 "<<setw(10)<<temvec[1] << std::endl; 00380 } 00381 } 00382 if (3 == _debug) { 00383 cout << "Candidate track:"<<endl<<" chisq: " 00384 << chisq << " nhit: " << nhit << " cpa/cot: " << 00385 param[0] << " phi0/z0: " << param[1] << endl; 00386 std::cout<< "chiDof="<<chisq/(2*nSegFit - 2) 00387 <<" maxSegChisqO="<<maxSegChisqO << std::endl;//yzhang debug 00388 if((chisq/(2*nSegFit - 2))<maxSegChisqO) cout << "---KEEP!---"<<endl; 00389 else cout << "---DROP!---"<<endl; 00390 } 00391 if (chisq < 0.) continue;//yzhang add 00392 // Chisq test 00393 double chiDof = chisq/(2.*nSegFit - 2.); 00394 if (g_maxSegChisqO ) { g_maxSegChisqO->fill(chiDof); } //yzhang hist cut 00395 if (chiDof > maxSegChisqO) continue; 00396 success = 1; 00397 double qual = 2. * nhit - chiDof; 00398 if (qual > qualBest) { 00399 qualBest = qual; 00400 nSegBest = nSegFit; 00401 nHitBest = nhit; 00402 paramBest[0] = param[0]; 00403 paramBest[1] = param[1]; 00404 chiBest = chisq; 00405 for (int i = 0; i < nToUse; i++) { 00406 segGroupBest[i] = segGroup[i]; 00407 //std::cout<<__FILE__<<" "<<__LINE__<<" Keep BEST"<< std::endl; 00408 } 00409 }// end test on qual 00410 } 00411 00412 if (success == 1) { 00413 // Store the results in a track, possibly creating it in the process 00414 trk = storePar(trk, paramBest, chiBest, context, t0); 00415 transferHits(trk, nToUse, segGroupBest); // Store hits with track 00416 } 00417 delete [] segGroupBest; 00418 delete [] segGroup; 00419 return success; 00420 }
|
|
|
|
00469 { 00470 //************************************************************************ 00471 for(int islayer=0; islayer<11; islayer++){ 00472 for(int i=0; i<segList[islayer].length(); i++){ 00473 segList[islayer][i]->plotSeg(); 00474 } 00475 } 00476 }
|
|
Implemented in MdcSegGrouperAx, MdcSegGrouperCsmc, MdcSegGrouperSt, MdcSegGrouperAx, MdcSegGrouperCsmc, and MdcSegGrouperSt. |
|
Implemented in MdcSegGrouperAx, MdcSegGrouperCsmc, MdcSegGrouperSt, MdcSegGrouperAx, MdcSegGrouperCsmc, and MdcSegGrouperSt. |
|
Implemented in MdcSegGrouperAx, MdcSegGrouperCsmc, MdcSegGrouperSt, MdcSegGrouperAx, MdcSegGrouperCsmc, and MdcSegGrouperSt. |
|
Implemented in MdcSegGrouperAx, MdcSegGrouperCsmc, MdcSegGrouperSt, MdcSegGrouperAx, MdcSegGrouperCsmc, and MdcSegGrouperSt. |
|
|
|
00079 { 00080 //------------------------------------------------------------------------ 00081 00082 // Loop over the superlayers, moving to next valid seg for each if necessary 00083 // First, loop over the slayers w/o good segs, filling segGroup w/ 0 00084 int iply; 00085 for (iply = nPlyFilled; iply < nDeep; iply++) { 00086 segGroup[iply] = 0; 00087 } 00088 00089 restart: 00090 if (printit) cout <<endl<< "MdcSegGrouper::nextGroup starting group finder, nply = " << nPlyFilled << endl; 00091 int nFound = 0; 00092 bool incrementNext = true; 00093 //int nSegUsed;//yzhang 2010-05-21 00094 for (iply = 0; iply < nPlyFilled; iply++) { 00095 segGroup[iply] = 0; 00096 if (!incrementNext && currentSeg[iply] >= firstGood[iply]) break; 00097 //if (nSegUsed > segPar.nSegUsedNextGroup) break; 00098 if (leaveGap[iply]) { 00099 // This ply is currently a gap; move on. 00100 if (iply == nPlyFilled - 1 && incrementNext) { 00101 // we've exhausted this gap group; start another 00102 iply = -1; 00103 resetSegCounters(); 00104 int lDone = updateGap(); 00105 if (lDone) { 00106 // all gap groups for nNull exhausted; increment nNull 00107 nNull++; 00108 if (nNull > maxNull) return 0; // All done 00109 resetGap(nNull); 00110 updateGap(); 00111 } // end if lDone 00112 } //end if exhausted gap group 00113 continue; 00114 } 00115 incrementNext = false; 00116 00117 // Loop through the segs in this ply until valid one found 00118 while (1) { 00119 currentSeg[iply]++; 00120 if (currentSeg[iply] == firstBad[iply]) { // reached end of segs 00121 incrementNext = true; 00122 currentSeg[iply] = firstGood[iply]; 00123 if (iply == nPlyFilled - 1) { 00124 // we've exhausted this gap group; start another 00125 iply = -1; 00126 resetSegCounters(); 00127 int lDone = updateGap(); 00128 if (lDone) { 00129 // all gap groups for nNull exhausted; increment nNull 00130 nNull++; 00131 if (nNull > maxNull) return 0; // All done 00132 resetGap(nNull); 00133 updateGap(); 00134 } // end if lDone 00135 } //end if exhausted gap group 00136 break; 00137 } // end reached end of segs 00138 if(3 == _debug) { 00139 if( (*combList[iply])[currentSeg[iply]]->segUsed()) { 00140 std::cout<< "segUsed! :"; 00141 (*combList[iply])[currentSeg[iply]]->plotSeg(); 00142 } 00143 } 00144 //yzhang 09-09-28 delete 00145 if( (*combList[iply])[currentSeg[iply]]->segUsed()) { 00146 continue; //yzhang 2010-05-21 add 00147 //nSegUsed++; 00148 } 00149 00150 // Test this seg for validity 00151 if (lTestSingle) { 00152 assert(isValid != 0); 00153 assert(isValid[iply] != 0); 00154 int invalid = (isValid[iply][currentSeg[iply]] == false); 00155 if (invalid) continue; 00156 } 00157 00158 // Whew. We successfully incremented. 00159 break; 00160 00161 } // end seg loop 00162 } // end ply loop 00163 00164 // Fill segGroup with appropriate segs 00165 for (iply = 0; iply < nPlyFilled; iply++) { 00166 if (leaveGap[iply]) { 00167 segGroup[iply] = 0; 00168 } else { 00169 segGroup[iply] = (*combList[iply])[currentSeg[iply]]; 00170 if (lTestGroup && nFound > 1) { 00171 int lBad = incompWithGroup(segGroup, segGroup[iply], iply); 00172 if(printit && lBad )std::cout<<" incompWithGroup Bad! restart" << std::endl; 00173 if (lBad) goto restart; 00174 } 00175 nFound++; 00176 } 00177 } 00178 if (printit) { 00179 cout << "-- end of nextGroup, nSeg="<<nFound <<endl; 00180 for (iply = 0; iply < nPlyFilled; iply++) { 00181 std::cout<<iply<<": "; 00182 if(0 != segGroup[iply]) segGroup[iply]->plotSeg(); 00183 } 00184 } 00185 00186 return nFound; 00187 }
|
|
00054 {return nDeep;}
|
|
00054 {return nDeep;}
|
|
|
|
|
|
Implemented in MdcSegGrouperAx, MdcSegGrouperSt, MdcSegGrouperAx, and MdcSegGrouperSt. |
|
Implemented in MdcSegGrouperAx, MdcSegGrouperSt, MdcSegGrouperAx, and MdcSegGrouperSt. |
|
|
|
00190 { 00191 //************************************************************************** 00192 00193 for (int i = 0; i < nPlyFilled; i++) { 00194 gapCounter[i] = nGap - 1 - i; 00195 } 00196 gapCounter[0]--; // so 1st increment will put 1st counter in right place 00197 00198 return; 00199 }
|
|
|
|
00238 { 00239 //------------------------------------------------------------------------- 00240 for (int i = 0; i < nPlyFilled; i++) { 00241 currentSeg[i] = firstGood[i] - 1; 00242 } 00243 }
|
|
Implemented in MdcSegGrouperAx, MdcSegGrouperCsmc, MdcSegGrouperSt, MdcSegGrouperAx, MdcSegGrouperCsmc, and MdcSegGrouperSt. |
|
Implemented in MdcSegGrouperAx, MdcSegGrouperCsmc, MdcSegGrouperSt, MdcSegGrouperAx, MdcSegGrouperCsmc, and MdcSegGrouperSt. |
|
|
|
00423 { 00424 //************************************************************************/ 00425 //Move hits from segments to track hitlist 00426 // Also note first and last layers in list 00427 // Only handles Mdc segments 00428 double smallRad = 1000.; 00429 if (trk->firstLayer() != 0) smallRad = trk->firstLayer()->rMid(); 00430 double bigRad = 0.; 00431 if (trk->lastLayer() != 0) bigRad = trk->lastLayer()->rMid(); 00432 00433 for (int i = 0; i < nSegs; i++) { 00434 if (segGroup[i] == 0) continue; // skipping this slayer 00435 if(3 == _debug) { 00436 cout << i << " " << segGroup[i] << endl; 00437 } 00438 segGroup[i]->setUsed(); // mark seg as used 00439 for (int ihit = 0; ihit < segGroup[i]->nHit(); ihit++) { 00440 MdcHitUse *aHit = segGroup[i]->hit(ihit); 00441 const MdcLayer *layer = aHit->mdcHit()->layer(); 00442 double radius = layer->rMid(); 00443 if (radius < smallRad) { 00444 smallRad = radius; 00445 trk->setFirstLayer(layer); 00446 } 00447 00448 // Assume that segs aren't added to backside of curler 00449 if (radius > bigRad && !trk->hasCurled()) { 00450 bigRad = radius; 00451 trk->setLastLayer(layer); 00452 } 00453 // Provide very crude starting guess of flightlength 00454 double flt = radius; 00455 flt += 0.000001 * (aHit->mdcHit()->x() +aHit->mdcHit()->y()); 00456 00457 aHit->setFltLen(flt); 00458 00459 TrkHitList* theHits = trk->track().hits(); 00460 00461 if (theHits == 0) return; 00462 theHits->appendHit(*aHit); 00463 //std::cout<<"in MdcSegGrouper append ok"<<std::endl;//yzhang debug 00464 } 00465 } // end loop over slayers 00466 }
|
|
|
|
00202 { 00203 //************************************************************************** 00204 if (nNull == 0) return 1; 00205 00206 for (int i = 0; i < nPlyFilled; i++) { 00207 leaveGap[i] = false; 00208 } 00209 for (int igap = 0; igap < nNull; igap++) { 00210 gapCounter[igap]++; 00211 if (gapCounter[igap] == nPlyFilled - igap) { 00212 // End of loop for this counter; look at the other counters to 00213 // decide where this one should be reset to. 00214 int inext = igap + 1; 00215 while (1) { 00216 if (inext >= nNull) return 1; // done with all combos 00217 if (gapCounter[inext] + inext + 1 < nPlyFilled) { 00218 // This is the right spot to reset to 00219 gapCounter[igap] = gapCounter[inext] + inext + 1 - igap; 00220 break; 00221 } 00222 inext++; 00223 } 00224 } 00225 else { 00226 // We successfully incremented. Quit looping and return. 00227 break; 00228 } 00229 } // end loop over igap 00230 00231 for (int j = 0; j < nNull; j++) { 00232 leaveGap[gapCounter[j]] = true; 00233 } 00234 return 0; 00235 00236 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|