117 std::cout <<
"=======Print before arbitrateHits=======" << std::endl;
121 std::vector<MdcTrack*> trksToKill;
122 trksToKill.reserve(4);
127 int* usedInTrackNum =
new int [
nTrack()];
131 int *refitTrack =
new int [
nTrack()];
132 for (
int i = 0; i <
nTrack(); i++) {
138 for (itrack = 0; itrack <
nTrack(); itrack++) {
140 if (atrack == 0)
continue;
142 trkXRef[itrack] = atrack;
145 for (itrack = 0; itrack <
nTrack(); itrack++) {
147 if (8 ==
tkParam.
lPrint) std::cout<<
"arbitrate track No."<<itrack<< std::endl;
149 if (atrack == 0)
continue;
156 assert (hitList != 0);
158 for (
int ii = 0; ii <
nTrack(); ii++) usedInTrackNum[ii] = 0;
163 int maxGapLength = 0;
167 int nDeleteInLayer[43];
168 for(
int i=0;i<43;i++){
172 if(8 ==
tkParam.
lPrint) std::cout<<
"--arbitrate--"<<std::endl;
174 int nUsed = ihit->hit()->nUsedHits();
176 std::cout<<
"nUsed="<<nUsed<<
":";
177 ihit->hit()->printAll(std::cout);
180 double deltaChi = -999;
181 ihit->getFitStuff(deltaChi);
182 std::cout<<
"deltaChi="<<deltaChi<<std::endl;
184 int layer = ihit->layerNumber();
185 nHitInLayer[layer]++;
187 if (!ihit->isActive()) {
192 nDeleteInLayer[layer]++;
194 std::cout<<
"=remove above inactive "<<std::endl;
198 if(ihit == hitList->
end())
break;
204 bool wasUsed =
false;
205 std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator>
q =
206 ihit->hit()->getUsedHits();
208 if ( !i->isActive() )
continue;
212 for(
int idel = 0;idel<trksToKill.size();idel++){
213 if( recoTrk == &(trksToKill[idel]->track()) ) wasDel = 1;
215 if(wasDel==1)
continue;
217 int id = recoTrk->
id();
218 if (
id == aRecoTrk.
id())
continue;
220 bool findKey = idMap.
get(
id, index);
223 usedInTrackNum[index]++;
225 std::cout<<
" track "<<itrack<<
"&" <<index
226 <<
" shared hits "<<usedInTrackNum[index]<<
":";
227 ihit->printAll(std::cout);
231 if (wasUsed) nPrev++;
237 for (
int i=0;i<43;i++){
240 std::cout<<i<<
" nHitInLayer "<<nHitInLayer[i]
241 <<
" nDeleteInLayer "<<nDeleteInLayer[i]<<std::endl;
244 if(nHitInLayer[i]>0 && (nHitInLayer[i]-nDeleteInLayer[i])==0) {
248 cout <<
"rec hits have been deleted in this layer"<<std::endl;
252 }
else if(nHitInLayer[i]==0){
261 if(testGap>=3){ nGapGE3++; }
262 if(testGap>maxGapLength) maxGapLength=testGap;
269 bool toBeDeleted =
false;
271 if(
tkParam.
lPrint>1) std::cout<<
"arbitrateHits tkNo:"<<itrack<<
" nGapGE2= "<<nGapGE2 <<
" nGapGE3= "<<nGapGE3 <<
" maxGapLength= "<<maxGapLength<<std::endl;
277 <<
" Killing tkNo " << itrack << endl;
286 cout <<
"arbitrateHits: nGapGE2 "<<nGapGE2<<
" >= "<<
tkParam.
nGapGE2 <<
" Killing tkNo " << itrack << endl;
292 cout <<
"arbitrateHits: nGapGE3 "<<nGapGE3<<
" >= "<<
tkParam.
nGapGE3 <<
" Killing tkNo " << itrack << endl;
298 cout <<
"arbitrateHits: maxGapLength "<<maxGapLength<<
" >= "<<
tkParam.
maxGapLength<<
" Killing tkNo " << itrack << endl;
305 delete &(atrack->
track());
307 trksToKill.push_back(atrack);
315 for (
int ii = 0; ii <
nTrack(); ii++) {
317 std::cout<<
"tk:"<<itrack<<
"&"<<ii
318 <<
" shared "<<usedInTrackNum[ii]<<
" hits "<< std::endl;
320 if (usedInTrackNum[ii] > nMost) {
321 nMost = usedInTrackNum[ii];
327 if (trackMost == trackOld) {
328 std::cout <<
"ErrMsg(error) MdcTrackListBase:"
329 <<
"Something ghastly happened in MdcTrackListBase::arbitrateHits"
333 trackOld = trackMost;
338 double groupDiff = 0.0;
347 std::cout<<
"track "<<trackMost<<
" shared "<<nMost<<
" hits > Cut nOverlap "
359 if(8 ==
tkParam.
lPrint) std::cout<<
"Go back through hits, looking up overlap hits"<< std::endl;
363 int nUsed = ihit->hit()->nUsedHits();
366 std::cout<<
"--hit go back, nUsed="<<nUsed<<
":";
367 ihit->hit()->printAll(std::cout);
371 if (nUsed < 2) {
continue; }
374 if (!ihit->isActive()) {
375 if (8 ==
tkParam.
lPrint){ std::cout<<
"act=0 continue"<<std::endl; }
380 std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator>
q = ihit->hit()->getUsedHits();
381 while (
q.first!=
q.second) {
386 if (!otherHot->
isActive())
continue;
389 if ( &aRecoTrk == otherTrack)
continue;
390 int otherId = otherTrack->
id();
391 long otherIndex = -1;
392 idMap.
get(otherId, otherIndex); assert(otherIndex >= 0);
395 if (lGroupHits && otherIndex != trackMost)
continue;
399 std::cout<<
"group hits "<< std::endl;
405 int aDof = tkFit->
nActive() - 5;
408 if (aDof <= 0) {groupDiff = 999;}
409 else if (otherDof <= 0) {groupDiff = -999;}
411 groupDiff += ihit->resid(0) * ihit->resid(0) * ihit->weight() /
416 theseHits[nFound] =
const_cast<TrkHitOnTrk*
>(ihit.get());
417 thoseHits[nFound] = otherHot;
423 std::cout<<
"handle hits individually"<< std::endl;
426 if (fabs(ihit->resid(0)) > fabs(otherHot->
resid(0)) ) {
434 std::cout<<
"dorp hit ";
440 refitTrack[otherIndex] = 1;
444 std::cout<<
"inactive hit on other track";
451 if (dropThisHit == 1)
break;
456 if (lGroupHits && nFound == nMost || nFound == nPrev) {
458 std::cout<<
"we've found all of the shared hits on this track,Quit"<<std::endl;
468 cout <<
"nGroup: " << nMost <<
" groupDiff: " << groupDiff << endl;
469 cout <<
"Track: " << aRecoTrk.
id() <<
" nHit: "
470 << hitList->
nHit() <<
" nActive: "
471 << tkFit->
nActive() <<
" chisq/dof: " <<
474 cout <<
"Track: "<< othTrack.
id() <<
" nHit: " <<
475 othTrack.
hits()->
nHit() <<
" nActive: " <<
478 (othTrack.
fitResult()->nActive() - 5) << endl;
481 if (groupDiff > 0.0) {
484 for (
int ii = 0; ii < nMost; ii++) {
490 if (8 ==
tkParam.
lPrint) std::cout<<
"inactive hits on this track, No."<<aRecoTrk.
id()<< std::endl;
493 refitTrack[trackMost] = 1;
494 for (
int ii = 0; ii < nMost; ii++) {
502 if (8 ==
tkParam.
lPrint) std::cout<<
"inactive hits on other track "<< std::endl;
515 idMap.
get(aRecoTrk.
id(), index); assert (index >= 0);
517 if (lRefit || refitTrack[index] == 1) {
519 std::cout<<
"after group ,refit track"<<aRecoTrk.
id()<< std::endl;
521 fitResult = hitList->
fit();
525 fitResult.
print(std::cerr);
533 int nDOF = tkFit->
nActive() - 5;
535 chisqperDOF = tkFit->
chisq() / nDOF;
537 chisqperDOF = tkFit->
chisq();
542 double tem2 = (float) hitList->
nHit() - tkFit->
nActive();
559 cout <<
"Refitting track " << aRecoTrk.
id() <<
" success = "
560 << fitResult.
success() <<
"\n";
563 if (fitResult.
failure() || badFit ) {
569 cout <<
"fitResult.failure? "<<fitResult.
failure()
570 <<
" badFit? "<<badFit <<
" Killing tkNo " << itrack << endl;
574 trksToKill.push_back(atrack);
579 if (lGroupHits)
goto restart;
582 if (8 ==
tkParam.
lPrint) std::cout<<
"end of loop over tracks"<< std::endl;
585 for (
int itk = 0; itk < (int)trksToKill.size(); itk++) {
586 delete &(trksToKill[itk]->track());
587 trksToKill[itk]->setTrack(0);
589 if (8 ==
tkParam.
lPrint) std::cout<<
"remode dead track No."<<itk<< std::endl;
591 if (8 ==
tkParam.
lPrint) std::cout<<
"---end of arbitrateHits"<< std::endl;
593 delete [] usedInTrackNum;
594 delete [] refitTrack;