CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Validation/RecoTau/plugins/DQMHistEffProducer.cc

Go to the documentation of this file.
00001 #include "Validation/RecoTau/plugins/DQMHistEffProducer.h"
00002 
00003 #include "Validation/RecoTau/plugins/dqmAuxFunctions.h"
00004 
00005 // framework & common header files
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 //DQM services
00010 #include "DQMServices/Core/interface/DQMStore.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013 
00014 #include <TH1.h>
00015 
00016 #include <iostream>
00017 
00018 DQMHistEffProducer::cfgEntryPlot::cfgEntryPlot(const edm::ParameterSet& cfg)
00019 {
00020   //std::cout << "<cfgEntryPlot::cfgEntryPlot>:" << std::endl;
00021 
00022   numerator_ = cfg.getParameter<std::string>("numerator");
00023   //std::cout << " numerator = " << numerator_ << std::endl;
00024 
00025   denominator_ = cfg.getParameter<std::string>("denominator");
00026   //std::cout << " denominator = " << denominator_ << std::endl;
00027 
00028   efficiency_ = cfg.getParameter<std::string>("efficiency");
00029   //std::cout << " efficiency = " << efficiency_ << std::endl;
00030 }
00031 
00032 DQMHistEffProducer::cfgEntryPlot::cfgEntryPlot(const std::string& numerator, const std::string& denominator, const std::string& efficiency)
00033   : numerator_(numerator), denominator_(denominator), efficiency_(efficiency)
00034 {
00035   //std::cout << "<cfgEntryPlot::cfgEntryPlot>:" << std::endl;
00036   //std::cout << " numerator = " << numerator_ << std::endl;
00037   //std::cout << " denominator = " << denominator_ << std::endl;
00038   //std::cout << " efficiency = " << efficiency_ << std::endl;
00039 }
00040 
00041 //
00042 //-----------------------------------------------------------------------------------------------------------------------
00043 //
00044 
00045 DQMHistEffProducer::DQMHistEffProducer(const edm::ParameterSet& cfg)
00046 {
00047   //std::cout << "<DQMHistEffProducer::DQMHistEffProducer>:" << std::endl;
00048   
00049   edm::ParameterSet plots = cfg.getParameter<edm::ParameterSet>("plots");
00050   std::vector<std::string> plotNames = plots.getParameterNamesForType<edm::ParameterSet>();
00051   for ( std::vector<std::string>::const_iterator plotName = plotNames.begin(); plotName != plotNames.end(); ++plotName ) {
00052     edm::ParameterSet plotConfig = plots.getParameter<edm::ParameterSet>(*plotName);
00053 
00054     typedef std::vector<std::string> vstring;
00055     vstring plotParameter = plotConfig.getParameter<vstring>("parameter");
00056     if ( plotParameter.size() == 0 ) {
00057       cfgEntryPlot_.push_back(cfgEntryPlot(plotConfig));
00058     } else {
00059       std::string numerator = plotConfig.getParameter<std::string>("numerator");
00060       std::string denominator = plotConfig.getParameter<std::string>("denominator");
00061       std::string efficiency = plotConfig.getParameter<std::string>("efficiency");
00062       for ( vstring::const_iterator parameter = plotParameter.begin(); parameter != plotParameter.end(); ++parameter ) {
00063         int errorFlag = 0;
00064         std::string modNumerator = replace_string(numerator, parKeyword, *parameter, 1, 1, errorFlag);
00065         std::string modDenominator = replace_string(denominator, parKeyword, *parameter, 1, 1, errorFlag);
00066         std::string modEfficiency = replace_string(efficiency, parKeyword, *parameter, 1, 1, errorFlag);
00067 
00068         if ( !errorFlag ) {
00069           cfgEntryPlot_.push_back(cfgEntryPlot(modNumerator, modDenominator, modEfficiency));
00070         } else {
00071           edm::LogError("DQMHistEffProducer") << " Failed to decode histogram names for plotName = " << (*plotName) 
00072                                               << " --> skipping !!";
00073         }
00074       }
00075     }
00076   }
00077 }
00078 
00079 DQMHistEffProducer::~DQMHistEffProducer() 
00080 {
00081 //--- nothing to be done yet
00082 }
00083 
00084 void DQMHistEffProducer::analyze(const edm::Event&, const edm::EventSetup&)
00085 {
00086 //--- nothing to be done yet
00087 }
00088 
00089 void DQMHistEffProducer::endJob()
00090 {
00091   //std::cout << "<DQMHistEffProducer::endJob>:" << std::endl;
00092 
00093 //--- check that DQMStore service is available
00094   if ( !edm::Service<DQMStore>().isAvailable() ) {
00095     edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
00096     return;
00097   }
00098 
00099   DQMStore& dqmStore = (*edm::Service<DQMStore>());
00100 
00101   for ( std::vector<cfgEntryPlot>::const_iterator plot = cfgEntryPlot_.begin(); plot != cfgEntryPlot_.end(); ++plot ) {
00102     //std::cout << "plot->numerator_ = " << plot->numerator_ << std::endl;
00103     std::string numeratorHistogramName, numeratorHistogramDirectory;
00104     separateHistogramFromDirectoryName(plot->numerator_, numeratorHistogramName, numeratorHistogramDirectory);
00105     //std::cout << "numeratorHistogramName = " << numeratorHistogramName << std::endl;
00106     //std::cout << "numeratorHistogramDirectory = " << numeratorHistogramDirectory << std::endl;
00107     MonitorElement* meNumerator = dqmStore.get(std::string(numeratorHistogramDirectory).append(dqmSeparator).append(numeratorHistogramName));
00108     //std::cout << "meNumerator = " << meNumerator << std::endl;
00109     TH1* histoNumerator = ( meNumerator != NULL ) ? meNumerator->getTH1() : NULL;
00110     
00111     //std::cout << "plot->denominator_ = " << plot->denominator_ << std::endl;
00112     std::string denominatorHistogramName, denominatorHistogramDirectory;
00113     separateHistogramFromDirectoryName(plot->denominator_, denominatorHistogramName, denominatorHistogramDirectory);
00114     //std::cout << "denominatorHistogramName = " << denominatorHistogramName << std::endl;
00115     //std::cout << "denominatorHistogramDirectory = " << denominatorHistogramDirectory << std::endl;
00116     MonitorElement* meDenominator = dqmStore.get(std::string(denominatorHistogramDirectory).append(dqmSeparator).append(denominatorHistogramName));
00117     //std::cout << "meDenominator = " << meDenominator << std::endl;
00118     TH1* histoDenominator = ( meDenominator != NULL ) ? meDenominator->getTH1() : NULL;
00119     
00120     if ( histoNumerator != NULL && histoDenominator != NULL ) {
00121       if ( !histoNumerator->GetSumw2N() ) histoNumerator->Sumw2();
00122       //std::cout << " histoNumerator->GetName = " << histoNumerator->GetName() << std::endl;
00123       
00124       if ( !histoDenominator->GetSumw2N() ) histoDenominator->Sumw2();
00125       //std::cout << " histoDenominator->GetName = " << histoNumerator->GetName() << std::endl;
00126       
00127       std::string effHistogramName, effHistogramDirectory, dummy;
00128       separateHistogramFromDirectoryName(plot->efficiency_, effHistogramName, effHistogramDirectory);
00129       if ( effHistogramDirectory == "" ) separateHistogramFromDirectoryName(numeratorHistogramName, dummy, effHistogramDirectory);
00130       if ( effHistogramDirectory != "" ) dqmStore.setCurrentFolder(effHistogramDirectory);
00131       
00132       MonitorElement* histoEfficiency = dqmStore.book1D(effHistogramName, effHistogramName, 
00133                                                         histoNumerator->GetNbinsX(), histoNumerator->GetXaxis()->GetXmin(), histoNumerator->GetXaxis()->GetXmax());
00134       
00135       histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");
00136     } else {
00137       edm::LogError("endJob") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
00138       if ( histoNumerator   == NULL ) edm::LogError("endJob") << "  numerator = " << plot->numerator_ << " does not exist.";
00139       if ( histoDenominator == NULL ) edm::LogError("endJob") << "  denominator = " << plot->denominator_ << " does not exist.";
00140     }
00141   }
00142 }
00143 
00144 #include "FWCore/Framework/interface/MakerMacros.h"
00145 
00146 DEFINE_FWK_MODULE(DQMHistEffProducer);