File indexing completed on 2024-04-06 12:24:52
0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/stream/EDProducer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateIsolation.h"
0007 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
0011 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0012 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0013 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0014 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0015 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
0016 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
0017 #include "RecoEgamma/EgammaTools/interface/HGCalShowerShapeHelper.h"
0018 #include "RecoEgamma/EgammaTools/interface/HGCalClusterTools.h"
0019 #include "RecoEgamma/EgammaTools/interface/EgammaHGCALIDParamDefaults.h"
0020
0021 class EgammaHLTHGCalIDVarProducer : public edm::stream::EDProducer<> {
0022 public:
0023 explicit EgammaHLTHGCalIDVarProducer(const edm::ParameterSet&);
0024 ~EgammaHLTHGCalIDVarProducer() override;
0025
0026 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027 void produce(edm::Event&, const edm::EventSetup&) override;
0028
0029 class PCAAssocMap {
0030 public:
0031 PCAAssocMap(double HGCalShowerShapeHelper::ShowerWidths::*var, const std::string& name) : var_(var), name_(name) {}
0032
0033 void initMap(const edm::Handle<reco::RecoEcalCandidateCollection>& candHandle) {
0034 assocMap_ = std::make_unique<reco::RecoEcalCandidateIsolationMap>(candHandle);
0035 }
0036
0037 void insert(reco::RecoEcalCandidateRef& ref, const HGCalShowerShapeHelper::ShowerWidths& showerWidths) {
0038 assocMap_->insert(ref, showerWidths.*var_);
0039 }
0040
0041 std::unique_ptr<reco::RecoEcalCandidateIsolationMap> releaseMap() { return std::move(assocMap_); }
0042 const std::string& name() const { return name_; }
0043
0044 private:
0045 double HGCalShowerShapeHelper::ShowerWidths::*var_;
0046 std::string name_;
0047 std::unique_ptr<reco::RecoEcalCandidateIsolationMap> assocMap_;
0048 };
0049
0050 private:
0051
0052 float rCylinder_;
0053 float hOverECone_;
0054 std::vector<PCAAssocMap> pcaAssocMaps_;
0055 const edm::EDGetTokenT<reco::RecoEcalCandidateCollection> recoEcalCandidateToken_;
0056 const edm::EDGetTokenT<reco::PFRecHitCollection> hgcalRecHitToken_;
0057 const edm::EDGetTokenT<reco::CaloClusterCollection> layerClusterToken_;
0058 HGCalShowerShapeHelper ssHelper_;
0059 };
0060
0061 EgammaHLTHGCalIDVarProducer::EgammaHLTHGCalIDVarProducer(const edm::ParameterSet& config)
0062 : rCylinder_(config.getParameter<double>("rCylinder")),
0063 hOverECone_(config.getParameter<double>("hOverECone")),
0064 recoEcalCandidateToken_(
0065 consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
0066 hgcalRecHitToken_(consumes<reco::PFRecHitCollection>(config.getParameter<edm::InputTag>("hgcalRecHits"))),
0067 layerClusterToken_(consumes<reco::CaloClusterCollection>(config.getParameter<edm::InputTag>("layerClusters"))),
0068 ssHelper_(consumesCollector()) {
0069 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2xx, "sigma2xx"));
0070 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2yy, "sigma2yy"));
0071 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2zz, "sigma2zz"));
0072 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2xy, "sigma2xy"));
0073 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2yz, "sigma2yz"));
0074 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2zx, "sigma2zx"));
0075 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2uu, "sigma2uu"));
0076 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2vv, "sigma2vv"));
0077 pcaAssocMaps_.emplace_back(PCAAssocMap(&HGCalShowerShapeHelper::ShowerWidths::sigma2ww, "sigma2ww"));
0078
0079 produces<reco::RecoEcalCandidateIsolationMap>("rVar");
0080 produces<reco::RecoEcalCandidateIsolationMap>("hForHOverE");
0081 for (auto& var : pcaAssocMaps_) {
0082 produces<reco::RecoEcalCandidateIsolationMap>(var.name());
0083 }
0084 }
0085
0086 EgammaHLTHGCalIDVarProducer::~EgammaHLTHGCalIDVarProducer() {}
0087
0088 void EgammaHLTHGCalIDVarProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0089 edm::ParameterSetDescription desc;
0090 desc.add<edm::InputTag>("recoEcalCandidateProducer", edm::InputTag("hltL1SeededRecoEcalCandidate"));
0091 desc.add<edm::InputTag>("hgcalRecHits", edm::InputTag("hgcalRecHits"));
0092 desc.add<edm::InputTag>("layerClusters", edm::InputTag("layerClusters"));
0093 desc.add<double>("rCylinder", EgammaHGCALIDParamDefaults::kRCylinder);
0094 desc.add<double>("hOverECone", 0.15);
0095 descriptions.add(("hltEgammaHLTHGCalIDVarProducer"), desc);
0096 }
0097
0098 void EgammaHLTHGCalIDVarProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0099 auto recoEcalCandHandle = iEvent.getHandle(recoEcalCandidateToken_);
0100 const auto& hgcalRecHits = iEvent.get(hgcalRecHitToken_);
0101 const auto& layerClusters = iEvent.get(layerClusterToken_);
0102
0103 ssHelper_.initPerEvent(iSetup, hgcalRecHits);
0104
0105 auto rVarMap = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
0106 auto hForHoverEMap = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
0107 for (auto& pcaMap : pcaAssocMaps_) {
0108 pcaMap.initMap(recoEcalCandHandle);
0109 }
0110
0111 for (size_t candNr = 0; candNr < recoEcalCandHandle->size(); candNr++) {
0112 reco::RecoEcalCandidateRef candRef(recoEcalCandHandle, candNr);
0113 auto ssCalc = ssHelper_.createCalc(*candRef->superCluster());
0114 rVarMap->insert(candRef, ssCalc.getRvar(rCylinder_));
0115
0116 float hForHoverE = HGCalClusterTools::hadEnergyInCone(
0117 candRef->superCluster()->eta(), candRef->superCluster()->phi(), layerClusters, 0., hOverECone_, 0., 0.);
0118 hForHoverEMap->insert(candRef, hForHoverE);
0119 auto pcaWidths = ssCalc.getPCAWidths(rCylinder_);
0120 for (auto& pcaMap : pcaAssocMaps_) {
0121 pcaMap.insert(candRef, pcaWidths);
0122 }
0123 }
0124 iEvent.put(std::move(rVarMap), "rVar");
0125 iEvent.put(std::move(hForHoverEMap), "hForHOverE");
0126 for (auto& pcaMap : pcaAssocMaps_) {
0127 iEvent.put(pcaMap.releaseMap(), pcaMap.name());
0128 }
0129 }
0130
0131 DEFINE_FWK_MODULE(EgammaHLTHGCalIDVarProducer);