Jacob's collection of useful tutorials and tips

Computing at PP RHUL

How to mount your pphome on your personal laptop/computer at RHUL

This is a particularly useful tip if you, like myself, want to edit files from your local machine running the latest version of emacs. More often then not the version available on linappserv is either outdated or simply too vanilla for you. I run Aquamacs on my MacBook which has several customizations specific to OS X and the Mac.

N.B. You need to be within PP network, either via the wired network or the Stella wireless network. Check below for instructions on how to mount your pphome from outside of the network.

There are two ways to mount your pphome folder to a local directory depending on whether you're on a UNIX-type or a Windows-type enviornment. Since I'm using OS X I'll focus on mounting using NFS, keep in mind that this also works on Linux operating systems as well.

The first step is to make sure that your UID is synced between our Linux environment and your personal machine.

!!SUPER IMPORTANT!!: Keep in mind that this process is potentially dangerous and should be done with care, you may literally lock yourself out of your own home folder so please back-up everything you hold dear before proceeding, and whatever happens you CANNOT hold me accountable.

Now that we have the disclaimer out of the way, let's get to it. If you don't know how to change your UID there are several tutorials for both Linux and OS X. I can only vouch for the OS X tutorial since I used it myself, the Linux one however seems fairly good as well. So if you're using Linux you need this tutorial and if you're on a Mac follow this tutorial. Keep in mind that for both you need to figure out your current UID and the UID you want to change to. To get the second one, log into linappserv using your account and perform the following command:

[jblanco@linappserv0 ~]$ stat ~/

