Can TFitResult be saved in a TTree Branch

Dear ROOTers,

instead of copying parameters+errors, chi2, etc… to TTree branches from the TFitResultPtr returned from TH1::Fit(), I wonder if I can just save the whole object into a TTree branch. (The documentation mentions that TFitResult wraps ROOT::Fit::Result together with TNamed for this reason)

But how should I save the TFitResult addressed by TFitResultPtr (via a std::shared_ptr) in a TTree branch? I think that the safest way (I mean to avoid to mess up with shared_ptr ref counts) if to have a separate (initially empty) TFitResult object as branch bucket, and I can copy-assign to it every event before filling.

Something like:

TFitResult fitres; mytree.Branch("fitres", &fitres);
while (/*my loop*/) {
   auto ptrfitres = myhisto.Fit( &myfitmodel, "S" );
   fitres = *ptrfitres //should trigger copy-assignment, right?

Any better idea?



That indeed sounds like the best way of doing it. Alternatively you can create a TFitResultHolder that has a member of type TFitResult* and you simply update the pointer to point to the current TFitResult.

Cheers, Axel.