60 void zero() { totSeed = totTraj = totRebuilt = totInvCand = 0; }
61 void traj(
long long t) { totTraj +=
t; }
62 void seed() { ++totSeed; }
63 void rebuilt(
long long t) { totRebuilt +=
t; }
64 void invalid() { ++totInvCand; }
66 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt " << totSeed <<
'/' << totTraj <<
'/' 67 << totRebuilt << std::endl;
69 StatCount() {
zero(); }
70 ~StatCount() {
print(); }
76 void traj(
long long) {}
78 void rebuilt(
long long) {}
92 #ifdef STANDARD_INTERMEDIARYCLEAN 119 conf.getParameter<
bool>(
"useSameTrajFilter")
156 iDesc.
add<
bool>(
"useSameTrajFilter",
true);
157 iDesc.
add<
int>(
"maxCand", 5);
158 iDesc.
add<
double>(
"lostHitPenalty", 30.);
159 iDesc.
add<
double>(
"foundHitBonus", 10.);
160 iDesc.
add<
bool>(
"intermediateCleaning",
true);
161 iDesc.
add<
bool>(
"alwaysUseInvalidHits",
true);
162 iDesc.
add<
bool>(
"lockHits",
true);
163 iDesc.
add<
bool>(
"bestHitOnly",
true);
164 iDesc.
add<
bool>(
"requireSeedHitsInRebuild",
true);
165 iDesc.
add<
bool>(
"keepOriginalIfRebuildFails",
false);
166 iDesc.
add<
int>(
"minNrOfHitsForRebuild", 5);
167 iDesc.
add<
double>(
"maxPtForLooperReconstruction", 0.);
168 iDesc.
add<
double>(
"maxDPhiForLooperReconstruction", 2.0);
231 std::shared_ptr<const TrajectorySeed> sharedSeed;
235 sharedSeed =
result.front().sharedSeed();
238 for (
auto&& traj :
result)
248 for (
auto const&
it :
work)
250 final.push_back(
it.toTrajectory());
251 final.back().setSharedSeed(sharedSeed);
256 statCount.rebuilt(
result.size());
261 unsigned int& nCandPerSeed,
265 <<
"Asking to create trajectories to an un-initialized GroupedCkfTrajectoryBuilder.\nYou have to call " 266 "clone(const MeasurementTrackerEvent *data) and then call trajectories on it instead.\n";
279 const bool inOut =
true;
286 cleaner.
clean(work_);
289 for (
auto const&
it : work_)
291 result.push_back(
it.toTrajectory());
292 result.back().setSharedSeed(pseed);
302 LogDebug(
"CkfPattern") <<
"GroupedCkfTrajectoryBuilder: returning result of size " <<
result.size();
303 statCount.traj(
result.size());
307 for (
auto const& traj :
result) {
309 for (
auto const& tm : traj.measurements()) {
310 auto const&
hit = tm.recHitR();
313 if (
hit.det() ==
nullptr)
317 if (
hit.dimension() != 2) {
321 auto const& clus = thit.firstClusterRef();
324 else if (thit.isMatched()) {
326 }
else if (thit.isProjected()) {
348 unsigned int nIter = 1;
349 unsigned int nCands = 0;
350 unsigned int prevNewCandSize = 0;
358 for (TempTrajectoryContainer::iterator traj =
candidates.begin(); traj !=
candidates.end(); traj++) {
360 LogDebug(
"CkfPattern") <<
"GCTB: terminating after advanceOneLayer==false";
368 nCands += newCand.size() - prevNewCandSize;
369 prevNewCandSize = newCand.size();
374 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
377 #ifdef STANDARD_INTERMEDIARYCLEAN 385 LogDebug(
"CkfPattern") <<
"candidates(3): " <<
result.size() <<
" candidates after " << nIter++
386 <<
" groupedCKF iteration: \n" 388 <<
" running candidates are: \n" 399 vector<const DetLayer*>& nl = stateAndLayers.second;
413 buffer <<
"Trying to go to";
414 for (vector<const DetLayer*>::iterator il = nl.begin(); il != nl.end(); il++) {
432 buffer <<
"GCTB: starting from " 437 << stateToUse.
charge() <<
" for layer at " <<
l << endl;
439 for (
int i = 0;
i < 5;
i++)
472 float pt2 = stateAndLayers.first.globalMomentum().perp2();
473 if (pt2 < maxPt2ForLooperReconstruction && pt2 > (0.3
f * 0.3
f))
474 stateAndLayers.second.push_back(traj.
lastLayer());
478 auto layerBegin = stateAndLayers.second.begin();
479 auto layerEnd = stateAndLayers.second.end();
487 LogDebug(
"CkfPattern") << whatIsTheNextStep(traj, stateAndLayers);
490 bool foundSegments(
false);
491 bool foundNewCandidates(
false);
492 for (
auto il = layerBegin; il != layerEnd; il++) {
493 TSOS stateToUse = stateAndLayers.first;
495 double dPhiCacheForLoopersReconstruction(0);
507 if (!cylinderCrossing.hasSolution())
510 GlobalPoint target1 = cylinderCrossing.position1();
511 GlobalPoint target2 = cylinderCrossing.position2();
514 fabs(starting.
phi() - target1.
phi()) > fabs(starting.
phi() - target2.
phi()) ? target1 : target2;
517 float length = 0.5f *
bounds.length();
533 if (fabs(farther.
z()) * 0.95
f > length)
548 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
555 LogDebug(
"CkfPattern") <<
" self propagating in advanceOneLayer.\n from: \n" << stateToUse;
564 LogDebug(
"CkfPattern") <<
"to: " << stateToUse;
574 LogDebug(
"CkfPattern") << whatIsTheStateToUse(stateAndLayers.first, stateToUse, *il);
577 auto&& segments = layerBuilder.segments(stateToUse);
579 LogDebug(
"CkfPattern") <<
"GCTB: number of segments = " << segments.size();
581 if (!segments.empty())
582 foundSegments =
true;
584 for (
auto is = segments.begin(); is != segments.end(); is++) {
588 auto const& measurements = is->measurements();
594 bool toBeRejected(
false);
595 for (
auto revIt = measurements.rbegin(); revIt != measurements.rend(); --revIt) {
600 if (revIt->recHitR().geographicalId() == newTrajMeasIt->recHitR().geographicalId() &&
601 (revIt->recHitR().geographicalId() !=
DetId(0))) {
612 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
613 cout <<
"-- discarded track's pt,eta,#found/lost: " 641 LogDebug(
"CkfPattern") <<
"GCTB: adding updated trajectory to candidates: inOut=" << inOut
646 bool better = lessTraj(newTraj, newCand.front());
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);
656 foundNewCandidates =
true;
659 std::make_heap(newCand.begin(), newCand.end(), lessTraj);
664 LogDebug(
"CkfPattern") <<
"GCTB: adding completed trajectory to results if passes cuts: inOut=" << inOut
671 if (!foundSegments) {
672 LogDebug(
"CkfPattern") <<
"GCTB: adding input trajectory to result";
673 if (!stateAndLayers.second.empty())
677 return foundNewCandidates;
683 struct LayersInTraj {
686 std::array<DetLayer const*, N>
layers;
697 if (im->layer() != currl) {
718 if (theTrajectories.empty())
721 LayersInTraj
layers[theTrajectories.size()];
723 for (
auto&
t : theTrajectories) {
724 if (
t.isValid() &&
t.lastMeasurement().recHitR().isValid())
731 for (
int ifirst = 0; ifirst != ntraj - 1; ++ifirst) {
732 auto firstTraj =
layers[ifirst].traj;
733 if (!firstTraj->isValid())
737 int firstLayerSize =
layers[ifirst].tot;
738 if (firstLayerSize < 4)
740 auto const& firstLayers =
layers[ifirst].layers;
742 for (
int isecond = ifirst + 1; isecond != ntraj; ++isecond) {
743 auto secondTraj =
layers[isecond].traj;
744 if (!secondTraj->isValid())
749 int secondLayerSize =
layers[isecond].tot;
753 if (firstLayerSize != secondLayerSize)
755 auto const& secondLayers =
layers[isecond].layers;
756 if (firstLayers[0] != secondLayers[0] || firstLayers[1] != secondLayers[1] || firstLayers[2] != secondLayers[2])
765 const DetLayer* layerPtr = firstLayers[0];
766 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
767 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
769 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
778 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
779 im2->layer() == layerPtr || unequal)
785 layerPtr = firstLayers[1];
787 while (im1 != firstMeasurements.
rend() && im1->layer() == layerPtr) {
788 if (!im1->recHit()->isValid())
792 bool secondValid(
true);
793 while (im2 != secondMeasurements.
rend() && im2->layer() == layerPtr) {
794 if (!im2->recHit()->isValid())
804 layerPtr = firstLayers[2];
805 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
806 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
808 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
817 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
818 im2->layer() == layerPtr || unequal)
822 firstTraj->invalidate();
825 secondTraj->invalidate();
838 theTrajectories.erase(
840 theTrajectories.end());
850 LogDebug(
"CkfPattern") <<
"Starting to rebuild " <<
result.size() <<
" tracks";
858 std::vector<const TrackingRecHit*> seedHits;
860 unsigned int nSeed =
seed.nHits();
864 for (TempTrajectoryContainer::iterator
it =
result.begin();
it !=
result.end();
it++) {
872 LogDebug(
"CkfPattern") <<
"RebuildSeedingRegion skipped as backward fit failed";
885 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
886 rebuiltTrajectories[
i].setStopReason(
it->stopReason());
898 result.swap(rebuiltTrajectories);
903 const std::vector<const TrackingRecHit*>& seedHits,
944 const bool inOut =
false;
952 int nrOfTrajectories(0);
953 bool orig_ok =
false;
956 for (TempTrajectoryContainer::iterator
it = rebuiltTrajectories.begin();
it != rebuiltTrajectories.end();
it++) {
965 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
972 LogDebug(
"CkfPattern") <<
"seed hits not found in rebuild";
987 reversedTrajectory.
push(*im);
990 LogDebug(
"CkgPattern") <<
"New traj direction = " << reversedTrajectory.
direction() <<
"\n" 1003 if ((nrOfTrajectories == 0) && orig_ok) {
1004 nrOfTrajectories = -1;
1006 return nrOfTrajectories;
1012 std::vector<const TrackingRecHit*>& remainingHits)
const {
1016 remainingHits.clear();
1018 LogDebug(
"CkfPattern") <<
"nSeed " << nSeed << endl
1019 <<
"Old traj direction = " << candidate.
direction() << endl
1029 unsigned int nHit(0);
1058 bwdDetLayer[nl++] = tm.layer();
1073 else if (
hit->isValid()) {
1075 remainingHits.push_back(
hit);
1096 LogDebug(
"CkfPattern") <<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1105 for (vector<TM>::const_iterator im = tmsbf.begin(); im != tmsbf.end(); im++) {
1106 fitted.emplace((*im).forwardPredictedState(),
1107 (*im).backwardPredictedState(),
1108 (*im).updatedState(),
1111 bwdDetLayer[iDetLayer]);
1132 const std::vector<const TrackingRecHit*>&
hits)
const {
1136 LogDebug(
"CkfPattern") <<
"Checking for " <<
hits.size() <<
" hits in " <<
maxDepth <<
" measurements" << endl;
1143 for (
auto ir =
hits.begin(); ir !=
hits.end(); ir++) {
1145 bool foundHit(
false);
1146 for (
auto im = rbegin; im != rend; --im) {
1147 if (im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some)) {
void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
const Chi2MeasurementEstimatorBase & estimator() const
void rescaleError(double factor)
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
PropagationDirection direction() const
T getParameter(std::string const &) const
static std::string dumpCandidates(collection &candidates)
TempTrajectory backwardFit(TempTrajectory &candidate, unsigned int nSeed, const TrajectoryFitter &fitter, std::vector< const TrackingRecHit *> &remainingHits) const
const_iterator rbegin() const
void join(TempTrajectory &segment)
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
bool isFromDet(TrackingRecHit const &hit)
virtual Location location() const =0
Which part of the detector (barrel, endcap)
ret
prodAgent to be discontinued
virtual void analyseResult(const TrajectoryContainer &result) const
Geom::Phi< T > phi() const
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
const Propagator * backwardPropagator(const TrajectorySeed &seed) const
const TrajectoryStateUpdator * theUpdator
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
void groupedIntermediaryClean(TempTrajectoryContainer &theTrajectories) const
intermediate cleaning in the case of grouped measurements
float maxDPhiForLooperReconstruction
const DataContainer & measurements() const
static std::string dumpMeasurement(const TrajectoryMeasurement &tm)
void setNLoops(int8_t value)
static std::string dumpMeasurements(const std::vector< TrajectoryMeasurement > &v)
unsigned int theMinNrOf2dHitsForRebuild
DataContainer const & measurements() const
float maxPt2ForLooperReconstruction
void setDPhiCacheForLoopersReconstruction(float dphi)
void buildTrajectories(const TrajectorySeed &seed, TrajectoryContainer &ret, unsigned int &nCandPerSeed, const TrajectoryFilter *) const override
common part of both public trajectory building methods
GlobalPoint globalPosition() const
static PropagationDirection oppositeDirection(PropagationDirection dir)
change of propagation direction
GroupedCkfTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
constructor from ParameterSet
void rebuildTrajectories(const TrajectorySeed &, TrajectoryContainer &result) const override
PropagationDirection const & direction() const
ConstRecHitContainer recHits() const
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
const TrajectoryMeasurement & lastMeasurement() const
Abs< T >::type abs(const T &t)
bool advanceOneLayer(const TrajectorySeed &seed, TempTrajectory &traj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &newCand, TempTrajectoryContainer &result) const
TrackCharge charge() const
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.
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
const BasicVectorType & basicVector() const
const MeasurementTrackerEvent * theMeasurementTracker
bool theKeepOriginalIfRebuildFails
const TransientTrackingRecHitBuilder * hitBuilder() const
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
const CurvilinearTrajectoryError & curvilinearError() const
unsigned int theMinNrOfHitsForRebuild
const AlgebraicSymMatrix55 & matrix() const
std::vector< TempTrajectory > TempTrajectoryContainer
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
void setNLoops(int8_t value)
double transverseCurvature() const
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
GlobalVector globalMomentum() const
TrajectoryStateOnSurface const & updatedState() const
const TrajectoryStateUpdator & updator() const
virtual void analyseSeed(const TrajectorySeed &seed) const
TrajectoryMeasurement const & firstMeasurement() const
void addToResult(std::shared_ptr< const TrajectorySeed > const &seed, TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
TrajectoryContainer trajectories(const TrajectorySeed &) const override
set Event for the internal MeasurementTracker data member
void setStopReason(StopReason s)
const_iterator rend() const
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
bool theIntermediateCleaning
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
virtual const BoundDisk & specificSurface() const final
bool isUndef(TrackingRecHit const &hit)
signed char nLoops() const
bool theRequireSeedHitsInRebuild
unsigned int groupedLimitedCandidates(const TrajectorySeed &seed, TempTrajectory const &startingTraj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &result) const
void push(const TrajectoryMeasurement &tm)
const DetLayer * layer() const
std::vector< Trajectory > TrajectoryContainer
const Chi2MeasurementEstimatorBase * theEstimator
void rebuildSeedingRegion(const TrajectorySeed &, TrajectoryContainer &result) const override
bool tkxor(bool a, bool b) const
bool empty() const
True if trajectory has no measurements.
void push(const TrajectoryMeasurement &tm)
void clean(TempTrajectoryContainer &) const override