gDirectory TTree and Eventlist (or histogram)

Dear Rooters,

I am writing an application based on the hadd macro. My problem is the following instead of adding histograms, I would like to retrieve a value from a tree for a given histogram.

	if(tree) {
 
	  tree->Draw("Height>>temp","", "entrylist",10000000);
	  TEventList *elist = (TEventList*)gDirectory->Get("temp");

	  if(!elist) {
	    std::cerr << "No list found" << std::endl;
	  } else {
             // do something with the list
	  }

The tree exists, but I always get the “no list found” message, even with no selection at all. I ‘cd’ into the file containing the tree, making sure I am in the right directory, but this does not help. I am working with ROOT 5.18 and I compile the code to have it stand-alone using [quote]g++ hadd.C -g root-config --cflags --libs[/quote]

Is there anything wrong with the above code, or what else can be the source of the non-creation of the list?

The same behavior occurs when I try to create a histogram using the >> syntax

Any hints appreciated.

Cheers,

Erik

Hi,

This is due to the line:TH1::AddDirectory(kFALSE);You should do:TH1::AddDirectory(kTRUE); tree->Draw("Height>>temp","", "entrylist",10000000); TH1::AddDirectory(kFALSE);

Cheers,
Philippe.

Hi Philippe,

indeed indeed. I did not pay attention to the beginning of the macro.

Thanks,

Erik