From 716967537b696c443b4a095f0008902ee692dc9f Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Fri, 5 Feb 2021 00:04:22 +0100 Subject: [PATCH] cPIndices function --- .../interface/AssociatorTools.h | 15 +++++++++++++++ .../LayerClusterAssociatorByEnergyScoreImpl.cc | 16 ++++------------ .../HGCalValidation/plugins/HGCalValidator.cc | 15 +++------------ 3 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 SimCalorimetry/HGCalAssociatorProducers/interface/AssociatorTools.h diff --git a/SimCalorimetry/HGCalAssociatorProducers/interface/AssociatorTools.h b/SimCalorimetry/HGCalAssociatorProducers/interface/AssociatorTools.h new file mode 100644 index 0000000000000..1c5113a328147 --- /dev/null +++ b/SimCalorimetry/HGCalAssociatorProducers/interface/AssociatorTools.h @@ -0,0 +1,15 @@ +void removeCPFromPU(const std::vector& caloParticles, std::vector& cPIndices) { + //Consider CaloParticles coming from the hard scatterer + //excluding the PU contribution and save the indices. + for (unsigned int cpId = 0; cpId < caloParticles.size(); ++cpId) { + if (caloParticles[cpId].g4Tracks()[0].eventId().event() != 0 or + caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() != 0) { + LogDebug("HGCalValidator") << "Excluding CaloParticles from event: " + << caloParticles[cpId].g4Tracks()[0].eventId().event() + << " with BX: " << caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() + << std::endl; + continue; + } + cPIndices.emplace_back(cpId); + } +} diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreImpl.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreImpl.cc index bb49fbf40e304..2a63778286cef 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreImpl.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LayerClusterAssociatorByEnergyScoreImpl.cc @@ -7,6 +7,8 @@ #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" +#include "SimCalorimetry/HGCalAssociatorProducers/interface/AssociatorTools.h" + LayerClusterAssociatorByEnergyScoreImpl::LayerClusterAssociatorByEnergyScoreImpl( edm::EDProductGetter const& productGetter, bool hardScatterOnly, @@ -23,21 +25,11 @@ hgcal::association LayerClusterAssociatorByEnergyScoreImpl::makeConnections( const auto& caloParticles = *cPCH.product(); auto nLayerClusters = clusters.size(); //Consider CaloParticles coming from the hard scatterer, excluding the PU contribution. - auto nCaloParticles = caloParticles.size(); std::vector cPIndices; //Consider CaloParticles coming from the hard scatterer //excluding the PU contribution and save the indices. - for (unsigned int cpId = 0; cpId < nCaloParticles; ++cpId) { - if (hardScatterOnly_ && (caloParticles[cpId].g4Tracks()[0].eventId().event() != 0 or - caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() != 0)) { - LogDebug("LayerClusterAssociatorByEnergyScoreImpl") - << "Excluding CaloParticles from event: " << caloParticles[cpId].g4Tracks()[0].eventId().event() - << " with BX: " << caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() << std::endl; - continue; - } - cPIndices.emplace_back(cpId); - } - nCaloParticles = cPIndices.size(); + removeCPFromPU(caloParticles, cPIndices); + auto nCaloParticles = cPIndices.size(); // Initialize cPOnLayer. To be returned outside, since it contains the // information to compute the CaloParticle-To-LayerCluster score. diff --git a/Validation/HGCalValidation/plugins/HGCalValidator.cc b/Validation/HGCalValidation/plugins/HGCalValidator.cc index 26de6d54ad8c4..361ff02650850 100644 --- a/Validation/HGCalValidation/plugins/HGCalValidator.cc +++ b/Validation/HGCalValidation/plugins/HGCalValidator.cc @@ -1,5 +1,7 @@ #include "Validation/HGCalValidation/interface/HGCalValidator.h" +#include "SimCalorimetry/HGCalAssociatorProducers/interface/AssociatorTools.h" + #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -250,21 +252,10 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, histoProducerAlgo_->fill_info_histos(histograms.histoProducerAlgo, totallayers_to_monitor_); } - auto nCaloParticles = caloParticles.size(); std::vector cPIndices; //Consider CaloParticles coming from the hard scatterer //excluding the PU contribution and save the indices. - for (unsigned int cpId = 0; cpId < nCaloParticles; ++cpId) { - if (caloParticles[cpId].g4Tracks()[0].eventId().event() != 0 or - caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() != 0) { - LogDebug("HGCalValidator") << "Excluding CaloParticles from event: " - << caloParticles[cpId].g4Tracks()[0].eventId().event() - << " with BX: " << caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() - << std::endl; - continue; - } - cPIndices.emplace_back(cpId); - } + removeCPFromPU(caloParticles, cPIndices); // ############################################## // fill caloparticles histograms