To fill a histogram by reading text file

it seems your file chiffres.txt is not available in the current directory…
‘Cannot open file ./chiffres,txt’…

where should be put ??

Next to the macro Macro2.C … in the same directory.
That’s what I did and, as you can see, your macro works for me.

Yeah , still the same problem :confused:

When you are in ROOT, after having executed you macro, can you enter exactly the following command et send me the output ?

.! ls chiffres.txt

in my case I get:

$ root
   ----------------------------------------------------------------
  | Welcome to ROOT 6.09/03                    http://root.cern.ch |
  |                                   (c) 1995-2017, The ROOT Team |
  | Built for macosx64                                             |
  | From heads/master@v6-09-02-487-ga8ffe35, Apr 18 2017, 09:47:08 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
   ----------------------------------------------------------------

root [0] .x Macro2.C
x[0]=1, y[0]=6, ex[0]=0, ey[0]=5
x[1]=2, y[1]=12, ex[1]=0, ey[1]=5
x[2]=3, y[2]=14, ex[2]=0, ey[2]=4.7
x[3]=4, y[3]=20, ex[3]=0, ey[3]=4.5
x[4]=5, y[4]=22, ex[4]=0, ey[4]=4.2
x[5]=6, y[5]=24, ex[5]=0, ey[5]=5.1
x[6]=7, y[6]=35, ex[6]=0, ey[6]=2.9
x[7]=8, y[7]=45, ex[7]=0, ey[7]=4.1
x[8]=9, y[8]=44, ex[8]=0, ey[8]=4.8
x[9]=10, y[9]=53, ex[9]=0, ey[9]=5.43
(int) 0
root [1] .! ls chiffres.txt
chiffres.txt
root [2] 

Can you do:

.! ls

? that will show how your txt file is really named. It could be that it looks correctly named in the finder but in fact it is not …

I see… you current directory is not the directory macros… two solutions:

  1. ‘cd’ to the macros directory before running ROOT
  2. specify the full path name of your txt file hone you open it in your macro.

Try:

TString file = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
file.ReplaceAll("Macro2.C", "chiffres.txt");
TGraphErrors graph_expected(file, "%lg %lg %lg");

or:

TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
TGraphErrors graph_expected(dir + "/chiffres.txt", "%lg %lg %lg");

You can do what Wile suggested or:

$ cd /Applications/root_v6.08.06/macros
$ root

or copy the file Macro2.c and chiffres.txt in some working sub-directory (rootlets for instance) in your home directory;

$ cd ~
$ mkdir roottest
$ cd roottest
$ cp /Applications/root_v6.08.06/macros/Macro2.C .
$ cp /Applications/root_v6.08.06/macros/chiffres.txt .
$ /Applications/root_v6.08.06/bin/root
...
root[0] .x Macro2.C

I would also recommend that you add /Applications/root_v6.08.06/bin in you PATH system variable. Having done it you will need to type only root to start it .

you should not put a slash in your 2nd ‘cd’ command…

Ok … so, you solved your problem ?

Nope, the same problem occurred :confused: