Exemple #1
0
def create2dHist(varname, params, title):
    if "to_pt" in varname and "tagRate" in varname:
        h = TProfile(varname, title, 50, params["plotPtRange"][0],
                     params["plotPtRange"][1])
        h.GetXaxis().SetTitle("#tau_{vis} p_{T} [GeV]")
        h.GetYaxis().SetTitle("tagging efficiency")
    if "to_eta" in varname and "tagRate" in varname:
        h = TProfile(varname, title, 50, params["plotEtaRange"][0],
                     params["plotEtaRange"][1])
        h.GetXaxis().SetTitle("#tau_{vis} #eta")
        h.GetYaxis().SetTitle("tagging efficiency")
    h.Sumw2()
    return h
Exemple #2
0
 def createHistogram( self, title=None, profile=False ):
     ## Create an empty histogram for this variable with the given title
     #  @param title      the title of the new histogram
     #  @param profile    set if the histogram should be a TProfile instead
     #  @return the new histogram 
     title = title if title is not None else self.title
     name = 'h%s_%s' % ( self.name.replace(' ', '').replace('(', '').replace(')',''), uuid.uuid1() )
     from ROOT import TH1D, TProfile
     if profile:
         h = TProfile( name, title, self.binning.nBins, 0., 1. )
     else:
         h = TH1D( name, title, self.binning.nBins, 0., 1. )
     self.binning.setupAxis( h.GetXaxis() )
     self.applyToAxis( h.GetXaxis() )
     return h
def plotting_init(data, trainvar, histo_dict, masses, weights='totalWeight'):
    """ Initializes the plotting

    Parameters:
    -----------
    data : pandas DataFrame
        Data to be used for creating the TProfiles
    trainvar : str
        Name of the training variable.
    histo_dict : dict
        Dictionary containing the info for plotting for a given trainvar
    masses : list
        List of masses to be used
    [weights='totalWeight'] : str
        What column to be used for weight in the data.

    Returns:
    --------
    canvas : ROOT.TCanvas instance
        canvas to be plotted on
    profile : ROOT.TProfile instance
        profile for the fitting
    """
    canvas = TCanvas('canvas', 'TProfile plot', 200, 10, 700, 500)
    canvas.GetFrame().SetBorderSize(6)
    canvas.GetFrame().SetBorderMode(-1)
    signal_data = data.loc[data['target'] == 1]
    gen_mHH_values = np.array(signal_data['gen_mHH'].values, dtype=np.float)
    trainvar_values = np.array(signal_data[trainvar].values, dtype=np.float)
    weights = np.array(signal_data[weights].values, dtype=np.float)
    sanity_check = len(gen_mHH_values) == len(trainvar_values) == len(weights)
    assert sanity_check
    title = 'Profile of ' + str(trainvar) + ' vs gen_mHH'
    num_bins = (len(masses) - 1)
    xlow = masses[0]
    xhigh = (masses[(len(masses) - 1)] + 100.0)
    ylow = histo_dict["min"]
    yhigh = histo_dict["max"]
    profile = TProfile('profile', title, num_bins, xlow, xhigh, ylow, yhigh)
    mass_bins = np.array(masses, dtype=float)
    profile.SetBins((len(mass_bins) - 1), mass_bins)
    profile.GetXaxis().SetTitle("gen_mHH (GeV)")
    profile.GetYaxis().SetTitle(str(trainvar))
    for x, y, w in zip(gen_mHH_values, trainvar_values, weights):
        profile.Fill(x, y, w)
    profile.Draw()
    canvas.Modified()
    canvas.Update()
    return canvas, profile
Exemple #4
0
def generator(nuslice_tree, rootfile, pset):
    n_bins = pset.n_bins
    drift_distance = pset.DriftDistance
    bin_width = drift_distance/n_bins
    half_bin_width = bin_width/2.

    xvals = np.arange(half_bin_width, drift_distance, bin_width)
    xerrs = np.array([half_bin_width] * len(xvals))
    dist_to_anode_bins = n_bins
    dist_to_anode_low = 0.
    dist_to_anode_up = drift_distance
    profile_bins = n_bins
    profile_option = 's'  # errors are the standard deviation

    dy_spreads = [None] * n_bins
    dy_means = [None] * n_bins
    dy_hist = TH2D("dy_hist", "#Delta y",
                   dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                   pset.dy_bins, pset.dy_low, pset.dy_up)
    dy_hist.GetXaxis().SetTitle("distance from anode (cm)")
    dy_hist.GetYaxis().SetTitle("y_flash - y_TPC (cm)")
    dy_prof = TProfile("dy_prof", "Profile of dy_spreads in #Delta y",
                       profile_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.dy_low*2, pset.dy_up*2, profile_option)
    dy_prof.GetXaxis().SetTitle("distance from anode (cm)")
    dy_prof.GetYaxis().SetTitle("y_flash - y_TPC (cm)")
    dy_h1 = TH1D("dy_h1", "",
                 profile_bins, dist_to_anode_low, dist_to_anode_up)
    dy_h1.GetXaxis().SetTitle("distance from anode (cm)")
    dy_h1.GetYaxis().SetTitle("y_flash - y_TPC (cm)")

    dz_spreads = [None] * n_bins
    dz_means = [None] * n_bins
    dz_hist = TH2D("dz_hist", "#Delta z",
                   dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                   pset.dz_bins, pset.dz_low, pset.dz_up)
    dz_hist.GetXaxis().SetTitle("distance from anode (cm)")
    dz_hist.GetYaxis().SetTitle("z_flash - z_TPC (cm)")
    dz_prof = TProfile("dz_prof", "Profile of dz_spreads in #Delta z",
                       profile_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.dz_low*2.5, pset.dz_up*2.5, profile_option)
    dz_prof.GetXaxis().SetTitle("distance from anode (cm)")
    dz_prof.GetYaxis().SetTitle("z_flash - z_TPC (cm)")
    dz_h1 = TH1D("dz_h1", "",
                 profile_bins, dist_to_anode_low, dist_to_anode_up)
    dz_h1.GetXaxis().SetTitle("distance from anode (cm)")
    dz_h1.GetYaxis().SetTitle("z_flash - z_TPC (cm)")

    rr_spreads = [None] * n_bins
    rr_means = [None] * n_bins
    rr_hist = TH2D("rr_hist", "PE Spread",
                   dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                   pset.rr_bins, pset.rr_low, pset.rr_up)
    rr_hist.GetXaxis().SetTitle("distance from anode (cm)")
    rr_hist.GetYaxis().SetTitle("RMS flash (cm)")
    rr_prof = TProfile("rr_prof", "Profile of PE Spread",
                       profile_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.rr_low, pset.rr_up, profile_option)
    rr_prof.GetXaxis().SetTitle("distance from anode (cm)")
    rr_prof.GetYaxis().SetTitle("RMS flash (cm)")
    rr_h1 = TH1D("rr_h1", "",
                 profile_bins, dist_to_anode_low, dist_to_anode_up)
    rr_h1.GetXaxis().SetTitle("distance from anode (cm)")
    rr_h1.GetYaxis().SetTitle("RMS flash (cm)")

    if detector == "sbnd":
        pe_spreads = [None] * n_bins
        pe_means = [None] * n_bins
        pe_hist = TH2D("pe_hist", "Uncoated/Coated Ratio",
                       dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.pe_bins, pset.pe_low, pset.pe_up)
        pe_hist.GetXaxis().SetTitle("distance from anode (cm)")
        pe_hist.GetYaxis().SetTitle("ratio_{uncoated/coated}")
        pe_prof = TProfile("pe_prof", "Profile of Uncoated/Coated Ratio",
                           profile_bins, dist_to_anode_low, dist_to_anode_up,
                           pset.pe_low, pset.pe_up, profile_option)
        pe_prof.GetXaxis().SetTitle("distance from anode (cm)")
        pe_prof.GetYaxis().SetTitle("ratio_{uncoated/coated}")
        pe_h1 = TH1D("pe_h1", "",
                     profile_bins, dist_to_anode_low, dist_to_anode_up)
        pe_h1.GetXaxis().SetTitle("distance from anode (cm)")
        pe_h1.GetYaxis().SetTitle("ratio_{uncoated/coated}")

    match_score_scatter = TH2D("match_score_scatter", "Scatter plot of match scores",
                               dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                               pset.score_hist_bins, pset.score_hist_low, pset.score_hist_up*(3./5.))
    match_score_scatter.GetXaxis().SetTitle("distance from anode (cm)")
    match_score_scatter.GetYaxis().SetTitle("match score (arbitrary)")
    match_score_hist = TH1D("match_score", "Match Score",
                            pset.score_hist_bins, pset.score_hist_low, pset.score_hist_up)
    match_score_hist.GetXaxis().SetTitle("match score (arbitrary)")

    for e in nuslice_tree:
        slice = e.charge_x

        dy_hist.Fill(slice, e.flash_y - e.charge_y)
        dy_prof.Fill(slice, e.flash_y - e.charge_y)
        dz_hist.Fill(slice, e.flash_z - e.charge_z)
        dz_prof.Fill(slice, e.flash_z - e.charge_z)
        rr_hist.Fill(slice, e.flash_r)
        rr_prof.Fill(slice, e.flash_r)
        if detector == "sbnd":
            pe_hist.Fill(slice, e.flash_ratio)
            pe_prof.Fill(slice, e.flash_ratio)

    # fill histograms for match score calculation from profile histograms
    for ib in list(range(0, profile_bins)):
        ibp = ib + 1
        dy_h1.SetBinContent(ibp, dy_prof.GetBinContent(ibp))
        dy_h1.SetBinError(ibp, dy_prof.GetBinError(ibp))
        dy_means[int(ib)] = dy_prof.GetBinContent(ibp)
        dy_spreads[int(ib)] = dy_prof.GetBinError(ibp)
        dz_h1.SetBinContent(ibp, dz_prof.GetBinContent(ibp))
        dz_h1.SetBinError(ibp, dz_prof.GetBinError(ibp))
        dz_means[int(ib)] = dz_prof.GetBinContent(ibp)
        dz_spreads[int(ib)] = dz_prof.GetBinError(ibp)
        rr_h1.SetBinContent(ibp, rr_prof.GetBinContent(ibp))
        rr_h1.SetBinError(ibp, rr_prof.GetBinError(ibp))
        rr_means[int(ib)] = rr_prof.GetBinContent(ibp)
        rr_spreads[int(ib)] = rr_prof.GetBinError(ibp)
        if detector == "sbnd":
            pe_h1.SetBinContent(ibp, pe_prof.GetBinContent(ibp))
            pe_h1.SetBinError(ibp, pe_prof.GetBinError(ibp))
            pe_means[int(ib)] = pe_prof.GetBinContent(ibp)
            pe_spreads[int(ib)] = pe_prof.GetBinError(ibp)

    for e in nuslice_tree:
        slice = e.charge_x
        # calculate match score
        isl = int(slice/bin_width)
        score = 0.
        if dy_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. dy_spreads[isl]: {dy_spreads[isl]} ")
            dy_spreads[isl] = dy_spreads[isl+1]
        if dz_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. dz_spreads[isl]: {dz_spreads[isl]} ")
            dz_spreads[isl] = dz_spreads[isl+1]
        if rr_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. rr_spreads[isl]: {rr_spreads[isl]} ")
            rr_spreads[isl] = rr_spreads[isl+1]
        if detector == "sbnd" and pe_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. pe_spreads[isl]: {pe_spreads[isl]} ")
            pe_spreads[isl] = pe_spreads[isl+1]
        score += abs(abs(e.flash_y-e.charge_y) - dy_means[isl])/dy_spreads[isl]
        score += abs(abs(e.flash_z-e.charge_z) - dz_means[isl])/dz_spreads[isl]
        score += abs(e.flash_r-rr_means[isl])/rr_spreads[isl]
        if detector == "sbnd" and pset.UseUncoatedPMT:
            score += abs(e.flash_ratio-pe_means[isl])/pe_spreads[isl]
        match_score_scatter.Fill(slice, score)
        match_score_hist.Fill(score)
    metrics_filename = 'fm_metrics_' + detector + '.root'
    hfile = gROOT.FindObject(metrics_filename)
    if hfile:
        hfile.Close()
    hfile = TFile(metrics_filename, 'RECREATE',
                  'Simple flash matching metrics for ' + detector.upper())
    dy_hist.Write()
    dy_prof.Write()
    dy_h1.Write()
    dz_hist.Write()
    dz_prof.Write()
    dz_h1.Write()
    rr_hist.Write()
    rr_prof.Write()
    rr_h1.Write()
    if detector == "sbnd":
        pe_hist.Write()
        pe_prof.Write()
        pe_h1.Write()
    match_score_scatter.Write()
    match_score_hist.Write()
    hfile.Close()

    canv = TCanvas("canv")

    dy_hist.Draw()
    crosses = TGraphErrors(n_bins,
                           array('f', xvals), array('f', dy_means),
                           array('f', xerrs), array('f', dy_spreads))
    crosses.SetLineColor(9)
    crosses.SetLineWidth(3)
    crosses.Draw("Psame")
    canv.Print("dy.pdf")
    canv.Update()

    dz_hist.Draw()
    crosses = TGraphErrors(n_bins,
                           array('f', xvals), array('f', dz_means),
                           array('f', xerrs), array('f', dz_spreads))
    crosses.SetLineColor(9)
    crosses.SetLineWidth(3)
    crosses.Draw("Psame")
    canv.Print("dz.pdf")
    canv.Update()

    rr_hist.Draw()
    crosses = TGraphErrors(n_bins,
                           array('f', xvals), array('f', rr_means),
                           array('f', xerrs), array('f', rr_spreads))
    crosses.SetLineColor(9)
    crosses.SetLineWidth(3)
    crosses.Draw("Psame")
    canv.Print("rr.pdf")
    canv.Update()

    if detector == "sbnd":
        pe_hist.Draw()
        crosses = TGraphErrors(n_bins,
                               array('f', xvals), array('f', pe_means),
                               array('f', xerrs), array('f', pe_spreads))
        crosses.SetLineColor(9)
        crosses.SetLineWidth(3)
        crosses.Draw("Psame")
        canv.Print("pe.pdf")
        canv.Update()

    match_score_scatter.Draw()
    canv.Print("match_score_scatter.pdf")
    canv.Update()

    match_score_hist.Draw()
    canv.Print("match_score.pdf")
    canv.Update()
    sleep(20)
