Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:21

0001 #include "DQM/EcalMonitorTasks/interface/LedTask.h"
0002 
0003 #include "DQM/EcalCommon/interface/MESetMulti.h"
0004 
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 namespace ecaldqm {
0008 
0009   LedTask::LedTask() : DQWorkerTask(), wlToME_(), pnAmp_(), emptyLS_(0), emptyLSLimit_(0) {
0010     std::fill_n(enable_, nEEDCC, false);
0011     std::fill_n(wavelength_, nEEDCC, 0);
0012     std::fill_n(rtHalf_, nEEDCC, 0);
0013   }
0014 
0015   void LedTask::setParams(edm::ParameterSet const& _params) {
0016     emptyLSLimit_ = _params.getUntrackedParameter<int>("emptyLSLimit");
0017 
0018     std::vector<int> ledWavelengths(_params.getUntrackedParameter<std::vector<int> >("ledWavelengths"));
0019 
0020     MESet::PathReplacements repl;
0021 
0022     MESetMulti& amplitude(static_cast<MESetMulti&>(MEs_.at("Amplitude")));
0023     unsigned nWL(ledWavelengths.size());
0024     for (unsigned iWL(0); iWL != nWL; ++iWL) {
0025       int wl(ledWavelengths[iWL]);
0026       if (wl != 1 && wl != 2)
0027         throw cms::Exception("InvalidConfiguration") << "Led Wavelength";
0028       repl["wl"] = std::to_string(wl);
0029       wlToME_[wl] = amplitude.getIndex(repl);
0030     }
0031   }
0032 
0033   void LedTask::addDependencies(DependencySet& _dependencies) {
0034     _dependencies.push_back(Dependency(kEEDigi, kEcalRawData));
0035     _dependencies.push_back(Dependency(kPnDiodeDigi, kEEDigi, kEcalRawData));
0036     _dependencies.push_back(Dependency(kEELaserLedUncalibRecHit, kPnDiodeDigi, kEEDigi, kEcalRawData));
0037   }
0038 
0039   bool LedTask::filterRunType(short const* _runType) {
0040     bool enable(false);
0041 
0042     for (unsigned iDCC(0); iDCC != nDCC; iDCC++) {
0043       if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0044         continue;
0045       unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
0046       if (_runType[iDCC] == EcalDCCHeaderBlock::LED_STD || _runType[iDCC] == EcalDCCHeaderBlock::LED_GAP) {
0047         enable = true;
0048         enable_[index] = true;
0049       } else
0050         enable_[index] = false;
0051     }
0052 
0053     return enable;
0054   }
0055 
0056   void LedTask::beginRun(edm::Run const&, edm::EventSetup const&) { emptyLS_ = 0; }
0057 
0058   void LedTask::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0059     isemptyLS = 0;
0060     if (emptyLS_ + 1 > emptyLSLimit_)
0061       emptyLS_ = -1;
0062   }
0063 
0064   void LedTask::beginEvent(edm::Event const&, edm::EventSetup const&, bool const&, bool&) { pnAmp_.clear(); }
0065 
0066   void LedTask::runOnRawData(EcalRawDataCollection const& _rawData) {
0067     MESet& meCalibStatus(MEs_.at("CalibStatus"));
0068     for (EcalRawDataCollection::const_iterator rItr(_rawData.begin()); rItr != _rawData.end(); ++rItr) {
0069       unsigned iDCC(rItr->id() - 1);
0070       if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0071         continue;
0072       unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
0073 
0074       if (!enable_[index]) {
0075         wavelength_[index] = -1;
0076         rtHalf_[index] = -1;
0077         continue;
0078       }
0079       if (rItr->getEventSettings().wavelength == 0)
0080         wavelength_[index] = 1;
0081       else if (rItr->getEventSettings().wavelength == 2)
0082         wavelength_[index] = 2;
0083       else
0084         wavelength_[index] = -1;
0085 
0086       if (wlToME_.find(wavelength_[index]) == wlToME_.end())
0087         enable_[index] = false;
0088 
0089       rtHalf_[index] = rItr->getRtHalf();
0090     }
0091     bool LedStatus[2];
0092     for (unsigned iW(0); iW < 2; iW++) {
0093       LedStatus[iW] = false;
0094     }
0095     for (unsigned index(0); index < nEEDCC; ++index) {
0096       switch (wavelength_[index]) {
0097         case 1:
0098           LedStatus[0] = true;
0099           break;
0100         case 2:
0101           LedStatus[1] = true;
0102           break;
0103         default:
0104           break;
0105       }
0106     }
0107     for (unsigned iWL(0); iWL < 2; iWL++) {
0108       meCalibStatus.fill(getEcalDQMSetupObjects(), double(iWL + 3), LedStatus[iWL] ? 1 : 0);
0109     }
0110   }
0111 
0112   void LedTask::runOnDigis(EEDigiCollection const& _digis) {
0113     MESet& meOccupancy(MEs_.at("Occupancy"));
0114     MESet& meShape(MEs_.at("Shape"));
0115     MESet& meSignalRate(MEs_.at("SignalRate"));
0116 
0117     int nReadouts[nEEDCC];
0118     int maxpos[nEEDCC][10];
0119     for (unsigned index(0); index < nEEDCC; ++index) {
0120       nReadouts[index] = 0;
0121       for (int i(0); i < 10; i++)
0122         maxpos[index][i] = 0;
0123     }
0124 
0125     for (EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0126       const DetId& id(digiItr->id());
0127 
0128       unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
0129       if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0130         continue;
0131       unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
0132 
0133       if (!enable_[index])
0134         continue;
0135       if (rtHalf(id, GetElectronicsMap()) != rtHalf_[index])
0136         continue;
0137 
0138       meOccupancy.fill(getEcalDQMSetupObjects(), id);
0139 
0140       ++nReadouts[index];
0141 
0142       EcalDataFrame dataFrame(*digiItr);
0143 
0144       int iMax(-1);
0145       int max(0);
0146       int min(4096);
0147       for (int i(0); i < 10; i++) {
0148         int adc(dataFrame.sample(i).adc());
0149         if (adc > max) {
0150           max = adc;
0151           iMax = i;
0152         }
0153         if (adc < min)
0154           min = adc;
0155       }
0156       if (iMax >= 0 && max - min > 3)  // normal RMS of pedestal is ~2.5
0157         maxpos[index][iMax] += 1;
0158     }
0159 
0160     // signal existence check
0161     bool enable(false);
0162     bool ledOnExpected(emptyLS_ >= 0);
0163 
0164     unsigned iME(-1);
0165 
0166     for (int index(0); index < nEEDCC; ++index) {
0167       if (nReadouts[index] == 0) {
0168         enable_[index] = false;
0169         continue;
0170       }
0171 
0172       int threshold(nReadouts[index] / 3);
0173       if (ledOnExpected)
0174         enable_[index] = false;
0175 
0176       for (int i(0); i < 10; i++) {
0177         if (maxpos[index][i] > threshold) {
0178           enable = true;
0179           enable_[index] = true;
0180           break;
0181         }
0182       }
0183 
0184       if (iME != wlToME_[wavelength_[index]]) {
0185         iME = wlToME_[wavelength_[index]];
0186         static_cast<MESetMulti&>(meSignalRate).use(iME);
0187       }
0188 
0189       meSignalRate.fill(
0190           getEcalDQMSetupObjects(), (index <= kEEmHigh ? index : index + nEBDCC) + 1, enable_[index] ? 1 : 0);
0191     }
0192 
0193     if (!enable && isemptyLS >= 0)
0194       isemptyLS = 1;
0195     else if (enable)
0196       isemptyLS = -1;
0197 
0198     if (enable)
0199       emptyLS_ = 0;
0200     else if (ledOnExpected)
0201       return;
0202 
0203     iME = -1;
0204 
0205     for (EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0206       const DetId& id(digiItr->id());
0207 
0208       unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
0209       if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0210         continue;
0211       unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
0212 
0213       if (!enable_[index])
0214         continue;
0215       if (rtHalf(id, GetElectronicsMap()) != rtHalf_[index])
0216         continue;
0217 
0218       if (iME != wlToME_[wavelength_[index]]) {
0219         iME = wlToME_[wavelength_[index]];
0220         static_cast<MESetMulti&>(meShape).use(iME);
0221       }
0222 
0223       // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
0224       EcalDataFrame dataFrame(*digiItr);
0225 
0226       for (int iSample(0); iSample < 10; iSample++)
0227         meShape.fill(getEcalDQMSetupObjects(), id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
0228 
0229       EcalPnDiodeDetId pnidA(pnForCrystal(id, 'a', GetElectronicsMap()));
0230       EcalPnDiodeDetId pnidB(pnForCrystal(id, 'b', GetElectronicsMap()));
0231       if (pnidA.null() || pnidB.null())
0232         continue;
0233       pnAmp_.insert(std::make_pair(pnidA.rawId(), 0.));
0234       pnAmp_.insert(std::make_pair(pnidB.rawId(), 0.));
0235     }
0236   }
0237 
0238   void LedTask::runOnPnDigis(EcalPnDiodeDigiCollection const& _digis) {
0239     MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
0240 
0241     unsigned iME(-1);
0242 
0243     for (EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0244       if (digiItr->sample(0).gainId() != 0 && digiItr->sample(0).gainId() != 1)
0245         continue;
0246 
0247       const EcalPnDiodeDetId& id(digiItr->id());
0248 
0249       std::map<uint32_t, float>::iterator ampItr(pnAmp_.find(id.rawId()));
0250       if (ampItr == pnAmp_.end())
0251         continue;
0252 
0253       unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
0254       if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0255         continue;
0256       unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
0257 
0258       float pedestal(0.);
0259       for (int iSample(0); iSample < 4; iSample++)
0260         pedestal += digiItr->sample(iSample).adc();
0261       pedestal /= 4.;
0262 
0263       float max(0.);
0264       for (int iSample(0); iSample < 50; iSample++) {
0265         float amp(digiItr->sample(iSample).adc() - pedestal);
0266         if (amp > max)
0267           max = amp;
0268       }
0269 
0270       if (iME != wlToME_[wavelength_[index]]) {
0271         iME = wlToME_[wavelength_[index]];
0272         static_cast<MESetMulti&>(mePNAmplitude).use(iME);
0273       }
0274 
0275       mePNAmplitude.fill(getEcalDQMSetupObjects(), id, max);
0276 
0277       ampItr->second = max;
0278     }
0279   }
0280 
0281   void LedTask::runOnUncalibRecHits(EcalUncalibratedRecHitCollection const& _uhits) {
0282     using namespace std;
0283 
0284     MESet& meAmplitude(MEs_.at("Amplitude"));
0285     MESet& meAmplitudeSummary(MEs_.at("AmplitudeSummary"));
0286     MESet& meTiming(MEs_.at("Timing"));
0287     MESet& meAOverP(MEs_.at("AOverP"));
0288 
0289     unsigned iME(-1);
0290 
0291     for (EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr) {
0292       EEDetId id(uhitItr->id());
0293 
0294       unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
0295       if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0296         continue;
0297       unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
0298 
0299       if (!enable_[index])
0300         continue;
0301       if (rtHalf(id, GetElectronicsMap()) != rtHalf_[index])
0302         continue;
0303 
0304       if (iME != wlToME_[wavelength_[index]]) {
0305         iME = wlToME_[wavelength_[index]];
0306         static_cast<MESetMulti&>(meAmplitude).use(iME);
0307         static_cast<MESetMulti&>(meAmplitudeSummary).use(iME);
0308         static_cast<MESetMulti&>(meTiming).use(iME);
0309         static_cast<MESetMulti&>(meAOverP).use(iME);
0310       }
0311 
0312       float amp(max((double)uhitItr->amplitude(), 0.));
0313       float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
0314 
0315       meAmplitude.fill(getEcalDQMSetupObjects(), id, amp);
0316       meAmplitudeSummary.fill(getEcalDQMSetupObjects(), id, amp);
0317       meTiming.fill(getEcalDQMSetupObjects(), id, jitter);
0318 
0319       float aop(0.);
0320 
0321       map<uint32_t, float>::iterator ampItrA(pnAmp_.find(pnForCrystal(id, 'a', GetElectronicsMap())));
0322       map<uint32_t, float>::iterator ampItrB(pnAmp_.find(pnForCrystal(id, 'b', GetElectronicsMap())));
0323       if (ampItrA == pnAmp_.end() && ampItrB == pnAmp_.end())
0324         continue;
0325       else if (ampItrB == pnAmp_.end())
0326         aop = amp / ampItrA->second;
0327       else if (ampItrA == pnAmp_.end())
0328         aop = amp / ampItrB->second;
0329       else
0330         aop = amp / (ampItrA->second + ampItrB->second) * 2.;
0331 
0332       meAOverP.fill(getEcalDQMSetupObjects(), id, aop);
0333     }
0334   }
0335 
0336   void LedTask::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0337     if (isemptyLS == 1)
0338       emptyLS_ += 1;
0339   }
0340 
0341   DEFINE_ECALDQM_WORKER(LedTask);
0342 }  // namespace ecaldqm