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

DQMOffline/Hcal : finalizing migration to ESGetToken #33796

Merged
merged 2 commits into from May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions DQMOffline/Hcal/interface/HcalRecHitsDQMClient.h
Expand Up @@ -24,19 +24,20 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include <FWCore/Framework/interface/EDAnalyzer.h>
#include "FWCore/Utilities/interface/ESGetToken.h"
#include <memory>
#include <unistd.h>

#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"
#include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h"

#include <fstream>
#include <iostream>
Expand All @@ -54,7 +55,8 @@ class HcalRecHitsDQMClient : public DQMEDHarvester {
std::string dirNameJet_;
std::string dirNameMET_;

const HcalDDDRecConstants *hcons;
edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> hcalDDDRecConstantsToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometryRunToken_;
int maxDepthHB_, maxDepthHE_, maxDepthHO_, maxDepthHF_, maxDepthAll_;

int nChannels_[5]; // 0:any, 1:HB, 2:HE, 3:HO, 4: HF
Expand Down
9 changes: 5 additions & 4 deletions DQMOffline/Hcal/src/HcalCollapseAnalyzer.cc
Expand Up @@ -60,9 +60,11 @@ class HcalCollapseAnalyzer : public DQMEDAnalyzer {
const int verbosity_;
const edm::InputTag recHitHBHE_, preRecHitHBHE_;
const bool doHE_, doHB_;
const HcalTopology *theHBHETopology = nullptr;

edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
edm::EDGetTokenT<HBHERecHitCollection> tok_prehbhe_;
edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> hcalTopologyToken_;

MonitorElement *h_merge, *h_size, *h_depth;
MonitorElement *h_sfrac, *h_frac, *h_balance;
Expand All @@ -74,7 +76,8 @@ HcalCollapseAnalyzer::HcalCollapseAnalyzer(const edm::ParameterSet &iConfig)
recHitHBHE_(iConfig.getUntrackedParameter<edm::InputTag>("recHitHBHE", edm::InputTag("hbhereco"))),
preRecHitHBHE_(iConfig.getUntrackedParameter<edm::InputTag>("preRecHitHBHE", edm::InputTag("hbheprereco"))),
doHE_(iConfig.getUntrackedParameter<bool>("doHE", true)),
doHB_(iConfig.getUntrackedParameter<bool>("doHB", false)) {
doHB_(iConfig.getUntrackedParameter<bool>("doHB", false)),
hcalTopologyToken_{esConsumes<HcalTopology, HcalRecNumberingRecord>()} {
// define tokens for access
tok_hbhe_ = consumes<HBHERecHitCollection>(recHitHBHE_);
tok_prehbhe_ = consumes<HBHERecHitCollection>(preRecHitHBHE_);
Expand All @@ -99,9 +102,7 @@ void HcalCollapseAnalyzer::analyze(edm::Event const &iEvent, edm::EventSetup con
edm::LogVerbatim("Collapse") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event()
<< " starts ==============";

edm::ESHandle<HcalTopology> htopo;
iSetup.get<HcalRecNumberingRecord>().get(htopo);
const HcalTopology *theHBHETopology = htopo.product();
theHBHETopology = &iSetup.getData(hcalTopologyToken_);

edm::Handle<HBHERecHitCollection> hbhereco;
iEvent.getByToken(tok_hbhe_, hbhereco);
Expand Down
36 changes: 18 additions & 18 deletions DQMOffline/Hcal/src/HcalRecHitsDQMClient.cc
Expand Up @@ -5,10 +5,15 @@
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Transition.h"
#include "FWCore/Utilities/interface/ESInputTag.h"

#include "DQMServices/Core/interface/DQMStore.h"

HcalRecHitsDQMClient::HcalRecHitsDQMClient(const edm::ParameterSet &iConfig) : conf_(iConfig) {
HcalRecHitsDQMClient::HcalRecHitsDQMClient(const edm::ParameterSet &iConfig)
: conf_(iConfig),
hcalDDDRecConstantsToken_{esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord, edm::Transition::BeginRun>()},
caloGeometryRunToken_{esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()} {
outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
debug_ = false;
verbose_ = false;
Expand All @@ -19,23 +24,18 @@ HcalRecHitsDQMClient::~HcalRecHitsDQMClient() {}

void HcalRecHitsDQMClient::beginJob() {}

void HcalRecHitsDQMClient::beginRun(const edm::Run &run, const edm::EventSetup &es) {
edm::ESHandle<HcalDDDRecConstants> pHRNDC;
es.get<HcalRecNumberingRecord>().get(pHRNDC);
hcons = &(*pHRNDC);
maxDepthHB_ = hcons->getMaxDepth(0);
maxDepthHE_ = hcons->getMaxDepth(1);
maxDepthHF_ = hcons->getMaxDepth(2);
maxDepthHO_ = hcons->getMaxDepth(3);

edm::ESHandle<CaloGeometry> geometry;

es.get<CaloGeometryRecord>().get(geometry);

const std::vector<DetId> &hbCells = geometry->getValidDetIds(DetId::Hcal, HcalBarrel);
const std::vector<DetId> &heCells = geometry->getValidDetIds(DetId::Hcal, HcalEndcap);
const std::vector<DetId> &hoCells = geometry->getValidDetIds(DetId::Hcal, HcalOuter);
const std::vector<DetId> &hfCells = geometry->getValidDetIds(DetId::Hcal, HcalForward);
void HcalRecHitsDQMClient::beginRun(const edm::Run &run, const edm::EventSetup &iSetup) {
HcalDDDRecConstants const &hcons = iSetup.getData(hcalDDDRecConstantsToken_);
maxDepthHB_ = hcons.getMaxDepth(0);
maxDepthHE_ = hcons.getMaxDepth(1);
maxDepthHF_ = std::max(hcons.getMaxDepth(2), 1);
maxDepthHO_ = hcons.getMaxDepth(3);

CaloGeometry const &geometry = iSetup.getData(caloGeometryRunToken_);
const std::vector<DetId> &hbCells = geometry.getValidDetIds(DetId::Hcal, HcalBarrel);
const std::vector<DetId> &heCells = geometry.getValidDetIds(DetId::Hcal, HcalEndcap);
const std::vector<DetId> &hoCells = geometry.getValidDetIds(DetId::Hcal, HcalOuter);
const std::vector<DetId> &hfCells = geometry.getValidDetIds(DetId::Hcal, HcalForward);

nChannels_[1] = hbCells.size();
nChannels_[2] = heCells.size();
Expand Down