115 { std::cout <<
"=======Print before arbitrateHits=======" << std::endl; }
118 std::vector<MdcTrack*> trksToKill;
119 trksToKill.reserve( 4 );
124 int* usedInTrackNum =
new int[
nTrack()];
128 int* refitTrack =
new int[
nTrack()];
129 for (
int i = 0; i <
nTrack(); i++ ) { refitTrack[i] = 0; }
133 for ( itrack = 0; itrack <
nTrack(); itrack++ )
135 MdcTrack* atrack = ( *this )[itrack];
136 if ( atrack == 0 )
continue;
138 trkXRef[itrack] = atrack;
141 for ( itrack = 0; itrack <
nTrack(); itrack++ )
144 if ( 8 ==
tkParam.lPrint ) std::cout <<
"arbitrate track No." << itrack << std::endl;
145 MdcTrack* atrack = ( *this )[itrack];
146 if ( atrack == 0 )
continue;
151 assert( tkFit != 0 );
153 assert( hitList != 0 );
155 for (
int ii = 0; ii <
nTrack(); ii++ ) usedInTrackNum[ii] = 0;
160 int maxGapLength = 0;
165 int nDeleteInLayer[43];
166 for (
int i = 0; i < 43; i++ )
169 nDeleteInLayer[i] = 0;
171 if ( 8 ==
tkParam.lPrint ) std::cout <<
"--arbitrate--" << std::endl;
174 int nUsed = ihit->hit()->nUsedHits();
177 std::cout <<
"nUsed=" << nUsed <<
":";
178 ihit->hit()->printAll( std::cout );
182 double deltaChi = -999;
183 ihit->getFitStuff( deltaChi );
184 std::cout <<
"deltaChi=" << deltaChi << std::endl;
186 int layer = ihit->layerNumber();
187 nHitInLayer[layer]++;
189 if ( !ihit->isActive() )
196 nDeleteInLayer[layer]++;
197 if ( 8 ==
tkParam.lPrint ) { std::cout <<
"=remove above inactive " << std::endl; }
200 if ( ihit == hitList->
end() )
break;
207 bool wasUsed =
false;
208 std::pair<TrkFundHit::hot_iterator, TrkFundHit::hot_iterator>
q =
209 ihit->hit()->getUsedHits();
212 if ( !i->isActive() )
continue;
216 for (
int idel = 0; idel < trksToKill.size(); idel++ )
218 if ( recoTrk == &( trksToKill[idel]->track() ) ) wasDel = 1;
220 if ( wasDel == 1 )
continue;
222 int id = recoTrk->
id();
223 if (
id == aRecoTrk.
id() )
continue;
225 bool findKey = idMap.
get(
id, index );
227 assert( index >= 0 );
228 usedInTrackNum[index]++;
231 std::cout <<
" track " << itrack <<
"&" << index <<
" shared hits "
232 << usedInTrackNum[index] <<
":";
233 ihit->printAll( std::cout );
237 if ( wasUsed ) nPrev++;
243 for (
int i = 0; i < 43; i++ )
249 std::cout << i <<
" nHitInLayer " << nHitInLayer[i] <<
" nDeleteInLayer "
250 << nDeleteInLayer[i] << std::endl;
253 if ( nHitInLayer[i] > 0 && ( nHitInLayer[i] - nDeleteInLayer[i] ) == 0 )
258 { cout <<
"rec hits have been deleted in this layer" << std::endl; }
262 else if ( nHitInLayer[i] == 0 )
275 if ( testGap >= 3 ) { nGapGE3++; }
276 if ( testGap > maxGapLength ) maxGapLength = testGap;
284 bool toBeDeleted =
false;
287 std::cout <<
"arbitrateHits tkNo:" << itrack <<
" nGapGE2= " << nGapGE2
288 <<
" nGapGE3= " << nGapGE3 <<
" maxGapLength= " << maxGapLength << std::endl;
291 if ( nHitDeleted >=
tkParam.nHitDeleted )
295 cout <<
"arbitrateHits: nHitDeleted " << nHitDeleted <<
" >= " <<
tkParam.nHitDeleted
296 <<
" Killing tkNo " << itrack << endl;
303 if ( nGapGE2 >=
tkParam.nGapGE2 )
307 cout <<
"arbitrateHits: nGapGE2 " << nGapGE2 <<
" >= " <<
tkParam.nGapGE2
308 <<
" Killing tkNo " << itrack << endl;
312 if ( nGapGE3 >=
tkParam.nGapGE3 )
316 cout <<
"arbitrateHits: nGapGE3 " << nGapGE3 <<
" >= " <<
tkParam.nGapGE3
317 <<
" Killing tkNo " << itrack << endl;
321 if ( maxGapLength >=
tkParam.maxGapLength )
325 cout <<
"arbitrateHits: maxGapLength " << maxGapLength
326 <<
" >= " <<
tkParam.maxGapLength <<
" Killing tkNo " << itrack << endl;
334 delete &( atrack->
track() );
336 trksToKill.push_back( atrack );
344 for (
int ii = 0; ii <
nTrack(); ii++ )
348 std::cout <<
"tk:" << itrack <<
"&" << ii <<
" shared " << usedInTrackNum[ii]
349 <<
" hits " << std::endl;
351 if ( usedInTrackNum[ii] > nMost )
353 nMost = usedInTrackNum[ii];
359 if ( trackMost == trackOld )
361 std::cout <<
"ErrMsg(error) MdcTrackListBase:"
362 <<
"Something ghastly happened in MdcTrackListBase::arbitrateHits"
366 trackOld = trackMost;
370 double groupDiff = 0.0;
377 if ( nMost >=
tkParam.nOverlap )
381 std::cout <<
"track " << trackMost <<
" shared " << nMost <<
" hits > Cut nOverlap "
382 <<
tkParam.nOverlap <<
", group hits!" << std::endl;
394 std::cout <<
"Go back through hits, looking up overlap hits" << std::endl;
397 if ( 8 ==
tkParam.lPrint ) std::cout <<
" nHits= " << hitList->
nHit() << std::endl;
400 int nUsed = ihit->hit()->nUsedHits();
404 std::cout <<
"--hit go back, nUsed=" << nUsed <<
":";
405 ihit->hit()->printAll( std::cout );
409 if ( nUsed < 2 ) {
continue; }
412 if ( !ihit->isActive() )
414 if ( 8 ==
tkParam.lPrint ) { std::cout <<
"act=0 continue" << std::endl; }
419 std::pair<TrkFundHit::hot_iterator, TrkFundHit::hot_iterator>
q =
420 ihit->hit()->getUsedHits();
421 while (
q.first !=
q.second )
427 if ( !otherHot->
isActive() )
continue;
430 if ( &aRecoTrk == otherTrack )
continue;
431 int otherId = otherTrack->
id();
432 long otherIndex = -1;
433 idMap.
get( otherId, otherIndex );
434 assert( otherIndex >= 0 );
437 if ( lGroupHits && otherIndex != trackMost )
continue;
441 if ( 8 ==
tkParam.lPrint ) { std::cout <<
"group hits " << std::endl; }
446 int aDof = tkFit->
nActive() - 5;
449 if ( aDof <= 0 ) { groupDiff = 999; }
450 else if ( otherDof <= 0 ) { groupDiff = -999; }
454 ihit->resid( 0 ) * ihit->resid( 0 ) * ihit->weight() / aDof -
455 otherHot->
resid( 0 ) * otherHot->
resid( 0 ) * otherHot->
weight() / otherDof;
457 theseHits[nFound] =
const_cast<TrkHitOnTrk*
>( ihit.get() );
458 thoseHits[nFound] = otherHot;
466 { std::cout <<
"handle hits individually" << std::endl; }
468 if ( fabs( ihit->resid( 0 ) ) > fabs( otherHot->
resid( 0 ) ) )
478 std::cout <<
"dorp hit ";
486 refitTrack[otherIndex] = 1;
491 std::cout <<
"inactive hit on other track";
498 if ( dropThisHit == 1 )
break;
503 if ( lGroupHits && nFound == nMost || nFound == nPrev )
507 std::cout <<
"we've found all of the shared hits on this track,Quit" << std::endl;
519 cout <<
"nGroup: " << nMost <<
" groupDiff: " << groupDiff << endl;
520 cout <<
"Track: " << aRecoTrk.
id() <<
" nHit: " << hitList->
nHit()
521 <<
" nActive: " << tkFit->
nActive()
522 <<
" chisq/dof: " << tkFit->
chisq() / ( tkFit->
nActive() - 5 ) << endl;
524 cout <<
"Track: " << othTrack.
id() <<
" nHit: " << othTrack.
hits()->
nHit()
530 if ( groupDiff > 0.0 )
534 for (
int ii = 0; ii < nMost; ii++ )
542 std::cout <<
"inactive hits on this track, No." << aRecoTrk.
id() << std::endl;
547 refitTrack[trackMost] = 1;
548 for (
int ii = 0; ii < nMost; ii++ )
557 if ( 8 ==
tkParam.lPrint ) std::cout <<
"inactive hits on other track " << std::endl;
570 idMap.
get( aRecoTrk.
id(), index );
571 assert( index >= 0 );
573 if ( lRefit || refitTrack[index] == 1 )
576 { std::cout <<
"after group ,refit track" << aRecoTrk.
id() << std::endl; }
577 fitResult = hitList->
fit();
589 int nDOF = tkFit->
nActive() - 5;
590 if ( nDOF > 5 ) { chisqperDOF = tkFit->
chisq() / nDOF; }
591 else { chisqperDOF = tkFit->
chisq(); }
593 if ( chisqperDOF >
tkParam.maxChisq ) badFit =
true;
595 double tem2 = (float)hitList->
nHit() - tkFit->
nActive();
598 if ( tem2 >=
tkParam.maxNmissTrack ) badFit =
true;
599 if ( tem2 /
float( hitList->
nHit() ) >
tkParam.maxNmissNorm ) { badFit =
true; }
602 std::cout <<
"fit quality:"
603 <<
" chisqperDof " << chisqperDOF <<
"?>" <<
tkParam.maxChisq
604 <<
" nActive " << tkFit->
nActive() <<
"?<" <<
tkParam.minHits <<
" nHit "
605 << hitList->
nHit() <<
" nhit-act " << tem2 <<
"?>= nMiss "
606 <<
tkParam.maxNmissTrack <<
" hit-act/nhit "
607 << tem2 / float( hitList->
nHit() ) <<
"?> MissNorm "
608 <<
tkParam.maxNmissNorm << std::endl;
612 cout <<
"Refitting track " << aRecoTrk.
id() <<
" success = " << fitResult.
success()
616 if ( fitResult.
failure() || badFit )
624 cout <<
"fitResult.failure? " << fitResult.
failure() <<
" badFit? " << badFit
625 <<
" Killing tkNo " << itrack << endl;
629 trksToKill.push_back( atrack );
634 if ( lGroupHits )
goto restart;
637 if ( 8 ==
tkParam.lPrint ) std::cout <<
"end of loop over tracks" << std::endl;
640 for (
int itk = 0; itk < (int)trksToKill.size(); itk++ )
642 delete &( trksToKill[itk]->track() );
643 trksToKill[itk]->setTrack( 0 );
644 remove( trksToKill[itk] );
645 if ( 8 ==
tkParam.lPrint ) std::cout <<
"remode dead track No." << itk << std::endl;
647 if ( 8 ==
tkParam.lPrint ) std::cout <<
"---end of arbitrateHits" << std::endl;
649 delete[] usedInTrackNum;