58 void zero() { totSeed = totTraj = totRebuilt = totInvCand = 0; }
59 void traj(
long long t) { totTraj +=
t; }
60 void seed() { ++totSeed; }
61 void rebuilt(
long long t) { totRebuilt +=
t; }
62 void invalid() { ++totInvCand; }
64 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt " << totSeed <<
'/' << totTraj <<
'/'
65 << totRebuilt << std::endl;
67 StatCount() { zero(); }
68 ~StatCount() {
print(); }
74 void traj(
long long) {}
76 void rebuilt(
long long) {}
90 #ifdef STANDARD_INTERMEDIARYCLEAN
116 conf.getParameter<
bool>(
"useSameTrajFilter")
135 ? conf.
getParameter<
double>(
"maxPtForLooperReconstruction")
139 ? conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction")
209 std::shared_ptr<const TrajectorySeed> sharedSeed;
213 sharedSeed =
result.front().sharedSeed();
216 for (
auto&& traj :
result)
226 for (
auto const& it :
work)
228 final.push_back(it.toTrajectory());
229 final.back().setSharedSeed(sharedSeed);
234 statCount.rebuilt(
result.size());
239 unsigned int& nCandPerSeed,
243 <<
"Asking to create trajectories to an un-initialized GroupedCkfTrajectoryBuilder.\nYou have to call "
244 "clone(const MeasurementTrackerEvent *data) and then call trajectories on it instead.\n";
257 const bool inOut =
true;
264 cleaner.
clean(work_);
267 for (
auto const& it : work_)
269 result.push_back(it.toTrajectory());
270 result.back().setSharedSeed(pseed);
280 LogDebug(
"CkfPattern") <<
"GroupedCkfTrajectoryBuilder: returning result of size " <<
result.size();
281 statCount.traj(
result.size());
285 for (
auto const& traj :
result) {
287 for (
auto const& tm : traj.measurements()) {
288 auto const&
hit = tm.recHitR();
291 if (
hit.det() ==
nullptr)
295 if (
hit.dimension() != 2) {
298 auto const& thit = static_cast<BaseTrackerRecHit const&>(
hit);
299 auto const& clus = thit.firstClusterRef();
302 else if (thit.isMatched()) {
304 }
else if (thit.isProjected()) {
322 unsigned int GroupedCkfTrajectoryBuilder::groupedLimitedCandidates(
const TrajectorySeed&
seed,
327 TempTrajectoryContainer&
result)
const {
328 unsigned int nIter = 1;
329 unsigned int nCands = 0;
330 unsigned int prevNewCandSize = 0;
337 for (TempTrajectoryContainer::iterator traj =
candidates.begin(); traj !=
candidates.end(); traj++) {
339 LogDebug(
"CkfPattern") <<
"GCTB: terminating after advanceOneLayer==false";
347 nCands += newCand.size() - prevNewCandSize;
348 prevNewCandSize = newCand.size();
353 std::nth_element(newCand.begin(),
357 newCand.erase(newCand.begin() +
theMaxCand, newCand.end());
359 LogDebug(
"CkfPattern") <<
"newCand(2): after removing extra candidates.\n"
363 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
373 #ifdef STANDARD_INTERMEDIARYCLEAN
376 groupedIntermediaryClean(newCand);
381 LogDebug(
"CkfPattern") <<
"candidates(3): " <<
result.size() <<
" candidates after " << nIter++
382 <<
" groupedCKF iteration: \n"
384 <<
" running candidates are: \n"
395 vector<const DetLayer*>& nl = stateAndLayers.second;
407 << sfdl->specificSurface().phi() << endl;
409 buffer <<
"Trying to go to";
410 for (vector<const DetLayer*>::iterator il = nl.begin(); il != nl.end(); il++) {
412 const BarrelDetLayer* bdl = dynamic_cast<const BarrelDetLayer*>(*il);
413 const ForwardDetLayer* fdl = dynamic_cast<const ForwardDetLayer*>(*il);
428 buffer <<
"GCTB: starting from "
433 << stateToUse.
charge() <<
" for layer at " <<
l << endl;
435 for (
int i = 0;
i < 5;
i++)
457 TempTrajectoryContainer& newCand,
458 TempTrajectoryContainer&
result)
const {
465 float pt2 = stateAndLayers.first.globalMomentum().perp2();
466 if (pt2 < maxPt2ForLooperReconstruction && pt2 > (0.3
f * 0.3
f))
467 stateAndLayers.second.push_back(traj.
lastLayer());
471 auto layerBegin = stateAndLayers.second.begin();
472 auto layerEnd = stateAndLayers.second.end();
480 LogDebug(
"CkfPattern") << whatIsTheNextStep(traj, stateAndLayers);
483 bool foundSegments(
false);
484 bool foundNewCandidates(
false);
485 for (
auto il = layerBegin; il != layerEnd; il++) {
486 TSOS stateToUse = stateAndLayers.first;
488 double dPhiCacheForLoopersReconstruction(0);
501 if (!cylinderCrossing.hasSolution())
504 GlobalPoint target1 = cylinderCrossing.position1();
505 GlobalPoint target2 = cylinderCrossing.position2();
508 fabs(starting.
phi() - target1.
phi()) > fabs(starting.
phi() - target2.
phi()) ? target1 : target2;
511 float length = 0.5f * bounds.
length();
527 if (fabs(farther.
z()) * 0.95
f > length)
542 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
549 LogDebug(
"CkfPattern") <<
" self propagating in advanceOneLayer.\n from: \n" << stateToUse;
558 LogDebug(
"CkfPattern") <<
"to: " << stateToUse;
568 LogDebug(
"CkfPattern") << whatIsTheStateToUse(stateAndLayers.first, stateToUse, *il);
571 auto&& segments = layerBuilder.segments(stateToUse);
573 LogDebug(
"CkfPattern") <<
"GCTB: number of segments = " << segments.size();
575 if (!segments.empty())
576 foundSegments =
true;
578 for (
auto is = segments.begin(); is != segments.end(); is++) {
582 auto const& measurements = is->measurements();
588 bool toBeRejected(
false);
589 for (
auto revIt = measurements.rbegin(); revIt != measurements.rend(); --revIt) {
594 if (revIt->recHitR().geographicalId() == newTrajMeasIt->recHitR().geographicalId() &&
595 (revIt->recHitR().geographicalId() !=
DetId(0))) {
606 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
607 cout <<
"-- discarded track's pt,eta,#found/lost: "
635 LogDebug(
"CkfPattern") <<
"GCTB: adding updated trajectory to candidates: inOut=" << inOut
636 <<
" hits=" << newTraj.foundHits();
640 foundNewCandidates =
true;
644 LogDebug(
"CkfPattern") <<
"GCTB: adding completed trajectory to results if passes cuts: inOut=" << inOut
645 <<
" hits=" << newTraj.foundHits();
651 if (!foundSegments) {
652 LogDebug(
"CkfPattern") <<
"GCTB: adding input trajectory to result";
653 if (!stateAndLayers.second.empty())
657 return foundNewCandidates;
663 struct LayersInTraj {
664 static constexpr
int N = 3;
666 std::array<DetLayer const*, N>
layers;
677 if (im->layer() != currl) {
695 void GroupedCkfTrajectoryBuilder::groupedIntermediaryClean(TempTrajectoryContainer& theTrajectories)
const {
698 if (theTrajectories.empty())
701 LayersInTraj
layers[theTrajectories.size()];
703 for (
auto&
t : theTrajectories) {
704 if (
t.isValid() &&
t.lastMeasurement().recHitR().isValid())
711 for (
int ifirst = 0; ifirst != ntraj - 1; ++ifirst) {
712 auto firstTraj =
layers[ifirst].traj;
713 if (!firstTraj->isValid())
717 int firstLayerSize =
layers[ifirst].tot;
718 if (firstLayerSize < 4)
720 auto const& firstLayers =
layers[ifirst].layers;
722 for (
int isecond = ifirst + 1; isecond != ntraj; ++isecond) {
723 auto secondTraj =
layers[isecond].traj;
724 if (!secondTraj->isValid())
729 int secondLayerSize =
layers[isecond].tot;
733 if (firstLayerSize != secondLayerSize)
735 auto const& secondLayers =
layers[isecond].layers;
736 if (firstLayers[0] != secondLayers[0] || firstLayers[1] != secondLayers[1] || firstLayers[2] != secondLayers[2])
745 const DetLayer* layerPtr = firstLayers[0];
746 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
747 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
749 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
758 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
759 im2->layer() == layerPtr || unequal)
765 layerPtr = firstLayers[1];
767 while (im1 != firstMeasurements.
rend() && im1->layer() == layerPtr) {
768 if (!im1->recHit()->isValid())
772 bool secondValid(
true);
773 while (im2 != secondMeasurements.
rend() && im2->layer() == layerPtr) {
774 if (!im2->recHit()->isValid())
784 layerPtr = firstLayers[2];
785 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
786 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
788 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
797 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
798 im2->layer() == layerPtr || unequal)
802 firstTraj->invalidate();
805 secondTraj->invalidate();
818 theTrajectories.erase(
820 theTrajectories.end());
825 TempTrajectoryContainer&
result)
const {
831 LogDebug(
"CkfPattern") <<
"Starting to rebuild " <<
result.size() <<
" tracks";
836 auto hitCloner = static_cast<TkTransientTrackingRecHitBuilder const*>(
hitBuilder())->cloner();
840 std::vector<const TrackingRecHit*> seedHits;
847 unsigned int nSeed(rseedHits.second - rseedHits.first);
851 for (TempTrajectoryContainer::iterator it =
result.begin(); it !=
result.end(); it++) {
856 auto&& reFitted = backwardFit(*it, nSeed, fitter, seedHits);
859 rebuiltTrajectories.push_back(
std::move(*it));
860 LogDebug(
"CkfPattern") <<
"RebuildSeedingRegion skipped as backward fit failed";
873 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
874 rebuiltTrajectories[
i].setStopReason(it->stopReason());
881 rebuiltTrajectories.push_back(
std::move(*it));
886 result.swap(rebuiltTrajectories);
891 const std::vector<const TrackingRecHit*>& seedHits,
893 TempTrajectoryContainer&
result)
const {
932 const bool inOut =
false;
940 int nrOfTrajectories(0);
941 bool orig_ok =
false;
944 for (TempTrajectoryContainer::iterator it = rebuiltTrajectories.begin(); it != rebuiltTrajectories.end(); it++) {
953 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
959 if (!verifyHits(newMeasurements.rbegin(), newMeasurements.size() - candidate.
measurements().
size(), seedHits)) {
960 LogDebug(
"CkfPattern") <<
"seed hits not found in rebuild";
971 reversedTrajectory.
setNLoops(it->nLoops());
975 reversedTrajectory.
push(*im);
978 LogDebug(
"CkgPattern") <<
"New traj direction = " << reversedTrajectory.
direction() <<
"\n"
991 if ((nrOfTrajectories == 0) && orig_ok) {
992 nrOfTrajectories = -1;
994 return nrOfTrajectories;
1000 std::vector<const TrackingRecHit*>& remainingHits)
const {
1004 remainingHits.clear();
1006 LogDebug(
"CkfPattern") <<
"nSeed " << nSeed << endl
1007 <<
"Old traj direction = " << candidate.
direction() << endl
1017 unsigned int nHit(0);
1033 fwdTraj.setNLoops(candidate.
nLoops());
1046 bwdDetLayer[nl++] = tm.layer();
1062 else if (
hit->isValid()) {
1064 remainingHits.push_back(
hit);
1088 LogDebug(
"CkfPattern") <<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1097 for (vector<TM>::const_iterator im = tmsbf.begin(); im != tmsbf.end(); im++) {
1098 fitted.emplace((*im).forwardPredictedState(),
1099 (*im).backwardPredictedState(),
1100 (*im).updatedState(),
1103 bwdDetLayer[iDetLayer]);
1124 const std::vector<const TrackingRecHit*>&
hits)
const {
1128 LogDebug(
"CkfPattern") <<
"Checking for " <<
hits.size() <<
" hits in " <<
maxDepth <<
" measurements" << endl;
1135 for (
auto ir =
hits.begin(); ir !=
hits.end(); ir++) {
1137 bool foundHit(
false);
1138 for (
auto im = rbegin; im != rend; --im) {
1139 if (im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some)) {