61 totSeed=totTraj=totRebuilt=totInvCand=0;
63 void traj(
long long t) {
66 void seed() {++totSeed;}
67 void rebuilt(
long long t) {
72 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt " 73 << totSeed <<
'/'<< totTraj <<
'/'<< totRebuilt
76 StatCount() { zero();}
77 ~StatCount() {
print();}
83 void traj(
long long){}
85 void rebuilt(
long long) {}
88 [[cms::thread_safe]] StatCount statCount;
102 #ifdef STANDARD_INTERMEDIARYCLEAN 129 conf.getParameter<bool>(
"useSameTrajFilter") ?
148 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
151 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
228 boost::shared_ptr<const TrajectorySeed> sharedSeed;
231 else sharedSeed = result.front().sharedSeed();
234 work.reserve(result.size());
235 for (
auto && traj : result)
236 if(traj.isValid()) work.emplace_back(
std::move(traj));
245 for (
auto const & it : work)
if (it.isValid()) {
246 final.push_back( it.toTrajectory() );
final.back().setSharedSeed(sharedSeed);
251 statCount.rebuilt(result.size());
261 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";
274 const bool inOut =
true;
276 if ( work_.empty() )
return startingTraj;
280 cleaner.
clean(work_);
282 boost::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
283 for (
auto const & it : work_)
if (it.isValid()) {
284 result.push_back( it.toTrajectory() ); result.back().setSharedSeed(pseed);
291 LogDebug(
"CkfPattern")<<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
292 statCount.traj(result.size());
296 for (
auto const & traj : result) {
298 for (
auto const & tm : traj.measurements()) {
299 auto const &
hit = tm.recHitR();
300 if (!
hit.isValid()) ++chit[0];
301 if (
hit.det()==
nullptr) ++chit[1];
303 if (
hit.dimension()!=2 ) {
308 if (clus.isPixel()) ++chit[3];
309 else if (thit.isMatched()) {
311 }
else if (thit.isProjected()) {
336 unsigned int nIter=1;
339 candidates.push_back( startingTraj);
341 while ( !candidates.empty()) {
344 for (TempTrajectoryContainer::iterator traj=candidates.begin();
345 traj!=candidates.end(); traj++) {
346 if ( !
advanceOneLayer(seed, *traj, regionalCondition, propagator, inOut, newCand, result) ) {
347 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
357 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
362 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
372 #ifdef STANDARD_INTERMEDIARYCLEAN 379 candidates.swap(newCand);
381 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n" 383 <<
"\n "<<candidates.size()<<
" running candidates are: \n" 391 vector<const DetLayer*> & nl = stateAndLayers.second;
405 buffer <<
"Trying to go to";
406 for ( vector<const DetLayer*>::iterator il=nl.begin();
413 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
421 buffer <<
"GCTB: starting from " 425 <<
" , pt / phi / pz /charge = " 430 <<
" for layer at "<< l << endl;
431 buffer <<
" errors:";
457 std::pair<TSOS,std::vector<const DetLayer*> > && stateAndLayers =
findStateAndLayers(traj);
464 float pt2 = stateAndLayers.first.globalMomentum().perp2();
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++) {
488 TSOS stateToUse = stateAndLayers.first;
490 double dPhiCacheForLoopersReconstruction(0);
503 if(!cylinderCrossing.hasSolution())
continue;
505 GlobalPoint target1 = cylinderCrossing.position1();
506 GlobalPoint target2 = cylinderCrossing.position2();
512 float length = 0.5f*bounds.
length();
528 if(fabs(farther.
z())*0.95
f>length)
continue;
538 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
539 if (!stateToUse.
isValid())
continue;
542 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
549 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
556 if (!stateToUse.
isValid())
continue;
557 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
569 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
572 auto && segments= layerBuilder.segments(stateToUse);
574 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
576 if ( !segments.empty() ) 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: " 637 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
641 foundNewCandidates =
true;
646 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
652 if ( !foundSegments ){
653 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
654 if (stateAndLayers.second.size() > 0)
658 return foundNewCandidates;
664 struct LayersInTraj {
667 std::array<DetLayer const *,N>
layers;
674 auto currl = layers[tot] = measurements.
back().
layer();
678 im!=measurements.
rend(); --im ) {
679 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<N) layers[tot] = currl;}
698 if (theTrajectories.empty())
return;
700 LayersInTraj
layers[theTrajectories.size()];
702 for (
auto &
t : theTrajectories) {
703 if (
t.isValid() &&
t.lastMeasurement().recHitR().isValid() )
704 layers[ntraj++].
fill(
t);
709 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
710 auto firstTraj = layers[ifirst].traj;
711 if (!firstTraj->isValid())
continue;
714 int firstLayerSize = layers[ifirst].tot;
715 if ( firstLayerSize<4 )
continue;
716 auto const & firstLayers = layers[ifirst].layers;
718 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
719 auto secondTraj = layers[isecond].traj;
720 if (!secondTraj->isValid())
continue;
724 int secondLayerSize = layers[isecond].tot;
728 if ( firstLayerSize!=secondLayerSize )
continue;
729 auto const & secondLayers = layers[isecond].layers;
730 if ( firstLayers[0]!=secondLayers[0] ||
731 firstLayers[1]!=secondLayers[1] ||
732 firstLayers[2]!=secondLayers[2] )
continue;
740 const DetLayer* layerPtr = firstLayers[0];
741 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
742 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
743 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
752 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
753 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
758 layerPtr = firstLayers[1];
760 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
761 if ( !im1->recHit()->isValid() ) firstValid =
false;
764 bool secondValid(
true);
765 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
766 if ( !im2->recHit()->isValid() ) secondValid =
false;
769 if ( !
tkxor(firstValid,secondValid) )
continue;
774 layerPtr = firstLayers[2];
775 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
776 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
777 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
786 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
787 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
790 firstTraj->invalidate();
794 secondTraj->invalidate();
807 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
810 theTrajectories.end());
824 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
833 std::vector<const TrackingRecHit*> seedHits;
840 unsigned int nSeed(rseedHits.second-rseedHits.first);
844 for ( TempTrajectoryContainer::iterator it=result.begin();
845 it!=result.end(); it++ ) {
851 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
852 if unlikely( !reFitted.isValid() ) {
853 rebuiltTrajectories.push_back(
std::move(*it));
854 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
868 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
869 rebuiltTrajectories[
i].setStopReason(it->stopReason());
874 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(
std::move(*it));
879 result.swap(rebuiltTrajectories);
880 result.erase(std::remove_if( result.begin(),result.end(),
887 const std::vector<const TrackingRecHit*>& seedHits,
923 cout <<
"Before backward building: #measurements = " 930 const bool inOut =
false;
938 int nrOfTrajectories(0);
939 bool orig_ok =
false;
942 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
943 it!=rebuiltTrajectories.end(); it++ ) {
953 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
962 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
973 reversedTrajectory.
setNLoops(it->nLoops());
976 reversedTrajectory.
push(*im);
979 LogDebug(
"CkgPattern")<<
"New traj direction = " << reversedTrajectory.
direction()<<
"\n" 992 if ( (nrOfTrajectories == 0) && orig_ok ) {
993 nrOfTrajectories = -1;
995 return nrOfTrajectories;
1001 std::vector<const TrackingRecHit*>& remainingHits)
const 1006 remainingHits.clear();
1008 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
1009 <<
"Old traj direction = " << candidate.
direction() << endl
1019 unsigned int nHit(0);
1045 if ( nHit<nHitMin ){
1047 bwdDetLayer[nl++]=tm.layer();
1064 remainingHits.push_back(hit);
1070 if unlikely( nHit<nHitMin )
return TempTrajectory();
1084 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1085 TempTrajectory fitted(fwdTraj.
direction(),nSeed);
1086 fitted.setNLoops(fwdTraj.
nLoops());
1093 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1094 fitted.emplace( (*im).forwardPredictedState(),
1095 (*im).backwardPredictedState(),
1096 (*im).updatedState(),
1099 bwdDetLayer[iDetLayer]
1123 const std::vector<const TrackingRecHit*>&
hits)
const 1128 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in " 1129 << maxDepth <<
" measurements" << endl;
1132 while (maxDepth > 0) { --
maxDepth; --rend; }
1133 for (
auto ir=hits.begin(); ir!=hits.end(); ir++ ) {
1135 bool foundHit(
false);
1136 for (
auto im=rbegin; im!=rend; --im ) {
1137 if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some) ) {
1142 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
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
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
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
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
TempTrajectory buildTrajectories(const TrajectorySeed &seed, TrajectoryContainer &ret, const TrajectoryFilter *) const override
common part of both public trajectory building methods
TrajectoryContainer trajectories(const TrajectorySeed &) const override
set Event for the internal MeasurementTracker data member
void groupedLimitedCandidates(const TrajectorySeed &seed, TempTrajectory const &startingTraj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &result) const
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
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