Cannot open file: TGraphErrors is Zombie

I’m completely new to Root and also to C++ coding. I’m going through the Root Primer and am trying to do the example in 2.5 for plotting measurements, which uses a file called “ExampleData.txt”, however I am getting an error when I try to execute the code. I have the file in the same folder as Root (as instructed).

Here is the code:
TGraphErrors gr(“ExampleData.txt”);

Here is the error:
Error in TGraphErrors::TGraphErrors: Cannot open file: ExampleData.txt, TGraphErrors is Zombie

As I said I am completely new to this, so thank you in advance for the help and patience.

Hi @mike.z,
That is probably because you don’t have ExampleData.txt file in the same directory where you are running ROOT prompt. You can download the data at https://github.com/root-project/NotebookPrimer/tree/master/data, then try to replicate the example. Let me know should you have any more questions.
Best,
Vincenzo

1 Like

Thank you for the response @vpadulan

I have the file in my root/bin directory. I think that is where root is running from. I source thisroot.sh from that directory. Maybe it is not the right one?

Hi @mike.z,
So I tried to reproduce your example from top to bottom.

I will then assume that you have a folder structure similar to the following

myfolder/
    ExampleData.txt
    root/
    build/
        ...
        bin/
            ...
            thisroot.sh

Since this would be the common/suggested way of having a local ROOT build on your machine (see here for reference).
Then, typying source myfolder/build/bin/thisroot.sh will setup your current environment with ROOT.
Now, while being inside myfolder, I type root to open the ROOT prompt. At the prompt, I type the following lines:

root [0] TGraphErrors gr("ExampleData.txt");
root [1] gr.Draw();
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1

And I correctly see the graph displayed. Tell me if you see anything wrong .
Best,
Vincenzo

ROOT Version: 6.16
Platform: CentOS

Please note that the “ExampleData.txt” file must be in your “current working directory”, NOT in the “${ROOTSYS}/bin” directory.

1 Like

Thank you @Wile_E_Coyote and @vpadulan

I got it to work by following your instructions. My folder structure like this: Home/ROOT/root/bin/thisroot.sh

I didn’t understand what “working folder” meant, and thought it referred to the /bin folder with thisroot.sh. When I put the file in my Home folder then the graph loaded properly.

Thank you again for the help and patience.

1 Like