File indexing completed on 2025-01-04 00:29:53
0001 #include "CondFormats/DataRecord/interface/EcalRecHitConditionsRcd.h"
0002 #include "CondFormats/EcalObjects/interface/alpaka/EcalRecHitConditionsDevice.h"
0003 #include "CondFormats/EcalObjects/interface/alpaka/EcalRecHitParametersDevice.h"
0004 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0005 #include "DataFormats/EcalRecHit/interface/RecoTypes.h"
0006 #include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
0007 #include "DataFormats/EcalRecHit/interface/alpaka/EcalRecHitDeviceCollection.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "FWCore/ParameterSet/interface/EmptyGroupDescription.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDGetToken.h"
0013 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0014 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
0015 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0016 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/EDProducer.h"
0017 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0018
0019 #include "DeclsForKernels.h"
0020 #include "EcalRecHitBuilder.h"
0021
0022 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0023
0024 class EcalRecHitProducerPortable : public stream::EDProducer<> {
0025 public:
0026 explicit EcalRecHitProducerPortable(edm::ParameterSet const& ps);
0027 ~EcalRecHitProducerPortable() override = default;
0028 static void fillDescriptions(edm::ConfigurationDescriptions&);
0029
0030 void produce(device::Event&, device::EventSetup const&) override;
0031
0032 private:
0033 bool const isPhase2_;
0034
0035 using InputProduct = EcalUncalibratedRecHitDeviceCollection;
0036 const device::EDGetToken<InputProduct> uncalibRecHitsTokenEB_;
0037 const device::EDGetToken<InputProduct> uncalibRecHitsTokenEE_;
0038
0039 using OutputProduct = EcalRecHitDeviceCollection;
0040 const device::EDPutToken<OutputProduct> recHitsTokenEB_;
0041 device::EDPutToken<OutputProduct> recHitsTokenEE_;
0042
0043
0044 ecal::rechit::ConfigurationParameters configParameters_;
0045
0046
0047 const device::ESGetToken<EcalRecHitConditionsDevice, EcalRecHitConditionsRcd> recHitConditionsToken_;
0048 const device::ESGetToken<EcalRecHitParametersDevice, JobConfigurationGPURecord> recHitParametersToken_;
0049 };
0050
0051 void EcalRecHitProducerPortable::fillDescriptions(edm::ConfigurationDescriptions& confDesc) {
0052 edm::ParameterSetDescription desc;
0053
0054 desc.add<edm::InputTag>("uncalibrecHitsInLabelEB",
0055 edm::InputTag("ecalMultiFitUncalibRecHitPortable", "EcalUncalibRecHitsEB"));
0056 desc.add<std::string>("recHitsLabelEB", "EcalRecHitsEB");
0057 desc.add<bool>("killDeadChannels", true);
0058 desc.add<bool>("recoverEBIsolatedChannels", false);
0059 desc.add<bool>("recoverEBVFE", false);
0060 desc.add<bool>("recoverEBFE", true);
0061
0062 desc.add<double>("EBLaserMIN", 0.5);
0063 desc.add<double>("EBLaserMAX", 3.0);
0064
0065 desc.ifValue(edm::ParameterDescription<bool>("isPhase2", false, true),
0066 false >> (edm::ParameterDescription<edm::InputTag>(
0067 "uncalibrecHitsInLabelEE",
0068 edm::InputTag("ecalMultiFitUncalibRecHitPortable", "EcalUncalibRecHitsEE"),
0069 true) and
0070 edm::ParameterDescription<std::string>("recHitsLabelEE", "EcalRecHitsEE", true) and
0071 edm::ParameterDescription<bool>("recoverEEIsolatedChannels", false, true) and
0072 edm::ParameterDescription<bool>("recoverEEVFE", false, true) and
0073 edm::ParameterDescription<bool>("recoverEEFE", true, true) and
0074 edm::ParameterDescription<double>("EELaserMIN", 0.5, true) and
0075 edm::ParameterDescription<double>("EELaserMAX", 8.0, true)) or
0076 true >> edm::EmptyGroupDescription());
0077
0078 confDesc.addWithDefaultLabel(desc);
0079 }
0080
0081 EcalRecHitProducerPortable::EcalRecHitProducerPortable(const edm::ParameterSet& ps)
0082 : isPhase2_{ps.getParameter<bool>("isPhase2")},
0083 uncalibRecHitsTokenEB_{consumes(ps.getParameter<edm::InputTag>("uncalibrecHitsInLabelEB"))},
0084 uncalibRecHitsTokenEE_{isPhase2_ ? device::EDGetToken<InputProduct>{}
0085 : consumes(ps.getParameter<edm::InputTag>("uncalibrecHitsInLabelEE"))},
0086 recHitsTokenEB_{produces(ps.getParameter<std::string>("recHitsLabelEB"))},
0087 recHitConditionsToken_{esConsumes()},
0088 recHitParametersToken_{esConsumes()} {
0089 if (!isPhase2_) {
0090 recHitsTokenEE_ = produces(ps.getParameter<std::string>("recHitsLabelEE"));
0091 }
0092 configParameters_.killDeadChannels = ps.getParameter<bool>("killDeadChannels");
0093 configParameters_.EBLaserMIN = ps.getParameter<double>("EBLaserMIN");
0094 configParameters_.EELaserMIN = isPhase2_ ? 0. : ps.getParameter<double>("EELaserMIN");
0095 configParameters_.EBLaserMAX = ps.getParameter<double>("EBLaserMAX");
0096 configParameters_.EELaserMAX = isPhase2_ ? 0. : ps.getParameter<double>("EELaserMAX");
0097
0098
0099 uint32_t flagmask = 0;
0100 flagmask |= 0x1 << EcalRecHit::kNeighboursRecovered;
0101 flagmask |= 0x1 << EcalRecHit::kTowerRecovered;
0102 flagmask |= 0x1 << EcalRecHit::kDead;
0103 flagmask |= 0x1 << EcalRecHit::kKilled;
0104 flagmask |= 0x1 << EcalRecHit::kTPSaturated;
0105 flagmask |= 0x1 << EcalRecHit::kL1SpikeFlag;
0106 configParameters_.flagmask = flagmask;
0107
0108
0109 configParameters_.recoverEBIsolatedChannels = ps.getParameter<bool>("recoverEBIsolatedChannels");
0110 configParameters_.recoverEEIsolatedChannels =
0111 isPhase2_ ? false : ps.getParameter<bool>("recoverEEIsolatedChannels");
0112 configParameters_.recoverEBVFE = ps.getParameter<bool>("recoverEBVFE");
0113 configParameters_.recoverEEVFE = isPhase2_ ? false : ps.getParameter<bool>("recoverEEVFE");
0114 configParameters_.recoverEBFE = ps.getParameter<bool>("recoverEBFE");
0115 configParameters_.recoverEEFE = isPhase2_ ? false : ps.getParameter<bool>("recoverEEFE");
0116 }
0117
0118 void EcalRecHitProducerPortable::produce(device::Event& event, device::EventSetup const& setup) {
0119 auto& queue = event.queue();
0120
0121
0122 auto const* uncalibRecHitsDevEB = &event.get(uncalibRecHitsTokenEB_);
0123 auto const* uncalibRecHitsDevEE = isPhase2_ ? nullptr : &event.get(uncalibRecHitsTokenEE_);
0124
0125
0126 auto const uncalibRecHitsSizeEB = uncalibRecHitsDevEB->const_view().metadata().size();
0127 auto const uncalibRecHitsSizeEE = isPhase2_ ? 0 : uncalibRecHitsDevEE->const_view().metadata().size();
0128
0129
0130 auto recHitsDevEB = std::make_unique<OutputProduct>(uncalibRecHitsSizeEB, queue);
0131 auto recHitsDevEE =
0132 isPhase2_ ? std::unique_ptr<OutputProduct>() : std::make_unique<OutputProduct>(uncalibRecHitsSizeEE, queue);
0133
0134
0135 auto recHitSizeViewEB = cms::alpakatools::make_device_view<uint32_t>(queue, recHitsDevEB->view().size());
0136 alpaka::memset(queue, recHitSizeViewEB, 0);
0137
0138 if (!isPhase2_) {
0139 auto recHitSizeViewEE = cms::alpakatools::make_device_view<uint32_t>(queue, recHitsDevEE->view().size());
0140 alpaka::memset(queue, recHitSizeViewEE, 0);
0141 }
0142
0143
0144 if (uncalibRecHitsSizeEB + uncalibRecHitsSizeEE > 0) {
0145
0146 auto const& eventTime = static_cast<const edm::Event&>(event).time().value();
0147
0148
0149 auto const& recHitConditionsDev = setup.getData(recHitConditionsToken_);
0150 auto const& recHitParametersDev = setup.getData(recHitParametersToken_);
0151
0152
0153
0154
0155 ecal::rechit::create_ecal_rechit(queue,
0156 uncalibRecHitsDevEB,
0157 uncalibRecHitsDevEE,
0158 *recHitsDevEB,
0159 *recHitsDevEE,
0160 recHitConditionsDev,
0161 recHitParametersDev,
0162 eventTime,
0163 configParameters_,
0164 isPhase2_);
0165 }
0166
0167
0168 event.put(recHitsTokenEB_, std::move(recHitsDevEB));
0169 if (!isPhase2_) {
0170 event.put(recHitsTokenEE_, std::move(recHitsDevEE));
0171 }
0172 }
0173
0174 }
0175
0176 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0177 DEFINE_FWK_ALPAKA_MODULE(EcalRecHitProducerPortable);