void TPTiming () { TAxis * ax = TPMatchEmul2D->GetZaxis() ; ax->SetRangeUser(-1,6) ; TCanvas* canv = new TCanvas("canv", "canv") ; canv->SetLogz(0) ; gStyle->SetOptStat(10) ; int color[10]= {1,10,3,4,5,6,7,8,9,2} ; gStyle->SetPalette(7, color) ; TPMatchEmul2D->GetXaxis()->SetTitle("Phi index"); TPMatchEmul2D->GetYaxis()->SetTitle("Eta index"); TPMatchEmul2D->Draw("colz") ; TH2I * label = new TH2I("label", "",72, 1, 73, 38, -19, 19) ; label->SetMarkerSize(0.6); label->SetBit(kCanDelete); for (int x=3 ; x<73 ; x+=4) { for (int y=21; y<=37; y++) { int towernb = 4*(y-21)+1 ; label->SetBinContent(x-1, y, towernb) ; //EB+ label->SetBinContent(x, 40-y, towernb) ; //EB- } } label->Draw("same text") ; TLatex txt; txt.SetTextSize(0.02); TLine line; line.SetLineColor(1) ; line.SetLineStyle(1) ; line.SetLineWidth(1) ; TAxis* xAxis = TPMatchEmul2D->GetXaxis(); TAxis* yAxis = TPMatchEmul2D->GetYaxis(); // draw SM borders and numbers float sm ; for (int i=0; i<36 ; i++ ) { if (i<18) { sm = 4*i+3 ; line.DrawLine(sm, 1, sm, 18) ; txt.SetTextAlign(32); txt.DrawText(sm-1+0.3, -17.7, Form("-%d",i+1)); } else { sm = 4*(i-18)+3 ; line.DrawLine(sm, 0, sm, -17) ; txt.SetTextAlign(12); txt.DrawText(sm-2+0.3, 18.5, Form("+%d",i-17)); } } line.DrawLine(1, 0, 73, 0) ; line.DrawLine(1, -17, 73, -17) ; line.DrawLine(1, 1, 73, 1) ; line.DrawLine(1, 18, 73, 18) ; }
//________________________________________________________________ void KVCanvas::ZoomSelected(TH2* TheHisto) { if (!TheHisto) return; TAxis* ax = TheHisto->GetXaxis(); Double_t ratio1 = (xmin - GetUxmin()) / (GetUxmax() - GetUxmin()); Double_t ratio2 = (xmax - GetUxmin()) / (GetUxmax() - GetUxmin()); if ((ratio2 - ratio1 > 0.05)) ax->SetRangeUser(xmin, xmax); ax = TheHisto->GetYaxis(); ratio1 = (ymin - GetUymin()) / (GetUymax() - GetUymin()); ratio2 = (ymax - GetUymin()) / (GetUymax() - GetUymin()); if ((ratio2 - ratio1 > 0.05)) ax->SetRangeUser(ymin, ymax); xmax = xmin = ymax = ymin = 0.; return; }
void plotImportance(const char* canvas, const char* title, const unsigned nVars, const char vars[][200], const double* importance, const double* error, bool automaticRange=false) { TCanvas *c = new TCanvas(canvas,"SPR Variable Importance",200,10,600,400); gStyle->SetPalette(1); TH1D* h1 = new TH1D("importance",title,nVars,0,nVars); double ymin(0), ymax(0); for( int i=0;i<nVars;i++ ) { h1->Fill(vars[i],importance[i]); if( automaticRange ) { ymin = ( ymin>importance[i] ? importance[i] : ymin ); ymax = ( ymax<importance[i] ? importance[i] : ymax ); } } if( automaticRange ) { ymin = ( ymin<0 ? ymin*1.2 : ymin*0.8 ); ymax *= 1.2; } else { ymin = 0.; ymax = 1.; } if( error == 0 ) { for( int i=0;i<nVars;i++ ) h1->SetBinError(i+1,0.); } else { for( int i=0;i<nVars;i++ ) h1->SetBinError(i+1,error[i]); } h1->LabelsDeflate("X"); h1->LabelsOption("v"); h1->SetLabelSize(0.06,"X"); h1->SetLineColor(4); h1->SetMarkerStyle(21); h1->SetMarkerColor(4); h1->SetLineWidth(2); TAxis* yaxis = h1->GetYaxis(); yaxis->SetRangeUser(ymin,ymax); if( error == 0 ) { h1->SetLineColor(4); h1->SetFillColor(4); h1->SetBarWidth(0.8); h1->SetBarOffset(0.1); h1->Draw("B"); } else h1->Draw("E0P"); l = new TLine(0,0,nVars,0); l->Draw(); }
void showHistograms(double canvasSizeX, double canvasSizeY, TH1* histogram, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.15); canvas->SetBottomMargin(0.15); canvas->SetLogy(useLogScale); histogram->SetTitle(""); histogram->SetStats(true); histogram->SetMinimum(yMin); histogram->SetMaximum(yMax); histogram->SetLineColor(1); histogram->SetLineWidth(2); histogram->SetMarkerColor(1); histogram->SetMarkerStyle(20); histogram->SetMarkerSize(1.5); histogram->Draw("hist"); TAxis* xAxis = histogram->GetXaxis(); xAxis->SetRangeUser(xMin, xMax); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleSize(0.060); xAxis->SetTitleOffset(xAxisOffset); xAxis->SetLabelSize(0.050); xAxis->SetNdivisions(505); TAxis* yAxis = histogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleSize(0.060); yAxis->SetTitleOffset(yAxisOffset); yAxis->SetLabelSize(0.050); yAxis->SetNdivisions(505); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScale ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); //canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete canvas; }
// === FUNCTION ============================================================ // Name: TPlot::Compare1D // Description: // =========================================================================== bool TPlot::Compare1D(std::string histname) { std::vector<PlotID> vth1; for(unsigned int i=0; i < plist.size(); ++i) { PlotID temp; temp.name = histname; temp.det = plist.at(i).first; temp.algo = plist.at(i).second; temp.marker = detMark[temp.det]; temp.color = algColor[temp.algo]; temp.hist = GetHist1D(histname, temp.det, temp.algo); vth1.push_back(temp); } TCanvas *c1 = new TCanvas("Canvas", "Yes, another Canvas", 10, 10, 800, 600); TLegend *leg = new TLegend(0.660804,0.5776614,0.959799,0.9319372,NULL,"brNDC"); TAxis* xaxis = NULL; TAxis* yaxis = NULL; double Ymax = 0; double ingl = 0; for(unsigned int i=0; i < vth1.size(); ++i) { PlotID plot1D = vth1.at(i); // Set Marker and Color plot1D.hist->SetMarkerStyle(plot1D.marker); plot1D.hist->SetMarkerColor(plot1D.color); plot1D.hist->SetLineColor(plot1D.color); plot1D.hist->SetLineWidth(1); plot1D.hist->SetMarkerSize(1); /*if (histname.find("TauEta") != std::string::npos)*/ /*{*/ /*plot1D.hist->Rebin(10);*/ /*}*/ //if (histname.find("Response") == std::string::npos && //histname.find("Resolution") == std::string::npos) { ////plot1D.hist->Rebin(2); //} // Draw if (i == 0) { plot1D.hist->Draw("PE"); xaxis = plot1D.hist->GetXaxis(); yaxis = plot1D.hist->GetYaxis(); ingl = plot1D.hist->Integral(); } else { if (histname.find("Response") == std::string::npos && histname.find("Resolution") == std::string::npos) { /*plot1D.hist->Scale(ingl / plot1D.hist->Integral());*/ } plot1D.hist->Draw("samepe"); } // Add Legend std::stringstream ss; ss << plot1D.det << " " << plot1D.algo; leg->AddEntry(plot1D.hist, ss.str().c_str(), "lp" ); // Get Yaxis maximun Ymax = plot1D.hist->GetMaximum() > Ymax ? plot1D.hist->GetMaximum() : Ymax; yaxis->SetRangeUser(0.0, 1.2*Ymax); } SetPlotStyle(histname, c1, leg, xaxis, yaxis); leg->Draw(); for(std::set<std::string>::const_iterator it=vformat.begin(); it!=vformat.end(); ++it) { std::stringstream ss; ss << histname <<"." << *it; c1->Update(); c1->SaveAs(ss.str().c_str()); } delete c1; delete leg; return true; } // ----- end of function TPlot::Compare1D -----
void Plot::FitSignal(int mode, int fitMode) { const int nPar = 6; TRandom ran; if(mode==0) { gStyle->SetOptLogy(1); } else { gStyle->SetOptLogy(0); } gStyle->SetOptStat(0); gStyle->SetOptTitle(0); const float limitBinSize = 2.0; // **** bin size here TCanvas* c = NewCanvas(); c->Divide(1,2); gROOT->cd(); TH1F* cc = new TH1F("CCSignal","CC Signal",500,0.0,1000.0); TH1F* ccBg = new TH1F("CCBgFit","CC Bg Fit",500,0.0,1000.0); TH1F* ccBgErr = new TH1F("CCBgErr","CC Bg Err",500,0.0,1000.0); TH1F* ccBgP = new TH1F("CCBgPlus","CC Bg Plus",500,0.0,1000.0); TH1F* ccBgM = new TH1F("CCBgMinus","CC Bg Minus",500,0.0,1000.0); TH1F* cp = new TH1F("CPSignal","CP Signal",500,0.0,1000.0); TH1F* cpBg = new TH1F("CPBgFit","CP Bg Fit",500,0.0,1000.0); TH1F* cpBgErr = new TH1F("CPBgErr","CP Bg Err",500,0.0,1000.0); TH1F* cpBgP = new TH1F("CPBgPlus","CP Bg Plus",500,0.0,1000.0); TH1F* cpBgM = new TH1F("CPBgMinus","CP Bg Minus",500,0.0,1000.0); TMatrixD matrix(nPar,nPar); fd->cd(); TH1F* hInt,*hBgInt; char fitname[100]; for(int ind=0; ind<2; ind++) { if(debug) printf("starting ind %i\n",ind); c->cd(ind+1); gStyle->SetOptLogy(1); printf("Starting %i ######################################\n",ind); TH1F* h; //char cind[20]; //char handle[100]; //sprintf(handle,"side_1exp_%02i_%02i_%02i",ind,mode,fitMode); TF1* fits[4]; //TF1* dpx[4]; if(debug) printf("looking for h %i\n",int(fd)); if(ind==0) { h = (TH1F*)fd->FindObjectAny("pair_mass_2GeV1"); } else if(ind==1) { h = (TH1F*)fd->FindObjectAny("pair_mass_2GeV3"); } if(debug) printf("new h %i\n",int(h)); if(debug) printf("new fit\n"); sprintf(fitname,"hfit_%1i",ind); fits[ind] = new TF1(fitname,"([0]*pow((x-30.0),[1])+[3]*pow((x-30.0),0.2))*([2]*exp(-[2]*(x-30.0))+[4]*[5]*exp(-[5]*(x-30.0)))",30.0,500.0); //fits[ind] = new TF1(fitname,"([0]*((1-[3])*pow((x-30.0),[1])+[3]*pow((x-30.0),0.2)))*(exp(-[2]*(x-30.0))+[4]*exp(-[5]*(x-30.0)))",30.0,500.0); fits[ind]->SetParameter(0,0.0004); fits[ind]->SetParameter(1,2); fits[ind]->SetParameter(2,0.02); fits[ind]->SetParameter(3,0.005); //fits[ind]->SetParameter(3,0.5); fits[ind]->SetParameter(4,1.005); fits[ind]->SetParameter(5,0.05); float llim = 30.0; h->Fit(fits[ind],"LN","",llim,1000.0); double par[20],parMin[20],fval,fvalMin; for(int i=0; i<nPar; i++) parMin[i] = fits[ind]->GetParameter(i); gMinuit->Eval(nPar,0,fvalMin,parMin,0); //printf("got back %10.5f\n",fvalMin); // save the fit results in a histogram, for limit program for(int ibin=16; ibin<250; ibin++) { float xx = h->GetBinCenter(ibin); float yy = fits[ind]->Eval(xx); if(ind==0) { cc->SetBinContent(ibin,h->GetBinContent(ibin)); ccBg->SetBinContent(ibin,yy); ccBgErr->SetBinContent(ibin,0.0); ccBgP->SetBinContent(ibin,0.0); ccBgM->SetBinContent(ibin,99999.0); } else { cp->SetBinContent(ibin,h->GetBinContent(ibin)); cpBg->SetBinContent(ibin,yy); cpBgErr->SetBinContent(ibin,0.0); cpBgP->SetBinContent(ibin,0.0); cpBgM->SetBinContent(ibin,99999.0); } } //vary the parameters to find an error envelope double par2[20],fval2=1e10; int pslim = (ind==0?25000:150000); for(int ips=0; ips<pslim; ips++) { if(ips%10000==0) printf("Processing %d\n",ips); for(int i=0; i<nPar; i++) { par[i] = parMin[i]; } for(int i=0; i<nPar; i++) { //int i = (ips%2==0?0:3); par[i] = parMin[i]+(2.0*(ran.Uniform()-0.5))*fits[ind]->GetParError(i); } fval = 0.0; gMinuit->Eval(nPar,0,fval,par,0); if((fval-fvalMin)<1.0) { printf("Found nearby min %10.5f\n",fval-fvalMin); float eOld,eNew; for(int ibin=16; ibin<250; ibin++) { float xx = h->GetBinCenter(ibin); for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,par[i]); float yy = fits[ind]->Eval(xx); for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,parMin[i]); float yyMin = fits[ind]->Eval(xx); TH1F *hBgErr,*hBgP,*hBgM; if(ind==0) { hBgErr = ccBgErr; hBgP = ccBgP; hBgM = ccBgM; } else { hBgErr = cpBgErr; hBgP = cpBgP; hBgM = cpBgM; } eOld = hBgErr->GetBinContent(ibin); eNew = yy - yyMin; if(eOld>fabs(eNew)) hBgErr->SetBinContent(ibin,fabs(eNew)); eOld = hBgP->GetBinContent(ibin); if(yy>eOld) hBgP->SetBinContent(ibin,yy); eOld = hBgM->GetBinContent(ibin); if(yy<eOld) hBgM->SetBinContent(ibin,yy); } } // end if near maximum /* if(fval<fval2) { for(int i=0; i<nPar; i++) par2[i] = par[i]; fval2 = fval; } */ } /* printf("forcing new fit..\n"); for(int i=0; i<nPar; i++) { printf("old,new = %10.5f %10.5f\n",parMin[i],par2[i]); fits[ind]->SetParameter(i,par2[i]); } */ // restore original fit fval = 0.0; gMinuit->Eval(nPar,0,fval,parMin,0); for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,parMin[i]); //extract fit error matrix gMinuit->mnemat(matrix.GetMatrixArray(),nPar); matrix.Print(); for(int i=0; i<nPar; i++) { for(int j=0; j<nPar; j++) { printf("%10.5f",matrix(i,j)/sqrt(matrix(i,i)*matrix(j,j))); } printf("\n"); } //matrix.Draw("text"); float hm = h->GetMaximum(); if(mode==0) { //TAxis* ax = h->GetXaxis(); //ax->SetRangeUser(24.1,199.9); h->SetMaximum(1.2*hm); //h->SetMinimum(0.0); } else if(mode==1) { TAxis* ax = h->GetXaxis(); ax->SetRangeUser(20.0,500.0); h->SetMaximum(1.15*hm); h->SetMinimum(0.0); } h->Draw(); fits[ind]->SetLineColor(1); fits[ind]->SetLineWidth(2.0); fits[ind]->Draw("SAME"); // find chi2's and KS's //AnaChiKs(h,fits[ind]); TAxis* ax,*ay; ax = h->GetXaxis(); ay = h->GetYaxis(); ax->SetTitle("m(#gamma#gamma) (GeV/c^{2})"); ay->SetTitle("Entries/2 GeV/c^{2}"); ax->CenterTitle(); ay->CenterTitle(); ax->SetTitleOffset(0.9); ay->SetTitleOffset(1.0); ax->SetTitleSize(0.08); ay->SetTitleSize(0.07); ax->SetLabelSize(0.07); ay->SetLabelSize(0.07); gPad->SetLeftMargin(0.16); gPad->SetBottomMargin(0.16); TText* text; text = new TLatex(0.5,0.8,"Diphoton Data"); text->SetNDC(true); text->SetTextSize(0.06); text->Draw(); if(ind==0) text = new TLatex(0.5,0.72,"Central-Central"); else if(ind==1) text = new TLatex(0.5,0.72,"Central-Plug"); text->SetNDC(true); text->SetTextSize(0.06); text->Draw(); if(ind==0) { text = new TLatex(0.15,0.92,"W/Z H#rightarrow X(#gamma#gamma)"); text->SetNDC(true); text->SetTextSize(0.08); text->Draw(); text = new TLatex(0.5,0.92,"CDF Run II Preliminary, 2.0 fb^{-1}"); text->SetNDC(true); text->SetTextSize(0.06); text->Draw(); } /* if(debug) printf("start loop\n"); int ibin; for(ibin=16; ibin<=250; ibin++) { if(debug) printf("start bin %i\n",ibin); float xx = (ibin-0.5)*2.0; // *** bin width here if(debug) printf("-1 test ibin %i\n",ibin); float yy = fits[ind]->Eval(xx); //printf("%f yy= %f \n",xx,yy); // the derivative of this yield wrt parameters if(debug) printf("0 test ibin %i\n",ibin); double y0 = yy; if(debug) printf("1 test ibin %i\n",ibin); TMatrixD vv(nPar,1); float dirSize = 0.5; for(int i=0; i<nPar; i++){ int ipar = i; double par = fits[ind]->GetParameter(ipar); double spar = fits[ind]->GetParError(ipar); double parp = par + dirSize*spar; fits[ind]->SetParameter(ipar,parp); double yp = fits[ind]->Eval(xx); vv(i,0) = limitBinSize*(yp-y0)/(dirSize*spar); fits[ind]->SetParameter(ipar,par); //printf("%f %f %f\n",yp,y0,spar); } //vv.Print(); if(debug) printf("start matrix %i\n",ibin); TMatrixD tempM(matrix, TMatrixDBase::kMult, vv); //matrix.Print(); TMatrixD tempN(vv, TMatrixDBase::kTransposeMult, tempM); //tempN.Print(); float bgSig = 0.0; if(tempN(0,0)>0.0) bgSig = sqrt(tempN(0,0)); // ****** hack temp ********** bgSig = 0.3*y0; // file hists to be saved if(debug) printf("start fill %i\n",ibin); if(ind==0) { //printf("filling cc %i %f\n",ibin,h->GetBinContent(ibin)); cc->SetBinContent(ibin,h->GetBinContent(ibin)); //printf("getting cc %i %f\n",ibin,cc->GetBinContent(ibin)); ccBg->SetBinContent(ibin,yy); ccBgErr->SetBinContent(ibin,bgSig); ccBgP->SetBinContent(ibin,yy+bgSig); ccBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0))); //if(ibin==27) { //printf("bg %f %f \n",yy,bgSig); //} } else { cp->SetBinContent(ibin,h->GetBinContent(ibin)); cpBg->SetBinContent(ibin,yy); cpBgErr->SetBinContent(ibin,bgSig); cpBgP->SetBinContent(ibin,yy+bgSig); cpBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0))); } if(debug) printf("end fill %i\n",ibin); } */ } printf("cc plus BG=%f\n",ccBgP->GetSum()); printf("cc minus BG=%f\n",ccBgM->GetSum()); printf("cp plus BG=%f\n",cpBgP->GetSum()); printf("cp minus BG=%f\n",cpBgM->GetSum()); char fn[100]; if(mode==0) { sprintf(fn,"FitSignal_%d",fitMode); savePlot(c,fn); } else if(mode==1) { sprintf(fn,"FitSignalLin_%d",fitMode); savePlot(c,fn); } //if(mode!=0) return; // plot of fit results gStyle->SetOptLogy(0); c = NewCanvas(); c->Divide(1,2); c->cd(1); cc->Draw(); ccBg->Draw("SAME"); c->cd(2); ccBgErr->SetMinimum(0.0); ccBgErr->SetMaximum(4.0); ccBgErr->Draw(); ccBgP->SetLineStyle(2); ccBgP->Draw("SAME"); ccBgM->SetLineStyle(2); ccBgM->Draw("SAME"); savePlot(c,"FitSignalResultsCC"); c = NewCanvas(); c->Divide(1,2); c->cd(1); cp->Draw(); cpBg->Draw("SAME"); c->cd(2); cpBgErr->SetMinimum(0.0); cpBgErr->SetMaximum(4.0); cpBgErr->Draw(); cpBgP->SetLineStyle(2); cpBgP->Draw("SAME"); cpBgM->SetLineStyle(2); cpBgM->Draw("SAME"); savePlot(c,"FitSignalResultsCP"); char title[100]; if(name) { sprintf(title,"TPeaksHiggs_FitSignalHist_%s.root",name); TFile* ff = new TFile(title,"RECREATE"); gROOT->GetList()->Write(); ff->Close(); } }
void showHistograms(double canvasSizeX, double canvasSizeY, TH1* histogram1, const std::string& legendEntry1, TH1* histogram2, const std::string& legendEntry2, TH1* histogram3, const std::string& legendEntry3, TH1* histogram4, const std::string& legendEntry4, double legendTextSize, double legendPosX, double legendPosY, double legendSizeX, double legendSizeY, std::vector<std::string>& labelTextLines, double labelTextSize, double labelPosX, double labelPosY, double labelSizeX, double labelSizeY, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { const unsigned numBinsMin_rebinned = 20; TH1* histogram1_rebinned = rebinHistogram(histogram1, numBinsMin_rebinned, xMin, xMax); TH1* histogram2_rebinned = rebinHistogram(histogram2, numBinsMin_rebinned, xMin, xMax); TH1* histogram3_rebinned = rebinHistogram(histogram3, numBinsMin_rebinned, xMin, xMax); TH1* histogram4_rebinned = rebinHistogram(histogram4, numBinsMin_rebinned, xMin, xMax); TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.14); canvas->SetBottomMargin(0.12); canvas->SetLogy(useLogScale); histogram1_rebinned->SetTitle(""); histogram1_rebinned->SetStats(false); histogram1_rebinned->SetMinimum(yMin); histogram1_rebinned->SetMaximum(yMax); TAxis* xAxis = histogram1_rebinned->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleSize(0.045); xAxis->SetTitleOffset(xAxisOffset); if ( xMax > xMin ) { std::cout << "limiting x-axis range to " << xMin << ".." << xMax << std::endl; xAxis->SetRangeUser(xMin, xMax); } TAxis* yAxis = histogram1_rebinned->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleSize(0.045); yAxis->SetTitleOffset(yAxisOffset); int colors[4] = { 1, 2, 3, 4 }; int lineStyles[4] = { 1, 7, 4, 3 }; histogram1_rebinned->SetLineColor(colors[0]); histogram1_rebinned->SetLineWidth(2); histogram1_rebinned->SetLineStyle(lineStyles[0]); histogram1_rebinned->Draw("hist"); if ( histogram2_rebinned ) { histogram2_rebinned->SetLineColor(colors[1]); histogram2_rebinned->SetLineWidth(2); histogram2_rebinned->SetLineStyle(lineStyles[1]); histogram2_rebinned->Draw("histsame"); } if ( histogram3_rebinned ) { histogram3_rebinned->SetLineColor(colors[2]); histogram3_rebinned->SetLineWidth(2); histogram3_rebinned->SetLineStyle(lineStyles[2]); histogram3_rebinned->Draw("histsame"); } if ( histogram4_rebinned ) { histogram4_rebinned->SetLineColor(colors[3]); histogram4_rebinned->SetLineWidth(2); histogram4_rebinned->SetLineStyle(lineStyles[3]); histogram4_rebinned->Draw("histsame"); } TLegend* legend = new TLegend(legendPosX, legendPosY, legendPosX + legendSizeX, legendPosY + legendSizeY, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextSize(legendTextSize); legend->AddEntry(histogram1_rebinned, legendEntry1.data(), "l"); if ( histogram2_rebinned ) legend->AddEntry(histogram2_rebinned, legendEntry2.data(), "l"); if ( histogram3_rebinned ) legend->AddEntry(histogram3_rebinned, legendEntry3.data(), "l"); if ( histogram4_rebinned ) legend->AddEntry(histogram4_rebinned, legendEntry4.data(), "l"); legend->Draw(); TPaveText* label = 0; if ( labelTextLines.size() > 0 ) { label = new TPaveText(labelPosX, labelPosY, labelPosX + labelSizeX, labelPosY + labelSizeY, "brNDC"); for ( std::vector<std::string>::const_iterator labelTextLine = labelTextLines.begin(); labelTextLine != labelTextLines.end(); ++labelTextLine ) { label->AddText(labelTextLine->data()); } label->SetFillColor(10); label->SetBorderSize(0); label->SetTextColor(1); label->SetTextAlign(12); label->SetTextSize(labelTextSize); label->Draw(); } canvas->Update(); std::string outputFileName_plot = "plots/"; size_t idx = outputFileName.find_last_of('.'); outputFileName_plot.append(std::string(outputFileName, 0, idx)); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete label; delete legend; delete canvas; delete histogram1_rebinned; delete histogram2_rebinned; delete histogram3_rebinned; delete histogram4_rebinned; }
//------------------------------------------------------------------------------ //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())); }
void plotVariable(string variable = "Elec_Fbrem", const TString& category = "TauNoGammas", const TString& xAxisTitle = "Fbrem", const TString& yAxisTitle = "a.u.", float xMin = -0.2, float xMax = 1, int nBins = 100, int numPVMin = 0, int numPVMax = 50, float PtMin = 10, float PtMax = 60, const TString& Region = "Endcap" ) { string discriminator = ""; // string discriminator = "-AntiEMed"; float AbsEtaMin = 0; float AbsEtaMax = 3.0; if(Region == "Barrel"){ AbsEtaMin = 0; AbsEtaMax = 1.479; } if(Region == "Endcap"){ AbsEtaMin = 1.479; AbsEtaMax = 3.0; } TCanvas *c1 = new TCanvas("c1","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); gStyle->SetOptStat(0); gStyle->SetTitleFillColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(0); gStyle->SetPadBorderMode(0); gStyle->SetPadColor(0); gStyle->SetTitleFillColor(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleH(0.07); gStyle->SetTitleFontSize(0.1); gStyle->SetTitleStyle(0); gStyle->SetTitleOffset(1.3,"y"); TLegend* leg = new TLegend(0.6,0.75,0.8,0.88,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.03); //leg->SetHeader("#splitline{CMS Preliminary}{ #sqrt{s}=7 TeV}"); // std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/AntiEMVA_Fall11DYJetsToLL-iter4.root"; // std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/Trees_ForV4/AntiEMVA_AntiEMVATrees-DYJetsToLL-madgraph-PUS6.root"; std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/Trees_ForV4/AntiEMVA_V4.root"; TFile* inputFile = new TFile (inputFileName.data(),"READ"); if(inputFile->IsZombie()){ cout << "No such file!" << endl; return; } TTree* inputTree = (TTree*)inputFile->Get("AntiEMVAAnalyzer2/tree"); // TTree* inputTree = (TTree*)inputFile->Get("AntiEMVAAnalyzer/tree"); std::vector<TH1*> histograms; std::vector<std::string> matchings ; matchings.push_back("GenHadMatch"); matchings.push_back("GenEleMatch"); for ( std::vector<std::string>::const_iterator matching = matchings.begin(); matching != matchings.end(); ++matching ) { TCut PUSelection(Form("NumPV>%i && NumPV<%i",numPVMin,numPVMax)); TCut ElecPtSelection (Form("Elec_Pt>%0f && Elec_Pt<%0f",PtMin,PtMax)); TCut TauPtSelection (Form("Tau_Pt>%0f && Tau_Pt<%0f",PtMin,PtMax)); TCut ElecAbsEtaSelection (Form("Elec_AbsEta>%0f && Elec_AbsEta<%0f",AbsEtaMin,AbsEtaMax)); TCut TauAbsEtaSelection = ""; if(Region == "Barrel"){ TauAbsEtaSelection = "Tau_Eta>-1.479 && Tau_Eta<1.479"; } if(Region == "Endcap"){ TauAbsEtaSelection = "(Tau_Eta>1.479 && Tau_Eta<3.0) || (Tau_Eta>-3.0 && Tau_Eta<-1.479)"; } // TCut TauAbsEtaSelection (Form("Tau_AbsEta>%0f && Tau_AbsEta<%0f",AbsEtaMin,AbsEtaMax)); TCut ElecMatchSelection (Form("Elec_%s == 1",matching->data())); // TCut ElecMatchSelection (Form("Elec_PFTauMatch && Elec_%s",matching->data())); TCut TauMatchSelection (Form("Tau_%s",matching->data())); TCut CategorySelection = ""; if(discriminator == ""){ if (category == "NoEleMatch") CategorySelection = "Tau_GsfEleMatch<0.5"; if (category == "woG") CategorySelection = "Tau_NumGammaCands<0.5"; if (category == "wGwoGSF") CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf<0.5"; if (category == "wGwGSFwoPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput<-0.1"; if (category == "wGwGSFwPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput>-0.1"; } if(discriminator == "-AntiEMed"){ if (category == "NoEleMatch") CategorySelection = "Tau_GsfEleMatch<0.5"; if (category == "woG") CategorySelection = "Tau_NumGammaCands<0.5"; if (category == "wGwoGSF") CategorySelection = "Tau_NumGammaCands>0.5 && (Tau_HasGsf<0.5 || (Tau_HasGsf>0.5 && Elec_PFMvaOutput>-0.1))"; if (category == "wGwGSFwoPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput<-0.1"; } TCut ElecSelection = CategorySelection && PUSelection && ElecPtSelection && ElecAbsEtaSelection && ElecMatchSelection ; TCut TauSelection = CategorySelection && PUSelection && TauPtSelection && TauAbsEtaSelection && TauMatchSelection ; TCut Selection; if (variable.find("Elec")!=std::string::npos)Selection = ElecSelection; if (variable.find("Tau")!=std::string::npos)Selection = TauSelection; TH1F* hVariable = new TH1F( "hVariable" ,"" , nBins ,xMin, xMax); hVariable->SetXTitle(Form("%s",variable.data())); if (matching->find("EleMatch")!=std::string::npos){ // hVariable->SetFillColor(kRed); // hVariable->SetFillStyle(3345); hVariable->SetLineColor(kRed); hVariable->SetLineWidth(2); } if (matching->find("HadMatch")!=std::string::npos){ // hVariable->SetFillColor(kBlue); // hVariable->SetFillStyle(3354); hVariable->SetLineColor(kBlue); hVariable->SetLineWidth(2); } inputTree->Draw(Form("%s>>hVariable",variable.data())); cout<<"Variable plotted : "<<variable<<endl; cout<<"Matching applied : "<<matching->data()<<endl; cout<<" Total number of Candidates : "<<hVariable->GetEntries()<<endl; inputTree->Draw(Form("%s>>hVariable",variable.data()),Selection); cout<<" Number of Cantidates after selection: "<<hVariable->GetEntries()<<endl; hVariable->Scale(1./hVariable->Integral()); leg->AddEntry(hVariable,Form("%s",matching->data())); histograms.push_back(hVariable); c1->Clear(); } // double yMin = +1.e+6; // double yMax = -1.e+6; TH1* refHistogram = histograms.front(); refHistogram->SetStats(false); refHistogram->SetTitle(""); // refHistogram->SetMinimum(yMin); // refHistogram->SetMaximum(yMax); if (xAxisTitle == "HoHplusE" ) { refHistogram->SetMaximum(1.0); refHistogram->SetMinimum(0.01); c1->SetLogy(); } if(xAxisTitle == "E_{#gamma}/(P_{in}-P_{out})" ){ refHistogram->SetMaximum(0.03); refHistogram->SetMinimum(0.0); } if(xAxisTitle == "HadrMva(#tau)" ){ refHistogram->SetMaximum(0.25); refHistogram->SetMinimum(0.0); } TAxis* xAxis = refHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.Data()); xAxis->SetTitleOffset(1.15); //if(variable.find("AbsEta")!=std::string::npos)xAxis->SetLimits(AbsEtaMin, AbsEtaMax); TAxis* yAxis = refHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.Data()); yAxis->SetTitleOffset(1.30); int numHistograms = histograms.size(); float YMax = 0; for ( int iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) { TH1* histogram = histograms[iHistogram]; if(histogram->GetMaximum()>YMax) YMax = histogram->GetMaximum(); } for ( int iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) { TH1* histogram = histograms[iHistogram]; yAxis->SetRangeUser(0.,YMax+0.10*YMax); std::string drawOption = "hist"; if ( iHistogram > 0 ) drawOption.append("same"); histogram->Draw(drawOption.data()); leg->Draw(); }//loop matchings string outputName = Form("plots/plotVariablesAntiEMVA/%s/plotVariablesAntiEMVA_v4_%s_%s_%s",category.Data(),category.Data(),variable.data(),Region.Data()); c1->Print(std::string(outputName).append(".png").data()); c1->Print(std::string(outputName).append(".pdf").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())); }
void makePlot(const std::string& inputFilePath, const std::string& canvasName, const std::string& histogram, const std::string& channel, const std::string& xAxisTitle, const std::string& yAxisTitle, const std::string& inputFileName, const std::string& outputFilePath, const std::string& outputFileName) { std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data()); TFile* inputFile = new TFile(inputFileName_full.data()); if ( !inputFile ) { std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl; assert(0); } inputFile->ls(); TCanvas* canvas = dynamic_cast<TCanvas*>(inputFile->Get(canvasName.data())); if ( !canvas ) { std::cerr << "Failed to load canvas = " << canvasName << " !!" << std::endl; assert(0); } int idxPad = -1; if ( histogram == "mVis" ) idxPad = 1; if ( histogram == "mTauTau" ) idxPad = 2; if ( !(idxPad >= 1 && idxPad <= 2) ) { std::cerr << "Invalid histogram = " << histogram << " !!" << std::endl; assert(0); } TVirtualPad* pad = canvas->GetPad(idxPad); std::cout << "pad = " << pad << ": ClassName = " << pad->ClassName() << std::endl; TCanvas* canvas_new = new TCanvas("canvas_new", "canvas_new", 900, 850); canvas_new->SetFillColor(10); canvas_new->SetBorderSize(2); canvas_new->SetTopMargin(0.065); canvas_new->SetLeftMargin(0.17); canvas_new->SetBottomMargin(0.155); canvas_new->SetRightMargin(0.045); canvas_new->SetLogx(false); canvas_new->SetLogy(false); canvas_new->Draw(); canvas_new->cd(); //TList* pad_primitives = canvas->GetListOfPrimitives(); TList* pad_primitives = pad->GetListOfPrimitives(); TH1* histogramDYJets = 0; TH1* histogramHiggs125 = 0; TH1* histogramHiggs200 = 0; TH1* histogramHiggs300 = 0; TIter pad_nextObj(pad_primitives); while ( TObject* obj = pad_nextObj() ) { std::string objName = ""; if ( dynamic_cast<TNamed*>(obj) ) objName = (dynamic_cast<TNamed*>(obj))->GetName(); std::cout << "obj = " << obj << ": name = " << objName << ", type = " << obj->ClassName() << std::endl; TH1* tmpHistogram = dynamic_cast<TH1*>(obj); if ( tmpHistogram ) { std::cout << "tmpHistogram:" << " fillColor = " << tmpHistogram->GetFillColor() << ", fillStyle = " << tmpHistogram->GetFillStyle() << "," << " lineColor = " << tmpHistogram->GetLineColor() << ", lineStyle = " << tmpHistogram->GetLineStyle() << ", lineWidth = " << tmpHistogram->GetLineWidth() << "," << " markerColor = " << tmpHistogram->GetMarkerColor() << ", markerStyle = " << tmpHistogram->GetMarkerStyle() << ", markerSize = " << tmpHistogram->GetMarkerSize() << "," << " integral = " << tmpHistogram->Integral() << std::endl; if ( tmpHistogram->GetFillColor() == 0 ) histogramDYJets = tmpHistogram; if ( tmpHistogram->GetFillColor() == 632 ) histogramHiggs125 = tmpHistogram; if ( tmpHistogram->GetFillColor() == 616 ) histogramHiggs200 = tmpHistogram; if ( tmpHistogram->GetFillColor() == 600 ) histogramHiggs300 = tmpHistogram; } } if ( !(histogramDYJets && histogramHiggs125 && histogramHiggs200 && histogramHiggs300) ) { std::cerr << "Failed to load histograms !!" << std::endl; assert(0); } int lineColors[4] = { 1, 2, 6, 4 }; int lineStyles[4] = { 1, 1, 1, 1 }; int lineWidths[4] = { 2, 2, 2, 2 }; int fillColors[4] = { 10, 2, 6, 4 }; int fillStyles[4] = { 0, 3002, 3004, 3005 }; histogramDYJets->SetFillColor(fillColors[0]); histogramDYJets->SetFillStyle(fillStyles[0]); histogramDYJets->SetLineColor(lineColors[0]); histogramDYJets->SetLineStyle(lineStyles[0]); histogramDYJets->SetLineWidth(lineWidths[0]); histogramHiggs125->SetFillColor(fillColors[1]); histogramHiggs125->SetFillStyle(fillStyles[1]); histogramHiggs125->SetLineColor(lineColors[1]); histogramHiggs125->SetLineStyle(lineStyles[1]); histogramHiggs125->SetLineWidth(lineWidths[1]); histogramHiggs200->SetFillColor(fillColors[2]); histogramHiggs200->SetFillStyle(fillStyles[2]); histogramHiggs200->SetLineColor(lineColors[2]); histogramHiggs200->SetLineStyle(lineStyles[2]); histogramHiggs200->SetLineWidth(lineWidths[2]); histogramHiggs300->SetFillColor(fillColors[3]); histogramHiggs300->SetFillStyle(fillStyles[3]); histogramHiggs300->SetLineColor(lineColors[3]); histogramHiggs300->SetLineStyle(lineStyles[3]); histogramHiggs300->SetLineWidth(lineWidths[3]); TAxis* xAxis = histogramHiggs300->GetXaxis(); if ( histogram == "mVis" ) xAxis->SetRangeUser(0,350); else xAxis->SetRangeUser(0,450); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(1.00); xAxis->SetTitleSize(0.070); xAxis->SetTitleFont(42); xAxis->SetLabelOffset(0.010); xAxis->SetLabelSize(0.050); xAxis->SetLabelFont(42); xAxis->SetTickLength(0.040); xAxis->SetNdivisions(505); //double xMin = 20.; //double xMax = xAxis->GetXmax(); //xAxis->SetRangeUser(xMin, xMax); TAxis* yAxis = histogramHiggs300->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(1.20); yAxis->SetTitleSize(0.070); yAxis->SetTitleFont(42); yAxis->SetLabelOffset(0.010); yAxis->SetLabelSize(0.055); yAxis->SetLabelFont(42); yAxis->SetTickLength(0.040); yAxis->SetNdivisions(505); histogramHiggs300->SetTitle(""); histogramHiggs300->SetStats(false); histogramHiggs300->SetMaximum(1.2*histogramDYJets->GetMaximum()); histogramHiggs300->SetMinimum(0.); histogramHiggs300->Draw("hist"); histogramHiggs200->Draw("histsame"); histogramHiggs125->Draw("histsame"); histogramDYJets->Draw("histsame"); histogramHiggs300->Draw("axissame"); TLegend* legend_new = new TLegend(0.50, 0.62, 0.87, 0.92, NULL, "brNDC"); legend_new->SetFillColor(10); legend_new->SetFillStyle(0); legend_new->SetBorderSize(0); legend_new->SetTextFont(42); legend_new->SetTextSize(0.055); legend_new->SetTextColor(1); legend_new->SetMargin(0.20); legend_new->AddEntry(histogramDYJets, "Z/#gamma* #rightarrow #tau#tau", "f"); legend_new->AddEntry(histogramHiggs125, "H(125 GeV) #rightarrow #tau#tau", "f"); legend_new->AddEntry(histogramHiggs200, "H(200 GeV) #rightarrow #tau#tau", "f"); legend_new->AddEntry(histogramHiggs300, "H(300 GeV) #rightarrow #tau#tau", "f"); legend_new->Draw(); double label_channel_y0; if ( channel == "e#mu" ) label_channel_y0 = 0.9275; else if ( channel == "#mu#tau_{h}" ) label_channel_y0 = 0.9400; else if ( channel == "#tau_{h}#tau_{h}" ) label_channel_y0 = 0.9350; else { std::cerr << "Invalid channel = " << channel << " !!" << std::endl; assert(0); } TPaveText* label_channel = new TPaveText(0.855, label_channel_y0, 0.945, label_channel_y0 + 0.055, "NDC"); label_channel->SetFillStyle(0); label_channel->SetBorderSize(0); label_channel->AddText(channel.data()); label_channel->SetTextFont(62); label_channel->SetTextSize(0.055); label_channel->SetTextColor(1); label_channel->SetTextAlign(31); label_channel->Draw(); canvas_new->Update(); std::string outputFileName_full = Form("%s%s", outputFilePath.data(), outputFileName.data()); size_t idx = outputFileName_full.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName_full, 0, idx); canvas_new->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas_new->Print(std::string(outputFileName_plot).append(".root").data()); delete legend_new; delete label_channel; delete canvas_new; delete inputFile; }
int main ( int argc, char *argv[] ) { StopStyle(); std::vector<std::string> vDec; //vDec.push_back("PhaseI"); //vDec.push_back("PhaseII3"); //vDec.push_back("PhaseII4"); vDec.push_back("PhaseI_0PU"); vDec.push_back("PhaseI_140PU"); vDec.push_back("PhaseII3_140PU"); vDec.push_back("PhaseII4_140PU"); std::vector<std::string> vLep; vLep.push_back("EleEta"); //vLep.push_back("ElePt"); vLep.push_back("MuonEta"); //vLep.push_back("MuonPt"); //vLep.push_back("TauEta"); //vLep.push_back("TauPt"); //vLep.push_back("JetEta"); //vLep.push_back("JetPt"); //vLep.push_back("JetPt"); //vLep.push_back("MET"); //vLep.push_back("MHT"); int cut = 0; //int cut = 5; //Before lepton veto //int cut = 14; //After METCut std::vector<int> VColor; VColor.push_back(1); VColor.push_back(2); VColor.push_back(4); VColor.push_back(6); VColor.push_back(kGreen+2); VColor.push_back(kOrange+9); VColor.push_back(60); TCanvas *c1 = new TCanvas("fd", "dfdf", 600, 500); TLegend *lg = NULL; //c1->SetGridx(); //c1->SetGridy(); for (int j = 0; j < vLep.size(); ++j) { if (vLep.at(j).find("Pt") != std::string::npos) lg = new TLegend(0.602349,0.1631356,0.8389262,0.4576271,NULL,"brNDC"); else if (vLep.at(j).find("EleEta") != std::string::npos ) //lg = new TLegend(0.3691275,0.1751055,0.6057047,0.4683544,"W(e#nu) + jets","brNDC"); lg = new TLegend(0.3238255,0.1673729,0.5486577,0.4618644,"W(e#nu) + jets","brNDC"); else if (vLep.at(j).find("MuonEta") != std::string::npos) //lg = new TLegend(0.3691275,0.1751055,0.6057047,0.4683544,"W(#mu#nu) + jets","brNDC"); lg = new TLegend(0.3238255,0.1673729,0.5486577,0.4618644,"W(#mu#nu) + jets","brNDC"); //lg = new TLegend(0.3791946,0.1737288,0.6157718,0.4682203,NULL,"brNDC"); else if (vLep.at(j).find("JetEta") != std::string::npos) lg = new TLegend(0.3657718,0.7139831,0.6241611,0.9533898,NULL,"brNDC"); else if (vLep.at(j).find("TauEta") != std::string::npos) lg = new TLegend(0.3842282,0.654661,0.6208054,0.9491525,NULL,"brNDC"); else lg = new TLegend(0.3791946,0.1737288,0.6157718,0.4682203,NULL,"brNDC"); //else if (vLep.at(j).find("EleEta") != std::string::npos) lg->SetBorderSize(0); lg->SetFillStyle(0); //transparent hollow? lg->SetTextFont(62); //lg->SetTextSize(0.03); lg->SetTextSize(0.04); double ymin = 0.0; double ymax = 0.0; TAxis *yaxis = NULL; TAxis *xaxis = NULL; for (int i = 0; i < vDec.size(); ++i) { char pu[10]; char det[10]; sscanf(vDec.at(i).c_str(), "%[^_]_%s", det, pu); std::cout << " pu " << pu << " "<< strcmp(pu, "0PU") << std::endl; std::string pileup ="" ; if (strcmp(pu, "0PU") == 0) pileup = "NoPileUp"; if (strcmp(pu, "50PU") == 0) pileup = "50PileUp"; if (strcmp(pu, "140PU") == 0) pileup = "140PileUp"; std::cout << " pileup " << pileup <<" dec " << det << std::endl; HTSample *HT = new HTSample("LPC_MHTCUT/", "Wlv*_14TEV_HT", pileup, det); HT->InitSample(3000*1000); c1->cd(); c1->Update(); TH1F* reco = NULL; TH1F* gen = NULL; //TH2D* reco = NULL; //TH2D* gen = NULL; std::cout << " " << vLep.at(j) << std::endl; if (vLep.at(j) != "MET" && vLep.at(j) != "MHT") { TString reconame = "AppMatched"+vLep.at(j); TString genname = "AppGen"+vLep.at(j); //reco = (TH2D*)HT->GetTH2D(reconame.Data(), cut); //gen = (TH2D*)HT->GetTH2D(genname.Data(), cut); reco = (TH1F*)HT->GetTH1(reconame.Data(), cut); gen = (TH1F*)HT->GetTH1(genname.Data(), cut); } else { //reco = (TH1F*)HT->GetTH1(vLep.at(j), cut); //gen = (TH1F*)HT->GetTH1("GenMet"); } if (vLep.at(j).find("Pt") != std::string::npos) { reco->Rebin(5); gen->Rebin(5); } //TH1F* reco = (TH1F*)HT->GetTH1("JetEta", cut); //TH1F* gen = (TH1F*)HT->GetTH1("GenJetEta", cut); //TH1F* reco = (TH1F*)HT->GetTH1("MuonPt", cut); //reco->Rebin(5); //TH1F* gen = (TH1F*)HT->GetTH1("GenMuonPt", cut); //gen->Rebin(5); //TH1F* reco = (TH1F*)HT->GetTH1("ElePt", cut); // //TH1F* gen = (TH1F*)HT->GetTH1("GenElePt", cut); reco->Divide(gen); reco->SetTitle(""); //gen->Draw(); //gen->SetLineColor(1); reco->SetLineWidth(3); reco->SetLineColor(VColor.at(i)); ymin = ymin < reco->GetMinimum() ? ymin : reco->GetMinimum(); ymax = ymax > reco->GetMaximum() ? ymax : reco->GetMaximum(); if (i == 0) { yaxis = reco->GetYaxis(); xaxis = reco->GetXaxis(); reco->Draw(); } else { reco->Draw("same"); } reco->GetYaxis()->SetTitle("Efficiency"); if (vDec.at(i).find("PU") != std::string::npos) { std::cout << " vDec.at(i)" << vDec.at(i) << std::endl; std::cout<<"Run to \033[0;31m"<<__func__<<"\033[0m at \033[1;36m"<< __FILE__<<"\033[0m, line \033[0;34m"<< __LINE__<<"\033[0m"<< std::endl; if (vDec.at(i) == "PhaseI_0PU") { lg->AddEntry(reco, "Phase I, <PU>=0", "fl"); reco->SetLineColor(1); } if (vDec.at(i) == "PhaseI_140PU") { lg->AddEntry(reco, "Phase I, <PU>=140", "fl"); reco->SetLineColor(4); } if (vDec.at(i) == "PhaseII3_140PU") { lg->AddEntry(reco, "Phase II Conf3, <PU>=140", "fl"); //lg->AddEntry(reco, "PhaseII3 <PU>=140", "fl"); reco->SetLineColor(kGreen+2); } if (vDec.at(i) == "PhaseII4_140PU") { lg->AddEntry(reco, "Phase II Conf4, <PU>=140", "fl"); reco->SetLineColor(2); } //TString leg = vDec.at(i); //lg->AddEntry(reco, leg.ReplaceAll("_", " "), "l"); } TString xlabel = reco->GetXaxis()->GetTitle(); std::cout << xlabel << std::endl; if (xlabel =="#Pt_{Matched m} [GeV]") std::cout<<"Run to \033[0;31m"<<__func__<<"\033[0m at \033[1;36m"<< __FILE__<<"\033[0m, line \033[0;34m"<< __LINE__<<"\033[0m"<< std::endl; if (xlabel =="#eta_{Matched e}" ) xlabel = "#eta_{e}"; if (xlabel =="#eta_{Matched m}" ) xlabel = "#eta_{#mu}"; if (xlabel =="#eta_{Matched t}" ) xlabel = "#eta_{t}"; if (xlabel =="#Pt_{Matched e} [GeV] " ) xlabel = "#P_{T}^{e} [GeV]"; if (xlabel =="#Pt_{Matched m} [GeV] " ) xlabel = "#P_{T}^{#mu} [GeV]"; if (xlabel =="#Pt_{Matched t} [GeV] " ) xlabel = "#P_{T}^{t} [GeV]"; reco->GetXaxis()->SetTitle(xlabel); reco->GetYaxis()->SetTitleOffset(1.0); reco->GetXaxis()->SetTitleOffset(0.9); reco->GetYaxis()->SetTitleSize(0.06); reco->GetXaxis()->SetTitleSize(0.06); reco->GetYaxis()->SetLabelSize(0.05); reco->GetXaxis()->SetLabelSize(0.05); //reco->GetYaxis()->SetRangeUser(0.1*ymin, 5*ymax); //c1->Print("Pt.png"); //c1->Print("MuonEta_0.png"); //c1->Print("EleEta_0.png"); //TH1F* jet = (TH1F*)HT->GetTH1("JetPTScale", cut); //jet->Draw(); //c1->Print("Jet.png"); delete HT; } yaxis->SetRangeUser(0.8*ymin, 1.2*ymax); xaxis->SetRangeUser(-4.5, 4.5); lg->Draw(); DrawTitle(); c1->RedrawAxis(); std::stringstream ss; ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".png"; c1->Print(ss.str().c_str()); ss.str(""); ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".pdf"; c1->Print(ss.str().c_str()); ss.str(""); ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".C"; c1->Print(ss.str().c_str()); ss.str(""); ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".root"; c1->Print(ss.str().c_str()); } return EXIT_SUCCESS; } // ---------- end of function main ----------
//------------------------------------------------------------------------------ // DrawZPeak //------------------------------------------------------------------------------ void DrawZPeak(TString energy) { if (energy.Contains("7TeV")) { _lumiText = "4.9 fb^{-1} (7 TeV)"; } else { _lumiText = "19.6 fb^{-1} (8 TeV)"; } // Read the input file //---------------------------------------------------------------------------- TString name = "invMass2Lep_"; TFile* file = new TFile("rootfiles/" + name + energy + ".root", "read"); TH1F* data; TH1F* WZ; TH1F* fakes; TH1F* ZZ; TH1F* Zgamma; TH1F* WV; TH1F* VVV; TH1F* allmc; if (energy.Contains("7TeV")) { data = (TH1F*)file->Get("hZMass_Sel_datahist_COMB"); WZ = (TH1F*)file->Get("hZMass_Sel_wz_COMB"); fakes = (TH1F*)file->Get("hZMass_Sel_datadriven_COMB"); ZZ = (TH1F*)file->Get("hZMass_Sel_zz_COMB"); Zgamma = (TH1F*)file->Get("hZMass_Sel_zg_COMB"); WV = (TH1F*)file->Get("hZMass_Sel_wz_COMB"); VVV = (TH1F*)file->Get("hZMass_Sel_wz_COMB"); allmc = (TH1F*)file->Get("all_estimates_with_error_COMB"); } else if (energy.Contains("8TeV")) { data = (TH1F*)file->Get("h_data"); WZ = (TH1F*)file->Get("h_WZ"); fakes = (TH1F*)file->Get("h_Fakes"); ZZ = (TH1F*)file->Get("h_ZZ"); Zgamma = (TH1F*)file->Get("h_ZGamma"); WV = (TH1F*)file->Get("h_WV"); VVV = (TH1F*)file->Get("h_VVV"); allmc = (TH1F*)file->Get("h_All"); } WZ->SetFillColor(kOrange-2); WZ->SetLineColor(kOrange-2); Zgamma->SetFillColor(kRed+1); // kRed+2 Zgamma->SetLineColor(kRed+1); // kRed+2 ZZ->SetFillColor(kRed+1); ZZ->SetLineColor(kRed+1); fakes->SetFillColor(kGray+1); fakes->SetLineColor(kGray+1); data->SetMarkerStyle(kFullCircle); allmc->SetFillColor (kBlack); allmc->SetFillStyle (3345); allmc->SetLineColor (kWhite); allmc->SetLineWidth (0); allmc->SetMarkerColor(kOrange-2); allmc->SetMarkerSize (0); THStack* hs = new THStack(); if (energy.Contains("8TeV")) { WV->SetFillColor(kRed+1); // kAzure WV->SetLineColor(kRed+1); // kAzure VVV->SetFillColor(kRed+1); // kBlack VVV->SetLineColor(kRed+1); // kBlack hs->Add(VVV); hs->Add(WV); } hs->Add(Zgamma); hs->Add(ZZ); hs->Add(fakes); hs->Add(WZ); // Draw //---------------------------------------------------------------------------- TCanvas* canvas = new TCanvas(energy, energy); data->Draw("ep"); // Axis labels //---------------------------------------------------------------------------- TAxis* xaxis = data->GetXaxis(); TAxis* yaxis = data->GetYaxis(); xaxis->SetLabelFont ( 42); xaxis->SetLabelOffset(0.01); xaxis->SetLabelSize (0.05); xaxis->SetNdivisions ( 505); xaxis->SetTitleFont ( 42); xaxis->SetTitleOffset( 1.3); xaxis->SetTitleSize (0.05); yaxis->SetLabelFont ( 42); yaxis->SetLabelOffset(0.01); yaxis->SetLabelSize (0.05); yaxis->SetNdivisions ( 505); yaxis->SetTitleFont ( 42); yaxis->SetTitleOffset( 1.6); yaxis->SetTitleSize (0.05); xaxis->SetRangeUser(68, 112); xaxis->SetTitle("m_{#font[12]{ll}} (GeV)"); yaxis->SetTitle(Form("Events / %.0f GeV", data->GetBinWidth(0))); // Adjust scale //---------------------------------------------------------------------------- Float_t theMax = GetMaximumIncludingErrors(data); Float_t theMaxMC = GetMaximumIncludingErrors(allmc); if (theMaxMC > theMax) theMax = theMaxMC; data->SetMaximum(1.15 * theMax); // Legend //---------------------------------------------------------------------------- Double_t x0 = 0.635; Double_t y0 = 0.770; DrawTLegend(x0, y0 + 2.*(_yoffset+0.001), data, " Data", "ep"); DrawTLegend(x0, y0 + 1.*(_yoffset+0.001), WZ, " WZ", "f"); DrawTLegend(x0, y0, fakes, " Non-prompt leptons", "f"); DrawTLegend(x0, y0 - 1.*(_yoffset+0.001), ZZ, " MC background", "f"); DrawTLegend(x0, y0 - 2.*(_yoffset+0.001), allmc, " stat. #oplus syst.", "f"); // Finish it //---------------------------------------------------------------------------- data->SetTitle(""); DrawTLatex(_cmsTextFont, 0.215, 0.880, 0.055, 13, "CMS"); // DrawTLatex(_extraTextFont, 0.215, 0.826, 0.030, 13, "Preliminary"); DrawTLatex(_lumiTextFont, 0.940, 0.940, 0.040, 31, _lumiText); hs ->Draw("hist,same"); allmc->Draw("e2,same"); data ->Draw("ep,same"); canvas->GetFrame()->DrawClone(); canvas->RedrawAxis(); canvas->Update(); canvas->SaveAs("pdf/" + name + energy + ".pdf"); canvas->SaveAs("png/" + name + energy + ".png"); }
int main ( int argc, char *argv[] ) { filename = argv[1]; plateu = atoi(argv[2]); StopStyle(); TCanvas *c1 = new TCanvas("XS" , "f**k" , 600, 500); c1->SetLogy(); //TLegend *leg = new TLegend(0.5889262,0.5889831,0.9446309,0.9385593,NULL,"brNDC"); //TLegend *leg = new TLegend(0.1526846,0.1588983,0.5083893,0.5084746,NULL,"brNDC"); TLegend *leg = new TLegend(0.3456376,0.5949367,0.7013423,0.8987342,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetFillStyle(0); //transparent hollow? leg->SetTextFont(62); leg->SetTextSize(0.03); TAxis *Xaxis = NULL; TAxis *Yaxis = NULL; VColor.push_back(1); VColor.push_back(2); VColor.push_back(4); VColor.push_back(kOrange+9); VColor.push_back(kGreen+2); VColor.push_back(6); VColor.push_back(60); if (filename.find("Discovery") != std::string::npos) style = "Discovery"; if (filename.find("CLimit") != std::string::npos) style = "CLimit"; //---------------------------------------------------------------------------- // Default input cross section //---------------------------------------------------------------------------- std::map<int, double> SigXs; SigXs[112] = 46; SigXs[200] = 11.47; SigXs[500] = 0.45; double x[3], y[3]; x[0] = 112; x[1] = 200; x[2] = 500; y[0] = SigXs[x[0]] * 1; y[1] = SigXs[x[1]] * 1; y[2] = SigXs[x[2]] * 1; //---------------------------------------------------------------------------- // A Test pave //---------------------------------------------------------------------------- //// Add to the plot the S/B ratio TPaveText *pt = 0; pt = new TPaveText(0.5587248,0.7669492,0.9446309,0.9110169,"brNDC"); pt->SetFillColor(0); pt->SetBorderSize(0); pt->SetTextSize(0.04); pt->SetTextColor(4); std::stringstream lumi; lumi << "3000 fb^{-1}, 14 TeV"; pt->AddText(lumi.str().c_str()); lumi.str(""); if (style == "CLimit") lumi << "95\% C.L. Limit"; if (style == "Discovery") lumi << "Discovery sensitivity"; pt->AddText(lumi.str().c_str()); lumi.str(""); char scenario = ' '; if (plateu == 10) scenario = 'A'; if (plateu == 5) scenario = 'B'; if (plateu == 1) scenario = 'C'; if (scenario != ' ') { lumi << "Scenario " << scenario; pt->AddText(lumi.str().c_str()); } //---------------------------------------------------------------------------- // Cross Section //---------------------------------------------------------------------------- TGraph* xs = new TGraph(3, x, y); xs->SetMarkerStyle(10); xs->SetTitle(""); xs->SetLineColor(VColor[0]); Xaxis = xs->GetXaxis(); Yaxis = xs->GetYaxis(); leg->AddEntry(xs, "Wino", "l"); xs->Draw("ALP"); PlotLines(c1, leg); ////---------------------------------------------------------------------------- //// End ////---------------------------------------------------------------------------- Yaxis->SetRangeUser(0.1, 300); ////Yaxis->SetRangeUser(0, 70); Yaxis->SetTitle("#sigma (fb)"); Xaxis->SetTitle("m(#tilde{#chi}^{0}_{1}) [GeV]"); //fit->Draw("same"); pt->Draw(); TString outname = filename; outname.ReplaceAll(".log", ""); std::stringstream ss; ss<< outname.Data()<< "_" << plateu << "p.pdf"; c1->SaveAs(ss.str().c_str()); ss.str(""); ss<< outname.Data()<< "_" << plateu << "p.png"; c1->SaveAs(ss.str().c_str()); return EXIT_SUCCESS; } // ---------- end of function main ----------
void DeltaPlot::viewGMstar (Char_t const* title) { FFactor GMS(12); GMS.LoadParameters(parametersFile); GMS.CheckParameters(); //GMS.PrintParameters(); const int nPoints = 2500; double qMin; double qMax; double qStep; double qA; double DX[nPoints], DY[nPoints], RY[nPoints]; qMin = 0.004; qMax = 3.0; qStep = (qMax-qMin)/nPoints; qA = qMin; for (int i = 0; i < nPoints; i++) { qA = qMin + i*qStep; double qA2 = qA*qA; double gen = GMS.AbsGEN(-qA2); double gmn = GMS.AbsGMN(-qA2); double msq = massDi*massDi - massNucl*massNucl - qA2; double abq = sqrt((qA2 + msq*msq)/(4.*massDi*massDi)); double jsc = (massDi+massNucl)/2./massNucl*(1.-qA2/4./massDi/massDi)*(1.-qA2/4./massNucl/massNucl); DX[i] = qA2; double mDip = 1. + qA2/0.71; double gD = 1./mDip/mDip; double gDmn = gD*(-muN); DY[i] = sqrt(2.)*2./3.*gDmn*jsc; double masst = qA2/(4.*massNucl*massNucl); double gmo = (GMS.ScalarOne(-qA2)-GMS.VectorOne(-qA2))/qA2+(GMS.ScalarTwo(-qA2)-GMS.VectorTwo(-qA2))/massN/massN/4.; RY[i] = sqrt(2.)*2./3.*gmn*jsc; } c[k] = new TCanvas (uName("c",k), uName("Graph_",k), x0+k*s, y0+k*s, w, h); //c[k]->SetLogy(); // logarithmic scale TGraphErrors *g[5]; TMultiGraph *mg = new TMultiGraph(); Double_t EX0[100] = {0}; // 1999-PRL-82-45_Frolov Double_t X1[] = {2.8, 4.0}; Double_t Y1[] = {0.0859, 0.0402}; Double_t U1[] = {0.0035, 0.0019}; Double_t D1[] = {0.0035, 0.0019}; g[1] = new TGraphErrors (2, X1, Y1, EX0, D1); g[1]->SetTitle("JLab/Hall C"); g[1]->SetMarkerColor(2); g[1]->SetMarkerStyle(21); mg->Add(g[1]); // 2006-PRL-97-112003_Ungaro Double_t X2[] = {3.0, 3.5, 4.2, 5.0, 6.0}; Double_t Y2[] = {0.0697, 0.0524, 0.0346, 0.0242, 0.0134}; Double_t U2[] = {0.0010, 0.0011, 0.0012, 0.0014, 0.0014}; Double_t D2[] = {0.0010, 0.0011, 0.0012, 0.0014, 0.0014}; g[2] = new TGraphErrors (5, X2, Y2, EX0, D2); g[2]->SetTitle("JLaB/CLAS"); g[2]->SetMarkerColor(4); g[2]->SetMarkerStyle(21); mg->Add(g[2]); // 1968-PL-28-148B_Bartel Double_t X3[] = {0.20, 0.30, 0.40, 0.47, 0.48, 0.50, 0.60, 0.63, 0.63, 0.77, 0.78, 0.79, 0.97, 0.98, 1.15, 1.34, 1.57, 2.34}; Double_t Y3[] = {1.7700, 1.3800, 1.1700, 0.9780, 0.9610, 0.9640, 0.7660, 0.7350, 0.7190, 0.5700, 0.5720, 0.5530, 0.4460, 0.4460, 0.3260, 0.2690, 0.2090, 0.1020}; Double_t U3[] = {0.0620, 0.0483, 0.0351, 0.0293, 0.0336, 0.0289, 0.0268, 0.0221, 0.0252, 0.0200, 0.0172, 0.0194, 0.0156, 0.0156, 0.0147, 0.0121, 0.0115, 0.0082}; Double_t D3[] = {0.0620, 0.0483, 0.0351, 0.0293, 0.0336, 0.0289, 0.0268, 0.0221, 0.0252, 0.0200, 0.0172, 0.0194, 0.0156, 0.0156, 0.0147, 0.0121, 0.0115, 0.0082}; g[3] = new TGraphErrors (18, X3, Y3, EX0, D3); g[3]->SetTitle("DESY"); g[3]->SetMarkerColor(6); g[3]->SetMarkerStyle(22); mg->Add(g[3]); // 1975-PR-D12-1884_Stein Double_t X4[] = {0.09, 0.22, 0.46, 0.78, 1.17, 1.48, 1.82}; Double_t Y4[] = {2.2448, 1.5824, 0.9147, 0.5007, 0.2708, 0.1728, 0.1122}; Double_t U4[] = {0.0709, 0.0332, 0.0243, 0.0136, 0.0116, 0.0095, 0.0064}; Double_t D4[] = {0.0709, 0.0332, 0.0243, 0.0136, 0.0116, 0.0095, 0.0064}; g[4] = new TGraphErrors (7, X4, Y4, EX0, D4); g[4]->SetTitle("SLAC"); g[4]->SetMarkerColor(4); g[4]->SetMarkerStyle(23); mg->Add(g[4]); for (int i=0; i<4; ++i) { g[i+1]->SetFillColor(0); //g[i+1]->SetLineColor(4); g[i+1]->SetMarkerSize(1.2); } // Formula D TGraph *gD = new TGraph (nPoints, DX, DY); gD->SetTitle("Dipole formulae"); gD->SetFillColor(0); gD->SetLineWidth(3); gD->SetMarkerSize(0.3); gD->SetMarkerStyle(21); gD->SetMarkerColor(4); gD->SetLineColor(4); mg->Add(gD); // Formula A TGraph *gA = new TGraph (nPoints, DX, RY); gA->SetTitle("Our result"); gA->SetFillColor(0); gA->SetLineWidth(3); gA->SetMarkerSize(0.3); gA->SetMarkerStyle(21); //gA->SetLineColor(3); mg->Add(gA); mg->Draw("AP"); //TF1 *fg = new TF1 ("fg", "[1]*x + [0]"); //mg->Fit("poly5","Fit"); // fg TAxis *aX = mg->GetXaxis(); aX->SetTitle("Q^{2} [GeV^{2}]"); //aX->SetLimits(0.,10.); aX->SetRangeUser(-0.01,7.0); aX->SetTitleOffset(1.2); aX->CenterTitle(); TAxis *aY = mg->GetYaxis(); aY->SetTitle("G_{M}^{*}"); //aY->SetRangeUser(0.6,1.8); aY->SetTitleOffset(1.2); aY->CenterTitle(); gPad->SetFillColor(kWhite); TLegend *leg = c[k]->BuildLegend(); leg->SetFillStyle(0); c[k]->Modified(); c[k]->SaveAs("imgGMstar.pdf"); ++k; }
void Limit_2D_LQ() { // setTDRStyle(); gStyle->SetPadLeftMargin(0.15); gStyle->SetLineWidth(2); gROOT->ForceStyle(); TCanvas *c = new TCanvas("c1", "c1",0,45,600,600); gStyle->SetOptStat(0); c->SetHighLightColor(2); c->Range(0,0,1,1); c->SetFillColor(0); c->SetBorderMode(0); c->SetBorderSize(2); c->SetLeftMargin(0.12); c->SetRightMargin(0.04); c->SetTopMargin(0.06); c->SetBottomMargin(0.12); c->SetFrameFillStyle(0); c->SetFrameLineWidth(2); c->SetFrameBorderMode(0); c->SetTickx(1); c->SetTicky(1); c->cd(); // const int nMass = 15; // Double_t mData[] = {200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900}; // Double_t limit_observed[] = {0.0827284, 0.0981056, 0.0646578, 0.0733808, 0.115078, 0.154828, 0.227671, 0.307448, 0.39362, 0.554267, 0.783352, 1.07813, 1.5539, 2.21602, 3.46142}; // Double_t limit_expected[] = {0.088132, 0.100218, 0.0708202, 0.0703361, 0.090391, 0.131143, 0.175555, 0.247355, 0.34838, 0.487021, 0.693413, 0.979308, 1.406, 2.00591, 3.09258}; //// // // // // // // https://twiki.cern.ch/twiki/bin/view/CMS/Exo2015LQ1AndLQ2Analyses std::map<int, float> XS; XS[200]= 60.6; XS[250]= 20.3; XS[300]= 8.05E+00; XS[350]= 3.58E+00; XS[400]= 1.74E+00; XS[450]= 9.05E-01; XS[500]= 4.96E-01; XS[550]= 2.84E-01; XS[600]= 1.69E-01; XS[650]= 1.03E-01; XS[700]= 6.48E-02; XS[750]= 4.16E-02; XS[800]= 2.73E-02; XS[850]= 1.82E-02; XS[900]= 1.23E-02; XS[950]= 8.45E-03; XS[1000]= 5.86E-03; XS[1050]= 4.11E-03; XS[1100]= 2.91E-03; XS[1150]= 2.08E-03; XS[1200]= 1.50E-03; XS[1250]= 1.09E-03; XS[1300]= 7.95E-04; XS[1350]= 5.85E-04; XS[1400]= 4.33E-04; XS[1450]= 3.21E-04; XS[1500]= 2.40E-04; const int nMass = 26; int mData[nMass] = { 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, // 1450, 1500}; // Observed!!!!!!! Double_t ObservedLimitValues[27] = { 5.169031, 2.127156, 1.119, // new 0.554736, 0.279327, 0.164877, 0.10318, 0.0695557, 0.0507156, 0.0386856, 0.031826, 0.0244583, 0.0194931, 0.0175816, 0.0156609, 0.0132805, 0.0108856, 0.00979614, 0.0088028, 0.00763702, 0.00695305, 0.00662155, 0.0061306, 0.0051651, 0.0056942, 0.00519066, 0.00458145}; // Expected !!!!! Double_t ExpectedLimitValues[27] = { 5.212884, 2.624342, 1.0423, //new 0.39624, 0.206909, 0.113708, 0.0687866, 0.0496826, 0.0375671, 0.028656, 0.0247536, 0.0197548, 0.0155945, 0.0136745, 0.0126492, 0.0102158, 0.00997849, 0.0089798, 0.00806923, 0.00694275, 0.00632095, 0.00601959, 0.00557327, 0.0051651, 0.00517654, 0.00471878, 0.00458145}; //Plus One sigma Double_t PlusOneSigmaLimitValues[27] = { 2.541088, 1.288593, 0.502809, 0.1918498, 0.103455, 0.051169, 0.0343934, 0.0248413, 0.0187836, 0.014328, 0.0106086, 0.0103477, 0.0077972, 0.0058606, 0.005421, 0.0061294, 0.00362851, 0.0040817, 0.00366787, 0.00485995, 0.00379255, 0.00361176, 0.00334397, 0.00361557, 0.00258828, 0.00377502, 0.00320702}; //////////////////////////////////////////////////////////////// // -1 sigma //////////////////////////////////////////////////////////////// Double_t MinusOneSigmaLimitValues[27] = { 1.480962, 0.7831655, 0.2920889, 0.09906, 0.051727, 0.0341121, 0.0171966, 0.0149048, 0.0093917, 0.007164, 0.0082512, 0.0056442, 0.0046784, 0.0032558, 0.00421643, 0.00306477, 0.00362854, 0.00326538, 0.0022007, 0.00208283, 0.00126419, 0.00180588, 0.00167198, 0.00154953, 0.0010353, 0.00094376, 0.00091629}; // Double_t limit_expected[26]; Double_t limit_plusOneSigma[26]; Double_t limit_MinusOneSigma[26]; Double_t limit_observed[26]; for (int i=0; i < 26; i++){ limit_expected[i]=ExpectedLimitValues[i]/XS[mData[i]]; limit_plusOneSigma[i]=(ExpectedLimitValues[i]+PlusOneSigmaLimitValues[i])/XS[mData[i]]; limit_MinusOneSigma[i]=(ExpectedLimitValues[i]-MinusOneSigmaLimitValues[i])/XS[mData[i]]; limit_observed[i]=ObservedLimitValues[i]/XS[mData[i]]; } /* //Asympt CLs Double_t limit_observed[] = {0.0594621, 0.0843084, 0.0609738, 0.0718055, 0.110206, 0.147462, 0.217648, 0.294432, 0.367942, 0.525929, 0.739963, 1.01469, 1.45093, 2.07904, 3.25821}; Double_t limit_expected[] = {0.074707, 0.103027, 0.0668945, 0.0737305, 0.0942383, 0.130371, 0.175293, 0.250977, 0.338867, 0.482422, 0.689453, 0.964844, 1.37109, 1.94531, 2.99219}; */ std::vector<double> limExp; std::vector<double> betaExp; std::vector<double> limPlusSigma; std::vector<double> betaPlusSigma; std::vector<double> limMinusSigma; std::vector<double> betaMinusSigma; std::vector<double> limObs; std::vector<double> betaObs; /////////////////////////////////////////////////////////////////////////////////////////// // Expected limit /////////////////////////////////////////////////////////////////////////////////////////// for(int i = 0; i != 1; ++i) { double lim1 = limit_expected[i]; double lim2 = limit_expected[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); // cout << m1 <<" "<< m2 <<" "<< 1<<" "<< 1<<" "<< lim1/beta/beta<<" "<< lim2/beta/beta <<" "<< " ---> "<< result<<"\n"; if ( result != 0 ) { limExp.push_back(result); betaExp.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } for(int i = 1; i != 2; ++i) { double lim1 = limit_expected[i]; double lim2 = limit_expected[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 1.001; beta >= 0; beta -= 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limExp.push_back(result); betaExp.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } for(int i = 2; i != nMass; ++i) { double lim1 = limit_expected[i]; double lim2 = limit_expected[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limExp.push_back(result); betaExp.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } /////////////////////////////////////////////////////////////////////////////////////////// // Expected +1 sigma limit /////////////////////////////////////////////////////////////////////////////////////////// for(int i = 0; i != 1; ++i) { double lim1 = limit_plusOneSigma[i]; double lim2 = limit_plusOneSigma[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); // cout << m1 <<" "<< m2 <<" "<< 1<<" "<< 1<<" "<< lim1/beta/beta<<" "<< lim2/beta/beta <<" "<< " ---> "<< result<<"\n"; if ( result != 0 ) { limPlusSigma.push_back(result); betaPlusSigma.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } for(int i = 1; i != 2; ++i) { double lim1 = limit_plusOneSigma[i]; double lim2 = limit_plusOneSigma[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 1.001; beta >= 0; beta -= 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limPlusSigma.push_back(result); betaPlusSigma.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } for(int i = 2; i != nMass; ++i) { double lim1 = limit_plusOneSigma[i]; double lim2 = limit_plusOneSigma[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limPlusSigma.push_back(result); betaPlusSigma.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } /////////////////////////////////////////////////////////////////////////////////////////// // Expected -1 sigma limit /////////////////////////////////////////////////////////////////////////////////////////// for(int i = 0; i != 1; ++i) { double lim1 = limit_MinusOneSigma[i]; double lim2 = limit_MinusOneSigma[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); // cout << m1 <<" "<< m2 <<" "<< 1<<" "<< 1<<" "<< lim1/beta/beta<<" "<< lim2/beta/beta <<" "<< " ---> "<< result<<"\n"; if ( result != 0 ) { limMinusSigma.push_back(result); betaMinusSigma.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } for(int i = 1; i != 2; ++i) { double lim1 = limit_MinusOneSigma[i]; double lim2 = limit_MinusOneSigma[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 1.001; beta >= 0; beta -= 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limMinusSigma.push_back(result); betaMinusSigma.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } for(int i = 2; i != nMass; ++i) { double lim1 = limit_MinusOneSigma[i]; double lim2 = limit_MinusOneSigma[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limMinusSigma.push_back(result); betaMinusSigma.push_back(beta); // cout << beta << '\t' << result << endl; //KK } } } /////////////////////////////////////////////////////////////////////////////////////////// // observed limit /////////////////////////////////////////////////////////////////////////////////////////// for(int i = 0; i != 1; ++i) { double lim1 = limit_observed[i]; double lim2 = limit_observed[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limObs.push_back(result); betaObs.push_back(beta); } } } for(int i = 1; i != 2; ++i) { double lim1 = limit_observed[i]; double lim2 = limit_observed[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 1.001; beta >= 0; beta -= 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limObs.push_back(result); betaObs.push_back(beta); } } } for(int i = 2; i != nMass; ++i) { double lim1 = limit_observed[i]; double lim2 = limit_observed[i+1]; double m1 = mData[i]; double m2 = mData[i+1]; for(double beta = 0.001; beta < 1.001; beta += 0.001) { double result = intersection(m1, m2, 1, 1, lim1/beta/beta, lim2/beta/beta); if ( result != 0 ) { limObs.push_back(result); betaObs.push_back(beta); } } } ////////////////////////////////////////////////////////////////// // Expected ////////////////////////////////////////////////////////////////// const int nexp = limExp.size(); // cout <<"--------------------> "<<nexp <<"\n\n\n\n"; Double_t massExp[nexp+4]; Double_t bExp[nexp+4]; for(int i = 0; i != nexp; ++i) { massExp[i] = limExp[i]; bExp[i] = betaExp[i]; // cout <<"###### exp massExp[i] "<<massExp[i] << " bExp[i] "<<bExp[i]<<"\n"; } massExp[nexp] = massExp[nexp-1]; bExp[nexp] = 1; massExp[nexp+1] = 200; bExp[nexp+1] = 1; massExp[nexp+2] = 200; bExp[nexp+2] = bExp[0]; massExp[nexp+3] = massExp[0]; bExp[nexp+3] = bExp[0]; ////////////////////////////////////////////////////////////////// // Plus One Sigma ////////////////////////////////////////////////////////////////// const int nplusSig = limPlusSigma.size(); // cout <<"--------------------> "<<nplusSig <<"\n\n\n\n"; Double_t massPlusOneSigma[nplusSig+4]; Double_t bPlusOneSigma[nplusSig+4]; for(int i = 0; i != nplusSig; ++i) { massPlusOneSigma[i] = limPlusSigma[i]; bPlusOneSigma[i] = betaPlusSigma[i]; // cout <<"###### exp massPlusOneSigma[i] "<<massPlusOneSigma[i] << " bPlusOneSigma[i] "<<bPlusOneSigma[i]<<"\n"; } massPlusOneSigma[nplusSig] = massPlusOneSigma[nplusSig-1]; bPlusOneSigma[nplusSig] = 1; massPlusOneSigma[nplusSig+1] = 200; bPlusOneSigma[nplusSig+1] = 1; massPlusOneSigma[nplusSig+2] = 200; bPlusOneSigma[nplusSig+2] = bPlusOneSigma[0]; massPlusOneSigma[nplusSig+3] = massPlusOneSigma[0]; bPlusOneSigma[nplusSig+3] = bPlusOneSigma[0]; Double_t NewbPlusOneSigma[nexp+4]; for(int i = 0; i != nexp+4; ++i) { NewbPlusOneSigma[i]=bPlusOneSigma[i]-bExp[i]; } ////////////////////////////////////////////////////////////////// // Minus One Sigma ////////////////////////////////////////////////////////////////// const int nMinusSig = limMinusSigma.size(); // cout <<"--------------------> "<<nMinusSig <<"\n\n\n\n"; Double_t massMinusOneSigma[nMinusSig+4]; Double_t bMinusOneSigma[nMinusSig+4]; for(int i = 0; i != nMinusSig; ++i) { massMinusOneSigma[i] = limMinusSigma[i]; bMinusOneSigma[i] = betaMinusSigma[i]; // cout <<"###### exp massMinusOneSigma[i] "<<massMinusOneSigma[i] << " bMinusOneSigma[i] "<<bMinusOneSigma[i]<<"\n"; } massMinusOneSigma[nMinusSig] = massMinusOneSigma[nMinusSig-1]; bMinusOneSigma[nMinusSig] = 1; massMinusOneSigma[nMinusSig+1] = 200; bMinusOneSigma[nMinusSig+1] = 1; massMinusOneSigma[nMinusSig+2] = 200; bMinusOneSigma[nMinusSig+2] = bMinusOneSigma[0]; massMinusOneSigma[nMinusSig+3] = massMinusOneSigma[0]; bMinusOneSigma[nMinusSig+3] = bMinusOneSigma[0]; Double_t NewbMinusOneSigma[nexp+4]; for(int i = 0; i != nexp+4; ++i) { NewbMinusOneSigma[i]=bExp[i]-bMinusOneSigma[i]; // cout<<" mas comaprison "<<massExp[i]<<" "<<massMinusOneSigma[i]<<" "<<massPlusOneSigma[i]<<"\n"; } ////////////////////////////////////////////////////////////////// // Observed ////////////////////////////////////////////////////////////////// const int nobs = limObs.size(); float massObs[nobs+4]; float bObs[nobs+4]; for(int i = 0; i != nobs; ++i) { massObs[i] = limObs[i]; bObs[i] = betaObs[i]; // cout <<"###### obs massObs[i] "<<massObs[i] << " bObs[i] "<<bObs[i]<<"\n"; } massObs[nobs] = massObs[nobs-1]; bObs[nobs] = 1; massObs[nobs+1] = 200; bObs[nobs+1] = 1; massObs[nobs+2] = 200; bObs[nobs+2] = bObs[0]; massObs[nobs+3] = massObs[0]; bObs[nobs+3] = bObs[0]; ////////////////////////////////////////////////////////////////// // TGRAPH ////////////////////////////////////////////////////////////////// // massExp.sort() TGraph* grExp = new TGraph(nexp+4, massExp, bExp); grExp->Sort(&TGraph::CompareX, 0, 0,-1111); TGraph* gPlusOneSigma = new TGraph(nplusSig+4, massPlusOneSigma, bPlusOneSigma); gPlusOneSigma->Sort(&TGraph::CompareX, 0, 0,-1111); TGraph* gMinusOneSigma = new TGraph(nMinusSig+4, massMinusOneSigma, bMinusOneSigma); gMinusOneSigma->Sort(&TGraph::CompareX, 0, 0,-1111); TGraph* grObs = new TGraph(nobs+4, massObs, bObs); // grObs->Sort(); // for(int i = 0; i < nexp+3; ++i) { // cout << i << "\t" << massExp[i] << "\t" << bExp[i] << endl; // } // ------------>Primitives in pad: pad_plot TPad *pad_plot = new TPad("pad_plot", "pad_plot",0,0,1,1); pad_plot->Draw(); pad_plot->cd(); pad_plot->Range(10.71429,-5.02439,1500,3.512195); pad_plot->SetFillColor(0); pad_plot->SetFillStyle(4000); pad_plot->SetBorderMode(0); pad_plot->SetBorderSize(2); // pad_plot->SetLogy(); // pad_plot->SetGridx(); // pad_plot->SetGridy(); pad_plot->SetLeftMargin(0.12); pad_plot->SetRightMargin(0.04); pad_plot->SetTopMargin(0.06); pad_plot->SetBottomMargin(0.12); pad_plot->SetFrameFillStyle(0); pad_plot->SetFrameLineWidth(2); pad_plot->SetFrameBorderMode(0); pad_plot->SetFrameFillStyle(0); pad_plot->SetFrameLineWidth(2); pad_plot->SetFrameBorderMode(0); pad_plot->SetTickx(1); pad_plot->SetTicky(1); TH2F* frame = new TH2F("frame", "", 100, 200, 1000, 100, 0.001, 1); TAxis* ax = frame->GetXaxis(); TAxis* ay = frame->GetYaxis(); ax->SetTitle("M_{LQ} [GeV]"); // ax->SetLabelOffset(0.01); ay->SetTitle("#beta"); //ay->SetTitle("#Beta(LQ#rightarrow#tau b)"); // ax->SetTitleFont(132); ax->SetTitleSize(0.05); // ay->SetTitleFont(132); ay->SetTitleSize(0.05); ay->SetRangeUser(0.,1); frame->Draw(); // grExp->SetLineColor(TColor::GetColor(0, 0, 333)); // grExp->SetFillColorAlpha(TColor::GetColor(200, 222, 285), 0.65); // grObs->SetLineColor(TColor::GetColor(0, 0, 333)); grObs->SetFillColorAlpha(TColor::GetColor(200, 222, 285), 0.65); // grObs->SetLineColor(kBlack); grObs->SetLineWidth(3); grExp->SetLineColor(kBlack); grExp->SetLineWidth(2); grExp->SetLineStyle(7); // grObs->SetFillStyle(3005); // grExp->SetLineWidth(2); // grObs->SetLineWidth(2); // grObs->SetFillStyle(3005); // grObs->Draw("F"); grExp->Draw("L"); // grExp->Draw("Lsame"); // gMinusOneSigma->SetLineColor(kBlue); gMinusOneSigma->SetLineWidth(0); // gMinusOneSigma->SetLineStyle(2); ci = TColor::GetColor("#fcf10f"); gMinusOneSigma->SetFillColorAlpha(15, 0.65); gMinusOneSigma->Draw("f"); // gPlusOneSigma->SetLineColor(kBlue); gPlusOneSigma->SetLineWidth(0); // gPlusOneSigma->SetLineStyle(2); // ci = TColor::GetColor("#fcf10f"); gPlusOneSigma->SetFillColor(0); gPlusOneSigma->Draw("fsame"); // gMinusOneSigma->Draw("Lsame"); grObs->Draw("LSame"); grObs->Draw("fsame"); // grExp->Draw("same"); // frame->Draw("same"); frame->Draw("sameaxis"); // grExp->Draw("Lsame"); // grObs->Draw("fsame"); // // Double_t x[5] = {200,300,400,500,600}; // Double_t y[5] = {5,.1,.9,.7,.5}; // TPolyLine *pline = new TPolyLine(nexp+4,massExp,bExp); // pline->SetFillColor(38); // pline->SetLineColor(2); // pline->SetLineWidth(4); // pline->Draw("f"); // pline->Draw(); // // TLatex* tx = new TLatex(250,0.93,"CMS"); // tx->SetTextFont(61); // tx->SetTextSize(0.05); // tx->Draw("SAME"); // TLatex* tx2 = new TLatex(1000,1.03101,"12.9 fb^{-1} (13 TeV)"); // tx2->SetTextSize(0.04); // tx2->SetTextAlign( 12 ); // tx2->SetTextColor( 1 ); // tx2->SetTextFont ( 42 ); // tx2->Draw("SAME"); float lowX=0.65; float lowY=0.85; TPaveText * lumi = new TPaveText(lowX, lowY+0.06, lowX+0.30, lowY+0.16, "NDC"); lumi->SetBorderSize( 0 ); lumi->SetFillStyle( 0 ); lumi->SetTextAlign( 12 ); lumi->SetTextColor( 1 ); lumi->SetTextSize(0.04); lumi->SetTextFont ( 42 ); lumi->AddText("12.9 fb^{-1} (13 TeV)"); lumi->Draw(); lowX=0.15; lowY=0.75; TPaveText * lumi1 = new TPaveText(lowX, lowY+0.06, lowX+0.15, lowY+0.16, "NDC"); lumi1->SetTextFont(61); lumi1->SetTextSize(0.05); lumi1->SetBorderSize( 0 ); lumi1->SetFillStyle( 0 ); lumi1->SetTextAlign( 12 ); lumi1->SetTextColor( 1 ); lumi1->AddText("CMS"); lumi1->Draw(); Double_t Graph0_felx3001[1000] = {0}; Double_t Graph0_fehx3001[1000] = {0}; // for (int i=0;i < 100; i++){ // // cout << "check--->>>>>"<<massExp[i]<<" "<<bExp[i]<<" "<<Graph0_felx3001[i]<<" "<<Graph0_fehx3001[i]<<" "<<NewbMinusOneSigma[i]<<" "<<NewbPlusOneSigma[i]<<"\n"; // } // const Int_t n = 5; // Double_t x[n] = {200, 250, 300, 350, 400}; // Double_t y[n] = {.2,.3,.4,.5,.6}; // Double_t exl[n] = {0}; // Double_t exh[n] = {0}; // Double_t eyl[n] = {.1,.2,.3,.4,.5}; // Double_t eyh[n] = {.3,.4,.5,.6,.7}; // TGraphAsymmErrors *grae = new TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh); TGraphAsymmErrors *grae = new TGraphAsymmErrors(700,massExp,bExp,Graph0_felx3001,Graph0_fehx3001,NewbMinusOneSigma,NewbPlusOneSigma); grae->Sort(&TGraph::CompareX, 0, 0,-1111); grae->SetName(""); grae->SetTitle(""); ci = TColor::GetColor("#fcf10f"); grae->SetFillColorAlpha(ci, 0.65); // grae->SetMarkerStyle(20); // TH1F *Graph_Graph3002 = new TH1F("Graph_Graph3002","",100,70,1630); // Graph_Graph3002->SetMinimum(0); // Graph_Graph3002->SetMaximum(7.043383); // Graph_Graph3002->SetDirectory(0); // Graph_Graph3002->SetStats(0); // Graph_Graph3002->SetLineStyle(0); // Graph_Graph3002->SetMarkerStyle(20); // Graph_Graph3002->GetXaxis()->SetNdivisions(506); // Graph_Graph3002->GetXaxis()->SetLabelFont(42); // Graph_Graph3002->GetXaxis()->SetTitleSize(0.05); // Graph_Graph3002->GetXaxis()->SetTickLength(0.02); // Graph_Graph3002->GetXaxis()->SetTitleOffset(1.08); // Graph_Graph3002->GetXaxis()->SetTitleFont(42); // Graph_Graph3002->GetYaxis()->SetNdivisions(506); // Graph_Graph3002->GetYaxis()->SetLabelFont(42); // Graph_Graph3002->GetYaxis()->SetLabelOffset(0.007); // Graph_Graph3002->GetYaxis()->SetTitleSize(0.05); // Graph_Graph3002->GetYaxis()->SetTickLength(0.02); // Graph_Graph3002->GetYaxis()->SetTitleOffset(1.08); // Graph_Graph3002->GetYaxis()->SetTitleFont(42); // Graph_Graph3002->GetZaxis()->SetNdivisions(506); // Graph_Graph3002->GetZaxis()->SetLabelFont(42); // Graph_Graph3002->GetZaxis()->SetLabelOffset(0.007); // Graph_Graph3002->GetZaxis()->SetTitleSize(0.05); // Graph_Graph3002->GetZaxis()->SetTickLength(0.02); // Graph_Graph3002->GetZaxis()->SetTitleFont(42); // grae->SetHistogram(Graph_Graph3002); // grae->Draw("3LP"); // TLegend* leg = new TLegend(0.50, 0.14, 0.90, 0.35,"CMS 19.7 fb^{-1}, #sqrt{s} = 8 TeV", "brNDC"); // TLegend* leg = new TLegend(0.50, 0.14, 0.90, 0.35,"19.7 fb^{-1}, #sqrt{s} = 8 TeV", "brNDC"); TLegend* leg = new TLegend(0.45, 0.20, 0.8, 0.35,"", "brNDC"); leg->SetTextFont(42); leg->SetTextSize(0.04); leg->SetMargin(0.15); leg->SetFillColor(0); leg->SetBorderSize(0); leg->AddEntry(grObs, "Observed exclusion","f"); leg->AddEntry(grExp, "Median expected limit","L"); leg->AddEntry(gMinusOneSigma, "68% expected limit","f"); leg->Draw(); //gPad->RedrawAxis(); // c->RedrawAxis(); // pad_plot->Modified(); pad_plot->Draw(); c->cd(); c->Modified(); // c->Print("limit_beta_vs_mass.eps"); c->Print("limit_2D_LQ.pdf"); // c->Print("limit_beta_vs_mass.png"); }