HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Histogram Style and Tools

HARPO style and histogram tools

The class MakeNiceHisto contains a number of tools to make "pretty" histograms. The list of functions can be seen in MakeNiceHisto.h

You can have access to these functions in the ROOT Command Line Interface by putting the following line in $HOME/.rootlogon.C:

{
  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);

  gSystem->Load("/your/path/to/libHarpoAnalysis.so");
  gROOT->LoadMacro("/your/path/to/base/MakeNiceHisto.h");
  gROOT->LoadMacro("/your/path/to/base/MakeNiceHisto.cxx");
}

The main function is MakeNiceHisto

TVirtualPad* MakeNiceHisto(TH1* hist, TVirtualPad* c1 = 0, const char* opt = "", Bool_t copy = 1);

It draws a histogram (1D or 2D), in a canvas, using the histogram style in SetHistStyle, and setting margins appropriately. By default, a copy of the histogram is drawn (copy = 1), so that the parameters cannot be altered afterwards. If you use copy = 0, modifications of the histogram will change the display.

For a TGraph object, the standard procedure would be to create a properly size histogram, use MakeNiceHisto, and then use Draw("same"). You can also use MakeNiceGraph, which will automatically set the size of the frame to the graphs extreme values.

TH1F* MakeNiceGraph(TGraph* hist, TVirtualPad* c1 = 0, const char* opt = "*");

There is a list of functions to create 1D or 2D histogram with a logarithmic bin size:

TH1F* HistLog(const char* name, const char* title, Int_t nBins, Double_t xMin, Double_t xMax);
TH2F* HistLogLog(const char* name, const char* title, Int_t nBinsX, Double_t xMinX, Double_t xMaxX, Int_t nBinsY, Double_t xMinY, Double_t xMaxY);
TH2F* HistLogLin(const char* name, const char* title, Int_t nBinsX, Double_t xMinX, Double_t xMaxX, Int_t nBinsY, Double_t xMinY, Double_t xMaxY);
TH2F* HistLinLog(const char* name, const char* title, Int_t nBinsX, Double_t xMinX, Double_t xMaxX, Int_t nBinsY, Double_t xMinY, Double_t xMaxY);
const Double_t *MakeLogBinning(Int_t nbins, Double_t xmin, Double_t xmax);

A few useful histogram operation are defined, with proper estimation of the errors:

Example

TH1F* h = new TH1F("h","",100,1,100);
TH1F* hLog = HistLog("hLog","",100,1,100);

for(Int_t i = 0; i<10000; i++){
  Double_t x = gRandom->Exp(10);
  h->Fill(x);
  hLog->Fill(x);
}


TCanvas* c = new TCanvas();
c->Divide(1,3);
ForceScale(h,1./10000);
NormaliseBins(h);
ForceScale(hLog,1./10000);
MakeNiceHisto(h,c->GetPad(1));
MakeNiceHisto(hLog,c->GetPad(2));
NormaliseBins(hLog);
MakeNiceHisto(hLog,c->GetPad(3));

c->GetPad(1)->SetLogx();
c->GetPad(2)->SetLogx();
c->GetPad(3)->SetLogx();