Double_t distributionEfficiencyFromOccurence( Double_t *x, Double_t *par){ // Compute the efficiency for a counting experiment // par[0] = N is the number of trials, integer expected // par[1] = K is the number of success, integer expected // x = p is the success probability // // Formula is taken from M.Patterno Double_t p = x[0]; Double_t N = par[0]; Double_t K = par[1]; //cout << "x=" << p << " N=" << N << " K=" << K << endl; // compute factor (N+1)!/K!/(N-K)! = (N+1)*(N+1-1)*...*(N+1-K)/K/.../1 // ratio of K+1 terms over K terms // compute the ratio term after term to avoid large factorials Double_t factor = N+1; for( Int_t i=1; i<=K; i++) { factor *= (N-K+i)/i; } //cout << "factors=" << factor << " " << TMath::Power( p, K) * TMath::Power( 1.-p, N-K) << endl; return factor * TMath::Power( p, K) * TMath::Power( 1.-p, N-K); }