# FillRandom in Root 6.08

Hello

I am having a problem with the peaks.C function from the tutorial.
It seems that h->FillRandom(âfâ,20000) does not work with Root 6.08/04.

``````#include "TCanvas.h"
#include "TMath.h"
#include "TH1.h"
#include "TF1.h"
#include "TRandom.h"
#include "TSpectrum.h"
#include "TVirtualFitter.h"
Int_t npeaks = 30;
Double_t fpeaks(Double_t *x, Double_t *par) {
Double_t result = par[0] + par[1]*x[0];
for (Int_t p=0;p<npeaks;p++) {
Double_t norm  = par[3*p+2];
Double_t mean  = par[3*p+3];
Double_t sigma = par[3*p+4];
result += norm*TMath::Gaus(x[0],mean,sigma);
}
return result;
}
void peaks(Int_t np=10) {
npeaks = TMath::Abs(np);
TH1F *h = new TH1F("h","test",500,0,1000);
//generate n peaks at random
Double_t par[3000];
par[0] = 0.8;
par[1] = -0.6/1000;
Int_t p;
for (p=0;p<npeaks;p++) {
par[3*p+2] = 1.;
par[3*p+3] = 10.+gRandom->Rndm()*980.;
par[3*p+4] = 3.+2.*gRandom->Rndm();
}

TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks);
f->SetNpx(1000);
f->SetParameters(par);
f->Draw();
h->FillRandom("f",200000);
h->Draw();
h->Print("All");
``````

gives zero content for the bins, although the TF1 âfâ function contains peaks.

The script works in version 5.34/30

Thank You,

B. Roessli

It works for me on ROOT 6.09.02.

Worked for me on ROOT 6.08/06 (with the addition of the missing curly bracket at the end).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.