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

Finalize migration to consumes for RecoEgamma/EgammaHLT* #2497

Merged
merged 9 commits into from Feb 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion DQM/Physics/src/QcdPhotonsDQM.cc
Expand Up @@ -315,7 +315,7 @@ void QcdPhotonsDQM::analyze(const Event& iEvent, const EventSetup& iSetup) {
iEvent.getByToken(theBarrelRecHitToken_, EBReducedRecHits);
Handle<EcalRecHitCollection> EEReducedRecHits;
iEvent.getByToken(theEndcapRecHitToken_, EEReducedRecHits);
EcalClusterLazyTools lazyTool(iEvent, iSetup, theBarrelRecHitTag_, theEndcapRecHitTag_);
EcalClusterLazyTools lazyTool(iEvent, iSetup, theBarrelRecHitToken_, theEndcapRecHitToken_);


// Find the highest et "decent" photon
Expand Down
2 changes: 1 addition & 1 deletion DQMOffline/Trigger/src/FourVectorHLTOffline.cc
Expand Up @@ -2352,7 +2352,7 @@ void FourVectorHLTOffline::selectElectrons(const edm::Event& iEvent, const edm::

if(pEBRecHits.isValid() && pEERecHits.isValid()) {

EcalClusterLazyTools lazyTool(iEvent, iSetup, recHitsEBTag_, recHitsEETag_);
EcalClusterLazyTools lazyTool(iEvent, iSetup, recHitsEBToken, recHitsEEToken);
const reco::CaloCluster* bc = iter->superCluster()->seed().get(); // get the basic cluster

float eleMaxOver3x3 = ( lazyTool.eMax(*bc) / lazyTool.e3x3(*bc) );
Expand Down
233 changes: 116 additions & 117 deletions EgammaAnalysis/ElectronTools/plugins/ElectronIdMVAProducer.cc
Expand Up @@ -24,29 +24,28 @@
using namespace std;
using namespace reco;
class ElectronIdMVAProducer : public edm::EDFilter {
public:
explicit ElectronIdMVAProducer(const edm::ParameterSet&);
~ElectronIdMVAProducer();

private:
virtual bool filter(edm::Event&, const edm::EventSetup&);

// ----------member data ---------------------------
bool verbose_;
edm::EDGetTokenT<reco::VertexCollection> vertexToken_;
edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
edm::EDGetTokenT<double> eventrhoToken_;
edm::InputTag reducedEBRecHitCollection_;
edm::InputTag reducedEERecHitCollection_;

double _Rho;
string method_;
vector<string> mvaWeightFiles_;
bool Trig_;
bool NoIP_;

EGammaMvaEleEstimator* mvaID_;

public:
explicit ElectronIdMVAProducer(const edm::ParameterSet&);
~ElectronIdMVAProducer();

private:
virtual bool filter(edm::Event&, const edm::EventSetup&);

// ----------member data ---------------------------
bool verbose_;
edm::EDGetTokenT<reco::VertexCollection> vertexToken_;
edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
edm::EDGetTokenT<double> eventrhoToken_;
edm::EDGetTokenT<EcalRecHitCollection> reducedEBRecHitCollectionToken_;
edm::EDGetTokenT<EcalRecHitCollection> reducedEERecHitCollectionToken_;

double _Rho;
string method_;
vector<string> mvaWeightFiles_;
bool Trig_;
bool NoIP_;

EGammaMvaEleEstimator* mvaID_;
};

//
Expand All @@ -61,47 +60,47 @@ class ElectronIdMVAProducer : public edm::EDFilter {
// constructors and destructor
//
ElectronIdMVAProducer::ElectronIdMVAProducer(const edm::ParameterSet& iConfig) {
verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
eventrhoToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
reducedEBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection");
reducedEERecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection");
method_ = iConfig.getParameter<string>("method");
std::vector<string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
Trig_ = iConfig.getParameter<bool>("Trig");
NoIP_ = iConfig.getParameter<bool>("NoIP");

produces<edm::ValueMap<float> >("");

mvaID_ = new EGammaMvaEleEstimator();

EGammaMvaEleEstimator::MVAType type_;
if(Trig_ && !NoIP_){type_ = EGammaMvaEleEstimator::kTrig;}

if(Trig_ && NoIP_){type_ = EGammaMvaEleEstimator::kTrigNoIP;}

if(!Trig_){type_ = EGammaMvaEleEstimator::kNonTrig;}

bool manualCat_ = true;

string path_mvaWeightFileEleID;
for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
}

mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);

verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
eventrhoToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
reducedEBRecHitCollectionToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection"));
reducedEERecHitCollectionToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection"));
method_ = iConfig.getParameter<string>("method");
std::vector<string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
Trig_ = iConfig.getParameter<bool>("Trig");
NoIP_ = iConfig.getParameter<bool>("NoIP");
produces<edm::ValueMap<float> >("");
mvaID_ = new EGammaMvaEleEstimator();
EGammaMvaEleEstimator::MVAType type_;
if(Trig_ && !NoIP_){type_ = EGammaMvaEleEstimator::kTrig;}
if(Trig_ && NoIP_){type_ = EGammaMvaEleEstimator::kTrigNoIP;}
if(!Trig_){type_ = EGammaMvaEleEstimator::kNonTrig;}
bool manualCat_ = true;
string path_mvaWeightFileEleID;
for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
}
mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
}


ElectronIdMVAProducer::~ElectronIdMVAProducer()
{

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}


Expand All @@ -111,64 +110,64 @@ ElectronIdMVAProducer::~ElectronIdMVAProducer()

// ------------ method called on each new Event ------------
bool ElectronIdMVAProducer::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;

std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );

