pspe
March 12, 2009, 2:13pm
1
Hi,
I’m using ROOT 5.23/02 and python 2.5.
I want to draw two TH1F (with different binning and scales) produced with two different TChains into the same frame with the following code:
from ROOT import *
w = TChain("events")
w.Add("/afs/cern.ch/user/s/speckmay/public/w/StackAnalysis_piplus_300GeV__002.root")
w.Add("/afs/cern.ch/user/s/speckmay/public/w/StackAnalysis_piplus_300GeV__003.root")
w.SetLineColor(ROOT.kBlack)
canv = TCanvas("showerProfiles","showerProfiles")
print "draw histos... (TTree.Draw) : tungsten"
hw = TH1F("hw","Tungsten",200,0,21.9978 )
w.Draw( "((layer+0.1)/9.091)>>hw","((230<e_mc)&&(e_mc<270))*e_layer/Entries$","goff")
print "retrieve tungsten histogram"
hw = w.GetHistogram()
print "draw histos... (TTree.Draw) : steel"
steel = TChain("events")
steel.Add("/afs/cern.ch/user/s/speckmay/public/s/StackAnalysis_piplus_300GeV__*.root")
steel.SetLineColor(ROOT.kRed)
hs = TH1F("hs","Steel" ,200,0,25.74997)
steel.Draw("((layer+0.1)/7.767)>>hs","((230<e_mc)&&(e_mc<270))*e_layer/Entries$","goff")
print "retrieve steel histogram"
hs = steel.GetHistogram()
hs.SetLineColor(ROOT.kRed)
hw.Draw()
hs.Draw("same")
It breaks with the following errors:
PyROOT> hw.Draw()
TCanvas::ResizePad:0: RuntimeWarning: Inf/NaN propagated to the pad. Check drawn objects.
TCanvas::ResizePad:0: RuntimeWarning: showerProfiles height changed from 0 to 10
PyROOT> hs.Draw(“same”)
TCanvas::ResizePad:0: RuntimeWarning: Inf/NaN propagated to the pad. Check drawn objects.
TCanvas::ResizePad:0: RuntimeWarning: showerProfiles height changed from 0 to 10
*** Break *** segmentation violation
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/18168/exe, process 18168
[Thread debugging using libthread_db enabled]
[New Thread -1208740160 (LWP 18168)]
[New Thread -1212142688 (LWP 18175)]
0x00ad07a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
Thread 2 (Thread -1212142688 (LWP 18175)):
#0 0x00ad07a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x00d46c1f in sem_wait@GLIBC_2.0 () from /lib/tls/libpthread.so.0
#2 0x00648aef in PyThread_acquire_lock (lock=0x9ad40a0, waitflag=1) at Python/thread_pthread.h:334
#3 0x00617703 in PyEval_RestoreThread (tstate=0xa152e88) at Python/ceval.c:312
#4 0x00aca1dd in time_sleep (self=0x0, args=0xb7c1878c) at /build/LCG/Python-2.5/Modules/timemodule.c:920
#5 0x005d54fa in PyCFunction_Call (func=0xb7c05d8c, arg=0xb7c1878c, kw=0x0) at Objects/methodobject.c:108
#6 0x0061e6f0 in PyEval_EvalFrameEx (f=0xa1ffe34, throwflag=0) at Python/ceval.c:3566
#7 0x0061f865 in PyEval_EvalCodeEx (co=0xb7eec968, globals=0xb7eef8ac, locals=0x0, args=0xb7cb5f58, argcount=1, kws=0x9b2a7d0, kwcount=0,
defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2833
#8 0x005c3a70 in function_call (func=0xb7caa4fc, arg=0xb7cb5f4c, kw=0xb7ca4714) at Objects/funcobject.c:517
#9 0x005a569c in PyObject_Call (func=0x0, arg=0xb7cb5f4c, kw=0xb7ca4714) at Objects/abstract.c:1860
#10 0x0061c34b in PyEval_EvalFrameEx (f=0xa1ffcd4, throwflag=0) at Python/ceval.c:3846
#11 0x0061f125 in PyEval_EvalFrameEx (f=0xa1ffb44, throwflag=0) at Python/ceval.c:3652
#12 0x0061f865 in PyEval_EvalCodeEx (co=0xb7cbac38, globals=0xb7c97d74, locals=0x0, args=0xb7c05718, argcount=1, kws=0x0, kwcount=0,
defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2833
#13 0x005c3a70 in function_call (func=0xb7c104c4, arg=0xb7c0570c, kw=0x0) at Objects/funcobject.c:517
#14 0x005a569c in PyObject_Call (func=0x0, arg=0xb7c0570c, kw=0x0) at Objects/abstract.c:1860
#15 0x005af8ad in instancemethod_call (func=0xb7eeb84c, arg=0xb7c0570c, kw=0x0) at Objects/classobject.c:2493
#16 0x005a569c in PyObject_Call (func=0x0, arg=0xb7f0102c, kw=0x0) at Objects/abstract.c:1860
#17 0x00617a04 in PyEval_CallObjectWithKeywords (func=0xb7eeb84c, arg=0xb7f0102c, kw=0x0) at Python/ceval.c:3435
#18 0x0064daf6 in t_bootstrap (boot_raw=0xa111588) at ./Modules/threadmodule.c:423
#19 0x00d423cc in start_thread () from /lib/tls/libpthread.so.0
#20 0x00bb5b3e in clone () from /lib/tls/libc.so.6
Thread 1 (Thread -1208740160 (LWP 18168)):
#0 0x00ad07a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
But, if i TChain.Add only one file to the first chain (“w”) instead of two (or more), the code works fine and the histograms are drawn as I want. I put some of the ROOT files which I used into my public folder, so the code should (not) work as posted.
What am I doing wrong?
thanks,
Peter
pcanal
March 12, 2009, 5:39pm
2
Hi,
The problem is most likely dues to a problem with the current handling of Entries$ in the case of chains.
You can work around the problem simply by calling w.GetEntries() before using Entries$ in TTree::Draw:
w = TChain("events")
w.Add("/afs/cern.ch/user/s/speckmay/public/w/StackAnalysis_piplus_300GeV__002.root")
w.Add("/afs/cern.ch/user/s/speckmay/public/w/StackAnalysis_piplus_300GeV__003.root")
w.GetEntries()
w.SetLineColor(ROOT.kBlack)
canv = TCanvas("showerProfiles","showerProfiles")
print "draw histos... (TTree.Draw) : tungsten"
hw = TH1F("hw","Tungsten",200,0,21.9978 )
w.Draw( "((layer+0.1)/9.091)>>hw","((230<e_mc)&&(e_mc<270))*e_layer/Entries$","goff")
Cheers,
Philippe.
pcanal
March 12, 2009, 7:03pm
3
Hi,
This problem has been resolved in the SVN trunk.
Cheers,
Philippe.
pspe
March 13, 2009, 8:31am
4
Hi,
Your fix solved my problem.
Thanks for the quick response and solution.
Peter