Optimizing and obtaining data from histograms

Dear ROOT users,
I have come across several problems with histograms. I use TH1 class.
Firstly, I would like to obtain the number of overflow and underflow bins. This property can be listed in the statistics box (TPaveStats). I can get all the other variables such as RMS:

    rms = histogram1->GetRMS();

Secondly, I have problems to change properties of each statistics box individually. I defined:

   c1->TPad::Divide(2,2);

For instance, I Would like to change the position of the statistics box at the TPad number 3 without affecting the others.

Finally, is it possible to plot grid on a specific pad?
This does not seem working:

   TCanvas *c1 = new TCanvas("c1","Analysis");
   c1->TPad::Divide(2,2);
   c1->TPad::cd(1);
   c1->SetGrid();

Thank you for your help.

Hi,

For each histogram, there is only one underflow and one overflow bin. They may or may not be empty. If you want the number in the stat box, you can do something like

printf("Underflow: %f, overflow: %f\n", h1->GetBinContent(0), h1->GetBinContent(h1->GetNbinsX() + 1));

See the example below.

Sure, here is the example, which incorporates all the features:

        c1 = new TCanvas("c1");
        c1->Divide(1, 2);
        TPad* c1_1=(TPad*)(c1->GetPrimitive("c1_1"));
        c1_1->cd();

        h1=new TH1F("h1","",100,0.,1.);
        h1->Fill(0.2);
        h1->Draw();

        TPad* c1_2=(TPad*)(c1->GetPrimitive("c1_2"));
        c1_2->cd();
        h2=new TH1F("h2","",100,0.,1.);
        h2->Fill(0.8);
        printf("Underflow: %f, overflow: %f\n", h2->GetBinContent(0), h2->GetBinContent(h2->GetNbinsX() + 1));
        h2->Draw();
        gPad->Update();

        TPaveStats *stats = (TPaveStats*)c1_2->GetPrimitive("stats");//obtaining the stat box from the second pad
        stats->SetName("h2stats");
        stats->SetX1NDC(0.5);//shifting the stat box to the left
        stats->SetX2NDC(0.7);
        c1_2->SetGrid(kTRUE);

        gPad->Update(); gPad->Modified();

HTH!

Thank you yus. It works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.