Problem with this code for plotting interference pattern

This question is in reference to the code on page # 9 of [interference] the link.

I wrote the code in C++ exactly the way it is given in the manual. However, this code does not have a main method, and I was doubtful if it would work, and it did not. The error I got is “Function main() is not defined in current scope”.

Naively, I thought changing void slits() to int main() would help, but it did not, and the new error I am getting is “Symbol nslit is not defined in current scope”.

Can anyone help me understand what might be the issue here? Thank you.
(https://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimerLetter.pdf)

My cpp code is attached. slit.cpp (714 Bytes)
Please read tips for efficient and successful posting and posting code

_ROOT Version: 5-34-38
Platform: Ubuntu
Compiler: Not Provided


  1. rename the file to “slits.cxx” (same basename as the function), as shown in the primer
  2. missing “auto pi = TMath::Pi();
  3. doublle” is not “double
1 Like

Sorry for not checking the typo myself.

Maybe it is a misconception I have. When I was learning about root, I always wrote the code in c++. Just wondering how one would be able to modify the code in c++ so that it runs fine?

I now see you use ROOT 5 so you cannot use “auto”. Use “double pi = TMath::Pi();” instead.

As long as you use ROOT 5, you must use: ROOT Primer 5

A better idea is to switch to ROOT 6.

The ROOT team provides ready-to-use binary distributions for some systems, including various Ubuntu versions, which you just need to download and unpack (see “Using binaries” therein).

2 Likes

Thank you, this helped.