Adding flat tree filling and saving to the duplicated Athena Hello World


This page describes how to modify the Hello World algorithm in order to create a histogram filled with dummy values and save it to an output root file. We will make the changes to the duplicated Athena Hello World so that later on we can compare with the original Athena Hello World code and see the things we added.

First, log into your account and set up CMT (as described in WorkBookSetAccount). Assuming you are running in a folder with the same name as the Athena version and located in the ~/testarea, if you have a bash shell define this variable which will help as move from a folder to another folder easily while allowing us to use the same copy paste commands for different versions of Athena.

cd ~/testarea/$ATHENA_VERSION
asetup $ATHENA_VERSION,here

Edit the HelloAlgNEW files

cd ~/testarea/$ATHENA_VERSION/Control/AthenaExamples/AthExHelloWorld/src

In the HelloAlgNew.h add the following include statements

#include "TTree.h"

and the following private variables

TTree *m_flatTree;

In the HelloAlgNew.cxx add the following code in the initialize() method just before "//NEW end"

  //define and initialize the tree                                                                                               
  m_flatTree = new TTree("flatTree","flatTree");
  m_flatTree->Branch("jetPt", &m_jetPt, "jetPt/D");
  //book the tree with the histogram/tree service                                                                                
  status = m_thistSvc->regTree("/file1/flatTree", m_flatTree);
  //check if the status is successful                                                                                            
  if (status.isFailure()) {
    ATH_MSG_ERROR("No THistSvc!!!!!!!");
    return StatusCode::FAILURE;

First we defined and initialized the tree. Then we added a branch with the variable jetPT. Here "file1" represents the name of the output file, which we will define later in the option file, where we will also introduce the histogram and tree service (it is also a tree service, even if its name mentions just the histograms). Also, "flatTree" represents the name of the flat tree contained in the output root file.

Then, in the execute() method just before "//NEW end" we fill the tree for the current event.

   //fill the tree                                                                                                                

Compile the package with the algorithms

No need to modify again the file "requirements"

gmake -C ../cmt


There is no need to modify the option file again. Now are are ready to run >& test_flatTree.log

As it ran successfully, we can open the output.root file and check that it has our jetPt histogram, which we can draw and we will see 10 entries (since our option file tells to run over 10 events - note that there is a loop with 10 steps even if no input file with real events is present) of values of 100.

root.exe output.root
root [1] .ls
root [2] jetPt->Draw()
root [2] flatTree->Draw("jetPt")

Major updates:
-- AdrianBuzatu - 25-Jan-2012
Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2012-01-27 - AdrianBuzatu
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Sandbox All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback