Hi Rodger, Rene:
That's very useful. However, Rodger, one still has to be careful to cache the covariance in the histogram immediately after doing the fit (as Rene example does). You can't do a bunch of fits and then go back and recover the covariance matrix.
-Art
A.E. Snyder, Group EC \!c*p?/ SLAC Mail Stop #95 ((. .)) Box 4349 | Stanford, Ca, USA, 94309 '\|/` e-mail:snyder_at_slac.stanford.edu o phone:650-926-2701 _ http://www.slac.stanford.edu/~snyder BaBar FAX:650-926-2657 Collaboration
On Tue, 6 Feb 2007, Rene Brun wrote:
> Arthur E. Snyder wrote:
> > One thing you want to be careful of is if you wish to keep the covariance
> > matrix. If you've done another fit keeping your TF1 won't keep
> > convariance. TF1 caches the errors and values but not the full convariance
> > matrix. This could be a problem if, e.g, you wanted to do a systematic
> > study by varying fit parameters according to correlated errors. It would
> > not be hard to had covariance cache to TF1 and perhaps it will be done
> > someday. In the meanwhile if you want to keep covariance you have to hang
> > on to it for yourself.
> >
> Art, Roger,
>
> See the small script cov.C below showing how to save the covariance
> matrix with the fitted histogram.
>
> Rene Brun
>
> //macro cov.C
> void cov() {
> // shows how to save the Fit covariance matrix as an object
> // in the histogram list of functions
>
> covwrite();
> covread();
> }
>
> void covwrite() {
> // shows how to save the Fit covariance matrix as an object
> // in the histogram list of functions
>
> TH1F *h = new TH1F("h","sho cov matrix",100,-3,3);
> h->FillRandom("gaus",5000);
> h->Fit("gaus");
> TVirtualFitter *fitter = TVirtualFitter::GetFitter();
> TMatrixD *matrix = new TMatrixD(3,3,fitter->GetCovarianceMatrix());
> h->GetListOfFunctions()->Add(matrix);
> h->GetListOfFunctions()->ls();
> TFile f("h.root","recreate");
> h->Write();
> }
>
> void covread() {
> TFile *f = TFile::Open("h.root");
> TH1F *h = (TH1F*)f->Get("h");
> h->Draw();
> TMatrixD *m =
> (TMatrixD*)h->GetListOfFunctions()->FindObject("TMatrixT<double>");
> m->Print();
> }
>
> > -Art
> >
> >
> > [a] I'm usually just a consumer of root help, but since this one is
> > something I knew about I thought I try to help out. A real root expert
> > might have more or better answers.
> >
> > A.E. Snyder, Group EC \!c*p?/
> > SLAC Mail Stop #95 ((. .))
> > Box 4349 |
> > Stanford, Ca, USA, 94309 '\|/`
> > e-mail:snyder_at_slac.stanford.edu o
> > phone:650-926-2701 _
> > http://www.slac.stanford.edu/~snyder BaBar
> > FAX:650-926-2657 Collaboration
> >
> >
> >
> > On Tue, 6 Feb 2007, Roger Mason wrote:
> >
> >
> >> Hello Art,
> >>
> >> "Arthur E. Snyder" <snyder_at_slac.stanford.edu> writes:
> >>
> >>
> >>> Well in c/c++ an array is just a pointer with a certain amount of space
> >>> reseved beyond it. So GetParErrors give you a pointer (i.e. the array held
> >>> by your TF1 object (fParErrors)).
> >>>
> >> I'm still at the stage with c++ where the pointer syntax, combined
> >> with object syntax, eludes me. Such was the case here.
> >>
> >>
> >>> If you want a copy that will not go away when your TF1 goes away (to be
> >>> safe) then I think you just have to copy it element by element, or use it
> >>> to construct a TMatrix or TVector or something.
> >>>
> >> Well, as long as I have the TF1 in the root file I am OK because I can
> >> always extract the parameters and errors and dump the into a text
> >> file. Why do I need this? Because I always tabulate results in
> >> drafts of my publications just so the referees can tell me to toss
> >> 'em and keep the pictures.
> >>
> >>
> >>> If your a fortran old-foggie like me this can be very confusing!
> >>>
> >>>
> >> Fortran was my first programming language too. I'm just glad that
> >> root is'nt written in Java.
> >>
> >> Thanks again,
> >> Roger
> >>
> >>
> >>
>
>
Received on Tue Feb 06 2007 - 23:04:12 CET
This archive was generated by hypermail 2.2.0 : Wed Feb 07 2007 - 05:50:01 CET