CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

ConfigurableHisto Class Reference

#include <ConfigurableHisto.h>

Inheritance diagram for ConfigurableHisto:
SplittingConfigurableHisto

List of all members.

Public Types

enum  HType { h1, h2, prof }

Public Member Functions

virtual void book (TFileDirectory *dir)
virtual ConfigurableHistoclone () const
void complete ()
 ConfigurableHisto (HType t, std::string name, edm::ParameterSet &iConfig)
virtual void fill (const edm::Event &iEvent)
TH1 * h ()
const HTypetype ()
virtual ~ConfigurableHisto ()

Protected Member Functions

 ConfigurableHisto (const ConfigurableHisto &master)

Protected Attributes

edm::ParameterSet conf_
TH1 * h_
std::string name_
HType type_
const CachingVariablew_
const CachingVariablex_
const CachingVariabley_
const CachingVariablez_

Detailed Description

Definition at line 53 of file ConfigurableHisto.h.


Member Enumeration Documentation

Enumerator:
h1 
h2 
prof 

Definition at line 55 of file ConfigurableHisto.h.

{ h1 ,h2, prof };

Constructor & Destructor Documentation

ConfigurableHisto::ConfigurableHisto ( HType  t,
std::string  name,
edm::ParameterSet iConfig 
) [inline]

Definition at line 56 of file ConfigurableHisto.h.

Referenced by clone(), and SplittingConfigurableHisto::SplittingConfigurableHisto().

                                                                        :
    type_(t),h_(0),name_(name), conf_(iConfig),x_(0),y_(0),z_(0),w_(0){}
virtual ConfigurableHisto::~ConfigurableHisto ( ) [inline, virtual]

Definition at line 59 of file ConfigurableHisto.h.

{}
ConfigurableHisto::ConfigurableHisto ( const ConfigurableHisto master) [inline, protected]

Definition at line 204 of file ConfigurableHisto.h.

References conf_, h_, name_, type_, w_, x_, y_, and z_.

                                                     {
    type_=master.type_;
    h_=0; //no histogram attached in copy constructor
    name_=master.name_;
    conf_=master.conf_;
    x_=master.x_;
    y_=master.y_;
    z_=master.z_;
    w_=master.w_;
  }

Member Function Documentation

virtual void ConfigurableHisto::book ( TFileDirectory dir) [inline, virtual]

Reimplemented in SplittingConfigurableHisto.

Definition at line 63 of file ConfigurableHisto.h.

References conf_, edm::ParameterSet::dump(), edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), h1, h2, h_, TFileDirectory::make(), ConfigurableAxis::Max(), ConfigurableAxis::Min(), name_, ConfigurableAxis::nBin(), prof, indexGen::title, type(), w_, x_, ConfigurableAxis::xBins(), and y_.

                                        {
    std::string title=conf_.getParameter<std::string>("title");
    edm::ParameterSet xAxisPSet=conf_.getParameter<edm::ParameterSet>("xAxis");
    ConfigurableAxis xAxis(xAxisPSet);
    x_=edm::Service<VariableHelperService>()->get().variable(xAxisPSet.getParameter<std::string>("var"));

    std::string yLabel="";    
    bool yVBin=false;
    ConfigurableAxis yAxis;
    if (conf_.exists("yAxis")){
      edm::ParameterSet yAxisPSet=conf_.getParameter<edm::ParameterSet>("yAxis");
      yAxis=ConfigurableAxis(yAxisPSet);
      yLabel=yAxis.Label();
      //at least TH2 or TProfile
      if (yAxisPSet.exists("var"))
        y_=edm::Service<VariableHelperService>()->get().variable(yAxisPSet.getParameter<std::string>("var"));
      yVBin=yAxis.variableSize();
    }
    
    if (conf_.exists("zAxis")){
      throw;
    }

    bool xVBin=xAxis.variableSize();


    if (type()==h1){
      //make TH1F
      if (xVBin)
        h_=dir->make<TH1F>(name_.c_str(),title.c_str(),
                           xAxis.nBin(), xAxis.xBins());
      else
        h_=dir->make<TH1F>(name_.c_str(),title.c_str(),
                           xAxis.nBin(),xAxis.Min(),xAxis.Max());
    }
    else if (type()==h2){
      //make TH2F
      if (xVBin){
        if (yVBin)
          h_=dir->make<TH2F>(name_.c_str(),title.c_str(),
                             xAxis.nBin(),xAxis.xBins(),
                             yAxis.nBin(),yAxis.xBins());
        else
          h_=dir->make<TH2F>(name_.c_str(),title.c_str(),
                             xAxis.nBin(),xAxis.xBins(),
                             yAxis.nBin(),yAxis.Min(),yAxis.Max());
      }else{
        if (yVBin)
          h_=dir->make<TH2F>(name_.c_str(),title.c_str(),
                             xAxis.nBin(),xAxis.Min(),xAxis.Max(),
                             yAxis.nBin(),yAxis.xBins());
        else
          h_=dir->make<TH2F>(name_.c_str(),title.c_str(),
                             xAxis.nBin(),xAxis.Min(),xAxis.Max(),
                             yAxis.nBin(),yAxis.Min(),yAxis.Max());
      }
    }
    else if (type()==prof){
      //make TProfile
      std::string pFopt="";
      if (conf_.exists("Option"))
        pFopt=conf_.getParameter<std::string>("Option");
      
      if (xVBin)
      h_=dir->make<TProfile>(name_.c_str(),title.c_str(),
                             xAxis.nBin(), xAxis.xBins(),
                             yAxis.Min(),yAxis.Max(),
                             pFopt.c_str());
      else
        h_=dir->make<TProfile>(name_.c_str(),title.c_str(),
                               xAxis.nBin(),xAxis.Min(),xAxis.Max(),
                               yAxis.Min(),yAxis.Max(),
                               pFopt.c_str());
      
    }
    else {
      edm::LogError("ConfigurableHisto")<<"cannot book: "<<name_<<"\n"<<conf_.dump();
      throw;
    }

    //cosmetics
    h_->GetXaxis()->SetTitle(xAxis.Label().c_str());
    h_->SetYTitle(yLabel.c_str());
    
    if (conf_.exists("weight"))
      {
        w_=edm::Service<VariableHelperService>()->get().variable(conf_.getParameter<std::string>("weight"));
      }
  }
