I have some problems trying to put a stat box on an histogram read out from a root file. Here is what I do:
TFile *f = new TFile("TemperatureB3.root");
TPaveStats *stat = (TPaveStats*)DeltaT->GetListOfFunctions()->FindObject("stats");
This (I expected…) would retrieve the histogram and put back the stat box which was on it when it was originally created. Instead, I get:
Error: illegal pointer to class object stat 0x0 366
In the macro where the plot was first created, there was a stat box on it (actually a fit parameter box). Why can’t it find it back?
I tried to reproduce your problem with the following macro:
TCanvas *c1 = new TCanvas("c1","performance",10,10,800,600) ;
TPaveStats *st = (TPaveStats*)hpx->GetListOfFunctions()->FindObject("stats") ;
For me it works , “st” is defined. hsimple.root is the file generated by $ROOTSYS/tutorials/hsimple.C .
What is your histogram DeltaT ?
has it something special ?
The “stats” box is only generated when the canvas is effectively paint.
In your script, you should add the following line after your hpx->Draw call.
oops … yes of course… I did try in interactive mode… outside a script (I made the script afterwards)
I tried adding the c1->Update(); to my macro but I still get the same result.
The plot DeltaT is filled and then drawn using the following code:
TH1F *B3DeltaTCorr = new TH1F("DeltaT","Temperature variation distribution",100,-5,5);
The … just means that there is other code lines creating different plots in between. Is there anything wrong with this in the first place?
I notice that in your hsimple.C file, you are using hfile->Write(); instead of hpx->Write(); . What is the difference? In my macro, I am opening the root file, then writing all histos using histoname->Write(); then I close the file using f->Close(); . Appart from this, I don’t see any differences between your macro and mine that could generate the problem. Am I missing something here?
Thanks for your help,