for icat, cat in enumerate(categoriesSELECTION): for variable in common5_input: var = variable[len("BDT_common5_input_"):] noreg_plots[var].projecttoHisto(icat, tree, variable, cat) for variable in reg_common5_input: var = variable[len("BDT_reg_common5_input_"):] reg_plots[var].projecttoHisto(icat, tree, variable, cat) noreg_output.projecttoHisto(icat, tree, "BDT_common5_output", cat) reg_output.projecttoHisto(icat, tree, "BDT_reg_common5_output", cat) c1 = ROOT.TCanvas() outputfile = ROOT.TFile(outputname + "_cat.root", "RECREATE") outputfile.cd() pdfout = PDFPrinting(outputname + "_cat") for key in noreg_plots: print key noreg_plots[key].addLabel(0.04, 0.03, "no Regression", 0, 0.035) reg_plots[key].addLabel(0.04, 0.03, "Regression", 0, 0.035) noreg_plots[key].WriteHisto(c1, "ttHbb", False, False, pdfout) reg_plots[key].WriteHisto(c1, "ttHbb", False, False, pdfout) noreg_output.addLabel(0.04, 0.03, "no Regression", 0, 0.035) reg_output.addLabel(0.04, 0.03, "Regression", 0, 0.035) noreg_output.WriteHisto(c1, "ttHbb", False, False, pdfout) reg_output.WriteHisto(c1, "ttHbb", False, False, pdfout) pdfout.closePDF()
plot_errabs.setmanualegendsize("right", 0.475, 0.65, 0.88, 0.88) plot_errsqu.changeColorlist( [ROOT.kAzure + 8, ROOT.kAzure - 7, ROOT.kPink + 4, ROOT.kRed - 7]) plot_errabs.changeColorlist( [ROOT.kAzure + 8, ROOT.kAzure - 7, ROOT.kPink + 4, ROOT.kRed - 7]) if autosel: plot_errsqu.addLabel(0.92, 0.15, "1: nTrees | 2: Shrinkage | 3: MaxDepth | 4: nCuts", 90, 0.03) plot_errsqu.addLabel(0.945, 0.15, "5: BaggedSampleFraction", 90, 0.03) plot_errabs.addLabel(0.92, 0.15, "1: nTrees | 2: Shrinkage | 3: MaxDepth | 4: nCuts", 90, 0.03) plot_errabs.addLabel(0.945, 0.15, "5: BaggedSampleFraction", 90, 0.03) pdfout = PDFPrinting(outputname) outputfile = ROOT.TFile(outputname + ".root", "RECREATE") outputfile.cd() c1 = ROOT.TCanvas() for iw, weight in enumerate(weightlist): targetvoutput = TwoDplot("Target", "Output", [50, 0.6, 1.6], [40, 0.7, 1.5], True) targetvoutput.setAxisTitle("Target", "Output") print "Processing weight", iw, "of", len(weightlist) - 1 print "Weight name:", weight.split("/")[-1] tree = TChain("MVATree")
del targetvsBDTGHnames del targetvsBDTGregcorrHnames, targetvsBDTGPTJetPartonHnames,filenames,names #raw_input("Press ret") """ pdfout = PDFPrinting("outname_configcomp") outputfile = ROOT.TFile("outname_configcomp"+".root","RECREATE") outputfile.cd() c1 = ROOT.TCanvas() for plots in compplots: for plot in plots: plot.WriteHisto(c1,"ttbar",False,False,pdfout) pdfout.closePDF() """ pdfout_norm = PDFPrinting(outputname) outputfile_norm = ROOT.TFile(outputname+".root","RECREATE") outputfile_norm.cd() c1_norm = ROOT.TCanvas() for plots in compplots: for plot in plots: plot.WriteHisto(c1_norm,"ttbar",False,True,pdfout_norm) pdfout_norm.closePDF()
ROOT.gStyle.SetOptStat(0); ROOT.gROOT.SetBatch(True) samples = ["/nfs/dust/cms/user/kschweig/JetRegression/training/trees0905/ttbar_incl", # "/nfs/dust/cms/user/kschweig/JetRegression/trees0822/ttHbb" ] samplenames = ["Background","Signal"] # Signal or Background sampletype = ["ttbar","ttHbb"] outputname = "bvl_inputvars_0907" legend = ["b jets","Light and c jets"] pdfout= PDFPrinting(outputname) outputfile = ROOT.TFile(outputname+".root","RECREATE") outputfile.cd() c1 = ROOT.TCanvas() for isample,sample in enumerate(samples): print "Processing sample",isample+1,"of",len(samples) tree = TChain("MVATree") if samplenames[isample] is "Signal": samplesel = "" else: samplesel = "Evt_Odd == 1 &&" for f in glob(sample+"/*_??_nominal*.root"):
del targetvsBDTGregcorrH del targetvsBDTGPTJetPartonH del inputfile, tree del targetvsBDTGHnames del targetvsBDTGregcorrHnames, targetvsBDTGPTJetPartonHnames, filenames, names #raw_input("Press ret") """ pdfout = PDFPrinting("outname_configcomp") outputfile = ROOT.TFile("outname_configcomp"+".root","RECREATE") outputfile.cd() c1 = ROOT.TCanvas() for plots in compplots: for plot in plots: plot.WriteHisto(c1,"ttbar",False,False,pdfout) pdfout.closePDF() """ pdfout_norm = PDFPrinting(outputname) outputfile_norm = ROOT.TFile(outputname + ".root", "RECREATE") outputfile_norm.cd() c1_norm = ROOT.TCanvas() for plots in compplots: for plot in plots: plot.WriteHisto(c1_norm, "ttbar", False, True, pdfout_norm) pdfout_norm.closePDF()
outputdif_zoom = ROOT.TH2F("outputdif_zoom","outputdif_zoom",binning_outputdiv_zoom_target[i][0],binning_outputdiv_zoom_target[i][1],binning_outputdiv_zoom_target[i][2],binning_outputdiv_zoom_div[i][0],binning_outputdiv_zoom_div[i][1],binning_outputdiv_zoom_div[i][2]) histolist = [resprereg,respostreg,outputdif_full,outputdif_zoom] tree.Project("resprereg","(Jet_MatchedPartonPt - Jet_Pt)/Jet_Pt:Jet_Pt","","") tree.Project("respostreg","(Jet_MatchedPartonPt - ("+regpt+"))/("+regpt+"):("+regpt+")","","") tree.Project("outputdif_full","( BDTG - "+target+") : "+target,"","") tree.Project("outputdif_zoom","( BDTG - "+target+") : "+target,"","") pdfout = PDFPrinting(outputname) outputfile = ROOT.TFile(outputname+".root","RECREATE") outputfile.cd() c1 = ROOT.TCanvas() c1.cd() for histo in histolist: histo.Draw("colz") c1.Update pdfout.addCanvastoPDF(c1) pdfout.closePDF() del histolist,resprereg,respostreg,outputdif_full,outputdif_zoom,inputfile,tree,pdfout
binning_outputdiv_zoom_div[i][0], binning_outputdiv_zoom_div[i][1], binning_outputdiv_zoom_div[i][2]) histolist = [resprereg, respostreg, outputdif_full, outputdif_zoom] tree.Project("resprereg", "(Jet_MatchedPartonPt - Jet_Pt)/Jet_Pt:Jet_Pt", "", "") tree.Project( "respostreg", "(Jet_MatchedPartonPt - (" + regpt + "))/(" + regpt + "):(" + regpt + ")", "", "") tree.Project("outputdif_full", "( BDTG - " + target + ") : " + target, "", "") tree.Project("outputdif_zoom", "( BDTG - " + target + ") : " + target, "", "") pdfout = PDFPrinting(outputname) outputfile = ROOT.TFile(outputname + ".root", "RECREATE") outputfile.cd() c1 = ROOT.TCanvas() c1.cd() for histo in histolist: histo.Draw("colz") c1.Update pdfout.addCanvastoPDF(c1) pdfout.closePDF() del histolist, resprereg, respostreg, outputdif_full, outputdif_zoom, inputfile, tree, pdfout
regout / inputjetvars["Jet_Pt"], iweight) del regression #if iweight == 0: # break ##### c1 = ROOT.TCanvas() c1.cd() postfix = "4" outputfile = ROOT.TFile(key + "regcorrtraining" + postfix + ".root", "RECREATE") outputfile.cd() pdfout = PDFPrinting(sample + "regcorrtraining" + postfix) print sample histosforexport = [] for histokey in outputhistos: outputhistos[histokey].WriteHisto(c1, sample, False, False, pdfout) histosforexport.append(outputhistos[histokey]) pdfout.closePDF() exporthistos("exported", histosforexport) del c1
outputfile.cd() c1 = ROOT.TCanvas() c1.cd() for key in inputplot_regcorr: inputplot_regcorr[key].makeStack(">") inputplot_regcorr[key].WriteStack(c1) for key in inputplots_regcorr: inputplots_regcorr[key].makeStack(">") inputplots_regcorr[key].WriteStack(c1) for key in outputplots_regcorr: outputplots_regcorr[key].makeStack(">") outputplots_regcorr[key].WriteStack(c1) PDFPrinting(outputfileprefix + '_regcorr', True, outputfile) del outputfile outputfile = ROOT.TFile(outputfileprefix + "_pt" + ".root", "RECREATE") outputfile.cd() for key in outputplots_pt: outputplots_pt[key].makeStack() outputplots_pt[key].WriteStack(c1) PDFPrinting(outputfileprefix + '_pt', True, outputfile) del outputfile outputfile = ROOT.TFile(outputfileprefix + "_eta" + ".root", "RECREATE")
tree1 = inputfile1.Get("MVATree") if isttH: histo_noreg = ROOT.TH1F("noreg","bbMass_noreg",125,50,250) histo_noreg.Sumw2() histo_reg = ROOT.TH1F("reg","bbMass_reg",125,50,250) histo_reg.Sumw2() else: histo_noreg = ROOT.TH1F("noreg","hadtopmass_noreg",150,100,300) histo_noreg.Sumw2() histo_reg = ROOT.TH1F("reg","hadtopmass_reg",150,100,300) histo_reg.Sumw2() if isttH: pdfout = PDFPrinting("bbMass_ger_"+leptons) else: pdfout = PDFPrinting("thadMass") c1 = ROOT.TCanvas() selection_Odd = "Evt_Odd == 0" if leptons is "all": selection_ttH = "Evt_bbMass > 0" elif leptons is "two": selection_ttH = "Evt_bbMass2Lep > 0" elif leptons is "one": selection_ttH = "Evt_bbMass1Lep > 0" elif leptons is "none": selection_ttH = "Evt_bbMass0Lep > 0" else:
"Jet_vtxNtracks": [13, -0.5, 12.5], "N_PrimaryVertices": [26, -0.5, 25.5], "Jet_leptonEta": [50, -2.5, 2.5], } c1 = ROOT.TCanvas() c1.cd() postfix = "regressed_" inputcombinations = itertools.combinations(inputvariables, 2) inputfile_data = ROOT.TFile(input_data) inputfile_ttbar = ROOT.TFile(input_ttbar) pdfout_data = PDFPrinting("output_" + postfix + str(input_data.split("/")[-1])[0:-5]) outputfile_data = ROOT.TFile("output_" + postfix + str(input_data.split("/")[-1]), "RECREATE") pdfout_ttbar = PDFPrinting("output_" + postfix + str(input_ttbar.split("/")[-1])[0:-5]) outputfile_ttbar = ROOT.TFile("output_" + postfix + str(input_ttbar.split("/")[-1]), "RECREATE") pdfout_scatter = PDFPrinting( "output_" + postfix + (str(input_ttbar.split("/")[-1])[0:-5]) + "_" + (str(input_data.split("/")[-1])[0:-5]) ) tree_data = inputfile_data.Get("MVATree") tree_ttbar = inputfile_ttbar.Get("MVATree") mcweight = "(Evt_Odd == 0) * 2 * 2.68 * Weight_PU && (Jet_regPt > 0)"
inputevthistos[key].FillnormHisto(inputevtvars[key],ikey) inputhistos = inputjethistos inputhistos.update(inputevthistos) c1 = ROOT.TCanvas() c1.cd() histosforexport = [] postfix = "_test_1" outputfile = ROOT.TFile(sample+"inputvars"+postfix+".root","RECREATE") outputfile.cd() pdfout = PDFPrinting(sample+"inputvars"+postfix) fillhisto = False for key in inputhistos: inputhistos[key].WriteHisto(c1, None, fillhisto, True, pdfout) histosforexport.append(inputhistos[key]) keylist = [] for key in inputfile: keylist.append(key) for ih, Cathist in enumerate(corr_eta_list): Cathist["Jet_corr"].makeStack() Cathist["Jet_corr"].WriteStack(c1, pdfout) histosforexport.append(Cathist["Jet_corr"])
"Jet_vtxMass": [14, 0, 7], "Jet_vtxNtracks": [13, -0.5, 12.5], "N_PrimaryVertices": [26, -.5, 25.5], "Jet_leptonEta": [50, -2.5, 2.5] } c1 = ROOT.TCanvas() c1.cd() postfix = "regressed_" inputcombinations = itertools.combinations(inputvariables, 2) inputfile_data = ROOT.TFile(input_data) inputfile_ttbar = ROOT.TFile(input_ttbar) pdfout_data = PDFPrinting("output_" + postfix + str(input_data.split("/")[-1])[0:-5]) outputfile_data = ROOT.TFile( "output_" + postfix + str(input_data.split("/")[-1]), "RECREATE") pdfout_ttbar = PDFPrinting("output_" + postfix + str(input_ttbar.split("/")[-1])[0:-5]) outputfile_ttbar = ROOT.TFile( "output_" + postfix + str(input_ttbar.split("/")[-1]), "RECREATE") pdfout_scatter = PDFPrinting("output_" + postfix + (str(input_ttbar.split("/")[-1])[0:-5]) + "_" + (str(input_data.split("/")[-1])[0:-5])) tree_data = inputfile_data.Get("MVATree") tree_ttbar = inputfile_ttbar.Get("MVATree")
histo_partonpt_misstag = ROOT.TH1F("partonpt_misstag", "partonpt_misstag", 60, 0, 2.5) histo_partonpt_noreg_misstag = ROOT.TH1F("partonpt_noreg_misstag", "partonpt_misstag", 60, 0, 2.5) histo_regcorr.Sumw2() histo_partonpt.Sumw2() histo_partonpt_nob.Sumw2() histo_partonregpt.Sumw2() histo_partonpt_noreg.Sumw2() histo_partonpt_misstag.Sumw2() histo_partonpt_noreg_misstag.Sumw2() isttH = True german = False pdfout = PDFPrinting("bregcontrol") c1 = ROOT.TCanvas() selection_Odd = "Evt_Odd == 0" selection = "Jet_Pt > 0" if isttH: selection = selection else: selection = selection + " && " + selection_Odd print "Projecting regcorr" tree1.Project("regcorr", "Jet_regcorr", selection + " && Jet_regPt > 0") print "Projecting Jet Pt / Paron pt for b-Jets" tree1.Project(
inputvars.update(inputevtvars) regpt = regression.evalReg(inputvars) outputhistos["Jet_regPt"].FillnormHisto(regpt, iweight) outputhistos["Jet_regcorr"].FillnormHisto( regpt / inputjetvars["Jet_Pt"], iweight) del regression #if iweight == 0: # break ##### c1 = ROOT.TCanvas() c1.cd() postfix = "" outputfile = ROOT.TFile(key + "inputvars" + postfix + ".root", "RECREATE") outputfile.cd() pdfout = PDFPrinting(sample + "trainingcomp" + postfix) print sample for histokey in outputhistos: outputhistos[histokey].WriteHisto(c1, sample, False, False, pdfout) pdfout.closePDF() del c1