Пример #1
0
def test1a(fname='data/fpgaLin/dp02a_Mar04C1a_data_0.root'):
    add_fit_menu()

    t1 = TChain('reco')
    t1.Add(fname)

    t1.Show(0)
    V = 200
    gr1 = TGraphErrors()

    for i in range(19):
        c1.cd(i+1)
        lt.DrawLatexNDC(0.2,0.4,'Ch={0:d}'.format(i))
        t1.Draw('Q[{0:d}]>>hx{0:d}'.format(i),'tID!=7')
        hx = gPad.GetPrimitive('hx{0:d}'.format(i))
        hx.Fit('gaus')
        fun1 = hx.GetFunction('gaus')
        encN = 7.40*V*fun1.GetParameter(2)/fun1.GetParameter(1)
        encE = 7.40*V*fun1.GetParError(2)/fun1.GetParameter(1)

        gr1.SetPoint(i,i,encN)
        gr1.SetPointError(i,0,encE)

    c1.cd(20)
    gr1.Draw('AP')

    c1.cd()
    waitRootCmdX()
Пример #2
0
def setup_frame(x_label,
                y_label,
                z_label=None,
                x_offset=1.0,
                y_offset=1.2,
                z_offset=1.2):
    htemp = gPad.GetPrimitive("htemp")

    htemp.GetXaxis().SetTitle(x_label)
    htemp.GetXaxis().SetTitleOffset(x_offset)
    htemp.GetXaxis().CenterTitle(True)
    htemp.GetXaxis().SetTitleSize(0.035)
    htemp.GetXaxis().SetLabelSize(0.035)

    htemp.GetYaxis().SetTitle(y_label)
    htemp.GetYaxis().SetTitleOffset(y_offset)
    htemp.GetYaxis().CenterTitle(True)
    htemp.GetYaxis().SetTitleSize(0.035)
    htemp.GetYaxis().SetLabelSize(0.035)

    if z_label is not None:
        htemp.GetZaxis().SetTitle(z_label)
        htemp.GetZaxis().SetTitleOffset(z_offset)
        htemp.GetZaxis().SetTitleSize(0.035)
        htemp.GetZaxis().CenterTitle(True)
        htemp.GetZaxis().SetLabelSize(0.035)
Пример #3
0
 def __H3(self,
          AVar,
          nABins,
          ALow,
          AHigh,
          BVar,
          nBBins,
          BLow,
          BHigh,
          CVar,
          nCBins,
          CLow,
          CHigh,
          cut=""):
     print "cut: |%s|" % (cut)
     print "varexp: |%s|" % (
         "%s:%s:%s>>htmpABC(%i,%f,%f,%i,%f,%f,%i,%f,%f)" %
         (CVar, BVar, AVar, nABins, ALow, AHigh, nBBins, BLow, BHigh,
          nCBins, CLow, CHigh))
     self.t.Draw(
         "%s:%s:%s>>htmpABC(%i,%f,%f,%i,%f,%f,%i,%f,%f)" %
         (CVar, BVar, AVar, nABins, ALow, AHigh, nBBins, BLow, BHigh,
          nCBins, CLow, CHigh), "", "lego")
     #    self.t.Draw("massSoftDrop>>htmpABC","")
     htmp = gPad.GetPrimitive('htmpABC')
     entropy = 0
     integral = 1. * htmp.Integral()
     for iB in xrange(1, nABins + 1):
         for jB in xrange(1, nBBins + 1):
             for kB in xrange(1, nCBins + 1):
                 p = htmp.GetBinContent(iB, jB, kB) / integral
                 if p > 0:
                     entropy -= p * log2(p)
     return entropy, htmp
Пример #4
0
 def __H1(self, varName, nBins, low, high, cut=""):
     usingCached = False
     if self.cachedABT:
         # only single variable entropy to compute for mi w/truth is for truth
         htmp = self.cachedABT.ProjectionZ('_pz')
         usingCached = True
     if self.cachedAB and not usingCached:
         if varName == self.Aname:
             htmp = self.cachedAB.ProjectionX("_px")
             usingCached = True
         elif varName == self.Bname:
             htmp = self.cachedAB.ProjectionY("_py")
             usingCached = True
     if not usingCached:
         self.t.Draw("%s>>htmp(%i,%f,%f)" % (varName, nBins, low, high),
                     cut)
         htmp = gPad.GetPrimitive('htmp')
     entropy = 0
     integral = 1. * htmp.Integral()
     for iB in xrange(1, nBins + 1):
         p = htmp.GetBinContent(iB) / integral
         if p > 0:
             # p<0 if weights?
             entropy -= p * log2(p)
     return entropy, htmp
