I am trying to create a histogram from an ascii file. My simple macro to do it, is
[code] #include “Riostream.h”
void HistoFromAscii(){
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0000);
gStyle->SetOptFit(1111);
gStyle->SetOptTitle(0);
TCanvas *c = new TCanvas("c", "c");
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("HistoFromAscii.C","");
dir.ReplaceAll("/./","/");
ifstream in;
in.open(Form("%sC6D62_e1405_m1.txt",dir.Data()));
Float_t x,y;
Int_t nlines = 0;
Int_t channels=3075;
//TH1F *h1 = new TH1F("h1","Total",channels,1,channels);//<--- This constractor is OK
TH1F *h1 = new TH1F();//<--- This constractor creates a weird histogram
while (1) {
in >> x >> y;
if (!in.good()) break;
if (nlines < 5) printf("x=%8f, y=%8f, nlines=%d\n",x,y,nlines);
h1->Fill(nlines,y);
nlines++;
}
printf("Found %d points\n",nlines);
in.close();
h1->SetLineColor(kRed);
h1->Draw();
//cout << "nlines = " << nlines << endl;
//h1->GetXaxis()->SetRangeUser(1,nlines);
}[/code]
My ascii file is the following http://pastebin.com/0C7vyupb
When I use the constractor
TH1F *h1 = new TH1F("h1","Total",channels,1,channels);
I get the correct output which is something like that
If I use the constractor
TH1F *h1 = new TH1F();
I get the following histogram
which actually represents only the first bin. I tried to change the range, just in case, but this doesn’t seem to be the problem.
I think that the second constractor is the best, because the number of the total bins is not always the same. Any idea on what is going on? Does anyone know haw can this be solved?
Thank you very much in advance!
Note that I am running root while in an lxplus session.