Exemple #1
0
    def write(self,fname):
        R = np.array([[1,1],[-1,1]]) # rotate pi/4, except also scale by sqrt(2)
        d_Aqq,d_Aqg = np.sqrt(np.diag(self.sigmas_totl))
        d_Ac = math.sqrt(R.dot(self.sigmas_totl.dot(R.T))[0,0])
        sim_d_Aqq,sim_d_Aqg = np.sqrt(np.diag(self.sigmas_simu))
        sim_d_Ac = math.sqrt(R.dot(self.sigmas_simu.dot(R.T))[0,0])
        syst_d_Ac = math.sqrt(R.dot((self.sigmas_syst+self.sigmas_pois).dot(R.T))[0,0])
        stat_d_Ac = math.sqrt(R.dot(self.sigmas_stat).dot(R.T)[0,0])
        print 100*stat_d_Ac, 100*syst_d_Ac

        stat = ellipse(mean=list(self.mean), sigmas2=list(oneSigmaN2LL * self.sigmas_stat))
        syst = ellipse(mean=list(self.mean), sigmas2=list(oneSigmaN2LL * self.sigmas_syst))
        pois = ellipse(mean=list(self.mean), sigmas2=list(oneSigmaN2LL * self.sigmas_pois))
        totl = ellipse(mean=list(self.mean), sigmas2=list(oneSigmaN2LL * self.sigmas_totl))
        simu = ellipse(mean=list(self.simmean), sigmas2=list(oneSigmaN2LL * self.sigmas_simu))
        poissyst = ellipse(mean=list(self.mean), sigmas2=list(oneSigmaN2LL * (self.sigmas_syst+self.sigmas_pois)))

        with open(fname.replace('_points',''), 'w') as wFile:
            print >> wFile, 'central', self.mean[0], self.mean[1]
            print >> wFile, 'thr30',  self.thr30_mean[0], self.thr30_mean[1]
            print >> wFile, 'sim', self.simmean[0], self.simmean[1]
            print >> wFile, 'sim30', self.simmean30[0], self.simmean30[1]

        with open(fname, 'w') as wFile:
            N = 100
            for t in range(N + 1):
                T = t * 2 * math.pi / N
                print >> wFile, '\t'.join(str(f) for f in
                                          sum((item.eval(T)
                                               for item in filter(None, [stat,syst,totl,
                                                                         simu,
                                                                         lineUD(self.mean[0],d_Aqq),
                                                                         lineUD(self.mean[1],d_Aqg),
                                                                         lineUD(sum(self.mean),d_Ac),
                                                                         lineUD(self.simmean[0], sim_d_Aqq),
                                                                         lineUD(self.simmean[1], sim_d_Aqg),
                                                                         lineUD(sum(self.simmean), sim_d_Ac),
                                                                         pois,
                                                                         poissyst
                                                                     ])), ()))
        temp = r'''
        \begin{tabular}{c|r@{.}lr@{.}lr@{.}l}
        \hline
        &\multicolumn{6}{c}{(%s)}\\
        & \multicolumn{2}{c}{$A_c^{y(\QQ)}$} & \multicolumn{2}{c}{$A_c^{y(\QG)}$} & \multicolumn{2}{c}{$A_c^{y}$} \\
        \hline
        \hline
        \POWHEG \sc{ct10} & %s & %s & %s \\
        %s & %s & %s & %s \\
        \hline
        \end{tabular}'''
        def form(n,e):
            n*=100
            e*=100
            err_digit = int(math.floor(math.log(abs(e))/math.log(10)))-1 if e else 0
            scale = float(10**(-err_digit)) if e else 1
            p,d = divmod(round(abs(n*scale))/scale,1)

            return (("%s%d&%0"+str(-err_digit)+"d(%d)")%('-' if n<0 else ' ',p,d*scale,round(e*scale))).ljust(8)

        simcorrection = self.central.tree.f_gg_hat * self.central.tree.Ac_y_ttgg

        print temp%(r'\%',
                    form(self.simmean[0], sim_d_Aqq),
                    form(self.simmean[1], sim_d_Aqg),
                    form(sum(self.simmean)+simcorrection, sim_d_Ac),
                    self.label,
                    form(self.mean[0], d_Aqq),
                    form(self.mean[1], d_Aqg),
                    form(sum(self.mean)+self.central.tree.correction, d_Ac),
                    )