Exemple #5
0
def main():
    parser = ArgumentParser(description='Scan over ROOT files to find the '+ \
                            'lumisections belonging to a specific run.')
    parser.add_argument('-b', action='store_true', help='enable batch mode')
    parser.add_argument('--dataset', required=True, choices=['PromptReco2015', \
                        'ReRecoOct2015', 'ReRecoDec2015', 'PromptReco2016', \
                        '2015ReRecoJan2017', '2016ReRecoJan2017'], \
                        help='specify data-taking period and reconstruction')
    parser.add_argument('-n', nargs=1, default=1, type=int, help='Specify '+ \
                        'the number of ZeroBias datasets to be included')
    parser.add_argument('-run', nargs=1, required=True, type=int, \
                        help='Specify the run number for the selection of '+ \
                        'the lumisections')
    parser.add_argument('-range', nargs=2, type=int, help='Specify a range '+ \
                        'in lumisections for the histogram')
    parser.add_argument('-X', dest='coords', action='append_const', \
                        const='vtx_x', help='look for vtx_x')
    parser.add_argument('-Y', dest='coords', action='append_const', \
                        const='vtx_y', help='look for vtx_y')
    parser.add_argument('-noscan', action='store_const', const=True, \
                        default=False, help='don\'t repeat the scan of the '+ \
                        'ROOT files, just do the plotting')
    parser.add_argument('-title', nargs=1, help='Specify a title for the '+ \
                        'histogram')
    args = parser.parse_args()

    from importlib import import_module
    from lsctools import config
    from lsctools.config import options as O, EOSPATH as eos
    from lsctools.tools import openRootFileU, closeRootFile, writeFiles, \
                               plotName, plotTitle, loadFiles, plotPath, \
                               drawSignature
    from lsctools.prepare import loopOverRootFiles
    from ROOT import TChain, TObject, TProfile, TCanvas, gStyle, gPad
    getattr(config, 'PCC' + args.dataset)()
    O['fulltrees'] = O['fulltrees'][:args.n]
    run = args.run[0]
    files = []
    if args.noscan:
        files = loadFiles('fulltrees_' + str(run))
    else:

        def action(tree, filename):
            condition = 'run == ' + str(run)
            if tree.GetEntries(condition) > 0:
                files.append(filename)
                print '<<< Found file:', filename

        loopOverRootFiles(action, 'fulltrees')
        writeFiles(files, 'fulltrees_' + str(run))
    chain = TChain(O['treename']['fulltrees'])
    for filename in files:
        chain.Add(eos + filename)
    name = 'vtxPos_perLS'
    title1 = 'run' + str(run) + '_perLS'
    title2 = 'Run ' + str(run)
    if (args.title):
        title2 = args.title[0] + ' (' + title2 + ')'
    f = openRootFileU(name)
    if args.range:
        mini = args.range[0]
        maxi = args.range[1]
        title1 += '_from' + str(mini) + 'to' + str(maxi)
    else:
        print '<<< Get minimum lumisection'
        mini = int(chain.GetMinimum('LS'))
        print '<<< Get maximum lumisection'
        maxi = int(chain.GetMaximum('LS'))
    for coord in args.coords:
        print '<<< Analyze coordinate', coord
        histname = plotName(coord + '_' + title1, timestamp=False)
        histtitl = plotTitle('- ' + title2)
        histfile = plotName(coord + '_' + title1)
        histpath = plotPath(coord + '_' + title1)
        hist = TProfile(histname, histtitl, maxi - mini + 1, mini - 0.5,
                        maxi + 0.5)
        chain.Draw(coord + '*1e4:LS>>' + histname, 'run == ' + str(run),
                   'goff')
        hist.Write('', TObject.kOverwrite)
        print '<<< Save plot:', histpath
        canvas = TCanvas()
        gStyle.SetOptStat(0)
        hist.Draw()
        hist.GetXaxis().SetTitle('LS')
        hist.GetYaxis().SetTitle(coord + ' [#mum]')
        hist.GetYaxis().SetTitleOffset(1.2)
        for axis in [hist.GetXaxis(), hist.GetYaxis()]:
            axis.SetTitleFont(133)
            axis.SetTitleSize(16)
            axis.SetLabelFont(133)
            axis.SetLabelSize(12)
            axis.CenterTitle()
        drawSignature(histfile)
        gPad.Modified()
        gPad.Update()
        canvas.Print(histpath)
        canvas.Close()
    closeRootFile(f, name)
