Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:17

0001 #include "Validation/RecoTau/plugins/DQMHistEffProducer.h"
0002 
0003 #include "Validation/RecoTau/plugins/dqmAuxFunctions.h"
0004 
0005 // framework & common header files
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 //DQM services
0010 #include "DQMServices/Core/interface/DQMStore.h"
0011 #include "FWCore/ServiceRegistry/interface/Service.h"
0012 
0013 #include <TH1.h>
0014 #include <TCanvas.h>
0015 
0016 #include <iostream>
0017 
0018 TauDQMHistEffProducer::cfgEntryPlot::cfgEntryPlot(const edm::ParameterSet& cfg) {
0019   //std::cout << "<cfgEntryPlot::cfgEntryPlot>:" << std::endl;
0020 
0021   numerator_ = cfg.getParameter<std::string>("numerator");
0022   //std::cout << " numerator = " << numerator_ << std::endl;
0023 
0024   denominator_ = cfg.getParameter<std::string>("denominator");
0025   //std::cout << " denominator = " << denominator_ << std::endl;
0026 
0027   efficiency_ = cfg.getParameter<std::string>("efficiency");
0028   //std::cout << " efficiency = " << efficiency_ << std::endl;
0029 }
0030 
0031 TauDQMHistEffProducer::cfgEntryPlot::cfgEntryPlot(const std::string& numerator,
0032                                                   const std::string& denominator,
0033                                                   const std::string& efficiency)
0034     : numerator_(numerator), denominator_(denominator), efficiency_(efficiency) {
0035   //std::cout << "<cfgEntryPlot::cfgEntryPlot>:" << std::endl;
0036   //std::cout << " numerator = " << numerator_ << std::endl;
0037   //std::cout << " denominator = " << denominator_ << std::endl;
0038   //std::cout << " efficiency = " << efficiency_ << std::endl;
0039 }
0040 
0041 //
0042 //-----------------------------------------------------------------------------------------------------------------------
0043 //
0044 
0045 TauDQMHistEffProducer::TauDQMHistEffProducer(const edm::ParameterSet& cfg) {
0046   //std::cout << "<TauDQMHistEffProducer::TauDQMHistEffProducer>:" << std::endl;
0047 
0048   edm::ParameterSet plots = cfg.getParameter<edm::ParameterSet>("plots");
0049   std::vector<std::string> plotNames = plots.getParameterNamesForType<edm::ParameterSet>();
0050   for (std::vector<std::string>::const_iterator plotName = plotNames.begin(); plotName != plotNames.end(); ++plotName) {
0051     edm::ParameterSet plotConfig = plots.getParameter<edm::ParameterSet>(*plotName);
0052 
0053     typedef std::vector<std::string> vstring;
0054     vstring plotParameter = plotConfig.getParameter<vstring>("parameter");
0055     if (plotParameter.empty()) {
0056       cfgEntryPlot_.push_back(cfgEntryPlot(plotConfig));
0057     } else {
0058       std::string numerator = plotConfig.getParameter<std::string>("numerator");
0059       std::string denominator = plotConfig.getParameter<std::string>("denominator");
0060       std::string efficiency = plotConfig.getParameter<std::string>("efficiency");
0061       for (vstring::const_iterator parameter = plotParameter.begin(); parameter != plotParameter.end(); ++parameter) {
0062         int errorFlag = 0;
0063         std::string modNumerator = replace_string(numerator, parKeyword, *parameter, 1, 1, errorFlag);
0064         std::string modDenominator = replace_string(denominator, parKeyword, *parameter, 1, 1, errorFlag);
0065         std::string modEfficiency = replace_string(efficiency, parKeyword, *parameter, 1, 1, errorFlag);
0066 
0067         if (!errorFlag) {
0068           cfgEntryPlot_.push_back(cfgEntryPlot(modNumerator, modDenominator, modEfficiency));
0069         } else {
0070           edm::LogError("TauDQMHistEffProducer")
0071               << " Failed to decode histogram names for plotName = " << (*plotName) << " --> skipping !!";
0072         }
0073       }
0074     }
0075   }
0076 }
0077 
0078 TauDQMHistEffProducer::~TauDQMHistEffProducer() {
0079   //--- nothing to be done yet
0080 }
0081 
0082 void TauDQMHistEffProducer::dqmEndJob(DQMStore::IBooker& ibook, DQMStore::IGetter& iget) {
0083   //std::cout << "<TauDQMHistEffProducer::endJob>:" << std::endl;
0084 
0085   for (std::vector<cfgEntryPlot>::const_iterator plot = cfgEntryPlot_.begin(); plot != cfgEntryPlot_.end(); ++plot) {
0086     //std::cout << "plot->numerator_ = " << plot->numerator_ << std::endl;
0087     std::string numeratorHistogramName, numeratorHistogramDirectory;
0088     separateHistogramFromDirectoryName(plot->numerator_, numeratorHistogramName, numeratorHistogramDirectory);
0089     //std::cout << "numeratorHistogramName = " << numeratorHistogramName << std::endl;
0090     //std::cout << "numeratorHistogramDirectory = " << numeratorHistogramDirectory << std::endl;
0091     MonitorElement* meNumerator =
0092         iget.get(std::string(numeratorHistogramDirectory).append(dqmSeparator).append(numeratorHistogramName));
0093     //std::cout << "meNumerator = " << meNumerator << std::endl;
0094     TH1* histoNumerator = (meNumerator != nullptr) ? meNumerator->getTH1() : nullptr;
0095 
0096     //std::cout << "plot->denominator_ = " << plot->denominator_ << std::endl;
0097     std::string denominatorHistogramName, denominatorHistogramDirectory;
0098     separateHistogramFromDirectoryName(plot->denominator_, denominatorHistogramName, denominatorHistogramDirectory);
0099     //std::cout << "denominatorHistogramName = " << denominatorHistogramName << std::endl;
0100     //std::cout << "denominatorHistogramDirectory = " << denominatorHistogramDirectory << std::endl;
0101     MonitorElement* meDenominator =
0102         iget.get(std::string(denominatorHistogramDirectory).append(dqmSeparator).append(denominatorHistogramName));
0103     //std::cout << "meDenominator = " << meDenominator << std::endl;
0104     TH1* histoDenominator = (meDenominator != nullptr) ? meDenominator->getTH1() : nullptr;
0105 
0106     if (histoNumerator != nullptr && histoDenominator != nullptr) {
0107       if (!histoNumerator->GetSumw2N())
0108         histoNumerator->Sumw2();
0109       //std::cout << " histoNumerator->GetName = " << histoNumerator->GetName() << std::endl;
0110 
0111       if (!histoDenominator->GetSumw2N())
0112         histoDenominator->Sumw2();
0113       //std::cout << " histoDenominator->GetName = " << histoNumerator->GetName() << std::endl;
0114 
0115       std::string effHistogramName, effHistogramDirectory, dummy;
0116       separateHistogramFromDirectoryName(plot->efficiency_, effHistogramName, effHistogramDirectory);
0117       //if ( effHistogramDirectory == "" ) separateHistogramFromDirectoryName(numeratorHistogramName, dummy, effHistogramDirectory);
0118       if (!effHistogramDirectory.empty()) {
0119         if (iget.dirExists(effHistogramDirectory))
0120           ibook.setCurrentFolder(effHistogramDirectory);
0121         else
0122           std::cout << "TauDQMHistEffProducer:: Directory: " << effHistogramDirectory << " does not exist!"
0123                     << std::endl;
0124       }
0125 
0126       MonitorElement* histoEfficiency = ibook.book1D(effHistogramName,
0127                                                      effHistogramName,
0128                                                      histoNumerator->GetNbinsX(),
0129                                                      histoNumerator->GetXaxis()->GetXmin(),
0130                                                      histoNumerator->GetXaxis()->GetXmax());
0131 
0132       histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");
0133 
0134       //to avoid the pointer to go out of scope:
0135       histoEfficiencyVector_.push_back(histoEfficiency);
0136 
0137       /*      std::vector<std::string> mes = dqmStore.getMEs();
0138       std::cout<<dqmStore.pwd()<<std::endl;
0139       for(unsigned int i =0; i<mes.size(); i++)
0140     std::cout<<mes[i]<<std::endl;
0141       */
0142     } else {
0143       edm::LogError("endRun") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
0144       if (histoNumerator == nullptr)
0145         edm::LogError("endRun") << "  numerator = " << plot->numerator_ << " does not exist.";
0146       if (histoDenominator == nullptr)
0147         edm::LogError("endRun") << "  denominator = " << plot->denominator_ << " does not exist.";
0148     }
0149   }
0150 }
0151 
0152 #include "FWCore/Framework/interface/MakerMacros.h"
0153 
0154 DEFINE_FWK_MODULE(TauDQMHistEffProducer);