Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/ESTransientHandle.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 
0004 #include <algorithm>
0005 #include <cassert>
0006 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
0007 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
0008 #include "CondFormats/DataRecord/interface/EcalPulseCovariancesRcd.h"
0009 #include "CondFormats/DataRecord/interface/EcalPulseShapesRcd.h"
0010 #include "CondFormats/DataRecord/interface/EcalSampleMaskRcd.h"
0011 #include "CondFormats/DataRecord/interface/EcalSamplesCorrelationRcd.h"
0012 #include "CondFormats/DataRecord/interface/EcalTimeBiasCorrectionsRcd.h"
0013 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
0014 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
0015 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
0016 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
0017 #include "CondFormats/EcalObjects/interface/EcalPulseCovariances.h"
0018 #include "CondFormats/EcalObjects/interface/EcalPulseShapes.h"
0019 #include "CondFormats/EcalObjects/interface/EcalSamplesCorrelation.h"
0020 #include "CondFormats/EcalObjects/interface/EcalSampleMask.h"
0021 #include "CondFormats/EcalObjects/interface/EcalTimeBiasCorrections.h"
0022 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h"
0023 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
0024 
0025 #include "CondFormats/EcalObjects/interface/alpaka/EcalMultifitConditionsDevice.h"
0026 #include "CondFormats/EcalObjects/interface/EcalMultifitConditionsSoA.h"
0027 #include "CondFormats/DataRecord/interface/EcalMultifitConditionsRcd.h"
0028 
0029 #include "DataFormats/EcalDigi/interface/EcalConstants.h"
0030 #include "CondFormats/EcalObjects/interface/EcalPulseShapes.h"
0031 
0032 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0033 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0034 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0035 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0036 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0037 #include "HeterogeneousCore/AlpakaInterface/interface/host.h"
0038 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0039 
0040 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0041   class EcalMultifitConditionsHostESProducer : public ESProducer {
0042   public:
0043     EcalMultifitConditionsHostESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0044       auto cc = setWhatProduced(this);
0045       pedestalsToken_ = cc.consumes();
0046       gainRatiosToken_ = cc.consumes();
0047       pulseShapesToken_ = cc.consumes();
0048       pulseCovariancesToken_ = cc.consumes();
0049       samplesCorrelationToken_ = cc.consumes();
0050       timeBiasCorrectionsToken_ = cc.consumes();
0051       timeCalibConstantsToken_ = cc.consumes();
0052       sampleMaskToken_ = cc.consumes();
0053       timeOffsetConstantToken_ = cc.consumes();
0054     }
0055 
0056     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0057       edm::ParameterSetDescription desc;
0058       descriptions.addWithDefaultLabel(desc);
0059     }
0060 
0061     std::unique_ptr<EcalMultifitConditionsHost> produce(EcalMultifitConditionsRcd const& iRecord) {
0062       auto const& pedestalsData = iRecord.get(pedestalsToken_);
0063       auto const& gainRatiosData = iRecord.get(gainRatiosToken_);
0064       auto const& pulseShapesData = iRecord.get(pulseShapesToken_);
0065       auto const& pulseCovariancesData = iRecord.get(pulseCovariancesToken_);
0066       auto const& samplesCorrelationData = iRecord.get(samplesCorrelationToken_);
0067       auto const& timeBiasCorrectionsData = iRecord.get(timeBiasCorrectionsToken_);
0068       auto const& timeCalibConstantsData = iRecord.get(timeCalibConstantsToken_);
0069       auto const& sampleMaskData = iRecord.get(sampleMaskToken_);
0070       auto const& timeOffsetConstantData = iRecord.get(timeOffsetConstantToken_);
0071 
0072       size_t numberOfXtals = pedestalsData.size();
0073 
0074       auto product = std::make_unique<EcalMultifitConditionsHost>(numberOfXtals, cms::alpakatools::host());
0075       auto view = product->view();
0076 
0077       // Filling pedestals
0078       const auto barrelSize = pedestalsData.barrelItems().size();
0079       const auto endcapSize = pedestalsData.endcapItems().size();
0080 
0081       auto const& pedestalsEB = pedestalsData.barrelItems();
0082       auto const& pedestalsEE = pedestalsData.endcapItems();
0083       auto const& gainRatiosEB = gainRatiosData.barrelItems();
0084       auto const& gainRatiosEE = gainRatiosData.endcapItems();
0085       auto const& pulseShapesEB = pulseShapesData.barrelItems();
0086       auto const& pulseShapesEE = pulseShapesData.endcapItems();
0087       auto const& pulseCovariancesEB = pulseCovariancesData.barrelItems();
0088       auto const& pulseCovariancesEE = pulseCovariancesData.endcapItems();
0089       auto const& timeCalibConstantsEB = timeCalibConstantsData.barrelItems();
0090       auto const& timeCalibConstantsEE = timeCalibConstantsData.endcapItems();
0091 
0092       for (unsigned int i = 0; i < barrelSize; ++i) {
0093         auto vi = view[i];
0094 
0095         vi.pedestals_mean_x12() = pedestalsEB[i].mean_x12;
0096         vi.pedestals_rms_x12() = pedestalsEB[i].rms_x12;
0097         vi.pedestals_mean_x6() = pedestalsEB[i].mean_x6;
0098         vi.pedestals_rms_x6() = pedestalsEB[i].rms_x6;
0099         vi.pedestals_mean_x1() = pedestalsEB[i].mean_x1;
0100         vi.pedestals_rms_x1() = pedestalsEB[i].rms_x1;
0101 
0102         vi.gain12Over6() = gainRatiosEB[i].gain12Over6();
0103         vi.gain6Over1() = gainRatiosEB[i].gain6Over1();
0104 
0105         vi.timeCalibConstants() = timeCalibConstantsEB[i];
0106 
0107         std::memcpy(vi.pulseShapes().data(), pulseShapesEB[i].pdfval, sizeof(float) * EcalPulseShape::TEMPLATESAMPLES);
0108         for (unsigned int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0109           for (unsigned int k = 0; k < EcalPulseShape::TEMPLATESAMPLES; ++k) {
0110             vi.pulseCovariance()(j, k) = pulseCovariancesEB[i].val(j, k);
0111           }
0112         }
0113       }  // end Barrel loop
0114       for (unsigned int i = 0; i < endcapSize; ++i) {
0115         auto vi = view[barrelSize + i];
0116 
0117         vi.pedestals_mean_x12() = pedestalsEE[i].mean_x12;
0118         vi.pedestals_rms_x12() = pedestalsEE[i].rms_x12;
0119         vi.pedestals_mean_x6() = pedestalsEE[i].mean_x6;
0120         vi.pedestals_rms_x6() = pedestalsEE[i].rms_x6;
0121         vi.pedestals_mean_x1() = pedestalsEE[i].mean_x1;
0122         vi.pedestals_rms_x1() = pedestalsEE[i].rms_x1;
0123 
0124         vi.gain12Over6() = gainRatiosEE[i].gain12Over6();
0125         vi.gain6Over1() = gainRatiosEE[i].gain6Over1();
0126 
0127         vi.timeCalibConstants() = timeCalibConstantsEE[i];
0128 
0129         std::memcpy(vi.pulseShapes().data(), pulseShapesEE[i].pdfval, sizeof(float) * EcalPulseShape::TEMPLATESAMPLES);
0130 
0131         for (unsigned int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0132           for (unsigned int k = 0; k < EcalPulseShape::TEMPLATESAMPLES; ++k) {
0133             vi.pulseCovariance()(j, k) = pulseCovariancesEE[i].val(j, k);
0134           }
0135         }
0136       }  // end Endcap loop
0137 
0138       // === Scalar data (not by xtal)
0139       // TimeBiasCorrection
0140       auto const timeCorrAmplBinsSizeEB = timeBiasCorrectionsData.EBTimeCorrAmplitudeBins.size();
0141       auto const timeCorrShiftBinsSizeEB = timeBiasCorrectionsData.EBTimeCorrShiftBins.size();
0142       // Assert that there are not more parameters than the EcalMultiFitConditionsSoA expects
0143       assert(timeCorrAmplBinsSizeEB <= kMaxTimeBiasCorrectionBinsEB);
0144       assert(timeCorrShiftBinsSizeEB <= kMaxTimeBiasCorrectionBinsEB);
0145       std::memcpy(view.timeBiasCorrections_amplitude_EB().data(),
0146                   timeBiasCorrectionsData.EBTimeCorrAmplitudeBins.data(),
0147                   sizeof(float) * timeCorrAmplBinsSizeEB);
0148       std::memcpy(view.timeBiasCorrections_shift_EB().data(),
0149                   timeBiasCorrectionsData.EBTimeCorrShiftBins.data(),
0150                   sizeof(float) * timeCorrShiftBinsSizeEB);
0151 
0152       auto const timeCorrAmplBinsSizeEE = timeBiasCorrectionsData.EETimeCorrAmplitudeBins.size();
0153       auto const timeCorrShiftBinsSizeEE = timeBiasCorrectionsData.EETimeCorrShiftBins.size();
0154       // Assert that there are not more parameters than the EcalMultiFitConditionsSoA expects
0155       assert(timeCorrAmplBinsSizeEE <= kMaxTimeBiasCorrectionBinsEE);
0156       assert(timeCorrShiftBinsSizeEE <= kMaxTimeBiasCorrectionBinsEE);
0157       std::memcpy(view.timeBiasCorrections_amplitude_EE().data(),
0158                   timeBiasCorrectionsData.EETimeCorrAmplitudeBins.data(),
0159                   sizeof(float) * timeCorrAmplBinsSizeEE);
0160       std::memcpy(view.timeBiasCorrections_shift_EE().data(),
0161                   timeBiasCorrectionsData.EETimeCorrShiftBins.data(),
0162                   sizeof(float) * timeCorrShiftBinsSizeEE);
0163 
0164       view.timeBiasCorrectionSizeEB() = std::min(timeCorrAmplBinsSizeEB, kMaxTimeBiasCorrectionBinsEB);
0165       view.timeBiasCorrectionSizeEE() = std::min(timeCorrAmplBinsSizeEE, kMaxTimeBiasCorrectionBinsEE);
0166 
0167       // SampleCorrelation
0168       std::memcpy(view.sampleCorrelation_EB_G12().data(),
0169                   samplesCorrelationData.EBG12SamplesCorrelation.data(),
0170                   sizeof(double) * ecalPh1::sampleSize);
0171       std::memcpy(view.sampleCorrelation_EB_G6().data(),
0172                   samplesCorrelationData.EBG6SamplesCorrelation.data(),
0173                   sizeof(double) * ecalPh1::sampleSize);
0174       std::memcpy(view.sampleCorrelation_EB_G1().data(),
0175                   samplesCorrelationData.EBG1SamplesCorrelation.data(),
0176                   sizeof(double) * ecalPh1::sampleSize);
0177 
0178       std::memcpy(view.sampleCorrelation_EE_G12().data(),
0179                   samplesCorrelationData.EEG12SamplesCorrelation.data(),
0180                   sizeof(double) * ecalPh1::sampleSize);
0181       std::memcpy(view.sampleCorrelation_EE_G6().data(),
0182                   samplesCorrelationData.EEG6SamplesCorrelation.data(),
0183                   sizeof(double) * ecalPh1::sampleSize);
0184       std::memcpy(view.sampleCorrelation_EE_G1().data(),
0185                   samplesCorrelationData.EEG1SamplesCorrelation.data(),
0186                   sizeof(double) * ecalPh1::sampleSize);
0187 
0188       // Sample masks
0189       view.sampleMask_EB() = sampleMaskData.getEcalSampleMaskRecordEB();
0190       view.sampleMask_EE() = sampleMaskData.getEcalSampleMaskRecordEE();
0191 
0192       // Time offsets
0193       view.timeOffset_EB() = timeOffsetConstantData.getEBValue();
0194       view.timeOffset_EE() = timeOffsetConstantData.getEEValue();
0195 
0196       // number of barrel items as offset for hashed ID access to EE items of columns
0197       view.offsetEE() = barrelSize;
0198 
0199       return product;
0200     }
0201 
0202   private:
0203     edm::ESGetToken<EcalPedestals, EcalPedestalsRcd> pedestalsToken_;
0204     edm::ESGetToken<EcalGainRatios, EcalGainRatiosRcd> gainRatiosToken_;
0205     edm::ESGetToken<EcalPulseShapes, EcalPulseShapesRcd> pulseShapesToken_;
0206     edm::ESGetToken<EcalPulseCovariances, EcalPulseCovariancesRcd> pulseCovariancesToken_;
0207     edm::ESGetToken<EcalSamplesCorrelation, EcalSamplesCorrelationRcd> samplesCorrelationToken_;
0208     edm::ESGetToken<EcalTimeBiasCorrections, EcalTimeBiasCorrectionsRcd> timeBiasCorrectionsToken_;
0209     edm::ESGetToken<EcalTimeCalibConstants, EcalTimeCalibConstantsRcd> timeCalibConstantsToken_;
0210     edm::ESGetToken<EcalSampleMask, EcalSampleMaskRcd> sampleMaskToken_;
0211     edm::ESGetToken<EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd> timeOffsetConstantToken_;
0212   };
0213 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0214 
0215 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(EcalMultifitConditionsHostESProducer);