Difference: IanConnellyTutorials (10 vs. 11)

Revision 1111 Jan 2013 - IanConnelly

Line: 1 to 1
 
META TOPICPARENT name="IanConnelly"

Tutorials and tips that may come in useful

Line: 10 to 10
  My short tutorial on configuring ROOT on Windows.
Added:
>
>

ROOT

 
Changed:
<
<

Using log scales and stacking in ROOT

>
>

Using log scales and stacking in ROOT

  To create a stack of histograms typically uses the THStack class. To create a stack of TGraphs you use the TMultiGraph class which works in a similar way.
Line: 29 to 30
  This final line is important because if you are stacking some histograms, the canvas will typically default to showing 3 or 4 orders of magnitude down from the largest maximum. It is a bit strange but it means that if you have a large background plot and a tiny signal plot, it may not appear straight away from just stacking and setting the scale to log. Setting the minimum to 1 forces the scale to go down to zero (ie log(1) = 0) and the maximum will remain the largest value from the histogram. This was particularly useful for me when I was plotting signal and background scaled number of events passing an MVA cut because to begin with the background events dwarf the amount of signal and only when the cuts progress towards the end of the x scale did the background get cut to the point where there were similar amounts of signal and background events.
Changed:
<
<

Macro for stacking TGraphs

>
>

Macro for stacking TGraphs

  This is a simple little macro but it took a little bit of time to work out all the options to draw the lines properly. The alternative would be to use Glen's script to read out a text file of numbers which plot multiple TGraphs on the same canvas which is slightly different to this. My macro takes two already made TGraphs and will scale them to whatever required luminosity and plot them on the same canvas in the same way THStack does.
Line: 59 to 60
 return 0; }
Changed:
<
<

Other macros

>
>

Other macros

  See my webpage for additional scripts and macros I have written as it is generally more convinient to keep them there.
Added:
>
>

Merging ROOT files

This isn't something I have used properly yet, but I have just come across it. In addition to the TFileMerger class available in ROOT, when you set up your enviroment, you also get a program called hadd which uses the syntax:

hadd <targetfile.root> <input files.root>
The program will add the histograms and ttree entries together. Whilst this can be used to combine, say, all your background samples into one single sample, I realise that it could be used as a simple alternative to PROOF and parallel processing.

My particular analysis program accepts as input the directory of a sample in which are a list of ROOT files which get added to a TChain and then my program, created using MakeClass, will run over the TChain. If I have a large number of ROOT files though, I can now split the same sample into a number of dataset directories, and run the analysis over smaller directories and then merge the results once all processing has been achieved.

In the long run it will probably be better to understand and use PROOF as, from what I have read, that dynamically alters the work load on available nodes to optimise the processing and then merges them together at the end. I think you can also use PROOF-lite to take advantage of multicore processors in your laptop/desktop if you are processing it locally which you wouldn't be able to do with hadd.

Using with Root dictionaries

CINT is able to produce libraries for specific ROOT objects. The main example is wanting to save a vector of TLorentzVectors to a TTree. By default this will not work. However, you can generate libraries to allow this to work. They take the command (in ROOT CINT):

>> root
>> gInterpreter->GenerateDictionary("vector<TLorentzVector>","TLorentzVector.h,vector")

Then to compile with this library you use the advice given above.

BASH Shell (Scripting and tips)

Ctrl-z in terminal - Pausing a process

If you have a process running, typing ctrl+z will pause that process allowing you to use the command line prompt.

If you then type bg it is equivalent to having originally set your program running with an & at the end - ie it tells it to resume running in the background.

You can also type fg to bring it back to running in the foreground where you can see output, but cannot access the command line.

Apparently typing jobs will tell you what is running in the background and allow you to call them to the foreground if need be.

Getting the full path of multiple files

In terminal you can use:

find . 
to retrieve the list of all files and folders in the current directory, much like ls.

However, this is useful if you want to get hold of the full path directory of a file, for example:

find `pwd` -type f
will return the list of all files in the current directory with their full path (as using pwd instead of . gives the static/global path to the files).

This can save some time if you need to list them in file to run over with a script.

Merging Multiple .ps files into one .pdf

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf \
*.ps

Error checking bash script commands

As per the link here, commands in terminal will have a success/fail result in the special character $?. For example:

ls *.root
RESULT=$?
if [ $RESULT -ne 0 ]; then
    echo "ERROR in the command"
fi

Emacs - How to make backspace key delete backwards

Whether it be an issue with my emacs setup on lxplus, it seems that my default backspace behaviour in

emacs -nw
is to be the same as the delete character. To change this in each session do:
M-x (ie Esc-x)
normal-erase-is-backspace-mode

BASH Scripting : Looping through two arrays simultaneously

