Projecting from TTree into TH1

Hi,

For convenience, I often call TH1::AddDirectory(0) to turn off Root’s tracking of histogram names. (Root sometimes seems to get confused and I find it safer to just manage the pointers/histograms myself.) However, this seems to make it impossible to project into a histogram from a tree. The TTree::Draw() and TTree:Project() methods rely on histogram names rather than pointers. Why is there no method that simply takes a pointer to the histogram I want to project into?

I can always make my own loop over the tree and fill the histogram myself, but that’s too much overheard for such a simple task.

Is there some easy way to do this?

-tom

We have not yet been able to settle on an API that support all the features needed.

Anyway TTree::Draw looks into the current ROOT directory to find the histos. So you could do (something like):

myhist->SetDirectory(gROOT); ..... TDirectory *keep = gDirectory; gROOT->cd(); mytree->Draw(".... >> myhist".....); keep->cd();

Cheers,
Philippe.