Exemple #6
0
def showENC():
    fname1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/ENC_Chip5Col12_scan1.dat'

    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'
    )

    tree1.Show(500)

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

    ### change it to tgraph
    g1 = TGraphErrors()
    for i in range(p1.GetNbinsX() + 2):
        N = p1.GetBinEntries(i)
        if N > 0:
            print i, N, p1.GetXaxis().GetBinCenter(i), p1.GetBinContent(
                i), p1.GetBinError(i)
            n = g1.GetN()
            g1.SetPoint(n, p1.GetXaxis().GetBinCenter(i), p1.GetBinContent(i))
            g1.SetPointError(n, 0, p1.GetBinError(i))


#     g1.SetMarkerColor(3)
#     g1.SetLineColor(3)

    p1.Draw("axis")
    g1.Draw('Psame')

    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)

    g1.Fit(fun1)
    fun1a = g1.GetFunction('fun1')

    #     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()
Exemple #7
0
    def showENC(self):
        tree1 = TTree()
        header = 'idX/i:vL/F:vH:A:D/i:R:W'
        first = True
        for f in self.dataFiles:
            if first: tree1.ReadFile(f, header)
            else: tree1.ReadFile(f)

        p1 = TProfile('p1', 'p1;#DeltaU [V];Prob', self.bins[0],
                      tree1.GetMinimum('vH-vL') * 0.8,
                      tree1.GetMaximum('vH-vL') * 1.2)
        tree1.Draw("D:(vH-vL)>>p1", "", "profE")

        ### change it to tgraph
        g1 = TGraphErrors()
        for i in range(p1.GetNbinsX() + 2):
            N = p1.GetBinEntries(i)
            if N > 0:
                print i, N, p1.GetXaxis().GetBinCenter(i), p1.GetBinContent(
                    i), p1.GetBinError(i)
                n = g1.GetN()
                g1.SetPoint(n,
                            p1.GetXaxis().GetBinCenter(i), p1.GetBinContent(i))
                g1.SetPointError(n, 0, p1.GetBinError(i))

        p1.Draw("axis")
        g1.Draw('Psame')

        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)

        g1.Fit(fun1)
        fun1a = g1.GetFunction('fun1')

        fun1a.SetLineColor(2)

        v0 = fun1a.GetParameter(0)
        e0 = fun1a.GetParError(0)
        v1 = fun1a.GetParameter(1)
        e1 = fun1a.GetParError(1)

        print v0, v1

        fUnit = 1000.
        self.lt.DrawLatexNDC(
            0.185, 0.89,
            '#mu = {0:.1f} #pm {1:.1f} mV'.format(v0 * fUnit, e0 * fUnit))
        self.lt.DrawLatexNDC(
            0.185, 0.84,
            '#sigma = {0:.1f} #pm {1:.1f} mV'.format(v1 * fUnit, e1 * fUnit))
        if self.Info:
            self.lt.DrawLatexNDC(0.185, 0.6, self.Info)

        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()
