How to save canvas (or histogram) in a tree?

I am just curious to know if it is possible to save the canvas or histogram in a tree. I mean currently, I am writing the canvas (or histogram) directly in a root file, without creating a tree. Here is the pseudo-code of what I am doing,

TFile *f1 = new TFile("test.root", "RECREATE");
TCanvas *can = new TCanvas("can", "can", 750, 500);
// Add histogram to the canvas
can -> Write();

As you can notice, there is no TTree in the code. It would be more organized if I can save this canvas in different branches of a tree.

Please suggest something. Because my analysis involves a lot of plots.

Thanks,
Divyang.

Saving a Canvas in a ROOT file is the normal way to proceed. Why do you want to save it in a tree?

TTree is meant for datasets with many values per branch, if you only fill each branch with one canvas that’s probably not the right structure.

To mimic the organization of TTree and branches you can save different canvases in different sub-directories of a TFile.

Cheers,
Enrico