Exemple #1
0
def drawTitle(text):
    '''Takes in the title text and draws it to the top of the current pad'''
    headerText = TText(.5, .95, text)
    headerText.SetTextAlign(22)
    headerText.Draw()

    return headerText
def D1H_txt_to_root(filename, outputpath=''):
    from ROOT import TFile, TCanvas, TPad, TH1D, TLatex, TStyle, gStyle, TText, gPad, TPaveText
    from inspect import currentframe, getframeinfo

    #gStyle.SetOptStat(0)
    can = TCanvas("can", "can", 200, 10, 500, 500)
    fileroot = filename.replace(".txt", "")
    fileroot = fileroot + "_F.root"
    f = open(filename, "r")

    lineList = f.readlines()
    Nbin = (len(lineList))  # get number of bins
    Line_string = str(lineList[0])
    _, bin_init, _, _ = Line_string.split()
    bin_init = float(bin_init)  # get initial bin
    Line_string = str(lineList[len(lineList) - 1])
    _, _, bin_final, _ = Line_string.split()
    bin_final = float(bin_final)  # get final bin
    f.seek(0)  # reset python read line

    hist = TH1D("h1f", "h1f", Nbin, bin_init, bin_final)
    total_e = 0
    for i in range(1, Nbin + 1):
        Line_string = str(f.readline())
        _, _, _, bin_c = Line_string.split()
        bin_c = float(bin_c)
        hist.SetBinContent(i, bin_c)
        total_e = total_e + bin_c
    total_e = int(total_e)
    hist.Draw()
    text = TText(hist.GetXaxis().GetBinCenter(2),
                 hist.GetYaxis().GetBinCenter(1),
                 "Recycled. Total Entry : %i" % total_e)
    text.SetTextFont(10)
    text.Draw()
    gPad.Update()
    can.Update()

    if (outputpath == ''):
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    else:
        fileroot = outputpath + "/_processed.root"
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    hist.Write()
    wf.Close()
    return fileroot
Exemple #3
0
def D1H_txt_to_roothist(filename, outputpath=''):
    from ROOT import TFile, TCanvas, TPad, TH1D, TLatex, TStyle, gStyle, TText, gPad, TPaveText
    from inspect import currentframe, getframeinfo
    import os

    #gStyle.SetOptStat(0)
    can = TCanvas("can", "can", 200, 10, 500, 500)

    if (filename[0] == "/"):
        filename = filename
    else:
        filename = os.getcwd(
        ) + "/" + filename  # get the path included filename
    loca = len(filename)
    for i in range(1, len(filename) + 1):  # find the "/" location
        if (filename[-i] == "/"):
            loca = i - 1
            break

    FILENAME = filename.replace(filename[:-loca],
                                "")  # this is the shorten filename
    #    print(FILENAME, "******")

    fileroot = filename.replace(".txt", "_F.root")
    fileroot = fileroot.replace("//", "/")
    f = open(filename, "r")

    lineList = f.readlines()
    Nbin = (len(lineList))  # get number of bins
    Line_string = str(lineList[0])
    _, bin_init, _, _ = Line_string.split()
    bin_init = float(bin_init)  # get initial bin
    Line_string = str(lineList[len(lineList) - 1])
    _, _, bin_final, _ = Line_string.split()
    bin_final = float(bin_final)  # get final bin
    f.seek(0)  # reset python read line

    hist = TH1D("hist", "hist", Nbin, bin_init, bin_final)
    total_e = 0
    for i in range(1, Nbin + 1):
        Line_string = str(f.readline())
        _, _, _, bin_c = Line_string.split()
        bin_c = float(bin_c)
        hist.SetBinContent(i, bin_c)
        total_e = total_e + bin_c
    total_e = int(total_e)
    hist.Draw()
    text = TText(hist.GetXaxis().GetBinCenter(2),
                 hist.GetYaxis().GetBinCenter(1),
                 "Recycled. Total Entry : %i" % total_e)
    text.SetTextFont(10)
    text.Draw()
    gPad.Update()
    can.Update()

    if (outputpath == ''):
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    else:
        if (outputpath[0] == "/"):
            fileroot = outputpath + "/" + FILENAME.replace(".txt", "_F.root")
            fileroot = fileroot.replace("//", "/")
        elif (outputpath[0] == "~"):
            fileroot = outputpath.replace(
                "~", os.environ['HOME']) + "/" + FILENAME.replace(
                    ".txt", "_F.root")
            fileroot = fileroot.replace("//", "/")
        else:
            fileroot = os.getcwd() + "/" + outputpath + "/" + FILENAME.replace(
                ".txt", "_F.root")
            fileroot = fileroot.replace("//", "/")
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    hist.Write()
    wf.Close()
    fileroot = fileroot.replace("//", "/")
    #    print(fileroot)
    return fileroot
