Tree >> histo problem

I am trying to fill a histogram from a tree, but when I try to draw the histogram it is empty. Here is the macro I am using:

void makeplots(char *infilename){
  
  TH1I *h = new TH1I("hist", "Q^{2}", 100, 0, 5);
  TFile *hfile = new TFile(infilename);
  
  // root file contains tree "event"  
  event->Draw("Q2>>hist");
  h->Draw();  
}

I tried replacing

h->Draw();  

with

hist->Draw();

And a correct plot is drawn, but it does not possess the attributes (bins, ranges etc) I specified when defining the histogram h. Is there a way of actually doing this? or do I have to keep using:

event->Draw("Q2>>hist(100,0,5)");

?

Cheers

The issue is that event->Draw("Q2>>hist"); looks for hist in the current directory. Since you didTH1I *h = new TH1I("hist", "Q^{2}", 100, 0, 5); TFile *hfile = new TFile(infilename);The current directory is hfileand your historgram is NOT in that directory (since it was created before your move to the directory by opening the file).

event->Draw("Q2>>hist(100,0,5)"); This is currently the best approach. We hope to add a new interface allowing the specification of the histogram by address to solve this issue.

Philippe.

[quote]This is currently the best approach. We hope to add a new interface allowing the specification of the histogram by address to solve this issue.

Philippe.[/quote]

Thanks for your help, and I look forward to this new feature.