コード例 #1
0
ファイル: LKThesisMacro.py プロジェクト: eschliec/TopAnalysis
 def makeEstimationHist(self, effqcd, effqcderr, sigEffHist, sigLooseHist, looseHist, tightHist):
     looseGBC = looseHist.GetBinContent
     tightGBC = tightHist.GetBinContent
     sigEffGBC = sigEffHist.GetBinContent
     #unweighted
     sigLGBC = sigLooseHist.GetBinContent
     for x in range(1, signalEff.GetNbinsX() + 1):
             tight = tightGBC(x)
             loose = looseGBC(x)
             effsig = sigEffGBC(x)
             effsigerr = self.getStatError(effsig, sigEffGBC(x))
             res = MatrixMethod.getNumbers(effqcd, effqcderr, effsig, effsigerr, loose, tight)
             print 'est: ', res['NQT'], 'pm', res['NQTerr'], 'real: ', self.qcdhisttight.GetBinContent(x)
コード例 #2
0
    def compute_acoustic_rad(self, masterframe_inst):
        top_selection = masterframe_inst.top_selection
        bot_selection = masterframe_inst.bot_selection

        if top_selection.get() != "Select Type" or bot_selection.get(
        ) != "Select Type":
            bot_properties, top_properties, medium_properties = definedicts(
                self, masterframe_inst)

            Ux, Uy, Uz, Vx, Vy, Vz = CreateGeometry(top_properties,
                                                    bot_properties)

            start = time.time()
            _acoustic_radiation_pressure, relative_potential, pressure, x_span, z_span = MatrixMethod(
                medium_properties, top_properties, bot_properties)
            end = time.time()
            diff = end - start
            print("Total time elapsed was %.4f" % diff, "seconds")
            x_len = len(x_span)
            z_len = len(z_span)

            xmax = np.max(x_span) * 1e3
            xmin = np.min(x_span) * 1e3
            zmax = np.max(z_span) * 1e3
            zmin = np.min(z_span) * 1e3

            X, Y = np.mgrid[zmin:zmax, xmin:xmax]
            Z = _acoustic_radiation_pressure

            maxPotential = np.max(_acoustic_radiation_pressure)
            minPotential = np.min(_acoustic_radiation_pressure)

            colormap = masterframe_inst.colormap.get()

            fig = plt.figure(figsize=(8, 6),
                             dpi=80,
                             facecolor='w',
                             edgecolor='k')
            ax = fig.add_subplot(111, projection='3d')
            ax.scatter(Vz * 1e3, Vy * 1e3, Vx * 1e3, marker='.')
            ax.scatter(Uz * 1e3, Uy * 1e3, Ux * 1e3, marker='.')

            zMax = np.max(Vx) * 1e3
            zMin = np.min(Ux) * 1e3
            yMax = np.max(Vy) * 1e3
            yMin = np.min(Uy) * 1e3
            xMax = np.max(Vz) * 1e3
            xMin = np.min(Uz) * 1e3

            ax.set_xlim([xMin, xMax])
            ax.set_ylim([yMin, yMax])
            ax.set_zlim([zMin, zMax])
            ax.set_zticklabels([])
            # ax.grid(False)
            # ax.axis('off')

            ax.view_init(azim=0, elev=-90)

            levels = np.linspace(minPotential, maxPotential, 1000)
            cset = ax.contourf(X, Y, Z, levels, cmap=colormap)
            ax.clabel(cset, fontsize=9, inline=1)
            ax.set_xlabel("z (mm)", fontsize=16, labelpad=16)
            plt.xticks(rotation=45)
            plt.title("Acoustic Radiation Pressure", fontsize=16)
            plt.xticks(size=16)

            middle_index = int(np.ceil(x_len / 2))

            profile = Z[:, middle_index]

            fig = plt.figure(figsize=(8, 6),
                             dpi=80,
                             facecolor='w',
                             edgecolor='k')
            plt.title("Radiation Pressure Profile", fontsize=16)
            ax = plt.gca()

            xPlot = np.linspace(zmin, zmax, z_len)
            plt.plot(xPlot, profile)
            ax.set_xticks(xPlot[::5])
            ax.set_xlabel("z (mm)", fontsize=16, labelpad=5)
            plt.xticks(rotation=45)

            np.savetxt('profile.txt', profile, delimiter=',')
            np.savetxt('xPlot.txt', xPlot, delimiter=',')
            np.savetxt('acoustic_radiation.txt', Z, delimiter=',')
            plt.show()

        else:
            print("Please define system geometry")
