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);
234 std::shared_ptr<const TrajectorySeed> sharedSeed;
238 sharedSeed =
result.front().sharedSeed();
241 for (
auto&& traj :
result)
251 for (
auto const&
it :
work)
253 final.push_back(
it.toTrajectory());
254 final.back().setSharedSeed(sharedSeed);
259 statCount.rebuilt(
result.size());
264 unsigned int& nCandPerSeed,
268 <<
"Asking to create trajectories to an un-initialized GroupedCkfTrajectoryBuilder.\nYou have to call " 269 "clone(const MeasurementTrackerEvent *data) and then call trajectories on it instead.\n";
282 const bool inOut =
true;
289 cleaner.
clean(work_);
292 for (
auto const&
it : work_)
294 result.push_back(
it.toTrajectory());
295 result.back().setSharedSeed(pseed);
305 LogDebug(
"CkfPattern") <<
"GroupedCkfTrajectoryBuilder: returning result of size " <<
result.size();
306 statCount.traj(
result.size());
310 for (
auto const& traj :
result) {
312 for (
auto const& tm : traj.measurements()) {
313 auto const&
hit = tm.recHitR();
316 if (
hit.det() ==
nullptr)
320 if (
hit.dimension() != 2) {
324 auto const& clus = thit.firstClusterRef();
327 else if (thit.isMatched()) {
329 }
else if (thit.isProjected()) {
353 unsigned int nIter = 1;
354 unsigned int nCands = 0;
355 unsigned int prevNewCandSize = 0;
362 for (TempTrajectoryContainer::iterator traj =
candidates.begin(); traj !=
candidates.end(); traj++) {
364 LogDebug(
"CkfPattern") <<
"GCTB: terminating after advanceOneLayer==false";
372 nCands += newCand.size() - prevNewCandSize;
373 prevNewCandSize = newCand.size();
378 std::nth_element(newCand.begin(),
382 newCand.erase(newCand.begin() +
theMaxCand, newCand.end());
384 LogDebug(
"CkfPattern") <<
"newCand(2): after removing extra candidates.\n" 388 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
398 #ifdef STANDARD_INTERMEDIARYCLEAN 406 LogDebug(
"CkfPattern") <<
"candidates(3): " <<
result.size() <<
" candidates after " << nIter++
407 <<
" groupedCKF iteration: \n" 409 <<
" running candidates are: \n" 420 vector<const DetLayer*>& nl = stateAndLayers.second;
434 buffer <<
"Trying to go to";
435 for (vector<const DetLayer*>::iterator il = nl.begin(); il != nl.end(); il++) {
453 buffer <<
"GCTB: starting from " 458 << stateToUse.
charge() <<
" for layer at " <<
l << endl;
460 for (
int i = 0;
i < 5;
i++)
490 float pt2 = stateAndLayers.first.globalMomentum().perp2();
491 if (pt2 < maxPt2ForLooperReconstruction && pt2 > (0.3
f * 0.3
f))
492 stateAndLayers.second.push_back(traj.
lastLayer());
496 auto layerBegin = stateAndLayers.second.begin();
497 auto layerEnd = stateAndLayers.second.end();
505 LogDebug(
"CkfPattern") << whatIsTheNextStep(traj, stateAndLayers);
508 bool foundSegments(
false);
509 bool foundNewCandidates(
false);
510 for (
auto il = layerBegin; il != layerEnd; il++) {
511 TSOS stateToUse = stateAndLayers.first;
513 double dPhiCacheForLoopersReconstruction(0);
525 if (!cylinderCrossing.hasSolution())
528 GlobalPoint target1 = cylinderCrossing.position1();
529 GlobalPoint target2 = cylinderCrossing.position2();
532 fabs(starting.
phi() - target1.
phi()) > fabs(starting.
phi() - target2.
phi()) ? target1 : target2;
535 float length = 0.5f *
bounds.length();
551 if (fabs(farther.
z()) * 0.95
f > length)
566 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
573 LogDebug(
"CkfPattern") <<
" self propagating in advanceOneLayer.\n from: \n" << stateToUse;
582 LogDebug(
"CkfPattern") <<
"to: " << stateToUse;
592 LogDebug(
"CkfPattern") << whatIsTheStateToUse(stateAndLayers.first, stateToUse, *il);
595 auto&& segments = layerBuilder.segments(stateToUse);
597 LogDebug(
"CkfPattern") <<
"GCTB: number of segments = " << segments.size();
599 if (!segments.empty())
600 foundSegments =
true;
602 for (
auto is = segments.begin(); is != segments.end(); is++) {
606 auto const& measurements = is->measurements();
612 bool toBeRejected(
false);
613 for (
auto revIt = measurements.rbegin(); revIt != measurements.rend(); --revIt) {
618 if (revIt->recHitR().geographicalId() == newTrajMeasIt->recHitR().geographicalId() &&
619 (revIt->recHitR().geographicalId() !=
DetId(0))) {
630 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
631 cout <<
"-- discarded track's pt,eta,#found/lost: " 659 LogDebug(
"CkfPattern") <<
"GCTB: adding updated trajectory to candidates: inOut=" << inOut
664 foundNewCandidates =
true;
668 LogDebug(
"CkfPattern") <<
"GCTB: adding completed trajectory to results if passes cuts: inOut=" << inOut
675 if (!foundSegments) {
676 LogDebug(
"CkfPattern") <<
"GCTB: adding input trajectory to result";
677 if (!stateAndLayers.second.empty())
681 return foundNewCandidates;
687 struct LayersInTraj {
690 std::array<DetLayer const*, N>
layers;
701 if (im->layer() != currl) {
722 if (theTrajectories.empty())
725 LayersInTraj
layers[theTrajectories.size()];
727 for (
auto&
t : theTrajectories) {
728 if (
t.isValid() &&
t.lastMeasurement().recHitR().isValid())
735 for (
int ifirst = 0; ifirst != ntraj - 1; ++ifirst) {
736 auto firstTraj =
layers[ifirst].traj;
737 if (!firstTraj->isValid())
741 int firstLayerSize =
layers[ifirst].tot;
742 if (firstLayerSize < 4)
744 auto const& firstLayers =
layers[ifirst].layers;
746 for (
int isecond = ifirst + 1; isecond != ntraj; ++isecond) {
747 auto secondTraj =
layers[isecond].traj;
748 if (!secondTraj->isValid())
753 int secondLayerSize =
layers[isecond].tot;
757 if (firstLayerSize != secondLayerSize)
759 auto const& secondLayers =
layers[isecond].layers;
760 if (firstLayers[0] != secondLayers[0] || firstLayers[1] != secondLayers[1] || firstLayers[2] != secondLayers[2])
769 const DetLayer* layerPtr = firstLayers[0];
770 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
771 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
773 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
782 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
783 im2->layer() == layerPtr || unequal)
789 layerPtr = firstLayers[1];
791 while (im1 != firstMeasurements.
rend() && im1->layer() == layerPtr) {
792 if (!im1->recHit()->isValid())
796 bool secondValid(
true);
797 while (im2 != secondMeasurements.
rend() && im2->layer() == layerPtr) {
798 if (!im2->recHit()->isValid())
808 layerPtr = firstLayers[2];
809 while (im1 != firstMeasurements.
rend() && im2 != secondMeasurements.
rend()) {
810 if (im1->layer() != layerPtr || im2->layer() != layerPtr)
812 if (!(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
821 if (im1 == firstMeasurements.
rend() || im2 == secondMeasurements.
rend() || im1->layer() == layerPtr ||
822 im2->layer() == layerPtr || unequal)
826 firstTraj->invalidate();
829 secondTraj->invalidate();
842 theTrajectories.erase(
844 theTrajectories.end());
855 LogDebug(
"CkfPattern") <<
"Starting to rebuild " <<
result.size() <<
" tracks";
863 std::vector<const TrackingRecHit*> seedHits;
865 unsigned int nSeed =
seed.nHits();
869 for (TempTrajectoryContainer::iterator
it =
result.begin();
it !=
result.end();
it++) {
877 LogDebug(
"CkfPattern") <<
"RebuildSeedingRegion skipped as backward fit failed";
890 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
891 rebuiltTrajectories[
i].setStopReason(
it->stopReason());
903 result.swap(rebuiltTrajectories);
908 const std::vector<const TrackingRecHit*>& seedHits,
949 const bool inOut =
false;
957 int nrOfTrajectories(0);
958 bool orig_ok =
false;
961 for (TempTrajectoryContainer::iterator
it = rebuiltTrajectories.begin();
it != rebuiltTrajectories.end();
it++) {
970 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
977 LogDebug(
"CkfPattern") <<
"seed hits not found in rebuild";
992 reversedTrajectory.
push(*im);
995 LogDebug(
"CkgPattern") <<
"New traj direction = " << reversedTrajectory.
direction() <<
"\n" 1008 if ((nrOfTrajectories == 0) && orig_ok) {
1009 nrOfTrajectories = -1;
1011 return nrOfTrajectories;
1017 std::vector<const TrackingRecHit*>& remainingHits)
const {
1021 remainingHits.clear();
1023 LogDebug(
"CkfPattern") <<
"nSeed " << nSeed << endl
1024 <<
"Old traj direction = " << candidate.
direction() << endl
1034 unsigned int nHit(0);
1063 bwdDetLayer[nl++] = tm.layer();
1078 else if (
hit->isValid()) {
1080 remainingHits.push_back(
hit);
1101 LogDebug(
"CkfPattern") <<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1110 for (vector<TM>::const_iterator im = tmsbf.begin(); im != tmsbf.end(); im++) {
1111 fitted.emplace((*im).forwardPredictedState(),
1112 (*im).backwardPredictedState(),
1113 (*im).updatedState(),
1116 bwdDetLayer[iDetLayer]);
1137 const std::vector<const TrackingRecHit*>&
hits)
const {
1141 LogDebug(
"CkfPattern") <<
"Checking for " <<
hits.size() <<
" hits in " <<
maxDepth <<
" measurements" << endl;
1148 for (
auto ir =
hits.begin(); ir !=
hits.end(); ir++) {
1150 bool foundHit(
false);
1151 for (
auto im = rbegin; im != rend; --im) {
1152 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
void setNLoops(signed char value)
void setNLoops(signed char value)
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)
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
DataContainer const & measurements() const
float maxPt2ForLooperReconstruction
void setDPhiCacheForLoopersReconstruction(float dphi)
GlobalPoint globalPosition() const
static PropagationDirection oppositeDirection(PropagationDirection dir)
change of propagation direction
GroupedCkfTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
constructor from ParameterSet
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() .
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
void rebuildTrajectories(TempTrajectory const &startingTraj, const TrajectorySeed &, TrajectoryContainer &result) const override
signed char nLoops() 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