58 totSeed=totTraj=totRebuilt=totInvCand=0;
60 void traj(
long long t) {
63 void seed() {++totSeed;}
64 void rebuilt(
long long t) {
69 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt "
70 << totSeed <<
'/'<< totTraj <<
'/'<< totRebuilt
73 StatCount() { zero();}
74 ~StatCount() {
print();}
80 void traj(
long long){}
82 void rebuilt(
long long) {}
85 [[cms::thread_safe]] StatCount statCount;
99 #ifdef STANDARD_INTERMEDIARYCLEAN
126 conf.getParameter<bool>(
"useSameTrajFilter") ?
146 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
149 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
225 work.reserve(result.size());
226 for (TrajectoryContainer::iterator traj=result.begin();
227 traj!=result.end(); ++traj) {
232 final.reserve(work.size());
235 boost::shared_ptr<const TrajectorySeed> sharedSeed;
238 else sharedSeed = result.front().sharedSeed();
241 for (TempTrajectoryContainer::iterator traj=work.begin();
242 traj!=work.end(); ++traj) {
243 final.push_back(traj->toTrajectory());
final.back().setSharedSeed(sharedSeed);
248 statCount.rebuilt(result.size());
258 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";
271 const bool inOut =
true;
273 if ( work_.empty() )
return startingTraj;
288 boost::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
289 result.reserve(work_.size());
290 for (TempTrajectoryContainer::const_iterator it = work_.begin(), ed = work_.end(); it != ed; ++it) {
291 result.push_back( it->toTrajectory() ); result.back().setSharedSeed(pseed);
299 LogDebug(
"CkfPattern")<<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
300 statCount.traj(result.size());
304 for (
auto const & traj : result) {
306 for (
auto const & tm : traj.measurements()) {
307 auto const &
hit = tm.recHitR();
308 if (!
hit.isValid()) ++chit[0];
309 if (
hit.det()==
nullptr) ++chit[1];
311 if (
hit.dimension()!=2 ) {
315 auto const & clus = thit.firstClusterRef();
316 if (clus.isPixel()) ++chit[3];
317 else if (thit.isMatched()) {
319 }
else if (thit.isProjected()) {
344 unsigned int nIter=1;
347 candidates.push_back( startingTraj);
349 while ( !candidates.empty()) {
352 for (TempTrajectoryContainer::iterator traj=candidates.begin();
353 traj!=candidates.end(); traj++) {
354 if ( !
advanceOneLayer(seed, *traj, regionalCondition, propagator, inOut, newCand, result) ) {
355 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
365 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
370 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
380 #ifdef STANDARD_INTERMEDIARYCLEAN
387 candidates.swap(newCand);
389 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n"
391 <<
"\n "<<candidates.size()<<
" running candidates are: \n"
398 std::stringstream buffer;
399 vector<const DetLayer*> & nl = stateAndLayers.second;
413 buffer <<
"Trying to go to";
414 for ( vector<const DetLayer*>::iterator il=nl.begin();
421 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
428 std::stringstream buffer;
429 buffer <<
"GCTB: starting from "
433 <<
" , pt / phi / pz /charge = "
438 <<
" for layer at "<< l << endl;
439 buffer <<
" errors:";
465 std::pair<TSOS,std::vector<const DetLayer*> > && stateAndLayers =
findStateAndLayers(traj);
472 float pt2 = stateAndLayers.first.globalMomentum().perp2();
476 stateAndLayers.second.push_back(traj.
lastLayer());
480 auto layerBegin = stateAndLayers.second.begin();
481 auto layerEnd = stateAndLayers.second.end();
489 LogDebug(
"CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
492 bool foundSegments(
false);
493 bool foundNewCandidates(
false);
494 for (
auto il=layerBegin; il!=layerEnd; il++) {
496 TSOS stateToUse = stateAndLayers.first;
498 double dPhiCacheForLoopersReconstruction(0);
511 if(!cylinderCrossing.hasSolution())
continue;
513 GlobalPoint target1 = cylinderCrossing.position1();
514 GlobalPoint target2 = cylinderCrossing.position2();
520 float length = 0.5f*bounds.
length();
536 if(fabs(farther.
z())*0.95
f>length)
continue;
546 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
547 if (!stateToUse.
isValid())
continue;
550 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
557 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
564 if (!stateToUse.
isValid())
continue;
565 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
577 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
580 auto && segments= layerBuilder.segments(stateToUse);
582 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
584 if ( !segments.empty() ) foundSegments =
true;
586 for (
auto is=segments.begin(); is!=segments.end(); is++ ) {
590 auto const & measurements = is->measurements();
596 bool toBeRejected(
false);
597 for(
auto revIt = measurements.rbegin(); revIt!=measurements.rend(); --revIt){
602 if(revIt->recHitR().geographicalId()==newTrajMeasIt->recHitR().geographicalId()
603 && (revIt->recHitR().geographicalId() !=
DetId(0)) ){
614 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
615 cout <<
"-- discarded track's pt,eta,#found/lost: "
645 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
649 foundNewCandidates =
true;
654 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
660 if ( !foundSegments ){
661 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
662 if (stateAndLayers.second.size() > 0)
666 return foundNewCandidates;
672 struct LayersInTraj {
675 std::array<DetLayer const *,N>
layers;
686 im!=measurements.
rend(); --im ) {
687 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<
N)
layers[tot] = currl;}
706 if (theTrajectories.empty())
return;
708 LayersInTraj
layers[theTrajectories.size()];
710 for (
auto & t : theTrajectories) {
712 layers[ntraj++].
fill(t);
717 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
718 auto firstTraj = layers[ifirst].traj;
719 if (!firstTraj->isValid())
continue;
722 int firstLayerSize = layers[ifirst].tot;
723 if ( firstLayerSize<4 )
continue;
724 auto const & firstLayers = layers[ifirst].layers;
726 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
727 auto secondTraj = layers[isecond].traj;
728 if (!secondTraj->isValid())
continue;
732 int secondLayerSize = layers[isecond].tot;
736 if ( firstLayerSize!=secondLayerSize )
continue;
737 auto const & secondLayers = layers[isecond].layers;
738 if ( firstLayers[0]!=secondLayers[0] ||
739 firstLayers[1]!=secondLayers[1] ||
740 firstLayers[2]!=secondLayers[2] )
continue;
748 const DetLayer* layerPtr = firstLayers[0];
749 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
750 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
751 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
760 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
761 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
766 layerPtr = firstLayers[1];
768 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
769 if ( !im1->recHit()->isValid() ) firstValid =
false;
772 bool secondValid(
true);
773 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
774 if ( !im2->recHit()->isValid() ) secondValid =
false;
777 if ( !
tkxor(firstValid,secondValid) )
continue;
782 layerPtr = firstLayers[2];
783 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
784 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
785 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
794 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
795 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
798 firstTraj->invalidate();
802 secondTraj->invalidate();
815 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
818 theTrajectories.end());
832 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
841 std::vector<const TrackingRecHit*> seedHits;
848 unsigned int nSeed(rseedHits.second-rseedHits.first);
852 for ( TempTrajectoryContainer::iterator it=result.begin();
853 it!=result.end(); it++ ) {
860 rebuiltTrajectories.push_back(
std::move(*it));
861 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as in-out trajectory does not exceed seed size.";
869 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
870 if unlikely( !reFitted.isValid() ) {
871 rebuiltTrajectories.push_back(
std::move(*it));
872 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
886 for (
size_t i = rebuiltTrajectories.size() - 1;
i < rebuiltTrajectories.size() - nRebuilt - 1; --
i) {
887 rebuiltTrajectories[
i].setStopReason(it->stopReason());
892 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(
std::move(*it));
897 result.swap(rebuiltTrajectories);
898 result.erase(std::remove_if( result.begin(),result.end(),
905 const std::vector<const TrackingRecHit*>& seedHits,
941 cout <<
"Before backward building: #measurements = "
948 const bool inOut =
false;
956 int nrOfTrajectories(0);
957 bool orig_ok =
false;
960 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
961 it!=rebuiltTrajectories.end(); it++ ) {
971 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
980 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
991 reversedTrajectory.
setNLoops(it->nLoops());
994 reversedTrajectory.
push(*im);
997 LogDebug(
"CkgPattern")<<
"New traj direction = " << reversedTrajectory.
direction()<<
"\n"
1010 if ( (nrOfTrajectories == 0) && orig_ok ) {
1011 nrOfTrajectories = -1;
1013 return nrOfTrajectories;
1019 std::vector<const TrackingRecHit*>& remainingHits)
const
1024 remainingHits.clear();
1031 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
1032 <<
"Old traj direction = " << candidate.
direction() << endl
1042 unsigned int nHit(0);
1068 if ( nHit<nHitMin ){
1070 bwdDetLayer[nl++]=tm.layer();
1087 remainingHits.push_back(hit);
1093 if unlikely( nHit<nHitMin )
return TempTrajectory();
1107 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1108 TempTrajectory fitted(fwdTraj.
direction(),nSeed);
1109 fitted.setNLoops(fwdTraj.
nLoops());
1116 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1117 fitted.emplace( (*im).forwardPredictedState(),
1118 (*im).backwardPredictedState(),
1119 (*im).updatedState(),
1122 bwdDetLayer[iDetLayer]
1146 const std::vector<const TrackingRecHit*>& hits)
const
1151 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in "
1152 << maxDepth <<
" measurements" << endl;
1155 while (maxDepth > 0) { --
maxDepth; --rend; }
1156 for (
auto ir=hits.begin(); ir!=hits.end(); ir++ ) {
1158 bool foundHit(
false);
1159 for (
auto im=rbegin; im!=rend; --im ) {
1160 if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some) ) {
1165 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
tuple ret
prodAgent to be discontinued
static std::string dumpCandidates(collection &candidates)
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
virtual Location location() const =0
Which part of the detector (barrel, endcap)
TrajectoryContainer trajectories(const TrajectorySeed &) const
set Event for the internal MeasurementTracker data member
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
const CurvilinearTrajectoryError & curvilinearError() const
TempTrajectory buildTrajectories(const TrajectorySeed &seed, TrajectoryContainer &ret, const TrajectoryFilter *) const
common part of both public trajectory building methods
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
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
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
void rebuildTrajectories(TempTrajectory const &startingTraj, const TrajectorySeed &, TrajectoryContainer &result) 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
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
void rebuildSeedingRegion(const TrajectorySeed &, TrajectoryContainer &result) 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
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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
unsigned int theMinNrOfHitsForRebuild
std::vector< TempTrajectory > TempTrajectoryContainer
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
unsigned int nHits() const
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
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
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
void push(const TrajectoryMeasurement &tm)
double transverseCurvature() const