Пример #5
0
def showDecay():
    tree1 = TTree()
    tree1.ReadFile(
        '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/ENC_Chip5Col12_scan1.dat',
        'idX/i:vL/F:vH:A:D/i:R:W')
    tree1.ReadFile(
        '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/ENC_Chip5Col12_scan2_mod.dat'
    )

    #     p1 = TProfile('p1','p1;#DeltaU [V];Prob',50,0.12,0.2)
    #     tree1.Draw("W:(vH-vL)>>p1","","profE")

    tree1.Draw("W*0.0001:(vH-vL)>>p1", "", "profs")

    p1 = gPad.GetPrimitive('p1')
    p1.GetYaxis().SetTitle('<Width> [us]')
    #     p1.GetYaxis().SetTitle('<Raising time> [us]')
    p1.GetXaxis().SetTitle('#Delta U [V]')

    #     fun1 = TF1('fun1','0.5*(1+TMath::Erf((x-[0])/(TMath::Sqrt(2)*[1])))',0.05,0.3)
    #     fun1.SetParameter(0,0.155);
    #     fun1.SetParameter(1,0.005);
    #
    #     p1.Fit(fun1)
    #     fun1a = p1.GetFunction('fun1')
    #     fun1a.SetLineColor(2)
    #
    #     p1.Draw("Esame")
    #
    #     v0 = fun1a.GetParameter(0)
    #     e0 = fun1a.GetParError(0)
    #     v1 = fun1a.GetParameter(1)
    #     e1 = fun1a.GetParError(1)
    #
    #     print v0, v1
    #
    #     fUnit = 1000.
    #     lt = TLatex()
    #     lt.DrawLatexNDC(0.185,0.89,'#mu = {0:.1f} #pm {1:.1f} mV'.format(v0*fUnit, e0*fUnit))
    #     lt.DrawLatexNDC(0.185,0.84,'#sigma = {0:.1f} #pm {1:.1f} mV'.format(v1*fUnit, e1*fUnit))
    #
    #     print 'TMath::Gaus(x,{0:.5f},{1:.5f})'.format(v0, v1)
    #     fun2 = TF1('gaus1','TMath::Gaus(x,{0:.5f},{1:.5f})'.format(v0, v1))
    #     fun2.SetLineColor(4)
    #     fun2.SetLineStyle(2)
    #     fun2.Draw('same')
    #
    #     lg = TLegend(0.7,0.4, 0.95, 0.5)
    #     lg.SetFillStyle(0)
    #     lg.AddEntry(p1,'Measurement','p')
    #     lg.AddEntry(fun1a,'Fit','l')
    #     lg.AddEntry(fun2,'Gaus','l')
    #     lg.Draw()

    waitRootCmdX()
Пример #6
0
 def setupEventInputs(self, event=None):
     if self.cfg_comp.isMC or self.cfg_comp.isEmbed:
         if not hasattr(self.cfg_comp,"puFileMC") or (self.cfg_comp.puFileMC is None and self.cfg_comp.puFileData is None):
             self.enable = False
         else:
             self.datafile.cd()
             self.mchist = self.datahist.Clone('pileup_MC')
             self.mchist.Reset()
             self.currentFile = event.input.events.object().getTFile().GetName()
             event.input.events.object().getTFile().Get("Events").Draw("slimmedAddPileupInfo.getTrueNumInteractions()>>pileup_MC", "slimmedAddPileupInfo.getBunchCrossing()==0")
             self.mchist = gPad.GetPrimitive("pileup_MC").Clone() # It's the only method that I get to work
             self.mchist.Scale( 1 / self.mchist.Integral(0, self.mchist.GetNbinsX() + 1) )
