59 totSeed=totTraj=totRebuilt=totInvCand=0;
61 void traj(
long long t) {
64 void seed() {++totSeed;}
65 void rebuilt(
long long t) {
70 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt " 71 << totSeed <<
'/'<< totTraj <<
'/'<< totRebuilt
74 StatCount() { zero();}
75 ~StatCount() {
print();}
81 void traj(
long long){}
83 void rebuilt(
long long) {}
100 #ifdef STANDARD_INTERMEDIARYCLEAN 127 conf.getParameter<
bool>(
"useSameTrajFilter") ?
146 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
149 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
230 boost::shared_ptr<const TrajectorySeed> sharedSeed;
233 else sharedSeed = result.front().sharedSeed();
236 work.reserve(result.size());
237 for (
auto && traj : result)
238 if(traj.isValid()) work.emplace_back(
std::move(traj));
247 for (
auto const & it : work)
if (it.isValid()) {
248 final.push_back( it.toTrajectory() );
final.back().setSharedSeed(sharedSeed);
253 statCount.rebuilt(result.size());
260 unsigned int& nCandPerSeed,
264 throw cms::Exception(
"LogicError") <<
"Asking to create trajectories to an un-initialized GroupedCkfTrajectoryBuilder.\nYou have to call clone(const MeasurementTrackerEvent *data) and then call trajectories on it instead.\n";
277 const bool inOut =
true;
279 if ( work_.empty() )
return startingTraj;
283 cleaner.
clean(work_);
285 boost::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
286 for (
auto const & it : work_)
if (it.isValid()) {
287 result.push_back( it.toTrajectory() ); result.back().setSharedSeed(pseed);
294 LogDebug(
"CkfPattern")<<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
295 statCount.traj(result.size());
299 for (
auto const & traj : result) {
301 for (
auto const & tm : traj.measurements()) {
302 auto const &
hit = tm.recHitR();
303 if (!
hit.isValid()) ++chit[0];
304 if (
hit.det()==
nullptr) ++chit[1];
306 if (
hit.dimension()!=2 ) {
311 if (clus.isPixel()) ++chit[3];
312 else if (thit.isMatched()) {
314 }
else if (thit.isProjected()) {
339 unsigned int nIter=1;
340 unsigned int nCands=0;
341 unsigned int prevNewCandSize=0;
344 candidates.push_back( startingTraj);
346 while ( !candidates.empty()) {
349 for (TempTrajectoryContainer::iterator traj=candidates.begin();
350 traj!=candidates.end(); traj++) {
351 if ( !
advanceOneLayer(seed, *traj, regionalCondition, propagator, inOut, newCand, result) ) {
352 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
360 nCands += newCand.size() - prevNewCandSize;
361 prevNewCandSize = newCand.size();
367 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
372 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
382 #ifdef STANDARD_INTERMEDIARYCLEAN 389 candidates.swap(newCand);
391 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n" 393 <<
"\n "<<candidates.size()<<
" running candidates are: \n" 403 vector<const DetLayer*> & nl = stateAndLayers.second;
417 buffer <<
"Trying to go to";
418 for ( vector<const DetLayer*>::iterator il=nl.begin();
425 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
433 buffer <<
"GCTB: starting from " 437 <<
" , pt / phi / pz /charge = " 442 <<
" for layer at "<< l << endl;
443 buffer <<
" errors:";
469 std::pair<TSOS,std::vector<const DetLayer*> > && stateAndLayers =
findStateAndLayers(seed,traj);
476 float pt2 = stateAndLayers.first.globalMomentum().perp2();
480 stateAndLayers.second.push_back(traj.
lastLayer());
484 auto layerBegin = stateAndLayers.second.begin();
485 auto layerEnd = stateAndLayers.second.end();
493 LogDebug(
"CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
496 bool foundSegments(
false);
497 bool foundNewCandidates(
false);
498 for (
auto il=layerBegin; il!=layerEnd; il++) {
500 TSOS stateToUse = stateAndLayers.first;
502 double dPhiCacheForLoopersReconstruction(0);
515 if(!cylinderCrossing.hasSolution())
continue;
517 GlobalPoint target1 = cylinderCrossing.position1();
518 GlobalPoint target2 = cylinderCrossing.position2();
524 float length = 0.5f*bounds.
length();
540 if(fabs(farther.
z())*0.95
f>length)
continue;
550 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
551 if (!stateToUse.
isValid())
continue;
554 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
561 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
568 if (!stateToUse.
isValid())
continue;
569 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
581 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
584 auto && segments= layerBuilder.segments(stateToUse);
586 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
588 if ( !segments.empty() ) foundSegments =
true;
590 for (
auto is=segments.begin(); is!=segments.end(); is++ ) {
594 auto const & measurements = is->measurements();
600 bool toBeRejected(
false);
601 for(
auto revIt = measurements.rbegin(); revIt!=measurements.rend(); --revIt){
606 if(revIt->recHitR().geographicalId()==newTrajMeasIt->recHitR().geographicalId()
607 && (revIt->recHitR().geographicalId() !=
DetId(0)) ){
618 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
619 cout <<
"-- discarded track's pt,eta,#found/lost: " 649 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
653 foundNewCandidates =
true;
658 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
664 if ( !foundSegments ){
665 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
666 if (!stateAndLayers.second.empty())
670 return foundNewCandidates;
676 struct LayersInTraj {
679 std::array<DetLayer const *,N>
layers;
686 auto currl = layers[tot] = measurements.
back().
layer();
690 im!=measurements.
rend(); --im ) {
691 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<N) layers[tot] = currl;}
710 if (theTrajectories.empty())
return;
712 LayersInTraj
layers[theTrajectories.size()];
714 for (
auto &
t : theTrajectories) {
715 if (
t.isValid() &&
t.lastMeasurement().recHitR().isValid() )
716 layers[ntraj++].
fill(
t);
721 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
722 auto firstTraj = layers[ifirst].traj;
723 if (!firstTraj->isValid())
continue;
726 int firstLayerSize = layers[ifirst].tot;
727 if ( firstLayerSize<4 )
continue;
728 auto const & firstLayers = layers[ifirst].layers;
730 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
731 auto secondTraj = layers[isecond].traj;
732 if (!secondTraj->isValid())
continue;
736 int secondLayerSize = layers[isecond].tot;
740 if ( firstLayerSize!=secondLayerSize )
continue;
741 auto const & secondLayers = layers[isecond].layers;
742 if ( firstLayers[0]!=secondLayers[0] ||
743 firstLayers[1]!=secondLayers[1] ||
744 firstLayers[2]!=secondLayers[2] )
continue;
752 const DetLayer* layerPtr = firstLayers[0];
753 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
754 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
755 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
764 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
765 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
770 layerPtr = firstLayers[1];
772 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
773 if ( !im1->recHit()->isValid() ) firstValid =
false;
776 bool secondValid(
true);
777 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
778 if ( !im2->recHit()->isValid() ) secondValid =
false;
781 if ( !
tkxor(firstValid,secondValid) )
continue;
786 layerPtr = firstLayers[2];
787 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
788 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
789 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
798 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
799 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
802 firstTraj->invalidate();
806 secondTraj->invalidate();
819 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
821 theTrajectories.end());
835 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
844 std::vector<const TrackingRecHit*> seedHits;
851 unsigned int nSeed(rseedHits.second-rseedHits.first);
855 for ( TempTrajectoryContainer::iterator it=result.begin();
856 it!=result.end(); it++ ) {
862 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
863 if UNLIKELY( !reFitted.isValid() ) {
864 rebuiltTrajectories.push_back(
std::move(*it));
865 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
879 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
880 rebuiltTrajectories[
i].setStopReason(it->stopReason());
885 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(
std::move(*it));
890 result.swap(rebuiltTrajectories);
891 result.erase(std::remove_if( result.begin(),result.end(),
898 const std::vector<const TrackingRecHit*>& seedHits,
934 cout <<
"Before backward building: #measurements = " 941 const bool inOut =
false;
949 int nrOfTrajectories(0);
950 bool orig_ok =
false;
953 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
954 it!=rebuiltTrajectories.end(); it++ ) {
964 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
973 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
984 reversedTrajectory.
setNLoops(it->nLoops());
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 1017 remainingHits.clear();
1019 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
1020 <<
"Old traj direction = " << candidate.
direction() << endl
1030 unsigned int nHit(0);
1056 if ( nHit<nHitMin ){
1058 bwdDetLayer[nl++]=tm.layer();
1075 remainingHits.push_back(hit);
1081 if UNLIKELY( nHit<nHitMin )
return TempTrajectory();
1095 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1096 TempTrajectory fitted(fwdTraj.
direction(),nSeed);
1097 fitted.setNLoops(fwdTraj.
nLoops());
1104 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1105 fitted.emplace( (*im).forwardPredictedState(),
1106 (*im).backwardPredictedState(),
1107 (*im).updatedState(),
1110 bwdDetLayer[iDetLayer]
1134 const std::vector<const TrackingRecHit*>&
hits)
const 1139 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in " 1140 << maxDepth <<
" measurements" << endl;
1143 while (maxDepth > 0) { --
maxDepth; --rend; }
1144 for (
auto ir=hits.begin(); ir!=hits.end(); ir++ ) {
1146 bool foundHit(
false);
1147 for (
auto im=rbegin; im!=rend; --im ) {
1148 if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some) ) {
1153 if ( !foundHit )
return false;
PropagationDirection direction() const
void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
void rescaleError(double factor)
T getParameter(std::string const &) const
const_iterator rend() const
unsigned int groupedLimitedCandidates(const TrajectorySeed &seed, TempTrajectory const &startingTraj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &result) const
virtual float length() const =0
static std::string dumpCandidates(collection &candidates)
void rebuildSeedingRegion(const TrajectorySeed &, TrajectoryContainer &result) const override
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
void clean(TempTrajectoryContainer &) const override
void join(TempTrajectory &segment)
TrackCharge charge() const
void rebuildTrajectories(TempTrajectory const &startingTraj, const TrajectorySeed &, TrajectoryContainer &result) const override
bool empty() const
True if trajectory has no measurements.
bool isFromDet(TrackingRecHit const &hit)
TempTrajectory buildTrajectories(const TrajectorySeed &seed, TrajectoryContainer &ret, unsigned int &nCandPerSeed, const TrajectoryFilter *) const override
common part of both public trajectory building methods
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
const CurvilinearTrajectoryError & curvilinearError() const
const DataContainer & measurements() const
virtual Location location() const =0
Which part of the detector (barrel, endcap)
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 const BoundCylinder & specificSurface() const final
Extension of the interface.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is rejected(acceptEvent retursns false).There are 3 relevant cases of types of criteria
float maxDPhiForLooperReconstruction
S & print(S &os, JobReport::InputFile const &f)
static std::string dumpMeasurement(const TrajectoryMeasurement &tm)
static std::string dumpMeasurements(const std::vector< TrajectoryMeasurement > &v)
unsigned int theMinNrOf2dHitsForRebuild
signed char nLoops() const
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
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
virtual PropagationDirection propagationDirection() const final
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
const Chi2MeasurementEstimatorBase & estimator() const
Abs< T >::type abs(const T &t)
std::pair< const_iterator, const_iterator > range
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
void addToResult(boost::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
const_iterator rbegin() const
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
const MeasurementTrackerEvent * theMeasurementTracker
bool theKeepOriginalIfRebuildFails
TrajectoryMeasurement const & firstMeasurement() const
virtual const BoundDisk & specificSurface() const final
unsigned int theMinNrOfHitsForRebuild
std::vector< TempTrajectory > TempTrajectoryContainer
const TrajectoryStateUpdator & updator() const
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
std::vector< std::vector< double > > tmp
unsigned int nHits() const
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
void setStopReason(StopReason s)
virtual OmniClusterRef const & firstClusterRef() const =0
bool tkxor(bool a, bool b) const
bool theIntermediateCleaning
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
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
void push(const TrajectoryMeasurement &tm)
double transverseCurvature() const