Draw a rebinned histogramm from ascii2root2TTree

Hello co-rooters!

I would like to divide to histograms that don’t have the same binning(an experimental and an evaluated one)
To do that, I take the evaluated one, which in principle has a finer binning, in ascii format, convert it to a root file and then rebin it in a coarser binning.

My code that converts the ascii file to root file is the following

TFile *f = new TFile(“refXS_tot.root”,“NEW”);

//~~~~~~~~~~~~~~~~~~~~~ 235U ~~~~~~~~~~~~~~~~~~~~~~// 
TTree *TU = new TTree("U235_ENDFtot","data from ascii file");
Long64_t nlines = TU->ReadFile("U5_cross_section_eV.txt","E:XS");
printf("Found %lld points\n",nlines);

int n = TU->Draw("E:XS");
TGraph *g = new TGraph(nlines,TU->GetV1(),TU->GetV2());



The code that reads the previously created root file and “tries” to plot a rebinned version of it is the following


TFile *MyFile = new TFile("refXS_tot.root","READ");//Open the root file
if ( MyFile->IsOpen() ) printf("File opened successfully\n");//Check if file is opened
TTree *XSTree  = (TTree*)MyFile.Get("U235_ENDFtot");//Get the XS tree
//Define the branches
Float_t E;
Float_t XS;
// Get number of entries
Int_t entries = XSTree->GetEntries();
printf(" Number of entries: %d\n",entries);

// Create neutron energy binning - same as the experimental yield
Int_t     N_BPDEC = 2000;// bins per decade
Int_t     E_MIN = -3;// lower energy limit (log10)
Int_t     E_MAX = 8;// upper energy limit (log10)
Int_t     ndec = E_MAX - E_MIN;//total energy range (log 10)
Int_t     nbins = (Int_t) ndec*N_BPDEC;//total numer of bins
Double_t  ebins[nbins+1];
Double_t  step = (Double_t) ndec / nbins;

for(Int_t i=0; i <= nbins; i++) {
  ebins[i] = (float) pow(10., step * (Double_t) i + E_MIN);

//X-Section Histogram
TH1F *hXSU5 = new TH1F("hXSU5","^{235}U Evaluated Cross Section - Rebinned; Neutron energy (eV); Cross Section (barns)",nbins,ebins);
for (int i=0; i<=entries; i++){//Fill the histogram


The problem is that although both codes run without any error whatsoever, the printed histogram that I get is empty, despite having the correct number of entries.

Any idea on why I can’t draw the histogram?
Thank you very much in advance!

for (int i=0; i<=entries; i++){ XSTree->GetEntry(i); // read E and XS hXSU5->Fill(E,XS); // fill the histogram }

Thank you very much for your help!

My output is the following

Any idea on why does it have discontinuity?
Does it have to do with the binning?

The “correct” unbinned looks like that

Your “unbinned” is a TGraph, while the “rebinned” is a TH1F (and apparently your x-bins do not correspond 1:1 to your data points, so some bins are not filled at all and some another are filled multiple times).

You are absolutely right, but that was the plan : To change the binning of the “unbinned” in order to fit with the experimental binning.

To draw a graph instead of a histogram, I used the following code

double *x=new double[hXSU5->GetNbinsX()]; double *y=new double[hXSU5->GetNbinsX()]; int N=0; for (int i=0; i<hXSU5->GetNbinsX(); i++){ x[N] = hXSU5-> GetBinCenter(i+1); y[N] = hXSU5-> GetBinContent(i+1); N++; } TGraph *XSection = new TGraph(N,x,y); XSection->Draw("al");

but again there are those discontinuities…