Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-25 23:40:02

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripMonitorQuality
0004 // Class:      SiStripMonitorQuality
0005 //
0006 /**\class SiStripMonitorDigi SiStripMonitorDigi.cc
0007  DQM/SiStripMonitorDigi/src/SiStripMonitorDigi.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Suchandra Dutta
0016 //         Created:  Fri Dec  7 20:50 CET 2007
0017 //
0018 //
0019 
0020 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0021 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0022 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0023 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
0024 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0025 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
0026 #include "DQM/SiStripMonitorPedestals/interface/SiStripMonitorQuality.h"
0027 #include "DQMServices/Core/interface/DQMStore.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0030 #include "FWCore/ServiceRegistry/interface/Service.h"
0031 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0032 
0033 // std
0034 #include <algorithm>
0035 #include <cmath>
0036 #include <cstdlib>
0037 #include <numeric>
0038 
0039 SiStripMonitorQuality::SiStripMonitorQuality(edm::ParameterSet const &iConfig)
0040     : dqmStore_(edm::Service<DQMStore>().operator->()),
0041       conf_(iConfig),
0042       tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
0043       detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0044       qualityToken_(esConsumes<edm::Transition::BeginRun>(
0045           edm::ESInputTag{"", iConfig.getParameter<std::string>("StripQualityLabel")})) {
0046   edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality  "
0047                                         << " Constructing....... ";
0048 }
0049 
0050 SiStripMonitorQuality::~SiStripMonitorQuality() {
0051   edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality  "
0052                                         << " Destructing....... ";
0053 }
0054 //
0055 void SiStripMonitorQuality::bookHistograms(DQMStore::IBooker &ibooker,
0056                                            const edm::Run &run,
0057                                            const edm::EventSetup &eSetup) {
0058   if (!qualityWatcher_.check(eSetup))
0059     return;
0060 
0061   const auto tTopo = &eSetup.getData(tTopoToken_);
0062 
0063   stripQuality_ = &eSetup.getData(qualityToken_);
0064   detCabling_ = &eSetup.getData(detCablingToken_);
0065 
0066   edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze: "
0067                                         << " Reading SiStripQuality " << std::endl;
0068 
0069   SiStripBadStrip::RegistryIterator rbegin = stripQuality_->getRegistryVectorBegin();
0070   SiStripBadStrip::RegistryIterator rend = stripQuality_->getRegistryVectorEnd();
0071   uint32_t detid;
0072 
0073   if (rbegin == rend)
0074     return;
0075 
0076   for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
0077     detid = rp->detid;
0078     // Check consistency in DetId
0079     if (detid == 0 || detid == 0xFFFFFFFF) {
0080       edm::LogError("SiStripMonitorQuality") << "SiStripMonitorQuality::bookHistograms : "
0081                                              << "Wrong DetId !!!!!! " << detid << " Neglecting !!!!!! ";
0082       continue;
0083     }
0084     // check if the detid is connected in cabling
0085     if (!detCabling_->IsConnected(detid)) {
0086       edm::LogError("SiStripMonitorQuality") << "SiStripMonitorQuality::bookHistograms : "
0087                                              << " DetId " << detid << " not connected,  Neglecting !!!!!! ";
0088       continue;
0089     }
0090 
0091     MonitorElement *det_me;
0092 
0093     int nStrip = detCabling_->nApvPairs(detid) * 256;
0094 
0095     // use SistripHistoId for producing histogram id (and title)
0096     SiStripHistoId hidmanager;
0097     // create SiStripFolderOrganizer
0098     SiStripFolderOrganizer folder_organizer;
0099     // set appropriate folder using SiStripFolderOrganizer
0100     folder_organizer.setDetectorFolder(detid,
0101                                        tTopo);  // pass the detid to this method
0102 
0103     std::string hid;
0104     hid = hidmanager.createHistoId("StripQualityFromCondDB", "det", detid);
0105 
0106     det_me = ibooker.book1D(hid, hid, nStrip, 0.5, nStrip + 0.5);
0107     det_me->setAxisTitle("Strip Number", 1);
0108     det_me->setAxisTitle("Quality Flag from CondDB ", 2);
0109     QualityMEs.insert(std::make_pair(detid, det_me));
0110   }
0111 }
0112 
0113 // ------------ method called to produce the data  ------------
0114 void SiStripMonitorQuality::analyze(edm::Event const &iEvent, edm::EventSetup const &eSetup) {
0115   if (!qualityWatcher_.check(eSetup))
0116     return;
0117 
0118   const auto tTopo = &eSetup.getData(tTopoToken_);
0119   stripQuality_ = &eSetup.getData(qualityToken_);
0120   detCabling_ = &eSetup.getData(detCablingToken_);
0121 
0122   edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze: "
0123                                         << " Reading SiStripQuality " << std::endl;
0124 
0125   SiStripBadStrip::RegistryIterator rbegin = stripQuality_->getRegistryVectorBegin();
0126   SiStripBadStrip::RegistryIterator rend = stripQuality_->getRegistryVectorEnd();
0127   uint32_t detid;
0128 
0129   if (rbegin == rend)
0130     return;
0131 
0132   for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
0133     detid = rp->detid;
0134     // Check consistency in DetId
0135     if (detid == 0 || detid == 0xFFFFFFFF) {
0136       edm::LogError("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze : "
0137                                              << "Wrong DetId !!!!!! " << detid << " Neglecting !!!!!! ";
0138       continue;
0139     }
0140     // check if the detid is connected in cabling
0141     if (!detCabling_->IsConnected(detid)) {
0142       edm::LogError("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze : "
0143                                              << " DetId " << detid << " not connected,  Neglecting !!!!!! ";
0144       continue;
0145     }
0146     MonitorElement *me = getQualityME(detid, tTopo);
0147     SiStripBadStrip::Range range = SiStripBadStrip::Range(stripQuality_->getDataVectorBegin() + rp->ibegin,
0148                                                           stripQuality_->getDataVectorBegin() + rp->iend);
0149     SiStripBadStrip::ContainerIterator it = range.first;
0150     for (; it != range.second; ++it) {
0151       unsigned int value = (*it);
0152       short str_start = stripQuality_->decode(value).firstStrip;
0153       short str_end = str_start + stripQuality_->decode(value).range;
0154       for (short isr = str_start; isr < str_end + 1; isr++) {
0155         if (isr <= (me->getNbinsX() - 1))
0156           me->Fill(isr + 1, 1.0);
0157       }
0158     }
0159   }
0160 }
0161 //
0162 // -- End Run
0163 //
0164 void SiStripMonitorQuality::dqmEndRun(edm::Run const &run, edm::EventSetup const &eSetup) {
0165   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
0166   std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
0167   if (outputMEsInRootFile) {
0168     dqmStore_->save(outputFileName);
0169   }
0170 }
0171 //
0172 // -- End Job
0173 //
0174 void SiStripMonitorQuality::endJob(void) {
0175   edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality::EndJob: "
0176                                         << " Finishing!! ";
0177 }
0178 //
0179 // -- End Job
0180 //
0181 SiStripMonitorQuality::MonitorElement *SiStripMonitorQuality::getQualityME(uint32_t idet,
0182                                                                            const TrackerTopology *tTopo) {
0183   std::map<uint32_t, MonitorElement *>::iterator pos = QualityMEs.find(idet);
0184   MonitorElement *det_me = nullptr;
0185   if (pos != QualityMEs.end()) {
0186     det_me = pos->second;
0187     det_me->Reset();
0188   } else {
0189     // this should never happen because of bookHistograms()
0190     edm::LogError("SiStripMonitorQuality") << "SiStripMonitorQuality::getQualityME : "
0191                                            << "Wrong DetId !!!!!! " << idet << " No ME found!";
0192   }
0193   return det_me;
0194 }
0195 DEFINE_FWK_MODULE(SiStripMonitorQuality);