TMultiGraph with Python -- TypeError

I’m trying to create a multigraph to show 3 pT plots on 1 single plot using PyROOT and setting it up in a def function, but I’m getting the following error: TypeError: could not convert argument 1. I’m a new user so I can’t upload my code and terminal output as attachments but I’d be glad to send it via replies. I want to be able to get these plots working and then save onto a pdf along with the other plots I’m getting (they’re singular – these so far will be the only superimposed graphs. Basically I want to get this right so that doing actual analysis via superimposing wouldn’t cause future issues). When I tried this using canvas originally, where I’d write mH.Draw(‘h’), mHbb.Draw(‘h, same’) it’d plot the 3 plots but then add the subsequent ones onto it so I thought TMultiGraph would help fix that issue and be able to create a legend that actually shows up on the plot. Any help would be great:

    import ROOT
#pythimport root2matplot as r2m  # can be used to generalize the for loop for calling files
# as this can actually go into any specific directory you want, unlike ROOT.TFile.Open()
#import matplotlib.pyplot as plt
import random 

def histogram(trees, canvas, mH, mX, mHbb, mHtt, mbb, mtt, FN, new_hist_file):
    all_entries = trees.GetEntries()
    mH.Sumw2()
    mX.Sumw2()
    mHbb.Sumw2()
    mHtt.Sumw2()
    mbb.Sumw2()
    mtt.Sumw2()
    # Grabbing all events with a for loop: i helps the code collect for all files
    for i in range(0, all_entries):
        trees.GetEntry(i)
        # Higgs
        H_pt = getattr(trees, "H_pt") # transverse momentum
        H_eta = getattr(trees, "H_eta") # angle
        H_phi = getattr(trees, "H_phi") # another angle
        H_E = getattr(trees, "H_e") # energy
        # Higgs bb information
        Hbb_pt = getattr(trees, "Hbb_pt") # transverse momentum
        #print(Hbb_pt)   
        Hbb_eta = getattr(trees, "Hbb_eta") # angle
        Hbb_phi = getattr(trees, "Hbb_phi") # another angle
        Hbb_E = getattr(trees, "Hbb_e") # energy
        # Higgs tt information
        Htt_pt = getattr(trees, "Htautau_pt") # transverse momentum
        #print(Htt_pt)
        Htt_eta = getattr(trees, "Htautau_eta") # angle
        Htt_phi = getattr(trees, "Htautau_phi") # another angle
        Htt_E = getattr(trees, "Htautau_e") # energy
        # b information 
        b_pt = getattr(trees, 'b_pt')
        b_eta = getattr(trees, 'b_eta')
        b_phi = getattr(trees, 'b_phi')
        b_E = getattr(trees, 'b_e')
        # t information
        t_pt = getattr(trees, 'tau_pt')
        t_eta = getattr(trees, 'tau_eta')
        t_phi = getattr(trees, 'tau_phi')
        t_E = getattr(trees, 'tau_e')
        # S bb information
        Sbb_pt = getattr(trees, 'Sbb_pt')
        #print(Sbb_pt)
        Sbb_eta = getattr(trees, 'Sbb_eta')
        Sbb_phi = getattr(trees, 'Sbb_phi')
        Sbb_E = getattr(trees, 'Sbb_e')
        # S tautau information
        Stt_pt = getattr(trees, 'Stautau_pt')
        Stt_eta = getattr(trees, 'Stautau_eta')
        Stt_phi = getattr(trees, 'Stautau_phi')
        Stt_E = getattr(trees, 'Stautau_e')
        # Converting all this to a 4-vector for simplicity
        H_0 = ROOT.TLorentzVector()
        H_0.SetPtEtaPhiE(H_pt[0], H_eta[0], H_phi[0], H_E[0])
        H_1 = ROOT.TLorentzVector()
        H_1.SetPtEtaPhiE(H_pt[1], H_eta[1], H_phi[1], H_E[1])
        # Hbb and Htt are floats, so just call them as is
        Hbb = ROOT.TLorentzVector()
        Hbb.SetPtEtaPhiE(Hbb_pt, Hbb_eta, Hbb_phi, Hbb_E) 
        Htt = ROOT.TLorentzVector()
        Htt.SetPtEtaPhiE(Htt_pt, Htt_eta, Htt_phi, Htt_E)
        # 4-vectors for b and t
        b_0 = ROOT.TLorentzVector()
        t_0 = ROOT.TLorentzVector()
        b_0.SetPtEtaPhiE(b_pt[0], b_eta[0], b_phi[0], b_E[0])
        t_0.SetPtEtaPhiE(t_pt[0], t_eta[0], t_phi[0], t_E[0])
        b_1 = ROOT.TLorentzVector()
        t_1 = ROOT.TLorentzVector()
        b_1.SetPtEtaPhiE(b_pt[1], b_eta[1], b_phi[1], b_E[1])
        t_1.SetPtEtaPhiE(t_pt[1], t_eta[1], t_phi[1], t_E[1])
        # 4-vectors for Sbb and Stt
        #Sbb = ROOT.TLorentzVector()
        #Sbb.SetPtEtaPhiE(Sbb_pt, Sbb_eta, Sbb_phi, Sbb_E)
        #Stt = ROOT.TLorentzVector()
        #Stt.SetPtEtaPhiE(Stt_pt, Stt_eta, Stt_phi, Stt_E)
        # Getting masses:
        X = H_0 + H_1  # X is just the total mass of 2 Higgs' added together
        X_mass = X.M()
        #print(X_mass)
        H_mass = H_0.M()
        Hbb_mass = Hbb.M()
        Htt_mass = Htt.M()
        bb = b_0 + b_1
        tt = t_0 + t_1
        bb_mass = bb.M()
        tt_mass = tt.M()
        #Sbb_mass = Sbb.M()
        #Stt_mass = Stt.M()
        # Fills the histogram
        mX.Fill(X_mass)
        mH.Fill(H_mass)
        mHbb.Fill(Hbb_mass)
        mHtt.Fill(Htt_mass)
        mbb.Fill(bb_mass)
        mtt.Fill(tt_mass)
        #mSbb.Fill(Sbb_mass)
        #mStt.Fill(Stt_mass)
        # Sets the histogram to continue to exist after closing the file
        mX.SetDirectory(0)
        mH.SetDirectory(0)
        mHbb.SetDirectory(0)
        mHtt.SetDirectory(0)
        mbb.SetDirectory(0)
        mtt.SetDirectory(0)
        #mSbb.SetDirectory(0)
        #mStt.SetDirectory(0)
    # Draws the histograms to be saved onto a pdf
    mH.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mX.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mHbb.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mHtt.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mbb.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mtt.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    new_hist_file.cd()
    # Writes the histograms -- for the .root files 
    mH.Write()
    mX.Write()
    mHbb.Write()
    mHtt.Write()
    mbb.Write()
    mtt.Write()
    #mSbb.Write()
    #mStt.Write()
    print('All histograms grabbed')
    return mH, mX, mHbb, mHtt, mbb, mtt
