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

[DQM] esConsumes migration for Validation package leftovers #34604

Merged
merged 14 commits into from Jul 29, 2021
17 changes: 10 additions & 7 deletions CommonTools/RecoAlgos/interface/CosmicTrackingParticleSelector.h
Expand Up @@ -70,7 +70,10 @@ class CosmicTrackingParticleSelector {
minHit_(cfg.getParameter<int>("minHit")),
chargedOnly_(cfg.getParameter<bool>("chargedOnly")),
pdgId_(cfg.getParameter<std::vector<int> >("pdgId")),
beamSpotToken_(iC.consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"))) {}
beamSpotToken_(iC.consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"))),
trackerDigiGeomToken_(iC.esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
globalTrackingGeomToken_(iC.esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>()),
theMFToken_(iC.esConsumes<MagneticField, IdealMagneticFieldRecord>()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I am not mistaken one does not need to re-declare the objects consumed in the tokens in the esConsumes call. Removing them will make the code shorter.

Copy link
Contributor

@makortel makortel Jul 23, 2021

Choose a reason for hiding this comment

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

This is correct, plain iC.esConsumes() is sufficient (as would be iC.consumes() for Event data products nowadays). They use a trick to deduce the product and record types from the token.


void select(const edm::Handle<collection>& c, const edm::Event& event, const edm::EventSetup& setup) {
selected_.clear();
Expand Down Expand Up @@ -103,13 +106,10 @@ class CosmicTrackingParticleSelector {
//if (tpr->pdgId()==pdgId_[it]) testId = true;
//}

edm::ESHandle<TrackerGeometry> tracker;
iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
edm::ESHandle<GlobalTrackingGeometry> theGeometry;
iSetup.get<GlobalTrackingGeometryRecord>().get(theGeometry);
edm::ESHandle<TrackerGeometry> tracker = iSetup.getHandle(trackerDigiGeomToken_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere in this file?

edm::ESHandle<GlobalTrackingGeometry> theGeometry = iSetup.getHandle(globalTrackingGeomToken_);

edm::ESHandle<MagneticField> theMF;
iSetup.get<IdealMagneticFieldRecord>().get(theMF);
edm::ESHandle<MagneticField> theMF = iSetup.getHandle(theMFToken_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the validity of the ESHandle is not checked perhaps one can retrieve directly the product.


GlobalVector finalGV(0, 0, 0);
GlobalPoint finalGP(0, 0, 0);
Expand Down Expand Up @@ -217,6 +217,9 @@ class CosmicTrackingParticleSelector {
std::vector<int> pdgId_;
container selected_;
edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerDigiGeomToken_;
edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> globalTrackingGeomToken_;
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> theMFToken_;

mutable edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
};
Expand Down
8 changes: 4 additions & 4 deletions DQM/Physics/interface/TopDQMHelpers.h
Expand Up @@ -269,7 +269,7 @@ class SelectionStep {
/// https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID
double eidCutValue_;
/// jet corrector as extra selection type
std::string jetCorrector_;
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
/// choice for b-tag as extra selection type
edm::EDGetTokenT<reco::JetTagCollection> btagLabel_;
/// choice of b-tag working point as extra selection type
Expand Down Expand Up @@ -301,7 +301,7 @@ SelectionStep<Object>::SelectionStep(const edm::ParameterSet& cfg, edm::Consumes
eidCutValue_ = elecId.getParameter<double>("cutValue");
}
if (cfg.exists("jetCorrector")) {
jetCorrector_ = cfg.getParameter<std::string>("jetCorrector");
jetCorrector_ = iC.esConsumes(edm::ESInputTag("", cfg.getParameter<std::string>("jetCorrector")));
}
if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
edm::ParameterSet jetBTagger = cfg.getParameter<edm::ParameterSet>("jetBTagger");
Expand Down Expand Up @@ -468,10 +468,10 @@ bool SelectionStep<Object>::select(const edm::Event& event, const edm::EventSetu

// load jet corrector if configured such
const JetCorrector* corrector = nullptr;
if (!jetCorrector_.empty()) {
if (!jetCorrector_.isInitialized()) {
// check whether a jet correcto is in the event setup or not
if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
corrector = &setup.getData(jetCorrector_);
} else {
edm::LogVerbatim("TopDQMHelpers") << "\n"
<< "---------------------------------------------------------------\n"
Expand Down
57 changes: 28 additions & 29 deletions DQM/Physics/src/SingleTopTChannelLeptonDQM.cc
Expand Up @@ -505,39 +505,38 @@ namespace SingleTopTChannelLepton {
return;
}

edm::Handle<reco::JetCorrector> corrector;
/*edm::Handle<reco::JetCorrector> corrector;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this commented out code, as it is not needed any more

event.getByToken(mJetCorrector, corrector);
if (!event.getByToken(mJetCorrector, corrector))
return;
return;*/
// load jet
// corrector if configured such
// const JetCorrector* corrector = 0;
// if (!jetCorrector_.empty()) {

// check whether a jet correcto is in the event setup or not
// if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<
// JetCorrectionsRecord>())) {
// corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
// } else {
// edm::LogVerbatim("SingleTopTChannelLeptonDQM")
// << "\n"
// << "-----------------------------------------------------------------"
// "-------------------- \n"
// << " No JetCorrectionsRecord available from EventSetup:\n"
// << " - Jets will not be corrected.\n"
// << " - If you want to change this add the following lines to your "
// "cfg file:\n"
// << "\n"
// << " ## load jet corrections\n"
// << " "
// "process.load(\"JetMETCorrections.Configuration."
// "JetCorrectionServicesAllAlgos_cff\") \n"
// << " process.prefer(\"ak5CaloL2L3\")\n"
// << "\n"
// << "-----------------------------------------------------------------"
// "-------------------- \n";
// }
//}
const JetCorrector* corrector = nullptr;
if (!jetCorrector_.isInitialized()) {
// check whether a jet correcto is in the event setup or not
if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
corrector = &setup.getData(jetCorrector_);
;
Copy link
Contributor

Choose a reason for hiding this comment

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

???

} else {
edm::LogVerbatim("SingleTopTChannelLeptonDQM")
<< "\n"
<< "-----------------------------------------------------------------"
"-------------------- \n"
<< " No JetCorrectionsRecord available from EventSetup:\n"
<< " - Jets will not be corrected.\n"
<< " - If you want to change this add the following lines to your "
"cfg file:\n"
<< "\n"
<< " ## load jet corrections\n"
<< " "
"process.load(\"JetMETCorrections.Configuration."
"JetCorrectionServicesAllAlgos_cff\") \n"
<< " process.prefer(\"ak5CaloL2L3\")\n"
<< "\n"
<< "-----------------------------------------------------------------"
"-------------------- \n";
}
}
// loop jet collection
std::vector<reco::Jet> correctedJets;
std::vector<double> JetTagValues;
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/SingleTopTChannelLeptonDQM.h
Expand Up @@ -165,7 +165,7 @@ namespace SingleTopTChannelLepton {
/// extra selection on muons
std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > muonSelect_;
/// jetCorrector
std::string jetCorrector_;
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
/// jetID as an extra selection type
edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;

Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/SingleTopTChannelLeptonDQM_miniAOD.cc
Expand Up @@ -115,7 +115,7 @@ namespace SingleTopTChannelLepton_miniAOD {
// jetCorrector is optional; in case it's not found
// the InputTag will remain empty
if (jetExtras.existsAs<std::string>("jetCorrector")) {
jetCorrector_ = jetExtras.getParameter<std::string>("jetCorrector");
jetCorrector_ = iC.esConsumes(edm::ESInputTag("", jetExtras.getParameter<std::string>("jetCorrector")));
}
// read jetID information if it exists
if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/SingleTopTChannelLeptonDQM_miniAOD.h
Expand Up @@ -117,7 +117,7 @@ namespace SingleTopTChannelLepton_miniAOD {
std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonSelect_;

/// jetCorrector
std::string jetCorrector_;
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
/// jetID as an extra selection type
edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
/// extra jetID selection on calo jets
Expand Down
6 changes: 3 additions & 3 deletions DQM/Physics/src/TopDiLeptonOfflineDQM.cc
Expand Up @@ -82,7 +82,7 @@ namespace TopDiLeptonOffline {
// jetCorrector is optional; in case it's not found
// the InputTag will remain empty
if (jetExtras.existsAs<std::string>("jetCorrector")) {
jetCorrector_ = jetExtras.getParameter<std::string>("jetCorrector");
jetCorrector_ = iC.esConsumes(edm::ESInputTag("", jetExtras.getParameter<std::string>("jetCorrector")));
}
// read jetID information if it exists
if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
Expand Down Expand Up @@ -415,10 +415,10 @@ namespace TopDiLeptonOffline {
*/

const JetCorrector* corrector = nullptr;
if (!jetCorrector_.empty()) {
if (!jetCorrector_.isInitialized()) {
// check whether a jet correcto is in the event setup or not
if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
corrector = &setup.getData(jetCorrector_);
} else {
edm::LogVerbatim("TopDiLeptonOfflineDQM") << "\n"
<< "-----------------------------------------------------------------"
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/TopDiLeptonOfflineDQM.h
Expand Up @@ -159,7 +159,7 @@ namespace TopDiLeptonOffline {
std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > muonSelect_;

/// jetCorrector
std::string jetCorrector_;
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
/// jetID as an extra selection type
edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
/// extra jetID selection on calo jets
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/TopSingleLeptonDQM.h
Expand Up @@ -155,7 +155,7 @@ namespace TopSingleLepton {
std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > muonSelect_;

/// jetCorrector
std::string jetCorrector_;
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;

/// jetID as an extra selection type
edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/TopSingleLeptonDQM_miniAOD.cc
Expand Up @@ -115,7 +115,7 @@ namespace TopSingleLepton_miniAOD {
// jetCorrector is optional; in case it's not found
// the InputTag will remain empty
if (jetExtras.existsAs<std::string>("jetCorrector")) {
jetCorrector_ = jetExtras.getParameter<std::string>("jetCorrector");
jetCorrector_ = iC.esConsumes(edm::ESInputTag("", jetExtras.getParameter<std::string>("jetCorrector")));
}
// read jetID information if it exists
if (jetExtras.existsAs<edm::ParameterSet>("jetID")) {
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/TopSingleLeptonDQM_miniAOD.h
Expand Up @@ -117,7 +117,7 @@ namespace TopSingleLepton_miniAOD {
std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonSelect_;

/// jetCorrector
std::string jetCorrector_;
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
/// jetID as an extra selection type
edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
/// extra jetID selection on calo jets
Expand Down
3 changes: 3 additions & 0 deletions SimTracker/TrackHistory/interface/TrackClassifier.h
Expand Up @@ -69,16 +69,19 @@ class TrackClassifier : public TrackCategories {
const G4toCMSLegacyProcTypeMap g4toCMSProcMap_;

edm::ESHandle<MagneticField> magneticField_;
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;

edm::Handle<edm::HepMCProduct> mcInformation_;

edm::ESHandle<ParticleDataTable> particleDataTable_;

edm::ESHandle<TransientTrackBuilder> transientTrackBuilder_;
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> transientTrackBuilderToken_;

edm::Handle<reco::BeamSpot> beamSpot_;

const TrackerTopology *tTopo_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoHandToken_;

//! Classify all the tracks by their association and reconstruction
//! information
Expand Down
12 changes: 7 additions & 5 deletions SimTracker/TrackHistory/src/TrackClassifier.cc
Expand Up @@ -17,7 +17,10 @@ TrackClassifier::TrackClassifier(edm::ParameterSet const &config, edm::ConsumesC
hepMCLabel_(config.getUntrackedParameter<edm::InputTag>("hepMC")),
beamSpotLabel_(config.getUntrackedParameter<edm::InputTag>("beamSpot")),
tracer_(config, std::move(collector)),
quality_(config, collector) {
quality_(config, collector),
magneticFieldToken_(collector.esConsumes<MagneticField, IdealMagneticFieldRecord>()),
transientTrackBuilderToken_(collector.esConsumes<TransientTrackBuilder, TransientTrackRecord>()),
tTopoHandToken_(collector.esConsumes<TrackerTopology, TrackerTopologyRcd>()) {
collector.consumes<edm::HepMCProduct>(hepMCLabel_);
collector.consumes<reco::BeamSpot>(beamSpotLabel_);

Expand Down Expand Up @@ -52,7 +55,7 @@ void TrackClassifier::newEvent(edm::Event const &event, edm::EventSetup const &s
event.getByLabel(hepMCLabel_, mcInformation_);

// Magnetic field
setup.get<IdealMagneticFieldRecord>().get(magneticField_);
magneticField_ = setup.getHandle(magneticFieldToken_);

// Get the partivle data table
setup.getData(particleDataTable_);
Expand All @@ -61,14 +64,13 @@ void TrackClassifier::newEvent(edm::Event const &event, edm::EventSetup const &s
event.getByLabel(beamSpotLabel_, beamSpot_);

// Transient track builder
setup.get<TransientTrackRecord>().get("TransientTrackBuilder", transientTrackBuilder_);
transientTrackBuilder_ = setup.getHandle(transientTrackBuilderToken_);

// Create the list of primary vertices associated to the event
genPrimaryVertices();

// Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoHand;
setup.get<TrackerTopologyRcd>().get(tTopoHand);
edm::ESHandle<TrackerTopology> tTopoHand = setup.getHandle(tTopoHandToken_);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about getting the product directly without passing for the ESHandle?

tTopo_ = tTopoHand.product();
}

Expand Down