Subscribe via RSS Feed

Root Analysis

How to start a ROOT analysis using Gate root output file (for beginners)

If you want to start a ROOT analysis here is a recipe. You can use the TTree::MakeClass method from ROOT which generates a skeleton class designed to loop over the entries of a tree from your root file. In the location of your output1.root, you launch root:
> root

Then you do the following:

  • root [0] TChain chain(“Hits”); <<<=== the name of the tree of interest: Hits. But it could be any tree from the root file.
  • root [1] chain.Add(“/home/…location_of_the_root_output_file/output1.root”);
  • root [1] chain.Add(“/home/…location_of_the_root_output_file/output2.root”);
  • root [2] chain.MakeClass(“MyAnalysis”);
  • <<<==== name of your code

MakeClass() will create 2 files: MyAnalysis.h and MyAnalysis.C

These two files are automatically generated. In the header file (MyAnalysis.h) all the root tree variables are declared and in the MyAnalysis.C file you will find a template that allows you to loop over your events. This is very useful when you have a huge root tree with tons of variables. A class is created for you!

You can run this code in root by doing:

  • Root > .L MyAnalysis.C
  • Root > MyAnalysis t
  • Root > t.Loop();

If you open the MyAnalysis.C you will see a piece of code that was generated by the method TTree::MakeClass(). You can modify/improve the code for example by writing a counter:

void MyAnalysis::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;

Int_t num_photons_PMT = 0;
Int_t num_INITIAL = 0;

// Loop over optical photons

for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb;

num_INITIAL++; // number of optical photons in the tree

if(HitPos_Y == 0.3) { ==> here you need to apply some cuts which are analysis dependant….. }
num_photons_PMT++;

}

}// End Loop over the entries.

// You can print some results on the screen:

std::cout<<"***************************** Results *****************************" << std::endl; std::cout<<"Number of Generated Optical Photons: " << num_INITIAL << std::endl; std::cout<<"Number of Photons at PMT: " << num_photons_PMT << std::endl; // You can make plots of your interest ....... see the root manual. 🙂 }

Additionnal ROOT material:
If you look at the directory gate/examples/example_OPTICAL, you will see a macro named DrawBranches.C — If you modify it so it points to your root file, and execute it in root:
root> .x DrawBranches.C — It will draw/plot all the branches of your tree into a postscript file. That might be helpful or not……

N.B: ‘Duplicated’ branches seem to be a root thing. Looking at:http://root.cern.ch/drupal/content/root-version-v5-34-00-patch-release-notes, It seems that this is fixed in TTree since root version v5-34-11 (october 2013).