def hist_pt(trees, canvas, mg, mH_pt, mHbb_pt, mHtt_pt, FN, new_hist_file):
    all_entries = trees.GetEntries()
    mH_pt.Sumw2()
    mHbb_pt.Sumw2()
    mHtt_pt.Sumw2()
    for i in range(0, all_entries):
        trees.GetEntry(i)
        H_pt = getattr(trees, "H_pt")
        H_pt0 = H_pt[0]
        Hbb_pt = getattr(trees, "Hbb_pt")
        Htt_pt = getattr(trees, "Htautau_pt")
        mH_pt.Fill(H_pt0)
        mHbb_pt.Fill(Hbb_pt)
        mHtt_pt.Fill(Htt_pt)
        mH_pt.SetDirectory(0)
        mHbb_pt.SetDirectory(0)
        mHtt_pt.SetDirectory(0)
    # Draws the histograms
    #mH_pt.Draw('h')
    #mHbb_pt.Draw('h')
    #mHtt_pt.Draw('h')
    mg = ROOT.TMultiGraph('mg', 'TMultiGraph')
    mg.Add(mH_pt_s)
    mg.Add(mHbb_pt_s)
    mg.Add(mHtt_pt_s)
    # Adding a legend since the pt plot has more than one graph on it
    legend = ROOT.TLegend(0.7,0.6,0.85,0.75) # puts legend at right corner    
    legend.AddEntry(mH_pt,"H_pt")               
    legend.AddEntry(mHbb_pt,"Hbb_pt")           
    legend.AddEntry(mHtt_pt, "Htt_pt")
    legend.SetLineWidth(0)     
    legend.Draw('same')
    canvas.Print("hist%s.pdf" % FN)
    ## Note: legend isn't showing on the plot even though it's drawn
    new_hist_file.cd()
    mH_pt.Write()
    mHbb_pt.Write()
    mHtt_pt.Write()
    print('All pt histograms are grabbed')
    return mH_pt, mHbb_pt, mHtt_pt

