def Make_TDC_Energy(Fname1,Fname2,Title, XaxisT,low,high,freq,RootName):
    
    f_fc=TFile(Fname1)
    f_tdc=TFile(Fname2)
    gr_Inregral_fc=f_fc.Get("Graph_Integral")
    gr_Inregral_tdc=f_tdc.Get("Graph_Integral")

    FNumber=int((high-low)/freq)
    
    xpoint=array("d",xrange(0,FNumber))
    ypoint=array("d",xrange(0,FNumber))




        
        
    num=-1
    for iAmp in range(low,high,freq):
        num+=1
        xpoint[num]=gr_Inregral_fc.Eval(iAmp)/3800;print xpoint[num]
        ypoint[num]= gr_Inregral_tdc.Eval(iAmp); print ypoint[num]

    TwoDGraph=TGraph(len(xpoint), xpoint,ypoint)
    canvas_Integral = MakeCanvas("can1","can1",800,800)
    TwoDGraph.SetTitle("Time [ns] vs. Energy [GeV]  ")
    TwoDGraph.SetMarkerStyle(22)
    TwoDGraph.SetMarkerColor(3)
    TwoDGraph.SetMarkerSize(2)
    TwoDGraph.GetXaxis().SetTitle("Energy [GeV]")
    TwoDGraph.GetYaxis().SetTitle("Time [ns]")
    TwoDGraph.GetYaxis().SetRangeUser(TMath.MinElement(len(xpoint),TwoDGraph.GetY())/1.3, TMath.MaxElement(len(xpoint),TwoDGraph.GetY()) * 1.2)
    TwoDGraph.Draw()
    canvas_Integral.SaveAs("Final_Time_Energy.pdf")
Exemplo n.º 2
0
def SupreImpose3Objects(File, Graph, rangelow, rangehigh, Xaxis, Yaxis, Title,
                        leg0, leg1, leg2, RoootName):

    #    gr_Int={}

    gr0 = File[0].Get(Graph)
    gr1 = File[1].Get(Graph)
    gr2 = File[2].Get(Graph)

    print gr1.GetName()

    #    num=0
    #    for itdc in File:
    #        gr_Int[num]=itdc.Get(Graph)
    #        num+=1

    canvas_tdc = MakeCanvas("TDC", "TDC", 800, 800)
    gr0.SetTitle("")
    gr0.GetYaxis().SetRangeUser(rangelow, rangehigh)
    gr0.GetYaxis().SetLabelSize(0.035)
    gr0.GetYaxis().SetTitleOffset(2)
    gr0.GetYaxis().SetTitle(Yaxis)
    gr0.SetLineColor(3)
    gr0.SetLineWidth(3)
    gr0.SetMarkerColor(3)
    gr0.SetMarkerSize(1.5)
    gr0.SetMarkerStyle(23)
    gr0.Draw()

    gr1.SetLineColor(2)
    gr1.SetLineWidth(2)
    gr1.SetMarkerColor(2)
    gr1.SetMarkerSize(1.5)
    gr1.SetMarkerStyle(23)
    #    gr1.Draw("sameLP")

    gr2.SetLineColor(4)
    gr2.SetMarkerSize(1.5)
    gr2.SetMarkerColor(4)
    gr2.SetMarkerStyle(23)
    gr2.SetLineWidth(2)
    gr2.Draw("sameLP")

    leg = TLegend(0.6, 0.7, 0.9, 0.9)

    leg.SetFillColor(0)
    leg.SetBorderSize(0)
    leg.SetTextSize(.03)

    leg.AddEntry(gr0, leg0, "l")
    #    leg.AddEntry(gr1,leg1,"l")
    leg.AddEntry(gr2, leg2, "l")
    leg.Draw()

    canvas_tdc.SaveAs(RoootName)
Exemplo n.º 3
0
    chan_mt = text_channel("#mu#tau")
    chan_emt = text_channel("e#mu#tau")
    chan_mmt = text_channel("#mu#mu#tau")
    chan_eet = text_channel("ee#tau")
    chan_tt = text_channel("#tau#tau")
    chan_et = text_channel("e#tau")

    # Figure out what goes in the CMS preliminary line
    blurb_map = {
        '7TeV': ('5.0', '7'),
        '8TeV': ('19.7', '8'),
        'all': ('24.7', '7+8'),
    }
    int_lumi, sqrts = blurb_map[args.period]

    canvas = MakeCanvas("asdf", "asdf", 800, 800)

    histograms['mmt']['stack'].Draw()
    if args.prefit == False:
        errorMMT.Draw("e2same")
    #histograms['mmt']['poisson'].Draw('pe same')
    catllt.Draw("same")
    histograms['mmt']['legend'].Draw()
    lumiBlurb = add_cms_blurb(sqrts, int_lumi)
    lumiBlurb.Draw("same")
    chan_mmt.Draw("same")
    canvas.SaveAs('plots/mmt' + plot_suffix)

    histograms['emt']['stack'].Draw()
    if args.prefit == False:
        errorEMT.Draw("e2same")
