Skip to content

Commit

Permalink
Merge pull request #33540 from bsunanda/Run4-hgx282X
Browse files Browse the repository at this point in the history
Run4-hgx282X Introduce ESGetToken in all classes in Validation/HGCalValidation/test
  • Loading branch information
cmsbuild authored Apr 28, 2021
2 parents 07bfb56 + cb9283c commit c575859
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
11 changes: 5 additions & 6 deletions Validation/HGCalValidation/test/FTSimHitTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class FTSimHitTest : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::

private:
edm::Service<TFileService> fs_;
std::string g4Label_, barrelHit_, endcapHit_;
edm::EDGetTokenT<edm::PSimHitContainer> tok_hitBarrel_, tok_hitEndcap_;
const std::string g4Label_, barrelHit_, endcapHit_;
const edm::ESGetToken<FastTimeDDDConstants, IdealGeometryRecord> tok_ftg_;
const FastTimeDDDConstants* ftcons_;
edm::EDGetTokenT<edm::PSimHitContainer> tok_hitBarrel_, tok_hitEndcap_;
TH1D *hsimE_[2], *hsimT_[2], *hcell_[2];
TH2D *hsimP_[2], *hsimM_[2];
};
Expand All @@ -58,6 +59,7 @@ FTSimHitTest::FTSimHitTest(const edm::ParameterSet& ps)
: g4Label_(ps.getUntrackedParameter<std::string>("ModuleLabel", "g4SimHits")),
barrelHit_(ps.getUntrackedParameter<std::string>("HitCollection", "FastTimerHitsBarrel")),
endcapHit_(ps.getUntrackedParameter<std::string>("HitCollection", "FastTimerHitsEndcap")),
tok_ftg_(esConsumes<FastTimeDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{})),
ftcons_(nullptr) {
usesResource(TFileService::kSharedResource);

Expand All @@ -76,10 +78,7 @@ void FTSimHitTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions
}

void FTSimHitTest::beginRun(edm::Run const&, edm::EventSetup const& es) {
edm::ESHandle<FastTimeDDDConstants> fdc;
es.get<IdealGeometryRecord>().get(fdc);
if (fdc.isValid())
ftcons_ = &(*fdc);
ftcons_ = &es.getData(tok_ftg_);

//Histograms for Sim Hits
std::string detector[2] = {"Barrel", "Endcap"};
Expand Down
37 changes: 27 additions & 10 deletions Validation/HGCalValidation/test/HGCHitValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class HGCHitValidation : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::o
edm::EDGetTokenT<HGChefRecHitCollection> fhRecHitToken_;
edm::EDGetTokenT<HGChebRecHitCollection> bhRecHitTokeng_;
edm::EDGetTokenT<HBHERecHitCollection> bhRecHitTokenh_;
edm::ESGetToken<HcalDDDSimConstants, HcalSimNumberingRecord> tok_hcals_;
edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_hcalr_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_caloG_;
std::vector<edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord>> tok_hgcal_;
std::vector<edm::ESGetToken<HGCalGeometry, IdealGeometryRecord>> tok_hgcalg_;

TTree *hgcHits_;
std::vector<float> *heeRecX_, *heeRecY_, *heeRecZ_, *heeRecEnergy_;
Expand Down Expand Up @@ -160,6 +165,23 @@ HGCHitValidation::HGCHitValidation(const edm::ParameterSet &cfg)
bhRecHitTokenh_ = consumes<HBHERecHitCollection>(bhRecHitSource);
else
bhRecHitTokeng_ = consumes<HGChebRecHitCollection>(bhRecHitSource);
tok_hcals_ = esConsumes<HcalDDDSimConstants, HcalSimNumberingRecord, edm::Transition::BeginRun>(edm::ESInputTag{});
tok_hcalr_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord, edm::Transition::BeginRun>(edm::ESInputTag{});
tok_caloG_ = esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{});
for (size_t i = 0; i < geometrySource_.size(); i++) {
if (geometrySource_[i].find("Hcal") != std::string::npos) {
tok_hgcal_.emplace_back(
esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{}));
tok_hgcalg_.emplace_back(
esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{}));
} else {
tok_hgcal_.emplace_back(esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
edm::ESInputTag{"", geometrySource_[i]}));
tok_hgcalg_.emplace_back(esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(
edm::ESInputTag{"", geometrySource_[i]}));
}
}

