Histogramme filling

Dear all,

I have been using the same macro to built my histogrammes for months, obtaining relevant and consistent results all the time. It seems to fail now, though.
The file structure is the same one I have been using from the beginning: it contains energies (one per line) and I want a histogramme plotting the energy distribution of my file. But I seem to obtain two superimposed gaussian-like curves in my file, I really do not get why.

Here is a copy of my code, with the file I want to use.

TCanvas *fenetre = new TCanvas("Angle 121", "Etude Angle", 700 , 500) ;
//fenetre->SetLogy();
fenetre->Draw ("C");

gStyle->SetOptStat (1); // Axis normalisation
ifstream histo("data_voie1.txt", ios::in); // name of the file containing the experimental datas
TH1* h1 = new TH1F("Histo1","", 40000, 0, 10000);
int i=0; // counts the number of datas
cout << "ready to enter the loop" << endl;
    while (!histo.eof()){
    i+=1;
    int x;
    histo>>x;
    h1->Fill(x,i); // fill the bin i with the number x of counts
    //cout << x << "  " << i<<  endl;
    } 
cout << " loop done " << endl;
histo.close();
int group_bins=1; // Groups the bins
//int N= 500000; // Number of datas in the histogram
//int Nbins = N/group_bins; // Number of bins
h1->Rebin(group_bins); // Histogram done with the new number of bins

// Axis parametrization
h1->SetTitle("Histogramme Energy Si1 wheel 0, no coincidence");
h1->GetXaxis ()->SetTitle ("Energy");
h1->GetYaxis ()->SetTitle ("Ncounts");

cout << "Histogram done" << endl;
h1->Draw("C");
h1->Draw();

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


data_voie1.txt (606.2 KB)

If anyone can help me with this it would be very helpful ! thanks a lot !

The code you provided gives a different format. Anyway, if you zoom in, those “2 curves” are coming from the data, not from the plot, so something’s going on with your data or your data file.

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