Exemplo n.º 4
0
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName):

    FNumber = int((high - low) / freq)

    LINK = [19]
    #    LINK=[15,16,17,18,19]
    #    LINKkChannel=[0,1,2,3,4,5]
    LINKkChannel = [2]
    for linkChannel in LINKkChannel:
        for link in LINK:
            xIntegral = array("d", xrange(0, FNumber))
            yIntegral = array("d", xrange(0, FNumber))
            yIntegralErrUp = array("d", xrange(0, FNumber))
            yIntegralErrDown = array("d", xrange(0, FNumber))
            xIntegral_RMS = array("d", xrange(0, FNumber))
            yIntegral_RMS = array("d", xrange(0, FNumber))
            yIntegral_RMSErrUp = array("d", xrange(0, FNumber))
            yIntegral_RMSErrDown = array("d", xrange(0, FNumber))
            xRatio = array("d", xrange(0, FNumber))
            yRatio = array("d", xrange(0, FNumber))
            xSingleEv = array("d", xrange(0, 40))
            ySingleEv = array("d", xrange(0, 40))
            num = -1
            for iAmp in range(low, high, freq):
                num += 1
                Fname = Fname1 + str(iAmp) + Fname2
                print "*************  -> initiating      The ", Fname, " and number of files exist= ", FNumber
                print "-------------------->  Now is doing ....  ", low, "  ____ ", Fname

                f = open(Fname)
                data = getData(f)
                #                tdc = getTDCValues(f)

                M = TH1F(Fname, Fname, 10000, 0, 1000000)
                x = array("d", xrange(0, 1001))
                y = array("d", xrange(0, 1001))

                for event in xrange(0, 995):

                    pedSum = 0
                    sigSum = 0
                    Signal = 0
                    Pedestal = 0
                    for BX in xrange(0, 40):

                        adcValue = data[event][link][BX][linkChannel]
                        if BX < 15: pedSum += adcValue
                        if BX > 19 and BX < 27: sigSum += adcValue
                        #                        if BX > 19 and  BX < 25: sigSum += adcValue
                        xSingleEv[BX] = BX
                        ySingleEv[BX] = adcValue

                    scanvas = MakeCanvas("mm", "nn", 800, 800)
                    GrSingleEv = TGraph(len(xSingleEv), xSingleEv, ySingleEv)
                    SFit = TF1("fit", "gaus", 19, 23)
                    SFit.SetParameter(0, 4000)
                    SFit.SetParameter(1, 20.9)
                    SFit.SetParLimits(1, 20, 22)
                    SFit.SetParameter(2, 1.5)
                    GrSingleEv.Draw("AC*")
                    GrSingleEv.Fit("fit", "R0")
                    SFit.Draw("same")
                    FitParam = SFit.GetParameters()
                    print "Gaus fit param 1, 2, 3= ", round(
                        FitParam[0], 4), round(FitParam[1],
                                               4), round(FitParam[2], 4)
                    #            scanvas.SaveAs("singleEv_"+str(iAmp)+"_"+str(event)+".pdf")

                    Pedestal = pedSum / 15.
                    y[event] = sigSum - Pedestal * 7
                    #                    y[event]= sigSum- Pedestal*5
                    M.Fill(y[event])

                histMean = M.GetMean()
                histRMS = M.GetStdDev()

                highVal = histMean + 4 * histRMS
                lowVal = histMean - 4 * histRMS
                highValAx = histMean + 6 * histRMS
                lowValAx = histMean - 6 * histRMS

                canvas = MakeCanvas("asdf", "asdf", 800, 800)
                canvas.Update()
                MyGr = TGraph(len(x), x, y)
                mfit = TF1("fit", "gaus", lowVal, highVal)
                M.Fit(mfit, "R0", "")
                FitParam = mfit.GetParameters()
                #        FitParErr=mfit.GetParError()

                integral = round(FitParam[1], 4)
                integralErr = round(mfit.GetParError(1), 4)
                if FitParam[1] / histMean < 0.9 or FitParam[1] / histMean > 1.1:
                    integral = histMean
                    integralErr = 0

                integral_RMS = round(FitParam[2], 4)
                integral_RMSErr = round(mfit.GetParError(2), 4)
                if round(FitParam[2], 4) / histRMS < 0.9 or round(
                        FitParam[2], 4) / histRMS > 1.1:
                    integral_RMS = histRMS
                    integral_RMSErr = 0

                print "iAmp=", iAmp, "   integral= ", integral, "   integral_RMS=", integral_RMS

                M.SetMarkerStyle(22)
                M.GetXaxis().SetRangeUser(lowValAx, highValAx)

                M.SetTitle(Title + " = " + str(iAmp))
                M.Draw("pe")
                mfit.Draw("same")
                fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC")
                fitInfo.SetBorderSize(0)
                fitInfo.SetFillStyle(0)
                fitInfo.SetTextAlign(12)
                fitInfo.SetTextSize(0.03)
                fitInfo.SetTextColor(1)
                fitInfo.SetTextFont(62)
                fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1)))
                fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1)))
                fitInfo.Draw()
                canvas.SaveAs("HistoSingleRun_" + str(iAmp) + "_" + Title +
                              RootName + "_link" + str(link) + "_ch_" +
                              str(linkChannel) + ".pdf")

                xIntegral[num] = iAmp
                yIntegral[num] = integral
                yIntegralErrUp[num] = integral + integralErr
                yIntegralErrDown[num] = integral - integralErr

                xIntegral_RMS[num] = iAmp
                yIntegral_RMS[num] = integral_RMS
                yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr
                yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr

                xRatio[num] = iAmp
                yRatio[num] = integral_RMS / integral

            Graph_Integral = TGraph(len(xIntegral), xIntegral, yIntegral)
            Graph_IntegralErUp = TGraph(len(xIntegral), xIntegral,
                                        yIntegralErrUp)
            Graph_IntegralErDown = TGraph(len(xIntegral), xIntegral,
                                          yIntegralErrDown)

            canvas_Integral = MakeCanvas("can1", "can1", 800, 800)
            Graph_Integral.SetTitle("Pulse Integral vs. Pulse  " + Title)
            Graph_Integral.SetMarkerStyle(22)
            Graph_Integral.SetMarkerColor(3)
            Graph_Integral.SetMarkerSize(2)
            Graph_Integral.GetXaxis().SetTitle(XaxisT)
            Graph_Integral.Draw()
            Graph_IntegralErUp.Draw("same")
            Graph_IntegralErDown.Draw("same")
            canvas_Integral.SaveAs("Integral_" + Title + RootName + "_link" +
                                   str(link) + "_ch_" + str(linkChannel) +
                                   ".pdf")

            Graph_Integral_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                        yIntegral_RMS)
            Graph_Integral_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                            yIntegral_RMSErrUp)
            Graph_Integral_RMSErDown = TGraph(len(xIntegral_RMS),
                                              xIntegral_RMS,
                                              yIntegral_RMSErrDown)

            canvas_Integral_RMS = MakeCanvas("can2", "can2", 800, 800)
            Graph_Integral_RMS.SetTitle("Pulse Integral RMS vs. Pulse  " +
                                        Title)
            Graph_Integral_RMS.SetMarkerStyle(23)
            Graph_Integral_RMS.SetMarkerColor(2)
            Graph_Integral_RMS.SetMarkerSize(2)
            Graph_Integral_RMS.GetXaxis().SetTitle(XaxisT)
            Graph_Integral_RMS.Draw()
            Graph_Integral_RMSErUp.Draw("same")
            Graph_Integral_RMSErDown.Draw("same")
            canvas_Integral_RMS.SaveAs("Integral_RMS_" + Title + RootName +
                                       "_link" + str(link) + "_ch_" +
                                       str(linkChannel) + ".pdf")

            Graph_Ratio = TGraph(len(xRatio), xRatio, yRatio)
            canvas_Ratio = MakeCanvas("can2", "can2", 800, 800)
            Graph_Ratio.SetTitle(
                "Ratio of Pulse Integral RMS and Pulse Integral  " + Title)
            Graph_Ratio.SetMarkerStyle(21)
            Graph_Ratio.SetMarkerColor(8)
            Graph_Ratio.SetMarkerSize(2)
            Graph_Ratio.GetXaxis().SetTitle(XaxisT)
            Graph_Ratio.Draw()
            canvas_Ratio.SaveAs("Ratio_" + Title + RootName + "_link" +
                                str(link) + "_ch_" + str(linkChannel) + ".pdf")

            OutFile = TFile(
                "outFile_" + RootName + "_link" + str(link) + "_ch_" +
                str(linkChannel) + ".root", "RECREATE")
            OutFile.WriteObject(Graph_Integral, "Graph_Integral")
            OutFile.WriteObject(Graph_Integral_RMS, "Graph_Integral_RMS")
            OutFile.WriteObject(Graph_Ratio, "Graph_Ratio")
            OutFile.Close()