Exemple #4
0
ar1.DrawArrow(.50, .275, .59, .275, 0.015, '|>')
ar1.DrawArrow(.70, .275, .79, .275, 0.015, '|>')
ar1.DrawArrow(.45, .175, .54, .175, 0.015, '|>')
ar1.DrawArrow(.43, .075, .54, .075, 0.015, '|>')
ar1.DrawArrow(.41, -.025, .54, -.025, 0.015, '|>')
ldot = TLine(.95, .92, .99, .92)
ldot.SetLineStyle(3)
ldot.Draw()
ldot.DrawLine(.9, .775, .99, .775)
ldot.DrawLine(.9, .275, .99, .275)
ldot.DrawLine(.55, .05, .55, 0)
ldot.DrawLine(.9, .05, .75, 0)
pname = TText(.46, .21, 'fEventOffset')
pname.SetTextFont(72)
pname.SetTextSize(0.018)
pname.Draw()
pname.DrawText(.44, .11, 'fBuffer')
pname.DrawText(.42, .01, 'fZipBuffer')
pname.DrawText(.26, .81, 'fLeaves = TObjArray of TLeaf')
pname.DrawText(.24, .40, 'fBasketEvent')
pname.DrawText(.22, .31, 'fBaskets = TObjArray of TBasket')
pname.DrawText(.20, 1.0, 'fBranches = TObjArray of TBranch')
ntleaf = TPaveText(0.30, .42, .62, .7)
ntleaf.SetTextSize(0.014)
ntleaf.SetFillColor(leafcolor)
ntleaf.SetTextAlign(12)
ntleaf.AddText('fLen: number of fixed elements')
ntleaf.AddText('fLenType: number of bytes of data type')
ntleaf.AddText('fOffset: relative to Leaf0-fAddress')
ntleaf.AddText('fNbytesIO: number of bytes used for I/O')
ntleaf.AddText('fIsPointer: True if pointer')
file.AddText('Header')
arrow = TArrow(6, 20.5, 17, 20.5, 0.02, '|>')
arrow.SetFillStyle(1001)
arrow.SetLineWidth(2)
arrow.Draw()
free = TPaveText(8, 20, 11, 21)
free.SetFillColor(18)
free.Draw()
free.AddText('First:Last')
free2 = TPaveText(12, 20, 15, 21)
free2.SetFillColor(18)
free2.Draw()
free2.AddText('First:Last')
tfree = TText(6.2, 21.2, 'fFree = TList of free blocks')
tfree.SetTextSize(0.02)
tfree.Draw()
tkeys = TText(5.2, 18.2, 'fKeys = TList of Keys')
tkeys.SetTextSize(0.02)
tkeys.Draw()
tmemory = TText(3.2, 15.2, 'fListHead = TList of Objects in memory')
tmemory.SetTextSize(0.02)
tmemory.Draw()

arrow.DrawArrow(5, 17, 17, 17, 0.02, '|>')
line = TLine(5, 19, 5, 17)
line.SetLineWidth(2)
line.Draw()
key0 = TPaveText(7, 16, 10, 18)
key0.SetTextSize(0.04)
key0.SetFillColor(keycolor)
key0.AddText('Key 0')
            h_2_6.Fill(float(t_run)/60.)

c1 = TCanvas("c1","Root Canvas",40,20,800,600)

gStyle.SetOptStat(111111)

h_1.SetFillColor(36)
h_1.GetYaxis().SetTitleOffset(1.2)
h_1.SetYTitle('Entries')
h_1.SetXTitle('Time, s')
c1.SetLogy()
h_1.Draw()

t_task = TText(0.35,0.8,'Task '+ task + " SIGNET" )
t_task.SetNDC()
t_task.Draw()

#print time stamp
t_time = datetime.now()
t_label = 'SP ' + t_time.strftime("%Y-%m-%d")