Exemple #2
0
        'delta_Aqq', 'delta_Aqg', 'delta_A', 'error_Aqq', 'error_Aqg',
        'error_A', 'pullqq', 'pullqg', 'pull'
    ]
    fixedLimits = [(-1.5, 1.5), (-1.5, 1.5), (-1.5, 1.5), (0.05, 1.05),
                   (0.05, 1.05), (0.05, 1.05), (-5, 5), (-5, 5), (-5, 5)]
    meanNLL = sum(e.NLL for e in tree) / tree.GetEntries()
    limits = fixedLimits
    wNLL = 40000

    within = 0
    tot = 0
    for e in tree:
        truth = e.gen_fitX, e.gen_fitY, 1.
        mean = e.fitX, e.fitY
        sigmas2 = [[e.fitXX, e.fitXY], [e.fitXY, e.fitYY]]
        el = ellipse(mean=mean, sigmas2=sigmas2)
        if np.dot(truth, el.matrix).dot(truth) < 0: within += 1
        tot += 1
        nbins = 30
        book.fill(meanNLL, 'meanNLL', nbins, -6.2e6, -5.8e6)
        book.fill(e.NLL - meanNLL, 'dNLL', nbins, -wNLL, wNLL)
        try:
            R = np.array([[1, 1],
                          [-1,
                           1]])  # rotate pi/4, except also scale by sqrt(2)
            sigmas = np.array([[e.fitXX, e.fitXY], [e.fitXY, e.fitYY]
                               ]) / oneSigmaN2LL
            sigma = math.sqrt(R.dot(sigmas).dot(R.T)[0, 0])

            values = 100 * np.array([
                e.fitX - e.gen_fitX, e.fitY - e.gen_fitY,
Exemple #3
0
    def write(self, fname):
        R = np.array([[1, 1],
                      [-1, 1]])  # rotate pi/4, except also scale by sqrt(2)
        d_Aqq, d_Aqg = np.sqrt(np.diag(self.sigmas_totl))
        d_Ac = math.sqrt(R.dot(self.sigmas_totl.dot(R.T))[0, 0])
        sim_d_Aqq, sim_d_Aqg = np.sqrt(np.diag(self.sigmas_simu))
        sim_d_Ac = math.sqrt(R.dot(self.sigmas_simu.dot(R.T))[0, 0])
        syst_d_Ac = math.sqrt(
            R.dot((self.sigmas_syst + self.sigmas_pois).dot(R.T))[0, 0])
        stat_d_Ac = math.sqrt(R.dot(self.sigmas_stat).dot(R.T)[0, 0])
        print 100 * stat_d_Ac, 100 * syst_d_Ac

        stat = ellipse(mean=list(self.mean),
                       sigmas2=list(oneSigmaN2LL * self.sigmas_stat))
        syst = ellipse(mean=list(self.mean),
                       sigmas2=list(oneSigmaN2LL * self.sigmas_syst))
        pois = ellipse(mean=list(self.mean),
                       sigmas2=list(oneSigmaN2LL * self.sigmas_pois))
        totl = ellipse(mean=list(self.mean),
                       sigmas2=list(oneSigmaN2LL * self.sigmas_totl))
        simu = ellipse(mean=list(self.simmean),
                       sigmas2=list(oneSigmaN2LL * self.sigmas_simu))
        poissyst = ellipse(mean=list(self.mean),
                           sigmas2=list(oneSigmaN2LL *
                                        (self.sigmas_syst + self.sigmas_pois)))

        with open(fname.replace('_points', ''), 'w') as wFile:
            print >> wFile, 'central', self.mean[0], self.mean[1]
            print >> wFile, 'thr30', self.thr30_mean[0], self.thr30_mean[1]
            print >> wFile, 'sim', self.simmean[0], self.simmean[1]
            print >> wFile, 'sim30', self.simmean30[0], self.simmean30[1]

        with open(fname, 'w') as wFile:
            N = 100
            for t in range(N + 1):
                T = t * 2 * math.pi / N
                print >> wFile, '\t'.join(
                    str(f) for f in sum((
                        item.eval(T)
                        for item in filter(None, [
                            stat, syst, totl, simu,
                            lineUD(self.mean[0], d_Aqq),
                            lineUD(self.mean[1], d_Aqg),
                            lineUD(sum(self.mean), d_Ac),
                            lineUD(self.simmean[0], sim_d_Aqq),
                            lineUD(self.simmean[1], sim_d_Aqg),
                            lineUD(sum(self.simmean), sim_d_Ac), pois, poissyst
                        ])), ()))
        temp = r'''
        \begin{tabular}{c|r@{.}lr@{.}lr@{.}l}
        \hline
        &\multicolumn{6}{c}{(%s)}\\
        & \multicolumn{2}{c}{$A_c^{y(\QQ)}$} & \multicolumn{2}{c}{$A_c^{y(\QG)}$} & \multicolumn{2}{c}{$A_c^{y}$} \\
        \hline
        \hline
        \POWHEG \sc{ct10} & %s & %s & %s \\
        %s & %s & %s & %s \\
        \hline
        \end{tabular}'''

        def form(n, e):
            n *= 100
            e *= 100
            err_digit = int(math.floor(math.log(abs(e)) /
                                       math.log(10))) - 1 if e else 0
            scale = float(10**(-err_digit)) if e else 1
            p, d = divmod(round(abs(n * scale)) / scale, 1)

            return (("%s%d&%0" + str(-err_digit) + "d(%d)") %
                    ('-' if n < 0 else ' ', p, d * scale, round(
                        e * scale))).ljust(8)

        simcorrection = self.central.tree.f_gg_hat * self.central.tree.Ac_y_ttgg

        print temp % (
            r'\%',
            form(self.simmean[0], sim_d_Aqq),
            form(self.simmean[1], sim_d_Aqg),
            form(sum(self.simmean) + simcorrection, sim_d_Ac),
            self.label,
            form(self.mean[0], d_Aqq),
            form(self.mean[1], d_Aqg),
            form(sum(self.mean) + self.central.tree.correction, d_Ac),
        )
import numpy as np

tfile = r.TFile.Open("jiggled_asymmetries.root")
ells = {}

for comp in ['ttqq','ttqg','ttag']:
    for lep in ['el','mu']:
        for epoch in ['orig','extra','total']:
            h = tfile.Get('_'.join([epoch,lep,comp]))
            stats = array.array('d',7*[0.])
            h.GetStats(stats)
            dx2 = stats[3]/stats[0] - stats[2]**2/stats[0]**2
            dy2 = stats[5]/stats[0] - stats[4]**2/stats[0]**2
            dxy = stats[6]/stats[0] - stats[2]*stats[4]/stats[0]**2
            sigmas2 = [[dx2, dxy], [dxy, dy2]]
            mean = ( h.GetMean(1), h.GetMean(2) )
            el = ellipse(mean=mean, sigmas2=sigmas2)
            ells[h.GetName()] = el

order = ['_'.join([epoch,lep,'']) for lep in ['el','mu'] for epoch in ['orig','extra','total']]
for comp in ['ttqq','ttqg','ttag']:
    with open(comp+'_points.txt','w') as out:
        meanel = ells['total_el_'+comp].mean
        meanmu = ells['total_mu_'+comp].mean
        print comp, meanel[0], meanel[1], meanmu[0], meanmu[1]
        print>> out, '# ', '\t'.join(order)
        N = 100
        for t in range(N + 1):
            T = t * 2 * math.pi / N
            print >> out, '\t'.join("%f\t%f\t\t"%ells[name].eval(T) for name in [o+comp for o in order])