Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions RecoHGCal/TICL/plugins/SimTrackstersProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ class SimTrackstersProducer : public edm::stream::EDProducer<> {
const edm::EDGetTokenT<std::vector<CaloParticle>> caloparticles_token_;
const edm::EDGetTokenT<MtdSimTracksterCollection> MTDSimTrackstersToken_;

const edm::EDGetTokenT<ticl::SimToRecoCollectionWithSimClusters> associatorMapSimClusterToReco_token_;
const edm::EDGetTokenT<ticl::SimToRecoCollection> associatorMapCaloParticleToReco_token_;
const edm::EDGetTokenT<ticl::SimToRecoCollectionWithSimClustersT<reco::CaloClusterCollection>>
associatorMapSimClusterToReco_token_;
const edm::EDGetTokenT<ticl::SimToRecoCollectionT<reco::CaloClusterCollection>> associatorMapCaloParticleToReco_token_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geom_token_;
hgcal::RecHitTools rhtools_;
const float fractionCut_;
Expand Down
51 changes: 29 additions & 22 deletions RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,41 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event
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())) {
// TODO may be worth to avoid dependency on the order
// of the collections, maybe using a map
edm::MultiSpan<HGCRecHit> rechitSpan;
rechitSpan.add(*ee_hits);
rechitSpan.add(*fh_hits);
rechitSpan.add(*bh_hits);

for (unsigned int i = 0; i < rechitSpan.size(); ++i) {
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");
return;
}

// TODO may be worth to avoid dependency on the order
// of the collections, maybe using a map
edm::MultiSpan<HGCRecHit> rechitSpan;
rechitSpan.add(*ee_hits);
rechitSpan.add(*fh_hits);
rechitSpan.add(*bh_hits);

for (unsigned int i = 0; i < rechitSpan.size(); ++i) {
const auto recHitDetId = rechitSpan[i].detid();
hitMapHGCal->emplace(recHitDetId, i);
}

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

if (!hgcalOnly_) {
auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();
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);

// 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.";
}
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "DataFormats/HGCRecHit/interface/HGCRecHit.h"
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"

Expand Down Expand Up @@ -64,34 +65,42 @@ namespace ticl {
typedef std::tuple<layerClusterToCaloParticle, caloParticleToLayerCluster> association;
} // namespace ticl

