Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29844 from lecriste/HGCalAssociators-merge
RecHit map and CaloParticle-LayerCluster associator
- Loading branch information
Showing
22 changed files
with
1,053 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
RecoLocalCalo/HGCalRecProducers/plugins/HGCalRecHitMapProducer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// user include files | ||
#include <map> | ||
|
||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
|
||
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" | ||
|
||
class HGCalRecHitMapProducer : public edm::global::EDProducer<> { | ||
public: | ||
HGCalRecHitMapProducer(const edm::ParameterSet&); | ||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; | ||
|
||
private: | ||
const edm::EDGetTokenT<HGCRecHitCollection> hits_ee_token_; | ||
const edm::EDGetTokenT<HGCRecHitCollection> hits_fh_token_; | ||
const edm::EDGetTokenT<HGCRecHitCollection> hits_bh_token_; | ||
}; | ||
|
||
DEFINE_FWK_MODULE(HGCalRecHitMapProducer); | ||
|
||
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*>>(); | ||
} | ||
|
||
void HGCalRecHitMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("EEInput", {"HGCalRecHit", "HGCEERecHits"}); | ||
desc.add<edm::InputTag>("FHInput", {"HGCalRecHit", "HGCHEFRecHits"}); | ||
desc.add<edm::InputTag>("BHInput", {"HGCalRecHit", "HGCHEBRecHits"}); | ||
descriptions.add("hgcalRecHitMapProducer", desc); | ||
} | ||
|
||
void HGCalRecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const { | ||
auto hitMap = std::make_unique<std::map<DetId, const HGCRecHit*>>(); | ||
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_); | ||
|
||
for (const auto& hit : ee_hits) { | ||
hitMap->emplace(hit.detid(), &hit); | ||
} | ||
|
||
for (const auto& hit : fh_hits) { | ||
hitMap->emplace(hit.detid(), &hit); | ||
} | ||
|
||
for (const auto& hit : bh_hits) { | ||
hitMap->emplace(hit.detid(), &hit); | ||
} | ||
evt.put(std::move(hitMap)); | ||
} |
7 changes: 7 additions & 0 deletions
7
SimCalorimetry/HGCalAssociatorProducers/plugins/BuildFile.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<use name="FWCore/Framework"/> | ||
<use name="FWCore/PluginManager"/> | ||
<use name="FWCore/ParameterSet"/> | ||
<use name="SimDataFormats/Associations"/> | ||
<use name="RecoLocalCalo/HGCalRecAlgos"/> | ||
<flags EDM_PLUGIN="1"/> | ||
|
526 changes: 526 additions & 0 deletions
526
SimCalorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreImpl.cc
Large diffs are not rendered by default.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
SimCalorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreImpl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Original Author: Marco Rovere | ||
|
||
#include <vector> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <memory> // shared_ptr | ||
|
||
#include "DataFormats/ForwardDetId/interface/HGCalDetId.h" | ||
#include "DataFormats/HGCRecHit/interface/HGCRecHit.h" | ||
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h" | ||
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" | ||
|
||
namespace edm { | ||
class EDProductGetter; | ||
} | ||
|
||
namespace hgcal { | ||
struct detIdInfoInCluster { | ||
bool operator==(const detIdInfoInCluster &o) const { return clusterId == o.clusterId; }; | ||
long unsigned int clusterId; | ||
float fraction; | ||
detIdInfoInCluster(long unsigned int cId, float fr) { | ||
clusterId = cId; | ||
fraction = fr; | ||
} | ||
}; | ||
|
||
struct detIdInfoInMultiCluster { | ||
bool operator==(const detIdInfoInMultiCluster &o) const { return multiclusterId == o.multiclusterId; }; | ||
unsigned int multiclusterId; | ||
long unsigned int clusterId; | ||
float fraction; | ||
}; | ||
|
||
struct caloParticleOnLayer { | ||
unsigned int caloParticleId; | ||
float energy = 0; | ||
std::vector<std::pair<DetId, float>> hits_and_fractions; | ||
std::unordered_map<int, std::pair<float, float>> layerClusterIdToEnergyAndScore; | ||
}; | ||
|
||
typedef std::vector<std::vector<std::pair<unsigned int, float>>> layerClusterToCaloParticle; | ||
typedef std::vector<std::vector<hgcal::caloParticleOnLayer>> caloParticleToLayerCluster; | ||
typedef std::tuple<layerClusterToCaloParticle, caloParticleToLayerCluster> association; | ||
} // namespace hgcal | ||
|
||
class LayerClusterAssociatorByEnergyScoreImpl : public hgcal::LayerClusterToCaloParticleAssociatorBaseImpl { | ||
public: | ||
explicit LayerClusterAssociatorByEnergyScoreImpl(edm::EDProductGetter const &, | ||
bool, | ||
std::shared_ptr<hgcal::RecHitTools>, | ||
const std::map<DetId, const HGCRecHit *> *&); | ||
|
||
hgcal::RecoToSimCollection associateRecoToSim(const edm::Handle<reco::CaloClusterCollection> &cCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const override; | ||
|
||
hgcal::SimToRecoCollection associateSimToReco(const edm::Handle<reco::CaloClusterCollection> &cCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const override; | ||
|
||
private: | ||
const bool hardScatterOnly_; | ||
std::shared_ptr<hgcal::RecHitTools> recHitTools_; | ||
const std::map<DetId, const HGCRecHit *> *hitMap_; | ||
unsigned layers_; | ||
edm::EDProductGetter const *productGetter_; | ||
hgcal::association makeConnections(const edm::Handle<reco::CaloClusterCollection> &cCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const; | ||
}; |
64 changes: 64 additions & 0 deletions
64
...lorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreProducer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Original author: Marco Rovere | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
|
||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
|
||
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h" | ||
#include "LayerClusterAssociatorByEnergyScoreImpl.h" | ||
|
||
class LayerClusterAssociatorByEnergyScoreProducer : public edm::global::EDProducer<> { | ||
public: | ||
explicit LayerClusterAssociatorByEnergyScoreProducer(const edm::ParameterSet &); | ||
~LayerClusterAssociatorByEnergyScoreProducer() override; | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); | ||
|
||
private: | ||
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; | ||
edm::EDGetTokenT<std::map<DetId, const HGCRecHit *>> hitMapToken_; | ||
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"))), | ||
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")) { | ||
rhtools_.reset(new hgcal::RecHitTools()); | ||
|
||
// Register the product | ||
produces<hgcal::LayerClusterToCaloParticleAssociator>(); | ||
} | ||
|
||
LayerClusterAssociatorByEnergyScoreProducer::~LayerClusterAssociatorByEnergyScoreProducer() {} | ||
|
||
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; | ||
|
||
auto impl = std::make_unique<LayerClusterAssociatorByEnergyScoreImpl>( | ||
iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap); | ||
auto toPut = std::make_unique<hgcal::LayerClusterToCaloParticleAssociator>(std::move(impl)); | ||
iEvent.put(std::move(toPut)); | ||
} | ||
|
||
void LayerClusterAssociatorByEnergyScoreProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcRecHitMapProducer")); | ||
desc.add<bool>("hardScatterOnly", true); | ||
|
||
cfg.add("layerClusterAssociatorByEnergyScore", desc); | ||
} | ||
|
||
//define this as a plug-in | ||
DEFINE_FWK_MODULE(LayerClusterAssociatorByEnergyScoreProducer); |
3 changes: 3 additions & 0 deletions
3
SimCalorimetry/HGCalSimProducers/python/hgcHitAssociation_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from SimCalorimetry.HGCalAssociatorProducers.layerClusterAssociatorByEnergyScore_cfi import layerClusterAssociatorByEnergyScore as lcAssocByEnergyScoreProducer | ||
|
||
from RecoLocalCalo.HGCalRecProducers.hgcalRecHitMapProducer_cfi import hgcalRecHitMapProducer as hgcRecHitMapProducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef SimDataFormats_Associations_LayerClusterToCaloParticleAssociator_h | ||
#define SimDataFormats_Associations_LayerClusterToCaloParticleAssociator_h | ||
// Original Author: Marco Rovere | ||
|
||
// system include files | ||
#include <memory> | ||
|
||
// user include files | ||
|
||
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociatorBaseImpl.h" | ||
|
||
// forward declarations | ||
|
||
namespace hgcal { | ||
|
||
class LayerClusterToCaloParticleAssociator { | ||
public: | ||
LayerClusterToCaloParticleAssociator(std::unique_ptr<hgcal::LayerClusterToCaloParticleAssociatorBaseImpl>); | ||
LayerClusterToCaloParticleAssociator() = default; | ||
LayerClusterToCaloParticleAssociator(LayerClusterToCaloParticleAssociator &&) = default; | ||
LayerClusterToCaloParticleAssociator &operator=(LayerClusterToCaloParticleAssociator &&) = default; | ||
~LayerClusterToCaloParticleAssociator() = default; | ||
|
||
// ---------- const member functions --------------------- | ||
/// Associate a LayerCluster to CaloParticles | ||
hgcal::RecoToSimCollection associateRecoToSim(const edm::Handle<reco::CaloClusterCollection> &cCCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const { | ||
return m_impl->associateRecoToSim(cCCH, cPCH); | ||
}; | ||
|
||
/// Associate a CaloParticle to LayerClusters | ||
hgcal::SimToRecoCollection associateSimToReco(const edm::Handle<reco::CaloClusterCollection> &cCCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const { | ||
return m_impl->associateSimToReco(cCCH, cPCH); | ||
} | ||
|
||
private: | ||
LayerClusterToCaloParticleAssociator(const LayerClusterToCaloParticleAssociator &) = delete; // stop default | ||
|
||
const LayerClusterToCaloParticleAssociator &operator=(const LayerClusterToCaloParticleAssociator &) = | ||
delete; // stop default | ||
|
||
// ---------- member data -------------------------------- | ||
std::unique_ptr<LayerClusterToCaloParticleAssociatorBaseImpl> m_impl; | ||
}; | ||
} // namespace hgcal | ||
|
||
#endif |
45 changes: 45 additions & 0 deletions
45
SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociatorBaseImpl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef SimDataFormats_Associations_LayerClusterToCaloParticleAssociatorBaseImpl_h | ||
#define SimDataFormats_Associations_LayerClusterToCaloParticleAssociatorBaseImpl_h | ||
|
||
/** \class LayerClusterToCaloParticleAssociatorBaseImpl | ||
* | ||
* Base class for LayerClusterToCaloParticleAssociators. Methods take as input | ||
* the handle of LayerClusters and the CaloParticle collections and return an | ||
* AssociationMap (oneToManyWithQuality) | ||
* | ||
* \author Marco Rovere | ||
*/ | ||
|
||
#include "DataFormats/Common/interface/Handle.h" | ||
#include "DataFormats/Common/interface/AssociationMap.h" | ||
#include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h" | ||
|
||
#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h" | ||
|
||
namespace hgcal { | ||
|
||
typedef edm::AssociationMap< | ||
edm::OneToManyWithQualityGeneric<CaloParticleCollection, reco::CaloClusterCollection, std::pair<float, float>>> | ||
SimToRecoCollection; | ||
typedef edm::AssociationMap< | ||
edm::OneToManyWithQualityGeneric<reco::CaloClusterCollection, CaloParticleCollection, float>> | ||
RecoToSimCollection; | ||
|
||
class LayerClusterToCaloParticleAssociatorBaseImpl { | ||
public: | ||
/// Constructor | ||
LayerClusterToCaloParticleAssociatorBaseImpl(); | ||
/// Destructor | ||
virtual ~LayerClusterToCaloParticleAssociatorBaseImpl(); | ||
|
||
/// Associate a LayerCluster to CaloParticles | ||
virtual hgcal::RecoToSimCollection associateRecoToSim(const edm::Handle<reco::CaloClusterCollection> &cCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const; | ||
|
||
/// Associate a CaloParticle to LayerClusters | ||
virtual hgcal::SimToRecoCollection associateSimToReco(const edm::Handle<reco::CaloClusterCollection> &cCH, | ||
const edm::Handle<CaloParticleCollection> &cPCH) const; | ||
}; | ||
} // namespace hgcal | ||
|
||
#endif |
7 changes: 7 additions & 0 deletions
7
SimDataFormats/Associations/src/LayerClusterToCaloParticleAssociator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Original Author: Marco Rovere | ||
|
||
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h" | ||
|
||
hgcal::LayerClusterToCaloParticleAssociator::LayerClusterToCaloParticleAssociator( | ||
std::unique_ptr<hgcal::LayerClusterToCaloParticleAssociatorBaseImpl> ptr) | ||
: m_impl(std::move(ptr)) {} |
19 changes: 19 additions & 0 deletions
19
SimDataFormats/Associations/src/LayerClusterToCaloParticleAssociatorBaseImpl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Original Author: Marco Rovere | ||
|
||
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociatorBaseImpl.h" | ||
|
||
namespace hgcal { | ||
LayerClusterToCaloParticleAssociatorBaseImpl::LayerClusterToCaloParticleAssociatorBaseImpl(){}; | ||
LayerClusterToCaloParticleAssociatorBaseImpl::~LayerClusterToCaloParticleAssociatorBaseImpl(){}; | ||
|
||
hgcal::RecoToSimCollection LayerClusterToCaloParticleAssociatorBaseImpl::associateRecoToSim( | ||
const edm::Handle<reco::CaloClusterCollection> &cCCH, const edm::Handle<CaloParticleCollection> &cPCH) const { | ||
return hgcal::RecoToSimCollection(); | ||
} | ||
|
||
hgcal::SimToRecoCollection LayerClusterToCaloParticleAssociatorBaseImpl::associateSimToReco( | ||
const edm::Handle<reco::CaloClusterCollection> &cCCH, const edm::Handle<CaloParticleCollection> &cPCH) const { | ||
return hgcal::SimToRecoCollection(); | ||
} | ||
|
||
} // namespace hgcal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.