RootTalk


ROOT Discussion Forums

GetBinCenter() in log

Discuss installing and running ROOT here. Please post bug reports here.

Moderator: rootdev

GetBinCenter() in log

Postby Zesp » Tue Mar 24, 2009 20:23

Hi there,
Below's a small improvement proposal to the TH1::GetBinCenter() method in order that it could also return the bin center in log.
Code: Select all
Double_t TH1::GetBinCenter (Int_t ibin, Bool_t log=kFALSE)
{
   Double_t lowEdge = this->GetXaxis()->GetBinLowEdge(ibin) ;
   Double_t upEdge  = this->GetXaxis()->GetBinUpEdge (ibin) ;
   if ( !log ) { return ( 0.5*(lowEdge+upEdge)        ) ; }
   else        { return ( TMath::Sqrt(lowEdge*upEdge) ) ; }
}

Cheers,
Z
User avatar
Zesp
 
Posts: 313
Joined: Tue Jul 27, 2004 22:08
Location: IPHC, Strasbourg, France

Postby brun » Wed Mar 25, 2009 9:01

A funny way to compute the log! Are you sure?
What happens if low is negative and up is positive?

Rene
User avatar
brun
 
Posts: 5823
Joined: Wed Aug 27, 2003 9:49
Location: CERN

Postby Zesp » Wed Mar 25, 2009 9:25

I may have badly expressed myself.
This of course only makes sense with gPad->SetLogx() and no negative values in xbins[].
With a log-equidistant binning, the mean is :
0.5*(ln E1 + ln E2) i.e. sqrt(E1*E2) in logx (e.g. sqrt(10^0*10^2) = 10).
Just a proposal...
User avatar
Zesp
 
Posts: 313
Joined: Tue Jul 27, 2004 22:08
Location: IPHC, Strasbourg, France

Postby brun » Wed Mar 25, 2009 9:48

If you want to convert a user coordinate to pad coordinate, simply do
Code: Select all
   pad.XtoPad(usercoordinate).
so if you have called pad.SetLogx, then
Code: Select all
   pad.XtoPad(h->GetXaxis()->GetBinCenter(bin))
will convert the center of the bin to the log coordinate

Rene
User avatar
brun
 
Posts: 5823
Joined: Wed Aug 27, 2003 9:49
Location: CERN

Postby Zesp » Sat Mar 28, 2009 14:56

This just returns TMath::Log10(x) and not the bin center in log.
Imagine a bin with xlow=1 and xup=100 :
- the center in lin is (100-1)/2=50.5
- the center in log would be sqrt(1*100)=10 (!=log(50.5))
This is very easy to compute. If this sounds useless, no problem. This was just a proposal.
User avatar
Zesp
 
Posts: 313
Joined: Tue Jul 27, 2004 22:08
Location: IPHC, Strasbourg, France

Postby brun » Sat Mar 28, 2009 20:20

I have implemented your suggestion as TAxis::GetBinCenterLog(bin), see:
http://root.cern.ch/root/html/TAxis.htm ... nCenterLog

Now in the SVN trunk.

Rene
User avatar
brun
 
Posts: 5823
Joined: Wed Aug 27, 2003 9:49
Location: CERN

Postby Zesp » Mon Mar 30, 2009 19:34

Thanks René !
User avatar
Zesp
 
Posts: 313
Joined: Tue Jul 27, 2004 22:08
Location: IPHC, Strasbourg, France

Re: GetBinCenter() in log

Postby Zesp » Mon Oct 08, 2012 9:33

Hi there,

Histogram statistics (mean value, "rms" and their corresponding errors) are computed using
Code: Select all
x = fXaxis.GetBinCenter(binx);
(see TH1::GetStats())

For log-equidistant binned histograms, it woul be proper to use
Code: Select all
x = fXaxis.GetBinCenterLog(binx);
(see above)

Could you please implement this?

Cheers,
Z
User avatar
Zesp
 
Posts: 313
Joined: Tue Jul 27, 2004 22:08
Location: IPHC, Strasbourg, France

Re: GetBinCenter() in log

Postby moneta » Wed Oct 10, 2012 17:26

Hi,

We are not supporting log-equidistant histograms, that can be built directly, so we cannot implement this.
Adding this feature would also add quite some complexity to the histogram classes.
If you want to do that from the beginning, why not filling directly the histogram with log(x) ?

Best Regards

Lorenzo
moneta
 
Posts: 1657
Joined: Fri Jun 03, 2005 14:38
Location: CERN

Re: GetBinCenter() in log

Postby Zesp » Sun Nov 04, 2012 23:50

Ok, thanks Lorenzo.

Just in case, attached's a script to compute the mean, rms, mean error and rms error of a log-equidistant histogram and display the corresponding (corrected) statbox.

Cheers,
Z
Attachments
ztest.cpp
(12.23 KiB) Downloaded 11 times
User avatar
Zesp
 
Posts: 313
Joined: Tue Jul 27, 2004 22:08
Location: IPHC, Strasbourg, France


Return to ROOT Support

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 4 guests