#include <MdcSegList.h>
Public Member Functions | |
MdcSegList (int nSupers, const MdcSegParams segParms) | |
~MdcSegList () | |
void | setPlot (int lPlt) |
void | plot () const |
const GmsList * | oneList (int slayIndex) const |
void | append (MdcSeg *aSeg) |
int | count () const |
void | destroySegs () |
MdcSeg * | getSeed (int iview, int goodOnly) |
void | resetSeed (const MdcDetector *gm) |
MdcSegParams * | segPar () |
Private Member Functions | |
void | sortByPhi () |
void | zeroSeed () |
void | tagAmbig () |
void | deleteDups (bool drop) |
void | massageSegs () |
Private Attributes | |
MdcSegParams | segParam |
GmsList * | segList |
int | _nsupers |
MdcSeg * | seedSeg [3] |
const MdcSuperLayer * | seedSlay [3] |
Friends | |
class | MdcSegFinder |
Definition at line 20 of file MdcSegList.h.
MdcSegList::MdcSegList | ( | int | nSupers, | |
const MdcSegParams | segParms | |||
) |
Definition at line 35 of file MdcSegList.cxx.
References _nsupers, segList, segParam, MdcSeg::setParam(), and zeroSeed().
00035 { 00036 /**************************************************************************/ 00037 segParam = segP; // bit-wise copy 00038 MdcSeg::setParam(&segParam); 00039 zeroSeed(); 00040 segList = new GmsList[nSlayer]; 00041 _nsupers = nSlayer; 00042 }
MdcSegList::~MdcSegList | ( | ) |
Definition at line 45 of file MdcSegList.cxx.
References segList.
00045 { 00046 /**************************************************************************/ 00047 delete [] segList; 00048 }
void MdcSegList::append | ( | MdcSeg * | aSeg | ) |
Definition at line 257 of file MdcSegList.cxx.
References GmsList::append(), MdcSuperLayer::index(), segList, and MdcSeg::superlayer().
Referenced by MdcSegFinder::tryPatterns().
00257 { 00258 /****************************************************************************/ 00259 segList[aSeg->superlayer()->index()].append(aSeg); 00260 }
int MdcSegList::count | ( | ) | const |
Definition at line 419 of file MdcSegList.cxx.
References _nsupers, genRecEmupikp::i, and segList.
Referenced by MdcTrackList::createFromSegs(), MdcSegFinder::createSegs(), massageSegs(), and sortByPhi().
00419 { 00420 //------------------------------------------------------------------------- 00421 int cnt = 0; 00422 for (int i = 0; i < _nsupers; i++) cnt += segList[i].count(); 00423 return cnt; 00424 }
void MdcSegList::deleteDups | ( | bool | drop | ) | [private] |
Definition at line 271 of file MdcSegList.cxx.
References _nsupers, _twopi, MdcSeg::chisq(), GmsList::count(), GmsList::first(), g_phiDiff, g_slopeDiff, MdcSegParams::lPrint, GmsListLink::next(), MdcSeg::nHit(), MdcLayer::nWires(), MdcSeg::phi(), MdcSegParams::phiDiffDropMult, MdcSeg::plotSeg(), GmsList::remove(), segList, segPar(), MdcSeg::setUsed(), MdcSeg::slope(), and MdcSegParams::slopeDiffDrop.
Referenced by massageSegs().
00271 { 00272 /****************************************************************************/ 00273 // Removes segments that have almost identical parameters. A bit risky, 00274 // perhaps, but what kind of life would you have if you never took 00275 // any risks? 00276 00277 // On second thought, offer the option of just marking them as used. 00278 00279 // Takes pairs of segments, and if they have the same slope and phi 00280 // (within cuts), selects better, using nHit and chisq. Note that 2 00281 // identical segs may be separated in list by non-identical 00282 00283 bool printit = (5 == segPar()->lPrint); 00284 00285 00286 if(printit) std::cout<< " =======MdcSegList::deleteDups()===== " << std::endl; 00287 00288 00289 for (int isuper = 0; isuper < _nsupers; isuper++) { 00290 if(isuper==10) continue;//yzhang add 2012-09-18 00291 GmsList *thisSegList = &segList[isuper]; 00292 if (thisSegList->count() < 2) continue; 00293 if(5 == segPar()->lPrint || 13 == segPar()->lPrint){ 00294 std::cout<<endl<< " -----slayer " << isuper<<"-----"<< std::endl; 00295 } 00296 00297 double thisphi, nextphi; 00298 double slopediff = segPar()->slopeDiffDrop; //FIXME 00299 00300 // Calculate road width for this slayer. 00301 const MdcLayer *aLayer = 00302 ((MdcSeg *)thisSegList->first())->superlayer()->firstLayer(); 00303 double width = _twopi / aLayer->nWires(); 00304 double phidiff = segPar()->phiDiffDropMult * width; //FIXME 00305 00306 int lWrapped = 0; 00307 00308 MdcSeg *startSeg = (MdcSeg *) thisSegList->first(); 00309 while ( startSeg != 0 ) { 00310 if (thisSegList->count() < 2) break; 00311 if (lWrapped) break; 00312 thisphi = startSeg->phi(); 00313 MdcSeg *nextSeg = startSeg; 00314 if(5 == segPar()->lPrint || 13 == segPar()->lPrint){ 00315 startSeg->plotSeg();std::cout<<std::endl; 00316 } 00317 00318 while (1) { // loop over nextSeg 00319 nextSeg = (MdcSeg *) nextSeg->next(); 00320 if (nextSeg == 0) { 00321 nextSeg = (MdcSeg *) thisSegList->first(); 00322 if (lWrapped == 1) break; // cluster covers 2pi; run, screaming 00323 lWrapped = 1; 00324 } 00325 if( nextSeg == startSeg ) break;//yzhang add 2011-06-16 00326 nextphi = nextSeg->phi(); 00327 00328 if (nextphi < thisphi) nextphi += _twopi; 00329 00330 if(printit){ 00331 std::cout<<std::endl<<"----start "; startSeg->plotSeg(); std::cout<<std::endl; 00332 std::cout<<" next "; nextSeg->plotSeg(); std::cout<<std::endl; 00333 std::cout<<" phi diff "<< nextphi -thisphi << " cut phidiff "<<phidiff; 00334 std::cout<<" slope diff "<< nextSeg->slope() - startSeg->slope() 00335 << " cut slopdiff "<<slopediff<<std::endl; 00336 } 00337 00338 if (g_phiDiff) {g_phiDiff->fill((nextphi - thisphi)/width);}//yzhang hist cut 00339 if (g_slopeDiff) {g_slopeDiff->fill(nextSeg->slope() - startSeg->slope());}//yzhang hist cut 00340 00341 if (nextphi - thisphi > phidiff) { 00342 if(printit){ std::cout<< " --not same phi" <<std::endl; } 00343 // Done with this segment (aSeg) 00344 startSeg = (MdcSeg *) startSeg->next(); 00345 break; 00346 } else if (fabs( nextSeg->slope() - startSeg->slope() ) > slopediff) { 00347 if(printit){ std::cout<< " --attached, but not identical -- move on to next nextSeg "<< std::endl; } 00348 // attached, but not identical -- move on to next nextSeg 00349 continue; 00350 } else { 00351 // identical; choose better 00352 int firstBetter = 0; 00353 assert (startSeg->nHit() > 2); 00354 double chiFirst = startSeg->chisq() / (startSeg->nHit() - 2); 00355 assert (nextSeg->nHit() > 2); 00356 double chiNext = nextSeg->chisq() / (nextSeg->nHit() - 2); 00357 double theDiff; 00358 int cdiff = (int) nextSeg->nHit() - (int) startSeg->nHit(); 00359 theDiff = (chiFirst - chiNext) + 2. * (cdiff); 00360 if (theDiff < 0.) firstBetter = 1; 00361 if(printit){ 00362 std::cout<< " --identical; choose better "<< std::endl; 00363 std::cout<< " chi start "<<chiFirst<<" chi next "<< chiNext<<" cdiff "<<cdiff<< std::endl; 00364 } 00365 00366 if (firstBetter) { 00367 if(printit){ std::cout<< " startSeg better,"; } 00368 MdcSeg *tempSeg = nextSeg; 00369 nextSeg = (MdcSeg *) nextSeg->next(); 00370 if (ldrop) { 00371 if(printit){ std::cout<< " delete nextSeg"<<std::endl; } 00372 thisSegList->remove(tempSeg); 00373 delete tempSeg; 00374 } else { 00375 if(printit){ std::cout<< " nextSeg->setUsed(true) "<<std::endl; } 00376 tempSeg->setUsed(); 00377 } 00378 if (nextSeg == 0) { 00379 nextSeg = (MdcSeg *) thisSegList->first(); 00380 if (lWrapped == 1) break; // cluster covers 2pi; run, screaming 00381 lWrapped = 1; 00382 } 00383 } else { 00384 if(printit){ std::cout<< " nextSeg better,"; } 00385 MdcSeg *tempSeg = startSeg; 00386 startSeg = (MdcSeg *) startSeg->next(); 00387 if (ldrop) { 00388 if(printit){ std::cout<< " delete startSeg"<<std::endl; } 00389 thisSegList->remove(tempSeg); 00390 delete tempSeg; 00391 } else { 00392 if(printit){ std::cout<< " startSeg->setUsed(true) "<<std::endl; } 00393 tempSeg->setUsed(); 00394 } 00395 break; 00396 } 00397 00398 } // end if identical 00399 } // end loop over nextSeg 00400 00401 } // end primary loop over segments 00402 } // end loop over superlayers 00403 }
void MdcSegList::destroySegs | ( | ) |
Definition at line 92 of file MdcSegList.cxx.
References _nsupers, first, genRecEmupikp::i, GmsListLink::next(), GmsList::remove(), segList, and zeroSeed().
00092 { 00093 /****************************************************************************/ 00094 00095 zeroSeed(); 00096 MdcSeg *aSeg, *bSeg; 00097 for (int i = 0; i < _nsupers; i++) { 00098 aSeg = (MdcSeg *) segList[i].first(); 00099 while (aSeg != 0) { 00100 bSeg = (MdcSeg *) aSeg->next(); 00101 segList[i].remove( aSeg ); 00102 delete aSeg ; 00103 aSeg = bSeg; 00104 } 00105 } 00106 return; 00107 }
MdcSeg * MdcSegList::getSeed | ( | int | iview, | |
int | goodOnly | |||
) |
Definition at line 139 of file MdcSegList.cxx.
References GmsList::first(), next, MdcSeg::nHit(), oneList(), MdcSuperLayer::prevInView(), seedSeg, and seedSlay.
Referenced by MdcTrackListCsmc::createFromSegs(), and MdcTrackList::createFromSegs().
00139 { 00140 //*************************************************************************** 00141 00142 // Find a suitable segment for starting a track. If goodOnly=1, look for 00143 // isolated, unambiguous segments; unambiguous is 00144 // defined as being the only segment within a band in phiseg (typically 00145 // 2 cell widths wide), or as differing only slightly from nearby 00146 // segments in phi and slope. When these have been exhausted, take any 00147 // unused segment. Return pointer to seed seg, or 0 if none found. 00148 00149 int viewIndex = iview + 1; 00150 if (seedSlay[viewIndex] == 0) return 0; 00151 while (1) { 00152 //if(seedSeg[viewIndex] != 0){ 00153 //seedSeg[viewIndex]->plotSeg(0,0);//yzhang debug 00154 //std::cout<<__FILE__<<" "<<__LINE__<<" goodOnly "<<goodOnly<< std::endl; 00155 //} 00156 if (seedSeg[viewIndex] == 0) { 00157 //seedSlay[viewIndex] = seedSlay[viewIndex]->nextInView();//yzhang temp 00158 seedSlay[viewIndex] = seedSlay[viewIndex]->prevInView(); //yzhang del 00159 if (seedSlay[viewIndex] == 0) return 0; 00160 seedSeg[viewIndex] = (MdcSeg *) 00161 oneList(seedSlay[viewIndex]->index())->first(); 00162 } // We have a segment; is it a viable seed? 00163 else if (seedSeg[viewIndex]->segUsed()) { 00164 //std::cout<<__FILE__<<" segUsed " << std::endl; 00165 seedSeg[viewIndex] = (MdcSeg *) seedSeg[viewIndex]->next(); 00166 } 00167 else if (seedSeg[viewIndex]->segAmbig() && goodOnly) { 00168 //std::cout<<__FILE__<<" segAmbig && goodOnly" << std::endl; 00169 seedSeg[viewIndex] = (MdcSeg *) seedSeg[viewIndex]->next(); 00170 //yzhang delete 09-10-10 00171 //delete (!seedSeg[viewIndex]->segAmbig() && !goodOnly) 00172 } //yzhang add 09-09-28 00173 else if ( !seedSeg[viewIndex]->segFull() && goodOnly) { 00174 //std::cout<<__FILE__<<" segFull && goodOnly" << std::endl; 00175 seedSeg[viewIndex] = (MdcSeg *) seedSeg[viewIndex]->next(); 00176 //zhangy add 00177 } else { 00178 // Reject segments with a lot of used hits 00179 int nused = 0; 00180 int navail = seedSeg[viewIndex]->nHit(); 00181 for (int ihit = 0; ihit < seedSeg[viewIndex]->nHit(); ihit++) { 00182 MdcHitUse *ahit = seedSeg[viewIndex]->hit(ihit); 00183 if ( ahit->mdcHit()->usedHit() ) nused++; 00184 } 00185 // Minimum 2 unused hits (but allow special-purpose segs w/ 0 hits) 00186 if (navail - nused < 2 && navail > 0) { 00187 seedSeg[viewIndex] = (MdcSeg *) seedSeg[viewIndex]->next(); 00188 } else { 00189 //std::cout<<__FILE__<<" Reject segments with a lot of used hits" << std::endl; 00190 break; 00191 } 00192 } 00193 /* 00194 if(seedSeg[viewIndex]!=0){ 00195 seedSeg[viewIndex]->plotSeg(); 00196 std::cout<< __FILE__ << " " << __LINE__ << " goodOnly " 00197 <<goodOnly<<" viewIndex "<<viewIndex<< " full "<<seedSeg[viewIndex]->segFull() <<std::endl; 00198 } 00199 */ 00200 } 00201 00202 // We have a seed 00203 MdcSeg *theSeed = seedSeg[viewIndex]; 00204 seedSeg[viewIndex] = (MdcSeg *) seedSeg[viewIndex]->next(); 00205 00206 return theSeed; 00207 }
void MdcSegList::massageSegs | ( | ) | [private] |
Definition at line 262 of file MdcSegList.cxx.
References count(), deleteDups(), MdcSegParams::dropDups, segPar(), sortByPhi(), and tagAmbig().
Referenced by MdcSegFinder::createSegs().
00262 { 00263 /****************************************************************************/ 00264 sortByPhi(); 00265 // Delete duplicates only if there are too many segments 00266 bool drop = (segPar()->dropDups && count() > 200);//yzhang FIXME 00267 deleteDups(drop); 00268 tagAmbig(); 00269 }
const GmsList * MdcSegList::oneList | ( | int | slayIndex | ) | const |
Definition at line 412 of file MdcSegList.cxx.
References segList.
Referenced by MdcSegGrouperSt::fillWithSegs(), MdcSegGrouperCsmc::fillWithSegs(), MdcSegGrouperAx::fillWithSegs(), getSeed(), and resetSeed().
00412 { 00413 //------------------------------------------------------------------------- 00414 return &segList[slayIndex]; 00415 }
void MdcSegList::plot | ( | ) | const |
Definition at line 75 of file MdcSegList.cxx.
References _nsupers, first, genRecEmupikp::i, GmsListLink::next(), MdcSeg::plotSegAll(), and segList.
00075 { 00076 /**************************************************************************/ 00077 00078 MdcSeg *aSeg; 00079 for (int i = 0; i < _nsupers; i++) { 00080 std::cout << " ---------------MdcSeg of Slayer "<<i<<"-------------" << std::endl; 00081 00082 aSeg = (MdcSeg *) segList[i].first(); 00083 while (aSeg != 0) { 00084 aSeg->plotSegAll(); 00085 std::cout << endl; 00086 aSeg = (MdcSeg *) aSeg->next(); 00087 } 00088 } 00089 }
void MdcSegList::resetSeed | ( | const MdcDetector * | gm | ) |
Definition at line 57 of file MdcSegList.cxx.
References GmsList::first(), MdcDetector::lastSlayInView(), oneList(), seedSeg, and seedSlay.
Referenced by MdcTrackListCsmc::createFromSegs(), MdcTrackList::createFromSegs(), and MdcSegFinder::createSegs().
00057 { 00058 /**************************************************************************/ 00059 00060 for (int iview = -1; iview <= 1; iview++) { 00061 int viewIndex = iview + 1; 00062 /* 00063 if(0 == iview){ 00064 seedSlay[viewIndex] = gm->firstSlayInView(iview); 00065 }else{ 00066 seedSlay[viewIndex] = gm->lastSlayInView(iview); 00067 } 00068 */ 00069 seedSlay[viewIndex] = gm->lastSlayInView(iview); 00070 if (seedSlay[viewIndex] != 0) seedSeg[viewIndex] = 00071 (MdcSeg *) oneList(seedSlay[viewIndex]->index())->first(); 00072 } 00073 }
MdcSegParams* MdcSegList::segPar | ( | ) | [inline] |
Definition at line 38 of file MdcSegList.h.
References segParam.
Referenced by MdcSegFinder::createSegs(), deleteDups(), massageSegs(), and MdcSegFinder::tryPatterns().
00038 {return &segParam;}
void MdcSegList::setPlot | ( | int | lPlt | ) |
Definition at line 406 of file MdcSegList.cxx.
References MdcSegParams::lPlot, and MdcSeg::segPar().
00406 { 00407 MdcSeg::segPar()->lPlot = lPlt; 00408 }
void MdcSegList::sortByPhi | ( | ) | [private] |
Definition at line 110 of file MdcSegList.cxx.
References _nsupers, count(), first, ganga-rec::j, GmsList::moveAfter(), GmsListLink::next(), next, MdcSeg::phi(), GmsListLink::prev(), and segList.
Referenced by massageSegs().
00110 { 00111 //**************************************************************************** 00112 // Sort the list of segments by phi. Insertion sort, good only for small n 00113 00114 for (int isuper = 0; isuper < _nsupers; isuper++) { 00115 00116 if (segList[isuper].first() == 0) continue; 00117 MdcSeg *aseg = (MdcSeg *) segList[isuper].first()->next(); 00118 for (int j = 1; j < (int) segList[isuper].count(); j++) { 00119 double phiSeg = aseg->phi(); 00120 MdcSeg *nextseg = (MdcSeg *) aseg->next(); 00121 00122 MdcSeg *bseg = (MdcSeg *) aseg->prev(); 00123 if (phiSeg < bseg->phi() ) { 00124 while (bseg != 0 && phiSeg < bseg->phi()) { 00125 bseg = (MdcSeg *) bseg->prev(); 00126 } 00127 segList[isuper].moveAfter(aseg, bseg); // insert aseg after bseg 00128 } 00129 00130 aseg = nextseg; 00131 } 00132 00133 } 00134 return; 00135 }
void MdcSegList::tagAmbig | ( | ) | [private] |
Definition at line 209 of file MdcSegList.cxx.
References _nsupers, _twopi, MdcLayer::nWires(), and segList.
Referenced by massageSegs().
00209 { 00210 //*************************************************************************** 00211 // Go through the list of segments and tag ones that will not make good 00212 // seeds -- i.e. ones that overlap with each other 00213 00214 for (int isuper = 0; isuper < _nsupers; isuper++) { 00215 const GmsList *thisSegList = &segList[isuper]; 00216 if (thisSegList->count() < 2) return; 00217 00218 // Bunch some declarations: 00219 double width, diff; 00220 double thisphi, nextphi; 00221 double nisocell = 2; 00222 // width = cell width in phi for this superlayer 00223 // diff = width of band about the track = nisocell * width 00224 00225 // Calculate road width for this slayer. 00226 const MdcLayer *aLayer = 00227 ((MdcSeg *)thisSegList->first())->superlayer()->firstLayer(); 00228 width = _twopi / aLayer->nWires(); 00229 diff = nisocell * width; 00230 00231 00232 for ( MdcSeg *startSeg = (MdcSeg *) thisSegList->first(); 00233 startSeg != 0; startSeg = (MdcSeg *) startSeg->next() ) { 00234 MdcSeg *nextSeg = (MdcSeg *) startSeg->next(); 00235 if (nextSeg == 0) nextSeg = (MdcSeg *) thisSegList->first(); 00236 00237 thisphi = startSeg->phi(); 00238 nextphi = nextSeg->phi(); 00239 if (nextphi < thisphi) nextphi += _twopi; 00240 00241 if (nextphi - thisphi < diff) { 00242 startSeg->setAmbig(); 00243 nextSeg->setAmbig(); 00244 } 00245 00246 } // end loop over segments 00247 } // end loop over superlayers 00248 00249 return; 00250 }
void MdcSegList::zeroSeed | ( | ) | [private] |
Definition at line 51 of file MdcSegList.cxx.
References seedSeg, and seedSlay.
Referenced by destroySegs(), and MdcSegList().
00051 { 00052 /**************************************************************************/ 00053 seedSeg[0] = seedSeg[1] = seedSeg[2] = 0; 00054 seedSlay[0] = seedSlay[1] = seedSlay[2] = 0; 00055 }
friend class MdcSegFinder [friend] |
Definition at line 22 of file MdcSegList.h.
int MdcSegList::_nsupers [private] |
Definition at line 43 of file MdcSegList.h.
Referenced by count(), deleteDups(), destroySegs(), MdcSegList(), plot(), sortByPhi(), and tagAmbig().
MdcSeg* MdcSegList::seedSeg[3] [private] |
const MdcSuperLayer* MdcSegList::seedSlay[3] [private] |
GmsList* MdcSegList::segList [private] |
Definition at line 42 of file MdcSegList.h.
Referenced by append(), count(), deleteDups(), destroySegs(), MdcSegList(), oneList(), plot(), sortByPhi(), tagAmbig(), and ~MdcSegList().
MdcSegParams MdcSegList::segParam [private] |