Handle<reco::VertexCollection> vertexCollection;
iEvent.getByToken(vertexToken_, vertexCollection);

Vertex dummy;
const Vertex *pv = &dummy;
if ( vertexCollection->size() != 0) {
pv = &*vertexCollection->begin();
} else { // create a dummy PV
Vertex::Error e;
e(0, 0) = 0.0015 * 0.0015;
e(1, 1) = 0.0015 * 0.0015;
e(2, 2) = 15. * 15.;
Vertex::Point p(0, 0, 0);
dummy = Vertex(p, e, 0, 0, 0);
}

EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection_, reducedEERecHitCollection_);

edm::ESHandle<TransientTrackBuilder> builder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
TransientTrackBuilder thebuilder = *(builder.product());

Handle<reco::GsfElectronCollection> egCollection;
iEvent.getByToken(electronToken_,egCollection);
const reco::GsfElectronCollection egCandidates = (*egCollection.product());

_Rho=0;
edm::Handle<double> rhoPtr;
iEvent.getByToken(eventrhoToken_,rhoPtr);
_Rho=*rhoPtr;

std::vector<float> values;
values.reserve(egCollection->size());

for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {

double mvaVal = -999999;
if(!NoIP_){
mvaVal = mvaID_->mvaValue( *egIter, *pv,thebuilder,lazyTools, verbose_);
}
if(NoIP_){
mvaVal = mvaID_->mvaValue( *egIter, *pv, _Rho,/*thebuilder,*/lazyTools, verbose_);
}

values.push_back( mvaVal );
}

edm::ValueMap<float>::Filler filler(*out);
filler.insert(egCollection, values.begin(), values.end() );
filler.fill();

iEvent.put(out);

