diff --git a/RecoHGCal/TICL/plugins/TrackstersFromSimClustersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc similarity index 68% rename from RecoHGCal/TICL/plugins/TrackstersFromSimClustersProducer.cc rename to RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 711def949d955..2e7151b29090d 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: Felice Pantaleo, Leonardo Cristella - felice.pantaleo@cern.ch, leonardo.cristella@cern.ch +// Date: 09/2021 // user include files @@ -29,14 +29,15 @@ #include "TrackstersPCA.h" #include +#include #include #include 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 +58,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"))), @@ -73,11 +74,14 @@ TrackstersFromSimClustersProducer::TrackstersFromSimClustersProducer(const edm:: consumes(ps.getParameter("layerClusterCaloParticleAssociator"))), geom_token_(esConsumes()), fractionCut_(ps.getParameter("fractionCut")) { - produces>(); + produces(); produces>(); + produces("fromCPs"); + produces>("fromCPs"); + produces>>(); } -void TrackstersFromSimClustersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void SimTrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { // hgcalMultiClusters edm::ParameterSetDescription desc; desc.add("detector", "HGCAL"); @@ -95,13 +99,17 @@ void TrackstersFromSimClustersProducer::fillDescriptions(edm::ConfigurationDescr descriptions.addWithDefaultLabel(desc); } -void TrackstersFromSimClustersProducer::produce(edm::Event& evt, const edm::EventSetup& es) { - auto result = std::make_unique>(); +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>(); + 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_); 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_); @@ -111,24 +119,33 @@ 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); + const auto num_simclusters = simclusters.size(); + result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later + const 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]; + + auto regr_energy = cp.energy(); + std::vector scSimTracksterIdx; + scSimTracksterIdx.reserve(cp.simClusters().size()); + + // 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(), *output_mask, *result); - } else { for (const auto& scRef : cp.simClusters()) { const auto& it = simClustersToRecoColl.find(scRef); @@ -148,14 +165,47 @@ void TrackstersFromSimClustersProducer::produce(edm::Event& evt, const edm::Even scRef.id(), *output_mask, *result); + + if (result->empty()) + 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 + addTrackster(cpIndex, + lcVec, + inputClusterMask, + fractionCut_, + regr_energy, + cp.pdgId(), + cp.charge(), + key.id(), + *output_mask_fromCP, + *result_fromCP); + + if (result_fromCP->empty()) + continue; + const auto index = result_fromCP->size() - 1; + if (cpToSc_SimTrackstersMap->find(index) == cpToSc_SimTrackstersMap->end()) { + (*cpToSc_SimTrackstersMap)[index] = scSimTracksterIdx; } } 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"); + evt.put(std::move(cpToSc_SimTrackstersMap)); } 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"),