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
16 changes: 7 additions & 9 deletions CommonTools/RecoAlgos/interface/CosmicTrackingParticleSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ 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"))),
globalTrackingGeomToken_(iC.esConsumes()),
theMFToken_(iC.esConsumes()) {}

void select(const edm::Handle<collection>& c, const edm::Event& event, const edm::EventSetup& setup) {
selected_.clear();
Expand Down Expand Up @@ -103,13 +105,7 @@ 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<MagneticField> theMF;
iSetup.get<IdealMagneticFieldRecord>().get(theMF);
edm::ESHandle<GlobalTrackingGeometry> theGeometry = iSetup.getHandle(globalTrackingGeomToken_);

GlobalVector finalGV(0, 0, 0);
GlobalPoint finalGP(0, 0, 0);
Expand Down Expand Up @@ -180,7 +176,7 @@ class CosmicTrackingParticleSelector {
if (!found)
return false;
else {
FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), theMF.product());
FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), &iSetup.getData(theMFToken_));
TSCBLBuilderNoMaterial tscblBuilder;
//as in TrackProducerAlgorithm
TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction, *bs);
Expand Down Expand Up @@ -217,6 +213,8 @@ class CosmicTrackingParticleSelector {
std::vector<int> pdgId_;
container selected_;
edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
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
Original file line number Diff line number Diff line change
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() && jetCorrector_.hasValidIndex()) {
// 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
84 changes: 31 additions & 53 deletions DQM/Physics/src/SingleTopTChannelLeptonDQM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace SingleTopTChannelLepton {
edm::ParameterSet jetExtras = cfg.getParameter<edm::ParameterSet>("jetExtras");
// jetCorrector is optional; in case it's not found
// the InputTag will remain empty
if (jetExtras.existsAs<edm::InputTag>("jetCorrector")) {
mJetCorrector = iC.consumes<reco::JetCorrector>(jetExtras.getParameter<edm::InputTag>("jetCorrector"));
if (jetExtras.existsAs<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 @@ -505,39 +505,34 @@ namespace SingleTopTChannelLepton {
return;
}

edm::Handle<reco::JetCorrector> corrector;
event.getByToken(mJetCorrector, corrector);
if (!event.getByToken(mJetCorrector, corrector))
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() && jetCorrector_.hasValidIndex()) {
// 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 Expand Up @@ -566,32 +561,15 @@ namespace SingleTopTChannelLepton {
reco::PFJet sel = dynamic_cast<const reco::PFJet&>(*jet);
if ((*jetlooseSelection_)(sel))
isLoose = true;
sel.scaleEnergy(corrector->correction(*jet));
sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
if (!(*jetSelection_)(sel))
continue;
// else if (dynamic_cast<const reco::CaloJet*>(&*jet)) {
// reco::CaloJet sel = dynamic_cast<const reco::CaloJet&>(*jet);
// sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
// if ( jetSelectCalo==nullptr)
// jetSelectCalo.reset(new StringCutObjectSelector<reco::CaloJet>(jetSelect_));
// if (!((*jetSelectCalo)(sel))) {
// continue;
// }
}
// else {
// reco::Jet sel = *jet;
// sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
// if ( jetSelectJet==nullptr)
// jetSelectJet.reset(new StringCutObjectSelector<reco::Jet>(jetSelect_));
//
// if (!((*jetSelectJet)(sel))) continue;
// }

}
// prepare jet to fill monitor histograms
reco::Jet monitorJet = *jet;

++mult; // determine jet (no Id) multiplicity
monitorJet.scaleEnergy(corrector->correction(*jet));
monitorJet.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);

if (isLoose) { //Loose Id
unsigned int idx = jet - jets->begin();
Expand Down
4 changes: 1 addition & 3 deletions DQM/Physics/src/SingleTopTChannelLeptonDQM.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ namespace SingleTopTChannelLepton {
/// electronId label
// edm::InputTag electronId_;
edm::EDGetTokenT<edm::ValueMap<float> > electronId_;
// Jet corrector
edm::EDGetTokenT<reco::JetCorrector> mJetCorrector;
/// electronId pattern we expect the following pattern:
/// 0: fails
/// 1: passes electron ID only
Expand Down Expand Up @@ -165,7 +163,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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() && jetCorrector_.hasValidIndex()) {
// 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
Original file line number Diff line number Diff line change
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
44 changes: 35 additions & 9 deletions DQM/Physics/src/TopSingleLeptonDQM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ namespace TopSingleLepton {
edm::ParameterSet jetExtras = cfg.getParameter<edm::ParameterSet>("jetExtras");
// jetCorrector is optional; in case it's not found
// the InputTag will remain empty
if (jetExtras.existsAs<edm::InputTag>("jetCorrector")) {
mJetCorrector = iC.consumes<reco::JetCorrector>(jetExtras.getParameter<edm::InputTag>("jetCorrector"));
if (jetExtras.existsAs<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 @@ -516,18 +516,44 @@ namespace TopSingleLepton {
------------------------------------------------------------
*/

const JetCorrector* corrector = nullptr;
if (!jetCorrector_.isInitialized() && jetCorrector_.hasValidIndex()) {
// check whether a jet correcto is in the event setup or not
if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
corrector = &setup.getData(jetCorrector_);
} else {
edm::LogVerbatim("TopDiLeptonOfflineDQM") << "\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";
}
}

// check availability of the btaggers
edm::Handle<reco::JetTagCollection> btagEff, btagPur, btagVtx, btagCSV;
if (includeBTag_) {
if (!event.getByToken(btagCSV_, btagCSV))
return;
}

edm::Handle<reco::JetCorrector> corrector;
event.getByToken(mJetCorrector, corrector);
if (!event.getByToken(mJetCorrector, corrector))
return;

// loop jet collection
std::vector<reco::Jet> correctedJets;
std::vector<double> JetTagValues;
Expand All @@ -545,7 +571,7 @@ namespace TopSingleLepton {
reco::PFJet sel = dynamic_cast<const reco::PFJet&>(*jet);
if ((*jetlooseSelection_)(sel))
isLoose = true;
sel.scaleEnergy(corrector->correction(*jet));
sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
if (!(*jetSelection_)(sel))
continue;
}
Expand All @@ -554,7 +580,7 @@ namespace TopSingleLepton {
reco::Jet monitorJet = *jet;

++mult; // determine jet (no Id) multiplicity
monitorJet.scaleEnergy(corrector->correction(*jet));
monitorJet.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);

if (isLoose) { //Loose Id
unsigned int idx = jet - jets->begin();
Expand Down
2 changes: 1 addition & 1 deletion DQM/Physics/src/TopSingleLeptonDQM.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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