Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added consumes interface to RecoTau sequence #1718

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h
Expand Up @@ -33,6 +33,7 @@
#include <boost/ptr_container/ptr_vector.hpp>

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/JetReco/interface/PFJetCollection.h"
Expand All @@ -53,13 +54,15 @@ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin {
public:
typedef boost::ptr_vector<reco::PFTau> output_type;
typedef std::auto_ptr<output_type> return_type;
// edm::ConsumesCollector iC();

explicit RecoTauBuilderPlugin(const edm::ParameterSet& pset):
explicit RecoTauBuilderPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector& iC):
RecoTauEventHolderPlugin(pset),
// The vertex association configuration is specified with the
// quality cuts.
vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts")) {
vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"),iC) {
pfCandSrc_ = pset.getParameter<edm::InputTag>("pfCandSrc");
pfCand_token = iC.consumes<PFCandidateCollection>(pfCandSrc_);
};

virtual ~RecoTauBuilderPlugin() {}
Expand Down Expand Up @@ -89,13 +92,13 @@ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin {
// Handle to PFCandidates needed to build Refs
edm::Handle<PFCandidateCollection> pfCands_;
reco::tau::RecoTauVertexAssociator vertexAssociator_;

edm::EDGetTokenT<PFCandidateCollection> pfCand_token;
};

