DrawHistos

From NETier2

{

   TFile* f=new TFile("RootHistos.root","READ");
   TDirectory* mdt=f->GetDirectory("MDT");

   TCanvas* canv=new TCanvas("canv");
   TPostScript* ps=new TPostScript("/usatlas/workarea/roberth/histos.ps",112);
   int npage=0;

   TIter nextkey(mdt->GetListOfKeys());
   TKey *key;
   while (key = (TKey*)nextkey()) {

    cout<<"key: "<<key->GetName()<<endl;

    TDirectory *chamberdir = (TDirectory*)key->ReadObj();

     TIter nexthistkey(chamberdir->GetListOfKeys());
     TKey* histkey;
     int nhist=0;
     int ipad=0;
     int nentries=0;

    while (histkey = (TKey*)nexthistkey()) {

       cout<<"histkey: "<<histkey->GetName()<<endl;
       TObject* obj=histkey->ReadObj();

       if (nhist==0) {
         if ( obj->IsA()->InheritsFrom( "TH1" ) )
         nentries=((TH1*)obj)->GetEntries();
       }

      if (nentries<100) continue;

       if (nhist==0) {
         // make new page in ps
         if (npage>0) ps->NewPage();
         canv->Clear();
         canv->SetFillColor(10);
         npage++;

        nhist=chamberdir->GetListOfKeys()->GetSize();

         if      (nhist<=4) canv->Divide(2,2);
         else if (nhist<=6) canv->Divide(2,3);
         else if (nhist<=8) canv->Divide(2,4);
         else { cout<<"too many hists... skipping"<<endl; continue;}
         ipad=0;
       }

       canv->cd(++ipad);
       obj->Draw();
       canv->Update();
     }
   }
   ps->Close();
}