Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:53

0001 #ifndef CalibTracker_SiStripHitEfficiency_SiStripHitEffData_h
0002 #define CalibTracker_SiStripHitEfficiency_SiStripHitEffData_h
0003 
0004 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
0005 #include "DQMServices/Core/interface/DQMStore.h"
0006 #include "DQMServices/Core/interface/MonitorElement.h"
0007 #include <unordered_map>
0008 
0009 struct SiStripHitEffData {
0010 public:
0011   SiStripHitEffData() : EventStats(), FEDErrorOccupancy(nullptr), m_isLoaded(false) {}
0012 
0013   void fillTkMapFromMap() {
0014     for (const auto& [id, count] : fedErrorCounts) {
0015       FEDErrorOccupancy->fill(id, count);
0016     }
0017   }
0018 
0019   void fillMapFromTkMap(const int nevents, const float threshold, const std::vector<DetId>& stripDetIds) {
0020     const auto& Maps = FEDErrorOccupancy->getAllMaps();
0021     std::vector<bool> isThere;
0022     isThere.reserve(Maps.size());
0023     std::transform(Maps.begin() + 1, Maps.end(), std::back_inserter(isThere), [](auto& x) { return !(x == nullptr); });
0024 
0025     int count{0};
0026     for (const auto& it : isThere) {
0027       count++;
0028       LogTrace("SiStripHitEffData") << " layer: " << count << " " << it << std::endl;
0029       if (it)
0030         LogTrace("SiStripHitEffData") << "resolving to " << Maps[count]->getName()
0031                                       << " with entries: " << Maps[count]->getEntries() << std::endl;
0032       // color the map
0033       Maps[count]->setOption("colz");
0034     }
0035 
0036     for (const auto& det : stripDetIds) {
0037       const auto& counts = FEDErrorOccupancy->getValue(det);
0038 
0039       if (counts > 0) {
0040         float fraction = counts / nevents;
0041 
0042         LogTrace("SiStripHitEffData") << det.rawId() << " has " << counts << " counts, " << fraction * 100
0043                                       << "% fraction of the " << nevents << " events processed" << std::endl;
0044 
0045         if (fraction > threshold) {
0046           fedErrorCounts.insert(std::make_pair(det, 1));
0047         }
0048       }  // do not check functioning modules
0049     }
0050     // the map has been loaded
0051     m_isLoaded = true;
0052   }
0053 
0054   const bool checkFedError(const DetId det) {
0055     if (m_isLoaded) {
0056       return (fedErrorCounts.find(det) == fedErrorCounts.end());
0057     } else {
0058       throw cms::Exception("LogicError") << __PRETTY_FUNCTION__ << "cannot check DetId when map not filled";
0059     }
0060   }
0061 
0062   dqm::reco::MonitorElement* EventStats;
0063   std::unordered_map<uint32_t, int> fedErrorCounts;
0064   std::unique_ptr<TkHistoMap> FEDErrorOccupancy;
0065 
0066 private:
0067   bool m_isLoaded;
0068 };
0069 
0070 #endif