Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:32

0001 #include "DQM/SiStripCommissioningClients/interface/PedsFullNoiseHistograms.h"
0002 #include "CondFormats/SiStripObjects/interface/PedsFullNoiseAnalysis.h"
0003 #include "DQM/SiStripCommissioningAnalysis/interface/PedsFullNoiseAlgorithm.h"
0004 #include "DQM/SiStripCommissioningSummary/interface/PedsFullNoiseSummaryFactory.h"
0005 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include <iostream>
0009 #include <memory>
0010 
0011 #include <sstream>
0012 #include <iomanip>
0013 #include "TProfile.h"
0014 
0015 using namespace std;
0016 using namespace sistrip;
0017 
0018 // -----------------------------------------------------------------------------
0019 /** */
0020 PedsFullNoiseHistograms::PedsFullNoiseHistograms(const edm::ParameterSet& pset, DQMStore* bei)
0021     : CommissioningHistograms(
0022           pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters"), bei, sistrip::PEDS_FULL_NOISE) {
0023   factory_ = std::make_unique<PedsFullNoiseSummaryFactory>();
0024   LogTrace(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0025                          << " Constructing object...";
0026 }
0027 
0028 // -----------------------------------------------------------------------------
0029 /** */
0030 PedsFullNoiseHistograms::~PedsFullNoiseHistograms() {
0031   LogTrace(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0032                          << " Destructing object...";
0033 }
0034 
0035 // -----------------------------------------------------------------------------
0036 /** */
0037 void PedsFullNoiseHistograms::histoAnalysis(bool debug) {
0038   LogTrace(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]";
0039 
0040   // Some initialisation
0041   uint16_t valid = 0;
0042   HistosMap::const_iterator iter;
0043   Analyses::iterator ianal;
0044   std::map<std::string, uint16_t> errors;
0045 
0046   // Clear map holding analysis objects
0047   for (ianal = data().begin(); ianal != data().end(); ianal++) {
0048     if (ianal->second) {
0049       delete ianal->second;
0050     }
0051   }
0052   data().clear();
0053 
0054   // Iterate through map containing histograms
0055   long int ichannel = 0;
0056   long int nchannel = histos().size();
0057   for (iter = histos().begin(); iter != histos().end(); iter++) {
0058     // Check vector of histos is not empty
0059     if (iter->second.empty()) {
0060       edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0061                                     << " Zero histograms found!";
0062       continue;
0063     }
0064 
0065     // Retrieve pointers to peds and noise histos
0066     std::vector<TH1*> hists;
0067     Histos::const_iterator ihis = iter->second.begin();
0068 
0069     for (; ihis != iter->second.end(); ihis++) {
0070       // pedestal and noise 1D profiles
0071       TProfile* prof = ExtractTObject<TProfile>().extract((*ihis)->me_);
0072       if (prof) {
0073         hists.push_back(prof);
0074       }
0075       // 2D noise histograms
0076       TH2S* his2D = ExtractTObject<TH2S>().extract((*ihis)->me_);
0077       if (his2D) {
0078         hists.push_back(his2D);
0079       }
0080     }
0081 
0082     if (ichannel % 100 == 0)
0083       edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0084                                      << " Analyzing channel " << ichannel << " out of " << nchannel;
0085     ichannel++;
0086 
0087     // Perform histo analysis
0088     PedsFullNoiseAnalysis* anal = new PedsFullNoiseAnalysis(iter->first);
0089     PedsFullNoiseAlgorithm algo(this->pset(), anal);
0090     algo.analysis(hists);
0091 
0092     data()[iter->first] = anal;
0093     if (anal->isValid()) {
0094       valid++;
0095     }
0096     if (!anal->getErrorCodes().empty()) {
0097       errors[anal->getErrorCodes()[0]]++;
0098     }
0099   }
0100 
0101   if (!histos().empty()) {
0102     edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0103                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0104                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0105     if (!errors.empty()) {
0106       uint16_t count = 0;
0107       std::stringstream ss;
0108       ss << std::endl;
0109       std::map<std::string, uint16_t>::const_iterator ii;
0110       for (ii = errors.begin(); ii != errors.end(); ++ii) {
0111         ss << " " << ii->first << ": " << ii->second << std::endl;
0112         count += ii->second;
0113       }
0114       edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0115                                     << " Found " << count << " errors (" << 100 * count / histos().size()
0116                                     << "%): " << ss.str();
0117     }
0118   } else {
0119     edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistograms::" << __func__ << "]"
0120                                   << " No histograms to analyze!";
0121   }
0122 }
0123 
0124 // -----------------------------------------------------------------------------
0125 /** */
0126 void PedsFullNoiseHistograms::printAnalyses() {
0127   Analyses::iterator ianal = data().begin();
0128   Analyses::iterator janal = data().end();
0129   for (; ianal != janal; ++ianal) {
0130     if (ianal->second) {
0131       std::stringstream ss;
0132       ianal->second->print(ss, 1);
0133       ianal->second->print(ss, 2);
0134       if (ianal->second->isValid()) {
0135         LogTrace(mlDqmClient_) << ss.str();
0136       } else {
0137         edm::LogWarning(mlDqmClient_) << ss.str();
0138       }
0139     }
0140   }
0141 }