Пример #7
0
def getCov(t, AVar, BVar, cut='', aBins=None, bBins=None):
    global hcounter
    if aBins != None and bBins != None:
        t.Draw(
            "%s:%s>>htmp(%i,%f,%f,%i,%f,%f)" %
            (AVar, BVar, bBins[0], bBins[1], bBins[2], aBins[0], aBins[1],
             aBins[2]), cut, "colz")
    else:
        t.Draw("%s:%s>>htmp" % (AVar, BVar), cut, "colz")
    htmp = gPad.GetPrimitive('htmp')
    hcounter += 1
    return htmp.GetCovariance()
Пример #8
0
 def __H2(self,
          AVar,
          nABins,
          ALow,
          AHigh,
          BVar,
          nBBins,
          BLow,
          BHigh,
          cut=""):
     usingCached = False
     if self.cachedABT:  # this is only used for MITruth
         htmp = TH2D("h2", "h2", nABins, ALow, AHigh, nBBins, BLow, BHigh)
         for iB in xrange(1, nABins + 1):
             for jB in xrange(1, nBBins + 1):
                 htmp.SetBinContent(
                     iB, jB,
                     self.cachedABT.GetBinContent(iB, jB, 1) +
                     self.cachedABT.GetBinContent(iB, jB, 2))
     if not usingCached:
         print "cut: |%s|" % (cut)
         print "varexp: |%s|" % (
             "%s:%s>>htmpAB(%i,%f,%f,%i,%f,%f)" %
             (BVar, AVar, nABins, ALow, AHigh, nBBins, BLow, BHigh))
         self.t.Draw(
             "%s:%s>>htmpAB(%i,%f,%f,%i,%f,%f)" %
             (BVar, AVar, nABins, ALow, AHigh, nBBins, BLow, BHigh), cut,
             "colz")
         htmp = gPad.GetPrimitive('htmpAB')
     entropy = 0
     integral = 1. * htmp.Integral()
     for iB in xrange(1, nABins + 1):
         for jB in xrange(1, nBBins + 1):
             p = htmp.GetBinContent(iB, jB) / integral
             if p > 0:
                 entropy -= p * log2(p)
     return entropy, htmp
Пример #9
0
def inspectCh(ds, chs):
    t = TTree()
    t.SetFillColor(0)
    t.SetFillStyle(0)
    for d in ds:
        t.ReadFile(d[1])

    cv1 = TCanvas()
    cv1.Divide(2,4)

    icv = 1
    for ch in chs:
        cv1.cd(icv)
        t.Draw('A','ch=={0:d}'.format(ch))
        hx = gPad.GetPrimitive('htemp')
        hx.GetXaxis().SetTitle('U_{Out} [V]')
        hx.SetName('h{0:d}'.format(ch))
        
        lt.DrawLatexNDC(0.7,0.9,"Ch {0:d}".format(ch))

        icv += 1

    cv1.cd(0)
    waitRootCmdX()
