void fitexpbinned(){ //generate binned data const int nbin = 100; TH1F *hdata = new TH1F("data", "exp distribution", nbin, 0., 10.); TRandom2 r; for(int ievent=0; ievent<100000; ievent++){ hdata->Fill(r.Exp(4.)); } hdata->Draw(); //fit binned data //A is the normalization and K is the mean of the exponential to fit double A, K; double A_start = 100, A_step = 100., K_start = 1.0, K_step = 0.1; double ll_max = -10000000., K_max = -10000000., A_max = -10000000.; double n[nbin],x[nbin]; //get the bin centers and bin contents in two arrays for (int ibin=1; ibinGetBinCenter(ibin); n[ibin] = hdata->GetBinContent(ibin); } //maximization for (int iA=0; iA<100; iA++){ A = A_start + iA*A_step; for (int iK=0; iK<100; iK++){ K = K_start + iK*K_step; double ll = 0.; for (int ibin=1; ibinll_max) { ll_max = ll; K_max = K; A_max = A; } } //cout<<"A= "<Draw("same"); }