def hist_pt_smeared(trees, canvas, mg, mH_pt_s, mHbb_pt_s, mHtt_pt_s, FN, new_hist_file, legend):
    all_entries = trees.GetEntries()
    mH_pt_s.Sumw2()
    mHbb_pt_s.Sumw2()
    mHtt_pt_s.Sumw2()
    for i in range(0, all_entries):
        trees.GetEntry(i)
        H_pt = getattr(trees, "H_pt")
        H_pt0_s = H_pt[0]
        Hbb_pt = getattr(trees, "Hbb_pt")
        Htt_pt = getattr(trees, "Htautau_pt")
        sigma = random.gauss(1, 0.12)
        mH_pt_s.Fill(H_pt0_s*sigma)
        mHbb_pt_s.Fill(Hbb_pt*sigma)
        mHtt_pt_s.Fill(Htt_pt*sigma)
        mH_pt_s.SetDirectory(0)
        mHbb_pt_s.SetDirectory(0)
        mHtt_pt_s.SetDirectory(0)
    # Draws histograms
    #mH_pt_s.Draw('h')
    #mHbb_pt_s.Draw('h')
    #mHtt_pt_s.Draw('h')
    mg.Add(mH_pt_s)
    mg.Add(mHbb_pt_s)
    mg.Add(mHtt_pt_s)
    mg.Draw('h')
    # Adding a legend since the pt plot has more than one graph on it
    legend = ROOT.TLegend(0.7,0.6,0.85,0.75) # puts legend at right corner    
    legend.AddEntry(mH_pt_s,"H_pt smeared")               
    legend.AddEntry(mHbb_pt_s,"Hbb_pt smeared")           
    legend.AddEntry(mHtt_pt_s, "Htt_pt smeared")
    legend.SetLineWidth(0)     
    legend.Draw('same')
    canvas.Print('hist%s.pdf' % FN)
    new_hist_file.cd()
    mH_pt_s.Write()
    mHbb_pt_s.Write()
    mHtt_pt_s.Write()
    print('All smeared pt histograms are grabbed')
    return mH_pt_s, mHbb_pt_s, mHtt_pt_s
# Adding a legend since the pt plot has more than one graph on it
    #legend = ROOT.TLegend()    # Add a legend near the top right corner -- 0.7,0.6,0.85,0.75
    #legend.AddEntry(mH_pt_s,"H_pt smeared")               
    #legend.AddEntry(mHbb_pt_s,"Hbb_pt smeared")           
    #legend.AddEntry(mHtt_pt_s, "Htt_pt smeared")
    #legend.SetLineWidth(0)
    #legend.Draw('same')
