Drawing TH2D to file with "colz" option


I’m trying to write/draw a TH2D to a .root file but I’m unable to do so. What I do with TH1D is something like:

[code]TFile *input_file = TFile::Open(“something.root”, “read”);
TTree input_tree = (TTree)input_file->Get(“tree”);
TFile *output = new TFile(“anything.root”, “RECREATE”);

TH1D *my_histogram = new TH1D(“my_histogram”, “histogram title”, 1000, 0, 1000);


For TH2D I was trying:

but it doesn’t work. Could you please be so kind as to point me in the right direction?



Thank you for the link. I read it and got the impression that the following should work:

It doesn’t work though. What am I doing wrong here?

input_tree->Draw(“my_variable:my_variable2>>my_histogram2”, “”, “colz”);
BTW. Do remember that it’s “Y:X” (and not “X:Y”).

Thank you.

I had tried that before but it didn’t work. I finally figured what’s going on. I’m viewing the histograms using the TBrowser. For some reason, “colz” is not working there. I have to use “my_histogram->SetOption(“colz”);”…

Thank you again.

1 Like