scales = [100, 1, 1, 1, 1]
color = [4, 2, 3, 6, 7, 8]
filename = 'ecal_ratio_multi.pdf'
#Get Actual Data
#d=h5py.File("/eos/project/d/dshep/LCD/V1/EleEscan/EleEscan_1_1.h5")
d = h5py.File("/afs/cern.ch/work/g/gkhattak/public/Ele_v1_1_2.h5", 'r')
X = np.array(d.get('ECAL')[0:num_events], np.float64)
Y = np.array(d.get('target')[0:num_events][:, 1], np.float64)
X[X < 1e-6] = 0
Y = Y
Data = np.sum(X, axis=(1, 2, 3))

for j in np.arange(num_events):
    Eprof.Fill(Y[j], Data[j] / Y[j])
Eprof.SetTitle("Ratio of Ecal and Ep")
Eprof.GetXaxis().SetTitle("Ep")
Eprof.GetYaxis().SetTitle("Ecal/Ep")
Eprof.Draw()
Eprof.Fit('pol6')
c.Update()
Eprof.GetFunction("pol6").SetLineColor(color[0])
c.Update()
Eprof.SetStats(0)
Eprof.GetYaxis().SetRangeUser(0, 0.04)
Eprof.SetLineColor(color[0])
legend = TLegend(0.7, 0.7, 0.9, 0.9)
legend.AddEntry(Eprof, "Data", "l")
Gprof = []
for i, gweight in enumerate(gweights):
    Gprof.append(TProfile("Gprof" + str(i), "Gprof" + str(i), 100, 0, 500))
    #Gprof[i].SetStates(0)