From 5895157fafbde30fa745f5c1c6e0d06d1d771e9f Mon Sep 17 00:00:00 2001 From: mmusich Date: Fri, 15 Jul 2022 16:22:29 +0200 Subject: [PATCH] avoid overflowing firstStrip_ in case of approximated clusters --- .../SiStripCluster/interface/SiStripCluster.h | 2 +- .../SiStripCluster/src/SiStripCluster.cc | 12 +++++-- .../plugins/SiStripApprox2Clusters.cc | 32 ++++++++++++++----- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/DataFormats/SiStripCluster/interface/SiStripCluster.h b/DataFormats/SiStripCluster/interface/SiStripCluster.h index 23f523f2c3b8f..383e3960f629e 100644 --- a/DataFormats/SiStripCluster/interface/SiStripCluster.h +++ b/DataFormats/SiStripCluster/interface/SiStripCluster.h @@ -38,7 +38,7 @@ class SiStripCluster { firstStrip_ |= mergedValueMask; // if this is a candidate merged cluster } - SiStripCluster(const SiStripApproximateCluster cluster); + SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips); // extend the cluster template diff --git a/DataFormats/SiStripCluster/src/SiStripCluster.cc b/DataFormats/SiStripCluster/src/SiStripCluster.cc index b03ebb025a937..6e3431d9ce9df 100644 --- a/DataFormats/SiStripCluster/src/SiStripCluster.cc +++ b/DataFormats/SiStripCluster/src/SiStripCluster.cc @@ -1,4 +1,4 @@ - +#include "FWCore/Utilities/interface/Likely.h" #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" SiStripCluster::SiStripCluster(const SiStripDigiRange& range) : firstStrip_(range.first->strip()), error_x(-99999.9) { @@ -22,13 +22,19 @@ SiStripCluster::SiStripCluster(const SiStripDigiRange& range) : firstStrip_(rang amplitudes_ = v; } -SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster) : error_x(-99999.9) { +SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips) : error_x(-99999.9) { barycenter_ = cluster.barycenter(); charge_ = cluster.width() * cluster.avgCharge(); amplitudes_.resize(cluster.width(), cluster.avgCharge()); + float halfwidth_ = 0.5f * float(cluster.width()); + //initialize firstStrip_ - firstStrip_ = cluster.barycenter() - cluster.width() / 2; + firstStrip_ = std::max(barycenter_ - halfwidth_, 0.f); + + if UNLIKELY (firstStrip_ + cluster.width() > maxStrips) { + firstStrip_ = maxStrips - cluster.width(); + } } int SiStripCluster::charge() const { diff --git a/RecoLocalTracker/SiStripClusterizer/plugins/SiStripApprox2Clusters.cc b/RecoLocalTracker/SiStripClusterizer/plugins/SiStripApprox2Clusters.cc index a1bd8d382cb2c..ad2bbd85d6aaa 100644 --- a/RecoLocalTracker/SiStripClusterizer/plugins/SiStripApprox2Clusters.cc +++ b/RecoLocalTracker/SiStripClusterizer/plugins/SiStripApprox2Clusters.cc @@ -1,15 +1,18 @@ -#include "FWCore/Framework/interface/MakerMacros.h" +#include "DataFormats/Common/interface/DetSetVector.h" +#include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h" +#include "DataFormats/SiStripCluster/interface/SiStripCluster.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/Framework/interface/global/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/InputTag.h" -#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h" -#include "DataFormats/SiStripCluster/interface/SiStripCluster.h" -#include "DataFormats/Common/interface/DetSetVectorNew.h" -#include "DataFormats/Common/interface/DetSetVector.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include #include @@ -23,11 +26,13 @@ class SiStripApprox2Clusters : public edm::global::EDProducer<> { private: edm::EDGetTokenT> clusterToken_; + edm::ESGetToken tkGeomToken_; }; SiStripApprox2Clusters::SiStripApprox2Clusters(const edm::ParameterSet& conf) { clusterToken_ = consumes>( conf.getParameter("inputApproxClusters")); + tkGeomToken_ = esConsumes(); produces>(); } @@ -35,11 +40,22 @@ void SiStripApprox2Clusters::produce(edm::StreamID id, edm::Event& event, const auto result = std::make_unique>(); const auto& clusterCollection = event.get(clusterToken_); + const auto& tkGeom = &iSetup.getData(tkGeomToken_); + const auto tkDets = tkGeom->dets(); + for (const auto& detClusters : clusterCollection) { edmNew::DetSetVector::FastFiller ff{*result, detClusters.id()}; + unsigned int detId = detClusters.id(); + + uint16_t nStrips{0}; + auto det = std::find_if(tkDets.begin(), tkDets.end(), [detId](auto& elem) -> bool { + return (elem->geographicalId().rawId() == detId); + }); + const StripTopology& p = dynamic_cast(*det)->specificTopology(); + nStrips = p.nstrips() - 1; for (const auto& cluster : detClusters) { - ff.push_back(SiStripCluster(cluster)); + ff.push_back(SiStripCluster(cluster, nStrips)); } }