From c41936f5d26fdda71977c453ad8fd0983021a07f Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Sat, 4 Sep 2021 20:02:37 +0200 Subject: [PATCH 1/7] Merge SimTracksters producers --- ...rsProducer.cc => SimTrackstersProducer.cc} | 46 +++++-- .../TrackstersFromCaloParticlesProducer.cc | 123 ------------------ RecoHGCal/TICL/python/SimTracksters_cff.py | 12 +- .../python/HGCalValidator_cfi.py | 2 +- 4 files changed, 40 insertions(+), 143 deletions(-) rename RecoHGCal/TICL/plugins/{TrackstersFromSimClustersProducer.cc => SimTrackstersProducer.cc} (79%) delete mode 100644 RecoHGCal/TICL/plugins/TrackstersFromCaloParticlesProducer.cc diff --git a/RecoHGCal/TICL/plugins/TrackstersFromSimClustersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc similarity index 79% rename from RecoHGCal/TICL/plugins/TrackstersFromSimClustersProducer.cc rename to RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 711def949d955..0f7c49904ed42 100644 --- a/RecoHGCal/TICL/plugins/TrackstersFromSimClustersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -1,5 +1,5 @@ -// Author: Felice Pantaleo - felice.pantaleo@cern.ch -// Date: 02/2021 +// Author: Leonardo Cristella - leonardo.cristella@cern.ch +// Date: 09/2021 // user include files @@ -34,9 +34,9 @@ using namespace ticl; -class TrackstersFromSimClustersProducer : public edm::stream::EDProducer<> { +class SimTrackstersProducer : public edm::stream::EDProducer<> { public: - explicit TrackstersFromSimClustersProducer(const edm::ParameterSet&); + explicit SimTrackstersProducer(const edm::ParameterSet&); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); void produce(edm::Event&, const edm::EventSetup&) override; @@ -57,9 +57,9 @@ class TrackstersFromSimClustersProducer : public edm::stream::EDProducer<> { hgcal::RecHitTools rhtools_; const double fractionCut_; }; -DEFINE_FWK_MODULE(TrackstersFromSimClustersProducer); +DEFINE_FWK_MODULE(SimTrackstersProducer); -TrackstersFromSimClustersProducer::TrackstersFromSimClustersProducer(const edm::ParameterSet& ps) +SimTrackstersProducer::SimTrackstersProducer(const edm::ParameterSet& ps) : detector_(ps.getParameter("detector")), doNose_(detector_ == "HFNose"), clusters_token_(consumes(ps.getParameter("layer_clusters"))), @@ -75,9 +75,11 @@ TrackstersFromSimClustersProducer::TrackstersFromSimClustersProducer(const edm:: fractionCut_(ps.getParameter("fractionCut")) { produces>(); produces>(); + produces>("fromCPs"); + produces>("fromCPs"); } -void TrackstersFromSimClustersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void SimTrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { // hgcalMultiClusters edm::ParameterSetDescription desc; desc.add("detector", "HGCAL"); @@ -95,13 +97,16 @@ void TrackstersFromSimClustersProducer::fillDescriptions(edm::ConfigurationDescr descriptions.addWithDefaultLabel(desc); } -void TrackstersFromSimClustersProducer::produce(edm::Event& evt, const edm::EventSetup& es) { +void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) { auto result = std::make_unique>(); auto output_mask = std::make_unique>(); + auto result_fromCP = std::make_unique>(); + auto output_mask_fromCP = std::make_unique>(); const auto& layerClusters = evt.get(clusters_token_); const auto& layerClustersTimes = evt.get(clustersTime_token_); const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_); output_mask->resize(layerClusters.size(), 1.f); + output_mask_fromCP->resize(layerClusters.size(), 1.f); const auto& simclusters = evt.get(simclusters_token_); const auto& caloparticles = evt.get(caloparticles_token_); @@ -112,11 +117,15 @@ void TrackstersFromSimClustersProducer::produce(edm::Event& evt, const edm::Even const auto& geom = es.getData(geom_token_); rhtools_.setGeometry(geom); auto num_simclusters = simclusters.size(); - result->reserve(num_simclusters); + result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later + auto num_caloparticles = caloparticles.size(); + result_fromCP->reserve(num_caloparticles); for (const auto& [key, lcVec] : caloParticlesToRecoColl) { auto const& cp = *(key); auto cpIndex = &cp - &caloparticles[0]; + + // Create a Trackster from the object entering HGCal if (cp.g4Tracks()[0].crossedBoundary()) { addTrackster(cpIndex, lcVec, @@ -128,7 +137,6 @@ void TrackstersFromSimClustersProducer::produce(edm::Event& evt, const edm::Even key.id(), *output_mask, *result); - } else { for (const auto& scRef : cp.simClusters()) { const auto& it = simClustersToRecoColl.find(scRef); @@ -150,12 +158,30 @@ void TrackstersFromSimClustersProducer::produce(edm::Event& evt, const edm::Even *result); } } + + // Create a Trackster from any CP + addTrackster(cpIndex, + lcVec, + inputClusterMask, + fractionCut_, + cp.g4Tracks()[0].getMomentumAtBoundary().energy(), + cp.pdgId(), + cp.charge(), + key.id(), + *output_mask_fromCP, + *result_fromCP); + } ticl::assignPCAtoTracksters( *result, layerClusters, layerClustersTimes, rhtools_.getPositionLayer(rhtools_.lastLayerEE(doNose_)).z()); result->shrink_to_fit(); + ticl::assignPCAtoTracksters( + *result_fromCP, layerClusters, layerClustersTimes, rhtools_.getPositionLayer(rhtools_.lastLayerEE(doNose_)).z()); + result_fromCP->shrink_to_fit(); evt.put(std::move(result)); evt.put(std::move(output_mask)); + evt.put(std::move(result_fromCP), "fromCPs"); + evt.put(std::move(output_mask_fromCP), "fromCPs"); } diff --git a/RecoHGCal/TICL/plugins/TrackstersFromCaloParticlesProducer.cc b/RecoHGCal/TICL/plugins/TrackstersFromCaloParticlesProducer.cc deleted file mode 100644 index 7d8cfef261f1d..0000000000000 --- a/RecoHGCal/TICL/plugins/TrackstersFromCaloParticlesProducer.cc +++ /dev/null @@ -1,123 +0,0 @@ -// Author: Leonardo Cristella - leonardo.cristella@cern.ch -// Date: 08/2021 - -// user include files - -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" - -#include "DataFormats/CaloRecHit/interface/CaloCluster.h" -#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" - -#include "DataFormats/HGCalReco/interface/Trackster.h" - -#include "DataFormats/Common/interface/ValueMap.h" -#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h" - -#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" -#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" - -#include "RecoHGCal/TICL/interface/commons.h" - -#include "TrackstersPCA.h" -#include -#include -#include - -using namespace ticl; - -class TrackstersFromCaloParticlesProducer : public edm::stream::EDProducer<> { -public: - explicit TrackstersFromCaloParticlesProducer(const edm::ParameterSet&); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - void produce(edm::Event&, const edm::EventSetup&) override; - -private: - std::string detector_; - const bool doNose_ = false; - const edm::EDGetTokenT> clusters_token_; - const edm::EDGetTokenT>> clustersTime_token_; - const edm::EDGetTokenT> filtered_layerclusters_mask_token_; - - const edm::EDGetTokenT> caloparticles_token_; - - const edm::EDGetTokenT associatorMapCaloParticleToReco_token_; - const edm::ESGetToken geom_token_; - hgcal::RecHitTools rhtools_; - const double fractionCut_; -}; -DEFINE_FWK_MODULE(TrackstersFromCaloParticlesProducer); - -TrackstersFromCaloParticlesProducer::TrackstersFromCaloParticlesProducer(const edm::ParameterSet& ps) - : detector_(ps.getParameter("detector")), - doNose_(detector_ == "HFNose"), - clusters_token_(consumes(ps.getParameter("layer_clusters"))), - clustersTime_token_(consumes(ps.getParameter("time_layerclusters"))), - filtered_layerclusters_mask_token_(consumes(ps.getParameter("filtered_mask"))), - caloparticles_token_(consumes(ps.getParameter("caloparticles"))), - associatorMapCaloParticleToReco_token_(consumes(ps.getParameter("associator"))), - geom_token_(esConsumes()), - fractionCut_(ps.getParameter("fractionCut")) { - produces>(); - produces>(); -} - -void TrackstersFromCaloParticlesProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - desc.add("detector", "HGCAL"); - desc.add("layer_clusters", edm::InputTag("hgcalLayerClusters")); - desc.add("time_layerclusters", edm::InputTag("hgcalLayerClusters", "timeLayerCluster")); - desc.add("filtered_mask", edm::InputTag("filteredLayerClustersSimTracksters", "ticlSimTracksters")); - desc.add("caloparticles", edm::InputTag("mix", "MergedCaloTruth")); - desc.add("associator", edm::InputTag("layerClusterCaloParticleAssociationProducer")); - desc.add("fractionCut", 0.); - - descriptions.addWithDefaultLabel(desc); -} - -void TrackstersFromCaloParticlesProducer::produce(edm::Event& evt, const edm::EventSetup& es) { - auto result = std::make_unique>(); - auto output_mask = std::make_unique>(); - const auto& layerClusters = evt.get(clusters_token_); - const auto& layerClustersTimes = evt.get(clustersTime_token_); - const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_); - output_mask->resize(layerClusters.size(), 1.f); - - const auto& caloparticles = evt.get(caloparticles_token_); - - const auto& caloParticlesToRecoColl = evt.get(associatorMapCaloParticleToReco_token_); - - const auto& geom = es.getData(geom_token_); - rhtools_.setGeometry(geom); - result->reserve(caloparticles.size()); - - for (const auto& [key, values] : caloParticlesToRecoColl) { - auto const& cp = *(key); - auto cpIndex = &cp - &caloparticles[0]; - - addTrackster(cpIndex, - values, - inputClusterMask, - fractionCut_, - cp.g4Tracks()[0].getMomentumAtBoundary().energy(), - cp.pdgId(), - cp.charge(), - key.id(), - *output_mask, - *result); - } - - ticl::assignPCAtoTracksters( - *result, layerClusters, layerClustersTimes, rhtools_.getPositionLayer(rhtools_.lastLayerEE(doNose_)).z()); - result->shrink_to_fit(); - - evt.put(std::move(result)); - evt.put(std::move(output_mask)); -} diff --git a/RecoHGCal/TICL/python/SimTracksters_cff.py b/RecoHGCal/TICL/python/SimTracksters_cff.py index cfee090998a9b..7f4d2db7df1e5 100644 --- a/RecoHGCal/TICL/python/SimTracksters_cff.py +++ b/RecoHGCal/TICL/python/SimTracksters_cff.py @@ -1,7 +1,6 @@ import FWCore.ParameterSet.Config as cms -from RecoHGCal.TICL.trackstersFromSimClustersProducer_cfi import trackstersFromSimClustersProducer as _trackstersFromSimClustersProducer -from RecoHGCal.TICL.trackstersFromCaloParticlesProducer_cfi import trackstersFromCaloParticlesProducer as _trackstersFromCaloParticlesProducer +from RecoHGCal.TICL.simTrackstersProducer_cfi import simTrackstersProducer as _simTrackstersProducer from RecoHGCal.TICL.filteredLayerClustersProducer_cfi import filteredLayerClustersProducer as _filteredLayerClustersProducer @@ -15,9 +14,7 @@ iteration_label = "ticlSimTracksters" ) -ticlSimTracksters = _trackstersFromSimClustersProducer.clone( -) -ticlSimTrackstersFromCP = _trackstersFromCaloParticlesProducer.clone( +ticlSimTracksters = _simTrackstersProducer.clone( ) from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 @@ -25,8 +22,5 @@ simclusters = "mixData:MergedCaloTruth", caloparticles = "mixData:MergedCaloTruth", ) -premix_stage2.toModify(ticlSimTrackstersFromCP, - caloparticles = "mixData:MergedCaloTruth", -) -ticlSimTrackstersTask = cms.Task(filteredLayerClustersSimTracksters, ticlSimTracksters, ticlSimTrackstersFromCP) +ticlSimTrackstersTask = cms.Task(filteredLayerClustersSimTracksters, ticlSimTracksters) diff --git a/Validation/HGCalValidation/python/HGCalValidator_cfi.py b/Validation/HGCalValidation/python/HGCalValidator_cfi.py index 811b89f58e9b6..301f285bb8b85 100644 --- a/Validation/HGCalValidation/python/HGCalValidator_cfi.py +++ b/Validation/HGCalValidation/python/HGCalValidator_cfi.py @@ -25,7 +25,7 @@ #2DLayerClusters, PFClusters, Tracksters label_lcl = layerClusterCaloParticleAssociation.label_lc, label_tst = cms.VInputTag(labelTst), - label_simTSFromCP = cms.InputTag("ticlSimTracksters"), + label_simTSFromCP = cms.InputTag("ticlSimTracksters", "fromCPs"), associator = cms.untracked.InputTag("layerClusterCaloParticleAssociationProducer"), From da38030c7b4e0619a1c0208d8da59dba3a16e825 Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Sat, 4 Sep 2021 21:31:33 +0200 Subject: [PATCH 2/7] Improve regressed energy --- RecoHGCal/TICL/plugins/SimTrackstersProducer.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 0f7c49904ed42..cfcfbc78923bc 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -125,13 +125,17 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) auto const& cp = *(key); auto cpIndex = &cp - &caloparticles[0]; + auto regr_energy = cp.energy(); + // Create a Trackster from the object entering HGCal if (cp.g4Tracks()[0].crossedBoundary()) { + regr_energy = cp.g4Tracks()[0].getMomentumAtBoundary().energy(); + addTrackster(cpIndex, lcVec, inputClusterMask, fractionCut_, - cp.g4Tracks()[0].getMomentumAtBoundary().energy(), + regr_energy, cp.pdgId(), cp.charge(), key.id(), @@ -164,7 +168,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) lcVec, inputClusterMask, fractionCut_, - cp.g4Tracks()[0].getMomentumAtBoundary().energy(), + regr_energy, cp.pdgId(), cp.charge(), key.id(), From 15c89d40fe526d723ec4377953e550480a1062bc Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Sun, 5 Sep 2021 23:30:24 +0200 Subject: [PATCH 3/7] Introduce SimTracksters linking --- .../TICL/plugins/SimTrackstersProducer.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index cfcfbc78923bc..229491ec75785 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -29,6 +29,7 @@ #include "TrackstersPCA.h" #include +#include #include #include @@ -73,10 +74,11 @@ SimTrackstersProducer::SimTrackstersProducer(const edm::ParameterSet& ps) consumes(ps.getParameter("layerClusterCaloParticleAssociator"))), geom_token_(esConsumes()), fractionCut_(ps.getParameter("fractionCut")) { - produces>(); + produces(); produces>(); - produces>("fromCPs"); + produces("fromCPs"); produces>("fromCPs"); + produces>>(); } void SimTrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -98,10 +100,11 @@ void SimTrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& des } void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) { - auto result = std::make_unique>(); + auto result = std::make_unique(); auto output_mask = std::make_unique>(); - auto result_fromCP = std::make_unique>(); + auto result_fromCP = std::make_unique(); auto output_mask_fromCP = std::make_unique>(); + auto cpToSc_STS = std::make_unique>>(); const auto& layerClusters = evt.get(clusters_token_); const auto& layerClustersTimes = evt.get(clustersTime_token_); const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_); @@ -117,7 +120,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) const auto& geom = es.getData(geom_token_); rhtools_.setGeometry(geom); auto num_simclusters = simclusters.size(); - result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later + result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later auto num_caloparticles = caloparticles.size(); result_fromCP->reserve(num_caloparticles); @@ -126,6 +129,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) auto cpIndex = &cp - &caloparticles[0]; auto regr_energy = cp.energy(); + std::vector scSTS; // Create a Trackster from the object entering HGCal if (cp.g4Tracks()[0].crossedBoundary()) { @@ -160,6 +164,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) scRef.id(), *output_mask, *result); + scSTS.push_back(result->size() - 1); } } @@ -174,7 +179,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) key.id(), *output_mask_fromCP, *result_fromCP); - + (*cpToSc_STS)[result_fromCP->size() - 1] = scSTS; } ticl::assignPCAtoTracksters( @@ -188,4 +193,5 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) evt.put(std::move(output_mask)); evt.put(std::move(result_fromCP), "fromCPs"); evt.put(std::move(output_mask_fromCP), "fromCPs"); + evt.put(std::move(cpToSc_STS)); } From 13c86d88ad96ad46c5f029e6f9ae1fcd6e2a180b Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Tue, 7 Sep 2021 10:23:04 +0200 Subject: [PATCH 4/7] Improve code readability --- RecoHGCal/TICL/plugins/SimTrackstersProducer.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 229491ec75785..89e77348d9bea 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -1,4 +1,4 @@ -// Author: Leonardo Cristella - leonardo.cristella@cern.ch +// Author: Felice Pantaleo, Leonardo Cristella - felice.pantaleo@cern.ch, leonardo.cristella@cern.ch // Date: 09/2021 // user include files @@ -104,7 +104,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) auto output_mask = std::make_unique>(); auto result_fromCP = std::make_unique(); auto output_mask_fromCP = std::make_unique>(); - auto cpToSc_STS = std::make_unique>>(); + auto cpToSc_SimTrackstersMap = std::make_unique>>(); const auto& layerClusters = evt.get(clusters_token_); const auto& layerClustersTimes = evt.get(clustersTime_token_); const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_); @@ -119,9 +119,9 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) const auto& geom = es.getData(geom_token_); rhtools_.setGeometry(geom); - auto num_simclusters = simclusters.size(); + const auto num_simclusters = simclusters.size(); result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later - auto num_caloparticles = caloparticles.size(); + const auto num_caloparticles = caloparticles.size(); result_fromCP->reserve(num_caloparticles); for (const auto& [key, lcVec] : caloParticlesToRecoColl) { @@ -129,7 +129,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) auto cpIndex = &cp - &caloparticles[0]; auto regr_energy = cp.energy(); - std::vector scSTS; + std::vector scSimTracksterIdx; // Create a Trackster from the object entering HGCal if (cp.g4Tracks()[0].crossedBoundary()) { @@ -164,7 +164,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) scRef.id(), *output_mask, *result); - scSTS.push_back(result->size() - 1); + scSimTracksterIdx.push_back(result->size() - 1); } } @@ -179,7 +179,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) key.id(), *output_mask_fromCP, *result_fromCP); - (*cpToSc_STS)[result_fromCP->size() - 1] = scSTS; + (*cpToSc_SimTrackstersMap)[result_fromCP->size() - 1] = scSimTracksterIdx; } ticl::assignPCAtoTracksters( @@ -193,5 +193,5 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) evt.put(std::move(output_mask)); evt.put(std::move(result_fromCP), "fromCPs"); evt.put(std::move(output_mask_fromCP), "fromCPs"); - evt.put(std::move(cpToSc_STS)); + evt.put(std::move(cpToSc_SimTrackstersMap)); } From 02254017c8596e90de469a9d65a1cf7b2d5a45a6 Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Tue, 7 Sep 2021 11:23:06 +0200 Subject: [PATCH 5/7] Reserve vector --- .../TICL/plugins/SimTrackstersProducer.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 89e77348d9bea..3ef1172a049d5 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -130,6 +130,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) auto regr_energy = cp.energy(); std::vector scSimTracksterIdx; + scSimTracksterIdx.reserve(cp.simClusters()); // Create a Trackster from the object entering HGCal if (cp.g4Tracks()[0].crossedBoundary()) { @@ -164,8 +165,15 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) scRef.id(), *output_mask, *result); - scSimTracksterIdx.push_back(result->size() - 1); + + if (result->size() < 1) + continue; + const auto index = result->size() - 1; + if (std::find(scSimTracksterIdx.begin(), scSimTracksterIdx.end(), index) == scSimTracksterIdx.end()) { + scSimTracksterIdx.emplace_back(index); + } } + scSimTracksterIdx.shrink_to_fit(); } // Create a Trackster from any CP @@ -179,7 +187,13 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) key.id(), *output_mask_fromCP, *result_fromCP); - (*cpToSc_SimTrackstersMap)[result_fromCP->size() - 1] = scSimTracksterIdx; + + if (result_fromCP->size() < 1) + continue; + const auto index = result_fromCP->size() - 1; + if (cpToSc_SimTrackstersMap->find(index) == cpToSc_SimTrackstersMap->end()) { + (*cpToSc_SimTrackstersMap)[index] = scSimTracksterIdx; + } } ticl::assignPCAtoTracksters( From 65b85ce5ce3880f87068945ef47c3bf9595e61a8 Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Tue, 7 Sep 2021 11:33:48 +0200 Subject: [PATCH 6/7] Forgotten .size() --- RecoHGCal/TICL/plugins/SimTrackstersProducer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 3ef1172a049d5..5656d91b99151 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -130,7 +130,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) auto regr_energy = cp.energy(); std::vector scSimTracksterIdx; - scSimTracksterIdx.reserve(cp.simClusters()); + scSimTracksterIdx.reserve(cp.simClusters().size()); // Create a Trackster from the object entering HGCal if (cp.g4Tracks()[0].crossedBoundary()) { From 59798029dec3a7d7af720f0923be565561baeaaa Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Tue, 7 Sep 2021 11:53:59 +0200 Subject: [PATCH 7/7] code-checks --- RecoHGCal/TICL/plugins/SimTrackstersProducer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 5656d91b99151..2e7151b29090d 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -166,7 +166,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) *output_mask, *result); - if (result->size() < 1) + if (result->empty()) continue; const auto index = result->size() - 1; if (std::find(scSimTracksterIdx.begin(), scSimTracksterIdx.end(), index) == scSimTracksterIdx.end()) { @@ -188,7 +188,7 @@ void SimTrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) *output_mask_fromCP, *result_fromCP); - if (result_fromCP->size() < 1) + if (result_fromCP->empty()) continue; const auto index = result_fromCP->size() - 1; if (cpToSc_SimTrackstersMap->find(index) == cpToSc_SimTrackstersMap->end()) {