CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

Overlayer Class Reference

#include <Overlayer.h>

List of all members.

Public Member Functions

Overlayerclear ()
Overlayerfind (std::string)
OverlayerlegendLeft (bool state=true)
Overlayerlogy (bool state=true)
 Overlayer (std::string filename, std::string datadir, std::string simdir, Color_t color)
void print (std::string)
OverlayerwithLegend (bool state=true)
Overlayerxlabel (std::string s)
Overlayerylabel (std::string s)

Private Member Functions

std::string getStats (const TH1 *const) const

Private Attributes

const Color_t color_
TH1 * data_
const std::string dataLocation_
TFile *const file_
std::string histName_
bool left_
TLegend * legend_
bool logy_
TH1 * sim_
const std::string simLocation_
std::string title_
std::string xlabel_
std::string ylabel_

Detailed Description

Definition at line 12 of file Overlayer.h.


Constructor & Destructor Documentation

Overlayer::Overlayer ( std::string  filename,
std::string  datadir,
std::string  simdir,
Color_t  color 
) [inline]

Definition at line 15 of file Overlayer.h.

References clear().

  : file_(new TFile(filename.c_str(),"READ")),
    dataLocation_(datadir),
    simLocation_(simdir),
    color_(color)
{ clear(); }


Member Function Documentation

Overlayer & Overlayer::clear ( void  )

Definition at line 43 of file Overlayer.h.

References gather_cfg::cout, data_, histName_, left_, legend_, logy_, sim_, title_, xlabel_, and ylabel_.

Referenced by Overlayer().

        {
  std::cout << "clear" << std::endl;
  data_=sim_=0;
  xlabel_=ylabel_=histName_=title_="";
  logy_=false;
  legend_=0;
  left_=false;
  return *this;
}
Overlayer & Overlayer::find ( std::string  name)

Definition at line 54 of file Overlayer.h.

References gather_cfg::cout, data_, dataLocation_, file_, histName_, mergeVDriftHistosByStation::name, sim_, and simLocation_.

                     {
  std::cout << "find " << name << "\t" << std::flush;
  histName_=name; 
  data_ = (TH1*) file_->GetDirectory(dataLocation_.c_str())->FindObjectAny(name.c_str());
  sim_ = (TH1*) file_->GetDirectory(simLocation_.c_str())->FindObjectAny(name.c_str());
  return *this;
}
std::string Overlayer::getStats ( const TH1 * const  hist) const [private]

Definition at line 81 of file Overlayer.h.

Referenced by withLegend().

                                      {
  stringstream ss;
  ss << "N: " << hist->GetEntries() << ", "
     << "#mu: " << round_string()(std::make_pair(hist->GetMean(),hist->GetMeanError())) << ", "
     << "#sigma: " << round_string()(std::make_pair(hist->GetRMS(),hist->GetRMSError()));
  return ss.str().c_str();
}
Overlayer& Overlayer::legendLeft ( bool  state = true) [inline]

Definition at line 28 of file Overlayer.h.

:
  std::string getStats(const TH1* const) const;
Overlayer& Overlayer::logy ( bool  state = true) [inline]

Definition at line 26 of file Overlayer.h.

{ left_=state; return *this;}
void Overlayer::print ( std::string  suffix)

Definition at line 90 of file Overlayer.h.