# Smearing histograms and saving them 
def smear(trees, canvas, mH_s, mX_s, mHbb_s, mHtt_s, mbb_s, mtt_s, FN, new_hist_file):
    all_entries = trees.GetEntries()
    mH_s.Sumw2()
    mX_s.Sumw2()
    mHbb_s.Sumw2()
    mHtt_s.Sumw2()
    mbb_s.Sumw2()
    mtt_s.Sumw2()
    for i in range(0, all_entries):
        trees.GetEntry(i)
        # Higgs information
        H_pt = getattr(trees, "H_pt") # transverse momentum
        H_eta = getattr(trees, "H_eta") # angle
        H_phi = getattr(trees, "H_phi") # another angle
        H_M = getattr(trees, "H_m") # invariant mass
        # Higgs bb information
        Hbb_pt = getattr(trees, "Hbb_pt") # transverse momentum
        Hbb_eta = getattr(trees, "Hbb_eta") # angle
        Hbb_phi = getattr(trees, "Hbb_phi") # another angle
        Hbb_M = getattr(trees, "Hbb_m") # mass
        # Higgs tt information
        Htt_pt = getattr(trees, "Htautau_pt") # transverse momentum
        Htt_eta = getattr(trees, "Htautau_eta") # angle
        Htt_phi = getattr(trees, "Htautau_phi") # another angle
        Htt_M = getattr(trees, "Htautau_m") # energy
        # b information 
        b_pt = getattr(trees, 'b_pt')
        b_eta = getattr(trees, 'b_eta')
        b_phi = getattr(trees, 'b_phi')
        b_M = getattr(trees, 'b_m')
        # t information
        t_pt = getattr(trees, 'tau_pt')
        t_eta = getattr(trees, 'tau_eta')
        t_phi = getattr(trees, 'tau_phi')
        t_M = getattr(trees, 'tau_m')
        # Establishing sigma -- the way to smear the plots to make them more realistic
        sigma = random.gauss(1, 0.12)
        # Converting all this to a 4-vector for simplicity
        H_0 = ROOT.TLorentzVector()
        H_0.SetPtEtaPhiM(H_pt[0]*sigma, H_eta[0], H_phi[0], H_m[0])
        H_1 = ROOT.TLorentzVector()
        H_1.SetPtEtaPhiM(H_pt[1]*sigma, H_eta[1], H_phi[1], H_m[1])
        # Hbb and Htt are floats, so just call them as is
        Hbb = ROOT.TLorentzVector()
        Hbb.SetPtEtaPhiM(Hbb_pt*sigma, Hbb_eta, Hbb_phi, Hbb_m) 
        Htt = ROOT.TLorentzVector()
        Htt.SetPtEtaPhiM(Htt_pt*sigma, Htt_eta, Htt_phi, Htt_m)
        # 4-vectors for b and t
        b_0 = ROOT.TLorentzVector()
        t_0 = ROOT.TLorentzVector()
        b_0.SetPtEtaPhiM(b_pt[0]*sigma, b_eta[0], b_phi[0], b_m[0])
        t_0.SetPtEtaPhiM(t_pt[0]*sigma, t_eta[0], t_phi[0], t_m[0])
        b_1 = ROOT.TLorentzVector()
        t_1 = ROOT.TLorentzVector()
        b_1.SetPtEtaPhiM(b_pt[1]*sigma, b_eta[1], b_phi[1], b_m[1])
        t_1.SetPtEtaPhiM(t_pt[1]*sigma, t_eta[1], t_phi[1], t_m[1])
        # Getting masses:
        X = H_0 + H_1  # X is just the total mass of 2 Higgs' added together
        X_mass = X.M()
        H_mass = H_0.M()
        Hbb_mass = Hbb.M()
        Htt_mass = Htt.M()
        bb = b_0 + b_1
        tt = t_0 + t_1
        bb_mass = bb.M()
        tt_mass = tt.M()
        # Fills the histogram, but multiply by some sigma
        mX_s.Fill(X_mass)
        mH_s.Fill(H_mass)
        mHbb_s.Fill(Hbb_mass)
        mHtt_s.Fill(Htt_mass)
        mbb_s.Fill(bb_mass)
        mtt_s.Fill(tt_mass)
        # Sets the histogram to continue to exist after closing the file
        mX_s.SetDirectory(0)
        mH_s.SetDirectory(0)
        mHbb_s.SetDirectory(0)
        mHtt_s.SetDirectory(0)
        mbb_s.SetDirectory(0)
        mtt_s.SetDirectory(0)
# Writes the histograms to a pdf file opened outside this function              
    mH_s.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mX_s.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mHbb_s.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mHtt_s.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mbb_s.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    mtt_s.Draw('h')
    canvas.Print("hist%s.pdf" % FN)
    new_hist_file.cd()
    mH_s.Write()
    mX_s.Write()
    mHbb_s.Write()
    mHtt_s.Write()
    mbb_s.Write()
    mtt_s.Write()
    print('All smeared histograms grabbed')
    return mH_s, mX_s, mHbb_s, mHtt_s, mbb_s, mtt_s
