Re: subtraction of fit from histogram

From: Inkyu PARK (Inkyu.Park@bnl.gov)
Date: Fri Mar 17 2000 - 00:13:58 MET


Hi Volker,

 A simple minded solution may be,

 // define your histograms
 
 TH1F h1("h1","",nb,b0,b1);
 TH1F h2("h2","",nb,b0,b1);
 TH1F h3("h3","",nb,b0,b1);
 
 // fill them by your data
 
 h1.Fill(x1);
 h2.Fill(x2);
 
 // define your function and fit h2
 
 TF1 fun("fun","f(x)",b0,b1);
 
 h2.Fit("fun");
 
 // fill hist h3 by function
 
 for (int i=0;i<nb;i++)
 {
   float x=h3->GetBinCenter(i);
   float y=fun->Eval(x);
   h3->Fill(y);
 }
 
 // subtract h3 from h1
 
 h1->Add(h3,-1);
 
 It's done!
 
 I know this is very straightforward solution, one may think about using
 TF1::GetHistogram() function instead of filling h3 bin by bin.
 
 Cheers,
 Inkyu

>
>
>

Date: Thu, 16 Mar 2000 11:14:35 +0100
From: Volker Hejny <V.Hejny@fz-juelich.de>
To: Roottalk <roottalk@pcroot.cern.ch>
Subject: subtraction of fit from histogram

Hallo,

I want to do the following job and wondered if there is
already something foreseen with ROOT.

I have a histogram i1 and another histogram i2 with a
fit. Now I'd like to subtract the function of histogram
i2 from the contents of histogram i1, i.e. I want to
subtract a fitted background from data. Does anyone
know a simple solution (despite from copying the function
manually bin by bin in a new histogram i3).

Thanks in advance and best regards,
Volker Hejny 

-- 
Volker Hejny                    Tel: 02461/616853                     
** 
Institut f. Kernphysik          Fax: 02461/613930                     **
---------------------------------------------------------------- **  **
---  
Forschungszentrum Juelich GmbH, D-52425 Juelich                    **



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET