File indexing completed on 2024-07-03 04:18:10
0001 #include "FWCore/Framework/interface/MakerMacros.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003
0004 #include "CondFormats/DataRecord/interface/HcalSiPMCharacteristicsRcd.h"
0005 #include "CondFormats/HcalObjects/interface/alpaka/HcalSiPMCharacteristicsDevice.h"
0006 #include "CondFormats/DataRecord/interface/HcalMahiConditionsRcd.h"
0007 #include "CondFormats/HcalObjects/interface/alpaka/HcalMahiConditionsDevice.h"
0008 #include "CondFormats/DataRecord/interface/HcalRecoParamsRcd.h"
0009 #include "CondFormats/HcalObjects/interface/alpaka/HcalRecoParamWithPulseShapeDevice.h"
0010 #include "CondFormats/HcalObjects/interface/alpaka/HcalMahiPulseOffsetsDevice.h"
0011
0012 #include "DataFormats/HcalDigi/interface/alpaka/HcalDigiDeviceCollection.h"
0013 #include "DataFormats/HcalRecHit/interface/alpaka/HcalRecHitDeviceCollection.h"
0014
0015 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0016 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
0017 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0018 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDGetToken.h"
0019 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0020 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/EDProducer.h"
0021 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0022
0023 #include "Mahi.h"
0024 #include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.h"
0025
0026 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0027
0028 class HBHERecHitProducerPortable : public stream::EDProducer<> {
0029 public:
0030 explicit HBHERecHitProducerPortable(edm::ParameterSet const&);
0031 ~HBHERecHitProducerPortable() override = default;
0032 static void fillDescriptions(edm::ConfigurationDescriptions&);
0033
0034 private:
0035 void produce(device::Event&, device::EventSetup const&) override;
0036
0037 using IProductTypef01 = hcal::Phase1DigiDeviceCollection;
0038 const device::EDGetToken<IProductTypef01> digisTokenF01HE_;
0039
0040 using IProductTypef5 = hcal::Phase0DigiDeviceCollection;
0041 const device::EDGetToken<IProductTypef5> digisTokenF5HB_;
0042
0043 using IProductTypef3 = hcal::Phase1DigiDeviceCollection;
0044 const device::EDGetToken<IProductTypef3> digisTokenF3HB_;
0045
0046 using OProductType = hcal::RecHitDeviceCollection;
0047 const device::EDPutToken<OProductType> rechitsM0Token_;
0048
0049 const device::ESGetToken<hcal::HcalMahiConditionsPortableDevice, HcalMahiConditionsRcd> mahiConditionsToken_;
0050 const device::ESGetToken<hcal::HcalSiPMCharacteristicsPortableDevice, HcalSiPMCharacteristicsRcd>
0051 sipmCharacteristicsToken_;
0052 const device::ESGetToken<hcal::HcalRecoParamWithPulseShapeDevice, HcalRecoParamsRcd> recoParamsToken_;
0053 const device::ESGetToken<hcal::HcalMahiPulseOffsetsPortableDevice, JobConfigurationGPURecord> mahiPulseOffsetsToken_;
0054
0055
0056 hcal::reconstruction::ConfigParameters configParameters_;
0057 };
0058
0059 HBHERecHitProducerPortable::HBHERecHitProducerPortable(edm::ParameterSet const& ps)
0060 : digisTokenF01HE_{consumes(ps.getParameter<edm::InputTag>("digisLabelF01HE"))},
0061 digisTokenF5HB_{consumes(ps.getParameter<edm::InputTag>("digisLabelF5HB"))},
0062 digisTokenF3HB_{consumes(ps.getParameter<edm::InputTag>("digisLabelF3HB"))},
0063 rechitsM0Token_{produces()},
0064 mahiConditionsToken_{esConsumes()},
0065 sipmCharacteristicsToken_{esConsumes()},
0066 recoParamsToken_{esConsumes()},
0067 mahiPulseOffsetsToken_{esConsumes(ps.getParameter<edm::ESInputTag>("mahiPulseOffSets"))} {
0068 configParameters_.maxTimeSamples = ps.getParameter<uint32_t>("maxTimeSamples");
0069 configParameters_.kprep1dChannelsPerBlock = ps.getParameter<uint32_t>("kprep1dChannelsPerBlock");
0070 configParameters_.sipmQTSShift = ps.getParameter<int>("sipmQTSShift");
0071 configParameters_.sipmQNTStoSum = ps.getParameter<int>("sipmQNTStoSum");
0072 configParameters_.firstSampleShift = ps.getParameter<int>("firstSampleShift");
0073
0074 configParameters_.useEffectivePedestals = ps.getParameter<bool>("useEffectivePedestals");
0075
0076 configParameters_.meanTime = ps.getParameter<double>("meanTime");
0077 configParameters_.timeSigmaSiPM = ps.getParameter<double>("timeSigmaSiPM");
0078 configParameters_.timeSigmaHPD = ps.getParameter<double>("timeSigmaHPD");
0079 configParameters_.ts4Thresh = ps.getParameter<double>("ts4Thresh");
0080
0081 configParameters_.applyTimeSlew = ps.getParameter<bool>("applyTimeSlew");
0082 auto const tzeroValues = ps.getParameter<std::vector<double>>("tzeroTimeSlewParameters");
0083 auto const slopeValues = ps.getParameter<std::vector<double>>("slopeTimeSlewParameters");
0084 auto const tmaxValues = ps.getParameter<std::vector<double>>("tmaxTimeSlewParameters");
0085
0086 configParameters_.tzeroTimeSlew = tzeroValues[HcalTimeSlew::Medium];
0087 configParameters_.slopeTimeSlew = slopeValues[HcalTimeSlew::Medium];
0088 configParameters_.tmaxTimeSlew = tmaxValues[HcalTimeSlew::Medium];
0089
0090 auto threadsMinimize = ps.getParameter<std::vector<uint32_t>>("kernelMinimizeThreads");
0091 configParameters_.kernelMinimizeThreads[0] = threadsMinimize[0];
0092 configParameters_.kernelMinimizeThreads[1] = threadsMinimize[1];
0093 configParameters_.kernelMinimizeThreads[2] = threadsMinimize[2];
0094 }
0095
0096 void HBHERecHitProducerPortable::fillDescriptions(edm::ConfigurationDescriptions& cdesc) {
0097 edm::ParameterSetDescription desc;
0098 desc.add<edm::ESInputTag>("mahiPulseOffSets", edm::ESInputTag(""));
0099 desc.add<uint32_t>("maxTimeSamples", 10);
0100 desc.add<uint32_t>("kprep1dChannelsPerBlock", 32);
0101 desc.add<edm::InputTag>("digisLabelF01HE", edm::InputTag{"hcalRawToDigiGPU", "f01HEDigisGPU"});
0102 desc.add<edm::InputTag>("digisLabelF5HB", edm::InputTag{"hcalRawToDigiGPU", "f5HBDigisGPU"});
0103 desc.add<edm::InputTag>("digisLabelF3HB", edm::InputTag{"hcalRawToDigiGPU", "f3HBDigisGPU"});
0104 desc.add<std::string>("recHitsLabelM0HBHE", "recHitsM0HBHE");
0105 desc.add<int>("sipmQTSShift", 0);
0106 desc.add<int>("sipmQNTStoSum", 3);
0107 desc.add<int>("firstSampleShift", 0);
0108 desc.add<bool>("useEffectivePedestals", true);
0109
0110 desc.add<double>("meanTime", 0.f);
0111 desc.add<double>("timeSigmaSiPM", 2.5f);
0112 desc.add<double>("timeSigmaHPD", 5.0f);
0113 desc.add<double>("ts4Thresh", 0.0);
0114
0115 desc.add<bool>("applyTimeSlew", true);
0116 desc.add<std::vector<double>>("tzeroTimeSlewParameters", {23.960177, 11.977461, 9.109694});
0117 desc.add<std::vector<double>>("slopeTimeSlewParameters", {-3.178648, -1.5610227, -1.075824});
0118 desc.add<std::vector<double>>("tmaxTimeSlewParameters", {16.00, 10.00, 6.25});
0119 desc.add<std::vector<uint32_t>>("kernelMinimizeThreads", {16, 1, 1});
0120
0121 cdesc.addWithDefaultLabel(desc);
0122 }
0123
0124 void HBHERecHitProducerPortable::produce(device::Event& event, device::EventSetup const& setup) {
0125 auto& queue = event.queue();
0126
0127
0128 auto const& f01HEDigisDev = event.get(digisTokenF01HE_);
0129 auto const& f5HBDigisDev = event.get(digisTokenF5HB_);
0130 auto const& f3HBDigisDev = event.get(digisTokenF3HB_);
0131
0132 auto const f01DigisSize = f01HEDigisDev->metadata().size();
0133 auto const f5DigisSize = f5HBDigisDev->metadata().size();
0134 auto const f3DigisSize = f3HBDigisDev->metadata().size();
0135
0136 auto const totalChannels = f01DigisSize + f5DigisSize + f3DigisSize;
0137 OProductType outputGPU_{totalChannels, queue};
0138
0139 if (totalChannels > 0) {
0140
0141 auto const& mahiConditionsDev = setup.getData(mahiConditionsToken_);
0142 auto const& sipmCharacteristicsDev = setup.getData(sipmCharacteristicsToken_);
0143 auto const& recoParamsWithPulseShapeDev = setup.getData(recoParamsToken_);
0144 auto const& mahiPulseOffsetsDev = setup.getData(mahiPulseOffsetsToken_);
0145
0146
0147
0148
0149 hcal::reconstruction::runMahiAsync(queue,
0150 f01HEDigisDev.const_view(),
0151 f5HBDigisDev.const_view(),
0152 f3HBDigisDev.const_view(),
0153 outputGPU_.view(),
0154 mahiConditionsDev.const_view(),
0155 sipmCharacteristicsDev.const_view(),
0156 recoParamsWithPulseShapeDev.const_view(),
0157 mahiPulseOffsetsDev.const_view(),
0158 configParameters_);
0159 }
0160
0161 event.emplace(rechitsM0Token_, std::move(outputGPU_));
0162 }
0163
0164 }
0165
0166 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0167 DEFINE_FWK_ALPAKA_MODULE(HBHERecHitProducerPortable);