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

Use HGCalRecHitMapProducer #30061

Merged
merged 20 commits into from Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 2 additions & 2 deletions DataFormats/HGCRecHit/src/classes_def.xml
Expand Up @@ -36,7 +36,7 @@
<class name="edm::reftobase::Holder<CaloRecHit, edm::Ref<edm::SortedCollection<HGCRecHit, edm::StrictWeakOrdering<HGCRecHit> >, HGCRecHit, edm::refhelper::FindUsingAdvance<edm::SortedCollection<HGCRecHit, edm::StrictWeakOrdering<HGCRecHit> >, HGCRecHit> > >" />
<enum name="HGCSeverityLevel::SeverityLevel"/>

<class name="std::map<DetId,const HGCRecHit*>" persistent="false"/>
<class name="edm::Wrapper<std::map<DetId,const HGCRecHit*>>" persistent="false"/>
<class name="std::unordered_map<DetId,const HGCRecHit*>" persistent="false"/>
<class name="edm::Wrapper<std::unordered_map<DetId,const HGCRecHit*>>" persistent="false"/>
<class name="std::pair<const DetId,const HGCRecHit*>" />
</lcgdict>
37 changes: 4 additions & 33 deletions Fireworks/Calo/interface/FWHeatmapProxyBuilderTemplate.h
Expand Up @@ -44,7 +44,7 @@ class FWHeatmapProxyBuilderTemplate : public FWSimpleProxyBuilder {
// ---------- member functions ---------------------------

protected:
std::map<DetId, const HGCRecHit*> hitmap;
const std::unordered_map<DetId, const HGCRecHit*>* hitmap;

static constexpr uint8_t gradient_steps = 9;
static constexpr uint8_t gradient[3][gradient_steps] = {{static_cast<uint8_t>(0.2082 * 255),
Expand Down Expand Up @@ -93,40 +93,11 @@ class FWHeatmapProxyBuilderTemplate : public FWSimpleProxyBuilder {

void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc) override {
if (item()->getConfig()->template value<bool>("Heatmap")) {
hitmap.clear();

edm::Handle<HGCRecHitCollection> recHitHandleEE;
edm::Handle<HGCRecHitCollection> recHitHandleFH;
edm::Handle<HGCRecHitCollection> recHitHandleBH;

const edm::EventBase* event = iItem->getEvent();
event->getByLabel(edm::InputTag("HGCalRecHit", "HGCEERecHits"), recHitHandleEE);
event->getByLabel(edm::InputTag("HGCalRecHit", "HGCHEFRecHits"), recHitHandleFH);
event->getByLabel(edm::InputTag("HGCalRecHit", "HGCHEBRecHits"), recHitHandleBH);

if (recHitHandleEE.isValid()) {
const auto& rechitsEE = *recHitHandleEE;

for (unsigned int i = 0; i < rechitsEE.size(); ++i) {
hitmap[rechitsEE[i].detid().rawId()] = &rechitsEE[i];
}
}

if (recHitHandleFH.isValid()) {
const auto& rechitsFH = *recHitHandleFH;

for (unsigned int i = 0; i < rechitsFH.size(); ++i) {
hitmap[rechitsFH[i].detid().rawId()] = &rechitsFH[i];
}
}

if (recHitHandleBH.isValid()) {
const auto& rechitsBH = *recHitHandleBH;

for (unsigned int i = 0; i < rechitsBH.size(); ++i) {
hitmap[rechitsBH[i].detid().rawId()] = &rechitsBH[i];
}
}
edm::Handle<std::unordered_map<DetId, const HGCRecHit*>> hitMapHandle;
event->getByLabel(edm::InputTag("hgcRecHitMapProducer"), hitMapHandle);
hitmap = &*hitMapHandle;
}

FWSimpleProxyBuilder::build(iItem, product, vc);
Expand Down
11 changes: 6 additions & 5 deletions Fireworks/Calo/plugins/FWCaloClusterProxyBuilder.cc
Expand Up @@ -107,7 +107,7 @@ void FWCaloClusterProxyBuilder::build(const reco::CaloCluster &iData,

// HGCal
if (iData.algo() == 8 || (type >= 8 && type <= 10)) {
if (heatmap && hitmap.find(it->first) == hitmap.end())
if (heatmap && hitmap->find(it->first) == hitmap->end())
continue;

const bool z = (it->first >> 25) & 0x1;
Expand Down Expand Up @@ -161,10 +161,11 @@ void FWCaloClusterProxyBuilder::build(const reco::CaloCluster &iData,
oItemHolder.AddElement(marker);
}

const float energy = fmin(
(item()->getConfig()->value<bool>("Cluster(0)/RecHit(1)") ? hitmap[it->first]->energy() : iData.energy()) /
saturation_energy,
1.0f);
const float energy =
fmin((item()->getConfig()->value<bool>("Cluster(0)/RecHit(1)") ? hitmap->at(it->first)->energy()
: iData.energy()) /
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the cases in which the automatic line breaking provided by the code format checks give weird results. I have no suggestions, nor I do require it gets modified: just noticing it.

saturation_energy,
1.0f);
const uint8_t colorFactor = gradient_steps * energy;

// Scintillator
Expand Down
8 changes: 5 additions & 3 deletions Fireworks/Calo/plugins/FWHGCalMultiClusterProxyBuilder.cc
Expand Up @@ -58,7 +58,7 @@ void FWHGCalMultiClusterProxyBuilder::build(const reco::HGCalMultiCluster &iData
for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
it != itEnd;
++it) {
if (heatmap && hitmap.find(it->first) == hitmap.end())
if (heatmap && hitmap->find(it->first) == hitmap->end())
continue;

const bool z = (it->first >> 25) & 0x1;
Expand Down Expand Up @@ -112,7 +112,8 @@ void FWHGCalMultiClusterProxyBuilder::build(const reco::HGCalMultiCluster &iData
}
boxset->AddBox(&pnts[0]);
if (heatmap) {
const uint8_t colorFactor = gradient_steps * (fmin(hitmap[it->first]->energy() / saturation_energy, 1.0f));
const uint8_t colorFactor =
gradient_steps * (fmin(hitmap->at(it->first)->energy() / saturation_energy, 1.0f));
boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
}

Expand All @@ -127,7 +128,8 @@ void FWHGCalMultiClusterProxyBuilder::build(const reco::HGCalMultiCluster &iData
float radius = fabs(corners[6] - corners[6 + offset]) / 2;
hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, 90.0, shapes[3]);
if (heatmap) {
const uint8_t colorFactor = gradient_steps * (fmin(hitmap[it->first]->energy() / saturation_energy, 1.0f));
const uint8_t colorFactor =
gradient_steps * (fmin(hitmap->at(it->first)->energy() / saturation_energy, 1.0f));
hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
}

Expand Down
16 changes: 5 additions & 11 deletions RecoEgamma/EgammaTools/interface/EgammaPCAHelper.h
Expand Up @@ -22,7 +22,7 @@
#include "RecoEgamma/EgammaTools/interface/ShowerDepth.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
#include "Math/Transform3D.h"
#include <map>
#include <unordered_map>

#include "TPrincipal.h"

Expand All @@ -43,14 +43,9 @@ namespace hgcal {
void storeRecHits(const reco::HGCalMultiCluster &cluster);

const TPrincipal &pcaResult();
/// to set from outside - once per event
void setHitMap(std::map<DetId, const HGCRecHit *> *hitMap);
/// to compute from inside - once per event
void fillHitMap(const HGCRecHitCollection &HGCEERecHits,
const HGCRecHitCollection &HGCFHRecHits,
const HGCRecHitCollection &HGCBHRecHits);

std::map<DetId, const HGCRecHit *> *getHitMap() { return hitMap_; }
/// to set once per event
void setHitMap(const std::unordered_map<DetId, const HGCRecHit *> *hitMap);
const std::unordered_map<DetId, const HGCRecHit *> *getHitMap() { return hitMap_; }

void setRecHitTools(const hgcal::RecHitTools *recHitTools);

Expand Down Expand Up @@ -90,9 +85,8 @@ namespace hgcal {
std::vector<double> dEdXWeights_;
std::vector<double> invThicknessCorrection_;

int hitMapOrigin_; // 0 not initialized; 1 set from outside ; 2 set from inside
const reco::CaloCluster *theCluster_;
std::map<DetId, const HGCRecHit *> *hitMap_;
const std::unordered_map<DetId, const HGCRecHit *> *hitMap_;
std::vector<Spot> theSpots_;
int pcaIteration_;
unsigned int maxlayer_;
Expand Down
2 changes: 2 additions & 0 deletions RecoEgamma/EgammaTools/interface/HGCalEgammaIDHelper.h
Expand Up @@ -71,13 +71,15 @@ class HGCalEgammaIDHelper {
edm::InputTag eeRecHitInputTag_;
edm::InputTag fhRecHitInputTag_;
edm::InputTag bhRecHitInputTag_;
edm::InputTag hitMapInputTag_;

std::vector<double> dEdXWeights_;
hgcal::EGammaPCAHelper pcaHelper_;
HGCalIsoCalculator isoHelper_;
edm::EDGetTokenT<HGCRecHitCollection> recHitsEE_;
edm::EDGetTokenT<HGCRecHitCollection> recHitsFH_;
edm::EDGetTokenT<HGCRecHitCollection> recHitsBH_;
edm::EDGetTokenT<std::unordered_map<DetId, const HGCRecHit*>> hitMap_;
hgcal::RecHitTools recHitTools_;
bool debug_;
};
Expand Down
Expand Up @@ -232,6 +232,7 @@ void HGCalElectronIDValueMapProducer::fillDescriptions(edm::ConfigurationDescrip
desc.add<edm::InputTag>("EERecHits", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
desc.add<edm::InputTag>("FHRecHits", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
desc.add<edm::InputTag>("BHRecHits", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcRecHitMapProducer"));
descriptions.add("hgcalElectronIDValueMap", desc);
}

Expand Down
Expand Up @@ -216,6 +216,7 @@ void HGCalPhotonIDValueMapProducer::fillDescriptions(edm::ConfigurationDescripti
desc.add<edm::InputTag>("EERecHits", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
desc.add<edm::InputTag>("FHRecHits", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
desc.add<edm::InputTag>("BHRecHits", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcRecHitMapProducer"));
descriptions.add("hgcalPhotonIDValueMap", desc);
}

Expand Down
33 changes: 4 additions & 29 deletions RecoEgamma/EgammaTools/src/EgammaPCAHelper.cc
Expand Up @@ -19,18 +19,13 @@ EGammaPCAHelper::EGammaPCAHelper()
// See RecoLocalCalo.HGCalRecProducers.HGCalRecHit_cfi
invThicknessCorrection_({1. / 1.132, 1. / 1.092, 1. / 1.084}),
pca_(new TPrincipal(3, "D")) {
hitMapOrigin_ = 0;
hitMap_ = new std::map<DetId, const HGCRecHit*>();
hitMap_ = nullptr;
debug_ = false;
}

EGammaPCAHelper::~EGammaPCAHelper() {
if (hitMapOrigin_ == 2)
delete hitMap_;
}
EGammaPCAHelper::~EGammaPCAHelper() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now use a default destructor


void EGammaPCAHelper::setHitMap(std::map<DetId, const HGCRecHit*>* hitMap) {
hitMapOrigin_ = 1;
void EGammaPCAHelper::setHitMap(const std::unordered_map<DetId, const HGCRecHit*>* hitMap) {
hitMap_ = hitMap;
pcaIteration_ = 0;
}
Expand All @@ -40,26 +35,6 @@ void EGammaPCAHelper::setRecHitTools(const hgcal::RecHitTools* recHitTools) {
maxlayer_ = recHitTools_->lastLayerBH();
}

void EGammaPCAHelper::fillHitMap(const HGCRecHitCollection& rechitsEE,
const HGCRecHitCollection& rechitsFH,
const HGCRecHitCollection& rechitsBH) {
hitMap_->clear();
for (const auto& hit : rechitsEE) {
hitMap_->emplace_hint(hitMap_->end(), hit.detid(), &hit);
}

for (const auto& hit : rechitsFH) {
hitMap_->emplace_hint(hitMap_->end(), hit.detid(), &hit);
}

for (const auto& hit : rechitsBH) {
hitMap_->emplace_hint(hitMap_->end(), hit.detid(), &hit);
}

pcaIteration_ = 0;
hitMapOrigin_ = 2;
}

void EGammaPCAHelper::storeRecHits(const reco::HGCalMultiCluster& cluster) {
theCluster_ = &cluster;
std::vector<std::pair<DetId, float>> result;
Expand Down Expand Up @@ -97,7 +72,7 @@ void EGammaPCAHelper::storeRecHits(const std::vector<std::pair<DetId, float>>& h
unsigned int layer = recHitTools_->getLayerWithOffset(hf[j].first);

const DetId rh_detid = hf[j].first;
std::map<DetId, const HGCRecHit*>::const_iterator itcheck = hitMap_->find(rh_detid);
std::unordered_map<DetId, const HGCRecHit*>::const_iterator itcheck = hitMap_->find(rh_detid);
if (itcheck == hitMap_->end()) {
edm::LogWarning("EgammaPCAHelper") << " Big problem, unable to find a hit " << rh_detid.rawId() << " "
<< rh_detid.det() << " " << HGCalDetId(rh_detid) << std::endl;
Expand Down
8 changes: 6 additions & 2 deletions RecoEgamma/EgammaTools/src/HGCalEgammaIDHelper.cc
Expand Up @@ -6,14 +6,16 @@ HGCalEgammaIDHelper::HGCalEgammaIDHelper(const edm::ParameterSet& iConfig, edm::
: eeRecHitInputTag_(iConfig.getParameter<edm::InputTag>("EERecHits")),
fhRecHitInputTag_(iConfig.getParameter<edm::InputTag>("FHRecHits")),
bhRecHitInputTag_(iConfig.getParameter<edm::InputTag>("BHRecHits")),
dEdXWeights_(iConfig.getParameter<std::vector<double> >("dEdXWeights")) {
hitMapInputTag_(iConfig.getParameter<edm::InputTag>("hitMapTag")),
dEdXWeights_(iConfig.getParameter<std::vector<double>>("dEdXWeights")) {
isoHelper_.setDeltaR(iConfig.getParameter<double>("isoDeltaR"));
isoHelper_.setNRings(iConfig.getParameter<unsigned int>("isoNRings"));
isoHelper_.setMinDeltaR(iConfig.getParameter<double>("isoDeltaRmin"));

recHitsEE_ = iC.consumes<HGCRecHitCollection>(eeRecHitInputTag_);
recHitsFH_ = iC.consumes<HGCRecHitCollection>(fhRecHitInputTag_);
recHitsBH_ = iC.consumes<HGCRecHitCollection>(bhRecHitInputTag_);
hitMap_ = iC.consumes<std::unordered_map<DetId, const HGCRecHit*>>(hitMapInputTag_);
pcaHelper_.setdEdXWeights(dEdXWeights_);
debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
}
Expand All @@ -25,11 +27,13 @@ void HGCalEgammaIDHelper::eventInit(const edm::Event& iEvent, const edm::EventSe
iEvent.getByToken(recHitsFH_, recHitHandleFH);
edm::Handle<HGCRecHitCollection> recHitHandleBH;
iEvent.getByToken(recHitsBH_, recHitHandleBH);
edm::Handle<std::unordered_map<DetId, const HGCRecHit*>> hitMapHandle;
iEvent.getByToken(hitMap_, hitMapHandle);

recHitTools_.getEventSetup(iSetup);
pcaHelper_.setRecHitTools(&recHitTools_);
isoHelper_.setRecHitTools(&recHitTools_);
pcaHelper_.fillHitMap(*recHitHandleEE, *recHitHandleFH, *recHitHandleBH);
pcaHelper_.setHitMap(hitMapHandle.product());
isoHelper_.setRecHits(recHitHandleEE, recHitHandleFH, recHitHandleBH);
}

Expand Down
@@ -1,5 +1,5 @@
// user include files
#include <map>
#include <unordered_map>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
Expand Down Expand Up @@ -28,11 +28,13 @@ class HGCalRecHitMapProducer : public edm::global::EDProducer<> {

DEFINE_FWK_MODULE(HGCalRecHitMapProducer);

using DetIdRecHitMap = std::unordered_map<DetId, const HGCRecHit*>;

HGCalRecHitMapProducer::HGCalRecHitMapProducer(const edm::ParameterSet& ps)
: hits_ee_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("EEInput"))),
hits_fh_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("FHInput"))),
hits_bh_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("BHInput"))) {
produces<std::map<DetId, const HGCRecHit*>>();
produces<DetIdRecHitMap>();
}

void HGCalRecHitMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand All @@ -44,7 +46,7 @@ void HGCalRecHitMapProducer::fillDescriptions(edm::ConfigurationDescriptions& de
}

void HGCalRecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
auto hitMap = std::make_unique<std::map<DetId, const HGCRecHit*>>();
auto hitMap = std::make_unique<DetIdRecHitMap>();
const auto& ee_hits = evt.get(hits_ee_token_);
const auto& fh_hits = evt.get(hits_fh_token_);
const auto& bh_hits = evt.get(hits_bh_token_);
Expand Down
Expand Up @@ -11,7 +11,7 @@ LayerClusterAssociatorByEnergyScoreImpl::LayerClusterAssociatorByEnergyScoreImpl
edm::EDProductGetter const& productGetter,
bool hardScatterOnly,
std::shared_ptr<hgcal::RecHitTools> recHitTools,
const std::map<DetId, const HGCRecHit*>*& hitMap)
const std::unordered_map<DetId, const HGCRecHit*>*& hitMap)
: hardScatterOnly_(hardScatterOnly), recHitTools_(recHitTools), hitMap_(hitMap), productGetter_(&productGetter) {
layers_ = recHitTools_->lastLayerBH();
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ class LayerClusterAssociatorByEnergyScoreImpl : public hgcal::LayerClusterToCalo
explicit LayerClusterAssociatorByEnergyScoreImpl(edm::EDProductGetter const &,
bool,
std::shared_ptr<hgcal::RecHitTools>,
const std::map<DetId, const HGCRecHit *> *&);
const std::unordered_map<DetId, const HGCRecHit *> *&);

hgcal::RecoToSimCollection associateRecoToSim(const edm::Handle<reco::CaloClusterCollection> &cCH,
const edm::Handle<CaloParticleCollection> &cPCH) const override;
Expand All @@ -60,7 +60,7 @@ class LayerClusterAssociatorByEnergyScoreImpl : public hgcal::LayerClusterToCalo
private:
const bool hardScatterOnly_;
std::shared_ptr<hgcal::RecHitTools> recHitTools_;
const std::map<DetId, const HGCRecHit *> *hitMap_;
const std::unordered_map<DetId, const HGCRecHit *> *hitMap_;
unsigned layers_;
edm::EDProductGetter const *productGetter_;
hgcal::association makeConnections(const edm::Handle<reco::CaloClusterCollection> &cCH,
Expand Down
Expand Up @@ -22,13 +22,13 @@ class LayerClusterAssociatorByEnergyScoreProducer : public edm::global::EDProduc

private:
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
edm::EDGetTokenT<std::map<DetId, const HGCRecHit *>> hitMapToken_;
edm::EDGetTokenT<std::unordered_map<DetId, const HGCRecHit *>> hitMap_;
const bool hardScatterOnly_;
std::shared_ptr<hgcal::RecHitTools> rhtools_;
};

LayerClusterAssociatorByEnergyScoreProducer::LayerClusterAssociatorByEnergyScoreProducer(const edm::ParameterSet &ps)
: hitMapToken_(consumes<std::map<DetId, const HGCRecHit *>>(ps.getParameter<edm::InputTag>("hitMapTag"))),
: hitMap_(consumes<std::unordered_map<DetId, const HGCRecHit *>>(ps.getParameter<edm::InputTag>("hitMapTag"))),
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")) {
rhtools_.reset(new hgcal::RecHitTools());

Expand All @@ -42,9 +42,8 @@ void LayerClusterAssociatorByEnergyScoreProducer::produce(edm::StreamID,
edm::Event &iEvent,
const edm::EventSetup &es) const {
rhtools_->getEventSetup(es);
edm::Handle<std::map<DetId, const HGCRecHit *>> hitMapHandle;
iEvent.getByToken(hitMapToken_, hitMapHandle);
const std::map<DetId, const HGCRecHit *> *hitMap = &*hitMapHandle;

const std::unordered_map<DetId, const HGCRecHit *> *hitMap = &iEvent.get(hitMap_);

auto impl = std::make_unique<LayerClusterAssociatorByEnergyScoreImpl>(
iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap);
Expand Down
8 changes: 1 addition & 7 deletions Validation/HGCalValidation/interface/HGCalValidator.h
Expand Up @@ -71,18 +71,12 @@ class HGCalValidator : public DQMGlobalEDAnalyzer<HGCalValidatorHistograms> {
edm::EDGetTokenT<std::vector<CaloParticle>> label_cp_effic;
edm::EDGetTokenT<std::vector<CaloParticle>> label_cp_fake;
edm::EDGetTokenT<std::vector<SimVertex>> simVertices_;
edm::EDGetTokenT<HGCRecHitCollection> recHitsEE_;
edm::EDGetTokenT<HGCRecHitCollection> recHitsFH_;
edm::EDGetTokenT<HGCRecHitCollection> recHitsBH_;
edm::EDGetTokenT<std::unordered_map<DetId, const HGCRecHit*>> hitMap_;
edm::EDGetTokenT<Density> density_;
edm::EDGetTokenT<hgcal::LayerClusterToCaloParticleAssociator> LCAssocByEnergyScoreProducer_;
std::unique_ptr<HGVHistoProducerAlgo> histoProducerAlgo_;

private:
void fillHitMap(std::map<DetId, const HGCRecHit*>&,
const HGCRecHitCollection&,
const HGCRecHitCollection&,
const HGCRecHitCollection&) const;
CaloParticleSelector cpSelector;
std::shared_ptr<hgcal::RecHitTools> tools_;
std::map<double, double> cummatbudg;
Expand Down