コード例 #3
0
ファイル: LKThesisMacro.py プロジェクト: eschliec/TopAnalysis
    def makeQualityHist(self, loose, tight, effsig, effsigerr, dir, basedir=''): 
        scale = self.scale
        keys = self.effbg[dir].keys()
        keys.sort()
        
        t2 = basedir + dir + 'bkg'
        t2 = t2.replace('/', '_')
        gROOT.mkdir(t2)
        gROOT.cd(t2)
        
        qualityBL = None
        qualityBT = None
        effB = None
        effQB = None
        effQCDmcVSCUT = copy.deepcopy(self.qcdhisttight.Clone('effMC_vs_MVAcut'))
        EQMSBC = effQCDmcVSCUT.SetBinContent
        EQMSBE = effQCDmcVSCUT.SetBinError
    
        qualityBL = copy.deepcopy(self.qcdhistloose.Clone('quality_loose'))
        qualityBL.SetName('quality_loose')
        qualityBL.SetTitle('quality_loose_BG')
        
        NvsCL = copy.deepcopy(self.qcdhistloose.Clone('NvsCutloose'))
        NvsCL.SetName('NvsCutloose')
        NvsCL.SetTitle('NvsCutloose')
        
        NvsCT= copy.deepcopy(self.qcdhistloose.Clone('NvsCuttight'))
        NvsCT.SetName('NvsCuttight')
        NvsCT.SetTitle('NvsCuttight')
            
        qualityBT = copy.deepcopy(self.qcdhistloose.Clone('quality_tight'))
        qualityBT.SetName('quality_tight')
        qualityBT.SetTitle('quality_tight_BG')
            
        effB = copy.deepcopy(self.qcdhistloose.Clone('effvsDiscCut_BG'))
        effB.SetName('effvsDiscCut_BG')
        effB.SetTitle('effvsDiscCut_BG')
            
        effQB = copy.deepcopy(self.qcdhistloose.Clone('quality_eff_BG'))
        effQB.SetName('quality_eff_BG')
        effQB.SetTitle('quality_eff_BG')
#            TH1F('quality_loose', 'quality_loose_BG', int(len(keys)), 0., eval(keys[len(keys) - 1]))
#            qualityBT = TH1F('quality_tight', 'quality_tight_BG', int(len(keys)), 0., eval(keys[len(keys) - 1]))
#            effB = TH1F('effvsDiscCut_BG', 'effvsDiscCut_BG', int(len(keys)), 0., eval(keys[len(keys) - 1]))
#            effQB = TH1F('quality_eff_BG', 'quality_eff_BG', int(len(keys)), 0., eval(keys[len(keys) - 1]))

        t1 = basedir + dir + 'sig'
        t1 = t1.replace('/', '_')
        gROOT.mkdir(t1)
        gROOT.cd(t1)
        
        qualitySL = copy.deepcopy(self.tophistloose.Clone('quality_loose_SIG'))
        qualitySL.SetName('quality_loose')
        qualitySL.SetTitle('quality_loose_SIG')
        
        qualityST = copy.deepcopy(self.tophistloose.Clone('quality_tight_SIG'))
        qualityST.SetName('quality_tight')
        qualityST.SetTitle('quality_tight_SIG')
        #TH1F('quality_loose', 'quality_loose_SIG', int(len(keys)), 0., eval(keys[len(keys) - 1]))
#        qualityST = TH1F('quality_tight', 'quality_tight_SIG', int(len(keys)), 0., eval(keys[len(keys) - 1]))
        
#        effS = TH1F('effvsDiscCut_SIG', 'effvsDiscCut_SIG', int(len(keys)), 0., eval(keys[len(keys)-1]))
        
        #caching of PyROOT methods (faster)
        qSBCBL = qualityBL.SetBinContent
        qSBEBL = qualityBL.SetBinError
        qSBCBT = qualityBT.SetBinContent
        qSBEBT = qualityBT.SetBinError        
        
        qSBCSL = qualitySL.SetBinContent
        qSBESL = qualitySL.SetBinError
        qSBCST = qualityST.SetBinContent
        qSBEST = qualityST.SetBinError    
        
        eSBCB = effB.SetBinContent
        eSBEB = effB.SetBinError
        eSBCQ = effQB.SetBinContent
        eSBEQ = effQB.SetBinError
        
        nLSBC = NvsCL.SetBinContent
        nTSBC = NvsCT.SetBinContent
        
        wjetsL = self.wjethistloose.Integral() * scale['wjets']
        wjetsT = self.wjethisttight.Integral() * scale['wjets']
        topL = self.tophistloose.Integral() * scale['top']
        topT = self.tophisttight.Integral() * scale['top']
        qcdL = self.qcdhistloose.Integral() * scale['qcd']
        qcdT = self.qcdhisttight.Integral() * scale['qcd']
        sigT = wjetsT + topT
        sigL = wjetsL + topL
        trueQCDEff = qcdT / qcdL
        trueQCDEffErr = self.getStatError(trueQCDEff, qcdT + qcdL)
