Problem with TFitResultPtr Branch

Hello dear Rooters,

I have a problem I can’t solve and I’ve ran out of ideas…

I make a fit from which then I get a TFitResultPtr and save it into a branch of my output root file. When I compile the whole code and I run the executable which generates the root file along with the fitResultPtr branch, I get a nice print which makes me believe that the fitResultPtr has been correctly allocated. Then, I wrote another code .C to read the root file and plot a TGraph along with its fit function (in a TGraph branch) from which I get the fitResultPtr, and I read the TFitResultPtr branch too calling later Print(“V”). When I do this I run into a segmentation fault that may arise from not allocating correctly the TFitResultPtr instance at a given event (as soon as I don’t make any call of the read TFitResulPtr, there’s no segmentation fault and the TGraph with its fit function are plotted correctly).

I know just this description is not clear enough to figure out what’s going on, so I attach here the codes. There’s a lot of trash, so ignore the commented lines. The relevant lines are pointed out. Let me know if you want all the files to run the program. It’s a huge directory!!

Obs: My ROOT version is 5.30, so TFitResult and TFitResultPtr are already implemented. Weirdly, I cannot use the line fitResult->Print(“V”); where fitResult is a TFitResultPtr instance, it gives me an error when compiling. :S

There’s an inconsistency between these websites:
root.cern.ch/root/v526/Version526.news.html , see section “new classes TFitResult, TFitResultPtr”
root.cern.ch/root/html/TGraph.html#TGraph:Fit, see “TFitResultPtr Fit(), Access to the fit result”
One of them says that TGraph(or TH1)::Fit returns a TFitResult instance and the other one says that it returns a TFitResultPtr instance.
readTreeAnalysis.C (1.87 KB)
analysis.cxx (22.6 KB)

Take a look at this .cxx file instead of the one I attached in the last post. Thanks!
analysis.cxx (14.7 KB)

I solved the problem.

Every entry of the tree is one-to-one with an binary file which has the profile output from an oscilloscope. Some of these entries have superpositions, which are detected and labelled by my code. Then, I write two branches (among others), one with a TMultiGraph and another with a TFitResultPtr. TMultiGraph has the TGraph of the superposition data along with the fit function (there can be more than one group of pulses overlapping in an entry). TFitResultPtr corresponds to the fit for the superposition. When I read the generates branches, my code was

(see readTreeAnalysis.C)



  for(Long64_t i = 0; i < nentries; i++){

                BfitResult->GetEntry(i);
                BMultiGOverlap->GetEntry(i);

                GList = (TList*)MultiGOverlap->GetListOfGraphs();
                GIter = new TIter(GList);

                GIter->Reset();
                while((GOverlap = (TGraph*)GIter->Next()) != NULL){
                        GOverlap->SetMarkerStyle(20);
                        GOverlap->SetMarkerSize(1);
                        GOverlap->SetMarkerColor(1);
                        GOverlap->Draw("P");
                }

                if(fitResult != NULL){
                        printf("Iteration%d\n", i);
                        fitRes = fitResult->Get();
                        fitRes->Print("V");
                }
        }

The segmentation fault was at fitRes->Print("V"); because fitRes was NULL. I assumed that when filling the tree, in absence of superposition fitResult was NULL, but actually was not and that’s why this condition was always fulfilled if(fitResult != NULL). Then, I changed the condition to if(fitResult->Get() != NULL) and now everything is working.

The strange thing to me is that in absence of superposition, the TFitResultPtr* instance is NOT NULL but the TFitResult* from it is so. I would’ve expected the TFitResultPtr* instance to be NULL. Why not? What is it so? In absence of superposition TGraph* was NULL as expected and that’s why the condition while((GOverlap = (TGraph*)GIter->Next()) != NULL) worked.

Any ideas on it?

Thanks in advance.