Using Herwig++ at RCF
First of all you need to get the binaries and libraries, you have two options to go from here:
Note: I compiled Herwig++ under 64bits so before you go ahead with this note it is recommended to switch to 64bits environment
~/> setup 64bits
- Use the binaries from my home directory. This can be done in two ways:
- Make a soft link to my my binaries and then add the relevant ENV variables to your .cshrc (RECOMMENDED):
- Change to your home directoy
-
:$ cd ~/> ln -s /star/u/mstftsm/localLibraries
- Add the following lines to the end of your .cshrc
-
setenv LD_LIBRARY_PATH /star/u/`id -u -n`/localLibraries/local/lib:$LD_LIBRARY_PATH setenv PATH /star/u/`id -u -n`/localLibraries/local/lib:/star/u/`id -u -n`/localLibraries/local/bin:$PATH
-
- OR use my libraries directly. Add the following lines to the end of your .cshrc:
-
setenv PATH /star/u/mstftsm/localLibraries/local/lib:/star/u/mstftsm/localLibraries/local/bin:$PATH setenv LD_LIBRARY_PATH /star/u/mstftsm/localLibraries/local/lib:$LD_LIBRARY_PATH
-
-
~/> source .cshrc
- Make a soft link to my my binaries and then add the relevant ENV variables to your .cshrc (RECOMMENDED):
- Or Compile your own version of Herwig++. A documentation of how I compiled it.
Test Herwig++
-
~/> mkdir testHerwig++ ~/> cd testHerwig++ ~/testHerwig++/> cp ~/localLibraries/local/share/Herwig++/LHC.in . ~/testHerwig++/> Herwig++ read LHC.in ~/testHerwig++/> Herwig++ run LHC.run -N 1000 event> 1000 1000 BasicConsistency: maximum 4-momentum violation: 50.1628 MeV
- If you got the same output as above, then so far things are cool.
Using CONS to compile analysis code of ROOT+Herwig++:
Issue (Optional):
Okay, I will give a short introduction to issues related to this and then give an example of how to do it from scratch. You can actually skip this section and go to the example directly.
You probably know that the standard way to use ROOT to analyze Herwig++ events is by making a Herwig++ analysis handler. Then you add that analysis handler to Herwig++ repository to be used as a part of the "chain" used by Herwig++.
What you actually need to pass to Herwig++ is the shared library (*.so) of your analysis class. In principle you can use g++ with correct flags to make properly compile and link your class to ROOT and Herwig++ libraries. Or you can use a Makefile for that. But if you are lazy like me, you probably want to use CONS to do that. Here is the issue with using the CONS with the defaults settings:
Dynamic linking (linking to shared libraries) with CONS:
The following is true under all libraries and all environments (32bits || 64bits), up to the writing date of this document.
If you look carefully at the default ROOT flags you will see that the flags issued to make the shared library (*.so) doesn't require linking to ROOT libraries. Actually here are the default flags used by CONS:
g++ -m32 -shared -Wl,-Bdynamic
These are known as the SOFLAGS of cons.
Try to compile any code under any star library and look at the shared libraries linked to your produced *.so. For example here is with the default CONS flags:
:$ ldd .sl53_x8664_gcc432/obj/StRoot/Foo/Foo.so libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002b1534c7b000) libm.so.6 => /lib64/libm.so.6 (0x00002b1534f7b000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002b15351fe000) libc.so.6 => /lib64/libc.so.6 (0x00002b153540d000) /lib64/ld-linux-x86-64.so.2 (0x00002b1534816000)
Those are the standard C++ libraries only, Now if we want to use this (*.so) file in ROOT it will be totally fine. We can use it in one way only:
1) Load it in ROOT using:
:$ root -l gSystem->Load("foo.so")
And we can use the shared library as we wish because ROOT framework loads the necessary ROOT libraries needed by your class.
But if we want to use the *.so library outside of ROOT we can't directly do that. For example if we want to pass the library to a program which knows nothing about ROOT (in our case it is Herwig++), and we want that program to use our library for analysis or to write it is output in TTrees. In this case, since the program knows nothing about ROOT, it doesn't take care of loading the needed ROOT libraries.
The solution I found is to change the default SOFLAGS of CONS so that it links the *.so to ROOT libraries. We need to get the flags we want to pass to CONS to link to ROOT libraries. It can be done using the command below:
:$ echo "'-shared -fPIC `root-config --cflags` `root-config --glibs`'"
Now we can the output of the previos command and pass it to CONS:
:$ cons SOFLAGS=THE_OUTPUT_OF_THE_PREVIOUS_COMMAND
Now the produced *.so libraries are properly linked to ROOT libraries as you can see below:
:$ ldd .sl53_x8664_gcc432/obj/StRoot/Foo/Foo.so libCore.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libCore.so (0x00002b925ec8c000) libCint.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libCint.so (0x00002b925f702000) libRIO.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libRIO.so (0x00002b92603e9000) libNet.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libNet.so (0x00002b926080e000) libHist.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libHist.so (0x00002b9260b4d000) libGraf.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libGraf.so (0x00002b92611e9000) libGraf3d.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libGraf3d.so (0x00002b9261632000) libGpad.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libGpad.so (0x00002b9261978000) libTree.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libTree.so (0x00002b9261c79000) libRint.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libRint.so (0x00002b92620c2000) libPostscript.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libPostscript.so (0x00002b92622f6000) libMatrix.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libMatrix.so (0x00002b926254e000) libPhysics.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libPhysics.so (0x00002b92629d5000) libMathCore.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libMathCore.so (0x00002b9262c78000) libThread.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libThread.so (0x00002b926308a000) libGui.so => /afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib/libGui.so (0x00002b92632e2000) libdl.so.2 => /lib64/libdl.so.2 (0x00002b9263d23000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002b9263f27000) libm.so.6 => /lib64/libm.so.6 (0x00002b9264228000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002b92644ab000) libc.so.6 => /lib64/libc.so.6 (0x00002b92646b9000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00002b9264a11000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b9264c49000) /lib64/ld-linux-x86-64.so.2 (0x00002b925e83d000)
So we can use the *.so library produced by CONS in two ways:
1) Load it in ROOT using gSystem->Load("Foo.so")
2) Or use it in any C++ program without having to use ROOT. Using dlopen for example. Or directly pass it to Herwig++ as we wish.
Example:
- You can copy my generic analysis class and Herwig++ configuration file. OR make a new analysis handler by following the short tutorial at Herwig++ wiki.
-
:$ cd ~/> cp -r /star/u/mstftsm/localLibraries/Herwig++-2.5.0/testHerwig++ . ~/> cd testHerwig++
-
- Inside your new directory testHerwig++ you have StRoot/StHerwigAnalysis.
- StTinyMcTrack is a class to hold a few variables about mcTracks.
- Take a look at the end StHerwigAnalysis.h, you will see the data holders I defined.
- Data holders booking and initilization is in StHerwigAnalysis.cxx, StHerwigAnalysis::doinitrun
- Writing data to root files and freeing pointers is done in StHerwigAnalysis.cxx, StHerwigAnalysis::doinitrun
- Event by event analysis code is add in StHerwigAnalysis.cxx, StHerwigAnalysis::analyze
- Inside testHerwig++ you will also find a Herwig++ configuration file RHIC.in, this is not guranteed to be fully tuned for RHIC, it a copy of LHC.in with modifications to 200GeV and MinBias events, see comments within the file.
- Now we need to change to 64bits environment and make some links to neeeded include files
-
~/testHerwig++/> setup 64bits ~/testHerwig++/> mkdir -p .`echo $STAR_HOST_SYS`/include ~/testHerwig++/> ln -s ~/localLibraries/local/include/ThePEG .`echo $STAR_HOST_SYS`/include ~/testHerwig++/> ln -s ~/localLibraries/local/include/Herwig++ .`echo $STAR_HOST_SYS`/include ~/testHerwig++/> ln -s ~/localLibraries/local/include/gsl .`echo $STAR_HOST_SYS`/include
-
- Get necessary flags to link the analysis code shared library to the ROOT libraries (please execute the command and don't copy/paste the output below, I included it here for illustration purposes only):
-
~/testHerwig++/> echo "'-shared -fPIC `root-config --cflags` `root-config --glibs`'" '-shared -fPIC -m64 -I/afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/include -L/afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lGui -lm -ldl -rdynamic
-
- Now we need to compile:
-
~/testHerwig++> cons SOFLAG='-shared -fPIC -m64 -I/afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/include -L/afs/rhic.bnl.gov/star/ROOT/5.22.00/.sl53_x8664_gcc432/rootdeb/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lGui -lm -ldl -rdynamic
-
- Finally test Herwigg++:
-
/testHerwig++/> Herwig++ read RHIC.in ~/testHerwig++/> Herwig++ run RHIC.run -N1000 event> 1000 1000 BasicConsistency: maximum 4-momentum violation: 1.983e-06 MeV
-
- The output root file (particles.root) contains information about stable charged particles.
ENJOY!
--
Mustafa^2
- mstftsm's blog
- Login or register to post comments