Skip to content

Commit

Permalink
Merge pull request #47106 from trackreco/mkFitHLT2025
Browse files Browse the repository at this point in the history
Speedup of mkFit hit converters, and introduction of mkFit HLT customization for 2025
  • Loading branch information
cmsbuild authored Jan 17, 2025
2 parents 8429f10 + d578a59 commit 403d6b0
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
import RecoTracker.MkFit.mkFitProducer_cfi as _mkFitProducer_cfi
import RecoTracker.MkFit.mkFitOutputConverter_cfi as _mkFitOutputConverter_cfi
mkFitSiPixelHitsPreSplitting = _mkFitSiPixelHitConverter_cfi.mkFitSiPixelHitConverter.clone(
hits = 'siPixelRecHitsPreSplitting'
hits = 'siPixelRecHitsPreSplitting',
clusters = 'siPixelClustersPreSplitting'
)
mkFitSiStripHits = _mkFitSiStripHitConverter_cfi.mkFitSiStripHitConverter.clone() # TODO: figure out better place for this module?
mkFitEventOfHitsPreSplitting = _mkFitEventOfHitsProducer_cfi.mkFitEventOfHitsProducer.clone(
Expand Down
26 changes: 11 additions & 15 deletions RecoTracker/MkFit/plugins/MkFitEventOfHitsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "Geometry/CommonTopologies/interface/StripTopology.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"

#include "RecoTracker/MkFit/interface/MkFitClusterIndexToHit.h"
#include "RecoTracker/MkFit/interface/MkFitEventOfHits.h"
#include "RecoTracker/MkFit/interface/MkFitGeometry.h"
#include "RecoTracker/MkFit/interface/MkFitHitWrapper.h"
Expand All @@ -39,15 +38,13 @@ class MkFitEventOfHitsProducer : public edm::global::EDProducer<> {
private:
void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;

void fill(const std::vector<const TrackingRecHit*>& hits,
mkfit::EventOfHits& eventOfHits,
const MkFitGeometry& mkFitGeom) const;
void fill(const std::vector<int>& hits, mkfit::EventOfHits& eventOfHits, const MkFitGeometry& mkFitGeom) const;

const edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
const edm::EDGetTokenT<MkFitHitWrapper> pixelHitsToken_;
const edm::EDGetTokenT<MkFitHitWrapper> stripHitsToken_;
const edm::EDGetTokenT<MkFitClusterIndexToHit> pixelClusterIndexToHitToken_;
const edm::EDGetTokenT<MkFitClusterIndexToHit> stripClusterIndexToHitToken_;
const edm::EDGetTokenT<std::vector<int>> pixelLayerIndexToHitToken_;
const edm::EDGetTokenT<std::vector<int>> stripLayerIndexToHitToken_;
const edm::ESGetToken<MkFitGeometry, TrackerRecoGeometryRecord> mkFitGeomToken_;
edm::ESGetToken<SiPixelQuality, SiPixelQualityRcd> pixelQualityToken_;
edm::ESGetToken<SiStripQuality, SiStripQualityRcd> stripQualityToken_;
Expand All @@ -61,8 +58,8 @@ MkFitEventOfHitsProducer::MkFitEventOfHitsProducer(edm::ParameterSet const& iCon
: beamSpotToken_{consumes(iConfig.getParameter<edm::InputTag>("beamSpot"))},
pixelHitsToken_{consumes(iConfig.getParameter<edm::InputTag>("pixelHits"))},
stripHitsToken_{consumes(iConfig.getParameter<edm::InputTag>("stripHits"))},
pixelClusterIndexToHitToken_{consumes(iConfig.getParameter<edm::InputTag>("pixelHits"))},
stripClusterIndexToHitToken_{consumes(iConfig.getParameter<edm::InputTag>("stripHits"))},
pixelLayerIndexToHitToken_{consumes(iConfig.getParameter<edm::InputTag>("pixelHits"))},
stripLayerIndexToHitToken_{consumes(iConfig.getParameter<edm::InputTag>("stripHits"))},
mkFitGeomToken_{esConsumes()},
putToken_{produces<MkFitEventOfHits>()},
usePixelQualityDB_{iConfig.getParameter<bool>("usePixelQualityDB")},
Expand Down Expand Up @@ -171,8 +168,8 @@ void MkFitEventOfHitsProducer::produce(edm::StreamID iID, edm::Event& iEvent, co
mkfit::StdSeq::loadDeads(*eventOfHits, deadvectors);
}

fill(iEvent.get(pixelClusterIndexToHitToken_).hits(), *eventOfHits, mkFitGeom);
fill(iEvent.get(stripClusterIndexToHitToken_).hits(), *eventOfHits, mkFitGeom);
fill(iEvent.get(pixelLayerIndexToHitToken_), *eventOfHits, mkFitGeom);
fill(iEvent.get(stripLayerIndexToHitToken_), *eventOfHits, mkFitGeom);

mkfit::StdSeq::cmssw_LoadHits_End(*eventOfHits);

Expand All @@ -183,13 +180,12 @@ void MkFitEventOfHitsProducer::produce(edm::StreamID iID, edm::Event& iEvent, co
iEvent.emplace(putToken_, std::move(eventOfHits));
}

void MkFitEventOfHitsProducer::fill(const std::vector<const TrackingRecHit*>& hits,
void MkFitEventOfHitsProducer::fill(const std::vector<int>& layerToHits,
mkfit::EventOfHits& eventOfHits,
const MkFitGeometry& mkFitGeom) const {
for (unsigned int i = 0, end = hits.size(); i < end; ++i) {
const auto* hit = hits[i];
if (hit != nullptr) {
const auto ilay = mkFitGeom.mkFitLayerNumber(hit->geographicalId());
for (unsigned int i = 0, end = layerToHits.size(); i < end; ++i) {
const auto ilay = layerToHits[i];
if (ilay >= 0) {
eventOfHits[ilay].registerHit(i);
}
}
Expand Down
41 changes: 27 additions & 14 deletions RecoTracker/MkFit/plugins/MkFitPhase2HitConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
namespace {
class ConvertHitTraitsPhase2 {
public:
using Clusters = Phase2TrackerCluster1DCollectionNew;
using Cluster = Clusters::data_type;

static constexpr bool applyCCC() { return false; }
static std::nullptr_t clusterCharge(const Phase2TrackerRecHit1D& hit, DetId hitId) { return nullptr; }
static float chargeScale(DetId id) { return 0; }
static const Cluster& cluster(const Clusters& prod, unsigned int index) { return prod.data()[index]; }
static std::nullptr_t clusterCharge(const Cluster&, float) { return nullptr; }
static bool passCCC(std::nullptr_t) { return true; }
static void setDetails(mkfit::Hit& mhit, const Phase2TrackerCluster1D& cluster, int shortId, std::nullptr_t) {
mhit.setupAsStrip(shortId, (1 << 8) - 1, cluster.size());
static void setDetails(mkfit::Hit& mhit, const Cluster& clu, int shortId, std::nullptr_t) {
mhit.setupAsStrip(shortId, (1 << 8) - 1, clu.size());
}
};
} // namespace
Expand All @@ -40,31 +45,34 @@ class MkFitPhase2HitConverter : public edm::global::EDProducer<> {
void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;

const edm::EDGetTokenT<Phase2TrackerRecHit1DCollectionNew> siPhase2RecHitToken_;
const edm::EDGetTokenT<Phase2TrackerCluster1DCollectionNew> siPhase2ClusterToken_;
const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> ttrhBuilderToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
const edm::ESGetToken<MkFitGeometry, TrackerRecoGeometryRecord> mkFitGeomToken_;
const edm::EDPutTokenT<MkFitHitWrapper> wrapperPutToken_;
const edm::EDPutTokenT<MkFitClusterIndexToHit> clusterIndexPutToken_;
const edm::EDPutTokenT<std::vector<int>> layerIndexPutToken_;
const edm::EDPutTokenT<std::vector<float>> clusterChargePutToken_;
const ConvertHitTraitsPhase2 convertTraits_;
};

MkFitPhase2HitConverter::MkFitPhase2HitConverter(edm::ParameterSet const& iConfig)
: siPhase2RecHitToken_{consumes<Phase2TrackerRecHit1DCollectionNew>(
iConfig.getParameter<edm::InputTag>("siPhase2Hits"))},
ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
ttopoToken_{esConsumes<TrackerTopology, TrackerTopologyRcd>()},
mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
wrapperPutToken_{produces<MkFitHitWrapper>()},
clusterIndexPutToken_{produces<MkFitClusterIndexToHit>()},
clusterChargePutToken_{produces<std::vector<float>>()},
: siPhase2RecHitToken_{consumes(iConfig.getParameter<edm::InputTag>("hits"))},
siPhase2ClusterToken_{consumes(iConfig.getParameter<edm::InputTag>("clusters"))},
ttrhBuilderToken_{esConsumes(iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
ttopoToken_{esConsumes()},
mkFitGeomToken_{esConsumes()},
wrapperPutToken_{produces()},
clusterIndexPutToken_{produces()},
layerIndexPutToken_{produces()},
clusterChargePutToken_{produces()},
convertTraits_{} {}

void MkFitPhase2HitConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;

desc.add("siPhase2Hits", edm::InputTag{"siPhase2RecHits"});
desc.add("hits", edm::InputTag{"siPhase2RecHits"});
desc.add("clusters", edm::InputTag{"siPhase2Clusters"});
desc.add("ttrhBuilder", edm::ESInputTag{"", "WithTrackAngle"});

descriptions.add("mkFitPhase2HitConverterDefault", desc);
Expand All @@ -77,6 +85,7 @@ void MkFitPhase2HitConverter::produce(edm::StreamID iID, edm::Event& iEvent, con

MkFitHitWrapper hitWrapper;
MkFitClusterIndexToHit clusterIndexToHit;
std::vector<int> layerIndexToHit;
std::vector<float> clusterCharge;

edm::ProductID stripClusterID;
Expand All @@ -85,18 +94,22 @@ void MkFitPhase2HitConverter::produce(edm::StreamID iID, edm::Event& iEvent, con
if (not phase2Hits.empty()) {
stripClusterID = mkfit::convertHits(ConvertHitTraitsPhase2{},
phase2Hits,
iEvent.get(siPhase2ClusterToken_),
hitWrapper.hits(),
clusterIndexToHit.hits(),
layerIndexToHit,
dummy,
ttopo,
ttrhBuilder,
mkFitGeom);
mkFitGeom,
phase2Hits.dataSize());
}

hitWrapper.setClustersID(stripClusterID);

iEvent.emplace(wrapperPutToken_, std::move(hitWrapper));
iEvent.emplace(clusterIndexPutToken_, std::move(clusterIndexToHit));
iEvent.emplace(layerIndexPutToken_, std::move(layerIndexToHit));
iEvent.emplace(clusterChargePutToken_, std::move(clusterCharge));
}

Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/MkFit/plugins/MkFitProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void MkFitProducer::produce(edm::StreamID iID, edm::Event& iEvent, const edm::Ev
stripContainerMask.copyMaskTo(stripMask);
}
} else {
if (mkFitGeom.isPhase1())
if (mkFitGeom.isPhase1() && minGoodStripCharge_ > 0)
stripClusterChargeCut(iEvent.get(stripClusterChargeToken_), stripMask);
}

Expand Down
39 changes: 27 additions & 12 deletions RecoTracker/MkFit/plugins/MkFitSiPixelHitConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@

namespace {
struct ConvertHitTraits {
using Clusters = SiPixelClusterCollectionNew;
using Cluster = Clusters::data_type;

static constexpr bool applyCCC() { return false; }
static std::nullptr_t clusterCharge(const SiPixelRecHit& hit, DetId hitId) { return nullptr; }
static float chargeScale(DetId) { return 0; }
static const Cluster& cluster(const Clusters& prod, unsigned int index) { return prod.data()[index]; }
static std::nullptr_t clusterCharge(const Cluster&, float) { return nullptr; }
static bool passCCC(std::nullptr_t) { return true; }
static void setDetails(mkfit::Hit& mhit, const SiPixelCluster& cluster, int shortId, std::nullptr_t) {
mhit.setupAsPixel(shortId, cluster.sizeX(), cluster.sizeY());
static void setDetails(mkfit::Hit& mhit, const Cluster& clu, int shortId, std::nullptr_t) {
mhit.setupAsPixel(shortId, clu.sizeX(), clu.sizeY());
}
};
} // namespace
Expand All @@ -39,26 +44,30 @@ class MkFitSiPixelHitConverter : public edm::global::EDProducer<> {
void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;

const edm::EDGetTokenT<SiPixelRecHitCollection> pixelRecHitToken_;
const edm::EDGetTokenT<SiPixelClusterCollectionNew> pixelClusterToken_;
const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> ttrhBuilderToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
const edm::ESGetToken<MkFitGeometry, TrackerRecoGeometryRecord> mkFitGeomToken_;
const edm::EDPutTokenT<MkFitHitWrapper> wrapperPutToken_;
const edm::EDPutTokenT<MkFitClusterIndexToHit> clusterIndexPutToken_;
const edm::EDPutTokenT<std::vector<int>> layerIndexPutToken_;
};

MkFitSiPixelHitConverter::MkFitSiPixelHitConverter(edm::ParameterSet const& iConfig)
: pixelRecHitToken_{consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("hits"))},
ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
ttopoToken_{esConsumes<TrackerTopology, TrackerTopologyRcd>()},
mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
wrapperPutToken_{produces<MkFitHitWrapper>()},
clusterIndexPutToken_{produces<MkFitClusterIndexToHit>()} {}
: pixelRecHitToken_{consumes(iConfig.getParameter<edm::InputTag>("hits"))},
pixelClusterToken_{consumes(iConfig.getParameter<edm::InputTag>("clusters"))},
ttrhBuilderToken_{esConsumes(iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
ttopoToken_{esConsumes()},
mkFitGeomToken_{esConsumes()},
wrapperPutToken_{produces()},
clusterIndexPutToken_{produces()},
layerIndexPutToken_{produces()} {}

void MkFitSiPixelHitConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;

desc.add("hits", edm::InputTag{"siPixelRecHits"});
desc.add("clusters", edm::InputTag{"siPixelClusters"});
desc.add("ttrhBuilder", edm::ESInputTag{"", "WithTrackAngle"});

descriptions.addWithDefaultLabel(desc);
Expand All @@ -71,21 +80,27 @@ void MkFitSiPixelHitConverter::produce(edm::StreamID iID, edm::Event& iEvent, co

MkFitHitWrapper hitWrapper;
MkFitClusterIndexToHit clusterIndexToHit;
std::vector<int> layerIndexToHit;

std::vector<float> dummy;
auto const& hits = iEvent.get(pixelRecHitToken_);
auto pixelClusterID = mkfit::convertHits(ConvertHitTraits{},
iEvent.get(pixelRecHitToken_),
hits,
iEvent.get(pixelClusterToken_),
hitWrapper.hits(),
clusterIndexToHit.hits(),
layerIndexToHit,
dummy,
ttopo,
ttrhBuilder,
mkFitGeom);
mkFitGeom,
hits.dataSize());

hitWrapper.setClustersID(pixelClusterID);

iEvent.emplace(wrapperPutToken_, std::move(hitWrapper));
iEvent.emplace(clusterIndexPutToken_, std::move(clusterIndexToHit));
iEvent.emplace(layerIndexPutToken_, std::move(layerIndexToHit));
}

DEFINE_FWK_MODULE(MkFitSiPixelHitConverter);
58 changes: 39 additions & 19 deletions RecoTracker/MkFit/plugins/MkFitSiStripHitConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ namespace {
class ConvertHitTraits {
public:
ConvertHitTraits(float minCharge) : minGoodStripCharge_(minCharge) {}
using Clusters = edmNew::DetSetVector<SiStripCluster>;
using Cluster = Clusters::data_type;

static constexpr bool applyCCC() { return true; }
static float clusterCharge(const SiStripRecHit2D& hit, DetId hitId) {
return siStripClusterTools::chargePerCM(hitId, hit.firstClusterRef().stripCluster());
}
static float chargeScale(DetId id) { return siStripClusterTools::sensorThicknessInverse(id); }
static const Cluster& cluster(const Clusters& prod, unsigned int index) { return prod.data()[index]; }
static float clusterCharge(const Cluster& clu, float scale) { return clu.charge() * scale; }
bool passCCC(float charge) const { return charge > minGoodStripCharge_; }
static void setDetails(mkfit::Hit& mhit, const SiStripCluster& cluster, int shortId, float charge) {
mhit.setupAsStrip(shortId, charge, cluster.amplitudes().size());
static void setDetails(mkfit::Hit& mhit, const Cluster& clu, int shortId, float charge) {
mhit.setupAsStrip(shortId, charge, clu.size());
}

private:
Expand All @@ -49,25 +51,28 @@ class MkFitSiStripHitConverter : public edm::global::EDProducer<> {

const edm::EDGetTokenT<SiStripRecHit2DCollection> stripRphiRecHitToken_;
const edm::EDGetTokenT<SiStripRecHit2DCollection> stripStereoRecHitToken_;
const edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> stripClusterToken_;
const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> ttrhBuilderToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
const edm::ESGetToken<MkFitGeometry, TrackerRecoGeometryRecord> mkFitGeomToken_;
const edm::EDPutTokenT<MkFitHitWrapper> wrapperPutToken_;
const edm::EDPutTokenT<MkFitClusterIndexToHit> clusterIndexPutToken_;
const edm::EDPutTokenT<std::vector<int>> layerIndexPutToken_;
const edm::EDPutTokenT<std::vector<float>> clusterChargePutToken_;
const ConvertHitTraits convertTraits_;
};

MkFitSiStripHitConverter::MkFitSiStripHitConverter(edm::ParameterSet const& iConfig)
: stripRphiRecHitToken_{consumes<SiStripRecHit2DCollection>(iConfig.getParameter<edm::InputTag>("rphiHits"))},
stripStereoRecHitToken_{consumes<SiStripRecHit2DCollection>(iConfig.getParameter<edm::InputTag>("stereoHits"))},
ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
ttopoToken_{esConsumes<TrackerTopology, TrackerTopologyRcd>()},
mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
wrapperPutToken_{produces<MkFitHitWrapper>()},
clusterIndexPutToken_{produces<MkFitClusterIndexToHit>()},
clusterChargePutToken_{produces<std::vector<float>>()},
: stripRphiRecHitToken_{consumes(iConfig.getParameter<edm::InputTag>("rphiHits"))},
stripStereoRecHitToken_{consumes(iConfig.getParameter<edm::InputTag>("stereoHits"))},
stripClusterToken_{consumes(iConfig.getParameter<edm::InputTag>("clusters"))},
ttrhBuilderToken_{esConsumes(iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
ttopoToken_{esConsumes()},
mkFitGeomToken_{esConsumes()},
wrapperPutToken_{produces()},
clusterIndexPutToken_{produces()},
layerIndexPutToken_{produces()},
clusterChargePutToken_{produces()},
convertTraits_{static_cast<float>(
iConfig.getParameter<edm::ParameterSet>("minGoodStripCharge").getParameter<double>("value"))} {}

Expand All @@ -76,6 +81,7 @@ void MkFitSiStripHitConverter::fillDescriptions(edm::ConfigurationDescriptions&

desc.add("rphiHits", edm::InputTag{"siStripMatchedRecHits", "rphiRecHit"});
desc.add("stereoHits", edm::InputTag{"siStripMatchedRecHits", "stereoRecHit"});
desc.add("clusters", edm::InputTag{"siStripClusters"});
desc.add("ttrhBuilder", edm::ESInputTag{"", "WithTrackAngle"});

edm::ParameterSetDescription descCCC;
Expand All @@ -92,16 +98,29 @@ void MkFitSiStripHitConverter::produce(edm::StreamID iID, edm::Event& iEvent, co

MkFitHitWrapper hitWrapper;
MkFitClusterIndexToHit clusterIndexToHit;
std::vector<int> layerIndexToHit;
std::vector<float> clusterCharge;

auto convert = [&](auto& hits) {
return mkfit::convertHits(
convertTraits_, hits, hitWrapper.hits(), clusterIndexToHit.hits(), clusterCharge, ttopo, ttrhBuilder, mkFitGeom);
};

edm::ProductID stripClusterID;
const auto& stripRphiHits = iEvent.get(stripRphiRecHitToken_);
const auto& stripStereoHits = iEvent.get(stripStereoRecHitToken_);
const auto maxSizeGuess(stripRphiHits.dataSize() + stripStereoHits.dataSize());
auto const& clusters = iEvent.get(stripClusterToken_);

auto convert = [&](auto& hits) {
return mkfit::convertHits(convertTraits_,
hits,
clusters,
hitWrapper.hits(),
clusterIndexToHit.hits(),
layerIndexToHit,
clusterCharge,
ttopo,
ttrhBuilder,
mkFitGeom,
maxSizeGuess);
};

if (not stripRphiHits.empty()) {
stripClusterID = convert(stripRphiHits);
}
Expand All @@ -119,6 +138,7 @@ void MkFitSiStripHitConverter::produce(edm::StreamID iID, edm::Event& iEvent, co

iEvent.emplace(wrapperPutToken_, std::move(hitWrapper));
iEvent.emplace(clusterIndexPutToken_, std::move(clusterIndexToHit));
iEvent.emplace(layerIndexPutToken_, std::move(layerIndexToHit));
iEvent.emplace(clusterChargePutToken_, std::move(clusterCharge));
}

Expand Down
Loading

0 comments on commit 403d6b0

Please sign in to comment.