Skip to content

Commit

Permalink
Merge pull request #35444 from sroychow/egammaelectools
Browse files Browse the repository at this point in the history
Migrate Egamma-Electools to use esConsumes
  • Loading branch information
cmsbuild authored Oct 4, 2021
2 parents c6304f6 + 633adb2 commit 3abab3e
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class CalibratedElectronProducerRun2T : public edm::stream::EDProducer<> {
private:
edm::EDGetTokenT<edm::View<T> > theElectronToken;
std::string theGBRForestName;
edm::ESHandle<GBRForest> theGBRForestHandle;

EpCombinationTool theEpCombinationTool;
ElectronEnergyCalibratorRun2 theEnCorrectorRun2;
std::unique_ptr<TRandom> theSemiDeterministicRng;

edm::ESGetToken<GBRForest, GBRWrapperRcd> gbrforestToken_;
};

template <typename T>
Expand All @@ -52,6 +53,7 @@ CalibratedElectronProducerRun2T<T>::CalibratedElectronProducerRun2T(const edm::P
theSemiDeterministicRng = std::make_unique<TRandom2>();
theEnCorrectorRun2.initPrivateRng(theSemiDeterministicRng.get());
}
gbrforestToken_ = esConsumes(edm::ESInputTag("", theGBRForestName));
produces<std::vector<T> >();
}

Expand All @@ -60,8 +62,8 @@ CalibratedElectronProducerRun2T<T>::~CalibratedElectronProducerRun2T() {}

template <typename T>
void CalibratedElectronProducerRun2T<T>::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
iSetup.get<GBRWrapperRcd>().get(theGBRForestName, theGBRForestHandle);
theEpCombinationTool.init(theGBRForestHandle.product());
const GBRForest *theGBRForest = &iSetup.getData(gbrforestToken_);
theEpCombinationTool.init(theGBRForest);

