Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DataFormats/Common/interface/ValueMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace edm {
void throwFillSize() const {
Exception::throwThis(errors::InvalidReference,
"ValueMap::Filler: handle and reference "
"collections should the same size\n");
"collections should have the same size\n");
}
void throwFillID(ProductID id) const {
Exception e(errors::InvalidReference);
Expand Down
7 changes: 6 additions & 1 deletion RecoLocalCalo/HGCalRecAlgos/src/RecHitTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,12 @@ bool RecHitTools::isScintillatorFine(const DetId& id) const {
return false;
}
}
bool RecHitTools::isBarrel(const DetId& id) const { return (id.det() == DetId::Ecal || id.det() == DetId::Hcal); }
bool RecHitTools::isBarrel(const DetId& id) const {
return (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) ||
(id.det() == DetId::Hcal && id.subdetId() == HcalBarrel) ||
(id.det() == DetId::Hcal && id.subdetId() == HcalOuter);
}

bool RecHitTools::isOnlySilicon(const unsigned int layer) const {
// HFnose TODO
bool isonlysilicon = (layer % bhLastLayer_) < bhOffset_;
Expand Down
54 changes: 31 additions & 23 deletions RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event
auto hitMapHGCal = std::make_unique<DetIdRecHitMap>();

// Retrieve collections
assert(hgcal_hits_token_.size() == 3);
const auto& ee_hits = evt.getHandle(hgcal_hits_token_[0]);
const auto& fh_hits = evt.getHandle(hgcal_hits_token_[1]);
const auto& bh_hits = evt.getHandle(hgcal_hits_token_[2]);

// Check validity of all handles
if ((ee_hits.isValid()) && (fh_hits.isValid()) && (bh_hits.isValid())) {
if (!ee_hits.isValid() || !fh_hits.isValid() || !bh_hits.isValid()) {
edm::LogWarning("HGCalRecHitMapProducer")
<< "One or more HGCal hit collections are unavailable. Returning an empty map.";
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
} else {
// TODO may be worth to avoid dependency on the order
// of the collections, maybe using a map
edm::MultiSpan<HGCRecHit> rechitSpan;
Expand All @@ -79,30 +84,33 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event
const auto recHitDetId = rechitSpan[i].detid();
hitMapHGCal->emplace(recHitDetId, i);
}
} else {
edm::LogWarning("HGCalRecHitMapProducer") << "One or more hit collections are unavailable. Returning an empty map.";

evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
}
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");

if (!hgcalOnly_) {
auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();

// Retrieve collections
const auto& ecal_hits = evt.getHandle(barrel_hits_token_[0]);
const auto& hbhe_hits = evt.getHandle(barrel_hits_token_[1]);

if ((ecal_hits.isValid()) && (hbhe_hits.isValid())) {
edm::MultiSpan<reco::PFRecHit> barrelRechitSpan;
barrelRechitSpan.add(*ecal_hits);
barrelRechitSpan.add(*hbhe_hits);
for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) {
const auto recHitDetId = barrelRechitSpan[i].detId();
hitMapBarrel->emplace(recHitDetId, i);
}
} else {
edm::LogWarning("RecHitMapProducer")
<< "One or more barrel hit collections are unavailable. Returning an empty map.";

if (hgcalOnly_) {
return;
}

auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();

assert(barrel_hits_token_.size() == 2);
const auto& ecal_hits = evt.getHandle(barrel_hits_token_[0]);
const auto& hbhe_hits = evt.getHandle(barrel_hits_token_[1]);

if (!ecal_hits.isValid() || !hbhe_hits.isValid()) {
edm::LogWarning("HGCalRecHitMapProducer")
<< "One or more barrel hit collections are unavailable. Returning an empty map.";
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
} else {
edm::MultiSpan<reco::PFRecHit> barrelRechitSpan;
barrelRechitSpan.add(evt.get(barrel_hits_token_[0]));
barrelRechitSpan.add(evt.get(barrel_hits_token_[1]));
for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) {
const auto recHitDetId = barrelRechitSpan[i].detId();
hitMapBarrel->emplace(recHitDetId, i);
}

evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ ticl::association LCToCPAssociatorByEnergyScoreImplT<HIT, CLUSTER>::makeConnecti
const SimCluster& simCluster = (*(it_sc));
std::vector<std::pair<uint32_t, float>> hits_and_fractions;
if constexpr (std::is_same_v<HIT, HGCRecHit>)
hits_and_fractions = simCluster.endcap_hits_and_fractions();
hits_and_fractions = simCluster.filtered_hits_and_fractions(
[this](const DetId& detid) { return !recHitTools_->isBarrel(detid); });
else
hits_and_fractions = simCluster.barrel_hits_and_fractions();
hits_and_fractions = simCluster.filtered_hits_and_fractions(
[this](const DetId& detid) { return recHitTools_->isBarrel(detid); });
for (const auto& it_haf : hits_and_fractions) {
const auto hitid = (it_haf.first);
unsigned int cpLayerId = recHitTools_->getLayerWithOffset(hitid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::LCToCPAssociatorByEnergySc
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
hits_label_(ps.getParameter<std::vector<edm::InputTag>>("hits")) {
for (auto &label : hits_label_) {
if constexpr (std::is_same_v<HIT, HGCRecHit>)
hgcal_hits_token_.push_back(consumes<HGCRecHitCollection>(label));
else
hits_token_.push_back(consumes<std::vector<HIT>>(label));
hits_token_.push_back(consumes<std::vector<HIT>>(label));
}

rhtools_ = std::make_shared<hgcal::RecHitTools>();
Expand All @@ -32,37 +29,19 @@ void LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::produce(edm::StreamID
rhtools_->setGeometry(*geom);

std::vector<const HIT *> hits;
if constexpr (std::is_same_v<HIT, HGCRecHit>) {
for (auto &token : hgcal_hits_token_) {
edm::Handle<HGCRecHitCollection> hits_handle;
iEvent.getByToken(token, hits_handle);

// Check handle validity
if (!hits_handle.isValid()) {
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT")
<< "HGCAL Hit collection not available for token. Skipping this collection.";
continue; // Skip invalid handle
}
for (unsigned i = 0; i < hits_token_.size(); ++i) {
auto hits_handle = iEvent.getHandle(hits_token_[i]);

for (const auto &hit : *hits_handle) {
hits.push_back(&hit);
}
// Check handle validity
if (!hits_handle.isValid()) {
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducer")
<< "Hit collection not available for token " << hits_label_[i] << ". Skipping this collection.";
continue; // Skip invalid handle
}
} else {
for (auto &token : hits_token_) {
edm::Handle<std::vector<HIT>> hits_handle;
iEvent.getByToken(token, hits_handle);

// Check handle validity
if (!hits_handle.isValid()) {
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT")
<< "Barrel Hit collection not available for token. Skipping this collection.";
continue; // Skip invalid handle
}

for (const auto &hit : *hits_handle) {
hits.push_back(&hit);
}
for (const auto &hit : *hits_handle) {
hits.push_back(&hit);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class LCToCPAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<>
const bool hardScatterOnly_;
std::shared_ptr<hgcal::RecHitTools> rhtools_;
std::vector<edm::InputTag> hits_label_;
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_token_;
std::vector<edm::EDGetTokenT<std::vector<HIT>>> hits_token_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@

// user include files
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/Framework/interface/ESHandle.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h"
#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
#include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
Expand All @@ -29,7 +25,6 @@
#include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"

#include "FWCore/Utilities/interface/EDGetToken.h"

//
Expand All @@ -42,11 +37,15 @@ class LCToCPAssociatorEDProducerT : public edm::global::EDProducer<> {
explicit LCToCPAssociatorEDProducerT(const edm::ParameterSet &);
~LCToCPAssociatorEDProducerT() override = default;

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

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

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

edm::InputTag label_lc;

edm::EDGetTokenT<CaloParticleCollection> CPCollectionToken_;
edm::EDGetTokenT<CLUSTER> LCCollectionToken_;
edm::EDGetTokenT<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>> associatorToken_;
Expand All @@ -57,8 +56,10 @@ LCToCPAssociatorEDProducerT<CLUSTER>::LCToCPAssociatorEDProducerT(const edm::Par
produces<ticl::SimToRecoCollectionT<CLUSTER>>();
produces<ticl::RecoToSimCollectionT<CLUSTER>>();

label_lc = pset.getParameter<edm::InputTag>("label_lc");

CPCollectionToken_ = consumes<CaloParticleCollection>(pset.getParameter<edm::InputTag>("label_cp"));
LCCollectionToken_ = consumes<CLUSTER>(pset.getParameter<edm::InputTag>("label_lc"));
LCCollectionToken_ = consumes<CLUSTER>(label_lc);
associatorToken_ =
consumes<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>>(pset.getParameter<edm::InputTag>("associator"));
}
Expand Down Expand Up @@ -95,7 +96,7 @@ void LCToCPAssociatorEDProducerT<CLUSTER>::produce(edm::StreamID,
// Protection against missing cluster collection
if (!LCCollection.isValid()) {
edm::LogWarning("LCToCPAssociatorEDProducerT")
<< "Cluster collection is unavailable. Producing empty associations.";
<< "CaloCluster collection with label " << label_lc << " is unavailable. Producing empty associations.";

// Return empty collections
auto emptyRecSimColl = std::make_unique<ticl::RecoToSimCollectionT<CLUSTER>>();
Expand Down Expand Up @@ -123,9 +124,9 @@ void LCToCPAssociatorEDProducerT<CLUSTER>::produce(edm::StreamID,
template <typename CLUSTER>
void LCToCPAssociatorEDProducerT<CLUSTER>::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("label_cp", edm::InputTag("cpAssocByEnergyScoreProducer"));
desc.add<edm::InputTag>("label_lc", edm::InputTag("mix", "MergedCaloTruth"));
desc.add<edm::InputTag>("associator", edm::InputTag("hgcalMergeLayerClusters"));
desc.add<edm::InputTag>("label_cp", edm::InputTag("mix", "MergedCaloTruth"));
desc.add<edm::InputTag>("label_lc", edm::InputTag("hgcalMergeLayerClusters"));
desc.add<edm::InputTag>("associator", edm::InputTag("lcAssocByEnergyScoreProducer"));
descriptions.addWithDefaultLabel(desc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ ticl::association LCToSCAssociatorByEnergyScoreImplT<HIT, CLUSTER>::makeConnecti
for (const auto& scId : sCIndices) {
std::vector<std::pair<uint32_t, float>> hits_and_fractions = simClusters[scId].hits_and_fractions();
if constexpr (std::is_same_v<HIT, HGCRecHit>)
hits_and_fractions = simClusters[scId].endcap_hits_and_fractions();
hits_and_fractions = simClusters[scId].filtered_hits_and_fractions(
[this](const DetId& detid) { return !recHitTools_->isBarrel(detid); });
else
hits_and_fractions = simClusters[scId].barrel_hits_and_fractions();
hits_and_fractions = simClusters[scId].filtered_hits_and_fractions(
[this](const DetId& detid) { return recHitTools_->isBarrel(detid); });
for (const auto& it_haf : hits_and_fractions) {
const auto hitid = (it_haf.first);
unsigned int scLayerId = recHitTools_->getLayer(hitid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ LCToSCAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::LCToSCAssociatorByEnergySc
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
hits_label_(ps.getParameter<std::vector<edm::InputTag>>("hits")) {
for (auto &label : hits_label_) {
if constexpr (std::is_same_v<HIT, HGCRecHit>)
hgcal_hits_token_.push_back(consumes<HGCRecHitCollection>(label));
else
hits_token_.push_back(consumes<std::vector<HIT>>(label));
hits_token_.push_back(consumes<std::vector<HIT>>(label));
}

rhtools_ = std::make_shared<hgcal::RecHitTools>();
Expand All @@ -32,37 +29,19 @@ void LCToSCAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::produce(edm::StreamID
rhtools_->setGeometry(*geom);

std::vector<const HIT *> hits;
if constexpr (std::is_same_v<HIT, HGCRecHit>) {
for (auto &token : hgcal_hits_token_) {
edm::Handle<HGCRecHitCollection> hits_handle;
iEvent.getByToken(token, hits_handle);

// Check handle validity
if (!hits_handle.isValid()) {
edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT")
<< "HGCAL Hit collection not available for token. Skipping this collection.";
continue; // Skip invalid handle
}
for (unsigned i = 0; i < hits_token_.size(); ++i) {
auto hits_handle = iEvent.getHandle(hits_token_[i]);

for (const auto &hit : *hits_handle) {
hits.push_back(&hit);
}
// Check handle validity
if (!hits_handle.isValid()) {
edm::LogWarning("LCToSCAssociatorByEnergyScoreProducer")
<< "Hit collection not available for token " << hits_label_[i] << ". Skipping this collection.";
continue; // Skip invalid handle
}
} else {
for (auto &token : hits_token_) {
edm::Handle<std::vector<HIT>> hits_handle;
iEvent.getByToken(token, hits_handle);

// Check handle validity
if (!hits_handle.isValid()) {
edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT")
<< "Barrel Hit collection not available for token. Skipping this collection.";
continue; // Skip invalid handle
}

for (const auto &hit : *hits_handle) {
hits.push_back(&hit);
}
for (const auto &hit : *hits_handle) {
hits.push_back(&hit);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class LCToSCAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<>
const bool hardScatterOnly_;
std::shared_ptr<hgcal::RecHitTools> rhtools_;
std::vector<edm::InputTag> hits_label_;
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_token_;
std::vector<edm::EDGetTokenT<std::vector<HIT>>> hits_token_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class LCToSCAssociatorEDProducerT : public edm::global::EDProducer<> {
private:
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;

edm::InputTag label_lcl;
edm::InputTag label_scl;

edm::EDGetTokenT<SimClusterCollection> SCCollectionToken_;
edm::EDGetTokenT<CLUSTER> LCCollectionToken_;
edm::EDGetTokenT<ticl::LayerClusterToSimClusterAssociatorT<CLUSTER>> associatorToken_;
Expand All @@ -46,8 +49,11 @@ LCToSCAssociatorEDProducerT<CLUSTER>::LCToSCAssociatorEDProducerT(const edm::Par
produces<ticl::SimToRecoCollectionWithSimClustersT<CLUSTER>>();
produces<ticl::RecoToSimCollectionWithSimClustersT<CLUSTER>>();

SCCollectionToken_ = consumes<SimClusterCollection>(pset.getParameter<edm::InputTag>("label_scl"));
LCCollectionToken_ = consumes<CLUSTER>(pset.getParameter<edm::InputTag>("label_lcl"));
label_lcl = pset.getParameter<edm::InputTag>("label_lcl");
label_scl = pset.getParameter<edm::InputTag>("label_scl");

LCCollectionToken_ = consumes<CLUSTER>(label_lcl);
SCCollectionToken_ = consumes<SimClusterCollection>(label_scl);
associatorToken_ =
consumes<ticl::LayerClusterToSimClusterAssociatorT<CLUSTER>>(pset.getParameter<edm::InputTag>("associator"));
}
Expand Down Expand Up @@ -84,10 +90,14 @@ void LCToSCAssociatorEDProducerT<CLUSTER>::produce(edm::StreamID,
Handle<CLUSTER> LCCollection;
iEvent.getByToken(LCCollectionToken_, LCCollection);

// Protection against missing cluster collection
if (!LCCollection.isValid()) {
// Protections
if (!SCCollection.isValid()) {
edm::LogWarning("LCToSCAssociatorEDProducerT")
<< "Cluster collection is unavailable. Producing empty associations.";
<< "CaloCluster collection with label " << label_scl << " is unavailable. Producing empty associations.";
}
if (!LCCollection.isValid()) {
edm::LogWarning("LCToSCAssociatorEDProducer")
<< "CaloCluster collection with label " << label_lcl << " is unavailable. Producing empty associations.";

// Return empty collections
auto emptyRecSimColl = std::make_unique<ticl::RecoToSimCollectionWithSimClustersT<CLUSTER>>();
Expand Down Expand Up @@ -117,9 +127,9 @@ void LCToSCAssociatorEDProducerT<CLUSTER>::produce(edm::StreamID,
template <typename CLUSTER>
void LCToSCAssociatorEDProducerT<CLUSTER>::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("label_scl", edm::InputTag("scAssocByEnergyScoreProducer"));
desc.add<edm::InputTag>("label_lcl", edm::InputTag("mix", "MergedCaloTruth"));
desc.add<edm::InputTag>("associator", edm::InputTag("hgcalMergeLayerClusters"));
desc.add<edm::InputTag>("label_scl", edm::InputTag("mix", "MergedCaloTruth"));
desc.add<edm::InputTag>("label_lcl", edm::InputTag("hgcalMergeLayerClusters"));
desc.add<edm::InputTag>("associator", edm::InputTag("scAssocByEnergyScoreProducer"));
descriptions.addWithDefaultLabel(desc);
}

Expand Down
Loading