Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-08 03:06:48

0001 #include "DataFormats/HGCalReco/interface/HGCalSoAClusters.h"
0002 #include "DataFormats/HGCalReco/interface/HGCalSoARecHitsHostCollection.h"
0003 #include "DataFormats/HGCalReco/interface/alpaka/HGCalSoAClustersDeviceCollection.h"
0004 #include "DataFormats/HGCalReco/interface/alpaka/HGCalSoARecHitsExtraDeviceCollection.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0011 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0012 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0013 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/SynchronizingEDProducer.h"
0014 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0015 #include "RecoLocalCalo/HGCalRecProducers/interface/HGCalSoAClustersExtra.h"
0016 #include "RecoLocalCalo/HGCalRecProducers/interface/HGCalTilesConstants.h"
0017 
0018 #include "HGCalLayerClustersSoAAlgoWrapper.h"
0019 
0020 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0021 
0022   class HGCalSoALayerClustersProducer : public stream::SynchronizingEDProducer<> {
0023   public:
0024     HGCalSoALayerClustersProducer(edm::ParameterSet const& config)
0025         : SynchronizingEDProducer(config),
0026           getTokenDeviceRecHits_{consumes(config.getParameter<edm::InputTag>("hgcalRecHitsSoA"))},
0027           getTokenDeviceClusters_{consumes(config.getParameter<edm::InputTag>("hgcalRecHitsLayerClustersSoA"))},
0028           deviceTokenSoAClusters_{produces()},
0029           thresholdW0_(config.getParameter<double>("thresholdW0")),
0030           positionDeltaRho2_(config.getParameter<double>("positionDeltaRho2")) {}
0031 
0032     ~HGCalSoALayerClustersProducer() override = default;
0033 
0034     void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) override {
0035       // Get LayerClusters almost-SoA on device: this has still the same
0036       // cardinality as the RecHitsSoA, but has all the required information
0037       // to assemble the clusters, i.e., it has the cluster index assigned to
0038       // each rechit.
0039       auto const& deviceInputClusters = iEvent.get(getTokenDeviceClusters_);
0040       auto const inputClusters_v = deviceInputClusters.view();
0041       //
0042       // Allocate output SoA for the clusters, one entry for each cluster
0043       auto device_numclusters = cms::alpakatools::make_device_view<const unsigned int>(
0044           alpaka::getDev(iEvent.queue()), inputClusters_v.numberOfClustersScalar());
0045       auto host_numclusters = cms::alpakatools::make_host_view<unsigned int>(num_clusters_);
0046       alpaka::memcpy(iEvent.queue(), host_numclusters, device_numclusters);
0047     }
0048 
0049     void produce(device::Event& iEvent, device::EventSetup const& iSetup) override {
0050       // Get RecHitsSoA on the device
0051       auto const& deviceInputRecHits = iEvent.get(getTokenDeviceRecHits_);
0052       auto const inputRechits_v = deviceInputRecHits.view();
0053 
0054       // Get LayerClusters almost-SoA on device: this has still the same
0055       // cardinality as the RecHitsSoA, but has all the required information
0056       // to assemble the clusters, i.e., it has the cluster index assigned to
0057       // each rechit.
0058       auto const& deviceInputClusters = iEvent.get(getTokenDeviceClusters_);
0059       auto const inputClusters_v = deviceInputClusters.view();
0060 
0061       HGCalSoAClustersDeviceCollection output(num_clusters_, iEvent.queue());
0062       auto output_v = output.view();
0063       // Allocate workspace SoA cluster
0064       HGCalSoAClustersExtraDeviceCollection outputWorkspace(num_clusters_, iEvent.queue());
0065       auto output_workspace_v = outputWorkspace.view();
0066 
0067       algo_.run(iEvent.queue(),
0068                 num_clusters_,
0069                 thresholdW0_,
0070                 positionDeltaRho2_,
0071                 inputRechits_v,
0072                 inputClusters_v,
0073                 output_v,
0074                 output_workspace_v);
0075       iEvent.emplace(deviceTokenSoAClusters_, std::move(output));
0076     }
0077 
0078     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0079       edm::ParameterSetDescription desc;
0080       desc.add<edm::InputTag>("hgcalRecHitsLayerClustersSoA", edm::InputTag("TO BE DEFINED"));
0081       desc.add<edm::InputTag>("hgcalRecHitsSoA", edm::InputTag("TO BE DEFINED"));
0082       desc.add<double>("thresholdW0", 2.9);
0083       desc.add<double>("positionDeltaRho2", 1.69);
0084       descriptions.addWithDefaultLabel(desc);
0085     }
0086 
0087   private:
0088     device::EDGetToken<HGCalSoARecHitsDeviceCollection> const getTokenDeviceRecHits_;
0089     device::EDGetToken<HGCalSoARecHitsExtraDeviceCollection> const getTokenDeviceClusters_;
0090     device::EDPutToken<HGCalSoAClustersDeviceCollection> const deviceTokenSoAClusters_;
0091     HGCalLayerClustersSoAAlgoWrapper algo_;
0092     unsigned int num_clusters_;
0093     float thresholdW0_;
0094     float positionDeltaRho2_;
0095   };
0096 
0097 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0098 
0099 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0100 DEFINE_FWK_ALPAKA_MODULE(HGCalSoALayerClustersProducer);