diff --git a/RecoEgamma/EgammaMCTools/plugins/BuildFile.xml b/RecoEgamma/EgammaMCTools/plugins/BuildFile.xml index 23dc7d7d8e660..fdc2a9c83e10b 100644 --- a/RecoEgamma/EgammaMCTools/plugins/BuildFile.xml +++ b/RecoEgamma/EgammaMCTools/plugins/BuildFile.xml @@ -7,5 +7,6 @@ + diff --git a/RecoEgamma/EgammaMCTools/plugins/PFClusterMatchedToPhotonsSelector.cc b/RecoEgamma/EgammaMCTools/plugins/PFClusterMatchedToPhotonsSelector.cc index 62d0e8b0ccacb..3909694c86c8a 100644 --- a/RecoEgamma/EgammaMCTools/plugins/PFClusterMatchedToPhotonsSelector.cc +++ b/RecoEgamma/EgammaMCTools/plugins/PFClusterMatchedToPhotonsSelector.cc @@ -29,11 +29,13 @@ #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/Common/interface/Ref.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" #include "DataFormats/Math/interface/deltaR.h" #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h" @@ -52,6 +54,11 @@ class PFClusterMatchedToPhotonsSelector : public edm::stream::EDProducer<> { edm::EDGetTokenT particleFlowClusterECALToken_; edm::EDGetTokenT associationToken_; edm::EDGetTokenT trackingParticleToken_; + edm::EDGetTokenT recHitsEB_; + edm::EDGetTokenT recHitsEE_; + + const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_; + double matchMaxDR2_; double matchMaxDEDR2_; @@ -60,7 +67,8 @@ class PFClusterMatchedToPhotonsSelector : public edm::stream::EDProducer<> { double volumeZ_EE_; }; -PFClusterMatchedToPhotonsSelector::PFClusterMatchedToPhotonsSelector(const edm::ParameterSet& iConfig) { +PFClusterMatchedToPhotonsSelector::PFClusterMatchedToPhotonsSelector(const edm::ParameterSet& iConfig) + : ecalClusterToolsESGetTokens_{consumesCollector()} { //now do what ever initialization is needed particleFlowClusterECALToken_ = consumes(iConfig.getParameter("pfClustersTag")); @@ -69,6 +77,8 @@ PFClusterMatchedToPhotonsSelector::PFClusterMatchedToPhotonsSelector(const edm:: trackingParticleToken_ = consumes(iConfig.getParameter("trackingParticleTag")); genParticleToken_ = consumes(iConfig.getParameter("genParticleTag")); + recHitsEB_ = consumes(iConfig.getParameter("recHitsEBLabel")); + recHitsEE_ = consumes(iConfig.getParameter("recHitsEELabel")); matchMaxDR2_ = iConfig.getParameter("maxDR2"); matchMaxDEDR2_ = iConfig.getParameter("maxDEDR2"); @@ -77,8 +87,10 @@ PFClusterMatchedToPhotonsSelector::PFClusterMatchedToPhotonsSelector(const edm:: volumeZ_EE_ = iConfig.getParameter("volumeZ_EE"); produces(); - produces(); produces >(); + produces >(); + produces >("PS1"); + produces >("PS2"); } void PFClusterMatchedToPhotonsSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -86,6 +98,8 @@ void PFClusterMatchedToPhotonsSelector::fillDescriptions(edm::ConfigurationDescr desc.add("pfClustersTag", edm::InputTag("particleFlowClusterECAL")); desc.add("trackingParticleTag", edm::InputTag("mix", "MergedTrackTruth")); desc.add("genParticleTag", edm::InputTag("genParticles")); + desc.add("recHitsEBLabel", edm::InputTag("ecalRecHit", "EcalRecHitsEB")); + desc.add("recHitsEELabel", edm::InputTag("ecalRecHit", "EcalRecHitsEE")); desc.add("maxDR2", 0.1 * 0.1); desc.add("maxDEDR2", 0.5 * 0.5); desc.add("volumeZ_EB", 304.5); @@ -99,20 +113,26 @@ void PFClusterMatchedToPhotonsSelector::produce(edm::Event& iEvent, const edm::E edm::Handle associationHandle_; edm::Handle trackingParticleHandle_; edm::Handle genParticleHandle_; + iEvent.getByToken(particleFlowClusterECALToken_, particleFlowClusterECALHandle_); iEvent.getByToken(trackingParticleToken_, trackingParticleHandle_); iEvent.getByToken(genParticleToken_, genParticleHandle_); iEvent.getByToken(associationToken_, associationHandle_); std::unique_ptr out = std::make_unique(); - std::unique_ptr association_out = - std::make_unique(); std::unique_ptr > genmatching_out = std::make_unique >(); + std::unique_ptr > clustersize_out = std::make_unique >(); + std::unique_ptr > energyPS1_out = std::make_unique >(); + std::unique_ptr > energyPS2_out = std::make_unique >(); std::vector genmatching; + std::vector clustersize; + std::vector energyPS1; + std::vector energyPS2; + + EcalClusterLazyTools lazyTool(iEvent, ecalClusterToolsESGetTokens_.get(iSetup), recHitsEB_, recHitsEE_); - size_t iN(0); for (size_t iP = 0; iP < particleFlowClusterECALHandle_->size(); iP++) { auto&& pfCluster = particleFlowClusterECALHandle_->at(iP); bool isMatched = false; @@ -129,6 +149,7 @@ void PFClusterMatchedToPhotonsSelector::produce(edm::Event& iEvent, const edm::E if (trackingParticle.status() != 1) continue; matchedKey = trackingParticle.genParticles().at(0).key(); + float dR2 = reco::deltaR2(trackingParticle, pfCluster.position()); if (dR2 > matchMaxDR2_) continue; @@ -160,23 +181,54 @@ void PFClusterMatchedToPhotonsSelector::produce(edm::Event& iEvent, const edm::E if (isMatched) { out->push_back(pfCluster); - for (size_t i = 0; i < associationHandle_.product()->size(); i++) { - if (associationHandle_.product()->at(i).first == iP) { - association_out->push_back(std::make_pair(iN, associationHandle_.product()->at(i).second)); + double ePS1 = 0, ePS2 = 0; + if (!(pfCluster.layer() == PFLayer::ECAL_BARREL)) { + auto ee_key_val = std::make_pair(iP, edm::Ptr()); + const auto clustops = std::equal_range( + associationHandle_.product()->begin(), associationHandle_.product()->end(), ee_key_val, sortByKey); + for (auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) { + edm::Ptr psclus(i_ps->second); + switch (psclus->layer()) { + case PFLayer::PS1: + ePS1 += psclus->energy(); + break; + case PFLayer::PS2: + ePS2 += psclus->energy(); + break; + default: + break; + } } } + genmatching.push_back(edm::Ref(genParticleHandle_, matchedKey)); + clustersize.push_back(lazyTool.n5x5(pfCluster)); + energyPS1.push_back(ePS1); + energyPS2.push_back(ePS2); } } - std::sort(association_out->begin(), association_out->end(), sortByKey); edm::OrphanHandle pfClusterHandle = iEvent.put(std::move(out)); - iEvent.put(std::move(association_out)); edm::ValueMap::Filler mapFiller(*genmatching_out); mapFiller.insert(pfClusterHandle, genmatching.begin(), genmatching.end()); mapFiller.fill(); iEvent.put(std::move(genmatching_out)); + + edm::ValueMap::Filler mapFiller_int(*clustersize_out); + mapFiller_int.insert(pfClusterHandle, clustersize.begin(), clustersize.end()); + mapFiller_int.fill(); + iEvent.put(std::move(clustersize_out)); + + edm::ValueMap::Filler mapFiller_energyPS1(*energyPS1_out); + mapFiller_energyPS1.insert(pfClusterHandle, energyPS1.begin(), energyPS1.end()); + mapFiller_energyPS1.fill(); + iEvent.put(std::move(energyPS1_out), "PS1"); + + edm::ValueMap::Filler mapFiller_energyPS2(*energyPS2_out); + mapFiller_energyPS2.insert(pfClusterHandle, energyPS2.begin(), energyPS2.end()); + mapFiller_energyPS2.fill(); + iEvent.put(std::move(energyPS2_out), "PS2"); } //define this as a plug-in