Пример #10
0
def MakeHistsToFit2(file, f_out_str):

    E_arr = array('d', [])
    E_arr_err = array('d', [])
    effic_arr = array('d', [])
    effic_arr_err = array('d', [])

    c1 = TCanvas("c1", "c1", 1600, 900)
    c1.SetGridx(1)
    c1.SetGridy(1)

    #Find which energy files exist, create file list and energy array
    f_wogamma_list = []
    curr_E_val = 0.1
    while curr_E_val <= 3.0:
        normfile = REL_DIR + "tree_pi+pi-p_nofit_" + str(curr_E_val) + ".root"
        if (os.path.isfile(normfile)):
            E_arr.append(curr_E_val)
            E_arr_err.append(0)
            f_wogamma_list.append(TFile.Open(normfile, 'read'))
            # print "File found!!!"
            # print "Was looking for file: " + normfile
            # print "Current E val: " + str(curr_E_val)
        # else:
        # print "File not found!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        # print "Was looking for file: " + normfile
        # print "Current E val: " + str(curr_E_val)
        curr_E_val += 0.05

    #Get normalization factor
    norm_arr = array('d', [])
    for i in range(0, len(f_wogamma_list)):
        my_tr = TTree()
        my_tr = f_wogamma_list[i].Get("pi+pi-p_nofit_Tree")
        norm_arr.append(my_tr.GetEntries())
        # print "Energy: "  + str(E_arr[i])
        # print "Normalization: "  + str(norm_arr[i])

    #Create and fit histograms in larger file
    f = TFile.Open(file, 'read')
    my_tr = TTree()
    my_tr = f.Get("gamma_pi+pi-p_nofit_Tree")
    h_DeltaPhi_list = []
    h_DeltaTheta_list = []
    h_EGammaPostCuts_list = []
    for i in range(0, len(E_arr)):
        h_DeltaPhi_curr = TH1F()
        my_tr.Draw("DeltaPhi>>h_DeltaPhi_curr(1000,-180.,180.)", "")
        h_DeltaPhi_curr = gPad.GetPrimitive("h_DeltaPhi_curr")
        h_DeltaPhi_curr.SetName("h_DeltaPhi_" + str(E_arr[i]))
        h_DeltaPhi_list.append(h_DeltaPhi_curr)
        h_DeltaTheta_curr = TH1F()
        my_tr.Draw("DeltaTheta>>h_DeltaTheta_curr(1000,-25.,10.)", "")
        h_DeltaTheta_curr = gPad.GetPrimitive("h_DeltaTheta_curr")
        h_DeltaTheta_curr.SetName("h_DeltaTheta_" + str(E_arr[i]))
        h_DeltaTheta_list.append(h_DeltaTheta_curr)

        h_EGammaPostCuts_curr = TH1F()
        E_cut_str = "abs(ThrownE-" + str(E_arr[i]) + ")<0.0001"
        print "Cut string: " + E_cut_str
        my_tr.Draw("FoundE>>h_EGammaPostCuts_curr(1000,0,4)",
                   "abs(DeltaPhi)<2.&&abs(DeltaTheta)<0.5&&" + E_cut_str)
        h_EGammaPostCuts_curr = gPad.GetPrimitive("h_EGammaPostCuts_curr")
        h_EGammaPostCuts_curr.SetName("h_EGammaPostCuts_" + str(E_arr[i]))
        h_EGammaPostCuts_list.append(h_EGammaPostCuts_curr)

        my_gaus_fit = TF1("my_gaus_fit", "gausn")
        my_gaus_fit.SetParLimits(0, 0, 30000)
        my_gaus_fit.SetParameter(1, E_arr[i])
        my_gaus_fit.SetParLimits(1, E_arr[i] - 0.5, E_arr[i] + 0.1)
        my_gaus_fit.SetParLimits(2, 0.02, 0.5)
        my_gaus_fit.SetNpx(1000)
        h_EGammaPostCuts_curr.Fit(my_gaus_fit, "Q", "", E_arr[i] - 0.3,
                                  E_arr[i] + 0.2)
        c1.SaveAs(".plots/ReactionFilterFit_pipip_" + str(E_arr[i]) + ".png")
        effic = my_gaus_fit.GetParameter(
            0) / h_EGammaPostCuts_curr.GetBinWidth(0) / norm_arr[i]
        effic_err = my_gaus_fit.GetParError(
            0) / h_EGammaPostCuts_curr.GetBinWidth(0) / norm_arr[i]

        if (E_arr[i] < 0.2):
            effic = h_EGammaPostCuts_curr.GetEntries() / norm_arr[i]
            effic_err = sqrt(h_EGammaPostCuts_curr.GetEntries()) / norm_arr[i]
        if (h_EGammaPostCuts_curr.GetEntries() < 100.):
            effic = -1
            effic_err = 0

        print "File Entries: " + str(my_tr.GetEntries())
        print "Histogram Entries: " + str(h_EGammaPostCuts_curr.GetEntries())
        print "Gaussian yield: " + str(
            my_gaus_fit.GetParameter(0) / h_EGammaPostCuts_curr.GetBinWidth(0))
        print "Normalization: " + str(norm_arr[i])
        print "Efficiency: " + str(effic)

        effic_arr.append(effic)
        effic_arr_err.append(effic_err)

    gr_gauscore_effic = TGraphErrors(len(E_arr), E_arr, effic_arr, E_arr_err,
                                     effic_arr_err)
    gr_gauscore_effic.SetName("gr_gauscore_effic")

    f_out = TFile(f_out_str, "RECREATE")
    gr_gauscore_effic.Write()
    for i in range(0, len(E_arr)):
        h_DeltaPhi_list[i].Write()
    for i in range(0, len(E_arr)):
        h_DeltaTheta_list[i].Write()
    for i in range(0, len(E_arr)):
        h_EGammaPostCuts_list[i].Write()
    f_out.Close()

    # curr_E_val = 0.1
    # curr_E_val = 2.0
    # while curr_E_val <= 3.:
    # while curr_E_val <= 2.2:
    # print "Curr E thing " + str(curr_E_val)

    # normfile = REL_DIR+"tree_pi+pi-p_nofit_"+str(curr_E_val)+".root"
    # my_tr2 = TTree()
    # my_tr2 =  f_wogamma_list[i].Get("pi+pi-p_nofit_Tree")
    # NormalizationFactor = my_tr2.GetEntries()

    # curr_E_val+=0.05

    return
