53 totSeed=totTraj=totRebuilt=totInvCand=0;
55 void traj(
long long t) {
58 void seed() {++totSeed;}
59 void rebuilt(
long long t) {
64 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt "
65 << totSeed <<
'/'<< totTraj <<
'/'<< totRebuilt
68 StatCount() { zero();}
69 ~StatCount() {
print();}
74 void traj(
long long){}
76 void rebuilt(
long long) {}
93 #ifdef STANDARD_INTERMEDIARYCLEAN
122 updator, propagatorAlong,propagatorOpposite,
123 estimator, recHitBuilder, filter, inOutFilter)
140 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
143 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
223 work.reserve(result.size());
224 for (TrajectoryContainer::iterator traj=result.begin();
225 traj!=result.end(); ++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());
314 unsigned int nIter=1;
317 candidates.push_back( startingTraj);
319 while ( !candidates.empty()) {
322 for (TempTrajectoryContainer::iterator traj=candidates.begin();
323 traj!=candidates.end(); traj++) {
324 if ( !
advanceOneLayer(*traj, regionalCondition, propagator, inOut, newCand, result) ) {
325 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
335 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
340 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
350 #ifdef STANDARD_INTERMEDIARYCLEAN
357 candidates.swap(newCand);
359 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n"
361 <<
"\n "<<candidates.size()<<
" running candidates are: \n"
368 std::stringstream buffer;
369 vector<const DetLayer*> & nl = stateAndLayers.second;
383 buffer <<
"Trying to go to";
384 for ( vector<const DetLayer*>::iterator il=nl.begin();
391 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
398 std::stringstream buffer;
399 buffer <<
"GCTB: starting from "
403 <<
" , pt / phi / pz /charge = "
408 <<
" for layer at "<< l << endl;
409 buffer <<
" errors:";
434 std::pair<TSOS,std::vector<const DetLayer*> > stateAndLayers =
findStateAndLayers(traj);
441 float pt2 = stateAndLayers.first.globalMomentum().perp2();
445 stateAndLayers.second.push_back(traj.
lastLayer());
449 vector<const DetLayer*>::iterator layerBegin = stateAndLayers.second.begin();
450 vector<const DetLayer*>::iterator layerEnd = stateAndLayers.second.end();
458 LogDebug(
"CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
461 bool foundSegments(
false);
462 bool foundNewCandidates(
false);
463 for ( vector<const DetLayer*>::iterator il=layerBegin;
464 il!=layerEnd; il++) {
466 TSOS stateToUse = stateAndLayers.first;
468 double dPhiCacheForLoopersReconstruction(0);
481 if(!cylinderCrossing.hasSolution())
continue;
483 GlobalPoint target1 = cylinderCrossing.position1();
484 GlobalPoint target2 = cylinderCrossing.position2();
490 float length = 0.5f*bounds.
length();
506 if(fabs(farther.
z())*0.95
f>length)
continue;
516 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
517 if (!stateToUse.
isValid())
continue;
520 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
527 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
534 if (!stateToUse.
isValid())
continue;
535 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
547 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
551 layerBuilder.segments(stateToUse);
553 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
555 if ( !segments.empty() ) foundSegments =
true;
557 for ( TempTrajectoryContainer::iterator is=segments.begin();
558 is!=segments.end(); is++ ) {
568 bool toBeRejected(
false);
570 revIt!=measurements.
rend(); --revIt){
575 if(revIt->recHitR().geographicalId()==newTrajMeasIt->recHitR().geographicalId()
576 && (revIt->recHitR().geographicalId() !=
DetId(0)) ){
617 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
619 newCand.push_back(std::move(newTraj));
620 foundNewCandidates =
true;
625 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
632 if ( !foundSegments ){
633 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
636 return foundNewCandidates;
642 struct LayersInTraj {
645 std::array<DetLayer const *,N>
layers;
656 im!=measurements.
rend(); --im ) {
657 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<
N)
layers[tot] = currl;}
676 if (theTrajectories.empty())
return;
678 LayersInTraj
layers[theTrajectories.size()];
680 for (
auto & t : theTrajectories) {
682 layers[ntraj++].
fill(t);
687 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
688 auto firstTraj = layers[ifirst].traj;
689 if (!firstTraj->isValid())
continue;
692 int firstLayerSize = layers[ifirst].tot;
693 if ( firstLayerSize<4 )
continue;
694 auto const & firstLayers = layers[ifirst].layers;
696 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
697 auto secondTraj = layers[isecond].traj;
698 if (!secondTraj->isValid())
continue;
702 int secondLayerSize = layers[isecond].tot;
706 if ( firstLayerSize!=secondLayerSize )
continue;
707 auto const & secondLayers = layers[isecond].layers;
708 if ( firstLayers[0]!=secondLayers[0] ||
709 firstLayers[1]!=secondLayers[1] ||
710 firstLayers[2]!=secondLayers[2] )
continue;
718 const DetLayer* layerPtr = firstLayers[0];
719 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
720 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
721 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
730 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
731 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
736 layerPtr = firstLayers[1];
738 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
739 if ( !im1->recHit()->isValid() ) firstValid =
false;
742 bool secondValid(
true);
743 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
744 if ( !im2->recHit()->isValid() ) secondValid =
false;
747 if ( !
tkxor(firstValid,secondValid) )
continue;
752 layerPtr = firstLayers[2];
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;
768 firstTraj->invalidate();
772 secondTraj->invalidate();
785 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
788 theTrajectories.end());
802 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
810 std::vector<const TrackingRecHit*> seedHits;
817 unsigned int nSeed(rseedHits.second-rseedHits.first);
821 for ( TempTrajectoryContainer::iterator it=result.begin();
822 it!=result.end(); it++ ) {
829 rebuiltTrajectories.push_back(std::move(*it));
830 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as in-out trajectory does not exceed seed size.";
838 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
839 if unlikely( !reFitted.isValid() ) {
840 rebuiltTrajectories.push_back(std::move(*it));
841 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
855 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(std::move(*it));
861 result.swap(rebuiltTrajectories);
862 result.erase(std::remove_if( result.begin(),result.end(),
869 const std::vector<const TrackingRecHit*>& seedHits,
905 cout <<
"Before backward building: #measurements = "
912 const bool inOut =
false;
920 int nrOfTrajectories(0);
921 bool orig_ok =
false;
924 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
925 it!=rebuiltTrajectories.end(); it++ ) {
935 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
944 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
955 reversedTrajectory.
setNLoops(it->nLoops());
958 reversedTrajectory.
push(*im);
961 LogDebug(
"CkgPattern")<<
"New traj direction = " << reversedTrajectory.
direction()<<
"\n"
974 if ( (nrOfTrajectories == 0) && orig_ok ) {
975 nrOfTrajectories = -1;
977 return nrOfTrajectories;
983 std::vector<const TrackingRecHit*>& remainingHits)
const
988 remainingHits.clear();
995 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
996 <<
"Old traj direction = " << candidate.
direction() << endl
1006 unsigned int nHit(0);
1032 if ( nHit<nHitMin ){
1034 bwdDetLayer[nl++]=tm.layer();
1051 remainingHits.push_back(hit);
1057 if unlikely( nHit<nHitMin )
return TempTrajectory();
1071 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1072 TempTrajectory fitted(fwdTraj.
direction());
1073 fitted.setNLoops(fwdTraj.
nLoops());
1080 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1081 fitted.emplace( (*im).forwardPredictedState(),
1082 (*im).backwardPredictedState(),
1083 (*im).updatedState(),
1086 bwdDetLayer[iDetLayer]
1110 const std::vector<const TrackingRecHit*>& hits)
const
1115 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in "
1116 << maxDepth <<
" measurements" << endl;
1119 while (maxDepth > 0) { --maxDepth; --rend; }
1120 for ( vector<const TrackingRecHit*>::const_iterator ir=hits.begin();
1121 ir!=hits.end(); ir++ ) {
1123 bool foundHit(
false);
1125 if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some) ) {
1130 if ( !foundHit )
return false;
PropagationDirection direction() const
GroupedCkfTrajectoryBuilder(const edm::ParameterSet &conf, const TrajectoryStateUpdator *updator, const Propagator *propagatorAlong, const Propagator *propagatorOpposite, const Chi2MeasurementEstimatorBase *estimator, const TransientTrackingRecHitBuilder *RecHitBuilder, const TrajectoryFilter *filter, const TrajectoryFilter *inOutFilter)
constructor from ParameterSet
void rescaleError(double factor)
T getParameter(std::string const &) const
const_iterator rend() const
static std::string dumpCandidates(collection &candidates)
TempTrajectoryContainer work_
void groupedIntermediaryClean(TempTrajectoryContainer &theTrajectories) const dso_internal
intermediate cleaning in the case of grouped measurements
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
ConstRecHitPointer const & recHit() const
void join(TempTrajectory &segment)
const Propagator * theBackwardPropagator
TrackCharge charge() const
void setData(const MeasurementTrackerEvent *data)
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
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
bool advanceOneLayer(TempTrajectory &traj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &newCand, TempTrajectoryContainer &result) const dso_internal
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
int foundHits() const
obsolete name, use measurements() instead.
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
bool tkxor(bool a, bool b) const dso_internal
static std::string dumpMeasurement(const TrajectoryMeasurement &tm)
static std::string dumpMeasurements(const std::vector< TrajectoryMeasurement > &v)
unsigned int theMinNrOf2dHitsForRebuild
virtual GroupedCkfTrajectoryBuilder * clone(const MeasurementTrackerEvent *data) const
virtual PropagationDirection propagationDirection() const GCC11_FINAL
bool verifyHits(TempTrajectory::DataContainer::const_iterator rbegin, size_t maxDepth, const std::vector< const TrackingRecHit * > &hits) const dso_internal
Verifies presence of a RecHits in a range of TrajectoryMeasurements.
signed char nLoops() const
ConstRecHitContainer recHits(bool splitting=false) const
const TrajectoryMeasurement & lastMeasurement() const
float maxPt2ForLooperReconstruction
PropagationDirection const & direction() const
PropagationDirection direction() const
void setDPhiCacheForLoopersReconstruction(float dphi)
DataContainer const & measurements() const
void rebuildTrajectories(TempTrajectory const &startingTraj, const TrajectorySeed &, TrajectoryContainer &result) const
virtual void analyseResult(const TrajectoryContainer &result) const
void groupedLimitedCandidates(TempTrajectory const &startingTraj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &result) const dso_internal
const T & max(const T &a, const T &b)
static PropagationDirection oppositeDirection(PropagationDirection dir)
change of propagation direction
const Chi2MeasurementEstimatorBase & estimator() const
Abs< T >::type abs(const T &t)
std::pair< const_iterator, const_iterator > range
void rebuildSeedingRegion(const TrajectorySeed &, TrajectoryContainer &result) const
const DetLayer * layer() 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
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
ConstRecHitPointer::element_type const & recHitR() const
virtual const BoundDisk & specificSurface() const GCC11_FINAL
TempTrajectory backwardFit(TempTrajectory &candidate, unsigned int nSeed, const TrajectoryFitter &fitter, std::vector< const TrackingRecHit * > &remainingHits) const dso_internal
const TrajectoryStateUpdator & updator() const
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
char data[epos_bytes_allocation]
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
bool theIntermediateCleaning
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
virtual const BoundCylinder & specificSurface() const GCC11_FINAL
Extension of the interface.
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
const Propagator * theForwardPropagator