Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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