Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-05 02:13:41

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