Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:44

0001 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalUncalibratedRecHit.h"
0002 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
0003 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
0004 #include "CondFormats/DataRecord/interface/EcalPulseCovariancesRcd.h"
0005 #include "CondFormats/DataRecord/interface/EcalPulseShapesRcd.h"
0006 #include "CondFormats/DataRecord/interface/EcalSampleMaskRcd.h"
0007 #include "CondFormats/DataRecord/interface/EcalSamplesCorrelationRcd.h"
0008 #include "CondFormats/DataRecord/interface/EcalTimeBiasCorrectionsRcd.h"
0009 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
0010 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
0011 #include "CondFormats/EcalObjects/interface/EcalGainRatiosGPU.h"
0012 #include "CondFormats/EcalObjects/interface/EcalMultifitParametersGPU.h"
0013 #include "CondFormats/EcalObjects/interface/EcalPedestalsGPU.h"
0014 #include "CondFormats/EcalObjects/interface/EcalPulseCovariancesGPU.h"
0015 #include "CondFormats/EcalObjects/interface/EcalPulseShapesGPU.h"
0016 #include "CondFormats/EcalObjects/interface/EcalSamplesCorrelationGPU.h"
0017 #include "CondFormats/EcalObjects/interface/EcalTimeBiasCorrectionsGPU.h"
0018 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstantsGPU.h"
0019 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
0020 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/Utilities/interface/ESInputTag.h"
0027 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0028 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0029 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0030 
0031 #include "DeclsForKernels.h"
0032 #include "EcalUncalibRecHitMultiFitAlgoGPU.h"
0033 
0034 class EcalUncalibRecHitProducerGPU : public edm::stream::EDProducer<> {
0035 public:
0036   explicit EcalUncalibRecHitProducerGPU(edm::ParameterSet const& ps);
0037   ~EcalUncalibRecHitProducerGPU() override;
0038   static void fillDescriptions(edm::ConfigurationDescriptions&);
0039 
0040 private:
0041   void produce(edm::Event&, edm::EventSetup const&) override;
0042 
0043 private:
0044   using InputProduct = cms::cuda::Product<ecal::DigisCollection<calo::common::DevStoragePolicy>>;
0045   const edm::EDGetTokenT<InputProduct> digisTokenEB_, digisTokenEE_;
0046   using OutputProduct = cms::cuda::Product<ecal::UncalibratedRecHit<calo::common::DevStoragePolicy>>;
0047   const edm::EDPutTokenT<OutputProduct> recHitsTokenEB_, recHitsTokenEE_;
0048 
0049   // conditions tokens
0050   const edm::ESGetToken<EcalPedestalsGPU, EcalPedestalsRcd> pedestalsToken_;
0051   const edm::ESGetToken<EcalGainRatiosGPU, EcalGainRatiosRcd> gainRatiosToken_;
0052   const edm::ESGetToken<EcalPulseShapesGPU, EcalPulseShapesRcd> pulseShapesToken_;
0053   const edm::ESGetToken<EcalPulseCovariancesGPU, EcalPulseCovariancesRcd> pulseCovariancesToken_;
0054   const edm::ESGetToken<EcalSamplesCorrelationGPU, EcalSamplesCorrelationRcd> samplesCorrelationToken_;
0055   const edm::ESGetToken<EcalTimeBiasCorrectionsGPU, EcalTimeBiasCorrectionsRcd> timeBiasCorrectionsToken_;
0056   const edm::ESGetToken<EcalTimeCalibConstantsGPU, EcalTimeCalibConstantsRcd> timeCalibConstantsToken_;
0057   const edm::ESGetToken<EcalSampleMask, EcalSampleMaskRcd> sampleMaskToken_;
0058   const edm::ESGetToken<EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd> timeOffsetConstantToken_;
0059   const edm::ESGetToken<EcalMultifitParametersGPU, JobConfigurationGPURecord> multifitParametersToken_;
0060 
0061   // configuration parameters
0062   ecal::multifit::ConfigurationParameters configParameters_;
0063 };
0064 
0065 void EcalUncalibRecHitProducerGPU::fillDescriptions(edm::ConfigurationDescriptions& confDesc) {
0066   edm::ParameterSetDescription desc;
0067 
0068   desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("ecalRawToDigiGPU", "ebDigis"));
0069   desc.add<edm::InputTag>("digisLabelEE", edm::InputTag("ecalRawToDigiGPU", "eeDigis"));
0070 
0071   desc.add<std::string>("recHitsLabelEB", "EcalUncalibRecHitsEB");
0072   desc.add<std::string>("recHitsLabelEE", "EcalUncalibRecHitsEE");
0073 
0074   desc.add<edm::ESInputTag>("timeCalibTag", edm::ESInputTag());
0075   desc.add<edm::ESInputTag>("timeOffsetTag", edm::ESInputTag());
0076   desc.add<double>("EBtimeFitLimits_Lower", 0.2);
0077   desc.add<double>("EBtimeFitLimits_Upper", 1.4);
0078   desc.add<double>("EEtimeFitLimits_Lower", 0.2);
0079   desc.add<double>("EEtimeFitLimits_Upper", 1.4);
0080   desc.add<double>("EBtimeConstantTerm", .6);
0081   desc.add<double>("EEtimeConstantTerm", 1.0);
0082   desc.add<double>("EBtimeNconst", 28.5);
0083   desc.add<double>("EEtimeNconst", 31.8);
0084   desc.add<double>("outOfTimeThresholdGain12pEB", 5);
0085   desc.add<double>("outOfTimeThresholdGain12mEB", 5);
0086   desc.add<double>("outOfTimeThresholdGain61pEB", 5);
0087   desc.add<double>("outOfTimeThresholdGain61mEB", 5);
0088   desc.add<double>("outOfTimeThresholdGain12pEE", 1000);
0089   desc.add<double>("outOfTimeThresholdGain12mEE", 1000);
0090   desc.add<double>("outOfTimeThresholdGain61pEE", 1000);
0091   desc.add<double>("outOfTimeThresholdGain61mEE", 1000);
0092   desc.add<double>("amplitudeThresholdEB", 10);
0093   desc.add<double>("amplitudeThresholdEE", 10);
0094   desc.addUntracked<std::vector<uint32_t>>("kernelMinimizeThreads", {32, 1, 1});
0095   desc.add<bool>("shouldRunTimingComputation", true);
0096   confDesc.addWithDefaultLabel(desc);
0097 }
0098 
0099 EcalUncalibRecHitProducerGPU::EcalUncalibRecHitProducerGPU(const edm::ParameterSet& ps)
0100     : digisTokenEB_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisLabelEB"))},
0101       digisTokenEE_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisLabelEE"))},
0102       recHitsTokenEB_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsLabelEB"))},
0103       recHitsTokenEE_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsLabelEE"))},
0104       pedestalsToken_{esConsumes<EcalPedestalsGPU, EcalPedestalsRcd>()},
0105       gainRatiosToken_{esConsumes<EcalGainRatiosGPU, EcalGainRatiosRcd>()},
0106       pulseShapesToken_{esConsumes<EcalPulseShapesGPU, EcalPulseShapesRcd>()},
0107       pulseCovariancesToken_{esConsumes<EcalPulseCovariancesGPU, EcalPulseCovariancesRcd>()},
0108       samplesCorrelationToken_{esConsumes<EcalSamplesCorrelationGPU, EcalSamplesCorrelationRcd>()},
0109       timeBiasCorrectionsToken_{esConsumes<EcalTimeBiasCorrectionsGPU, EcalTimeBiasCorrectionsRcd>()},
0110       timeCalibConstantsToken_{esConsumes<EcalTimeCalibConstantsGPU, EcalTimeCalibConstantsRcd>(
0111           ps.getParameter<edm::ESInputTag>("timeCalibTag"))},
0112       sampleMaskToken_{esConsumes<EcalSampleMask, EcalSampleMaskRcd>()},
0113       timeOffsetConstantToken_{esConsumes<EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd>(
0114           ps.getParameter<edm::ESInputTag>("timeOffsetTag"))},
0115       multifitParametersToken_{esConsumes<EcalMultifitParametersGPU, JobConfigurationGPURecord>()} {
0116   std::pair<double, double> EBtimeFitLimits, EEtimeFitLimits;
0117   EBtimeFitLimits.first = ps.getParameter<double>("EBtimeFitLimits_Lower");
0118   EBtimeFitLimits.second = ps.getParameter<double>("EBtimeFitLimits_Upper");
0119   EEtimeFitLimits.first = ps.getParameter<double>("EEtimeFitLimits_Lower");
0120   EEtimeFitLimits.second = ps.getParameter<double>("EEtimeFitLimits_Upper");
0121 
0122   auto EBtimeConstantTerm = ps.getParameter<double>("EBtimeConstantTerm");
0123   auto EEtimeConstantTerm = ps.getParameter<double>("EEtimeConstantTerm");
0124   auto EBtimeNconst = ps.getParameter<double>("EBtimeNconst");
0125   auto EEtimeNconst = ps.getParameter<double>("EEtimeNconst");
0126 
0127   auto outOfTimeThreshG12pEB = ps.getParameter<double>("outOfTimeThresholdGain12pEB");
0128   auto outOfTimeThreshG12mEB = ps.getParameter<double>("outOfTimeThresholdGain12mEB");
0129   auto outOfTimeThreshG61pEB = ps.getParameter<double>("outOfTimeThresholdGain61pEB");
0130   auto outOfTimeThreshG61mEB = ps.getParameter<double>("outOfTimeThresholdGain61mEB");
0131   auto outOfTimeThreshG12pEE = ps.getParameter<double>("outOfTimeThresholdGain12pEE");
0132   auto outOfTimeThreshG12mEE = ps.getParameter<double>("outOfTimeThresholdGain12mEE");
0133   auto outOfTimeThreshG61pEE = ps.getParameter<double>("outOfTimeThresholdGain61pEE");
0134   auto outOfTimeThreshG61mEE = ps.getParameter<double>("outOfTimeThresholdGain61mEE");
0135   auto amplitudeThreshEB = ps.getParameter<double>("amplitudeThresholdEB");
0136   auto amplitudeThreshEE = ps.getParameter<double>("amplitudeThresholdEE");
0137 
0138   // switch to run timing computation kernels
0139   configParameters_.shouldRunTimingComputation = ps.getParameter<bool>("shouldRunTimingComputation");
0140 
0141   // minimize kernel launch conf
0142   auto threadsMinimize = ps.getUntrackedParameter<std::vector<uint32_t>>("kernelMinimizeThreads");
0143   configParameters_.kernelMinimizeThreads[0] = threadsMinimize[0];
0144   configParameters_.kernelMinimizeThreads[1] = threadsMinimize[1];
0145   configParameters_.kernelMinimizeThreads[2] = threadsMinimize[2];
0146 
0147   //
0148   // configuration and physics parameters: done once
0149   // assume there is a single device
0150   // use sync copying
0151   //
0152 
0153   // time fit parameters and limits
0154   configParameters_.timeFitLimitsFirstEB = EBtimeFitLimits.first;
0155   configParameters_.timeFitLimitsSecondEB = EBtimeFitLimits.second;
0156   configParameters_.timeFitLimitsFirstEE = EEtimeFitLimits.first;
0157   configParameters_.timeFitLimitsSecondEE = EEtimeFitLimits.second;
0158 
0159   // time constant terms
0160   configParameters_.timeConstantTermEB = EBtimeConstantTerm;
0161   configParameters_.timeConstantTermEE = EEtimeConstantTerm;
0162 
0163   // time N const
0164   configParameters_.timeNconstEB = EBtimeNconst;
0165   configParameters_.timeNconstEE = EEtimeNconst;
0166 
0167   // amplitude threshold for time flags
0168   configParameters_.amplitudeThreshEB = amplitudeThreshEB;
0169   configParameters_.amplitudeThreshEE = amplitudeThreshEE;
0170 
0171   // out of time thresholds gain-dependent
0172   configParameters_.outOfTimeThreshG12pEB = outOfTimeThreshG12pEB;
0173   configParameters_.outOfTimeThreshG12pEE = outOfTimeThreshG12pEE;
0174   configParameters_.outOfTimeThreshG61pEB = outOfTimeThreshG61pEB;
0175   configParameters_.outOfTimeThreshG61pEE = outOfTimeThreshG61pEE;
0176   configParameters_.outOfTimeThreshG12mEB = outOfTimeThreshG12mEB;
0177   configParameters_.outOfTimeThreshG12mEE = outOfTimeThreshG12mEE;
0178   configParameters_.outOfTimeThreshG61mEB = outOfTimeThreshG61mEB;
0179   configParameters_.outOfTimeThreshG61mEE = outOfTimeThreshG61mEE;
0180 }
0181 
0182 EcalUncalibRecHitProducerGPU::~EcalUncalibRecHitProducerGPU() {}
0183 
0184 void EcalUncalibRecHitProducerGPU::produce(edm::Event& event, edm::EventSetup const& setup) {
0185   //DurationMeasurer<std::chrono::milliseconds> timer{std::string{"produce duration"}};
0186 
0187   // cuda products
0188   auto const& ebDigisProduct = event.get(digisTokenEB_);
0189   auto const& eeDigisProduct = event.get(digisTokenEE_);
0190   // event data
0191   ecal::multifit::EventOutputDataGPU eventOutputDataGPU;
0192 
0193   // raii
0194   cms::cuda::ScopedContextProduce ctx{ebDigisProduct};
0195 
0196   // get actual obj
0197   auto const& ebDigis = ctx.get(ebDigisProduct);
0198   auto const& eeDigis = ctx.get(eeDigisProduct);
0199   ecal::multifit::EventInputDataGPU inputDataGPU{ebDigis, eeDigis};
0200   const uint32_t neb = ebDigis.size;
0201   const uint32_t nee = eeDigis.size;
0202 
0203   // stop here if there are no digis
0204   if (neb + nee > 0) {
0205     // conditions
0206     auto const& timeCalibConstantsData = setup.getData(timeCalibConstantsToken_);
0207     auto const& sampleMaskData = setup.getData(sampleMaskToken_);
0208     auto const& timeOffsetConstantData = setup.getData(timeOffsetConstantToken_);
0209     auto const& multifitParametersData = setup.getData(multifitParametersToken_);
0210 
0211     auto const& pedestals = setup.getData(pedestalsToken_).getProduct(ctx.stream());
0212     auto const& gainRatios = setup.getData(gainRatiosToken_).getProduct(ctx.stream());
0213     auto const& pulseShapes = setup.getData(pulseShapesToken_).getProduct(ctx.stream());
0214     auto const& pulseCovariances = setup.getData(pulseCovariancesToken_).getProduct(ctx.stream());
0215     auto const& samplesCorrelation = setup.getData(samplesCorrelationToken_).getProduct(ctx.stream());
0216     auto const& timeBiasCorrections = setup.getData(timeBiasCorrectionsToken_).getProduct(ctx.stream());
0217     auto const& timeCalibConstants = timeCalibConstantsData.getProduct(ctx.stream());
0218     auto const& multifitParameters = multifitParametersData.getProduct(ctx.stream());
0219 
0220     // assign ptrs/values: this is done not to change how things look downstream
0221     configParameters_.amplitudeFitParametersEB = multifitParameters.amplitudeFitParametersEB.get();
0222     configParameters_.amplitudeFitParametersEE = multifitParameters.amplitudeFitParametersEE.get();
0223     configParameters_.timeFitParametersEB = multifitParameters.timeFitParametersEB.get();
0224     configParameters_.timeFitParametersEE = multifitParameters.timeFitParametersEE.get();
0225     configParameters_.timeFitParametersSizeEB = multifitParametersData.getValues()[2].get().size();
0226     configParameters_.timeFitParametersSizeEE = multifitParametersData.getValues()[3].get().size();
0227 
0228     // bundle up conditions
0229     ecal::multifit::ConditionsProducts conditions{pedestals,
0230                                                   gainRatios,
0231                                                   pulseShapes,
0232                                                   pulseCovariances,
0233                                                   samplesCorrelation,
0234                                                   timeBiasCorrections,
0235                                                   timeCalibConstants,
0236                                                   sampleMaskData,
0237                                                   timeOffsetConstantData,
0238                                                   timeCalibConstantsData.getOffset(),
0239                                                   multifitParameters};
0240 
0241     // dev mem
0242     eventOutputDataGPU.allocate(configParameters_, neb, nee, ctx.stream());
0243 
0244     // scratch mem
0245     ecal::multifit::EventDataForScratchGPU eventDataForScratchGPU;
0246     eventDataForScratchGPU.allocate(configParameters_, neb, nee, ctx.stream());
0247 
0248     //
0249     // schedule algorithms
0250     //
0251     ecal::multifit::entryPoint(
0252         inputDataGPU, eventOutputDataGPU, eventDataForScratchGPU, conditions, configParameters_, ctx.stream());
0253   }
0254 
0255   // set the size of eb and ee
0256   eventOutputDataGPU.recHitsEB.size = neb;
0257   eventOutputDataGPU.recHitsEE.size = nee;
0258 
0259   // put into the event
0260   ctx.emplace(event, recHitsTokenEB_, std::move(eventOutputDataGPU.recHitsEB));
0261   ctx.emplace(event, recHitsTokenEE_, std::move(eventOutputDataGPU.recHitsEE));
0262 }
0263 
0264 DEFINE_FWK_MODULE(EcalUncalibRecHitProducerGPU);