histogram fillstyle after reading

From: Gerhard Brandt <gbrandt_at_mail.desy.de>
Date: Thu, 09 Feb 2006 16:07:10 +0100

hi,

i've got a problem that seems very basic but i can't find the solution:

does anyone have a working example of how to read a histogram from a file and change the style so it is filled? changing markers, linewidth etc. works but i can't get it filled.

i am using ROOT 4.00.08 (in a brief scan of CVS messages in histpainter i saw no obvious fixes since then). macro below.

thanks !

gerhard

{

    gROOT->Reset();
    gROOT->SetStyle("Plain");
    gStyle->SetHistFillStyle(1001);
    gStyle->SetHistFillColor(2);
    gROOT->ForceStyle();

    TCanvas *canv = new TCanvas("canv", "canvas", 800, 600);     canv->UseCurrentStyle();

    TFile file1("histo.root");

    TIter keys(file1->GetListOfKeys());
    TKey* key;
    while ( key = (TKey*)(keys.Next()) ) {

       // Read histos
       if ( !strcmp(key->GetClassName(), "TH1F") ) {
         TString str(key->GetName());

         TH1F *hist1 = static_cast<TH1F*>(file1->Get(str));
         if ( !hist1 ) {
           cout << "Could not find "<<str<<" in "<<file1->GetName()<<endl;
           continue;
         }
         cout << str << endl;

         hist1->SetDirectory(0);
         hist1->SetFillColor(42);

         cout << hist1->GetFillColor() << endl;
         cout << hist1->GetFillStyle() << endl; // this prints 1001 allright

         hist1->Draw();

      }

    }
} Received on Thu Feb 09 2006 - 16:07:27 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET