TH1->FillRandom() do not work

Dear you,

My ROOT version is: ROOT 5.28/00g (tags/v5-28-00g@40876, Sep 14 2011, 15:32:32 on win32) Debug

The TH1::void FillRandom(const char *fname, Int_t ntimes) do not work correctly when ‘fname’ is a TF1.

TF1 *f1 = new TF1("func1","1/sin(x)", 0, TMath::Pi()/2);
TH1F *hf1 = new TH1F("Rrand","T_rand", 1000, 0, 1.5);
hf1->FillRandom("func1",10000)

All of the entries in the result histogram ‘hf1’ is in the first bin, as showed in the following picture.



And the following code caused crash of ROOT, as showed in the next picture.

TF1 *f1 = new TF1("func1","1/sin(x)", 0, TMath::Pi()/2);
TH1F *hf1 = new TH1F("Rrand","T_rand", 10, 0, 10); //The bin size and axise range is deferent to the previous code
hf1->FillRandom("func1",10000)

It seems that the crash may be related to the ‘xaxise’ range and bin size of ‘hf1’.


Any help is appreciated!

Hi,

First thing I notice is that sin (0) = 0 and 1 / 0 is bad…

Cheers,
Charles

[quote=“cplager”]Hi,

First thing I notice is that sin (0) = 0 and 1 / 0 is bad…

Cheers,
Charles[/quote]

Dear cplager, thank you very much!
Just as your answer, that’s the problem.

Han