t = TText(0.905,0.6,t_label)
t.SetNDC()
t.SetTextAlign(21) # middle, bottom
t.SetTextAngle(-90)
t.SetTextSize(0.017)
t.Draw()

c1.Modified()
c1.Update()
Exemple #7
0
arrow.SetFillStyle( 1001 )
arrow.Draw()
line.DrawLine( 7, 8.5, 7, 8.0 )
line.DrawLine( 7, 8.0, 10.6, 8 )
arrow.DrawArrow( 10.6,8, 10.6, 8.4, 0.01, '|>' )
line.DrawLine( 10.6, 11, 10.6, 11.5 )
line.DrawLine( 10.6, 11.5, 14.6, 11.5 )
arrow.DrawArrow( 14.6, 11.5, 14.6, 11.1, 0.01, '|>' )
line.DrawLine( 14.6, 8.5, 14.6, 8.0 )
line.DrawLine( 14.6, 8.0, 16, 8 )
ldot.DrawLine( 16, 8, 19, 8 )
vert = TText( 1.5, 9.75, 'File' )
vert.SetTextAlign( 21 )
vert.SetTextAngle( 90 )
vert.SetTextSize( 0.025 )
vert.Draw()
vert.DrawText(  2.0, 9.75, 'Header' )
vert.DrawText(  2.9, 9.75, 'Logical Record' )
vert.DrawText(  3.2, 9.75, 'Header' )
vert.DrawText(  7.3, 9.75, 'Logical Record' )
vert.DrawText(  7.6, 9.75, 'Header' )
vert.DrawText( 10.9, 9.75, 'Logical Record' )
vert.DrawText( 11.2, 9.75, 'Header' )
vert.DrawText( 14.9, 9.75, 'Logical Record' )
vert.DrawText( 15.2, 9.75, 'Header' )
hori = TText( 4.75, 10, 'Object' )
hori.SetTextAlign( 22 )
hori.SetTextSize( 0.035 )
hori.Draw()
hori.DrawText( 4.75, 9.5, 'Data' )
hori.DrawText( 9.2, 10, 'Deleted' )
    def MCSPlot(self, pname):

        #print self.fname
        f = TFile(self.fname)
        self.RMS = {}
        self.RMSErr = {}
        self.Chi2 = {}
        self.RMSsysdiff = {}
        self.RMSsyserr = {}

        # create a plot for each histvarname
        for histvar in self.histvarnames:
            self.RMS[histvar] = {}
            self.RMSErr[histvar] = {}
            self.RMSsysdiff[histvar] = {}
            self.RMSsyserr[histvar] = {}
            self.Chi2[histvar] = {}
            names = [histvar + '_' + x for x in self.histstatenames]
            print names
            hists = [f.Get(histvar + '_' + x) for x in self.histstatenames]

            print hists[0]
            hists[0].SetTitle("")
            # hists[3].Scale(norm)
            # self.formatHist(hist[0], 0)
            resplots = [x.Clone() for x in hists]
            resplots[0].SetTitle('')
            resplots[0].GetYaxis().SetTitle("Normalized Residuals")

            # if histvar == 'thetaScatt':
            leg = TLegend(0.55, 0.73, 0.89, 0.92)
            leg.SetLineColor(10)
            # else:
            #    leg = TLegend(0.35,0.2,0.65,0.5)
            for i in range(len(self.histstatedesc)):
                hists[i].Sumw2()
                if histvar == 'theta2Scatt':
                    hists[i].Rebin(8)
                    resplots[i].Rebin(8)
                elif histvar == 'thetaScatt':
                    hists[i].Rebin(1)
                    resplots[i].Rebin(1)
                else:
                    hists[i].Rebin(1)
                    resplots[i].Rebin(1)
                self.formatHists(hists[i], i)
                self.formatHists(resplots[i], i)
                self.addToRMS(i, hists[i], hists[0], resplots[i], histvar)
                if histvar == 'theta2Scatt':
                    hists[i].GetYaxis().SetTitle('Probability per ' + str(
                        round(1000 * 1000 *
                              hists[i].GetXaxis().GetBinWidth(4), 2)) +
                                                 ' mrad^{2}')
                else:
                    hists[i].GetYaxis().SetTitle('Probability per ' + str(
                        round(1000 * hists[i].GetXaxis().GetBinWidth(4), 2)) +
                                                 ' mrad')
                leg.AddEntry(hists[i], self.histstatedesc[i], self.histopts[i])
                #print hists[0]
                self.calculateChi2(i, hists[i], hists[0], resplots[i], histvar,
                                   pname)

            c = TCanvas(self.fname[:-5] + '_' + histvar + '_c1')
            if self.desc[0] == 'XePion':
                t1 = TText(0.18, 0.885, "MICE ISIS cycle 2015/03")
                t2 = TText(0.18, 0.85,
                           "Xe, " + self.desc[1][2:5] + ", MAUS v3.1.2")
            else:
                t1 = TText(0.18, 0.885, "MICE ISIS cycle 2015/04")
                t2 = TText(0.18, 0.85,
                           "LiH, " + self.desc[1][2:5] + ", MAUS v3.1.2")
            t1.SetNDC(1)
            t1.SetTextSize(0.04)
            t1.SetTextFont(42)
            t2.SetNDC(1)
            t2.SetTextSize(0.03)
            t2.SetTextFont(42)

            hists[0].GetYaxis().SetRangeUser(4e-4, 2.0)
            hists[0].SetTitle(";" + hists[0].GetXaxis().GetTitle() +
                              " (radians);" + hists[0].GetYaxis().GetTitle())
            hists[0].Draw('ep')

            c.SetBottomMargin(0.15)
            c.SetTopMargin(0.075)

            for h in hists[1:len(self.histstatedesc)]:
                h.Draw('epsame')
            leg.SetTextSize(0.04)
            leg.Draw('same')
            t1.Draw()
            t2.Draw()
            c.SetLogy()
            c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar +
                     '_sys.eps')
            c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar +
                     '_sys.root')
            c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar +
                     '_sys_pq.jpg')
            c.Clear()

            c.SetLogy(0)
            resplots[0].GetYaxis().SetRangeUser(-2, 2)
            resplots[0].SetTitle(";" + resplots[0].GetXaxis().GetTitle() +
                                 " (radians);" +
                                 resplots[0].GetYaxis().GetTitle())
            leg.SetX1NDC(0.5)
            leg.SetX2NDC(0.89)
            leg.SetY1NDC(0.2)
            leg.SetY2NDC(0.4)
            resplots[0].Draw("p")
            for r in resplots:
                r.Draw('psame')
            leg.SetTextSize(0.04)
            leg.Draw('same')
            t1.Draw()
            t2.Draw()
            # pblock.Draw()
            c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar +
                     '_sys_res_T.eps')
            c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar +
                     '_sys_res_pq.jpg')

        momhist = f.Get("cor_mom")
        #mom = [momhist.GetMean() + 19.468, momhist.GetMeanError()]
        #if self.fname.find("LiHMuon_03172")  >= 0:
        #    mom = [momhist.GetMean()*1.107 + 1.05, momhist.GetMeanError()]
        #elif self.fname.find("LiHMuon_03200")  >= 0:
        #    mom = [momhist.GetMean()*1.104 + 1.139, momhist.GetMeanError()]
        #elif self.fname.find("LiHMuon_03240")  >= 0:
        #    mom = [momhist.GetMean()*1.17 - 9.41, momhist.GetMeanError()]
        if self.fname.find("LiHMuon_03172") >= 0:
            mom = [momhist.GetMean(), momhist.GetMeanError()]
        elif self.fname.find("LiHMuon_03200") >= 0:
            mom = [momhist.GetMean(), momhist.GetMeanError()]
        elif self.fname.find("LiHMuon_03240") >= 0:
            mom = [momhist.GetMean(), momhist.GetMeanError()]
        rms = [momhist.GetRMS(), momhist.GetRMSError()]
        summary = []
        syssummary = []

        def sigfig(x):
            if math.fabs(x) > 1e-5:
                return int(math.ceil(math.fabs(math.log(math.fabs(x), 10))))
            else:
                return 1

    # syssummary.append("p (MeV/c) & "+self.histvarnames[0]+"&"+self.histvarnames[1]+"&"+self.histvarnames[3]+"\\\\")

        if pname != "Truth":

            for sys in self.sysFiles:
                # if sys[3] == 'Material': stindx = 1
                # else:
                stindx = 0
                # print sys[3], self.histstatenames[stindx]

                difference0 = self.RMSsysdiff[self.histvarnames[0]][
                    self.histstatenames[stindx]][sys[3]]
                difference1 = self.RMSsysdiff[self.histvarnames[1]][
                    self.histstatenames[stindx]][sys[3]]
                difference3 = self.RMSsysdiff[self.histvarnames[3]][
                    self.histstatenames[stindx]][sys[3]]

                syserr0 = self.RMSsyserr[self.histvarnames[0]][
                    self.histstatenames[stindx]][sys[3]]
                syserr1 = self.RMSsyserr[self.histvarnames[1]][
                    self.histstatenames[stindx]][sys[3]]
                syserr3 = self.RMSsyserr[self.histvarnames[3]][
                    self.histstatenames[stindx]][sys[3]]

                relerr0 = syserr0 / self.RMS[self.histvarnames[0]][
                    self.histstatenames[0]]
                relerr1 = syserr1 / self.RMS[self.histvarnames[1]][
                    self.histstatenames[0]]
                relerr3 = syserr3 / self.RMS[self.histvarnames[3]][
                    self.histstatenames[0]]

                syssummary.append(str(round(mom[0],sigfig(mom[1])))+"$\pm$"+str(round(mom[1],sigfig(mom[1])))+\
                                  " & "+str(round(difference0,sigfig(difference0)))+\
                                  " & "+str(round(syserr0,sigfig(syserr0)))+\
                                  " & "+str(round(relerr0,sigfig(relerr0)))+\
                                  " & "+str(round(difference1,sigfig(difference1)))+\
                                  " & "+str(round(syserr1,sigfig(syserr1)))+\
                                  " & "+str(round(relerr1,sigfig(relerr1)))+\
                                  " & "+str(round(difference3,sigfig(difference3)))+\
                                  " & "+str(round(syserr3,sigfig(syserr3)))+\
                                  " & "+str(round(relerr3,sigfig(relerr3)))+"\\\\")
                # print syssummary[-1]

            syssummary.append(str(round(mom[0],2))+"$\pm$"+str(round(mom[1],2))+\
                             " & "+ str(round(rms[0],2))+"$\pm$"+str(round(rms[1],2))+\
                             " & "+str(round(self.RMSsysdiff[self.histvarnames[0]][self.histstatenames[0]]['Sum'],2))+\
                             " & "+str(round(self.RMSsyserr[self.histvarnames[0]][self.histstatenames[0]]['Sum'],2))+\
                             " & "+str(round(self.RMSsyserr[self.histvarnames[0]][self.histstatenames[0]]['Sum']/self.RMS[self.histvarnames[0]][self.histstatenames[0]],2))+\
                             " & "+str(round(self.RMSsysdiff[self.histvarnames[1]][self.histstatenames[0]]['Sum'],2))+\
                             " & "+str(round(self.RMSsyserr[self.histvarnames[1]][self.histstatenames[0]]['Sum'],2))+\
                             " & "+str(round(self.RMSsyserr[self.histvarnames[1]][self.histstatenames[0]]['Sum']/self.RMS[self.histvarnames[1]][self.histstatenames[0]],2))+\
                             " & "+str(round(self.RMSsysdiff[self.histvarnames[3]][self.histstatenames[0]]['Sum'],2))+
                             " & "+str(round(self.RMSsyserr[self.histvarnames[3]][self.histstatenames[0]]['Sum'],2))+
                             " & "+str(round(self.RMSsyserr[self.histvarnames[3]][self.histstatenames[0]]['Sum']/self.RMS[self.histvarnames[2]][self.histstatenames[0]],2))+"\\\\")

            # summary.append("p (MeV/c) &  &"+str(self.histstatenames[0])+" & "+str(self.histstatenames[1])+" & $\chi^{2}$/ndf & "+
            #                +str(self.histstatenames[2])+" & $\chi^{2}$/ndf \\\\")
            # print mom, self.RMS, self.RMSErr, self.Chi2

            for histvar in self.histvarnames:
                summary.append(str(round(mom[0],2))+"$\pm$"+str(round(mom[1],2))+\
                               "& $\ "+histvar+"$ & "+str(round(self.RMS[histvar][self.histstatenames[0]],2))+ \
                               "$\pm$"+str(round(self.RMSErr[histvar][self.histstatenames[0]],2))+ \
                               "$\pm$"+str(round(self.RMSsyserr[histvar][self.histstatenames[0]]["Sum"],2))+ \
                               " & "+str(round(self.RMS[histvar][self.histstatenames[1]],2))+ \
                               "$\pm$"+str(round(self.RMSErr[histvar][self.histstatenames[1]],2))+ \
                           # "$\pm$"+str(round(self.RMSsyserr[histvar][self.histstatenames[1]]["Sum"],2))+\
                               " & "+str(round(self.Chi2[histvar][self.histstatenames[1]][0],1))+ \
                               " / "+ str(self.Chi2[histvar][self.histstatenames[1]][1])+ \
                               " & "+str(round(self.RMS[histvar][self.histstatenames[2]],2))+ \
                               "$\pm$"+str(round(self.RMSErr[histvar][self.histstatenames[2]],2))+ \
                           #"$\pm$"+str(round(self.RMSsyserr[histvar][self.histstatenames[2]]["Sum"],2))+\
                               " & "+str(round(self.Chi2[histvar][self.histstatenames[2]][0],1))+ \
                               " / "+ str(self.Chi2[histvar][self.histstatenames[2]][1])
                               +"\\\\")
                # print summary[-1]

            f.Close()
            return [summary, syssummary]
