Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:33

0001 #include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <iostream>
0005 #include <iomanip>  // std::setw
0006 
0007 //****************************************************************************//
0008 void SiPixelQualityProbabilities::setProbabilities(const unsigned int puBin, const probabilityVec &theProbabilities) {
0009   if (m_probabilities.find(puBin) != m_probabilities.end()) {
0010     edm::LogWarning("SiPixelQualityProbabilities") << "PU bin: " << puBin << " is already in the map!" << std::endl;
0011     return;
0012   } else {
0013     m_probabilities.emplace(puBin, theProbabilities);
0014   }
0015 }
0016 
0017 //****************************************************************************//
0018 SiPixelQualityProbabilities::probabilityVec SiPixelQualityProbabilities::getProbabilities(
0019     const unsigned int puBin) const {
0020   probabilityMap::const_iterator it = m_probabilities.find(puBin);
0021 
0022   if (it != m_probabilities.end()) {
0023     return it->second;
0024   } else {
0025     throw cms::Exception("SiPixelQualityProbabilities") << "No Probabilities are defined for PU bin " << puBin << "\n";
0026   }
0027 }
0028 
0029 //****************************************************************************//
0030 const SiPixelQualityProbabilities::probabilityVec &SiPixelQualityProbabilities::getProbabilities(
0031     const unsigned int puBin) {
0032   probabilityMap::const_iterator it = m_probabilities.find(puBin);
0033 
0034   if (it != m_probabilities.end()) {
0035     return it->second;
0036   } else {
0037     throw cms::Exception("SiPixelQualityProbabilities") << "No Probabilities are defined for PU bin " << puBin << "\n";
0038   }
0039 }
0040 
0041 //****************************************************************************//
0042 void SiPixelQualityProbabilities::printAll() const {
0043   edm::LogVerbatim("SiPixelQualityProbabilities") << "SiPixelQualityProbabilities::printAll()";
0044   edm::LogVerbatim("SiPixelQualityProbabilities") << " ================================================================"
0045                                                      "===================================================";
0046   for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
0047     edm::LogVerbatim("SiPixelQualityProbabilities") << "PU :" << it->first << "  \n ";
0048     for (const auto &entry : it->second) {
0049       edm::LogVerbatim("SiPixelQualityProbabilities")
0050           << "SiPixelQuality snapshot: " << entry.first << " |probability: " << entry.second << std::endl;
0051     }
0052   }
0053 }
0054 
0055 //****************************************************************************//
0056 void SiPixelQualityProbabilities::print(std::ostream &os) const {
0057   for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
0058     os << "PU :" << it->first << "  \n ";
0059     for (const auto &entry : it->second) {
0060       os << "SiPixelQuality snapshot: " << entry.first << " |probability: " << entry.second << std::endl;
0061     }
0062   }
0063 }
0064 
0065 //****************************************************************************//
0066 std::vector<unsigned int> SiPixelQualityProbabilities::getPileUpBins() const {
0067   std::vector<unsigned int> bins;
0068   bins.reserve(m_probabilities.size());
0069 
0070   for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
0071     bins.push_back(it->first);
0072   }
0073   return bins;
0074 }
0075 
0076 //****************************************************************************//
0077 std::ostream &operator<<(std::ostream &os, SiPixelQualityProbabilities theProbabilities) {
0078   std::stringstream ss;
0079   theProbabilities.print(ss);
0080   os << ss.str();
0081   return os;
0082 }