120 std::cout <<
"=======Print before arbitrateHits=======" << std::endl;
124 std::vector<MdcTrack*> trksToKill;
125 trksToKill.reserve(4);
130 int* usedInTrackNum =
new int [
nTrack()];
134 int *refitTrack =
new int [
nTrack()];
135 for (
int i = 0; i <
nTrack(); i++) {
141 for (itrack = 0; itrack <
nTrack(); itrack++) {
143 if (atrack == 0)
continue;
145 trkXRef[itrack] = atrack;
148 for (itrack = 0; itrack <
nTrack(); itrack++) {
150 if (8 ==
tkParam.
lPrint) std::cout<<
"arbitrate track No."<<itrack<< std::endl;
152 if (atrack == 0)
continue;
159 assert (hitList != 0);
161 for (
int ii = 0; ii <
nTrack(); ii++) usedInTrackNum[ii] = 0;
166 int maxGapLength = 0;
170 int nDeleteInLayer[43];
171 for(
int i=0;i<43;i++){
175 if(8 ==
tkParam.
lPrint) std::cout<<
"--arbitrate--"<<std::endl;
180 int nUsed = ihit->hit()->nUsedHits();
182 std::cout<<
"nUsed="<<nUsed<<
":";
183 ihit->hit()->printAll(std::cout);
186 double deltaChi = -999;
187 ihit->getFitStuff(deltaChi);
188 std::cout<<
"deltaChi="<<deltaChi<<std::endl;
190 int layer = ihit->layerNumber();
191 nHitInLayer[layer]++;
193 if (!ihit->isActive()) {
198 nDeleteInLayer[layer]++;
200 std::cout<<
"=remove above inactive "<<std::endl;
204 if(ihit == hitList->
end())
break;
210 bool wasUsed =
false;
211 std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator>
q =
212 ihit->hit()->getUsedHits();
214 if ( !i->isActive() )
continue;
218 for(
int idel = 0;idel<trksToKill.size();idel++){
219 if( recoTrk == &(trksToKill[idel]->track()) ) wasDel = 1;
221 if(wasDel==1)
continue;
223 int id = recoTrk->
id();
224 if (
id == aRecoTrk.
id())
continue;
226 bool findKey = idMap.
get(
id, index);
229 usedInTrackNum[index]++;
231 std::cout<<
" track "<<itrack<<
"&" <<index
232 <<
" shared hits "<<usedInTrackNum[index]<<
":";
233 ihit->printAll(std::cout);
237 if (wasUsed) nPrev++;
245 for (
int i=first_layer;i<43;i++){
248 std::cout<<i<<
" nHitInLayer "<<nHitInLayer[i]
249 <<
" nDeleteInLayer "<<nDeleteInLayer[i]<<std::endl;
252 if(nHitInLayer[i]>0 && (nHitInLayer[i]-nDeleteInLayer[i])==0) {
256 cout <<
"rec hits have been deleted in this layer"<<std::endl;
260 }
else if(nHitInLayer[i]==0){
269 if(testGap>=3){ nGapGE3++; }
270 if(testGap>maxGapLength) maxGapLength=testGap;
277 bool toBeDeleted =
false;
279 if(
tkParam.
lPrint>1) std::cout<<
"arbitrateHits tkNo:"<<itrack<<
" nGapGE2= "<<nGapGE2 <<
" nGapGE3= "<<nGapGE3 <<
" maxGapLength= "<<maxGapLength<<std::endl;
285 <<
" Killing tkNo " << itrack << endl;
294 cout <<
"arbitrateHits: nGapGE2 "<<nGapGE2<<
" >= "<<
tkParam.
nGapGE2 <<
" Killing tkNo " << itrack << endl;
300 cout <<
"arbitrateHits: nGapGE3 "<<nGapGE3<<
" >= "<<
tkParam.
nGapGE3 <<
" Killing tkNo " << itrack << endl;
306 cout <<
"arbitrateHits: maxGapLength "<<maxGapLength<<
" >= "<<
tkParam.
maxGapLength<<
" Killing tkNo " << itrack << endl;
313 delete &(atrack->
track());
315 trksToKill.push_back(atrack);
323 for (
int ii = 0; ii <
nTrack(); ii++) {
325 std::cout<<
"tk:"<<itrack<<
"&"<<ii
326 <<
" shared "<<usedInTrackNum[ii]<<
" hits "<< std::endl;
328 if (usedInTrackNum[ii] > nMost) {
329 nMost = usedInTrackNum[ii];
335 if (trackMost == trackOld) {
336 std::cout <<
"ErrMsg(error) MdcTrackListBase:"
337 <<
"Something ghastly happened in MdcTrackListBase::arbitrateHits"
341 trackOld = trackMost;
346 double groupDiff = 0.0;
355 std::cout<<
"track "<<trackMost<<
" shared "<<nMost<<
" hits > Cut nOverlap "
367 if(8 ==
tkParam.
lPrint) std::cout<<
"Go back through hits, looking up overlap hits"<< std::endl;
372 int nUsed = ihit->hit()->nUsedHits();
375 std::cout<<
"--hit go back, nUsed="<<nUsed<<
":";
376 ihit->hit()->printAll(std::cout);
380 if (nUsed < 2) {
continue; }
383 if (!ihit->isActive()) {
384 if (8 ==
tkParam.
lPrint){ std::cout<<
"act=0 continue"<<std::endl; }
389 std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator>
q = ihit->hit()->getUsedHits();
390 while (
q.first!=
q.second) {
395 if (!otherHot->
isActive())
continue;
398 if ( &aRecoTrk == otherTrack)
continue;
399 int otherId = otherTrack->
id();
400 long otherIndex = -1;
401 idMap.
get(otherId, otherIndex); assert(otherIndex >= 0);
404 if (lGroupHits && otherIndex != trackMost)
continue;
408 std::cout<<
"group hits "<< std::endl;
414 int aDof = tkFit->
nActive() - 5;
417 if (aDof <= 0) {groupDiff = 999;}
418 else if (otherDof <= 0) {groupDiff = -999;}
420 groupDiff += ihit->resid(0) * ihit->resid(0) * ihit->weight() /
425 theseHits[nFound] =
const_cast<TrkHitOnTrk*
>(ihit.get());
426 thoseHits[nFound] = otherHot;
432 std::cout<<
"handle hits individually"<< std::endl;
435 if (fabs(ihit->resid(0)) > fabs(otherHot->
resid(0)) ) {
443 std::cout<<
"dorp hit ";
449 refitTrack[otherIndex] = 1;
453 std::cout<<
"inactive hit on other track";
460 if (dropThisHit == 1)
break;
465 if (lGroupHits && nFound == nMost || nFound == nPrev) {
467 std::cout<<
"we've found all of the shared hits on this track,Quit"<<std::endl;
477 cout <<
"nGroup: " << nMost <<
" groupDiff: " << groupDiff << endl;
478 cout <<
"Track: " << aRecoTrk.
id() <<
" nHit: "
479 << hitList->
nHit() <<
" nActive: "
480 << tkFit->
nActive() <<
" chisq/dof: " <<
483 cout <<
"Track: "<< othTrack.
id() <<
" nHit: " <<
484 othTrack.
hits()->
nHit() <<
" nActive: " <<
487 (othTrack.
fitResult()->nActive() - 5) << endl;
490 if (groupDiff > 0.0) {
493 for (
int ii = 0; ii < nMost; ii++) {
499 if (8 ==
tkParam.
lPrint) std::cout<<
"inactive hits on this track, No."<<aRecoTrk.
id()<< std::endl;
502 refitTrack[trackMost] = 1;
503 for (
int ii = 0; ii < nMost; ii++) {
511 if (8 ==
tkParam.
lPrint) std::cout<<
"inactive hits on other track "<< std::endl;
524 idMap.
get(aRecoTrk.
id(), index); assert (index >= 0);
526 if (lRefit || refitTrack[index] == 1) {
528 std::cout<<
"after group ,refit track"<<aRecoTrk.
id()<< std::endl;
530 fitResult = hitList->
fit();
534 fitResult.
print(std::cerr);
542 int nDOF = tkFit->
nActive() - 5;
544 chisqperDOF = tkFit->
chisq() / nDOF;
546 chisqperDOF = tkFit->
chisq();
551 double tem2 = (float) hitList->
nHit() - tkFit->
nActive();
568 cout <<
"Refitting track " << aRecoTrk.
id() <<
" success = "
569 << fitResult.
success() <<
"\n";
572 if (fitResult.
failure() || badFit ) {
578 cout <<
"fitResult.failure? "<<fitResult.
failure()
579 <<
" badFit? "<<badFit <<
" Killing tkNo " << itrack << endl;
583 trksToKill.push_back(atrack);
588 if (lGroupHits)
goto restart;
591 if (8 ==
tkParam.
lPrint) std::cout<<
"end of loop over tracks"<< std::endl;
594 for (
int itk = 0; itk < (int)trksToKill.size(); itk++) {
595 delete &(trksToKill[itk]->track());
596 trksToKill[itk]->setTrack(0);
598 if (8 ==
tkParam.
lPrint) std::cout<<
"remode dead track No."<<itk<< std::endl;
600 if (8 ==
tkParam.
lPrint) std::cout<<
"---end of arbitrateHits"<< std::endl;
602 delete [] usedInTrackNum;
603 delete [] refitTrack;