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);
500 if (!cylinderCrossing.hasSolution())
503 GlobalPoint target1 = cylinderCrossing.position1();
504 GlobalPoint target2 = cylinderCrossing.position2();
507 fabs(starting.
phi() - target1.
phi()) > fabs(starting.
phi() - target2.
phi()) ? target1 : target2;
510 float length = 0.5f * bounds.
length();
526 if (fabs(farther.
z()) * 0.95
f > length)
541 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
548 LogDebug(
"CkfPattern") <<
" self propagating in advanceOneLayer.\n from: \n" << stateToUse;
557 LogDebug(
"CkfPattern") <<
"to: " << stateToUse;
567 LogDebug(
"CkfPattern") << whatIsTheStateToUse(stateAndLayers.first, stateToUse, *il);
570 auto&& segments = layerBuilder.segments(stateToUse);
572 LogDebug(
"CkfPattern") <<
"GCTB: number of segments = " << segments.size();
574 if (!segments.empty())
575 foundSegments =
true;
577 for (
auto is = segments.begin(); is != segments.end(); is++) {
581 auto const& measurements = is->measurements();
587 bool toBeRejected(
false);
588 for (
auto revIt = measurements.rbegin(); revIt != measurements.rend(); --revIt) {
593 if (revIt->recHitR().geographicalId() == newTrajMeasIt->recHitR().geographicalId() &&
594 (revIt->recHitR().geographicalId() !=
DetId(0))) {
605 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
606 cout <<
"-- discarded track's pt,eta,#found/lost: "
634 LogDebug(
"CkfPattern") <<
"GCTB: adding updated trajectory to candidates: inOut=" << inOut
635 <<
" hits=" << newTraj.foundHits();
639 foundNewCandidates =
true;
643 LogDebug(
"CkfPattern") <<
"GCTB: adding completed trajectory to results if passes cuts: inOut=" << inOut
644 <<
" hits=" << newTraj.foundHits();
650 if (!foundSegments) {
651 LogDebug(
"CkfPattern") <<
"GCTB: adding input trajectory to result";
652 if (!stateAndLayers.second.empty())
656 return foundNewCandidates;
662 struct LayersInTraj {
663 static constexpr
int N = 3;
665 std::array<DetLayer const*, N>
layers;
676 if (im->layer() != currl) {
694 void GroupedCkfTrajectoryBuilder::groupedIntermediaryClean(TempTrajectoryContainer& theTrajectories)
const {
697 if (theTrajectories.empty())
700 LayersInTraj
layers[theTrajectories.size()];
702 for (
auto&
t : theTrajectories) {
703 if (
t.isValid() &&
t.lastMeasurement().recHitR().isValid())
710 for (
int ifirst = 0; ifirst != ntraj - 1; ++ifirst) {
711 auto firstTraj =
layers[ifirst].traj;
712 if (!firstTraj->isValid())
716 int firstLayerSize =
layers[ifirst].tot;
717 if (firstLayerSize < 4)
719 auto const& firstLayers =
layers[ifirst].layers;
721 for (
int isecond = ifirst + 1; isecond != ntraj; ++isecond) {
722 auto secondTraj =
layers[isecond].traj;
723 if (!secondTraj->isValid())
728 int secondLayerSize =
layers[isecond].tot;
732 if (firstLayerSize != secondLayerSize)
734 auto const& secondLayers =
layers[isecond].layers;
735 if (firstLayers[0] != secondLayers[0] || firstLayers[1] != secondLayers[1] || firstLayers[2] != secondLayers[2])
744 const DetLayer* layerPtr = firstLayers[0];
745 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
746 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
748 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
757 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
758 im2->layer() == layerPtr || unequal)
764 layerPtr = firstLayers[1];
766 while (im1 != firstMeasurements.
rend() && im1->layer() == layerPtr) {
767 if (!im1->recHit()->isValid())
771 bool secondValid(
true);
772 while (im2 != secondMeasurements.
rend() && im2->layer() == layerPtr) {
773 if (!im2->recHit()->isValid())
783 layerPtr = firstLayers[2];
784 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
785 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
787 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
796 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
797 im2->layer() == layerPtr || unequal)
801 firstTraj->invalidate();
804 secondTraj->invalidate();
817 theTrajectories.erase(
819 theTrajectories.end());
824 TempTrajectoryContainer&
result)
const {
830 LogDebug(
"CkfPattern") <<
"Starting to rebuild " <<
result.size() <<
" tracks";
835 auto hitCloner = static_cast<TkTransientTrackingRecHitBuilder const*>(
hitBuilder())->cloner();
838 std::vector<const TrackingRecHit*> seedHits;
840 unsigned int nSeed =
seed.nHits();
844 for (TempTrajectoryContainer::iterator it =
result.begin(); it !=
result.end(); it++) {
849 auto&& reFitted = backwardFit(*it, nSeed, fitter, seedHits);
851 rebuiltTrajectories.push_back(
std::move(*it));
852 LogDebug(
"CkfPattern") <<
"RebuildSeedingRegion skipped as backward fit failed";
865 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
866 rebuiltTrajectories[
i].setStopReason(it->stopReason());
873 rebuiltTrajectories.push_back(
std::move(*it));
878 result.swap(rebuiltTrajectories);
883 const std::vector<const TrackingRecHit*>& seedHits,
885 TempTrajectoryContainer&
result)
const {
924 const bool inOut =
false;
932 int nrOfTrajectories(0);
933 bool orig_ok =
false;
936 for (TempTrajectoryContainer::iterator it = rebuiltTrajectories.begin(); it != rebuiltTrajectories.end(); it++) {
945 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
951 if (!verifyHits(newMeasurements.rbegin(), newMeasurements.size() - candidate.
measurements().
size(), seedHits)) {
952 LogDebug(
"CkfPattern") <<
"seed hits not found in rebuild";
963 reversedTrajectory.
setNLoops(it->nLoops());
967 reversedTrajectory.
push(*im);
970 LogDebug(
"CkgPattern") <<
"New traj direction = " << reversedTrajectory.
direction() <<
"\n"
983 if ((nrOfTrajectories == 0) && orig_ok) {
984 nrOfTrajectories = -1;
986 return nrOfTrajectories;
992 std::vector<const TrackingRecHit*>& remainingHits)
const {
996 remainingHits.clear();
998 LogDebug(
"CkfPattern") <<
"nSeed " << nSeed << endl
999 <<
"Old traj direction = " << candidate.
direction() << endl
1009 unsigned int nHit(0);
1025 fwdTraj.setNLoops(candidate.
nLoops());
1038 bwdDetLayer[nl++] = tm.layer();
1053 else if (
hit->isValid()) {
1055 remainingHits.push_back(
hit);
1076 LogDebug(
"CkfPattern") <<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1085 for (vector<TM>::const_iterator im = tmsbf.begin(); im != tmsbf.end(); im++) {
1086 fitted.emplace((*im).forwardPredictedState(),
1087 (*im).backwardPredictedState(),
1088 (*im).updatedState(),
1091 bwdDetLayer[iDetLayer]);
1112 const std::vector<const TrackingRecHit*>&
hits)
const {
1116 LogDebug(
"CkfPattern") <<
"Checking for " <<
hits.size() <<
" hits in " <<
maxDepth <<
" measurements" << endl;
1123 for (
auto ir =
hits.begin(); ir !=
hits.end(); ir++) {
1125 bool foundHit(
false);
1126 for (
auto im = rbegin; im != rend; --im) {
1127 if (im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some)) {