Dear co-rooters,
I am trying to create a TH2F from an ascii file that can be found [here] (https://cernbox.cern.ch/index.php/s/kXJg0T5CvxZlrsQ)
( 1st column = x_bin, 2nd column = y_bin, 3rd column = bin_content, 4th column = bin_content_uncertainty )
My code to create this histogram and fill is the following
#include "/afs/cern.ch/user/a/astamato/public/lib_thanos/c_header.h"
#include "/afs/cern.ch/user/a/astamato/public/lib_thanos/root_header.h"
void vasilis2root(){
//Define variables
int x_bins = 241, y_bins = 1000, n_bins = x_bins*y_bins;
double x_step = 0.05, y_step=0.1;
float x[x_bins], y[y_bins], n[n_bins], dn[n_bins];
float X, X_0, Y, Y_0, N, dN;
int bin;
X_0 = 0.;
Y_0 = 0.;
//Fill the arrays with values
for (int i=0; i<x_bins; i++){
x[i]=pow(10,-3.+i*x_step);
cout << i << ". x value = " << x[i] << endl;
}
y[0]=0.1;
for (int i=1; i<y_bins; i++){
y[i]=y[i-1]+y_step;
cout << i << ". y value = " << y[i] << endl;
}
//Read the ascii file that contains the data
std::ifstream file ("lambda.dat");
if(!file){
cout << "File doesn't exist" << endl;
}
int kk = 0;
while(!file.eof()){
file >> X >> Y >> N >> dN;
n[kk]=N;
dn[kk]=dN;
kk++;
//cout << i << ". N value = " << n[i] << " +/- " << dn[i] << endl;
}
TH2F *lambda = new TH2F("lambda", "Resolution Function", x_bins, x, y_bins, y);
/*for (int xx=1; xx<=lambda->GetNbinsX(); xx++){
for (int yy=1; yy<=lambda->GetNbinsY(); yy++){
bin = lambda->FindBin(xx,yy);
lambda->AddBinContent(bin, n[bin]);
}
}*/
lambda->Draw("colz");
}
When running this code and printing out the values of the arrays, everything seems to be in increasing order. However when trying to plot it, I get the following error
> 998. y value = 99.899
> 999. y value = 99.999
> Warning in <TROOT::Append>: Replacing existing TH1: lambda (Potential memory leak).
> Error in <TAxis::TAxis::Set>: bins must be in increasing order
> Error in <TAxis::TAxis::Set>: bins must be in increasing order
> Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
> Error in <TCanvas::Range>: illegal world coordinates range: x1=0.001125, y1=0.112375, x2=-0.000125, y2=-0.011375
> Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=0.001000, ymin=0.100000, xmax=0.000000, ymax=0.001000
> root [41] Error in <TCanvas::Range>: illegal world coordinates range: x1=0.001125, y1=0.112375, x2=-0.000125, y2=-0.011375
> Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=0.001000, ymin=0.100000, xmax=0.000000, ymax=0.001000
But I don’t seem to be able to understand why!
Any idea would be very helpful!
Thanks in advance!