I wanted to have two arrays, one with a filename and the other with an output file name. I needed to use shell scripting to manipulate the file names because of some systematics which needed renaming. I orginially set up a loop over a list of filenames which can be performed as:

FILES=(file1.root file2.root textfile.txt)
for F in ${FILES[@]}; do
    echo $F
done

However you cannot quite use this as you would in C++ as you are not using a counter, per se, to control it.

An alternative method taken from here explains how to simultaneously loop through two distinct lists:

# First have your lists in two files (listA.txt, listB.txt here)
while read -u 5 aVAR && read -u 6 bVAR; do
    echo $aVAR "   " $bVAR
done 5<listA.txt 6<listB.txt

This makes use of file handlers (here assigned to 5 and 6) to loop through the file (just make sure each item is on a new line in the files) and voila!

 

Using Pythia

Pythia is an event generator which simulates particle collisions and the uses the Lund string model to propagate the hadronisation of the interaction. Pythia 8 is currently the latest incarnation and is written in C++. It is possible to set up a local installation of Pythia on your own laptop and assuming you have ROOT installed also, you can use both sets of libraries to carry out a parton level analysis of anything you might want to model.

Line: 169 to 271
  The status codes (and more information about the particle classes and extra things) are available on the html document. This is installed locally or can be accessed online at the Lund hosted version here.
Changed:
<
<

Ctrl-z in terminal - Pausing a process

If you have a process running, typing ctrl+z will pause that process allowing you to use the command line prompt.

If you then type bg it is equivalent to having originally set your program running with an & at the end - ie it tells it to resume running in the background.

You can also type fg to bring it back to running in the foreground where you can see output, but cannot access the command line.

Apparently typing jobs will tell you what is running in the background and allow you to call them to the foreground if need be.

Merging ROOT files

This isn't something I have used properly yet, but I have just come across it. In addition to the TFileMerger class available in ROOT, when you set up your enviroment, you also get a program called hadd which uses the syntax:

hadd <targetfile.root> <input files.root>
The program will add the histograms and ttree entries together. Whilst this can be used to combine, say, all your background samples into one single sample, I realise that it could be used as a simple alternative to PROOF and parallel processing.

My particular analysis program accepts as input the directory of a sample in which are a list of ROOT files which get added to a TChain and then my program, created using MakeClass, will run over the TChain. If I have a large number of ROOT files though, I can now split the same sample into a number of dataset directories, and run the analysis over smaller directories and then merge the results once all processing has been achieved.

In the long run it will probably be better to understand and use PROOF as, from what I have read, that dynamically alters the work load on available nodes to optimise the processing and then merges them together at the end. I think you can also use PROOF-lite to take advantage of multicore processors in your laptop/desktop if you are processing it locally which you wouldn't be able to do with hadd.

Getting the full path of multiple files

>
>

Analysis Specific

 
Changed:
<
<
In terminal you can use:
find . 
to retrieve the list of all files and folders in the current directory, much like ls.

However, this is useful if you want to get hold of the full path directory of a file, for example:

find `pwd` -type f
will return the list of all files in the current directory with their full path (as using pwd instead of . gives the static/global path to the files).

This can save some time if you need to list them in file to run over with a script.

Merging Multiple .ps files into one .pdf

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf \
*.ps

Extracting the luminosity of data files

>
>

Extracting the luminosity of data files

  This is going here as I struggled far more than I should have to get the correct options. You use atlas-lumicalc to extract the luminosity associated with a particular good runs list. The GRL is used as a mask to only use data which has been taken at a time when all the detector functions were working correctly.
Line: 254 to 313
  This syntax indicates to take all runs between the ones hyphenated, but the equals sign seems to work in this case but not the one above.
Deleted:
<
<

Error checking bash script commands

As per the link here, commands in terminal will have a success/fail result in the special character $?. For example:

ls *.root
RESULT=$?
if [ $RESULT -ne 0 ]; then
    echo "ERROR in the command"
fi

Emacs - How to make backspace key delete backwards

Whether it be an issue with my emacs setup on lxplus, it seems that my default backspace behaviour in

emacs -nw
is to be the same as the delete character. To change this in each session do:
M-x (ie Esc-x)
normal-erase-is-backspace-mode
 

Interesting thing with C dynamic libraries

Line: 319 to 358
 
 readelf -d <Executable> 
will list the shared objects and the rpath.
 ldd <Executable> 
will display the libraries that are needed to run.
Deleted:
<
<

Using with Root dictionaries

CINT is able to produce libraries for specific ROOT objects. The main example is wanting to save a vector of TLorentzVectors to a TTree. By default this will not work. However, you can generate libraries to allow this to work. They take the command (in ROOT CINT):

>> root
>> gInterpreter->GenerateDictionary("vector<TLorentzVector>","TLorentzVector.h,vector")

Then to compile with this library you use the advice given above.

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 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