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.