Hi Tadeusz, In your macro below, you have the statement: TFile hfile("prob.root"); When you exit from the procedure prob, all objects created in prob (except the ones created via new) are automatically deleted. This is the normal scoping rule in C++. The object hfile is also deleted. When hfile is deleted, all objects in the container hfile are deleted. If you simply replace the above statement by: TFile *hfile = new TFile("prob.root"); your program will not delete objects at the end of execution. I have modified the macro accordingly. Concerning, Factorial, Binomial, etc, these functions could be added in a TUtils class (as static functions). Just waiting for good and efficient code. I have no time to implement these functions. As described in the TF1 constructor, the parameter referencing the function must be of type Double_t. Rene Brun Tadeusz Pytlos wrote: > > Hello Rooters, > I have a few problems linking with fiting of histogram. > 1) I'm trying to solve such equation > myhist=integral(0,infinity) fun1(dN)*fun2() d(dN), > where function fun2() I don't know, so I treat it as parameters > to estimate par[dN]. Of course, intergral I replace by sum(0,dN). > The problem is that there are only maximum 10 parameters to fit! > It's too less for my purposes. Is it possible to implement more? > Or is there any better possibility to solve my problem? > Can I use TMinuit for such problem? I will be grateful > for any ideas. > I include my macro and root file with histogram. Myhist is red and > right side of equation is black. > > 2) Is possible to implement such functions like Factorial > and Binomial in future ROOT? > 3) I don't understand why my macro didn't stop, but I have to use > getchar(). What clears my canvas? > 4) I went about it, but I want to mention. I had problems with > Double_t fitf(Int_t *k, Double_t *par). Is fit function only designed > for Double_t? > Thank you in advance. > Best wishes, > Tadeusz Pytlos > > ---------------prob.C--------------------------- > > 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 dN; > Int_t m=12; > Float_t At=m*156.25; > Float_t Ad=3.24; > Int_t k=x[0]; > Double_t mm=Factorial(m); > Double_t kk=Factorial(k); > Double_t mk=Factorial(m-k); > Double_t Binomial=mm/kk/mk; > Float_t a0=1-Ad/At; > Double_t a1,a2,a3,fun1,wart; > > wart=0; > for(dN=0;dN<10;dN++) > { > a1=1-TMath::Exp(-dN*a0); > a2=TMath::Power(a1,k); > a3=TMath::Exp(-dN*(m-k)*a0); > fun1=Binomial*a2*a3; > wart=wart+fun1*par[dN]; > } > Double_t fitval=wart; > return fitval; > } > > void prob() > { > ////////////////////////////////////////////////////////// > // This file has been automatically generated > // (Mon Nov 24 12:46:19 1997 by ROOT version 1.03/07) > // from TTree kas/BASKET > // found on file: dst00459.root > ////////////////////////////////////////////////////////// > > //Reset ROOT and connect tree file > gROOT->Reset(); > // TFile hfile("prob.root"); 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=1; > sprintf(padname,"page_%d",kpad); > 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(); > > char hname[20]; > TH1 *h; > > sprintf(hname,"h%d",kpad); > h=(TH1F*)hfile.Get(hname); > h.SetLineWidth(2); > h.SetLineStyle(1); > h.SetLineColor(1); > h.SetXTitle("k"); > h.SetYTitle("N"); > h.SetMinimum(0.001); > h.Draw(); > > TF1 *func=new TF1("func",fitf,0,30,10); > func->SetParameters(0,0,0,0,0,0,0,0,0,0); > h.SetLineColor(2); > h->Fit("func","r"); > > page.Update(); > TPostScript mps("prob.eps",113); > page.Draw(); > mps.Close(); > > // ans=getchar(); // thiese 2 lines are not necessary > // page->cd(); > > } > > -- > Tadeusz Pytlos > mailto:pytlos@fizwe5.fic.uni.lodz.pl > Lodz, Poland > > --------------------------------------------------------------- > > Name: prob.root > Part 1.2 Type: unspecified type (APPLICATION/octet-stream) > Encoding: BASE64
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:32 MET