Exemple #9
0
class photon_detector(object):
    #_____________________________________________________________________________
    def __init__(self):
        #length, height and distance of the front side from the origin, all in m
        self.length = 8.
        self.height = 0.15
        self.dist = 23.2
        self.angle = -0.025  # rotation to be on electron beam axis

    #_____________________________________________________________________________
    def rotate(self, theta):
        #rotate by angle theta about the origin
        self.angle += theta

    #_____________________________________________________________________________
    def draw_2d(self):

        #make corner points
        vec = []
        vec.append(TVector2(self.length / 2, -self.height / 2))
        vec.append(TVector2(-self.length / 2, -self.height / 2))
        vec.append(TVector2(-self.length / 2, self.height / 2))
        vec.append(TVector2(self.length / 2, self.height / 2))

        #rotate and translate along electron beam
        vtrans = TVector2(-1, 0).Rotate(self.angle)
        vtrans.SetMagPhi(self.dist + self.length / 2, vtrans.Phi())
        for i in xrange(len(vec)):
            vec[i] = vec[i].Rotate(self.angle)
            vec[i] += vtrans

        #last point same as the first
        vec.append(vec[0])

        self.geom = TGraph(len(vec))
        self.geom.SetLineWidth(2)
        self.geom.SetLineColor(rt.kYellow + 1)
        self.geom.SetFillColor(rt.kYellow)
        for i in xrange(len(vec)):
            self.geom.SetPoint(i, vec[i].X(), vec[i].Y() * 100)

        self.geom.Draw("lfsame")

        #label
        self.label = TText(vtrans.X(),
                           (vtrans.Y() - self.height / 2 - 0.11) * 100 - 3,
                           "Lumi detector")
        self.label.SetTextSize(0.03)
        #self.label.SetTextAngle(90)
        #self.label.SetTextAlign(32)
        self.label.SetTextAlign(23)
        self.label.Draw("same")

        #label for low Q^2 tagger
        self.label_tag = TText(vtrans.X() + 2, (vtrans.Y() + 0.6) * 100 - 3,
                               "Place for low-Q2 tagger")
        self.label_tag.SetTextSize(0.03)
        #self.label.SetTextAngle(90)
        #self.label.SetTextAlign(32)
        self.label_tag.SetTextAlign(23)
        self.label_tag.Draw("same")