template <typename HIT>
class LCToCPAssociatorByEnergyScoreImpl : public ticl::LayerClusterToCaloParticleAssociatorBaseImpl {
template <typename HIT, typename CLUSTER>
class LCToCPAssociatorByEnergyScoreImplT : public ticl::LayerClusterToCaloParticleAssociatorBaseImplT<CLUSTER> {
public:
explicit LCToCPAssociatorByEnergyScoreImpl(edm::EDProductGetter const &,
bool,
std::shared_ptr<hgcal::RecHitTools>,
const std::unordered_map<DetId, const unsigned int> *,
const std::vector<const HIT *> &hits);
explicit LCToCPAssociatorByEnergyScoreImplT(edm::EDProductGetter const &,
bool,
std::shared_ptr<hgcal::RecHitTools>,
const std::unordered_map<DetId, const unsigned int> *,
const std::vector<const HIT *> &hits);

ticl::RecoToSimCollection associateRecoToSim(const edm::Handle<reco::CaloClusterCollection> &cCH,
const edm::Handle<CaloParticleCollection> &cPCH) const override;
ticl::RecoToSimCollectionT<CLUSTER> associateRecoToSim(
const edm::Handle<CLUSTER> &cCH, const edm::Handle<CaloParticleCollection> &cPCH) const override;

ticl::SimToRecoCollection associateSimToReco(const edm::Handle<reco::CaloClusterCollection> &cCH,
const edm::Handle<CaloParticleCollection> &cPCH) const override;
ticl::SimToRecoCollectionT<CLUSTER> associateSimToReco(
const edm::Handle<CLUSTER> &cCH, const edm::Handle<CaloParticleCollection> &cPCH) const override;

private:
const bool hardScatterOnly_;
std::shared_ptr<hgcal::RecHitTools> recHitTools_;
const std::unordered_map<DetId, const unsigned int> *hitMap_;
unsigned layers_;
edm::EDProductGetter const *productGetter_;
ticl::association makeConnections(const edm::Handle<reco::CaloClusterCollection> &cCH,
ticl::association makeConnections(const edm::Handle<CLUSTER> &cCH,
const edm::Handle<CaloParticleCollection> &cPCH) const;
std::vector<const HIT *> hits_;
};

extern template class LCToCPAssociatorByEnergyScoreImpl<HGCRecHit>;
extern template class LCToCPAssociatorByEnergyScoreImpl<reco::PFRecHit>;
extern template class LCToCPAssociatorByEnergyScoreImplT<HGCRecHit, reco::CaloClusterCollection>;
extern template class LCToCPAssociatorByEnergyScoreImplT<reco::PFRecHit, reco::CaloClusterCollection>;
extern template class LCToCPAssociatorByEnergyScoreImplT<HGCRecHit, reco::PFClusterCollection>;
extern template class LCToCPAssociatorByEnergyScoreImplT<reco::PFRecHit, reco::PFClusterCollection>;

using HGCalLCToCPAssociatorByEnergyScoreImpl = LCToCPAssociatorByEnergyScoreImpl<HGCRecHit>;
using BarrelLCToCPAssociatorByEnergyScoreImpl = LCToCPAssociatorByEnergyScoreImpl<reco::PFRecHit>;
using HGCalLCToCPAssociatorByEnergyScoreImpl =
LCToCPAssociatorByEnergyScoreImplT<HGCRecHit, reco::CaloClusterCollection>;
using BarrelLCToCPAssociatorByEnergyScoreImpl =
LCToCPAssociatorByEnergyScoreImplT<reco::PFRecHit, reco::CaloClusterCollection>;
using HGCalPCToCPAssociatorByEnergyScoreImpl =
LCToCPAssociatorByEnergyScoreImplT<HGCRecHit, reco::CaloClusterCollection>;
using BarrelPCToCPAssociatorByEnergyScoreImpl =
LCToCPAssociatorByEnergyScoreImplT<reco::PFRecHit, reco::CaloClusterCollection>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <memory>

template <typename HIT>
LCToCPAssociatorByEnergyScoreProducer<HIT>::LCToCPAssociatorByEnergyScoreProducer(const edm::ParameterSet &ps)
template <typename HIT, typename CLUSTER>
LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::LCToCPAssociatorByEnergyScoreProducerT(const edm::ParameterSet &ps)
: hitMap_(consumes<std::unordered_map<DetId, const unsigned int>>(ps.getParameter<edm::InputTag>("hitMapTag"))),
caloGeometry_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
Expand All @@ -18,16 +18,16 @@ LCToCPAssociatorByEnergyScoreProducer<HIT>::LCToCPAssociatorByEnergyScoreProduce
rhtools_ = std::make_shared<hgcal::RecHitTools>();

// Register the product
produces<ticl::LayerClusterToCaloParticleAssociator>();
produces<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>>();
}

template <typename HIT>
LCToCPAssociatorByEnergyScoreProducer<HIT>::~LCToCPAssociatorByEnergyScoreProducer() {}
template <typename HIT, typename CLUSTER>
LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::~LCToCPAssociatorByEnergyScoreProducerT() {}

template <typename HIT>
void LCToCPAssociatorByEnergyScoreProducer<HIT>::produce(edm::StreamID,
edm::Event &iEvent,
const edm::EventSetup &es) const {
template <typename HIT, typename CLUSTER>
void LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::produce(edm::StreamID,
edm::Event &iEvent,
const edm::EventSetup &es) const {
edm::ESHandle<CaloGeometry> geom = es.getHandle(caloGeometry_);
rhtools_->setGeometry(*geom);

Expand All @@ -39,8 +39,8 @@ void LCToCPAssociatorByEnergyScoreProducer<HIT>::produce(edm::StreamID,

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

Expand All @@ -55,8 +55,8 @@ void LCToCPAssociatorByEnergyScoreProducer<HIT>::produce(edm::StreamID,

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

Expand All @@ -66,16 +66,30 @@ void LCToCPAssociatorByEnergyScoreProducer<HIT>::produce(edm::StreamID,
}
}

const auto hitMap = &iEvent.get(hitMap_);
if (hits.empty()) {
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT") << "No hits collected. Producing empty associator.";
}

if (!iEvent.getHandle(hitMap_)) {
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT") << "Hit map not valid. Producing empty associator.";

auto impl = std::make_unique<LCToCPAssociatorByEnergyScoreImpl<HIT>>(
const std::unordered_map<DetId, const unsigned int> hitMap; // empty map
auto impl = std::make_unique<LCToCPAssociatorByEnergyScoreImplT<HIT, CLUSTER>>(
iEvent.productGetter(), hardScatterOnly_, rhtools_, &hitMap, hits);
auto emptyAssociator = std::make_unique<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>>(std::move(impl));
iEvent.put(std::move(emptyAssociator));
return;
}

const auto hitMap = &iEvent.get(hitMap_);
auto impl = std::make_unique<LCToCPAssociatorByEnergyScoreImplT<HIT, CLUSTER>>(
iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap, hits);
auto toPut = std::make_unique<ticl::LayerClusterToCaloParticleAssociator>(std::move(impl));
auto toPut = std::make_unique<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>>(std::move(impl));
iEvent.put(std::move(toPut));
}

template <typename HIT>
void LCToCPAssociatorByEnergyScoreProducer<HIT>::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
template <typename HIT, typename CLUSTER>
void LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
edm::ParameterSetDescription desc;
desc.add<bool>("hardScatterOnly", true);
if constexpr (std::is_same_v<HIT, HGCRecHit>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"

template <typename HIT>
class LCToCPAssociatorByEnergyScoreProducer : public edm::global::EDProducer<> {
template <typename HIT, typename CLUSTER>
class LCToCPAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<> {
public:
explicit LCToCPAssociatorByEnergyScoreProducer(const edm::ParameterSet &);
~LCToCPAssociatorByEnergyScoreProducer() override;
explicit LCToCPAssociatorByEnergyScoreProducerT(const edm::ParameterSet &);
~LCToCPAssociatorByEnergyScoreProducerT() override;

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

Expand All @@ -39,12 +39,22 @@ class LCToCPAssociatorByEnergyScoreProducer : public edm::global::EDProducer<> {
std::vector<edm::EDGetTokenT<std::vector<HIT>>> hits_token_;
};

template class LCToCPAssociatorByEnergyScoreProducer<HGCRecHit>;
template class LCToCPAssociatorByEnergyScoreProducer<reco::PFRecHit>;
template class LCToCPAssociatorByEnergyScoreProducerT<HGCRecHit, reco::CaloClusterCollection>;
template class LCToCPAssociatorByEnergyScoreProducerT<reco::PFRecHit, reco::CaloClusterCollection>;
template class LCToCPAssociatorByEnergyScoreProducerT<HGCRecHit, reco::PFClusterCollection>;
template class LCToCPAssociatorByEnergyScoreProducerT<reco::PFRecHit, reco::PFClusterCollection>;

using HGCalLCToCPAssociatorByEnergyScoreProducer = LCToCPAssociatorByEnergyScoreProducer<HGCRecHit>;
using HGCalLCToCPAssociatorByEnergyScoreProducer =
LCToCPAssociatorByEnergyScoreProducerT<HGCRecHit, reco::CaloClusterCollection>;
DEFINE_FWK_MODULE(HGCalLCToCPAssociatorByEnergyScoreProducer);
using BarrelLCToCPAssociatorByEnergyScoreProducer = LCToCPAssociatorByEnergyScoreProducer<reco::PFRecHit>;
using BarrelLCToCPAssociatorByEnergyScoreProducer =
LCToCPAssociatorByEnergyScoreProducerT<reco::PFRecHit, reco::CaloClusterCollection>;
DEFINE_FWK_MODULE(BarrelLCToCPAssociatorByEnergyScoreProducer);
using HGCalPCToCPAssociatorByEnergyScoreProducer =
LCToCPAssociatorByEnergyScoreProducerT<HGCRecHit, reco::PFClusterCollection>;
DEFINE_FWK_MODULE(HGCalPCToCPAssociatorByEnergyScoreProducer);
using BarrelPCToCPAssociatorByEnergyScoreProducer =
LCToCPAssociatorByEnergyScoreProducerT<reco::PFRecHit, reco::PFClusterCollection>;
DEFINE_FWK_MODULE(BarrelPCToCPAssociatorByEnergyScoreProducer);

#endif
Loading