Exemplo n.º 5
0
    style1.cd()

    x_att1, y_att1 = np.loadtxt('att.txt', unpack=True)
    x_att=array("d",x_att1)
    y_att=array("d",y_att1)
    gatt = ROOT.TGraph(len(x_att), x_att,y_att)

    x_amm, y_amm = np.loadtxt('amm.txt', unpack=True)
    for i in range(0,len(x_amm)):
        BRmm=gamma_mu(1,float(x_amm[i]),1)
        BRtt=gamma_tau(1,float(x_amm[i]),1)
        #y_amm[i]=y_amm[i]*BRtt/BRmm
        y_amm[i]=100*y_amm[i]
    gamm = ROOT.TGraph(len(x_amm), x_amm.flatten('C'),y_amm.flatten('C'))

    canvas = MakeCanvas("asdf","asdf",800,800)
    canvas.cd()
    canvas.SetLogy()
    gamm.Draw("AC")
    gamm.SetLineColor(ROOT.EColor.kAzure-1)
    gamm.SetLineStyle(7)
    gamm.GetXaxis().SetRangeUser(25,80);
    gamm.GetXaxis().SetLimits(25,80);
    gamm.SetMinimum(5.0);
    gamm.SetMaximum(200);
    gamm.GetXaxis().SetTitle("m_{a} (GeV)");
    gamm.GetYaxis().SetTitle("95% CL on #sigma(bbA) #times B(a#rightarrow#tau#tau)")
    gamm.Draw("AC")
    canvas.Update();
    gatt.SetLineColor(ROOT.EColor.kGreen-1)
    gatt.Draw("same")
            return svar

def get_fail(fname):
    ffile = open(fname,'r')
    for line in ffile.readlines():
        if line.startswith("fail"):
            matcher = re.compile('(?<=fail)\d+\.\d+')
            matches = matcher.findall(line)
            svar = 0
            if matches:
                svar = float(matches[0])
            return svar

style1=GetStyleHtt()
style1.cd()
c=MakeCanvas("asdf","asdf",750,1000)

upperPad = ROOT.TPad("upperPad", "upperPad", .005, .2525, .995, .995);
lowerPad = ROOT.TPad("lowerPad", "lowerPad", .005, .005, .995, .335);
lowerPad.SetBottomMargin(0.3)
lowerPad.SetLeftMargin(0.18)
upperPad.SetLeftMargin(0.18)
upperPad.Draw();lowerPad.Draw();
upperPad.cd();
CMSPrelim("CMS Preliminary 2012','#sqrt{s} = 8 TeV, L = 19.7 fb^{-1}")

legende=make_legend()
istart=1

