From $ROOTSYS/tutorials/gl/gviz3d.C

// Simple TStructViewer tutorial

#include <TRandom.h>
#include <TList.h>
#include <TROOT.h>

// Function creating elements of lists
void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList) {
   const Int_t ncl =12;
   const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
      "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
      Int_t nobj = gRandom->Uniform(0,maxObjects);
      for (Int_t i=0;i<nobj;i++) {
         if (maxDepth && gRandom->Rndm() < pList) {
            TList *slist = new TList();
            slist->SetName(Form("list_%d_%d",maxDepth,i));
            list->Add(slist);
            MakeCrazy(slist,maxDepth-1,maxObjects,pList);
         } else {
            Int_t icl = (Int_t)gRandom->Uniform(0,ncl);
            TNamed *named = (TNamed*)gROOT->ProcessLine(Form("new %s;",clnames[icl]));
            named->SetName(Form("%s_%d_%d",clnames[icl],maxDepth,i));
            list->Add(named);
         }
      }
}

// function creating a hierachy of objects to test the TStructViewer
TList *crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2) {
   TList *list = new TList();
   list->SetName("SuperList");
   MakeCrazy(list,maxDepth,maxObjects,pList);
   gROOT->GetListOfTasks()->Add(list);
   return list;
}
// function adding colors to viewer
void FillColorsMap(TStructViewer* sv)
{
   // Fills list fColors with TStructNodeProperty
  const Int_t ncl =12;
  const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
    "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};

  for (int i = 0; i < ncl ; i++) {
    sv->SetColor(clnames[i], (Int_t)gRandom->Integer(8)+2);
  }
}


void gviz3d()
{
   // Loading library needed by TStructViewer
   gSystem->Load("libGviz3d");
   // Creating a pointer to list
   TList* pointer = crazy(2,10);
   // Creating a viewer
   TStructViewer* sv = new TStructViewer(pointer);
   // adding colors
   FillColorsMap(sv);
   sv->Draw();
}
 gviz3d.C:1
 gviz3d.C:2
 gviz3d.C:3
 gviz3d.C:4
 gviz3d.C:5
 gviz3d.C:6
 gviz3d.C:7
 gviz3d.C:8
 gviz3d.C:9
 gviz3d.C:10
 gviz3d.C:11
 gviz3d.C:12
 gviz3d.C:13
 gviz3d.C:14
 gviz3d.C:15
 gviz3d.C:16
 gviz3d.C:17
 gviz3d.C:18
 gviz3d.C:19
 gviz3d.C:20
 gviz3d.C:21
 gviz3d.C:22
 gviz3d.C:23
 gviz3d.C:24
 gviz3d.C:25
 gviz3d.C:26
 gviz3d.C:27
 gviz3d.C:28
 gviz3d.C:29
 gviz3d.C:30
 gviz3d.C:31
 gviz3d.C:32
 gviz3d.C:33
 gviz3d.C:34
 gviz3d.C:35
 gviz3d.C:36
 gviz3d.C:37
 gviz3d.C:38
 gviz3d.C:39
 gviz3d.C:40
 gviz3d.C:41
 gviz3d.C:42
 gviz3d.C:43
 gviz3d.C:44
 gviz3d.C:45
 gviz3d.C:46
 gviz3d.C:47
 gviz3d.C:48
 gviz3d.C:49
 gviz3d.C:50
 gviz3d.C:51
 gviz3d.C:52
 gviz3d.C:53
 gviz3d.C:54
 gviz3d.C:55
 gviz3d.C:56
 gviz3d.C:57
 gviz3d.C:58
 gviz3d.C:59
 gviz3d.C:60
 gviz3d.C:61
 gviz3d.C:62