Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:42:07

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