For some reasons, I have to use root under vista, insead of ubuntu 12.04.
I installed root and everything seems to be fine.
I have a two column .txt file(1st column x, 2nd column y) and I would like to plot y=f(x).
I used the relevant example from http://root.cern.ch/root/html/tutorials/tree/basic.C.html
My code is
[code]#include "Riostream.h"
void basic() {
// Read data from an ascii file and create a root file with an histogram and an ntuple.
// see a variant of this macro in basic2.C
//Author: Rene Brun
// read file $ROOTSYS/tutorials/tree/basic.dat
// this file has 3 columns of float data
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll(“basic.c”,"");
dir.ReplaceAll("/./","/");
ifstream in;
in.open(Form("%sout.txt",dir.Data()));
Float_t x,y;
Int_t nlines = 0;
TFile *f = new TFile(“basic.root”,“RECREATE”);
TH1F *h1 = new TH1F(“h1”,“x distribution”, 5000, 1, 5000);
TNtuple *ntuple = new TNtuple(“ntuple”,“data from ascii file”,“x:y”);
while (1) {
in >> x >> y;
if (!in.good()) break;
if (nlines < 5) printf(“x=%8f, y=%8f\n”,x);
h1->Fill(x,y);
ntuple->Fill(x,y);
nlines++;
}
printf(" found %d points\n",nlines);
in.close();
f->Write();
TCanvas *c = new TCanvas(“c”, “c”);
c->SetFillColor(4);
c->SetFrameFillColor(10);
}
[/code]
The previous macro is saved as basic.c and it’s run by using .x basic.c. My two column out.txt file is the following
500.00 1.98
550.00 2.13
600.00 2.27
650.00 2.42
700.00 2.57
800.00 2.88
900.00 3.19
1000 3.51
1100 3.84
1200 4.18
1300 4.53
1400 4.89
1500 5.26
1600 5.65
1700 6.04
1800 6.44
2000 7.27
2250 8.37
2500 9.53
2750 10.75
3000 12.04
3250 13.38
3500 14.78
3750 16.24
4000 17.76
4500 20.96
5000 24.38
The first weird thing is that there is no plot(although 27 points found). The y values on the first run are all 0
x=500.00, y=0.000000
x=550.00, y=0.000000
x=600.00, y=0.000000
x=650.00, y=0.000000
x=700.00, y=0.000000
found 27 pints
If I rerun the code again I always get a weird value on y and no plot again with a weird permission error.
SysError in <TFile::TFile>: could not delete basic.root(errno: 13)(Permission denied)
x=550.00, y=0.000000
x=600.00, y=3244368.000000
x=650.00, y=3244368.000000
x=700.00, y=3244368.000000
found 27 points
Warning in <TFile::Write>: file basic.root not opened in write mode
Any idea on what might be wrong?