CMS 3D CMS Logo

Classes | Public Member Functions | Private Attributes

DQMHistEffProducer Class Reference

#include <DQMHistEffProducer.h>

Inheritance diagram for DQMHistEffProducer:
edm::EDAnalyzer

List of all members.

Classes

struct  cfgEntryPlot

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 DQMHistEffProducer (const edm::ParameterSet &)
virtual void endJob ()
virtual ~DQMHistEffProducer ()

Private Attributes

std::vector< cfgEntryPlotcfgEntryPlot_

Detailed Description

Class to produce efficiency histograms by dividing nominator by denominator histograms

Date:
2008/12/19 19:05:50
Revision:
1.1
Author:
Christian Veelken, UC Davis

Definition at line 22 of file DQMHistEffProducer.h.


Constructor & Destructor Documentation

DQMHistEffProducer::DQMHistEffProducer ( const edm::ParameterSet cfg) [explicit]

Definition at line 45 of file DQMHistEffProducer.cc.

References cfgEntryPlot_, RecoTauValidation_cfi::denominator, postValidation_cfi::efficiency, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), parKeyword, and replace_string().

{
  //std::cout << "<DQMHistEffProducer::DQMHistEffProducer>:" << std::endl;
  
  edm::ParameterSet plots = cfg.getParameter<edm::ParameterSet>("plots");
  std::vector<std::string> plotNames = plots.getParameterNamesForType<edm::ParameterSet>();
  for ( std::vector<std::string>::const_iterator plotName = plotNames.begin(); plotName != plotNames.end(); ++plotName ) {
    edm::ParameterSet plotConfig = plots.getParameter<edm::ParameterSet>(*plotName);

    typedef std::vector<std::string> vstring;
    vstring plotParameter = plotConfig.getParameter<vstring>("parameter");
    if ( plotParameter.size() == 0 ) {
      cfgEntryPlot_.push_back(cfgEntryPlot(plotConfig));
    } else {
      std::string numerator = plotConfig.getParameter<std::string>("numerator");
      std::string denominator = plotConfig.getParameter<std::string>("denominator");
      std::string efficiency = plotConfig.getParameter<std::string>("efficiency");
      for ( vstring::const_iterator parameter = plotParameter.begin(); parameter != plotParameter.end(); ++parameter ) {
        int errorFlag = 0;
        std::string modNumerator = replace_string(numerator, parKeyword, *parameter, 1, 1, errorFlag);
        std::string modDenominator = replace_string(denominator, parKeyword, *parameter, 1, 1, errorFlag);
        std::string modEfficiency = replace_string(efficiency, parKeyword, *parameter, 1, 1, errorFlag);

        if ( !errorFlag ) {
          cfgEntryPlot_.push_back(cfgEntryPlot(modNumerator, modDenominator, modEfficiency));
        } else {
          edm::LogError("DQMHistEffProducer") << " Failed to decode histogram names for plotName = " << (*plotName) 
                                              << " --> skipping !!";
        }
      }
    }
  }
}
DQMHistEffProducer::~DQMHistEffProducer ( ) [virtual]

Definition at line 79 of file DQMHistEffProducer.cc.

{
//--- nothing to be done yet
}

Member Function Documentation

void DQMHistEffProducer::analyze ( const edm::Event ,
const edm::EventSetup  
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 84 of file DQMHistEffProducer.cc.

{
//--- nothing to be done yet
}
void DQMHistEffProducer::endJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 89 of file DQMHistEffProducer.cc.

References python::multivaluedict::append(), DQMStore::book1D(), cfgEntryPlot_, dqmSeparator, DQMStore::get(), MonitorElement::getTH1(), MonitorElement::getTH1F(), NULL, EcalCondTools::plot(), separateHistogramFromDirectoryName(), and DQMStore::setCurrentFolder().

{
  //std::cout << "<DQMHistEffProducer::endJob>:" << std::endl;

//--- check that DQMStore service is available
  if ( !edm::Service<DQMStore>().isAvailable() ) {
    edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
    return;
  }

  DQMStore& dqmStore = (*edm::Service<DQMStore>());

  for ( std::vector<cfgEntryPlot>::const_iterator plot = cfgEntryPlot_.begin(); plot != cfgEntryPlot_.end(); ++plot ) {
    //std::cout << "plot->numerator_ = " << plot->numerator_ << std::endl;
    std::string numeratorHistogramName, numeratorHistogramDirectory;
    separateHistogramFromDirectoryName(plot->numerator_, numeratorHistogramName, numeratorHistogramDirectory);
    //std::cout << "numeratorHistogramName = " << numeratorHistogramName << std::endl;
    //std::cout << "numeratorHistogramDirectory = " << numeratorHistogramDirectory << std::endl;
    MonitorElement* meNumerator = dqmStore.get(std::string(numeratorHistogramDirectory).append(dqmSeparator).append(numeratorHistogramName));
    //std::cout << "meNumerator = " << meNumerator << std::endl;
    TH1* histoNumerator = ( meNumerator != NULL ) ? meNumerator->getTH1() : NULL;
    
    //std::cout << "plot->denominator_ = " << plot->denominator_ << std::endl;
    std::string denominatorHistogramName, denominatorHistogramDirectory;
    separateHistogramFromDirectoryName(plot->denominator_, denominatorHistogramName, denominatorHistogramDirectory);
    //std::cout << "denominatorHistogramName = " << denominatorHistogramName << std::endl;
    //std::cout << "denominatorHistogramDirectory = " << denominatorHistogramDirectory << std::endl;
    MonitorElement* meDenominator = dqmStore.get(std::string(denominatorHistogramDirectory).append(dqmSeparator).append(denominatorHistogramName));
    //std::cout << "meDenominator = " << meDenominator << std::endl;
    TH1* histoDenominator = ( meDenominator != NULL ) ? meDenominator->getTH1() : NULL;
    
    if ( histoNumerator != NULL && histoDenominator != NULL ) {
      if ( !histoNumerator->GetSumw2N() ) histoNumerator->Sumw2();
      //std::cout << " histoNumerator->GetName = " << histoNumerator->GetName() << std::endl;
      
      if ( !histoDenominator->GetSumw2N() ) histoDenominator->Sumw2();
      //std::cout << " histoDenominator->GetName = " << histoNumerator->GetName() << std::endl;
      
      std::string effHistogramName, effHistogramDirectory, dummy;
      separateHistogramFromDirectoryName(plot->efficiency_, effHistogramName, effHistogramDirectory);
      if ( effHistogramDirectory == "" ) separateHistogramFromDirectoryName(numeratorHistogramName, dummy, effHistogramDirectory);
      if ( effHistogramDirectory != "" ) dqmStore.setCurrentFolder(effHistogramDirectory);
      
      MonitorElement* histoEfficiency = dqmStore.book1D(effHistogramName, effHistogramName, 
                                                        histoNumerator->GetNbinsX(), histoNumerator->GetXaxis()->GetXmin(), histoNumerator->GetXaxis()->GetXmax());
      
      histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");
    } else {
      edm::LogError("endJob") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
      if ( histoNumerator   == NULL ) edm::LogError("endJob") << "  numerator = " << plot->numerator_ << " does not exist.";
      if ( histoDenominator == NULL ) edm::LogError("endJob") << "  denominator = " << plot->denominator_ << " does not exist.";
    }
  }
}

Member Data Documentation

Definition at line 40 of file DQMHistEffProducer.h.

Referenced by DQMHistEffProducer(), and endJob().