17#include "MdcTrkRecon/MdcSegList.h"
18#include "MdcData/MdcHit.h"
19#include "MdcData/MdcHitUse.h"
20#include "MdcGeom/BesAngle.h"
21#include "MdcGeom/Constants.h"
22#include "MdcGeom/MdcDetector.h"
23#include "MdcGeom/MdcSuperLayer.h"
24#include "MdcTrkRecon/GmsList.h"
25#include "MdcTrkRecon/MdcSeg.h"
26#include "MdcTrkRecon/mdcWrapWire.h"
28#include "AIDA/IHistogram1D.h"
51void MdcSegList::zeroSeed() {
53 seedSeg[0] = seedSeg[1] = seedSeg[2] = 0;
54 seedSlay[0] = seedSlay[1] = seedSlay[2] = 0;
60 for (
int iview = -1; iview <= 1; iview++ )
62 int viewIndex = iview + 1;
71 if ( seedSlay[viewIndex] != 0 )
80 for (
int i = 0; i < _nsupers; i++ )
82 std::cout <<
" ---------------MdcSeg of Slayer " << i <<
"-------------" << std::endl;
84 aSeg = (
MdcSeg*)segList[i].first();
100 for (
int i = 0; i < _nsupers; i++ )
102 aSeg = (
MdcSeg*)segList[i].first();
106 segList[i].remove( aSeg );
115void MdcSegList::sortByPhi() {
119 for (
int isuper = 0; isuper < _nsupers; isuper++ )
122 if ( segList[isuper].first() == 0 )
continue;
124 for (
int j = 1; j < (int)segList[isuper].
count(); j++ )
126 double phiSeg = aseg->
phi();
130 if ( phiSeg < bseg->phi() )
132 while ( bseg != 0 && phiSeg < bseg->phi() ) { bseg = (
MdcSeg*)bseg->
prev(); }
133 segList[isuper].moveAfter( aseg, bseg );
153 int viewIndex = iview + 1;
154 if ( seedSlay[viewIndex] == 0 )
return 0;
161 if ( seedSeg[viewIndex] == 0 )
164 seedSlay[viewIndex] = seedSlay[viewIndex]->prevInView();
165 if ( seedSlay[viewIndex] == 0 )
return 0;
168 else if ( seedSeg[viewIndex]->segUsed() )
171 seedSeg[viewIndex] = (
MdcSeg*)seedSeg[viewIndex]->next();
173 else if ( seedSeg[viewIndex]->segAmbig() && goodOnly )
176 seedSeg[viewIndex] = (
MdcSeg*)seedSeg[viewIndex]->next();
180 else if ( !seedSeg[viewIndex]->segFull() && goodOnly )
183 seedSeg[viewIndex] = (
MdcSeg*)seedSeg[viewIndex]->next();
190 int navail = seedSeg[viewIndex]->nHit();
191 for (
int ihit = 0; ihit < seedSeg[viewIndex]->nHit(); ihit++ )
197 if ( navail - nused < 2 && navail > 0 )
198 { seedSeg[viewIndex] = (
MdcSeg*)seedSeg[viewIndex]->next(); }
216 MdcSeg* theSeed = seedSeg[viewIndex];
217 seedSeg[viewIndex] = (
MdcSeg*)seedSeg[viewIndex]->next();
222void MdcSegList::tagAmbig() {
227 for (
int isuper = 0; isuper < _nsupers; isuper++ )
229 const GmsList* thisSegList = &segList[isuper];
230 if ( thisSegList->
count() < 2 )
return;
234 double thisphi, nextphi;
242 diff = nisocell * width;
248 if ( nextSeg == 0 ) nextSeg = (
MdcSeg*)thisSegList->
first();
250 thisphi = startSeg->phi();
251 nextphi = nextSeg->
phi();
252 if ( nextphi < thisphi ) nextphi +=
_twopi;
254 if ( nextphi - thisphi < diff )
256 startSeg->setAmbig();
276void MdcSegList::massageSegs() {
285void MdcSegList::deleteDups(
bool ldrop ) {
299 if ( printit ) std::cout <<
" =======MdcSegList::deleteDups()===== " << std::endl;
301 for (
int isuper = 0; isuper < _nsupers; isuper++ )
303 if ( isuper == 10 )
continue;
304 GmsList* thisSegList = &segList[isuper];
305 if ( thisSegList->
count() < 2 )
continue;
307 { std::cout << endl <<
" -----slayer " << isuper <<
"-----" << std::endl; }
309 double thisphi, nextphi;
313 const MdcLayer* aLayer = ( (MdcSeg*)thisSegList->
first() )->superlayer()->firstLayer();
319 MdcSeg* startSeg = (MdcSeg*)thisSegList->
first();
320 while ( startSeg != 0 )
322 if ( thisSegList->
count() < 2 )
break;
323 if ( lWrapped )
break;
324 thisphi = startSeg->
phi();
325 MdcSeg* nextSeg = startSeg;
329 std::cout << std::endl;
334 nextSeg = (MdcSeg*)nextSeg->
next();
337 nextSeg = (MdcSeg*)thisSegList->
first();
338 if ( lWrapped == 1 )
break;
341 if ( nextSeg == startSeg )
break;
342 nextphi = nextSeg->
phi();
344 if ( nextphi < thisphi ) nextphi +=
_twopi;
348 std::cout << std::endl <<
"----start ";
350 std::cout << std::endl;
351 std::cout <<
" next ";
353 std::cout << std::endl;
354 std::cout <<
" phi diff " << nextphi - thisphi <<
" cut phidiff " << phidiff;
355 std::cout <<
" slope diff " << nextSeg->
slope() - startSeg->
slope()
356 <<
" cut slopdiff " << slopediff << std::endl;
360 {
g_phiDiff->fill( ( nextphi - thisphi ) / width ); }
364 if ( nextphi - thisphi > phidiff )
366 if ( printit ) { std::cout <<
" --not same phi" << std::endl; }
368 startSeg = (MdcSeg*)startSeg->
next();
371 else if ( fabs( nextSeg->
slope() - startSeg->
slope() ) > slopediff )
375 std::cout <<
" --attached, but not identical -- move on to next nextSeg "
385 assert( startSeg->
nHit() > 2 );
386 double chiFirst = startSeg->
chisq() / ( startSeg->
nHit() - 2 );
387 assert( nextSeg->
nHit() > 2 );
388 double chiNext = nextSeg->
chisq() / ( nextSeg->
nHit() - 2 );
390 int cdiff = (int)nextSeg->
nHit() - (int)startSeg->
nHit();
391 theDiff = ( chiFirst - chiNext ) + 2. * ( cdiff );
392 if ( theDiff < 0. ) firstBetter = 1;
395 std::cout <<
" --identical; choose better " << std::endl;
396 std::cout <<
" chi start " << chiFirst <<
" chi next " << chiNext <<
" cdiff "
397 << cdiff << std::endl;
402 if ( printit ) { std::cout <<
" startSeg better,"; }
403 MdcSeg* tempSeg = nextSeg;
404 nextSeg = (MdcSeg*)nextSeg->
next();
407 if ( printit ) { std::cout <<
" delete nextSeg" << std::endl; }
408 thisSegList->
remove( tempSeg );
413 if ( printit ) { std::cout <<
" nextSeg->setUsed(true) " << std::endl; }
418 nextSeg = (MdcSeg*)thisSegList->
first();
419 if ( lWrapped == 1 )
break;
425 if ( printit ) { std::cout <<
" nextSeg better,"; }
426 MdcSeg* tempSeg = startSeg;
427 startSeg = (MdcSeg*)startSeg->
next();
430 if ( printit ) { std::cout <<
" delete startSeg" << std::endl; }
431 thisSegList->
remove( tempSeg );
436 if ( printit ) { std::cout <<
" startSeg->setUsed(true) " << std::endl; }
454 return &segList[slayIndex];
461 for (
int i = 0; i < _nsupers; i++ ) cnt += segList[i].
count();
AIDA::IHistogram1D * g_phiDiff
AIDA::IHistogram1D * g_slopeDiff
static const double twoPi
GmsListLink * prev() const
GmsListLink * next() const
GmsListLink * first() const
unsigned int count() const
GmsList & remove(GmsListLink *)
const MdcSuperLayer * lastSlayInView(int iview) const
const MdcHit * mdcHit() const
void append(MdcSeg *aSeg)
MdcSegList(int nSupers, const MdcSegParams segParms)
const GmsList * oneList(int slayIndex) const
MdcSeg * getSeed(int iview, int goodOnly)
void resetSeed(const MdcDetector *gm)
const MdcSuperLayer * superlayer() const
static MdcSegParams * segPar()
static void setParam(MdcSegParams *segpar)
const TrkFundHit & hit() const