Getting doubled values on TH1D (Root 6)

Hi everybody, i’m just starting with Root and i’m trying to fill a 1D histogram with x and y values. I’m using Fill(x,y) to set the values, but when i draw the histogram i get values on the y that seem doubled. What am i doing wrong?
I think that the lines that i see are related to the fit. I would like to have the data and also the fit curve, nothing else.

This is the code (it’s a very simple program :unamused: ):

void decade(Int_t n0, Double_t alfa, Double_t time_bin, Double_t T) {
    Int_t size=1+(T/time_bin);
    Int_t ndec;
    TCanvas *c = new TCanvas("c", "Canvas", 500, 500);
    TH1D *h = new TH1D("h","Istogramma",size,0.,T);
    for (Int_t t=0; t<=T; t=t+time_bin) {
        ndec=0;
        for(Int_t n=0; n<n0; n++) {
            if((gRandom->Rndm())<(alfa*time_bin)) {
                ndec++;
            }
        }
        n0=n0-ndec;
        h->Fill((t+time_bin/2),n0);
    }
    h->Fit("expo");
    gStyle->SetOptFit(1112);
    h->Draw();
}

And thanks to everybody for your help :slight_smile:

Fill does not “set” the value of a bin it cumulate the weight you pass as second parameter in the tain touched by the first parameter. The t+time_bin/2 must hit several time the same bin.

Thanks for your reply.
Is there a way to reset it? I mean, i want that at the x coordinate the histo shows the y that i pass. If Fill(x,y) cumulates the weights, how can i just tell the histo to show the y value that i pass?

Use:

root.cern/doc/master/classTH1.h … 0aaf638ee6

Instead …