Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:58:51

0001 #include "DQM/EcalMonitorTasks/interface/OccupancyTask.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 
0009 namespace ecaldqm {
0010   OccupancyTask::OccupancyTask() : DQWorkerTask(), recHitThreshold_(0.), tpThreshold_(0.), m_iTime(0.) {}
0011 
0012   void OccupancyTask::setParams(edm::ParameterSet const& _params) {
0013     recHitThreshold_ = _params.getUntrackedParameter<double>("recHitThreshold");
0014     tpThreshold_ = _params.getUntrackedParameter<double>("tpThreshold");
0015     metadataTag = _params.getParameter<edm::InputTag>("metadata");
0016     lumiCheck_ = _params.getUntrackedParameter<bool>("lumiCheck", false);
0017     if (!onlineMode_) {
0018       MEs_.erase(std::string("PU"));
0019       MEs_.erase(std::string("NEvents"));
0020       MEs_.erase(std::string("TrendEventsperLumi"));
0021       MEs_.erase(std::string("TrendPUperLumi"));
0022       MEs_.erase(std::string("AELoss"));
0023     }
0024   }
0025 
0026   void OccupancyTask::setTokens(edm::ConsumesCollector& _collector) {
0027     lasertoken_ = _collector.esConsumes();
0028     metaDataToken_ = _collector.consumes<OnlineLuminosityRecord>(metadataTag);
0029   }
0030 
0031   bool OccupancyTask::filterRunType(short const* _runType) {
0032     for (int iFED(0); iFED < 54; iFED++) {
0033       if (_runType[iFED] == EcalDCCHeaderBlock::COSMIC || _runType[iFED] == EcalDCCHeaderBlock::MTCC ||
0034           _runType[iFED] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
0035           _runType[iFED] == EcalDCCHeaderBlock::PHYSICS_GLOBAL || _runType[iFED] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
0036           _runType[iFED] == EcalDCCHeaderBlock::PHYSICS_LOCAL)
0037         return true;
0038     }
0039 
0040     return false;
0041   }
0042 
0043   void OccupancyTask::beginRun(edm::Run const&, edm::EventSetup const& _es) { FillLaser = true; }
0044   void OccupancyTask::beginEvent(edm::Event const& _evt,
0045                                  edm::EventSetup const& _es,
0046                                  bool const& ByLumiResetSwitch,
0047                                  bool&) {
0048     if (ByLumiResetSwitch) {
0049       MEs_.at("DigiAllByLumi").reset(GetElectronicsMap());
0050       MEs_.at("TPDigiThrAllByLumi").reset(GetElectronicsMap());
0051       MEs_.at("RecHitThrAllByLumi").reset(GetElectronicsMap());
0052       nEv = 0;
0053       if (onlineMode_) {
0054         MEs_.at("PU").reset(GetElectronicsMap(), -1);
0055         MEs_.at("NEvents").reset(GetElectronicsMap(), -1);
0056         FindPUinLS = true;
0057       }
0058     }
0059     nEv++;
0060     MESet& meLaserCorrProjEta(MEs_.at("LaserCorrProjEta"));
0061     m_iTime = _evt.time().value();
0062     if (FillLaser) {
0063       float lasercalib = 1.;
0064       auto const& laser = &_es.getData(lasertoken_);
0065       const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
0066 
0067       for (int i = 0; i < EBDetId::kSizeForDenseIndexing; i++) {
0068         if (!EBDetId::validDenseIndex(i))
0069           continue;
0070         EBDetId ebid(EBDetId::unhashIndex(i));
0071         lasercalib = laser->getLaserCorrection(ebid, evtTimeStamp);
0072         meLaserCorrProjEta.fill(getEcalDQMSetupObjects(), ebid, lasercalib);
0073       }
0074 
0075       for (int i = 0; i < EEDetId::kSizeForDenseIndexing; i++) {
0076         if (!EEDetId::validDenseIndex(i))
0077           continue;
0078         EEDetId eeid(EEDetId::unhashIndex(i));
0079         lasercalib = laser->getLaserCorrection(eeid, evtTimeStamp);
0080         meLaserCorrProjEta.fill(getEcalDQMSetupObjects(), eeid, lasercalib);
0081       }
0082       FillLaser = false;
0083     }
0084     if (lumiCheck_ && FindPUinLS) {
0085       scal_pu = -1.;
0086       MESet& mePU(static_cast<MESet&>(MEs_.at("PU")));
0087       edm::Handle<OnlineLuminosityRecord> metaData;
0088       _evt.getByToken(metaDataToken_, metaData);
0089 
0090       if (metaData.isValid())
0091         scal_pu = metaData->avgPileUp();
0092       mePU.fill(getEcalDQMSetupObjects(), double(scal_pu));
0093       FindPUinLS = false;
0094     }
0095   }
0096 
0097   void OccupancyTask::runOnRawData(EcalRawDataCollection const& _dcchs) {
0098     MESet& meDCC(MEs_.at("DCC"));
0099 
0100     for (EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr)
0101       meDCC.fill(getEcalDQMSetupObjects(), dcchItr->id());
0102   }
0103 
0104   void OccupancyTask::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0105     if (onlineMode_) {
0106       MESet& meNEvents(static_cast<MESet&>(MEs_.at("NEvents")));
0107       MESet& meTrendEventsperLumi(MEs_.at("TrendEventsperLumi"));
0108       MESet& meTrendPUperLumi(MEs_.at("TrendPUperLumi"));
0109 
0110       meNEvents.fill(getEcalDQMSetupObjects(), double(nEv));
0111       meTrendEventsperLumi.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), double(nEv));
0112       meTrendPUperLumi.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), double(scal_pu));
0113     }
0114   }
0115 
0116   template <typename DigiCollection>
0117   void OccupancyTask::runOnDigis(DigiCollection const& _digis, Collections _collection) {
0118     MESet& meDigi(MEs_.at("Digi"));
0119     MESet& meDigiProjEta(MEs_.at("DigiProjEta"));
0120     MESet& meDigiProjPhi(MEs_.at("DigiProjPhi"));
0121     MESet& meDigiAll(MEs_.at("DigiAll"));
0122     MESet& meDigiAllByLumi(MEs_.at("DigiAllByLumi"));
0123     MESet& meDigiDCC(MEs_.at("DigiDCC"));
0124     MESet& meDigi1D(MEs_.at("Digi1D"));
0125     MESet& meTrendNDigi(MEs_.at("TrendNDigi"));
0126     MESet* meAELoss = nullptr;
0127     if (onlineMode_)
0128       meAELoss = &MEs_.at("AELoss");
0129 
0130     std::for_each(_digis.begin(), _digis.end(), [&](typename DigiCollection::Digi const& digi) {
0131       DetId id(digi.id());
0132       meDigi.fill(getEcalDQMSetupObjects(), id);
0133       meDigiProjEta.fill(getEcalDQMSetupObjects(), id);
0134       meDigiProjPhi.fill(getEcalDQMSetupObjects(), id);
0135       meDigiAll.fill(getEcalDQMSetupObjects(), id);
0136       meDigiAllByLumi.fill(getEcalDQMSetupObjects(), id);
0137       meDigiDCC.fill(getEcalDQMSetupObjects(), id);
0138       if (onlineMode_)
0139         meAELoss->fill(getEcalDQMSetupObjects(), id);
0140     });
0141 
0142     int iSubdet(_collection == kEBDigi ? EcalBarrel : EcalEndcap);
0143     meDigi1D.fill(getEcalDQMSetupObjects(), iSubdet, double(_digis.size()));
0144     meTrendNDigi.fill(getEcalDQMSetupObjects(), iSubdet, double(timestamp_.iLumi), double(_digis.size()));
0145   }
0146 
0147   void OccupancyTask::runOnTPDigis(EcalTrigPrimDigiCollection const& _digis) {
0148     //    MESet& meTPDigiAll(MEs_.at("TPDigiAll"));
0149     //    MESet& meTPDigiProjEta(MEs_.at("TPDigiProjEta"));
0150     //    MESet& meTPDigiProjPhi(MEs_.at("TPDigiProjPhi"));
0151     MESet& meTPDigiRCT(MEs_.at("TPDigiRCT"));
0152     MESet& meTPDigiThrAll(MEs_.at("TPDigiThrAll"));
0153     MESet& meTPDigiThrAllByLumi(MEs_.at("TPDigiThrAllByLumi"));
0154     MESet& meTPDigiThrProjEta(MEs_.at("TPDigiThrProjEta"));
0155     MESet& meTPDigiThrProjPhi(MEs_.at("TPDigiThrProjPhi"));
0156     MESet& meTrendNTPDigi(MEs_.at("TrendNTPDigi"));
0157 
0158     double nFilteredEB(0.);
0159     double nFilteredEE(0.);
0160 
0161     std::for_each(_digis.begin(), _digis.end(), [&](EcalTrigPrimDigiCollection::value_type const& digi) {
0162       EcalTrigTowerDetId const& id(digi.id());
0163       //       meTPDigiProjEta.fill(id);
0164       //       meTPDigiProjPhi.fill(id);
0165       //       meTPDigiAll.fill(id);
0166       if (digi.compressedEt() > tpThreshold_) {
0167         meTPDigiThrProjEta.fill(getEcalDQMSetupObjects(), id);
0168         meTPDigiThrProjPhi.fill(getEcalDQMSetupObjects(), id);
0169         meTPDigiThrAll.fill(getEcalDQMSetupObjects(), id);
0170         meTPDigiThrAllByLumi.fill(getEcalDQMSetupObjects(), id);
0171         meTPDigiRCT.fill(getEcalDQMSetupObjects(), id);
0172         if (id.subDet() == EcalBarrel)
0173           nFilteredEB += 1.;
0174         else
0175           nFilteredEE += 1.;
0176       }
0177     });
0178 
0179     meTrendNTPDigi.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), nFilteredEB);
0180     meTrendNTPDigi.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), nFilteredEE);
0181   }
0182 
0183   void OccupancyTask::runOnRecHits(EcalRecHitCollection const& _hits, Collections _collection) {
0184     MESet& meRecHitAll(MEs_.at("RecHitAll"));
0185     MESet& meRecHitProjEta(MEs_.at("RecHitProjEta"));
0186     MESet& meRecHitProjPhi(MEs_.at("RecHitProjPhi"));
0187     MESet& meRecHitThrAll(MEs_.at("RecHitThrAll"));
0188     MESet& meRecHitThrAllByLumi(MEs_.at("RecHitThrAllByLumi"));
0189     MESet& meRecHitThrmvp(MEs_.at("RecHitThrmvp"));
0190     MESet& meRecHitThrpm(MEs_.at("RecHitThrpm"));
0191     MESet& meRecHitThrProjEta(MEs_.at("RecHitThrProjEta"));
0192     MESet& meRecHitThrProjPhi(MEs_.at("RecHitThrProjPhi"));
0193     MESet& meRecHitThr1D(MEs_.at("RecHitThr1D"));
0194     MESet& meTrendNRecHitThr(MEs_.at("TrendNRecHitThr"));
0195 
0196     uint32_t mask(~(0x1 << EcalRecHit::kGood));
0197     double nFiltered(0.);
0198 
0199     float nRHThrp(0), nRHThrm(0);
0200     int iSubdet(_collection == kEBRecHit ? EcalBarrel : EcalEndcap);
0201     std::for_each(_hits.begin(), _hits.end(), [&](EcalRecHitCollection::value_type const& hit) {
0202       DetId id(hit.id());
0203 
0204       meRecHitAll.fill(getEcalDQMSetupObjects(), id);
0205       meRecHitProjEta.fill(getEcalDQMSetupObjects(), id);
0206       meRecHitProjPhi.fill(getEcalDQMSetupObjects(), id);
0207 
0208       if (!hit.checkFlagMask(mask) && hit.energy() > recHitThreshold_) {
0209         meRecHitThrProjEta.fill(getEcalDQMSetupObjects(), id);
0210         meRecHitThrProjPhi.fill(getEcalDQMSetupObjects(), id);
0211         meRecHitThrAll.fill(getEcalDQMSetupObjects(), id);
0212         meRecHitThrAllByLumi.fill(getEcalDQMSetupObjects(), id);
0213         nFiltered += 1.;
0214         bool isPlusFar(iSubdet == EcalBarrel ? (EBDetId(id).iphi() > 100 && EBDetId(id).iphi() < 280) : zside(id) > 0);
0215         if (isPlusFar)
0216           nRHThrp++;
0217         else
0218           nRHThrm++;
0219       }
0220     });
0221 
0222     meRecHitThr1D.fill(getEcalDQMSetupObjects(), iSubdet, nFiltered);
0223     meTrendNRecHitThr.fill(getEcalDQMSetupObjects(), iSubdet, double(timestamp_.iLumi), nFiltered);
0224     meRecHitThrmvp.fill(getEcalDQMSetupObjects(), iSubdet, nRHThrp, nRHThrm);
0225     meRecHitThrpm.fill(getEcalDQMSetupObjects(), iSubdet, nRHThrp - nRHThrm);
0226   }
0227 
0228   DEFINE_ECALDQM_WORKER(OccupancyTask);
0229 }  // namespace ecaldqm