Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-24 01:30:29

0001 #include <array>
0002 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Utilities/interface/StreamID.h"
0007 #include "FWCore/Utilities/interface/InputTag.h"
0008 
0009 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0010 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
0011 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0012 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0013 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
0014 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0015 #include "HeterogeneousCore/AlpakaCore/interface/MoveToDeviceCache.h"
0016 
0017 #include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h"
0018 #include "DataFormats/EcalDigi/interface/EcalConstants.h"
0019 #include "DataFormats/EcalDigi/interface/alpaka/EcalDigiPhase2DeviceCollection.h"
0020 #include "DataFormats/EcalDigi/interface/EcalDigiPhase2HostCollection.h"
0021 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHitHostCollection.h"
0022 #include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
0023 #include "DataFormats/Portable/interface/PortableObject.h"
0024 
0025 #include "EcalUncalibRecHitPhase2WeightsAlgoPortable.h"
0026 #include "EcalUncalibRecHitPhase2WeightsStruct.h"
0027 
0028 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0029   class EcalUncalibRecHitPhase2WeightsProducerPortable : public global::EDProducer<> {
0030   public:
0031     explicit EcalUncalibRecHitPhase2WeightsProducerPortable(edm::ParameterSet const &ps);
0032     ~EcalUncalibRecHitPhase2WeightsProducerPortable() override = default;
0033     static void fillDescriptions(edm::ConfigurationDescriptions &);
0034 
0035     void produce(edm::StreamID sid, device::Event &, device::EventSetup const &) const override;
0036 
0037   private:
0038     using InputProduct = EcalDigiPhase2DeviceCollection;
0039     const device::EDGetToken<InputProduct> digisToken_;  //both tokens stored on the device
0040     using OutputProduct = EcalUncalibratedRecHitDeviceCollection;
0041     const device::EDPutToken<OutputProduct> uncalibratedRecHitsToken_;
0042 
0043     // class data member
0044     cms::alpakatools::MoveToDeviceCache<Device, PortableHostObject<EcalUncalibRecHitPhase2Weights>> weightsCache_;
0045   };
0046 
0047   // constructor with initialisation of elements
0048   EcalUncalibRecHitPhase2WeightsProducerPortable::EcalUncalibRecHitPhase2WeightsProducerPortable(
0049       const edm::ParameterSet &ps)
0050       : EDProducer(ps),
0051         digisToken_{consumes(ps.getParameter<edm::InputTag>("digisLabelEB"))},
0052         uncalibratedRecHitsToken_{produces(ps.getParameter<std::string>("uncalibratedRecHitsLabelEB"))},
0053         weightsCache_(PortableHostObject<EcalUncalibRecHitPhase2Weights>(
0054             cms::alpakatools::host(), [](const edm::ParameterSet &ps) {
0055               EcalUncalibRecHitPhase2Weights weights;
0056               const auto amp_weights = ps.getParameter<std::vector<double>>("weights");
0057               const auto timeWeights = ps.getParameter<std::vector<double>>("timeWeights");
0058               for (unsigned int i = 0; i < ecalPh2::sampleSize; ++i) {
0059                 if (i < amp_weights.size()) {
0060                   weights.weights[i] = static_cast<float>(amp_weights[i]);
0061                 } else {
0062                   weights.weights[i] = 0;
0063                 }
0064                 if (i < timeWeights.size()) {
0065                   weights.timeWeights[i] = static_cast<float>(timeWeights[i]);
0066                 } else {
0067                   weights.timeWeights[i] = 0;
0068                 }
0069               }
0070               return weights;
0071             }(ps))) {}
0072 
0073   void EcalUncalibRecHitPhase2WeightsProducerPortable::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0074     edm::ParameterSetDescription desc;
0075 
0076     desc.add<std::string>("uncalibratedRecHitsLabelEB", "EcalUncalibRecHitsEB");
0077     //The weights values below should be kept up to date with those on the CPU version of this module
0078     //stored in RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitPhase2WeightsProducer.cc
0079     desc.add<std::vector<double>>("weights",
0080                                   {-0.121016,
0081                                    -0.119899,
0082                                    -0.120923,
0083                                    -0.0848959,
0084                                    0.261041,
0085                                    0.509881,
0086                                    0.373591,
0087                                    0.134899,
0088                                    -0.0233605,
0089                                    -0.0913195,
0090                                    -0.112452,
0091                                    -0.118596,
0092                                    -0.121737,
0093                                    -0.121737,
0094                                    -0.121737,
0095                                    -0.121737});
0096     desc.add<std::vector<double>>("timeWeights",
0097                                   {0.429452,
0098                                    0.442762,
0099                                    0.413327,
0100                                    0.858327,
0101                                    4.42324,
0102                                    2.04369,
0103                                    -3.42426,
0104                                    -4.16258,
0105                                    -2.36061,
0106                                    -0.725371,
0107                                    0.0727267,
0108                                    0.326005,
0109                                    0.402035,
0110                                    0.404287,
0111                                    0.434207,
0112                                    0.422775});
0113 
0114     desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("ecalPhase2DigiToPortableProducer", "ebDigis"));
0115 
0116     descriptions.addWithDefaultLabel(desc);
0117   }
0118 
0119   void EcalUncalibRecHitPhase2WeightsProducerPortable::produce(edm::StreamID sid,
0120                                                                device::Event &event,
0121                                                                const device::EventSetup &setup) const {
0122     //get the device collection of digis
0123     auto const &digis = event.get(digisToken_);
0124 
0125     //get size of digis
0126     const uint32_t size = digis->metadata().size();
0127 
0128     //allocate output product on the device
0129     OutputProduct uncalibratedRecHits{static_cast<int32_t>(size), event.queue()};
0130 
0131     //do not run the algo if there are no digis
0132     if (size > 0) {
0133       auto const &weightsObj = weightsCache_.get(event.queue());
0134       //launch the asynchronous work
0135       ecal::weights::phase2Weights(digis, uncalibratedRecHits, weightsObj.const_data(), event.queue());
0136     }
0137     //put the output collection into the event
0138     event.emplace(uncalibratedRecHitsToken_, std::move(uncalibratedRecHits));
0139   }
0140 
0141 }  //namespace ALPAKA_ACCELERATOR_NAMESPACE
0142 DEFINE_FWK_ALPAKA_MODULE(EcalUncalibRecHitPhase2WeightsProducerPortable);