Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-25 09:24:25

0001 #include <TCanvas.h>
0002 #include <TList.h>
0003 #include <TString.h>
0004 
0005 void SaveHistogramsFromList(TList &l, TString prefix) {
0006     TObject* obj = nullptr;
0007     TIter next(&l);
0008 
0009     while ((obj = next())) {
0010         if (obj->InheritsFrom(TH1D::Class()) || obj->InheritsFrom(TH2D::Class())) {
0011             TH1* hist = (TH1*)obj;
0012 
0013             TString name = hist->GetName();
0014             TString canvasName = name + "_canvas";
0015 
0016             TCanvas* c = new TCanvas(canvasName, canvasName, 800, 600);
0017             c->cd();
0018 
0019             if (hist->InheritsFrom(TH2::Class()))
0020                 hist->Draw("COLZ");
0021             else
0022                 hist->Draw();
0023 
0024             TString filename = prefix + name + ".png";
0025             c->SaveAs(filename);
0026 
0027             delete c;
0028         }
0029     }
0030 }
0031