diff --git a/DataFormats/Common/interface/ValueMap.h b/DataFormats/Common/interface/ValueMap.h index 7de885f872abb..f6045fee43881 100644 --- a/DataFormats/Common/interface/ValueMap.h +++ b/DataFormats/Common/interface/ValueMap.h @@ -89,7 +89,7 @@ namespace edm { void throwFillSize() const { Exception::throwThis(errors::InvalidReference, "ValueMap::Filler: handle and reference " - "collections should the same size\n"); + "collections should have the same size\n"); } void throwFillID(ProductID id) const { Exception e(errors::InvalidReference); diff --git a/RecoLocalCalo/HGCalRecAlgos/src/RecHitTools.cc b/RecoLocalCalo/HGCalRecAlgos/src/RecHitTools.cc index efcb8e14ca139..20ca94a6a0384 100644 --- a/RecoLocalCalo/HGCalRecAlgos/src/RecHitTools.cc +++ b/RecoLocalCalo/HGCalRecAlgos/src/RecHitTools.cc @@ -519,7 +519,12 @@ bool RecHitTools::isScintillatorFine(const DetId& id) const { return false; } } -bool RecHitTools::isBarrel(const DetId& id) const { return (id.det() == DetId::Ecal || id.det() == DetId::Hcal); } +bool RecHitTools::isBarrel(const DetId& id) const { + return (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) || + (id.det() == DetId::Hcal && id.subdetId() == HcalBarrel) || + (id.det() == DetId::Hcal && id.subdetId() == HcalOuter); +} + bool RecHitTools::isOnlySilicon(const unsigned int layer) const { // HFnose TODO bool isonlysilicon = (layer % bhLastLayer_) < bhOffset_; diff --git a/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc b/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc index a7380435bef18..ac122c61ba1e2 100644 --- a/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc +++ b/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc @@ -62,12 +62,17 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event auto hitMapHGCal = std::make_unique(); // Retrieve collections + assert(hgcal_hits_token_.size() == 3); const auto& ee_hits = evt.getHandle(hgcal_hits_token_[0]); const auto& fh_hits = evt.getHandle(hgcal_hits_token_[1]); const auto& bh_hits = evt.getHandle(hgcal_hits_token_[2]); // Check validity of all handles - if ((ee_hits.isValid()) && (fh_hits.isValid()) && (bh_hits.isValid())) { + if (!ee_hits.isValid() || !fh_hits.isValid() || !bh_hits.isValid()) { + edm::LogWarning("HGCalRecHitMapProducer") + << "One or more HGCal hit collections are unavailable. Returning an empty map."; + evt.put(std::move(hitMapHGCal), "hgcalRecHitMap"); + } else { // TODO may be worth to avoid dependency on the order // of the collections, maybe using a map edm::MultiSpan rechitSpan; @@ -79,30 +84,33 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event const auto recHitDetId = rechitSpan[i].detid(); hitMapHGCal->emplace(recHitDetId, i); } - } else { - edm::LogWarning("HGCalRecHitMapProducer") << "One or more hit collections are unavailable. Returning an empty map."; + + evt.put(std::move(hitMapHGCal), "hgcalRecHitMap"); } - evt.put(std::move(hitMapHGCal), "hgcalRecHitMap"); - - if (!hgcalOnly_) { - auto hitMapBarrel = std::make_unique(); - - // Retrieve collections - const auto& ecal_hits = evt.getHandle(barrel_hits_token_[0]); - const auto& hbhe_hits = evt.getHandle(barrel_hits_token_[1]); - - if ((ecal_hits.isValid()) && (hbhe_hits.isValid())) { - edm::MultiSpan barrelRechitSpan; - barrelRechitSpan.add(*ecal_hits); - barrelRechitSpan.add(*hbhe_hits); - for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) { - const auto recHitDetId = barrelRechitSpan[i].detId(); - hitMapBarrel->emplace(recHitDetId, i); - } - } else { - edm::LogWarning("RecHitMapProducer") - << "One or more barrel hit collections are unavailable. Returning an empty map."; + + if (hgcalOnly_) { + return; + } + + auto hitMapBarrel = std::make_unique(); + + assert(barrel_hits_token_.size() == 2); + const auto& ecal_hits = evt.getHandle(barrel_hits_token_[0]); + const auto& hbhe_hits = evt.getHandle(barrel_hits_token_[1]); + + if (!ecal_hits.isValid() || !hbhe_hits.isValid()) { + edm::LogWarning("HGCalRecHitMapProducer") + << "One or more barrel hit collections are unavailable. Returning an empty map."; + evt.put(std::move(hitMapBarrel), "barrelRecHitMap"); + } else { + edm::MultiSpan barrelRechitSpan; + barrelRechitSpan.add(evt.get(barrel_hits_token_[0])); + barrelRechitSpan.add(evt.get(barrel_hits_token_[1])); + for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) { + const auto recHitDetId = barrelRechitSpan[i].detId(); + hitMapBarrel->emplace(recHitDetId, i); } + evt.put(std::move(hitMapBarrel), "barrelRecHitMap"); } } diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreImpl.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreImpl.cc index 5fb52e52df071..c40d276ed35ec 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreImpl.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreImpl.cc @@ -74,9 +74,11 @@ ticl::association LCToCPAssociatorByEnergyScoreImplT::makeConnecti const SimCluster& simCluster = (*(it_sc)); std::vector> hits_and_fractions; if constexpr (std::is_same_v) - hits_and_fractions = simCluster.endcap_hits_and_fractions(); + hits_and_fractions = simCluster.filtered_hits_and_fractions( + [this](const DetId& detid) { return !recHitTools_->isBarrel(detid); }); else - hits_and_fractions = simCluster.barrel_hits_and_fractions(); + hits_and_fractions = simCluster.filtered_hits_and_fractions( + [this](const DetId& detid) { return recHitTools_->isBarrel(detid); }); for (const auto& it_haf : hits_and_fractions) { const auto hitid = (it_haf.first); unsigned int cpLayerId = recHitTools_->getLayerWithOffset(hitid); diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc index fd0f88f5839f6..288969190b7e8 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc @@ -9,10 +9,7 @@ LCToCPAssociatorByEnergyScoreProducerT::LCToCPAssociatorByEnergySc hardScatterOnly_(ps.getParameter("hardScatterOnly")), hits_label_(ps.getParameter>("hits")) { for (auto &label : hits_label_) { - if constexpr (std::is_same_v) - hgcal_hits_token_.push_back(consumes(label)); - else - hits_token_.push_back(consumes>(label)); + hits_token_.push_back(consumes>(label)); } rhtools_ = std::make_shared(); @@ -32,37 +29,19 @@ void LCToCPAssociatorByEnergyScoreProducerT::produce(edm::StreamID rhtools_->setGeometry(*geom); std::vector hits; - if constexpr (std::is_same_v) { - for (auto &token : hgcal_hits_token_) { - edm::Handle hits_handle; - iEvent.getByToken(token, hits_handle); - // Check handle validity - if (!hits_handle.isValid()) { - edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT") - << "HGCAL Hit collection not available for token. Skipping this collection."; - continue; // Skip invalid handle - } + for (unsigned i = 0; i < hits_token_.size(); ++i) { + auto hits_handle = iEvent.getHandle(hits_token_[i]); - for (const auto &hit : *hits_handle) { - hits.push_back(&hit); - } + // Check handle validity + if (!hits_handle.isValid()) { + edm::LogWarning("LCToCPAssociatorByEnergyScoreProducer") + << "Hit collection not available for token " << hits_label_[i] << ". Skipping this collection."; + continue; // Skip invalid handle } - } else { - for (auto &token : hits_token_) { - edm::Handle> hits_handle; - iEvent.getByToken(token, hits_handle); - - // Check handle validity - if (!hits_handle.isValid()) { - edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT") - << "Barrel Hit collection not available for token. Skipping this collection."; - continue; // Skip invalid handle - } - for (const auto &hit : *hits_handle) { - hits.push_back(&hit); - } + for (const auto &hit : *hits_handle) { + hits.push_back(&hit); } } diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.h b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.h index 9fa906dfb60c5..32c933cd0f058 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.h +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.h @@ -35,7 +35,6 @@ class LCToCPAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<> const bool hardScatterOnly_; std::shared_ptr rhtools_; std::vector hits_label_; - std::vector> hgcal_hits_token_; std::vector>> hits_token_; }; diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorEDProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorEDProducer.cc index 79b37cac5f9c3..1ab593840f0ca 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorEDProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorEDProducer.cc @@ -10,17 +10,13 @@ // user include files #include "FWCore/Framework/interface/global/EDProducer.h" - #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" - #include "FWCore/Framework/interface/ESHandle.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" - #include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h" - #include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h" @@ -29,7 +25,6 @@ #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h" - #include "FWCore/Utilities/interface/EDGetToken.h" // @@ -42,11 +37,15 @@ class LCToCPAssociatorEDProducerT : public edm::global::EDProducer<> { explicit LCToCPAssociatorEDProducerT(const edm::ParameterSet &); ~LCToCPAssociatorEDProducerT() override = default; + // static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; + edm::InputTag label_lc; + edm::EDGetTokenT CPCollectionToken_; edm::EDGetTokenT LCCollectionToken_; edm::EDGetTokenT> associatorToken_; @@ -57,8 +56,10 @@ LCToCPAssociatorEDProducerT::LCToCPAssociatorEDProducerT(const edm::Par produces>(); produces>(); + label_lc = pset.getParameter("label_lc"); + CPCollectionToken_ = consumes(pset.getParameter("label_cp")); - LCCollectionToken_ = consumes(pset.getParameter("label_lc")); + LCCollectionToken_ = consumes(label_lc); associatorToken_ = consumes>(pset.getParameter("associator")); } @@ -95,7 +96,7 @@ void LCToCPAssociatorEDProducerT::produce(edm::StreamID, // Protection against missing cluster collection if (!LCCollection.isValid()) { edm::LogWarning("LCToCPAssociatorEDProducerT") - << "Cluster collection is unavailable. Producing empty associations."; + << "CaloCluster collection with label " << label_lc << " is unavailable. Producing empty associations."; // Return empty collections auto emptyRecSimColl = std::make_unique>(); @@ -123,9 +124,9 @@ void LCToCPAssociatorEDProducerT::produce(edm::StreamID, template void LCToCPAssociatorEDProducerT::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { edm::ParameterSetDescription desc; - desc.add("label_cp", edm::InputTag("cpAssocByEnergyScoreProducer")); - desc.add("label_lc", edm::InputTag("mix", "MergedCaloTruth")); - desc.add("associator", edm::InputTag("hgcalMergeLayerClusters")); + desc.add("label_cp", edm::InputTag("mix", "MergedCaloTruth")); + desc.add("label_lc", edm::InputTag("hgcalMergeLayerClusters")); + desc.add("associator", edm::InputTag("lcAssocByEnergyScoreProducer")); descriptions.addWithDefaultLabel(desc); } diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreImpl.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreImpl.cc index 6044c7f1a7135..7947ba7ad2acc 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreImpl.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreImpl.cc @@ -73,9 +73,11 @@ ticl::association LCToSCAssociatorByEnergyScoreImplT::makeConnecti for (const auto& scId : sCIndices) { std::vector> hits_and_fractions = simClusters[scId].hits_and_fractions(); if constexpr (std::is_same_v) - hits_and_fractions = simClusters[scId].endcap_hits_and_fractions(); + hits_and_fractions = simClusters[scId].filtered_hits_and_fractions( + [this](const DetId& detid) { return !recHitTools_->isBarrel(detid); }); else - hits_and_fractions = simClusters[scId].barrel_hits_and_fractions(); + hits_and_fractions = simClusters[scId].filtered_hits_and_fractions( + [this](const DetId& detid) { return recHitTools_->isBarrel(detid); }); for (const auto& it_haf : hits_and_fractions) { const auto hitid = (it_haf.first); unsigned int scLayerId = recHitTools_->getLayer(hitid); diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc index 932438079096d..c3d90da83be95 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc @@ -9,10 +9,7 @@ LCToSCAssociatorByEnergyScoreProducerT::LCToSCAssociatorByEnergySc hardScatterOnly_(ps.getParameter("hardScatterOnly")), hits_label_(ps.getParameter>("hits")) { for (auto &label : hits_label_) { - if constexpr (std::is_same_v) - hgcal_hits_token_.push_back(consumes(label)); - else - hits_token_.push_back(consumes>(label)); + hits_token_.push_back(consumes>(label)); } rhtools_ = std::make_shared(); @@ -32,37 +29,19 @@ void LCToSCAssociatorByEnergyScoreProducerT::produce(edm::StreamID rhtools_->setGeometry(*geom); std::vector hits; - if constexpr (std::is_same_v) { - for (auto &token : hgcal_hits_token_) { - edm::Handle hits_handle; - iEvent.getByToken(token, hits_handle); - // Check handle validity - if (!hits_handle.isValid()) { - edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT") - << "HGCAL Hit collection not available for token. Skipping this collection."; - continue; // Skip invalid handle - } + for (unsigned i = 0; i < hits_token_.size(); ++i) { + auto hits_handle = iEvent.getHandle(hits_token_[i]); - for (const auto &hit : *hits_handle) { - hits.push_back(&hit); - } + // Check handle validity + if (!hits_handle.isValid()) { + edm::LogWarning("LCToSCAssociatorByEnergyScoreProducer") + << "Hit collection not available for token " << hits_label_[i] << ". Skipping this collection."; + continue; // Skip invalid handle } - } else { - for (auto &token : hits_token_) { - edm::Handle> hits_handle; - iEvent.getByToken(token, hits_handle); - - // Check handle validity - if (!hits_handle.isValid()) { - edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT") - << "Barrel Hit collection not available for token. Skipping this collection."; - continue; // Skip invalid handle - } - for (const auto &hit : *hits_handle) { - hits.push_back(&hit); - } + for (const auto &hit : *hits_handle) { + hits.push_back(&hit); } } diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.h b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.h index 229c0107b83a8..b25da3653a586 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.h +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.h @@ -35,7 +35,6 @@ class LCToSCAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<> const bool hardScatterOnly_; std::shared_ptr rhtools_; std::vector hits_label_; - std::vector> hgcal_hits_token_; std::vector>> hits_token_; }; diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorEDProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorEDProducer.cc index 201bfafc5e91d..98529bcfd129b 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorEDProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorEDProducer.cc @@ -36,6 +36,9 @@ class LCToSCAssociatorEDProducerT : public edm::global::EDProducer<> { private: void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; + edm::InputTag label_lcl; + edm::InputTag label_scl; + edm::EDGetTokenT SCCollectionToken_; edm::EDGetTokenT LCCollectionToken_; edm::EDGetTokenT> associatorToken_; @@ -46,8 +49,11 @@ LCToSCAssociatorEDProducerT::LCToSCAssociatorEDProducerT(const edm::Par produces>(); produces>(); - SCCollectionToken_ = consumes(pset.getParameter("label_scl")); - LCCollectionToken_ = consumes(pset.getParameter("label_lcl")); + label_lcl = pset.getParameter("label_lcl"); + label_scl = pset.getParameter("label_scl"); + + LCCollectionToken_ = consumes(label_lcl); + SCCollectionToken_ = consumes(label_scl); associatorToken_ = consumes>(pset.getParameter("associator")); } @@ -84,10 +90,14 @@ void LCToSCAssociatorEDProducerT::produce(edm::StreamID, Handle LCCollection; iEvent.getByToken(LCCollectionToken_, LCCollection); - // Protection against missing cluster collection - if (!LCCollection.isValid()) { + // Protections + if (!SCCollection.isValid()) { edm::LogWarning("LCToSCAssociatorEDProducerT") - << "Cluster collection is unavailable. Producing empty associations."; + << "CaloCluster collection with label " << label_scl << " is unavailable. Producing empty associations."; + } + if (!LCCollection.isValid()) { + edm::LogWarning("LCToSCAssociatorEDProducer") + << "CaloCluster collection with label " << label_lcl << " is unavailable. Producing empty associations."; // Return empty collections auto emptyRecSimColl = std::make_unique>(); @@ -117,9 +127,9 @@ void LCToSCAssociatorEDProducerT::produce(edm::StreamID, template void LCToSCAssociatorEDProducerT::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { edm::ParameterSetDescription desc; - desc.add("label_scl", edm::InputTag("scAssocByEnergyScoreProducer")); - desc.add("label_lcl", edm::InputTag("mix", "MergedCaloTruth")); - desc.add("associator", edm::InputTag("hgcalMergeLayerClusters")); + desc.add("label_scl", edm::InputTag("mix", "MergedCaloTruth")); + desc.add("label_lcl", edm::InputTag("hgcalMergeLayerClusters")); + desc.add("associator", edm::InputTag("scAssocByEnergyScoreProducer")); descriptions.addWithDefaultLabel(desc); } diff --git a/SimDataFormats/CaloAnalysis/interface/SimCluster.h b/SimDataFormats/CaloAnalysis/interface/SimCluster.h index 71f9b367bce63..3d1bb687a7601 100644 --- a/SimDataFormats/CaloAnalysis/interface/SimCluster.h +++ b/SimDataFormats/CaloAnalysis/interface/SimCluster.h @@ -8,6 +8,7 @@ #include "SimDataFormats/CaloHit/interface/PCaloHit.h" #include "SimDataFormats/Track/interface/SimTrack.h" #include +#include #include "DataFormats/DetId/interface/DetId.h" #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" @@ -193,26 +194,15 @@ class SimCluster { return result; } - /** @brief Returns list of rechit IDs and fractions in the barrel for this SimCluster */ - std::vector> barrel_hits_and_fractions() const { + /** @brief Returns filtered list of rechit IDs and fractions for this SimCluster based on a predicate */ + std::vector> filtered_hits_and_fractions( + const std::function &predicate) const { std::vector> result; for (size_t i = 0; i < hits_.size(); ++i) { DetId detid(hits_[i]); - if (detid.subdetId() != EcalBarrel && detid.subdetId() != HcalBarrel && detid.subdetId() != HcalOuter) - continue; - result.emplace_back(hits_[i], fractions_[i]); - } - return result; - } - - /** @brief Returns list of rechit IDs and fractions in the endcap for this SimCluster */ - std::vector> endcap_hits_and_fractions() const { - std::vector> result; - for (size_t i = 0; i < hits_.size(); ++i) { - DetId detid(hits_[i]); - if (detid.subdetId() == EcalBarrel || detid.subdetId() == HcalBarrel || detid.subdetId() == HcalOuter) - continue; - result.emplace_back(hits_[i], fractions_[i]); + if (predicate(detid)) { + result.emplace_back(hits_[i], fractions_[i]); + } } return result; } diff --git a/Validation/HGCalValidation/interface/BarrelValidator.h b/Validation/HGCalValidation/interface/BarrelValidator.h index 00ddbc9744c89..c1db75980b72c 100644 --- a/Validation/HGCalValidation/interface/BarrelValidator.h +++ b/Validation/HGCalValidation/interface/BarrelValidator.h @@ -74,9 +74,9 @@ class BarrelValidator : public DQMGlobalEDAnalyzer { const bool doCaloParticlePlots_; const bool doCaloParticleSelection_; const bool doSimClustersPlots_; - edm::InputTag label_SimClustersPlots_, label_SimClustersLevel_; + std::string label_SimClustersPlots_, label_SimClustersLevel_; const bool doLayerClustersPlots_; - edm::InputTag label_layerClustersPlots_, label_LCToCPLinking_; + std::string label_layerClustersPlots_, label_LCToCPLinking_; std::vector label_clustersmask; std::vector> labelToken; @@ -94,8 +94,8 @@ class BarrelValidator : public DQMGlobalEDAnalyzer { std::vector>> associatorMapRtSim; std::unique_ptr histoProducerAlgo_; - std::vector barrel_hits_label_; - std::vector>> barrel_hits_tokens_; + std::vector hits_labels_; + std::vector>> hits_tokens_; edm::EDGetTokenT scToCpMapToken_; private: diff --git a/Validation/HGCalValidation/interface/HGCalValidator.h b/Validation/HGCalValidation/interface/HGCalValidator.h index be4524105f43d..4728ec9dada4c 100644 --- a/Validation/HGCalValidation/interface/HGCalValidator.h +++ b/Validation/HGCalValidation/interface/HGCalValidator.h @@ -85,9 +85,9 @@ class HGCalValidator : public DQMGlobalEDAnalyzer { const bool doCaloParticlePlots_; const bool doCaloParticleSelection_; const bool doSimClustersPlots_; - edm::InputTag label_SimClustersPlots_, label_SimClustersLevel_; + std::string label_SimClustersPlots_, label_SimClustersLevel_; const bool doLayerClustersPlots_; - edm::InputTag label_layerClustersPlots_, label_LCToCPLinking_; + std::string label_layerClustersPlots_, label_LCToCPLinking_; const bool doTrackstersPlots_; std::string label_TS_, label_TSbyHitsCP_, label_TSbyHits_, label_TSbyLCsCP_, label_TSbyLCs_; std::vector label_clustersmask; @@ -113,7 +113,7 @@ class HGCalValidator : public DQMGlobalEDAnalyzer { edm::EDGetTokenT> associatorMapSimtR; edm::EDGetTokenT> associatorMapRtSim; std::unique_ptr histoProducerAlgo_; - std::vector hits_label_; + std::vector hits_labels_; std::vector> hits_tokens_; std::unique_ptr candidateVal_; std::vector> tracksterToTracksterAssociatorsTokens_; diff --git a/Validation/HGCalValidation/plugins/BarrelValidator.cc b/Validation/HGCalValidation/plugins/BarrelValidator.cc index 2da8957dae3a7..3d73d7c435cc0 100644 --- a/Validation/HGCalValidation/plugins/BarrelValidator.cc +++ b/Validation/HGCalValidation/plugins/BarrelValidator.cc @@ -71,20 +71,20 @@ BarrelValidator::BarrelValidator(const edm::ParameterSet& pset) doCaloParticlePlots_(pset.getUntrackedParameter("doCaloParticlePlots")), doCaloParticleSelection_(pset.getUntrackedParameter("doCaloParticleSelection")), doSimClustersPlots_(pset.getUntrackedParameter("doSimClustersPlots")), - label_SimClustersPlots_(pset.getParameter("label_SimClusters")), - label_SimClustersLevel_(pset.getParameter("label_SimClustersLevel")), + label_SimClustersPlots_(pset.getParameter("label_SimClusters")), + label_SimClustersLevel_(pset.getParameter("label_SimClustersLevel")), doLayerClustersPlots_(pset.getUntrackedParameter("doLayerClustersPlots")), - label_layerClustersPlots_(pset.getParameter("label_layerClusterPlots")), - label_LCToCPLinking_(pset.getParameter("label_LCToCPLinking")), - barrel_hits_label_(pset.getParameter>("barrel_hits")), + label_layerClustersPlots_(pset.getParameter("label_layerClustersPlots")), + label_LCToCPLinking_(pset.getParameter("label_LCToCPLinking")), + hits_labels_(pset.getParameter>("hits")), scToCpMapToken_( consumes(pset.getParameter("simClustersToCaloParticlesMap"))) { //In this way we can easily generalize to associations between other objects also. const edm::InputTag& label_cp_effic_tag = pset.getParameter("label_cp_effic"); const edm::InputTag& label_cp_fake_tag = pset.getParameter("label_cp_fake"); - for (auto& label : barrel_hits_label_) { - barrel_hits_tokens_.push_back(consumes>(label)); + for (auto& label : hits_labels_) { + hits_tokens_.push_back(consumes>(label)); } label_cp_effic = consumes>(label_cp_effic_tag); @@ -172,13 +172,13 @@ void BarrelValidator::bookHistograms(DQMStore::IBooker& ibook, //Booking histograms concerning with simClusters if (doSimClustersPlots_) { ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_SimClustersPlots_.label() + "/" + label_SimClustersLevel_.label()); + ibook.setCurrentFolder(dirName_ + label_SimClustersPlots_ + "/" + label_SimClustersLevel_); histoProducerAlgo_->bookSimClusterHistos(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_); for (unsigned int ws = 0; ws < label_clustersmask.size(); ws++) { ibook.cd(); InputTag algo = label_clustersmask[ws]; - string dirName = dirName_ + label_SimClustersPlots_.label() + "/"; + string dirName = dirName_ + label_SimClustersPlots_ + "/"; if (!algo.process().empty()) dirName += algo.process() + "_"; LogDebug("BarrelValidator") << dirName << "\n"; @@ -204,15 +204,15 @@ void BarrelValidator::bookHistograms(DQMStore::IBooker& ibook, //Booking histograms concerning with hgcal layer clusters if (doLayerClustersPlots_) { ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/ClusterLevel"); + ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_ + "/ClusterLevel"); histoProducerAlgo_->bookClusterHistos_ClusterLevel(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_); ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/" + label_LCToCPLinking_.label()); + ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_ + "/" + label_LCToCPLinking_); histoProducerAlgo_->bookClusterHistos_LCtoCP_association( ibook, histograms.histoProducerAlgo, totallayers_to_monitor_); ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/CellLevel"); + ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_ + "/CellLevel"); histoProducerAlgo_->bookClusterHistos_CellLevel(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_); } } @@ -281,9 +281,15 @@ void BarrelValidator::dqmAnalyze(const edm::Event& event, const std::unordered_map& barrelHitMap = *barrelHitMapHandle; edm::MultiSpan barrelRechitSpan; - for (const auto& token : barrel_hits_tokens_) { + for (unsigned int i = 0; i < hits_tokens_.size(); ++i) { Handle> hitsHandle; - event.getByToken(token, hitsHandle); + event.getByToken(hits_tokens_[i], hitsHandle); + + if (!hitsHandle.isValid()) { + edm::LogWarning("MissingInput") << "Missing " << hits_labels_[i] << " handle."; + continue; + } + barrelRechitSpan.add(*hitsHandle); } @@ -513,13 +519,7 @@ void BarrelValidator::fillDescriptions(edm::ConfigurationDescriptions& descripti psd1.add("nintZ", 1100); desc.add("histoProducerAlgoBlock", psd1); } - desc.add>("hgcal_hits", - { - edm::InputTag("HGCalRecHit", "HGCEERecHits"), - edm::InputTag("HGCalRecHit", "HGCHEFRecHits"), - edm::InputTag("HGCalRecHit", "HGCHEBRecHits"), - }); - desc.add>("barrel_hits", + desc.add>("hits", { edm::InputTag("particleFlowRecHitECAL"), edm::InputTag("particleFlowRecHitHBHE"), @@ -543,11 +543,11 @@ void BarrelValidator::fillDescriptions(edm::ConfigurationDescriptions& descripti desc.addUntracked("doCaloParticlePlots", true); desc.addUntracked("doCaloParticleSelection", true); desc.addUntracked("doSimClustersPlots", true); - desc.add("label_SimClusters", edm::InputTag("SimClusters")); - desc.add("label_SimClustersLevel", edm::InputTag("ClusterLevel")); + desc.add("label_SimClusters", "SimClusters"); + desc.add("label_SimClustersLevel", "ClusterLevel"); desc.addUntracked("doLayerClustersPlots", true); - desc.add("label_layerClusterPlots", edm::InputTag("hgcalMergeLayerClusters")); - desc.add("label_LCToCPLinking", edm::InputTag("LCToCP_association")); + desc.add("label_layerClustersPlots", "LayerClusters"); + desc.add("label_LCToCPLinking", "LCToCP_association"); desc.add("simClustersToCaloParticlesMap", edm::InputTag("SimClusterToCaloParticleAssociation", "simClusterToCaloParticleMap")); desc.add("label_cp_effic", edm::InputTag("mix", "MergedCaloTruth")); diff --git a/Validation/HGCalValidation/plugins/HGCalValidator.cc b/Validation/HGCalValidation/plugins/HGCalValidator.cc index 48f3651937fb3..2ed59f9f7cf72 100644 --- a/Validation/HGCalValidation/plugins/HGCalValidator.cc +++ b/Validation/HGCalValidation/plugins/HGCalValidator.cc @@ -81,11 +81,11 @@ HGCalValidator::HGCalValidator(const edm::ParameterSet& pset) doCaloParticlePlots_(pset.getUntrackedParameter("doCaloParticlePlots")), doCaloParticleSelection_(pset.getUntrackedParameter("doCaloParticleSelection")), doSimClustersPlots_(pset.getUntrackedParameter("doSimClustersPlots")), - label_SimClustersPlots_(pset.getParameter("label_SimClusters")), - label_SimClustersLevel_(pset.getParameter("label_SimClustersLevel")), + label_SimClustersPlots_(pset.getParameter("label_SimClusters")), + label_SimClustersLevel_(pset.getParameter("label_SimClustersLevel")), doLayerClustersPlots_(pset.getUntrackedParameter("doLayerClustersPlots")), - label_layerClustersPlots_(pset.getParameter("label_layerClusterPlots")), - label_LCToCPLinking_(pset.getParameter("label_LCToCPLinking")), + label_layerClustersPlots_(pset.getParameter("label_layerClustersPlots")), + label_LCToCPLinking_(pset.getParameter("label_LCToCPLinking")), doTrackstersPlots_(pset.getUntrackedParameter("doTrackstersPlots")), label_TS_(pset.getParameter("label_TS")), label_TSbyHitsCP_(pset.getParameter("label_TSbyHitsCP")), @@ -97,7 +97,7 @@ HGCalValidator::HGCalValidator(const edm::ParameterSet& pset) label_candidates_(pset.getParameter("ticlCandidates")), cummatbudinxo_(pset.getParameter("cummatbudinxo")), isTICLv5_(pset.getUntrackedParameter("isticlv5")), - hits_label_(pset.getParameter>("hits")), + hits_labels_(pset.getParameter>("hits")), scToCpMapToken_( consumes(pset.getParameter("simClustersToCaloParticlesMap"))), cutTk_(pset.getParameter("cutTk")) { @@ -105,7 +105,7 @@ HGCalValidator::HGCalValidator(const edm::ParameterSet& pset) const edm::InputTag& label_cp_effic_tag = pset.getParameter("label_cp_effic"); const edm::InputTag& label_cp_fake_tag = pset.getParameter("label_cp_fake"); - for (auto& label : hits_label_) { + for (auto& label : hits_labels_) { hits_tokens_.push_back(consumes(label)); } label_cp_effic = consumes>(label_cp_effic_tag); @@ -233,14 +233,14 @@ void HGCalValidator::bookHistograms(DQMStore::IBooker& ibook, //Booking histograms concerning with simClusters if (doSimClustersPlots_) { ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_SimClustersPlots_.label() + "/" + label_SimClustersLevel_.label()); + ibook.setCurrentFolder(dirName_ + label_SimClustersPlots_ + "/" + label_SimClustersLevel_); histoProducerAlgo_->bookSimClusterHistos( ibook, histograms.histoProducerAlgo, totallayers_to_monitor_, thicknesses_to_monitor_); for (unsigned int ws = 0; ws < label_clustersmask.size(); ws++) { ibook.cd(); InputTag algo = label_clustersmask[ws]; - string dirName = dirName_ + label_SimClustersPlots_.label() + "/"; + string dirName = dirName_ + label_SimClustersPlots_ + "/"; if (!algo.process().empty()) dirName += algo.process() + "_"; LogDebug("HGCalValidator") << dirName << "\n"; @@ -267,19 +267,19 @@ void HGCalValidator::bookHistograms(DQMStore::IBooker& ibook, //Booking histograms concerning with hgcal layer clusters if (doLayerClustersPlots_) { ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/ClusterLevel"); + ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_ + "/ClusterLevel"); histoProducerAlgo_->bookClusterHistos_ClusterLevel(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_, thicknesses_to_monitor_, cummatbudinxo_.fullPath()); ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/" + label_LCToCPLinking_.label()); + ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_ + "/" + label_LCToCPLinking_); histoProducerAlgo_->bookClusterHistos_LCtoCP_association( ibook, histograms.histoProducerAlgo, totallayers_to_monitor_); ibook.cd(); - ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/CellLevel"); + ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_ + "/CellLevel"); histoProducerAlgo_->bookClusterHistos_CellLevel( ibook, histograms.histoProducerAlgo, totallayers_to_monitor_, thicknesses_to_monitor_); } @@ -418,11 +418,14 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, const std::unordered_map& hitMap = *hitMapHandle; edm::MultiSpan rechitSpan; - for (const auto& token : hits_tokens_) { - Handle hitsHandle; - event.getByToken(token, hitsHandle); - if (!hitsHandle.isValid()) + for (unsigned int i = 0; i < hits_tokens_.size(); ++i) { + auto hitsHandle = event.getHandle(hits_tokens_[i]); + + if (!hitsHandle.isValid()) { + edm::LogWarning("MissingInput") << "Missing " << hits_labels_[i] << " handle."; continue; + } + rechitSpan.add(*hitsHandle); } @@ -577,7 +580,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, event.getByToken(label_tstTokens[wml], tracksterHandle); if (!tracksterHandle.isValid()) { - edm::LogWarning("MissinInput") << "Failed to retrieve tracksters for wml index: " << wml; + edm::LogWarning("MissingInput") << "Failed to retrieve tracksters for wml index: " << wml; continue; // Or handle the error as needed } @@ -802,11 +805,11 @@ void HGCalValidator::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.addUntracked("doCaloParticlePlots", true); desc.addUntracked("doCaloParticleSelection", true); desc.addUntracked("doSimClustersPlots", true); - desc.add("label_SimClusters", edm::InputTag("SimClusters")); - desc.add("label_SimClustersLevel", edm::InputTag("ClusterLevel")); + desc.add("label_SimClusters", "SimClusters"); + desc.add("label_SimClustersLevel", "ClusterLevel"); desc.addUntracked("doLayerClustersPlots", true); - desc.add("label_layerClusterPlots", edm::InputTag("hgcalMergeLayerClusters")); - desc.add("label_LCToCPLinking", edm::InputTag("LCToCP_association")); + desc.add("label_layerClustersPlots", "LayerClusters"); + desc.add("label_LCToCPLinking", "LCToCP_association"); desc.addUntracked("doTrackstersPlots", true); desc.add("label_TS", "Morphology"); desc.add("label_TSbyHitsCP", "TSbyHits_CP"); diff --git a/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py b/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py index c50f6846da9e3..b5dc7722cc8ff 100644 --- a/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py +++ b/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py @@ -12,12 +12,12 @@ hltTracksterLabels = _hltTiclIterLabels.copy() hltTracksterLabels.extend(['hltTiclSimTracksters', 'hltTiclSimTracksters_fromCPs']) -hltLcToCP_linking = _hltHgcalValidator.label_LCToCPLinking._InputTag__moduleLabel +hltLcToCP_linking = _hltHgcalValidator.label_LCToCPLinking.value() hltPostProcessorHGCALlayerclusters = _postProcessorHGCALlayerclusters.clone( - subDirs = cms.untracked.vstring(hltPrefix + _hltHgcalValidator.label_layerClusterPlots._InputTag__moduleLabel + '/' + hltLcToCP_linking), + subDirs = cms.untracked.vstring(hltPrefix + _hltHgcalValidator.label_layerClustersPlots.value() + '/' + hltLcToCP_linking), ) -hltSubdirsSim = [hltPrefix + _hltHgcalValidator.label_SimClusters._InputTag__moduleLabel + '/'+iteration+'/' for iteration in hltTracksterLabels] +hltSubdirsSim = [hltPrefix + _hltHgcalValidator.label_SimClusters.value() + '/'+iteration+'/' for iteration in hltTracksterLabels] hltPostProcessorHGCALsimclusters = _postProcessorHGCALsimclusters.clone( subDirs = cms.untracked.vstring(hltSubdirsSim) ) diff --git a/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py b/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py index 1b3a6704d87f6..3dc13b11e9729 100644 --- a/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py +++ b/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py @@ -21,7 +21,7 @@ hits = cms.VInputTag("hltHGCalRecHit:HGCEERecHits", "hltHGCalRecHit:HGCHEFRecHits", "hltHGCalRecHit:HGCHEBRecHits"), hitMap = cms.InputTag("hltRecHitMapProducer","hgcalRecHitMap"), simTrackstersMap = cms.InputTag("hltTiclSimTracksters"), - label_layerClusterPlots = cms.InputTag("hltHgcalMergeLayerClusters"), + label_layerClustersPlots = cms.string("hltHgcalMergeLayerClusters"), label_lcl = cms.InputTag("hltMergeLayerClusters"), label_simTS = cms.InputTag("hltTiclSimTracksters"), label_simTSFromCP = cms.InputTag("hltTiclSimTracksters","fromCPs"), diff --git a/Validation/HGCalValidation/python/PostProcessorBarrel_cfi.py b/Validation/HGCalValidation/python/PostProcessorBarrel_cfi.py index f658bccd6af5f..173a8a71f43fa 100644 --- a/Validation/HGCalValidation/python/PostProcessorBarrel_cfi.py +++ b/Validation/HGCalValidation/python/PostProcessorBarrel_cfi.py @@ -15,9 +15,9 @@ eff_layers.extend(["merge_eta_layer_barrel{} 'LayerCluster Merge Rate vs #eta Layer{}' NumMerge_LayerCluster_Eta_perlayer_barrel{} Denom_LayerCluster_Eta_perlayer_barrel{}".format(i, i, i, i) for i in range(maxlayer)]) eff_layers.extend(["merge_phi_layer_barrel{} 'LayerCluster Merge Rate vs #phi Layer{}' NumMerge_LayerCluster_Phi_perlayer_barrel{} Denom_LayerCluster_Phi_perlayer_barrel{}".format(i, i, i, i) for i in range(maxlayer)]) -lcToCP_linking = barrelValidator.label_LCToCPLinking._InputTag__moduleLabel +lcToCP_linking = barrelValidator.label_LCToCPLinking.value() postProcessorBarrellayerclusters = DQMEDHarvester('DQMGenericClient', - subDirs = cms.untracked.vstring(prefix + barrelValidator.label_layerClusterPlots._InputTag__moduleLabel + '/' + lcToCP_linking), + subDirs = cms.untracked.vstring(prefix + barrelValidator.label_layerClustersPlots.value() + '/' + lcToCP_linking), efficiency = cms.vstring(eff_layers), resolution = cms.vstring(), cumulativeDists = cms.untracked.vstring(), diff --git a/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py b/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py index 5bfade2d97dc6..dc4b7f7514905 100644 --- a/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py +++ b/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py @@ -20,9 +20,9 @@ eff_layers.extend(["merge_eta_layer{:02d} 'LayerCluster Merge Rate vs #eta Layer{:02d} in z-' NumMerge_LayerCluster_Eta_perlayer{:02d} Denom_LayerCluster_Eta_perlayer{:02d}".format(i, i%maxlayerzm+1, i, i) if (i> haf_cp; for (const auto& sc : caloParticle.simClusters()) { - LogDebug("BarrelValidator") << " This sim cluster has " << sc->hits_and_fractions().size() << " simHits and " - << sc->energy() << " energy. " << std::endl; - simHits += sc->hits_and_fractions().size(); - for (auto const& h_and_f : sc->hits_and_fractions()) { + auto barrel_hf = sc->filtered_hits_and_fractions([this](const DetId& x) { return recHitTools_->isBarrel(x); }); + + LogDebug("BarrelValidator") << " This sim cluster has " << barrel_hf.size() << " simHits and " << sc->energy() + << " energy. " << std::endl; + + simHits += barrel_hf.size(); + for (auto const& h_and_f : barrel_hf) { const auto hitDetId = h_and_f.first; const int layerId = recHitTools_->getLayerWithOffset(hitDetId); // set to 0 if matched RecHit not found @@ -789,27 +792,24 @@ void BarrelVHistoProducerAlgo::fill_caloparticle_histos( void BarrelVHistoProducerAlgo::BarrelVHistoProducerAlgo::fill_simCluster_histos( const Histograms& histograms, std::vector const& simClusters, unsigned int layers) const { //To keep track of total num of simClusters per layer - //tnscpl[layerid] - std::vector tnscpl(1000, 0); //tnscpl.clear(); tnscpl.reserve(1000); + std::vector tnscpl(layers, 0); //loop through simClusters for (const auto& sc : simClusters) { //To keep track if we added the simCluster in a specific layer - std::vector occurenceSCinlayer(1000, 0); //[layerid][0 if not added] + std::vector occurenceSCinlayer(layers, 0); //loop through hits of the simCluster - for (const auto& hAndF : sc.hits_and_fractions()) { + for (const auto& hAndF : + sc.filtered_hits_and_fractions([this](const DetId& x) { return recHitTools_->isBarrel(x); })) { const DetId sh_detid = hAndF.first; - if (recHitTools_->isBarrel(sh_detid)) { - //The layer the cluster belongs to. As mentioned in the mapping above, it takes into account -z and +z. - int layerid = recHitTools_->getLayerWithOffset(sh_detid); - //zside that the current cluster belongs to. - if (occurenceSCinlayer[layerid] == 0) { - tnscpl[layerid]++; - } - occurenceSCinlayer[layerid]++; + //The layer the cluster belongs to + int layerid = recHitTools_->getLayerWithOffset(sh_detid); + if (occurenceSCinlayer[layerid] == 0) { + tnscpl[layerid]++; } + occurenceSCinlayer[layerid]++; } //end of loop through hits } //end of loop through SimClusters of the event @@ -1343,8 +1343,7 @@ void BarrelVHistoProducerAlgo::fill_generic_cluster_histos( const ticl::SimToRecoCollectionT& cPOnLayerMap, edm::MultiSpan const& barrelHits) const { //To keep track of total num of layer clusters per layer - //tnlcpl[layerid] - std::vector tnlcpl(1000, 0); //tnlcpl.clear(); tnlcpl.reserve(1000); + std::vector tnlcpl(layers, 0); layerClusters_to_CaloParticles(histograms, clusterHandle, @@ -1359,7 +1358,7 @@ void BarrelVHistoProducerAlgo::fill_generic_cluster_histos( cPOnLayerMap, barrelHits); - std::vector tecpl(1000, 0.0); //tecpl.clear(); tecpl.reserve(1000); + std::vector tecpl(layers, 0.0); // loop through clusters of the event for (const auto& lcId : clusters) { @@ -1370,8 +1369,8 @@ void BarrelVHistoProducerAlgo::fill_generic_cluster_histos( const float lc_en = lcId.energy(); int layerid = recHitTools_->getLayerWithOffset(seedid); //Energy clustered per layer - tecpl[layerid] = tecpl[layerid] + lc_en; - tnlcpl[layerid] = tnlcpl[layerid] + 1; + tecpl[layerid] += lc_en; + tnlcpl[layerid] += 1; } //end of loop through clusters of the event diff --git a/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc b/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc index cf0922149005a..fd05c9106c0e3 100644 --- a/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc +++ b/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc @@ -1490,13 +1490,14 @@ void HGVHistoProducerAlgo::fill_caloparticle_histos(const Histograms& histograms float hitEnergyWeight_invSum = 0; std::vector> haf_cp; for (const auto& sc : caloParticle.simClusters()) { - LogDebug("HGCalValidator") << " This sim cluster has " << sc->hits_and_fractions().size() << " simHits and " - << sc->energy() << " energy. " << std::endl; - simHits += sc->endcap_hits_and_fractions().size(); - for (auto const& h_and_f : sc->endcap_hits_and_fractions()) { + auto endcap_hf = sc->filtered_hits_and_fractions([this](const DetId& x) { return !recHitTools_->isBarrel(x); }); + + LogDebug("HGCalValidator") << " This sim cluster has " << endcap_hf.size() << " simHits and " << sc->energy() + << " energy. " << std::endl; + + simHits += endcap_hf.size(); + for (auto const& h_and_f : endcap_hf) { const auto hitDetId = h_and_f.first; - if (recHitTools_->isBarrel(hitDetId)) - continue; const int layerId = recHitTools_->getLayerWithOffset(hitDetId) + layers * ((recHitTools_->zside(hitDetId) + 1) >> 1) - 1; // set to 0 if matched RecHit not found @@ -1590,8 +1591,7 @@ void HGVHistoProducerAlgo::fill_simCluster_histos(const Histograms& histograms, //+z: 50->99 //To keep track of total num of simClusters per layer - //tnscpl[layerid] - std::vector tnscpl(1000, 0); //tnscpl.clear(); tnscpl.reserve(1000); + std::vector tnscpl(2 * layers, 0); //To keep track of the total num of clusters per thickness in plus and in minus endcaps std::map tnscpthplus; @@ -1621,7 +1621,7 @@ void HGVHistoProducerAlgo::fill_simCluster_histos(const Histograms& histograms, //For the hits thickness of the layer cluster. double thickness = 0.; //To keep track if we added the simCluster in a specific layer - std::vector occurenceSCinlayer(1000, 0); //[layerid][0 if not added] + std::vector occurenceSCinlayer(2 * layers, 0); //[layerid][0 if not added] //loop through hits of the simCluster for (const auto& hAndF : sc.hits_and_fractions()) { @@ -2231,8 +2231,7 @@ void HGVHistoProducerAlgo::fill_generic_cluster_histos( //+z: 52->103 //To keep track of total num of layer clusters per layer - //tnlcpl[layerid] - std::vector tnlcpl(1000, 0); //tnlcpl.clear(); tnlcpl.reserve(1000); + std::vector tnlcpl(2 * layers, 0); //To keep track of the total num of clusters per thickness in plus and in minus endcaps std::map tnlcpthplus; @@ -2263,9 +2262,9 @@ void HGVHistoProducerAlgo::fill_generic_cluster_histos( //To find out the total amount of energy clustered per layer //Initialize with zeros because I see clear gives weird numbers. - std::vector tecpl(1000, 0.0); //tecpl.clear(); tecpl.reserve(1000); + std::vector tecpl(2 * layers, 0.0); //for the longitudinal depth barycenter - std::vector ldbar(1000, 0.0); //ldbar.clear(); ldbar.reserve(1000); + std::vector ldbar(2 * layers, 0.0); // Need to compare with the total amount of energy coming from CaloParticles double caloparteneplus = 0.; @@ -2764,7 +2763,7 @@ void HGVHistoProducerAlgo::fill_trackster_histos( //To keep track of total num of layer clusters per Trackster //tnLcInTstperlaypz[layerid], tnLcInTstperlaymz[layerid] - std::vector tnLcInTstperlay(1000, 0); //+z + std::vector tnLcInTstperlay(2 * layers, 0); //+z //For the layers the Trackster expands to. Will use a set because there would be many //duplicates and then go back to vector for random access, since they say it is faster.