Skip to content

Commit

Permalink
Merge pull request #29844 from lecriste/HGCalAssociators-merge
Browse files Browse the repository at this point in the history
RecHit map and CaloParticle-LayerCluster associator
  • Loading branch information
cmsbuild committed May 26, 2020
2 parents 8200cc9 + fc6c8aa commit 376764d
Show file tree
Hide file tree
Showing 22 changed files with 1,053 additions and 377 deletions.
4 changes: 4 additions & 0 deletions DataFormats/HGCRecHit/src/classes_def.xml
Expand Up @@ -35,4 +35,8 @@

<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::pair<const DetId,const HGCRecHit*>" />
</lcgdict>
64 changes: 64 additions & 0 deletions RecoLocalCalo/HGCalRecProducers/plugins/HGCalRecHitMapProducer.cc
@@ -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 SimCalorimetry/HGCalAssociatorProducers/plugins/BuildFile.xml
@@ -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"/>

Large diffs are not rendered by default.

@@ -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;
};
@@ -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);
@@ -0,0 +1,3 @@
from SimCalorimetry.HGCalAssociatorProducers.layerClusterAssociatorByEnergyScore_cfi import layerClusterAssociatorByEnergyScore as lcAssocByEnergyScoreProducer

from RecoLocalCalo.HGCalRecProducers.hgcalRecHitMapProducer_cfi import hgcalRecHitMapProducer as hgcRecHitMapProducer
2 changes: 2 additions & 0 deletions SimDataFormats/Associations/BuildFile.xml
@@ -1,5 +1,7 @@
<use name="DataFormats/Common"/>
<use name="DataFormats/RecoCandidate"/>
<use name="DataFormats/CaloRecHit"/>
<use name="SimDataFormats/CaloAnalysis"/>
<use name="clhep"/>
<export>
<lib name="1"/>
Expand Down
@@ -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
@@ -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
@@ -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)) {}
@@ -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
3 changes: 3 additions & 0 deletions SimDataFormats/Associations/src/classes.h
Expand Up @@ -6,6 +6,7 @@
#include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
#include "SimDataFormats/Associations/interface/VertexAssociation.h"
#include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h"
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h"

namespace SimDataFormats_Associations {
struct SimDataFormats_Associations {
Expand All @@ -16,6 +17,8 @@ namespace SimDataFormats_Associations {

edm::Wrapper<reco::VertexToTrackingVertexAssociator> dummy4;

edm::Wrapper<hgcal::LayerClusterToCaloParticleAssociator> dummy5;

reco::VertexSimToRecoCollection vstrc;
reco::VertexSimToRecoCollection::const_iterator vstrci;
edm::Wrapper<reco::VertexSimToRecoCollection> wvstrc;
Expand Down
3 changes: 3 additions & 0 deletions SimDataFormats/Associations/src/classes_def.xml
Expand Up @@ -9,6 +9,9 @@
<class name="reco::VertexToTrackingVertexAssociator" persistent="false"/>
<class name="edm::Wrapper<reco::VertexToTrackingVertexAssociator>" persistent="false"/>

<class name="hgcal::LayerClusterToCaloParticleAssociator" persistent="false"/>
<class name="edm::Wrapper<hgcal::LayerClusterToCaloParticleAssociator>" persistent="false"/>

<class name="reco::VertexSimToRecoCollection" >
<field name="transientMap_" transient="true"/>
</class>
Expand Down
Expand Up @@ -78,6 +78,7 @@
{'TauReco' : ['reco::PFJetRef']},
{'JetReco' : ['reco::.*Jet','reco::.*Jet(Collection|Ref)']},
{'HGCDigi' : ['HGCSample']},
{'HGCRecHit' : ['constHGCRecHit','HGCRecHit']},
{'SiPixelObjects' : ['SiPixelQuality.*']},
]

Expand Down
2 changes: 1 addition & 1 deletion Validation/Configuration/python/autoValidation.py
Expand Up @@ -14,7 +14,7 @@
'miniAODValidation' : ['prevalidationMiniAOD','validationMiniAOD','validationHarvestingMiniAOD'],
'standardValidation' : ['prevalidation','validation','validationHarvesting'],
'standardValidationNoHLT' : ['prevalidationNoHLT','validationNoHLT','validationHarvestingNoHLT'],
'HGCalValidation' : ['', 'globalValidationHGCal', 'hgcalValidatorPostProcessor'],
'HGCalValidation' : ['globalPrevalidationHGCal', 'globalValidationHGCal', 'hgcalValidatorPostProcessor'],
'MTDValidation' : ['', 'globalValidationMTD', 'mtdValidationPostProcessor'],
'OuterTrackerValidation' : ['', 'globalValidationOuterTracker', 'postValidationOuterTracker'],
'ecalValidation_phase2' : ['', 'validationECALPhase2', ''],
Expand Down

0 comments on commit 376764d

Please sign in to comment.