Frustrating crash when projecting histo with compiled code

Dear Root experts,

I’m experiencing a very frustrating crash when projecting a histogram in compiled code. I wrote a very simple test program that:

  1. opens root file
  2. gets ttree
  3. books a histogram
  4. projects one variable onto the booked histogram.

The code compiles without problems but crashes when projecting the histogram. I have put the simplified version of the code in The tar includes the code, makefile, and the rootfile.

I’m experiencing this problem both on my machine running root version 5.27/03 and gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3, and on my workstation running root version 5.22/00 (cms) and gcc 3.4.5.

The Makefile is very simple and in my machine has the following definitions:
ROOTGLIBS = -L/usr/local/bin/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lz -lGui -pthread -lm -ldl -rdynamic

ROOTCFLAGS = -pthread -m32 -I/usr/local/bin/root/include

Below, I’m copying the output of gdb running the test program.

Thanks for any help.

Eduardo Luiggi

luiggi@cepheid> gdb test
GNU gdb 6.8-debian
Copyright © 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and “show warranty” for details.
This GDB was configured as “i486-linux-gnu”…
(gdb) run
Starting program: /home/luiggi/work/cms/hiMassTauTau/test
[Thread debugging using libthread_db enabled]
[New Thread 0xb4dda6d0 (LWP 31709)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb4dda6d0 (LWP 31709)]
0xb72d1a24 in TClass::AddRef () from /usr/local/bin/root/lib/
Current language: auto; currently asm
(gdb) bt
#0 0xb72d1a24 in TClass::AddRef () from /usr/local/bin/root/lib/
#1 0xb72e3377 in TClassRef::InternalGetClass () from /usr/local/bin/root/lib/
#2 0xb76a06fe in TClassRef::GetClass () from /usr/local/bin/root/lib/
#3 0xb5f055f0 in TBranchElement::InitInfo () from /usr/local/bin/root/lib/
#4 0xb5efc6a8 in TBranchElement::GetInfo () from /usr/local/bin/root/lib/
#5 0xb4c42cc5 in TTreeFormula::FindLeafForExpression () from /usr/local/bin/root/lib/
#6 0xb4c44cb9 in TTreeFormula::DefinedVariable () from /usr/local/bin/root/lib/
#7 0xb64da896 in TFormula::Analyze () from /usr/local/bin/root/lib/
#8 0xb64e5a8a in TFormula::Compile () from /usr/local/bin/root/lib/
#9 0xb4c334e4 in TTreeFormula::Init () from /usr/local/bin/root/lib/
#10 0xb4c3563a in TTreeFormula::TTreeFormula () from /usr/local/bin/root/lib/
#11 0xb4c2abff in TSelectorDraw::CompileVariables () from /usr/local/bin/root/lib/
#12 0xb4c2b304 in TSelectorDraw::Begin () from /usr/local/bin/root/lib/
#13 0xb4c500f1 in TTreePlayer::Process () from /usr/local/bin/root/lib/
#14 0xb4c5c7dc in TTreePlayer::DrawSelect () from /usr/local/bin/root/lib/
#15 0xb5f4478d in TTree::Draw () from /usr/local/bin/root/lib/
#16 0xb5f43eae in TTree::Project () from /usr/local/bin/root/lib/
#17 0x08048ac5 in main () at test.C:12

When doing graphics or using the Tree process classes you must define a TApplication as shown below

[code]#include <TFile.h>
#include <TH1F.h>
#include <TTree.h>
#include “TApplication.h”

using namespace std;

int main(int argc, char argv){
TApplication theApp = new TApplication(“Rint”, &argc, argv);
theFile = new TFile(“zprimeETauAnalysisPatV5.root”);
theTree = (TTree

TH1F* theHisto = new TH1F(“theHisto”, “theHisto”, 100, 0, 500);
theTree->Project(“theHisto”, “eTauMass”);

return 0;

or much simpler (and by far the recommended way), change


and run a normal ROOT session with



Thanks Rene, works great.