Sunday, May 27, 2012

ROOT to skip few columns with TGraph

I often use TGraph and TGraphErrors to make plots from text files with columns of data. Example below:

////////////////////////////////////
TGraphErrors *ProfNch09ATLAS = new TGraphErrors("Data/Profile_Nch_pT_09TeV_Data_ATLAS.dat", "%lg %lg %lg");
/////////////////////////////////

Which reads from the .dat file that has 3 columns of data. the x-value, the y-value, and the error in y-valye. If you need to add a 4th columns, the error in the x-value or the bin size, you can add it to be the 3rd column in your text file and the next file can be read using:

/////////////////////////////////
TGraphErrors("Data/Profile_Nch_pT_09TeV_Data_ATLAS.dat", "%lg %lg %lg %lg");
////////////////////////////////

but what id you had another plot that needs the original file? that is plotting on the the first two columns alongside the fourth. This time you can use the option *

///////////////////////////////
 TGraphErrors("Data/Profile_Nch_pT_09TeV_Data_ATLAS.dat", "%lg %lg %*lg %lg");
///////////////////////////////

For files with a dilemeter different than '/t' and ' ' the 'option' argument need to be used. see http://root.cern.ch/root/html/TGraph.html

Wednesday, February 1, 2012

ROOT to perform a shell command in a macro

You can make a ROOT macro execute another root macro or a shell command using the following line:

gROOT->ProcessLine("!shell_command");
or
gROOT->ProcessLine("ThisRootMacro()");

Don't forget that the macro needs to be uploaded first:
gROOT->LoadMaco(ThisRootMacro.C);

Tuesday, January 10, 2012

Running two separate verions of firefox on linux

In many cases of active web and software usage you might need to run an older version of a web browser. In this case I needed a to run Firefox 8 and I didn't want to remove my current version. here is what to do:

1- Create a separate directory and move to it:
$ mkdir /home/mzakaria/opt/firefox8
$ cd ~/opt/firefox8/

2- go to Mozilla FTP server at ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/. and look up the release you want

3- get the folder using wget:
$ wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/8.0/linux-i686/en-US/firefox-8.0.tar.bz2 (I got the one with i686 b/c I am using a 32bit machine, you can check that with the command uname -m; it will give you i686 if it was a 32bit)

4- untar the package:
$ tar xvjf firefox-8.0.tar.bz2

5-  move the unpacked folder to a folder with the name you chose (in case you are bringing more than one release)
$ mv firefox firefox8

6- Each version needs a separate user profile — otherwise, it won’t be possible to run them simultaneously, and worse, it might break the default profile which is used by the system version. For our version:
$ firefox -no-remote -CreateProfile firefox8

7- That's it! change to the folder again and run it:
$ cd firefox8/
$ ./firefox -no-remote -P firefox8

Notice that this will create a completely separate browser, you might want to move some bookmarks or certificates.


Friday, December 2, 2011

How to record a live stream

I found a lovely post on how to record a live stream or to record whatever audio is:

I'm using the Sound Recorder application that comes in standard Ubuntu installations. To set this up using other programs (like audacity) just substitute it in these instructions.

  1. Install pavucontrol (PulseAudio Volume Control) using apt-get or the Ubuntu Software Center.
  2. Open PulseAudio Volume Control. It should be in the applications menu under Sound and Video.
  3. Open Sound Recorder and start recording. Playing any sound at this point would be helpful, as your level indicator should react once you have finished.
  4. Go to the "Recording" tab in the PulseAudio Volume Control window.
  5. Make sure that "Applications" is selected in the drop down menu on the "Recording" tab.
  6. Choose "Monitor of Internal Audio Analog Atereo" from the "Record Stream from" menu in the Sound Recorder entry of the application list.

This appears to be persistent so that you will only have to do this once, but you will have to repeat these steps to record in another application.

After this I notice that my mice is disconnected from skype. Consider this as a fix:Open “Sound Preferences” -> “Hardware” -> “Change Profile to Analog Stereo Input” -> test -> “Change Profile to Analog Stereo Duplex” -> test again.

Saturday, July 30, 2011