Пример #11
0
def MakeHistsToFit(file, MIN_E, MAX_E, E_STEP, f_out_str):

    E_arr = array('d', [])

    c1 = TCanvas("c1", "c1", 1600, 900)
    c1.SetGridx(1)
    c1.SetGridy(1)

    norm_arr = array('d', [])
    curr_E_val = MIN_E
    while curr_E_val <= MAX_E + 0.0001:
        E_arr.append(curr_E_val)
        curr_E_val += E_STEP

    #Create and fit histograms in larger file
    f = TFile.Open(file, 'read')
    my_tr = TTree()
    my_tr = f.Get(WITH_GAMMA_TREENAME)
    h_DeltaPhi_list = []  #List of deltaPhi histograms to save
    h_DeltaTheta_list = []  #List of deltaTheta histograms to save
    h_EGammaPreCuts_list = []  #List of E_gamma histograms to save
    h_EGammaPostCuts_list = []  #List of E_gamma histograms to save
    h_EThrown_list = []  #List of E_gamma histograms to save

    num_tree_entries = float(my_tr.GetEntries())
    num_branch_entries = my_tr.Draw("ThrownE", "")
    norm_scale_factor = num_branch_entries / num_tree_entries

    # print "Num tree entries: " + str(num_tree_entries)
    # print "Num branch entries: " + str(num_branch_entries)

    print "Need to scale by: " + str(norm_scale_factor)

    for i in range(0, len(E_arr)):

        E_cut_str = ""
        if (NORMALIZE_EXTERNAL):
            E_cut_str = "abs(ThrownE-" + str(E_arr[i]) + ")<0.0001"
        if (not NORMALIZE_EXTERNAL):
            E_cut_str = str(E_arr[i] -
                            E_STEP / 2.) + "<ThrownE&&ThrownE<" + str(
                                E_arr[i] +
                                E_STEP / 2.) + "&&ThrownTheta<9&&ThrownTheta>4"
        print "Cut string: " + E_cut_str

        #Make DeltaPhi and DeltaTheta histograms
        h_DeltaPhi_curr = TH1F()
        my_tr.Draw("DeltaPhi>>h_DeltaPhi_curr(1000,-180.,180.)", E_cut_str)
        h_DeltaPhi_curr = gPad.GetPrimitive("h_DeltaPhi_curr")
        if (NORMALIZE_EXTERNAL):
            h_DeltaPhi_curr.SetNameTitle("h_DeltaPhi_" + str(E_arr[i]),
                                         "h_DeltaPhi_" + str(E_arr[i]))
        if (not NORMALIZE_EXTERNAL):
            h_DeltaPhi_curr.SetNameTitle("h_DeltaPhi_" + E_cut_str,
                                         "h_DeltaPhi_" + E_cut_str)
        h_DeltaPhi_list.append(h_DeltaPhi_curr)
        print "h_DeltaPhi_curr hist entries:" + str(
            h_DeltaPhi_curr.GetEntries())

        h_DeltaTheta_curr = TH1F()
        my_tr.Draw("DeltaTheta>>h_DeltaTheta_curr(1000,-25.,10.)", E_cut_str)
        h_DeltaTheta_curr = gPad.GetPrimitive("h_DeltaTheta_curr")
        if (NORMALIZE_EXTERNAL):
            h_DeltaTheta_curr.SetNameTitle("h_DeltaTheta_" + str(E_arr[i]),
                                           "h_DeltaTheta_" + str(E_arr[i]))
        if (not NORMALIZE_EXTERNAL):
            h_DeltaTheta_curr.SetNameTitle("h_DeltaTheta_" + E_cut_str,
                                           "h_DeltaTheta_" + E_cut_str)
        h_DeltaTheta_list.append(h_DeltaTheta_curr)
        print "h_DeltaTheta_curr hist entries:" + str(
            h_DeltaTheta_curr.GetEntries())

        h_EGammaPreCuts_curr = TH1F()
        my_tr.Draw(
            "FoundE>>h_EGammaPreCuts_curr(1000,0," + str(MAX_E + 1) + ")",
            E_cut_str)
        h_EGammaPreCuts_curr = gPad.GetPrimitive("h_EGammaPreCuts_curr")
        if (NORMALIZE_EXTERNAL):
            h_EGammaPreCuts_curr.SetNameTitle(
                "h_EGammaPreCuts_" + str(E_arr[i]),
                "h_EGammaPreCuts_" + str(E_arr[i]))
        if (not NORMALIZE_EXTERNAL):
            h_EGammaPreCuts_curr.SetNameTitle("h_EGammaPreCuts_" + E_cut_str,
                                              "h_EGammaPreCuts_" + E_cut_str)
        h_EGammaPreCuts_list.append(h_EGammaPreCuts_curr)
        print "h_EGammaPreCuts_curr hist entries:" + str(
            h_EGammaPreCuts_curr.GetEntries())

        h_EGammaPostCuts_curr = TH1F()
        my_tr.Draw(
            "FoundE>>h_EGammaPostCuts_curr(1000,0," + str(MAX_E + 1) + ")",
            "abs(DeltaPhi)<" + DELTA_PHI_CUT + "&&abs(DeltaTheta)<" +
            DELTA_THETA_CUT + "&&" + E_cut_str)
        h_EGammaPostCuts_curr = gPad.GetPrimitive("h_EGammaPostCuts_curr")
        if (NORMALIZE_EXTERNAL):
            h_EGammaPostCuts_curr.SetNameTitle(
                "h_EGammaPostCuts_" + str(E_arr[i]),
                "h_EGammaPostCuts_" + str(E_arr[i]))
        if (not NORMALIZE_EXTERNAL):
            h_EGammaPostCuts_curr.SetNameTitle("h_EGammaPostCuts_" + E_cut_str,
                                               "h_EGammaPostCuts_" + E_cut_str)
        h_EGammaPostCuts_curr.SetTitle("E_{#gamma} thrown = " + str(E_arr[i]))
        h_EGammaPostCuts_curr.GetXaxis().SetTitle("E_{#gamma}")
        h_EGammaPostCuts_curr.GetYaxis().SetTitle("Yield")
        h_EGammaPostCuts_list.append(h_EGammaPostCuts_curr)
        print "h_EGammaPostCuts_curr hist entries:" + str(
            h_EGammaPostCuts_curr.GetEntries())

        h_EThrown_curr = TH1F()
        # my_tr.Draw("ThrownE>>h_EThrown_curr(1000,0,10",E_cut_str)
        my_tr.Draw("MCWeight>>h_EThrown_curr(1000,-10,10", E_cut_str)
        h_EThrown_curr = gPad.GetPrimitive("h_EThrown_curr")
        if (NORMALIZE_EXTERNAL):
            h_EThrown_curr.SetNameTitle("h_EThrown_" + str(E_arr[i]),
                                        "h_EThrown_" + str(E_arr[i]))
        if (not NORMALIZE_EXTERNAL):
            h_EThrown_curr.SetNameTitle("h_EThrown_" + E_cut_str,
                                        "h_EThrown_" + E_cut_str)
        h_EThrown_curr.SetTitle("E_{#gamma} thrown = " + str(E_arr[i]))
        h_EThrown_curr.GetXaxis().SetTitle("E_{#gamma}")
        h_EThrown_curr.GetYaxis().SetTitle("Yield")
        h_EThrown_list.append(h_EThrown_curr)
        print "h_EThrown_curr hist entries:" + str(h_EThrown_curr.GetEntries())

    #Save to file
    f_out = TFile(f_out_str, "RECREATE")
    # gr_gauscore_effic.Write()

    for i in range(0, len(E_arr)):
        h_EGammaPostCuts_list[i].Write()
    for i in range(0, len(E_arr)):
        h_DeltaPhi_list[i].Write()
    for i in range(0, len(E_arr)):
        h_DeltaTheta_list[i].Write()
    for i in range(0, len(E_arr)):
        h_EGammaPreCuts_list[i].Write()
    for i in range(0, len(E_arr)):
        h_EThrown_list[i].Write()
    f_out.Close()

    return norm_scale_factor
