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!

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

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

see (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:
This didn’t work and I posted my question.

You proposed to do:
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.