Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-30 04:13:36

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 
0005 #include "DQMServices/Core/interface/DQMStore.h"
0006 
0007 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0008 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0009 #include "DQM/SiStripMonitorClient/plugins/SiStripBadComponentInfo.h"
0010 
0011 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0012 
0013 #include <cmath>
0014 #include <cstdio>
0015 #include <iomanip>
0016 #include <iostream>
0017 #include <sstream>
0018 #include <string>
0019 
0020 //
0021 // -- Contructor
0022 //
0023 SiStripBadComponentInfo::SiStripBadComponentInfo(edm::ParameterSet const& pSet)
0024     : bookedStatus_(false),
0025       nSubSystem_(6),
0026       tTopoToken_(esConsumes<edm::Transition::EndRun>()),
0027       withFedErrHelper_{pSet, consumesCollector()} {
0028   // Create MessageSender
0029   LogDebug("SiStripBadComponentInfo") << "SiStripBadComponentInfo::Creating SiStripBadComponentInfo ";
0030 }
0031 
0032 SiStripBadComponentInfo::~SiStripBadComponentInfo() {
0033   LogDebug("SiStripBadComponentInfo") << "SiStripBadComponentInfo::Deleting SiStripBadComponentInfo ";
0034 }
0035 
0036 //
0037 // -- Read Condition
0038 //
0039 void SiStripBadComponentInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0040   LogDebug("SiStripBadComponentInfo") << "SiStripBadComponentInfo:: End of Run";
0041 
0042   // Retrieve tracker topology from geometry
0043   tTopo_ = std::make_unique<TrackerTopology>(eSetup.getData(tTopoToken_));
0044 
0045   if (withFedErrHelper_.endRun(eSetup) && !withFedErrHelper_.addBadCompFromFedErr()) {
0046     fillBadComponentMaps(&eSetup.getData(withFedErrHelper_.qualityToken()));
0047   }
0048 }
0049 
0050 void SiStripBadComponentInfo::fillBadComponentMaps(const SiStripQuality* siStripQuality) {
0051   auto const& BC = siStripQuality->getBadComponentList();
0052 
0053   for (size_t i = 0; i < BC.size(); ++i) {
0054     int subdet = -999;
0055     int component = -999;
0056 
0057     //&&&&&&&&&&&&&&&&&
0058     // Single SubSyste
0059     //&&&&&&&&&&&&&&&&&
0060     int subDet = DetId(BC[i].detid).subdetId();
0061     if (subDet == StripSubdetector::TIB) {
0062       //&&&&&&&&&&&&&&&&&
0063       // TIB
0064       //&&&&&&&&&&&&&&&&&
0065       subdet = 3;
0066       component = tTopo_->tibLayer(BC[i].detid);
0067     } else if (subDet == StripSubdetector::TID) {
0068       //&&&&&&&&&&&&&&&&&
0069       // TID
0070       //&&&&&&&&&&&&&&&&&
0071       if (tTopo_->tidSide(BC[i].detid) == 2)
0072         subdet = 4;
0073       else
0074         subdet = 5;
0075       component = tTopo_->tidWheel(BC[i].detid);
0076     } else if (subDet == StripSubdetector::TOB) {
0077       //&&&&&&&&&&&&&&&&&
0078       // TOB
0079       //&&&&&&&&&&&&&&&&&
0080       subdet = 6;
0081       component = tTopo_->tobLayer(BC[i].detid);
0082     } else if (subDet == StripSubdetector::TEC) {
0083       //&&&&&&&&&&&&&&&&&
0084       // TEC
0085       //&&&&&&&&&&&&&&&&&
0086       if (tTopo_->tecSide(BC[i].detid) == 2)
0087         subdet = 2;
0088       else
0089         subdet = 1;
0090       component = tTopo_->tecWheel(BC[i].detid);
0091     }
0092     fillBadComponentMaps(subdet, component, BC[i]);
0093   }
0094 
0095   //&&&&&&&&&&&&&&&&&&
0096   // Single Strip Info
0097   //&&&&&&&&&&&&&&&&&&
0098 
0099   SiStripQuality::RegistryIterator rbegin = siStripQuality->getRegistryVectorBegin();
0100   SiStripQuality::RegistryIterator rend = siStripQuality->getRegistryVectorEnd();
0101 
0102   for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
0103     uint32_t detid = rp->detid;
0104     int subdet = -999;
0105     int component = -999;
0106     DetId detectorId = DetId(detid);
0107     int subDet = detectorId.subdetId();
0108     if (subDet == StripSubdetector::TIB) {
0109       subdet = 3;
0110       component = tTopo_->tibLayer(detid);
0111     } else if (subDet == StripSubdetector::TID) {
0112       if (tTopo_->tidSide(detid) == 2)
0113         subdet = 5;
0114       else
0115         subdet = 4;
0116       component = tTopo_->tidWheel(detid);
0117     } else if (subDet == StripSubdetector::TOB) {
0118       subdet = 6;
0119       component = tTopo_->tobLayer(detid);
0120     } else if (subDet == StripSubdetector::TEC) {
0121       if (tTopo_->tecSide(detid) == 2)
0122         subdet = 2;
0123       else
0124         subdet = 1;
0125       component = tTopo_->tecWheel(detid);
0126     }
0127 
0128     SiStripQuality::Range sqrange = SiStripQuality::Range(siStripQuality->getDataVectorBegin() + rp->ibegin,
0129                                                           siStripQuality->getDataVectorBegin() + rp->iend);
0130 
0131     for (int it = 0; it < sqrange.second - sqrange.first; it++) {
0132       unsigned int range = siStripQuality->decode(*(sqrange.first + it)).range;
0133       float val = (mapBadStrip.find(std::make_pair(subdet, component)) != mapBadStrip.end())
0134                       ? mapBadStrip.at(std::make_pair(subdet, component))
0135                       : 0.;
0136       val += range;
0137       mapBadStrip[std::make_pair(subdet, component)] = val;
0138     }
0139   }
0140 }
0141 
0142 void SiStripBadComponentInfo::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0143   LogDebug("SiStripBadComponentInfo") << "SiStripBadComponentInfo::dqmEndRun";
0144   if (withFedErrHelper_.addBadCompFromFedErr()) {
0145     fillBadComponentMaps(&withFedErrHelper_.getMergedQuality(igetter));
0146   }
0147   bookBadComponentHistos(ibooker, igetter);
0148   createSummary(badAPVME_, mapBadAPV);
0149   createSummary(badFiberME_, mapBadFiber);
0150   createSummary(badStripME_, mapBadStrip);
0151 }
0152 //
0153 // -- Book MEs for SiStrip Dcs Fraction
0154 //
0155 void SiStripBadComponentInfo::bookBadComponentHistos(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0156   if (!bookedStatus_) {
0157     std::string strip_dir = "";
0158     ibooker.cd();
0159     //    SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
0160     if (igetter.dirExists("SiStrip")) {
0161       ibooker.cd("SiStrip");
0162       strip_dir = ibooker.pwd();
0163     }
0164     edm::LogInfo("SiStripBadComponentInfo")
0165         << "SiStripBadComponentInfo::bookBadComponentHistos ==> " << strip_dir << " " << ibooker.pwd() << std::endl;
0166     if (!strip_dir.empty())
0167       ibooker.setCurrentFolder(strip_dir + "/EventInfo");
0168     else
0169       ibooker.setCurrentFolder("SiStrip/EventInfo");
0170 
0171     ibooker.cd();
0172     if (!strip_dir.empty())
0173       ibooker.setCurrentFolder(strip_dir + "/EventInfo/BadComponentContents");
0174 
0175     std::string hname, htitle;
0176     hname = "BadAPVMap";
0177     htitle = "SiStrip Bad APVs";
0178     badAPVME_ = ibooker.book2D(hname, htitle, nSubSystem_, 0.5, nSubSystem_ + 0.5, 10, 0.5, 10.5);
0179     badAPVME_->setAxisTitle("Sub Detector Type", 1);
0180     badAPVME_->setAxisTitle("Layer/Disc Number", 2);
0181 
0182     hname = "BadFiberMap";
0183     htitle = "SiStrip Bad Fibers";
0184     badFiberME_ = ibooker.book2D(hname, htitle, nSubSystem_, 0.5, nSubSystem_ + 0.5, 10, 0.5, 10.5);
0185     badFiberME_->setAxisTitle("Sub Detector Type", 1);
0186     badFiberME_->setAxisTitle("Layer/Disc Number", 2);
0187 
0188     hname = "BadStripMap";
0189     htitle = "SiStrip Bad Strips";
0190     badStripME_ = ibooker.book2D(hname, htitle, nSubSystem_, 0.5, nSubSystem_ + 0.5, 10, 0.5, 10.5);
0191     badStripME_->setAxisTitle("Sub Detector Type", 1);
0192     badStripME_->setAxisTitle("Layer/Disc Number", 2);
0193 
0194     std::vector<std::string> names;
0195     names.push_back("TECB");
0196     names.push_back("TECF");
0197     names.push_back("TIB");
0198     names.push_back("TIDB");
0199     names.push_back("TIDF");
0200     names.push_back("TOB");
0201 
0202     for (unsigned int i = 0; i < names.size(); i++) {
0203       badAPVME_->setBinLabel(i + 1, names[i]);
0204       badFiberME_->setBinLabel(i + 1, names[i]);
0205       badStripME_->setBinLabel(i + 1, names[i]);
0206     }
0207 
0208     bookedStatus_ = true;
0209     ibooker.cd();
0210   }
0211 }
0212 
0213 void SiStripBadComponentInfo::fillBadComponentMaps(int xbin, int component, SiStripQuality::BadComponent const& BC) {
0214   auto index = std::make_pair(xbin, component);
0215 
0216   if (BC.BadApvs) {
0217     int ntot = std::bitset<16>(BC.BadApvs & 0x3f).count();
0218     float val = (mapBadAPV.find(index) != mapBadAPV.end()) ? mapBadAPV.at(index) : 0.;
0219     val += ntot;
0220     mapBadAPV[index] = val;
0221   }
0222   if (BC.BadFibers) {
0223     int ntot = std::bitset<16>(BC.BadFibers & 0x7).count();
0224     float val = (mapBadFiber.find(index) != mapBadFiber.end()) ? mapBadFiber.at(index) : 0.;
0225     val += ntot;
0226     mapBadFiber[index] = val;
0227   }
0228 }
0229 void SiStripBadComponentInfo::createSummary(MonitorElement* me, const std::map<std::pair<int, int>, float>& map) {
0230   for (int i = 1; i < nSubSystem_ + 1; i++) {
0231     float sum = 0.0;
0232     for (int k = 1; k < me->getNbinsY(); k++) {
0233       auto index = std::make_pair(i, k);
0234       if (map.find(index) != map.end()) {
0235         me->setBinContent(i, k, map.at(index));  // fill the layer/wheel bins
0236         sum += map.at(index);
0237       }
0238     }
0239     me->setBinContent(i, me->getNbinsY(), sum);  // fill the summary bin (last one)
0240   }
0241 }
0242 #include "FWCore/Framework/interface/MakerMacros.h"
0243 DEFINE_FWK_MODULE(SiStripBadComponentInfo);