From 7c596f539ceb43768dca1762f61eedc9cbaef032 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Sun, 20 Feb 2022 15:57:36 +0100 Subject: [PATCH 1/2] Clean the analyzers in SimG4CMS/CherenkovAnalysis/plugins --- .../plugins/CherenkovAnalysis.cc | 11 ++-- .../plugins/XtalDedxAnalysis.cc | 58 +++++++++---------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc b/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc index ffa54a1d458ec..1de0b0b84ef72 100644 --- a/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc +++ b/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc @@ -51,7 +51,7 @@ class CherenkovAnalysis : public edm::one::EDAnalyzer private: const double maxEnergy_; const int nBinsEnergy_; - edm::EDGetTokenT tok_calo_; + const edm::EDGetTokenT tok_calo_; TH1F *hEnergy_; TH1F *hTimeStructure_; @@ -63,11 +63,11 @@ class CherenkovAnalysis : public edm::one::EDAnalyzer //__________________________________________________________________________________________________ CherenkovAnalysis::CherenkovAnalysis(const edm::ParameterSet &iConfig) - : maxEnergy_(iConfig.getParameter("maxEnergy")), nBinsEnergy_(iConfig.getParameter("nBinsEnergy")) { + : maxEnergy_(iConfig.getParameter("maxEnergy")), + nBinsEnergy_(iConfig.getParameter("nBinsEnergy")), + tok_calo_(consumes(iConfig.getParameter("caloHitSource"))) { usesResource(TFileService::kSharedResource); - tok_calo_ = consumes(iConfig.getParameter("caloHitSource")); - // Book histograms edm::Service tfile; @@ -89,8 +89,7 @@ void CherenkovAnalysis::fillDescriptions(edm::ConfigurationDescriptions &descrip //__________________________________________________________________________________________________ void CherenkovAnalysis::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { - edm::Handle pCaloHits; - iEvent.getByToken(tok_calo_, pCaloHits); + const edm::Handle& pCaloHits = iEvent.getHandle(tok_calo_); double totalEnergy = 0; diff --git a/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc b/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc index 5da745958379d..6fa37de9fc6e6 100644 --- a/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc +++ b/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc @@ -46,32 +46,32 @@ class XtalDedxAnalysis : public edm::one::EDAnalyzer void endJob() override {} void analyzeHits(std::vector &, - edm::Handle &, - edm::Handle &); + const edm::Handle &, + const edm::Handle &); private: - edm::InputTag caloHitSource_; - std::string simTkLabel_; - - edm::EDGetTokenT tok_calo_; - edm::EDGetTokenT tok_tk_; - edm::EDGetTokenT tok_vtx_; + const edm::InputTag caloHitSource_; + const std::string simTkLabel_; + const double energyMax_; + const edm::EDGetTokenT tok_calo_; + const edm::EDGetTokenT tok_tk_; + const edm::EDGetTokenT tok_vtx_; TH1F *meNHit_[4], *meE1T0_[4], *meE9T0_[4], *meE1T1_[4], *meE9T1_[4]; TH1I *mType_; }; -XtalDedxAnalysis::XtalDedxAnalysis(const edm::ParameterSet &ps) { +XtalDedxAnalysis::XtalDedxAnalysis(const edm::ParameterSet &ps) : + caloHitSource_(ps.getParameter("caloHitSource")), + simTkLabel_(ps.getParameter("moduleLabelTk")), + energyMax_(ps.getParameter("energyMax")), + tok_calo_(consumes(caloHitSource_)), + tok_tk_(consumes(edm::InputTag(simTkLabel_))), + tok_vtx_(consumes(edm::InputTag(simTkLabel_))) { + usesResource(TFileService::kSharedResource); - caloHitSource_ = ps.getParameter("caloHitSource"); - simTkLabel_ = ps.getParameter("moduleLabelTk"); - double energyMax = ps.getParameter("energyMax"); edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Source " << caloHitSource_ << " Track Label " - << simTkLabel_ << " Energy Max " << energyMax; - // register for data access - tok_calo_ = consumes(caloHitSource_); - tok_tk_ = consumes(edm::InputTag(simTkLabel_)); - tok_vtx_ = consumes(edm::InputTag(simTkLabel_)); + << simTkLabel_ << " Energy Max " << energyMax_; // Book histograms edm::Service tfile; @@ -90,22 +90,22 @@ XtalDedxAnalysis::XtalDedxAnalysis(const edm::ParameterSet &ps) { meNHit_[i]->GetYaxis()->SetTitle("Events"); sprintf(name, "E1T0%d", i); sprintf(title, "E1 (Loss %s) in GeV", types[i].c_str()); - meE1T0_[i] = tfile->make(name, title, 5000, 0, energyMax); + meE1T0_[i] = tfile->make(name, title, 5000, 0, energyMax_); meE1T0_[i]->GetXaxis()->SetTitle(title); meE1T0_[i]->GetYaxis()->SetTitle("Events"); sprintf(name, "E9T0%d", i); sprintf(title, "E9 (Loss %s) in GeV", types[i].c_str()); - meE9T0_[i] = tfile->make(name, title, 5000, 0, energyMax); + meE9T0_[i] = tfile->make(name, title, 5000, 0, energyMax_); meE9T0_[i]->GetXaxis()->SetTitle(title); meE9T0_[i]->GetYaxis()->SetTitle("Events"); sprintf(name, "E1T1%d", i); sprintf(title, "E1 (Loss %s with t < 400 ns) in GeV", types[i].c_str()); - meE1T1_[i] = tfile->make(name, title, 5000, 0, energyMax); + meE1T1_[i] = tfile->make(name, title, 5000, 0, energyMax_); meE1T1_[i]->GetXaxis()->SetTitle(title); meE1T1_[i]->GetYaxis()->SetTitle("Events"); sprintf(name, "E9T1%d", i); sprintf(title, "E9 (Loss %s with t < 400 ns) in GeV", types[i].c_str()); - meE9T1_[i] = tfile->make(name, title, 5000, 0, energyMax); + meE9T1_[i] = tfile->make(name, title, 5000, 0, energyMax_); meE9T1_[i]->GetXaxis()->SetTitle(title); meE9T1_[i]->GetYaxis()->SetTitle("Events"); } @@ -129,16 +129,10 @@ void XtalDedxAnalysis::analyze(const edm::Event &e, const edm::EventSetup &) { edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Run = " << e.id().run() << " Event = " << e.id().event(); #endif std::vector caloHits; - edm::Handle pCaloHits; - e.getByToken(tok_calo_, pCaloHits); - - std::vector theSimTracks; - edm::Handle simTk; - e.getByToken(tok_tk_, simTk); + const edm::Handle& pCaloHits = e.getHandle(tok_calo_); - std::vector theSimVertex; - edm::Handle simVtx; - e.getByToken(tok_vtx_, simVtx); + const edm::Handle& simTk = e.getHandle(tok_tk_); + const edm::Handle& simVtx = e.getHandle(tok_vtx_); if (pCaloHits.isValid()) { caloHits.insert(caloHits.end(), pCaloHits->begin(), pCaloHits->end()); @@ -150,8 +144,8 @@ void XtalDedxAnalysis::analyze(const edm::Event &e, const edm::EventSetup &) { } void XtalDedxAnalysis::analyzeHits(std::vector &hits, - edm::Handle &SimTk, - edm::Handle &SimVtx) { + const edm::Handle &SimTk, + const edm::Handle &SimVtx) { edm::SimTrackContainer::const_iterator simTrkItr; int nHit = hits.size(); double e10[4], e90[4], e11[4], e91[4], hit[4]; From 32855603c321e8ba5f051755fc3481142f56d644 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Sun, 20 Feb 2022 16:18:21 +0100 Subject: [PATCH 2/2] Code check --- .../CherenkovAnalysis/plugins/CherenkovAnalysis.cc | 4 ++-- .../CherenkovAnalysis/plugins/XtalDedxAnalysis.cc | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc b/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc index 1de0b0b84ef72..0408473b51054 100644 --- a/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc +++ b/SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc @@ -63,7 +63,7 @@ class CherenkovAnalysis : public edm::one::EDAnalyzer //__________________________________________________________________________________________________ CherenkovAnalysis::CherenkovAnalysis(const edm::ParameterSet &iConfig) - : maxEnergy_(iConfig.getParameter("maxEnergy")), + : maxEnergy_(iConfig.getParameter("maxEnergy")), nBinsEnergy_(iConfig.getParameter("nBinsEnergy")), tok_calo_(consumes(iConfig.getParameter("caloHitSource"))) { usesResource(TFileService::kSharedResource); @@ -89,7 +89,7 @@ void CherenkovAnalysis::fillDescriptions(edm::ConfigurationDescriptions &descrip //__________________________________________________________________________________________________ void CherenkovAnalysis::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { - const edm::Handle& pCaloHits = iEvent.getHandle(tok_calo_); + const edm::Handle &pCaloHits = iEvent.getHandle(tok_calo_); double totalEnergy = 0; diff --git a/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc b/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc index 6fa37de9fc6e6..f7f955508e578 100644 --- a/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc +++ b/SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc @@ -61,14 +61,13 @@ class XtalDedxAnalysis : public edm::one::EDAnalyzer TH1I *mType_; }; -XtalDedxAnalysis::XtalDedxAnalysis(const edm::ParameterSet &ps) : - caloHitSource_(ps.getParameter("caloHitSource")), +XtalDedxAnalysis::XtalDedxAnalysis(const edm::ParameterSet &ps) + : caloHitSource_(ps.getParameter("caloHitSource")), simTkLabel_(ps.getParameter("moduleLabelTk")), energyMax_(ps.getParameter("energyMax")), tok_calo_(consumes(caloHitSource_)), tok_tk_(consumes(edm::InputTag(simTkLabel_))), tok_vtx_(consumes(edm::InputTag(simTkLabel_))) { - usesResource(TFileService::kSharedResource); edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Source " << caloHitSource_ << " Track Label " << simTkLabel_ << " Energy Max " << energyMax_; @@ -129,10 +128,10 @@ void XtalDedxAnalysis::analyze(const edm::Event &e, const edm::EventSetup &) { edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Run = " << e.id().run() << " Event = " << e.id().event(); #endif std::vector caloHits; - const edm::Handle& pCaloHits = e.getHandle(tok_calo_); + const edm::Handle &pCaloHits = e.getHandle(tok_calo_); - const edm::Handle& simTk = e.getHandle(tok_tk_); - const edm::Handle& simVtx = e.getHandle(tok_vtx_); + const edm::Handle &simTk = e.getHandle(tok_tk_); + const edm::Handle &simVtx = e.getHandle(tok_vtx_); if (pCaloHits.isValid()) { caloHits.insert(caloHits.end(), pCaloHits->begin(), pCaloHits->end());