f.seek(0)    # reset python read line

hist = TH1D("h1f","h1f",Nbin,bin_init,bin_final)
total_e = 0
for i in range(1,Nbin+1):
    Line_string = str(f.readline())
    _,_,bin_c = Line_string.split();
    bin_c = float(bin_c)
    hist.SetBinContent(i,bin_c)
    total_e = total_e + bin_c
total_e = int(total_e)
hist.Draw()
print(hist.GetMaximumBin())
text = TText(hist.GetXaxis().GetBinCenter(2), hist.GetYaxis().GetBinCenter(1), "Recycled. Total Entry : %i" %total_e)
text.SetTextFont(10)
text.Draw()
gPad.Update()
can.Update()

'''
pave1 = TPaveText(0.1,0.1,0.9,0.98); 
pave1.SetFillColor(42);
pave1.AddText("Recycled")
pave1.Draw()
gPad.Update()
can.Update()
'''

'''
 ## I have tried to modified and upload the stats box, but failed.. is this differenct from C++??
#ps = can.GetPrimitive("stats")     # TPaveStats
Exemple #11
0
def StraightLine( opt="" ):

    from ConstrainedFit import clsq
    from numpy import matrix, zeros

    # Data, errors and correlations:
    xdata= [ 1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0 ]
    ydata= [ 3.0, 2.5, 3.0, 5.0, 7.0, 5.5, 7.5 ]
    xerrs= [ 0.5, 0.3, 0.3, 0.5, 0.5, 0.3, 0.3 ]
    yerrs= [ 0.7, 1.0, 0.5, 0.7, 0.7, 1.0, 0.7 ]
    xyrho= [ -0.25, 0.5, 0.5, -0.25, 0.25, 0.95, -0.25 ]
    #xyrho= [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
    covm= matrix( zeros( (14,14) ) )
    data= []
    npoints= len(xdata)
    for i in range( npoints ):
        subcovm= matrix( [ [ xerrs[i]**2, xyrho[i]*xerrs[i]*yerrs[i] ],
                           [ xyrho[i]*xerrs[i]*yerrs[i], yerrs[i]**2 ] ] )
        covm[2*i:2*i+2,2*i:2*i+2]= subcovm
        data.append( xdata[i] )
        data.append( ydata[i] )
    print( covm )
    print( data )

    # Fit parameters for straight line:
    upar= [ 1.0, 0.5 ]
    upnames= { 0: "a", 1: "b" }
    # or parabola, see possible mpar[.]**2 term in constraints
    #upar= [ 0.0, 1.0, 1.0 ]
    #upnames= { 0: "a", 1: "b", 2: "c" }

    # Constraint function forces y_i = a + b*x_i for every
    # pair of measurements x_i, y_i:
    def straightlineConstraints( mpar, upar ):
        constraints= []
        for i in range( npoints ):
            constraints.append( upar[0] + upar[1]*mpar[2*i]
                                # + upar[2]*mpar[2*i]**2
                                - mpar[2*i+1] )
        return constraints

    # Setup the solver and solve:
    solver= clsq.clsqSolver( data, covm, upar, straightlineConstraints,
                             uparnames=upnames )
    print( "Constraints before solution" )
    print( solver.getConstraints() )
    lBlobel= False
    lCorr= False
    if "b" in opt:
        lBlobel= True
    if "corr" in opt:
        lCorr= True
    solver.solve( lBlobel=lBlobel )
    ca= clsq.clsqAnalysis( solver )
    ca.printResults( corr=lCorr )

    if "m" in opt:
        _doMinosAll( solver, "u" )

    global tg, lell, tf, tt, canvc, canvp
    from ROOT import TGraph, TF1, TText, TCanvas

    if "cont" in opt:
        canvc= TCanvas( "canv", "Chi^2 Contours", 600, 600 )
        _doProfile2d( solver, ipar1=0, type1="u", ipar2=1, type2="u" )

    # Plot:
    from array import array
    xarr= array( "f", xdata )
    yarr= array( "f", ydata )
    tg= TGraph( npoints, xarr, yarr )
    tg.SetMarkerStyle( 20 )
    tg.SetMinimum( 0.0 )
    tg.SetMaximum( 9.0 )
    tg.SetTitle( "straight line 2D fit" )
    xa= tg.GetXaxis()
    ya= tg.GetYaxis()
    xa.SetTitle( "X" )
    ya.SetTitle( "Y" )
    canvp= TCanvas( "canp", "Straight line 2D fit", 600, 400 )
    tg.Draw( "ap" )
    lell= []
    for i in range( npoints ):
        te= _makeEllipse( xdata[i], ydata[i], xerrs[i], yerrs[i], xyrho[i] )
        lell.append( te )
        te.Draw( "s" )
    solution= solver.getUpars()
    tf= TF1( "tf", "[0]+[1]*x", 0.0, 15.0 )
    for i in range( len(upar) ):
        tf.SetParameter( i, solution[i] )
        tf.SetParName( 0, upnames[i] )
    tf.Draw( "same" )
    tt= TText( 1, 8, "y= a + b*x" )
    tt.Draw( "same" )

    return