Pyroot, TChain problems when overlaying two histograms

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:

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

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.

Hi,

This problem has been resolved in the SVN trunk.

Cheers,
Philippe.

Hi,

Your fix solved my problem.

Thanks for the quick response and solution.
Peter