56 totSeed=totTraj=totRebuilt=totInvCand=0;
58 void traj(
long long t) {
61 void seed() {++totSeed;}
62 void rebuilt(
long long t) {
67 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt "
68 << totSeed <<
'/'<< totTraj <<
'/'<< totRebuilt
71 StatCount() { zero();}
72 ~StatCount() {
print();}
78 void traj(
long long){}
80 void rebuilt(
long long) {}
83 [[cms::thread_safe]] StatCount statCount;
97 #ifdef STANDARD_INTERMEDIARYCLEAN
116 conf.getParameter<bool>(
"useSameTrajFilter") ?
136 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
139 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
215 work.reserve(result.size());
216 for (TrajectoryContainer::iterator traj=result.begin();
217 traj!=result.end(); ++traj) {
218 if(traj->isValid()) work.push_back(
TempTrajectory(std::move(*traj)));
222 final.reserve(work.size());
225 boost::shared_ptr<const TrajectorySeed> sharedSeed;
228 else sharedSeed = result.front().sharedSeed();
231 for (TempTrajectoryContainer::iterator traj=work.begin();
232 traj!=work.end(); ++traj) {
233 final.push_back(traj->toTrajectory());
final.back().setSharedSeed(sharedSeed);
238 statCount.rebuilt(result.size());
248 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";
261 const bool inOut =
true;
263 if (
work_.empty() )
return startingTraj;
279 boost::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
280 result.reserve(
work_.size());
281 for (TempTrajectoryContainer::const_iterator it =
work_.begin(), ed =
work_.end(); it != ed; ++it) {
282 result.push_back( it->toTrajectory() ); result.back().setSharedSeed(pseed);
290 LogDebug(
"CkfPattern")<<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
291 statCount.traj(result.size());
295 for (
auto const & traj : result) {
297 for (
auto const & tm : traj.measurements()) {
298 auto const &
hit = tm.recHitR();
299 if (!
hit.isValid()) ++chit[0];
300 if (
hit.det()==
nullptr) ++chit[1];
302 if (
hit.dimension()!=2 ) {
306 auto const & clus = thit.firstClusterRef();
307 if (clus.isPixel()) ++chit[3];
308 else if (thit.isMatched()) {
310 }
else if (thit.isProjected()) {
335 unsigned int nIter=1;
338 candidates.push_back( startingTraj);
340 while ( !candidates.empty()) {
343 for (TempTrajectoryContainer::iterator traj=candidates.begin();
344 traj!=candidates.end(); traj++) {
345 if ( !
advanceOneLayer(seed, *traj, regionalCondition, propagator, inOut, newCand, result) ) {
346 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
356 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
361 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
371 #ifdef STANDARD_INTERMEDIARYCLEAN
378 candidates.swap(newCand);
380 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n"
382 <<
"\n "<<candidates.size()<<
" running candidates are: \n"
389 std::stringstream buffer;
390 vector<const DetLayer*> & nl = stateAndLayers.second;
404 buffer <<
"Trying to go to";
405 for ( vector<const DetLayer*>::iterator il=nl.begin();
412 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
419 std::stringstream buffer;
420 buffer <<
"GCTB: starting from "
424 <<
" , pt / phi / pz /charge = "
429 <<
" for layer at "<< l << endl;
430 buffer <<
" errors:";
456 std::pair<TSOS,std::vector<const DetLayer*> > && stateAndLayers =
findStateAndLayers(traj);
463 float pt2 = stateAndLayers.first.globalMomentum().perp2();
467 stateAndLayers.second.push_back(traj.
lastLayer());
471 auto layerBegin = stateAndLayers.second.begin();
472 auto layerEnd = stateAndLayers.second.end();
480 LogDebug(
"CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
483 bool foundSegments(
false);
484 bool foundNewCandidates(
false);
485 for (
auto il=layerBegin; il!=layerEnd; il++) {
487 TSOS stateToUse = stateAndLayers.first;
489 double dPhiCacheForLoopersReconstruction(0);
502 if(!cylinderCrossing.hasSolution())
continue;
504 GlobalPoint target1 = cylinderCrossing.position1();
505 GlobalPoint target2 = cylinderCrossing.position2();
511 float length = 0.5f*bounds.
length();
527 if(fabs(farther.
z())*0.95
f>length)
continue;
537 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
538 if (!stateToUse.
isValid())
continue;
541 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
548 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
555 if (!stateToUse.
isValid())
continue;
556 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
568 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
571 auto && segments= layerBuilder.segments(stateToUse);
573 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
575 if ( !segments.empty() ) foundSegments =
true;
577 for (
auto is=segments.begin(); is!=segments.end(); is++ ) {
581 auto const & measurements = is->measurements();
587 bool toBeRejected(
false);
588 for(
auto revIt = measurements.rbegin(); revIt!=measurements.rend(); --revIt){
593 if(revIt->recHitR().geographicalId()==newTrajMeasIt->recHitR().geographicalId()
594 && (revIt->recHitR().geographicalId() !=
DetId(0)) ){
605 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
606 cout <<
"-- discarded track's pt,eta,#found/lost: "
636 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
638 newCand.push_back(std::move(newTraj));
639 foundNewCandidates =
true;
644 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
651 if ( !foundSegments ){
652 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
655 return foundNewCandidates;
661 struct LayersInTraj {
664 std::array<DetLayer const *,N>
layers;
675 im!=measurements.
rend(); --im ) {
676 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<
N)
layers[tot] = currl;}
695 if (theTrajectories.empty())
return;
697 LayersInTraj
layers[theTrajectories.size()];
699 for (
auto & t : theTrajectories) {
701 layers[ntraj++].
fill(t);
706 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
707 auto firstTraj = layers[ifirst].traj;
708 if (!firstTraj->isValid())
continue;
711 int firstLayerSize = layers[ifirst].tot;
712 if ( firstLayerSize<4 )
continue;
713 auto const & firstLayers = layers[ifirst].layers;
715 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
716 auto secondTraj = layers[isecond].traj;
717 if (!secondTraj->isValid())
continue;
721 int secondLayerSize = layers[isecond].tot;
725 if ( firstLayerSize!=secondLayerSize )
continue;
726 auto const & secondLayers = layers[isecond].layers;
727 if ( firstLayers[0]!=secondLayers[0] ||
728 firstLayers[1]!=secondLayers[1] ||
729 firstLayers[2]!=secondLayers[2] )
continue;
737 const DetLayer* layerPtr = firstLayers[0];
738 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
739 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
740 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
749 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
750 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
755 layerPtr = firstLayers[1];
757 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
758 if ( !im1->recHit()->isValid() ) firstValid =
false;
761 bool secondValid(
true);
762 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
763 if ( !im2->recHit()->isValid() ) secondValid =
false;
766 if ( !
tkxor(firstValid,secondValid) )
continue;
771 layerPtr = firstLayers[2];
772 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
773 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
774 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
783 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
784 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
787 firstTraj->invalidate();
791 secondTraj->invalidate();
804 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
807 theTrajectories.end());
821 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
830 std::vector<const TrackingRecHit*> seedHits;
837 unsigned int nSeed(rseedHits.second-rseedHits.first);
841 for ( TempTrajectoryContainer::iterator it=result.begin();
842 it!=result.end(); it++ ) {
849 rebuiltTrajectories.push_back(std::move(*it));
850 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as in-out trajectory does not exceed seed size.";
858 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
859 if unlikely( !reFitted.isValid() ) {
860 rebuiltTrajectories.push_back(std::move(*it));
861 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
875 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(std::move(*it));
881 result.swap(rebuiltTrajectories);
882 result.erase(std::remove_if( result.begin(),result.end(),
889 const std::vector<const TrackingRecHit*>& seedHits,
925 cout <<
"Before backward building: #measurements = "
932 const bool inOut =
false;
940 int nrOfTrajectories(0);
941 bool orig_ok =
false;
944 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
945 it!=rebuiltTrajectories.end(); it++ ) {
955 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
964 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
975 reversedTrajectory.
setNLoops(it->nLoops());
978 reversedTrajectory.
push(*im);
981 LogDebug(
"CkgPattern")<<
"New traj direction = " << reversedTrajectory.
direction()<<
"\n"
994 if ( (nrOfTrajectories == 0) && orig_ok ) {
995 nrOfTrajectories = -1;
997 return nrOfTrajectories;
1003 std::vector<const TrackingRecHit*>& remainingHits)
const
1008 remainingHits.clear();
1015 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
1016 <<
"Old traj direction = " << candidate.
direction() << endl
1026 unsigned int nHit(0);
1052 if ( nHit<nHitMin ){
1054 bwdDetLayer[nl++]=tm.layer();
1071 remainingHits.push_back(hit);
1077 if unlikely( nHit<nHitMin )
return TempTrajectory();
1087 fwdTraj.recHits(),firstTsos);
1091 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1092 TempTrajectory fitted(fwdTraj.
direction());
1093 fitted.setNLoops(fwdTraj.
nLoops());
1100 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1101 fitted.emplace( (*im).forwardPredictedState(),
1102 (*im).backwardPredictedState(),
1103 (*im).updatedState(),
1106 bwdDetLayer[iDetLayer]
1130 const std::vector<const TrackingRecHit*>& hits)
const
1135 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in "
1136 << maxDepth <<
" measurements" << endl;
1139 while (maxDepth > 0) { --maxDepth; --rend; }
1140 for (
auto ir=hits.begin(); ir!=hits.end(); ir++ ) {
1142 bool foundHit(
false);
1143 for (
auto im=rbegin; im!=rend; --im ) {
1144 if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some) ) {
1149 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
static std::string dumpCandidates(collection &candidates)
TempTrajectoryContainer work_
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
virtual PropagationDirection propagationDirection() const
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
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
virtual const BoundDisk & specificSurface() const
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 MeasurementTracker & measurementTracker() 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
Extension of the interface.
const TrajectoryStateUpdator & updator() const
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
bool tkxor(bool a, bool b) const
bool theIntermediateCleaning
bool isUndef(TrackingRecHit const &hit)
TrackingRecHit const & recHitR() const
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