示例#1
0
def makeEfficiency(passed, total, title, lineColor):
    if TEfficiency.CheckConsistency(passed, total):
        efficiency = TEfficiency(passed, total)
        #title = std::regex_replace(title, std::regex("\\muCandGenEtaMuons"), "tagging efficiency");
        efficiency.SetTitle(title)
        efficiency.SetStatisticOption(6)
        #TEfficiency.EStatOption.kBUniform
        efficiency.SetPosteriorMode()
        efficiency.SetLineColor(lineColor)
        return efficiency
    else:
        print(
            "makeEfficiency TEfficiency::CheckConsistency(*ptGenPtTTMuonNom, *ptGenPtTTMuonDenom) failed"
        )
        exit(1)
    # Open file
    tfile = TFile.Open(infile)

    # ____________________________________________________________________________
    # emtf_eff_vs_genpt_l1pt20
    hname = "emtf_eff_vs_genpt_l1pt20"
    h1a_denom = tfile.Get(hname + "_denom")
    h1a_numer = tfile.Get(hname + "_numer")
    h1b_denom = tfile.Get(hname2026_f(hname) + "_denom")
    h1b_numer = tfile.Get(hname2026_f(hname) + "_numer")

    print h1a_denom.GetEntries(), h1a_numer.GetEntries()
    print h1b_denom.GetEntries(), h1b_denom.GetEntries()

    h1a_eff = TEfficiency(h1a_numer, h1a_denom)
    h1a_eff.SetStatisticOption(0)  # kFCP
    h1a_eff.SetConfidenceLevel(0.682689492137)  # one sigma
    h1a_eff.SetMarkerColor(632)  # kRed
    h1a_eff.SetLineColor(632)  # kRed
    h1a_eff.SetLineWidth(2)

    h1b_eff = TEfficiency(h1b_numer, h1b_denom)
    h1b_eff.SetStatisticOption(0)  # kFCP
    h1b_eff.SetConfidenceLevel(0.682689492137)  # one sigma
    h1b_eff.SetMarkerColor(600)  # kBlue
    h1b_eff.SetLineColor(600)  # kBlue
    h1b_eff.SetLineWidth(2)

    gr = h1a_eff.CreateGraph()
    gr.Draw("ap")
    frame = gr.GetHistogram()
示例#3
0
                    # (this handles the eff = 0, 1 case)
                    #
                    # DOES NOT SEEM TO WORK FOR WEIGHTED HISTOGRAMS --> IT REDUCES TO THE NORMAL APPROX
                    #
		    #t_efficiency.SetStatisticOption(TEfficiency.kFCP)
                    #
                    # Use TEfficiency, with the Bayesian uniform prior at XX% CL (set before)
                    # (This is the same as the TGraphAsymmErrors below)
                    #
                    # In order to get the same value for efficiency as in a frequentist approach (as from TH1::Divide("B")),
                    # the MODE should be used as an estimator. This works as long as a uniform prior is chosen.
                    #
                    # Please refer to the TEfficiency class docs for details:
                    # https://root.cern.ch/doc/master/classTEfficiency.html
                    #
		    t_efficiency.SetStatisticOption(TEfficiency.kBUniform)
                    t_efficiency.SetPosteriorMode()

                # 3.
                #
                # Calculate efficiency using TGraphAsymmErrors
                # (uses a Bayesian uniform prior beta(1,1) for the efficiency with 68% CL. It handles the errors in case eff is 0 or 1)
                #
                g_efficiency = TGraphAsymmErrors(hist_eff)
                g_efficiency.Divide(hist_pass,hist_tot,"cl=0.683 b(1,1) mode")

                # Save the efficiencies in the proper dictionaries
                #
                hists[histname + "_Efficiency_" + append_str] = hist_eff
                tefficiencies[histname + "_Efficiency_" + append_str] = t_efficiency
                graphs[histname + "_Efficiency_" + append_str + "_graph"] = g_efficiency
示例#4
0
 n_particles = cur.execute(
     "SELECT nParticles FROM particleSourceMessenger;").fetchone()[0]
 name, pde, pct, papl, paps, n_cell, v_ov = cur.execute(
     "SELECT name, pdeAt400nm, crosstalkProbability, apProbLong, apProbShort, numberOfCells, overVoltage FROM sipmModel;"
 ).fetchone()
 con.close()
 # Read cached results from tsv file
 e, n = np.loadtxt(path, delimiter=" ").transpose()  # MeV, #
 # Determine bin width
 wvl = 4.135667516e-15 * 299792458.0 / e * 1e3
 wvl_min = min(wvl)
 wvl_max = max(wvl)
 nbins = int((wvl_max - wvl_min) / args.bin_width)
 eff = TEfficiency("%d-pass" % i, "%d-eff" % i, nbins, wvl_min, wvl_max)
 eff.SetUseWeightedEvents()
 eff.SetStatisticOption(TEfficiency.kFNormal)
 for wvli, ni in zip(wvl, n):
     eff.FillWeighted(True, ni, wvli)
     eff.FillWeighted(False, n_particles - ni, wvli)
 x = np.array(
     [eff.GetTotalHistogram().GetBinCenter(i) for i in xrange(nbins)])
 y = np.array([eff.GetEfficiency(i) for i in xrange(nbins)]) * 100.0
 yerr_low = np.array([
     eff.ClopperPearson(int(n_particles),
                        int(eff.GetEfficiency(i) * n_particles), 0.68,
                        False) for i in xrange(nbins)
 ]) * 100.0
 yerr_up = np.array([
     eff.ClopperPearson(int(n_particles),
                        int(eff.GetEfficiency(i) * n_particles), 0.68, True)
     for i in xrange(nbins)
示例#5
0
import sys
from ROOT import TEfficiency

if (len(sys.argv) != 3):
    print
    print 'USAGE : python FCstats.py Ntotal Npass'
    print
    exit()

tot = int(sys.argv[-2])
passing = int(sys.argv[-1])

k = TEfficiency()
k.SetStatisticOption(TEfficiency.kFFC)

# get +/- 1 sigma interval from Feldman Cousins statistics
eff = passing / float(tot)
eff_upper = k.FeldmanCousins(tot, passing, 0.6827, True)
eff_lower = k.FeldmanCousins(tot, passing, 0.6827, False)

print 'Efficiency : %.03f.' % (eff)
print '1-sigma interval : [%.03f, %.03f]' % (eff_lower, eff_upper)