Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-11 23:28:12

0001 #include <alpaka/alpaka.hpp>
0002 
0003 #include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Utilities/interface/StreamID.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 "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0011 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0012 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0013 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
0014 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0015 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
0016 
0017 #include "DataFormats/TrackSoA/interface/alpaka/TracksSoACollection.h"
0018 #include "DataFormats/TrackSoA/interface/TracksDevice.h"
0019 #include "DataFormats/VertexSoA/interface/alpaka/ZVertexSoACollection.h"
0020 #include "DataFormats/VertexSoA/interface/ZVertexDevice.h"
0021 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0022 
0023 #include "vertexFinder.h"
0024 
0025 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0026 
0027   using namespace cms::alpakatools;
0028 
0029   template <typename TrackerTraits>
0030   class PixelVertexProducerAlpaka : public global::EDProducer<> {
0031     using TkSoADevice = TracksSoACollection<TrackerTraits>;
0032     using Algo = vertexFinder::Producer<TrackerTraits>;
0033 
0034   public:
0035     explicit PixelVertexProducerAlpaka(const edm::ParameterSet& iConfig);
0036     ~PixelVertexProducerAlpaka() override = default;
0037 
0038     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0039 
0040   private:
0041     void produce(edm::StreamID streamID, device::Event& iEvent, const device::EventSetup& iSetup) const override;
0042 
0043     const Algo algo_;
0044 
0045     // Tracking cuts before sending tracks to vertex algo
0046     const float ptMin_;
0047     const float ptMax_;
0048 
0049     device::EDGetToken<TkSoADevice> tokenDeviceTrack_;
0050     device::EDPutToken<ZVertexSoACollection> tokenDeviceVertex_;
0051   };
0052 
0053   template <typename TrackerTraits>
0054   PixelVertexProducerAlpaka<TrackerTraits>::PixelVertexProducerAlpaka(const edm::ParameterSet& conf)
0055       : algo_(conf.getParameter<bool>("oneKernel"),
0056               conf.getParameter<bool>("useDensity"),
0057               conf.getParameter<bool>("useDBSCAN"),
0058               conf.getParameter<bool>("useIterative"),
0059               conf.getParameter<bool>("doSplitting"),
0060               conf.getParameter<int>("minT"),
0061               conf.getParameter<double>("eps"),
0062               conf.getParameter<double>("errmax"),
0063               conf.getParameter<double>("chi2max")),
0064         ptMin_(conf.getParameter<double>("PtMin")),  // 0.5 GeV
0065         ptMax_(conf.getParameter<double>("PtMax")),  // 75. Onsumes
0066         tokenDeviceTrack_(consumes(conf.getParameter<edm::InputTag>("pixelTrackSrc"))),
0067         tokenDeviceVertex_(produces()) {
0068     // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
0069 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0070     producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::ZVertexSoACollection>");
0071 #endif
0072   }
0073 
0074   template <typename TrackerTraits>
0075   void PixelVertexProducerAlpaka<TrackerTraits>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0076     edm::ParameterSetDescription desc;
0077 
0078     // Only one of these three algos can be used at once.
0079     // Maybe this should become a Plugin Factory
0080     desc.add<bool>("oneKernel", true);
0081     desc.add<bool>("useDensity", true);
0082     desc.add<bool>("useDBSCAN", false);
0083     desc.add<bool>("useIterative", false);
0084     desc.add<bool>("doSplitting", true);
0085 
0086     desc.add<int>("minT", 2);          // min number of neighbours to be "core"
0087     desc.add<double>("eps", 0.07);     // max absolute distance to cluster
0088     desc.add<double>("errmax", 0.01);  // max error to be "seed"
0089     desc.add<double>("chi2max", 9.);   // max normalized distance to cluster
0090 
0091     desc.add<double>("PtMin", 0.5);
0092     desc.add<double>("PtMax", 75.);
0093     desc.add<edm::InputTag>("pixelTrackSrc", edm::InputTag("pixelTracksAlpaka"));
0094 
0095     descriptions.addWithDefaultLabel(desc);
0096   }
0097 
0098   template <typename TrackerTraits>
0099   void PixelVertexProducerAlpaka<TrackerTraits>::produce(edm::StreamID streamID,
0100                                                          device::Event& iEvent,
0101                                                          const device::EventSetup& iSetup) const {
0102     auto const& hTracks = iEvent.get(tokenDeviceTrack_);
0103 
0104     iEvent.emplace(tokenDeviceVertex_, algo_.makeAsync(iEvent.queue(), hTracks.view(), ptMin_, ptMax_));
0105   }
0106 
0107   using PixelVertexProducerAlpakaPhase1 = PixelVertexProducerAlpaka<pixelTopology::Phase1>;
0108   using PixelVertexProducerAlpakaPhase2 = PixelVertexProducerAlpaka<pixelTopology::Phase2>;
0109   using PixelVertexProducerAlpakaHIonPhase1 = PixelVertexProducerAlpaka<pixelTopology::HIonPhase1>;
0110 
0111 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0112 
0113 DEFINE_FWK_ALPAKA_MODULE(PixelVertexProducerAlpakaPhase1);
0114 DEFINE_FWK_ALPAKA_MODULE(PixelVertexProducerAlpakaPhase2);
0115 DEFINE_FWK_ALPAKA_MODULE(PixelVertexProducerAlpakaHIonPhase1);