Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid overflowing firstStrip_ in case of approximated clusters #38735

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DataFormats/SiStripCluster/interface/SiStripCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Iter>
Expand Down
12 changes: 9 additions & 3 deletions DataFormats/SiStripCluster/src/SiStripCluster.cc
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <vector>
#include <memory>
Expand All @@ -23,23 +26,36 @@ class SiStripApprox2Clusters : public edm::global::EDProducer<> {

private:
edm::EDGetTokenT<edmNew::DetSetVector<SiStripApproximateCluster>> clusterToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
};

SiStripApprox2Clusters::SiStripApprox2Clusters(const edm::ParameterSet& conf) {
clusterToken_ = consumes<edmNew::DetSetVector<SiStripApproximateCluster>>(
conf.getParameter<edm::InputTag>("inputApproxClusters"));
tkGeomToken_ = esConsumes();
produces<edmNew::DetSetVector<SiStripCluster>>();
}

void SiStripApprox2Clusters::produce(edm::StreamID id, edm::Event& event, const edm::EventSetup& iSetup) const {
auto result = std::make_unique<edmNew::DetSetVector<SiStripCluster>>();
const auto& clusterCollection = event.get(clusterToken_);

const auto& tkGeom = &iSetup.getData(tkGeomToken_);
const auto tkDets = tkGeom->dets();
mmusich marked this conversation as resolved.
Show resolved Hide resolved

for (const auto& detClusters : clusterCollection) {
edmNew::DetSetVector<SiStripCluster>::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<const StripGeomDetUnit*>(*det)->specificTopology();
nStrips = p.nstrips() - 1;

for (const auto& cluster : detClusters) {
ff.push_back(SiStripCluster(cluster));
ff.push_back(SiStripCluster(cluster, nStrips));
}
}

Expand Down