A-A-Abdelhamid / LLP_Sleptons_RPV_SUSY

Here you can find MadGraph5 cards, diagrams, logs, plots, and code used in the project
2 stars 1 forks source link

TEfficiency and Uncertainty #9

Open A-A-Abdelhamid opened 1 year ago

A-A-Abdelhamid commented 1 year ago

Using this code:

total_histogram = TH1F()
passed_histogram = TH1F()

# Fill the histograms with total events and passed events
total_events = 20000  # Total number of events (denominator)
passed_events = 7856     # Number of passed events (numerator)

total_histogram.SetBinContent(1, total_events)

passed_histogram.SetBinContent(1, passed_events)

# Set uncertainties for total and passed events
etot= math.sqrt(total_events)
epass= math.sqrt(passed_events)

total_histogram.SetBinError(1, etot)
passed_histogram.SetBinError(1, epass)

eff = TEfficiency(passed_histogram, total_histogram)

print("Acceptance is ", eff.GetEfficiency(1))
print("Error_Low: ",eff.GetEfficiencyErrorLow(1))
print("Error_high: ", eff.GetEfficiencyErrorUp(1))

I got

Acceptance is  0.3928
Error_Low:  0.003472834950754622
Error high:  0.0034836322326174396

I also did it manually in the next comment, and they reasonably agree.

A-A-Abdelhamid commented 1 year ago

Consulting "Wikipedia" as advised, this is the simplified error propagation formula:

Screenshot 2023-08-17 at 12 42 01 PM

Acceptance (A) = passed events/(passed+ non-passed events) = p/(p+n) Uncertainty for p (passed) is square root p, for n (did not pass) is square root n

dA/dp = n/(p+n)^2

dA/dn = p/(p+n)^2

p = 7856     # Number of passed events 

n= 20000-p # Number of events that did not pass

p_err= math.sqrt(p)
n_err= math.sqrt(n)

dA_dp= n/((n+p)**2)
dA_dn= p/((n+p)**2)

sigma_A= math.sqrt((dA_dp*p_err)**2 + (dA_dn*n_err)**2 )

A= p/(p+n)
print("Acceptance is: ", A, "with uncertainty of  +/-", sigma_A)

And the output is:

Acceptance is: 0.3928 with uncertainty of +/- 0.0034533184040861334

Both methods agree to 2 significant-figure value of uncertainty = "0.0034"