Tutorials and tips that may come in useful

This is still a massive work in progress. At some point I will copy out some of the notes I have made which have been useful and put them here.

Setting up ROOT on Windows

My short tutorial on configuring ROOT on Windows.

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.

THStack* stack = new THStack("Name","Title");

stack->Add(histogram_name);

Setting up a log scale is easy enough in ROOT. Assuming you have a TCanvas you apply the following:

TCanvas* canvas = new TCanvas("Name","Title",10,10,900,900)

canvas->SetLogy(); //You can also do SetLogx();

stack->SetMinimum(1);

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.

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.

tgraphstack(){
    
    TFile* f = new TFile("f_hist.root", "OPEN");
    
    TGraph* signal = (TGraph*)f->Get("scaled signal;1");
    TGraph* background = (TGraph*)f->Get("scaled background;1");
    TMultiGraph* multiG = new TMultiGraph("multiG", "Evolution of number of events with BDT cut scaled to 20fb^{-1}");
    
    TCanvas* c = new TCanvas("c","c", 2000, 2000);
    c->SetLogy();
    c->RangeAxis(-1,1,0,1000000);
    multiG->Add(background);
    multiG->Add(signal);
    //Interesting behaviour where TMultiGraph just sets the minimum y axis to 3 orders of magnitude less than the maximum point being plotted.
    //Using SetMinimum forces the minimum point to be fixed
    //Here use 1 because log(1) = 0
    multiG->SetMinimum(1);
    multiG->Draw("AL");
    //This option draws axes and plots as a line
    //This has to come after the call to draw
    multiG->GetXaxis()->SetTitle("t_{BDT} cut"); 
    multiG->GetYaxis()->SetTitle("Log(scaled number of events)");     //Use Draw("AL") to say plot axis and line

return 0;
}

Other macros

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

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. Obviously Pythia does not have any detector level effects (as it is parton level) so you are basically working at a "even-better-than-best-case-scenario" with your results. That said, the distributions found should be similar to the proper MC and data sets. It is worth pointing out that currently pile-up is not well modelled in Pythia 8, not that it has been something I have had to worry about so far, but that was the reason from switching from Pythia 8 back to Pythia 6 in the generation of MC11b and MC11c.

You can get Pythia from here.

Once installed you can compile Pythia and ROOT libraries using the following Makefile. In addition, you will need to edit a line in one of the xml files. I forget which, but on the first compile an error will come up which should point you in the direction of it. The reason being that the file uses a relative path directory (ie ../folder) instead of an absolute one. This means if you try and compile outside of the folder that Pythia generates the example codes, you will get this error, so bear this in mind.

# Glen Cowan, RHUL Physics, February 2012
# Editted for use by Ian Connelly, Feb 2012

PROGNAME      = signal
SOURCES       = signal.cc
INCLUDES      = 
OBJECTS       = $(patsubst %.cc, %.o, $(SOURCES))
ROOTCFLAGS   := $(shell root-config --cflags)
ROOTLIBS     := $(shell root-config --libs)
ROOTGLIBS    := $(shell root-config --glibs)
ROOTLIBS     := $(shell root-config --nonew --libs)
ROOTINCDIR   := $(shell root-config --incdir)
CFLAGS       += $(ROOTCFLAGS)
LIBS         += $(ROOTLIBS)
#  Not sure why Minuit isn't being included -- put in by hand
#
LIBS         += -lMinuit
LDFLAGS       = -O

#  Now the Pythia stuff
#

# Location of Pythia8 directories 
# (default is parent directory, change as necessary)
PY8DIR=/Users/Ian/Documents/pythia8160
PY8INCDIR=$(PY8DIR)/include
PY8LIBDIR=$(PY8DIR)/lib
PY8LIBDIRARCH=$(PY8DIR)/lib/archive


# Include Pythia and Pythia examples config files
-include $(PY8DIR)/config.mk
-include $(PY8DIR)/examples/config.mk

LIBS += -lpythia8
LIBS += -llhapdfdummy

$(PROGNAME):  $(OBJECTS) 
      g++ -o $@ $(OBJECTS) $(LDFLAGS) -L$(PY8LIBDIRARCH) $(LIBS)

%.o : %.cc $(INCLUDES) 
   g++  ${CFLAGS} -c -I$(ROOTINCDIR) -I$(PY8INCDIR) -g -o $@ $<

test:
   @echo $(PY8LIBDIRARCH)

clean:   
   -rm -f ${PROGNAME} ${OBJECTS}

The example workbook which is available on the main site is very good at introducing the syntax that Pythia uses. The standard procedure is: set up the collision->decide what parton modelling is required (ie hadronisation? multiple interactions?)->run event loop->include analysis in event loop->fin.

You are able to access every single parton which is created in the hard interaction and also in the soft hadronisation afterwards using something like this (for HZ->bbvv):

int main() {
    
    //Set up generation
    
    Pythia pythia;
    pythia.readString("HiggsSM:ffbar2HZ = on"); //Higgsstrahlung production
    pythia.readString("Beams:eCM = 8000."); //eCM = 8TeV
    pythia.readString("25:m0 = 125"); //Higgs mass 125
    pythia.readString("25:onMode = off"); //Turn off all Higgs decay modes
    pythia.readString("25:onIfAny = 5 -5"); //Allow H->bb
    pythia.readString("23:onMode = off"); //Turn off all Z decay mdoes
    pythia.readString("23:onIfAny = 12 14 16 -12 -14 -16"); //Allow Z->vv
    pythia.readString("PartonLevel:MI = off ! no multiple interactions");
    pythia.readString("PartonLevel:ISR = off ! no initial-state radiation");
    pythia.readString("PartonLevel:FSR = off ! no final-state radiation");
    pythia.readString("HadronLevel:Hadronize = off");
    
    //Initialise any TFiles, TTrees, TH1s, vectors before event loop
    pythia.init();

    //Event loop
    for(int iEvent = 0; iEvent < 30000; ++iEvent){
    pythia.next();
        for(int i = 0; i < pythia.event.size(); ++i){
            //Then these are the annihilated hardest incoming partons
            if(pythia.event[i].status() == -21){ 
                
            }

        }
    }
return 0;
}

The status codes allow you to find partons which are final state or intermediate state partons. In addition, there is another method called pythia.process[i] which apparently only accesses the hard partons whereas .event[i] accesses all of them. Note though that if you turn off too many effects so you only have the hard interaction, .process[i] stops functioning (from what I have heard) so you can only access through .event[i].

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.

Edit | Attach | Watch | Print version | History: r42 | r4 < r3 < r2 < r1 | 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: r2 - 13 Mar 2012 - IanConnelly

 
  • Edit
  • Attach
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