for i in range(1,31):
    filename = 'file%s.root' % i
    X_HH = ROOT.TFile.Open(filename, 'READ')
    print('File' ,i, 'is grabbed and read')
    trees = X_HH.Get('analysis')
    print('Tree', i, 'is grabbed')
    # Establishing the histogram
    # Bins are chosen based off the values obtained for each particle
    mH = ROOT.TH1D("Higgs", "m_{H}, Higgs", 100, 100e3, 200e3)
    mH.GetYaxis().SetTitle("Number of events")
    mH.GetXaxis().SetTitle("m_{H} [MeV]")
    mH.SetLineColor(ROOT.kRed)
    mH.SetTitle('Higgs mass plot -- no smearing')
    # For X histograms, since the plots have different masses that were measured, a specific if/elif/
    # else loop sets the limits for each one
    if i < 7:
        X_low = 250e3
        X_high = 400e3
        # Fix titles back to original setting ---> do it via canvas or something
        # it's repeating histograms when changing the title
        mX = ROOT.TH1D("X particle at m = 300 GeV", "m_{X}, X particle", 100, X_low, X_high) 
        mX_s = ROOT.TH1D("X particle smeared at m = 300 GeV", "m_{X}, X particle", 100, X_low, X_high)
        mX.SetLineColor(ROOT.kBlue)
        mX_s.SetLineColor(ROOT.kBlue-7)
        X_title = mX.SetTitle('X mass (at 300GeV) plot -- no smearing')
        X_s_title = mX_s.SetTitle('X mass (at 300GeV) plot with smearing')
        print('X particle histograms for files 1 --> 6 are grabbed')
    elif 7 <= i <= 12:
        X_low = 200e3
        X_high = 600e3
        mX = ROOT.TH1D("X particle at m = 500 GeV", "m_{X}, X particle", 100, X_low, X_high) 
        mX_s = ROOT.TH1D("X particle smeared at m = 500 GeV", "m_{X}, X particle", 100, X_low, X_high)
        mX.SetLineColor(ROOT.kBlue)
        mX_s.SetLineColor(ROOT.kBlue-7)
        X_title = mX.SetTitle('X mass (at 500GeV) plot -- no smearing')
        X_s_title = mX_s.SetTitle('X mass (at 500GeV) plot with smearing')
        print('X particle histograms for files 7 --> 12 are grabbed')
    elif 13 <= i <= 18:
        X_low = 200e3
        X_high = 1100e3
        mX = ROOT.TH1D("X particle at m = 1000 GeV", "m_{X}, X particle", 100, X_low, X_high) 
        mX_s = ROOT.TH1D("X particle smeared at m = 1000 GeV", "m_{X}, X particle", 100, X_low, X_high)
        mX.SetLineColor(ROOT.kBlue)
        mX_s.SetLineColor(ROOT.kBlue-7)
        X_title = mX.SetTitle('X mass (at 1000GeV) plot -- no smearing')
        X_s_title = mX_s.SetTitle('X mass (at 1000GeV) plot with smearing')
        print('X particle histograms for files 13 --> 18 are grabbed')
    elif 19 <= i <= 24:
        X_low = 200e3
        X_high = 1700e3
        mX = ROOT.TH1D("X particle at m = 1500 GeV", "m_{X}, X particle", 100, X_low, X_high) 
        mX_s = ROOT.TH1D("X particle smeared at m = 1500 GeV", "m_{X}, X particle", 100, X_low, X_high)
        mX.SetLineColor(ROOT.kBlue)
        mX_s.SetLineColor(ROOT.kBlue-7)
        X_title = mX.SetTitle('X mass (at 1500GeV) plot -- no smearing')
        X_s_title = mX_s.SetTitle('X mass (at 1500GeV) plot with smearing')
        print('X particle histograms for files 19 --> 24 are grabbed')
    else:
        X_low = 200e3
        X_high = 2100e3
        mX = ROOT.TH1D("X particle at m = 2000 GeV", 'm_{X}, X particle', 100, X_low, X_high)
        mX_s = ROOT.TH1D("X particle smeared at m = 2000 GeV", "m_{X}, X particle", 100, X_low, X_high) 
        mX.SetLineColor(ROOT.kBlue)
        mX_s.SetLineColor(ROOT.kBlue-7)
        X_title = mX.SetTitle('X mass (at 2000GeV) plot -- no smearing')
        X_s_title = mX_s.SetTitle('X mass (at 2000GeV) plot with smearing')
        print('X particle histograms for files 25 --> 30 are grabbed')
    mX = ROOT.TH1D('X particle', 'm_{X}, X particle', 100, X_low, X_high)
    mX.GetYaxis().SetTitle("Number of events")
    mX.GetXaxis().SetTitle('m_{X} [MeV]')
    mH_pt = ROOT.TH1D('pt comparison', 'Hpt', 100, 50e3, 200e3)
    mH_pt.GetYaxis().SetTitle("Number of events")
    mH_pt.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mH_pt.SetLineColor(ROOT.kSpring-7)
    mH_pt.SetTitle('pt comparison -- no smearing')
    mHbb_pt = ROOT.TH1D('pt comparison', 'Hbbpt', 100, 50e3, 200e3)
    mHbb_pt.GetYaxis().SetTitle("Number of events")
    mHbb_pt.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mHbb_pt.SetLineColor(ROOT.kRed+4)
    mHbb_pt.SetTitle('pt comparison -- no smearing')
    mHtt_pt = ROOT.TH1D('pt comparison', 'Httpt', 100, 50e3, 200e3)
    mHtt_pt.GetYaxis().SetTitle("Number of events")
    mHtt_pt.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mHtt_pt.SetLineColor(ROOT.kAzure)
    mHtt_pt.SetTitle('pt comparison -- no smearing')
    mHbb = ROOT.TH1D("Higgs bb", "m_{Hbb}, Higgs bb", 100, 50e3, 200e3)
    mHbb.GetYaxis().SetTitle("Number of events")
    mHbb.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mHbb.SetLineColor(ROOT.kOrange+9)
    mHbb.SetTitle('Higgs bb mass plot -- no smearing')
    mHtt = ROOT.TH1D("Higgs tau tau", "m_{Htt}, Higgs tt", 100, 50e3, 200e3)
    mHtt.GetYaxis().SetTitle("Number of events")
    mHtt.GetXaxis().SetTitle("m_{Htt} [MeV]")
    mHtt.SetLineColor(ROOT.kOrange+8)
    mHtt.SetTitle('Higgs tau tau mass plot -- no smearing')
    mbb = ROOT.TH1D('bb plot', 'm_{bb}, bb', 100, 9e3, 10e3)
    mbb.GetYaxis().SetTitle("Number of events")
    mbb.GetXaxis().SetTitle("m_{bb} [MeV]")
    mbb.SetLineColor(ROOT.kMagenta+3)
    mbb.SetTitle('bb mass plot -- no smearing')
    mtt = ROOT.TH1D('tautau plot', 'm_{tt}, tt', 50, 3e3, 4e3)
    mtt.GetYaxis().SetTitle("Number of events")
    mtt.GetXaxis().SetTitle("m_{tt} [MeV]")
    mtt.SetLineColor(ROOT.kMagenta-6)
    mtt.SetTitle('tau tau mass plot -- no smearing')
    mH_s = ROOT.TH1D("Higgs smeared", "m_{H}, Higgs", 100, 100e3, 200e3)
    mH_s.GetYaxis().SetTitle("Number of events")
    mH_s.GetXaxis().SetTitle("m_{H_s} [MeV]")
    mH_s.SetLineColor(ROOT.kRed-3)
    mH_s.SetTitle('Higgs mass plot with smearing')
    mX_s = ROOT.TH1D('X particle smeared', 'm_{X}, X particle', 100, X_low, X_high)
    mX_s.GetYaxis().SetTitle("Number of events")
    mX_s.GetXaxis().SetTitle('m_{X_s} [MeV]')
    mH_pt_s = ROOT.TH1D('pt comparison', 'Hpt', 100, 50e3, 200e3)
    mH_pt_s.GetYaxis().SetTitle("Number of events")
    mH_pt_s.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mH_pt_s.SetLineColor(ROOT.kSpring-7)
    mH_pt_s.SetTitle('pt comparison -- with smearing')
    mHbb_pt_s = ROOT.TH1D('pt comparison', 'Hbbpt', 100, 50e3, 200e3)
    mHbb_pt_s.GetYaxis().SetTitle("Number of events")
    mHbb_pt_s.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mHbb_pt_s.SetLineColor(ROOT.kRed+4)
    mHbb_pt_s.SetTitle('pt comparison -- with smearing')
    mHtt_pt_s = ROOT.TH1D('pt comparison', 'Httpt', 100, 50e3, 200e3)
    mHtt_pt_s.GetYaxis().SetTitle("Number of events")
    mHtt_pt_s.GetXaxis().SetTitle("m_{Hbb} [MeV]")
    mHtt_pt_s.SetLineColor(ROOT.kAzure)
    mHtt_pt_s.SetTitle('pt comparison -- with smearing')
    mHbb_s = ROOT.TH1D("Higgs bb smeared", "m_{Hbb}, Higgs bb", 100, 50e3, 200e3)
    mHbb_s.GetYaxis().SetTitle("Number of events")
    mHbb_s.GetXaxis().SetTitle("m_{Hbb_s} [MeV]")
    mHbb_s.SetLineColor(ROOT.kOrange+4)
    mHbb_s.SetTitle('Higgs bb mass plot with smearing')
    mHtt_s = ROOT.TH1D("Higgs tau tau smeared", "m_{Htt}, Higgs tt", 100, 50e3, 200e3)
    mHtt_s.GetYaxis().SetTitle("Number of events")
    mHtt_s.GetXaxis().SetTitle("m_{Htt_s} [MeV]")
    mHtt_s.SetLineColor(ROOT.kViolet)
    mHtt_s.SetTitle('Higgs tau tau mass plot with smearing')
    mbb_s = ROOT.TH1D('bb plot smeared', 'm_{bb}, bb', 300, 9e3, 10e3)
    mbb_s.GetYaxis().SetTitle("Number of events")
    mbb_s.GetXaxis().SetTitle("m_{bb_s} [MeV]")
    mbb_s.SetLineColor(ROOT.kViolet-3)
    mbb_s.SetTitle('bb mass plot with smearing')
    mtt_s = ROOT.TH1D('tautau plot smeared', 'm_{tt}, tt', 50, 3e3, 4e3)
    mtt_s.GetYaxis().SetTitle("Number of events")
    mtt_s.GetXaxis().SetTitle("m_{tt_s} [MeV]")
    mtt_s.SetLineColor(ROOT.kBlue+2)
    mtt_s.SetTitle('tau tau mass plot with smearing')
    # Got Sbb and Stt data but idk what the limits for the hist should be yet:
    #mSbb = ROOT.TH1D("S particle bb", "m_{Sbb}, S bb", 5, 0, 20000e3)
    #mStt = ROOT.TH1D("S particle tau tau", "m_{Stt}, S tt", 5, 0, 20000e3)
    # Saves hist.root files with all the plots
    hist = 'hist%s.root' % i
    new_hist_file = ROOT.TFile.Open(hist, 'RECREATE')
    # Saves files as pdfs 
    mg = ROOT.TMultiGraph('mg', 'TMultiGraph') # to plot multiple graphs on one single plot
    canvas = ROOT.TCanvas("canvas")
    canvas.cd() # Open the canvas for continuous printing
    canvas.Print('hist%s.pdf'% i +'[')
    FN = i
    # Call the functions so the plots are grabbed in the loop and saved in their respective files
    histogram(trees, canvas, mH, mX, mHbb, mHtt, mbb, mtt, FN, new_hist_file)
    hist_pt(trees, canvas, mg, mH_pt, mHbb_pt, mHtt_pt, FN, new_hist_file)
    hist_pt_smeared(trees, canvas, mg, mH_pt_s, mHbb_pt_s, mHtt_pt_s, FN, new_hist_file)
    smear(trees, canvas, mH_s, mX_s, mHbb_s, mHtt_s, mbb_s, mtt_s, FN, new_hist_file)
    canvas.Print('hist%s.pdf'% i +']')
    # Building the histogram to save onto the histogram file that's being created
    print('Running over data')
    # Closing the data file
    X_HH.Close()  
    print('Done running data from file')
    print('Writing histograms to output file...')
    print('Histograms collected for file', i,)
    # Creates and then closes the hist file
    new_hist_file.cd()
    new_hist_file.Close()

In this code you do not Draw mg. Also the option same does not exist for TLegend.

Ah ok – I had done mH_pt.Draw() etc. thinking that would work but I guess it combines canvas and TMultiGraph uses right? I’ll try this out and see what happens.

I’m getting the same error (this is from my terminal):

TypeError: none of the 2 overloaded methods succeeded. Full details:
  void TMultiGraph::Add(TGraph* graph, const char* chopt = "") =>
    TypeError: could not convert argument 1
  void TMultiGraph::Add(TMultiGraph* multigraph, const char* chopt = "") =>
    TypeError: could not convert argument 1

[quote=“ethereal-space-cadet, post:1, topic:50663”]
In the code:

    mg.Add(mH_pt_s)
    mg.Add(mHbb_pt_s)
    mg.Add(mHtt_pt_s)

mH_pt_s, mHbb_pt_s and mHtt_pt_s must be TGraphs. Are they ?

No they’re ROOT.TH1D’s. I’m relatively new to ROOT

I ended up fixing the issue by using THStack

Yes, TMuitiGraph is for TGraphs and THStack for histograms.