Пример #12
0
def makeCutROCPlus(name,
                   eTree,
                   rTree,
                   var,
                   rocAry,
                   prevCut,
                   baseCut='',
                   text=''):

    # Mapping for renaming aspects depending on if dPhi or dEta is the 'leading' cut
    nameMap = {
        'abs(trackDeltaEta)': ['abs(trackDeltaPhi)', 'phi', 'eta'],
        'abs(trackDeltaPhi)': ['abs(trackDeltaEta)', 'eta', 'phi']
    }

    # Get our total # of events for sig and bkg
    eTree.Draw(var, baseCut)
    hE = gPad.GetPrimitive("htemp")
    sigInit = hE.Integral()
    rTree.Draw(var, baseCut)
    hR = gPad.GetPrimitive("htemp")
    bkgInit = hR.Integral()

    # Extra cuts to vary phi and eta simultaneously
    dXCuts = []
    for i in range(1, 8):
        dXCuts.append(i * .01)
    dXCuts = [0.01, 0.02, 0.03, 0.04, 0.05, 0.08, 0.12, 0.2, 0.5]

    sigs = {}
    bkgs = {}
    graphs = {}
    for cut in dXCuts:
        # For storing our values as we check the cuts
        sigs[cut] = array('d', [])
        bkgs[cut] = array('d', [])

        # Plot our distribution, and check yields as we
        # integrate along it
        if baseCut != '': prevCut += "*" + baseCut
        addition = "*(%s<%f)" % (nameMap[var][0], cut)
        h1 = ROOT.TH1F('h1', 'h1', rocAry[0], rocAry[1], rocAry[2])
        eTree.Draw(var + ' >> h1', prevCut + addition)
        h2 = ROOT.TH1F('h2', 'h2', rocAry[0], rocAry[1], rocAry[2])
        rTree.Draw(var + ' >> h2', prevCut + addition)

        #for b in range( 1, h1.GetNbinsX()+1 ) :
        for b in range(0, h1.GetNbinsX()):
            eInt = h1.Integral(0, b)
            rInt = h2.Integral(0, b)
            sigs[cut].append(eInt / sigInit)
            bkgs[cut].append(1. - rInt / bkgInit)
        del h1, h2

        graphs[cut] = ROOT.TGraph(rocAry[0], sigs[cut], bkgs[cut])
        graphs[cut].SetTitle("d#%s < %.2f" % (nameMap[var][1], cut))

    c = ROOT.TCanvas('c', 'c', 800, 800)
    c.SetGrid()
    c.SetTitle(name)

    leg = setLegStyle(0.2, 0.3, 0.47, 0.6)
    leg.SetFillStyle(1001)
    leg.SetFillColor(ROOT.kWhite)

    # Set everything for the first one and draw it
    graphs[dXCuts[0]].Draw()
    graphs[dXCuts[0]].GetXaxis().SetTitle('Signal Efficiency')
    graphs[dXCuts[0]].GetYaxis().SetTitle('Background Rejection')
    #graphs[dXCuts[0]].SetMaximum( 0.95 )
    #graphs[dXCuts[0]].SetMinimum( 0.6 )
    #graphs[dXCuts[0]].GetXaxis().SetLimits( 0.3, 1. )
    #if 'Baseline' in name :
    graphs[dXCuts[0]].SetMaximum(1.05)
    graphs[dXCuts[0]].SetMinimum(0.0)
    graphs[dXCuts[0]].GetXaxis().SetLimits(0.0, 1.)
    #graphs[dXCuts[0]].SetLineColor(ROOT.kRed-10)
    graphs[dXCuts[0]].SetLineColor(1)
    graphs[dXCuts[0]].SetLineWidth(2)
    graphs[dXCuts[0]].SetMarkerStyle(0)
    graphs[dXCuts[0]].Draw()
    leg.AddEntry(graphs[dXCuts[0]], graphs[dXCuts[0]].GetTitle(), "lpe")
    dXCuts.remove(dXCuts[0])

    for i, cut in enumerate(dXCuts):
        #graphs[cut].Draw('SAME')
        #if i < 5 :
        #    graphs[cut].SetLineColor(ROOT.kRed-10+2*(i+1) )
        #else :
        #    graphs[cut].SetLineColor(ROOT.kBlue-10+2*(i+1) )
        graphs[cut].SetLineColor(2 + i)
        graphs[cut].SetLineWidth(2)
        graphs[cut].Draw('SAME')
        leg.AddEntry(graphs[cut], graphs[cut].GetTitle(), "lpe")
    leg.Draw()
    c.Update()

    if text:
        txt1 = ROOT.TLatex(.2, .80, "x")
        txt1.SetTextSize(0.04)
        txt1.DrawLatexNDC(.2, .15, text)
        if baseCut != '' and "Baseline" not in name:
            txt2 = ROOT.TLatex(.2, .80, "x")
            txt2.SetTextSize(0.035)
            text2 = "All considered events passing: %s" % baseCut
            txt2.DrawLatexNDC(.2, .19, text2)

    c.Print('plotsOpt/ROCPlus_' + name + '.png')
