Skip to content

Commit 194b3ed

Browse files
committed
do not sort, limit to maxCand in grouped as well
1 parent 1c90a19 commit 194b3ed

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

RecoTracker/CkfPattern/plugins/GroupedCkfTrajectoryBuilder.cc

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ unsigned int GroupedCkfTrajectoryBuilder::groupedLimitedCandidates(const Traject
350350
unsigned int prevNewCandSize = 0;
351351
TempTrajectoryContainer candidates;
352352
TempTrajectoryContainer newCand;
353+
newCand.reserve(theMaxCand);
353354
candidates.push_back(startingTraj);
354355

355356
while (!candidates.empty()) {
@@ -367,28 +368,11 @@ unsigned int GroupedCkfTrajectoryBuilder::groupedLimitedCandidates(const Traject
367368
nCands += newCand.size() - prevNewCandSize;
368369
prevNewCandSize = newCand.size();
369370

370-
if ((int)newCand.size() > theMaxCand) {
371-
//ShowCand()(newCand);
372-
373-
std::nth_element(newCand.begin(),
374-
newCand.begin() + theMaxCand,
375-
newCand.end(),
376-
GroupedTrajCandLess(theLostHitPenalty, theFoundHitBonus));
377-
newCand.erase(newCand.begin() + theMaxCand, newCand.end());
378-
}
379-
LogDebug("CkfPattern") << "newCand(2): after removing extra candidates.\n"
380-
<< PrintoutHelper::dumpCandidates(newCand);
371+
assert((int)newCand.size() <= theMaxCand);
381372
}
382373

383374
LogDebug("CkfPattern") << "newCand.size() at end = " << newCand.size();
384-
/*
385-
if (theIntermediateCleaning) {
386-
candidates.clear();
387-
candidates = groupedIntermediaryClean(newCand);
388-
} else {
389-
candidates.swap(newCand);
390-
}
391-
*/
375+
392376
if (theIntermediateCleaning) {
393377
#ifdef STANDARD_INTERMEDIARYCLEAN
394378
IntermediateTrajectoryCleaner::clean(newCand);
@@ -478,6 +462,9 @@ bool GroupedCkfTrajectoryBuilder::advanceOneLayer(const TrajectorySeed& seed,
478462
TempTrajectoryContainer& result) const {
479463
std::pair<TSOS, std::vector<const DetLayer*> >&& stateAndLayers = findStateAndLayers(seed, traj);
480464

465+
bool full = (int)newCand.size() == theMaxCand;
466+
auto lessTraj = GroupedTrajCandLess(theLostHitPenalty, theFoundHitBonus);
467+
481468
if (maxPt2ForLooperReconstruction > 0) {
482469
if (
483470
//stateAndLayers.second.size()==0 &&
@@ -655,8 +642,22 @@ bool GroupedCkfTrajectoryBuilder::advanceOneLayer(const TrajectorySeed& seed,
655642
<< " hits=" << newTraj.foundHits();
656643

657644
newTraj.setStopReason(StopReason::NOT_STOPPED);
658-
newCand.push_back(std::move(newTraj));
659-
foundNewCandidates = true;
645+
if (full) {
646+
bool better = lessTraj(newTraj, newCand.front());
647+
if (better) {
648+
// replace worst
649+
foundNewCandidates = true;
650+
std::pop_heap(newCand.begin(), newCand.end(), lessTraj);
651+
newCand.back().swap(newTraj);
652+
std::push_heap(newCand.begin(), newCand.end(), lessTraj);
653+
} // else? no need to add it just to remove it later!
654+
} else {
655+
newCand.push_back(std::move(newTraj));
656+
foundNewCandidates = true;
657+
full = (int)newCand.size() == theMaxCand;
658+
if (full)
659+
std::make_heap(newCand.begin(), newCand.end(), lessTraj);
660+
}
660661
} else {
661662
// Have finished building this track. Check if it passes cuts.
662663

RecoTracker/CkfPattern/src/CkfTrajectoryBuilder.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ unsigned int CkfTrajectoryBuilder::limitedCandidates(const std::shared_ptr<const
149149
} // else? no need to add it just to remove it later!
150150
} else {
151151
newCand.push_back(std::move(newTraj));
152-
std::push_heap(newCand.begin(), newCand.end(), trajCandLess);
153152
full = (int)newCand.size() == theMaxCand;
153+
if (full)
154+
std::make_heap(newCand.begin(), newCand.end(), trajCandLess);
154155
}
155156
} else {
156157
addToResult(sharedSeed, newTraj, result);
@@ -170,7 +171,7 @@ unsigned int CkfTrajectoryBuilder::limitedCandidates(const std::shared_ptr<const
170171
assert((int)newCand.size() == theMaxCand);
171172
} // end loop on candidates
172173

173-
std::sort_heap(newCand.begin(), newCand.end(), trajCandLess);
174+
// no reason to sort (no sorting in Grouped version!)
174175
if (theIntermediateCleaning)
175176
IntermediateTrajectoryCleaner::clean(newCand);
176177

0 commit comments

Comments
 (0)