Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-27 06:44:04

0001 #include "DQM/EcalMonitorTasks/interface/GpuTask.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "DQM/EcalCommon/interface/MESetMulti.h"
0005 
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
0010 #include "DataFormats/EcalDigi/interface/EcalConstants.h"
0011 
0012 namespace ecaldqm {
0013   GpuTask::GpuTask()
0014       : DQWorkerTask(),
0015         runGpuTask_(false),
0016         enableDigi_(false),
0017         enableUncalib_(false),
0018         enableRecHit_(false),
0019         digi1D_(false),
0020         digi2D_(false),
0021         uncalib1D_(false),
0022         uncalib2D_(false),
0023         rechit1D_(false),
0024         rechit2D_(false),
0025         EBCpuDigis_(nullptr),
0026         EECpuDigis_(nullptr),
0027         EBCpuUncalibRecHits_(nullptr),
0028         EECpuUncalibRecHits_(nullptr),
0029         EBCpuRecHits_(nullptr),
0030         EECpuRecHits_(nullptr) {}
0031 
0032   void GpuTask::addDependencies(DependencySet& dependencies) {
0033     // Ensure we run on CPU objects before GPU objects
0034     if (runGpuTask_) {
0035       dependencies.push_back(Dependency(kEBGpuDigi, kEBCpuDigi));
0036       dependencies.push_back(Dependency(kEEGpuDigi, kEECpuDigi));
0037 
0038       dependencies.push_back(Dependency(kEBGpuUncalibRecHit, kEBCpuUncalibRecHit));
0039       dependencies.push_back(Dependency(kEEGpuUncalibRecHit, kEECpuUncalibRecHit));
0040 
0041       dependencies.push_back(Dependency(kEBGpuRecHit, kEBCpuRecHit));
0042       dependencies.push_back(Dependency(kEEGpuRecHit, kEECpuRecHit));
0043     }
0044   }
0045 
0046   void GpuTask::setParams(edm::ParameterSet const& params) {
0047     runGpuTask_ = params.getUntrackedParameter<bool>("runGpuTask");
0048 
0049     // Enabling objects set to false if runGpuTask_ is false
0050     enableDigi_ = runGpuTask_ && params.getUntrackedParameter<bool>("enableDigi");
0051     enableUncalib_ = runGpuTask_ && params.getUntrackedParameter<bool>("enableUncalib");
0052     enableRecHit_ = runGpuTask_ && params.getUntrackedParameter<bool>("enableRecHit");
0053 
0054     // Flags set to false if corresponding type is not enabled
0055     digi1D_ = enableDigi_ && params.getUntrackedParameter<bool>("digi1D");
0056     digi2D_ = enableDigi_ && params.getUntrackedParameter<bool>("digi2D");
0057     uncalib1D_ = enableUncalib_ && params.getUntrackedParameter<bool>("uncalib1D");
0058     uncalib2D_ = enableUncalib_ && params.getUntrackedParameter<bool>("uncalib2D");
0059     rechit1D_ = enableRecHit_ && params.getUntrackedParameter<bool>("rechit1D");
0060     rechit2D_ = enableRecHit_ && params.getUntrackedParameter<bool>("rechit2D");
0061 
0062     uncalibOOTAmps_ = params.getUntrackedParameter<std::vector<int> >("uncalibOOTAmps");
0063 
0064     if (!enableDigi_) {
0065       MEs_.erase(std::string("DigiCpu"));
0066       MEs_.erase(std::string("DigiCpuAmplitude"));
0067       MEs_.erase(std::string("DigiGpuCpu"));
0068       MEs_.erase(std::string("DigiGpuCpuAmplitude"));
0069     }
0070     if (!enableUncalib_) {
0071       MEs_.erase(std::string("UncalibCpu"));
0072       MEs_.erase(std::string("UncalibCpuAmp"));
0073       MEs_.erase(std::string("UncalibCpuAmpError"));
0074       MEs_.erase(std::string("UncalibCpuPedestal"));
0075       MEs_.erase(std::string("UncalibCpuJitter"));
0076       MEs_.erase(std::string("UncalibCpuJitterError"));
0077       MEs_.erase(std::string("UncalibCpuChi2"));
0078       MEs_.erase(std::string("UncalibCpuOOTAmp"));
0079       MEs_.erase(std::string("UncalibCpuFlags"));
0080       MEs_.erase(std::string("UncalibGpuCpu"));
0081       MEs_.erase(std::string("UncalibGpuCpuAmp"));
0082       MEs_.erase(std::string("UncalibGpuCpuAmpError"));
0083       MEs_.erase(std::string("UncalibGpuCpuPedestal"));
0084       MEs_.erase(std::string("UncalibGpuCpuJitter"));
0085       MEs_.erase(std::string("UncalibGpuCpuJitterError"));
0086       MEs_.erase(std::string("UncalibGpuCpuChi2"));
0087       MEs_.erase(std::string("UncalibGpuCpuOOTAmp"));
0088       MEs_.erase(std::string("UncalibGpuCpuFlags"));
0089     }
0090     if (!enableRecHit_) {
0091       MEs_.erase(std::string("RecHitCpu"));
0092       MEs_.erase(std::string("RecHitCpuEnergy"));
0093       MEs_.erase(std::string("RecHitCpuTime"));
0094       MEs_.erase(std::string("RecHitCpuFlags"));
0095       MEs_.erase(std::string("RecHitGpuCpu"));
0096       MEs_.erase(std::string("RecHitGpuCpuEnergy"));
0097       MEs_.erase(std::string("RecHitGpuCpuTime"));
0098       MEs_.erase(std::string("RecHitGpuCpuFlags"));
0099     }
0100     if (!digi1D_) {
0101       MEs_.erase(std::string("DigiGpu"));
0102       MEs_.erase(std::string("DigiGpuAmplitude"));
0103     }
0104     if (!uncalib1D_) {
0105       MEs_.erase(std::string("UncalibGpu"));
0106       MEs_.erase(std::string("UncalibGpuAmp"));
0107       MEs_.erase(std::string("UncalibGpuAmpError"));
0108       MEs_.erase(std::string("UncalibGpuPedestal"));
0109       MEs_.erase(std::string("UncalibGpuJitter"));
0110       MEs_.erase(std::string("UncalibGpuJitterError"));
0111       MEs_.erase(std::string("UncalibGpuChi2"));
0112       MEs_.erase(std::string("UncalibGpuOOTAmp"));
0113       MEs_.erase(std::string("UncalibGpuFlags"));
0114     }
0115     if (!rechit1D_) {
0116       MEs_.erase(std::string("RecHitGpu"));
0117       MEs_.erase(std::string("RecHitGpuEnergy"));
0118       MEs_.erase(std::string("RecHitGpuTime"));
0119       MEs_.erase(std::string("RecHitGpuFlags"));
0120     }
0121     if (!digi2D_) {
0122       MEs_.erase(std::string("Digi2D"));
0123       MEs_.erase(std::string("Digi2DAmplitude"));
0124     }
0125     if (!uncalib2D_) {
0126       MEs_.erase(std::string("Uncalib2D"));
0127       MEs_.erase(std::string("Uncalib2DAmp"));
0128       MEs_.erase(std::string("Uncalib2DAmpError"));
0129       MEs_.erase(std::string("Uncalib2DPedestal"));
0130       MEs_.erase(std::string("Uncalib2DJitter"));
0131       MEs_.erase(std::string("Uncalib2DJitterError"));
0132       MEs_.erase(std::string("Uncalib2DChi2"));
0133       MEs_.erase(std::string("Uncalib2DOOTAmp"));
0134       MEs_.erase(std::string("Uncalib2DFlags"));
0135     }
0136     if (!rechit2D_) {
0137       MEs_.erase(std::string("RecHit2D"));
0138       MEs_.erase(std::string("RecHit2DEnergy"));
0139       MEs_.erase(std::string("RecHit2DTime"));
0140       MEs_.erase(std::string("RecHit2DFlags"));
0141     }
0142   }
0143 
0144   bool GpuTask::filterRunType(short const* runType) {
0145     for (unsigned iFED(0); iFED != ecaldqm::nDCC; iFED++) {
0146       if (runType[iFED] == EcalDCCHeaderBlock::COSMIC || runType[iFED] == EcalDCCHeaderBlock::MTCC ||
0147           runType[iFED] == EcalDCCHeaderBlock::COSMICS_GLOBAL || runType[iFED] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
0148           runType[iFED] == EcalDCCHeaderBlock::COSMICS_LOCAL || runType[iFED] == EcalDCCHeaderBlock::PHYSICS_LOCAL)
0149         return true;
0150     }
0151 
0152     return false;
0153   }
0154 
0155   void GpuTask::beginEvent(edm::Event const&, edm::EventSetup const&, bool const&, bool&) {
0156     EBCpuDigis_ = nullptr;
0157     EECpuDigis_ = nullptr;
0158     EBCpuUncalibRecHits_ = nullptr;
0159     EECpuUncalibRecHits_ = nullptr;
0160     EBCpuRecHits_ = nullptr;
0161     EECpuRecHits_ = nullptr;
0162   }
0163 
0164   template <typename DigiCollection>
0165   void GpuTask::runOnCpuDigis(DigiCollection const& cpuDigis, Collections collection) {
0166     // Return if not enabled
0167     if (!enableDigi_)
0168       return;
0169 
0170     MESet& meDigiCpu(MEs_.at("DigiCpu"));
0171     MESet& meDigiCpuAmplitude(MEs_.at("DigiCpuAmplitude"));
0172 
0173     int iSubdet(collection == kEBCpuDigi ? EcalBarrel : EcalEndcap);
0174 
0175     // Save CpuDigis for comparison with GpuDigis
0176     // "if constexpr" ensures cpuDigis is the correct type at compile time
0177     if constexpr (std::is_same_v<DigiCollection, EBDigiCollection>) {
0178       assert(iSubdet == EcalBarrel);
0179       EBCpuDigis_ = &cpuDigis;
0180     } else {
0181       assert(iSubdet == EcalEndcap);
0182       EECpuDigis_ = &cpuDigis;
0183     }
0184 
0185     unsigned nCpuDigis(cpuDigis.size());
0186     meDigiCpu.fill(getEcalDQMSetupObjects(), iSubdet, nCpuDigis);
0187 
0188     for (auto const& cpuDigi : cpuDigis) {
0189       // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame (digis) in the constructor
0190       EcalDataFrame cpuDataFrame(cpuDigi);
0191 
0192       for (unsigned iSample = 0; iSample < ecalPh1::sampleSize; iSample++) {
0193         static_cast<MESetMulti&>(meDigiCpuAmplitude).use(iSample);
0194 
0195         int cpuAmp(cpuDataFrame.sample(iSample).adc());
0196         meDigiCpuAmplitude.fill(getEcalDQMSetupObjects(), iSubdet, cpuAmp);
0197       }
0198     }
0199   }
0200 
0201   template <typename DigiCollection>
0202   void GpuTask::runOnGpuDigis(DigiCollection const& gpuDigis, Collections collection) {
0203     // Return if not enabled
0204     if (!enableDigi_)
0205       return;
0206 
0207     MESet& meDigiGpuCpu(MEs_.at("DigiGpuCpu"));
0208     MESet& meDigiGpuCpuAmplitude(MEs_.at("DigiGpuCpuAmplitude"));
0209 
0210     int iSubdet(collection == kEBGpuDigi ? EcalBarrel : EcalEndcap);
0211 
0212     // Get CpuDigis saved from GpuTask::runOnCpuDigis() for this event
0213     // "if constexpr" ensures cpuDigis is the correct type at compile time
0214     // Note: gpuDigis is a collection and cpuDigis is a pointer to a collection (for historical reasons)
0215     DigiCollection const* cpuDigis;
0216     if constexpr (std::is_same_v<DigiCollection, EBDigiCollection>) {
0217       assert(iSubdet == EcalBarrel);
0218       cpuDigis = EBCpuDigis_;
0219     } else {
0220       assert(iSubdet == EcalEndcap);
0221       cpuDigis = EECpuDigis_;
0222     }
0223 
0224     if (!cpuDigis) {
0225       edm::LogWarning("EcalDQM") << "GpuTask: Did not find " << ((iSubdet == EcalBarrel) ? "EB" : "EE")
0226                                  << "CpuDigis Collection. Aborting runOnGpuDigis\n";
0227       return;
0228     }
0229 
0230     unsigned nGpuDigis(gpuDigis.size());
0231     unsigned nCpuDigis(cpuDigis->size());
0232 
0233     meDigiGpuCpu.fill(getEcalDQMSetupObjects(), iSubdet, nGpuDigis - nCpuDigis);
0234 
0235     if (digi1D_) {
0236       MESet& meDigiGpu(MEs_.at("DigiGpu"));
0237       meDigiGpu.fill(getEcalDQMSetupObjects(), iSubdet, nGpuDigis);
0238     }
0239 
0240     if (digi2D_) {
0241       MESet& meDigi2D(MEs_.at("Digi2D"));
0242       meDigi2D.fill(getEcalDQMSetupObjects(), iSubdet, nCpuDigis, nGpuDigis);
0243     }
0244 
0245     for (auto const& gpuDigi : gpuDigis) {
0246       // Find CpuDigi with matching DetId
0247       DetId gpuId(gpuDigi.id());
0248       typename DigiCollection::const_iterator cpuItr(cpuDigis->find(gpuId));
0249       if (cpuItr == cpuDigis->end()) {
0250         edm::LogWarning("EcalDQM") << "GpuTask: Did not find CpuDigi DetId " << gpuId.rawId() << " in CPU collection\n";
0251         continue;
0252       }
0253 
0254       // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame (digis) in the constructor
0255       EcalDataFrame gpuDataFrame(gpuDigi);
0256       EcalDataFrame cpuDataFrame(*cpuItr);
0257 
0258       for (unsigned iSample = 0; iSample < ecalPh1::sampleSize; iSample++) {
0259         static_cast<MESetMulti&>(meDigiGpuCpuAmplitude).use(iSample);
0260 
0261         int gpuAmp(gpuDataFrame.sample(iSample).adc());
0262         int cpuAmp(cpuDataFrame.sample(iSample).adc());
0263 
0264         meDigiGpuCpuAmplitude.fill(getEcalDQMSetupObjects(), iSubdet, gpuAmp - cpuAmp);
0265 
0266         if (digi1D_) {
0267           MESet& meDigiGpuAmplitude(MEs_.at("DigiGpuAmplitude"));
0268           static_cast<MESetMulti&>(meDigiGpuAmplitude).use(iSample);
0269           meDigiGpuAmplitude.fill(getEcalDQMSetupObjects(), iSubdet, gpuAmp);
0270         }
0271 
0272         if (digi2D_) {
0273           MESet& meDigi2DAmplitude(MEs_.at("Digi2DAmplitude"));
0274           static_cast<MESetMulti&>(meDigi2DAmplitude).use(iSample);
0275           meDigi2DAmplitude.fill(getEcalDQMSetupObjects(), iSubdet, cpuAmp, gpuAmp);
0276         }
0277       }
0278     }
0279   }
0280 
0281   void GpuTask::runOnCpuUncalibRecHits(EcalUncalibratedRecHitCollection const& cpuHits, Collections collection) {
0282     // Return if not enabled
0283     if (!enableUncalib_)
0284       return;
0285 
0286     MESet& meUncalibCpu(MEs_.at("UncalibCpu"));
0287     MESet& meUncalibCpuAmp(MEs_.at("UncalibCpuAmp"));
0288     MESet& meUncalibCpuAmpError(MEs_.at("UncalibCpuAmpError"));
0289     MESet& meUncalibCpuPedestal(MEs_.at("UncalibCpuPedestal"));
0290     MESet& meUncalibCpuJitter(MEs_.at("UncalibCpuJitter"));
0291     MESet& meUncalibCpuJitterError(MEs_.at("UncalibCpuJitterError"));
0292     MESet& meUncalibCpuChi2(MEs_.at("UncalibCpuChi2"));
0293     MESet& meUncalibCpuOOTAmp(MEs_.at("UncalibCpuOOTAmp"));
0294     MESet& meUncalibCpuFlags(MEs_.at("UncalibCpuFlags"));
0295 
0296     int iSubdet(collection == kEBCpuUncalibRecHit ? EcalBarrel : EcalEndcap);
0297 
0298     // Save CpuUncalibRecHits for comparison with GpuUncalibRecHits
0299     if (iSubdet == EcalBarrel)
0300       EBCpuUncalibRecHits_ = &cpuHits;
0301     else
0302       EECpuUncalibRecHits_ = &cpuHits;
0303 
0304     unsigned nCpuHits(cpuHits.size());
0305     meUncalibCpu.fill(getEcalDQMSetupObjects(), iSubdet, nCpuHits);
0306 
0307     for (auto const& cpuHit : cpuHits) {
0308       float cpuAmp(cpuHit.amplitude());
0309       float cpuAmpError(cpuHit.amplitudeError());
0310       float cpuPedestal(cpuHit.pedestal());
0311       float cpuJitter(cpuHit.jitter());
0312       float cpuJitterError(cpuHit.jitterError());
0313       float cpuChi2(cpuHit.chi2());
0314       uint32_t cpuFlags(cpuHit.flags());
0315 
0316       if (cpuJitterError == 10000)  // Set this so 10000 (special value) shows up in last bin
0317         cpuJitterError = 0.249999;
0318 
0319       meUncalibCpuAmp.fill(getEcalDQMSetupObjects(), iSubdet, cpuAmp);
0320       meUncalibCpuAmpError.fill(getEcalDQMSetupObjects(), iSubdet, cpuAmpError);
0321       meUncalibCpuPedestal.fill(getEcalDQMSetupObjects(), iSubdet, cpuPedestal);
0322       meUncalibCpuJitter.fill(getEcalDQMSetupObjects(), iSubdet, cpuJitter);
0323       meUncalibCpuJitterError.fill(getEcalDQMSetupObjects(), iSubdet, cpuJitterError);
0324       meUncalibCpuChi2.fill(getEcalDQMSetupObjects(), iSubdet, cpuChi2);
0325       meUncalibCpuFlags.fill(getEcalDQMSetupObjects(), iSubdet, cpuFlags);
0326 
0327       for (unsigned iAmp = 0; iAmp < uncalibOOTAmps_.size(); iAmp++) {
0328         static_cast<MESetMulti&>(meUncalibCpuOOTAmp).use(iAmp);
0329 
0330         // Get corresponding OOT Amplitude
0331         int cpuOOTAmp(cpuHit.outOfTimeAmplitude(uncalibOOTAmps_[iAmp]));
0332         meUncalibCpuOOTAmp.fill(getEcalDQMSetupObjects(), iSubdet, cpuOOTAmp);
0333       }
0334     }
0335   }
0336 
0337   void GpuTask::runOnGpuUncalibRecHits(EcalUncalibratedRecHitCollection const& gpuHits, Collections collection) {
0338     // Return if not enabled
0339     if (!enableUncalib_)
0340       return;
0341 
0342     MESet& meUncalibGpuCpu(MEs_.at("UncalibGpuCpu"));
0343     MESet& meUncalibGpuCpuAmp(MEs_.at("UncalibGpuCpuAmp"));
0344     MESet& meUncalibGpuCpuAmpError(MEs_.at("UncalibGpuCpuAmpError"));
0345     MESet& meUncalibGpuCpuPedestal(MEs_.at("UncalibGpuCpuPedestal"));
0346     MESet& meUncalibGpuCpuJitter(MEs_.at("UncalibGpuCpuJitter"));
0347     MESet& meUncalibGpuCpuJitterError(MEs_.at("UncalibGpuCpuJitterError"));
0348     MESet& meUncalibGpuCpuChi2(MEs_.at("UncalibGpuCpuChi2"));
0349     MESet& meUncalibGpuCpuOOTAmp(MEs_.at("UncalibGpuCpuOOTAmp"));
0350     MESet& meUncalibGpuCpuFlags(MEs_.at("UncalibGpuCpuFlags"));
0351 
0352     int iSubdet(collection == kEBGpuUncalibRecHit ? EcalBarrel : EcalEndcap);
0353 
0354     // Get CpuUncalibRecHits saved from GpuTask::runOnCpuUncalibRecHits() for this event
0355     // Note: _gpuHits is a collection and cpuHits is a pointer to a collection (for historical reasons)
0356     EcalUncalibratedRecHitCollection const* cpuHits =
0357         (iSubdet == EcalBarrel) ? EBCpuUncalibRecHits_ : EECpuUncalibRecHits_;
0358     if (!cpuHits) {
0359       edm::LogWarning("EcalDQM") << "GpuTask: Did not find " << ((iSubdet == EcalBarrel) ? "EB" : "EE")
0360                                  << "CpuUncalibRecHits Collection. Aborting runOnGpuUncalibRecHits\n";
0361       return;
0362     }
0363 
0364     unsigned nGpuHits(gpuHits.size());
0365     unsigned nCpuHits(cpuHits->size());
0366 
0367     meUncalibGpuCpu.fill(getEcalDQMSetupObjects(), iSubdet, nGpuHits - nCpuHits);
0368 
0369     if (uncalib1D_) {
0370       MESet& meUncalibGpu(MEs_.at("UncalibGpu"));
0371       meUncalibGpu.fill(getEcalDQMSetupObjects(), iSubdet, nGpuHits);
0372     }
0373 
0374     if (uncalib2D_) {
0375       MESet& meUncalib2D(MEs_.at("Uncalib2D"));
0376       meUncalib2D.fill(getEcalDQMSetupObjects(), iSubdet, nCpuHits, nGpuHits);
0377     }
0378 
0379     for (auto const& gpuHit : gpuHits) {
0380       // Find CpuUncalibRecHit with matching DetId
0381       DetId gpuId(gpuHit.id());
0382       EcalUncalibratedRecHitCollection::const_iterator cpuItr(cpuHits->find(gpuId));
0383       if (cpuItr == cpuHits->end()) {
0384         edm::LogWarning("EcalDQM") << "GpuTask: Did not find GpuUncalibRecHit DetId " << gpuId.rawId()
0385                                    << " in CPU collection\n";
0386         continue;
0387       }
0388 
0389       float gpuAmp(gpuHit.amplitude());
0390       float gpuAmpError(gpuHit.amplitudeError());
0391       float gpuPedestal(gpuHit.pedestal());
0392       float gpuJitter(gpuHit.jitter());
0393       float gpuJitterError(gpuHit.jitterError());
0394       float gpuChi2(gpuHit.chi2());
0395       uint32_t gpuFlags(gpuHit.flags());
0396 
0397       if (gpuJitterError == 10000)  // Set this so 10000 (special value) shows up in last bin
0398         gpuJitterError = 0.249999;
0399 
0400       float cpuAmp(cpuItr->amplitude());
0401       float cpuAmpError(cpuItr->amplitudeError());
0402       float cpuPedestal(cpuItr->pedestal());
0403       float cpuJitter(cpuItr->jitter());
0404       float cpuJitterError(cpuItr->jitterError());
0405       float cpuChi2(cpuItr->chi2());
0406       uint32_t cpuFlags(cpuItr->flags());
0407 
0408       if (cpuJitterError == 10000)  // Set this so 10000 (special value) shows up in last bin
0409         cpuJitterError = 0.249999;
0410 
0411       meUncalibGpuCpuAmp.fill(getEcalDQMSetupObjects(), iSubdet, gpuAmp - cpuAmp);
0412       meUncalibGpuCpuAmpError.fill(getEcalDQMSetupObjects(), iSubdet, gpuAmpError - cpuAmpError);
0413       meUncalibGpuCpuPedestal.fill(getEcalDQMSetupObjects(), iSubdet, gpuPedestal - cpuPedestal);
0414       meUncalibGpuCpuJitter.fill(getEcalDQMSetupObjects(), iSubdet, gpuJitter - cpuJitter);
0415       meUncalibGpuCpuJitterError.fill(getEcalDQMSetupObjects(), iSubdet, gpuJitterError - cpuJitterError);
0416       meUncalibGpuCpuChi2.fill(getEcalDQMSetupObjects(), iSubdet, gpuChi2 - cpuChi2);
0417       meUncalibGpuCpuFlags.fill(getEcalDQMSetupObjects(), iSubdet, gpuFlags - cpuFlags);
0418 
0419       if (uncalib1D_) {
0420         MESet& meUncalibGpuAmp(MEs_.at("UncalibGpuAmp"));
0421         MESet& meUncalibGpuAmpError(MEs_.at("UncalibGpuAmpError"));
0422         MESet& meUncalibGpuPedestal(MEs_.at("UncalibGpuPedestal"));
0423         MESet& meUncalibGpuJitter(MEs_.at("UncalibGpuJitter"));
0424         MESet& meUncalibGpuJitterError(MEs_.at("UncalibGpuJitterError"));
0425         MESet& meUncalibGpuChi2(MEs_.at("UncalibGpuChi2"));
0426         MESet& meUncalibGpuFlags(MEs_.at("UncalibGpuFlags"));
0427 
0428         meUncalibGpuAmp.fill(getEcalDQMSetupObjects(), iSubdet, gpuAmp);
0429         meUncalibGpuAmpError.fill(getEcalDQMSetupObjects(), iSubdet, gpuAmpError);
0430         meUncalibGpuPedestal.fill(getEcalDQMSetupObjects(), iSubdet, gpuPedestal);
0431         meUncalibGpuJitter.fill(getEcalDQMSetupObjects(), iSubdet, gpuJitter);
0432         meUncalibGpuJitterError.fill(getEcalDQMSetupObjects(), iSubdet, gpuJitterError);
0433         meUncalibGpuChi2.fill(getEcalDQMSetupObjects(), iSubdet, gpuChi2);
0434         meUncalibGpuFlags.fill(getEcalDQMSetupObjects(), iSubdet, gpuFlags);
0435       }
0436 
0437       if (uncalib2D_) {
0438         MESet& meUncalib2DAmp(MEs_.at("Uncalib2DAmp"));
0439         MESet& meUncalib2DAmpError(MEs_.at("Uncalib2DAmpError"));
0440         MESet& meUncalib2DPedestal(MEs_.at("Uncalib2DPedestal"));
0441         MESet& meUncalib2DJitter(MEs_.at("Uncalib2DJitter"));
0442         MESet& meUncalib2DJitterError(MEs_.at("Uncalib2DJitterError"));
0443         MESet& meUncalib2DChi2(MEs_.at("Uncalib2DChi2"));
0444         MESet& meUncalib2DFlags(MEs_.at("Uncalib2DFlags"));
0445 
0446         meUncalib2DAmp.fill(getEcalDQMSetupObjects(), iSubdet, cpuAmp, gpuAmp);
0447         meUncalib2DAmpError.fill(getEcalDQMSetupObjects(), iSubdet, cpuAmpError, gpuAmpError);
0448         meUncalib2DPedestal.fill(getEcalDQMSetupObjects(), iSubdet, cpuPedestal, gpuPedestal);
0449         meUncalib2DJitter.fill(getEcalDQMSetupObjects(), iSubdet, cpuJitter, gpuJitter);
0450         meUncalib2DJitterError.fill(getEcalDQMSetupObjects(), iSubdet, cpuJitterError, gpuJitterError);
0451         meUncalib2DChi2.fill(getEcalDQMSetupObjects(), iSubdet, cpuChi2, gpuChi2);
0452         meUncalib2DFlags.fill(getEcalDQMSetupObjects(), iSubdet, cpuFlags, gpuFlags);
0453       }
0454 
0455       for (unsigned iAmp = 0; iAmp < uncalibOOTAmps_.size(); iAmp++) {
0456         static_cast<MESetMulti&>(meUncalibGpuCpuOOTAmp).use(iAmp);
0457 
0458         // Get corresponding OOT Amplitude
0459         int gpuOOTAmp(gpuHit.outOfTimeAmplitude(uncalibOOTAmps_[iAmp]));
0460         int cpuOOTAmp(cpuItr->outOfTimeAmplitude(uncalibOOTAmps_[iAmp]));
0461 
0462         meUncalibGpuCpuOOTAmp.fill(getEcalDQMSetupObjects(), iSubdet, gpuOOTAmp - cpuOOTAmp);
0463 
0464         if (uncalib1D_) {
0465           MESet& meUncalibGpuOOTAmp(MEs_.at("UncalibGpuOOTAmp"));
0466           static_cast<MESetMulti&>(meUncalibGpuOOTAmp).use(iAmp);
0467           meUncalibGpuOOTAmp.fill(getEcalDQMSetupObjects(), iSubdet, gpuOOTAmp);
0468         }
0469 
0470         if (uncalib2D_) {
0471           MESet& meUncalib2DOOTAmp(MEs_.at("Uncalib2DOOTAmp"));
0472           static_cast<MESetMulti&>(meUncalib2DOOTAmp).use(iAmp);
0473           meUncalib2DOOTAmp.fill(getEcalDQMSetupObjects(), iSubdet, cpuOOTAmp, gpuOOTAmp);
0474         }
0475       }
0476     }
0477   }
0478 
0479   void GpuTask::runOnCpuRecHits(EcalRecHitCollection const& cpuHits, Collections collection) {
0480     // Return if not enabled
0481     if (!enableRecHit_)
0482       return;
0483 
0484     MESet& meRecHitCpu(MEs_.at("RecHitCpu"));
0485     MESet& meRecHitCpuEnergy(MEs_.at("RecHitCpuEnergy"));
0486     MESet& meRecHitCpuTime(MEs_.at("RecHitCpuTime"));
0487     MESet& meRecHitCpuFlags(MEs_.at("RecHitCpuFlags"));
0488 
0489     int iSubdet(collection == kEBCpuRecHit ? EcalBarrel : EcalEndcap);
0490 
0491     // Save CpuRecHits for comparison with GpuRecHits
0492     if (iSubdet == EcalBarrel)
0493       EBCpuRecHits_ = &cpuHits;
0494     else
0495       EECpuRecHits_ = &cpuHits;
0496 
0497     unsigned nCpuHits(cpuHits.size());
0498     meRecHitCpu.fill(getEcalDQMSetupObjects(), iSubdet, nCpuHits);
0499 
0500     for (auto const& cpuHit : cpuHits) {
0501       float cpuEnergy(cpuHit.energy());
0502       float cpuTime(cpuHit.time());
0503       uint32_t cpuFlags(cpuHit.flagsBits());
0504 
0505       meRecHitCpuEnergy.fill(getEcalDQMSetupObjects(), iSubdet, cpuEnergy);
0506       meRecHitCpuTime.fill(getEcalDQMSetupObjects(), iSubdet, cpuTime);
0507       meRecHitCpuFlags.fill(getEcalDQMSetupObjects(), iSubdet, cpuFlags);
0508     }
0509   }
0510 
0511   void GpuTask::runOnGpuRecHits(EcalRecHitCollection const& gpuHits, Collections collection) {
0512     // Return if not enabled
0513     if (!enableRecHit_)
0514       return;
0515 
0516     MESet& meRecHitGpuCpu(MEs_.at("RecHitGpuCpu"));
0517     MESet& meRecHitGpuCpuEnergy(MEs_.at("RecHitGpuCpuEnergy"));
0518     MESet& meRecHitGpuCpuTime(MEs_.at("RecHitGpuCpuTime"));
0519     MESet& meRecHitGpuCpuFlags(MEs_.at("RecHitGpuCpuFlags"));
0520 
0521     int iSubdet(collection == kEBGpuRecHit ? EcalBarrel : EcalEndcap);
0522 
0523     // Get CpuRecHits saved from GpuTask::runOnCpuRecHits() for this event
0524     // Note: _gpuHits is a collection and cpuHits is a pointer to a collection (for historical reasons)
0525     EcalRecHitCollection const* cpuHits = (iSubdet == EcalBarrel) ? EBCpuRecHits_ : EECpuRecHits_;
0526     if (!cpuHits) {
0527       edm::LogWarning("EcalDQM") << "GpuTask: Did not find " << ((iSubdet == EcalBarrel) ? "EB" : "EE")
0528                                  << "CpuRecHits Collection. Aborting runOnGpuRecHits\n";
0529       return;
0530     }
0531 
0532     unsigned nGpuHits(gpuHits.size());
0533     unsigned nCpuHits(cpuHits->size());
0534 
0535     meRecHitGpuCpu.fill(getEcalDQMSetupObjects(), iSubdet, nGpuHits - nCpuHits);
0536 
0537     if (rechit1D_) {
0538       MESet& meRecHitGpu(MEs_.at("RecHitGpu"));
0539       meRecHitGpu.fill(getEcalDQMSetupObjects(), iSubdet, nGpuHits);
0540     }
0541     if (rechit2D_) {
0542       MESet& meRecHit2D(MEs_.at("RecHit2D"));
0543       meRecHit2D.fill(getEcalDQMSetupObjects(), iSubdet, nCpuHits, nGpuHits);
0544     }
0545 
0546     for (auto const& gpuHit : gpuHits) {
0547       // Find CpuRecHit with matching DetId
0548       DetId gpuId(gpuHit.detid());
0549       EcalRecHitCollection::const_iterator cpuItr(cpuHits->find(gpuId));
0550       if (cpuItr == cpuHits->end()) {
0551         edm::LogWarning("EcalDQM") << "GpuTask: Did not find GpuRecHit DetId " << gpuId.rawId()
0552                                    << " in CPU collection\n";
0553         continue;
0554       }
0555 
0556       float gpuEnergy(gpuHit.energy());
0557       float gpuTime(gpuHit.time());
0558       uint32_t gpuFlags(gpuHit.flagsBits());
0559 
0560       float cpuEnergy(cpuItr->energy());
0561       float cpuTime(cpuItr->time());
0562       uint32_t cpuFlags(cpuItr->flagsBits());
0563 
0564       meRecHitGpuCpuEnergy.fill(getEcalDQMSetupObjects(), iSubdet, gpuEnergy - cpuEnergy);
0565       meRecHitGpuCpuTime.fill(getEcalDQMSetupObjects(), iSubdet, gpuTime - cpuTime);
0566       meRecHitGpuCpuFlags.fill(getEcalDQMSetupObjects(), iSubdet, gpuFlags - cpuFlags);
0567 
0568       if (rechit1D_) {
0569         MESet& meRecHitGpuEnergy(MEs_.at("RecHitGpuEnergy"));
0570         MESet& meRecHitGpuTime(MEs_.at("RecHitGpuTime"));
0571         MESet& meRecHitGpuFlags(MEs_.at("RecHitGpuFlags"));
0572 
0573         meRecHitGpuEnergy.fill(getEcalDQMSetupObjects(), iSubdet, gpuEnergy);
0574         meRecHitGpuTime.fill(getEcalDQMSetupObjects(), iSubdet, gpuTime);
0575         meRecHitGpuFlags.fill(getEcalDQMSetupObjects(), iSubdet, gpuFlags);
0576       }
0577 
0578       if (rechit2D_) {
0579         MESet& meRecHit2DEnergy(MEs_.at("RecHit2DEnergy"));
0580         MESet& meRecHit2DTime(MEs_.at("RecHit2DTime"));
0581         MESet& meRecHit2DFlags(MEs_.at("RecHit2DFlags"));
0582 
0583         meRecHit2DEnergy.fill(getEcalDQMSetupObjects(), iSubdet, cpuEnergy, gpuEnergy);
0584         meRecHit2DTime.fill(getEcalDQMSetupObjects(), iSubdet, cpuTime, gpuTime);
0585         meRecHit2DFlags.fill(getEcalDQMSetupObjects(), iSubdet, cpuFlags, gpuFlags);
0586       }
0587     }
0588   }
0589 
0590   DEFINE_ECALDQM_WORKER(GpuTask);
0591 }  // namespace ecaldqm