return true;
using namespace edm;
std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );
Handle<reco::VertexCollection> vertexCollection;
iEvent.getByToken(vertexToken_, vertexCollection);
Vertex dummy;
const Vertex *pv = &dummy;
if ( vertexCollection->size() != 0) {
pv = &*vertexCollection->begin();
} else { // create a dummy PV
Vertex::Error e;
e(0, 0) = 0.0015 * 0.0015;
e(1, 1) = 0.0015 * 0.0015;
e(2, 2) = 15. * 15.;
Vertex::Point p(0, 0, 0);
dummy = Vertex(p, e, 0, 0, 0);
}
EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollectionToken_, reducedEERecHitCollectionToken_);
edm::ESHandle<TransientTrackBuilder> builder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
TransientTrackBuilder thebuilder = *(builder.product());
Handle<reco::GsfElectronCollection> egCollection;
iEvent.getByToken(electronToken_,egCollection);
const reco::GsfElectronCollection egCandidates = (*egCollection.product());
_Rho=0;
edm::Handle<double> rhoPtr;
iEvent.getByToken(eventrhoToken_,rhoPtr);
_Rho=*rhoPtr;
std::vector<float> values;
values.reserve(egCollection->size());
for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
double mvaVal = -999999;
if(!NoIP_){
mvaVal = mvaID_->mvaValue( *egIter, *pv,thebuilder,lazyTools, verbose_);
}
if(NoIP_){
mvaVal = mvaID_->mvaValue( *egIter, *pv, _Rho,/*thebuilder,*/lazyTools, verbose_);
}
values.push_back( mvaVal );
}
edm::ValueMap<float>::Filler filler(*out);
filler.insert(egCollection, values.begin(), values.end() );
filler.fill();
iEvent.put(out);
return true;
}

//define this as a plug-in
Expand Down
57 changes: 26 additions & 31 deletions EgammaAnalysis/ElectronTools/test/ElectronTestAnalyzer.cc
Expand Up @@ -67,34 +67,36 @@ using namespace edm;
using namespace reco;
using namespace std;
class ElectronTestAnalyzer : public edm::EDAnalyzer {
public:
explicit ElectronTestAnalyzer(const edm::ParameterSet&);
~ElectronTestAnalyzer();


private:
virtual void beginJob(const edm::EventSetup&) ;
virtual void analyze(const edm::Event&, const edm::EventSetup&);
virtual void endJob() ;
virtual void myBindVariables();
virtual void myVar(const reco::GsfElectron& ele,
const reco::Vertex& vertex,
const TransientTrackBuilder& transientTrackBuilder,
EcalClusterLazyTools myEcalCluster,
bool printDebug = kFALSE);
virtual void evaluate_mvas(const edm::Event& iEvent, const edm::EventSetup& iSetup);

public:
explicit ElectronTestAnalyzer(const edm::ParameterSet&);
~ElectronTestAnalyzer();
private:
virtual void beginJob(const edm::EventSetup&) ;
virtual void analyze(const edm::Event&, const edm::EventSetup&);
virtual void endJob() ;
virtual void myBindVariables();
virtual void myVar(const reco::GsfElectron& ele,
const reco::Vertex& vertex,
const TransientTrackBuilder& transientTrackBuilder,
EcalClusterLazyTools myEcalCluster,
bool printDebug = kFALSE);
virtual void evaluate_mvas(const edm::Event& iEvent, const edm::EventSetup& iSetup);
bool trainTrigPresel(const reco::GsfElectron& ele);

ParameterSet conf_;

edm::EDGetTokenT<GsfElectronCollection> gsfEleToken_;
edm::EDGetTokenT<GenParticleCollection> genToken_;
//edm::EDGetTokenT<edm::HepMCProduct> mcTruthToken_;
edm::EDGetTokenT<reco::VertexCollection> vertexToken_;
//edm::EDGetTokenT<reco::PFCandidateCollection> pfCandToken_;
edm::EDGetTokenT<double> eventrhoToken_;
edm::EDGetTokenT<reco::MuonCollection> muonToken_;
edm::EDGetTokenT<EcalRecHitCollection> reducedEBRecHitCollectionToken_;
edm::EDGetTokenT<EcalRecHitCollection> reducedEERecHitCollectionToken_;

EGammaMvaEleEstimator* myMVATrigV0;
EGammaMvaEleEstimator* myMVATrigNoIPV0;
Expand Down Expand Up @@ -181,8 +183,9 @@ ElectronTestAnalyzer::ElectronTestAnalyzer(const edm::ParameterSet& iConfig):
vertexToken_(consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"))),
//pfCandToken_(consumes<reco::PFCandidateCollection>(edm::InputTag("particleFlow"))),
eventrhoToken_(consumes<double>(edm::InputTag("kt6PFJets", "rho"))),
muonToken_(consumes<reco::MuonCollection>(edm::InputTag("muons")))

muonToken_(consumes<reco::MuonCollection>(edm::InputTag("muons"))),
reducedEBRecHitCollectionToken_(consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"))),
reducedEERecHitCollectionToken_(consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE")))
{
Bool_t manualCat = true;

Expand Down Expand Up @@ -320,12 +323,7 @@ ElectronTestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& i
Vertex::Point p(0, 0, 0);
dummy = Vertex(p, e, 0, 0, 0);
}


InputTag reducedEBRecHitCollection(string("reducedEcalRecHitsEB"));
InputTag reducedEERecHitCollection(string("reducedEcalRecHitsEE"));

EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection, reducedEERecHitCollection);
EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollectionToken_, reducedEERecHitCollectionToken_);

edm::ESHandle<TransientTrackBuilder> builder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
Expand Down Expand Up @@ -777,10 +775,7 @@ ElectronTestAnalyzer::evaluate_mvas(const edm::Event& iEvent, const edm::EventSe
IdentifiedMuons.push_back(*iM);
}

InputTag reducedEBRecHitCollection(string("reducedEcalRecHitsEB"));
InputTag reducedEERecHitCollection(string("reducedEcalRecHitsEE"));

EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection, reducedEERecHitCollection);
EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollectionToken_, reducedEERecHitCollectionToken_);

