Slice of TH3D

Hi,

I am taking the xy plane of a TH3D histogram by iterating through each bin on the plane and putting the contents into a TH2D respectively.

    rootValXY=r.TH2D("xyPlane","xy plane",f.binN.x,f.minL.x,f.maxL.x,f.binN.y,f.minL.y,f.maxL.y)
    for y in range(0,f.binN.y):
        for x in range(0,f.binN.x):
            binXY=f.histObj.GetBinContent(f.histObj.GetBin(x+1, y+1, f.binN.z/2))
            rootValXY.SetBinContent(rootValXY.GetBin(x+1,y+1), binXY)

Then when I say:

    c2=r.TCanvas("c2")
    r.gStyle.SetOptStat(0)
    rootValXY.SetContour(10)
    rootValXY.DrawCopy("colz")
    rootValXY.Draw("cont3 same")
    rootValXY.Draw()
    rootValXY.SetLineColor(r.kRed)
    c2.Print("test.png")

test.png looks like the attached picture.

It seems like it disregards the formatting code. This formatting worked for TH2D which was a result of Project3D of TH3D which is essentially the same right?


Hello,

We’ll have a look at it with the graphics expert and get back to you on Monday.

Thank you,

Enric

I am not sure what you mean by “It seems like it disregards the formatting code”…

Hi,

Because with that code I would expect it to look somewhat like the top row on this:


Can you provide a running sample reproducing the problem ?

Hi,

Attached the small code and root file and the output picture.

#!/usr/bin/env python
import ROOT

fileObj=ROOT.TFile("2dxyplane.root")
histObj=fileObj.Get("xyPlane")
c2=ROOT.TCanvas("c2")
ROOT.gStyle.SetOptStat(0)
histObj.SetContour(10)
histObj.DrawCopy("colz")
histObj.Draw("cont3 same")
histObj.Draw()
histObj.SetLineColor(ROOT.kRed)
c2.Print("test.png")


2dxyplane.root (157 KB)
example.py (294 Bytes)

{
   TFile *f = new TFile("2dxyplane.root");
   gStyle->SetOptStat(0);
   xyPlane->SetContour(10);
   xyPlane->DrawCopy("colz");
   TH2D *h2 = (TH2D*)xyPlane->DrawClone("cont3 same");
   h2->SetLineColor(2);
   gPad->Modified(); gPad->Update();
}