[ROOT] histograms always empty when compiling and running a macro

From: Andreas WILDAUER (andreas.wildauer@cern.ch)
Date: Tue May 04 2004 - 10:53:39 MEST


Hi all,

I have the following problem:

I am trying to write a macro which reads a root ntuble file and creates some 
histograms. When I compile an execute the scripts the histograms are always 
empty.

I know this has something to do with the fact that after the program finishes 
the histo go out of scope, but I dont know how to fix it.

I need (a want to) compile because I am using things like std::vector aso.
The ntuple looks ok when I check it with TBrowser.

Thanks in advance
Andi


Heres how I try to do it:

 // Standard Includes
#include "TFile.h"
...

void printHistos(void)
{
TFile f( ... right path to the file ...  );

t = (TTree*)f.Get("t3333");

std::vector<TH1F*>*  myHistos = new std::vector<TH1F*>;
std::vector<TString> histoTitles;

histoTitles.push_back("d0");
histoTitles.push_back("z0");

TCanvas* canv = new TCanvas("m_canv", "Track Plots", 200, 200, 700,320);
canv->Divide(5,2);

t->Draw("Trk_d0>>h1(100,-3.,3.)","","");
myHistos->push_back((TH1F*)gDirectory->Get("h1"));

t->Draw("Trk_z0>>h2(100,-3.,3.)","","");
myHistos->push_back((TH1F*)gDirectory->Get("h2"));

int count = 1;
 for (std::vector<TH1F>::iterator fz = myHistos->begin();
     fz != myHistos->end(); ++fz)
 {
  canv->cd(count);
  (*fz).Draw();
  ++count;
 }
}
-- 

=======================================================================
Andreas Wildauer
    CERN/PH ATC, mailbox E25310, CH-1211 Geneva 23, Switzerland
    office 40 3-D06
    email  Andreas.Wildauer@cern.ch
    tel    +41 22 76 71779
=======================================================================



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:07 MET