References trackerHits::c, color_, gather_cfg::cout, data_, histName_, legend_, logy_, max(), sim_, title_, xlabel_, and ylabel_.

                        {
  std::cout << "print\t" << std::flush;

  sim_->GetXaxis()->SetLabelSize(0.05);  sim_->GetXaxis()->SetTitleSize(0.05);
  sim_->GetYaxis()->SetLabelSize(0.05);  sim_->GetYaxis()->SetTitleSize(0.05);
  sim_->SetTitle((title_+";"+xlabel_+";"+ylabel_).c_str());
  sim_->Scale(data_->Integral()/sim_->Integral());  
  sim_->SetMinimum( (logy_?0.1:0) );
  sim_->SetMaximum( (logy_?2:1.1) * std::max( sim_->GetBinContent(sim_->GetMaximumBin()) + sim_->GetBinError(sim_->GetMaximumBin()) ,
                                              data_->GetBinContent(data_->GetMaximumBin()) + data_->GetBinError(data_->GetMaximumBin()) ) );

  sim_->SetFillColor(color_);
  TH1* sim_errors = (TH1*) sim_->Clone((histName_+"_clone").c_str());
  sim_->SetLineColor(kRed);
  sim_errors->SetFillColor(kRed);
  sim_errors->SetFillStyle(3244);
  data_->SetMarkerStyle(20);
  
  TCanvas c("c","",800,600);
  if(logy_) c.SetLogy();

  sim_->Draw("hist");
  sim_errors->Draw("e2same");
  data_->Draw("same");
  if(legend_) legend_->Draw();

  c.Print((histName_+suffix).c_str());  
}
Overlayer & Overlayer::withLegend ( bool  state = true)

Definition at line 62 of file Overlayer.h.

References gather_cfg::cout, data_, dataLocation_, getStats(), left_, legend_, max(), sim_, simLocation_, and AlCaHLTBitMon_QueryRunRegistry::string.

                                           {
  std::cout << "legend: " << (state?"true\t":"false\t") << std::flush;
  if(!state) {legend_=0; return *this;}
  
  std::string data_stats = getStats(data_);
  std::string sim_stats = getStats(sim_);
  unsigned maxlength = std::max( std::max( dataLocation_.size(), simLocation_.size()), 
                                 std::max( data_stats.size(), sim_stats.size()) );

  if(left_) legend_ = new TLegend(0,0.75,maxlength*0.015,1.0);
  else legend_ = new TLegend(1.0-maxlength*0.015,0.75,1.0,1.0); 

  legend_->SetFillColor(kWhite);
  legend_->AddEntry(data_,("#splitline{"+dataLocation_+"}{"+ data_stats + "}").c_str() );
  legend_->AddEntry(sim_,("#splitline{"+simLocation_+"}{"+ sim_stats + "}").c_str() );
  return *this;
}
Overlayer& Overlayer::xlabel ( std::string  s) [inline]

Definition at line 24 of file Overlayer.h.

References alignCSCRings::s, and ylabel_.

{ ylabel_=s; return *this;}
Overlayer& Overlayer::ylabel ( std::string  s) [inline]

Definition at line 25 of file Overlayer.h.

References logy_, and evf::utils::state.

{ logy_=state; return *this;}

Member Data Documentation

const Color_t Overlayer::color_ [private]

Definition at line 35 of file Overlayer.h.

Referenced by print().

TH1* Overlayer::data_ [private]

Definition at line 37 of file Overlayer.h.

Referenced by clear(), find(), print(), and withLegend().

const std::string Overlayer::dataLocation_ [private]

Definition at line 34 of file Overlayer.h.

Referenced by find(), and withLegend().

TFile* const Overlayer::file_ [private]

Definition at line 33 of file Overlayer.h.

Referenced by find().

std::string Overlayer::histName_ [private]

Definition at line 36 of file Overlayer.h.

Referenced by clear(), find(), and print().

bool Overlayer::left_ [private]

Definition at line 39 of file Overlayer.h.

Referenced by clear(), and withLegend().

TLegend* Overlayer::legend_ [private]

Definition at line 40 of file Overlayer.h.

Referenced by clear(), print(), and withLegend().

bool Overlayer::logy_ [private]

Definition at line 39 of file Overlayer.h.

Referenced by clear(), print(), and ylabel().

TH1* Overlayer::sim_ [private]

Definition at line 38 of file Overlayer.h.

Referenced by clear(), find(), print(), and withLegend().

const std::string Overlayer::simLocation_ [private]

Definition at line 34 of file Overlayer.h.

Referenced by find(), and withLegend().

std::string Overlayer::title_ [private]

Definition at line 36 of file Overlayer.h.

Referenced by clear(), and print().

std::string Overlayer::xlabel_ [private]

Definition at line 36 of file Overlayer.h.

Referenced by clear(), and print().

std::string Overlayer::ylabel_ [private]

Definition at line 36 of file Overlayer.h.

Referenced by clear(), print(), and xlabel().