Skip to content

Commit

Permalink
Merge pull request #37183 from bsunanda/Run3-hcx331
Browse files Browse the repository at this point in the history
Run3-hcx331 Cleanup some of the codes in Validation/HcalRecHits
  • Loading branch information
cmsbuild committed Mar 10, 2022
2 parents 291fef2 + ba7cfa2 commit 90abdab
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 99 deletions.
39 changes: 20 additions & 19 deletions Validation/HcalRecHits/interface/HcalRecHitsValidation.h
Expand Up @@ -57,7 +57,7 @@
class HcalRecHitsValidation : public DQMEDAnalyzer {
public:
HcalRecHitsValidation(edm::ParameterSet const &conf);
~HcalRecHitsValidation() override;
~HcalRecHitsValidation() override = default;
void analyze(edm::Event const &ev, edm::EventSetup const &c) override;

void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
Expand All @@ -68,26 +68,27 @@ class HcalRecHitsValidation : public DQMEDAnalyzer {
double phi12(double phi1, double en1, double phi2, double en2);
double dPhiWsign(double phi1, double phi2);

std::string topFolderName_;

std::string outputFile_;
std::string hcalselector_;
std::string ecalselector_;
std::string sign_;
std::string mc_;
bool testNumber_;
const std::string topFolderName_;
const std::string outputFile_;
const std::string hcalselector_;
const std::string ecalselector_;
const std::string sign_;
const std::string mc_;
const bool testNumber_;

// RecHit Collection input tags
edm::EDGetTokenT<edm::HepMCProduct> tok_evt_;
edm::EDGetTokenT<EBRecHitCollection> tok_EB_;
edm::EDGetTokenT<EERecHitCollection> tok_EE_;
edm::EDGetTokenT<edm::PCaloHitContainer> tok_hh_;
edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
edm::EDGetTokenT<HORecHitCollection> tok_ho_;

edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_HRNDC_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_Geom_;
const edm::InputTag EBRecHitCollectionLabel_;
const edm::InputTag EERecHitCollectionLabel_;
const edm::EDGetTokenT<edm::HepMCProduct> tok_evt_;
const edm::EDGetTokenT<EBRecHitCollection> tok_EB_;
const edm::EDGetTokenT<EERecHitCollection> tok_EE_;
const edm::EDGetTokenT<edm::PCaloHitContainer> tok_hh_;
const edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
const edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
const edm::EDGetTokenT<HORecHitCollection> tok_ho_;

const edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_HRNDC_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_Geom_;

// choice of subdetector in config : noise/HB/HE/HO/HF/ALL (0/1/2/3/4/5)
int subdet_;
Expand Down
17 changes: 8 additions & 9 deletions Validation/HcalRecHits/interface/NoiseRates.h
Expand Up @@ -41,25 +41,24 @@
class NoiseRates : public DQMEDAnalyzer {
public:
explicit NoiseRates(const edm::ParameterSet &);
~NoiseRates() override;
~NoiseRates() override = default;

void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;

private:
void analyze(const edm::Event &, const edm::EventSetup &) override;

std::string outputFile_;
const std::string outputFile_;

// parameters
edm::InputTag rbxCollName_; // label for the rbx collection
edm::EDGetTokenT<reco::HcalNoiseRBXCollection> tok_rbx_;
double minRBXEnergy_; // RBX energy threshold
double minHitEnergy_; // RecHit energy threshold

bool useAllHistos_;
const edm::InputTag rbxCollName_; // label for the rbx collection
const double minRBXEnergy_; // RBX energy threshold
const double minHitEnergy_; // RecHit energy threshold
const bool useAllHistos_;

const edm::EDGetTokenT<reco::HcalNoiseRBXCollection> tok_rbx_;
// Hcal Noise Summary Parameters
edm::EDGetTokenT<HcalNoiseSummary> noisetoken_;
const edm::EDGetTokenT<HcalNoiseSummary> noisetoken_;

MonitorElement *hLumiBlockCount_;
MonitorElement *hRBXEnergy_;
Expand Down
69 changes: 31 additions & 38 deletions Validation/HcalRecHits/src/HcalRecHitsValidation.cc
Expand Up @@ -4,10 +4,25 @@
#include "Validation/HcalRecHits/interface/HcalRecHitsValidation.h"

HcalRecHitsValidation::HcalRecHitsValidation(edm::ParameterSet const &conf)
: topFolderName_(conf.getParameter<std::string>("TopFolderName")) {
: topFolderName_(conf.getParameter<std::string>("TopFolderName")),
outputFile_(conf.getUntrackedParameter<std::string>("outputFile", "myfile.root")),
hcalselector_(conf.getUntrackedParameter<std::string>("hcalselector", "all")),
ecalselector_(conf.getUntrackedParameter<std::string>("ecalselector", "yes")),
sign_(conf.getUntrackedParameter<std::string>("sign", "*")),
mc_(conf.getUntrackedParameter<std::string>("mc", "yes")),
testNumber_(conf.getParameter<bool>("TestNumber")),
EBRecHitCollectionLabel_(conf.getParameter<edm::InputTag>("EBRecHitCollectionLabel")),
EERecHitCollectionLabel_(conf.getParameter<edm::InputTag>("EERecHitCollectionLabel")),
tok_evt_(consumes<edm::HepMCProduct>(edm::InputTag("generatorSmeared"))),
tok_EB_(consumes<EBRecHitCollection>(EBRecHitCollectionLabel_)),
tok_EE_(consumes<EERecHitCollection>(EERecHitCollectionLabel_)),
tok_hh_(consumes<edm::PCaloHitContainer>(conf.getUntrackedParameter<edm::InputTag>("SimHitCollectionLabel"))),
tok_hbhe_(consumes<HBHERecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("HBHERecHitCollectionLabel"))),
tok_hf_(consumes<HFRecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("HFRecHitCollectionLabel"))),
tok_ho_(consumes<HORecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("HORecHitCollectionLabel"))),
tok_HRNDC_(esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>()),
tok_Geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()) {
// DQM ROOT output
outputFile_ = conf.getUntrackedParameter<std::string>("outputFile", "myfile.root");

if (!outputFile_.empty()) {
edm::LogInfo("OutputInfo") << " Hcal RecHit Task histograms will be saved to '" << outputFile_.c_str() << "'";
} else {
Expand All @@ -16,28 +31,9 @@ HcalRecHitsValidation::HcalRecHitsValidation(edm::ParameterSet const &conf)

nevtot = 0;

hcalselector_ = conf.getUntrackedParameter<std::string>("hcalselector", "all");
ecalselector_ = conf.getUntrackedParameter<std::string>("ecalselector", "yes");
sign_ = conf.getUntrackedParameter<std::string>("sign", "*");
mc_ = conf.getUntrackedParameter<std::string>("mc", "yes");
testNumber_ = conf.getParameter<bool>("TestNumber");

// Collections
tok_hbhe_ = consumes<HBHERecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("HBHERecHitCollectionLabel"));
tok_hf_ = consumes<HFRecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("HFRecHitCollectionLabel"));
tok_ho_ = consumes<HORecHitCollection>(conf.getUntrackedParameter<edm::InputTag>("HORecHitCollectionLabel"));

