I have a stupid problem. I am using ROOT 5.28.00a and I am using a compiled C++ code.
In my code I am doing :
…
// Define “root” as an instance of TROOT
TROOT root(“myroot”,“myroot”);
TApplication MonApp(“MonApp”,0,0);
…
FeldmanCousins fc(*data,*mc);
…
fc.CreateConfBelt(true); // save the information in the belt for plotting
fc.SaveBeltToFile(true);
the last RooStats function is saving histograms by doing the following : slac.stanford.edu/grp/eg/mi … uction.cxx
TFile* f=0;
if(fSaveBeltToFile){
oocoutI(f,Contents) << “NeymanConstruction saving ConfidenceBelt to file SamplingDistributions.root” << endl;
f = new TFile(“SamplingDistributions.root”,“recreate”);
}
When I run my code I get the following ERROR :
Error in TROOT::WriteTObject: The current directory (MonApp) is not associated with a file. The object (Profile Likelihood Ratio) has not been written.
How could I save this file when running my compiled C++ (I don’t have any problem when running my a similar ROOT macro). I guess I will have to associate MonApp with an output file but I was not able to see how to do it.
I putted my code of afs CERN :
/afs/cern.ch/user/t/tarrade/public/Test
copy this directory (you need 5.28.00a)
cd Test
make
./MakeRooStatsLimits test.root 120 output.root 5
and you will see :
Error in TROOT::WriteTObject: The current directory (MonApp) is not associated with a file. The object (Profile Likelihood Ratio) has not been written.
Error in TROOT::WriteTObject: The current directory (MonApp) is not associated with a file. The object (hist_Profile Likelihood Ratio) has not been written.
I also realized that if I comment out this line :
toymcsampler->SetProofConfig(&pc); // enable proof
the problem disappear! So it seems to be a problem how I am running my compile code using some proof stuff (using muli core one one machine)
The most direct solution is to add mydirectory->cd();before you calls to Write in order to make sure that gDirectory is correctly setup (where ‘mydirectory’ is a pointer to the output TFile or a subdirectory of the output TFile).