TTree::Draw() e1:e2:e3 into TH2

Hi all,

in the TTree::Draw() reference I see that, when varexp = “e1:e2:e3”, it produces an unbinned 3-d scatter-plot.

I would like to know if it is possible to transform this scatter plot into a TH2 histogram, where e3 is the bin content.

I have managed to do ttree->Draw(“e1:e2:e3>>myTH2”,"",“colz”), but myTH2 binning is lost.

Thanks for the help!
Mateus

Maybe one of these (option 1 or 2) does what you want:

T->Draw("a:b:c>>myh");
myh->Draw();
// option 1:
myh->Project3D("yz");  // y=a, z=b, (x=c); creates a TH2D named myh_yz
myh_yz->Draw("colz");
// option 2:
myh->Project3DProfile("yz");  // creates a TH2DProfile named myh_pyz
myh_pyz->Draw("colz");

see https://root.cern.ch/doc/master/classTH3.html#a94dd0a21d42fd95756e906e7f50fa293 (Project3DProfile is below).

tree->Draw("y : x >> someTH2", "z", "colz");

1 Like

Thank you for the replies.
I think a combination of both will take me where I want.

@Wile_E_Coyote, just to confirm, with your suggestion it is not possible to do cuts on a given branch, correct?

I am familiar with selection… but it seems I can’t do a selection together with what you proposed.
What I have is X Y coordinates (column and row) of my pixel detector with the hit energy being measured on each pixel. And I have several frames with this info.

So my plan was to do:
hits->Draw(“col:row:energy>>pixel_map”,“frame==1000”,“colz”)
This didn’t work and I posted my question.

You proposed to do:
hits->Draw(“col:row”,“energy”,“colz”)
And this works fine.

How should I combine the two commands?
hits->Draw(“col:row”,“energy && frame==1000”,“colz”)?
This simply takes the frame selection and ignores the energy value

"energy * (frame==1000)"

See the “selection” description and examples in: TTree::Draw

That is great! Thanks a lot!
Sorry for overlooking this.
I will read the description more carefully once more to find this explanation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.