You must realize that object->Draw is simply adding the object
to the list of objects to be drawn in the pad. Actual drawing
happens only when the pad needs to be paint.
In your case, your function must have one parameter (dN).
Without my change, the function was always drawn with the same
parameter.
Rene Brun
////=========Modified function starts here
//------------ prot.C
Int_t p=10;
Int_t r=6;
Int_t m=12;
Int_t width=40;
Int_t shift=0;
Int_t dN;
Double_t Factorial(Int_t f)
{
Int_t b;
Double_t x;
if(f==0)
{
x=1.0;
return x;
}
x=1;
b=0;
do
{
b=b+1;
x=x*b;
}while(b!=f);
return x;
}
Double_t fitf(Double_t *x,Double_t *par)
{
Int_t N;
Int_t k=x[0];
dN = Int_t(par[0]); //===========>new
if(k>m) return 0;
Int_t Nevn=17156;
Double_t kk=Factorial(k);
Double_t mm=Factorial(m);
Double_t mk=Factorial(m-k);
Double_t Binomial=mm/kk/mk;
Double_t a1,a2,a3,fun1;
Double_t At,Ad,a0;
At=TMath::Pi()*(4900-3600);
Ad=3.24;
a0=Ad/At;
a1=1-TMath::Exp(-dN*a0);
a2=TMath::Power(a1,k);
a3=TMath::Exp(-dN*(m-k)*a0);
fun1=Nevn*Binomial*a2*a3;
return fun1;
}
void prot()
{
TFile *hfile=new TFile("prob.root");
page = new TCanvas("page","Probability",0,0,500,700);
page->SetFillColor(10);
page->Divide(1,1);
Int_t kpad,ans;
char padname[20];
kpad=0;
sprintf(padname,"page_%d",kpad+1);
TPad *pad = (TPad*)page->GetPrimitive(padname);
pad->cd();
pad->SetGrid();
pad->SetLogy();
pad->GetFrame()->SetFillColor(42);
pad->GetFrame()->SetBorderMode(-1);
pad->GetFrame()->SetBorderSize(5);
pad->Draw();
TH1S *hin=new TH1S("hin","hin",m,0,m);
hin.SetLineWidth(2);
hin.SetLineStyle(1);
hin.SetLineColor(1);
hin.SetXTitle("k");
hin.SetYTitle("N");
hin.SetMinimum(1e-1);
hin.SetMaximum(1e5);
hin.Draw();
dN=20;
TF1 *f1=new TF1("f1",fitf,0,30,1); //===========>modified
// TF1 *f1=new TF1("f1","20*sin(x)",0,30);
f1->SetParameter(0,dN); //===========>new
f1->SetLineColor(2);
f1->Draw("same");
dN=100;
TF1 *f2=new TF1("f2",(void*)fitf,0,30,1); //===========>modified
// TF1 *f2=new TF1("f2","100*sin(x)",0,30);
f2->SetParameter(0,dN); //===========>new
f2->SetLineColor(3);
f2->Draw("same");
dN=1000;
TF1 *f3=new TF1("f3",(void*)fitf,0,30,1); //===========>modified
// TF1 *f3=new TF1("f3","1000*sin(x)",0,30);
f3->SetParameter(0,dN); //===========>new
f3->SetLineColor(4);
f3->Draw("same");
}
//================end of modified function
Tadeusz Pytlos wrote:
>
> Dear Rooters,
> I have problems with drawing a few user defined functions
> on the same picture. If I take simple functions (commented functions),
> all is OK, but if I take 3 user defined functions only the last one
> is drawing. How to draw all functions? Or how to redefine my approach
> to draw all three functions?
> Thank you in advance,
> Tadeusz
>
> //------------ prot.C
>
> Int_t p=10;
> Int_t r=6;
> Int_t m=12;
> Int_t width=40;
> Int_t shift=0;
> Int_t dN;
>
> Double_t Factorial(Int_t f)
> {
> Int_t b;
> Double_t x;
> if(f==0)
> {
> x=1.0;
> return x;
> }
> x=1;
> b=0;
> do
> {
> b=b+1;
> x=x*b;
> }while(b!=f);
> return x;
> }
>
> Double_t fitf(Double_t *x,Double_t *par)
> {
> Int_t N;
> Int_t k=x[0];
> if(k>m) return 0;
> Int_t Nevn=17156;
> Double_t kk=Factorial(k);
> Double_t mm=Factorial(m);
> Double_t mk=Factorial(m-k);
> Double_t Binomial=mm/kk/mk;
> Double_t a1,a2,a3,fun1;
> Double_t At,Ad,a0;
> At=TMath::Pi()*(4900-3600);
> Ad=3.24;
> a0=Ad/At;
> a1=1-TMath::Exp(-dN*a0);
> a2=TMath::Power(a1,k);
> a3=TMath::Exp(-dN*(m-k)*a0);
> fun1=Nevn*Binomial*a2*a3;
> return fun1;
> }
>
> void prot()
> {
> TFile *hfile=new TFile("prob.root");
> page = new TCanvas("page","Probability",0,0,500,700);
> page->SetFillColor(10);
> page->Divide(1,1);
>
> Int_t kpad,ans;
> char padname[20];
>
> kpad=0;
> sprintf(padname,"page_%d",kpad+1);
> TPad *pad = (TPad*)page->GetPrimitive(padname);
> pad->cd();
> pad->SetGrid();
> pad->SetLogy();
> pad->GetFrame()->SetFillColor(42);
> pad->GetFrame()->SetBorderMode(-1);
> pad->GetFrame()->SetBorderSize(5);
> pad->Draw();
>
> TH1S *hin=new TH1S("hin","hin",m,0,m);
> hin.SetLineWidth(2);
> hin.SetLineStyle(1);
> hin.SetLineColor(1);
> hin.SetXTitle("k");
> hin.SetYTitle("N");
> hin.SetMinimum(1e-1);
> hin.SetMaximum(1e5);
> hin.Draw();
>
> dN=20;
> TF1 *f1=new TF1("f1",fitf,0,30,0);
> // TF1 *f1=new TF1("f1","20*sin(x)",0,30);
> f1->SetLineColor(2);
> f1->Draw("same");
>
> dN=100;
> TF1 *f2=new TF1("f2",fitf,0,30,0);
> // TF1 *f2=new TF1("f2","100*sin(x)",0,30);
> f2->SetLineColor(3);
> f2->Draw("same");
>
> dN=1000;
> TF1 *f3=new TF1("f3",fitf,0,30,0);
> // TF1 *f3=new TF1("f3","1000*sin(x)",0,30);
> f3->SetLineColor(4);
> f3->Draw("same");
>
> }
>
>
> --
> Tadeusz Pytlos
> mailto:pytlos@fizwe5.fic.uni.lodz.pl
> Lodz, Poland