Re: get histogram from a function with different range

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Mar 04 2000 - 12:47:41 MET


Hi Angela,
What do you mean by "Finally I want to get an histogram from this
function" ?
Do you want to get random numbers following the fitted function ?
Do you want simply to draw the fitted function using an histogram
drawing option ?
Depending what you want to do, you may get some inspiration
from the example below.

Rene Brun

void angela() {
   TCanvas *c1 = new TCanvas("c1","c1",600,800);
   c1->Divide(1,3);
   TH1F *h1 = new TH1F("h1","test1",100,-3,3);
   TH1F *h2 = new TH1F("h2","test2",100,-3,3);
   TH1F *h3 = new TH1F("h3","test3",100,-3,3);
   for (Int_t i=0;i<10000;i++) h1->Fill(gRandom->Gaus(0,1));
   c1->cd(1);
   TF1 *f1 = new TF1("f1","pol3",-3,0.5);
   h1->Fit("f1","rn");
   h1->Draw();
   f1->Draw("lsame");
   c1->cd(2);
   h2->SetMaximum(h1->GetMaximum());
   h2->Draw();
   f1->Draw("hsame");
   c1->cd(3);
   for (Int_t j=0;j<10000;j++) h3->Fill(f1->GetRandom());
   h3->Draw();   
}

On Fri, 3 Mar 2000, Angela Biselli wrote:

> Hi rooters,
> I'm trying to do the following:
> I have a histogram in a range (-0.1, 0.15)
> I want to fit a polinomia in the subrange (-0.1,0.05)
> Finally I want to get an histogram from this function with the same range
> of the first one (I want the values from 0.06 to 0.15 set to zero)
> I tried to use GetHistogram() but it return me a histogram with the range
> of the fit.
> TH1F *emmsqW2cter= new TH1F("emmsqW2cter","mm^{2}  e-p C_{12}W=1.232#pm0.50 scaled to NH_{3} using clebsh gordon",100,-0.1,0.15);
> ....
> TF1 *f1 = new TF1("f1","pol9",-0.1,0.05);
> emmsqW1cter->Fit("f1","R0");
> emmsqW1cter->Draw();
> TH1F *hfitW1 = new TH1F("hfitW1","hfit1",100,-0.1,0.15);
> hfitW1=f1->GetHistogram();
> 
> Is there a way to get such a histogram? 
> I also tought to define a new function defined as a sum of the polinomia
> in the first range and zero in the second one,and the get the histogram
> from that function,but it seems that it is not possible to do something
> like
> TF1 *f1 = new TF1("f1","pol9",-0.1,0.05);
> emmsqW1cter->Fit("f1","R0");
> TF1 *f2 = new TF1("f2","pol0",0.05,0.15);
> f2->SetParameter(0,0)
> TF1 *tot=new TF1("tot","f1+f2",-0.1,0.15)
> How can be done something similar to this
> 
> thanks
> Angela
> 



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