file_table=open("table_PU_"+options.input+".txt","w")
linetab="\\begin{tabular}{|c|c|c|c|c|c|c|} \n \\hline \n Working point & \\multicolumn{2}{c|}{1-15} & \\multicolumn{2}{c|}{16-25} & \\multicolumn{2}{c|}{26+} \\\\ \n & MC eff. & SF & MC eff. & SF & MC eff. & SF \\\\ \\hline \\hline \n"
Exemplo n.º 7
0
def Measure_Integral(AllRuns, Title, RootName, WID):

    FNumber = len(AllRuns)

    xIntegral = array("d", xrange(0, FNumber))
    yIntegral = array("d", xrange(0, FNumber))
    yIntegralErrUp = array("d", xrange(0, FNumber))
    yIntegralErrDown = array("d", xrange(0, FNumber))
    xIntegral_RMS = array("d", xrange(0, FNumber))
    yIntegral_RMS = array("d", xrange(0, FNumber))
    yIntegral_RMSErrUp = array("d", xrange(0, FNumber))
    yIntegral_RMSErrDown = array("d", xrange(0, FNumber))
    xRatio = array("d", xrange(0, FNumber))
    yRatio = array("d", xrange(0, FNumber))
    xSingleEv = array("d", xrange(0, 40))
    ySingleEv = array("d", xrange(0, 40))

    OutFile = TFile(RootName, "RECREATE")
    num = -1
    iAmp = 0
    for Fname in AllRuns:
        num += 1
        iAmp += 1

        f = open(Fname)
        #        data = getData(f)
        tdc = getTDCValues(f)

        M = TH1F(Fname, Fname, 200, 0, 100)
        x = array("d", xrange(0, 1001))
        y = array("d", xrange(0, 1001))

        for event in xrange(0, 995):
            pedSum = 0
            sigSum = 0
            Signal = 0
            Pedestal = 0
            for BX in xrange(0, 40):
                #                print "[event][link][BX][linkChannel] = ", event,"  "  ,link,"  "  , BX ,"  "  ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel]
                #            print BX
                #            print event
                #            print "data=", data[event][link][BX][linkChannel]
                #                print "TDC=", tdc[event][link][BX][linkChannel]
                #            print "\n"
                #                print "@@@@@@@@------->     [event] ", event
                tdcValue = tdc[event][link][BX][linkChannel]
                #                print "@@@@@@@@------->     [event] ", event
                if (WID[num] < 10 and BX == 20
                        and tdc[event][link][BX][linkChannel] != 31.5):
                    sigSum += tdcValue
                if (WID[num] > 10 and BX == 21
                        and tdc[event][link][BX][linkChannel] != 31.5):
                    sigSum += tdcValue
#                    print "[event][link][BX][linkChannel] = ", event,"  "  ,link,"  "  , BX ,"  "  ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel]
#                if BX > 19 and  BX < 25: sigSum += adcValue
#                if BX > 18 and BX < 26: print "[event][link][BX][linkChannel] = ", event,"  "  ,link,"  "  , BX ,"  "  ,linkChannel, "---->data[event][link][BX][linkChannel]", data[event][link][BX][linkChannel]

#            print "---------------------> sigSum= ",sigSum
            y[event] = sigSum
            M.Fill(y[event])

        histMean = M.GetMean()
        histRMS = M.GetStdDev()

        highVal = histMean + 4 * histRMS
        lowVal = histMean - 4 * histRMS
        highValAx = histMean + 6 * histRMS
        lowValAx = histMean - 6 * histRMS

        canvas = MakeCanvas("asdf", "asdf", 800, 800)
        canvas.Update()
        MyGr = TGraph(len(x), x, y)
        mfit = TF1("fit", "gaus", lowVal, highVal)
        M.Fit(mfit, "R0", "")
        FitParam = mfit.GetParameters()
        #        FitParErr=mfit.GetParError()

        integral = histMean
        if FitParam[1] < 1.5 * histMean: integral = round(FitParam[1], 4)

        integral_RMS = histRMS
        if round(FitParam[2], 4) < 2 * histRMS:
            integral_RMS = round(FitParam[2], 4)

        integralErr = round(mfit.GetParError(1), 4)
        integral_RMSErr = round(mfit.GetParError(2), 4)
        print "iAmp=", iAmp, "   integral= ", integral, "   integral_RMS=", integral_RMS

        M.SetMarkerStyle(22)
        M.GetXaxis().SetRangeUser(lowValAx, highValAx)
        #        M.GetXaxis().SetRangeUser(lowValAx,highValAx)

        M.SetTitle(Title + " = " + str(iAmp))
        M.Draw("pe")
        mfit.Draw("same")
        fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC")
        fitInfo.SetBorderSize(0)
        fitInfo.SetFillStyle(0)
        fitInfo.SetTextAlign(12)
        fitInfo.SetTextSize(0.03)
        fitInfo.SetTextColor(1)
        fitInfo.SetTextFont(62)
        fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1)))
        fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1)))
        fitInfo.Draw()
        canvas.SaveAs("HistoSingleRun_" + str(iAmp) + "_" + Title + "_TDC.pdf")

        XVAL = iAmp
        xIntegral[num] = XVAL
        yIntegral[num] = integral
        yIntegralErrUp[num] = integral + integralErr
        yIntegralErrDown[num] = integral - integralErr

        xIntegral_RMS[num] = XVAL
        yIntegral_RMS[num] = integral_RMS
        yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr
        yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr

        print "iAmp, integral=  ", iAmp, "  ", integral, "  XVAL= ", XVAL
        xRatio[num] = XVAL
        yRatio[num] = integral_RMS / integral


#        xIntegral.append(iAmp)
#        yIntegral.append(integral)
#        xIntegral_RMS.append(iAmp)
#        yIntegral_RMS.append(integral_RMS)

    Graph_Integral = TGraph(len(xIntegral), xIntegral, yIntegral)
    Graph_IntegralErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp)
    Graph_IntegralErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown)

    canvas_Integral = MakeCanvas("can1", "can1", 800, 800)
    #    canvas_Integral.SetLogy()
    Graph_Integral.SetTitle("TDC Stability")
    Graph_Integral.SetMarkerStyle(22)
    Graph_Integral.SetMarkerColor(3)
    Graph_Integral.SetMarkerSize(2)
    Graph_Integral.GetXaxis().SetTitle("Day")
    Graph_Integral.GetYaxis().SetRangeUser(0, 40)
    print "%%%%%%%% Graph_Integral.GetMaximum()= ", TMath.MaxElement(
        len(xIntegral_RMS), Graph_Integral.GetY())
    #    Graph_Integral.SetMaximum(1.5)
    Graph_Integral.Draw()
    #    Graph_IntegralErUp.Draw("same")
    #    Graph_IntegralErDown.Draw("same")
    canvas_Integral.SaveAs("Integral_" + Title + "_TDC.pdf")

    Graph_Integral_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                yIntegral_RMS)
    Graph_Integral_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                    yIntegral_RMSErrUp)
    Graph_Integral_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                      yIntegral_RMSErrDown)

    canvas_Integral_RMS = MakeCanvas("can2", "can2", 800, 800)
    Graph_Integral_RMS.SetTitle("TDC RMS vs. Pulse  " + Title)
    Graph_Integral_RMS.SetMarkerStyle(23)
    Graph_Integral_RMS.SetMarkerColor(2)
    Graph_Integral_RMS.SetMarkerSize(2)
    Graph_Integral_RMS.GetXaxis().SetTitle("Day")
    Graph_Integral_RMS.GetYaxis().SetRangeUser(
        TMath.MinElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) / 2,
        TMath.MaxElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) * 1.5)
    Graph_Integral_RMS.Draw()
    #    Graph_Integral_RMSErUp.Draw("same")
    #    Graph_Integral_RMSErDown.Draw("same")
    canvas_Integral_RMS.SaveAs("Integral_RMS_" + Title + "_TDC.pdf")

    Graph_Ratio = TGraph(len(xRatio), xRatio, yRatio)
    canvas_Ratio = MakeCanvas("can2", "can2", 800, 800)
    Graph_Ratio.SetTitle("Ratio of TDC RMS and TDC  " + Title)
    Graph_Ratio.SetMarkerStyle(21)
    Graph_Ratio.SetMarkerColor(4)
    Graph_Ratio.SetMarkerSize(2)
    Graph_Ratio.GetXaxis().SetTitle("Day")
    Graph_Ratio.GetYaxis().SetRangeUser(
        TMath.MinElement(len(xIntegral_RMS), Graph_Ratio.GetY()) / 2,
        TMath.MaxElement(len(xIntegral_RMS), Graph_Ratio.GetY()) * 1.5)
    Graph_Ratio.Draw()
    canvas_Ratio.SaveAs("Ratio_" + Title + "_TDC.pdf")

    OutFile = TFile(RootName, "RECREATE")
    OutFile.WriteObject(Graph_Integral, "Graph_Integral")
    OutFile.WriteObject(Graph_Integral_RMS, "Graph_Integral_RMS")
    OutFile.WriteObject(Graph_Ratio, "Graph_Ratio")
    OutFile.Close()
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName):

    FNumber = int((high - low) / freq)

    LINK = [3]
    #    LINK=[15,16,17,18,19]
    LINKkChannel = [0, 1, 2, 3, 4, 5]
    #    LINKkChannel=[0]
    for linkChannel in LINKkChannel:
        for link in LINK:

            xIntegral = array("d", xrange(0, FNumber))
            yIntegral = array("d", xrange(0, FNumber))
            yIntegralErrUp = array("d", xrange(0, FNumber))
            yIntegralErrDown = array("d", xrange(0, FNumber))
            xIntegral_RMS = array("d", xrange(0, FNumber))
            yIntegral_RMS = array("d", xrange(0, FNumber))
            yIntegral_RMSErrUp = array("d", xrange(0, FNumber))
            yIntegral_RMSErrDown = array("d", xrange(0, FNumber))
            xRatio = array("d", xrange(0, FNumber))
            yRatio = array("d", xrange(0, FNumber))
            xSingleEv = array("d", xrange(0, 40))
            ySingleEv = array("d", xrange(0, 40))

            num = -1
            for iAmp in range(low, high, freq):
                num += 1
                Fname = Fname1 + str(iAmp) + Fname2

                f = open(Fname)
                data = getData(f)

                M = TH1F(Fname, Fname, 200, 0.4, 1.4)
                HistoSergey = TH1F(Fname, Fname, 200, -10, 200)
                M.SetDefaultSumw2()
                x = array("d", xrange(0, 1001))
                y = array("d", xrange(0, 1001))

                for event in xrange(0, 9):
                    for BX in xrange(0, 40):

                        xSingleEv[BX] = BX
                        ySingleEv[BX] = data[event][link][BX][linkChannel]
                        if BX < 16: HistoSergey.Fill(ySingleEv[BX])
                        if ySingleEv[BX] <= 0: ySingleEv[BX] = 0.1
                        if ySingleEv[BX] < 0.1: print "--->", ySingleEv[BX]

                    scanvas = MakeCanvas("mm", "nn", 800, 800)
                    scanvas.SetLogy()
                    GrSingleEv = TGraph(len(xSingleEv), xSingleEv, ySingleEv)

                    #                    SFit=TF1("fit", "gaus", 19,23)
                    #                    SFit.SetParameter(0, 250)
                    #                    SFit.SetParameter(1, 20.9)
                    #            SFit.SetParLimits(1, 20, 22)
                    #                    SFit.SetParameter(2, 1)
                    GrSingleEv.GetXaxis().SetRangeUser(0, 40)
                    GrSingleEv.GetYaxis().SetRangeUser(0.05, 100000)
                    GrSingleEv.Draw("AC*")
                    #                    GrSingleEv.Fit("fit","R0")
                    #                    SFit.Draw("same")
                    #                    FitParam=SFit.GetParameters()
                    #                    print "Gaus fit param 1, 2, 3= " , round(FitParam[0],4), round(FitParam[1],4), round(FitParam[2],4)
                    fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC")
                    fitInfo.SetBorderSize(0)
                    fitInfo.SetFillStyle(0)
                    fitInfo.SetTextAlign(12)
                    fitInfo.SetTextSize(0.03)
                    fitInfo.SetTextColor(1)
                    fitInfo.SetTextFont(62)
                    fitInfo.AddText("eventNumber_" + str(event) + "_link" +
                                    str(link) + "_ch_" + str(linkChannel))
                    fitInfo.Draw()

                    scanvas.SaveAs("PLOT/singleEv_" + str(iAmp) + "_" +
                                   str(event) + RootName + "_link" +
                                   str(link) + "_ch_" + str(linkChannel) +
                                   ".pdf")

                sergeycanvas = MakeCanvas("mm", "nn", 800, 800)
                HistoSergey.Draw()
                sergeycanvas.SaveAs("SergeyHisto" + RootName + "_link" +
                                    str(link) + "_ch_" + str(linkChannel) +
                                    ".pdf")
