Discussion:
[ROOT] TH2F stats Access
Adam Roe
2006-09-21 14:01:52 UTC
Permalink
Hi all (again),
I asked a question this morning, but i believe i phrased it wrong. I am trying to access the highest y-value in a data set which is in a histogram. Here is an explicit (trivial) example of what I am trying to do:

root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);
root [2] h2Test->SetBinContent(1,1,1);
root [3] h2Test->SetBinContent(3,5,2);
root [4] h2Test->SetBinContent(4,41,3);

And now i would like to call somethineg which returns 41, the maximum y value in h2Test. I would then use this to reset the yaxis range, so that this point is included.

I cannot find a way to get this value. The looping is rather large and complicated, so i am trying to avoid filling a vector with x-y coordinates and then fidning the maximum value in it.

This functionality is very simple for a TH1F. calling h1->GetMaximum() returns the highest y-value that is reached in h1. But i cannot get it to function for TH2F.

Thanks,
Adam
Rene Brun
2006-09-21 16:03:08 UTC
Permalink
The looping to do this should be extremely simple (3 C++ lines), but you
don't need to do this
for the goal that you want to achieve.
You should simply use the automatic binning facility of the
histogramming package.Instead of

root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);

do

root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 0, 10,0,0);

Rene Brun
Post by Adam Roe
Hi all (again),
root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);
root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);
root [2] h2Test->SetBinContent(1,1,1);
root [3] h2Test->SetBinContent(3,5,2);
root [4] h2Test->SetBinContent(4,41,3);
And now i would like to call somethineg which returns 41, the maximum y value in h2Test. I would then use this to reset the yaxis range, so that this point is included.
I cannot find a way to get this value. The looping is rather large and complicated, so i am trying to avoid filling a vector with x-y coordinates and then fidning the maximum value in it.
This functionality is very simple for a TH1F. calling h1->GetMaximum() returns the highest y-value that is reached in h1. But i cannot get it to function for TH2F.
Thanks,
Adam
Adam Roe
2006-09-22 08:00:58 UTC
Permalink
Hi,
This is what I got:
root [0] TH2F* h2Test = new TH2F("h2Test", "test of autoBin", 10, 0, 0, 10, 0,0);
root [1] h2Test->SetBinContent(7,12,2);
root [2] h2Test->SetBinContent(1,5,1);
root [3] h2Test->Draw();
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Error in <TCanvas::Range>: illegal world coordinates range: x1=0.000000, y1=0.000000, x2=0.000000, y2=0.000000
Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=0.000000, ymin=0.000000, xmax=0.000000, ymax=0.000000

The plot shown has 2 entires in the stats, but none are shown. the other stats all say 0 as well. If it makes a difference, I am using CERN linux, and the release of root that is built with a recent CMS software package, CMSSW_0_9_0_pre2

Thanks,
Adam


-----Original Message-----
From: Rene Brun
Sent: Thu 9/21/2006 6:03 PM
To: Adam Roe
Cc: roottalk (Mailing list discussing all aspects of the ROOT system)
Subject: Re: [ROOT] TH2F stats Access

The looping to do this should be extremely simple (3 C++ lines), but you
don't need to do this
for the goal that you want to achieve.
You should simply use the automatic binning facility of the
histogramming package.Instead of

root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);

do

root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 0, 10,0,0);

Rene Brun
Post by Adam Roe
Hi all (again),
root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);
root [1] TH2F* h2Test = new TH2F("h2Test", "test of yMax", 10, 0, 10, -5, 20);
root [2] h2Test->SetBinContent(1,1,1);
root [3] h2Test->SetBinContent(3,5,2);
root [4] h2Test->SetBinContent(4,41,3);
And now i would like to call somethineg which returns 41, the maximum y value in h2Test. I would then use this to reset the yaxis range, so that this point is included.
I cannot find a way to get this value. The looping is rather large and complicated, so i am trying to avoid filling a vector with x-y coordinates and then fidning the maximum value in it.
This functionality is very simple for a TH1F. calling h1->GetMaximum() returns the highest y-value that is reached in h1. But i cannot get it to function for TH2F.
Thanks,
Adam
Sophie Ferry
2006-09-25 13:26:41 UTC
Permalink
Hi
there is this comment in
double TRandom::Rndm(int)