Updating Firefox on Ubuntu

I can't find a solid reason to update my browser (unless some site or software that I use asks me to). Today I got tempted by a message on my gmail account asking me to do that. So here is how to do it:

sudo add-apt-repository ppa:mozillateam/firefox-stable
sudo apt-get update
sudo apt-get upgrade
 

This was method 2 among 3 ways to do it that I found under this post.

One new feature Firefox5 has is the Sync feature. So now you can have all your tabs and browsing needs saved (safely as I hope) and you can access then from any machine.

Tuesday, July 12, 2011

Editing PDF files on linux, Two solutions

Since most our meetings and seminars are presented as PDF files. I finally realised that I need some way to edit them on Linux. Something as simple as adding comments and such would do. couple of research attempts lead me to the following link:
http://www.cyberciti.biz/tips/open-source-linux-pdf-writer.html


I tried PDFedit instantly and it did deliver what it promised. the only problem is the limited selection of arrow shapes (hard to use for Feynman diagrams).


To install and run:
$ sudo apt-get install pdfedit
$ pdfedit /path/to/pdf.file & 

The code runs smoothly but has it's limits; If the document had symbols unrecognised by it (Say Japanese characters or Math symbols). It will open but with many of it's functions missing. 

Another option is Open office! They new release (3.0 and after) has a package that is able to open PDF files on a drawing pad. you will even get to stick comments and such. This approach also suffers when opening some unrecognised set of fonts or objects. It will still be fully functional but the locations will be misset up as well as missing some symbols. 

We conclude this note with Images. Where your best bed is with GIMP. Which is a standard release in UBUNTU. Once you do the changes make sure to save as xcf. then using the command:
$  convert file.xcf file.pdf

You will get he new file in the required form.

Sunday, July 3, 2011

ROOT after a little bit of C++

I made a recent revision for Malik's excellent book about C++. This time I made it up to chapter 14 where I learned a lot about pointers. It turns out that this concept is heavily used in ROOT. For example here is a snippet of a code I am using to create plots of publication quality:

#include
#include "TInterpreter.h"
#include "TCanvas.h"
#include "TLatex.h"
#include "TROOT.h"
#include "TH2F.h"
#include "TGraphErrors.h"
#include "TLegend.h"
#include "TPad.h"


These are preprocessor statements to include libraries and header files. the <> symbol is doe standard libraries. and the ones between quotes "" is for libraries made.
void readRFPAS2RHWZ2() {



This starts the function of the type void called readRFPAS2RHWZ2()




float x = 0.446127; //The coordinate of 900GeV labe (t1d, t2d, etc)
float y = 0.190389;
float x1 = 0.2000; //The coordinates for the legends.
float y1 = 0.326465;
float x2 = 0.50275;
float y2 = 0.551054;

Simple variable declaration.

 TInterpreter::Instance() -> LoadMacro("tdrstyle.C");
This is a bit odd as an expression. I am not sure how to interpret it but here is a try. There is a space TInterpreter with an class Instance that has an object LoadMacro. it is called as a pointer:

(*TInterpreter::Instance).LodMacro = tdrstyle.C

What this does is to ask our code to use that macro.
 gROOT -> Reset();

Basically calling another pointer.
(*gROOT).Reset();
 TInterpreter::Instance() -> Execute ("setTDRStyle","");

Same as above.

 TCanvas *c1 = new TCanvas("c1","different scales hists",600,600);

new means we are creating a dynamic variable. in this case of the type TCanvas. it is assigned to the pointer c1.

 c1->Range(-100,-100,10,10);

now c1 points to another object in TCanvas.
(*c1).Range = (-100,-100,10,10);

 TH1F *Dist_Nch_pT20_ = new TH1F("Dist_Nch_pT20_","title",100,-0.5,30);

also TH1F is a data type. with the pointer Dist_Nch_pT20_ is set with the address of the class named Dist_Nch_pT20_  with the parameters needed. next we assign the objects:
 Dist_Nch_pT20_->SetXTitle("N_{ch}");

etc.

So we conclude it is nothing but a bunch of dynamic classes assigned by pointers.