def Measure_Integral(AllRuns, Title, RootName):

    FNumber=len(AllRuns)
    
    xIntegral=array("d",xrange(0,FNumber))
    yIntegral=array("d",xrange(0,FNumber))
    yIntegralErrUp=array("d",xrange(0,FNumber))
    yIntegralErrDown=array("d",xrange(0,FNumber))
    xIntegral_RMS=array("d",xrange(0,FNumber))
    yIntegral_RMS=array("d",xrange(0,FNumber))
    yIntegral_RMSErrUp=array("d",xrange(0,FNumber))
    yIntegral_RMSErrDown=array("d",xrange(0,FNumber))
    xRatio=array("d",xrange(0,FNumber))
    yRatio=array("d",xrange(0,FNumber))
    xSingleEv=array("d",xrange(0,40))
    ySingleEv=array("d",xrange(0,40))
    
    OutFile=TFile(RootName,"RECREATE")
    num=-1
    iAmp=0
    for Fname in AllRuns:
        num+=1
        iAmp+=1

        f = open(Fname)
        data = getData(f)

        M=TH1F(Fname,Fname,600,0,120000)
        x = array("d", xrange(0,1001))
        y = array("d", xrange(0,1001))


        for event in xrange(0,995):
            pedSum=0
            sigSum=0
            Signal=0
            Pedestal=0
            for BX in xrange(0, 40):

                adcValue=data[event][link][BX][linkChannel]
                if BX < 15 : pedSum += adcValue
                if BX > 19 and  BX < 25: sigSum += adcValue
                xSingleEv[BX]=BX
                ySingleEv[BX]=adcValue
        
            scanvas = MakeCanvas("mm","nn",800,800)
            GrSingleEv=TGraph(len(xSingleEv),xSingleEv,ySingleEv)
            OutFile.WriteObject(GrSingleEv,"singleEv_"+str(iAmp)+"_"+str(event))
            SFit=TF1("fit", "gaus", 19,23)
            SFit.SetParameter(0, 4000)
            SFit.SetParameter(1, 20.9)
            SFit.SetParLimits(1, 20, 22)
            SFit.SetParameter(2, 1.5)
            GrSingleEv.Draw("AC*")
            GrSingleEv.Fit("fit","R0")
            SFit.Draw("same")
            FitParam=SFit.GetParameters()
            print "Gaus fit param 1, 2, 3= " , round(FitParam[0],4), round(FitParam[1],4), round(FitParam[2],4)
            scanvas.SaveAs("PLOT/singleEv_"+str(iAmp)+"_"+str(event)+".pdf")
            
            Pedestal=pedSum/15.
            y[event]= sigSum- Pedestal*5
            M.Fill(y[event])

        histMean= M.GetMean()
        histRMS= M.GetStdDev()

        highVal = histMean + 4 * histRMS
        lowVal = histMean - 4 * histRMS
        highValAx = histMean + 6 * histRMS
        lowValAx = histMean - 6 * histRMS

        canvas = MakeCanvas("asdf","asdf",800,800)
        canvas.Update()
        MyGr= TGraph(len(x), x,y)
        mfit=TF1("fit", "gaus", lowVal,highVal)
        M.Fit(mfit, "R0","")
        FitParam=mfit.GetParameters()
#        FitParErr=mfit.GetParError()
        integral= round(FitParam[1],4)
        integral_RMS= round(FitParam[2],4)
        integralErr= round(mfit.GetParError(1),4)
        integral_RMSErr= round(mfit.GetParError(2),4)
        print "iAmp=", iAmp, "   integral= ", integral,  "   integral_RMS=", integral_RMS


        M.SetMarkerStyle(22)
        M.GetXaxis().SetRangeUser(lowValAx,highValAx)
        
        M.SetTitle(Title+" = "+str(iAmp))
        M.Draw("pe")
        mfit.Draw("same")
        fitInfo  =TPaveText(.20,0.7,.60,0.9, "NDC");
        fitInfo.SetBorderSize(   0 );
        fitInfo.SetFillStyle(    0 );
        fitInfo.SetTextAlign(   12 );
        fitInfo.SetTextSize ( 0.03 );
        fitInfo.SetTextColor(    1 );
        fitInfo.SetTextFont (   62 );
        fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1],1)))
        fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2],1)))
        fitInfo.Draw()
        canvas.SaveAs("HistoSingleRun_"+str(iAmp)+"_"+Title+RootName+".pdf")



        xIntegral[num]=iAmp
        yIntegral[num]=integral
        yIntegralErrUp[num]=integral+integralErr
        yIntegralErrDown[num]=integral-integralErr

        xIntegral_RMS[num]=iAmp
        yIntegral_RMS[num]=integral_RMS
        yIntegral_RMSErrUp[num]=integral_RMS+integral_RMSErr
        yIntegral_RMSErrDown[num]=integral_RMS-integral_RMSErr
        
        xRatio[num]=iAmp
        yRatio[num]=integral_RMS/integral

#        xIntegral.append(iAmp)
#        yIntegral.append(integral)
#        xIntegral_RMS.append(iAmp)
#        yIntegral_RMS.append(integral_RMS)

    Graph_Integral= TGraph(len(xIntegral), xIntegral,yIntegral)
    Graph_IntegralErUp= TGraph(len(xIntegral), xIntegral,yIntegralErrUp)
    Graph_IntegralErDown= TGraph(len(xIntegral), xIntegral,yIntegralErrDown)
    
    canvas_Integral = MakeCanvas("can1","can1",800,800)
#    canvas_Integral.SetLogy()
    Graph_Integral.SetTitle("Pulse Integral Stability")
    Graph_Integral.SetMarkerStyle(22)
    Graph_Integral.SetMarkerColor(3)
    Graph_Integral.SetMarkerSize(2)
    Graph_Integral.GetXaxis().SetTitle("Day")
    Graph_Integral.GetYaxis().SetRangeUser(80000,85000)
    Graph_Integral.Draw()
