Re: How to get value from histogram ?

From: Eduard Avetisyan <Eduard.Avetisyan_at_desy.de>
Date: Thu, 11 Aug 2011 18:01:02 +0200

Hello L.H.,

By calling "final->GetBinContent(0)" you assing the value stored in the _underflow bin_ of your histogram to your highestvalue variable (the underflow bin stores all the data that has been below the lowest limit, in your case -3.). Since all your data was well confined between your limits, the underflow bin was empty, hence your variable has 0 value.

(If I got your problem right) you may obtain the highest value stored by calling final->GetMaximumStored() , or
final->GetBinContent(final->GetMaximumBin()) , that should be equivalent.

Cheers

        Eduard

On Thu, 11 Aug 2011, Le Hoang Nguyen wrote:

> Hello
>
> I am new to Root and I am having some problem in taking data from histogram
> e.g :
>
> void getrandomh() {
> > TH1F *source = new TH1F("source","source hist",100,-3,3);
> > source->FillRandom("gaus",1000);
> > TH1F *final = new TH1F("final","final hist",100,-3,3);
> > for (Int_t i=0;i<1000000;i++) {
> > final->Fill(source->GetRandom());
> > }
> > double highestvalue;
>
>
> > highestvalue = final->GetBinContent(0);
> > std::cout << highestvalue << std::endl;
>
>
> > TCanvas *c1 = new TCanvas("c1","c1",800,1000);
> > c1->Divide(1,2);
> > c1->cd(1);
> > source->Draw();
> > c1->cd(2);
> > final->Draw();
> > c1->cd();
> > }
> >
>
> So what I need is the exported value is about ~20000 but the result is just
> zero ?
> So would you please point out what is my problem here ? What should I use
> for a right result ?
>
> With regards
>
> L.H.
>
Received on Thu Aug 11 2011 - 18:01:11 CEST

This archive was generated by hypermail 2.2.0 : Thu Aug 11 2011 - 23:50:01 CEST