CMS 3D CMS Logo

Classes | Public Member Functions | Private Attributes

TauDQMHistEffProducer Class Reference

#include <DQMHistEffProducer.h>

Inheritance diagram for TauDQMHistEffProducer:
edm::EDAnalyzer

List of all members.

Classes

struct  cfgEntryPlot

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void endJob ()
virtual void endRun (const edm::Run &r, const edm::EventSetup &c)
 TauDQMHistEffProducer (const edm::ParameterSet &)
virtual ~TauDQMHistEffProducer ()

Private Attributes

std::vector< cfgEntryPlotcfgEntryPlot_
std::vector< MonitorElement * > histoEfficiencyVector_

Detailed Description

Class to produce efficiency histograms by dividing nominator by denominator histograms

Date:
2012/04/20 13:26:14
Revision:
1.3
Author:
Christian Veelken, UC Davis

Definition at line 24 of file DQMHistEffProducer.h.


Constructor & Destructor Documentation

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

Definition at line 46 of file DQMHistEffProducer.cc.

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

{
  //std::cout << "<TauDQMHistEffProducer::TauDQMHistEffProducer>:" << 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("TauDQMHistEffProducer") << " Failed to decode histogram names for plotName = " << (*plotName) 
                                              << " --> skipping !!";
        }
      }
    }
  }
}
TauDQMHistEffProducer::~TauDQMHistEffProducer ( ) [virtual]

Definition at line 80 of file DQMHistEffProducer.cc.

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

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 85 of file DQMHistEffProducer.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 39 of file DQMHistEffProducer.h.

{}
void TauDQMHistEffProducer::endRun ( const edm::Run r,
const edm::EventSetup c 
) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 90 of file DQMHistEffProducer.cc.

References python::multivaluedict::append(), DQMStore::book1D(), cfgEntryPlot_, gather_cfg::cout, DQMStore::dirExists(), dqmSeparator, DQMStore::get(), MonitorElement::getTH1(), MonitorElement::getTH1F(), histoEfficiencyVector_, NULL, plotResiduals::plot(), separateHistogramFromDirectoryName(), and DQMStore::setCurrentFolder().

{
  //std::cout << "<TauDQMHistEffProducer::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 != "" ) 
        {
          if(dqmStore.dirExists(effHistogramDirectory))
            dqmStore.setCurrentFolder(effHistogramDirectory);
          else
            std::cout<<"TauDQMHistEffProducer:: Directory: "<<effHistogramDirectory<<" does not exist!"<<std::endl;
        }
      
      MonitorElement* histoEfficiency = dqmStore.book1D(effHistogramName, effHistogramName, 
                                                        histoNumerator->GetNbinsX(), histoNumerator->GetXaxis()->GetXmin(), histoNumerator->GetXaxis()->GetXmax());
      
      histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");

      //to avoid the pointer to go out of scope:
      histoEfficiencyVector_.push_back(histoEfficiency);

      /*      std::vector<std::string> mes = dqmStore.getMEs();
      std::cout<<dqmStore.pwd()<<std::endl;
      for(unsigned int i =0; i<mes.size(); i++)
        std::cout<<mes[i]<<std::endl;
      */
    } else {
      edm::LogError("endRun") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
      if ( histoNumerator   == NULL ) edm::LogError("endRun") << "  numerator = " << plot->numerator_ << " does not exist.";
      if ( histoDenominator == NULL ) edm::LogError("endRun") << "  denominator = " << plot->denominator_ << " does not exist.";
    }
  }
}

Member Data Documentation

Definition at line 43 of file DQMHistEffProducer.h.

Referenced by endRun(), and TauDQMHistEffProducer().

Definition at line 44 of file DQMHistEffProducer.h.

Referenced by endRun().