Skip to content

Commit

Permalink
Merge pull request #28 from fllor/PFRecHitAndCluster_GPU_13_0_8
Browse files Browse the repository at this point in the history
Fix PFRecHit validation; add Alpaka PFRecHit to legacy format conversion; performance optimisations
jsamudio authored Jul 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 144acf3 + 925663c commit d184815
Showing 13 changed files with 939 additions and 184 deletions.
7 changes: 3 additions & 4 deletions DataFormats/ParticleFlowReco_Alpaka/interface/PFRecHitSoA.h
Original file line number Diff line number Diff line change
@@ -12,19 +12,18 @@

namespace reco {

using PFRecHitsNeighbours = Eigen::Matrix<uint32_t, 8, 1>;
using PFRecHitsNeighbours = Eigen::Matrix<int32_t, 8, 1>;
GENERATE_SOA_LAYOUT(PFRecHitSoALayout,
SOA_COLUMN(uint32_t, detId),
SOA_COLUMN(float, energy),
SOA_COLUMN(float, time),
SOA_COLUMN(int, depth),
SOA_COLUMN(PFLayer::Layer, layer),
SOA_COLUMN(uint32_t, num_neighbours),
SOA_EIGEN_COLUMN(PFRecHitsNeighbours, neighbours),
SOA_EIGEN_COLUMN(PFRecHitsNeighbours, neighbours), // Neighbour indices (or -1); order: N, S, E, W, NE, SW, SE, NW
SOA_COLUMN(float, x),
SOA_COLUMN(float, y),
SOA_COLUMN(float, z),
SOA_SCALAR(uint32_t, size)
SOA_SCALAR(uint32_t, size) // Number of PFRecHits in SoA
)

using PFRecHitSoA = PFRecHitSoALayout<>;
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@

# Input source
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('/store/relval/CMSSW_12_4_0/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_124X_mcRun3_2022_realistic_v5-v1/10000/012eda92-aad5-4a95-8dbd-c79546b5f508.root'),
fileNames = cms.untracked.vstring('/store/relval/CMSSW_13_0_0_pre4/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_130X_mcRun3_2022_realistic_v2_HS-v4/2590000/05ad6501-815f-4df6-b115-03ad028f9b76.root'),
secondaryFileNames = cms.untracked.vstring()
)

Original file line number Diff line number Diff line change
@@ -20,8 +20,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
PFRecHitDeviceCollection& collection);

private:
PFRecHitProducerKernel(cms::alpakatools::device_buffer<Device, uint32_t[]>&&);
PFRecHitProducerKernel(cms::alpakatools::device_buffer<Device, uint32_t[]>&&,
cms::alpakatools::device_buffer<Device, uint32_t>&&);
cms::alpakatools::device_buffer<Device, uint32_t[]> denseId2pfRecHit;
cms::alpakatools::device_buffer<Device, uint32_t> num_pfRecHits;
};

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
2 changes: 2 additions & 0 deletions RecoParticleFlow/PFRecHitProducer/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
<use name="DataFormats/ParticleFlowReco_Alpaka"/>
<use name="CommonTools/ParticleFlow"/>
<use name="DQMServices/Core"/>
<use name="Geometry/CaloGeometry"/>
<use name="Geometry/Records"/>
<flags EDM_PLUGIN="1"/>
</library>

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
#include "DataFormats/ParticleFlowReco_Alpaka/interface/PFRecHitHostCollection.h"


class LegacyPFRecHitProducer : public edm::stream::EDProducer<> {
public:
LegacyPFRecHitProducer(edm::ParameterSet const& config) :
alpakaPfRecHitsToken(consumes(config.getParameter<edm::InputTag>("src"))),
legacyPfRecHitsToken(produces()),
geomToken(esConsumes<edm::Transition::BeginRun>())
{}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src");
descriptions.addWithDefaultLabel(desc);
}

private:
void beginRun(edm::Run const&, edm::EventSetup const&) override;
void produce(edm::Event&, const edm::EventSetup&) override;

const edm::EDGetTokenT<reco::PFRecHitHostCollection> alpakaPfRecHitsToken;
const edm::EDPutTokenT<reco::PFRecHitCollection> legacyPfRecHitsToken;

edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken;
edm::ESHandle<CaloGeometry> geoHandle;
std::unordered_map<PFLayer::Layer, const CaloSubdetectorGeometry*> hcalGeo;
};

void LegacyPFRecHitProducer::beginRun(edm::Run const&, const edm::EventSetup& setup) {
geoHandle = setup.getHandle(geomToken);
hcalGeo[PFLayer::HCAL_BARREL1] = geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
hcalGeo[PFLayer::HCAL_ENDCAP] = geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
}

void LegacyPFRecHitProducer::produce(edm::Event& event, const edm::EventSetup& setup) {
edm::Handle<reco::PFRecHitHostCollection> pfRecHitsAlpakaSoA;
event.getByToken(alpakaPfRecHitsToken, pfRecHitsAlpakaSoA);
const reco::PFRecHitHostCollection::ConstView& alpakaPfRecHits = pfRecHitsAlpakaSoA->const_view();

reco::PFRecHitCollection out;
out.reserve(alpakaPfRecHits.size());

for(size_t i = 0; i < alpakaPfRecHits.size(); i++) {
reco::PFRecHit& pfrh = out.emplace_back(
hcalGeo.at(alpakaPfRecHits[i].layer())->getGeometry(alpakaPfRecHits[i].detId()),
alpakaPfRecHits[i].detId(),
alpakaPfRecHits[i].layer(),
alpakaPfRecHits[i].energy());
pfrh.setTime(alpakaPfRecHits[i].time());
pfrh.setDepth(alpakaPfRecHits[i].depth());

// order in Alpaka: N, S, E, W,NE,SW,SE,NW
const short eta[8] = {0, 0, 1,-1, 1,-1, 1,-1};
const short phi[8] = {1,-1, 0, 0, 1,-1,-1, 1};
for(size_t k = 0; k < 8; k++)
if(alpakaPfRecHits[i].neighbours()(k) != -1)
pfrh.addNeighbour(eta[k], phi[k], 0, alpakaPfRecHits[i].neighbours()(k));
}

event.emplace(legacyPfRecHitsToken, out);
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(LegacyPFRecHitProducer);
// */
Loading

0 comments on commit d184815

Please sign in to comment.