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

Migrate classes deriving from IsoDepositExtractor to esConsumes() #34996

Merged
merged 1 commit into from Aug 25, 2021
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
Expand Up @@ -63,6 +63,7 @@ namespace egammaisolation {
double etLow_;

edm::EDGetTokenT<HBHERecHitCollection> hcalRecHitProducerToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
};
} // namespace egammaisolation

Expand All @@ -79,7 +80,8 @@ EgammaHcalExtractor::EgammaHcalExtractor(const edm::ParameterSet& par, edm::Cons
: extRadius_(par.getParameter<double>("extRadius")),
intRadius_(par.getParameter<double>("intRadius")),
etLow_(par.getParameter<double>("etMin")),
hcalRecHitProducerToken_(iC.consumes<HBHERecHitCollection>(par.getParameter<edm::InputTag>("hcalRecHits"))) {}
hcalRecHitProducerToken_(iC.consumes<HBHERecHitCollection>(par.getParameter<edm::InputTag>("hcalRecHits"))),
geometryToken_(iC.esConsumes()) {}

EgammaHcalExtractor::~EgammaHcalExtractor() {}

Expand All @@ -90,9 +92,7 @@ reco::IsoDeposit EgammaHcalExtractor::deposit(const edm::Event& iEvent,
auto const& hcalRecHits = iEvent.get(hcalRecHitProducerToken_);

//Get Calo Geometry
edm::ESHandle<CaloGeometry> pG;
iSetup.get<CaloGeometryRecord>().get(pG);
const CaloGeometry* caloGeom = pG.product();
const CaloGeometry* caloGeom = &iSetup.getData(geometryToken_);
CaloDualConeSelector<HBHERecHit> coneSel(intRadius_, extRadius_, caloGeom, DetId::Hcal);

//Take the SC position
Expand Down
Expand Up @@ -20,7 +20,6 @@
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand Down Expand Up @@ -77,6 +76,8 @@ namespace egammaisolation {
edm::InputTag endcapEcalHitsTag_;
edm::EDGetTokenT<EcalRecHitCollection> barrelEcalHitsToken_;
edm::EDGetTokenT<EcalRecHitCollection> endcapEcalHitsToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
edm::ESGetToken<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd> sevlvToken_;
bool fakeNegativeDeposit_;
bool tryBoth_;
bool useEt_;
Expand Down Expand Up @@ -113,6 +114,8 @@ EgammaRecHitExtractor::EgammaRecHitExtractor(const edm::ParameterSet& par, edm::
endcapEcalHitsTag_(par.getParameter<edm::InputTag>("endcapEcalHits")),
barrelEcalHitsToken_(iC.consumes<EcalRecHitCollection>(barrelEcalHitsTag_)),
endcapEcalHitsToken_(iC.consumes<EcalRecHitCollection>(endcapEcalHitsTag_)),
geometryToken_(iC.esConsumes()),
sevlvToken_(iC.esConsumes()),
fakeNegativeDeposit_(par.getParameter<bool>("subtractSuperClusterEnergy")),
tryBoth_(par.getParameter<bool>("tryBoth")),
vetoClustered_(par.getParameter<bool>("vetoClustered")),
Expand Down Expand Up @@ -170,18 +173,13 @@ EgammaRecHitExtractor::~EgammaRecHitExtractor() {}
reco::IsoDeposit EgammaRecHitExtractor::deposit(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const reco::Candidate& emObject) const {
edm::ESHandle<CaloGeometry> pG;
iSetup.get<CaloGeometryRecord>().get(pG);

//Get the channel status from the db
//edm::ESHandle<EcalChannelStatus> chStatus;
//iSetup.get<EcalChannelStatusRcd>().get(chStatus);

edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
const EcalSeverityLevelAlgo* sevLevel = &iSetup.getData(sevlvToken_);

const CaloGeometry* caloGeom = pG.product();
const CaloGeometry* caloGeom = &iSetup.getData(geometryToken_);
const CaloSubdetectorGeometry* barrelgeom = caloGeom->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
const CaloSubdetectorGeometry* endcapgeom = caloGeom->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);

Expand Down
1 change: 0 additions & 1 deletion RecoMuon/MuonIsolation/plugins/CaloExtractor.cc
@@ -1,7 +1,6 @@
#include "CaloExtractor.h"

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

Expand Down
24 changes: 11 additions & 13 deletions RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.cc
@@ -1,18 +1,13 @@
#include "CaloExtractorByAssociator.h"

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
#include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"

#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"

#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
Expand Down Expand Up @@ -55,6 +50,7 @@ CaloExtractorByAssociator::CaloExtractorByAssociator(const ParameterSet& par, ed
theNoiseTow_EE(par.getParameter<double>("NoiseTow_EE")),
theService(nullptr),
theAssociator(nullptr),
bFieldToken_(iC.esConsumes()),
thePrintTimeReport(par.getUntrackedParameter<bool>("PrintTimeReport")) {
ParameterSet serviceParameters = par.getParameter<ParameterSet>("ServiceParameters");
theService = new MuonServiceProxy(serviceParameters, edm::ConsumesCollector(iC));
Expand All @@ -63,6 +59,10 @@ CaloExtractorByAssociator::CaloExtractorByAssociator(const ParameterSet& par, ed
theAssociatorParameters = new TrackAssociatorParameters();
theAssociatorParameters->loadParameters(par.getParameter<edm::ParameterSet>("TrackAssociatorParameters"), iC);
theAssociator = new TrackDetectorAssociator();

if (theUseRecHitsFlag) {
caloGeomToken_ = iC.esConsumes();
}
}

CaloExtractorByAssociator::~CaloExtractorByAssociator() {
Expand Down Expand Up @@ -124,10 +124,9 @@ std::vector<IsoDeposit> CaloExtractorByAssociator::deposits(const Event& event,
IsoDeposit depHcal(muonDir);
IsoDeposit depHOcal(muonDir);

edm::ESHandle<MagneticField> bField;
eventSetup.get<IdealMagneticFieldRecord>().get(bField);
auto const& bField = eventSetup.getData(bFieldToken_);

reco::TransientTrack tMuon(muon, &*bField);
reco::TransientTrack tMuon(muon, &bField);
FreeTrajectoryState iFTS = tMuon.initialFreeState();
TrackDetMatchInfo mInfo = theAssociator->associate(event, eventSetup, iFTS, *theAssociatorParameters);

Expand Down Expand Up @@ -159,14 +158,13 @@ std::vector<IsoDeposit> CaloExtractorByAssociator::deposits(const Event& event,
if (theUseRecHitsFlag) {
//! do things based on rec-hits here
//! too much copy-pasting now (refactor later?)
edm::ESHandle<CaloGeometry> caloGeom;
eventSetup.get<CaloGeometryRecord>().get(caloGeom);
auto const& caloGeom = eventSetup.getData(caloGeomToken_);

//Ecal
std::vector<const EcalRecHit*>::const_iterator eHitCI = mInfo.ecalRecHits.begin();
for (; eHitCI != mInfo.ecalRecHits.end(); ++eHitCI) {
const EcalRecHit* eHitCPtr = *eHitCI;
GlobalPoint eHitPos = caloGeom->getPosition(eHitCPtr->detid());
GlobalPoint eHitPos = caloGeom.getPosition(eHitCPtr->detid());
double deltar0 = reco::deltaR(muon, eHitPos);
double cosTheta = 1. / cosh(eHitPos.eta());
double energy = eHitCPtr->energy();
Expand Down Expand Up @@ -207,7 +205,7 @@ std::vector<IsoDeposit> CaloExtractorByAssociator::deposits(const Event& event,
std::vector<const HBHERecHit*>::const_iterator hHitCI = mInfo.hcalRecHits.begin();
for (; hHitCI != mInfo.hcalRecHits.end(); ++hHitCI) {
const HBHERecHit* hHitCPtr = *hHitCI;
GlobalPoint hHitPos = caloGeom->getPosition(hHitCPtr->detid());
GlobalPoint hHitPos = caloGeom.getPosition(hHitCPtr->detid());
double deltar0 = reco::deltaR(muon, hHitPos);
double cosTheta = 1. / cosh(hHitPos.eta());
double energy = hHitCPtr->energy();
Expand Down Expand Up @@ -248,7 +246,7 @@ std::vector<IsoDeposit> CaloExtractorByAssociator::deposits(const Event& event,
std::vector<const HORecHit*>::const_iterator hoHitCI = mInfo.hoRecHits.begin();
for (; hoHitCI != mInfo.hoRecHits.end(); ++hoHitCI) {
const HORecHit* hoHitCPtr = *hoHitCI;
GlobalPoint hoHitPos = caloGeom->getPosition(hoHitCPtr->detid());
GlobalPoint hoHitPos = caloGeom.getPosition(hoHitCPtr->detid());
double deltar0 = reco::deltaR(muon, hoHitPos);
double cosTheta = 1. / cosh(hoHitPos.eta());
double energy = hoHitCPtr->energy();
Expand Down
8 changes: 8 additions & 0 deletions RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.h
Expand Up @@ -25,6 +25,11 @@

#include "DataFormats/GeometryVector/interface/GlobalPoint.h"

#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"

class TrackAssociatorParameters;
class TrackDetectorAssociator;
class MuonServiceProxy;
Expand Down Expand Up @@ -100,6 +105,9 @@ namespace muonisolation {
TrackAssociatorParameters* theAssociatorParameters;
TrackDetectorAssociator* theAssociator;

edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> bFieldToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;

//! flag to turn on/off printing of a time report
bool thePrintTimeReport;

Expand Down
1 change: 0 additions & 1 deletion RecoMuon/MuonIsolation/plugins/JetExtractor.cc
@@ -1,7 +1,6 @@
#include "JetExtractor.h"

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

Expand Down
2 changes: 0 additions & 2 deletions RecoMuon/MuonIsolation/plugins/PixelTrackExtractor.cc
Expand Up @@ -8,8 +8,6 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"

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

using namespace edm;
using namespace std;
using namespace reco;
Expand Down