/* Class that updates a PFTau's members (i.e. electron variables) */
class RecoTauModifierPlugin : public RecoTauEventHolderPlugin {
public:
explicit RecoTauModifierPlugin(const edm::ParameterSet& pset):
explicit RecoTauModifierPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector& iC):
RecoTauEventHolderPlugin(pset){};
virtual ~RecoTauModifierPlugin() {}
// Modify an existing PFTau (i.e. add electron rejection, etc)
Expand All @@ -106,7 +109,7 @@ class RecoTauModifierPlugin : public RecoTauEventHolderPlugin {
/* Class that returns a double value indicating the quality of a given tau */
class RecoTauCleanerPlugin : public RecoTauEventHolderPlugin {
public:
explicit RecoTauCleanerPlugin(const edm::ParameterSet& pset):
explicit RecoTauCleanerPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector &iC ):
RecoTauEventHolderPlugin(pset){};
virtual ~RecoTauCleanerPlugin() {}
// Modify an existing PFTau (i.e. add electron rejection, etc)
Expand All @@ -117,10 +120,10 @@ class RecoTauCleanerPlugin : public RecoTauEventHolderPlugin {

#include "FWCore/PluginManager/interface/PluginFactory.h"
typedef edmplugin::PluginFactory<reco::tau::RecoTauBuilderPlugin*
(const edm::ParameterSet&)> RecoTauBuilderPluginFactory;
(const edm::ParameterSet&, edm::ConsumesCollector &iC)> RecoTauBuilderPluginFactory;
typedef edmplugin::PluginFactory<reco::tau::RecoTauModifierPlugin*
(const edm::ParameterSet&)> RecoTauModifierPluginFactory;
(const edm::ParameterSet&, edm::ConsumesCollector &iC)> RecoTauModifierPluginFactory;
typedef edmplugin::PluginFactory<reco::tau::RecoTauCleanerPlugin*
(const edm::ParameterSet&)> RecoTauCleanerPluginFactory;
(const edm::ParameterSet&, edm::ConsumesCollector &iC)> RecoTauCleanerPluginFactory;

#endif
6 changes: 4 additions & 2 deletions RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h
Expand Up @@ -22,6 +22,8 @@
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "RecoTauTag/RecoTau/interface/RecoTauPluginsCommon.h"

#include "FWCore/Framework/interface/ConsumesCollector.h"

namespace reco {
// Forward declarations
class PFJet;
Expand All @@ -35,7 +37,7 @@ class RecoTauPiZeroBuilderPlugin : public RecoTauEventHolderPlugin {
// Storing the result in an auto ptr on function return allows
// allows us to safely release the ptr_vector in the virtual function
typedef std::auto_ptr<PiZeroVector> return_type;
explicit RecoTauPiZeroBuilderPlugin(const edm::ParameterSet& pset):
explicit RecoTauPiZeroBuilderPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector &iC):
RecoTauEventHolderPlugin(pset) {}
virtual ~RecoTauPiZeroBuilderPlugin() {}
/// Build a collection of piZeros from objects in the input jet
Expand All @@ -58,5 +60,5 @@ class RecoTauPiZeroQualityPlugin : public RecoTauNamedPlugin {
typedef edmplugin::PluginFactory<reco::tau::RecoTauPiZeroQualityPlugin*
(const edm::ParameterSet&)> RecoTauPiZeroQualityPluginFactory;
typedef edmplugin::PluginFactory<reco::tau::RecoTauPiZeroBuilderPlugin*
(const edm::ParameterSet&)> RecoTauPiZeroBuilderPluginFactory;
(const edm::ParameterSet&, edm::ConsumesCollector &iC)> RecoTauPiZeroBuilderPluginFactory;
#endif
6 changes: 5 additions & 1 deletion RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h
Expand Up @@ -17,6 +17,8 @@
*
*/

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/EDConsumerBase.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/Common/interface/Handle.h"
Expand Down Expand Up @@ -48,7 +50,7 @@ class RecoTauVertexAssociator {
kCombined
};

RecoTauVertexAssociator (const edm::ParameterSet& pset);
RecoTauVertexAssociator (const edm::ParameterSet& pset, edm::ConsumesCollector& iC);
virtual ~RecoTauVertexAssociator (){}
/// Get the primary vertex associated to a given jet. Returns a null Ref if
/// no vertex is found.
Expand All @@ -74,6 +76,8 @@ class RecoTauVertexAssociator {
RecoTauQualityCuts qcuts_;
bool recoverLeadingTrk;

edm::EDGetTokenT<reco::VertexCollection> vx_token;

};

} /* tau */ } /* reco */
Expand Down
9 changes: 8 additions & 1 deletion RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h
Expand Up @@ -36,6 +36,7 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DataFormats/TauReco/interface/PFTau.h"
#include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
Expand Down Expand Up @@ -75,8 +76,13 @@ class TauDiscriminationProducerBase : public edm::EDProducer {
struct TauDiscInfo {
edm::InputTag label;
edm::Handle<TauDiscriminator> handle;
edm::EDGetTokenT<TauDiscriminator> disc_token;
// = consumes<TauDiscriminator>(label);
double cut;
void fill(const edm::Event& evt) { evt.getByLabel(label, handle); };
void fill(const edm::Event& evt) {
// disc_token = consumes<TauDiscriminator>(label);
evt.getByToken(disc_token, handle);
};
};

protected:
Expand All @@ -86,6 +92,7 @@ class TauDiscriminationProducerBase : public edm::EDProducer {
edm::InputTag TauProducer_;

std::string moduleLabel_;
edm::EDGetTokenT<TauCollection> Tau_token;

private:
std::vector<TauDiscInfo> prediscriminants_;
Expand Down
Expand Up @@ -57,7 +57,7 @@ class PFRecoTauDiscriminationAgainstElectronMVA2 : public PFTauDiscriminationPro
minMVA1prongStripsWgsfWpfEleMvaEC_ = iConfig.getParameter<double>("minMVA1prongStripsWgsfWpfEleMvaEC");

srcGsfElectrons_ = iConfig.getParameter<edm::InputTag>("srcGsfElectrons");

GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
mva_ = new AntiElectronIDMVA2();
// CV: working version of file compression not implemented yet
//mva_->Initialize_from_string(method_,
Expand Down Expand Up @@ -149,6 +149,7 @@ class PFRecoTauDiscriminationAgainstElectronMVA2 : public PFTauDiscriminationPro
double minMVA1prongStripsWgsfWOpfEleMvaEC_ ;
double minMVA1prongStripsWgsfWpfEleMvaEC_ ;
edm::InputTag srcGsfElectrons_;
edm::EDGetTokenT<reco::GsfElectronCollection> GsfElectrons_token;
edm::Handle<reco::GsfElectronCollection> gsfElectrons_;
edm::Handle<TauCollection> taus_;
std::auto_ptr<PFTauDiscriminator> category_output_;
Expand All @@ -158,11 +159,11 @@ class PFRecoTauDiscriminationAgainstElectronMVA2 : public PFTauDiscriminationPro
void PFRecoTauDiscriminationAgainstElectronMVA2::beginEvent(const edm::Event& evt, const edm::EventSetup& es)
{
if ( returnMVA_ ) {
evt.getByLabel(TauProducer_, taus_);
evt.getByToken(Tau_token, taus_);
category_output_.reset(new PFTauDiscriminator(TauRefProd(taus_)));
tauIndex_ = 0;
}
evt.getByLabel(srcGsfElectrons_, gsfElectrons_);
evt.getByToken(GsfElectrons_token, gsfElectrons_);
}

double PFRecoTauDiscriminationAgainstElectronMVA2::discriminate(const PFTauRef& thePFTauRef)
Expand Down
Expand Up @@ -71,7 +71,7 @@ class PFRecoTauDiscriminationAgainstElectronMVA3 : public PFTauDiscriminationPro
minMVA3prongNoMatch_ = iConfig.getParameter<double>("minMVA3prongNoMatch");

srcGsfElectrons_ = iConfig.getParameter<edm::InputTag>("srcGsfElectrons");

GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
mva_ = new AntiElectronIDMVA3();
// CV: working version of file compression not implemented yet
// mva_->Initialize_from_string(method_,
Expand Down Expand Up @@ -189,6 +189,7 @@ class PFRecoTauDiscriminationAgainstElectronMVA3 : public PFTauDiscriminationPro
double minMVA3prongMatch_ ;
double minMVA3prongNoMatch_ ;
edm::InputTag srcGsfElectrons_;
edm::EDGetTokenT<reco::GsfElectronCollection> GsfElectrons_token;
edm::Handle<reco::GsfElectronCollection> gsfElectrons_;
edm::Handle<TauCollection> taus_;
std::auto_ptr<PFTauDiscriminator> category_output_;
Expand All @@ -198,11 +199,11 @@ class PFRecoTauDiscriminationAgainstElectronMVA3 : public PFTauDiscriminationPro
void PFRecoTauDiscriminationAgainstElectronMVA3::beginEvent(const edm::Event& evt, const edm::EventSetup& es)
{
if ( returnMVA_ ) {
evt.getByLabel(TauProducer_, taus_);
evt.getByToken(Tau_token, taus_);
category_output_.reset(new PFTauDiscriminator(TauRefProd(taus_)));
tauIndex_ = 0;
}
evt.getByLabel(srcGsfElectrons_, gsfElectrons_);
evt.getByToken(GsfElectrons_token, gsfElectrons_);
}

double PFRecoTauDiscriminationAgainstElectronMVA3::discriminate(const PFTauRef& thePFTauRef)
Expand Down
Expand Up @@ -47,6 +47,7 @@ class PFRecoTauDiscriminationAgainstMuon2 : public PFTauDiscriminationProducerBa
maxNumberOfHitsLast2Stations_ = cfg.exists("maxNumberOfHitsLast2Stations") ? cfg.getParameter<int>("maxNumberOfHitsLast2Stations"): 0;
if ( cfg.exists("srcMuons") ) {
srcMuons_ = cfg.getParameter<edm::InputTag>("srcMuons");
Muons_token=consumes<reco::MuonCollection>(srcMuons_);
dRmuonMatch_ = cfg.getParameter<double>("dRmuonMatch");
}
verbosity_ = cfg.exists("verbosity") ? cfg.getParameter<int>("verbosity") : 0;
Expand All @@ -66,14 +67,15 @@ class PFRecoTauDiscriminationAgainstMuon2 : public PFTauDiscriminationProducerBa
int maxNumberOfHitsLast2Stations_;
edm::InputTag srcMuons_;
edm::Handle<reco::MuonCollection> muons_;
edm::EDGetTokenT<reco::MuonCollection> Muons_token;
double dRmuonMatch_;
int verbosity_;
};

void PFRecoTauDiscriminationAgainstMuon2::beginEvent(const edm::Event& evt, const edm::EventSetup& es)
{
if ( srcMuons_.label() != "" ) {
evt.getByLabel(srcMuons_, muons_);
evt.getByToken(Muons_token, muons_);
}
}

Expand Down
Expand Up @@ -25,13 +25,13 @@ using namespace edm;
class PFRecoTauDiscriminationByFlightPathSignificance
: public PFTauDiscriminationProducerBase {
public:
explicit PFRecoTauDiscriminationByFlightPathSignificance(
const ParameterSet& iConfig)
:PFTauDiscriminationProducerBase(iConfig),
vertexAssociator_(iConfig.getParameter<ParameterSet>("qualityCuts")) {
explicit PFRecoTauDiscriminationByFlightPathSignificance(const ParameterSet& iConfig)
:PFTauDiscriminationProducerBase(iConfig){
flightPathSig = iConfig.getParameter<double>("flightPathSig");
withPVError = iConfig.getParameter<bool>("UsePVerror");
booleanOutput = iConfig.getParameter<bool>("BooleanOutput");
edm::ConsumesCollector iC(consumesCollector());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. Just do

vertexAssociator_ = new reco::tau::RecoTauVertexAssociator(iConfig.getParameter("qualityCuts"), consumesCollector());

vertexAssociator_ = new reco::tau::RecoTauVertexAssociator(iConfig.getParameter<ParameterSet>("qualityCuts"),iC);
}

~PFRecoTauDiscriminationByFlightPathSignificance(){}
Expand All @@ -43,7 +43,7 @@ class PFRecoTauDiscriminationByFlightPathSignificance
double threeProngFlightPathSig(const PFTauRef&);
double vertexSignificance(reco::Vertex&,reco::Vertex&,GlobalVector&);

reco::tau::RecoTauVertexAssociator vertexAssociator_;
reco::tau::RecoTauVertexAssociator* vertexAssociator_;

bool booleanOutput;
double flightPathSig;
Expand All @@ -55,7 +55,7 @@ class PFRecoTauDiscriminationByFlightPathSignificance
void PFRecoTauDiscriminationByFlightPathSignificance::beginEvent(
const Event& iEvent, const EventSetup& iSetup){

vertexAssociator_.setEvent(iEvent);
vertexAssociator_->setEvent(iEvent);

// Transient Tracks
edm::ESHandle<TransientTrackBuilder> builder;
Expand All @@ -74,7 +74,7 @@ double PFRecoTauDiscriminationByFlightPathSignificance::threeProngFlightPathSig(
const PFTauRef& tau){
double flightPathSignificance = 0;

reco::VertexRef primaryVertex = vertexAssociator_.associatedVertex(*tau);
reco::VertexRef primaryVertex = vertexAssociator_->associatedVertex(*tau);

if (primaryVertex.isNull()) {
edm::LogError("FlightPathSignficance") << "Could not get vertex associated"
Expand Down
16 changes: 11 additions & 5 deletions RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByIsolation.cc
Expand Up @@ -78,9 +78,9 @@ class PFRecoTauDiscriminationByIsolation :
"isolationQualityCuts");

qcuts_.reset(new tau::RecoTauQualityCuts(isolationQCuts));

edm::ConsumesCollector iC(consumesCollector());
vertexAssociator_.reset(
new tau::RecoTauVertexAssociator(qualityCutsPSet_));
new tau::RecoTauVertexAssociator(qualityCutsPSet_,iC));

applyDeltaBeta_ = pset.exists("applyDeltaBetaCorrection") ?
pset.getParameter<bool>("applyDeltaBetaCorrection") : false;
Expand Down Expand Up @@ -111,7 +111,9 @@ class PFRecoTauDiscriminationByIsolation :
puFactorizedIsoQCuts.second));

pfCandSrc_ = pset.getParameter<edm::InputTag>("particleFlowSrc");
pfCand_token=consumes<reco::PFCandidateCollection>(pfCandSrc_);
vertexSrc_ = pset.getParameter<edm::InputTag>("vertexSrc");
vertex_token=consumes<reco::VertexCollection>(vertexSrc_);
deltaBetaCollectionCone_ = pset.getParameter<double>(
"isoConeSizeForDeltaBeta");
std::string deltaBetaFactorFormula =
Expand All @@ -124,6 +126,7 @@ class PFRecoTauDiscriminationByIsolation :
pset.getParameter<bool>("applyRhoCorrection") : false;
if (applyRhoCorrection_) {
rhoProducer_ = pset.getParameter<edm::InputTag>("rhoProducer");
rho_token=consumes<double>(rhoProducer_);
rhoConeSize_ = pset.getParameter<double>("rhoConeSize");
rhoUEOffsetCorrection_ =
pset.getParameter<double>("rhoUEOffsetCorrection");
Expand Down Expand Up @@ -167,8 +170,10 @@ class PFRecoTauDiscriminationByIsolation :
// Delta Beta correction
bool applyDeltaBeta_;
edm::InputTag pfCandSrc_;
edm::EDGetTokenT<reco::PFCandidateCollection> pfCand_token;
// Keep track of how many vertices are in the event
edm::InputTag vertexSrc_;
edm::EDGetTokenT<reco::VertexCollection> vertex_token;
std::vector<reco::PFCandidateRef> chargedPFCandidatesInEvent_;
// Size of cone used to collect PU tracks
double deltaBetaCollectionCone_;
Expand All @@ -178,6 +183,7 @@ class PFRecoTauDiscriminationByIsolation :
// Rho correction
bool applyRhoCorrection_;
edm::InputTag rhoProducer_;
edm::EDGetTokenT<double> rho_token;
double rhoConeSize_;
double rhoUEOffsetCorrection_;
double rhoCorrectionThisEvent_;
Expand All @@ -199,7 +205,7 @@ void PFRecoTauDiscriminationByIsolation::beginEvent(const edm::Event& event,
if (applyDeltaBeta_) {
// Collect all the PF pile up tracks
edm::Handle<reco::PFCandidateCollection> pfCandHandle_;
event.getByLabel(pfCandSrc_, pfCandHandle_);
event.getByToken(pfCand_token, pfCandHandle_);
chargedPFCandidatesInEvent_.reserve(pfCandHandle_->size());
for (size_t i = 0; i < pfCandHandle_->size(); ++i) {
reco::PFCandidateRef pfCand(pfCandHandle_, i);
Expand All @@ -209,14 +215,14 @@ void PFRecoTauDiscriminationByIsolation::beginEvent(const edm::Event& event,
// Count all the vertices in the event, to parameterize the DB
// correction factor
edm::Handle<reco::VertexCollection> vertices;
event.getByLabel(vertexSrc_, vertices);
event.getByToken(vertex_token, vertices);
size_t nVtxThisEvent = vertices->size();
deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
}

if (applyRhoCorrection_) {
edm::Handle<double> rhoHandle_;
event.getByLabel(rhoProducer_, rhoHandle_);
event.getByToken(rho_token, rhoHandle_);
rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_)*
(3.14159)*rhoConeSize_*rhoConeSize_;
}
Expand Down
Expand Up @@ -66,6 +66,7 @@ class PFRecoTauDiscriminationByMVAIsolation : public PFTauDiscriminationProducer
// Read GBRForest
TFile *gbrfFile = new TFile(gbrfFilePath_.fullPath().data());
gbrfTauIso_ = (GBRForest *)(gbrfFile->Get("gbrfTauIso"));
rho_token=consumes<double>(rhoProducer_);
}

~PFRecoTauDiscriminationByMVAIsolation(){}
Expand All @@ -76,6 +77,7 @@ class PFRecoTauDiscriminationByMVAIsolation : public PFTauDiscriminationProducer

private:
edm::InputTag rhoProducer_;
edm::EDGetTokenT<double> rho_token;
edm::FileInPath gbrfFilePath_;
GBRForest *gbrfTauIso_;
bool returnMVA_;
Expand All @@ -88,7 +90,7 @@ void PFRecoTauDiscriminationByMVAIsolation::beginEvent(const edm::Event& event,
{
// Get rho of event
edm::Handle<double> hRho;
event.getByLabel(rhoProducer_, hRho);
event.getByToken(rho_token, hRho);
rho_ = *hRho;
}

Expand Down