#        eSBCS = effS.SetBinContent
#        eSBES = effS.SetBinError
        x = 1
        for i in keys:  
            
            effqcd = self.effbg[dir][i][0]
            effqcderr = self.effbg[dir][i][1]
            
            mixaSel, mixbSel, qcdTSel, qcdLSel = [1,1,1,1]
            if x ==1:
                mixaSel = self.mixa.GetBinContent(x)
                mixbSel = self.mixb.GetBinContent(x)
                qcdTSel = self.qcdhisttight.GetBinContent(x)
                qcdLSel = self.qcdhistloose.GetBinContent(x)
            else:
                mixaSel = self.mixa.Integral(1, x)
                mixbSel = self.mixb.Integral(1, x)
                qcdTSel = self.qcdhisttight.Integral(1, x)
#                if x == 4:
#                    print qcdTSel, self.wjethisttight.Integral(1, x) + self.tophisttight.Integral(1, x)
                qcdLSel = self.qcdhistloose.Integral(1, x)
#            if qcdT == 0:
#                nTSBC(x,0)
#            else:
            nTSBC(x,qcdTSel/qcdT)
#            if qcdLSel == 0:
#                nLSBC(x,0)
#            else:
            nLSBC(x,qcdLSel/qcdL)
            
            
#            effsig = (self.effsig[dir][i][0] + self.effwjet[dir][i][0])/2
#            effsigerr = sqrt(self.effsig[dir][i][1]*self.effsig[dir][i][1] + self.effwjet[dir][i][1]*self.effwjet[dir][i][1])/2
            eSBCB(x, effqcd)
            eSBEB(x, effqcderr)
            res = MatrixMethod.getNumbers(effqcd, effqcderr, sigT / sigL, effsigerr, loose, tight)
            sigma = (res['NQT']) / qcdT
            sigmaErr = res['NQTerr'] / qcdT
            sigmaS = res['NST'] / sigT
            sigmaErrS = res['NSTerr'] / sigT
            
            if dir =='all' and i == '0.20':
                tab = 'From %s and %s \n'%(dir, basedir)
                tab += '$N_L = %d, N_T = %d$ \\\\ \n' % (loose, tight)
                tab += 'cut %s, $\epsilon_q = %1.4f \\pm %1.4f$, $\epsilon_s = %1.4f \\pm %1.4f$ \n' %(i, effqcd, effqcderr, sigT / sigL, effsigerr) 
                tab += '\\begin{table}[!ht] \n'
                tab += '\\begin{tabular}{l c c c c} \n'
                tab += '\\toprule'+'\n'
                tab += ' & $N_q$ & $N_q^{MC}$ & $N_s$ & $N_s^{MC}$\\\\ \n'
                tab += '\\midrule \n'
                tab += 'loose & $%d \\pm %d$ & %d & $%d \\pm %d$ & \\num{%d} \\\\ \n' %(res['NQ'], res['NQerr'], qcdL, res['NS'], res['NSerr'], sigL)
                tab += 'tight  & $%d \\pm %d$ & %d & $%d \\pm %d$ & \\num{%d} \\\\ \n' %(res['NQT'], res['NQTerr'], qcdT, res['NST'], res['NSTerr'], sigT)
                tab += '\\bottomrule \n'
                tab += '\\end{tabular} \n'
                tab += '\\end{table} \n'
                self.addToTables(tab)
            if self.debug  and dir == 'all':
                print 'overall'
                print 'T est: ', res['NQT'], 'pm', res['NQTerr'], 'real: ', qcdT
                print 'T est: ', res['NST'], 'pm', res['NSTerr'], 'real: ', sigT
                print effqcd, effqcderr
                print effsig, effsigerr
                print i, sigma, '+-', sigmaErr 
                print i, sigmaS, '+-', sigmaErrS
            
            EQMSBC(x, qcdTSel/qcdLSel)
            EQMSBE(x, self.getStatError(qcdTSel/qcdLSel, qcdLSel/5))
            err = sqrt(trueQCDEffErr * trueQCDEffErr + effqcderr * effqcderr)
            eSBCQ(x, effqcd/trueQCDEff)
            eSBEQ(x, err)
            
            qSBCBT(x, sigma)
            qSBEBT(x, sigmaErr)
            qSBCST(x, sigmaS)
            qSBEST(x, sigmaErrS)
            
            
            sigma = (res['NQ']) / qcdL
            sigmaErr = res['NQerr'] / qcdL
            sigmaS = res['NS'] / sigL
            sigmaErrS = res['NSerr'] / sigL
            
            if self.debug and dir == 'all':
                print 'L est: ', res['NQ'], 'pm', res['NQerr'], 'real: ', qcdL
                print 'L est: ', res['NS'], 'pm', res['NSerr'], 'real: ', sigL
                print i, sigma, '+-', sigmaErr
                print i, sigmaS, '+-', sigmaErrS 
#            
            qSBCBL(x, sigma)
            qSBEBL(x, sigmaErr)
            
            qSBCSL(x, sigmaS)
            qSBESL(x, sigmaErrS)
            x += 1
        return [qualityBL, qualityBT, qualitySL, qualityST, effB, effQB, NvsCL, NvsCT, effQCDmcVSCUT]