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
124 conf.getParameter<bool>(
"useSameTrajFilter") ?
144 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
147 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
223 work.reserve(result.size());
224 for (TrajectoryContainer::iterator traj=result.begin();
225 traj!=result.end(); ++traj) {
226 if(traj->isValid()) work.push_back(
TempTrajectory(std::move(*traj)));
230 final.reserve(work.size());
233 boost::shared_ptr<const TrajectorySeed> sharedSeed;
236 else sharedSeed = result.front().sharedSeed();
239 for (TempTrajectoryContainer::iterator traj=work.begin();
240 traj!=work.end(); ++traj) {
241 final.push_back(traj->toTrajectory());
final.back().setSharedSeed(sharedSeed);
246 statCount.rebuilt(result.size());
256 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";
269 const bool inOut =
true;
271 if ( work_.empty() )
return startingTraj;
287 boost::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
288 result.reserve(work_.size());
289 for (TempTrajectoryContainer::const_iterator it = work_.begin(), ed = work_.end(); it != ed; ++it) {
290 result.push_back( it->toTrajectory() ); result.back().setSharedSeed(pseed);
298 LogDebug(
"CkfPattern")<<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
299 statCount.traj(result.size());
303 for (
auto const & traj : result) {
305 for (
auto const & tm : traj.measurements()) {
306 auto const &
hit = tm.recHitR();
307 if (!
hit.isValid()) ++chit[0];
308 if (
hit.det()==
nullptr) ++chit[1];
310 if (
hit.dimension()!=2 ) {
314 auto const & clus = thit.firstClusterRef();
315 if (clus.isPixel()) ++chit[3];
316 else if (thit.isMatched()) {
318 }
else if (thit.isProjected()) {
343 unsigned int nIter=1;
346 candidates.push_back( startingTraj);
348 while ( !candidates.empty()) {
351 for (TempTrajectoryContainer::iterator traj=candidates.begin();
352 traj!=candidates.end(); traj++) {
353 if ( !
advanceOneLayer(seed, *traj, regionalCondition, propagator, inOut, newCand, result) ) {
354 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
364 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
369 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
379 #ifdef STANDARD_INTERMEDIARYCLEAN
386 candidates.swap(newCand);
388 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n"
390 <<
"\n "<<candidates.size()<<
" running candidates are: \n"
397 std::stringstream buffer;
398 vector<const DetLayer*> & nl = stateAndLayers.second;
412 buffer <<
"Trying to go to";
413 for ( vector<const DetLayer*>::iterator il=nl.begin();
420 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
427 std::stringstream buffer;
428 buffer <<
"GCTB: starting from "
432 <<
" , pt / phi / pz /charge = "
437 <<
" for layer at "<< l << endl;
438 buffer <<
" errors:";
464 std::pair<TSOS,std::vector<const DetLayer*> > && stateAndLayers =
findStateAndLayers(traj);
471 float pt2 = stateAndLayers.first.globalMomentum().perp2();
475 stateAndLayers.second.push_back(traj.
lastLayer());
479 auto layerBegin = stateAndLayers.second.begin();
480 auto layerEnd = stateAndLayers.second.end();
488 LogDebug(
"CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
491 bool foundSegments(
false);
492 bool foundNewCandidates(
false);
493 for (
auto il=layerBegin; il!=layerEnd; il++) {
495 TSOS stateToUse = stateAndLayers.first;
497 double dPhiCacheForLoopersReconstruction(0);
510 if(!cylinderCrossing.hasSolution())
continue;
512 GlobalPoint target1 = cylinderCrossing.position1();
513 GlobalPoint target2 = cylinderCrossing.position2();
519 float length = 0.5f*bounds.
length();
535 if(fabs(farther.
z())*0.95
f>length)
continue;
545 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
546 if (!stateToUse.
isValid())
continue;
549 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
556 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
563 if (!stateToUse.
isValid())
continue;
564 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
576 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
579 auto && segments= layerBuilder.segments(stateToUse);
581 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
583 if ( !segments.empty() ) foundSegments =
true;
585 for (
auto is=segments.begin(); is!=segments.end(); is++ ) {
589 auto const & measurements = is->measurements();
595 bool toBeRejected(
false);
596 for(
auto revIt = measurements.rbegin(); revIt!=measurements.rend(); --revIt){
601 if(revIt->recHitR().geographicalId()==newTrajMeasIt->recHitR().geographicalId()
602 && (revIt->recHitR().geographicalId() !=
DetId(0)) ){
613 cout <<
"WARNING: neglect candidate because it contains the same hit twice \n";
614 cout <<
"-- discarded track's pt,eta,#found/lost: "
644 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
646 newCand.push_back(std::move(newTraj));
647 foundNewCandidates =
true;
652 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
659 if ( !foundSegments ){
660 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
663 return foundNewCandidates;
669 struct LayersInTraj {
672 std::array<DetLayer const *,N>
layers;
683 im!=measurements.
rend(); --im ) {
684 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<
N)
layers[tot] = currl;}
703 if (theTrajectories.empty())
return;
705 LayersInTraj
layers[theTrajectories.size()];
707 for (
auto & t : theTrajectories) {
709 layers[ntraj++].
fill(t);
714 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
715 auto firstTraj = layers[ifirst].traj;
716 if (!firstTraj->isValid())
continue;
719 int firstLayerSize = layers[ifirst].tot;
720 if ( firstLayerSize<4 )
continue;
721 auto const & firstLayers = layers[ifirst].layers;
723 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
724 auto secondTraj = layers[isecond].traj;
725 if (!secondTraj->isValid())
continue;
729 int secondLayerSize = layers[isecond].tot;
733 if ( firstLayerSize!=secondLayerSize )
continue;
734 auto const & secondLayers = layers[isecond].layers;
735 if ( firstLayers[0]!=secondLayers[0] ||
736 firstLayers[1]!=secondLayers[1] ||
737 firstLayers[2]!=secondLayers[2] )
continue;
745 const DetLayer* layerPtr = firstLayers[0];
746 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
747 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
748 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
757 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
758 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
763 layerPtr = firstLayers[1];
765 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
766 if ( !im1->recHit()->isValid() ) firstValid =
false;
769 bool secondValid(
true);
770 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
771 if ( !im2->recHit()->isValid() ) secondValid =
false;
774 if ( !
tkxor(firstValid,secondValid) )
continue;
779 layerPtr = firstLayers[2];
780 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
781 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
782 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
791 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
792 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
795 firstTraj->invalidate();
799 secondTraj->invalidate();
812 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
815 theTrajectories.end());
829 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
838 std::vector<const TrackingRecHit*> seedHits;
845 unsigned int nSeed(rseedHits.second-rseedHits.first);
849 for ( TempTrajectoryContainer::iterator it=result.begin();
850 it!=result.end(); it++ ) {
857 rebuiltTrajectories.push_back(std::move(*it));
858 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as in-out trajectory does not exceed seed size.";
866 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
867 if unlikely( !reFitted.isValid() ) {
868 rebuiltTrajectories.push_back(std::move(*it));
869 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
883 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(std::move(*it));
889 result.swap(rebuiltTrajectories);
890 result.erase(std::remove_if( result.begin(),result.end(),
897 const std::vector<const TrackingRecHit*>& seedHits,
933 cout <<
"Before backward building: #measurements = "
940 const bool inOut =
false;
948 int nrOfTrajectories(0);
949 bool orig_ok =
false;
952 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
953 it!=rebuiltTrajectories.end(); it++ ) {
963 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
972 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
983 reversedTrajectory.
setNLoops(it->nLoops());
986 reversedTrajectory.
push(*im);
989 LogDebug(
"CkgPattern")<<
"New traj direction = " << reversedTrajectory.
direction()<<
"\n"
1002 if ( (nrOfTrajectories == 0) && orig_ok ) {
1003 nrOfTrajectories = -1;
1005 return nrOfTrajectories;
1011 std::vector<const TrackingRecHit*>& remainingHits)
const
1016 remainingHits.clear();
1023 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
1024 <<
"Old traj direction = " << candidate.
direction() << endl
1034 unsigned int nHit(0);
1060 if ( nHit<nHitMin ){
1062 bwdDetLayer[nl++]=tm.layer();
1079 remainingHits.push_back(hit);
1085 if unlikely( nHit<nHitMin )
return TempTrajectory();
1095 fwdTraj.recHits(),firstTsos);
1099 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1100 TempTrajectory fitted(fwdTraj.
direction());
1101 fitted.setNLoops(fwdTraj.
nLoops());
1108 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1109 fitted.emplace( (*im).forwardPredictedState(),
1110 (*im).backwardPredictedState(),
1111 (*im).updatedState(),
1114 bwdDetLayer[iDetLayer]
1138 const std::vector<const TrackingRecHit*>& hits)
const
1143 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in "
1144 << maxDepth <<
" measurements" << endl;
1147 while (maxDepth > 0) { --maxDepth; --rend; }
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) ) {
1157 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)
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