This should produce the following:

  File: `/home/jblanco/'
  Size: 59           Blocks: 8          IO Block: 4096   directory
Device: 24h/36d   Inode: 3           Links: 29
Access: (0755/drwxr-xr-x)  Uid: ( 1234/ jblanco)   Gid: (  120/    hep2)
Access: 2011-05-25 14:23:02.212553501 +0100
Modify: 2011-05-25 14:14:14.746438370 +0100
Change: 2011-05-25 14:14:14.746438370 +0100

Note the UID number in the output. Make sure to use YOUR UID when following the above tutorials. Before you ask, no that's NOT my UID.

Once you have changed your UID and made sure that all the appropriate ownerships have been changed and directories have been renamed we can proceed to mount the NFS share.

On Mac OS X this can be easily accomplished from Disk Utility.app. First of all create a new mount directory either through the terminal or Finder. Now, in your dock click on Applications->Utilities->Disk Utility, here select File->NFS Mounts... A new window should open with an empty list, select the + sign to add a new mount. The address should be of the following form, making sure you replace jblanco with your Linux username:


and the mount point should point to the directory that you just created. Select Verify, you should barely see the confirmation message if all is well.

On Linux It can be a bit trickier and what method you use depends on what's available for your distro, the safest bet is to edit your fstab file, this contains the information for all mounted drives. As always be careful before doing anything that might break your installation, your machine or yourself. Here is a link to a wiki page on NFS shares for Ubuntu, but the information should be relevant to most distros.

Enjoy your new found productivity boost. smile

How to mount your pphome on your personal laptop/computer OUTSIDE of RHUL

Make sure that you can ssh into linappservX successfully, because we are going to use and ssh-tunnel to mount your pphome.

Now you need to get SSHFS, depending on your os follow the appropriate bit. The mounting instructions are the same for both Linux and OS X. I didn't include Windows since a) you should use SMB (not sure you can from the outside) and b) SSHFS requires installing Cygwin under Windows.

On Linux Depending on your distributions you will have to use a different package manager to install sshfs, for Ubuntu just run:

[User@Machine ~] sudo apt-get install sshfs

On Mac OS X For OS X it's a little more complicated, you'll have to install MacFUSE from here, once you've installed it, make sure you go into the preference pane and check "Show Beta Versions" and click update. Once you've done that you download the pre-compiled SSHFS binary (for Leopard but works in SL), extract it and copy the binary to /usr/local/bin. Make sure you close and re-open your terminal.

To mount your pphome create a new directory where your pphome will be mounted and run the appropriate sshfs command:

[User@Machine ~] mkdir /Some/Directory
[User@Machine ~] sshfs jblanco@linappservX.pp.rhul.ac.uk:/home/jblanco

Replacing jblanco with your home directory name and typing the password when prompted.

BOOM! you have access from the outside

ROOT Tutorials

Compiling ROOT in Ubuntu

Download the relevant source file from the ROOT website to your desktop. In this tutorial I'm using version 5.26 but this should apply to any recent release.

First open up a terminal and run the following commands:

[User@Machine ~]$ mkdir root-build
[User@Machine ~]$ cp ~/Desktop/root_v5.26.00.source.tar.gz ~/root-build
[User@Machine ~]$ cd ~/root-build
[User@Machine ~]$ tar -xvf root_v5.26.00.source.tar.gz
[User@Machine ~]$ cd root

We just created a new directory in your Home directory, then extracted the source files there. To keep things organized I place sources in a dedicated directory inside my home.

Now we need to download some extra packages to resolve dependencies. Depending on what extra functionality you need, you might want to download/compile other packages. Thankfully aptitude, the package manager bundled with Ubuntu, will help you download all the packages you need and a few that you may not but which add extra functionality.

In the terminal run the following commands to download the necessary packages and configure your build of ROOT:

[User@Machine ~]$ sudo aptitude build-dep root-system
[User@Machine ~]$ ./configure

This will make sure that you have everything you need to compile ROOT. If at any point you're told that some library is missing, note the name of the library and install it by running:

[User@Machine ~]$ sudo apt-get install *NAME OF PACKAGE*-dev

N.B. Packages ending in -devel will appear in the Ubuntu repo's as *NAME*-dev. The suffix -devel is part of the convention used in Red Hat and its variants like SLC4/5. If the package you need is missing, try googling around for the package name to find the equivalent, hopefully the build-dep command will provide you with all you need.

If you have any special configuration requirements such as Pythia interface or Python support make sure that the relevant libraries are present, you can run the command:

[User@Machine ~]$ ./configure --help

to check if you need to define paths to any libraries or include files. If all has gone well with configuring, simply compile ROOT by running:

[User@Machine ~]$ make

This should begin compiling ROOT for you, now I can't stress this enough, compiling could take A LONG TIME so don't worry.

Now we need to set a couple of environmental variables. In the terminal again,

[User@Machine ~]$ sudo gedit ~/.bashrc

and add the following lines to your bashrc file to configure where ROOT will be installed to:

export ROOTSYS=/usr/local/root
export PATH=$ROOTSYS/bin:$PATH

Of course if you want to install it to any other location make sure you change the ROOTSYS path above.

Re-source your bash configuration file and install:

[User@Machine ~]$ . ~/.bashrc
[User@Machine ~]$ make install

This should copy all files needed to the ROOTSYS folder you specified in your bash configuration. This should let you run ROOT in the normal way.

Enjoy smile

Run ROOT in batch mode to speed up processing

For ages I found the fact that ROOT has to draw histograms or other graphics before you can manipulate certain elements of it such as the axis of a TH1. Drawing to screen is an expensive operation and takes a LONG time especially if you're SSH-ing into the machine you're working on. There is a way to avoid all of this and speed up processing immensly without loosing any features at all. Run ROOT in batch mode by specifying the -b flag when you call your macro:

root -b 'YourScript.cxx("variable1")'

This will run your script, produce plots and even save them to file as you would normally but simply without drawing them to the screen. As far as I can tell your macro will function just as before except for being a lot faster. This is really useful if you don't really need to look at the plots as things are running. Of course if you're debugging things remove the flag to stare the plots right in the eyes.

Additional Tip: I also add the -q flag when running to force ROOT to quit once the macro has run allowing you to do other stuff in your bash script.

Making Data vs MC-style plots with SF plot attached

So we've seen these sort of plots everywhere and they are cool (in a PP ROOT plotting sort of way. Stockholm-syndrome much?). They are however a little tricky to get right. Learning the anatomy of a TCanvas is painful and even when you think you know what you're doing, you really don't. You'll have something that looks like that plot below, note that the X-axis of the top plot is behind the bottom plot, so you need to make sure that both top and bottom plot have the same range for things to make sense.

So here is a simple way of getting these sort of canvases drawn. One might be tempted to create a canvas and then call TCanvas::Divide, but this will produce two pads that have margins and its a mess. Instead you want to create the pads yourself. First lets make the canvas and the top pad.

TCanvas* canvas = new TCanvas( "SomeName", "SomeTitle", 900, 700 );
TPad top_pad("top_pad", "top_pad",0,0.4, 1.0, 1.0);

You just created a pad of a certain size in the canvas and set the bottom margin of that pad to zero, that way the SF plot that will be going in the bottom pad is flush with the top pad. After this portion of code then go ahead and draw whatever you want on the top pad, including things like histograms and legends.

Next we'll create the bottom pad making sure things are flush with the top pad content:

canvas->cd(); // This line is REALLY important otherwise you'll draw a subpad in the top pad :-(

TPad bottom_pad("bottom_pad", "bottom_pad", 0, 0.03, 1.0, 0.4);
bottom_pad.SetGrid(1,1); // Optional: Enable gridlines on plots

Then draw whatever you need on the bottom pad, save the canvas to a root file or output as EPS/PNG/PDF for slides and notes.


Update: Making beautiful 2D plots

Edit: After I've written this tutorial I learned a lot about what makes a colour palette effective in conveying information and how the human brain perceives colour. While the mechanism for setting the palette still works well, the palette of colours I used is terrible. Not only do the colours used not convey much information, the palette can also misrepresent the data. Below is the updated tutorial.

If you've ever made 2D plots in ROOT using the colz command you know how ugly the colours are. In this tutorial I will be using a fake 2D histogram called foo. This tutorial will be written in C++ however this can be easily ported to Python if you want to.

Normally to plot a TH2 histogram with a colour gradient one uses the following command:

root [0] foo->Draw("colz")

This will use the hideous black, pink, bright green and grey palette. To change this behaviour, before running the draw command, run:

root [0] gStyle->SetPalette(53)

This will force plots to be drawn with a dark body radiator palette that goes from black through red and then white. The intensity of the colour and saturation convey much more information, darker colours represent lower values and brighter colours represent higher values.

To make the gradient even smoother you can also add something like the following:

void set_plot_style()
  const Int_t NCont = 255;

This should make your 2D plots much nicer to look at and easier to read.

Check out the ColourBrewer tool which was designed to build colour palettes for information maps. You can of course use it to build nice colour palettes for your own 2D plots or 1D distributions when you have lots of related curves. There are a lot of options to play with there, but the most important ones are to select the type of data you're plotting (sequential in the case of 2D plots) and select how many colours you need. Look at the TColour::SetCreateGradientTable function for more information on creating custom palettes.


Edit | Attach | Watch | Print version | History: r8 < r7 < r6 < r5 < r4 | Backlinks | Raw View | Raw edit | More topic actions

Physics WebpagesRHUL WebpagesCampus Connect • Royal Holloway, University of London, Egham, Surrey TW20 0EX; Tel/Fax +44 (0)1784 434455/437520

Topic revision: r8 - 11 Aug 2014 - JacobBlanco

This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback