def auto_min( histogram, nbins=20 ): """Find the first nonzero entry in the histogam and return a minimum """ nbinx=histogram.GetNbinsX() i = 1 first = 1 last = nbinx if ( histogram.Integral() == 0. ): return histogram.GetXaxis().GetXmin() content = histogram.GetBinContent(i) while ( i<nbinx and content == 0 ): content=histogram.GetBinContent(i) first=i i+=1 xmin=histogram.GetXaxis().GetBinCenter(first) xwid=histogram.GetXaxis().GetBinWidth(nbinx/2) xmin-=nbins*xwid xxmin = histogram.GetXaxis().GetXmin() return TMath.Max(xmin,xxmin)
def runCheck(filename): ## Input f = ROOT.TFile.Open(filename) if f is None: print("File %s could not be opened" % (filename)) if not (ROOT.gDirectory.cd("Method_BDT/BDTD")): print "No directory for BDT method found\n" quit() ## Get histograms and set styles sig = f.Get("Method_BDT/BDTD/MVA_BDTD_S") sigOv = f.Get("Method_BDT/BDTD/MVA_BDTD_Train_S") bkg = f.Get("Method_BDT/BDTD/MVA_BDTD_B") bkgOv = f.Get("Method_BDT/BDTD/MVA_BDTD_Train_B") TMVAGlob.SetSignalAndBackgroundStyle(sig, bkg) TMVAGlob.NormalizeHists(sig, bkg) TMVAGlob.NormalizeHists(sigOv, bkgOv) setTrainHistStyle(sigOv, sig.GetLineColor()) setTrainHistStyle(bkgOv, bkg.GetLineColor()) ## Frame c = ROOT.TCanvas("canvas", "Overtraining check", 800, 600) ROOT.gStyle.SetOptStat(0) xmin = TMath.Max( TMath.Min(sig.GetMean() - 10 * sig.GetRMS(), bkg.GetMean() - 10 * bkg.GetRMS()), sig.GetXaxis().GetXmin()) xmax = TMath.Min( TMath.Max(sig.GetMean() + 10 * sig.GetRMS(), bkg.GetMean() + 10 * bkg.GetRMS()), sig.GetXaxis().GetXmax()) ymin = 0 ymax = TMath.Max(sig.GetMaximum(), bkg.GetMaximum()) * 1.3 frame = ROOT.TH2F("ovCheck", "Overtraining check", 500, xmin, xmax, 500, ymin, ymax) frame.GetXaxis().SetTitle("BDTD response") frame.GetYaxis().SetTitle("(1/N) dN^{ }/^{ }dx") frame.Draw() ## Legends legend = ROOT.TLegend(c.GetLeftMargin(), 1 - c.GetTopMargin() - 0.12, c.GetLeftMargin() + 0.35, 1 - c.GetTopMargin()) legend.SetFillStyle(1) lSigEntry = "Signal" lBkgEntry = "Background" legend.AddEntry(sig, lSigEntry + " (test sample)", "F") legend.AddEntry(bkg, lBkgEntry + " (test sample)", "F") legend.SetBorderSize(1) legend.SetMargin(0.2) legend.Draw("same") legend2 = ROOT.TLegend(1 - c.GetRightMargin() - 0.35, 1 - c.GetTopMargin() - 0.12, 1 - c.GetRightMargin(), 1 - c.GetTopMargin()) legend2.SetFillStyle(1) legend2.SetBorderSize(1) legend2.AddEntry(sigOv, "Signal (training sample)", "P") legend2.AddEntry(bkgOv, "Background (training sample)", "P") legend2.SetMargin(0.1) legend2.Draw("same") sig.Draw("samehist") sigOv.Draw("e1 same") bkg.Draw("samehist") bkgOv.Draw("e1 same") ## Tests kolS = kolB = -1 if math.isnan(sig.ComputeIntegral(True)) or math.isnan( sigOv.ComputeIntegral(True)): kolS = -1 else: kolS = sig.KolmogorovTest(sigOv) if math.isnan(bkg.ComputeIntegral(True)) or math.isnan( bkgOv.ComputeIntegral(True)): kolB = -1 else: kolB = bkg.KolmogorovTest(bkgOv) print( "Kolmogorov-Smirnov test values for signal (background): %1.3f (%1.3f)" % (kolS, kolB)) chi2S = sig.Chi2Test(sigOv, "WW") chi2B = bkg.Chi2Test(bkgOv, "WW") print("Chi2 test values for signal (background): %1.3f (%1.3f)" % (chi2S, chi2B)) tHeader = ROOT.TText(0.165, 0.74, "Sig\t\t\t\t\t\t\t\t\tBkg") tHeader.SetNDC() tHeader.SetTextSize(0.032) tHeader.AppendPad() tTableText = "#splitline{KS:\t%1.3f \t%1.3f}{#chi^{2}: \t\t%1.3f \t%1.3f}" % ( kolS, kolB, chi2S, chi2B) tTable = ROOT.TLatex(0.12, 0.69, tTableText) tTable.SetNDC() tTable.SetTextSize(0.032) tTable.AppendPad() ## Print to EPS c.Print("plots/overtrain_BDTD.eps") # c.Print("plots/overtrain_BDTD.pdf") ## Save to temp text file return (kolS, kolB, chi2S, chi2B)
ientry = tree_l.LoadTree( jentry ) if ientry < 0: break # copy next entry into memory and verify nb = tree_l.GetEntry( jentry ) if nb <= 0: continue nJet[0] = tree_l.nJet mindr_lep1_jet[0] = tree_l.mindr_lep1_jet mindr_lep2_jet[0] = tree_l.mindr_lep2_jet avg_dr_jet[0] = tree_l.avg_dr_jet lep1_abs_eta[0] = TMath.Abs(tree_l.lep1_eta) lep2_abs_eta[0] = TMath.Abs(tree_l.lep2_eta) max_lep_eta[0] = TMath.Max(TMath.Abs(tree_l.lep1_eta), TMath.Abs(tree_l.lep2_eta)) lep1_conePt[0] = tree_l.lep1_conePt lep2_conePt[0] = tree_l.lep2_conePt mindr_tau_jet[0] = tree_l.mindr_tau_jet ptmiss[0] = TMath.Min(tree_l.ptmiss, 500) mT_lep1[0] = tree_l.mT_lep1 mT_lep2[0] = tree_l.mT_lep2 htmiss[0] = tree_l.htmiss dr_leps[0] = tree_l.dr_leps tau_pt[0] = tree_l.tau_pt tau_abs_eta[0] = TMath.Abs(tree_l.tau_eta) dr_lep1_tau[0] = tree_l.dr_lep1_tau dr_lep2_tau[0] = tree_l.dr_lep2_tau mTauTauVis1[0] = tree_l.mTauTauVis1 mTauTauVis2[0] = tree_l.mTauTauVis2 '''
h1.Draw("axis") # draw axis only h2.GetZaxis().SetTitleSize(0.05) h2.GetZaxis().SetLabelSize(0.05) h2.Draw("same, colz") HeaderLabel.SetLabel(title + ": " + plot["label2"]) HeaderLabel.Draw() outname = outputDir + plot["name"] + "_2.pdf" c.SaveAs(outname) fout.cd() c.Write() print "Wrote plot: ", outname else: h1.SetLineColor(plot["color1"]) h2.SetLineColor(plot["color2"]) h1.SetMaximum(1.1*TMath.Max(h1.GetMaximum(), h2.GetMaximum())) h1.SetMinimum(0) # print "Title is ", h1.GetTitle() h1.SetTitle(title + h1.GetTitle()) h1.SetLineWidth(2) h2.SetLineWidth(2) h1.Draw("hist") h2.Draw("hist same") leg = TLegend(0.45, 0.7, 0.95, 0.90) leg.AddEntry(h1, plot["label1"], "l") leg.AddEntry(h2, plot["label2"], "l") leg.SetFillStyle(0) leg.SetBorderSize(0) leg.SetTextFont(42) leg.Draw("l")
h.Rebin(rebin) h.SetDirectory(0) h.SetLineColor(color[i]) h.SetLineWidth(2) hist.append(h) i += 1 #----- Drawing ----------------------- can = TCanvas('can_Signal_' + var, 'can_Signal_' + var, 900, 600) can.SetRightMargin(0.2) hist[0].GetYaxis().SetNdivisions(505) hist[0].GetXaxis().SetTitle(xtitle) hist[0].GetXaxis().SetRangeUser(xmin, xmax) hist[0].SetMaximum(1.2 * TMath.Max(hist[0].GetBinContent(hist[0].GetMaximumBin()), hist[4].GetBinContent(hist[4].GetMaximumBin()))) hist[0].Draw('hist') hist[1].Draw('same hist') hist[2].Draw('same hist') hist[3].Draw('same hist') hist[4].Draw('same hist') #gPad.RedrawAxis() leg = TLegend(0.81, 0.65, 0.96, 0.9) leg.AddEntry(hist[0], '1.0 TeV', 'L') leg.AddEntry(hist[1], '1.5 TeV', 'L') leg.AddEntry(hist[2], '2.0 TeV', 'L') leg.AddEntry(hist[3], '2.5 TeV', 'L') leg.AddEntry(hist[4], '3.0 TeV', 'L') leg.SetFillColor(0) leg.SetTextFont(42)
histQCD.Add(hist[1]) hsQCD = THStack('QCD', 'QCD') hsQCD.Add(hist[0]) hsQCD.Add(hist[1]) #----- Drawing ----------------------- can = TCanvas('can_' + var, 'can_' + var, 900, 600) if logy: gPad.SetLogy() hAux = hist[3].Clone('aux') hAux.Reset() hAux.GetXaxis().SetRangeUser(xmin, xmax) hAux.GetXaxis().SetTitle(xtitle) hAux.SetMaximum(1.2 * TMath.Max(hist[3].GetBinContent( hist[3].GetMaximumBin()), histQCD.GetBinContent(histQCD.GetMaximumBin()))) hAux.SetMinimum(0.01) hAux.Draw() hsQCD.Draw('same hist') hist[3].Draw('same E') hist[2].Draw('same hist') gPad.RedrawAxis() #----- keep the GUI alive ------------ if __name__ == '__main__': rep = '' while not rep in ['q', 'Q']: rep = raw_input('enter "q" to quit: ') if 1 < len(rep): rep = rep[0]
def train_and_apply(): np.random.seed(1) ROOT.gROOT.SetBatch() #Extract data from root file tree = uproot.open("out_all.root")["outA/Tevts"] branch_mc = [ "MC_B_P", "MC_B_eta", "MC_B_phi", "MC_B_pt", "MC_D0_P", "MC_D0_eta", "MC_D0_phi", "MC_D0_pt", "MC_Dst_P", "MC_Dst_eta", "MC_Dst_phi", "MC_Dst_pt", "MC_Est_mu", "MC_M2_miss", "MC_mu_P", "MC_mu_eta", "MC_mu_phi", "MC_mu_pt", "MC_pis_P", "MC_pis_eta", "MC_pis_phi", "MC_pis_pt", "MC_q2" ] branch_rec = [ "B_P", "B_eta", "B_phi", "B_pt", "D0_P", "D0_eta", "D0_phi", "D0_pt", "Dst_P", "Dst_eta", "Dst_phi", "Dst_pt", "Est_mu", "M2_miss", "mu_P", "mu_eta", "mu_phi", "mu_pt", "pis_P", "pis_eta", "pis_phi", "pis_pt", "q2" ] nvariable = len(branch_mc) x_train = tree.array(branch_mc[0], entrystop=options.maxevents) for i in range(1, nvariable): x_train = np.vstack( (x_train, tree.array(branch_mc[i], entrystop=options.maxevents))) x_test = tree.array(branch_rec[0], entrystop=options.maxevents) for i in range(1, nvariable): x_test = np.vstack( (x_test, tree.array(branch_rec[i], entrystop=options.maxevents))) x_train = x_train.T x_test = x_test.T x_test = array2D_float(x_test) #Different type of reconstruction variables #BN normalization gamma = 0 beta = 0.2 ar = np.array(x_train) a = K.constant(ar[:, 0]) mean = K.mean(a) var = K.var(a) x_train = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) for i in range(1, nvariable): a = K.constant(ar[:, i]) mean = K.mean(a) var = K.var(a) a = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) x_train = np.vstack((x_train, a)) x_train = x_train.T ar = np.array(x_test) a = K.constant(ar[:, 0]) mean = K.mean(a) var = K.var(a) x_test = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) for i in range(1, nvariable): a = K.constant(ar[:, i]) mean = K.mean(a) var = K.var(a) a = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) x_test = np.vstack((x_test, a)) x_test = x_test.T #Add noise, remain to be improved noise = np.random.normal(loc=0.0, scale=0.01, size=x_train.shape) x_train_noisy = x_train + noise noise = np.random.normal(loc=0.0, scale=0.01, size=x_test.shape) x_test_noisy = x_test + noise x_train = np.clip(x_train, -1., 1.) x_test = np.clip(x_test, -1., 1.) x_train_noisy = np.clip(x_train_noisy, -1., 1.) x_test_noisy = np.clip(x_test_noisy, -1., 1.) # Network parameters input_shape = (x_train.shape[1], ) batch_size = 128 latent_dim = 2 # Build the Autoencoder Model # First build the Encoder Model inputs = Input(shape=input_shape, name='encoder_input') x = inputs # Shape info needed to build Decoder Model shape = K.int_shape(x) # Generate the latent vector latent = Dense(latent_dim, name='latent_vector')(x) # Instantiate Encoder Model encoder = Model(inputs, latent, name='encoder') encoder.summary() # Build the Decoder Model latent_inputs = Input(shape=(latent_dim, ), name='decoder_input') x = Dense(shape[1])(latent_inputs) x = Reshape((shape[1], ))(x) outputs = Activation('tanh', name='decoder_output')(x) # Instantiate Decoder Model decoder = Model(latent_inputs, outputs, name='decoder') decoder.summary() # Autoencoder = Encoder + Decoder # Instantiate Autoencoder Model autoencoder = Model(inputs, decoder(encoder(inputs)), name='autoencoder') autoencoder.summary() autoencoder.compile(loss='mse', optimizer='adam') # Train the autoencoder autoencoder.fit(x_train_noisy, x_train, validation_data=(x_test_noisy, x_test), epochs=options.epochs, batch_size=batch_size) # Predict the Autoencoder output from corrupted test imformation x_decoded = autoencoder.predict(x_test_noisy) # Draw Comparision Plots c = TCanvas("c", "c", 700, 700) fPads1 = TPad("pad1", "Run2", 0.0, 0.29, 1.00, 1.00) fPads2 = TPad("pad2", "", 0.00, 0.00, 1.00, 0.29) fPads1.SetBottomMargin(0.007) fPads1.SetLeftMargin(0.10) fPads1.SetRightMargin(0.03) fPads2.SetLeftMargin(0.10) fPads2.SetRightMargin(0.03) fPads2.SetBottomMargin(0.25) fPads1.Draw() fPads2.Draw() fPads1.cd() nbin = 50 min = -1. max = 1. variable = "P^{B}" lbin = (max - min) / nbin lbin = str(float((max - min) / nbin)) xtitle = branch_rec[options.branch - 1] ytitle = "Events/" + lbin + "GeV" h_rec = TH1D("h_rec", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_rec.Sumw2() h_pre = TH1D("h_pre", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_pre.Sumw2() for i in range(x_test_noisy.shape[0]): h_rec.Fill(x_test_noisy[i][options.branch - 1]) h_pre.Fill(x_decoded[i][options.branch - 1]) h_rec = UnderOverFlow1D(h_rec) h_pre = UnderOverFlow1D(h_pre) maxY = TMath.Max(h_rec.GetMaximum(), h_pre.GetMaximum()) h_rec.SetLineColor(2) h_rec.SetFillStyle(0) h_rec.SetLineWidth(2) h_rec.SetLineStyle(1) h_pre.SetLineColor(3) h_pre.SetFillStyle(0) h_pre.SetLineWidth(2) h_pre.SetLineStyle(1) h_rec.SetStats(0) h_pre.SetStats(0) h_rec.GetYaxis().SetRangeUser(0, maxY * 1.1) h_rec.Draw("HIST") h_pre.Draw("same HIST") h_rec.GetYaxis().SetTitleSize(0.06) h_rec.GetYaxis().SetTitleOffset(0.78) theLeg = TLegend(0.5, 0.45, 0.95, 0.82, "", "NDC") theLeg.SetName("theLegend") theLeg.SetBorderSize(0) theLeg.SetLineColor(0) theLeg.SetFillColor(0) theLeg.SetFillStyle(0) theLeg.SetLineWidth(0) theLeg.SetLineStyle(0) theLeg.SetTextFont(42) theLeg.SetTextSize(.05) theLeg.AddEntry(h_rec, "Reconstruction", "L") theLeg.AddEntry(h_pre, "Prediction", "L") theLeg.SetY1NDC(0.9 - 0.05 * 6 - 0.005) theLeg.SetY1(theLeg.GetY1NDC()) fPads1.cd() theLeg.Draw() title = TLatex( 0.91, 0.93, "AE prediction compare with reconstruction, epochs=" + str(options.epochs)) title.SetNDC() title.SetTextSize(0.05) title.SetTextFont(42) title.SetTextAlign(31) title.SetLineWidth(2) title.Draw() fPads2.cd() h_Ratio = h_pre.Clone("h_Ratio") h_Ratio.Divide(h_rec) h_Ratio.SetLineColor(1) h_Ratio.SetLineWidth(2) h_Ratio.SetMarkerStyle(8) h_Ratio.SetMarkerSize(0.7) h_Ratio.GetYaxis().SetRangeUser(0, 2) h_Ratio.GetYaxis().SetNdivisions(504, 0) h_Ratio.GetYaxis().SetTitle("Pre/Rec") h_Ratio.GetYaxis().SetTitleOffset(0.35) h_Ratio.GetYaxis().SetTitleSize(0.13) h_Ratio.GetYaxis().SetTitleSize(0.13) h_Ratio.GetYaxis().SetLabelSize(0.11) h_Ratio.GetXaxis().SetLabelSize(0.1) h_Ratio.GetXaxis().SetTitleOffset(0.8) h_Ratio.GetXaxis().SetTitleSize(0.14) h_Ratio.SetStats(0) axis1 = TGaxis(min, 1, max, 1, 0, 0, 0, "L") axis1.SetLineColor(1) axis1.SetLineWidth(1) for i in range(1, h_Ratio.GetNbinsX() + 1, 1): D = h_rec.GetBinContent(i) eD = h_rec.GetBinError(i) if D == 0: eD = 0.92 B = h_pre.GetBinContent(i) eB = h_pre.GetBinError(i) if B < 0.1 and eB >= B: eB = 0.92 Err = 0. if B != 0.: Err = TMath.Sqrt((eD * eD) / (B * B) + (D * D * eB * eB) / (B * B * B * B)) h_Ratio.SetBinContent(i, D / B) h_Ratio.SetBinError(i, Err) if B == 0.: Err = TMath.Sqrt((eD * eD) / (eB * eB) + (D * D * eB * eB) / (eB * eB * eB * eB)) h_Ratio.SetBinContent(i, D / 0.92) h_Ratio.SetBinError(i, Err) if D == 0 and B == 0: h_Ratio.SetBinContent(i, -1) h_Ratio.SetBinError(i, 0) h_Ratio.Draw("e0") axis1.Draw() c.SaveAs(branch_rec[options.branch - 1] + "_comparision.png")
def __init__(self, base, geom, volume="EMSS", geomvolume="same", stat="radlen", xmin=+0., xmax=-1., ymin=+0., ymax=-1., canvas=0, legend=False ): self.name = volume self.base = base self.geom = geom baseFile = get_geom_file(base) # get the files compFile = get_geom_file(geom) hname = "h_"+stat+"_"+volume+"_eta" # retrive the histograms from the files print "Get histo: " + str(hname) self.histo_base = stat_histo( stat, volume, file=baseFile ) if ( geomvolume == "same" ): self.histo_comp = stat_histo( stat, volume, compFile ) else: self.histo_comp = stat_histo( stat, geomvolume, compFile ) self.histo_diff = self.histo_base.Clone( hname + "_diff" ) # difference the histograms self.histo_diff.Add( self.histo_comp, -1.0 ) self.histo_diff.Divide(self.histo_base) # diff will be (old-new)/old * 100% if ( canvas == 0 ): canvas = TCanvas("temp"+base+geom+volume+geomvolume,"Differential 1D: baseline="+base+" compare="+geom,500,400); self.canvas = canvas # Detect and apply optional x-axis range if ( xmax > xmin ): self.histo_base.GetXaxis().SetRangeUser(xmin,xmax) self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax) # ... or zoom in on an appropriate scale else: # auto_range( self.histo_base ) # auto_range( self.histo_comp ) xmin = auto_min( self.histo_base ) xmax = auto_max( self.histo_base ) self.histo_base.GetXaxis().SetRangeUser(xmin,xmax) self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax) # xmin = TMath.Min( self.histo_base.GetXaxis().GetXmin(),self.histo_comp.GetXaxis().GetXmin() ) # xmax = TMath.Max( self.histo_base.GetXaxis().GetXmax(),self.histo_comp.GetXaxis().GetXmax() ) # print "xmin="+str(xmin) # print "xmax="+str(xmax) # Detect and apply optional y-axis range if ( ymax > ymin ): self.histo_base.GetYaxis().SetRangeUser(ymin,ymax) else: ymin = self.histo_base.GetMinimum() ymax = TMath.Max( self.histo_base.GetMaximum(), self.histo_comp.GetMaximum()) ymax *= 1.05 # Current range in y-axis extends from 0 to ymax. We want # to expand this to go from -0.2*ymax to ymax. ymin = -0.2 * ymax self.histo_base.GetYaxis().SetRangeUser(ymin,ymax) # Draw the baseline and comparison histograms self.histo_base.SetLineWidth(2) self.histo_base.SetFillStyle(1001) self.histo_base.SetFillColor(22) self.histo_base.Draw() self.histo_comp.SetLineColor(2) self.histo_comp.SetLineStyle(2) self.histo_comp.SetFillStyle(3345) self.histo_comp.SetFillColor(2) self.histo_comp.Draw("same") # Rescale difference histogram so that it is in percent self.histo_diff.Scale(100.0) # This is the maximum of the histogram. yfull_max = self.histo_diff.GetMaximum() yfull_min = self.histo_diff.GetMinimum() yfull = TMath.Max( yfull_max, TMath.Abs( yfull_min ) ) self.max_differential = yfull yfull *= 1.3 if ( yfull == 0. ): yfull = 1.0 # We need to rescale the histogram so that it fits w/in 10% of ymax self.histo_diff.Scale( 0.10 * ymax / yfull ) # Next we shift the histogram down by 0.1 * ymax nbinx=self.histo_diff.GetNbinsX(); i=1 while ( i<=nbinx ): self.histo_diff[i] -= 0.1 * ymax i+=1 # Reset the line color and draw on the same plot self.histo_diff.SetLineColor(4) self.histo_diff.Draw("same") self.line = TLine(xmin, -0.1 * ymax, xmax, -0.1*ymax ) self.line.SetLineStyle(3) self.line.Draw() # And superimpose an axis on the new plot xa = xmax self.axis = TGaxis( xa, -0.2*ymax, xa, 0.0, -yfull, +yfull, 50510, "-+L" ) self.axis.SetLabelSize(0.03) self.axis.SetLabelOffset(-0.02) self.axis.SetLineColor(4) self.axis.SetTextColor(4) self.axis.SetLabelColor(4) self.axis.SetNdivisions(4) # self.axis.SetTitle("(base-comp)/base [%]") self.axis.SetTitleSize(0.0175) self.axis.SetTitleOffset(-0.5) self.axis.Draw(); # Add the legend if requested if ( legend ): self.legend = TLegend( 0.78, 0.80, 0.98, 0.98 ) self.legend.AddEntry( self.histo_base, base ) self.legend.AddEntry( self.histo_comp, geom ) self.legend.AddEntry( self.histo_diff, "#frac{"+base+"-"+geom+"}{"+base+"} [%]" ) self.legend.Draw()
##### signal only leg_sig = TLegend(0.6, 0.7, 0.85, 0.85) leg_sig.SetLineColor(0) leg_sig.SetFillColor(0) leg_sig.AddEntry(hist_allCutsSig_1000, "M=1000", "l") leg_sig.AddEntry(hist_allCutsSig_5000, "M=5000", "l") leg_sig.AddEntry(hist_allCutsSig_8000, "M=8000", "l") can_allCuts_sig.cd() hist_allCutsSig_1000.GetXaxis().SetRangeUser(xmin, xmax) hist_allCutsSig_1000.GetXaxis().SetTitle(xtitle) hist_allCutsSig_1000.GetYaxis().SetTitle("arb. units") max_1000_5000 = TMath.Max( hist_allCutsSig_1000.GetBinContent(hist_allCutsSig_1000.GetMaximumBin()), hist_allCutsSig_5000.GetBinContent(hist_allCutsSig_5000.GetMaximumBin())) hist_allCutsSig_1000.SetMaximum(1.2 * TMath.Max( hist_allCutsSig_8000.GetBinContent(hist_allCutsSig_8000.GetMaximumBin()), max_1000_5000)) hist_allCutsSig_1000.DrawNormalized("hist") hist_allCutsSig_5000.DrawNormalized("hist same") hist_allCutsSig_8000.DrawNormalized("hist same") leg_sig.Draw() can_allCuts_sig.Write() can_allCuts_sig.SaveAs(outputDir + var + '_signal_allCuts.png') can_allCuts_sig.SaveAs(outputDir + var + '_signal_allCuts.svg') can_allCuts_sig.Close() can_allOtherCuts_sig.cd() hist_allOtherCutsSig_1000.GetXaxis().SetRangeUser(xmin, xmax)