virtual ConfigurableHisto* ConfigurableHisto::clone ( void  ) const [inline, virtual]

Reimplemented in SplittingConfigurableHisto.

Definition at line 61 of file ConfigurableHisto.h.

References ConfigurableHisto().

{ return new ConfigurableHisto(*this);}
void ConfigurableHisto::complete ( ) [inline]

Reimplemented in SplittingConfigurableHisto.

Definition at line 200 of file ConfigurableHisto.h.

{}
virtual void ConfigurableHisto::fill ( const edm::Event iEvent) [inline, virtual]

Reimplemented in SplittingConfigurableHisto.

Definition at line 153 of file ConfigurableHisto.h.

References CachingVariable::compute(), conf_, edm::ParameterSet::dump(), h1, h2, h_, iEvent, name_, prof, type_, w_, CommonMethods::weight(), x_, and y_.

                                            {
    if (!h_)      return;

    double weight=1.0;
    if (w_){
      if (w_->compute(iEvent))
        weight=(*w_)(iEvent);
      else{
        edm::LogInfo("ConfigurableHisto")<<"could not compute the weight for: "<<name_
                                         <<" with config:\n"<<conf_.dump()
                                         <<" default to 1.0";
      }
    }
    
    TProfile * pcast(0);
    TH2 * h2cast(0);
    switch(type_){
    case h1:
      if (!h_) throw;
      if (x_->compute(iEvent)) h_->Fill((*x_)(iEvent),weight);
      else{
        edm::LogInfo("ConfigurableHisto")<<"could not fill: "<<name_
                                         <<" with config:\n"<<conf_.dump();
      }
      break;
    case prof:
      pcast=dynamic_cast<TProfile*>(h_);
      if (!pcast) throw;
      if (x_->compute(iEvent) && y_->compute(iEvent)) pcast->Fill((*x_)(iEvent),(*y_)(iEvent),weight);
      else{
        edm::LogInfo("ConfigurableHisto")<<"could not fill: "<<name_
                                         <<" with config:\n"<<conf_.dump();
      }
      break;
    case h2:
      h2cast=dynamic_cast<TH2*>(h_);
      if (!h2cast) throw;
      if (x_->compute(iEvent) && y_->compute(iEvent)) h2cast->Fill((*x_)(iEvent),(*y_)(iEvent),weight);
      else{
        edm::LogInfo("ConfigurableHisto")<<"could not fill: "<<name_
                                         <<" with config:\n"<<conf_.dump();
      }
      break;
    }
  }
TH1* ConfigurableHisto::h ( ) [inline]

Definition at line 201 of file ConfigurableHisto.h.

References h_.

Referenced by SplittingConfigurableHisto::book(), and SplittingConfigurableHisto::complete().

{return h_;}
const HType& ConfigurableHisto::type ( ) [inline]

Definition at line 198 of file ConfigurableHisto.h.

References type_.

Referenced by book().

{ return type_;}  

Member Data Documentation

Definition at line 217 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

TH1* ConfigurableHisto::h_ [protected]

Definition at line 215 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), fill(), and h().

std::string ConfigurableHisto::name_ [protected]

Definition at line 214 of file ConfigurableHisto.h.

Referenced by ConfigurableHisto(), fill(), and type().

Definition at line 222 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

Definition at line 219 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

Definition at line 220 of file ConfigurableHisto.h.

Referenced by book(), ConfigurableHisto(), and fill().

Definition at line 221 of file ConfigurableHisto.h.

Referenced by ConfigurableHisto().