Viewing TCanvas objects in TBrowser default canvas

Hi,

I am using root to produce some 2d histograms by executing a compiled macro. I am writing these to a root file and viewing them in a TBrowser:have something like this

TFile* fout = new TFile("trans_plots.root","recreate"); //Create the output file TCanvas* c2 = new TCanvas("hCosThetavsPhi_untrans1","hCosThetavsPhi_untrans1",700,400); hCosThetavsPhi_untrans1->Draw("COLZ"); hCosThetavsPhi_untrans->Draw("TEXT SAME"); c2->Write(); delete c2; fout->Close();

My question is, when I write TH2D* objects to the root file I can view them in the TBrowser via the left pane. However, with TCanvas* objects I double click them and they don’t show in the TBrowser window, instead they open up subsequent windows.

How can I get my ‘merged’ histograms to be viewable directly from the TBrowser window? This will greatly speed up analysis.

Cheers.

EDIT: I’ve tried all manner of things like not using a Canvas and using ->SetOption(“COLZ”), ->SetOption(“TEXT SAME”) on my TH2D* objects but the end result only works this way using a Canvas. Even if there’s some way to get the same result by writing the TH2D* objects to file and not using Canvas(es) would be fine.

Hi,

There is actually no way of doing what you’re asking for.

[color=#FF0000]EDIT[/color]: BTW, why do you save the canvas and not the histograms? Then you would obtain the behavior you want…

Cheers, Bertrand.

Sorry for bumping this old topic. It seems it had no resolution; I just want to make sure it still doesn’t.

I would really love to save a view of two superimposed histograms to a .root file. The only way I can see, as OP says, is to save the TCanvas where I’ve previously drawn the two histograms (with the “same” option). This, however, doesn’t make the saved canvas appear in the TBrowser’s default canvas - instead, it pops up a new window.
I don’t quite understand @bellenot’s answer: is there a way to save the histograms already superimposed? The only way I know of is to save the two histograms separately, so I’d have to open the TBrowser, then double click on one to open it in the default canvas, then use the “same” option to draw the other one in the same canvas…

@couet can most probably confirm that you cannot save “superimposed” histograms. But if you have several histogram in a ROOT file, you can superimpose them by putting the SAME option in the drawing option combo box of the TBrowser…

THStack

1 Like

Thank you very much for your answers.

@couet I have read about THStack in these hours, but I am under the impression that it doesn’t solve all use-cases. For example, can you make it work with two TH2 in the OP use-case, ie you want to draw one as COLZ and one as TEXT? Or can it be used with TEfficiency (which is actually something I am working on right now)?

Yes 2D THStack are drawn as LEGO. Saving the canvas as you did is the way to go when you want to mix options. It is true that when you double click on the saved canvas in the TBrowser it will open a separated window. That’s the only “issue”… The graphics result is what you are looking for.