// Make main selection plots // n-1, control type plots and plots after all cuts void makePlot(const TString & histoName, TFile * outputFile, TString anaType, const TString & xTitle, const double & xMin, const double & xMax, const double & yMin = 0., const double & yMax = 0., bool logY=false, const float lumi = 0, const bool plotData=false, bool drawRatioPlot=false ) { std::cout << "----> Making plots for : " << histoName.Data() << std::endl; std::cout << "Plotting data ? " << plotData << std::endl; TH1::SetDefaultSumw2(); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); // Keep track of integrals of background & data double totalBkgMCIntegral = 0; // double totalDataIntegral = 0; // // DATA // TH1F * histoData=0; if (plotData) { TFile * inputFile= new TFile ("CombinedFiles/Data_combined_"+anaType+".root", "READ"); histoData = (TH1F*)inputFile->Get(histoName); // totalDataIntegral = histoData->Integral(); histoData->SetStats(0); histoData->SetMarkerStyle(21); histoData->SetMarkerSize(1); } // // SIGNAL MC // // Not good at the moment - just taking one or two examples to plot and hard coded the names of the files here TFile * signalInputFile1= new TFile (signal1+anaType+".root", "READ"); TH1F * histoSignal1 = (TH1F*)signalInputFile1->Get(histoName); histoSignal1->SetStats(0); histoSignal1->Scale(lumi); TFile * signalInputFile2= new TFile (signal2+anaType+".root", "READ"); TH1F * histoSignal2 = (TH1F*)signalInputFile2->Get(histoName); histoSignal2->SetStats(0); histoSignal2->Scale(lumi); int minIntegral=0; int maxIntegral=histoSignal1->GetNbinsX(); // if ( histoName=="nMinus1_isolationLeptonH_removedLifetimeCuts" || histoName=="nMinus1_relIsolationLeptonH_removedLifetimeCuts" ) { // // std::cout << find90Cut( histoSignal1 ) << std::endl; // // std::cout << find90Cut( histoSignal2 ) << std::endl; // // minIntegral=histoSignal1->FindBin( find90Cut(histoSignal1) ); // // // Check integral below specific cut // if ( histoName=="nMinus1_relIsolationLeptonH_removedLifetimeCuts" ) { // std::cout << "Signal 1" << std::endl; // std::cout << "Efficiency with rel iso cut at 0.1 : " << histoSignal1->Integral( 1, histoSignal1->FindBin(0.1) ) / histoSignal1->Integral() << std::endl; // std::cout << "Efficiency with rel iso cut at 0.05 : " << histoSignal1->Integral( 1, histoSignal1->FindBin(0.05) ) / histoSignal1->Integral() << std::endl; // std::cout << "Signal 2" << std::endl; // std::cout << "Efficiency with rel iso cut at 0.1 : " << histoSignal2->Integral( 1, histoSignal2->FindBin(0.1) ) / histoSignal2->Integral() << std::endl; // std::cout << "Efficiency with rel iso cut at 0.05 : " << histoSignal2->Integral( 1, histoSignal2->FindBin(0.05) ) / histoSignal2->Integral() << std::endl; // } // } TFile * signalInputFile3= new TFile (signal3+anaType+".root", "READ"); TH1F * histoSignal3 = (TH1F*)signalInputFile3->Get(histoName); histoSignal3->SetStats(0); histoSignal3->Scale(lumi); // // BACKGROUND MC // THStack stack("Background MC",""); setPlotTitle(stack, lumi); // Add all different background MC to this stack TLegend *legend= new TLegend(0.5,0.6,0.85,0.85); totalBkgMCIntegral = addBackgroundHistos(anaType, histoName, stack, legend, lumi, minIntegral, maxIntegral); // if ( histoName=="nMinus1_isolationLeptonH_removedLifetimeCuts" || histoName=="nMinus1_relIsolationLeptonH_removedLifetimeCuts" ) { // std::cout << "Integral of background between " << minIntegral << " and " << maxIntegral << " : " << totalBkgMCIntegral << std::endl; // } // Output histograms to file outputFile->cd(); // Setup canvas TCanvas canvas(histoName); canvas.cd(); // Draw one or two pads TPad * up = new TPad("u","u",0.01,0.25,0.99,0.99); up->SetNumber(1); up->Draw(); TPad * dp = new TPad("d","d",0.01,0.01,0.99,0.25); if ( drawRatioPlot ) { dp->SetNumber(2); dp->UseCurrentStyle(); dp->Draw(); } else { up->SetPad(0.01,0.01,0.99,0.99); up->Draw(); } if ( logY ) up->SetLogy(); canvas.Draw(); canvas.cd(1); up->cd(); canvas.SetFillColor(kWhite); canvas.SetBorderMode(0); // Draw background MC // There may be zero entries, which will mess up drawing options // Not a good fix at the moment bool axesExist=false; if (totalBkgMCIntegral>0) { axesExist=true; stack.Draw("HISTE"); stack.GetXaxis()->SetRangeUser(xMin, xMax); stack.SetMaximum(yMax); stack.SetMinimum(yMin); stack.GetXaxis()->SetTitle(xTitle); stack.GetYaxis()->SetTitle("Entries"); } std::cout << "Drawing signal histos" << std::endl; // Draw signal MC histoSignal1->SetLineStyle(2); histoSignal1->SetLineColor(kMagenta+2); histoSignal1->SetLineWidth(2); if(axesExist) histoSignal1->Draw("same,HIST"); else histoSignal1->Draw("HIST"); histoSignal2->SetLineStyle(2); histoSignal2->SetLineColor(kGreen+2); histoSignal2->SetLineWidth(2); if(axesExist) histoSignal2->Draw("same,HIST"); else histoSignal2->Draw("HIST"); // histoSignal3->SetLineStyle(2); // histoSignal3->SetLineColor(4); // histoSignal3->SetLineWidth(2); // histoSignal3->Draw("same,HIST"); // Draw data if ( plotData ) { if (axesExist) histoData->Draw("same,P,E,X0"); else histoData->Draw("P,E,X0"); } // Draw legend legend->SetBorderSize(0); legend->SetFillStyle(0); if ( plotData ) legend->AddEntry(histoData,"data","p"); legend->AddEntry(histoSignal1,"m_{H}=1000 GeV/c^{2} m_{X}=350 GeV/c^{2}","l"); legend->AddEntry(histoSignal2,"m_{H}=400 GeV/c^{2} m_{X}=50 GeV/c^{2}","l"); // legend->AddEntry(histoSignal3,"m_{squark}=350 GeV/c^{2} m_{#Chi}=148 GeV/c^{2}","l"); legend->Draw(); canvas.Update(); // Draw mc/data ratio if ( drawRatioPlot ) { dp->cd(); TH1F ratioHist( drawMCDataRatio( ((TH1*)stack.GetStack()->Last()), histoData ) ); // Check content of ratioHist ratioHist.GetXaxis()->SetRangeUser(xMin, xMax); ratioHist.SetMarkerStyle(20); ratioHist.GetYaxis()->SetNdivisions(5,0,0); ratioHist.GetYaxis()->SetTickLength(0.01); dp->SetGridy(); ratioHist.Draw("P"); canvas.Update(); canvas.Write(); } else canvas.Write(); // Draw systematic errors for reco PV plot // FIXME For some reason, old canvas can't handle this! if ( histoName=="nRecoPV" ) { TGraphAsymmErrors gr( makePUPlot( stack, anaType, lumi ) ); // Move back to output file (as other files have been opened and closed in makePUPlot outputFile->cd(); gr.SetFillColor(1); gr.SetFillStyle(3001); gr.Draw("2P0"); canvas.Update(); // Test TCanvas can("puSystematic"); can.cd(); // can.SetLogy(); can.Draw(); gr.SetTitle("TGraphAsymmErrors Example"); stack.Draw("HISTE"); gr.Draw("2P0"); histoData->Draw("P,E,X0SAME"); legend->Draw(); can.Update(); can.Write(); } }