Skip to content

Commit

Permalink
Merge pull request #14299 from VinInn/TkFastClean
Browse files Browse the repository at this point in the history
Tracking Fast cleaner during pattern recognition
  • Loading branch information
cmsbuild committed May 2, 2016
2 parents 0fe4e8d + 5c25610 commit 836ba5d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 35 deletions.
53 changes: 23 additions & 30 deletions RecoTracker/CkfPattern/plugins/GroupedCkfTrajectoryBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
// only included for RecHit comparison operator:
#include "TrackingTools/TrajectoryCleaning/interface/TrajectoryCleanerBySharedHits.h"

#include "TrackingTools/TrajectoryCleaning/interface/FastTrajectoryCleaner.h"


// for looper reconstruction
#include "TrackingTools/GeomPropagators/interface/HelixBarrelCylinderCrossing.h"
#include "TrackingTools/GeomPropagators/interface/HelixBarrelPlaneCrossingByCircle.h"
Expand Down Expand Up @@ -221,25 +224,26 @@ GroupedCkfTrajectoryBuilder::rebuildTrajectories(TempTrajectory const & starting

TrajectoryContainer final;

// better the seed to be always the same...
boost::shared_ptr<const TrajectorySeed> sharedSeed;
if (result.empty())
sharedSeed.reset(new TrajectorySeed(seed));
else sharedSeed = result.front().sharedSeed();


work.reserve(result.size());
for (TrajectoryContainer::iterator traj=result.begin();
traj!=result.end(); ++traj) {
if(traj->isValid()) work.push_back(TempTrajectory(std::move(*traj)));
}
for (auto && traj : result)
if(traj.isValid()) work.emplace_back(std::move(traj));


rebuildSeedingRegion(seed,startingTraj,work);
final.reserve(work.size());

// better the seed to be always the same...
boost::shared_ptr<const TrajectorySeed> sharedSeed;
if (result.empty())
sharedSeed.reset(new TrajectorySeed(seed));
else sharedSeed = result.front().sharedSeed();

// we clean here now
FastTrajectoryCleaner cleaner(theFoundHitBonus,theLostHitPenalty,false);
cleaner.clean(work);

for (TempTrajectoryContainer::iterator traj=work.begin();
traj!=work.end(); ++traj) {
final.push_back(traj->toTrajectory()); final.back().setSharedSeed(sharedSeed);
for (auto const & it : work) if (it.isValid()) {
final.push_back( it.toTrajectory() ); final.back().setSharedSeed(sharedSeed);
}

result.swap(final);
Expand Down Expand Up @@ -271,25 +275,14 @@ GroupedCkfTrajectoryBuilder::buildTrajectories (const TrajectorySeed& seed,
groupedLimitedCandidates(seed, startingTraj, regionalCondition, forwardPropagator(seed), inOut, work_);
if ( work_.empty() ) return startingTraj;

/* rebuilding is de-coupled from standard building
//
// try to additional hits in the seeding region
//
if ( theMinNrOfHitsForRebuild>0 ) {
// reverse direction
//thePropagator->setPropagationDirection(oppositeDirection(seed.direction()));
// rebuild part of the trajectory
rebuildSeedingRegion(startingTraj,work);
}
*/
// cleaning now done here...
FastTrajectoryCleaner cleaner(theFoundHitBonus,theLostHitPenalty);
cleaner.clean(work_);

boost::shared_ptr<const TrajectorySeed> pseed(new TrajectorySeed(seed));
result.reserve(work_.size());
for (TempTrajectoryContainer::const_iterator it = work_.begin(), ed = work_.end(); it != ed; ++it) {
result.push_back( it->toTrajectory() ); result.back().setSharedSeed(pseed);
for (auto const & it : work_) if (it.isValid()) {
result.push_back( it.toTrajectory() ); result.back().setSharedSeed(pseed);
}

work_.clear();
if (work_.capacity() > work_MaxSize_) { TempTrajectoryContainer().swap(work_); work_.reserve(work_MaxSize_/2); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
maxCand = cms.int32(5),
intermediateCleaning = cms.bool(True),
# Chi2 added to track candidate if no hit found in layer
lostHitPenalty = cms.double(30.0),
lostHitPenalty = cms.double(20.0),
MeasurementTrackerName = cms.string(''),
lockHits = cms.bool(True),
TTRHBuilder = cms.string('WithTrackAngle'),
Expand Down
50 changes: 50 additions & 0 deletions TrackingTools/TrajectoryCleaning/interface/FastTrajectoryCleaner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef TrajectoryCleaning_FastTrajectoryCleaner_h
#define TrajectoryCleaning_FastTrajectoryCleaner_h

#include "TrackingTools/TrajectoryCleaning/interface/TrajectoryCleaner.h"

/** A concrete TrajectoryCleaner that assumes all trajectories
* coming from the same seed and therefore incompatible
* The "best" trajectory of is kept, the others are invalidated.
* The goodness of a track is defined in terms of Chi^2, number of
* reconstructed hits, and number of lost hits.
* As it can be used during PatternReco there is the option to not consider hits from the common seed
*/


class FastTrajectoryCleaner final : public TrajectoryCleaner {
public:

using TrajectoryPointerContainer = TrajectoryCleaner::TrajectoryPointerContainer;
using TempTrajectoryContainer = TrajectoryCleaner::TempTrajectoryContainer;

FastTrajectoryCleaner() :
validHitBonus_(0.5f*5.0f),
missingHitPenalty_(20.0f),
dismissSeed_(true){}


FastTrajectoryCleaner(float bonus, float penalty, bool noSeed=true) :
validHitBonus_(0.5f*bonus),
missingHitPenalty_(penalty),
dismissSeed_(noSeed){}



FastTrajectoryCleaner(const edm::ParameterSet & iConfig) :
validHitBonus_(0.5*iConfig.getParameter<double>("ValidHitBonus")),
missingHitPenalty_(iConfig.getParameter<double>("MissingHitPenalty")),
dismissSeed_(iConfig.getParameter<bool>("dismissSeed")){}

~FastTrajectoryCleaner(){}

void clean(TempTrajectoryContainer&) const override;
void clean(TrajectoryPointerContainer&) const override;

private:
float validHitBonus_; // here per dof
float missingHitPenalty_;
bool dismissSeed_;
};

#endif
12 changes: 9 additions & 3 deletions TrackingTools/TrajectoryCleaning/interface/TrajectoryCleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define TrajectoryCleaning_TrajectoryCleaner_h

#include "TrackingTools/PatternTools/interface/Trajectory.h"
#include "TrackingTools/PatternTools/interface/TempTrajectory.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

/** The component of track reconstruction that resolves ambiguities
Expand All @@ -19,10 +20,15 @@ class TrajectoryCleaner {
typedef TrajectoryContainer::iterator TrajectoryIterator;
typedef TrajectoryPointerContainer::iterator TrajectoryPointerIterator;

TrajectoryCleaner(){};
TrajectoryCleaner(edm::ParameterSet & iConfig){};
virtual ~TrajectoryCleaner(){};
using TempTrajectoryContainer = std::vector<TempTrajectory>;



TrajectoryCleaner(){}
TrajectoryCleaner(edm::ParameterSet & iConfig){}
virtual ~TrajectoryCleaner(){}

virtual void clean( TempTrajectoryContainer&) const;
virtual void clean( TrajectoryContainer&) const;
virtual void clean( TrajectoryPointerContainer&) const = 0;

Expand Down
48 changes: 48 additions & 0 deletions TrackingTools/TrajectoryCleaning/src/FastTrajectoryCleaner.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "TrackingTools/TrajectoryCleaning/interface/FastTrajectoryCleaner.h"
void FastTrajectoryCleaner::clean( TrajectoryPointerContainer & tc) const
{
edm::LogError("FastTrajectoryCleaner") << "not implemented for Trajectory";
assert(false);
}

void FastTrajectoryCleaner::clean( TempTrajectoryContainer & tc) const
{

if (tc.size() <= 1) return; // nothing to clean
float maxScore= -std::numeric_limits<float>::max();
TempTrajectory * bestTr = nullptr;
for (auto & it : tc) {
if (!it.isValid()) continue;
auto const & pd = it.measurements();
// count active degree of freedom
int dof=0;
for (auto const & im : pd) {
if(dismissSeed_ & (im.estimate()==0)) continue;
auto const & h = im.recHitR();
if (!h.isValid()) continue;
dof+=h.dimension();
}
float score = validHitBonus_*dof - missingHitPenalty_*it.lostHits() - it.chiSquared();
if (score>=maxScore) {
bestTr = &it;
maxScore = score;
}
}

for (auto & it : tc) {
if ((&it)!=bestTr) it.invalidate();
}


}

/*
auto score = [&](Trajectory const&t)->float {
// possible variant under study
// auto ns = t.foundHits()-t.trailingFoundHits();
//auto penalty = 0.8f*missingHitPenalty_;
// return validHitBonus_*(t.foundHits()-0.2f*t.cccBadHits()) - penalty*t.lostHits() - t.chiSquared();
// classical score
return validHitBonus_*t.foundHits() - missingHitPenalty_*t.lostHits() - t.chiSquared();
};
*/
9 changes: 8 additions & 1 deletion TrackingTools/TrajectoryCleaning/src/TrajectoryCleaner.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

#include "TrackingTools/TrajectoryCleaning/interface/TrajectoryCleaner.h"
#include<cassert>

#include "FWCore/Utilities/interface/typelookup.h"
void TrajectoryCleaner::clean( TempTrajectoryContainer&) const
{
edm::LogError("TrajectoryCleaner") << "not implemented for TempTrajectory";
assert(false);
}

void TrajectoryCleaner::clean( TrajectoryContainer& tc) const
{
Expand All @@ -14,4 +19,6 @@ void TrajectoryCleaner::clean( TrajectoryContainer& tc) const
clean(thePointerContainer);
}


#include "FWCore/Utilities/interface/typelookup.h"
TYPELOOKUP_DATA_REG(TrajectoryCleaner);

0 comments on commit 836ba5d

Please sign in to comment.