////////////////////////////////////////////////// // addXAxis - add X axis information unsigned int addXAxis(SEXP data, SEXP dataNames, unsigned int j, TH1* hist) { int n = hist->GetNbinsX(); TAxis* axis = hist->GetXaxis(); // Determine breaks-- // Add to list SEXP breaks = addNumericVector(data, dataNames, j++, n+1, "breaks"); // Get information for ( unsigned int i=0; i<n; ++i ) { NUMERIC_POINTER(breaks)[i] = axis->GetBinLowEdge(i+1); } // Add the high edge NUMERIC_POINTER(breaks)[n] = axis->GetBinUpEdge(n); // Determine mids-- SEXP mids = addNumericVector(data, dataNames, j++, n, "mids"); // Get information for ( unsigned int i=0; i<n; ++i ) { NUMERIC_POINTER(mids)[i] = axis->GetBinCenter(i+1); } // Get name of axis SEXP xname = addCharVector(data, dataNames, j++, 1, "xname"); SET_STRING_ELT( xname, 0, mkChar( axis->GetTitle() ) ); // Done return j; }
/** comapre axis for equalitiy * * check whether the cass histogram axis and the root histogram axis are the * same. Test for number of bins, low and high ends and the title of the axis. * * @return true when both axis are the same * @param ca the axis of the cass histogram * @param ra the axis of the root histogram * * @author Lutz Foucar */ bool operator== (const cass::Result<float>::axe_t &ca, const TAxis &ra) { return (static_cast<int>(ca.nBins) == ra.GetNbins() && fabs(ca.low - ra.GetXmin()) < sqrt(numeric_limits<double>::epsilon()) && fabs(ca.up - ra.GetXmax()) < sqrt(numeric_limits<double>::epsilon()) && ca.title == ra.GetTitle()); }
//______________________________________________________________________________ void drawsparse_draw(THnSparse* h) { // Draw a THnSparse using TParallelCoord, creating a temporary TTree. TTree* tree = toTree(h); TString whatToDraw; TIter iLeaf(tree->GetListOfLeaves()); const TLeaf* leaf = 0; while ((leaf = (const TLeaf*)iLeaf())) { if (whatToDraw.Length()) whatToDraw += ":"; whatToDraw += leaf->GetName(); } tree->Draw(whatToDraw, "", "para"); TParallelCoord* parallelCoord = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord"); TIter iVar(parallelCoord->GetVarList()); TParallelCoordVar* var = 0; for (Int_t d = 0;(var = (TParallelCoordVar*) iVar()) && d < h->GetNdimensions(); ++d) { TAxis* axis = h->GetAxis(d); var->SetHistogramBinning(axis->GetNbins()); var->SetCurrentLimits(axis->GetXmin(), axis->GetXmax()); var->SetTitle(axis->GetTitle()); } var->SetTitle("bin content"); }
// Calculate efficiency and clone+scale Function. TH1F *Signal_Hist(TH1F* tightH, Double_t Sigma, Double_t Lumi, Int_t AnzahlEvents,Bool_t EJet, Double_t &Efficiency, Bool_t withError) { TH1F *SignalH; char NewName[500], NewTitle[500], NewHist[1000]; Efficiency=((Double_t)tightH->Integral())/((Double_t)AnzahlEvents); //Effizienz: N_gesamt=sigma * Lumi; N_Schnitt=N_nachSchnitten/N_vorallenschnitten Efficiency=Efficiency*Sigma*Lumi; printf("Efficiency Signal: %f\n",Efficiency ); sprintf(NewName,"%s_Signal",tightH->GetName()); TAxis *xaxis = tightH ->GetXaxis(); TAxis *yaxis = tightH->GetYaxis(); Int_t Nbins=tightH->GetNbinsX(); // Double_t firstbinx= xaxis->GetBinLowEdge(1); // Double_t lastbin= xaxis->GetBinUpEdge(binzahl); const char* xTitle=xaxis->GetTitle(); const char* yTitle=yaxis->GetTitle(); sprintf(NewTitle,"%s - Signal-Histogram",xTitle); SignalH=(TH1F*)tightH->Clone(NewName); sprintf(NewHist,"%s;%s;%s",NewTitle, xTitle ,yTitle); Double_t scale=1./(tightH->Integral())*Efficiency; SignalH->Scale(scale); if(withError) for(Int_t i=0;i<Nbins;i++) { Double_t BinError=TMath::Sqrt(SignalH->GetBinContent(i+1)); SignalH->SetBinError(i+1,BinError); } return SignalH; }
inline TH1D* hGeV2TeV(TH1D* hGeV) { const Int_t nbins = hGeV->GetNbinsX(); Double_t bins[nbins+1]; TAxis* xaxis = (TAxis*)hGeV->GetXaxis(); TAxis* yaxis = (TAxis*)hGeV->GetYaxis(); for(int i=0 ; i<nbins ; i++) { bins[i] = xaxis->GetBinLowEdge(i+1)/1000.; cout << "|" << bins[i]; } bins[nbins] = xaxis->GetBinUpEdge(nbins)/1000.; cout << "|" << bins[nbins] << "|" << endl; TString name = (TString)hGeV->GetName(); TString title = (TString)hGeV->GetTitle(); TString xtitle = (TString)xaxis->GetTitle(); TString ytitle = (TString)yaxis->GetTitle(); TH1D* hTeV = new TH1D(name+"_TeV",title+";"+xtitle+";"+ytitle, nbins,bins); for(Int_t b=0 ; b<=nbins+1 ; b++) hTeV->SetBinContent(b, hGeV->GetBinContent(b)); return hTeV; }
TH1F *QCD_MatrixMethod_qcdhist(TH1F *looseH, TH1F *tightH, TH1F*epsqcd_hist, Double_t EpsSig, Double_t EpsSigErr,Bool_t makeGlobal, Double_t *NQCD_glob, Double_t *NQCD_glob_err, Bool_t witherror) { printf("we use the histo method for qcd determination!\n"); Double_t EpsQCD=0.0; Double_t EpsQCDErr=0.0; Int_t binhelp=0; TH1F *QCDH(0); char NewName[500], NewTitle[500], NewHist[1000]; sprintf(NewName,"%s_QCD",looseH->GetName()); TAxis *xaxis = looseH ->GetXaxis(); TAxis *yaxis = looseH->GetYaxis(); Int_t Nbins=looseH->GetNbinsX(); Double_t firstbinx= xaxis->GetBinLowEdge(1); Double_t lastbin= xaxis->GetBinUpEdge(Nbins); const char* xTitle=xaxis->GetTitle(); const char* yTitle=yaxis->GetTitle(); sprintf(NewTitle,"%s - QCD-Histogramm",xTitle); sprintf(NewHist,"%s;%s;%s",NewTitle, xTitle ,yTitle); // for global: number of QCD-Background alltogether Double_t NQCD_all=0.0, NQCD_all_Error=0.0 ; // The same idea as in QCD_MatrixMethod but this time assume Loose, // Tight and EpsilonQCD are histograms with several bins (instead of // scalar values). Thus calculate NQCD_all as a sum of corresponding // values per bin. for(Int_t i=0;i<Nbins;i++) { if(i<12) //just to have not too crappy values { binhelp=epsqcd_hist->FindBin(looseH->GetBinCenter(i+1)); EpsQCD=epsqcd_hist->GetBinContent(binhelp); EpsQCDErr=epsqcd_hist->GetBinError(binhelp); } Double_t NQCD_all_help=(EpsSig*looseH->GetBinContent(i+1)- tightH->GetBinContent(i+1))/(EpsSig - EpsQCD); // if(NQCD_all_help>0.0) NQCD_all+=EpsQCD*NQCD_all_help; Double_t N1=looseH->GetBinContent(i+1) - tightH->GetBinContent(i+1); // Double_t N1Error=TMath::Sqrt(N1); Double_t N1Error=TMath::Sqrt(pow(looseH->GetBinError(i+1),2.0) - pow(tightH->GetBinError(i+1),2.0)); Double_t N2=tightH->GetBinContent(i+1); // Double_t N2Error=TMath::Sqrt(N2); Double_t N2Error=tightH->GetBinError(i+1); Double_t NtQEpsSig=EpsQCD*(N2 - EpsQCD* (N1 + N2))/pow((EpsSig - EpsQCD),2); Double_t NtQEpsQCD=EpsSig*(EpsSig*(N1+N2) - N2 )/pow((EpsSig - EpsQCD),2); Double_t NtQN1=EpsQCD*EpsSig/(EpsSig - EpsQCD); Double_t NtQN2=EpsQCD*(EpsSig-1)/(EpsSig - EpsQCD); Double_t binContentErrorSquare=pow(NtQEpsSig,2)*pow(EpsSigErr,2) + pow(NtQEpsQCD,2)*pow(EpsQCDErr,2) + pow(NtQN1,2)*pow(N1Error,2) + pow(NtQN2,2)* pow(N2Error,2); Double_t binContentError=TMath::Sqrt(binContentErrorSquare); // if(NQCD_all_help>0.0) NQCD_all_Error+=binContentErrorSquare; // printf("Anzahl QCD gesamt:%f, Fehler dieser Anzahl:%f\n\n",NQCD_gesamt,NQCD_gesamt_Error); } // End loop over bins NQCD_all_Error=TMath::Sqrt(NQCD_all_Error); // End for global if(makeGlobal && NQCD_glob) { *NQCD_glob=NQCD_all; if(NQCD_glob_err) *NQCD_glob_err=NQCD_all_Error; return QCDH; } QCDH=new TH1F(NewName,NewHist,Nbins,firstbinx, lastbin); QCDH->Sumw2(); for(Int_t i=0;i<Nbins;i++) { if(i<12) //just to have not too crappy values { binhelp=epsqcd_hist->FindBin(looseH->GetBinCenter(i+1)); EpsQCD=epsqcd_hist->GetBinContent(binhelp); EpsQCDErr=epsqcd_hist->GetBinError(binhelp); } Double_t binContentloose=looseH->GetBinContent(i+1); Double_t binContenttight=tightH->GetBinContent(i+1); Double_t NQCD=(EpsSig*binContentloose - binContenttight)/(EpsSig - EpsQCD); Double_t binContent=EpsQCD*NQCD; // QCDEffizienz+= binContent; if(binContent <0.0) binContent=0.0; QCDH->SetBinContent(i+1,binContent); // printf("QCDEffizienz:%f\n",QCDEffizienz); if(witherror) { Double_t N1=binContentloose - binContenttight; // Double_t N1Error=TMath::Sqrt(N1); Double_t N1Error=TMath::Sqrt(looseH->GetBinError(i+1) - tightH->GetBinError(i+1)); Double_t N2=binContenttight; // Double_t N2Error=TMath::Sqrt(N2); Double_t N2Error=TMath::Sqrt(tightH->GetBinError(i+1)); Double_t NtQEpsSig=EpsQCD*(N2 - EpsQCD* (N1 + N2))/pow((EpsSig - EpsQCD),2); Double_t NtQEpsQCD=EpsSig*(EpsSig*(N1+N2) - N2 )/pow((EpsSig - EpsQCD),2); Double_t NtQN1=EpsQCD*EpsSig/(EpsSig - EpsQCD); Double_t NtQN2=EpsQCD*(EpsSig-1)/(EpsSig - EpsQCD); Double_t binContentErrorSquare=pow(NtQEpsSig,2)*pow(EpsSigErr,2) + pow(NtQEpsQCD,2)*pow(EpsQCDErr,2) + pow(NtQN1,2)*pow(N1Error,2) + pow(NtQN2,2)* pow(N2Error,2); Double_t binContentError=TMath::Sqrt(binContentErrorSquare); QCDH->SetBinError(i+1,binContentError); } } return QCDH; }
TH1F *QCD_MatrixMethod(TH1F *looseH, TH1F *tightH, Double_t EpsQCD, Double_t EpsSig, Double_t EpsQCDErr, Double_t EpsSigErr,Bool_t makeGlobal, Double_t *NQCD_glob, Double_t *NQCD_glob_err, Bool_t witherror,Double_t *NW_glob, Double_t *NW_glob_err) { TH1F *QCDH(0); char NewName[500], NewTitle[500], NewHist[1000]; sprintf(NewName,"%s_QCD",looseH->GetName()); TAxis *xaxis = looseH ->GetXaxis(); TAxis *yaxis = looseH->GetYaxis(); Int_t Nbins=looseH->GetNbinsX(); Double_t firstbinx= xaxis->GetBinLowEdge(1); Double_t lastbin= xaxis->GetBinUpEdge(Nbins); const char* xTitle=xaxis->GetTitle(); const char* yTitle=yaxis->GetTitle(); sprintf(NewTitle,"%s - QCD-Histogramm",xTitle); sprintf(NewHist,"%s;%s;%s",NewTitle, xTitle ,yTitle); // for global: number of QCD-Background alltogether Double_t NQCD_all=0.0, NQCD_all_Error=0.0 ; Double_t NW_all=0.0, NW_all_Error=0.0 ; // Functions with one bin only that would count how many loose or tight // events are there. TH1F *qcd_all_loose=new TH1F(hn(),"total number of QCD events",1,0.0,1.0); TH1F *qcd_all_tight=new TH1F(hn(),"total number of QCD events",1,0.0,1.0); qcd_all_loose->Sumw2(); qcd_all_tight->Sumw2(); // Count events for(Int_t i=0;i<=Nbins;i++) { Double_t binContentloose=looseH->GetBinContent(i+1); Double_t binContenttight=tightH->GetBinContent(i+1); qcd_all_loose->Fill(0.5,binContentloose); qcd_all_tight->Fill(0.5,binContenttight); } for(Int_t i=0;i<1;i++) { NQCD_all=(EpsSig*qcd_all_loose->GetBinContent(i+1)- qcd_all_tight->GetBinContent(i+1))/(EpsSig - EpsQCD); NQCD_all=EpsQCD*NQCD_all; Double_t N1=qcd_all_loose->GetBinContent(i+1) - qcd_all_tight->GetBinContent(i+1); // Double_t N1Error=TMath::Sqrt(N1); // Double_t N1Error=TMath::Sqrt(pow(qcd_all_loose->GetBinError(i+1),2.0) - pow(qcd_all_tight->GetBinError(i+1),2.0)); Double_t N1Error=TMath::Sqrt(N1); Double_t N2=qcd_all_tight->GetBinContent(i+1); // Double_t N2Error=TMath::Sqrt(N2); // Double_t N2Error=qcd_all_tight->GetBinError(i+1); Double_t N2Error=TMath::Sqrt(N2); Double_t NtQEpsSig=EpsQCD*(N2 - EpsQCD* (N1 + N2))/pow((EpsSig - EpsQCD),2); Double_t NtQEpsQCD=EpsSig*(EpsSig*(N1+N2) - N2 )/pow((EpsSig - EpsQCD),2); Double_t NtQN1=EpsQCD*EpsSig/(EpsSig - EpsQCD); Double_t NtQN2=EpsQCD*(EpsSig-1)/(EpsSig - EpsQCD); Double_t binContentErrorSquare=pow(NtQEpsSig,2)*pow(EpsSigErr,2) + pow(NtQEpsQCD,2)*pow(EpsQCDErr,2) + pow(NtQN1,2)*pow(N1Error,2) + pow(NtQN2,2)* pow(N2Error,2); Double_t binContentError=TMath::Sqrt(binContentErrorSquare); NQCD_all_Error=binContentError; // printf("N1: %f N2: %f\n", N1, N2); // printf("NtQEpsSig: %f NtQEpsQCD:%f %f %f %f\n", NtQEpsSig, NtQEpsQCD, N2 - EpsQCD* (N1 + N2), EpsSig*(N1+N2) - N2 , pow((EpsSig - EpsQCD),2)); // printf("the bin error: %f where value is %f\n", binContentError, NQCD_all); // printf("the single contributions: %f %f %f %f\n", pow(NtQEpsSig,2)*pow(EpsSigErr,2),pow(NtQEpsQCD,2)*pow(EpsQCDErr,2), pow(NtQN1,2)*pow(N1Error,2), pow(NtQN2,2)* pow(N2Error,2)); // printf("Anzahl QCD gesamt:%f, Fehler dieser Anzahl:%f\n\n",NQCD_gesamt,NQCD_gesamt_Error); } // End for global if(makeGlobal && NQCD_glob) { //set the NQCD value to 0 if it's smaller if(NQCD_all < 0.0) NQCD_all=0.0; *NQCD_glob=NQCD_all; if(NQCD_glob_err) *NQCD_glob_err=NQCD_all_Error; } for(Int_t i=0;i<1;i++) { NW_all=( qcd_all_tight->GetBinContent(i+1) - EpsQCD * qcd_all_loose->GetBinContent(i+1))/(EpsSig - EpsQCD); NW_all=EpsSig*NW_all; Double_t N1=qcd_all_loose->GetBinContent(i+1) - qcd_all_tight->GetBinContent(i+1); // Double_t N1Error=TMath::Sqrt(N1); // Double_t N1Error=TMath::Sqrt(pow(qcd_all_loose->GetBinError(i+1),2.0) - pow(qcd_all_tight->GetBinError(i+1),2.0)); Double_t N1Error=TMath::Sqrt(N1); Double_t N2=qcd_all_tight->GetBinContent(i+1); // Double_t N2Error=TMath::Sqrt(N2); // Double_t N2Error=qcd_all_tight->GetBinError(i+1); Double_t N2Error=TMath::Sqrt(N2); Double_t NtWEpsSig=EpsQCD*(N2 - EpsQCD* (N1 + N2))/pow((EpsSig - EpsQCD),2); Double_t NtWEpsQCD=EpsSig*(EpsSig*(N1+N2) - N2 )/pow((EpsSig - EpsQCD),2); Double_t NtWN1=EpsQCD*EpsSig/(EpsSig - EpsQCD); Double_t NtWN2=EpsSig*(1-EpsQCD)/(EpsSig - EpsQCD); Double_t binContentErrorSquare=pow(NtWEpsSig,2)*pow(EpsSigErr,2) + pow(NtWEpsQCD,2)*pow(EpsQCDErr,2) + pow(NtWN1,2)*pow(N1Error,2) + pow(NtWN2,2)* pow(N2Error,2); Double_t binContentError=TMath::Sqrt(binContentErrorSquare); NW_all_Error=binContentError; // printf("N1: %f N2: %f\n", N1, N2); // printf("NtQEpsSig: %f NtQEpsQCD:%f %f %f %f\n", NtQEpsSig, NtQEpsQCD, N2 - EpsQCD* (N1 + N2), EpsSig*(N1+N2) - N2 , pow((EpsSig - EpsQCD),2)); // printf("the bin error: %f where value is %f\n", binContentError, NQCD_all); // printf("the single contributions: %f %f %f %f\n", pow(NtQEpsSig,2)*pow(EpsSigErr,2),pow(NtQEpsQCD,2)*pow(EpsQCDErr,2), pow(NtQN1,2)*pow(N1Error,2), pow(NtQN2,2)* pow(N2Error,2)); // printf("Anzahl QCD gesamt:%f, Fehler dieser Anzahl:%f\n\n",NQCD_gesamt,NQCD_gesamt_Error); } // End for global if(makeGlobal && NW_glob) { //set the NQCD value to 0 if it's smaller if(NW_all < 0.0) NW_all=0.0; *NW_glob=NW_all; if(NW_glob_err) *NW_glob_err=NW_all_Error; return QCDH; } if(makeGlobal && NQCD_glob) { return QCDH; } // Create QCDH histogram QCDH=new TH1F(NewName,NewHist,Nbins,firstbinx, lastbin); QCDH->Sumw2(); for(Int_t i=0;i<Nbins;i++) { Double_t binContentloose=looseH->GetBinContent(i+1); Double_t binContenttight=tightH->GetBinContent(i+1); Double_t NQCD=(EpsSig*binContentloose - binContenttight)/(EpsSig - EpsQCD); Double_t binContent=EpsQCD*NQCD; // QCDEffizienz+= binContent; if(binContent <0.0) binContent=0.0; QCDH->SetBinContent(i+1,binContent); // printf("QCDEffizienz:%f\n",QCDEffizienz); if(witherror) { Double_t N1=binContentloose - binContenttight; // Double_t N1Error=TMath::Sqrt(N1); // Double_t N1Error=TMath::Sqrt(looseH->GetBinError(i+1) - tightH->GetBinError(i+1)); Double_t N1Error=TMath::Sqrt(N1); Double_t N2=binContenttight; // Double_t N2Error=TMath::Sqrt(N2); // Double_t N2Error=TMath::Sqrt(tightH->GetBinError(i+1)); Double_t N2Error=TMath::Sqrt(N2); Double_t NtQEpsSig=EpsQCD*(N2 - EpsQCD* (N1 + N2))/pow((EpsSig - EpsQCD),2); Double_t NtQEpsQCD=EpsSig*(EpsSig*(N1+N2) - N2 )/pow((EpsSig - EpsQCD),2); Double_t NtQN1=EpsQCD*EpsSig/(EpsSig - EpsQCD); Double_t NtQN2=EpsQCD*(EpsSig-1)/(EpsSig - EpsQCD); Double_t binContentErrorSquare=pow(NtQEpsSig,2)*pow(EpsSigErr,2) + pow(NtQEpsQCD,2)*pow(EpsQCDErr,2) + pow(NtQN1,2)*pow(N1Error,2) + pow(NtQN2,2)* pow(N2Error,2); Double_t binContentError=TMath::Sqrt(binContentErrorSquare); QCDH->SetBinError(i+1,binContentError); } } return QCDH; }
//------------------------------------------------------------------------------ //Subtraction //------------------------------------------------------------------------------ void Subtraction(TString hname, TString xtitle, Int_t ngroup = -1, Int_t precision = 1, TString units = "NULL", Double_t xmin = -999, Double_t xmax = 999, Bool_t moveOverflow = true) { TCanvas* canvas = new TCanvas(hname, hname, 800, 800); TPad* pad1 = new TPad("pad1", "pad1", 0, 0.0, 1, 1.0); pad1->SetTopMargin (0.08); //pad1->SetBottomMargin(0.02); pad1->Draw(); //---------------------------------------------------------------------------- // pad1 //---------------------------------------------------------------------------- pad1->cd(); pad1->SetLogy(_setLogy); TH1F* hist[nProcesses]; for (UInt_t ip=0; ip<nProcesses; ip++) { hist[ip] = (TH1F*)input[ip]->Get(hname); hist[ip]->SetName(hname + process[ip]); if (moveOverflow) MoveOverflowBins (hist[ip], xmin, xmax); else ZeroOutOfRangeBins(hist[ip], xmin, xmax); if (ngroup > 0) hist[ip]->Rebin(ngroup); if (_dataDriven && ip == iWW) hist[ip]->Scale(WWScale[_njet]); if (_dataDriven && ip == iDY) hist[ip]->Scale(ZjScale[_njet]); if (_dataDriven && ip == iDYtau) hist[ip]->Scale(ZjScale[_njet]); } // Data subtraction for Top background estimation //---------------------------------------------------------------------------- TH1F* subData = (TH1F*)hist[iData]->Clone("subData"); for (UInt_t ip=0; ip<nProcesses; ip++) { if (ip == itt) continue; if (ip == itW) continue; if (ip == iData ) continue; subData->Add(hist[ip],-1); } subData->SetLineColor(kRed+1); Double_t subData_Yield = subData->Integral(); //subData->SetLineColor(); // Top background //---------------------------------------------------------------------------- TH1F* Top = (TH1F*)hist[itt]->Clone("Top"); Top->Add(hist[itW]); Top->SetLineColor(kBlue+1); Double_t Top_Yield = Top->Integral(); // Axis labels //---------------------------------------------------------------------------- TAxis* xaxis = subData->GetXaxis(); TAxis* yaxis = subData->GetYaxis(); TString ytitle = Form("entries / %s.%df", "%", precision); xaxis->SetTitle(xtitle); yaxis->SetTitle(Form(ytitle.Data(), subData->GetBinWidth(0))); yaxis->SetTitleOffset(1.6); if (!units.Contains("NULL")) { xaxis->SetTitle(Form("%s [%s]", xaxis->GetTitle(), units.Data())); yaxis->SetTitle(Form("%s %s", yaxis->GetTitle(), units.Data())); } // Draw //---------------------------------------------------------------------------- xaxis->SetRangeUser(xmin, xmax); subData->Draw("hist"); Top->Draw("hist same"); // Adjust scale //---------------------------------------------------------------------------- subData->SetMinimum(0.0); Float_t theMax = GetMaximumIncludingErrors(subData, xmin, xmax); Float_t theMaxMC = GetMaximumIncludingErrors(Top, xmin, xmax); if (theMaxMC > theMax) theMax = theMaxMC; if (pad1->GetLogy()) { theMax = TMath::Power(10, TMath::Log10(theMax) + 2.7); subData->SetMinimum(0.05); } else theMax *= 1.55; subData->SetMaximum(theMax); // Legend //---------------------------------------------------------------------------- Double_t x0 = 0.720; Double_t y0 = 0.834; Double_t yoffset = 0.048; Double_t delta = yoffset + 0.001; Double_t ndelta = 0; DrawLegend(x0 - 0.49, y0 - ndelta, subData, Form(" Data Subtraction (MC without Top) (%.0f)", Yield(subData)), "l", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, Top, Form(" Top (%.0f)", Yield(Top)), "l", 0.03, 0.2, yoffset); ndelta += delta; // Additional titles //---------------------------------------------------------------------------- //TString channelLabel = "ee/#mu#mu/e#mu/#mue"; TString channelLabel = ""; //if (_channel == "EE") channelLabel = "ee"; //if (_channel == "MuMu") channelLabel = "#mu#mu"; //if (_channel == "EMu") channelLabel = "e#mu"; //if (_channel == "MuE") channelLabel = "#mue"; //if (_channel == "SF") channelLabel = "ee/#mu#mu"; //if (_channel == "OF") channelLabel = "e#mu/#mue"; channelLabel += Form(" %d", _njet); if (_njet == 0) channelLabel += "-jets"; if (_njet == 1) channelLabel += "-jet"; if (_njet >= 2) channelLabel += "-jets"; DrawTLatex(0.185, 0.975, 0.05, 13, channelLabel.Data(),""); DrawTLatex(0.940, 0.983, 0.05, 33, Form("L = %.1f fb^{-1}", _luminosity/1e3),""); if (Top_Yield!=0){ cout << "subData_Yield = "<<subData_Yield<<", Top_Yield = "<<Top_Yield<<", Ratio = "<< subData_Yield/Top_Yield <<endl; TLatex *tex3 = new TLatex(0.250, 0.75, "Scale Factor"); tex3->SetNDC(); tex3->SetTextSize(0.035); tex3->Draw(); TLatex *tex4 = new TLatex(0.250, 0.7, Form("%.0f / %.0f = %3.3f",subData_Yield ,Top_Yield ,subData_Yield/Top_Yield)); tex4->SetNDC(); tex4->SetTextSize(0.035); tex4->Draw(); } // Save //---------------------------------------------------------------------------- pad1->cd(); //SetAxis(subData, "", subData->GetYaxis()->GetTitle(), 0.05, 1.6); canvas->cd(); TString suffixLogy = (_setLogy) ? "_Log" : "_Lin"; canvas->SaveAs(Form("%s/%s%s_sub.%s", _output.Data(), hname.Data(), suffixLogy.Data(), _format.Data())); }
//------------------------------------------------------------------------------ // DrawHistogram //------------------------------------------------------------------------------ void DrawHistogram(TString hname, TString xtitle, Int_t ngroup = -1, Int_t precision = 1, TString units = "NULL", Double_t xmin = -999, Double_t xmax = 999, Bool_t moveOverflow = true) { //TCanvas* canvas = new TCanvas(hname, hname, 550, 720); TCanvas* canvas = new TCanvas(hname, hname, 800, 800); TPad* pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); TPad* pad2 = new TPad("pad2", "pad2", 0, 0.0, 1, 0.3); pad1->SetTopMargin (0.08); pad1->SetBottomMargin(0.02); pad1->Draw(); pad2->SetTopMargin (0.08); pad2->SetBottomMargin(0.35); pad2->Draw(); //---------------------------------------------------------------------------- // pad1 //---------------------------------------------------------------------------- pad1->cd(); pad1->SetLogy(_setLogy); THStack* hstack = new THStack(hname, hname); TH1F* hist[nProcesses]; //Save histograms to root file TFile* outfile; //TString fname = Form("files/%s_%djet.root", hname.Data(),_njet); TString fname = "files/0jet_"+hname+".root"; if(_njet==1) fname = "files/1jet_"+hname+".root"; outfile = new TFile(fname, "create"); TH1F* data; TH1F* top; TH1F* tW; TH1F* WW; TH1F* WZ; TH1F* ZZ; TH1F* Wg; TH1F* WgSMu; TH1F* WgSEl; TH1F* Wjets; TH1F* Zjets; TH1F* DYtau; TH1F* Zgamma; TH1F* ggH; for (UInt_t ip=0; ip<nProcesses; ip++) { hist[ip] = (TH1F*)input[ip]->Get(hname); hist[ip]->SetName(hname + process[ip]); hist[ip]->SetTitle(""); if(ip == iData) data = (TH1F*)hist[iData]->Clone("Data"); //data -> Sumw2(); if(ip == itt) top = (TH1F*)hist[itt]->Clone("top"); //top -> Sumw2(); if(ip == itW) tW = (TH1F*)hist[itW]->Clone("tW"); //tW -> Sumw2(); if(ip == iWW) WW = (TH1F*)hist[iWW]->Clone("WW"); //WW -> Sumw2(); if(ip == iWZ) WZ = (TH1F*)hist[iWZ]->Clone("WZ"); //VV -> Sumw2(); if(ip == iZZ) ZZ = (TH1F*)hist[iZZ]->Clone("ZZ"); //ZZ -> Sumw2(); if(ip == iWg) Wg = (TH1F*)hist[iWg]->Clone("Wg"); //Wg -> Sumw2(); if(ip == iWgSMu){ WgSMu = (TH1F*)hist[iWgSMu]->Clone("WgSMu"); //WgSMu -> Sumw2(); hist[iWgSMu]->Scale(1.5); } if(ip == iWgSEl){ WgSEl = (TH1F*)hist[iWgSEl]->Clone("WgSEl"); //WgSel -> Sumw2(); hist[iWgSEl]->Scale(1.5); //WgSel -> Sumw2(); } if(ip == iWj) Wjets = (TH1F*)hist[iWj]->Clone("W+jets"); //Wjets -> Sumw2(); if(ip == iDY) Zjets = (TH1F*)hist[iDY]->Clone("Z+jets"); //Zjets -> Sumw2(); if(ip == iDYtau) DYtau = (TH1F*)hist[iDYtau]->Clone("DYtau"); //DYtau -> Sumw2(); if(ip == iZgamma) Zgamma = (TH1F*)hist[iZgamma]->Clone("Zgamma"); //Zgamma -> Sumw2(); if(ip == iH125) ggH = (TH1F*)hist[iH125]->Clone("ggH"); //ggH -> Sumw2(); if (moveOverflow) MoveOverflowBins (hist[ip], xmin, xmax); else ZeroOutOfRangeBins(hist[ip], xmin, xmax); if (ngroup > 0) hist[ip]->Rebin(ngroup); if (ip == iWg) { //hist[ip]->Scale(0.01); } if (ip == iData) { hist[ip]->SetMarkerStyle(kFullCircle); } else { hist[ip]->SetFillColor(color[ip]); hist[ip]->SetFillStyle(1001); hist[ip]->SetLineColor(color[ip]); if (_dataDriven && ip == itt) hist[ip]->Scale(ttScale[_njet]); if (_dataDriven && ip == itW) hist[ip]->Scale(tWScale[_njet]); if (_dataDriven && ip == iWW) hist[ip]->Scale(WWScale[_njet]); if (_dataDriven && ip == iDY) hist[ip]->Scale(ZjScale[_njet]); if (_dataDriven && ip == iDYtau) hist[ip]->Scale(ZjScale[_njet]); if( ip != iZZ ) hstack->Add(hist[ip]);//TODO something wrong with ZZ } } if (_dataDriven) { top->Scale(ttScale[_njet]); tW->Scale(tWScale[_njet]); WW->Scale(WWScale[_njet]); Zjets->Scale(ZjScale[_njet]); DYtau->Scale(ZjScale[_njet]); } top ->Add(tW); //VV ->Add(ZZ); //VV ->Add(Wg); //Zjets->Add(DYtau); //Zjets->Add(Zgamma); data -> Write(); top -> Write(); WW -> Write(); //VV -> Write(); //Wjets -> Write(); //Zjets -> Write(); ggH -> Write(); outfile->Close(); // All MC //---------------------------------------------------------------------------- TH1F* allmc = (TH1F*)hist[iData]->Clone("allmc"); allmc->SetFillColor (kGray+2); allmc->SetFillStyle ( 3345); allmc->SetLineColor (kGray+2); allmc->SetMarkerColor(kGray+2); allmc->SetMarkerSize ( 0); for (UInt_t ibin=1; ibin<=allmc->GetNbinsX(); ibin++) { Double_t binValue = 0; Double_t binError = 0; for (UInt_t ip=0; ip<nProcesses; ip++) { if (ip == iData) continue; if (ip == iZZ) continue; Double_t binContent = hist[ip]->GetBinContent(ibin); binValue += binContent; binError += (hist[ip]->GetBinError(ibin) * hist[ip]->GetBinError(ibin)); //We need to calculate systematic uncertainty for ggH case // if (_dataDriven) // binError += (systError[ip]*binContent * systError[ip]*binContent); } binError = sqrt(binError); allmc->SetBinContent(ibin, binValue); allmc->SetBinError (ibin, binError); } // Axis labels //------------------------------------------------------------------ TAxis* xaxis = hist[iData]->GetXaxis(); TAxis* yaxis = hist[iData]->GetYaxis(); TString ytitle = Form("entries / %s.%df", "%", precision); xaxis->SetTitle(xtitle); yaxis->SetTitle(Form(ytitle.Data(), hist[iData]->GetBinWidth(0))); yaxis->SetTitleOffset(1.6); if (!units.Contains("NULL")) { xaxis->SetTitle(Form("%s [%s]", xaxis->GetTitle(), units.Data())); yaxis->SetTitle(Form("%s %s", yaxis->GetTitle(), units.Data())); } // Draw //-------------------------------------------------------------------- xaxis->SetRangeUser(xmin, xmax); hist[iData]->Draw("ep"); hstack ->Draw("hist,same"); allmc ->Draw("e2,same"); hist[iData]->Draw("ep,same"); // Adjust scale //---------------------------------------------------------------------------- Float_t theMax = GetMaximumIncludingErrors(hist[iData], xmin, xmax); Float_t theMaxMC = GetMaximumIncludingErrors(allmc, xmin, xmax); if (theMaxMC > theMax) theMax = theMaxMC; if (pad1->GetLogy()) { theMax = TMath::Power(10, TMath::Log10(theMax) + 2.7); hist[iData]->SetMinimum(0.05); } else theMax *= 1.55; hist[iData]->SetMaximum(theMax); // Legend //---------------------------------------------------------------------- Double_t x0 = 0.720; Double_t y0 = 0.834; Double_t yoffset = 0.048; Double_t delta = yoffset + 0.001; Double_t ndelta = 0; Double_t YieldTop = Yield(hist[itt]) + Yield(hist[itW]); Double_t YieldWZ = Yield(hist[iWZ]); Double_t YieldVV = Yield(hist[iWZ]) + Yield(hist[iZZ]) + Yield(hist[iWg]); //Double_t YieldZJets = Yield(hist[iDY]) + Yield(hist[iDYtau]); Double_t YieldZJets = Yield(hist[iDY]) + Yield(hist[iDYtau]) + Yield(hist[iZgamma]); DrawLegend(x0 - 0.49, y0 - ndelta, hist[iData], Form(" data (%.0f)", Yield(hist[iData])), "lp", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.23, y0 - ndelta, hist[itt], Form(" tt (%.0f)", Yield(hist[itt])), "f", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.23, y0 - ndelta, hist[itW], Form(" tW (%.0f)", Yield(hist[itW])), "f", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.49, y0 - ndelta, allmc, Form(" all (%.0f)", Yield(allmc)), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWW], Form(" WW (%.0f)", Yield(hist[iWW])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWZ], Form(" WZ (%.0f)", Yield(hist[iWZ])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWg], Form(" Wg (%.0f)", Yield(hist[iWg])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWgSMu], Form(" Wg*Mu (%.0f)", Yield(hist[iWgSMu])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWgSEl], Form(" Wg*El (%.0f)", Yield(hist[iWgSEl])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWj], Form(" W+jets (%.0f)",Yield(hist[iWj])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iZZ], Form(" ZZ (%.0f)", Yield(hist[iZZ])), "f", 0.03, 0.2, yoffset); ndelta += delta; ndelta = 0; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iDY], Form(" DY (%.0f)", Yield(hist[iDY])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iDYtau], Form(" DYtau (%.0f)", Yield(hist[iDYtau])),"f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iZgamma],Form(" Zg (%.0f)", Yield(hist[iZgamma])),"f", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.23, y0 - ndelta, hist[iDY], Form(" Z+jets (%.0f)", YieldZJets), "f", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.23, y0 - ndelta, hist[iH125], Form(" Higgs (%.0f)", Yield(hist[iH125])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iH125], Form(" ggH (%.0f)", Yield(hist[iH125])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[itt], Form(" tt (%.0f)", Yield(hist[itt])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[itW], Form(" tW (%.0f)", Yield(hist[itW])), "f", 0.03, 0.2, yoffset); ndelta += delta; // Additional titles //---------------------------------------------------------------------------- //TString channelLabel = "ee/#mu#mu/e#mu/#mue"; TString channelLabel = ""; //if (_channel == "EE") channelLabel = "ee"; //if (_channel == "MuMu") channelLabel = "#mu#mu"; //if (_channel == "EMu") channelLabel = "e#mu"; //if (_channel == "MuE") channelLabel = "#mue"; //if (_channel == "SF") channelLabel = "ee/#mu#mu"; //if (_channel == "OF") channelLabel = "e#mu/#mue"; channelLabel += Form(" %d", _njet); if (_njet == 0) channelLabel += "-jets"; if (_njet == 1) channelLabel += "-jet"; if (_njet >= 2) channelLabel += "-jets"; double nBin; double binWidth; nBin = allmc->GetSize(); nBin -=2; binWidth = allmc->GetBinWidth(2); int Z1bin=70/binWidth; int Z2bin=110/binWidth; cout<<"number of bin: "<<nBin<<endl; cout<<"Z bin1: "<<Z1bin<<" Z bin2: "<<Z2bin<<endl; double nMcZ, nDataZ; nMcZ = allmc->Integral(Z1bin,Z2bin); nDataZ = hist[iData]->Integral(Z1bin,Z2bin); double effiCorr; effiCorr=nDataZ/nMcZ; cout<<"efficiency correction factor: "<<effiCorr<<endl; double nMcGstar, nDataGstar, nMcGamma; nMcGstar = hist[iWgSMu]->Integral(1,2); nMcGamma = hist[iWg]->Integral(1,2); //nMcGstar = allmc->Integral(1,2); nMcGstar *= effiCorr; nMcGamma *= effiCorr; nDataGstar = hist[iData]->Integral(1,2); double Kfactor; double KfactorErr; nDataGstar -= nMcGamma; Kfactor = nDataGstar/nMcGstar; KfactorErr =Kfactor* TMath::Sqrt(nDataGstar/nDataGstar/nDataGstar + nMcGstar/nMcGstar/nMcGstar); KfactorErr += 0.1; cout<<"Kfactor: "<<Kfactor<<"+"<<KfactorErr<<endl; //DrawTLatex(0.185, 0.975, 0.05, 13, channelLabel.Data(),""); DrawTLatex(0.940, 0.983, 0.05, 33, Form("L = %.1f fb^{-1}", _luminosity/1e3),""); DrawTLatex(0.45, 0.48, 0.04, 13, Form("K factor (Data/Wg*) = %.2f #pm %.2f", Kfactor, KfactorErr ),""); DrawTLatex(0.45, 0.43, 0.04, 13, Form("0< InvM(#mu^{+}#mu^{-}) <4 GeV"),""); //---------------------------------------------------------------------------- // pad2 //---------------------------------------------------------------------------- pad2->cd(); TH1F* ratio = (TH1F*)hist[iData]->Clone("ratio"); TH1F* uncertainty = (TH1F*)allmc->Clone("uncertainty"); for (UInt_t ibin=1; ibin<=ratio->GetNbinsX(); ibin++) { Double_t mcValue = allmc->GetBinContent(ibin); Double_t mcError = allmc->GetBinError (ibin); Double_t dtValue = ratio->GetBinContent(ibin); Double_t dtError = ratio->GetBinError (ibin); Double_t ratioValue = (mcValue > 0) ? dtValue/mcValue : 0.0; Double_t ratioError = (mcValue > 0) ? dtError/mcValue : 0.0; Double_t uncertaintyError = (mcValue > 0) ? mcError/mcValue : 0.0; ratio->SetBinContent(ibin, ratioValue); ratio->SetBinError (ibin, ratioError); uncertainty->SetBinContent(ibin, 1.0); uncertainty->SetBinError (ibin, uncertaintyError); } TAxis* uaxis = (TAxis*)uncertainty->GetXaxis(); uaxis->SetRangeUser(xmin, xmax); uncertainty->Draw("e2"); ratio ->Draw("ep,same"); uncertainty->GetYaxis()->SetRangeUser(0, 2.5); // Save //---------------------------------------------------------------------- pad2->cd(); SetAxis(uncertainty, hist[iData]->GetXaxis()->GetTitle(), "data / prediction", 0.10, 0.8); pad1->cd(); SetAxis(hist[iData], "", hist[iData]->GetYaxis()->GetTitle(), 0.05, 1.6); canvas->cd(); TString suffixLogy = (_setLogy) ? "_Log" : "_Lin"; canvas->SaveAs(Form("%s/%s%s.%s", _output.Data(), hname.Data(), suffixLogy.Data(), _format.Data())); }
//------------------------------------------------------------------------------ // DrawHistogram //------------------------------------------------------------------------------ void DrawHistogram(TString hname, TString xtitle, Int_t ngroup = -1, Int_t precision = 1, TString units = "NULL", Double_t xmin = -999, Double_t xmax = 999, Bool_t moveOverflow = true) { //TCanvas* canvas = new TCanvas(hname, hname, 550, 720); TCanvas* canvas = new TCanvas(hname, hname, 800, 800); TPad* pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); TPad* pad2 = new TPad("pad2", "pad2", 0, 0.0, 1, 0.3); pad1->SetTopMargin (0.08); pad1->SetBottomMargin(0.02); pad1->Draw(); pad2->SetTopMargin (0.08); pad2->SetBottomMargin(0.35); pad2->Draw(); //---------------------------------------------------------------------------- // pad1 //---------------------------------------------------------------------------- pad1->cd(); pad1->SetLogy(_setLogy); THStack* hstack = new THStack(hname, hname); TH1F* hist[nProcesses]; TH1F* hist_0[nProcesses]; // 0-jet TH1F* hist_1[nProcesses]; // 1-jet for (UInt_t ip=0; ip<nProcesses; ip++) { if( _njet == 10 ){ hist_0[ip] = (TH1F*)input_0[ip]->Get(hname); hist_1[ip] = (TH1F*)input_1[ip]->Get(hname); }else{ //hist[ip] = (TH1F*)input[ip]->Get(hname); //hist[ip]->SetName(hname + process[ip]); } if (moveOverflow){ if(_njet ==10){ MoveOverflowBins (hist_0[ip], xmin, xmax); MoveOverflowBins (hist_1[ip], xmin, xmax); }else{ //MoveOverflowBins (hist[ip], xmin, xmax); } }else{ if(_njet == 10){ ZeroOutOfRangeBins(hist_0[ip], xmin, xmax); ZeroOutOfRangeBins(hist_1[ip], xmin, xmax); }else{ //ZeroOutOfRangeBins(hist[ip], xmin, xmax); } } if (ngroup > 0){ if(_njet == 10){ hist_0[ip]->Rebin(ngroup); hist_1[ip]->Rebin(ngroup); }else{ //hist[ip]->Rebin(ngroup); } } // Add 0, 1 jet if (ip == iData) { if(_njet == 10 ){ hist[ip] = (TH1F*)hist_0[ip]->Clone(hname+process[ip]); hist[ip]->Add(hist_1[ip]); hist[ip]->SetMarkerStyle(kFullCircle); }else{ //hist[ip]->SetMarkerStyle(kFullCircle); } } else { if(_njet == 10){ if (_dataDriven && ip == itt) hist_0[ip]->Scale(ttScale[0]); if (_dataDriven && ip == itW) hist_0[ip]->Scale(tWScale[0]); if (_dataDriven && ip == iWW) hist_0[ip]->Scale(WWScale[0]); if (_dataDriven && ip == iDY) hist_0[ip]->Scale(ZjScale[0]); if (_dataDriven && ip == iDYtau) hist_0[ip]->Scale(ZjScale[0]); if (_dataDriven && ip == itt) hist_1[ip]->Scale(ttScale[1]); if (_dataDriven && ip == itW) hist_1[ip]->Scale(tWScale[1]); if (_dataDriven && ip == iWW) hist_1[ip]->Scale(WWScale[1]); if (_dataDriven && ip == iDY) hist_1[ip]->Scale(ZjScale[1]); if (_dataDriven && ip == iDYtau) hist_1[ip]->Scale(ZjScale[1]); hist[ip] = (TH1F*)hist_0[ip]->Clone(hname+process[ip]); hist[ip]->Add(hist_1[ip]); hist[ip]->SetFillColor(color[ip]); hist[ip]->SetFillStyle(1001); hist[ip]->SetLineColor(color[ip]); }else{ //hist[ip]->SetFillColor(color[ip]); //hist[ip]->SetFillStyle(1001); //hist[ip]->SetLineColor(color[ip]); //if (_dataDriven && ip == itt) hist[ip]->Scale(ttScale[_njet]); //if (_dataDriven && ip == itW) hist[ip]->Scale(tWScale[_njet]); //if (_dataDriven && ip == iWW) hist[ip]->Scale(WWScale[_njet]); //if (_dataDriven && ip == iDY) hist[ip]->Scale(ZjScale[_njet]); //if (_dataDriven && ip == iDYtau) hist[ip]->Scale(ZjScale[_njet]); } hstack->Add(hist[ip]); } } //========================================================= //Save histograms to root file to draw paper style plots //========================================================= //TFile* outfile; //TString fname = Form("files/%s_%djet.root", hname.Data(),_njet); //TString fname = "files/0jet_"+hname+".root"; //if(_njet==1) fname = "files/1jet_"+hname+".root"; //if(_njet==10) fname = "files/10jet_"+hname+".root"; //outfile = new TFile(fname, "create"); //if(ip == iData) TH1F* data = (TH1F*)hist[iData]->Clone("Data"); //data -> Sumw2(); //if(ip == itt) TH1F* top = (TH1F*)hist[itt]->Clone("top"); //top -> Sumw2(); //if(ip == itW) TH1F* tW = (TH1F*)hist[itW]->Clone("tW"); //tW -> Sumw2(); //if(ip == iWW) TH1F* WW = (TH1F*)hist[iWW]->Clone("WW"); //WW -> Sumw2(); //if(ip == iWZ) TH1F* VVandVVV = (TH1F*)hist[iWZ]->Clone("VVandVVV"); //VV -> Sumw2(); //if(ip == iZZ) TH1F* ZZ = (TH1F*)hist[iZZ]->Clone("ZZ"); //ZZ -> Sumw2(); //if(ip == iWg) TH1F* Wg = (TH1F*)hist[iWg]->Clone("Wg"); //Wg -> Sumw2(); //if(ip == iWj) TH1F* Wjets = (TH1F*)hist[iWj]->Clone("W+jets"); //Wjets -> Sumw2(); //if(ip == iDY) TH1F* Zjets = (TH1F*)hist[iDY]->Clone("Z+jets"); //Zjets -> Sumw2(); //if(ip == iDYtau) TH1F* DYtau = (TH1F*)hist[iDYtau]->Clone("DYtau"); //DYtau -> Sumw2(); //if(ip == iZgamma) TH1F* Zgamma = (TH1F*)hist[iZgamma]->Clone("Zgamma"); //Zgamma -> Sumw2(); //if(ip == iH125) TH1F* ggH = (TH1F*)hist[iH125]->Clone("ggH"); //ggH -> Sumw2(); // //top -> Add(tW); //VVandVVV -> Add(ZZ); //VVandVVV -> Add(Wg); //Zjets -> Add(DYtau); //Zjets -> Add(Zgamma); // //data -> Write(); //top -> Write(); //WW -> Write(); //VVandVVV -> Write(); //Wjets -> Write(); //Zjets -> Write(); //ggH -> Write(); // //outfile -> Close(); // //========================================================= //Draw paper style plots //========================================================= //Use LatinoPlotTools. //As input root file, use above saved root file "outfile" //Run the following executable file: //https://github.com/latinos/LatinoPlotTools/blob/master/WWRunI/scripts/doHWidth_Top_control.sh // All MC //---------------------------------------------------------------------------- TH1F* allmc = (TH1F*)hist[iData]->Clone("allmc"); allmc->SetFillColor (kGray+2); allmc->SetFillStyle ( 3345); allmc->SetLineColor (kGray+2); allmc->SetMarkerColor(kGray+2); allmc->SetMarkerSize ( 0); for (UInt_t ibin=1; ibin<=allmc->GetNbinsX(); ibin++) { Double_t binValue = 0; Double_t binError = 0; for (UInt_t ip=0; ip<nProcesses; ip++) { if (ip == iData) continue; Double_t binContent = hist[ip]->GetBinContent(ibin); binValue += binContent; binError += (hist[ip]->GetBinError(ibin) * hist[ip]->GetBinError(ibin)); //We need to calculate systematic uncertainty for ggH case // if (_dataDriven) // binError += (systError[ip]*binContent * systError[ip]*binContent); } binError = sqrt(binError); allmc->SetBinContent(ibin, binValue); allmc->SetBinError (ibin, binError); } // Axis labels //---------------------------------------------------------------------------- TAxis* xaxis = hist[iData]->GetXaxis(); TAxis* yaxis = hist[iData]->GetYaxis(); TString ytitle = Form("entries / %s.%df", "%", precision); xaxis->SetTitle(xtitle); yaxis->SetTitle(Form(ytitle.Data(), hist[iData]->GetBinWidth(0))); yaxis->SetTitleOffset(1.6); if (!units.Contains("NULL")) { xaxis->SetTitle(Form("%s [%s]", xaxis->GetTitle(), units.Data())); yaxis->SetTitle(Form("%s %s", yaxis->GetTitle(), units.Data())); } // Draw //---------------------------------------------------------------------------- xaxis->SetRangeUser(xmin, xmax); hist[iData]->Draw("ep"); hstack ->Draw("hist,same"); allmc ->Draw("e2,same"); hist[iData]->Draw("ep,same"); // Adjust scale //---------------------------------------------------------------------------- Float_t theMax = GetMaximumIncludingErrors(hist[iData], xmin, xmax); Float_t theMaxMC = GetMaximumIncludingErrors(allmc, xmin, xmax); if (theMaxMC > theMax) theMax = theMaxMC; if (pad1->GetLogy()) { theMax = TMath::Power(10, TMath::Log10(theMax) + 2.7); hist[iData]->SetMinimum(0.05); } else theMax *= 1.55; hist[iData]->SetMaximum(theMax); // Legend //---------------------------------------------------------------------------- Double_t x0 = 0.720; Double_t y0 = 0.834; Double_t yoffset = 0.048; Double_t delta = yoffset + 0.001; Double_t ndelta = 0; Double_t YieldTop = Yield(hist[itt]) + Yield(hist[itW]); Double_t YieldVV = Yield(hist[iWZ]) + Yield(hist[iZZ]) + Yield(hist[iWg]); //Double_t YieldZJets = Yield(hist[iDY]) + Yield(hist[iDYtau]); Double_t YieldZJets = Yield(hist[iDY]) + Yield(hist[iDYtau]) + Yield(hist[iZgamma]); DrawLegend(x0 - 0.49, y0 - ndelta, hist[iData], Form(" data (%.0f)", Yield(hist[iData])), "lp", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, allmc, Form(" all (%.0f)", Yield(allmc)), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWW], Form(" WW (%.0f)", Yield(hist[iWW])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.49, y0 - ndelta, hist[iWZ], Form(" VV (%.0f)", YieldVV), "f", 0.03, 0.2, yoffset); ndelta += delta; ndelta = 0; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iDY], Form(" Z+jets (%.0f)", YieldZJets), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iWj], Form(" W+jets (%.0f)", Yield(hist[iWj])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[itt], Form(" top (%.0f)", YieldTop), "f", 0.03, 0.2, yoffset); ndelta += delta; //DrawLegend(x0 - 0.23, y0 - ndelta, hist[iH125], Form(" Higgs (%.0f)", Yield(hist[iH125])), "f", 0.03, 0.2, yoffset); ndelta += delta; DrawLegend(x0 - 0.23, y0 - ndelta, hist[iH125], Form(" ggH (%.0f)", Yield(hist[iH125])), "f", 0.03, 0.2, yoffset); ndelta += delta; // Additional titles //---------------------------------------------------------------------------- //TString channelLabel = "ee/#mu#mu/e#mu/#mue"; TString channelLabel = ""; //if (_channel == "EE") channelLabel = "ee"; //if (_channel == "MuMu") channelLabel = "#mu#mu"; //if (_channel == "EMu") channelLabel = "e#mu"; //if (_channel == "MuE") channelLabel = "#mue"; //if (_channel == "SF") channelLabel = "ee/#mu#mu"; //if (_channel == "OF") channelLabel = "e#mu/#mue"; if( _njet != 10) channelLabel += Form(" %d", _njet); if (_njet == 0) channelLabel += "-jets"; if (_njet == 1) channelLabel += "-jet"; if (_njet >= 2 && _njet!= 10) channelLabel += "-jets"; if ( _njet== 10) channelLabel += "SS 0+1 jets"; DrawTLatex(0.185, 0.975, 0.05, 13, channelLabel.Data()); DrawTLatex(0.940, 0.983, 0.05, 33, Form("L = %.1f fb^{-1}", _luminosity/1e3)); //---------------------------------------------------------------------------- // pad2 //---------------------------------------------------------------------------- pad2->cd(); TH1F* ratio = hist[iData]->Clone("ratio"); TH1F* uncertainty = allmc->Clone("uncertainty"); for (UInt_t ibin=1; ibin<=ratio->GetNbinsX(); ibin++) { Double_t mcValue = allmc->GetBinContent(ibin); Double_t mcError = allmc->GetBinError (ibin); Double_t dtValue = ratio->GetBinContent(ibin); Double_t dtError = ratio->GetBinError (ibin); Double_t ratioValue = (mcValue > 0) ? dtValue/mcValue : 0.0; Double_t ratioError = (mcValue > 0) ? dtError/mcValue : 0.0; Double_t uncertaintyError = (mcValue > 0) ? mcError/mcValue : 0.0; ratio->SetBinContent(ibin, ratioValue); ratio->SetBinError (ibin, ratioError); uncertainty->SetBinContent(ibin, 1.0); uncertainty->SetBinError (ibin, uncertaintyError); } TAxis* uaxis = (TAxis*)uncertainty->GetXaxis(); uaxis->SetRangeUser(xmin, xmax); uncertainty->Draw("e2"); ratio ->Draw("ep,same"); uncertainty->GetYaxis()->SetRangeUser(0, 2.5); // Save //---------------------------------------------------------------------------- pad2->cd(); SetAxis(uncertainty, hist[iData]->GetXaxis()->GetTitle(), "data / prediction", 0.10, 0.8); pad1->cd(); SetAxis(hist[iData], "", hist[iData]->GetYaxis()->GetTitle(), 0.05, 1.6); canvas->cd(); TString suffixLogy = (_setLogy) ? "_Log" : "_Lin"; canvas->SaveAs(Form("%s/%s%s.%s", _output.Data(), hname.Data(), suffixLogy.Data(), _format.Data())); }