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