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<edm::
ParameterSet>(
"trajectoryFilter"), iC),
117 conf.getParameter<bool>(
"useSameTrajFilter")
119 conf.getParameter<edm::
ParameterSet>(
"trajectoryFilter"), iC)
121 conf.getParameter<edm::
ParameterSet>(
"inOutTrajectoryFilter"), iC)) {
136 ? conf.
getParameter<
double>(
"maxPtForLooperReconstruction")
140 ? conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction")
210 std::shared_ptr<const TrajectorySeed> sharedSeed;
214 sharedSeed = result.front().sharedSeed();
216 work.reserve(result.size());
217 for (
auto&& traj : result)
227 for (
auto const& it : work)
229 final.push_back(it.toTrajectory());
230 final.back().setSharedSeed(sharedSeed);
235 statCount.rebuilt(result.size());
240 unsigned int& nCandPerSeed,
244 <<
"Asking to create trajectories to an un-initialized GroupedCkfTrajectoryBuilder.\nYou have to call "
245 "clone(const MeasurementTrackerEvent *data) and then call trajectories on it instead.\n";
258 const bool inOut =
true;
265 cleaner.
clean(work_);
267 std::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
268 for (
auto const& it : work_)
270 result.push_back(it.toTrajectory());
271 result.back().setSharedSeed(pseed);
281 LogDebug(
"CkfPattern") <<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
282 statCount.traj(result.size());
286 for (
auto const& traj : result) {
288 for (
auto const& tm : traj.measurements()) {
289 auto const&
hit = tm.recHitR();
292 if (
hit.det() ==
nullptr)
296 if (
hit.dimension() != 2) {
300 auto const& clus = thit.firstClusterRef();
303 else if (thit.isMatched()) {
305 }
else if (thit.isProjected()) {
329 unsigned int nIter = 1;
330 unsigned int nCands = 0;
331 unsigned int prevNewCandSize = 0;
334 candidates.push_back(startingTraj);
336 while (!candidates.empty()) {
338 for (TempTrajectoryContainer::iterator traj = candidates.begin(); traj != candidates.end(); traj++) {
339 if (!
advanceOneLayer(seed, *traj, regionalCondition, propagator, inOut, newCand, result)) {
340 LogDebug(
"CkfPattern") <<
"GCTB: terminating after advanceOneLayer==false";
348 nCands += newCand.size() - prevNewCandSize;
349 prevNewCandSize = newCand.size();
354 std::nth_element(newCand.begin(),
358 newCand.erase(newCand.begin() +
theMaxCand, newCand.end());
360 LogDebug(
"CkfPattern") <<
"newCand(2): after removing extra candidates.\n"
364 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
374 #ifdef STANDARD_INTERMEDIARYCLEAN
380 candidates.swap(newCand);
382 LogDebug(
"CkfPattern") <<
"candidates(3): " << result.size() <<
" candidates after " << nIter++
383 <<
" groupedCKF iteration: \n"
385 <<
" running candidates are: \n"
396 vector<const DetLayer*>& nl = stateAndLayers.second;
410 buffer <<
"Trying to go to";
411 for (vector<const DetLayer*>::iterator il = nl.begin(); il != nl.end(); il++) {
429 buffer <<
"GCTB: starting from "
434 << stateToUse.
charge() <<
" for layer at " << l << endl;
435 buffer <<
" errors:";
436 for (
int i = 0;
i < 5;
i++)
460 std::pair<TSOS, std::vector<const DetLayer*> >&& stateAndLayers =
findStateAndLayers(seed, traj);
466 float pt2 = stateAndLayers.first.globalMomentum().perp2();
467 if (pt2 < maxPt2ForLooperReconstruction && pt2 > (0.3
f * 0.3
f))
468 stateAndLayers.second.push_back(traj.
lastLayer());
472 auto layerBegin = stateAndLayers.second.begin();
473 auto layerEnd = stateAndLayers.second.end();
481 LogDebug(
"CkfPattern") << whatIsTheNextStep(traj, stateAndLayers);
484 bool foundSegments(
false);
485 bool foundNewCandidates(
false);
486 for (
auto il = layerBegin; il != layerEnd; il++) {
487 TSOS stateToUse = stateAndLayers.first;
489 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)
537 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
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
640 foundNewCandidates =
true;
644 LogDebug(
"CkfPattern") <<
"GCTB: adding completed trajectory to results if passes cuts: inOut=" << inOut
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) {
698 if (theTrajectories.empty())
701 LayersInTraj
layers[theTrajectories.size()];
703 for (
auto& t : theTrajectories) {
705 layers[ntraj++].
fill(t);
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())
778 if (!
tkxor(firstValid, secondValid))
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());
831 LogDebug(
"CkfPattern") <<
"Starting to rebuild " << result.size() <<
" tracks";
839 std::vector<const TrackingRecHit*> seedHits;
841 unsigned int nSeed = seed.
nHits();
845 for (TempTrajectoryContainer::iterator it = result.begin(); it != result.end(); it++) {
850 auto&& reFitted =
backwardFit(*it, nSeed, fitter, seedHits);
852 rebuiltTrajectories.push_back(
std::move(*it));
853 LogDebug(
"CkfPattern") <<
"RebuildSeedingRegion skipped as backward fit failed";
866 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
867 rebuiltTrajectories[
i].setStopReason(it->stopReason());
874 rebuiltTrajectories.push_back(
std::move(*it));
879 result.swap(rebuiltTrajectories);
880 result.erase(std::remove_if(result.begin(), result.end(), std::not_fn(&
TempTrajectory::isValid)), result.end());
884 const std::vector<const TrackingRecHit*>& seedHits,
925 const bool inOut =
false;
933 int nrOfTrajectories(0);
934 bool orig_ok =
false;
937 for (TempTrajectoryContainer::iterator it = rebuiltTrajectories.begin(); it != rebuiltTrajectories.end(); it++) {
946 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
953 LogDebug(
"CkfPattern") <<
"seed hits not found in rebuild";
964 reversedTrajectory.
setNLoops(it->nLoops());
968 reversedTrajectory.
push(*im);
971 LogDebug(
"CkgPattern") <<
"New traj direction = " << reversedTrajectory.
direction() <<
"\n"
984 if ((nrOfTrajectories == 0) && orig_ok) {
985 nrOfTrajectories = -1;
987 return nrOfTrajectories;
993 std::vector<const TrackingRecHit*>& remainingHits)
const {
997 remainingHits.clear();
999 LogDebug(
"CkfPattern") <<
"nSeed " << nSeed << endl
1000 <<
"Old traj direction = " << candidate.
direction() << endl
1010 unsigned int nHit(0);
1037 if (nHit < nHitMin) {
1039 bwdDetLayer[nl++] = tm.layer();
1056 remainingHits.push_back(hit);
1063 return TempTrajectory();
1075 return TempTrajectory();
1077 LogDebug(
"CkfPattern") <<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1078 TempTrajectory fitted(fwdTraj.
direction(), nSeed);
1079 fitted.setNLoops(fwdTraj.
nLoops());
1086 for (vector<TM>::const_iterator im = tmsbf.begin(); im != tmsbf.end(); im++) {
1087 fitted.emplace((*im).forwardPredictedState(),
1088 (*im).backwardPredictedState(),
1089 (*im).updatedState(),
1092 bwdDetLayer[iDetLayer]);
1113 const std::vector<const TrackingRecHit*>& hits)
const {
1117 LogDebug(
"CkfPattern") <<
"Checking for " << hits.size() <<
" hits in " << maxDepth <<
" measurements" << endl;
1120 while (maxDepth > 0) {
1124 for (
auto ir = hits.begin(); ir != hits.end(); ir++) {
1126 bool foundHit(
false);
1127 for (
auto im = rbegin; im != rend; --im) {
1128 if (im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some)) {
PropagationDirection direction() const
void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
void rescaleError(double factor)
const_iterator rend() const
tuple ret
prodAgent to be discontinued
unsigned int groupedLimitedCandidates(const TrajectorySeed &seed, TempTrajectory const &startingTraj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &result) const
static std::string dumpCandidates(collection &candidates)
const edm::EventSetup & c
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
virtual float length() const =0
void join(TempTrajectory &segment)
TrackCharge charge() const
bool empty() const
True if trajectory has no measurements.
bool isFromDet(TrackingRecHit const &hit)
virtual Location location() const =0
Which part of the detector (barrel, endcap)
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
const CurvilinearTrajectoryError & curvilinearError() const
const DataContainer & measurements() const
Geom::Phi< T > phi() const
void setNLoops(signed char value)
void setNLoops(signed char value)
const TrajectoryStateUpdator * theUpdator
virtual void analyseSeed(const TrajectorySeed &seed) const
GlobalPoint globalPosition() const
ConstRecHitContainer recHits() const
virtual PropagationDirection propagationDirection() const final
void addToResult(std::shared_ptr< const TrajectorySeed > const &seed, TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
float maxDPhiForLooperReconstruction
static std::string dumpMeasurement(const TrajectoryMeasurement &tm)
static std::string dumpMeasurements(const std::vector< TrajectoryMeasurement > &v)
unsigned int theMinNrOf2dHitsForRebuild
TempTrajectory buildTrajectories(const TrajectorySeed &seed, TrajectoryContainer &ret, unsigned int &nCandPerSeed, const TrajectoryFilter *) const override
common part of both public trajectory building methods
signed char nLoops() const
const TrajectoryMeasurement & lastMeasurement() const
float maxPt2ForLooperReconstruction
PropagationDirection const & direction() const
PropagationDirection direction() const
void setDPhiCacheForLoopersReconstruction(float dphi)
DataContainer const & measurements() const
const TransientTrackingRecHitBuilder * hitBuilder() const
virtual void analyseResult(const TrajectoryContainer &result) const
static PropagationDirection oppositeDirection(PropagationDirection dir)
change of propagation direction
GroupedCkfTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
constructor from ParameterSet
bool verifyHits(TempTrajectory::DataContainer::const_iterator rbegin, size_t maxDepth, const std::vector< const TrackingRecHit * > &hits) const
Verifies presence of a RecHits in a range of TrajectoryMeasurements.
void groupedIntermediaryClean(TempTrajectoryContainer &theTrajectories) const
intermediate cleaning in the case of grouped measurements
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
const Chi2MeasurementEstimatorBase & estimator() const
Abs< T >::type abs(const T &t)
TempTrajectory backwardFit(TempTrajectory &candidate, unsigned int nSeed, const TrajectoryFitter &fitter, std::vector< const TrackingRecHit * > &remainingHits) const
const DetLayer * layer() const
bool advanceOneLayer(const TrajectorySeed &seed, TempTrajectory &traj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &newCand, TempTrajectoryContainer &result) const
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
const_iterator rbegin() const
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
const MeasurementTrackerEvent * theMeasurementTracker
bool theKeepOriginalIfRebuildFails
TrajectoryMeasurement const & firstMeasurement() const
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
unsigned int theMinNrOfHitsForRebuild
std::vector< TempTrajectory > TempTrajectoryContainer
T getParameter(std::string const &) const
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
ConstRecHitPointer::element_type const & recHitR() const
const TrajectoryStateUpdator & updator() const
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
void rebuildTrajectories(TempTrajectory const &startingTraj, const TrajectorySeed &, TrajectoryContainer &result) const override
unsigned int nHits() const
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
TrajectoryContainer trajectories(const TrajectorySeed &) const override
set Event for the internal MeasurementTracker data member
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
void setStopReason(StopReason s)
bool tkxor(bool a, bool b) const
bool theIntermediateCleaning
virtual const BoundDisk & specificSurface() const final
bool isUndef(TrackingRecHit const &hit)
const Propagator * backwardPropagator(const TrajectorySeed &seed) const
TrajectoryStateOnSurface const & updatedState() const
bool theRequireSeedHitsInRebuild
signed char nLoops() const
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
const BasicVectorType & basicVector() const
void push(const TrajectoryMeasurement &tm)
std::vector< Trajectory > TrajectoryContainer
const Chi2MeasurementEstimatorBase * theEstimator
void rebuildSeedingRegion(const TrajectorySeed &, TrajectoryContainer &result) const override
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
void push(const TrajectoryMeasurement &tm)
void clean(TempTrajectoryContainer &) const override
double transverseCurvature() const