Skip to content

Commit

Permalink
Merge pull request #9093 from wmtan/TrackerHitAssociatorConsumesInReco
Browse files Browse the repository at this point in the history
Use consumes interface for TrackerHitAssociator(RECO)
  • Loading branch information
cmsbuild committed May 17, 2015
2 parents 138d196 + 756df63 commit 1dd1105
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
ClusterRefinerTagMCmerged::
ClusterRefinerTagMCmerged(const edm::ParameterSet& conf)
: inputTag( conf.getParameter<edm::InputTag>("UntaggedClusterProducer") ),
confClusterRefiner_(conf.getParameter<edm::ParameterSet>("ClusterRefiner")) {
confClusterRefiner_(conf.getParameter<edm::ParameterSet>("ClusterRefiner")),
useAssociateHit_(!confClusterRefiner_.getParameter<bool>("associateRecoTracks")),
trackerHitAssociatorConfig_(confClusterRefiner_, consumesCollector()) {
produces< edmNew::DetSetVector<SiStripCluster> > ();
inputToken = consumes< edmNew::DetSetVector<SiStripCluster> >(inputTag);
}
Expand All @@ -16,7 +18,7 @@ produce(edm::Event& event, const edm::EventSetup& es) {
std::auto_ptr< edmNew::DetSetVector<SiStripCluster> > output(new edmNew::DetSetVector<SiStripCluster>());
output->reserve(10000,4*10000);

associator_.reset(new TrackerHitAssociator(event, confClusterRefiner_));
associator_.reset(new TrackerHitAssociator(event, trackerHitAssociatorConfig_));
edm::Handle< edmNew::DetSetVector<SiStripCluster> > input;

if ( findInput(inputToken, input, event) ) refineCluster(input, output);
Expand All @@ -43,8 +45,7 @@ refineCluster(const edm::Handle< edmNew::DetSetVector<SiStripCluster> >& input,
SiStripCluster* newCluster = new SiStripCluster(clust->firstStrip(), amp.begin(), amp.end());
if (associator_ != 0) {
std::vector<SimHitIdpr> simtrackid;
bool useAssociateHit = !confClusterRefiner_.getParameter<bool>("associateRecoTracks");
if (useAssociateHit) {
if (useAssociateHit_) {
std::vector<PSimHit> simhit;
associator_->associateCluster(clust, DetId(detId), simtrackid, simhit);
NtkAll = simtrackid.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class ClusterRefinerTagMCmerged : public edm::stream::EDProducer<> {
typedef edm::EDGetTokenT< edmNew::DetSetVector<SiStripCluster> > token_t;
token_t inputToken;
edm::ParameterSet confClusterRefiner_;
bool useAssociateHit_;

std::shared_ptr<TrackerHitAssociator> associator_;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;
std::unique_ptr<TrackerHitAssociator> associator_;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "boost/multi_array.hpp"

#include <iostream>
#include <memory>
using namespace std;

class TrackClusterSplitter : public edm::EDProducer
Expand Down Expand Up @@ -150,7 +151,8 @@ class TrackClusterSplitter : public edm::EDProducer

// sim strip split
typedef std::pair<uint32_t, EncodedEventId> SimHitIdpr;
TrackerHitAssociator* hitAssociator;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;
std::unique_ptr<TrackerHitAssociator> hitAssociator;

template<typename C>
static const C* getCluster(const TrackingRecHit* hit) ;
Expand Down Expand Up @@ -232,7 +234,8 @@ void TrackClusterSplitter::splitCluster<SiStripCluster> (const SiStripClusterWit
#define foreach BOOST_FOREACH

TrackClusterSplitter::TrackClusterSplitter(const edm::ParameterSet& iConfig):
useTrajectories_(iConfig.getParameter<bool>("useTrajectories"))
useTrajectories_(iConfig.getParameter<bool>("useTrajectories")),
trackerHitAssociatorConfig_(consumesCollector())
{
if (useTrajectories_) {
trajTrackAssociations_ = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajTrackAssociations"));
Expand Down Expand Up @@ -349,7 +352,7 @@ TrackClusterSplitter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
iEvent.getByToken(stripClusters_, inputStripClusters);

if(simSplitStrip_)
hitAssociator = new TrackerHitAssociator(iEvent);
hitAssociator.reset(new TrackerHitAssociator(iEvent, trackerHitAssociatorConfig_));


allSiPixelClusters.clear(); siPixelDetsWithClusters.clear();
Expand Down Expand Up @@ -516,9 +519,6 @@ TrackClusterSplitter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
std::auto_ptr<edmNew::DetSetVector<SiPixelCluster> > newPixelClusters( splitClusters( siPixelDetsWithClusters, vertices->front() ) );
std::auto_ptr<edmNew::DetSetVector<SiStripCluster> > newStripClusters( splitClusters( siStripDetsWithClusters, vertices->front() ) );

if ( simSplitStrip_ )
delete hitAssociator;

iEvent.put(newPixelClusters);
iEvent.put(newStripClusters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <utility>
#include <vector>
#include <fstream>
#include <memory>

using namespace std;

Expand Down Expand Up @@ -85,15 +86,15 @@ class ClusterShapeExtractor : public edm::EDAnalyzer

TFile * file;

edm::ParameterSet theConfig;
string trackProducer;
bool hasSimHits;
bool hasRecTracks;

edm::EDGetTokenT<SiPixelClusterShapeCache> theClusterShapeCacheToken;

const TrackerGeometry * theTracker;
TrackerHitAssociator * theHitAssociator;
std::unique_ptr<TrackerHitAssociator> theHitAssociator;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;
const ClusterShapeHitFilter * theClusterShape;

vector<TH2F *> hspc; // simulated pixel cluster
Expand Down Expand Up @@ -153,8 +154,8 @@ void ClusterShapeExtractor::beginRun(const edm::Run & run, const edm::EventSetup

/*****************************************************************************/
ClusterShapeExtractor::ClusterShapeExtractor
(const edm::ParameterSet& pset) : theConfig(pset),
theClusterShapeCacheToken(consumes<SiPixelClusterShapeCache>(pset.getParameter<edm::InputTag>("clusterShapeCacheSrc")))
(const edm::ParameterSet& pset) : theClusterShapeCacheToken(consumes<SiPixelClusterShapeCache>(pset.getParameter<edm::InputTag>("clusterShapeCacheSrc"))),
trackerHitAssociatorConfig_(pset, consumesCollector())
{
trackProducer = pset.getParameter<string>("trackProducer");
hasSimHits = pset.getParameter<bool>("hasSimHits");
Expand Down Expand Up @@ -417,7 +418,7 @@ void ClusterShapeExtractor::analyzeSimHits
(const edm::Event& ev, const edm::EventSetup& es)
{
// Get associator
theHitAssociator = new TrackerHitAssociator(ev,theConfig);
theHitAssociator.reset(new TrackerHitAssociator(ev,trackerHitAssociatorConfig_));

// Pixel hits
{
Expand Down Expand Up @@ -459,8 +460,6 @@ void ClusterShapeExtractor::analyzeSimHits
processMatchedRecHits(recHits);
}
}

delete theHitAssociator;
}

/*****************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace cms {
lastSeed(TrajectorySeedCollection& theSeedColl){return theSeedColl.begin()+1;}

void initDebugger(edm::EventSetup const & es){
dbg = new CkfDebugger(es);
dbg = new CkfDebugger(es, consumesCollector());
myTrajectoryBuilder = dynamic_cast<const CkfDebugTrajectoryBuilder*>(theTrajectoryBuilder.get());
if (myTrajectoryBuilder) myTrajectoryBuilder->setDebugger( dbg);
else throw cms::Exception("CkfDebugger") << "please use CkfDebugTrajectoryBuilder";
Expand Down
3 changes: 2 additions & 1 deletion RecoTracker/DebugTools/interface/CkfDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef TransientTrackingRecHit::ConstRecHitPointer CTTRHp;

class CkfDebugger {
public:
CkfDebugger( edm::EventSetup const & es );
CkfDebugger( edm::EventSetup const & es, edm::ConsumesCollector&& iC );

~CkfDebugger();

Expand Down Expand Up @@ -101,6 +101,7 @@ class CkfDebugger {
const GeometricSearchTracker* theGeomSearchTracker;
const MeasurementEstimator* theChi2;
const Propagator* theForwardPropagator;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;
TrackerHitAssociator* hitAssociator;
const MeasurementTracker* theMeasurementTracker;
const TransientTrackingRecHitBuilder* theTTRHBuilder;
Expand Down
3 changes: 1 addition & 2 deletions RecoTracker/DebugTools/interface/TestHits.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class TestHits : public edm::EDAnalyzer {

std::pair<LocalPoint,LocalVector> projectHit(const PSimHit&, const StripGeomDetUnit*, const BoundPlane&);

const edm::ParameterSet conf_;
TrackerHitAssociator * hitAssociator;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;

double mineta, maxeta;

Expand Down
3 changes: 1 addition & 2 deletions RecoTracker/DebugTools/interface/TestSmoothHits.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class TestSmoothHits : public edm::EDAnalyzer {

std::pair<LocalPoint,LocalVector> projectHit(const PSimHit&, const StripGeomDetUnit*, const BoundPlane&);

const edm::ParameterSet conf_;
TrackerHitAssociator * hitAssociator;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;

double mineta, maxeta;

Expand Down
3 changes: 1 addition & 2 deletions RecoTracker/DebugTools/interface/TestTrackHits.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ class TestTrackHits : public edm::EDAnalyzer {
throw cms::Exception("CkfDebugger error: rechit of dimension not 1,2,3,4,5");
}

const edm::ParameterSet conf_;
TrackerHitAssociator * hitAssociator;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;

std::string propagatorName;
std::string builderName;
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/DebugTools/plugins/CkfDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

using namespace std;

CkfDebugger::CkfDebugger( edm::EventSetup const & es ):totSeeds(0)
CkfDebugger::CkfDebugger( edm::EventSetup const & es, edm::ConsumesCollector&& iC):trackerHitAssociatorConfig_(std::move(iC)), totSeeds(0)
{
file = new TFile("out.root","recreate");
hchi2seedAll = new TH1F("hchi2seedAll","hchi2seedAll",2000,0,200);
Expand Down Expand Up @@ -157,7 +157,7 @@ void CkfDebugger::printSimHits( const edm::Event& iEvent)
{
edm::LogVerbatim("CkfDebugger") << "\nEVENT #" << iEvent.id();

hitAssociator = new TrackerHitAssociator(iEvent);//delete deleteHitAssociator() in TrackCandMaker.cc
hitAssociator = new TrackerHitAssociator(iEvent, trackerHitAssociatorConfig_);//delete deleteHitAssociator() in TrackCandMaker.cc

std::map<unsigned int, std::vector<PSimHit> >& theHitsMap = hitAssociator->SimHitMap;
idHitsMap.clear();
Expand Down
32 changes: 15 additions & 17 deletions RecoTracker/DebugTools/plugins/TestHits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ using namespace std;
using namespace edm;

TestHits::TestHits(const edm::ParameterSet& iConfig):
conf_(iConfig){
LogTrace("TestHits") << conf_<< std::endl;
propagatorName = conf_.getParameter<std::string>("Propagator");
builderName = conf_.getParameter<std::string>("TTRHBuilder");
srcName = conf_.getParameter<std::string>("src");
fname = conf_.getParameter<std::string>("Fitter");
mineta = conf_.getParameter<double>("mineta");
maxeta = conf_.getParameter<double>("maxeta");
trackerHitAssociatorConfig_(consumesCollector()) {
LogTrace("TestHits") << iConfig<< std::endl;
propagatorName = iConfig.getParameter<std::string>("Propagator");
builderName = iConfig.getParameter<std::string>("TTRHBuilder");
srcName = iConfig.getParameter<std::string>("src");
fname = iConfig.getParameter<std::string>("Fitter");
mineta = iConfig.getParameter<double>("mineta");
maxeta = iConfig.getParameter<double>("maxeta");
}

TestHits::~TestHits(){}
Expand Down Expand Up @@ -195,7 +195,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
LogTrace("TestHits") << "\nnew event";

iEvent.getByLabel(srcName,theTCCollection );
hitAssociator = new TrackerHitAssociator(iEvent);
TrackerHitAssociator hitAssociator(iEvent, trackerHitAssociatorConfig_);

TrajectoryStateCombiner combiner;

Expand Down Expand Up @@ -245,7 +245,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
double delta = 99999;
LocalPoint rhitLPv = rhit->localPosition();

std::vector<PSimHit> assSimHits = hitAssociator->associateHit(*(rhit->hit()));
std::vector<PSimHit> assSimHits = hitAssociator.associateHit(*(rhit->hit()));
if (assSimHits.size()==0) continue;
PSimHit shit;
for(std::vector<PSimHit>::const_iterator m=assSimHits.begin(); m<assSimHits.end(); m++){
Expand Down Expand Up @@ -402,7 +402,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
auto m = dynamic_cast<const SiStripMatchedRecHit2D*>((rhit)->hit())->monoHit();
CTTRHp tMonoHit = theBuilder->build(&m);
if (tMonoHit==0) continue;
vector<PSimHit> assMonoSimHits = hitAssociator->associateHit(*tMonoHit->hit());
vector<PSimHit> assMonoSimHits = hitAssociator.associateHit(*tMonoHit->hit());
if (assMonoSimHits.size()==0) continue;
const PSimHit sMonoHit = *(assSimHits.begin());
const Surface * monoSurf = &( tMonoHit->det()->surface() );
Expand Down Expand Up @@ -497,7 +497,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
CTTRHp tStereoHit =
theBuilder->build(&s);
if (tStereoHit==0) continue;
vector<PSimHit> assStereoSimHits = hitAssociator->associateHit(*tStereoHit->hit());
vector<PSimHit> assStereoSimHits = hitAssociator.associateHit(*tStereoHit->hit());
if (assStereoSimHits.size()==0) continue;
const PSimHit sStereoHit = *(assSimHits.begin());
const Surface * stereoSurf = &( tStereoHit->det()->surface() );
Expand Down Expand Up @@ -591,7 +591,6 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
LogTrace("TestHits") << "traj chi2=" << tchi2 ;
LogTrace("TestHits") << "track chi2=" << result[0].chiSquared() ;
}
delete hitAssociator;
LogTrace("TestHits") << "end of event" << std::endl;
}
// TSOS lastState = theTSOS;
Expand Down Expand Up @@ -628,7 +627,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
// double delta = 99999;
// LocalPoint rhitLP = rhit->localPosition();

// std::vector<PSimHit> assSimHits = hitAssociator->associateHit(*(*rhit)->hit());
// std::vector<PSimHit> assSimHits = hitAssociator.associateHit(*(*rhit)->hit());
// if (assSimHits.size()==0) continue;
// PSimHit shit;
// for(std::vector<PSimHit>::const_iterator m=assSimHits.begin(); m<assSimHits.end(); m++){
Expand Down Expand Up @@ -747,7 +746,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
// CTTRHp tMonoHit =
// theBuilder->build(dynamic_cast<const SiStripMatchedRecHit2D*>((*rhit)->hit())->monoHit());
// if (tMonoHit==0) continue;
// vector<PSimHit> assMonoSimHits = hitAssociator->associateHit(*tMonoHit->hit());
// vector<PSimHit> assMonoSimHits = hitAssociator.associateHit(*tMonoHit->hit());
// if (assMonoSimHits.size()==0) continue;
// const PSimHit sMonoHit = *(assSimHits.begin());
// const Surface * monoSurf = &( tMonoHit->det()->surface() );
Expand Down Expand Up @@ -841,7 +840,7 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
// CTTRHp tStereoHit =
// theBuilder->build(dynamic_cast<const SiStripMatchedRecHit2D*>((*rhit)->hit())->stereoHit());
// if (tStereoHit==0) continue;
// vector<PSimHit> assStereoSimHits = hitAssociator->associateHit(*tStereoHit->hit());
// vector<PSimHit> assStereoSimHits = hitAssociator.associateHit(*tStereoHit->hit());
// if (assStereoSimHits.size()==0) continue;
// const PSimHit sStereoHit = *(assSimHits.begin());
// const Surface * stereoSurf = &( tStereoHit->det()->surface() );
Expand Down Expand Up @@ -932,7 +931,6 @@ void TestHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
// }
// }
// }
// delete hitAssociator;
// LogTrace("TestHits") << "end of event" << std::endl;
// }

Expand Down
12 changes: 6 additions & 6 deletions RecoTracker/DebugTools/plugins/TestOutliers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class TestOutliers : public edm::EDAnalyzer {
edm::InputTag trackTagsOut_; //used to select what tracks to read from configuration file
edm::InputTag trackTagsOld_; //used to select what tracks to read from configuration file
edm::InputTag tpTags_; //used to select what tracks to read from configuration file
TrackerHitAssociator::Config trackerHitAssociatorConfig_;
edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> theAssociatorOldToken;
edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> theAssociatorOutToken;
TrackerHitAssociator* hitAssociator;
edm::ESHandle<TrackerGeometry> theG;
std::string out;
TFile * file;
Expand Down Expand Up @@ -122,6 +122,7 @@ TestOutliers::TestOutliers(const edm::ParameterSet& iConfig)
trackTagsOut_(iConfig.getUntrackedParameter<edm::InputTag>("tracksOut")),
trackTagsOld_(iConfig.getUntrackedParameter<edm::InputTag>("tracksOld")),
tpTags_(iConfig.getUntrackedParameter<edm::InputTag>("tp")),
trackerHitAssociatorConfig_(consumesCollector()),
theAssociatorOldToken(consumes<reco::TrackToTrackingParticleAssociator>(iConfig.getUntrackedParameter<edm::InputTag>("TrackAssociatorByHitsOld"))),
theAssociatorOutToken(consumes<reco::TrackToTrackingParticleAssociator>(iConfig.getUntrackedParameter<edm::InputTag>("TrackAssociatorByHitsOut"))),
out(iConfig.getParameter<std::string>("out"))
Expand Down Expand Up @@ -177,7 +178,7 @@ TestOutliers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<reco::BeamSpot> beamSpot;
iEvent.getByLabel("offlineBeamSpot",beamSpot);

hitAssociator = new TrackerHitAssociator(iEvent);
TrackerHitAssociator hitAssociator(iEvent, trackerHitAssociatorConfig_);

edm::Handle<reco::TrackToTrackingParticleAssociator> hAssociatorOld;
iEvent.getByToken(theAssociatorOldToken, hAssociatorOld);
Expand Down Expand Up @@ -546,7 +547,7 @@ TestOutliers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {

//LogTrace("TestOutliers") << "vector<SimHitIdpr>";
//look if the hit comes from a correct sim track
std::vector<SimHitIdpr> simTrackIds = hitAssociator->associateHitId(**itHit);
std::vector<SimHitIdpr> simTrackIds = hitAssociator.associateHitId(**itHit);
bool goodhit = false;
for(size_t j=0; j<simTrackIds.size(); j++){
for (size_t jj=0; jj<tpids.size(); jj++){
Expand Down Expand Up @@ -596,7 +597,7 @@ TestOutliers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
//get the vector of sim hit associated and choose the one with the largest energy loss
//double delta = 99999;
//LocalPoint rhitLPv = (*itHit)->localPosition();
//vector<PSimHit> assSimHits = hitAssociator->associateHit(**itHit);
//vector<PSimHit> assSimHits = hitAssociator.associateHit(**itHit);
//if (assSimHits.size()==0) continue;
//PSimHit shit;
//for(std::vector<PSimHit>::const_iterator m=assSimHits.begin(); m<assSimHits.end(); m++){
Expand All @@ -610,7 +611,7 @@ TestOutliers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
unsigned int monoId = 0;
std::vector<double> energyLossM;
std::vector<double> energyLossS;
std::vector<PSimHit> assSimHits = hitAssociator->associateHit(**itHit);
std::vector<PSimHit> assSimHits = hitAssociator.associateHit(**itHit);
if (assSimHits.size()==0) continue;
PSimHit shit;
std::vector<unsigned int> trackIds;
Expand Down Expand Up @@ -888,7 +889,6 @@ TestOutliers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
}
}
}
delete hitAssociator;
}


Expand Down

0 comments on commit 1dd1105

Please sign in to comment.