Re: TH2 Random generation

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Thu, 8 Apr 2010 09:44:05 +0200


Hi,

You can project the TH2 in a TH1 at the fixed x value and then get y as a random number from the TH1. For example, if h2 is a TH2 histogram and x0 is your fixed x value you can do:

int x0bin = h2->GetXaxis()->FindBin(x0); TH1 * h1 = h2->ProjectionY("h1", x0bin, x0bin); double y = h1->GetRandom();

 Best Regards

Lorenzo
On Apr 7, 2010, at 4:08 PM, Manuel Mussini wrote:

> Hi,
> is there any way to generate random numbers from a TH2 at a fixed x value?
> I mean ... I have a TH2, I have an x value and I need to generate a random y value following the TH2 shape in the fixed "vertical" section!
>
> Any suggestion?
>
> Thanks!
>
>
>
> Bye...
Received on Thu Apr 08 2010 - 09:44:09 CEST

This archive was generated by hypermail 2.2.0 : Thu Apr 08 2010 - 11:50:02 CEST