edm::ESHandle<TransientTrackBuilder> builder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
Expand Down
2 changes: 2 additions & 0 deletions HLTrigger/HLTanalyzers/interface/HLTAnalyzer.h
Expand Up @@ -185,6 +185,8 @@ class HLTAnalyzer : public edm::EDAnalyzer {
edm::EDGetTokenT<reco::RecoEcalCandidateIsolationMap> IsoPhoTrackIsolToken_;
edm::EDGetTokenT<reco::SuperClusterCollection> HFECALClustersToken_;
edm::EDGetTokenT<reco::RecoEcalCandidateCollection> HFElectronsToken_;
edm::EDGetTokenT<EcalRecHitCollection> EcalRecHitEBToken_;
edm::EDGetTokenT<EcalRecHitCollection> EcalRecHitEEToken_;

// ECAL Activity
edm::EDGetTokenT<reco::RecoEcalCandidateCollection> ECALActivityToken_;
Expand Down
6 changes: 3 additions & 3 deletions HLTrigger/HLTanalyzers/src/HLTAnalyzer.cc
Expand Up @@ -300,6 +300,8 @@ HLTAnalyzer::HLTAnalyzer(edm::ParameterSet const& conf) {
ActivityR9Token_ = consumes<reco::RecoEcalCandidateIsolationMap>(ActivityR9_);
ActivityR9IDToken_ = consumes<reco::RecoEcalCandidateIsolationMap>(ActivityR9ID_);
ActivityHoverEHToken_ = consumes<reco::RecoEcalCandidateIsolationMap>(ActivityHoverEH_);
EcalRecHitEBToken_ = consumes<EcalRecHitCollection>(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
EcalRecHitEEToken_ = consumes<EcalRecHitCollection>(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));

CandIsoToken_ = consumes<reco::RecoEcalCandidateCollection>(CandIso_);
CandNonIsoToken_ = consumes<reco::RecoEcalCandidateCollection>(CandNonIso_);
Expand Down Expand Up @@ -533,9 +535,7 @@ void HLTAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetu
edm::Handle<reco::VertexCollection> recoVertexsOffline0;

// new stuff for the egamma EleId
edm::InputTag ecalRechitEBTag (std::string("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
edm::InputTag ecalRechitEETag (std::string("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
EcalClusterLazyTools lazyTools( iEvent, iSetup, ecalRechitEBTag, ecalRechitEETag);
EcalClusterLazyTools lazyTools( iEvent, iSetup, EcalRecHitEBToken_, EcalRecHitEEToken_ );

edm::Handle<reco::HFEMClusterShapeAssociationCollection> electronHFClusterAssociation;
iEvent.getByToken(HFEMClusterShapeAssociationToken_,electronHFClusterAssociation);
Expand Down