Note that this is a generator which is known to have defects
(the lower random bits are correlated) and therefore should NOT be
used in any statistical study.

in this comment also true for :

TH2::GetRandom2(double&, double&)

thanks
Sophie
Rene Brun
2006-09-25 13:56:08 UTC
Permalink
Sophie,

TH2::GetRandom2 uses the current random number generator. By default the
current
generator is TRandom3, ie a very good generator.

Rene Brun
Post by Sophie Ferry
Hi
there is this comment in
double TRandom::Rndm(int)
Note that this is a generator which is known to have defects
(the lower random bits are correlated) and therefore should NOT be
used in any statistical study.
TH2::GetRandom2(double&, double&)
thanks
Sophie
Hengtong Ding
2006-09-25 15:16:56 UTC
Permalink
Hi Sophie,
You can use the better one Double_t TRandom3::Rndm(Int_t),

but for the random numbers sampling from two dimension histograms,

anyone knows a better way to avoid the defects Sophie mentioned?

cheers,
hengtong
Post by Sophie Ferry
Hi
there is this comment in
double TRandom::Rndm(int)
Note that this is a generator which is known to have defects
(the lower random bits are correlated) and therefore should NOT be
used in any statistical study.
TH2::GetRandom2(double&, double&)
thanks
Sophie
--
************************************************
* Hengtong Ding *
* *
* Address: Institute of Particle Physics, *
* Central China Normal University *
* Wuhan, 430079, P. R. China *
* Tel: 0086 27 6786 7946 (lab) *
* 0086 27 8715 0351 (dormitory) *
* Fax: 0086 27 6786 3213 *
* Email: ***@iopp.ccnu.edu.cn *
* ***@hotmail.com *
************************************************
Rene Brun
2006-09-26 10:04:47 UTC
Permalink
Hi Sophie,

Let me repeat, you do not have to use TRandom2::Rndm. TH2::GetRandom2 will
automatically call the default generator (ie TRandom3). Just call
GetRandom2.

Rene Brun
Post by Hengtong Ding
Hi Sophie,
You can use the better one Double_t TRandom3::Rndm(Int_t),
but for the random numbers sampling from two dimension histograms,
anyone knows a better way to avoid the defects Sophie mentioned?
cheers,
hengtong
Post by Sophie Ferry
Hi
there is this comment in
double TRandom::Rndm(int)
Note that this is a generator which is known to have defects
(the lower random bits are correlated) and therefore should NOT be
used in any statistical study.
TH2::GetRandom2(double&, double&)
thanks
Sophie
Hengtong Ding
2006-09-26 11:02:52 UTC
Permalink
Hi Rene,

Thanks for your pointing out!

best regards,
hengtong
Post by Hengtong Ding
Hi Sophie,
Let me repeat, you do not have to use TRandom2::Rndm. TH2::GetRandom2 will
automatically call the default generator (ie TRandom3). Just call
GetRandom2.
Rene Brun
Post by Hengtong Ding
Hi Sophie,
You can use the better one Double_t TRandom3::Rndm(Int_t),
but for the random numbers sampling from two dimension histograms,
anyone knows a better way to avoid the defects Sophie mentioned?
cheers,
hengtong
Post by Sophie Ferry
Hi
there is this comment in
double TRandom::Rndm(int)
Note that this is a generator which is known to have defects
(the lower random bits are correlated) and therefore should NOT be
used in any statistical study.
TH2::GetRandom2(double&, double&)
thanks
Sophie
Loading...