TH1F::Add() using PyRoot

Hello, I am using PyRoot and trying to add the contents of one histogram into another using the Add() method.

>>> from ROOT import *
>>> file=TFile("SingleTopNtuple/SingleTop.ntuple.TDR_000.root")
>>> tree=file.Get("UserData")
>>> histo=TH1F("histo", "", 10, 0, 10)
>>> tree.Draw("elec_num>>histo")
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>>> histo2=TH1F("histo2", "", 10,0,10)
>>> histo2.Add(histo, 1.0)

Then the result is

 *** Break *** segmentation violation
 Generating stack trace...
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
 0x01646409 in TH1::Add(TF1*, double, char const*) + 0x377 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4.03.02/slc3_ia32_gcc3o
 0x016d71a8 in <unknown> from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4.03.02/slc3_ia32_gcc323/root/lib/libHist.so
 0x008eea3f in G__CallFunc::Exec(void*) + 0x71 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4.03.02/slc3_ia32_gcc323/root/lib/o
 0x0040ac75 in PyROOT::MethodHolder::execute(void*) + 0x5d from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4.03.02/slc3_ia32_gcc3.
 0x0040b7e7 in PyROOT::MethodHolder::callMethod(void*) + 0x1f3 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4.03.02/slc3_ia32_.
 0x0040bbbb in PyROOT::MethodHolder::operator()(_object*, _object*) + 0x151 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4.03..
 0x00408cd7 in PyROOT::MethodDispatcher::operator()(_object*, _object*) + 0xcf from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/root/4..
 0x00408ada in PyROOT::MethodDispatcher::invoke(_object*, _object*, _object*) + 0x2a from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/r.
 0x0032ea52 in PyCFunction_Call at Objects/methodobject.c:118 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_go
 0x0030a558 in PyObject_Call at Objects/abstract.c:1756 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/o
 0x00360a88 in <unknown> from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/lib/libpython2.3.so
 0x00360702 in <unknown> from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/lib/libpython2.3.so
 0x0035e804 in <unknown> from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/lib/libpython2.3.so
 0x0035f38f in PyEval_EvalCodeEx at Python/ceval.c:2663 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/o
 0x0035c4ab in PyEval_EvalCode at Python/ceval.c:543 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/libo
 0x00389138 in <unknown> from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/lib/libpython2.3.so
 0x00388415 in PyRun_InteractiveOneFlags at Python/pythonrun.c:758 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_io
 0x003881cd in PyRun_InteractiveLoopFlags at Python/pythonrun.c:694 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_o
 0x00388103 in PyRun_AnyFileExFlags at Python/pythonrun.c:654 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_go
 0x0038fc74 in Py_Main at Modules/main.c:415 from /export/data74/atlas/Athena/10.0.1/sw/lcg/external/Python/2.3.4/slc3_ia32_gcc323/lib/libpytho
 0x080486ba in main + 0x22 from python
 0x0012678a in __libc_start_main + 0xda from /lib/tls/libc.so.6
 0x0804860d in Py_Main + 0x31 from python
Aborted

It seems that the method called is not the right one, TH1::Add(TF1* h1, Double_t c1 = 1, Option_t* option = “”) while I need TH1::Add(const TH1* h1, Double_t c1 = 1)

Could you suggest me what I should do to make it work?
I am using Python 2.3.4 and Root 4.03/02.
Thank you for your help in advance.

Akira

Akira,

this is a problem in the overload resolution in that old version of PyROOT, that has long been fixed since. Please usehisto2.Add( histo2, histo1, 1.0, 1.0 ) I forget the exact semantics, so please check.

HTH,
Wim

Wim

Thank you for your help everytime.
This works fine!

Cheers
Akira