Skip to content

Commit

Permalink
Remove getByToken from RecoParticleFlow/PFProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Jan 20, 2019
1 parent 8d5b2d1 commit 73aa52a
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 191 deletions.
3 changes: 1 addition & 2 deletions RecoParticleFlow/PFProducer/interface/PFAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class PFAlgo {
double dptRel_DispVtx);

//MIKEB : Parameters for the vertices..
void setPFVertexParameters(bool useVertex,
const reco::VertexCollection* primaryVertices);
void setPFVertexParameters(bool useVertex, reco::VertexCollection const& primaryVertices);

// FlorianB : Collection of e/g electrons
void setEGElectronCollection(const reco::GsfElectronCollection & egelectrons);
Expand Down
6 changes: 2 additions & 4 deletions RecoParticleFlow/PFProducer/interface/PFEGammaAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ class PFEGammaAlgo {
//destructor
~PFEGammaAlgo(){ };

void setEEtoPSAssociation(const edm::Handle<EEtoPSAssociation>& eetops) {
eetops_ = eetops;
}
void setEEtoPSAssociation(EEtoPSAssociation const& eetops) { eetops_ = &eetops; }

void setAlphaGamma_ESplanes_fromDB(const ESEEIntercalibConstants* esEEInterCalib){
cfg_.thePFEnergyCalibration->initAlphaGamma_ESplanes_fromDB(esEEInterCalib);
Expand Down Expand Up @@ -159,7 +157,7 @@ class PFEGammaAlgo {

// useful pre-cached mappings:
// hopefully we get an enum that lets us just make an array in the future
edm::Handle<reco::PFCluster::EEtoPSAssociation> eetops_;
reco::PFCluster::EEtoPSAssociation const* eetops_;
reco::PFBlockRef _currentblock;
reco::PFBlock::LinkData _currentlinks;
// keep a map of pf indices to the splayed block for convenience
Expand Down
2 changes: 1 addition & 1 deletion RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PFMuonAlgo {
//Assign a different track to the muon
void changeTrack(reco::PFCandidate&,const MuonTrackTypePair&);
//PF Post cleaning algorithm
void setInputsForCleaning(const reco::VertexCollection*);
void setInputsForCleaning(reco::VertexCollection const&);
void postClean(reco::PFCandidateCollection *);
void addMissingMuons(edm::Handle<reco::MuonCollection>, reco::PFCandidateCollection* cands);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ChargedHadronPFTrackIsolationProducer : public edm::global::EDProducer<>
private:
// input collection
edm::InputTag srccandidates_;
edm::EDGetTokenT<edm::View<reco::PFCandidate> > candidates_token;
edm::EDGetTokenT<edm::View<reco::PFCandidate> > candidatesToken_;
double minTrackPt_;
double minRawCaloEnergy_;

Expand All @@ -44,7 +44,7 @@ class ChargedHadronPFTrackIsolationProducer : public edm::global::EDProducer<>
ChargedHadronPFTrackIsolationProducer::ChargedHadronPFTrackIsolationProducer(const edm::ParameterSet& cfg)
{
srccandidates_ = cfg.getParameter<edm::InputTag>("src");
candidates_token = consumes<edm::View<reco::PFCandidate> >(srccandidates_);
candidatesToken_ = consumes<edm::View<reco::PFCandidate> >(srccandidates_);
minTrackPt_ = cfg.getParameter<double>("minTrackPt");
minRawCaloEnergy_ = cfg.getParameter<double>("minRawCaloEnergy");

Expand All @@ -54,9 +54,7 @@ ChargedHadronPFTrackIsolationProducer::ChargedHadronPFTrackIsolationProducer(con
void ChargedHadronPFTrackIsolationProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const
{
// get a view of our candidates via the base candidates
typedef edm::View<reco::PFCandidate> PFCandidateView;
edm::Handle<PFCandidateView> candidates;
evt.getByToken(candidates_token, candidates);
auto candidates = evt.getHandle(candidatesToken_);

std::vector<bool> values;

Expand Down
7 changes: 3 additions & 4 deletions RecoParticleFlow/PFProducer/plugins/EFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ EFilter::filter(edm::Event& iEvent,



Handle<std::vector<reco::PFSimParticle> > particles;
iEvent.getByToken(inputTagParticles_, particles);
auto const& particles = iEvent.get(inputTagParticles_);

if( !particles->empty() ) {
if( !particles.empty() ) {
// take first trajectory point of first particle (the mother)
const reco::PFTrajectoryPoint& tp = (*particles)[0].trajectoryPoint(0);
const reco::PFTrajectoryPoint& tp = particles[0].trajectoryPoint(0);

const math::XYZTLorentzVector& mom = tp.momentum();

Expand Down
51 changes: 12 additions & 39 deletions RecoParticleFlow/PFProducer/plugins/PFEGammaProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ PFEGammaProducer::produce(edm::Event& iEvent,
auto sClusters_ = std::make_unique<reco::SuperClusterCollection>();

// Get the EE-PS associations
edm::Handle<reco::PFCluster::EEtoPSAssociation> eetops;
iEvent.getByToken(eetopsSrc_,eetops);
pfeg_->setEEtoPSAssociation(eetops);
pfeg_->setEEtoPSAssociation(iEvent.get(eetopsSrc_));

// preshower conditions
edm::ESHandle<ESEEIntercalibConstants> esEEInterCalibHandle_;
Expand All @@ -104,35 +102,13 @@ PFEGammaProducer::produce(edm::Event& iEvent,
iSetup.get<ESChannelStatusRcd>().get(esChannelStatusHandle_);
pfeg_->setESChannelStatus(esChannelStatusHandle_.product());

// Get The vertices from the event
// and assign dynamic vertex parameters
edm::Handle<reco::VertexCollection> vertices;
bool gotVertices = iEvent.getByToken(vertices_,vertices);
if(!gotVertices) {
std::ostringstream err;
err<<"Cannot find vertices for this event.Continuing Without them ";
edm::LogError("PFEGammaProducer")<<err.str()<<std::endl;
}

//Assign the PFAlgo Parameters
setPFVertexParameters(vertices.product());
setPFVertexParameters(iEvent.get(vertices_));

// get the collection of blocks

edm::Handle< reco::PFBlockCollection > blocks;

LOGDRESSED("PFEGammaProducer")<<"getting blocks"<<std::endl;
bool found = iEvent.getByToken( inputTagBlocks_, blocks );

if(!found ) {

std::ostringstream err;
err<<"cannot find blocks: (tag index)"
<< std::hex<< inputTagBlocks_.index() << std::dec;
edm::LogError("PFEGammaProducer")<<err.str()<<std::endl;

throw cms::Exception( "MissingProduct", err.str());
}
auto blocks = iEvent.getHandle( inputTagBlocks_);

LOGDRESSED("PFEGammaProducer")
<<"EGPFlow is starting..."<<std::endl;
Expand Down Expand Up @@ -358,20 +334,17 @@ PFEGammaProducer::setPFEGParameters(PFEGammaAlgo::PFEGConfigInfo& cfg) {
}

void
PFEGammaProducer::setPFVertexParameters(const reco::VertexCollection* primaryVertices) {

primaryVertex_ = primaryVertices->front();
for (unsigned short i=0 ;i<primaryVertices->size();++i)
{
if(primaryVertices->at(i).isValid()&&(!primaryVertices->at(i).isFake()))
{
primaryVertex_ = primaryVertices->at(i);
break;
PFEGammaProducer::setPFVertexParameters(reco::VertexCollection const& primaryVertices)
{
primaryVertex_ = primaryVertices.front();
for(auto const& pv : primaryVertices) {
if(pv.isValid() && !pv.isFake()) {
primaryVertex_ = pv;
break;
}
}

pfeg_->setPhotonPrimaryVtx(primaryVertex_ );


pfeg_->setPhotonPrimaryVtx(primaryVertex_ );
}

void PFEGammaProducer::createSingleLegConversions(reco::PFCandidateEGammaExtraCollection &extras,
Expand Down
2 changes: 1 addition & 1 deletion RecoParticleFlow/PFProducer/plugins/PFEGammaProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PFEGammaProducer : public edm::stream::EDProducer<edm::GlobalCache<pfEGHel

void setPFEGParameters(PFEGammaAlgo::PFEGConfigInfo&);

void setPFVertexParameters(const reco::VertexCollection* primaryVertices);
void setPFVertexParameters(reco::VertexCollection const& primaryVertices);

void createSingleLegConversions(reco::PFCandidateEGammaExtraCollection &extras,
reco::ConversionCollection &oneLegConversions,
Expand Down
14 changes: 5 additions & 9 deletions RecoParticleFlow/PFProducer/plugins/PFLinker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,24 @@ void PFLinker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {

auto pfCandidates_p = std::make_unique<reco::PFCandidateCollection>();

edm::Handle<reco::GsfElectronCollection> gsfElectrons;
iEvent.getByToken(inputTagGsfElectrons_,gsfElectrons);
auto gsfElectrons = iEvent.getHandle(inputTagGsfElectrons_);

std::map<reco::GsfElectronRef,reco::PFCandidatePtr> electronCandidateMap;


edm::Handle<reco::PhotonCollection> photons;
iEvent.getByToken(inputTagPhotons_,photons);
auto photons = iEvent.getHandle(inputTagPhotons_);
std::map<reco::PhotonRef,reco::PFCandidatePtr> photonCandidateMap;


edm::Handle<reco::MuonToMuonMap> muonMap;
if(fillMuonRefs_)
iEvent.getByToken(inputTagMuonMap_,muonMap);
muonMap = iEvent.getHandle(inputTagMuonMap_);
std::map<reco::MuonRef,reco::PFCandidatePtr> muonCandidateMap;

unsigned nColPF=inputTagPFCandidates_.size();

edm::Handle<reco::PFCandidateCollection> pfCandidates;
for(unsigned icol=0;icol<nColPF;++icol) {
iEvent.getByToken(inputTagPFCandidates_[icol],pfCandidates);
auto pfCandidates = iEvent.getHandle(inputTagPFCandidates_[icol]);
unsigned ncand=pfCandidates->size();

for( unsigned i=0; i<ncand; ++i) {
Expand Down Expand Up @@ -185,8 +182,7 @@ void PFLinker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::ValueMap<reco::PFCandidatePtr> pfMapMuons;

if(fillMuonRefs_){
edm::Handle<reco::MuonCollection> muons;
iEvent.getByToken(inputTagMuons_, muons);
auto muons = iEvent.getHandle(inputTagMuons_);

pfMapMuons = fillValueMap<reco::MuonCollection>(iEvent,
muonTag_.label(),
Expand Down
95 changes: 21 additions & 74 deletions RecoParticleFlow/PFProducer/plugins/PFProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,17 @@ using namespace std;
using namespace edm;


PFProducer::PFProducer(const edm::ParameterSet& iConfig) {
PFProducer::PFProducer(const edm::ParameterSet& iConfig)
{
//--ab: get calibration factors for HF:
bool calibHF_use;
std::vector<double> calibHF_eta_step;
std::vector<double> calibHF_a_EMonly;
std::vector<double> calibHF_b_HADonly;
std::vector<double> calibHF_a_EMHAD;
std::vector<double> calibHF_b_EMHAD;
calibHF_use = iConfig.getParameter<bool>("calibHF_use");
calibHF_eta_step = iConfig.getParameter<std::vector<double> >("calibHF_eta_step");
calibHF_a_EMonly = iConfig.getParameter<std::vector<double> >("calibHF_a_EMonly");
calibHF_b_HADonly = iConfig.getParameter<std::vector<double> >("calibHF_b_HADonly");
calibHF_a_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_a_EMHAD");
calibHF_b_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_b_EMHAD");
std::shared_ptr<PFEnergyCalibrationHF>
thepfEnergyCalibrationHF ( new PFEnergyCalibrationHF(calibHF_use,calibHF_eta_step,calibHF_a_EMonly,calibHF_b_HADonly,calibHF_a_EMHAD,calibHF_b_EMHAD) ) ;
auto thepfEnergyCalibrationHF = std::make_shared<PFEnergyCalibrationHF>(
iConfig.getParameter<bool>("calibHF_use"),
iConfig.getParameter<std::vector<double> >("calibHF_eta_step"),
iConfig.getParameter<std::vector<double> >("calibHF_a_EMonly"),
iConfig.getParameter<std::vector<double> >("calibHF_b_HADonly"),
iConfig.getParameter<std::vector<double> >("calibHF_a_EMHAD"),
iConfig.getParameter<std::vector<double> >("calibHF_b_EMHAD")
);
//-----------------

inputTagBlocks_ = consumes<reco::PFBlockCollection>(iConfig.getParameter<InputTag>("blocks"));
Expand Down Expand Up @@ -491,75 +485,29 @@ PFProducer::beginRun(const edm::Run & run,


void
PFProducer::produce(Event& iEvent,
const EventSetup& iSetup) {

LogDebug("PFProducer")<<"START event: "
<<iEvent.id().event()
<<" in run "<<iEvent.id().run()<<endl;


// Get The vertices from the event
// and assign dynamic vertex parameters
edm::Handle<reco::VertexCollection> vertices;
bool gotVertices = iEvent.getByToken(vertices_,vertices);
if(!gotVertices) {
ostringstream err;
err<<"Cannot find vertices for this event.Continuing Without them ";
LogError("PFProducer")<<err.str()<<endl;
}
PFProducer::produce(Event& iEvent, const EventSetup& iSetup)
{
LogDebug("PFProducer")<<"START event: " <<iEvent.id().event() <<" in run "<<iEvent.id().run()<<endl;

//Assign the PFAlgo Parameters
pfAlgo_->setPFVertexParameters(useVerticesForNeutral_,vertices.product());
pfAlgo_->setPFVertexParameters(useVerticesForNeutral_, iEvent.get(vertices_));

// get the collection of blocks

Handle< reco::PFBlockCollection > blocks;

iEvent.getByToken( inputTagBlocks_, blocks );
auto blocks = iEvent.getHandle( inputTagBlocks_);
assert( blocks.isValid() );

// get the collection of muons
if ( postMuonCleaning_ ) pfAlgo_->setMuonHandle( iEvent.getHandle(inputTagMuons_) );

Handle< reco::MuonCollection > muons;
if (useEGammaElectrons_) pfAlgo_->setEGElectronCollection( iEvent.get(inputTagEgammaElectrons_) );

if ( postMuonCleaning_ ) {

iEvent.getByToken( inputTagMuons_, muons );
pfAlgo_->setMuonHandle(muons);
}

if (useEGammaElectrons_) {
Handle < reco::GsfElectronCollection > egelectrons;
iEvent.getByToken( inputTagEgammaElectrons_, egelectrons );
pfAlgo_->setEGElectronCollection(*egelectrons);
}

if(use_EGammaFilters_) {

// Read PFEGammaCandidates

edm::Handle<edm::View<reco::PFCandidate> > pfEgammaCandidates;
iEvent.getByToken(inputTagPFEGammaCandidates_,pfEgammaCandidates);

// Get the value maps

edm::Handle<edm::ValueMap<reco::GsfElectronRef> > valueMapGedElectrons;
iEvent.getByToken(inputTagValueMapGedElectrons_,valueMapGedElectrons);

edm::Handle<edm::ValueMap<reco::PhotonRef> > valueMapGedPhotons;
iEvent.getByToken(inputTagValueMapGedPhotons_,valueMapGedPhotons);

pfAlgo_->setEGammaCollections(*pfEgammaCandidates,
*valueMapGedElectrons,
*valueMapGedPhotons);

}
if(use_EGammaFilters_) pfAlgo_->setEGammaCollections( iEvent.get(inputTagPFEGammaCandidates_),
iEvent.get(inputTagValueMapGedElectrons_),
iEvent.get(inputTagValueMapGedPhotons_));


LogDebug("PFProducer")<<"particle flow is starting"<<endl;

assert( blocks.isValid() );

pfAlgo_->reconstructParticles( blocks );

if(verbose_) {
Expand Down Expand Up @@ -664,4 +612,3 @@ PFProducer::produce(Event& iEvent,

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ void EGPhotonImporter::
importToBlock( const edm::Event& e,
BlockElementImporterBase::ElementList& elems ) const {
typedef BlockElementImporterBase::ElementList::value_type ElementType;
edm::Handle<reco::PhotonCollection> photons;
e.getByToken(_src,photons);
auto photons = e.getHandle(_src);
elems.reserve(elems.size()+photons->size());
// setup our elements so that all the SCs are grouped together
auto SCs_end = std::partition(elems.begin(),elems.end(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ DEFINE_EDM_PLUGIN(BlockElementImporterFactory,
void GSFTrackImporter::
importToBlock( const edm::Event& e,
BlockElementImporterBase::ElementList& elems ) const {
typedef BlockElementImporterBase::ElementList::value_type ElementType;
edm::Handle<reco::GsfPFRecTrackCollection> gsftracks;
e.getByToken(_src,gsftracks);
auto gsftracks = e.getHandle(_src);
elems.reserve(elems.size() + gsftracks->size());
// setup our elements so that all the SCs are grouped together
auto SCs_end = std::partition(elems.begin(),elems.end(),
[](const ElementType& a){
[](const auto& a){
return a->type() == reco::PFBlockElement::SC;
});
size_t SCs_end_position = std::distance(elems.begin(),SCs_end);
Expand Down Expand Up @@ -73,7 +71,7 @@ importToBlock( const edm::Event& e,
new reco::PFBlockElementSuperCluster(scref);
scbe->setFromGsfElectron(true);
scbe->setFromPFSuperCluster(_superClustersArePF);
SCs_end = elems.insert(SCs_end,ElementType(scbe));
SCs_end = elems.emplace(SCs_end,scbe);
++SCs_end; // point to element *after* the new one
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ void GeneralTracksImporter::
importToBlock( const edm::Event& e,
BlockElementImporterBase::ElementList& elems ) const {
typedef BlockElementImporterBase::ElementList::value_type ElementType;
edm::Handle<reco::PFRecTrackCollection> tracks;
e.getByToken(src_,tracks);
edm::Handle<reco::MuonCollection> muons;
e.getByToken(muons_,muons);
auto tracks = e.getHandle(src_);
auto muons = e.getHandle(muons_);
elems.reserve(elems.size() + tracks->size());
std::vector<bool> mask(tracks->size(),true);
reco::MuonRef muonref;
Expand Down
Loading

0 comments on commit 73aa52a

Please sign in to comment.