Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-05 02:38:51

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripQualityStatistics
0004 // Class:      SiStripQualityStatistics
0005 //
0006 /**\class SiStripQualityStatistics SiStripQualityStatistics.h CalibTracker/SiStripQuality/plugins/SiStripQualityStatistics.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Domenico GIORDANO
0015 //         Created:  Wed Oct  3 12:11:10 CEST 2007
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0024 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0025 #include "CalibTracker/SiStripQuality/interface/SiStripQualityWithFromFedErrorsHelper.h"
0026 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0027 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
0028 #include "DQMServices/Core/interface/DQMEDHarvester.h"
0029 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0030 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0031 #include "FWCore/Framework/interface/Frameworkfwd.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0034 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0035 
0036 class SiStripFedCabling;
0037 
0038 class SiStripQualityStatistics : public DQMEDHarvester {
0039 public:
0040   explicit SiStripQualityStatistics(const edm::ParameterSet&);
0041   ~SiStripQualityStatistics() override = default;
0042 
0043   void endRun(edm::Run const&, edm::EventSetup const&) override;
0044   void dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter&) override;
0045 
0046   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0047 
0048 private:
0049   void updateAndSave(const SiStripQuality* siStripQuality);
0050   void SetBadComponents(int, int, SiStripQuality::BadComponent&);
0051 
0052   edm::RunID run_;
0053   std::string dataLabel_;
0054   const std::string TkMapFileName_;
0055   const bool saveTkHistoMap_;
0056   //Global Info
0057   int NTkBadComponent[4];  //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
0058   int NBadComponent[4][19][4];
0059   //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
0060   //     i: 0=TIB, 1=TID, 2=TOB, 3=TEC
0061   //     k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
0062   std::stringstream ssV[4][19];
0063 
0064   TrackerMap *tkMap, *tkMapFullIOVs;
0065   SiStripDetInfo detInfo_;
0066   std::unique_ptr<TkHistoMap> tkhisto;
0067   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0068   const edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
0069   std::unique_ptr<TrackerTopology> tTopo_;
0070   SiStripQualityWithFromFedErrorsHelper withFedErrHelper_;
0071 };
0072 
0073 SiStripQualityStatistics::SiStripQualityStatistics(const edm::ParameterSet& iConfig)
0074     : TkMapFileName_(iConfig.getUntrackedParameter<std::string>("TkMapFileName", "")),
0075       saveTkHistoMap_(iConfig.getUntrackedParameter<bool>("SaveTkHistoMap", true)),
0076       tkMap(nullptr),
0077       tkMapFullIOVs(nullptr),
0078       tTopoToken_(esConsumes<edm::Transition::EndRun>()),
0079       tkDetMapToken_(esConsumes<edm::Transition::EndRun>()),
0080       withFedErrHelper_{iConfig, consumesCollector(), true} {
0081   detInfo_ = SiStripDetInfoFileReader::read(
0082       iConfig.getUntrackedParameter<edm::FileInPath>("file", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))
0083           .fullPath());
0084 
0085   tkMapFullIOVs = new TrackerMap("BadComponents");
0086   tkhisto = nullptr;
0087 }
0088 
0089 void SiStripQualityStatistics::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0090   edm::ParameterSetDescription desc;
0091   desc.addUntracked<std::string>("TkMapFileName", "");
0092   desc.addUntracked<bool>("SaveTkHistoMap", true);
0093   desc.addUntracked<edm::FileInPath>("file", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile));
0094   SiStripQualityWithFromFedErrorsHelper::fillDescription(desc);
0095   descriptions.add("siStripQualityStatistics", desc);
0096 }
0097 
0098 void SiStripQualityStatistics::dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter& getter) {
0099   if (withFedErrHelper_.addBadCompFromFedErr()) {
0100     updateAndSave(&withFedErrHelper_.getMergedQuality(getter));
0101   }
0102   std::string filename = TkMapFileName_;
0103   if (!filename.empty()) {
0104     tkMapFullIOVs->save(false, 0, 0, filename);
0105     filename.erase(filename.begin() + filename.find('.'), filename.end());
0106     tkMapFullIOVs->print(false, 0, 0, filename);
0107 
0108     if (saveTkHistoMap_) {
0109       tkhisto->save(filename + ".root");
0110       tkhisto->saveAsCanvas(filename + "_Canvas.root", "E");
0111     }
0112   }
0113 }
0114 
0115 void SiStripQualityStatistics::endRun(edm::Run const& run, edm::EventSetup const& iSetup) {
0116   tTopo_ = std::make_unique<TrackerTopology>(iSetup.getData(tTopoToken_));
0117   if ((!tkhisto) && (!TkMapFileName_.empty())) {
0118     //here the baseline (the value of the empty,not assigned bins) is put to -1 (default is zero)
0119     tkhisto = std::make_unique<TkHistoMap>(&iSetup.getData(tkDetMapToken_), "BadComp", "BadComp", -1.);
0120   }
0121 
0122   if (withFedErrHelper_.endRun(iSetup) && !withFedErrHelper_.addBadCompFromFedErr()) {
0123     run_ = run.id();
0124     updateAndSave(&iSetup.getData(withFedErrHelper_.qualityToken()));
0125   }
0126 }
0127 
0128 void SiStripQualityStatistics::updateAndSave(const SiStripQuality* siStripQuality) {
0129   for (int i = 0; i < 4; ++i) {
0130     NTkBadComponent[i] = 0;
0131     for (int j = 0; j < 19; ++j) {
0132       ssV[i][j].str("");
0133       for (int k = 0; k < 4; ++k)
0134         NBadComponent[i][j][k] = 0;
0135     }
0136   }
0137 
0138   if (tkMap)
0139     delete tkMap;
0140   tkMap = new TrackerMap("BadComponents");
0141 
0142   std::stringstream ss;
0143   std::vector<uint32_t> detids = detInfo_.getAllDetIds();
0144   std::vector<uint32_t>::const_iterator idet = detids.begin();
0145   for (; idet != detids.end(); ++idet) {
0146     ss << "detid " << (*idet) << " IsModuleUsable " << siStripQuality->IsModuleUsable((*idet)) << "\n";
0147     if (siStripQuality->IsModuleUsable((*idet)))
0148       tkMap->fillc(*idet, 0x00ff00);
0149   }
0150   LogDebug("SiStripQualityStatistics") << ss.str() << std::endl;
0151 
0152   std::vector<SiStripQuality::BadComponent> BC = siStripQuality->getBadComponentList();
0153 
0154   for (size_t i = 0; i < BC.size(); ++i) {
0155     //&&&&&&&&&&&&&
0156     //Full Tk
0157     //&&&&&&&&&&&&&
0158 
0159     if (BC[i].BadModule)
0160       NTkBadComponent[0]++;
0161     if (BC[i].BadFibers)
0162       NTkBadComponent[1] += ((BC[i].BadFibers >> 2) & 0x1) + ((BC[i].BadFibers >> 1) & 0x1) + ((BC[i].BadFibers) & 0x1);
0163     if (BC[i].BadApvs)
0164       NTkBadComponent[2] += ((BC[i].BadApvs >> 5) & 0x1) + ((BC[i].BadApvs >> 4) & 0x1) + ((BC[i].BadApvs >> 3) & 0x1) +
0165                             ((BC[i].BadApvs >> 2) & 0x1) + ((BC[i].BadApvs >> 1) & 0x1) + ((BC[i].BadApvs) & 0x1);
0166 
0167     //&&&&&&&&&&&&&&&&&
0168     //Single SubSystem
0169     //&&&&&&&&&&&&&&&&&
0170     int component;
0171     DetId detectorId = DetId(BC[i].detid);
0172     int subDet = detectorId.subdetId();
0173     if (subDet == StripSubdetector::TIB) {
0174       //&&&&&&&&&&&&&&&&&
0175       //TIB
0176       //&&&&&&&&&&&&&&&&&
0177 
0178       component = tTopo_->tibLayer(BC[i].detid);
0179       SetBadComponents(0, component, BC[i]);
0180 
0181     } else if (subDet == StripSubdetector::TID) {
0182       //&&&&&&&&&&&&&&&&&
0183       //TID
0184       //&&&&&&&&&&&&&&&&&
0185 
0186       component = tTopo_->tidSide(BC[i].detid) == 2 ? tTopo_->tidWheel(BC[i].detid) : tTopo_->tidWheel(BC[i].detid) + 3;
0187       SetBadComponents(1, component, BC[i]);
0188 
0189     } else if (subDet == StripSubdetector::TOB) {
0190       //&&&&&&&&&&&&&&&&&
0191       //TOB
0192       //&&&&&&&&&&&&&&&&&
0193 
0194       component = tTopo_->tobLayer(BC[i].detid);
0195       SetBadComponents(2, component, BC[i]);
0196 
0197     } else if (subDet == StripSubdetector::TEC) {
0198       //&&&&&&&&&&&&&&&&&
0199       //TEC
0200       //&&&&&&&&&&&&&&&&&
0201 
0202       component = tTopo_->tecSide(BC[i].detid) == 2 ? tTopo_->tecWheel(BC[i].detid) : tTopo_->tecWheel(BC[i].detid) + 9;
0203       SetBadComponents(3, component, BC[i]);
0204     }
0205   }
0206 
0207   //&&&&&&&&&&&&&&&&&&
0208   // Single Strip Info
0209   //&&&&&&&&&&&&&&&&&&
0210   float percentage = 0;
0211 
0212   SiStripQuality::RegistryIterator rbegin = siStripQuality->getRegistryVectorBegin();
0213   SiStripQuality::RegistryIterator rend = siStripQuality->getRegistryVectorEnd();
0214 
0215   for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
0216     uint32_t detid = rp->detid;
0217 
0218     int subdet = -999;
0219     int component = -999;
0220     DetId detectorId = DetId(detid);
0221     int subDet = detectorId.subdetId();
0222     if (subDet == StripSubdetector::TIB) {
0223       subdet = 0;
0224       component = tTopo_->tibLayer(detid);
0225     } else if (subDet == StripSubdetector::TID) {
0226       subdet = 1;
0227       component = tTopo_->tidSide(detid) == 2 ? tTopo_->tidWheel(detid) : tTopo_->tidWheel(detid) + 3;
0228     } else if (subDet == StripSubdetector::TOB) {
0229       subdet = 2;
0230       component = tTopo_->tobLayer(detid);
0231     } else if (subDet == StripSubdetector::TEC) {
0232       subdet = 3;
0233       component = tTopo_->tecSide(detid) == 2 ? tTopo_->tecWheel(detid) : tTopo_->tecWheel(detid) + 9;
0234     }
0235 
0236     SiStripQuality::Range sqrange = SiStripQuality::Range(siStripQuality->getDataVectorBegin() + rp->ibegin,
0237                                                           siStripQuality->getDataVectorBegin() + rp->iend);
0238 
0239     percentage = 0;
0240     for (int it = 0; it < sqrange.second - sqrange.first; it++) {
0241       unsigned int range = siStripQuality->decode(*(sqrange.first + it)).range;
0242       NTkBadComponent[3] += range;
0243       NBadComponent[subdet][0][3] += range;
0244       NBadComponent[subdet][component][3] += range;
0245       percentage += range;
0246     }
0247     if (percentage != 0)
0248       percentage /= 128. * detInfo_.getNumberOfApvsAndStripLength(detid).first;
0249     if (percentage > 1)
0250       edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage << std::endl;
0251 
0252     //------- Global Statistics on percentage of bad components along the IOVs ------//
0253     tkMapFullIOVs->fill(detid, percentage);
0254     if (tkhisto != nullptr)
0255       tkhisto->fill(detid, percentage);
0256   }
0257 
0258   //&&&&&&&&&&&&&&&&&&
0259   // printout
0260   //&&&&&&&&&&&&&&&&&&
0261 
0262   ss.str("");
0263   ss << "\n-----------------\nNew IOV starting from run " << run_.run() << "\n-----------------\n";
0264   ss << "\n-----------------\nGlobal Info\n-----------------";
0265   ss << "\nBadComponent \t   Modules \tFibers "
0266         "\tApvs\tStrips\n----------------------------------------------------------------";
0267   ss << "\nTracker:\t\t" << NTkBadComponent[0] << "\t" << NTkBadComponent[1] << "\t" << NTkBadComponent[2] << "\t"
0268      << NTkBadComponent[3];
0269   ss << "\n";
0270   ss << "\nTIB:\t\t\t" << NBadComponent[0][0][0] << "\t" << NBadComponent[0][0][1] << "\t" << NBadComponent[0][0][2]
0271      << "\t" << NBadComponent[0][0][3];
0272   ss << "\nTID:\t\t\t" << NBadComponent[1][0][0] << "\t" << NBadComponent[1][0][1] << "\t" << NBadComponent[1][0][2]
0273      << "\t" << NBadComponent[1][0][3];
0274   ss << "\nTOB:\t\t\t" << NBadComponent[2][0][0] << "\t" << NBadComponent[2][0][1] << "\t" << NBadComponent[2][0][2]
0275      << "\t" << NBadComponent[2][0][3];
0276   ss << "\nTEC:\t\t\t" << NBadComponent[3][0][0] << "\t" << NBadComponent[3][0][1] << "\t" << NBadComponent[3][0][2]
0277      << "\t" << NBadComponent[3][0][3];
0278   ss << "\n";
0279 
0280   for (int i = 1; i < 5; ++i)
0281     ss << "\nTIB Layer " << i << " :\t\t" << NBadComponent[0][i][0] << "\t" << NBadComponent[0][i][1] << "\t"
0282        << NBadComponent[0][i][2] << "\t" << NBadComponent[0][i][3];
0283   ss << "\n";
0284   for (int i = 1; i < 4; ++i)
0285     ss << "\nTID+ Disk " << i << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
0286        << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
0287   for (int i = 4; i < 7; ++i)
0288     ss << "\nTID- Disk " << i - 3 << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
0289        << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
0290   ss << "\n";
0291   for (int i = 1; i < 7; ++i)
0292     ss << "\nTOB Layer " << i << " :\t\t" << NBadComponent[2][i][0] << "\t" << NBadComponent[2][i][1] << "\t"
0293        << NBadComponent[2][i][2] << "\t" << NBadComponent[2][i][3];
0294   ss << "\n";
0295   for (int i = 1; i < 10; ++i)
0296     ss << "\nTEC+ Disk " << i << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
0297        << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
0298   for (int i = 10; i < 19; ++i)
0299     ss << "\nTEC- Disk " << i - 9 << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
0300        << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
0301   ss << "\n";
0302 
0303   ss << "\n----------------------------------------------------------------\n\t\t   Detid  \tModules Fibers "
0304         "Apvs\n----------------------------------------------------------------";
0305   for (int i = 1; i < 5; ++i)
0306     ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
0307   ss << "\n";
0308   for (int i = 1; i < 4; ++i)
0309     ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
0310   for (int i = 4; i < 7; ++i)
0311     ss << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
0312   ss << "\n";
0313   for (int i = 1; i < 7; ++i)
0314     ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
0315   ss << "\n";
0316   for (int i = 1; i < 10; ++i)
0317     ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
0318   for (int i = 10; i < 19; ++i)
0319     ss << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
0320 
0321   edm::LogInfo("SiStripQualityStatistics") << ss.str() << std::endl;
0322 
0323   std::string filename = TkMapFileName_;
0324   std::stringstream sRun;
0325   sRun.str("");
0326   sRun << "_Run_" << std::setw(6) << std::setfill('0') << run_.run() << std::setw(0);
0327 
0328   if (!filename.empty()) {
0329     filename.insert(filename.find('.'), sRun.str());
0330     tkMap->save(true, 0, 0, filename);
0331     filename.erase(filename.begin() + filename.find('.'), filename.end());
0332     tkMap->print(true, 0, 0, filename);
0333   }
0334 }
0335 
0336 void SiStripQualityStatistics::SetBadComponents(int i, int component, SiStripQuality::BadComponent& BC) {
0337   int napv = detInfo_.getNumberOfApvsAndStripLength(BC.detid).first;
0338 
0339   ssV[i][component] << "\n\t\t " << BC.detid << " \t " << BC.BadModule << " \t " << ((BC.BadFibers) & 0x1) << " ";
0340   if (napv == 4)
0341     ssV[i][component] << "x " << ((BC.BadFibers >> 1) & 0x1);
0342 
0343   if (napv == 6)
0344     ssV[i][component] << ((BC.BadFibers >> 1) & 0x1) << " " << ((BC.BadFibers >> 2) & 0x1);
0345   ssV[i][component] << " \t " << ((BC.BadApvs) & 0x1) << " " << ((BC.BadApvs >> 1) & 0x1) << " ";
0346   if (napv == 4)
0347     ssV[i][component] << "x x " << ((BC.BadApvs >> 2) & 0x1) << " " << ((BC.BadApvs >> 3) & 0x1);
0348   if (napv == 6)
0349     ssV[i][component] << ((BC.BadApvs >> 2) & 0x1) << " " << ((BC.BadApvs >> 3) & 0x1) << " "
0350                       << ((BC.BadApvs >> 4) & 0x1) << " " << ((BC.BadApvs >> 5) & 0x1) << " ";
0351 
0352   if (BC.BadApvs) {
0353     NBadComponent[i][0][2] += ((BC.BadApvs >> 5) & 0x1) + ((BC.BadApvs >> 4) & 0x1) + ((BC.BadApvs >> 3) & 0x1) +
0354                               ((BC.BadApvs >> 2) & 0x1) + ((BC.BadApvs >> 1) & 0x1) + ((BC.BadApvs) & 0x1);
0355     NBadComponent[i][component][2] += ((BC.BadApvs >> 5) & 0x1) + ((BC.BadApvs >> 4) & 0x1) +
0356                                       ((BC.BadApvs >> 3) & 0x1) + ((BC.BadApvs >> 2) & 0x1) +
0357                                       ((BC.BadApvs >> 1) & 0x1) + ((BC.BadApvs) & 0x1);
0358     tkMap->fillc(BC.detid, 0xff0000);
0359   }
0360   if (BC.BadFibers) {
0361     NBadComponent[i][0][1] += ((BC.BadFibers >> 2) & 0x1) + ((BC.BadFibers >> 1) & 0x1) + ((BC.BadFibers) & 0x1);
0362     NBadComponent[i][component][1] +=
0363         ((BC.BadFibers >> 2) & 0x1) + ((BC.BadFibers >> 1) & 0x1) + ((BC.BadFibers) & 0x1);
0364     tkMap->fillc(BC.detid, 0x0000ff);
0365   }
0366   if (BC.BadModule) {
0367     NBadComponent[i][0][0]++;
0368     NBadComponent[i][component][0]++;
0369     tkMap->fillc(BC.detid, 0x0);
0370   }
0371 }
0372 
0373 #include "FWCore/Framework/interface/MakerMacros.h"
0374 DEFINE_FWK_MODULE(SiStripQualityStatistics);