52 totSeed=totTraj=totRebuilt=totInvCand=0;
54 void traj(
long long t) {
57 void seed() {++totSeed;}
58 void rebuilt(
long long t) {
63 std::cout <<
"GroupedCkfTrajectoryBuilder stat\nSeed/Traj/Rebuilt "
64 << totSeed <<
'/'<< totTraj <<
'/'<< totRebuilt
67 StatCount() {
zero();}
68 ~StatCount() {
print();}
73 void traj(
long long){}
75 void rebuilt(
long long) {}
92 #ifdef STANDARD_INTERMEDIARYCLEAN
122 updator, propagatorAlong,propagatorOpposite,
123 estimator, recHitBuilder, measurementTracker, filter, inOutFilter)
140 conf.
getParameter<
double>(
"maxPtForLooperReconstruction") : 0;
143 conf.
getParameter<
double>(
"maxDPhiForLooperReconstruction") : 2.0;
216 work.reserve(result.size());
217 for (TrajectoryContainer::iterator traj=result.begin();
218 traj!=result.end(); ++traj) {
223 final.reserve(work.size());
226 boost::shared_ptr<const TrajectorySeed> sharedSeed;
229 else sharedSeed = result.front().sharedSeed();
232 for (TempTrajectoryContainer::iterator traj=work.begin();
233 traj!=work.end(); ++traj) {
234 final.push_back(traj->toTrajectory());
final.back().setSharedSeed(sharedSeed);
239 statCount.rebuilt(result.size());
258 const bool inOut =
true;
260 if (
work_.empty() )
return startingTraj;
276 boost::shared_ptr<const TrajectorySeed> pseed(
new TrajectorySeed(seed));
277 result.reserve(
work_.size());
278 for (TempTrajectoryContainer::const_iterator it =
work_.begin(), ed =
work_.end(); it != ed; ++it) {
279 result.push_back( it->toTrajectory() ); result.back().setSharedSeed(pseed);
287 LogDebug(
"CkfPattern")<<
"GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
288 statCount.traj(result.size());
303 unsigned int nIter=1;
306 candidates.push_back( startingTraj);
308 while ( !candidates.empty()) {
311 for (TempTrajectoryContainer::iterator traj=candidates.begin();
312 traj!=candidates.end(); traj++) {
313 if ( !
advanceOneLayer(*traj, regionalCondition, propagator, inOut, newCand, result) ) {
314 LogDebug(
"CkfPattern")<<
"GCTB: terminating after advanceOneLayer==false";
324 newCand.erase( newCand.begin()+
theMaxCand, newCand.end());
329 LogDebug(
"CkfPattern") <<
"newCand.size() at end = " << newCand.size();
339 #ifdef STANDARD_INTERMEDIARYCLEAN
346 candidates.swap(newCand);
348 LogDebug(
"CkfPattern") <<
"candidates(3): "<<result.size()<<
" candidates after "<<nIter++<<
" groupedCKF iteration: \n"
350 <<
"\n "<<candidates.size()<<
" running candidates are: \n"
357 std::stringstream buffer;
358 vector<const DetLayer*> & nl = stateAndLayers.second;
372 buffer <<
"Trying to go to";
373 for ( vector<const DetLayer*>::iterator il=nl.begin();
380 if (fdl) buffer <<
" z " << fdl->
specificSurface().position().z() << endl;
387 std::stringstream buffer;
388 buffer <<
"GCTB: starting from "
392 <<
" , pt / phi / pz /charge = "
397 <<
" for layer at "<< l << endl;
398 buffer <<
" errors:";
423 std::pair<TSOS,std::vector<const DetLayer*> > stateAndLayers =
findStateAndLayers(traj);
430 float pt2 = stateAndLayers.first.globalMomentum().perp2();
434 stateAndLayers.second.push_back(traj.
lastLayer());
438 vector<const DetLayer*>::iterator layerBegin = stateAndLayers.second.begin();
439 vector<const DetLayer*>::iterator layerEnd = stateAndLayers.second.end();
447 LogDebug(
"CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
450 bool foundSegments(
false);
451 bool foundNewCandidates(
false);
452 for ( vector<const DetLayer*>::iterator il=layerBegin;
453 il!=layerEnd; il++) {
455 TSOS stateToUse = stateAndLayers.first;
457 double dPhiCacheForLoopersReconstruction(0);
470 if(!cylinderCrossing.hasSolution())
continue;
472 GlobalPoint target1 = cylinderCrossing.position1();
473 GlobalPoint target2 = cylinderCrossing.position2();
479 float length = 0.5f*bounds.
length();
495 if(fabs(farther.
z())*0.95
f>length)
continue;
505 stateToUse = extrapolator.
extrapolate(stateToUse, target, *propagator);
506 if (!stateToUse.
isValid())
continue;
509 dPhiCacheForLoopersReconstruction =
std::abs(tmpDphi);
516 LogDebug(
"CkfPattern")<<
" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
523 if (!stateToUse.
isValid())
continue;
524 LogDebug(
"CkfPattern")<<
"to: "<<stateToUse;
536 LogDebug(
"CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
542 LogDebug(
"CkfPattern")<<
"GCTB: number of segments = " << segments.size();
544 if ( !segments.empty() ) foundSegments =
true;
546 for ( TempTrajectoryContainer::iterator is=segments.begin();
547 is!=segments.end(); is++ ) {
557 bool toBeRejected(
false);
559 revIt!=measurements.
rend(); --revIt){
564 if(revIt->recHitR().geographicalId()==newTrajMeasIt->recHitR().geographicalId()
565 && (revIt->recHitR().geographicalId() !=
DetId(0)) ){
606 LogDebug(
"CkfPattern")<<
"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
608 newCand.push_back(std::move(newTraj));
609 foundNewCandidates =
true;
614 LogDebug(
"CkfPattern")<<
"GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<
" hits="<<newTraj.
foundHits();
621 if ( !foundSegments ){
622 LogDebug(
"CkfPattern")<<
"GCTB: adding input trajectory to result";
625 return foundNewCandidates;
631 struct LayersInTraj {
634 std::array<DetLayer const *,N> layers;
641 auto currl = layers[tot] = measurements.
back().
layer();
645 im!=measurements.
rend(); --im ) {
646 if ( im->layer()!=currl ) { ++tot; currl = im->layer();
if (tot<
N) layers[tot] = currl;}
665 if (theTrajectories.empty())
return;
667 LayersInTraj layers[theTrajectories.size()];
669 for (
auto & t : theTrajectories) {
671 layers[ntraj++].
fill(t);
676 for (
int ifirst=0; ifirst!=ntraj-1; ++ifirst) {
677 auto firstTraj = layers[ifirst].traj;
678 if (!firstTraj->isValid())
continue;
681 int firstLayerSize = layers[ifirst].tot;
682 if ( firstLayerSize<4 )
continue;
683 auto const & firstLayers = layers[ifirst].layers;
685 for (
int isecond= ifirst+1; isecond!=ntraj; ++isecond) {
686 auto secondTraj = layers[isecond].traj;
687 if (!secondTraj->isValid())
continue;
691 int secondLayerSize = layers[isecond].tot;
695 if ( firstLayerSize!=secondLayerSize )
continue;
696 auto const & secondLayers = layers[isecond].layers;
697 if ( firstLayers[0]!=secondLayers[0] ||
698 firstLayers[1]!=secondLayers[1] ||
699 firstLayers[2]!=secondLayers[2] )
continue;
707 const DetLayer* layerPtr = firstLayers[0];
708 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
709 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
710 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
719 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
720 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
725 layerPtr = firstLayers[1];
727 while ( im1!=firstMeasurements.
rend()&&im1->layer()==layerPtr ) {
728 if ( !im1->recHit()->isValid() ) firstValid =
false;
731 bool secondValid(
true);
732 while ( im2!=secondMeasurements.
rend()&&im2->layer()==layerPtr ) {
733 if ( !im2->recHit()->isValid() ) secondValid =
false;
736 if ( !
tkxor(firstValid,secondValid) )
continue;
741 layerPtr = firstLayers[2];
742 while ( im1!=firstMeasurements.
rend()&&im2!=secondMeasurements.
rend() ) {
743 if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr )
break;
744 if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
753 if ( im1==firstMeasurements.
rend() || im2==secondMeasurements.
rend() ||
754 im1->layer()==layerPtr || im2->layer()==layerPtr || unequal )
continue;
757 firstTraj->invalidate();
761 secondTraj->invalidate();
774 theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
777 theTrajectories.end());
791 LogDebug(
"CkfPattern")<<
"Starting to rebuild " << result.size() <<
" tracks";
799 std::vector<const TrackingRecHit*> seedHits;
806 unsigned int nSeed(rseedHits.second-rseedHits.first);
810 for ( TempTrajectoryContainer::iterator it=result.begin();
811 it!=result.end(); it++ ) {
818 rebuiltTrajectories.push_back(std::move(*it));
819 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as in-out trajectory does not exceed seed size.";
827 auto && reFitted =
backwardFit(*it,nSeed,fitter,seedHits);
828 if unlikely( !reFitted.isValid() ) {
829 rebuiltTrajectories.push_back(std::move(*it));
830 LogDebug(
"CkfPattern")<<
"RebuildSeedingRegion skipped as backward fit failed";
844 if ( nRebuilt<0 ) rebuiltTrajectories.push_back(std::move(*it));
850 result.swap(rebuiltTrajectories);
851 result.erase(std::remove_if( result.begin(),result.end(),
858 const std::vector<const TrackingRecHit*>& seedHits,
894 cout <<
"Before backward building: #measurements = "
901 const bool inOut =
false;
909 int nrOfTrajectories(0);
910 bool orig_ok =
false;
913 for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
914 it!=rebuiltTrajectories.end(); it++ ) {
924 LogDebug(
"CkfPattern") <<
"newMeasurements.size()<=candidate.measurements().size()";
933 LogDebug(
"CkfPattern")<<
"seed hits not found in rebuild";
944 reversedTrajectory.
setNLoops(it->nLoops());
947 reversedTrajectory.
push(*im);
950 LogDebug(
"CkgPattern")<<
"New traj direction = " << reversedTrajectory.
direction()<<
"\n"
963 if ( (nrOfTrajectories == 0) && orig_ok ) {
964 nrOfTrajectories = -1;
966 return nrOfTrajectories;
972 std::vector<const TrackingRecHit*>& remainingHits)
const
977 remainingHits.clear();
984 LogDebug(
"CkfPattern")<<
"nSeed " << nSeed << endl
985 <<
"Old traj direction = " << candidate.
direction() << endl
995 unsigned int nHit(0);
1021 if ( nHit<nHitMin ){
1023 bwdDetLayer[nl++]=tm.layer();
1040 remainingHits.push_back(hit);
1046 if unlikely( nHit<nHitMin )
return TempTrajectory();
1060 LogDebug(
"CkfPattern")<<
"Obtained bwdFitted trajectory with measurement size " << bwdFitted.
measurements().size();
1061 TempTrajectory fitted(fwdTraj.
direction());
1062 fitted.setNLoops(fwdTraj.
nLoops());
1069 for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
1070 fitted.emplace( (*im).forwardPredictedState(),
1071 (*im).backwardPredictedState(),
1072 (*im).updatedState(),
1075 bwdDetLayer[iDetLayer]
1099 const std::vector<const TrackingRecHit*>& hits)
const
1104 LogDebug(
"CkfPattern")<<
"Checking for " << hits.size() <<
" hits in "
1105 << maxDepth <<
" measurements" << endl;
1108 while (maxDepth > 0) { --
maxDepth; --rend; }
1109 for ( vector<const TrackingRecHit*>::const_iterator ir=hits.begin();
1110 ir!=hits.end(); ir++ ) {
1112 bool foundHit(
false);
1114 if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(),
TrackingRecHit::some) ) {
1119 if ( !foundHit )
return false;
PropagationDirection direction() const
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
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
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
GroupedCkfTrajectoryBuilder(const edm::ParameterSet &conf, const TrajectoryStateUpdator *updator, const Propagator *propagatorAlong, const Propagator *propagatorOpposite, const Chi2MeasurementEstimatorBase *estimator, const TransientTrackingRecHitBuilder *RecHitBuilder, const MeasurementTracker *measurementTracker, const TrajectoryFilter *filter, const TrajectoryFilter *inOutFilter)
constructor from ParameterSet
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.
TempTrajectoryContainer segments(const TSOS startingState)
new segments within layer
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 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
const LayerMeasurements * theLayerMeasurements
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
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_iterator rbegin() const
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
bool theKeepOriginalIfRebuildFails
const MeasurementTracker * theMeasurementTracker
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
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