#    Graph_IntegralErUp.Draw("same")
#    Graph_IntegralErDown.Draw("same")
    canvas_Integral.SaveAs("Integral_"+Title+RootName+".pdf")

    Graph_Integral_RMS= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMS)
    Graph_Integral_RMSErUp= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMSErrUp)
    Graph_Integral_RMSErDown= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMSErrDown)

    canvas_Integral_RMS = MakeCanvas("can2","can2",800,800)
    Graph_Integral_RMS.SetTitle("Pulse Integral RMS vs. Pulse  "+Title)
    Graph_Integral_RMS.SetMarkerStyle(23)
    Graph_Integral_RMS.SetMarkerColor(2)
    Graph_Integral_RMS.SetMarkerSize(2)
    Graph_Integral.GetXaxis().SetTitle("Day")
    Graph_Integral_RMS.Draw()
#    Graph_Integral_RMSErUp.Draw("same")
#    Graph_Integral_RMSErDown.Draw("same")
    canvas_Integral_RMS.SaveAs("Integral_RMS_"+Title+RootName+".pdf")


    Graph_Ratio= TGraph(len(xRatio), xRatio,yRatio)
    canvas_Ratio = MakeCanvas("can2","can2",800,800)
    Graph_Ratio.SetTitle("Ratio of Pulse Integral RMS and Pulse Integral  "+Title)
    Graph_Ratio.SetMarkerStyle(21)
    Graph_Ratio.SetMarkerColor(8)
    Graph_Ratio.SetMarkerSize(2)
    Graph_Integral.GetXaxis().SetTitle("Day")
    Graph_Ratio.Draw()
    canvas_Ratio.SaveAs("Ratio_"+Title+RootName+".pdf")

#    OutFile=TFile(RootName,"RECREATE")
    OutFile.WriteObject(Graph_Integral,"Graph_Integral")
    OutFile.WriteObject(Graph_Integral_RMS,"Graph_Integral_RMS")
    OutFile.WriteObject(Graph_Ratio,"Graph_Ratio")
    OutFile.Close()
Exemplo n.º 10
0
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName):

    FNumber = int((high - low) / freq)
    print "*************  -> initiating      The ", Fname1, " and number of files exist= ", FNumber

    #    xIntegral=[]
    #    yIntegral=[]
    #    xIntegral_RMS=[]
    #    yIntegral_RMS=[]

    #    LINK=[15]
    LINK = [15, 16, 17, 18, 19.20]
    #    LINKkChannel=[0,1,2,3,4,5]
    LINKkChannel = [4]
    for linkChannel in LINKkChannel:
        for link in LINK:
            xIntegral = array("d", xrange(0, FNumber))
            yIntegral = array("d", xrange(0, FNumber))
            yIntegralErrUp = array("d", xrange(0, FNumber))
            yIntegralErrDown = array("d", xrange(0, FNumber))
            xIntegral_RMS = array("d", xrange(0, FNumber))
            yIntegral_RMS = array("d", xrange(0, FNumber))
            yIntegral_RMSErrUp = array("d", xrange(0, FNumber))
            yIntegral_RMSErrDown = array("d", xrange(0, FNumber))
            xRatio = array("d", xrange(0, FNumber))
            yRatio = array("d", xrange(0, FNumber))
            num = -1
            for iAmp in range(low, high, freq):
                num += 1
                Fname = Fname1 + str(iAmp) + Fname2
                print "*************  -> initiating      The ", Fname, " and number of files exist= ", FNumber
                print "-------------------->  Now is doing ....  ", low, "  ____ ", Fname

                f = open(Fname)
                #        data = getData(f)
                tdc = getTDCValues(f)

                M = TH1F(Fname, Fname, 200, 0, 100)
                x = array("d", xrange(0, 1001))
                y = array("d", xrange(0, 1001))

                for event in xrange(0, 995):
                    tdcValue = 0
                    for BX in xrange(0, 40):

                        if (iAmp <= 10 and BX == 20
                                and tdc[event][link][BX][linkChannel] != 31.5):
                            tdcValue = tdc[event][link][BX][linkChannel]
                        if (iAmp > 10 and BX == 21
                                and tdc[event][link][BX][linkChannel] != 31.5):
                            tdcValue = tdc[event][link][BX][linkChannel]

                    y[event] = tdcValue
                    M.Fill(y[event])

                histMean = M.GetMean()
                histRMS = M.GetStdDev()

                highVal = histMean + 4 * histRMS
                lowVal = histMean - 4 * histRMS
                highValAx = histMean + 6 * histRMS
                lowValAx = histMean - 6 * histRMS

                canvas = MakeCanvas("can", "can", 800, 800)
                canvas.Update()
                MyGr = TGraph(len(x), x, y)
                mfit = TF1("fit", "gaus", lowVal, highVal)
                M.Fit(mfit, "R0", "")
                FitParam = mfit.GetParameters()
                #        FitParErr=mfit.GetParError()

                integral = histMean
                if FitParam[1] < 1.5 * histMean:
                    integral = round(FitParam[1], 4)

                integral_RMS = histRMS
                if round(FitParam[2], 4) < 2 * histRMS:
                    integral_RMS = round(FitParam[2], 4)

                integralErr = round(mfit.GetParError(1), 4)
                integral_RMSErr = round(mfit.GetParError(2), 4)
                print "iAmp=", iAmp, "   integral= ", integral, "   integral_RMS=", integral_RMS

                M.SetMarkerStyle(22)
                M.GetXaxis().SetRangeUser(0, 30)

                M.SetTitle("TDC v.s. Delay Setting (ns)")
                M.Draw("pe")
                mfit.Draw("same")
                fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC")
                fitInfo.SetBorderSize(0)
                fitInfo.SetFillStyle(0)
                fitInfo.SetTextAlign(12)
                fitInfo.SetTextSize(0.03)
                fitInfo.SetTextColor(1)
                fitInfo.SetTextFont(62)
                fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1)))
                fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1)))
                fitInfo.AddText("Delay Setting =" + str(iAmp))
                fitInfo.AddText("link  =" + str(link) + "  channel=" +
                                str(linkChannel))
                fitInfo.Draw()
                canvas.SaveAs("outHistoSingleRun_" + RootName + str(iAmp) +
                              "_link" + str(link) + "_ch_" + str(linkChannel) +
                              ".pdf")

                XVAL = low + num * freq
                xIntegral[num] = XVAL
                yIntegral[num] = integral
                yIntegralErrUp[num] = integral + integralErr
                yIntegralErrDown[num] = integral - integralErr

                xIntegral_RMS[num] = XVAL
                yIntegral_RMS[num] = integral_RMS
                yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr
                yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr

                print "iAmp, integral=  ", iAmp, "  ", integral, "  XVAL= ", XVAL
