Hello,
I’m trying to add several similar histograms from different root files, but I’m facing a problem when closing the input file. It looks the object is being deleted when I close the input file.
Here is an extract of the code to reproduce the problem. It can be run using the input file attached.
[code]#include
#include “TFile.h”
#include “TH2D.h”
#include “TCanvas.h”
#include “TApplication.h”
using namespace std;
int main() {
TApplication app(“test”,0,0);
TH2D *myHisto;
TCanvas *c1=new TCanvas(“c1”,“c1”,800,600);
c1->SetFillColor(0);
TFile myfile(“input.root”,“READ”);
if(!myfile.IsOpen()) {
cerr<<“Error, could not read input file”<<endl;
return 1;
}
TH2D hist_tmp;
myfile.GetObject(“mh2AccAZLambda_00”,hist_tmp);
if(!hist_tmp) return 1;
myHisto=new TH2D(((TH2D*)hist_tmp->Clone(“mh2AccAZLambda_00_copy”)));
myfile.Close();
myHisto->DrawCopy(“colz”); app.Run();
return 0;
}
[/code]
when I run it I have the following error:
[quote]==> Dumping object at: 0x0000000011652300, name=TObject, class=TObject
fUniqueID 0 object unique identifier
fBits 0x01000208 bit field status word[/quote]
If I exchange the following lines, it runs fine (but I need to encapsulate this in a loop, so this is not a solution for me).
myfile.Close();
myHisto->DrawCopy("colz"); app.Run();
I tried to look in the documentation and the forum without success. Any idea of what I am doing wrong?
EDIT: If this matters, I’m using 5.28/00c on Lyon cluster.
Thanks,
Colas
mini.tar.gz (1.39 MB)