Пример #13
0
def makeCutROC(name, eTree, rTree, var, rocAry, prevCut, baseCut='', text=''):

    # Get our total # of events for sig and bkg
    eTree.Draw(var, baseCut)
    hE = gPad.GetPrimitive("htemp")
    sigInit = hE.Integral()
    rTree.Draw(var, baseCut)
    hR = gPad.GetPrimitive("htemp")
    bkgInit = hR.Integral()

    # For storing our values as we check the cuts
    sigVals = array('d', [])
    bkgVals = array('d', [])
    paramVals = array('d', [])

    # Plot our distribution, and check yields as we
    # integrate along it
    if baseCut != '': prevCut += "*" + baseCut
    h1 = ROOT.TH1F('h1', 'h1', rocAry[0], rocAry[1], rocAry[2])
    eTree.Draw(var + ' >> h1', prevCut)
    h2 = ROOT.TH1F('h2', 'h2', rocAry[0], rocAry[1], rocAry[2])
    rTree.Draw(var + ' >> h2', prevCut)

    #for b in range( 1, h1.GetNbinsX()+1 ) :
    for b in range(0, h1.GetNbinsX()):
        paramVals.append(h1.GetXaxis().GetBinCenter(b))
        eInt = h1.Integral(0, b)
        rInt = h2.Integral(0, b)
        #if b < 10 :
        #    print "Eff: %f    Rate: %f" % (eInt,rInt)
        sigVals.append(eInt / sigInit)
        bkgVals.append(1. - rInt / bkgInit)
        if abs(sigVals[-1] - .9) < 0.001:
            print "Cut: %f    Sig: %f    Bkg: %f" % (paramVals[-1],
                                                     sigVals[-1], bkgVals[-1])
        if 'PtMatch' in name:
            if abs(sigVals[-1] - .9) < 0.01:
                print "Cut: %f    Sig: %f    Bkg: %f" % (
                    paramVals[-1], sigVals[-1], bkgVals[-1])
            if abs(sigVals[-1] - .95) < 0.01:
                print "Cut: %f    Sig: %f    Bkg: %f" % (
                    paramVals[-1], sigVals[-1], bkgVals[-1])

    c = ROOT.TCanvas('c', 'c', 800, 800)
    c.SetGrid()
    c.SetTitle(name)
    g = ROOT.TGraph(rocAry[0], sigVals, bkgVals)
    g.Draw()
    g.GetXaxis().SetTitle('Signal Efficiency')
    g.GetYaxis().SetTitle('Background Rejection')
    g.SetMarkerStyle(0)
    g.SetLineColor(2)
    g.SetLineWidth(2)
    g.SetMaximum(1.05)
    g.SetMinimum(0.5)
    if "BaselineCut" in name:
        g.SetMinimum(0.0)
    g.GetXaxis().SetLimits(0.0, 1.)
    g.Draw()
    c.Update()

    if text:
        chan = ROOT.TLatex(.2, .80, "x")
        chan.SetTextSize(0.04)
        chan.DrawLatexNDC(.2, .2, text)

    c.Print('plotsOpt/ROC_' + name + '.png')