#                xRatio[num]=XVAL
#                yRatio[num]=integral_RMS/integral

#        xIntegral.append(iAmp)
#        yIntegral.append(integral)
#        xIntegral_RMS.append(iAmp)
#        yIntegral_RMS.append(integral_RMS)

            Graph_TDC = TGraph(len(xIntegral), xIntegral, yIntegral)
            Graph_TDCErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp)
            Graph_TDCErDown = TGraph(len(xIntegral), xIntegral,
                                     yIntegralErrDown)

            canvas_TDC = MakeCanvas("can1", "can1", 800, 800)
            Graph_TDC.SetTitle("")
            Graph_TDC.SetMarkerStyle(22)
            Graph_TDC.SetMarkerColor(3)
            Graph_TDC.SetMarkerSize(2)
            Graph_TDC.GetXaxis().SetTitle(XaxisT)
            Graph_TDC.GetYaxis().SetRangeUser(0, 30)
            Graph_TDC.GetYaxis().SetTitle("TDC [ns]")
            Graph_TDC.Draw()
            Graph_TDCErUp.Draw("same")
            Graph_TDCErDown.Draw("same")
            canvas_TDC.SaveAs("outHisto_" + RootName + "_link" + str(link) +
                              "_ch_" + str(linkChannel) + ".pdf")

            Graph_TDC_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                   yIntegral_RMS)
            Graph_TDC_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                       yIntegral_RMSErrUp)
            Graph_TDC_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS,
                                         yIntegral_RMSErrDown)

            canvas_TDC_RMS = MakeCanvas("can2", "can2", 800, 800)
            Graph_TDC_RMS.SetTitle("TDC RMS vs. Pulse  " + Title)
            Graph_TDC_RMS.SetMarkerStyle(23)
            Graph_TDC_RMS.SetMarkerColor(2)
            Graph_TDC_RMS.SetMarkerSize(2)
            Graph_TDC_RMS.GetXaxis().SetTitle(XaxisT)
            Graph_TDC_RMS.GetYaxis().SetRangeUser(0, 2)
            Graph_TDC_RMS.Draw()
            Graph_TDC_RMSErUp.Draw("same")
            Graph_TDC_RMSErDown.Draw("same")
            canvas_TDC_RMS.SaveAs("outHistoRMS_" + RootName + "_link" +
                                  str(link) + "_ch_" + str(linkChannel) +
                                  ".pdf")

            OutFile = TFile(
                "outFile_" + RootName + "_link" + str(link) + "_ch_" +
                str(linkChannel) + ".root", "RECREATE")
            OutFile.WriteObject(Graph_TDC, "Graph_TDC")
            OutFile.WriteObject(Graph_TDC_RMS, "Graph_TDC_RMS")
            OutFile.Close()
Exemplo n.º 11
0
    catltt.SetFillStyle(    0 );
    catltt.SetTextAlign(   12 );
    catltt.SetTextSize ( 0.05 );
    catltt.SetTextColor(    1 );
    catltt.SetTextFont (   62 );
    catltt.AddText("WH fully-had");

    # Figure out what goes in the CMS preliminary line
    blurb_map = {
        '7TeV': ('5.0', '7'),
        '8TeV': ('19.7', '8'),
        'all': ('24.7', '7+8'),
    }
    int_lumi, sqrts = blurb_map[args.period]

    canvas=MakeCanvas("asdf","asdf",800,800)

    histograms['llt']['stack'].Draw()
    if args.prefit==False:
       errorLLT.Draw("e2same");
    #histograms['llt']['poisson'].Draw('pe same')
    catllt.Draw("same")
    histograms['llt']['legend'].Draw()
    lumiBlurb=add_cms_blurb(sqrts, int_lumi)
    lumiBlurb.Draw("same")
    canvas.SaveAs('plots/llt' + plot_suffix)

    histograms['zh']['stack'].Draw()
    if args.prefit==False:
       errorZH.Draw("e2same")
    histograms['zh']['poisson'].SetMarkerStyle(20)
Exemplo n.º 12
0
    return lumi


def make_legend():
    output = ROOT.TLegend(0.67, 0.60, 0.92, 0.90, "", "brNDC")
    output.SetLineWidth(0)
    output.SetLineStyle(0)
    output.SetFillStyle(0)
    output.SetBorderSize(0)
    output.SetTextFont(62)
    return output


style1 = GetStyleHtt()
style1.cd()
c = MakeCanvas("asdf", "asdf", 750, 750)
c.cd()

#CMSPrelim("CMS Preliminary, 19.7 fb^{-1} at 8 TeV")

file = ROOT.TFile("final.root", "r")

categories = ["passOS", "failOS"]
ncat = 2

for i in range(0, ncat):
    QCD = file.Get(categories[i]).Get("QCD")
    W = file.Get(categories[i]).Get("W")
    TT = file.Get(categories[i]).Get("TT")
    DYB = file.Get(categories[i]).Get("DYB")
    DYS = file.Get(categories[i]).Get("DYS120")