// register for data access
tok_evt_ = consumes<edm::HepMCProduct>(edm::InputTag("generatorSmeared"));
edm::InputTag EBRecHitCollectionLabel = conf.getParameter<edm::InputTag>("EBRecHitCollectionLabel");
tok_EB_ = consumes<EBRecHitCollection>(EBRecHitCollectionLabel);
edm::InputTag EERecHitCollectionLabel = conf.getParameter<edm::InputTag>("EERecHitCollectionLabel");
tok_EE_ = consumes<EERecHitCollection>(EERecHitCollectionLabel);

tok_hh_ = consumes<edm::PCaloHitContainer>(conf.getUntrackedParameter<edm::InputTag>("SimHitCollectionLabel"));

tok_HRNDC_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>();
tok_Geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();

subdet_ = 5;
if (hcalselector_ == "noise")
Expand Down Expand Up @@ -66,8 +62,6 @@ HcalRecHitsValidation::HcalRecHitsValidation(edm::ParameterSet const &conf)
imc = 0;
}

HcalRecHitsValidation::~HcalRecHitsValidation() {}

void HcalRecHitsValidation::bookHistograms(DQMStore::IBooker &ib, edm::Run const &run, edm::EventSetup const &es) {
Char_t histo[200];

Expand Down Expand Up @@ -225,8 +219,7 @@ void HcalRecHitsValidation::analyze(edm::Event const &ev, edm::EventSetup const
double partR = 0.3;

if (imc != 0) {
edm::Handle<edm::HepMCProduct> evtMC;
ev.getByToken(tok_evt_, evtMC); // generator in late 310_preX
const edm::Handle<edm::HepMCProduct> &evtMC = ev.getHandle(tok_evt_); // generator in late 310_preX
if (!evtMC.isValid()) {
edm::LogInfo("HcalRecHitsValidation") << "no HepMCProduct found";
} else {
Expand Down Expand Up @@ -270,12 +263,12 @@ void HcalRecHitsValidation::analyze(edm::Event const &ev, edm::EventSetup const

// ECAL
if (ecalselector_ == "yes" && (subdet_ == 1 || subdet_ == 2 || subdet_ == 5)) {
Handle<EBRecHitCollection> rhitEB;
const edm::Handle<EBRecHitCollection> &rhitEB = ev.getHandle(tok_EB_);

EcalRecHitCollection::const_iterator RecHit;
EcalRecHitCollection::const_iterator RecHitEnd;

if (ev.getByToken(tok_EB_, rhitEB)) {
if (rhitEB.isValid()) {
RecHit = rhitEB.product()->begin();
RecHitEnd = rhitEB.product()->end();

Expand All @@ -297,9 +290,9 @@ void HcalRecHitsValidation::analyze(edm::Event const &ev, edm::EventSetup const
}
}

Handle<EERecHitCollection> rhitEE;
const edm::Handle<EERecHitCollection> &rhitEE = ev.getHandle(tok_EE_);

if (ev.getByToken(tok_EE_, rhitEE)) {
if (rhitEE.isValid()) {
RecHit = rhitEE.product()->begin();
RecHitEnd = rhitEE.product()->end();

Expand Down Expand Up @@ -432,8 +425,8 @@ void HcalRecHitsValidation::analyze(edm::Event const &ev, edm::EventSetup const
// SimHits vs. RecHits
if (subdet_ > 0 && subdet_ < 6 && imc != 0) { // not noise

edm::Handle<PCaloHitContainer> hcalHits;
if (ev.getByToken(tok_hh_, hcalHits)) {
const edm::Handle<PCaloHitContainer> &hcalHits = ev.getHandle(tok_hh_);
if (hcalHits.isValid()) {
const PCaloHitContainer *SimHitResult = hcalHits.product();

double enSimHits = 0.;
Expand Down Expand Up @@ -537,8 +530,8 @@ void HcalRecHitsValidation::fillRecHitsTmp(int subdet_, edm::Event const &ev) {

if (subdet_ == 1 || subdet_ == 2 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
// HBHE
edm::Handle<HBHERecHitCollection> hbhecoll;
if (ev.getByToken(tok_hbhe_, hbhecoll)) {
const edm::Handle<HBHERecHitCollection> &hbhecoll = ev.getHandle(tok_hbhe_);
if (hbhecoll.isValid()) {
for (HBHERecHitCollection::const_iterator j = hbhecoll->begin(); j != hbhecoll->end(); j++) {
HcalDetId cell(j->id());
const HcalGeometry *cellGeometry =
Expand Down Expand Up @@ -572,8 +565,8 @@ void HcalRecHitsValidation::fillRecHitsTmp(int subdet_, edm::Event const &ev) {

if (subdet_ == 4 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
// HF
edm::Handle<HFRecHitCollection> hfcoll;
if (ev.getByToken(tok_hf_, hfcoll)) {
const edm::Handle<HFRecHitCollection> &hfcoll = ev.getHandle(tok_hf_);
if (hfcoll.isValid()) {
for (HFRecHitCollection::const_iterator j = hfcoll->begin(); j != hfcoll->end(); j++) {
HcalDetId cell(j->id());
auto cellGeometry = geometry_->getSubdetectorGeometry(cell)->getGeometry(cell);
Expand Down Expand Up @@ -606,8 +599,8 @@ void HcalRecHitsValidation::fillRecHitsTmp(int subdet_, edm::Event const &ev) {

// HO
if (subdet_ == 3 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
edm::Handle<HORecHitCollection> hocoll;
if (ev.getByToken(tok_ho_, hocoll)) {
const edm::Handle<HORecHitCollection> &hocoll = ev.getHandle(tok_ho_);
if (hocoll.isValid()) {
for (HORecHitCollection::const_iterator j = hocoll->begin(); j != hocoll->end(); j++) {
HcalDetId cell(j->id());
auto cellGeometry = geometry_->getSubdetectorGeometry(cell)->getGeometry(cell);
Expand Down
28 changes: 10 additions & 18 deletions Validation/HcalRecHits/src/NoiseRates.cc
Expand Up @@ -14,25 +14,19 @@
// constructors and destructor
//

NoiseRates::NoiseRates(const edm::ParameterSet &iConfig) {
NoiseRates::NoiseRates(const edm::ParameterSet &iConfig)
: outputFile_(iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root")),
rbxCollName_(iConfig.getUntrackedParameter<edm::InputTag>("rbxCollName")),
minRBXEnergy_(iConfig.getUntrackedParameter<double>("minRBXEnergy")),
minHitEnergy_(iConfig.getUntrackedParameter<double>("minHitEnergy")),
useAllHistos_(iConfig.getUntrackedParameter<bool>("useAllHistos", false)),
tok_rbx_(consumes<reco::HcalNoiseRBXCollection>(rbxCollName_)),
noisetoken_(consumes<HcalNoiseSummary>(iConfig.getParameter<edm::InputTag>("noiselabel"))) {
// DQM ROOT output
outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");

// set parameters
rbxCollName_ = iConfig.getUntrackedParameter<edm::InputTag>("rbxCollName");
minRBXEnergy_ = iConfig.getUntrackedParameter<double>("minRBXEnergy");
minHitEnergy_ = iConfig.getUntrackedParameter<double>("minHitEnergy");

tok_rbx_ = consumes<reco::HcalNoiseRBXCollection>(rbxCollName_);

useAllHistos_ = iConfig.getUntrackedParameter<bool>("useAllHistos", false);

// Hcal Noise Summary
noisetoken_ = consumes<HcalNoiseSummary>(iConfig.getParameter<edm::InputTag>("noiselabel"));
}

NoiseRates::~NoiseRates() {}

//
// member functions
//
Expand Down Expand Up @@ -102,17 +96,15 @@ void NoiseRates::analyze(const edm::Event &iEvent, const edm::EventSetup &evSetu
lumiCountMap_[lumiSection]++;

// get the RBX Noise collection
edm::Handle<reco::HcalNoiseRBXCollection> handle;
iEvent.getByToken(tok_rbx_, handle);
const edm::Handle<reco::HcalNoiseRBXCollection> &handle = iEvent.getHandle(tok_rbx_);
if (!handle.isValid()) {
throw edm::Exception(edm::errors::ProductNotFound)
<< " could not find HcalNoiseRBXCollection named " << rbxCollName_ << ".\n";
return;
}

// get the Noise summary object
edm::Handle<HcalNoiseSummary> summary_h;
iEvent.getByToken(noisetoken_, summary_h);
const edm::Handle<HcalNoiseSummary> &summary_h = iEvent.getHandle(noisetoken_);
if (!summary_h.isValid()) {
throw edm::Exception(edm::errors::ProductNotFound) << " could not find HcalNoiseSummary.\n";
return;
Expand Down
23 changes: 8 additions & 15 deletions Validation/HcalRecHits/test/HcalDumpHits.cc
Expand Up @@ -29,7 +29,7 @@
class HcalDumpHits : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
explicit HcalDumpHits(const edm::ParameterSet&);
~HcalDumpHits() override {}
~HcalDumpHits() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

Expand Down Expand Up @@ -79,8 +79,7 @@ void HcalDumpHits::beginRun(const edm::Run&, const edm::EventSetup& iSetup) { hc

void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
// first SimHits
edm::Handle<edm::PCaloHitContainer> theCaloHitContainer;
iEvent.getByToken(simHitSource_, theCaloHitContainer);
const edm::Handle<edm::PCaloHitContainer>& theCaloHitContainer = iEvent.getHandle(simHitSource_);
if (theCaloHitContainer.isValid()) {
edm::LogVerbatim("HcalValidation") << theCaloHitContainer->size() << " SimHits in HCAL";
unsigned int k(0);
Expand All @@ -93,8 +92,7 @@ void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
}

// Digis (HBHE/HF/HO)
edm::Handle<QIE11DigiCollection> hbheDigiCollection;
iEvent.getByToken(hbheDigiSource_, hbheDigiCollection);
const edm::Handle<QIE11DigiCollection>& hbheDigiCollection = iEvent.getHandle(hbheDigiSource_);
if (hbheDigiCollection.isValid()) {
edm::LogVerbatim("HcalValidation") << hbheDigiCollection->size() << " Digis for HB/HE";
unsigned int k(0);
Expand All @@ -109,8 +107,7 @@ void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
++k;
}
}
edm::Handle<QIE10DigiCollection> hfDigiCollection;
iEvent.getByToken(hfDigiSource_, hfDigiCollection);
const edm::Handle<QIE10DigiCollection>& hfDigiCollection = iEvent.getHandle(hfDigiSource_);
if (hfDigiCollection.isValid()) {
edm::LogVerbatim("HcalValidation") << hfDigiCollection->size() << " Digis for HF";
unsigned int k(0);
Expand All @@ -125,8 +122,7 @@ void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
++k;
}
}
edm::Handle<HODigiCollection> hoDigiCollection;
iEvent.getByToken(hoDigiSource_, hoDigiCollection);
const edm::Handle<HODigiCollection>& hoDigiCollection = iEvent.getHandle(hoDigiSource_);
if (hoDigiCollection.isValid()) {
edm::LogVerbatim("HcalValidation") << hoDigiCollection->size() << " Digis for HO";
unsigned int k(0);
Expand All @@ -142,8 +138,7 @@ void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
}

// RecHits (HBHE/HF/HO)
edm::Handle<HBHERecHitCollection> hbhecoll;
iEvent.getByToken(hbheRecHitSource_, hbhecoll);
const edm::Handle<HBHERecHitCollection>& hbhecoll = iEvent.getHandle(hbheRecHitSource_);
if (hbhecoll.isValid()) {
edm::LogVerbatim("HcalValidation") << hbhecoll->size() << " RecHits for HB/HE";
unsigned int k(0);
Expand All @@ -153,8 +148,7 @@ void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
++k;
}
}
edm::Handle<HFRecHitCollection> hfcoll;
iEvent.getByToken(hfRecHitSource_, hfcoll);
const edm::Handle<HFRecHitCollection>& hfcoll = iEvent.getHandle(hfRecHitSource_);
if (hfcoll.isValid()) {
edm::LogVerbatim("HcalValidation") << hfcoll->size() << " RecHits for HF";
unsigned int k(0);
Expand All @@ -164,8 +158,7 @@ void HcalDumpHits::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
++k;
}
}
edm::Handle<HORecHitCollection> hocoll;
iEvent.getByToken(hoRecHitSource_, hocoll);
const edm::Handle<HORecHitCollection>& hocoll = iEvent.getHandle(hoRecHitSource_);
if (hocoll.isValid()) {
edm::LogVerbatim("HcalValidation") << hocoll->size() << " RecHits for HO";
unsigned int k(0);
Expand Down

0 comments on commit 90abdab

Please sign in to comment.