103 {
104
105
106
107
108
109
110
111
112
113
115 { std::cout << "=======Print before arbitrateHits=======" << std::endl; }
116
117 int nDeleted = 0;
118 std::vector<MdcTrack*> trksToKill;
119 trksToKill.reserve( 4 );
120
121 MdcMap<long, long> idMap;
122
123
124 int* usedInTrackNum =
new int[
nTrack()];
125
126 MdcTrack** trkXRef =
new MdcTrack*[
nTrack()];
127
128 int* refitTrack =
new int[
nTrack()];
129 for (
int i = 0; i <
nTrack(); i++ ) { refitTrack[i] = 0; }
130
131
132 int itrack;
133 for ( itrack = 0; itrack <
nTrack(); itrack++ )
134 {
135 MdcTrack* atrack = ( *this )[itrack];
136 if ( atrack == 0 ) continue;
138 trkXRef[itrack] = atrack;
139 }
140
141 for ( itrack = 0; itrack <
nTrack(); itrack++ )
142 {
143
144 if ( 8 ==
tkParam.lPrint ) std::cout <<
"arbitrate track No." << itrack << std::endl;
145 MdcTrack* atrack = ( *this )[itrack];
146 if ( atrack == 0 ) continue;
147 TrkRecoTrk& aRecoTrk = atrack->
track();
148 int lRefit = 0;
149 int trackOld = -1;
150 const TrkFit* tkFit = aRecoTrk.
fitResult();
151 assert( tkFit != 0 );
152 TrkHitList* hitList = aRecoTrk.
hits();
153 assert( hitList != 0 );
154 restart:
155 for (
int ii = 0; ii <
nTrack(); ii++ ) usedInTrackNum[ii] = 0;
156
157
158 int nPrev = 0;
159 int nHitDeleted = 0;
160 int maxGapLength = 0;
161
162 int nGapGE2 = 0;
163 int nGapGE3 = 0;
164 int nHitInLayer[43];
165 int nDeleteInLayer[43];
166 for ( int i = 0; i < 43; i++ )
167 {
168 nHitInLayer[i] = 0;
169 nDeleteInLayer[i] = 0;
170 }
171 if ( 8 ==
tkParam.lPrint ) std::cout <<
"--arbitrate--" << std::endl;
173 {
174 int nUsed = ihit->hit()->nUsedHits();
176 {
177 std::cout << "nUsed=" << nUsed << ":";
178 ihit->hit()->printAll( std::cout );
179 }
181 {
182 double deltaChi = -999;
183 ihit->getFitStuff( deltaChi );
184 std::cout << "deltaChi=" << deltaChi << std::endl;
185 }
186 int layer = ihit->layerNumber();
187 nHitInLayer[layer]++;
188
189 if ( !ihit->isActive() )
190 {
191
192
193
195 {
196 nDeleteInLayer[layer]++;
197 if ( 8 ==
tkParam.lPrint ) { std::cout <<
"=remove above inactive " << std::endl; }
198 TrkFundHit* hit = const_cast<TrkFundHit*>( ihit->hit() );
200 if ( ihit == hitList->
end() )
break;
201 --ihit;
202 }
203 continue;
204 }
205 if ( nUsed > 1 )
206 {
207 bool wasUsed = false;
208 std::pair<TrkFundHit::hot_iterator, TrkFundHit::hot_iterator>
q =
209 ihit->hit()->getUsedHits();
211 {
212 if ( !i->isActive() ) continue;
213 TrkRecoTrk* recoTrk = i->parentTrack();
214
215 int wasDel = 0;
216 for ( int idel = 0; idel < trksToKill.size(); idel++ )
217 {
218 if ( recoTrk == &( trksToKill[idel]->track() ) ) wasDel = 1;
219 }
220 if ( wasDel == 1 ) continue;
221
222 int id = recoTrk->
id();
223 if (
id == aRecoTrk.
id() )
continue;
224 long index = 0;
225 bool findKey = idMap.
get(
id, index );
226
227 assert( index >= 0 );
228 usedInTrackNum[index]++;
230 {
231 std::cout << " track " << itrack << "&" << index << " shared hits "
232 << usedInTrackNum[index] << ":";
233 ihit->printAll( std::cout );
234 }
235 wasUsed = true;
236 }
237 if ( wasUsed ) nPrev++;
238 }
239 }
240
241 int testGap = 0;
242
243 for ( int i = 0; i < 43; i++ )
244 {
245
246
248 {
249 std::cout << i << " nHitInLayer " << nHitInLayer[i] << " nDeleteInLayer "
250 << nDeleteInLayer[i] << std::endl;
251 }
252
253 if ( nHitInLayer[i] > 0 && ( nHitInLayer[i] - nDeleteInLayer[i] ) == 0 )
254 {
255
256 nHitDeleted++;
258 { cout << "rec hits have been deleted in this layer" << std::endl; }
259 testGap++;
260
261 }
262 else if ( nHitInLayer[i] == 0 )
263 {
264
265 testGap++;
266
267 }
268 else
269 {
270
271
272 if ( testGap >= 2 )
273 {
274 nGapGE2++;
275 if ( testGap >= 3 ) { nGapGE3++; }
276 if ( testGap > maxGapLength ) maxGapLength = testGap;
277
278
279 }
280 testGap = 0;
281 }
282 }
283
284 bool toBeDeleted = false;
285
287 std::cout << "arbitrateHits tkNo:" << itrack << " nGapGE2= " << nGapGE2
288 << " nGapGE3= " << nGapGE3 << " maxGapLength= " << maxGapLength << std::endl;
289
290
291 if ( nHitDeleted >=
tkParam.nHitDeleted )
292 {
294 {
295 cout <<
"arbitrateHits: nHitDeleted " << nHitDeleted <<
" >= " <<
tkParam.nHitDeleted
296 << " Killing tkNo " << itrack << endl;
297 }
298 toBeDeleted = true;
299 }
300
301
302
303 if ( nGapGE2 >=
tkParam.nGapGE2 )
304 {
306 {
307 cout <<
"arbitrateHits: nGapGE2 " << nGapGE2 <<
" >= " <<
tkParam.nGapGE2
308 << " Killing tkNo " << itrack << endl;
309 }
310 toBeDeleted = true;
311 }
312 if ( nGapGE3 >=
tkParam.nGapGE3 )
313 {
315 {
316 cout <<
"arbitrateHits: nGapGE3 " << nGapGE3 <<
" >= " <<
tkParam.nGapGE3
317 << " Killing tkNo " << itrack << endl;
318 }
319 toBeDeleted = true;
320 }
321 if ( maxGapLength >=
tkParam.maxGapLength )
322 {
324 {
325 cout << "arbitrateHits: maxGapLength " << maxGapLength
326 <<
" >= " <<
tkParam.maxGapLength <<
" Killing tkNo " << itrack << endl;
327 }
328 toBeDeleted = true;
329 }
330
331 if ( toBeDeleted )
332 {
333 nDeleted++;
334 delete &( atrack->
track() );
336 trksToKill.push_back( atrack );
337 continue;
338 }
339
340
341
342 int nMost = 0;
343 int trackMost = 0;
344 for (
int ii = 0; ii <
nTrack(); ii++ )
345 {
347 {
348 std::cout << "tk:" << itrack << "&" << ii << " shared " << usedInTrackNum[ii]
349 << " hits " << std::endl;
350 }
351 if ( usedInTrackNum[ii] > nMost )
352 {
353 nMost = usedInTrackNum[ii];
354 trackMost = ii;
355 }
356 }
357
358
359 if ( trackMost == trackOld )
360 {
361 std::cout << "ErrMsg(error) MdcTrackListBase:"
362 << "Something ghastly happened in MdcTrackListBase::arbitrateHits"
363 << std::endl;
364 return 0;
365 }
366 trackOld = trackMost;
367
368
369
370 double groupDiff = 0.0;
371
372 int nFound = 0;
373 TrkHitOnTrk** theseHits = 0;
374 TrkHitOnTrk** thoseHits = 0;
375 int lGroupHits = 0;
376
377 if ( nMost >=
tkParam.nOverlap )
378 {
380 {
381 std::cout << "track " << trackMost << " shared " << nMost << " hits > Cut nOverlap "
382 <<
tkParam.nOverlap <<
", group hits!" << std::endl;
383 }
384 lGroupHits = 1;
385 theseHits = new TrkHitOnTrk*[nMost];
386 thoseHits = new TrkHitOnTrk*[nMost];
387 }
388
389
390
391
392
394 std::cout << "Go back through hits, looking up overlap hits" << std::endl;
395 if ( nMost > 0 )
396 {
397 if ( 8 ==
tkParam.lPrint ) std::cout <<
" nHits= " << hitList->
nHit() << std::endl;
399 {
400 int nUsed = ihit->hit()->nUsedHits();
401
403 {
404 std::cout << "--hit go back, nUsed=" << nUsed << ":";
405 ihit->hit()->printAll( std::cout );
406 }
407
408
409 if ( nUsed < 2 ) { continue; }
410
411
412 if ( !ihit->isActive() )
413 {
414 if ( 8 ==
tkParam.lPrint ) { std::cout <<
"act=0 continue" << std::endl; }
415 continue;
416 }
417
418
419 std::pair<TrkFundHit::hot_iterator, TrkFundHit::hot_iterator>
q =
420 ihit->hit()->getUsedHits();
421 while (
q.first !=
q.second )
422 {
423 int dropThisHit = 0;
424 TrkHitOnTrk* otherHot =
const_cast<TrkHitOnTrk*
>( ( --
q.second ).get() );
426
427 if ( !otherHot->
isActive() )
continue;
428
429
430 if ( &aRecoTrk == otherTrack ) continue;
431 int otherId = otherTrack->
id();
432 long otherIndex = -1;
433 idMap.
get( otherId, otherIndex );
434 assert( otherIndex >= 0 );
435
436
437 if ( lGroupHits && otherIndex != trackMost ) continue;
438
439 if ( lGroupHits )
440 {
441 if ( 8 ==
tkParam.lPrint ) { std::cout <<
"group hits " << std::endl; }
442
443
444
445
446 int aDof = tkFit->
nActive() - 5;
449 if ( aDof <= 0 ) { groupDiff = 999; }
450 else if ( otherDof <= 0 ) { groupDiff = -999; }
451 else
452 {
453 groupDiff +=
454 ihit->resid( 0 ) * ihit->resid( 0 ) * ihit->weight() / aDof -
455 otherHot->
resid( 0 ) * otherHot->
resid( 0 ) * otherHot->
weight() / otherDof;
456 }
457 theseHits[nFound] = const_cast<TrkHitOnTrk*>( ihit.get() );
458 thoseHits[nFound] = otherHot;
459 nFound++;
460 dropThisHit = 1;
461 }
462 else
463 {
464
466 { std::cout << "handle hits individually" << std::endl; }
467 nFound++;
468 if ( fabs( ihit->resid( 0 ) ) > fabs( otherHot->
resid( 0 ) ) )
469 {
470
471 lRefit = 1;
472
473
474 const_cast<TrkHitOnTrk*>( ihit.get() )->setActivity( 0 );
475 dropThisHit = 1;
477 {
478 std::cout << "dorp hit ";
479 const_cast<TrkHitOnTrk*>( ihit.get() )->print( std::cout );
480 }
481 break;
482 }
483 else
484 {
485
486 refitTrack[otherIndex] = 1;
487
490 {
491 std::cout << "inactive hit on other track";
492 const_cast<TrkHitOnTrk*>( ihit.get() )->print( std::cout );
493 }
494 break;
495 }
496 }
497
498 if ( dropThisHit == 1 ) break;
499
500 }
501
502
503 if ( lGroupHits && nFound == nMost || nFound == nPrev )
504 {
506 {
507 std::cout << "we've found all of the shared hits on this track,Quit" << std::endl;
508 }
509 break;
510 }
511
512 }
513
514
515 if ( lGroupHits )
516 {
518 {
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;
523 TrkRecoTrk& othTrack = trkXRef[trackMost]->
track();
524 cout <<
"Track: " << othTrack.
id() <<
" nHit: " << othTrack.
hits()->
nHit()
527 << endl;
528 }
529
530 if ( groupDiff > 0.0 )
531 {
532
533 lRefit = 1;
534 for ( int ii = 0; ii < nMost; ii++ )
535 {
536 TrkHitOnTrk* alink = theseHits[ii];
537 TrkFundHit* hit =
const_cast<TrkFundHit*
>( alink->
hit() );
539
540 }
542 std::cout <<
"inactive hits on this track, No." << aRecoTrk.
id() << std::endl;
543 }
544 else
545 {
546
547 refitTrack[trackMost] = 1;
548 for ( int ii = 0; ii < nMost; ii++ )
549 {
550 TrkHitOnTrk* alink = thoseHits[ii];
551 TrkFundHit* hit =
const_cast<TrkFundHit*
>( alink->
hit() );
552 TrkRecoTrk& othTrack = trkXRef[trackMost]->
track();
554
555
556 }
557 if ( 8 ==
tkParam.lPrint ) std::cout <<
"inactive hits on other track " << std::endl;
558 }
559 delete[] theseHits;
560 delete[] thoseHits;
561
562 }
563
564 }
565
566
567
568 TrkErrCode fitResult;
569 long index = -1;
570 idMap.
get( aRecoTrk.
id(), index );
571 assert( index >= 0 );
572
573 if ( lRefit || refitTrack[index] == 1 )
574 {
576 { std::cout <<
"after group ,refit track" << aRecoTrk.
id() << std::endl; }
577 fitResult = hitList->
fit();
580 "Arbitrated" ),
581 "MdcTrkRecon" );
583
584 double chisqperDOF;
585 bool badFit = true;
587 {
588 badFit = false;
589 int nDOF = tkFit->
nActive() - 5;
590 if ( nDOF > 5 ) { chisqperDOF = tkFit->
chisq() / nDOF; }
591 else { chisqperDOF = tkFit->
chisq(); }
592
593 if ( chisqperDOF >
tkParam.maxChisq ) badFit =
true;
595 double tem2 = (float)hitList->
nHit() - tkFit->
nActive();
597 {
598 if ( tem2 >=
tkParam.maxNmissTrack ) badFit =
true;
599 if ( tem2 /
float( hitList->
nHit() ) >
tkParam.maxNmissNorm ) { badFit =
true; }
600 }
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;
609 }
611 {
612 cout <<
"Refitting track " << aRecoTrk.
id() <<
" success = " << fitResult.
success()
613 << "\n";
614 }
615
616 if ( fitResult.
failure() || badFit )
617 {
618 nDeleted++;
619
620
621
623 {
624 cout <<
"fitResult.failure? " << fitResult.
failure() <<
" badFit? " << badFit
625 << " Killing tkNo " << itrack << endl;
626 }
627
628
629 trksToKill.push_back( atrack );
630 continue;
631 }
632 }
633
634 if ( lGroupHits ) goto restart;
635
636 }
637 if ( 8 ==
tkParam.lPrint ) std::cout <<
"end of loop over tracks" << std::endl;
638
639
640 for ( int itk = 0; itk < (int)trksToKill.size(); itk++ )
641 {
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;
646 }
647 if ( 8 ==
tkParam.lPrint ) std::cout <<
"---end of arbitrateHits" << std::endl;
648
649 delete[] usedInTrackNum;
650 delete[] refitTrack;
651 delete[] trkXRef;
652 return nDeleted;
653}
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
bool get(const K &theKey, V &theAnswer) const
void put(const K &, const V &)
void remove(MdcTrack *atrack)
void setTrack(TrkRecoTrk *trk)
virtual double chisq() const =0
void print(std::ostream &ostr) const
virtual void addHistory(const TrkErrCode &status, const char *modulename)
virtual int nActive() const =0
TrkHitOnTrkIter< TrkFundHit > hot_iterator
hot_iterator begin() const
bool removeHit(const TrkFundHit *theHit)
TrkHotList::hot_iterator hot_iterator
void setActivity(bool turnOn)
double resid(bool exclude=false) const
TrkRecoTrk * parentTrack() const
const TrkFundHit * hit() const
const TrkFit * fitResult() const
const TrkFitStatus * status() const