makeTree_ = cfg.getUntrackedParameter<bool>("makeTree", true);
hgcHits_ = nullptr;
heeRecX_ = heeRecY_ = heeRecZ_ = heeRecEnergy_ = nullptr;
Expand Down Expand Up @@ -286,23 +308,20 @@ void HGCHitValidation::beginRun(edm::Run const &iRun, edm::EventSetup const &iSe
edm::LogVerbatim("HGCalValid") << "Tries to initialize HcalGeometry "
<< " and HcalDDDSimConstants for " << i;
ifHcalG_ = true;
edm::ESHandle<HcalDDDSimConstants> pHSNDC;
iSetup.get<HcalSimNumberingRecord>().get(pHSNDC);
edm::ESHandle<HcalDDDSimConstants> pHSNDC = iSetup.getHandle(tok_hcals_);
if (pHSNDC.isValid()) {
hcCons_ = pHSNDC.product();
hgcCons_.push_back(nullptr);
} else {
edm::LogWarning("HGCalValid") << "Cannot initiate HcalDDDSimConstants: " << geometrySource_[i] << std::endl;
}
edm::ESHandle<HcalDDDRecConstants> pHRNDC;
iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
edm::ESHandle<HcalDDDRecConstants> pHRNDC = iSetup.getHandle(tok_hcalr_);
if (pHRNDC.isValid()) {
hcConr_ = pHRNDC.product();
} else {
edm::LogWarning("HGCalValid") << "Cannot initiate HcalDDDRecConstants: " << geometrySource_[i] << std::endl;
}
edm::ESHandle<CaloGeometry> caloG;
iSetup.get<CaloGeometryRecord>().get(caloG);
edm::ESHandle<CaloGeometry> caloG = iSetup.getHandle(tok_caloG_);
if (caloG.isValid()) {
const CaloGeometry *geo = caloG.product();
hcGeometry_ = geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
Expand All @@ -313,15 +332,13 @@ void HGCHitValidation::beginRun(edm::Run const &iRun, edm::EventSetup const &iSe
} else {
edm::LogVerbatim("HGCalValid") << "Tries to initialize HGCalGeometry "
<< " and HGCalDDDConstants for " << i;
edm::ESHandle<HGCalDDDConstants> hgcCons;
iSetup.get<IdealGeometryRecord>().get(geometrySource_[i], hgcCons);
edm::ESHandle<HGCalDDDConstants> hgcCons = iSetup.getHandle(tok_hgcal_[i]);
if (hgcCons.isValid()) {
hgcCons_.push_back(hgcCons.product());
} else {
edm::LogWarning("HGCalValid") << "Cannot initiate HGCalDDDConstants for " << geometrySource_[i] << std::endl;
}
edm::ESHandle<HGCalGeometry> hgcGeom;
iSetup.get<IdealGeometryRecord>().get(geometrySource_[i], hgcGeom);
edm::ESHandle<HGCalGeometry> hgcGeom = iSetup.getHandle(tok_hgcalg_[i]);
if (hgcGeom.isValid()) {
hgcGeometry_.push_back(hgcGeom.product());
} else {
Expand Down
7 changes: 4 additions & 3 deletions Validation/HGCalValidation/test/HGCalSiliconValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class HGCalSiliconValidation : public edm::one::EDAnalyzer<edm::one::WatchRuns,
const std::string g4Label_, nameDetector_, hgcalHits_;
const edm::InputTag hgcalDigis_;
const int iSample_;
const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> tok_hgcalgeom_;
edm::EDGetTokenT<edm::PCaloHitContainer> tok_hits_;
edm::EDGetToken tok_digi_;

Expand All @@ -64,7 +65,8 @@ HGCalSiliconValidation::HGCalSiliconValidation(const edm::ParameterSet& ps)
nameDetector_(ps.getUntrackedParameter<std::string>("detectorName", "HGCalEESensitive")),
hgcalHits_((ps.getUntrackedParameter<std::string>("HitCollection", "HGCHitsEE"))),
hgcalDigis_(ps.getUntrackedParameter<edm::InputTag>("DigiCollection")),
iSample_(ps.getUntrackedParameter<int>("Sample", 5)) {
iSample_(ps.getUntrackedParameter<int>("Sample", 5)),
tok_hgcalgeom_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameDetector_})) {
usesResource(TFileService::kSharedResource);

tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hgcalHits_));
Expand Down Expand Up @@ -105,8 +107,7 @@ void HGCalSiliconValidation::analyze(const edm::Event& e, const edm::EventSetup&
edm::LogVerbatim("HGCalValidation") << "HGCalSiliconValidation:Run = " << e.id().run()
<< " Event = " << e.id().event();

edm::ESHandle<HGCalGeometry> geom;
iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
edm::ESHandle<HGCalGeometry> geom = iSetup.getHandle(tok_hgcalgeom_);
if (!geom.isValid()) {
edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
} else {
Expand Down
4 changes: 1 addition & 3 deletions Validation/HGCalValidation/test/HGCalWaferHitCheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDAnalyzer.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 @@ -197,8 +196,7 @@ void HGCalWaferHitCheck::analyzeHits(std::string const& name, T const& hits) {

// ------------ method called when starting to processes a run ------------
void HGCalWaferHitCheck::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
edm::ESHandle<HGCalDDDConstants> pHGDC = iSetup.getHandle(geomToken_);
hgcons_ = &(*pHGDC);
hgcons_ = &iSetup.getData(geomToken_);
if (verbosity_ > 0)
edm::LogVerbatim("HGCalValidation") << nameDetector_ << " defined with " << hgcons_->layers(false)
<< " Layers with " << (hgcons_->firstLayer() - 1) << " in front";
Expand Down
1 change: 0 additions & 1 deletion Validation/HGCalValidation/test/HGCalWaferStudy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.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

0 comments on commit c575859

Please sign in to comment.