I am running a macro which save several histogram in a root file. But I am not able to save one particular histogram in the root file. I define the histo as:
TH1F *hbfinal_pt1_[BkgType]; //array of bkg histogram pointers with all pt-bins
I can see that the histogram has been plotted correctly but i do not get it inside the root file. However i can save the same type of other histos! Is something wrong with the above piece of code?
While running the macro i only get “potenetial memory leak” warnings.
Hi,
I just solve the problem. I made a short script similar and tried to reproduced the problem . But this time it works.
In the original script I noticed if i define the mentioned piece of code other than the filling/adding part before the following lines,
TFile *fs[maxNoSignalFile];
for(Int_t is=0;is<NoSignalFile;is++) //Run over the different pt-bins files of the signal
{
fs[is] = (TFile*)gROOT->GetListOfFiles()->FindObject(sigFileName[is]);
if (!fs[is])
{
fs[is] = new TFile(sigFileName[is]);
}
TTree *tree = (TTree*)fs[is]->Get(inputTreeName);
:
:
:
where I am reading a tree from a root files, it works(I do no know the reason whay??)
But if i put it after ther reading of tree then it does not write the histo to output root file but fills and draw them correctly.
[quote] But if i put it after ther reading of tree then it does not write the histo to output root file but fills and draw them correctly. [/quote]This is the expected behavior. By default the histogram attach themselves to the current ROOT directory (and file). Opening a ROOT file makes it the current directory. To solve the problem do either:outputFile->cd();
myhisto = new TH1F(....);ormyhisto = new TH1F(....);
myhisto->SetDirectory(outputFile);