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

Fixed CMS deprecation warnings in CommonTools/ParticleFlow #37746

Merged
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
4 changes: 1 addition & 3 deletions CommonTools/ParticleFlow/interface/PFMETAlgo.h
Expand Up @@ -31,9 +31,7 @@ namespace pf2pat {
public:
explicit PFMETAlgo(const edm::ParameterSet&);

~PFMETAlgo();

reco::MET produce(const reco::PFCandidateCollection& pfCandidates);
reco::MET produce(const reco::PFCandidateCollection& pfCandidates) const;

private:
/// HF calibration factor (in 31X applied by PFProducer)
Expand Down
31 changes: 11 additions & 20 deletions CommonTools/ParticleFlow/plugins/DeltaBetaWeights.cc
Expand Up @@ -9,20 +9,19 @@
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <memory>

class DeltaBetaWeights : public edm::EDProducer {
class DeltaBetaWeights : public edm::global::EDProducer<> {
public:
explicit DeltaBetaWeights(const edm::ParameterSet&);
~DeltaBetaWeights() override;

private:
void produce(edm::Event&, const edm::EventSetup&) override;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
// ----------member data ---------------------------
edm::InputTag src_;
edm::InputTag pfCharged_;
Expand All @@ -48,32 +47,24 @@ DeltaBetaWeights::DeltaBetaWeights(const edm::ParameterSet& iConfig)
// src_token = consumes<reco::PFCandidateCollection>(src_);
}

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

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(DeltaBetaWeights);

// ------------ method called to produce the data ------------
void DeltaBetaWeights::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
void DeltaBetaWeights::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
using namespace edm;

edm::Handle<edm::View<reco::Candidate> > pfCharged;
edm::Handle<edm::View<reco::Candidate> > pfPU;
edm::Handle<edm::View<reco::Candidate> > src;

iEvent.getByToken(src_token, src);
iEvent.getByToken(pfCharged_token, pfCharged);
iEvent.getByToken(pfPU_token, pfPU);
edm::View<reco::Candidate> const pfCharged = iEvent.get(pfCharged_token);
edm::View<reco::Candidate> const& pfPU = iEvent.get(pfPU_token);
edm::View<reco::Candidate> const& src = iEvent.get(src_token);

double sumNPU = .0;
double sumPU = .0;

std::unique_ptr<reco::PFCandidateCollection> out(new reco::PFCandidateCollection);

for (const reco::Candidate& cand : *src) {
out->reserve(src.size());
for (const reco::Candidate& cand : src) {
if (cand.charge() != 0) {
// this part of code should be executed only if input collection is not entirely composed of neutral candidates, i.e. never by default
edm::LogWarning("DeltaBetaWeights")
Expand All @@ -87,14 +78,14 @@ void DeltaBetaWeights::produce(edm::Event& iEvent, const edm::EventSetup& iSetup
sumPU = 1.0;
double eta = cand.eta();
double phi = cand.phi();
for (const reco::Candidate& chCand : *pfCharged) {
for (const reco::Candidate& chCand : pfCharged) {
double sum = (chCand.pt() * chCand.pt()) / (deltaR2(eta, phi, chCand.eta(), chCand.phi()));
if (sum > 1.0)
sumNPU *= sum;
}
sumNPU = 0.5 * log(sumNPU);

for (const reco::Candidate& puCand : *pfPU) {
for (const reco::Candidate& puCand : pfPU) {
double sum = (puCand.pt() * puCand.pt()) / (deltaR2(eta, phi, puCand.eta(), puCand.phi()));
if (sum > 1.0)
sumPU *= sum;
Expand Down
41 changes: 21 additions & 20 deletions CommonTools/ParticleFlow/plugins/PFCandidateRecalibrator.cc
Expand Up @@ -64,6 +64,12 @@ class PFCandidateRecalibrator : public edm::stream::EDProducer<> {

edm::EDGetTokenT<reco::PFCandidateCollection> pfcandidates_;

const edm::ESGetToken<HcalDbService, HcalDbRecord> gtCondToken_;
const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> htopoToken_;
const edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> buggedCondToken_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> calogeomTokenRun_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> calogeomTokenEvent_;

std::vector<HEChannel> badChHE_;
std::vector<HFChannel> badChHF_;

Expand All @@ -73,6 +79,11 @@ class PFCandidateRecalibrator : public edm::stream::EDProducer<> {

PFCandidateRecalibrator::PFCandidateRecalibrator(const edm::ParameterSet& iConfig)
: pfcandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfcandidates"))),
gtCondToken_(esConsumes<edm::Transition::BeginRun>()),
htopoToken_(esConsumes<edm::Transition::BeginRun>()),
buggedCondToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "bugged"))),
calogeomTokenRun_(esConsumes<edm::Transition::BeginRun>()),
calogeomTokenEvent_(esConsumes()),
shortFibreThr_(iConfig.getParameter<double>("shortFibreThr")),
longFibreThr_(iConfig.getParameter<double>("longFibreThr")) {
produces<reco::PFCandidateCollection>();
Expand All @@ -83,25 +94,17 @@ PFCandidateRecalibrator::PFCandidateRecalibrator(const edm::ParameterSet& iConfi
void PFCandidateRecalibrator::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
if (hcalDbWatcher_.check(iSetup) || hcalRCWatcher_.check(iSetup)) {
//Get Calib Constants from current GT
edm::ESHandle<HcalDbService> gtCond;
iSetup.get<HcalDbRecord>().get(gtCond);
HcalDbService const& gtCond = iSetup.getData(gtCondToken_);

//Get Calib Constants from bugged tag
edm::ESHandle<HcalTopology> htopo;
iSetup.get<HcalRecNumberingRecord>().get(htopo);
const HcalTopology* theHBHETopology = htopo.product();
const HcalTopology& theHBHETopology = iSetup.getData(htopoToken_);

edm::ESHandle<HcalRespCorrs> buggedCond;
iSetup.get<HcalRespCorrsRcd>().get("bugged", buggedCond);
HcalRespCorrs buggedRespCorrs(*buggedCond.product());
buggedRespCorrs.setTopo(theHBHETopology);
HcalRespCorrs buggedRespCorrs = iSetup.getData(buggedCondToken_);
buggedRespCorrs.setTopo(&theHBHETopology);

//access calogeometry
edm::ESHandle<CaloGeometry> calogeom;
iSetup.get<CaloGeometryRecord>().get(calogeom);
const CaloGeometry* cgeo = calogeom.product();
const HcalGeometry* hgeom =
static_cast<const HcalGeometry*>(cgeo->getSubdetectorGeometry(DetId::Hcal, HcalForward));
const CaloGeometry& cgeo = iSetup.getData(calogeomTokenRun_);
const HcalGeometry* hgeom = static_cast<const HcalGeometry*>(cgeo.getSubdetectorGeometry(DetId::Hcal, HcalForward));

//reset the bad channel containers
badChHE_.clear();
Expand All @@ -110,7 +113,7 @@ void PFCandidateRecalibrator::beginRun(const edm::Run& iRun, const edm::EventSet
//fill bad cells HE (use eta, phi)
const std::vector<DetId>& cellsHE = hgeom->getValidDetIds(DetId::Detector::Hcal, HcalEndcap);
for (auto id : cellsHE) {
float currentRespCorr = gtCond->getHcalRespCorr(id)->getValue();
float currentRespCorr = gtCond.getHcalRespCorr(id)->getValue();
float buggedRespCorr = buggedRespCorrs.getValues(id)->getValue();
if (buggedRespCorr == 0.)
continue;
Expand All @@ -125,7 +128,7 @@ void PFCandidateRecalibrator::beginRun(const edm::Run& iRun, const edm::EventSet
//fill bad cells HF (use ieta, iphi)
auto const& cellsHF = hgeom->getValidDetIds(DetId::Detector::Hcal, HcalForward);
for (auto id : cellsHF) {
float currentRespCorr = gtCond->getHcalRespCorr(id)->getValue();
float currentRespCorr = gtCond.getHcalRespCorr(id)->getValue();
float buggedRespCorr = buggedRespCorrs.getValues(id)->getValue();
if (buggedRespCorr == 0.)
continue;
Expand All @@ -143,10 +146,8 @@ void PFCandidateRecalibrator::endRun(const edm::Run& iRun, const edm::EventSetup

void PFCandidateRecalibrator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
//access calogeometry
edm::ESHandle<CaloGeometry> calogeom;
iSetup.get<CaloGeometryRecord>().get(calogeom);
const CaloGeometry* cgeo = calogeom.product();
const HcalGeometry* hgeom = static_cast<const HcalGeometry*>(cgeo->getSubdetectorGeometry(DetId::Hcal, HcalForward));
const CaloGeometry& cgeo = iSetup.getData(calogeomTokenEvent_);
const HcalGeometry* hgeom = static_cast<const HcalGeometry*>(cgeo.getSubdetectorGeometry(DetId::Hcal, HcalForward));

//access PFCandidates
edm::Handle<reco::PFCandidateCollection> pfcandidates;
Expand Down
38 changes: 11 additions & 27 deletions CommonTools/ParticleFlow/plugins/PFMET.cc
Expand Up @@ -12,31 +12,25 @@
#include "DataFormats/METReco/interface/METFwd.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"

#include <memory>
#include <string>

class PFMET : public edm::EDProducer {
class PFMET : public edm::global::EDProducer<> {
public:
explicit PFMET(const edm::ParameterSet&);

~PFMET() override;

void produce(edm::Event&, const edm::EventSetup&) override;

void beginJob() override;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

private:
/// Input PFCandidates
edm::InputTag inputTagPFCandidates_;
edm::EDGetTokenT<reco::PFCandidateCollection> tokenPFCandidates_;
edm::EDPutTokenT<reco::METCollection> putToken_;

pf2pat::PFMETAlgo pfMETAlgo_;
};
Expand All @@ -47,33 +41,23 @@ using namespace reco;
using namespace math;

PFMET::PFMET(const edm::ParameterSet& iConfig) : pfMETAlgo_(iConfig) {
inputTagPFCandidates_ = iConfig.getParameter<InputTag>("PFCandidates");
tokenPFCandidates_ = consumes<PFCandidateCollection>(inputTagPFCandidates_);
auto inputTagPFCandidates = iConfig.getParameter<InputTag>("PFCandidates");
tokenPFCandidates_ = consumes<PFCandidateCollection>(inputTagPFCandidates);

produces<METCollection>();
putToken_ = produces<METCollection>();

LogDebug("PFMET") << " input collection : " << inputTagPFCandidates_;
LogDebug("PFMET") << " input collection : " << inputTagPFCandidates;
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(PFMET);

PFMET::~PFMET() {}

void PFMET::beginJob() {}

void PFMET::produce(Event& iEvent, const EventSetup& iSetup) {
void PFMET::produce(edm::StreamID, Event& iEvent, const EventSetup& iSetup) const {
LogDebug("PFMET") << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;

// get PFCandidates

Handle<PFCandidateCollection> pfCandidates;
iEvent.getByToken(tokenPFCandidates_, pfCandidates);

unique_ptr<METCollection> pOutput(new METCollection());

pOutput->push_back(pfMETAlgo_.produce(*pfCandidates));
iEvent.put(std::move(pOutput));
METCollection output{1, pfMETAlgo_.produce(iEvent.get(tokenPFCandidates_))};
iEvent.emplace(putToken_, std::move(output));

LogDebug("PFMET") << "STOP event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
}
4 changes: 1 addition & 3 deletions CommonTools/ParticleFlow/src/PFMETAlgo.cc
Expand Up @@ -20,9 +20,7 @@ PFMETAlgo::PFMETAlgo(const edm::ParameterSet& iConfig) {
hfCalibFactor_ = iConfig.getParameter<double>("hfCalibFactor");
}

PFMETAlgo::~PFMETAlgo() {}

reco::MET PFMETAlgo::produce(const reco::PFCandidateCollection& pfCandidates) {
reco::MET PFMETAlgo::produce(const reco::PFCandidateCollection& pfCandidates) const {
double sumEx = 0;
double sumEy = 0;
double sumEt = 0;
Expand Down
1 change: 1 addition & 0 deletions CommonTools/ParticleFlow/test/PFIsoReaderDemo.cc
Expand Up @@ -13,6 +13,7 @@
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"

PFIsoReaderDemo::PFIsoReaderDemo(const edm::ParameterSet& iConfig) {
usesResource(TFileService::kSharedResource);
inputTagGsfElectrons_ = iConfig.getParameter<edm::InputTag>("Electrons");
tokenGsfElectrons_ = consumes<reco::GsfElectronCollection>(inputTagGsfElectrons_);
inputTagPhotons_ = iConfig.getParameter<edm::InputTag>("Photons");
Expand Down
11 changes: 6 additions & 5 deletions CommonTools/ParticleFlow/test/PFIsoReaderDemo.h
@@ -1,6 +1,6 @@
#ifndef PFISOREADERDEMO_H
#define PFISOREADERDEMO_H
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
Expand All @@ -13,12 +13,13 @@

#include "TH2F.h"

class PFIsoReaderDemo : public edm::EDAnalyzer {
class PFIsoReaderDemo : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
public:
explicit PFIsoReaderDemo(const edm::ParameterSet&);
~PFIsoReaderDemo();
virtual void beginRun(edm::Run const&, edm::EventSetup const&);
virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& c);
~PFIsoReaderDemo() override;
void beginRun(edm::Run const&, edm::EventSetup const&) override;
void analyze(const edm::Event& iEvent, const edm::EventSetup& c) override;
void endRun(edm::Run const&, edm::EventSetup const&) override {}

typedef std::vector<edm::Handle<edm::ValueMap<reco::IsoDeposit> > > IsoDepositMaps;
typedef std::vector<edm::Handle<edm::ValueMap<double> > > IsoDepositVals;
Expand Down