Using "file->Get()" with compiled code

Hello ROOTers,

I would very much appreciate some help on a small problem with a standard physics analysis.

Within the analysis I process two data sets, loaded separately within a class header file using TChain. The first set is run through and a .root file of histograms written to. The second run accesses this .root file using:

TFile *myfile = new TFile("mydata.root");

The histograms within this file are then drawn in the second run using:

TH1F* mypointer = static_cast<TH1F*>(myfile->Get("myhist")); myhist->Draw("E1");

When I load my .C file using:

Everything is okay, ROOT sorts things out for me. However, it takes much longer. So compiling using:

Improves the run-time greatly. The problems is, the following error is raised:

`myhist' was not declared in this scope warning: unused variable mypointer

Any help with this matter would be much appreciated. I am running version 5.22/00.
Thanks for your time,

Peter

Hello again,

I’ve found a resolution to the problem. Not a big one at that!

Thanks anyway,

Peter

Hi,

Rather thanTH1F* mypointer = static_cast<TH1F*>(myfile->Get("myhist")); myhist->Draw("E1"); you should use:TH1F* mypointer; myfile->GetObject("myhist",mypointer); mypointer->Draw("E1"); . Note that the real problem (for the compile code) is that you are not using the variable you just declared!

Cheers,
Philippe.

Hi Philippe,

Thanks for the tips. And yes, like I said - it wasn’t a big problem in the end! Previously, before I had compiled the code, ROOT must have worked round my error for me and used the pointer instead. Was a bit of an “oh, right” moment when I realised.

Cheers,

Peter