Problem opening .dat file

So this is my first time using Root. I’ve installed everything and my professor gave me a script (.cpp) and a data file (.dat) just to test whether everything works fine.

I know there are no problems in neither of the files because they are working fine for the rest of my classmates. To keep it short, it reads all the data from the .dat file, builds a histogram and tries to fit it to a Poisson distribution.

However, whenever I run it I get the error “Warning in : Fit data is empty”. I think the problem happens when opening the file, because I added the following code after the open file instruction_

FILE *f= fopen(filename.c_str(),"r");

if(f)
  {
      printf("Opened successfully \n");
  }
  else{
      printf("Couldn't open the file \n");
  }

and I always get the “Couldn’t open the file” text.

I reinstalled everything twice by following the steps and I’m clueless. The professor is too (he is no expert on the matter sigh).

Any help will be appreciated!

Additional info:
_ROOT Version: 6.28/06
_Platform: Windows 10
_Compiler: Visual Studio 2022 17.7.4


Well, we need more information. What is the value of filename? are you sure it is in the same directory than where you run your script? How and where are you starting ROOT?

Hi bellenot, thank you for answering!

The value of filename:

string filename = "fondo.dat";

Both files “fondo.dat” and “poisson.cpp” are in the same directory (C:\root_v6.28.06\macros\Templates_GM).

I’m not entirely sure about what you’re asking with the last question. Let me describe how I’m starting root:

  1. Open x64 Native Tools Command Prompt for VS 2022 as Administrator.
  2. Execute the following commands: cd %USERPROFILE% and then %C:\root_v6.28.06\bin\thisroot.bat% so that .bat is running too.
  3. Execute root by typing root.
  4. Open the browser with TBrowser b.
  5. Navigate the tabs until I find “poisson.cpp” (in the same folder as “fondo.dat”).
  6. Click “Run”.

If it’s of any help, root always closes after executing the program. I have attached the whole program just in case, but there should be no need to check it because, as I said, it works fine for everyone except me.

Thank you again!

poisson.cpp (5.5 KB)

OK, so that won’t work. The easiest way is the following:

  1. Open x64 Native Tools Command Prompt for VS 2022 as Administrator.
  2. Execute the following commands: cd C:\root_v6.28.06\macros\Templates_GM and then C:\root_v6.28.06\bin\thisroot.bat so that .bat is running too.
  3. Execute root by typing root.
  4. Open the browser with TBrowser b.
  5. Click “Run”.

I.e. start from where the files are located

OMG bellenot thank you so much!
I was so worried something was wrong! Now I can finally start learning with the Primer.

I take that the problem is that when changing to a different location I was somehow closing the “thisroot.bat” process? Or maybe that I was starting root from a location where I didn’t have the scripts I needed?

Thank you once again!

1 Like

You’re very welcome! And FYI, the thisroot.bat script just sets the necessary environment variables allowing to run ROOT from anywhere. It doesn’t start any process. And if you want to run a macro from another directory, you have to cd to that directory or give the full path