edm::Handle<edm::View<T> > in;
iEvent.getByToken(theElectronToken, in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Description: [one line class summary]

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/transform.h"
Expand All @@ -45,7 +45,7 @@ Description: [one line class summary]
// class declaration
//

class EGammaCutBasedEleIdAnalyzer : public edm::EDAnalyzer {
class EGammaCutBasedEleIdAnalyzer : public edm::one::EDAnalyzer<> {
public:
typedef std::vector<edm::Handle<edm::ValueMap<reco::IsoDeposit> > > IsoDepositMaps;
typedef std::vector<edm::Handle<edm::ValueMap<double> > > IsoDepositVals;
Expand All @@ -61,11 +61,12 @@ class EGammaCutBasedEleIdAnalyzer : public edm::EDAnalyzer {
void analyze(const edm::Event &, const edm::EventSetup &) override;
void endJob() override;

/*
void beginRun(edm::Run const &, edm::EventSetup const &) override;
void endRun(edm::Run const &, edm::EventSetup const &) override;
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override;
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override;

*/
// ----------member data ---------------------------

// input tags
Expand Down Expand Up @@ -254,7 +255,7 @@ void EGammaCutBasedEleIdAnalyzer::beginJob() {

// ------------ method called once each job just after ending the event loop ------------
void EGammaCutBasedEleIdAnalyzer::endJob() {}

/*
// ------------ method called when starting to processes a run ------------
void EGammaCutBasedEleIdAnalyzer::beginRun(edm::Run const &, edm::EventSetup const &) {}
Expand All @@ -266,7 +267,7 @@ void EGammaCutBasedEleIdAnalyzer::beginLuminosityBlock(edm::LuminosityBlock cons
// ------------ method called when ending the processing of a luminosity block ------------
void EGammaCutBasedEleIdAnalyzer::endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}

*/
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void EGammaCutBasedEleIdAnalyzer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
//The following says we do not know what parameters are allowed so do no validation
Expand Down
12 changes: 6 additions & 6 deletions EgammaAnalysis/ElectronTools/plugins/ElectronIdMVAProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand All @@ -21,7 +21,7 @@
// class declaration
//

class ElectronIdMVAProducer : public edm::EDFilter {
class ElectronIdMVAProducer : public edm::stream::EDFilter<> {
public:
explicit ElectronIdMVAProducer(const edm::ParameterSet&);
~ElectronIdMVAProducer() override;
Expand All @@ -37,6 +37,7 @@ class ElectronIdMVAProducer : public edm::EDFilter {
edm::EDGetTokenT<EcalRecHitCollection> reducedEBRecHitCollectionToken_;
edm::EDGetTokenT<EcalRecHitCollection> reducedEERecHitCollectionToken_;
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_;
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> ttrackbuilderToken_;

double _Rho;
std::string method_;
Expand Down Expand Up @@ -73,6 +74,8 @@ ElectronIdMVAProducer::ElectronIdMVAProducer(const edm::ParameterSet& iConfig)
Trig_ = iConfig.getParameter<bool>("Trig");
NoIP_ = iConfig.getParameter<bool>("NoIP");

ttrackbuilderToken_ = esConsumes(edm::ESInputTag("", "TransientTrackBuilder"));

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

mvaID_ = new EGammaMvaEleEstimator();
Expand Down Expand Up @@ -134,10 +137,7 @@ bool ElectronIdMVAProducer::filter(edm::Event& iEvent, const edm::EventSetup& iS
ecalClusterToolsESGetTokens_.get(iSetup),
reducedEBRecHitCollectionToken_,
reducedEERecHitCollectionToken_);

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

edm::Handle<reco::GsfElectronCollection> egCollection;
iEvent.getByToken(electronToken_, egCollection);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand All @@ -11,7 +11,7 @@

#include "EgammaAnalysis/ElectronTools/interface/ElectronEffectiveArea.h"

class ElectronIsolatorFromEffectiveArea : public edm::EDFilter {
class ElectronIsolatorFromEffectiveArea : public edm::stream::EDFilter<> {
public:
typedef edm::ValueMap<double> CandDoubleMap;
typedef ElectronEffectiveArea EEA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand All @@ -21,7 +21,7 @@
// class declaration
//

class ElectronPATIdMVAProducer : public edm::EDProducer {
class ElectronPATIdMVAProducer : public edm::stream::EDProducer<> {
public:
explicit ElectronPATIdMVAProducer(const edm::ParameterSet&);
~ElectronPATIdMVAProducer() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "Geometry/Records/interface/CaloTopologyRecord.h"
Expand All @@ -27,7 +27,7 @@
// class declaration
//

class ElectronRegressionEnergyProducer : public edm::EDFilter {
class ElectronRegressionEnergyProducer : public edm::stream::EDFilter<> {
public:
explicit ElectronRegressionEnergyProducer(const edm::ParameterSet&);
~ElectronRegressionEnergyProducer() override;
Expand Down Expand Up @@ -57,6 +57,9 @@ class ElectronRegressionEnergyProducer : public edm::EDFilter {

edm::EDGetTokenT<reco::VertexCollection> hVertexToken_;
edm::EDGetTokenT<double> hRhoKt6PFJetsToken_;

edm::ESGetToken<CaloTopology, CaloTopologyRecord> ecalTopoToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;
};

ElectronRegressionEnergyProducer::ElectronRegressionEnergyProducer(const edm::ParameterSet& iConfig) {
Expand All @@ -75,6 +78,9 @@ ElectronRegressionEnergyProducer::ElectronRegressionEnergyProducer(const edm::Pa
hVertexToken_ = consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
hRhoKt6PFJetsToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));

ecalTopoToken_ = esConsumes();
caloGeomToken_ = esConsumes();

produces<edm::ValueMap<double> >(nameEnergyReg_);
produces<edm::ValueMap<double> >(nameEnergyErrorReg_);

Expand Down Expand Up @@ -104,13 +110,8 @@ bool ElectronRegressionEnergyProducer::filter(edm::Event& iEvent, const edm::Eve
assert(regressionEvaluator->isInitialized());

if (!geomInitialized_) {
edm::ESHandle<CaloTopology> theCaloTopology;
iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
ecalTopology_ = &(*theCaloTopology);

edm::ESHandle<CaloGeometry> theCaloGeometry;
iSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
caloGeometry_ = &(*theCaloGeometry);
ecalTopology_ = &(iSetup.getData(ecalTopoToken_));
caloGeometry_ = &(iSetup.getData(caloGeomToken_));
geomInitialized_ = true;
}

Expand Down
13 changes: 6 additions & 7 deletions EgammaAnalysis/ElectronTools/plugins/GBRForestGetterFromDB.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#ifndef CalibratedElectronProducer_h
#define CalibratedElectronProducer_h

#include <iostream>
#include <string>

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondFormats/DataRecord/interface/GBRWrapperRcd.h"
#include "CondFormats/GBRForest/interface/GBRForest.h"
#include <TFile.h>
Expand All @@ -25,23 +23,24 @@ class GBRForestGetterFromDB : public edm::one::EDAnalyzer<> {
std::string theGBRForestName;
std::string theOutputFileName;
std::string theOutputObjectName;
edm::ESHandle<GBRForest> theGBRForestHandle;
edm::ESGetToken<GBRForest, GBRWrapperRcd> theGBRForestToken_;
};

GBRForestGetterFromDB::GBRForestGetterFromDB(const edm::ParameterSet &conf)
: theGBRForestName(conf.getParameter<std::string>("grbForestName")),
theOutputFileName(conf.getUntrackedParameter<std::string>("outputFileName")),
theOutputObjectName(conf.getUntrackedParameter<std::string>(
"outputObjectName", theGBRForestName.empty() ? "GBRForest" : theGBRForestName)) {}
"outputObjectName", theGBRForestName.empty() ? "GBRForest" : theGBRForestName)),
theGBRForestToken_(esConsumes()) {}

GBRForestGetterFromDB::~GBRForestGetterFromDB() {}

void GBRForestGetterFromDB::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
iSetup.get<GBRWrapperRcd>().get(theGBRForestName, theGBRForestHandle);
auto theGBRForestHandle = iSetup.getHandle(theGBRForestToken_);
TFile *fOut = TFile::Open(theOutputFileName.c_str(), "RECREATE");
fOut->WriteObject(theGBRForestHandle.product(), theOutputObjectName.c_str());
fOut->Close();
std::cout << "Wrote output to " << theOutputFileName << std::endl;
edm::LogPrint("GBRForestGetterFromDB") << "Wrote output to " << theOutputFileName;
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/Common/interface/ValueMap.h"

class PatElectronEAIsoCorrectionProducer : public edm::EDProducer {
class PatElectronEAIsoCorrectionProducer : public edm::stream::EDProducer<> {
public:
explicit PatElectronEAIsoCorrectionProducer(const edm::ParameterSet& iConfig);
~PatElectronEAIsoCorrectionProducer() override{};
Expand Down
23 changes: 11 additions & 12 deletions EgammaAnalysis/ElectronTools/plugins/PhotonIsoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
Expand All @@ -22,7 +22,7 @@
// class declaration
//

class PhotonIsoProducer : public edm::EDFilter {
class PhotonIsoProducer : public edm::stream::EDFilter<> {
public:
explicit PhotonIsoProducer(const edm::ParameterSet&);
~PhotonIsoProducer() override;
Expand Down Expand Up @@ -117,15 +117,14 @@ bool PhotonIsoProducer::filter(edm::Event& iEvent, const edm::EventSetup& iSetup
isolator.fGetIsolation(&*aPho, &thePfColl, myVtxRef, vertexCollection);

if (verbose_) {
std::cout << " run " << iEvent.id().run() << " lumi " << iEvent.id().luminosityBlock() << " event "
<< iEvent.id().event();
std::cout << " pt " << aPho->pt() << " eta " << aPho->eta() << " phi " << aPho->phi() << " charge "
<< aPho->charge() << " : " << std::endl;
;

std::cout << " ChargedIso " << isolator.getIsolationCharged() << std::endl;
std::cout << " PhotonIso " << isolator.getIsolationPhoton() << std::endl;
std::cout << " NeutralHadron Iso " << isolator.getIsolationNeutral() << std::endl;
edm::LogPrint("PhotonIsoProducer") << " run " << iEvent.id().run() << " lumi " << iEvent.id().luminosityBlock()
<< " event " << iEvent.id().event();
edm::LogPrint("PhotonIsoProducer") << " pt " << aPho->pt() << " eta " << aPho->eta() << " phi " << aPho->phi()
<< " charge " << aPho->charge() << " : ";

edm::LogPrint("PhotonIsoProducer") << " ChargedIso " << isolator.getIsolationCharged();
edm::LogPrint("PhotonIsoProducer") << " PhotonIso " << isolator.getIsolationPhoton();
edm::LogPrint("PhotonIsoProducer") << " NeutralHadron Iso " << isolator.getIsolationNeutral();
}

chIsoValues.push_back(isolator.getIsolationCharged());
Expand Down
Loading

0 comments on commit 3abab3e

Please sign in to comment.