Compile CERN ROOT program with RooFit in Eclipse

CERN ROOT and Eclipse

Hi guys! I have succeeded compiling my c++ program that utilizes CERN ROOT framework with RooFit in Eclipse. It was a little pain in the ass so I want to share my experience with you. I’m using MacOS 10.10 and Eclipse Luna 4.4.2.

At first after installing ROOT go to your ROOT installation directory and run ‘sh /bin/thisroot.sh’

Make sure your environment variables are set. In MacOS they are declared in ~/.bash_profile file. For example, I have:

export ROOTSYS=/Users/petrstepanov/root-6.04.08
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_PATH

after editing your ‘.bash_profile’ run from terminal ‘source .bash_profile’

CERN Root requires the main function to have the same name as your filename. Now we want to make a standalone program and compiling externally. Doublecheck you have renamed it to main(){} function in your program.

Next, try compiling your RooFit code from console. Add following libraries -lRooFit -lRooFitCore flags (maybe some others too like -lMinuit, -lFumili). Go to program parent folder in terminal and try compile:

g++ `root-config --cflags --libs` -L $ROOTSYS/lib -lRooFit -lRooFitCore -lHtml -lMinuit -lFumili your-program-name.cpp -o your-program-name.o

Then Launch:

./your-program-name.o

If compilation completes successfully it means you can repeat it from Eclipse. Every time you compile in eclipse go to “Console” tab and see the discrepancies of your g++ parameters with the ones that worked for you when you compiled in console. Try following steps:

1. Go to Project -> Properties -> C/C++ Build -> Environment. You should have ROOTSYS, LD_LIBRARY_PATH and DYLD_LIBRARY_PATH set there.

2. Go to Project -> Properties -> C/C++ Build -> Settings -> MacOS X C++ Linker -> Miscellaneous. On the right notice Miscellaneous text field. Paste there identical flags/parameters that worked for you when you compiled from console. I have all other settings under “MacOS X C++ Linker” default/empty.

3. Go to Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous. Paste same string there. Since this string has all necessary flags for the compiler I cleared default eclipse settings under “GCC C++ Compiler”. E.G. no include path, no language standart, none optimization.

That’s pretty much it. Below please see the some Eclipse errors that showed up in the console. I briefly state the solutions there

  • Eclipse Output: atomic is not implemented
    Solution you have to use C++11 compiler. This is achieved by adding following parameters -stdlib=libc++ -std=c++11 to the compiler directives.
  • Eclipse Output: symbol(s) not found for architecture x86_64
    Solution: you probably forgot to include one of the libraries (g++ parameter). Doublecheck following flags: -L/path-to-root-libraries/ – make sure path is correct. Also try including include more libraries. The ones that I was missing were -lRooFit -lRooFitCore -lFumili. After adding these flags problem gone.
  • Eclipse Output: unknown type name ‘…’ (in my case – ‘RooAddPdf’ and ‘RooGausian’)
    Solution: cyclic dependency in roofit #include “…” files. Remove all include lines in your code and start adding them as-demanded by compiler again.
  • Eclipse Output: can’t link with a main executable file for architecture x86_64
    Solution: add “-c” to compiler flags – eclipse will not try to link your source file
    http://stackoverflow.com/questions/6309773/link-error-on-mac-osx-10-6-7

P.S. You might need a list of g++ compiler flags:
https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Option-Summary.html#Option%20Summary

Setting up CERN ROOT framework with Eclipse

Whatsup guys! I have experienced some troubles setting up ROOT framework with Eclipse on MacOS. It took me hours to find the right articles. Here is the way that worked for me.

First I have installed ROOT with homebrew. You can find the instructions in this article:

https://alexpearce.me/2013/12/root-on-os-x-mavericks/

Now we want to setup ROOT and Eclipse.

Download and install Eclipse with CDT (you can have 2 eclipses at a time one for java and other for c🙂
Next follow this link:

https://twiki.cern.ch/twiki/bin/view/CMSPublic/BristolEclipseTutorial#How_to_set_up_Eclipse_for_ROOT

If you need the ROOT homebrew installation directory just type in terminal

“brew info root”

Finally some compiler optimizations can be found in this article:

http://www.tc.umn.edu/~kaes0001/randomstuff/EclipseRoot.pdf

Good luck!

RooChi2Var how-to

About chi^2 quantiles

http://ru.wikipedia.org/wiki/%D0%9A%D0%B2%D0%B0%D0%BD%D1%82%D0%B8%D0%BB%D0%B8_%D1%80%D0%B0%D1%81%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D1%85%D0%B8-%D0%BA%D0%B2%D0%B0%D0%B4%D1%80%D0%B0%D1%82

How to evaluate critical values of chi^2

http://otvety.google.ru/otvety/thread?tid=0957f82b3f43a2ed&pli=1

 

 

Get number of free parameters

http://root.cern.ch/phpBB3/viewtopic.php?p=26708

http://root.cern.ch/phpBB3/viewtopic.php?f=15&t=7501

Examples

http://root.cern.ch/svn/root/tags/v5-19-02a/test/stressRooFit.cxx