int makePlots(float mass) { const int makeGraphs = 0; double rate_data = 104; // ritva double rate_hh; double rate_hw; double rate_qcd = 7.5; // alexandros double rate_ewk = 71.2; // matti // Check that these numbers correspond to // the rates in the datacard if (mass==120) { rate_hh = 608.872; // ritva rate_hw = 303.188; // ritva } else if (mass==100) { rate_hh = 568.476; rate_hw = 208.439; } else if (mass==160) { rate_hh = 233.449 ; rate_hw = 441.343 ; } else { cout<< "Illegal data point!" << endl; exit(-1); } char tmp[200]; int rebin = 1; // EWK from Matti TFile *file1 = new TFile("mt_ewk_lands.root","read"); TH1F *histo1 = (TH1F *) file1->Get("mt_ewk"); // from Ritva TFile *file2 = new TFile("mt_lands_ritva3.root","read"); TH1F *histo21 = (TH1F *) file2->Get("mt_data"); // now HW and HH from Matti's new file TFile *fileMatti = new TFile("mt_matti.root","read"); sprintf(tmp,"mt_hw_%.0f",mass); cout << "getting histo " << tmp << endl; TH1F *histo22 = (TH1F *) fileMatti->Get(tmp); sprintf(tmp,"mt_hh_%.0f",mass); TH1F *histo23 = (TH1F *) fileMatti->Get(tmp); // from Alexandros TFile *file3 = new TFile("fromAlexandros.root"); TH1F * histo3 = (TH1F *) file3->Get("Data_met_AfterBigBox"); // empty dummy histos TH1F * histoD1; TH1F * histoD2; histoD1 = new TH1F("T2_tt","T2_tt",40/rebin,0,400); histoD2 = new TH1F("res.","res.",40/rebin,0,400); histo1 ->Scale( rate_ewk /histo1->Integral() ); histo21->Scale( rate_data/histo21->Integral() ); histo22->Scale( rate_hw /histo22->Integral() ); histo23->Scale( rate_hh /histo23->Integral() ); histo3-> Scale( rate_qcd /histo3->Integral() ); histo1->Rebin( rebin ); histo21->Rebin( rebin ); histo22->Rebin( rebin ); histo23->Rebin( rebin ); histo3->Rebin( rebin ); histoD1->Rebin( rebin ); histoD2->Rebin( rebin ); if (makeGraphs) { int bgColor = kBlue-9; int sigColor= kRed-9; TCanvas * tc = new TCanvas(); tc->Divide(3,2); int index=1; tc->cd(index++); histo1->Draw(); // black histo21->SetMarkerColor(kBlue); histo21->SetFillColor(kBlue); histo21->SetFillStyle(kBlue); tc->cd(index++);histo21->Draw();// blue tc->cd(index++);histo22->Draw();//red tc->cd(index++);histo23->Draw();//brown histo3->SetMarkerColor(kGreen); tc->cd(index++);histo3 ->Draw();//green histoD1->SetMarkerColor(kOrange); tc->cd(index++);histoD1 ->Draw();//orange tc->SaveAs("hplus_test.png"); TH1F * sumBG = new TH1F("sumBg","sumBg",40/rebin,0,400); TH1F * sumSig = new TH1F("sumSig","sumSig",40/rebin,0,400); TH1F * sumData; TCanvas * tu = new TCanvas(); sumBG->Add(histo1); sumBG->Add(histo3); // sumBG->SetMarkerColor(kBlue); // sumBG->SetFillColor(kBlue); sumBG->SetFillColor(bgColor); // sumBG->SetFillStyle(1001); // sumBG->SetMarkerStyle(2); // sumBG->Draw("hist"); const double f=0.1; sumSig->Add(histo23,f*f); sumSig->Add(histo22,2.0*(1.0-f)*f); // sumSig->SetMarkerColor(kRed); sumSig->SetFillColor(sigColor); // sumSig->SetMarkerStyle(2); // sumSig->Draw("same"); sumData = (TH1F * ) histo21->Clone("sumData"); sumData->SetMarkerColor(kBlack); // sumData->Draw("same"); THStack * st = new THStack(); st->Add(sumBG); st->Add(sumSig); st->Draw("histe"); THStack * st2 = st->Clone(); sumData->Draw("same"); st2->Draw("same E"); TLatex text; text.SetTextAlign(12); text.SetTextSize(0.04); text.SetNDC(); // char tmpLabel[30]; // sprintf(tmpLabel,"Peak at %.3f", // myhi->GetBinCenter(myhi->GetMaximumBin())); text.SetTextColor(bgColor); text.DrawLatex(0.4,0.85,"background (ewk+qcd)"); text.SetTextColor(sigColor); text.DrawLatex(0.4,0.75,"bg + signal (HW+HH, br_{t#rightarrowH^{+}b}=0.1) "); text.SetTextColor(kBlack); text.DrawLatex(0.4,0.65,"data"); tu->SaveAs("hplus_test_db.png"); } histo1 ->SetName("Type1"); histo21->SetName("data_obs"); histo22->SetName("HW_1"); histo23->SetName("HH_1"); histo3 ->SetName("QCD"); sprintf(tmp,"hplus_%.0f.root",mass); TFile * fileOut = new TFile(tmp,"recreate"); histo1->Write(); histo21->Write(); histo22->Write(); histo23->Write(); histo3->Write(); histoD1->Write(); histoD2->Write(); fileOut->Close(); return 0; }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas. // // It also plots the signal as a dashed // // line and the data with a ratio at the // // the bottom of data/allBackgrounds // // *************************************** // TCanvas* drawPlots::plotAll(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* data, TH1D* errDown, TH1D* errUp, bool isSignalRegion, bool doLogAxis){ const unsigned int MAINPLOT_WIDTH = 800; const unsigned int MAINPLOT_HEIGHT = 500; const unsigned int RATIOPLOT_HEIGHT = 125; const unsigned int OFFSET = 10; //LUKE: Title offset and title size are proportional in //root, so you have to change them together, //this makes me a sad panda const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.4; const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.14; const double RATIOPLOT_YAXIS_TICK_LENGTH = 0.01; const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.15; const double RATIOPLOT_XAXIS_TITLE_OFFSET = 0.9; const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.2; const double RATIOPLOT_XAXIS_TICK_LENGTH = 0.05; const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.2; const double CANVAS_HEIGHT = MAINPLOT_HEIGHT+RATIOPLOT_HEIGHT+OFFSET; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); canvas->cd(); // create main pad const double mainPad_ylow = (CANVAS_HEIGHT - MAINPLOT_HEIGHT)/CANVAS_HEIGHT; const double mainPad_yhigh = 1.; const double pad_margin_left = 0.15; const double pad_margin_right = 0.05; double main_y_max = -99; double main_y_min = -99; double main_x_max = -99; double main_x_min = -99; for(int a=0; a<histos.size(); a++){ if(histos[a]){ if(histos[a]->GetEntries()> 0.){ GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max); } } } if(data){ int maxBinData = data->GetMaximumBin(); double dataYmax = data->GetBinContent(maxBinData); if(dataYmax > main_y_max) main_y_max = dataYmax; } // create main pad TPad* mainPad = new TPad("main","main",0.,mainPad_ylow,1.,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); SetAtlasStyle(); if(doLogAxis)mainPad->SetLogy(); // clone signal or data because one should exist for each plot TH1D* allBackgrounds; bool gotSomething=false; if(signal) allBackgrounds = (TH1D*)signal->Clone("all_backgrounds"); else if(data) allBackgrounds = (TH1D*)data->Clone("all_backgrounds"); else{ for(int b=0; b<histos.size(); b++){ if(histos[b] && !gotSomething){ allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds"); gotSomething=true; } } } // set all bins to zero so that you can add all histograms to it for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++) allBackgrounds->SetBinContent(i,0); THStack* Stack = new THStack(); std::string title = std::string(";") + axisName + ";Events"; Stack->SetTitle(title.c_str()); for(int b=0; b<histos.size(); b++){ if(histos[b]){ if(histos[b]->GetEntries() > 0.){ histos[b]->SetLineColor(1); histos[b]->SetFillColor(tools::setColor(names[b])); Stack->Add(histos[b]); for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){ double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j); allBackgrounds->SetBinContent(j,binContent); } } } } TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio"); if(doLogAxis){ main_y_max = main_y_max*10; if(Stack->GetMinimum()>.1) Stack->SetMinimum(.1); } else main_y_max = main_y_max*1.4; Stack->SetMaximum(main_y_max); Stack->Draw("hist"); errDown->Draw("E2same"); errUp->Draw("E2Same"); // make error histograms for the ratio plot TH1D* ratioErrDown = (TH1D*) errDown->Clone("ratio_error_down"); TH1D* ratioErrUp = (TH1D*) errUp->Clone("ratio_error_up"); ratioErrDown->Divide(backgroundsForRatio); ratioErrUp->Divide(backgroundsForRatio); if(!isSignalRegion && data) data->Draw("e same"); if(signal){ signal->SetLineStyle(2); signal->SetLineColor(kRed); signal->SetLineWidth(5); signal->Draw("hist same"); } TLegend* leg = new TLegend(0.8,0.65,0.95,0.9); leg->SetFillStyle(0); leg->SetBorderSize(0); if(signal) leg->AddEntry(signal, "Signal", "l"); if(!isSignalRegion) leg->AddEntry(data, "Data"); for(int q=0; q<histos.size(); q++){ if(histos[q]){ if(histos[q]->GetEntries() > 0.) leg->AddEntry(histos[q], names[q].c_str(), "f"); } } leg->Draw("lpe"); ATLAS_LABEL(0.2,0.85,1); char text[]="#sqrt{s}=8 TeV"; myText(0.6,0.75,1,.04, text); char text_L[]="#int L dt = 20.3 fb^{-1}"; myText(0.6, 0.85,1, .04, text_L); char inText[100]; int t; if(signal) t=sprintf(inText, "N_{Signal} = %.1f", signal->Integral(0,signal->GetNbinsX()+1)); else t=sprintf(inText, "N_{Signal} = %.1f", 0.); myText(0.2, 0.75, 1, .04, inText); double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1); if(back_int > 10000.) t=sprintf(inText, "N_{Bkgd} = %.3e", back_int); else t=sprintf(inText, "N_{Bkgd} = %.1f", back_int); myText(0.2, 0.7, 1, .04, inText); if(!isSignalRegion){ if(data) t=sprintf(inText, "N_{Data} = %.0f", data->Integral(0,data->GetNbinsX()+1)); else t=sprintf(inText, "N_{Data} = %.0f", 0.); myText(0.2, 0.65, 1, .04, inText); } canvas->cd(); // Draw Ratio plot double ratio_max = 1.6; double ratio_min = 0.4; const double x_axis_size = 0.4; const double ratio_pad_height = RATIOPLOT_HEIGHT/CANVAS_HEIGHT; double pad_xlow = 0.,pad_xhigh = 1.; double pad_ylow = OFFSET/CANVAS_HEIGHT,pad_yhigh = ratio_pad_height; const char* pad_name = "pad"; TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh); pad4ratio->SetMargin(pad_margin_left,pad_margin_right,x_axis_size,0.); pad4ratio->Draw(); pad4ratio->cd(); TH1D* ratioPlot; if(data) ratioPlot = (TH1D*)data->Clone("ratio"); else if(signal) ratioPlot = (TH1D*)signal->Clone("ratio"); // if there is no data then use signal for axis ratioPlot->SetTitle(""); ratioPlot->GetYaxis()->SetTitle("Data/MC"); ratioPlot->GetXaxis()->SetTitle(axisName.c_str()); if(data){ ratioPlot->Divide(allBackgrounds); // here change ratio_min and ratio_max if the ratio plot is quite flat double maxDeviation=0; double tempDev=0; for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){ tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.); if(tempDev > maxDeviation) maxDeviation = tempDev; } if(maxDeviation < 0.1){ ratio_max = 1.12; ratio_min = 0.88; } else if(maxDeviation < 0.2){ ratio_max = 1.25; ratio_min = .75; } ratioPlot->SetMinimum(ratio_min); ratioPlot->SetMaximum(ratio_max); } ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE); ratioPlot->GetXaxis()->SetTickLength(RATIOPLOT_XAXIS_TICK_LENGTH); ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetTickLength(RATIOPLOT_YAXIS_TICK_LENGTH); ratioPlot->GetYaxis()->SetNdivisions(3); ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE); ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET); ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE); ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET); if(!isSignalRegion && data){ ratioPlot->Draw(); // plot horizontal line at y=1 TF1* horizontal = new TF1("horizontal","pol1",-10000,10000); horizontal->SetParameter(0,1.); horizontal->SetParameter(1,0.); horizontal->SetLineColor(kBlack); horizontal->SetLineStyle(2); horizontal->SetLineWidth(1); horizontal->Draw("same"); ratioErrDown->Draw("E2same"); ratioErrUp->Draw("E2same"); }else if(isSignalRegion){ ratioPlot->Draw("axis"); char text[]="DATA IS BLINDED HERE"; myText(0.4,0.6,1,.2,text); }else{ // in this case it is not the signal region but there is no data ratioPlot->Draw("axis"); char text[]="NO DATA"; myText(0.4,0.6,1,.2,text); } return canvas; }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas. // // It also plots the signal as a dashed // // line and the data with a ratio at the // // the bottom of data/allBackgrounds // // // // This one is supposed to match the plots // // make by JP // // *************************************** // TCanvas* drawPlots::plotAll_VLQ(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, std::vector<TH1D*> signal, TH1D* data, TGraphAsymmErrors* err, bool isSignalRegion, bool doLogAxis, std::string channel){ const unsigned int CANVAS_WIDTH = 720; const unsigned int CANVAS_HEIGHT = 750; const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.75; const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.09; const double RATIOPLOT_XAXIS_TITLE_OFFSET = 1.6; const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.09; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); canvas->cd(); SetAtlasStyle(); gStyle->SetHistLineWidth(1.); // create histogram to store all backgrounds TH1D* allBackgrounds; bool gotSomething=false; for(int c=0; c<signal.size(); c++){ if(signal[c]){ allBackgrounds = (TH1D*)signal[c]->Clone("all_backgrounds"); gotSomething=true; } } if(!gotSomething && data) allBackgrounds = (TH1D*)data->Clone("all_backgrounds"); if(!gotSomething){ for(int b=0; b<histos.size(); b++){ if(histos[b] && !gotSomething){ allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds"); gotSomething=true; } } } if(!gotSomething){ std::cout << "Error: could not find any background, data, or signal for this plot" << std::endl; return canvas; } // set all bins to zero for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++) allBackgrounds->SetBinContent(i,0); // make stack of backgrounds, fill backgrounds histogram THStack* Stack = new THStack(); for(int b=0; b<histos.size(); b++){ if(histos[b]){ if(histos[b]->GetEntries() > 0.){ histos[b]->SetLineColor(1); histos[b]->SetFillColor(tools::setColor(names[b])); Stack->Add(histos[b]); for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){ double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j); allBackgrounds->SetBinContent(j,binContent); } } } } TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio"); // create main pad const double mainPad_ylow = 0.3; const double mainPad_yhigh = 0.95; const double mainPad_xlow = 0.; const double mainPad_xhigh = 0.95; const double pad_margin_left = 0.2; const double pad_margin_right = 0.02; double main_y_max = -99; double main_y_min = -99; TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); // find max y if(allBackgrounds){ int maxBinBkg = allBackgrounds->GetMaximumBin(); double bkgYmax = allBackgrounds->GetBinContent(maxBinBkg); main_y_max = bkgYmax; } if(data){ int maxBinData = data->GetMaximumBin(); double dataYmax = data->GetBinContent(maxBinData); if(dataYmax > main_y_max) main_y_max = dataYmax; } if(main_y_max < .002) main_y_max = .1; if(doLogAxis){ mainPad->SetLogy(); main_y_min = 0.007; main_y_max*=600; }else{ main_y_min = 0.001; main_y_max*=1.6; } // draw axis allBackgrounds->SetMaximum(main_y_max); allBackgrounds->SetMinimum(main_y_min); std::string title = std::string(";") + axisName + ";events/bin"; allBackgrounds->SetTitle(title.c_str()); allBackgrounds->GetYaxis()->SetTitleOffset(1.4); allBackgrounds->GetYaxis()->SetTitleSize(0.06); allBackgrounds->GetXaxis()->SetTitleOffset(1.2); allBackgrounds->GetYaxis()->SetLabelSize(0.04); allBackgrounds->GetXaxis()->SetLabelSize(0.04); allBackgrounds->Draw("hist"); // draw stack with error Stack->Draw("hist same"); if(err){ err->Draw("E2 same"); } // make error histograms for the ratio plot TGraphAsymmErrors* ratioErr = tools::getRatio(err, backgroundsForRatio); // draw data if(!isSignalRegion && data) data->Draw("e same"); // draw signal if(signal[0]){ signal[0]->SetLineStyle(2); signal[0]->SetLineColor(kRed); signal[0]->SetLineWidth(5); signal[0]->Draw("hist same"); } if(signal.size() > 1){ if(signal[1]){ signal[1]->SetLineStyle(2); signal[1]->SetLineColor(kOrange+7); signal[1]->SetLineWidth(4); signal[1]->Draw("hist same"); } if(signal.size() > 2){ if(signal[2]){ signal[2]->SetLineStyle(2); signal[2]->SetLineColor(kPink-6); signal[2]->SetLineWidth(4); signal[2]->Draw("hist same"); } } } allBackgrounds->Draw("axis same"); // draw legend float leg_height = 0.45; float leg_width = 0.2; float leg_xoffset = 0.74; float leg_yoffset = 0.7; TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(52); leg->SetTextSize(0.033); // currently assuming first signal is Tbq (single T production), second is TTS, third is BBS if(signal[0]) leg->AddEntry(signal[0], "Tbq (650 GeV)", "l"); if(signal.size()>1){ if(signal[1]) leg->AddEntry(signal[1], "TT_{S} (650 GeV)", "l"); if(signal[2]) leg->AddEntry(signal[2], "BB_{S} (650 GeV)", "l"); } if(!isSignalRegion) leg->AddEntry(data, "data 2012"); for(int q=0; q<histos.size(); q++){ if(histos[q]){ if(histos[q]->GetEntries() > 0.) leg->AddEntry(histos[q], plotLists::GetLegendName(names[q]).c_str(), "f"); } } leg->Draw("lpe"); ATLAS_LABEL(0.24,0.86,1); myText(0.36, 0.86, 1, .05, "Internal"); char text[]="#sqrt{s}=8 TeV"; myText(0.55,0.77,1,.04, text); char text_L[]="#int L dt = 20.3 fb^{-1}"; myText(0.5, 0.84,1, .04, text_L); if(channel!=""){ char chan_txt[channel.size()-1]; strcpy(chan_txt, (channel.substr(1)).c_str()); myText(0.5, 0.7, 1, .06, chan_txt); } char inText[100]; int t; if(signal[0]) t=sprintf(inText, "N_{Tbq} = %.1f", signal[0]->Integral(0,signal[0]->GetNbinsX()+1)); else t=sprintf(inText, "N_{Tbq} = %.1f", 0.); myText(0.24, 0.7, 1, .04, inText); if(signal.size()>1){ if(signal[1]) t=sprintf(inText, "N_{TTS} = %.1f", signal[1]->Integral(0,signal[1]->GetNbinsX()+1)); else t=sprintf(inText, "N_{TTS} = %.1f", 0.); myText(0.24, 0.65, 1, .04, inText); if(signal.size()>2){ if(signal[2]) t=sprintf(inText, "N_{BBS} = %.1f", signal[2]->Integral(0,signal[2]->GetNbinsX()+1)); else t=sprintf(inText, "N_{BBS} = %.1f", 0.); myText(0.24, 0.6, 1, .04, inText); } } double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1); if(back_int > 10000.) t=sprintf(inText, "N_{B} = %.3e", back_int); else t=sprintf(inText, "N_{B} = %.1f", back_int); myText(0.24, 0.75, 1, .04, inText); if(!isSignalRegion){ if(data) t=sprintf(inText, "N_{D} = %.0f", data->Integral(0,data->GetNbinsX()+1)); else t=sprintf(inText, "N_{D} = %.0f", 0.); myText(0.24, 0.8, 1, .04, inText); } canvas->cd(); // Draw Ratio plot double ratio_max = 1.6; double ratio_min = 0.4; double pad_xlow = 0.; double pad_xhigh = 0.95; double pad_ylow = 0.0; double pad_yhigh = 0.3; const char* pad_name = "pad"; TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh); pad4ratio->SetMargin(pad_margin_left,pad_margin_right,0.46,0.); pad4ratio->Draw(); pad4ratio->cd(); TH1D* ratioPlot; if(data) ratioPlot = (TH1D*)data->Clone("ratio"); else if (signal[0]) ratioPlot = (TH1D*)signal[0]->Clone("ratio"); // just for getting the axis ratioPlot->SetTitle(""); ratioPlot->Divide(allBackgrounds); ratioPlot->GetYaxis()->SetTitle("Data/MC"); ratioPlot->GetXaxis()->SetTitle(axisName.c_str()); if (data){ // here change ratio_min and ratio_max if the ratio plot is quite flat double maxDeviation=0; double tempDev=0; for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){ tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.); if(tempDev > maxDeviation) maxDeviation = tempDev; } if(maxDeviation < 0.1){ ratio_max = 1.12; ratio_min = 0.88; } else if(maxDeviation < 0.2){ ratio_max = 1.25; ratio_min = .75; } ratioPlot->SetMinimum(ratio_min); ratioPlot->SetMaximum(ratio_max); } if(ratioPlot->GetXaxis()->GetNdivisions() > ratioPlot->GetNbinsX()) ratioPlot->GetXaxis()->SetNdivisions(ratioPlot->GetNbinsX()); if(ratioPlot->GetXaxis()->GetNdivisions() > 11) ratioPlot->GetXaxis()->SetNdivisions(11); ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetNdivisions(3); ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE); ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET); ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE); ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET); if(!isSignalRegion && data){ ratioPlot->Draw(); // plot horizontal line at y=1 TF1* horizontal = new TF1("horizontal","pol1",-10000,10000); horizontal->SetParameter(0,1.); horizontal->SetParameter(1,0.); horizontal->SetLineColor(kBlack); horizontal->SetLineStyle(2); horizontal->SetLineWidth(1); horizontal->Draw("same"); ratioErr->Draw("E2 same"); }else if(isSignalRegion){ ratioPlot->Draw("axis"); char text[]="DATA IS BLIND HERE"; myText(0.4,0.6,1,.15,text); }else{ // in this case it is not the signal region but there is no data ratioPlot->Draw("axis"); char text[]="NO DATA"; myText(0.4,0.6,1,.15,text); } return canvas; }
void view() { TFile* f = TFile::Open("result.root"); int signalColorTable[20], backgroundColorTable[20]; for ( int i=0; i<20; ++i ) { signalColorTable[i] = kAzure+10-i; backgroundColorTable[i] = kOrange+10-i; } TList* signalPlots = makePlots((TDirectory*)f->Get("MC_Signal_EMEM"), signalColorTable); TList* backgroundPlots = makePlots((TDirectory*)f->Get("MC_Background_EMEM"), backgroundColorTable, true); if ( signalPlots == 0 || backgroundPlots == 0 ) return; const int nPlots = signalPlots->GetSize(); for ( int i=0; i<nPlots; ++i ) { THStack* hSignal = (THStack*)signalPlots->At(i); THStack* hBackground = (THStack*)backgroundPlots->At(i); TString histName = hSignal->GetName(); bool doLog = histName.Contains("Pt");// || histName.Contains("RelIso"); TCanvas* c = new TCanvas(TString("c")+hSignal->GetName(), hSignal->GetTitle(), 1200, 600); TPad* pad; c->Divide(2,1); TString xTitle, yTitle; pad = (TPad*)c->cd(1); if ( doLog ) pad->SetLogy(); pad->SetBorderSize(0); pad->SetBorderMode(0); hBackground->Draw(); xTitle = ((TH1*)hBackground->GetHists()->At(0))->GetXaxis()->GetTitle(); yTitle = ((TH1*)hBackground->GetHists()->At(0))->GetYaxis()->GetTitle(); hBackground->GetXaxis()->SetTitle(xTitle); hBackground->GetYaxis()->SetTitle(yTitle); pad->BuildLegend(0.6, 0.6, 0.98, 0.98); pad = (TPad*)c->cd(2); if ( doLog ) pad->SetLogy(); pad->SetBorderSize(0); pad->SetBorderMode(0); hSignal->Draw("nostack"); xTitle = ((TH1*)hSignal->GetHists()->At(0))->GetXaxis()->GetTitle(); yTitle = ((TH1*)hSignal->GetHists()->At(0))->GetYaxis()->GetTitle(); hSignal->GetXaxis()->SetTitle(xTitle); hSignal->GetYaxis()->SetTitle(yTitle); pad->BuildLegend(0.6, 0.7, 0.98, 0.98); c->Print(TString(c->GetName())+".png"); } }
void drawMassPlot( const std::string& dirName, const std::string& category, TH1D* h1_data, TH1D* h1_thq, TH1D* h1_ggh, TH1D* h1_vbf, TH1D* h1_wzh, TH1D* h1_tth, const std::string& suffix ) { DrawBase* db = new DrawBase("mgg"); db->set_lumi(19700.); TFile* dummyFile = TFile::Open("dummy.root", "recreate"); db->add_dataFile(dummyFile, "Data"); TGraphAsymmErrors* gr_data = fitTools::getGraphPoissonErrors( h1_data, false ); gr_data->SetMarkerStyle(20); gr_data->SetMarkerSize(1.3); h1_thq->SetFillColor(kWhite); h1_tth->SetFillColor(kGray); h1_wzh->SetFillColor(28); h1_vbf->SetFillColor(90); h1_ggh->SetFillColor(46); h1_thq->SetLineColor(kBlack); h1_tth->SetLineColor(kBlack); h1_wzh->SetLineColor(kBlack); h1_vbf->SetLineColor(kBlack); h1_ggh->SetLineColor(kBlack); TString category_tstr(category); bool isLeptonic = category_tstr.Contains("leptonic"); THStack stack; if( !isLeptonic ) { stack.Add(h1_ggh); stack.Add(h1_vbf); } stack.Add(h1_wzh); stack.Add(h1_tth); stack.Add(h1_thq); std::string channelName_legend = (isLeptonic) ? "Leptonic Channel" : "Hadronic Channel"; float yMin_leg = (isLeptonic) ? 0.9-4.*0.07 : 0.9-6.*0.07; TLegend* legend = new TLegend( 0.62, yMin_leg, 0.9, 0.92, channelName_legend.c_str() ); legend->SetTextFont(42); legend->SetFillColor(kWhite); legend->SetTextSize(0.038); legend->SetTextColor(kBlack); if( useCS ) legend->AddEntry( gr_data, "Data CS", "P" ); else legend->AddEntry( gr_data, "Data", "P" ); legend->AddEntry( h1_thq, "tHq (Ct = -1)", "F" ); legend->AddEntry( h1_tth, "ttH (125)", "F" ); legend->AddEntry( h1_wzh, "VH (125)", "F" ); if( !isLeptonic ) { legend->AddEntry( h1_vbf, "VBF H (125)", "F" ); legend->AddEntry( h1_ggh, "ggF H (125)", "F" ); } float yMax = 0.; float yMax_data = h1_data->GetMaximum(); if( yMax_data>0. ) { if( yMax_data < 1.5 ) yMax=3.5; else if( yMax_data < 2.5 ) yMax=6.; else yMax=yMax_data*2.; } else { float yMax_mc = h1_thq->GetMaximum()*1.2; yMax = 1.8*yMax_mc; } TH2D* h2_axes = new TH2D( "axes", "", 10, 100., 180., 10, 0., yMax); h2_axes->SetXTitle( "Diphoton Mass [GeV]"); h2_axes->SetYTitle( "Events / (1 GeV)"); TCanvas* c1 = new TCanvas("c1", "", 600, 600); c1->cd(); TPaveText* labelTop = db->get_labelTop(); h2_axes->Draw(); legend->Draw("same"); labelTop->Draw("same"); stack.Draw("histo same"); if( BLINDED ) { TLine* lineBlind_low = new TLine( 115., 0., 115., yMax ); TLine* lineBlind_hi = new TLine( 135., 0., 135., yMax ); lineBlind_low->SetLineColor(46); lineBlind_hi ->SetLineColor(46); lineBlind_low->SetLineStyle(2); lineBlind_hi ->SetLineStyle(2); lineBlind_low->SetLineWidth(2); lineBlind_hi ->SetLineWidth(2); lineBlind_low->Draw("same"); lineBlind_hi ->Draw("same"); } gr_data->Draw("p same"); gPad->RedrawAxis(); std::string canvasName = dirName + "/" + category + "/mggPlot_" + category; if( suffix!="" ) canvasName = canvasName + "_" + suffix; std::string canvasName_eps = canvasName + ".eps"; std::string canvasName_png = canvasName + ".png"; c1->SaveAs(canvasName_eps.c_str()); c1->SaveAs(canvasName_png.c_str()); delete c1; delete h2_axes; delete legend; }
void distribution(const string folderNameWithRootFiles = "", const Int_t signalRegion0_controlRegion1 = 0, const Int_t mumu0_ee1 = 0, const Int_t data0_noData1 = 0, const string var = "met", const Int_t yAxisLog_flag = 0, const Int_t MCpoissonUncertainty_flag = 0, const Double_t xAxisMin = 0, const Double_t xAxisMax = -1, const Double_t yAxisMin = 0, const Double_t yAxisMax = -1, const Int_t binDensity_flag = 0, const Int_t MCnormalizedToData_flag = 0) { // if signalRegion0_controlRegion1 == 0 (default), will do met distribution in the monojet signal region, else it will do the control region // mumu0_ee1 is for lepton flavour in CS (not used in SR) // data0_noData1 is to use or not a data file to compared with MC // yAxisLog_flag is to choose whether or not to use log scale in Y axis (default is 0, that is, normal scale) // xAxisMin and xAxisMax are the ranges for x Axis. Default values are used if xAxisMin > xAxisMax (otherwise user values are used) TH1::SetDefaultSumw2(); //all the following histograms will automatically call TH1::Sumw2() gROOT->SetStyle("Plain"); // to have white legend (on my pc it's already white, but in tier2 it appears grey) gStyle->SetFillColor(10); string filenameExtension = ".root"; // string fileDirectoryPath = "spring15_25ns_rootfiles/"; string fileDirectoryPath = "/cmshome/ciprianim/CMSSW721/output/" + folderNameWithRootFiles + "/"; string plotDirectoryPath = fileDirectoryPath; // string plotDirectoryPath = "/cmshome/ciprianim/CMSSW721/pdfsFromAnalysis/plots/monojet/met_distribution/"; //string plotDirectoryPath = "./distributions/"; string plotFileExtension = ".pdf"; string suffix; if (mumu0_ee1 == 0) suffix = "_mumu"; else if (mumu0_ee1 == 1) suffix = "_ee"; else { cout << "Error: mumu0_ee1 must be 0 or 1. End of programme." << endl; exit(EXIT_FAILURE); } TH1D* hvar = NULL; // to get histogram from file string hvarName; // name of histogram to take from file string xAxisName; // name of X axis when plotting distribution. It is a tex string (with ROOT standard), e.g. "#slash{E}_{T} [GeV]" for MET // ===== TO BE MODIFIED ===== // hvarName = "HmetNoLepDistribution"; // xAxisName = "#slash{E}_{T} [GeV]"; setDistribution(signalRegion0_controlRegion1, mumu0_ee1, var, hvarName, xAxisName); // ===================== vector<TH1D*> hMC; TH1D* hdata = NULL; vector<string> sampleName; vector<string> MC_TexLabel; if (data0_noData1 == 1) setSampleName(signalRegion0_controlRegion1, sampleName, MC_TexLabel, mumu0_ee1); else setSampleName2lepSkim(signalRegion0_controlRegion1, sampleName, MC_TexLabel, mumu0_ee1); string data_TexLabel = "data"; Int_t nFiles = (Int_t) sampleName.size(); vector<Int_t> histColor; setHistColor(histColor, nFiles); string filenameBase; string canvasName; if (signalRegion0_controlRegion1 == 0) { filenameBase = "monojet_SR_spring15_25ns_"; canvasName = var + "_monojetSR_"; } else { canvasName = var + "_zjetsCS" + suffix; if (mumu0_ee1 == 0) filenameBase = "zmumujets_CS_spring15_25ns_"; else if (mumu0_ee1 == 1) filenameBase = "zeejets_CS_spring15_25ns_"; } vector<string> MCfileName; for (Int_t i = 0; i < nFiles; i++) { MCfileName.push_back(fileDirectoryPath + filenameBase + sampleName[i] + filenameExtension); } for(Int_t i = 0; i < nFiles; i++) { cout<<"fileName : "<<MCfileName[i]<<endl; TFile* f = TFile::Open(MCfileName[i].c_str(),"READ"); if (!f || !f->IsOpen()) { cout<<"*******************************"<<endl; cout<<"Error opening file \""<<MCfileName[i]<<"\".\nApplication will be terminated."<<endl; cout<<"*******************************"<<endl; exit(EXIT_FAILURE); } //cout << "check 1 " << endl; hvar = (TH1D*)f->Get(hvarName.c_str()); if (!hvar) { cout << "Error: histogram not found in file ' " << MCfileName[i] << "'. End of programme." << endl; exit(EXIT_FAILURE); } hMC.push_back( (TH1D*)hvar->Clone() ); } // ==== FILE NAME WILL HAVE TO BE MODIFIED, NOW IT IS JUST A TEST ===== string datafileName = fileDirectoryPath; if (data0_noData1 == 0) { if (signalRegion0_controlRegion1 == 0) { datafileName += "monojet_SR_spring15_25ns_DATA.root"; } else { if (mumu0_ee1 == 0) datafileName += "zmumujets_CS_spring15_25ns_DATA.root"; else if (mumu0_ee1 == 1) datafileName += "zeejets_CS_spring15_25ns_DATA.root"; } } // ==== opening data file ====== if (data0_noData1 == 0) { cout<<"fileName : "<<datafileName<<endl; TFile* f = TFile::Open(datafileName.c_str(),"READ"); if (!f || !f->IsOpen()) { cout<<"*******************************"<<endl; cout<<"Error opening file \""<<datafileName<<"\".\nApplication will be terminated."<<endl; cout<<"*******************************"<<endl; exit(EXIT_FAILURE); } hvar = (TH1D*)f->Get(hvarName.c_str()); if (!hvar) { cout << "Error: histogram not found in file ' " << datafileName << "'. End of programme." << endl; exit(EXIT_FAILURE); } hdata = (TH1D*)hvar->Clone(); } // =============================== THStack* hMCstack = new THStack("hMCstack",""); Double_t stackNorm = 0.0; for (Int_t j = 0; j < nFiles; j++) { for (Int_t i = 1; i <= hMC[j]->GetNbinsX(); i++) { if (MCpoissonUncertainty_flag == 1) { hMC[j]->SetBinError(i,sqrt(hMC[j]->GetBinContent(i))); } } hMC[j]->SetFillColor(histColor[j]); stackNorm += hMC[j]->Integral(); } // loop again on MC histograms to scale them and then fill the thstack for (Int_t j = 0; j < nFiles; j++) { if (data0_noData1 == 0 && MCnormalizedToData_flag != 0) { Double_t dataNorm = hdata->Integral(); if (binDensity_flag != 0) hMC[j]->Scale(dataNorm/stackNorm,"width"); else hMC[j]->Scale(dataNorm/stackNorm); } else if (binDensity_flag != 0) hMC[j]->Scale(1.0,"width"); // option width divides by bin width and manages the correct error setting hMCstack->Add(hMC[j]); } if (data0_noData1 == 0) { cout << "Events in data: " << hdata->Integral() << endl; cout << "Events in MC : " << ((TH1D*) hMCstack->GetStack()->Last())->Integral() << endl; } if (data0_noData1 == 0 && binDensity_flag != 0) hdata->Scale(1.0,"width"); //if (data0_noData1 == 0 && MCnormalizedToData_flag != 0) // now here we go with the canvas TH1D * ratioplot = NULL; // will use it for the ratio plots TPad *subpad_1 = NULL; // will use it to access specific subpad in canvas TPad *subpad_2 = NULL; TCanvas *c; if (data0_noData1 == 0) c = new TCanvas(canvasName.c_str(), (var + " distribution").c_str(), 700, 700); else c = new TCanvas(canvasName.c_str(), (var + " distribution").c_str()); TLegend *leg = new TLegend(0.7,0.6,0.99,0.94); // if there are data, split canvas to draw the dta/MC ratio plot if (data0_noData1 == 0) { subpad_1 = new TPad("pad_1","",0.0,0.28,1.0,1.0); if (yAxisLog_flag) subpad_1->SetLogy(); //subpad_1->SetBottomMargin(0); subpad_2 = new TPad("pad_2","",0.0,0.0,1.0,0.32); subpad_2->SetGridy(); //subpad_2->SetTopMargin(0); subpad_2->SetBottomMargin(0.3); subpad_1->Draw(); subpad_2->Draw(); subpad_1->cd(); } else if (yAxisLog_flag) c->SetLogy(); hMCstack->Draw("HIST"); //if (yAxisMin > 0) hMCstack->SetMinimum(yAxisMin); if (yAxisMin < yAxisMax) { if (data0_noData1 == 0) subpad_1->Update(); // to be done after Draw() to access pad parameters such as default axis range else c->Update(); hMCstack->GetYaxis()->SetRangeUser(yAxisMin,yAxisMax); } // if (data0_noData1 == 0) { // if (yAxisMin > 0) hMCstack->GetYaxis()->SetRangeUser(yAxisMin, subpad_1->GetY2()); // else hMCstack->GetYaxis()->SetRangeUser(yAxisMin, c->GetY2()); // } //hMCstack->SetMaximum(4000.0); TH1D* stackCopy = (TH1D*)(((TH1D*)hMCstack->GetStack()->Last())->DrawCopy("E2 SAME")); stackCopy->SetFillColor(kBlack); stackCopy->SetFillStyle(3144); if (data0_noData1 == 1) { // when using data ( == 0) the x axis will not have labels (they will only be below in the ratio plot hMCstack->GetXaxis()->SetTitle(xAxisName.c_str()); hMCstack->GetXaxis()->SetTitleSize(0.06); hMCstack->GetXaxis()->SetTitleOffset(0.6); } if (xAxisMin < xAxisMax) { if (data0_noData1 == 0) subpad_1->Update(); // to be done after Draw() to access pad parameters such as default axis range else c->Update(); hMCstack->GetXaxis()->SetRangeUser(xAxisMin,xAxisMax); } if (binDensity_flag == 0) hMCstack->GetYaxis()->SetTitle("events"); else hMCstack->GetYaxis()->SetTitle("events / GeV"); hMCstack->GetYaxis()->SetTitleSize(0.06); hMCstack->GetYaxis()->SetTitleOffset(0.8); hMCstack->GetYaxis()->CenterTitle(); for (Int_t j = (nFiles-1); j >= 0; j--) { leg->AddEntry(hMC[j],Form("%s",MC_TexLabel[j].c_str()),"lf"); } if (data0_noData1 == 0) { hdata->SetMarkerStyle(8); // large dot hdata->Draw("EX0 SAME"); //X0 doesn't draw x error leg->AddEntry(hdata,Form("%s",data_TexLabel.c_str()),"p"); } gStyle->SetStatStyle(0); leg->Draw(); leg->SetMargin(0.3); leg->SetBorderSize(0); if (data0_noData1 == 0) { // if using data, draw the ratio plot subpad_2->cd(); ratioplot = new TH1D(*hdata); ratioplot->Divide(stackCopy); ratioplot->SetStats(0); ratioplot->SetTitle(""); ratioplot->GetXaxis()->SetLabelSize(0.10); ratioplot->GetXaxis()->SetTitle(xAxisName.c_str()); ratioplot->GetXaxis()->SetTitleSize(0.14); ratioplot->GetXaxis()->SetTitleOffset(0.8); ratioplot->GetYaxis()->SetLabelSize(0.10); ratioplot->GetYaxis()->SetTitle("data / MC"); ratioplot->GetYaxis()->SetTitleSize(0.15); ratioplot->GetYaxis()->SetTitleOffset(0.3); ratioplot->GetYaxis()->CenterTitle(); ratioplot->GetYaxis()->SetRangeUser(0.5,1.5); ratioplot->GetYaxis()->SetNdivisions(011); if (xAxisMin < xAxisMax) { //subpad_2->Update(); // to be done after Draw() to access pad parameters such as default axis range ratioplot->GetXaxis()->SetRangeUser(xAxisMin,xAxisMax); } ratioplot->SetMarkerStyle(8); //medium dot ratioplot->DrawCopy("E"); } c->SaveAs( (plotDirectoryPath + c->GetName() + plotFileExtension).c_str() ); }
void stack_norm_ring_contribs(const string& fFile, const string& fTitleExt, const string& fNameExt) { string title = "d<E>/d#eta in i#eta Ring " + fTitleExt + ";i#eta;d<E>/d#eta [GeV]"; TFile file(fFile.c_str()); file.cd("offsetAnalysis"); TH1D *p_AEEREB = p_AvgEinEREB->ProjectionX(); TH1D *p_AEEREE = p_AvgEinEREE->ProjectionX(); TH1D *p_AEERHB = p_AvgEinERHB->ProjectionX(); TH1D *p_AEERHE = p_AvgEinERHE->ProjectionX(); TH1D *p_AEERHFl = p_AvgEinERHFl->ProjectionX(); TH1D *p_AEERHFs = p_AvgEinERHFs->ProjectionX(); //TH1D *p_AEERHO = p_AvgEinC5HO->ProjectionX(); for (int i=41; i>0; i--) { p_AEEREB->SetBinContent(i,p_AEEREB->GetBinContent(i)/tower_size[41-i]); p_AEEREE->SetBinContent(i,p_AEEREE->GetBinContent(i)/tower_size[41-i]); p_AEERHB->SetBinContent(i,p_AEERHB->GetBinContent(i)/tower_size[41-i]); p_AEERHE->SetBinContent(i,p_AEERHE->GetBinContent(i)/tower_size[41-i]); p_AEERHFl->SetBinContent(i,p_AEERHFl->GetBinContent(i)/tower_size[41-i]); p_AEERHFs->SetBinContent(i,p_AEERHFs->GetBinContent(i)/tower_size[41-i]); } for (int i=43; i<84; i++) { p_AEEREB->SetBinContent(i,p_AEEREB->GetBinContent(i)/tower_size[i-43]); p_AEEREE->SetBinContent(i,p_AEEREE->GetBinContent(i)/tower_size[i-43]); p_AEERHB->SetBinContent(i,p_AEERHB->GetBinContent(i)/tower_size[i-43]); p_AEERHE->SetBinContent(i,p_AEERHE->GetBinContent(i)/tower_size[i-43]); p_AEERHFl->SetBinContent(i,p_AEERHFl->GetBinContent(i)/tower_size[i-43]); p_AEERHFs->SetBinContent(i,p_AEERHFs->GetBinContent(i)/tower_size[i-43]); } p_AEEREB->SetFillColor(50); p_AEEREE->SetFillColor(8); p_AEERHB->SetFillColor(4); p_AEERHE->SetFillColor(6); p_AEERHFl->SetFillColor(16); p_AEERHFs->SetFillColor(12); //p_AEERHO->SetFillColor(7); TCanvas *c = new TCanvas("c", "",1120,800); c->cd(); THStack *hs = new THStack("hs",title.c_str()); hs->Add(p_AEEREB); hs->Add(p_AEEREE); hs->Add(p_AEERHB); hs->Add(p_AEERHE); hs->Add(p_AEERHFl); hs->Add(p_AEERHFs); //hs->Add(p_AEERHO); hs->Draw("hist"); TLegend *legend = new TLegend(.6,.55,.68,.85); legend->SetBorderSize(1); legend->SetFillColor(0); //legend->SetFillStyle(0); legend->SetTextFont(42); legend->AddEntry(p_AEEREB,"EB","f"); legend->AddEntry(p_AEEREE,"EE","f"); legend->AddEntry(p_AEERHB,"HB","f"); legend->AddEntry(p_AEERHE,"HE","f"); legend->AddEntry(p_AEERHFl,"HFl","f"); legend->AddEntry(p_AEERHFs,"HFs","f"); //legend->AddEntry(p_AEERHO,"HO","f"); legend->Draw(); string fileName = "p_NormAvgEinER_stacked__" + fNameExt + ".png"; c->SetGridy(); c->SaveAs(fileName.c_str()); delete legend; delete hs; delete c; }
void stackPlotter::plotStack(const TString& key, legendposition legpos) { if(debug) std::cout << "stackPlotter::plotStack" << std::endl; std::vector<std::pair<Int_t,TH1*> > legEntries = stacksLegEntries_[key]; if(legEntries.size()<1) return; TCanvas *c = new TCanvas(key,key,800,600); TLegend *leg = new TLegend(0.75,0.75,0.95,0.95); //will be overwritten by style! THStack *stack = new THStack(); //determine legend position TBI (add all histos, look at mean and max values etc) //float max=stack->GetMaximum(); //unfortunately no mean function also not filled, yet. //needs another loop on histos TH1 * h=(TH1 *) legEntries.at(0).second->Clone(); for(size_t i=1;i<legEntries.size();i++){ h->Add(legEntries.at(i).second); } // int maxbin=h->GetMaximumBin(); //int minbin=h->GetMinimumBin(); // float ymax=h->GetBinContent(maxbin); //float ymin=h->GetBinContent(minbin); //pass this to the style functions delete h; //gStyle->SetOptTitle(0);//no title for(size_t i=0; i < legEntries.size(); i++) { TString legName = legEntries.at(i).second->GetName(); if(legName == "") continue; applyStyleToTH1(legEntries.at(i).second,legpos); stack->Add(legEntries.at(i).second,"HIST"); stack->SetTitle("");//legEntries.at(i).second->GetTitle()); stack->SetName(legEntries.at(i).second->GetTitle()); //mirror entry for legend leg->AddEntry(legEntries.at(legEntries.size()-1-i).second, legEntries.at(legEntries.size()-1-i).second->GetName(), "F"); } // draw plot and legend c->cd(); applyStyleToCanvas(c,legpos); stack->Draw(); stack->GetXaxis()->SetTitle(legEntries.at(0).second->GetXaxis()->GetTitle()); stack->GetYaxis()->SetTitle(legEntries.at(0).second->GetYaxis()->GetTitle()); applyStyleToAxis(stack,legpos); applyStyleToLegend(leg,legpos); stack->Draw(); leg->Draw(); //c->BuildLegend(); // save and exit if(saveplots_) { c->SaveAs(outdir_+"/"+key+".pdf"); c->SaveAs(outdir_+"/"+key+".png"); } if(savecanvases_ && outfile_) { outfile_->cd(); c->Write(); } delete stack; delete leg; delete c; }
void plot(int mass) { double myQCDRelUncert = 0.038; double myEWKRelUncert = 0.131; double myFakesRelUncert = 0.238; double delta = 1.4; double br = 0.05; bool debug = false; bool log = false; double ymin = 0.001; double ymax = 48; static bool bMessage = false; if (!bMessage) { cout << "Values used as relative uncertainty (please check):" << endl; cout << " QCD: " << myQCDRelUncert << endl; cout << " EWK genuine tau: " << myEWKRelUncert << endl; cout << " EWK fake tau: " << myFakesRelUncert << endl << endl; bMessage = true; } cout << "Processing mass point: " << mass << " GeV/c2" << endl; gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleFont(43, "xyz"); gStyle->SetTitleSize(33, "xyz"); gStyle->SetLabelFont(43, "xyz"); gStyle->SetLabelSize(27, "xyz"); //std::string infile = "EPS_data_nodeltaphi/hplus_100.root"; //std::string infile = "EPS_data_deltaphi160/hplus_100.root"; std::stringstream s; s << "lands_histograms_hplushadronic_m" << mass << ".root"; std::string infile = s.str(); // Canvas TCanvas *myCanvas = new TCanvas("myCanvas", "",0,0,600,600); myCanvas->SetHighLightColor(2); myCanvas->Range(0,0,1,1); myCanvas->SetFillColor(0); myCanvas->SetBorderMode(0); myCanvas->SetBorderSize(2); if (log) myCanvas->SetLogy(); myCanvas->SetTickx(1); myCanvas->SetTicky(1); myCanvas->SetLeftMargin(0.16); myCanvas->SetRightMargin(0.05); myCanvas->SetTopMargin(0.05); myCanvas->SetBottomMargin(0.08); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->cd(); Int_t ci; TFile* f = TFile::Open(infile.c_str()); s.str(""); s << "HW" << mass << "_1"; TH1* hw = (TH1*)f->Get(s.str().c_str()); s.str(""); s << "HH" << mass << "_1"; TH1* hh = (TH1*)f->Get(s.str().c_str()); TH1* data = (TH1*)f->Get("data_obs"); data->SetLineWidth(2); data->SetMarkerStyle(20); data->SetMarkerSize(1.2); TH1* ewktau = (TH1*)f->Get("EWK_Tau"); ci = TColor::GetColor("#993399"); ewktau->SetFillColor(ci); ewktau->SetLineWidth(0); TH1* ewkDY = (TH1*)f->Get("EWK_DYx"); TH1* ewkVV = (TH1*)f->Get("EWK_VVx"); ewktau->Add(ewkDY); ewktau->Add(ewkVV); //TH1* qcd = (TH1*)f->Get("QCDInv"); TH1* qcd = (TH1*)f->Get("QCD"); ci = TColor::GetColor("#ffcc33"); qcd->SetFillColor(ci); qcd->SetLineWidth(0); TH1* fakett = (TH1*)f->Get("fake_tt"); ci = TColor::GetColor("#669900"); fakett->SetFillColor(ci); fakett->SetLineWidth(0); TH1* fakeW = (TH1*)f->Get("fake_W"); ci = TColor::GetColor("#cc3300"); fakeW->SetFillColor(ci); fakeW->SetLineWidth(0); TH1* faket = (TH1*)f->Get("fake_t"); TH1F *hFrame = new TH1F("hFrame","",20,0,400); hFrame->SetMinimum(ymin); if (log) hFrame->SetMaximum(ymax*1.5); else hFrame->SetMaximum(ymax); hFrame->SetDirectory(0); hFrame->SetStats(0); hFrame->SetLineStyle(0); hFrame->SetMarkerStyle(20); hFrame->SetXTitle("Transverse mass (#tau jet, E_{T}^{miss}), (GeV/c^{2})"); if (paperStatus) hFrame->SetXTitle("Transverse mass (#tau_{h}, E_{T}^{miss}), (GeV/c^{2})"); hFrame->SetYTitle("Events / 20 GeV/c^{2}"); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(27); hFrame->GetYaxis()->SetTitleOffset(1.3); // signal hh->Scale(br*br); hw->Scale(2*br*(1.0-br)); TH1* signal = (TH1*)hh->Clone(); signal->Add(hw); ci = TColor::GetColor("#ff3399"); signal->SetLineColor(ci); signal->SetLineStyle(2); signal->SetLineWidth(2); // Fakes TH1* fakes = (TH1*)(fakett->Clone()); fakes->Add(fakeW); fakes->Add(faket); // stacked backgrounds THStack *exp = new THStack(); exp->SetName("exp"); exp->SetTitle("exp"); exp->Add(fakes); exp->Add(ewktau); exp->Add(qcd); exp->Add(signal); TH1* hExpBkg = (TH1*)fakes->Clone(); hExpBkg->Add(ewktau); hExpBkg->Add(qcd); // uncertainty TH1* uncert = (TH1*)fakeW->Clone(); uncert->Add(fakett); uncert->Add(ewktau); uncert->Add(qcd); uncert->SetFillColor(1); uncert->SetFillStyle(3344); uncert->SetLineColor(0); uncert->SetLineStyle(0); uncert->SetLineWidth(0); TH1* hExpBkgTotalUncert = (TH1*)uncert->Clone(); hExpBkgTotalUncert->SetFillStyle(3354); TH1* hAgreement = (TH1*)data->Clone(); hAgreement->Divide(hExpBkg); TGraphErrors* hAgreementRelUncert = new TGraphErrors(hAgreement->GetNbinsX()); hAgreementRelUncert->SetLineWidth(2); hAgreementRelUncert->SetLineColor(kBlack); for (int i = 1; i <= hFrame->GetNbinsX(); ++i) { double myQCDTotalUncert = TMath::Power(qcd->GetBinError(i), 2) + TMath::Power(qcd->GetBinContent(i)*myQCDRelUncert, 2); double myEWKTotalUncert = TMath::Power(ewktau->GetBinError(i), 2) + TMath::Power(ewktau->GetBinContent(i)*myEWKRelUncert, 2); double myFakesTotalUncert = TMath::Power(fakes->GetBinError(i), 2) + TMath::Power(fakes->GetBinContent(i)*myFakesRelUncert, 2); hExpBkgTotalUncert->SetBinError(i, TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert)); if (hExpBkg->GetBinContent(i) > 0) { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), data->GetBinContent(i) / hExpBkg->GetBinContent(i)); double myUncertData = 0; if (data->GetBinContent(i) > 0) myUncertData = TMath::Power(data->GetBinError(i) / data->GetBinContent(i), 2); double myUncertBkg = (myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / TMath::Power(hExpBkg->GetBinContent(i), 2); hAgreementRelUncert->SetPointError(i-1, 0, data->GetBinContent(i) / hExpBkg->GetBinContent(i) * TMath::Sqrt(myUncertData + myUncertBkg)); } else { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), 0); hAgreementRelUncert->SetPointError(i-1, 0, 0); } if (debug) { cout << "Point: " << hAgreementRelUncert->GetX()[i-1]-10 << "-" << hAgreementRelUncert->GetX()[i-1]+10 << " GeV/c2, agreement: " << hAgreementRelUncert->GetY()[i-1] << ", uncert: " << hAgreement->GetBinError(i) << ", " << hAgreementRelUncert->GetErrorY(i-1) << endl; cout << " bkg. stat. uncert. " << hExpBkg->GetBinError(i) << " (i.e. " << hExpBkg->GetBinError(i) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << ", stat+syst uncert. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) << " (i.e. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << endl; } } // Agreement pad TPad* pad = new TPad("ratiopad","ratiopad",0.,0.,1.,.3); pad->Draw(); pad->cd(); pad->Range(0,0,1,1); pad->SetFillColor(0); pad->SetFillStyle(4000); pad->SetBorderMode(0); pad->SetBorderSize(2); pad->SetTickx(1); pad->SetTicky(1); pad->SetLeftMargin(0.16); pad->SetRightMargin(0.05); pad->SetTopMargin(0); pad->SetBottomMargin(0.34); pad->SetFrameFillStyle(0); pad->SetFrameBorderMode(0); // Plot here ratio if (1.0-delta > 0) hAgreement->SetMinimum(1.0-delta); else hAgreement->SetMinimum(0.); hAgreement->SetMaximum(1.0+delta); hAgreement->GetXaxis()->SetLabelOffset(0.007); hAgreement->GetXaxis()->SetLabelFont(43); hAgreement->GetXaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelFont(43); hAgreement->GetYaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelOffset(0.007); hAgreement->GetYaxis()->SetNdivisions(505); hAgreement->GetXaxis()->SetTitleFont(43); hAgreement->GetYaxis()->SetTitleFont(43); hAgreement->GetXaxis()->SetTitleSize(33); hAgreement->GetYaxis()->SetTitleSize(33); hAgreement->SetTitleSize(27, "xyz"); hAgreement->GetXaxis()->SetTitleOffset(3.2); hAgreement->GetYaxis()->SetTitleOffset(1.3); hAgreement->SetXTitle(hFrame->GetXaxis()->GetTitle()); hAgreement->SetYTitle("Data/#Sigmabkg"); hAgreement->Draw("e2"); // Plot line at zero TH1* hAgreementLine = dynamic_cast<TH1*>(hAgreement->Clone()); for (int i = 1; i <= hAgreementLine->GetNbinsX(); ++i) { hAgreementLine->SetBinContent(i,1.0); hAgreementLine->SetBinError(i,0.0); } hAgreementLine->SetLineColor(kRed); hAgreementLine->SetLineWidth(2); hAgreementLine->SetLineStyle(3); hAgreementLine->Draw("hist same"); hAgreement->Draw("same"); hAgreementRelUncert->Draw("[]"); pad->RedrawAxis(); myCanvas->cd(); TPad* plotpad = new TPad("plotpad", "plotpad",0,0.3,1.,1.); plotpad->Draw(); plotpad->cd(); plotpad->Range(0,0,1,1); plotpad->SetFillColor(0); plotpad->SetFillStyle(4000); plotpad->SetBorderMode(0); plotpad->SetBorderSize(2); //if (logy) // plotpad->SetLogy(); plotpad->SetTickx(1); plotpad->SetTicky(1); plotpad->SetLeftMargin(0.16); plotpad->SetRightMargin(0.05); plotpad->SetTopMargin(0.065); plotpad->SetBottomMargin(0.0); plotpad->SetFrameFillStyle(0); plotpad->SetFrameBorderMode(0); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(33); hFrame->GetYaxis()->SetTitleOffset(1.3); // Draw objects hFrame->Draw(); exp->Draw("hist same"); uncert->Draw("E2 same"); hExpBkgTotalUncert->Draw("E2 same"); // Data data->Draw("same"); //signal->Draw("same"); TLegend *leg = new TLegend(0.53,0.6,0.87,0.91,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextFont(63); leg->SetTextSize(18); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(kWhite); //leg->SetFillStyle(4000); // enabling this will cause the plot to be erased from the pad TLegendEntry* entry = leg->AddEntry(data, "Data", "P"); s.str(""); s << "with H^{#pm}#rightarrow#tau^{#pm}#nu"; entry = leg->AddEntry(signal, s.str().c_str(), "L"); entry = leg->AddEntry(qcd, "QCD (meas.)", "F"); entry = leg->AddEntry(ewktau, "EWK genuine #tau (meas.)", "F"); entry = leg->AddEntry(fakes, "EWK fake #tau (MC)", "F"); entry = leg->AddEntry(uncert, "stat. uncert.", "F"); entry = leg->AddEntry(hExpBkgTotalUncert, "stat. #oplus syst. uncert.", "F"); leg->Draw(); string myTitle = "CMS Preliminary"; if (paperStatus) myTitle = "CMS"; TLatex *tex = new TLatex(0.62,0.945,myTitle.c_str()); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.2,0.945,"#sqrt{s} = 7 TeV"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.43,0.945,"2.2 fb^{-1}"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "m_{H^{#pm}} = " << mass << " GeV/c^{2}"; tex = new TLatex(0.28,0.865,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "BR(t#rightarrowbH^{#pm})=" << setprecision(2) << br; tex = new TLatex(0.28,0.805,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); plotpad->RedrawAxis(); plotpad->Modified(); s.str(""); s << "mT_datadriven_m" << mass << ".png"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".C"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".eps"; myCanvas->Print(s.str().c_str()); }
//void PaintOverflow(THStack *h); void SamMacroModBinWidth(){ float value = 2.5; TCanvas *c1 = new TCanvas("c1", "c1",800,500); TPad* spectrumPad=0; TPad* ratioPad=0; //c1->Divide(1,2); //gStyle->SetOptStat(111111); gStyle->SetOptFit(kFALSE); gStyle->SetOptStat(kFALSE); gStyle->SetStatX(0.457589); gStyle->SetStatY(0.312937); gStyle->SetStatW(0.29241/2+0.0185); gStyle->SetStatH(0.169580+0.05); gStyle->SetStatFontSize(0.0402098); gStyle->SetStatFont(0.02); gStyle->SetFitFormat("5.2g"); gStyle->SetStatBorderSize(0); gStyle->SetStatFontSize(0.040209); gStyle->SetStatFontSize(0.035209); c1->Range(1.592761,-5.173913,3.533814,6.006211); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(2); c1->SetLogx(1); c1->SetLogy(1); c1->SetTickx(1); c1->SetTicky(1); c1->SetLeftMargin(0.13); c1->SetRightMargin(0.07); c1->SetFrameBorderMode(0); c1->SetFrameBorderMode(0); c1->SetTopMargin(0.085); c1->SetBottomMargin(0.11); // Build the histo with constant log bin width const int NMBINS = 100; const double MMIN = 60., MMAX = 3000.; double logMbins[NMBINS+1]; float binNormNr=0.; for (int ibin = 0; ibin <= NMBINS; ibin++) { logMbins[ibin] = exp(log(MMIN) + (log(MMAX)-log(MMIN))*ibin/NMBINS); cout << logMbins[ibin] << endl; } TH1* hTTbarDiboson = new TH1F("hTTbarDiboson","",NMBINS, logMbins); TH1* hDijetWjets = new TH1F("hDijetWjets","",NMBINS, logMbins); TH1* ttbarHist = new TH1F("ttbarHist","",NMBINS, logMbins); TH1* dibosonsBkgHist = new TH1F("dibosonsBkgHist","",NMBINS, logMbins); //========================================================== // // Get the histograms //========================================================== //TFile *file1 = new TFile("h_ZprimeRecomass_DYBinWidth.root","READ"); //TH1* zeeHist = (TH1*) file1->Get("ZprimeRecomassBinWidth"); TFile *file1 = new TFile("DY-MuMu-MC-OS-allbins-MC-2673pb.root","READ"); TH1* zeeHist = (TH1*) file1->Get("hMassDYAll6"); TFile *file2 = new TFile("h_ZprimeRecomass_Tlike.root","READ"); TH1* ttbarHist = (TH1*) file2->Get("ZprimeRecomassBinWidth"); TFile *file3 = new TFile("h_ZprimeRecomass_DiBoson.root","READ"); TH1* dibosonsBkgHist = (TH1*) file3->Get("ZprimeRecomassBinWidth"); TFile *file4 = new TFile("h_ZprimeRecomass_data.root","READ"); TH1* dataHistTempbar = (TH1*) file4->Get("ZprimeRecomassBinWidth"); TFile *file5 = new TFile("FR-DiJets-Data-OS-BinWidth-2673pb.root","READ"); TH1* jetBkgHist = (TH1*) file5->Get("DataSub"); TFile *file6 = new TFile("FR-Wjets-25nsMC-OS-BinWidth-2673pb.root","READ"); TH1* WjetsBkgHist = (TH1*) file6->Get("WjetsHisto"); std::cout<<"nbQCD(dijets,Data) = "<<jetBkgHist->Integral()<<endl; std::cout<<"nb.Wjets(MC) = "<<WjetsBkgHist->Integral()<<endl; hTTbarDiboson->Add(ttbarHist,dibosonsBkgHist,1,1); hDijetWjets->Add(jetBkgHist,WjetsBkgHist,1,1); zeeHist->Rebin(value); hTTbarDiboson->Rebin(value); dibosonsBkgHist->Rebin(value); dataHistTempbar->Rebin(value); hDijetWjets->Rebin(value); WjetsBkgHist->Rebin(value); float binWidthNorm=1; int zeeColour = TColor::GetColor("#99ccff"); int jetBkgColour = TColor::GetColor("#ffff66"); int ttbarColour = TColor::GetColor("#ff6666"); int bosonColour = TColor::GetColorDark(3); int WjetsColour = TColor::GetColorDark(5); int font = 42; //float xAxisMin = 60; //72 //float xAxisMax = 1000.0; //float yAxisMin = 1e-4; //float yAxisMax = 1e3; TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm,0); normHistToBinWidth(zeeHist,binWidthNorm); normHistToBinWidth(hTTbarDiboson,binWidthNorm); //normHistToBinWidth(dibosonsBkgHist,binWidthNorm); normHistToBinWidth(hDijetWjets,binWidthNorm); //normHistToBinWidth(WjetsBkgHist,binWidthNorm); //gStyle->SetOptStat(111111); //PaintOverflow(zeeHist); //PaintOverflow(ttbarHist); //PaintOverflow(dibosonsBkgHist); //PaintOverflow(dataHistTempbar); //PaintOverflow(jetBkgHist); //PaintOverflow(WjetsBkgHist); THStack *axisHist = new THStack("axisHist",""); zeeHist->SetFillColor(zeeColour); zeeHist->SetLineWidth(2); zeeHist->SetLineColor(1); zeeHist->SetTitle(""); hTTbarDiboson->SetFillColor(ttbarColour); hTTbarDiboson->SetLineWidth(2); hTTbarDiboson->SetLineColor(1); //dibosonsBkgHist->SetFillColor(bosonColour); //dibosonsBkgHist->SetLineWidth(2); //dibosonsBkgHist->SetLineColor(1); //WjetsBkgHist->SetFillColor(WjetsColour); //WjetsBkgHist->SetFillColor(jetBkgColour); //WjetsBkgHist->SetLineWidth(2); //WjetsBkgHist->SetLineColor(1); hDijetWjets->SetFillColor(jetBkgColour); hDijetWjets->SetLineWidth(2); hDijetWjets->SetLineColor(1); axisHist->Add(hDijetWjets,"histo"); //axisHist->Add(WjetsBkgHist,"histo"); axisHist->Add(hTTbarDiboson); //axisHist->Add(dibosonsBkgHist); axisHist->Add(zeeHist); axisHist->Draw("histo"); //axisHist->GetYaxis()->SetTitle("Events / 20 GeV"); axisHist->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]"); axisHist->GetYaxis()->SetTitle("Events/GeV"); //axisHist->GetXaxis()->SetTitleOffset(1.1); //axisHist->GetYaxis()->SetTitleOffset(1.1); axisHist->GetXaxis()->SetTitleSize(0.047); axisHist->GetYaxis()->SetTitleSize(0.047); axisHist->GetXaxis()->SetLabelSize(0.050); axisHist->GetYaxis()->SetLabelSize(0.050); axisHist->GetXaxis()->SetMoreLogLabels(); axisHist->GetXaxis()->SetNoExponent(); axisHist->GetXaxis()->SetRangeUser(70.0,2999.0); //axisHist->SetMinimum(0.01); //axisHist->SetMaximum(20000.0); axisHist->SetMinimum(0.0001); axisHist->SetMaximum(2000.0); dataHist->SetMarkerStyle(20); dataHist->SetMarkerSize(0.9); dataHist->GetXaxis()->SetRange(5,83); dataHist->GetXaxis()->SetTitleSize(0.047); dataHist->GetXaxis()->SetTitleOffset(0.9); dataHist->GetYaxis()->SetTitleSize(0.047); dataHist->GetYaxis()->SetTitleOffset(1.2); dataHist->Draw("PZ"); //========================================================== TLegend *leg = new TLegend(0.56741,0.62671,0.820536,0.87664,NULL,"brNDC"); //for lumi in plot leg->AddEntry(dataHist,"Data","PE"); leg->AddEntry(zeeHist,"#gamma^{*}/Z#rightarrow#mu^{+}#mu^{-}","F"); leg->AddEntry(hTTbarDiboson,"t#bar{t}, tW, WW, WZ, ZZ, #tau^{+}#tau^{-}","F"); //leg->AddEntry(dibosonsBkgHist,"di-boson, #gamma^{*}/Z#rightarrow#tau^{+}#tau^{-}","F"); //leg->AddEntry(WjetsBkgHist,"W+jets (FR)","F"); leg->AddEntry(hDijetWjets,"Jets (data)","F"); leg->SetBorderSize(0); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(19); leg->SetFillStyle(0); leg->SetTextFont(font); leg->SetTextSize(0.04); leg->Draw(); //========================================================== TPaveText* tText1 = new TPaveText(0.75, 0.92, 0.87, 0.98, "brNDC"); tText1->SetBorderSize(0); tText1->SetFillColor(0); tText1->SetFillStyle(0); TText *t1 = tText1->AddText("2.8 fb^{-1} (13 TeV)"); tText1->SetTextSize(0.04); tText1->Draw(); //========================================================== TPaveText* tText2 = new TPaveText(0.85, 0.86, 0.88, 0.87, "brNDC"); tText2->SetBorderSize(0); tText2->SetFillColor(0); tText2->SetFillStyle(0); TText *t1 = tText2->AddText("CMS"); tText2->SetTextSize(0.04); tText2->Draw(); //========================================================== TPaveText* tText3 = new TPaveText(0.80, 0.81, 0.85, 0.83, "brNDC"); tText3->SetBorderSize(0); tText3->SetFillColor(0); tText3->SetFillStyle(0); TText *t1 = tText3->AddText("#it{Preliminary}"); tText3->SetTextSize(0.04); tText3->Draw(); //--------------------------------------------------------------------- //--------------------------------------------------------------------- //=================================================================================== c1->Print("Stack-DY-Spring15MCs-Data2015-mass-spectrum-MuMu-OS-2800pb_logx.png","png"); c1->Print("Stack-DY-Spring15MCs-Data2015-mass-spectrum-MuMu-OS-2673pb_logx.pdf","pdf"); //========================================================================= //========================================================================= //========================================================================= //========================================================================= //========================================================================= //========================================================================= TCanvas *c2 = new TCanvas("c2", "c2",800,500); TPad* spectrumPad=0; TPad* ratioPad=0; // Build the histo with constant log bin width const int NMBINS = 100; const double MMIN = 60., MMAX = 3000.; double logMbins[NMBINS+1]; float binNormNr=0.; for (int ibin = 0; ibin <= NMBINS; ibin++) { logMbins[ibin] = exp(log(MMIN) + (log(MMAX)-log(MMIN))*ibin/NMBINS); cout << logMbins[ibin] << endl; } TH1* hTTbarDiboson = new TH1F("hTTbarDiboson","",NMBINS, logMbins); TH1* hDijetWjets = new TH1F("hDijetWjets","",NMBINS, logMbins); TH1* ttbarHist = new TH1F("ttbarHist","",NMBINS, logMbins); TH1* dibosonsBkgHist = new TH1F("dibosonsBkgHist","",NMBINS, logMbins); TH1F* hDivideHisto2 = new TH1F("hDivideHisto2","",150,0.0,3000.0); //TH1F* hMass1 = new TH1F("hMass1","",150,0.0,3000.0); //TH1F* hMass2 = new TH1F("hMass2","",150,0.0,3000.0); //TH1F* hMass3 = new TH1F("hMass3","",150,0.0,3000.0); //TH1F* hMass5 = new TH1F("hMass5","",150,0.0,3000.0); //TH1F* hMass6 = new TH1F("hMass6","",150,0.0,3000.0); //TH1F* AllEKWbkg = new TH1F("AllEKWbkg","",150,0.0,3000.0); gStyle->SetOptFit(1111); gStyle->SetOptStat(0); gStyle->SetStatX(0.457589); gStyle->SetStatY(0.312937); gStyle->SetStatW(0.29241/2+0.0185); gStyle->SetStatH(0.169580+0.05); gStyle->SetStatFontSize(0.0402098); gStyle->SetStatFont(0.03); gStyle->SetFitFormat("5.2g"); gStyle->SetStatBorderSize(0); gStyle->SetStatFontSize(0.040209); gStyle->SetStatFontSize(0.035209); c2->Range(1.592761,-5.173913,3.533814,6.006211); c2->SetFillColor(0); c2->SetBorderMode(0); c2->SetBorderSize(2); c2->SetLogx(1); c2->SetLogy(1); c2->SetTickx(1); c2->SetTicky(1); c2->SetLeftMargin(0.13); c2->SetRightMargin(0.07); c2->SetFrameBorderMode(0); c2->SetFrameBorderMode(0); c2->SetTopMargin(0.085); c2->SetBottomMargin(0.11); //========================================================== // // Get the histograms //========================================================== //TFile *file1 = new TFile("h_ZprimeRecomass_DYBinWidth.root","READ"); //TH1* zeeHist = (TH1*) file1->Get("ZprimeRecomassBinWidth"); TFile *file1 = new TFile("DY-MuMu-MC-OS-allbins-MC-2673pb.root","READ"); TH1* zeeHist = (TH1*) file1->Get("hMassDYAll6"); TFile *file2 = new TFile("h_ZprimeRecomass_Tlike.root","READ"); TH1* ttbarHist = (TH1*) file2->Get("ZprimeRecomassBinWidth"); TFile *file3 = new TFile("h_ZprimeRecomass_DiBoson.root","READ"); TH1* dibosonsBkgHist = (TH1*) file3->Get("ZprimeRecomassBinWidth"); TFile *file4 = new TFile("h_ZprimeRecomass_data.root","READ"); TH1* dataHistTempbar = (TH1*) file4->Get("ZprimeRecomassBinWidth"); TFile *file5 = new TFile("FR-DiJets-Data-OS-BinWidth-2673pb.root","READ"); TH1* jetBkgHist = (TH1*) file5->Get("DataSub"); TFile *file6 = new TFile("FR-Wjets-25nsMC-OS-BinWidth-2673pb.root","READ"); TH1* WjetsBkgHist = (TH1*) file6->Get("WjetsHisto"); std::cout<<"nbQCD(dijets,Data) = "<<jetBkgHist->Integral()<<endl; std::cout<<"nb.Wjets(MC) = "<<WjetsBkgHist->Integral()<<endl; hTTbarDiboson->Add(ttbarHist,dibosonsBkgHist,1,1); hDijetWjets->Add(jetBkgHist,WjetsBkgHist,1,1); //zeeHist->Rebin(value); //hTTbarDiboson->Rebin(value); //dibosonsBkgHist->Rebin(value); //dataHistTempbar->Rebin(value); //hDijetWjets->Rebin(value); //WjetsBkgHist->Rebin(value); float binWidthNorm2=-1; int zeeColour = TColor::GetColor("#99ccff"); int jetBkgColour = TColor::GetColor("#ffff66"); int ttbarColour = TColor::GetColor("#ff6666"); int bosonColour = TColor::GetColorDark(3); int WjetsColour = TColor::GetColorDark(5); int font = 42; float xAxisMin = 60; //72 float xAxisMax = 1000.0; float yAxisMin = 1e-4; float yAxisMax = 1e4; dataHistTempbar = makeIntHist(dataHistTempbar); zeeHist = makeIntHist(zeeHist); hTTbarDiboson = makeIntHist(hTTbarDiboson); hDijetWjets = makeIntHist(hDijetWjets); TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm2,0); THStack *axisHist2 = new THStack("axisHist2",""); zeeHist->SetFillColor(zeeColour); zeeHist->SetLineWidth(2); zeeHist->SetLineColor(1); zeeHist->SetTitle(""); hTTbarDiboson->SetFillColor(ttbarColour); hTTbarDiboson->SetLineWidth(2); hTTbarDiboson->SetLineColor(1); //dibosonsBkgHist->SetFillColor(bosonColour); //dibosonsBkgHist->SetLineWidth(2); //dibosonsBkgHist->SetLineColor(1); hDijetWjets->SetFillColor(jetBkgColour); hDijetWjets->SetLineWidth(2); hDijetWjets->SetLineColor(1); //WjetsBkgHist->SetFillColor(WjetsColour); //WjetsBkgHist->SetLineWidth(2); //WjetsBkgHist->SetLineColor(1); axisHist2->Add(hDijetWjets,"histo"); //axisHist2->Add(WjetsBkgHist,"histo"); //axisHist2->Add(dibosonsBkgHist,"histo"); axisHist2->Add(hTTbarDiboson,"histo"); axisHist2->Add(zeeHist,"histo"); axisHist2->Draw(); axisHist2->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]"); axisHist2->GetYaxis()->SetTitle("Events #geq M(#mu^{+}#mu^{-}) [GeV]"); axisHist2->GetXaxis()->SetTitleOffset(1.1); axisHist2->GetYaxis()->SetTitleOffset(1.1); axisHist2->GetXaxis()->SetTitleSize(0.047); axisHist2->GetYaxis()->SetTitleSize(0.047); axisHist2->GetXaxis()->SetLabelSize(0.040); axisHist2->GetYaxis()->SetLabelSize(0.040); axisHist2->GetXaxis()->SetMoreLogLabels(); axisHist2->GetXaxis()->SetNoExponent(); axisHist2->GetXaxis()->SetRangeUser(70.0,4000.0); axisHist2->SetMinimum(0.01); axisHist2->SetMaximum(60000.0); dataHist->SetMarkerStyle(20); dataHist->SetMarkerSize(0.9); dataHist->Draw("PZsames"); //========================================================== TLegend *leg = new TLegend(0.56741,0.62671,0.820536,0.87664,NULL,"brNDC"); //for lumi in plot leg->AddEntry(dataHist,"Data","PE"); leg->AddEntry(zeeHist,"#gamma^{*}/Z#rightarrow#mu^{+}#mu^{-}","F"); leg->AddEntry(hTTbarDiboson,"t#bar{t}, tW, WW, WZ, ZZ, #tau^{+}#tau^{-}","F"); leg->AddEntry(hDijetWjets,"Jets (data)","F"); leg->SetBorderSize(0); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(19); leg->SetFillStyle(0); leg->SetTextFont(font); leg->SetTextSize(0.04); leg->Draw(); //========================================================== TPaveText* tText1 = new TPaveText(0.75, 0.92, 0.87, 0.98, "brNDC"); tText1->SetBorderSize(0); tText1->SetFillColor(0); tText1->SetFillStyle(0); TText *t1 = tText1->AddText("2.8 fb^{-1} (13 TeV)"); tText1->SetTextSize(0.04); tText1->Draw(); //========================================================== TPaveText* tText2 = new TPaveText(0.85, 0.86, 0.88, 0.87, "brNDC"); tText2->SetBorderSize(0); tText2->SetFillColor(0); tText2->SetFillStyle(0); TText *t1 = tText2->AddText("CMS"); tText2->SetTextSize(0.04); tText2->Draw(); //========================================================== TPaveText* tText3 = new TPaveText(0.80, 0.81, 0.85, 0.83, "brNDC"); tText3->SetBorderSize(0); tText3->SetFillColor(0); tText3->SetFillStyle(0); TText *t1 = tText3->AddText("#it{Preliminary}"); tText3->SetTextSize(0.04); tText3->Draw(); //=================================================================================== //=================================================================================== c2->Print("Stack-DY-Spring15MCs-Data2015-cumulative-spectrum-MuMu-OS-2800pb-logx.png","png"); //c2->Print("Stack-DY-Spring15MCs-Data2015-cumulative-spectrum-MuMu-OS-2673pb-logx.pdf","pdf"); }
void TSelectionClass::saveHistos() { cout<<"save Histo: "<<hFiducialCutSilicon->GetTitle()<<endl; TString name = hFiducialCutSilicon->GetName(); name.Insert(0,"c"); TCanvas *c1= fiducialCuts->getAllFiducialCutsCanvas(hFiducialCutSilicon); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1 = 0; delete hFiducialCutSilicon; name = hFiducialCutSiliconDiamondHit->GetName(); name.Insert(0,"c"); c1 = fiducialCuts->getAllFiducialCutsCanvas(hFiducialCutSiliconDiamondHit,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete hFiducialCutSiliconDiamondHit; name = "c"; name.Append(hFiducialCutSiliconOneAndOnlyOneDiamondHit->GetName()); c1= fiducialCuts->getAllFiducialCutsCanvas(hFiducialCutSiliconOneAndOnlyOneDiamondHit,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete hFiducialCutSiliconOneAndOnlyOneDiamondHit; name = "c"; name.Append(hSelectedEvents->GetName()); c1 = fiducialCuts->getAllFiducialCutsCanvas(hSelectedEvents,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete hSelectedEvents; map<Int_t,TH2F*>::iterator it; for (it = mapFiducialCutSiliconDiamondHitSamePattern.begin(); it!=mapFiducialCutSiliconDiamondHitSamePattern.end(); it++){ TH2F* histo = (*it).second; name = histo->GetName(); name.Replace(0,1,"c"); c1 = fiducialCuts->getAllFiducialCutsCanvas(histo,true); c1->SetName(name); histSaver->SaveCanvas(c1); delete c1; c1=0; delete histo; } hAnalysisFraction->Scale(.1); hAnalysisFraction->SetStats(false); // hAnalysisFraction->GetYaxis()->SetRangeUser(0,100); histSaver->SaveHistogram(hAnalysisFraction); delete hAnalysisFraction; histSaver->SaveHistogram(hDiamondPatternFiducialPattern); histSaver->SaveHistogram(hDiamondPatternFiducialPatternNoMapping); name = "stackPatternMapping"; hDiamondPatternFiducialPattern->SetLineColor(kGreen); hDiamondPatternFiducialPatternNoMapping->SetLineColor(kRed); THStack *stack = new THStack(name,name); stack->Add(hDiamondPatternFiducialPattern); stack->Add(hDiamondPatternFiducialPatternNoMapping); stack->Draw(); if(stack->GetXaxis()) stack->GetXaxis()->SetTitle("pattern no."); if(stack->GetYaxis()) stack->GetYaxis()->SetTitle("number of entries #"); histSaver->SaveStack(stack,"hist",true); if(stack) delete stack; histSaver->SaveHistogram(pDiamondPatternFiducialPatternProfile); if(hDiamondPatternFiducialPatternNoMapping) delete hDiamondPatternFiducialPatternNoMapping; if(hDiamondPatternFiducialPattern) delete hDiamondPatternFiducialPattern; if (pDiamondPatternFiducialPatternProfile) delete pDiamondPatternFiducialPatternProfile; }
void limit() { //This program demonstrates the computation of 95 % C.L. limits. //It uses a set of randomly created histograms. // //Author: [email protected] on 21.08.02 // Create a new canvas. TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500); c1->SetFillColor(42); // Create some histograms TH1D* background = new TH1D("background","The expected background",30,-4,4); TH1D* signal = new TH1D("signal","the expected signal",30,-4,4); TH1D* data = new TH1D("data","some fake data points",30,-4,4); background->SetFillColor(48); signal->SetFillColor(41); data->SetMarkerStyle(21); data->SetMarkerColor(kBlue); background->Sumw2(); // needed for stat uncertainty signal->Sumw2(); // needed for stat uncertainty // Fill histograms randomly TRandom2 r; Float_t bg,sig,dt; for (Int_t i = 0; i < 25000; i++) { bg = r.Gaus(0,1); sig = r.Gaus(1,.2); background->Fill(bg,0.02); signal->Fill(sig,0.001); } for (Int_t i = 0; i < 500; i++) { dt = r.Gaus(0,1); data->Fill(dt); } THStack *hs = new THStack("hs","Signal and background compared to data..."); hs->Add(background); hs->Add(signal); hs->Draw("hist"); data->Draw("PE1,Same"); c1->Modified(); c1->Update(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(6); c1->GetFrame()->SetBorderMode(-1); c1->Modified(); c1->Update(); gSystem->ProcessEvents(); // Compute the limits cout << "Computing limits... " << endl; TLimitDataSource* mydatasource = new TLimitDataSource(signal,background,data); TConfidenceLevel *myconfidence = TLimit::ComputeLimit(mydatasource,50000); cout << "CLs : " << myconfidence->CLs() << endl; cout << "CLsb : " << myconfidence->CLsb() << endl; cout << "CLb : " << myconfidence->CLb() << endl; cout << "< CLs > : " << myconfidence->GetExpectedCLs_b() << endl; cout << "< CLsb > : " << myconfidence->GetExpectedCLsb_b() << endl; cout << "< CLb > : " << myconfidence->GetExpectedCLb_b() << endl; // Add stat uncertainty cout << endl << "Computing limits with stat systematics... " << endl; TConfidenceLevel *mystatconfidence = TLimit::ComputeLimit(mydatasource,50000,true); cout << "CLs : " << mystatconfidence->CLs() << endl; cout << "CLsb : " << mystatconfidence->CLsb() << endl; cout << "CLb : " << mystatconfidence->CLb() << endl; cout << "< CLs > : " << mystatconfidence->GetExpectedCLs_b() << endl; cout << "< CLsb > : " << mystatconfidence->GetExpectedCLsb_b() << endl; cout << "< CLb > : " << mystatconfidence->GetExpectedCLb_b() << endl; // Add some systematics cout << endl << "Computing limits with systematics... " << endl; TVectorD errorb(2); TVectorD errors(2); TObjArray* names = new TObjArray(); TObjString name1("bg uncertainty"); TObjString name2("sig uncertainty"); names->AddLast(&name1); names->AddLast(&name2); errorb[0]=0.05; // error source 1: 5% errorb[1]=0; // error source 2: 0% errors[0]=0; // error source 1: 0% errors[1]=0.01; // error source 2: 1% TLimitDataSource* mynewdatasource = new TLimitDataSource(); mynewdatasource->AddChannel(signal,background,data,&errors,&errorb,names); TConfidenceLevel *mynewconfidence = TLimit::ComputeLimit(mynewdatasource,50000,true); cout << "CLs : " << mynewconfidence->CLs() << endl; cout << "CLsb : " << mynewconfidence->CLsb() << endl; cout << "CLb : " << mynewconfidence->CLb() << endl; cout << "< CLs > : " << mynewconfidence->GetExpectedCLs_b() << endl; cout << "< CLsb > : " << mynewconfidence->GetExpectedCLsb_b() << endl; cout << "< CLb > : " << mynewconfidence->GetExpectedCLb_b() << endl; // show canonical -2lnQ plots in a new canvas // - The histogram of -2lnQ for background hypothesis (full) // - The histogram of -2lnQ for signal and background hypothesis (dashed) TCanvas *c2 = new TCanvas("c2"); myconfidence->Draw(); // clean up (except histograms and canvas) delete myconfidence; delete mydatasource; delete mystatconfidence; delete mynewconfidence; delete mynewdatasource; }
void msquared() { double yPos, xPos, theta, energy = 0.; // NOTE: theta comes in degrees int numHit, pID = 0; // Initialize histograms double nEnergyMin = 10; // MeV double nEnergyMax = 510; // MeV int nEnergyBins = 50; double dEnergyBinSize = (double)(nEnergyMax - nEnergyMin) / (double)nEnergyBins; double nThetaMin = 34; // mrad double nThetaMax = 88; // mrad int nThetaBins = 50; double dThetaBinSize = (nThetaMax - nThetaMin) / nThetaBins; double nM2Min = -5000; // MeV double nM2Max = 5000; // MeV int nM2Bins = 100; double dM2BinSize = (nM2Max - nM2Min)/nM2Bins; THStack *hs = new THStack("hs","Stacked M^2"); TFile* file = new TFile("e+e-2yyGUN.root"); TTree* Hits_Info = (TTree *)file->Get("Signal"); Hits_Info->SetBranchAddress("numHits", &numHit); Hits_Info->SetBranchAddress("energyTot", &energy); Hits_Info->SetBranchAddress("XPosition", &xPos); Hits_Info->SetBranchAddress("YPosition", &yPos); Hits_Info->SetBranchAddress("Particle_ID", &pID); Hits_Info->SetBranchAddress("Theta", &theta); TH1D* hmyy = new TH1D("M_{A'}^{2}" , // plot label "e+e- > yy", // title nM2Bins, // x number of bins nM2Min, // x lower bound nM2Max); // x upper bound // go through all entries and fill the histograms int nentries = Hits_Info->GetEntries(); for (int i=0; i<nentries; i++) { Hits_Info->GetEntry(i); if (pID == 22) { // gammas only theta*= TMath::Pi()/180; //radians cout << "M^2 is: " << mSquared(energy, theta) << endl; cout << "Energy is: " << energy << endl; hmyy->Fill(mSquared(energy, theta), XSECyy * BINNING_WEIGHT / dM2BinSize); } } cout << "DM2binsize is:" << dM2BinSize << endl; hmyy->SetFillColor(kBlue); hmyy->SetFillStyle(3001); hmyy->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hmyy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hmyy->GetXaxis()->CenterTitle(); hmyy->GetYaxis()->CenterTitle(); TFile* fileyyy = new TFile("e+e-2yyyGUN.root"); TTree* Hits_Infoyyy = (TTree *)fileyyy->Get("Signal"); Hits_Infoyyy->SetBranchAddress("numHits", &numHit); Hits_Infoyyy->SetBranchAddress("energyTot", &energy); Hits_Infoyyy->SetBranchAddress("XPosition", &xPos); Hits_Infoyyy->SetBranchAddress("YPosition", &yPos); Hits_Infoyyy->SetBranchAddress("Particle_ID", &pID); Hits_Infoyyy->SetBranchAddress("Theta", &theta); TH1D* hmyyy = new TH1D("M_{A'}^{2}" , // plot label "e+e- > yyy", // title nM2Bins, // x number of bins nM2Min, // x lower bound nM2Max); // x upper bound // go through all entries and fill the histograms nentries = Hits_Infoyyy->GetEntries(); for (int i=0; i<nentries; i++) { Hits_Infoyyy->GetEntry(i); if (pID == 22) { // gammas only theta*= TMath::Pi()/180; //radians cout << "M^2 is: " << mSquared(energy, theta) << endl; cout << "Energy is: " << energy << endl; hmyyy->Fill(mSquared(energy, theta), XSECyyy * BINNING_WEIGHT / dM2BinSize); } } cout << "DM2binsize is:" << dM2BinSize << endl; hmyyy->SetFillColor(kRed); hmyyy->SetFillStyle(3001); hmyyy->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hmyyy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hmyyy->GetXaxis()->CenterTitle(); hmyyy->GetYaxis()->CenterTitle(); TFile* fileepluseminusy = new TFile("e+e-2e+e-yECUT0.3NOPT_2_5_1000000.root"); //This is 1000000 events so DOWNEIGHT IT: XSECepluseminusy = 0.1 * XSECepluseminusy; TTree* Hits_Infoepluseminusy = (TTree *)fileepluseminusy->Get("Signal"); Hits_Infoepluseminusy->SetBranchAddress("numHits", &numHit); Hits_Infoepluseminusy->SetBranchAddress("energyTot", &energy); Hits_Infoepluseminusy->SetBranchAddress("XPosition", &xPos); Hits_Infoepluseminusy->SetBranchAddress("YPosition", &yPos); Hits_Infoepluseminusy->SetBranchAddress("Particle_ID", &pID); Hits_Infoepluseminusy->SetBranchAddress("Theta", &theta); TH1D* hmepluseminusy = new TH1D("M_{A'}^{2}" , // plot label "e+e- > e+e-y (only registering gammas)", // title nM2Bins, // x number of bins nM2Min, // x lower bound nM2Max); // x upper bound // go through all entries and fill the histograms nentries = Hits_Infoepluseminusy->GetEntries(); for (int i=0; i<nentries; i++) { Hits_Infoepluseminusy->GetEntry(i); if (pID == 22) { // gammas only theta*= TMath::Pi()/180; //radians cout << "M^2 is: " << mSquared(energy, theta) << endl; cout << "Energy is: " << energy << endl; hmepluseminusy->Fill(mSquared(energy, theta), XSECepluseminusy * BINNING_WEIGHT / dM2BinSize); } } cout << "DM2binsize is:" << dM2BinSize << endl; hmepluseminusy->SetFillColor(7); hmepluseminusy->SetFillStyle(3001); hmepluseminusy->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hmepluseminusy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hmepluseminusy->GetXaxis()->CenterTitle(); hmepluseminusy->GetYaxis()->CenterTitle(); //ADD YIMIN'S PLOT TFile *f = new TFile("YIMINPLOTBREM.root"); f->ls(); TH1F * hYIMIN = (TH1F*)f->Get("M^2"); hYIMIN->SetFillColor(kOrange); hYIMIN->SetTitle("Bremsstrahlung"); hYIMIN->SetFillStyle(3001); hYIMIN->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hYIMIN->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hYIMIN->GetXaxis()->CenterTitle(); hYIMIN->GetYaxis()->CenterTitle(); /********************** ADD BRIANS PLOT ********************/ NUM_TOT_POSITRONS = 1e+07; BIAS = 1e+04; BINNING_WEIGHT = POSITRONS_PER_SEC/(BIAS*NUM_TOT_POSITRONS); B = pow(1-pow(GAMMA_PLUS, -2.), .5); TFile* fileinelastic = new TFile("brian_1e7_pos_1e4_bias.root"); TTree* Hits_Infoinelastic = (TTree *)fileinelastic->Get("Signal"); Hits_Infoinelastic->SetBranchAddress("numHits", &numHit); Hits_Infoinelastic->SetBranchAddress("energyTot", &energy); Hits_Infoinelastic->SetBranchAddress("XPosition", &xPos); Hits_Infoinelastic->SetBranchAddress("YPosition", &yPos); Hits_Infoinelastic->SetBranchAddress("Particle_ID", &pID); Hits_Infoinelastic->SetBranchAddress("Theta", &theta); TH1D* hminelastic = new TH1D("M_{A'}^{2}" , // plot label "Inelastic (only registering gammas)", // title nM2Bins, // x number of bins nM2Min, // x lower bound nM2Max); // x upper bound // go through all entries and fill the histograms nentries = Hits_Infoinelastic->GetEntries(); for (int i=0; i<nentries; i++) { Hits_Infoinelastic->GetEntry(i); if (pID == 22) { // gammas only theta*= TMath::Pi()/180; //radians cout << "M^2 is: " << mSquared(energy, theta) << endl; cout << "Energy is: " << energy << endl; hminelastic->Fill(mSquared(energy, theta), BINNING_WEIGHT / dM2BinSize); } } cout << "DM2binsize is:" << dM2BinSize << endl; hminelastic->SetFillColor(kGreen); hminelastic->SetFillStyle(3001); hminelastic->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hminelastic->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hminelastic->GetXaxis()->CenterTitle(); hminelastic->GetYaxis()->CenterTitle(); hs->Add(hminelastic); hs->Add(hYIMIN); hs->Add(hmyyy); hs->Add(hmepluseminusy); hs->Add(hmyy); // create canvas and draw histogram TCanvas* canvas = new TCanvas("canvas", "canvas", 700, 700); canvas->Divide(3,2); TPad* p; p = (TPad*)canvas->cd(1); //p->SetGrid(); p->SetLogy(); hs->Draw(); hs->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hs->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hs->GetXaxis()->CenterTitle(); hs->GetYaxis()->CenterTitle(); p = (TPad*)canvas->cd(4); hmepluseminusy->Draw(); p = (TPad*)canvas->cd(3); hmyyy->Draw(); p = (TPad*)canvas->cd(2); hmyy->Draw(); p = (TPad*)canvas->cd(5); hYIMIN->Draw(); p = (TPad*)canvas->cd(6); hminelastic->Draw(); /* p = (TPad*)canvas->cd(4); p->SetLogy(); p->SetGrid(); hm2->Draw();*/ }
void fakeStudyMu( TCut Cuts_ = "ptL1>0", TString variable_ = "MtLeg1", TString XTitle_ = "M_{T}(#mu,MET)", TString Unities_ = "GeV", Int_t nBins_ = 12, Float_t xMin_=0, Float_t xMax_=120, Float_t magnifySgn_ = 10, Float_t hltEff_ = 1.0, Int_t enableHLTmatching_ = 1, Int_t logy_ = 0 ) { float Lumi = 24.86+159.15; TCanvas *c1 = new TCanvas("c1","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); c1->SetLogy(logy_); TLegend* leg = new TLegend(0.60,0.50,0.85,0.85,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.04); leg->SetHeader("#mu+#tau_{had}"); THStack* aStack = new THStack("aStack",Form("CMS Preliminary 2011 #sqrt{s}=7 TeV L=%.0f pb^{-1}", Lumi )); TH1F* hSiml = new TH1F(); TH1F* hSgn = new TH1F(); TH1F* hSgn1 = new TH1F(); TH1F* hSgn2 = new TH1F(); TH1F* hData = new TH1F(); // OpenNTuples TString fDataName = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleRun2011-Mu_Open_MuTauStream.root"; TString fSignalNameVBF = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleVBFH115-Mu-powheg-PUS1_Open_MuTauStream.root"; TString fSignalNameGGH = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleGGFH115-Mu-powheg-PUS1_Open_MuTauStream.root"; TString fBackgroundNameDYTauTau = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameDYMuMu = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameWJets = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleWJets-Mu-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameQCD = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleQCDmu_Open_MuTauStream.root"; TString fBackgroundNameTTbar = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleTTJets-Mu-madgraph-PUS1_Open_MuTauStream.root"; TString fBackgroundNameSingleTop = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleSingleTop-Mu_Open_MuTauStream.root"; TString fBackgroundNameDiBoson = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDiBoson-Mu_Open_MuTauStream.root"; TFile *fData(0); TFile *fSignalVBF(0); TFile *fSignalGGH(0); TFile *fBackgroundDYTauTau(0); TFile *fBackgroundDYMuMu(0); TFile *fBackgroundWJets(0); TFile *fBackgroundQCD(0); TFile *fBackgroundTTbar(0); TFile *fBackgroundSingleTop(0); TFile *fBackgroundDiBoson(0); fData = TFile::Open( fDataName ); fSignalVBF = TFile::Open( fSignalNameVBF ); fSignalGGH = TFile::Open( fSignalNameGGH ); fBackgroundDYTauTau = TFile::Open( fBackgroundNameDYTauTau ); fBackgroundDYMuMu = TFile::Open( fBackgroundNameDYMuMu ); fBackgroundWJets = TFile::Open( fBackgroundNameWJets ); fBackgroundQCD = TFile::Open( fBackgroundNameQCD ); fBackgroundTTbar = TFile::Open( fBackgroundNameTTbar ); fBackgroundSingleTop= TFile::Open( fBackgroundNameSingleTop ); fBackgroundDiBoson = TFile::Open( fBackgroundNameDiBoson ); if(!fSignalVBF || !fBackgroundDYTauTau || !fBackgroundWJets || !fBackgroundQCD || !fBackgroundTTbar || !fBackgroundSingleTop || !fSignalGGH || !fBackgroundDYMuMu || !fBackgroundDiBoson || !fData){ std::cout << "ERROR: could not open files" << std::endl; exit(1); } TString tree = "outTreePtOrd"; TTree *data = (TTree*)fData->Get(tree); TTree *signalVBF = (TTree*)fSignalVBF->Get(tree); TTree *signalGGH = (TTree*)fSignalGGH->Get(tree); TFile* dummy1 = new TFile("dummy1.root","RECREATE"); TTree *backgroundDYTauTau = ((TTree*)fBackgroundDYTauTau->Get(tree))->CopyTree("isTauLegMatched>0.5"); TTree *backgroundDYMuMu = ((TTree*)fBackgroundDYMuMu->Get(tree))->CopyTree("isTauLegMatched<0.5"); cout <<backgroundDYTauTau->GetEntries() << " -- " << backgroundDYMuMu->GetEntries() << endl; TTree *backgroundWJets = (TTree*)fBackgroundWJets->Get(tree); TTree *backgroundQCD = (TTree*)fBackgroundQCD->Get(tree); TTree *backgroundTTbar = (TTree*)fBackgroundTTbar->Get(tree); TTree *backgroundSingleTop = (TTree*)fBackgroundSingleTop->Get(tree); TTree *backgroundDiBoson = (TTree*)fBackgroundDiBoson->Get(tree); // here I choose the order in the stack std::vector<string> samples; samples.push_back("ggH115"); samples.push_back("qqH115"); samples.push_back("DiBoson"); samples.push_back("SingleTop"); samples.push_back("TTbar"); samples.push_back("Wjets"); samples.push_back("QCD"); samples.push_back("ZfakeTau"); samples.push_back("Ztautau"); samples.push_back("Data"); // here I define the map between a sample name and its tree std::map<std::string,TTree*> tMap; tMap["Data"]=data; tMap["ggH115"]=signalGGH; tMap["qqH115"]=signalVBF; tMap["Ztautau"]=backgroundDYTauTau; tMap["ZfakeTau"]=backgroundDYMuMu; tMap["Wjets"]=backgroundWJets; tMap["QCD"]=backgroundQCD; tMap["TTbar"]=backgroundTTbar; tMap["SingleTop"]=backgroundSingleTop; tMap["DiBoson"]=backgroundDiBoson; Float_t pt1, pt2, Deta, Mjj, eta1, eta2; Float_t diTauSVFitPt,diTauVisPt,diTauVisEta,diTauSVFitEta,diTauVisMass,diTauSVFitMass,ptL1,ptL2,etaL1,etaL2,diTauCharge,MtLeg1,numPV,combRelIsoLeg1DBeta,combRelIsoLeg1,pZetaCutVar, MEt, ptVeto, leadTrackPt, jetsBtagHE1, jetsBtagHE2; Float_t sampleWeight,puWeight; std::map<TString,Float_t> vMap; for( unsigned iter=0; iter<samples.size(); iter++){ std::map<std::string,TTree*>::iterator it = tMap.find(samples[iter]); TString h1Name = "h1_"+it->first; TH1F* h1 = new TH1F( h1Name ,Form("CMS Preliminary 2011 #sqrt{s}=7 TeV L=%.0f pb^{-1}", Lumi) , nBins_ ,xMin_ , xMax_); TFile* dummy = new TFile("dummy.root","RECREATE"); TCut Cuts = Cuts_; TCut hlt = enableHLTmatching_ ? "( ((HLTmatch==2 && run<=163261) || (HLTmatch==1 && run>163261)) && ((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261)) )" : "( ((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261)) )"; if((it->first).find("Data")!=string::npos) Cuts = Cuts_ && hlt; TTree* currentTree = (TTree*)(it->second)->CopyTree(Cuts); Int_t counter = 0; currentTree->SetBranchAddress( "pt1", &pt1 ); currentTree->SetBranchAddress( "pt2", &pt2 ); currentTree->SetBranchAddress( "Deta",&Deta ); currentTree->SetBranchAddress( "Mjj", &Mjj ); currentTree->SetBranchAddress( "diTauSVFitPt",&diTauSVFitPt); currentTree->SetBranchAddress( "diTauSVFitEta",&diTauSVFitEta); currentTree->SetBranchAddress( "diTauSVFitMass",&diTauSVFitMass); currentTree->SetBranchAddress( "diTauVisPt",&diTauVisPt); currentTree->SetBranchAddress( "diTauVisEta",&diTauVisEta); currentTree->SetBranchAddress( "diTauVisMass",&diTauVisMass); currentTree->SetBranchAddress( "ptL1", &ptL1 ); currentTree->SetBranchAddress( "ptL2", &ptL2 ); currentTree->SetBranchAddress( "etaL1", &etaL1 ); currentTree->SetBranchAddress( "etaL2", &etaL2 ); currentTree->SetBranchAddress( "combRelIsoLeg1DBeta",&combRelIsoLeg1DBeta); currentTree->SetBranchAddress( "combRelIsoLeg1",&combRelIsoLeg1); currentTree->SetBranchAddress( "diTauCharge",&diTauCharge); currentTree->SetBranchAddress( "MtLeg1",&MtLeg1); currentTree->SetBranchAddress( "pZetaCutVar",&pZetaCutVar); currentTree->SetBranchAddress( "numPV",&numPV); currentTree->SetBranchAddress( "sampleWeight",&sampleWeight); currentTree->SetBranchAddress( "puWeight",&puWeight); currentTree->SetBranchAddress( "ptVeto",&ptVeto); currentTree->SetBranchAddress( "MEt",&MEt); currentTree->SetBranchAddress( "leadTrackPt",&leadTrackPt); currentTree->SetBranchAddress( "jetsBtagHE1",&jetsBtagHE1); currentTree->SetBranchAddress( "jetsBtagHE2",&jetsBtagHE2); for (Long64_t ievt=0; ievt<currentTree->GetEntries();ievt++) { currentTree->GetEntry(ievt); if (ievt%10000 == 0){ std::cout << (it->first) << " ---> processing event: " << ievt << " ..." <<std::endl; } vMap["diTauSVFitPt"] = diTauSVFitPt; vMap["diTauSVFitEta"] = diTauSVFitEta; vMap["diTauSVFitMass"]= diTauSVFitMass; vMap["diTauVisPt"] = diTauVisPt; vMap["diTauVisEta"] = diTauVisEta; vMap["diTauVisMass"] = diTauVisMass; vMap["ptL1"] = ptL1; vMap["ptL2"] = ptL2; vMap["etaL1"] = etaL1; vMap["etaL2"] = etaL2; vMap["diTauCharge"]= Float_t(diTauCharge); vMap["MtLeg1"]= MtLeg1; vMap["pZetaCutVar"] = pZetaCutVar; vMap["numPV"]= numPV; vMap["combRelIsoLeg1"]= combRelIsoLeg1; vMap["combRelIsoLeg1DBeta"]= combRelIsoLeg1DBeta; vMap["sampleWeight"]= sampleWeight; vMap["puWeight"]= puWeight; vMap["puWeight"]= puWeight; vMap["jetsBtagHE1"]= jetsBtagHE1; vMap["jetsBtagHE2"]= jetsBtagHE2; vMap["leadTrackPt"]= leadTrackPt; vMap["pt1"]= pt1; vMap["pt2"]= pt2; vMap["Deta"]= Deta; vMap["Mjj"]= Mjj; vMap["ptVeto"]= ptVeto; if((it->first).find("Data")==string::npos) sampleWeight*=(Lumi/1000*hltEff_*puWeight); counter++; h1->Fill( vMap[variable_], sampleWeight); }// end loop if( (it->first).find("ZfakeTau")!=string::npos ) { h1->SetFillColor(7); leg->AddEntry(h1,"Z+jets, fake-#tau","F"); } if( (it->first).find("Ztautau")!=string::npos ) { h1->SetFillColor(kRed); leg->AddEntry(h1,"Z+jets, genuine-#tau","F"); } if( (it->first).find("TTbar")!=string::npos ) { h1->SetFillColor(kBlue); leg->AddEntry(h1,"t#bar{t}+jets","F"); } if( (it->first).find("SingleTop")!=string::npos ) { h1->SetFillColor(29); leg->AddEntry(h1,"single-t","F"); } if( (it->first).find("Wjets")!=string::npos ) { h1->SetFillColor(kGreen); leg->AddEntry(h1,"W+jets","F"); } if( (it->first).find("DiBoson")!=string::npos ) { h1->SetFillColor(38); leg->AddEntry(h1,"Di-Boson","F"); } if( (it->first).find("QCD")!=string::npos ) { h1->SetFillColor(42); leg->AddEntry(h1,"QCD-multijets","F"); } if((it->first).find("qqH115")!=string::npos){ hSgn1 = (TH1F*)h1->Clone("hSgn1"); hSgn1->Scale(magnifySgn_); hSgn1->SetLineWidth(2); h1->SetFillColor(kBlack); h1->SetFillStyle(3004); h1->SetLineColor(kBlack); leg->AddEntry(h1,Form("VBF H(115) X %.0f",magnifySgn_),"F"); } if((it->first).find("ggH115")!=string::npos){ hSgn2 = (TH1F*)h1->Clone("hSgn2"); hSgn2->Scale(magnifySgn_); hSgn2->SetLineWidth(2); h1->SetFillColor(kBlack); h1->SetFillStyle(3005); h1->SetLineColor(kBlack); leg->AddEntry(h1,Form("GGF H(115) X %.0f",magnifySgn_),"F"); } if((it->first).find("Data")!=string::npos){ hData = (TH1F*)h1->Clone("hData"); hData->Sumw2(); hData->SetMarkerStyle(20); hData->SetMarkerSize(1.2); hData->SetMarkerColor(kBlack); hData->SetLineColor(kBlack); hData->SetXTitle(XTitle_+" ("+Unities_+")"); hData->SetYTitle(Form(" Events/(%.0f %s)", hData->GetBinWidth(1), Unities_.Data() ) ); hData->SetTitleSize(0.04,"X"); hData->SetTitleSize(0.05,"Y"); hData->SetTitleOffset(0.95,"Y"); leg->AddEntry(hData,"DATA","P"); } if(iter==0) hSiml=(TH1F*)h1->Clone("hSiml"); else if((it->first).find("Data")==string::npos) hSiml->Add(h1); if((it->first).find("Data")==string::npos) aStack->Add(h1); if(VERBOSE) cout<<(it->first) << " ==> " << h1->Integral() << " +/- " << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries()) << endl; } // all signal summed together: hSgn = (TH1F*)hSgn1->Clone("hSgn"); hSgn->Add(hSgn1,hSgn2,1,1); if(VERBOSE) cout<< "S/sqrt(B) ==> " << hSgn->Integral()/ TMath::Sqrt(hSiml->Integral()) << " +/- " << (1./2)*TMath::Sqrt(hSiml->GetEntries())*(hSiml->GetSumOfWeights())/hSiml->Integral()*( hSgn->Integral()/ TMath::Sqrt(hSiml->Integral()) ) << endl; hData->SetXTitle(XTitle_+" ("+Unities_+")"); hData->SetYTitle(Form(" Events/(%.1f %s)", hData->GetBinWidth(1), Unities_.Data() ) ); hData->SetTitleSize(0.04,"X"); hData->SetTitleSize(0.05,"Y"); hData->SetTitleOffset(0.95,"Y"); hData->Draw("P"); aStack->Draw("HISTSAME"); hData->Draw("PSAME"); //hSgn1->Draw("HISTSAME"); //hSgn2->Draw("HISTSAME"); TH1F* hStack = (TH1F*)aStack->GetHistogram(); hStack->SetXTitle(XTitle_+" ("+Unities_+")"); hStack->SetYTitle(Form(" Events/(%.0f %s)", hStack->GetBinWidth(1), Unities_.Data() ) ); hStack->SetTitleSize(0.04,"X"); hStack->SetTitleSize(0.05,"Y"); hStack->SetTitleOffset(0.95,"Y"); //aStack->GetYaxis()->SetRangeUser(0.0,std::max(hData->GetMaximum(),hStack->GetMaximum())*1.1); leg->Draw(); }
// option = 1 (muon-pt), option = 2 (transverse mass) void doPlots(int option) { //gStyle->SetFillColor(1); // interested in plot made after all cuts have been applied string final_histo_desc; if(analysis_channel == 1) final_histo_desc = mumet_cuts_desc_short[Num_mumet_cuts-1]; else if(analysis_channel == 2) final_histo_desc = elmet_cuts_desc_short[Num_elmet_cuts-1]; string prefix = ""; if(option == 1 && analysis_channel == 1) prefix = "hPT"; if(option == 1 && analysis_channel == 2) prefix = "hET"; else if(option == 2) prefix = "hTM"; TH1F ** bgdSamples = 0; const string * bgdNames = 0; unsigned NbgdSamples = 0; if(analysis_channel == 1) { bgdSamples = &bgdMuMET[0]; bgdNames = &bgdNamesMuMET[0]; NbgdSamples = NbgdSamplesMuMET; } else if(analysis_channel == 2) { bgdSamples = &bgdElMET[0]; bgdNames = &bgdNamesElMET[0]; NbgdSamples = NbgdSamplesElMET; } string histo = prefix + algo + "_" + final_histo_desc; for(unsigned i = 0; i != NbgdSamples; ++i) { string histo_i = bgdNames[i] + "/" + histo; bgdSamples[i] = (TH1F* ) _file0->Get(histo_i.c_str()); if(badHisto(bgdSamples[i], histo_i)) return; } string mass = "1.5";//W' mass string histo_wp = "wprime" + mass + "/" + histo; TH1F * wp = (TH1F* )_file0->Get(histo_wp.c_str()); if(badHisto(wp, "wprime" + mass)) return; string histo_wp_noint = "wprime" + mass + "_noint/" + histo; TH1F * wp_noint = (TH1F* )_file0->Get(histo_wp_noint.c_str()); if(badHisto(wp_noint, "wprime" + mass + "_noint")) return; string histo_wp_oppsign = "wprime" + mass + "_oppsign/" + histo; TH1F * wp_oppsign = (TH1F* )_file0->Get(histo_wp_oppsign.c_str()); if(badHisto(wp_oppsign, "wprime" + mass + "_oppsign")) return; string histo_wp_samesign = "wprime" + mass + "_samesign/" + histo; TH1F * wp_samesign = (TH1F* )_file0->Get(histo_wp_samesign.c_str()); if(badHisto(wp_samesign, "wprime" + mass + "_samesign")) return; string hname = "tot_bgd"; double xmin = -1; double xmax = -1; double xmax_ratio = -1; double xmax_cumu = -1; string title = "INVALID"; string var_plotted = "INVALID2"; char data_ipb[1024]; sprintf(data_ipb, " data (%4.1f pb^{-1})", Lumi_ipb); char lumi_value[1024]; sprintf(lumi_value, "%4.1fipb", Lumi_ipb); char lumi_value2[1024]; sprintf(lumi_value2, "%4.1f pb^{-1}", Lumi_ipb); string cms_prelim = "CMS Preliminary 2011"; char lumi_sqrts_[1024]; sprintf(lumi_sqrts_, "L_{int} = %4.1f pb^{-1}, #sqrt{s} = 7 TeV", Lumi_ipb); string lumi_sqrts = lumi_sqrts_; float x_offset = 0; int Nbins = bgdSamples[0]->GetNbinsX(); if(option == 1) { hname += "_mupt"; desc = " p_{T} distribution"; xmin = 150; xmax = 1200; title = "Muon p_{T} (GeV/c)"; var_plotted = "MuPt"; x_offset = -100; } else if(option == 2) { hname += "_TM"; string desc0 = ""; if(analysis_channel == 1) desc0 = "#mu"; else if(analysis_channel == 2) desc0 = "e"; desc = desc0 + "&ME_{T} transverse mass: 2011 data (" + string(lumi_value2) + ")"; xmin = 200; xmax = 2000; title = "M_{T} (GeV/c^{2})"; var_plotted = "TM"; } string file = var_plotted + "_" + lumi_value + ".gif"; // ============== CREATE DISTRIBUTIONS HERE ====================== // this is the total background distribution (W + QCD + top + Z/DY) TH1F * bgd = new TH1F(hname.c_str(), desc.c_str(), Nbins, bgdSamples[0]->GetXaxis()->GetXmin(), bgdSamples[0]->GetXaxis()->GetXmax()); TH1F * bgd_output = new TH1F("MT_bgd","MT_bgd",nbins_output,xmin_output,xmax_output); THStack *hsbgd =new THStack(hname.c_str(),desc.c_str());//+++++++++ for(unsigned i = 0; i != NbgdSamples; ++i){ //for(int i = NbgdSamples - 1; i != -1; i--){ if(analysis_channel == 2){ // 1, 2-4, 5-7, 8-10,11-12,13-15,16- if(i<1){bgdClr=bgdColorElMET[0];} else if(i>1 && i<5){bgdClr=bgdColorElMET[1];} else if(4<i && i<8){bgdClr=bgdColorElMET[2];} else if(7<i && i<11){bgdClr=bgdColorElMET[3];} else if(10<i && i<13){bgdClr=bgdColorElMET[4];} else if(12<i && i<16){bgdClr=bgdColorElMET[5];} else if(i>15){bgdClr=bgdColorElMET[6];} bgdSamples[i]->SetLineColor(bgdClr);bgdSamples[i]->SetFillColor(bgdClr); hsbgd->Add(bgdSamples[i]);//+++++++++ } bgd->Add(bgdSamples[i]); bgd_output->Add(bgdSamples[i]); } const int fill_style_sig = 3001; const int fill_style_bgd = 3001; bgd->SetLineColor(kAzure+1); bgd->SetFillColor(kAzure+1); bgd->SetFillStyle(fill_style_bgd); // =============== PLOT DISTRIBUTIONS HERE ======================== TCanvas * c1 = new TCanvas(); c1->SetLogy(); if(wClr && analysis_channel == 2)hsbgd->Draw("e"); else bgd->Draw("e"); wp->SetLineColor(kRed); wp_noint->SetLineColor(kRed+1); wp_oppsign->SetLineColor(kRed+2); wp_samesign->SetLineColor(kRed+3); wp->SetFillColor(kRed); wp_noint->SetFillColor(kRed+1); wp_oppsign->SetFillColor(kRed+2); wp_samesign->SetFillColor(kRed+3); wp->SetFillStyle(fill_style_sig); wp_noint->SetFillStyle(fill_style_sig); wp_oppsign->SetFillStyle(fill_style_sig); wp_samesign->SetFillStyle(fill_style_sig); wp->Draw("same"); wp_noint->Draw("same"); wp_oppsign->Draw("same"); wp_samesign->Draw("same"); TLegend * lg = new TLegend(0.52, 0.67, 0.82, 0.89); lg->SetTextSize(0.03); lg->SetBorderSize(0); lg->SetFillColor(0); lg->AddEntry(bgd, "Total bgd", "F"); string histo_entry_title = "W ' (" + mass + " TeV)"; lg->AddEntry(wp, histo_entry_title.c_str(), "F"); histo_entry_title = "W ' (" + mass + " TeV), no interference"; lg->AddEntry(wp_noint, histo_entry_title.c_str(), "F"); histo_entry_title = "W ' (" + mass + " TeV), negative interference"; lg->AddEntry(wp_oppsign, histo_entry_title.c_str(), "F"); histo_entry_title = "W ' (" + mass + " TeV), positive interference"; lg->AddEntry(wp_samesign, histo_entry_title.c_str(), "F"); lg->Draw(); c1->SaveAs(file.c_str()); TFile *bgd_output_file = new TFile("Wprime_bgd_mu.root","recreate"); bgd_output->Write(); bgd_output_file->Close(); }
void makePlot( vector<TChain*> samples , vector<string> names , char* var , char* xtitle , TCut sel , TCut weight , int nbin , float xmin , float xmax , bool printplot = false , bool logplot = true , bool stacksig = false) { const unsigned int n = samples.size(); TH1F* h[n]; TCanvas* can = new TCanvas(Form("%s_can",var),Form("%s_can",var),800,600); can->cd(); int colors[] = {kBlue-10,kGreen+2,kRed+3}; int linecolors[] = {1,2,4}; THStack* t = new THStack(Form("%s_stack",var),Form("%s_stack",var)); TH1F* bkgtot = new TH1F(); int nbkg = 0; float ymax = 0; //TLegend* leg = new TLegend(0.5,0.75,0.85,0.9); TLegend* leg = new TLegend(0.5,0.45,0.85,0.6); leg->SetFillColor(0); leg->SetBorderSize(0); //TCut nj2("njets==2"); //TCut nj2(""); char* legentry = ""; for( unsigned int i = 0 ; i < n ; i++ ){ if( TString(names.at(i)).Contains("sig") ) continue; h[i] = new TH1F(Form("hist_%s_%s",names.at(i).c_str(),var),"",nbin,xmin,xmax); //h[i]->Sumw2(); //samples.at(i)->Draw(Form("min(%s,%f)>>hist_%s_%s",var,xmax-0.0001,names.at(i).c_str(),var),(sel+nj2)*weight); samples.at(i)->Draw(Form("min(%s,%f)>>hist_%s_%s",var,xmax-0.0001,names.at(i).c_str(),var),(sel)*weight); h[i]->SetFillColor(colors[i]); cout << "Intregal " << names.at(i) << " " << h[i]->Integral() << endl; //cout << "Bin3 " << names.at(i) << " " << h[i]->GetBinContent(3) << " +/- " << h[i]->GetBinError(3) << endl; t->Add(h[i]); nbkg++; ymax += h[i]->GetMaximum(); if( TString(names.at(i)).Contains("ttbar") ) legentry = "t#bar{t}"; if( TString(names.at(i)).Contains("Vjets") ) legentry = "V+jets"; leg->AddEntry(h[i],legentry,"f"); if( i==0 ) bkgtot = (TH1F*) h[i]->Clone("bkgtot"); else bkgtot->Add(h[i]); } for( unsigned int i = 0 ; i < n ; i++ ){ if( !TString(names.at(i)).Contains("sig") ) continue; h[i] = new TH1F(Form("hist_%s_%s",names.at(i).c_str(),var),"",nbin,xmin,xmax); //h[i]->Sumw2(); samples.at(i)->Draw(Form("min(%s,%f)>>hist_%s_%s",var,xmax-0.0001,names.at(i).c_str(),var),sel*weight); cout << "Intregal " << names.at(i) << " " << h[i]->Integral() << endl; //cout << "Bin3 " << names.at(i) << " " << h[i]->GetBinContent(3) << " +/- " << h[i]->GetBinError(3) << endl; if( TString(names.at(i)).Contains("WH500GeV_sig") ) legentry = "WH signal (500,100)"; if( TString(names.at(i)).Contains("WH1TeV_sig") ) legentry = "WH signal (1000,100)"; if( TString(names.at(i)).Contains("WH2TeV_sig") ) legentry = "WH signal (2000,100)"; if( TString(names.at(i)).Contains("WH3TeV_sig") ) legentry = "WH signal (3000,100)"; leg->AddEntry(h[i],legentry,"l"); if( stacksig ) h[i]->Add(bkgtot); } if( logplot ) ymax*=10; else ymax*=1.1; TH2F* hdummy = new TH2F("hdummy","",nbin,xmin,xmax,100,1,ymax); if( logplot ) gPad->SetLogy(); hdummy->GetXaxis()->SetTitle(xtitle); hdummy->Draw(); t->Draw("same"); for( unsigned int isig = nbkg ; isig < n ; isig++ ){ //h[isig]->Scale(10); h[isig]->SetLineColor(linecolors[isig-nbkg]); h[isig]->SetLineWidth(2); h[isig]->Draw("samehist"); } //leg->Draw(); hdummy->Draw("axissame"); if( printplot ) can->Print(Form("plots/%s.pdf",var)); }
void crossXmass(int k=4){ gSystem->Load("libFWCoreFWLite.so"); gROOT->LoadMacro("tdrstyle.C"); setTDRStyle(); //gStyle->SetOptStat(0000); gStyle->SetOptFit(0011); TFile * file = new TFile("preUnfolding.root"); TFile * file_unfolded = new TFile("unfolded.root"); TFile * file_acceptance = new TFile("acceptance.root"); TFile * file_truthFinal = new TFile("truthFinal.root"); TFile * file_zprimeM1000W1 = new TFile("zprime/ZPrimeM1000W1.root"); TFile * file_zprimeM2000W1 = new TFile("zprime/ZPrimeM2000W1.root"); //truth level after reconstruction level selection TH1F * hGenDistMADGRAPH = (TH1F*) file->Get("hTruth_MadGraph"); TH1F * hGenDistPOWHEG = (TH1F*) file->Get("hTruth_Powheg"); //unfolded plot TH1F * h_unfold = (TH1F*) file_unfolded->Get("unfolded"); //acceptance TH1F * hAcceptDist = (TH1F*) file_acceptance->Get("hAccept_vsum"); TH1F * hAcceptDistFull = (TH1F*) file_acceptance->Get("hAccept_vsum_Full"); //truth level for final TH1D * hGenMADGRAPH = (TH1D*) file_truthFinal->Get("hTruthFinalMADGRAPH"); TH1D * hGenPOWHEG = (TH1D*) file_truthFinal->Get("hTruthFinalPOWHEG"); TH1D * hGenMADGRAPH_Full = (TH1D*) file_truthFinal->Get("hTruthFinalMADGRAPH_Full"); TH1D * hGenPOWHEG_Full = (TH1D*) file_truthFinal->Get("hTruthFinalPOWHEG_Full"); double lumi = 1143.22; bool printX = true; //print cross section bool norm = false; TH1F* hSigmaData = getMeasuredCrossSection(h_unfold, hAcceptDistFull,lumi,norm, true, "unfolded",false); TH1F* hSigmaTruthHisto = getTruthCrossSection(hGenDistMADGRAPH, hGenMADGRAPH_Full, lumi, norm, false, 1, printX); TH1F* hSigmazprimeM1000W1 = getTruthCrossSection(file_zprimeM1000W1, ZXsectionW1[7], "M1000W1"); TH1F* hSigmazprimeM2000W1 = getTruthCrossSection(file_zprimeM2000W1, ZXsectionW1[18], "M2000W1"); TH1F* hSigmazprime = hSigmazprimeM1000W1; TCanvas * c_Xmass = new TCanvas("c_Xmass","c_Xmass",1); c_Xmass->SetLogy(); TH1F* h_Xmass = (TH1F*)h_unfold->Clone("hSigmaData"); TH1F* h_Xmass_ttbar = (TH1F*)h_unfold->Clone("hSigmaData"); TH1F* h_Xmass_zprime = (TH1F*) h_unfold->Clone("hSigmaData"); h_Xmass->Reset(); h_Xmass_ttbar->Reset(); h_Xmass_zprime->Reset(); int nbins = h_unfold->GetNbinsX(); double total = 0; double total_ttbar = 0; double total_zprime = 0; for(int i=nbins; i >= 1 ;i--){ double sigma = hSigmaData->GetBinContent(i)*hSigmaData->GetBinWidth(i); double sigma_ttbar = hSigmaTruthHisto->GetBinContent(i)*hSigmaTruthHisto->GetBinWidth(i); double sigma_zprime = hSigmazprime->GetBinContent(i)*hSigmazprime->GetBinWidth(i); total += sigma; total_ttbar += sigma_ttbar; total_zprime += sigma_zprime; cout << hSigmazprime->GetBinContent(i)*hSigmazprime->GetBinWidth(i) << endl; h_Xmass->SetBinContent(i, total); h_Xmass_ttbar->SetBinContent(i, total_ttbar); h_Xmass_zprime->SetBinContent(i, total_zprime); } THStack *hs = new THStack("hs","zprime plus ttbar"); h_Xmass_ttbar->SetFillColor(2); h_Xmass_zprime->SetLineColor(4); h_Xmass_zprime->SetLineWidth(2); hs->Add(h_Xmass_ttbar); hs->Add(h_Xmass_zprime); hs->Draw(); hs->GetYaxis()->SetTitle("#int_{x}^{#infty} d#sigma/dm_{t#bar{t}} dm_{t#bar{t}}"); hs->GetXaxis()->SetTitle(" m_{t#bar{t}}"); h_Xmass->Draw("p same"); TLegend *l= new TLegend(); l->AddEntry(h_Xmass, "Data" ,"p"); l->AddEntry(h_Xmass_ttbar, "t#bar{t}" ,"F"); l->AddEntry(h_Xmass_zprime, "zprime" ,"L"); SetLegendStyle(l,true); l->Draw("same"); }
double etaFit(TString bin, TString valReturn, TString dir){ setTDRStyle(); bool savePlots = false; //these only need to be global is using constraints double Nwjets, Nzjets, NQCD; bool inclZ = false; bool inclW = false; if(dir == "Scale_up" || dir == "Scale_down" || dir == "Match_up" || dir == "Match_down"){ inclZ = true; inclW = true; } //choose object TString Obj = bin; int rebinFact = 1; double MinX = 0.; double MaxX = 2.6; TString Xtitle = "#left|#eta#right|_{#mu}"; //Data data = getSample("SingleMu", 1, rebinFact, Obj, "central"); //MC TH1D* tt = getSample("TTJet", lumi*225.2/6920475, rebinFact, Obj, dir); TH1D* tt_tot = getSample("TTJet", lumi*225.2/6920475, rebinFact, "Muon", dir); TH1D* wjets; //TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, Obj, dir); TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, rebinFact, Obj, dir); TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, rebinFact, Obj, dir); TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, rebinFact, Obj, dir); TH1D* zjets; //TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, Obj, dir); TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, rebinFact, Obj, dir); TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, rebinFact, Obj, dir); TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, rebinFact, Obj, dir); TH1D* qcd = getQCD(rebinFact); TH1D* qcd_mc = getSample("QCD_Pt-15to20_MuEnrichedPt5", lumi*7.022e8 * 0.0039/1722678, rebinFact, Obj, dir); TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5", lumi*2.87e8 * 0.0065/8486893, rebinFact, Obj, dir); TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5", lumi*6.609e7 * 0.0122/8928999, rebinFact, Obj, dir); TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5", lumi*8082000.0 * 0.0218/7256011, rebinFact, Obj, dir); TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5", lumi*1024000.0 * 0.0395/9030624, rebinFact, Obj, dir); TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, rebinFact, Obj, dir); TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, rebinFact, Obj, dir); TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, rebinFact, Obj, dir); TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, rebinFact, Obj, dir); TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, rebinFact, Obj, dir); TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5", lumi*0.774 * 0.1097/3807263, rebinFact, Obj, dir); qcd_mc->Add(qcd2); qcd_mc->Add(qcd3); qcd_mc->Add(qcd4); qcd_mc->Add(qcd5); qcd_mc->Add(qcd6); qcd_mc->Add(qcd7); qcd_mc->Add(qcd8); qcd_mc->Add(qcd9); qcd_mc->Add(qcd10); qcd_mc->Add(qcd11); qcd->Scale(qcd_mc->Integral()); cout << "NQCD: " << qcd_mc->Integral() << endl; TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, rebinFact, Obj, dir); TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, rebinFact, Obj, dir); TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, rebinFact, Obj, dir); TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, rebinFact, Obj, dir); TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, rebinFact, Obj, dir); TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, rebinFact, Obj, dir); //make combined top and single top template TH1D* top = (TH1D*)tt->Clone("top"); top->Add(top_t); top->Add(top_tw);top->Add(top_s); top->Add(tbar_t); top->Add(tbar_tw);top->Add(tbar_s); //sum single top into one TH1D* single_top = (TH1D*)top_t->Clone("single top"); single_top->Add(top_tw);single_top->Add(top_s); single_top->Add(tbar_t); single_top->Add(tbar_tw);single_top->Add(tbar_s); THStack *hs = new THStack("hs","test"); hs->Add(qcd); if(inclZ == true){ zjets = getSample("DYJetsToLL", lumi*5745.25/30457954, rebinFact, Obj, dir); }else{ zjets = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, Obj, dir); zjets->Add(z2jets); zjets->Add(z3jets); zjets->Add(z4jets); } if(inclW == true){ wjets = getSample("WJetsToLNu", lumi*37509/57708550, rebinFact, Obj, dir); }else{ wjets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, Obj, dir); wjets->Add(w2jets); wjets->Add(w3jets); wjets->Add(w4jets); } hs->Add(zjets); hs->Add(wjets); hs->Add(top_t); hs->Add(top_tw); hs->Add(top_s); hs->Add(tbar_t); hs->Add(tbar_tw); hs->Add(tbar_s); hs->Add(tt); //combined histo for pseudo? TH1D* allMC = (TH1D*)top->Clone("allMC"); allMC->Add(wjets); allMC->Add(zjets); allMC->Add(qcd); if(savePlots ==true){ //draw histos to files TCanvas *c1 = new TCanvas("Plot","Plot",900, 600); hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3); hs->Draw(); data->Draw("E same"); data->SetMarkerStyle(20); hs->GetXaxis()->SetLimits(MinX, MaxX); hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05); TLegend *tleg2; tleg2 = new TLegend(0.7,0.7,0.8,0.9); tleg2->SetTextSize(0.04); tleg2->SetBorderSize(0); tleg2->SetFillColor(10); tleg2->AddEntry(data , "2012 data", "lpe"); tleg2->AddEntry(tt , "t#bar{t}", "lf"); tleg2->AddEntry(top_t, "single top", "lf"); tleg2->AddEntry(wjets , "w+jets", "lf"); tleg2->AddEntry(zjets , "z+jets", "lf"); tleg2->AddEntry(qcd , "QCD", "lf"); //tleg2->AddEntry(singtEff, "single-t" , "l"); //tleg2->AddEntry(singtwEff, "single-tW" , "l"); tleg2->Draw("same"); TText* textPrelim = doPrelim(0.17,0.96); textPrelim->Draw(); TString plotName("plots/Control/Muon/"); plotName += "absEta"; plotName += "_ge2btags.pdf"; // c1->SaveAs(plotName); delete c1; } //clone and scale top_fit = (TH1D*)top->Clone("top fit"); wjets_fit = (TH1D*)wjets->Clone("wjets fit"); zjets_fit = (TH1D*)zjets->Clone("zjets fit"); qcd_fit = (TH1D*)qcd->Clone("qcd fit"); bg_fit = (TH1D*)wjets_fit->Clone("bg fit"); bg_fit->Add(zjets_fit); bg_fit->Add(qcd_fit); top_fit->Scale(1./ top_fit->Integral()); wjets_fit->Scale(1./ wjets_fit->Integral()); zjets_fit->Scale(1./ zjets_fit->Integral()); qcd_fit->Scale(1./ qcd_fit->Integral()); bg_fit->Scale(1./ bg_fit->Integral()); if(savePlots == true){ //draw histos to files TCanvas *c2 = new TCanvas("Plot","Plot",900, 600); top_fit->SetFillColor(kWhite); wjets_fit->SetFillColor(kWhite); zjets_fit->SetFillColor(kWhite); qcd_fit->SetFillColor(kWhite); bg_fit->SetFillColor(kWhite); bg_fit->SetLineColor(kBlack); top_fit->Draw(); bg_fit->Draw("same"); wjets_fit->Draw("same"); zjets_fit->Draw("same"); qcd_fit->Draw("same"); top_fit->SetAxisRange(MinX, MaxX); top_fit->GetXaxis()->SetTitle(Xtitle); top_fit->GetXaxis()->SetTitleSize(0.05); top_fit->GetYaxis()->SetTitle("Normalised Events");top_fit->GetYaxis()->SetTitleSize(0.05); TLegend *tleg3; tleg3 = new TLegend(0.65,0.7,0.8,0.9); tleg3->SetTextSize(0.04); tleg3->SetBorderSize(0); tleg3->SetFillColor(10); tleg3->AddEntry(top_fit , "signal", "l"); tleg3->AddEntry(bg_fit , "background", "l"); tleg3->AddEntry(wjets_fit , "w+jets", "l"); tleg3->AddEntry(zjets_fit , "z+jets", "l"); tleg3->AddEntry(qcd_fit , "QCD", "l"); tleg3->Draw("same"); TText* textPrelim2 = doPrelim(0.17,0.96); textPrelim2->Draw(); c2->SaveAs("plots/Fits/"+bin+"_Template.pdf"); delete c2; } int Ntotal = data->Integral(); double Nsignal = top->Integral(); Nwjets = wjets->Integral(); Nzjets = zjets->Integral(); NQCD = qcd->Integral(); // Initialize minuit, set initial values etc. of parameters. const int npar = 2; // the number of parameters TMinuit minuit(npar); minuit.SetFCN(fcn); minuit.SetPrintLevel(-1); minuit.SetErrorDef(1.); int ierflg = 0; double Nbg= wjets->Integral()+zjets->Integral()+qcd->Integral(); string parName[npar] = {"ttbar+single-top", "background"}; //background parameters double par[npar] = {top->Integral(), Nbg}; //using the MC estimation as the start values 1fb cout << "total data events: " << Ntotal << endl; for(int i=0; i<npar; i++){ //minuit.mnparm(i, parName[i], par[i],10., -1.e6, 1.e6, ierflg); minuit.mnparm(i, parName[i], par[i], 10., 0, Ntotal, ierflg); } //the following is copied from Fabian's fitting code to improve minimum, but you can comment it, it won't affect the fitting results. // 1 standard // 2 try to improve minimum (slower) double arglist[10]; arglist[0]=2; minuit.mnexcm("SET STR",arglist,1,ierflg); minuit.Migrad(); double outpar[npar], err[npar]; for (int i=0; i<npar; i++){ minuit.GetParameter(i,outpar[i],err[i]); } for (int i=0; i<top_fit->GetNbinsX() ; i++){ top_fit->SetBinContent(i+1, top_fit->GetBinContent(i+1)*outpar[0]); bg_fit->SetBinContent(i+1, wjets_fit->GetBinContent(i+1)*outpar[1]); //zjets_fit->SetBinContent(i+1, zjets_fit->GetBinContent(i+1)*outpar[2]); //qcd_fit->SetBinContent(i+1, qcd_fit->GetBinContent(i+1)*outpar[3]); } //print out the results for all templates // cout <<" \n Total number of events after the fit" << endl; // cout<<" & ttbar+single top & w+jets & z+jets & qcd "<<endl; // cout << " & " << Nsignal << " & " << Nwjets << " & " << Nzjets << " & " << NQCD <<endl; // cout<< " & "<<outpar[0]<<"+-"<<err[0]<<" & "<<outpar[1]<<"+-"<<err[1]<<" & "<<outpar[2]<<"+-"<<err[2]<<" & "<<outpar[3]<<"+-"<<err[3]<<endl; cout <<" \n Total number of events after the fit" << endl; cout<<" & ttbar+single top & w+jets & z+jets & qcd "<<endl; cout << " & " << Nsignal << " & " << Nwjets + Nzjets + NQCD <<endl; cout<< " & "<<outpar[0] << "+-" <<err[0] << " & " <<outpar[1]<<"+-"<<err[1] <<endl; if(savePlots == true){ TCanvas *c3 = new TCanvas("Plot","Plot",900, 600); THStack* sum_fit = new THStack("sum fit","stacked histograms"); //used for stack plot qcd_fit->SetFillColor(kYellow); zjets_fit->SetFillColor(kBlue); wjets_fit->SetFillColor(kGreen); top_fit->SetFillColor(kRed); //sum_fit->Add(qcd_fit); sum_fit->Add(zjets_fit); sum_fit->Add(wjets_fit); top_fit->SetLineColor(kBlack); bg_fit->SetFillColor(kGreen); sum_fit->Add(bg_fit);sum_fit->Add(top_fit); sum_fit->Draw(); data->Draw("E same"); sum_fit->GetXaxis()->SetLimits(MinX, MaxX); sum_fit->GetXaxis()->SetTitle(Xtitle); sum_fit->GetXaxis()->SetTitleSize(0.05); sum_fit->GetYaxis()->SetTitle("Number of Events");sum_fit->GetYaxis()->SetTitleSize(0.05); TLegend *tleg4; tleg4 = new TLegend(0.65,0.7,0.8,0.9); tleg4->SetTextSize(0.04); tleg4->SetBorderSize(0); tleg4->SetFillColor(10); tleg4->AddEntry(top_fit , "signal", "ef"); tleg4->AddEntry(bg_fit , "background", "ef"); tleg4->Draw("same"); TText* textPrelim3 = doPrelim(0.17,0.96); textPrelim3->Draw(); c3->SaveAs("plots/Fits/"+bin+"_Fit.pdf"); delete c3; } //cout << "cross section is: " << ((outpar[0]-single_top->Integral())/ tt_tot->Integral())*225.2 << endl; if(valReturn == "measured"){ return outpar[0]; }else if(valReturn == "measuredErr"){ return err[0]; }else if(valReturn == "bgscale"){ return (outpar[1]/Nbg); } return 0; }
void MissingMass() { Char_t* process = "21015"; Char_t* filename = Form("TA2CristinaCompton_%s.root",process); TFile *file1 = new TFile(filename); TTree *tree1 = (TTree*)file1->Get("TA2CristinaComptonTree"); gStyle->SetOptStat(1111); Int_t NPrompt, NRandom; Double_t MissingMassPrompt[2000], MissingMassRandom[2000]; Int_t TaggerChannelPrompt[2000], TaggerChannelRandom[2000]; Int_t TaggerChannelPromptPi0[2000], TaggerChannelRandomPi0[2000]; Int_t NPromptPi0, NRandomPi0; Double_t MissingMassPromptPi0[2000], MissingMassRandomPi0[2000]; Int_t NPhoton, NProton, NPi0; Double_t PhotonTheta[30]; Double_t ProtonTheta[30]; Double_t Pi0Theta[30]; tree1->SetBranchAddress("NPhoton", &NPhoton); tree1->SetBranchAddress("NProton", &NProton); tree1->SetBranchAddress("NPi0", &NPi0); tree1->SetBranchAddress("PhotonTheta", &PhotonTheta); tree1->SetBranchAddress("ProtonTheta", &ProtonTheta); tree1->SetBranchAddress("Pi0Theta", &Pi0Theta); tree1->SetBranchAddress("NPrompt", &NPrompt); tree1->SetBranchAddress("NRandom", &NRandom); tree1->SetBranchAddress("MissingMassPrompt", &MissingMassPrompt); tree1->SetBranchAddress("MissingMassRandom", &MissingMassRandom); tree1->SetBranchAddress("TaggerChannelPrompt", &TaggerChannelPrompt); tree1->SetBranchAddress("TaggerChannelRandom", &TaggerChannelRandom); tree1->SetBranchAddress("NPromptPi0", &NPromptPi0); tree1->SetBranchAddress("NRandomPi0", &NRandomPi0); tree1->SetBranchAddress("MissingMassPromptPi0", &MissingMassPromptPi0); tree1->SetBranchAddress("MissingMassRandomPi0", &MissingMassRandomPi0); tree1->SetBranchAddress("TaggerChannelPromptPi0",&TaggerChannelPromptPi0); tree1->SetBranchAddress("TaggerChannelRandomPi0",&TaggerChannelRandomPi0); TH1D *a0 = new TH1D("REAL: Compton MM Prompt", "REAL: Compton MM Prompt", 400, 900, 1300); TH1D *a1 = new TH1D("REAL: Compton MM Random", "REAL: Compton MM Random", 400, 900, 1300); TH1D *a2 = new TH1D("Compton Missing Mass", "Compton Missing Mass", 400, 900, 1300); TH1D *p0 = new TH1D("REAL: Pi0 MM Prompt", "REAL: Pi0 MM Prompt", 400, 900, 1300); TH1D *p1 = new TH1D("REAL: Pi0 MM Random", "REAL: Pi0 MM Random", 400, 900, 1300); TH1D *p2 = new TH1D("Pi0 Missing Mass", "Pi0 Missing Mass", 400, 900, 1300); Int_t nentries = (Int_t)tree1->GetEntries(); for (Int_t i=0;i<nentries;i++) { tree1->GetEntry(i); if ((NPhoton == 1) && (NProton == 1) && (NPi0 == 0)) { for (Int_t a = 0; a < NPrompt; a++) { if (TaggerChannelPrompt[a] >= 240 && TaggerChannelPrompt[a] <= 265) { a0->Fill(MissingMassPrompt[a]); } } for (Int_t a = 0; a < NRandom; a++){ if (TaggerChannelPrompt[a] >= 240 && TaggerChannelPrompt[a] <= 265) { a1->Fill(MissingMassRandom[a]); } } } if (NPi0 == 1) { for (Int_t a = 0; a < NPromptPi0; a++) { p0->Fill(MissingMassPromptPi0[a]); } for (Int_t a = 0; a < NRandomPi0; a++) { p1->Fill(MissingMassRandomPi0[a]); } } } a2->Add(a0,1); a2->Add(a1,-0.1538); // Compute Compton Subtracted Missing Mass p2->Add(p0,1); p2->Add(p1,-0.1538); // Compute Pi0 Subtracted Missing Mass Char_t* canv = Form("Compton Missing Mass"); canvasA = new TCanvas(canv,canv); /* canvasA->Divide(1,3); canvasA->cd(1); a0->Draw(); canvasA->cd(2); a1->Draw(); canvasA->cd(3); */ a2->Draw(); Char_t* canv = Form("Pi0 Missing Mass"); canvasB = new TCanvas(canv,canv); /* canvasB->Divide(1,3); canvasB->cd(1); p0->Draw(); canvasB->cd(2); p1->Draw(); canvasB->cd(3); */ p2->Draw(); // --------------------- Char_t* process = "Compton280"; Char_t* filename = Form("TA2Trigger%s.root",process); TFile *file2 = new TFile(filename); TTree *tree2 = (TTree*)file2->Get("TA2TriggerTree"); tree2->SetBranchAddress("NPhoton", &NPhoton); tree2->SetBranchAddress("NProton", &NProton); tree2->SetBranchAddress("NPi0", &NPi0); tree2->SetBranchAddress("PhotonTheta", &PhotonTheta); tree2->SetBranchAddress("ProtonTheta", &ProtonTheta); tree2->SetBranchAddress("NPrompt", &NPrompt); tree2->SetBranchAddress("MissingMassPrompt", &MissingMassPrompt); TH1D *a3 = new TH1D("Comp: MM Prompt", "Comp: MM Prompt", 400, 900, 1300); Int_t nentries = (Int_t)tree2->GetEntries(); for (Int_t i=0;i<nentries;i++) { tree2->GetEntry(i); if ((NPhoton == 1) && (NProton == 1) && (NPi0 == 0) && (PhotonTheta[0] >= 45) && (ProtonTheta[0] > 20)) { for (Int_t a = 0; a < NPrompt; a++) {a3->Fill(MissingMassPrompt[a]); } } } // --------------------- Char_t* process = "Pi0280"; Char_t* filename = Form("TA2Trigger%s.root",process); TFile *file3 = new TFile(filename); TTree *tree3 = (TTree*)file3->Get("TA2TriggerTree"); tree3->SetBranchAddress("NPhoton", &NPhoton); tree3->SetBranchAddress("NProton", &NProton); tree3->SetBranchAddress("NPi0", &NPi0); tree3->SetBranchAddress("PhotonTheta", &PhotonTheta); tree3->SetBranchAddress("ProtonTheta", &ProtonTheta); tree3->SetBranchAddress("NPrompt", &NPrompt); tree3->SetBranchAddress("MissingMassPrompt", &MissingMassPrompt); TH1D *a4 = new TH1D("Pi0: MM Prompt", "Pi0: MM Prompt", 400, 900, 1300); Int_t nentries = (Int_t)tree3->GetEntries(); for (Int_t i=0;i<nentries;i++) { tree3->GetEntry(i); if ((NPhoton == 1) && (NProton == 1) && (NPi0 == 0) && (PhotonTheta[0] >= 45) && (ProtonTheta[0] > 20)) { for (Int_t a = 0; a < NPrompt; a++) {a4->Fill(MissingMassPrompt[a]); } } } //--------------Spectra THStack *hs = new THStack("hs", "Simulated data (Blue = Compton, Purple = Pi0)"); TH1D *a5 = new TH1D("Scaled Comp: MM Prompt", "Scaled Comp: MM Prompt", 400, 900, 1300); TH1D *a6 = new TH1D("Scaled Pi0: MM Prompt", "Scaled Pi0: MM Prompt", 400, 900, 1300); a5->SetMarkerStyle(21); a5->SetMarkerColor(kBlue); a5->SetFillColor(kBlue); a6->SetMarkerStyle(21); a6->SetMarkerColor(kMagenta+1); a6->SetFillColor(kMagenta+1); a5->Add(a3,0.034); a6->Add(a4,0.34); hs->Add(a5); hs->Add(a6); Char_t* canv = Form("Missing Mass"); canvasC = new TCanvas(canv,canv); a2->SetLineColor(kRed); a2->SetLineWidth(3); hs->Draw(); a2->Draw("sames"); }
void stack_in_cone_contribs(const string& fFile, const double fYmax, const string& fTitleExt, const string& fNameExt) { string title = "<E> in R_{cone}=0.5 -- "+ fTitleExt +";#eta;<E> [GeV]"; TFile file(fFile.c_str()); TDirectoryFile *subDir = (TDirectoryFile*)file.Get("offsetAnalysis"); TProfile *p_AEC5EB = (TProfile*)subDir->Get("p_AvgEinC5EB"); TProfile *p_AEC5EE = (TProfile*)subDir->Get("p_AvgEinC5EE"); TProfile *p_AEC5HB = (TProfile*)subDir->Get("p_AvgEinC5HB"); TProfile *p_AEC5HE = (TProfile*)subDir->Get("p_AvgEinC5HE"); TProfile *p_AEC5HFl = (TProfile*)subDir->Get("p_AvgEinC5HFl"); TProfile *p_AEC5HFs = (TProfile*)subDir->Get("p_AvgEinC5HFs"); // TProfile *p_AEC5HO = (TProfile*)subDir->Get("p_AvgEinC5HO"); TH1D *h_AEC5EB = p_AEC5EB->ProjectionX(); TH1D *h_AEC5EE = p_AEC5EE->ProjectionX(); TH1D *h_AEC5HB = p_AEC5HB->ProjectionX(); TH1D *h_AEC5HE = p_AEC5HE->ProjectionX(); TH1D *h_AEC5HFl = p_AEC5HFl->ProjectionX(); TH1D *h_AEC5HFs = p_AEC5HFs->ProjectionX(); //TH1D *h_AEC5HO = p_AEC5HO->ProjectionX(); h_AEC5EB->SetFillColor(50); h_AEC5EE->SetFillColor(8); h_AEC5HB->SetFillColor(4); h_AEC5HE->SetFillColor(6); h_AEC5HFl->SetFillColor(16); h_AEC5HFs->SetFillColor(12); //h_AEC5HO->SetFillColor(7); // TCanvas *c = new TCanvas("c", "",1120,800); TCanvas *c = new TCanvas("c", "",800,800); c->cd(); TH2F *h_bg = new TH2F("h_bg",title.c_str(),100,-5.,5.,100,0.,fYmax); h_bg->GetXaxis()->SetTitleSize(0.05); h_bg->GetYaxis()->SetTitleSize(0.05); h_bg->SetTitleOffset(1.,"X"); h_bg->SetTitleOffset(1.3,"Y"); h_bg->Draw(); THStack *hs = new THStack("hs",""); hs->Add(h_AEC5EB); hs->Add(h_AEC5EE); hs->Add(h_AEC5HB); hs->Add(h_AEC5HE); hs->Add(h_AEC5HFl); hs->Add(h_AEC5HFs); //hs->Add(h_AEC5HO); hs->Draw("histsame"); TLegend *legend = new TLegend(.65,.6,.75,.85); legend->SetBorderSize(1); legend->SetFillColor(0); // legend->SetFillStyle(0); // legend->SetTextFont(42); legend->AddEntry(h_AEC5EB,"EB","f"); legend->AddEntry(h_AEC5HB,"HB","f"); legend->AddEntry(h_AEC5EE,"EE","f"); legend->AddEntry(h_AEC5HE,"HE","f"); legend->AddEntry(h_AEC5HFl,"HFl","f"); legend->AddEntry(h_AEC5HFs,"HFs","f"); //legend->AddEntry(h_AEC5HO,"HO","f"); legend->Draw(); string fileName = "h_AvgEinC5_stacked_" + fNameExt; c->SetGridy(); gPad->Modified(); gPad->Update(); c->SaveAs(fileName.c_str()); delete legend; delete hs; delete c; }
void Draw(string filename, bool norm, bool logy, bool eff, bool cum, TLine* line){ if(debug) printf(" Draw (norm is %i) %s\n",norm, filename.c_str()); TCanvas c1; if(logy) c1.SetLogy(); string title; if(Data.size()){ title = Data[0].hist->GetTitle(); title += ";"; title += Data[0].hist->GetXaxis()->GetTitle(); title += ";"; title += Data[0].hist->GetYaxis()->GetTitle(); }else if(Bkg.size()){ title = Bkg[0].hist->GetTitle(); title += ";"; title += Bkg[0].hist->GetXaxis()->GetTitle(); title += ";"; title += Bkg[0].hist->GetYaxis()->GetTitle(); } TH1F* hData = NULL; for(uint i=0; i<Data.size(); i++){ if(i==0) hData = (TH1F*)Data[i].hist->Clone("hData"); else hData->Add(Data[i].hist); } hData->SetMarkerSize(5); if(!eff){ THStack* sBkg = new THStack("sBkg",title.c_str()); THStack* sSigs[Sig.size()]; for(uint i=0; i<Bkg.size(); i++){ sBkg->Add(Bkg[i].hist); } for(uint i=0; i<Sig.size(); i++){ sSigs[i] = (THStack*) sBkg->Clone(); sSigs[i]->Add(Sig[i].hist); } Double_t max = sBkg->GetMaximum(); sBkg->Draw("HIST"); for(unsigned int i=0; i<Sig.size(); i++){ max = TMath::Max(max, sSigs[i]->GetMaximum()); sSigs[i]->Draw("HIST SAME"); } if(hData){ max = TMath::Max(max, hData->GetMaximum()); hData->Draw("E1 SAME"); } sBkg->SetMaximum(1.1*max); }else{ THStack* hs = new THStack("hs",title.c_str()); hs->Add(hData); for(unsigned int i=0; i<Bkg.size(); ++i){ hs->Add(Bkg[i].hist); } for(unsigned int i=0; i<Sig.size(); ++i){ hs->Add(Sig[i].hist); } hs->Draw("nostack HIST"); } if(debug) cout<<"Title: "<<title<<endl; if(debug) cout<<"Creating Legend\n"; TLegend *legend = new TLegend(0.65,0.50,0.88,0.89,""); if(Data.size()) legend->AddEntry(hData, "Data", "PLE"); for(unsigned int i=0; i<Bkg.size(); ++i){ legend->AddEntry(Bkg[i].hist,SampleNames[Bkg[i].name].c_str(), "L"); } for(unsigned int i=0; i<Sig.size(); ++i){ legend->AddEntry(Sig[i].hist,SampleNames[Sig[i].name].c_str(), "L"); } if(norm){//???? //TAxis* axis = samples[0]->at(0).hist->GetXaxis(); //int first = axis->GetFirst(); //int last = axis->GetLast(); //float sum = hists[i]->Integral(first,last); //hists[i]->Scale(1./sum); //axis->SetRange(first,last); } //hs->GetXaxis()->SetNdivisions(10); if(debug) printf("Setting title\n"); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->SetFillStyle(0); legend->Draw(); if(line) line->Draw(); c1.SaveAs(filename.c_str()); c1.Print("Summary.pdf","pdf"); }
THStack* BasePlot::GetStack(bool isLog) { THStack* hstack = new THStack(); float binWidth = 0; for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) { _hist[i]->SetLineColor(sampleColor[i]); _hist[i]->SetFillColor(sampleColor[i]); _hist[i]->SetFillStyle(1001); binWidth = _hist[i]->GetBinWidth(1); hstack->Add(_hist[i]); } for (size_t i=0; i<_autreHists.size(); i++) { _autreHists[i].second->SetLineColor(autreColors[i]); _autreHists[i].second->SetFillColor(autreColors[i]); _autreHists[i].second->SetFillStyle(1001); hstack->Add(_autreHists[i].second); } hstack->Draw("GOFF"); if(_prelim) hstack->SetTitle("CMS preliminary"); else hstack->SetTitle("CMS, #sqrt{s} = 7 TeV"); Float_t theMax = hstack->GetMaximum(); Float_t theMin = hstack->GetMinimum(); if (_hist[iHWW]) { if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum(); if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum(); } if (_data) { Float_t dataMax = GetMaximumIncludingErrors(_data); if (dataMax > theMax) theMax = dataMax; } int sampCount = GetSampCount(); float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14); // Min --- only need to change if log theMin = theMin==0?0.1:theMin/10; if(isLog) hstack->SetMinimum(theMin); // Max if (_myMax != -1) { hstack->SetMaximum(_myMax); } else if (isLog) { hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1)); } else { hstack->SetMaximum(scaleBy * theMax); } if(_breakdown) { THStackAxisFonts(hstack, "y", "entries"); hstack->GetHistogram()->LabelsOption("v"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data())); if(_units.Sizeof() == 1) { THStackAxisFonts(hstack, "x", _xLabel.Data()); // THStackAxisFonts(hstack, "y", "entries"); } } return hstack; }
void draw_from_trees(TString var, TCut other_cuts, TString weights, TString title, int nbinsx, double xlow, double xup, TString options="plotSig:plotLog:plotData", double cut_low=-1, double cut_high=-1, TString plot_title="default") { bool plotSig = options.Contains("plotSig") && (!options.Contains("!plotSig")); bool plotLog = options.Contains("plotLog") && (!options.Contains("!plotLog")); bool plotData = options.Contains("plotData") && (!options.Contains("!plotData")); bool plotT1tttt = options.Contains("T1tttt") && (!options.Contains("!T1tttt")); // Book histograms TH1D * httbar = new TH1D("ttbar" , title, nbinsx, xlow, xup); TH1D * hqcd = new TH1D("qcd" , title, nbinsx, xlow, xup); TH1D * hznn = new TH1D("znn" , title, nbinsx, xlow, xup); TH1D * hwjets = new TH1D("wjets" , title, nbinsx, xlow, xup); TH1D * hother = new TH1D("other" , title, nbinsx, xlow, xup); TH1D * hmc_exp = new TH1D("mc_exp" , title, nbinsx, xlow, xup); TH1D * hsingle_top = new TH1D("single_top" , title, nbinsx, xlow, xup); TH1D * ht1bbbb_1500_100 = new TH1D("t1bbbb_1500_100" , title, nbinsx, xlow, xup); TH1D * ht1bbbb_1000_900 = new TH1D("t1bbbb_1000_900" , title, nbinsx, xlow, xup); TH1D * ht1tttt_1500_100 = new TH1D("t1tttt_1500_100" , title, nbinsx, xlow, xup); TH1D * ht1tttt_1200_800 = new TH1D("t1tttt_1200_800" , title, nbinsx, xlow, xup); // Format cuts TCut cut(other_cuts); cout << "Filling histograms for " << var.Data() << endl; ttbar_ch->Project("ttbar",var,cut*weights); qcd_ch->Project("qcd",var,cut*weights); znn_ch->Project("znn",var,cut*weights); wjets_ch->Project("wjets",var,cut*weights); other_ch->Project("other",var,cut*weights); single_top_ch->Project("single_top",var,cut*weights); t1bbbb_1500_100_ch->Project("t1bbbb_1500_100",var,cut*weights); t1bbbb_1000_900_ch->Project("t1bbbb_1000_900",var,cut*weights); t1tttt_1500_100_ch->Project("t1tttt_1500_100",var,cut*weights); t1tttt_1200_800_ch->Project("t1tttt_1200_800",var,cut*weights); TH1D * hSMSLargeSplitting; TH1D * hSMSCompressed; if (plotT1tttt) { hSMSLargeSplitting=ht1tttt_1500_100; hSMSCompressed=ht1tttt_1200_800; } else { hSMSLargeSplitting=ht1bbbb_1500_100; hSMSCompressed=ht1bbbb_1000_900; } bool addOverflow(true); Double_t e_overflow(0.), i_overflow(0.); if (addOverflow) { i_overflow=httbar->IntegralAndError(nbinsx,nbinsx+1,e_overflow); httbar->SetBinContent(nbinsx, i_overflow); httbar->SetBinError(nbinsx, e_overflow); i_overflow=hqcd->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hqcd->SetBinContent(nbinsx, i_overflow); hqcd->SetBinError(nbinsx, e_overflow); i_overflow=hznn->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hznn->SetBinContent(nbinsx, i_overflow); hznn->SetBinError(nbinsx, e_overflow); i_overflow=hwjets->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hwjets->SetBinContent(nbinsx, i_overflow); hwjets->SetBinError(nbinsx, e_overflow); i_overflow=hsingle_top->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hsingle_top->SetBinContent(nbinsx, i_overflow); hsingle_top->SetBinError(nbinsx, e_overflow); i_overflow=hother->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hother->SetBinContent(nbinsx, i_overflow); hother->SetBinError(nbinsx, e_overflow); i_overflow=hSMSLargeSplitting->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hSMSLargeSplitting->SetBinContent(nbinsx, i_overflow); hSMSLargeSplitting->SetBinError(nbinsx, e_overflow); i_overflow=hSMSCompressed->IntegralAndError(nbinsx,nbinsx+1,e_overflow); hSMSCompressed->SetBinContent(nbinsx, i_overflow); hSMSCompressed->SetBinError(nbinsx, e_overflow); } // Add up MC histograms hmc_exp->Add(httbar); hmc_exp->Add(hqcd); hmc_exp->Add(hznn); hmc_exp->Add(hwjets); hmc_exp->Add(hsingle_top); hmc_exp->Add(hother); double binwidth = (xup - xlow) / nbinsx; TString ytitle = Form("Events / %.3f", binwidth); hmc_exp->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle()); hmc_exp->GetYaxis()->SetTitle(ytitle); cout << "... DONE: add all backgrounds to mc_exp." << endl; Double_t ttbar_e(0.), qcd_e(0.), znn_e(0.), wjets_e(0.), other_e(0.), single_top_e(0.), bg_tot_e(0.), t1bbbb_1500_100_e(0.); double ttbar_n(httbar->IntegralAndError(0,nbinsx+1, ttbar_e)); double qcd_n(hqcd->IntegralAndError(0,nbinsx+1, qcd_e)); double znn_n(hznn->IntegralAndError(0,nbinsx+1, znn_e)); double wjets_n(hwjets->IntegralAndError(0,nbinsx+1, wjets_e)); double other_n(hother->IntegralAndError(0,nbinsx+1, other_e)); double single_top_n(hsingle_top->IntegralAndError(0,nbinsx+1, single_top_e)); double bg_tot(hmc_exp->IntegralAndError(0,nbinsx+1, bg_tot_e)); double t1bbbb_1500_100_n(ht1bbbb_1500_100->IntegralAndError(0,nbinsx+1, t1bbbb_1500_100_e)); printf("Counts before cut: %s\n",var.Data()); printf("&ttbar&qcd&znn&wjets&single top&other&t1bbbb_1500_100\\\\ \n"); printf("%s & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f \\\\\n", var.Data(), ttbar_n,ttbar_e, qcd_n,qcd_e, znn_n,znn_e, wjets_n,wjets_e, single_top_n,single_top_e, other_n,other_e, bg_tot,bg_tot_e, t1bbbb_1500_100_n,t1bbbb_1500_100_e); cout << "... DONE: filled histograms." << endl; THStack * hs = new THStack("hs", ""); hs->Add(hother); hs->Add(hznn); hs->Add(hsingle_top); hs->Add(hwjets); hs->Add(httbar); hs->Add(hqcd); //hs->GetYaxis()->SetTitle("Events / 5 fb^{-1}"); //hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle()); // Setup histogram styles set_style(httbar, "ttbar"); set_style(hqcd, "qcd"); set_style(hznn, "znn"); set_style(hwjets, "wjets"); set_style(hother, "other"); set_style(hsingle_top, "single_top"); // Setup auxiliary histograms (ratios, errors, etc) TH1D * staterr = (TH1D *) hmc_exp->Clone("staterr"); staterr->Sumw2(); //staterr->SetFillColor(kRed); staterr->SetFillColor(kGray+3); staterr->SetMarkerSize(0); staterr->SetFillStyle(3013); // Setup legends TLegend * leg1 = new TLegend(0.48, 0.68, 0.72, 0.92); set_style(leg1,0.025); if (plotData) leg1->AddEntry(hsingle_top, "Data", "pel"); if (plotSig) { if (plotT1tttt) { leg1->AddEntry(hSMSLargeSplitting, "#splitline{T1tttt}{(1500,100) GeV}", "l"); leg1->AddEntry(hSMSCompressed, "#splitline{T1tttt}{(1200,800) GeV}", "l"); } else { leg1->AddEntry(hSMSLargeSplitting, "#splitline{T1bbbb}{(1500,100) GeV}", "l"); leg1->AddEntry(hSMSCompressed, "#splitline{T1bbbb}{(1000,900) GeV}", "l"); } } leg1->AddEntry(httbar, "t#bar{t}", "f"); leg1->AddEntry(hqcd, "QCD", "f"); TLegend * leg2 = new TLegend(0.72, 0.68, 0.94, 0.92); set_style(leg2,0.025); leg2->AddEntry(hznn, "Z+jets", "f"); leg2->AddEntry(hwjets, "W+jets", "f"); leg2->AddEntry(hsingle_top, "Single Top", "f"); leg2->AddEntry(hother, "Other", "f"); leg2->AddEntry(staterr, "MC uncert.", "f"); double ymax = hs->GetMaximum(); if(plotLog) { hs->SetMaximum(100*ymax); hs->SetMinimum(0.1); } else hs->SetMaximum(1.1*ymax); // Vertical lines for cuts TLine* line_low = new TLine(cut_low,0,cut_low,1.5*ymax); TLine* line_high = new TLine(cut_high,0,cut_high,1.5*ymax); set_style(line_low); set_style(line_high); // Setup canvas and pads TCanvas * c1 = new TCanvas("c1", "c1", 700, 700); TPad * pad1 = new TPad("pad1", "top pad" , 0.0, 0.3, 1.0, 1.0); TPad * pad2 = new TPad("pad2", "bottom pad", 0.0, 0.0, 1.0, 0.3); if(plotData) { pad1->SetBottomMargin(0.0); pad1->Draw(); pad2->SetTopMargin(0.0); pad2->SetBottomMargin(0.35); pad2->Draw(); pad1->cd(); pad1->SetLogy(plotLog); } else { c1->cd(); c1->SetLogy(plotLog); } // Draw hists hs->Draw("hist"); hs->SetTitle(hmc_exp->GetTitle()); hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle()); hs->GetYaxis()->SetTitle(ytitle); hs->GetXaxis()->SetLabelSize(0.04); hs->GetYaxis()->SetLabelSize(0.04); if (plotData) { // hsingle_top->Draw("e1 same"); hs->GetXaxis()->SetLabelSize(0); } staterr->Draw("e2 same"); if (plotSig) { hSMSLargeSplitting->SetLineColor(2); hSMSLargeSplitting->SetLineWidth(3); hSMSLargeSplitting->SetFillColor(0); hSMSCompressed->SetLineColor(kMagenta+2); hSMSCompressed->SetLineWidth(3); hSMSCompressed->SetFillColor(0); hSMSLargeSplitting->Draw("hist same"); hSMSCompressed->Draw("hist same"); } if (cut_low>0) line_low->Draw("same"); if (cut_high>0) line_high->Draw("same"); // Draw legends leg1->Draw(); leg2->Draw(); TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextFont(62); latex->SetTextSize(0.042); latex->DrawLatex(0.19, 0.89, "CMS Simulation"); latex->SetTextSize(0.03); latex->DrawLatex(0.19, 0.84, "#sqrt{s} = 13 TeV, L = 20 fb^{-1}"); // Print cout << "MakePlots(): Printing..." << endl; c1->cd(); if (plot_title.EqualTo("default")) plot_title=plotdir+var; gPad->Print(plotdir+plot_title+".pdf"); TFile* outrootfile = TFile::Open(plotdir+plot_title+".root", "RECREATE"); httbar->Write(); hqcd->Write(); hznn->Write(); hwjets->Write(); hother->Write(); hSMSLargeSplitting->Write(); hSMSCompressed->Write(); hmc_exp->Write(); hsingle_top->Write(); outrootfile->Close(); // Clean up delete staterr; delete leg1; delete leg2; delete latex; // delete pave; delete hs; delete pad1; delete pad2; delete c1; delete httbar; delete hqcd; delete hznn; delete hwjets; delete hsingle_top; delete hother; delete hmc_exp; delete ht1bbbb_1500_100; delete ht1tttt_1500_100; delete ht1bbbb_1000_900; delete ht1tttt_1200_800; // delete hSMSLargeSplitting; // delete hSMSCompressed; cout << "MakePlots(): DONE!" << endl; return; }
void doControlPlotsMET(){ setTDRStyle(); //loop over variables for(int i = 0; i<N; i++){ //double MinX = MinXs[i]; //double MaxX = MaxXs[i]; Variable = Variables[i]; TString Xtitle = XTitles[i]; int RebingFact = RebinFacts[i]; //Data TH1D* data = getSample("DoubleMu", 1, Obj, Next, Variable, RebinFact, Systematic); std::cout << data->Integral() << std::endl; //MC TH1D* tt = getSample("TTJet", 1, Obj, Next, Variable, RebinFact, Systematic); TH1D* wjets = getSample("WJetsToLNu", 1, Obj, Next, Variable, RebinFact, Systematic); TH1D* DY1 = getSample("DYJetsToLL_M-10To50", 1, Obj, Next, Variable, RebinFact, Systematic); TH1D* DY2 = getSample("DYJetsToLL_M-50", 1, Obj, Next, Variable, RebinFact, Systematic); TH1D* T_tW = getSample("T_tW-channel", 1, Obj, Next, Variable, RebinFact, Systematic); TH1D* Tbar_tW = getSample("Tbar_tW-channel",1, Obj, Next, Variable, RebinFact, Systematic); THStack *hs = new THStack("hs","test"); hs->Add(wjets); hs->Add(DY1); hs->Add(DY2); hs->Add(T_tW); hs->Add(Tbar_tW); hs->Add(tt); //draw histos to files TCanvas *c1 = new TCanvas("Plot","Plot",900, 600); hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3); hs->Draw(); data->Draw("E same"); data->SetMarkerStyle(20); // hs->GetXaxis()->SetLimits(MinX, MaxX); hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05); if(logPlot == true){ c1->SetLogy(); } TLegend *tleg2; tleg2 = new TLegend(0.6,0.7,0.8,0.9); tleg2->SetTextSize(0.04); tleg2->SetBorderSize(0); tleg2->SetFillColor(10); tleg2->AddEntry(data , "2012 data", "lpe"); tleg2->AddEntry(tt , "t#bar{t}", "lf"); tleg2->AddEntry(T_tW, "single-t", "lf"); tleg2->AddEntry(Tbar_tW, "single-#bar{t}", "lf"); tleg2->AddEntry(DY1 , "DYJetsToLL-10To50", "lf"); tleg2->AddEntry(DY2 , "DYJetsToLL-50", "lf"); tleg2->AddEntry(wjets , "W+jets", "lf"); tleg2->Draw("same"); TString plotName("plots/Control/PassesCutsUpTo1Btag/MET/"); if(logPlot == true){ plotName += Variable+"Log.pdf"; // plotName += Nbtags+".pdf"; }else{ plotName += Variable+".pdf"; // plotName += Nbtags+".pdf"; } TText* textPrelim = doPrelim(0.16,0.96); textPrelim->Draw(); c1->SaveAs(plotName); delete c1; } }
void makeTree(string sample = "DY", string selection = "", float Lumi = 1){ vector<pair<string,float> > files; vector< TH1F* > histos; vector<string> directories; if(sample.find("DY")!=string::npos){ files.push_back( make_pair("DY-madgraph-10to50.root", (310*0.19*Lumi) ) ); files.push_back( make_pair("DY-madgraph-50.root", (2289*0.56*Lumi) ) ); } if(sample.find("Wjets")!=string::npos){ files.push_back( make_pair("W1Jets_ptW-0to100.root", (3.693e+03*0.44*Lumi) ) ); files.push_back( make_pair("W1Jets_ptW-100to300.root", (7.197e+01*0.58*Lumi) ) ); files.push_back( make_pair("W1Jets_ptW-300to800.root", (5.658e-01*0.73*Lumi) ) ); files.push_back( make_pair("W2Jets_ptW-0to100.root", (9.434e+02*0.46*Lumi) ) ); files.push_back( make_pair("W2Jets_ptW-100to300.root", (6.718e+01*0.59*Lumi) ) ); files.push_back( make_pair("W2Jets_ptW-300to800.root", (8.553e-01*0.75*Lumi) ) ); files.push_back( make_pair("W3Jets_ptW-0to100.root", (2.087e+02*0.48*Lumi) ) ); files.push_back( make_pair("W3Jets_ptW-100to300.root", (3.243e+01*0.60*Lumi) ) ); files.push_back( make_pair("W3Jets_ptW-300to800.root", (6.229e-01*0.76*Lumi) ) ); files.push_back( make_pair("W4Jets_ptW-0to100.root", (4.446e+01*0.50*Lumi) ) ); files.push_back( make_pair("W4Jets_ptW-100to300.root", (1.138e+01*0.61*Lumi) ) ); files.push_back( make_pair("W4Jets_ptW-300to800.root", (2.950e-01*0.77*Lumi) ) ); files.push_back( make_pair("W5Jets_ptW-0to100.root", (1.111e+01*0.53*Lumi) ) ); files.push_back( make_pair("W5Jets_ptW-100to300.root", (3.789e+00*0.65*Lumi) ) ); files.push_back( make_pair("W5Jets_ptW-300to800.root", (1.565e-01*0.79*Lumi) ) ); } if(sample.find("TT")!=string::npos){ files.push_back( make_pair("TT.root", (94*Lumi) ) ); } if(sample.find("QCD")!=string::npos){ files.push_back( make_pair("QCD_Pt-0to5.root", (4.84e+10*6.07E-07*Lumi)) ); files.push_back( make_pair("QCD_Pt-5to15.root", (3.68e+10*1.82E-06*Lumi)) ); files.push_back( make_pair("QCD_Pt-15to30.root", (8.16e+08*0.000113*Lumi)) ); files.push_back( make_pair("QCD_Pt-30to50.root", (5.31e+07*0.00388126*Lumi)) ); files.push_back( make_pair("QCD_Pt-50to80.root", (6.36e+06*0.02321727*Lumi)) ); files.push_back( make_pair("QCD_Pt-80to120.root", (7.84e+05*0.06100585*Lumi)) ); files.push_back( make_pair("QCD_Pt-120to170.root", (1.15e+05*0.11389810*Lumi)) ); files.push_back( make_pair("QCD_Pt-170to300.root", (2.43e+04*0.13732413*Lumi)) ); files.push_back( make_pair("QCD_Pt-300to470.root", (1.17e+03*0.317390358*Lumi)) ); files.push_back( make_pair("QCD_Pt_470to600.root", (7.02e+01*0.431763719*Lumi)) ); files.push_back( make_pair("QCD_Pt_600to800.root", (1.56e+01*0.508048972*Lumi)) ); files.push_back( make_pair("QCD_Pt_800to1000.root", (1.84e+00*0.385363968*Lumi)) ); files.push_back( make_pair("QCD_Pt_1000to1400.root", (3.32e-01*0.661857989*Lumi)) ); //files.push_back( make_pair("QCD_Pt_1400to1800.root", (1.09e-02*0.784767648*Lumi)) ); } directories.push_back("etoTauMargLooseNoCracks80"); directories.push_back("etoTauMargLooseNoCracks70"); directories.push_back("etoTauMargLooseNoCracks60"); directories.push_back("etoTauMargMediumNoCracks80"); directories.push_back("etoTauMargMediumNoCracks70"); directories.push_back("etoTauMargMediumNoCracks60"); directories.push_back("etoTauMargTightNoCracks80"); directories.push_back("etoTauMargTightNoCracks70"); directories.push_back("etoTauMargTightNoCracks60"); directories.push_back("etoTauSCMargNoCracks80"); directories.push_back("etoTauSCMargNoCracks70"); directories.push_back("etoTauSCMargNoCracks60"); TFile *outFile = new TFile(("testNewWriteFromPAT_soup"+selection+".root").c_str(),"RECREATE"); int numFiles = 0; for(unsigned int j = 0; j<directories.size(); j++){ numFiles = 0; histos.clear(); for(unsigned int i = 0; i<files.size();i++){ histos.push_back( new TH1F(Form("h_%d",i),Form("file %s",(files[i].first).c_str()),20,40,120) ); } THStack* aStack = new THStack("aStack",""); TLegend* leg = new TLegend(0.1331269,0.5926573,0.3622291,0.8671329,NULL,"brNDC"); leg->SetFillStyle(4000); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.03); cout << "Directory " << directories[j] << endl; TChain* outChain = new TChain((directories[j]+"/fitter_tree").c_str()); int counter = 0; for(unsigned int i = 0; i<files.size();i++){ TFile *file = new TFile(("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_"+files[i].first).c_str(),"READ"); if(file->IsZombie()){ cout << "No file " << files[i].first << " is found" << endl; continue; } file->cd("allEventsFilter"); TH1F* totalEvents = (TH1F*)gDirectory->Get("totalEvents"); float readEvents = totalEvents->GetBinContent(1); file->cd(directories[j].c_str()); TTree *oldTree = (TTree*) gDirectory->Get("fitter_tree"); float scaleToNNLO = 1.0; if((files[i].first).find("DY")!=string::npos) scaleToNNLO = 1.33; if((files[i].first).find("W")!=string::npos) scaleToNNLO = 1.23; if((files[i].first).find("TT")!=string::npos) scaleToNNLO = 1.75; int entries = std::min( (int)oldTree->GetEntries(), (int)(((files[i].second*scaleToNNLO)/readEvents)*oldTree->GetEntries()) ); TFile *newFile = new TFile( ("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_"+files[i].first+"new").c_str(), "RECREATE"); TDirectory* dir = (TDirectory*) newFile->mkdir(directories[j].c_str()); TTree *tree = oldTree->CloneTree( entries ); // weight for the tree: 1 if you require less than the overall tree entries, otherwise set it to L*sigma/processed //float weight = std::max((double)files[i].second,1.0); //tree->SetWeight( weight ); double weight; tree->Branch("weight", &weight,"weight/D"); weight = std::max((double)(files[i].second/readEvents),1.0); tree->Fill(); TH1F* h = new TH1F("h","",20,40,120); tree->Draw("mass>>h",("weight*("+selection+")").c_str()); histos[i]->Add(h,1); histos[i]->SetFillColor(i+1); histos[i]->SetLineColor(i+1); //setUpHisto(histos[i],Lumi, directories[j]); aStack->Add( histos[i] ); leg->AddEntry( histos[i], (files[i].first).c_str(),"F"); dir->cd(); tree->Write(); newFile->Write(); counter+=entries; cout << files[i].first << " ==> total entries " << oldTree->GetEntries() << " --- Required " << (int)(files[i].second/readEvents*oldTree->GetEntries()) << " --- Provided " << entries << endl; std::cout << "The tree will have weight: " << weight << std::endl; //outTree->CopyEntries(tree,entries); if(entries>0){ int isOK = outChain->AddFile( ("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_"+files[i].first+"new").c_str()); if( isOK == 0) cout << "No linked file" << endl; numFiles += isOK; } cout << " outChain has " << outChain->GetEntries() << " and attached files " << numFiles << endl; file->Close(); newFile->Close(); //delete h; delete file; delete newFile; } // file //outFile->cd(); TDirectory* dir = (TDirectory*) outFile->mkdir(directories[j].c_str()); TTree* outTree = (TTree*) outChain->CopyTree(""); //outTree->Draw("mass"); cout<< "Total events copied in output directory " << outTree->GetEntries() << " from requested " << counter << endl; dir->cd(); outTree->Write("", TObject::kOverwrite); TCanvas *c1 = new TCanvas("c1","stacked mass",10,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); aStack->Draw("HIST"); setUpHisto( (TH1F*)aStack->GetHistogram(), Lumi, directories[j] ); leg->SetHeader(directories[j].c_str()); leg->Draw(); c1->Write(); for(int i = 0; i<histos.size(); i++){ delete histos[i]; } delete aStack; delete leg; }//directories outFile->Write(); outFile->Close(); delete outFile; }
void fake() { gROOT->SetBatch(); gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); SetStyle(); TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); TLegend *leg = new TLegend(0.65,0.90,0.90,0.70); leg->SetFillColor(253); leg->SetBorderSize(0); std::string fpath = "histTEST_MERGED/QCD_Pt_170to300_TuneCUETP8M1_13TeV_pythia8/data.root"; // std::string histnameFake = "h_muFake_pt"; // std::string histnameReal = "h_muReal_pt"; // std::string histnameFake = "h_muFake_trackerLayersWithMeasurement"; // std::string histnameReal = "h_muReal_trackerLayersWithMeasurement"; // std::string histnameFake = "h_muFake_numberOfValidMuonHits"; // std::string histnameReal = "h_muReal_numberOfValidMuonHits"; // std::string histnameFake = "h_muFake_numberOfMatches"; // std::string histnameReal = "h_muReal_numberOfMatches"; // std::string histnameFake = "h_muFake_numberOfMatchedStations"; // std::string histnameReal = "h_muReal_numberOfMatchedStations"; // std::string histnameFake = "h_muFake_numberOfValidHits"; // std::string histnameReal = "h_muReal_numberOfValidHits"; // std::string histnameFake = "h_muFake_numberOfValidPixelHits"; // std::string histnameReal = "h_muReal_numberOfValidPixelHits"; std::string histnameFake = "h_muFake_numberOfHits"; std::string histnameReal = "h_muReal_numberOfHits"; // std::string histnameFake = "h_muFake_normalizedChi2GlobalTrack"; // std::string histnameReal = "h_muReal_normalizedChi2GlobalTrack"; // std::string histnameFake = "h_muFake_normalizedChi2InnerTrack"; // std::string histnameReal = "h_muReal_normalizedChi2InnerTrack"; TFile *f; TH1D *hFake; TH1D *hReal; f = TFile::Open(fpath.c_str()); { TH1D *hFake_c = (TH1D*)f->Get(histnameFake.c_str()); hFake_c->SetMarkerSize(0.0); TH1D *hReal_c = (TH1D*)f->Get(histnameReal.c_str()); hReal_c->SetMarkerSize(0.0); hFake = (TH1D*)hFake_c->Clone("hFake"); hReal = (TH1D*)hReal_c->Clone("hReal"); } addbin(hFake); addbin(hReal); std::cout << hReal->Integral() << std::endl; std::cout << hFake->Integral() << std::endl; double iFake = hFake->Integral(); double iReal = hReal->Integral(); // double iAll = iFake+iReal; // hFake->Scale(1./iAll); // hReal->Scale(1./iAll); hFake->SetLineColor(9); hFake->SetFillColor(9); hReal->SetLineColor(46); hReal->SetFillColor(46); THStack *hst = new THStack(); hst->Add(hReal); hst->Add(hFake); hst->Draw("hist e1"); float max = hst->GetMaximum(); hst->SetMaximum(1.3*max); hst->SetMinimum(0.); if( histnameFake == "h_muFake_pt" ) hst->GetXaxis()->SetTitle("p_{T} [GeV]"); hst->GetYaxis()->SetTitle("Number of muons"); leg->AddEntry(hFake,"Fake","f"); leg->AddEntry(hReal,"Real","f"); leg->Draw(); c1->Print("pics/fake.eps"); c1->Clear(); TH1F *hRealScaled = (TH1F*)hReal->Clone("hRealScaled"); hRealScaled->Scale(1./iReal); TH1F *hFakeScaled = (TH1F*)hFake->Clone("hFakeScaled"); hFakeScaled->Scale(1./iFake); hFakeScaled->SetLineColor(9); hFakeScaled->SetFillColor(0); hRealScaled->SetLineColor(46); hRealScaled->SetFillColor(0); hRealScaled->Draw("hist e1"); hFakeScaled->Draw("hist e1 same"); float max1 = hRealScaled->GetMaximum(); float max2 = hFakeScaled->GetMaximum(); max = (max1 > max2) ? max1 : max2; hRealScaled->SetMaximum(1.3*max); hRealScaled->SetMinimum(0.); if( histnameFake == "h_muFake_pt" ) hRealScaled->GetXaxis()->SetTitle("p_{T} [GeV]"); if( histnameFake == "h_muFake_trackerLayersWithMeasurement" ) hRealScaled->GetXaxis()->SetTitle("trackerLayersWithMeasurement"); if( histnameFake == "h_muFake_numberOfValidMuonHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidMuonHits"); if( histnameFake == "h_muFake_numberOfMatches" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatches"); if( histnameFake == "h_muFake_numberOfMatchedStations" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatchedStations"); if( histnameFake == "h_muFake_numberOfValidHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidHits"); if( histnameFake == "h_muFake_numberOfValidPixelHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidPixelHits"); if( histnameFake == "h_muFake_numberOfHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfHits"); if( histnameFake == "h_muFake_normalizedChi2GlobalTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2GlobalTrack"); if( histnameFake == "h_muFake_normalizedChi2InnerTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2InnerTrack"); hRealScaled->GetYaxis()->SetTitle("Normalized to unity"); leg->Draw(); c1->Print("pics/fakeComp.eps"); c1->Clear(); gApplication->Terminate(); }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas // // just for MC- no ratio and no data // // *************************************** // TCanvas* drawPlots::plot_MC_noRatio(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal){ const unsigned int MAINPLOT_WIDTH = 800; const unsigned int MAINPLOT_HEIGHT = 600; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,MAINPLOT_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->cd(); double main_y_max = -99; double main_y_min = -99; double main_x_max = -99; double main_x_min = -99; for(int a=0; a<histos.size(); a++){ GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max); } // create main pad TPad* mainPad = new TPad("main","main",0.,0.,1.,1.); mainPad->SetMargin(0.15,0.05,0.15,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); SetAtlasStyle(); THStack* Stack = new THStack(); // fix title here, also not showing on plot std::string title = std::string(";") + axisName + ";Events"; Stack->SetTitle(title.c_str()); for(int b=0; b<histos.size(); b++){ histos[b]->SetLineColor(1); histos[b]->SetFillColor(tools::setColor(names[b])); Stack->Add(histos[b]); } main_y_max = main_y_max*1.5; Stack->SetMaximum(main_y_max); Stack->Draw("hist"); signal->SetLineStyle(2); signal->SetLineColor(kRed); signal->Draw("hist same"); TLegend* leg = new TLegend(0.7,0.7,0.93,0.9); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->AddEntry(signal, "Signal", "f"); for(int q=0; q<names.size(); q++){ leg->AddEntry(histos[q], names[q].c_str(), "f"); } leg->Draw("lpe"); ATLAS_LABEL(0.2,0.8,1); char text[]="#sqrt{s}=8 TeV"; myText(0.2,0.7,1,text); return canvas; }
void doPlotsBtag(){ setTDRStyle(); //loop over variables for(int i = 0; i<2; i++){ double MinX = MinXs[i]; double MaxX = MaxXs[i]; Variable = Variables[i]; TString Xtitle = XTitles[i]; //Data TH1D* data = getSample("SingleMu", 1); //MC TH1D* tt = getSample("TTJet", lumi*225.2/6920475); TH1D* wjets = getSample("W1Jet", lumi*37509/57708550); TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779); TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404); TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443); TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904); TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954); TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904); TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749); TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628); TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785); TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5", lumi*34679.3/8500505); TH1D* qcd1 = getSample("QCD_Pt-15to20_MuEnrichedPt5", lumi*7.022e8 * 0.0039/1722678); TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5", lumi*2.87e8 * 0.0065/8486893); TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5", lumi*6.609e7 * 0.0122/8928999); TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5", lumi*8082000.0 * 0.0218/7256011); TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5", lumi*1024000.0 * 0.0395/9030624); TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505); TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483); TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481); TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767); TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142); TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5", lumi*0.774 * 0.1097/3807263); TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707); TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395); TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516); TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817); TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239); TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948); THStack *hs = new THStack("hs","test"); if(inclQ == true){ hs->Add(qcd); }else{ hs->Add(qcd1); hs->Add(qcd2); hs->Add(qcd3); hs->Add(qcd4); hs->Add(qcd5); hs->Add(qcd6); hs->Add(qcd7); hs->Add(qcd8); hs->Add(qcd9); hs->Add(qcd10); hs->Add(qcd11); } if(inclZ == true){ hs->Add(zjets); }else{ hs->Add(z1jets); hs->Add(z2jets); hs->Add(z3jets); hs->Add(z4jets); } if(inclW == true){ hs->Add(wjets); }else{ hs->Add(w1jets); hs->Add(w2jets); hs->Add(w3jets); hs->Add(w4jets); } hs->Add(top_t); hs->Add(top_tw); hs->Add(top_s); hs->Add(tbar_t); hs->Add(tbar_tw); hs->Add(tbar_s); hs->Add(tt); //draw histos to files TCanvas *c1 = new TCanvas("Plot","Plot",900, 600); hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.2); hs->Draw(); data->Draw("E same"); data->SetMarkerStyle(20); //events: cout << "ttbar: " << tt->Integral() << endl; cout << "data: " << data->Integral() << endl; hs->GetXaxis()->SetLimits(MinX, MaxX); hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05); TLegend *tleg2; tleg2 = new TLegend(0.7,0.7,0.8,0.9); tleg2->SetTextSize(0.04); tleg2->SetBorderSize(0); tleg2->SetFillColor(10); tleg2->AddEntry(data , "2012 data", "lpe"); tleg2->AddEntry(tt , "t#bar{t}", "lf"); tleg2->AddEntry(top_t, "single top", "lf"); tleg2->AddEntry(wjets , "w+jets", "lf"); tleg2->AddEntry(zjets , "z+jets", "lf"); tleg2->AddEntry(qcd , "QCD", "lf"); //tleg2->AddEntry(singtEff, "single-t" , "l"); //tleg2->AddEntry(singtwEff, "single-tW" , "l"); tleg2->Draw("same"); TText* textPrelim = doPrelim(0.17,0.96); textPrelim->Draw(); if(logPlot ==true){ c1->SetLogy(); } TString plotName("plots/Control/Btags/"); if(logPlot ==true){ plotName += Variable+"Test_Log"; plotName += ".pdf"; }else{ plotName += Variable; plotName += ".pdf"; } c1->SaveAs(plotName); delete c1; } }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas. // // It also plots the signal as a dashed // // line and the data with a ratio at the // // the bottom of data/allBackgrounds // // // // This one is supposed to make plots for // // the paper draft // // *************************************** // TCanvas* drawPlots::plotAll_VLQ_paperStyle(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, std::vector<TH1D*> signal, TH1D* data, TGraphAsymmErrors* err, bool doLogAxis, std::string extraTag){ const unsigned int CANVAS_WIDTH = 720; const unsigned int CANVAS_HEIGHT = 750; const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.75; const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.09; const double RATIOPLOT_XAXIS_TITLE_OFFSET = 1.6; const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.09; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); //canvas->cd(); SetAtlasStyle(); gStyle->SetHistLineWidth(1.); gStyle->SetErrorX(0); err->SetLineColor(kWhite); err->SetLineWidth(0); // create histogram to store all backgrounds TH1D* allBackgrounds; bool gotSomething=false; for(int c=0; c<signal.size(); c++){ if(signal[c]){ allBackgrounds = (TH1D*)signal[c]->Clone("all_backgrounds"); gotSomething=true; } } if(!gotSomething && data){ allBackgrounds = (TH1D*)data->Clone("all_backgrounds"); gotSomething=true; } if(!gotSomething){ for(int b=0; b<histos.size(); b++){ if(histos[b] && !gotSomething){ allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds"); gotSomething=true; } } } if(!gotSomething){ std::cout << "Error: could not find any background, data, or signal for this plot" << std::endl; return canvas; } // set all bins to zero for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++) allBackgrounds->SetBinContent(i,0); // go through histos and combine the histograms that need to be combined // WZ stays separate, ttV stays separate, all others become "Other bkg" TH1D* otherBkgs=0; TH1D* ttbarX=0; TH1D* WZ_Sherpa=0; for(int cc=0; cc<histos.size(); cc++){ if(histos[cc]){ for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){ double binContent=allBackgrounds->GetBinContent(j)+histos[cc]->GetBinContent(j); allBackgrounds->SetBinContent(j,binContent); } if(names[cc]=="ttbarX") ttbarX=(TH1D*)histos[cc]->Clone("ttbarX_new"); else if(names[cc]=="WZ_Sherpa") WZ_Sherpa=(TH1D*)histos[cc]->Clone("WZ_new"); else{ if(!otherBkgs) otherBkgs=(TH1D*)histos[cc]->Clone("other_bkg_new"); else otherBkgs->Add(histos[cc]); } } } // make stack of backgrounds, fill backgrounds histogram THStack* Stack = new THStack(); if(ttbarX){ ttbarX->SetLineColor(kGray); ttbarX->SetFillColor(kGray); Stack->Add(ttbarX); } if(WZ_Sherpa){ WZ_Sherpa->SetLineColor(kBlue-9); WZ_Sherpa->SetFillColor(kBlue-9); Stack->Add(WZ_Sherpa); } if(otherBkgs){ otherBkgs->SetLineColor(kOrange-2); otherBkgs->SetFillColor(kOrange-2); Stack->Add(otherBkgs); } TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio"); // create main pad const double mainPad_ylow = 0.3; const double mainPad_yhigh = 0.95; const double mainPad_xlow = 0.; const double mainPad_xhigh = 0.95; const double pad_margin_left = 0.2; const double pad_margin_right = 0.02; double main_y_max = -99; double main_y_min = -99; TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); // find max y if(allBackgrounds){ int maxBinBkg = allBackgrounds->GetMaximumBin(); double bkgYmax = allBackgrounds->GetBinContent(maxBinBkg); main_y_max = bkgYmax; } if(data){ int maxBinData = data->GetMaximumBin(); double dataYmax = data->GetBinContent(maxBinData); if(dataYmax > main_y_max) main_y_max = dataYmax; } if(main_y_max < .002) main_y_max = .1; if(doLogAxis){ mainPad->SetLogy(); main_y_min = 0.07; main_y_max*=60; }else{ main_y_min = 0.001; main_y_max*=1.6; } // draw axis allBackgrounds->SetMaximum(main_y_max); allBackgrounds->SetMinimum(main_y_min); std::string title = std::string(";") + axisName + ";Events"; std::stringstream binw; binw<<allBackgrounds->GetBinWidth(1); std::string width = binw.str(); if (axisName.find("GeV") != std::string::npos){ width += " GeV"; title += " / "+width; } allBackgrounds->SetTitle(title.c_str()); allBackgrounds->GetYaxis()->SetTitleOffset(1.4); allBackgrounds->GetYaxis()->SetTitleSize(0.06); allBackgrounds->GetXaxis()->SetTitleOffset(1.2); allBackgrounds->GetYaxis()->SetLabelSize(0.04); allBackgrounds->GetXaxis()->SetLabelSize(0.04); allBackgrounds->Draw("hist"); // draw stack with error Stack->Draw("hist same"); if(err){ err->Draw("E2 same"); } // make error histograms for the ratio plot TGraphAsymmErrors* ratioErr = tools::getRatio(err, backgroundsForRatio); // draw data if(data) data->Draw("e same"); // draw signal if(signal[0]){ signal[0]->SetLineStyle(2); signal[0]->SetLineColor(kRed+2);//kGreen+3 before signal[0]->SetLineWidth(5); signal[0]->Draw("hist same"); } if(signal.size() > 1){ if(signal[1]){ //signal[1]->SetLineStyle(2); signal[1]->SetLineColor(kRed+2); signal[1]->SetLineWidth(4); signal[1]->Draw("hist same"); } if(signal.size() > 2){ if(signal[2]){ //signal[2]->SetLineStyle(2); signal[2]->SetLineColor(kBlue+2); signal[2]->SetLineWidth(4); signal[2]->Draw("hist same"); } } } allBackgrounds->Draw("axis same"); // draw legend float leg_height = 0.3; float leg_width = 0.2; float leg_xoffset = 0.74; float leg_yoffset = 0.77; TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(52); leg->SetTextSize(0.033); // currently assuming first signal is Tbq (single T production), second is TTS, third is BBS leg->AddEntry(data, "data 2012"); leg->AddEntry(otherBkgs, "Other bkg.", "f"); leg->AddEntry(WZ_Sherpa, "WZ", "f"); leg->AddEntry(ttbarX, "t#bar{t}+X", "f"); if(signal.size()>1){ if(signal[2]) leg->AddEntry(signal[2], "B#bar{B} (650 GeV)", "l"); if(signal[1]) leg->AddEntry(signal[1], "T#bar{T} (650 GeV)", "l"); } if(signal[0]) leg->AddEntry(signal[0], "T#bar{b}q (650 GeV)", "l"); leg->AddEntry( err, "Uncertainty", "f"); leg->Draw("lpe"); ATLAS_LABEL(0.24,0.86,1); myText(0.36, 0.86, 1, .05, "Internal"); char text[]="#sqrt{s}=8 TeV"; myText(0.55,0.77,1,.04, text); char text_L[]="#int L dt = 20.3 fb^{-1}"; myText(0.5, 0.84,1, .04, text_L); if(extraTag!=""){ char tag_txt[extraTag.size()]; strcpy(tag_txt, extraTag.c_str()); if(extraTag.size()>15) myText(0.7, 0.56, 1, .04, tag_txt); else myText(0.75, 0.56, 1, .04, tag_txt); } char text_tri[]="Trilepton"; myText(0.55, 0.70, 1, .04, text_tri); /* double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1); int t; char inText[100]; if(back_int > 10000.) t=sprintf(inText, "N_{B} = %.3e", back_int); else t=sprintf(inText, "N_{B} = %.1f", back_int); myText(0.24, 0.6, 1, .04, inText); if(data) t=sprintf(inText, "N_{D} = %.0f", data->Integral(0,data->GetNbinsX()+1)); else t=sprintf(inText, "N_{D} = %.0f", 0.); myText(0.24, 0.7, 1, .04, inText); */ canvas->cd(); // Draw Ratio plot // 1.6 and .4 are the normal ones double ratio_max = 3.2; double ratio_min = -.9; double pad_xlow = 0.; double pad_xhigh = 0.95; double pad_ylow = 0.0; double pad_yhigh = 0.3; const char* pad_name = "pad"; TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh); pad4ratio->SetMargin(pad_margin_left,pad_margin_right,0.46,0.); pad4ratio->Draw(); pad4ratio->cd(); TH1D* ratioPlot; if(data) ratioPlot = (TH1D*)data->Clone("ratio"); else if (signal[0]) ratioPlot = (TH1D*)signal[0]->Clone("ratio"); // just for getting the axis else if (signal[1]) ratioPlot = (TH1D*)signal[1]->Clone("ratio"); else return canvas; ratioPlot->SetTitle(""); ratioPlot->Divide(allBackgrounds); ratioPlot->GetYaxis()->SetTitle("Data / bkg"); ratioPlot->GetXaxis()->SetTitle(axisName.c_str()); if (data){ // here change ratio_min and ratio_max if the ratio plot is quite flat double maxDeviation=0; double minDeviation=10.; double tempDev=0; for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){ double binContent = ratioPlot->GetBinContent(ibin); tempDev=0; if(binContent>0 && binContent < 10) tempDev = std::abs(binContent-1.); if(tempDev > maxDeviation) maxDeviation = tempDev; if(tempDev < minDeviation) minDeviation = tempDev; } if(maxDeviation < 0.6){ ratio_max = 1.6; ratio_min = 0.4; } else if(maxDeviation < 0.1){ ratio_max = 1.12; ratio_min = 0.88; } else if(maxDeviation < 0.2){ ratio_max = 1.25; ratio_min = .75; } if(minDeviation > 1.5){ if(minDeviation > 2.) ratio_max = 2.7; else ratio_max = 2.2; } ratioPlot->SetMinimum(ratio_min); ratioPlot->SetMaximum(ratio_max); } if(ratioPlot->GetXaxis()->GetNdivisions() > ratioPlot->GetNbinsX()) ratioPlot->GetXaxis()->SetNdivisions(ratioPlot->GetNbinsX()); if(ratioPlot->GetXaxis()->GetNdivisions() > 11) ratioPlot->GetXaxis()->SetNdivisions(11); ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetNdivisions(3); ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE); ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET); ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE); ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET); if(data){ ratioPlot->Draw(); // plot horizontal line at y=1 TF1* horizontal = new TF1("horizontal","pol1",-10000,10000); horizontal->SetParameter(0,1.); horizontal->SetParameter(1,0.); horizontal->SetLineColor(kBlack); horizontal->SetLineStyle(2); horizontal->SetLineWidth(1); horizontal->Draw("same"); ratioErr->Draw("E2 same"); }else{ // there is no data ratioPlot->Draw("axis"); char text[]="NO DATA"; myText(0.4,0.6,1,.15,text); } return canvas; }
void BiasDiff () { vector<TH1F*> AIC; for (UInt_t i = 1 ; i <= 7; i++){ AIC.push_back( new TH1F( Form("AIC_%d",i), " ", 9, 0,10 )); AIC[i-1]->GetXaxis()->SetBinLabel(1,"category 0"); AIC[i-1]->GetXaxis()->SetBinLabel(2,""); AIC[i-1]->GetXaxis()->SetBinLabel(3,"category 1"); AIC[i-1]->GetXaxis()->SetBinLabel(4,""); AIC[i-1]->GetXaxis()->SetBinLabel(5,"category 2"); AIC[i-1]->GetXaxis()->SetBinLabel(6,""); AIC[i-1]->GetXaxis()->SetBinLabel(7,"category 3"); AIC[i-1]->GetXaxis()->SetBinLabel(8,""); AIC[i-1]->GetXaxis()->SetBinLabel(9,"Inclusive"); AIC[i-1]->SetFillColor(bkgColors[i-1]); AIC[i-1]->SetLineColor(bkgColors[i-1]); } AIC[0]->Fill(1.0,0.02); AIC[0]->Fill(3.0,0.3089); AIC[0]->Fill(5.0,0.62); AIC[0]->Fill(7.0,0.36); AIC[0]->Fill(9.0,0.03); AIC[1]->Fill(1.0,0.08); AIC[1]->Fill(3.0,0.21); AIC[1]->Fill(5.0,0.08); AIC[1]->Fill(7.0,0.16); AIC[1]->Fill(9.0,0.33); AIC[2]->Fill(1.0,0.01); AIC[2]->Fill(3.0,0.02); AIC[2]->Fill(5.0,0.01); AIC[2]->Fill(7.0,0.02); AIC[2]->Fill(9.0,0.04); AIC[3]->Fill(1.0,0.20); AIC[3]->Fill(3.0,0.38); AIC[3]->Fill(5.0,0.24); AIC[3]->Fill(7.0,0.451); AIC[3]->Fill(9.0,0.60); AIC[4]->Fill(1.0,0.03); AIC[4]->Fill(3.0,0.08); AIC[4]->Fill(5.0,0.017); AIC[4]->Fill(7.0,0.001); AIC[4]->Fill(9.0,0.0001); AIC[5]->Fill(1.0,0.58); AIC[5]->Fill(3.0,0.001); AIC[5]->Fill(5.0,0.03); AIC[5]->Fill(7.0,0.007); AIC[5]->Fill(9.0,0.000003); AIC[6]->Fill(1.0,0.08); AIC[6]->Fill(3.0,0.0001); AIC[6]->Fill(5.0,0.003); AIC[6]->Fill(7.0,0.001); AIC[6]->Fill(9.0,0.0000004); TCanvas *cv = 0; TLegend *legend = 0; bool firstdrawn = false; // =================================== // AIC // =================================== cv = new TCanvas("cv","cv",800,600); legend = new TLegend(0.64,0.64,0.90,0.84); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->SetFillStyle(0); THStack *stackAIC = new THStack(); for (Int_t i = AIC.size()-1; i>=0; i--) { if (AIC[i]->Integral()>0) { stackAIC->Add(AIC[i]); legend->AddEntry(AIC[i],modelLegendLabels[i].c_str(),"F"); } } stackAIC->Draw(); stackAIC->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackAIC->GetHists()->At(0)))->GetXaxis()->GetTitle()); legend->Draw(); cv->SaveAs("AICvalues.pdf"); // ======================================================= //double x[7] = {1.0,2.0,3.0,4.0,5.0,6.0,7.0}; double x[4] = {1.0,2.0,3.0,4.0}; double comps[4],singEs[4],doubEs[4],tripEs[4],modEs[4],polys[4],pows[4],dpows[4]; //Composite //comps[0] = ( (0.0042-0.0033)/0.0033+(0.0007-0.0036)/0.0036+(0.0180-0.012)/0.012+(0.0090-0.0023)/0.0023+ (0.0033-0.0031)/0.0031 ) /5; comps[0] = ( (0.0045-0.0043)/0.0043 + (0.0035-0.0018)/0.0018 + (0.0074-0.0084)/0.0084 + (0.0053-0.0065)/0.0065 + (0.0016-0.0029)/0.0029 ) /5; //comps[2] = ( (0.0036-0.0049)/0.0049 + (0.0075-0.0029)/0.0029 + (0.0125-0.0126)/0.0126 + (0.0041-0.0031)/0.0031 + (0.0053-0.0027)/0.0027 )/ 5; comps[1] = ( (0.0088-0.0122)/0.0122 + (0.0072-0.0064)/0.0064 + (0.0064-0.0057)/0.0057 ) / 3; comps[2] = ( (0.0142-0.0254)/0.0254 + (0.0118-0.0120)/0.0120 + (0.0024-0.0105)/0.0105 + (0.0057-0.0102)/0.0102 ) / 4; //comps[5] = ((0.0047 - 0.0043)/0.0043 + (0.0091 - 0.0083)/0.0083 + (0.0062 - 0.0071)/0.0071 + (0.0129-0.0120)/0.0120 + (0.0035 - 0.0014)/0.0014 ) / 5; comps[3] = ( (0.0040 - 0.0059)/0.0059 + (0.004 - 0.0009)/0.0009 + (0.0088 - 0.0046)/0.0046 + (0.0026 - 0.0033)/0.0033 + (0.0014 - 0.0022)/0.0022 ) / 5; //singE singEs[0] = ( (0.0221-0.0043)/0.0043 + (0.0079-0.0018)/0.0018 + (0.0084-0.0084)/0.0084 + (0.0033-0.0065)/0.0065 + (0.0082-0.0029)/0.0029 ) /5; singEs[1] = ( (0.0050-0.0122)/0.0122 + (0.0084-0.0064)/0.0064 + (0.0114-0.0057)/0.0057 ) / 3; singEs[2] = ( (0.0196-0.0254)/0.0254 + (0.0024-0.0120)/0.0120 + (0.0008-0.0105)/0.0105 + (0.0003-0.0102)/0.0102 ) / 4; //singEs[3] = ( (0.0126 - 0.0059)/0.0059 + (0.0174 - 0.0009)/0.0009 + (0.0129 - 0.0046)/0.0046 + (0.0193 - 0.0033)/0.0033 + (0.0181 - 0.0022)/0.0022 ) / 5; singEs[3] = 3.0; //doubE doubEs[0] = 0; doubEs[1] = ( (0.0079-0.0122)/0.0122 + (0.0084-0.0064)/0.0064 + (0.0073-0.0057)/0.0057 ) / 3; doubEs[2] = ( (0.0069-0.0254)/0.0254 + (0.0002-0.0120)/0.0120 + (0.0016-0.0105)/0.0105 + (0.0093-0.0102)/0.0102 ) / 4; doubEs[3] = ( (0.0035 - 0.0059)/0.0059 + (0.004 - 0.0009)/0.0009 + (0.0097 - 0.0046)/0.0046 + (0.0041 - 0.0033)/0.0033 + (0.0052 - 0.0022)/0.0022 ) / 5; //tripE tripEs[0] = ( (0.0045-0.0043)/0.0043 + (0.0035-0.0018)/0.0018 + (0.0074-0.0084)/0.0084 + (0.0053-0.0065)/0.0065 + (0.0016-0.0029)/0.0029 ) /5; tripEs[1] = ( (0.0079-0.0122)/0.0122 + (0.0084-0.0064)/0.0064 + (0.0073-0.0057)/0.0057 ) / 3; tripEs[2] = ( (0.0069-0.0254)/0.0254 + (0.0004-0.0120)/0.0120 + (0.0017-0.0105)/0.0105 + (0.0027-0.0102)/0.0102 ) / 4; tripEs[3] = ( (0.0039 - 0.0059)/0.0059 + (0.0043 - 0.0009)/0.0009 + (0.0092 - 0.0046)/0.0046 + (0.0015 - 0.0033)/0.0033 + (0.0039 - 0.0022)/0.0022 ) / 5; //modE modEs[0] = ( (0.0076-0.0043)/0.0043 + (0.0022-0.0018)/0.0018 + (0.0022-0.0084)/0.0084 + (0.0071-0.0065)/0.0065 + (0.0008-0.0029)/0.0029 ) /5; modEs[1] = 0; modEs[2] = ( (0.0051-0.0254)/0.0254 + (0.001-0.0120)/0.0120 + (0.0017-0.0105)/0.0105 + (0.0041-0.0102)/0.0102 ) / 4; modEs[3] = ( (0.0026 - 0.0059)/0.0059 + (0.0037 - 0.0009)/0.0009 + (0.0088 - 0.0046)/0.0046 + (0.0072 - 0.0033)/0.0033 + (0.0049 - 0.0022)/0.0022 ) / 5; //poly **** polys[0] = ( (0.0094-0.0043)/0.0043 + (0.0041-0.0018)/0.0018 + (0.0178-0.0084)/0.0084 + (0.0019-0.0065)/0.0065 + (0.0036-0.0029)/0.0029 ) /5; polys[1] = ( (0.0088-0.0122)/0.0122 + (0.0050-0.0064)/0.0064 + (0.0544-0.0057)/0.0057 ) / 3; polys[2] = 0; polys[3] = ( (0.0111 - 0.0059)/0.0059 + (0.0070 - 0.0009)/0.0009 + (0.0091 - 0.0046)/0.0046 + (0.0055 - 0.0033)/0.0033 + (0.0099 - 0.0022)/0.0022 ) / 5; //pow pows[0] = ( (0.0042-0.0043)/0.0043 + (0.0093-0.0018)/0.0018 + (0.026-0.0084)/0.0084 + (0.0183-0.0065)/0.0065 + (0.0082-0.0029)/0.0029 ) /5; pows[1] = ( (0.0022-0.0122)/0.0122 + (0.0031-0.0064)/0.0064 + (0.0052-0.0057)/0.0057 ) / 3; pows[2] = ( (0.0018-0.0254)/0.0254 + (0.0153-0.0120)/0.0120 + (0.0194-0.0105)/0.0105 + (0.0149-0.0102)/0.0102 ) / 4; pows[3] = ( (0.0058 - 0.0059)/0.0059 + (0.0009 - 0.0009)/0.0009 + (0.0045 - 0.0046)/0.0046 + (0.0047 - 0.0033)/0.0033 + (0.0021 - 0.0022)/0.0022 ) / 5; //dpow **** dpows[0] = ( (0.0005-0.0043)/0.0043 + (0.0093-0.0018)/0.0018 + (0.0261-0.0084)/0.0084 + (0.0183-0.0065)/0.0065 + (0.0082-0.0029)/0.0029 ) /5; dpows[1] = ( (0.0022-0.0122)/0.0122 + (0.0030-0.0064)/0.0064 + (0.0052-0.0057)/0.0057 ) / 3; dpows[2] = ( (0.0018-0.0254)/0.0254 + (0.0153-0.0120)/0.0120 + (0.0194-0.0105)/0.0105 + (0.0097-0.0102)/0.0102 ) / 4; dpows[3] = 0; TMultiGraph *mg = new TMultiGraph(); TGraph *comp = new TGraph(4, x,comps); TGraph *singE = new TGraph(4,x,singEs); TGraph *doubE = new TGraph(4,x,doubEs); TGraph *tripE = new TGraph(4,x,tripEs); TGraph *modE = new TGraph(4,x,modEs); TGraph *poly = new TGraph(4,x,polys); TGraph *pow = new TGraph(4,x,pows); TGraph *dpow = new TGraph(4,x,dpows); legend = new TLegend(0.64,0.64,0.92,0.94); //comp->GetXaxis()->SetBinLabel(1,"Single Exp."); dpow->GetXaxis()->SetBinLabel(1,"Double Exp."); //comp->GetXaxis()->SetBinLabel(3,"Triple Exp."); dpow->GetXaxis()->SetBinLabel(2,"Modified Exp."); dpow->GetXaxis()->SetBinLabel(3,"Polynomial"); //comp->GetXaxis()->SetBinLabel(6,"Single Power"); dpow->GetXaxis()->SetBinLabel(4,"Double Power"); singE->SetMarkerColor(bkgColors[0]); doubE->SetMarkerColor(bkgColors[1]); tripE->SetMarkerColor(bkgColors[2]); modE->SetMarkerColor(bkgColors[3]); poly->SetMarkerColor(bkgColors[4]); pow->SetMarkerColor(bkgColors[5]); dpow->SetMarkerColor(bkgColors[6]); comp->SetMarkerColor(28); singE->SetLineColor(bkgColors[0]); doubE->SetLineColor(bkgColors[1]); tripE->SetLineColor(bkgColors[2]); modE->SetLineColor(bkgColors[3]); poly->SetLineColor(bkgColors[4]); pow->SetLineColor(bkgColors[5]); dpow->SetLineColor(bkgColors[6]); comp->SetLineColor(28); legend->AddEntry(comp,"Composite","p"); legend->AddEntry(singE,"Single Exponential","p"); legend->AddEntry(doubE,"Double Exponential","p"); legend->AddEntry(tripE,"Triple Exponential","p"); legend->AddEntry(modE,"Modified Exponential","p"); legend->AddEntry(poly,"Polynomial","p"); legend->AddEntry(pow,"Power Law","p"); legend->AddEntry(dpow,"Double Power Law","p"); mg->Add(comp); mg->Add(singE); mg->Add(doubE); mg->Add(tripE); mg->Add(modE); mg->Add(poly); mg->Add(pow); mg->Add(dpow); //mg->GetYaxis()->SetRangeUser(-1,3); cv = new TCanvas("cv","cv",800,600); mg->Draw("apl"); legend->Draw(); cv->Update(); cv->SaveAs("BiasAverages.pdf"); }