Re: Fitting a stack

From: Anna Kreshuk <anna.krechtchouk_at_cern.ch>
Date: Wed, 06 Jul 2005 18:32:25 +0200


Hi Mario,

I'm not sure what you mean by "show a fit separately", but you can access the last histogram of the stack (i.e. the sum of all stacked histos), fit it and use the results. For example, you could do something like:

void fitstack()
{

   TH1D *h1 = new TH1D("h1", "h1", 100, -5, 5);    TH1D *h2 = new TH1D("h2", "h2", 100, -5, 5);    THStack *hstack = new THStack("hs", "hs");    TF1 *f1 = new TF1("f1", "gaus", -5, 5);

   h1->FillRandom("gaus", 10000);
   h2->FillRandom("gaus", 10000);

   hstack->Add(h1);
   hstack->Add(h2);   

   TH1D *hlast = (TH1D*)(hstack->GetStack()->Last());    hlast->Fit(f1);
   hstack->Draw();
} Received on Wed Jul 06 2005 - 18:32:31 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:10 MET