Exemplo n.º 1
0
//------------------------------------------------------------------------------
//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()));
  
}
Exemplo n.º 2
0
        void Draw(const int &rebin=1) {

	  Color_t _sampleColor[nSamples];
            //_sampleColor[iHWW  ] = kRed+1;
            //_sampleColor[iWW   ] = kAzure-9;
            //_sampleColor[iZJets] = kGreen+2;
            //_sampleColor[iZTau]  = kGreen+2;
            //_sampleColor[iTop  ] = kYellow;
            //_sampleColor[iWZ   ] = kAzure-2;
            //_sampleColor[iWJets] = kGray+1;
            //_sampleColor[iWJets] = kViolet-9;
            //_sampleColor[iWJets] = kCyan;

	    _sampleColor[itH   ] = kRed;
            _sampleColor[iWZ   ] = kAzure-9;
            _sampleColor[iZZ   ] = kAzure-5;
            _sampleColor[iWW   ] = kAzure-1;
            _sampleColor[itt   ] = kGray;
            _sampleColor[ittw  ] = kOrange+7;
            _sampleColor[ittz  ] = kOrange+1;
            _sampleColor[iwww  ] = kSpring+9;
            _sampleColor[iwwz  ] = kSpring+3;
            _sampleColor[iwzz  ] = kSpring-7;
            _sampleColor[idyl  ] = kViolet-1;
            _sampleColor[idy   ] = kViolet-1;
	    
            //setUpStyle();
            if(!gPad) new TCanvas();

            THStack* hstack = new THStack();
            for (int i=0; i<nSamples; i++) {

                // in case the user doesn't set it
                if( !_hist[i] ) continue;

                _hist[i]->Rebin(rebin);
                _hist[i]->SetLineColor(_sampleColor[i]);

                // signal gets overlaid
                if (i == itH) continue;

                _hist[i]->SetFillColor(_sampleColor[i]);
                _hist[i]->SetFillStyle(1001);

                hstack->Add(_hist[i]);
            }

            if(_hist[itH]) _hist[itH]->SetLineWidth(3);
            if(_data) _data->Rebin(rebin);
            if(_data) _data->SetLineColor  (kBlack);
            if(_data) _data->SetMarkerStyle(kFullCircle);

            if(_nostack) {
              for(int ihist=0;ihist<(int)_hist.size();ihist++) {
                _hist[ihist]->SetFillStyle(0);
                _hist[ihist]->SetLineWidth(2);
              }
              hstack->Draw("hist,nostack");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            } else {
              hstack->Draw("hist");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            }
            //hstack->SetTitle("CMS preliminary");

            Float_t theMax = hstack->GetMaximum();
            Float_t theMin = hstack->GetMinimum();

	    theMax = 1.0;
            //Float_t theMin = hstack->GetMinimum();

            if (_hist[itH]) {
                if (_hist[itH]->GetMaximum() > theMax) theMax = _hist[itH]->GetMaximum();
                if (_hist[itH]->GetMinimum() < theMin) theMin = _hist[itH]->GetMinimum();
            }

            if (_data) {

                Float_t dataMax = GetMaximumIncludingErrors(_data);

                if (dataMax > theMax) theMax = dataMax;
            }

            if (gPad->GetLogy()) {
                hstack->SetMaximum(500 * theMax);
                hstack->SetMinimum(0.05);
            } else {
                hstack->SetMaximum(1.55 * theMax);
            }

            if(_breakdown) {
                THStackAxisFonts(hstack, "y", "entries");
                hstack->GetHistogram()->LabelsOption("v");
            } else {
                THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                if(_units.Sizeof() == 1) {
                    THStackAxisFonts(hstack, "x", _xLabel.Data());
                    THStackAxisFonts(hstack, "y", "entries");
                } else {
                    THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                    THStackAxisFonts(hstack, "y", TString::Format("entries / %.0f %s", _hist[iWZ]->GetBinWidth(0),_units.Data()));
                }
            }

            // total mess to get it nice, should be redone
            size_t j=0;
            TString higgsLabel = " tH x 100";
            //if(_mass != 0) higgsLabel.Form(" m_{H}=%d",_mass);

	    
            if(_data        ) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _data,         " data",    "lp"); j++; }
            if(_hist[itH   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itH   ], higgsLabel, "l" ); j++; }
            if(_hist[iWZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWZ   ], " WZ",      "f" ); j++; }
            if(_hist[iZZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iZZ   ], " ZZ",      "f" ); j++; }
            if(_hist[iWW   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWW   ], " WW",      "f" ); j++; }
            if(_hist[itt   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itt   ], " tt",      "f" ); j++; }
            if(_hist[ittw  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittw  ], " ttW",     "f" ); j++; }
            if(_hist[ittz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittz  ], " ttZ",     "f" ); j++; }
            if(_hist[iwww  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwww  ], " WWW",     "f" ); j++; }
            if(_hist[iwwz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwwz  ], " WWZ",     "f" ); j++; }
            if(_hist[iwzz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwzz  ], " WZZ",     "f" ); j++; }
            if(_hist[idy   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[idy   ], " Drell-Yan","f" ); j++; }
	    

            //TLatex* luminosity = new TLatex(0.9, 0.815, TString::Format("L = %.1f fb^{-1}",_lumi));
            TLatex* luminosity = new TLatex(0.9, 0.95, TString::Format("CMS Preliminary \\sqrt{s} = 8 TeV, L = %.1f fb^{-1}",_lumi));
            luminosity->SetNDC();
            luminosity->SetTextAlign(32);
            luminosity->SetTextFont(42);
            luminosity->SetTextSize(_tsize);
            luminosity->Draw("same");
            // if(_extraLabel) _extraLabel->Draw("same");
            // return hstack->GetHistogram();
        }
Exemplo n.º 3
0
//------------------------------------------------------------------------------
// 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()));
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
// 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");
}
Exemplo n.º 5
0
THStack* BasePlot::GetStack(bool isLog)  {
    THStack* hstack = new THStack();

    float binWidth = 0;
    for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) {

        _hist[i]->SetLineColor(sampleColor[i]);
        _hist[i]->SetFillColor(sampleColor[i]);
        _hist[i]->SetFillStyle(1001);
        binWidth = _hist[i]->GetBinWidth(1);

        hstack->Add(_hist[i]);
    }

    for (size_t i=0; i<_autreHists.size(); i++) {

        _autreHists[i].second->SetLineColor(autreColors[i]);
        _autreHists[i].second->SetFillColor(autreColors[i]);
        _autreHists[i].second->SetFillStyle(1001);

        hstack->Add(_autreHists[i].second);
    }


    hstack->Draw("GOFF");
    if(_prelim) hstack->SetTitle("CMS preliminary");
    else        hstack->SetTitle("CMS, #sqrt{s} = 7 TeV");

    Float_t theMax = hstack->GetMaximum();
    Float_t theMin = hstack->GetMinimum();

    if (_hist[iHWW]) {
        if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum();
        if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum();
    }

    if (_data) {
        Float_t dataMax = GetMaximumIncludingErrors(_data);
        if (dataMax > theMax) theMax = dataMax;
    }

    int sampCount = GetSampCount();
    float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14);

    // Min --- only need to change if log
    theMin = theMin==0?0.1:theMin/10;
    if(isLog) hstack->SetMinimum(theMin);

    // Max
    if (_myMax != -1) {
        hstack->SetMaximum(_myMax);
    } else if (isLog) {
        hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1));
    } else {
        hstack->SetMaximum(scaleBy * theMax);
    }


    if(_breakdown) {
        THStackAxisFonts(hstack, "y", "entries");
        hstack->GetHistogram()->LabelsOption("v");
    } else {
        THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
        THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data()));
        if(_units.Sizeof() == 1) {
            THStackAxisFonts(hstack, "x", _xLabel.Data());
//            THStackAxisFonts(hstack, "y", "entries");
        }
    }
    return hstack;
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------
// 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()));
}
Exemplo n.º 7
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// drawFigure6
//
//    logy = 0
//    logy = 1
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void drawFigure6(Int_t logy = 0)
{
  gInterpreter->ExecuteMacro("WZPaperStyle.C");

  gSystem->mkdir("pdf", kTRUE);
  gSystem->mkdir("png", kTRUE);


  // Read the input file
  //----------------------------------------------------------------------------
  TString name = "WZ_PtZ_plot_allCh_largeATGC";

  TFile* file = new TFile("rootfiles/" + name + ".root", "read");

  TCanvas* c1 = (TCanvas*)file->Get("c1_allCh");

  TH1F* data     = (TH1F*)c1->FindObject("histo_data_3e");
  TH1F* aTGC_dk  = (TH1F*)c1->FindObject("histo_aTGC_dk_3e");
  TH1F* aTGC_lam = (TH1F*)c1->FindObject("histo_aTGC_lam_3e");
  TH1F* aTGC_dg  = (TH1F*)c1->FindObject("histo_aTGC_dg_3e");
  TH1F* WZ       = (TH1F*)c1->FindObject("histo_SM_3e");
  TH1F* fakes    = (TH1F*)c1->FindObject("fake_0");
  TH1F* ZZ       = (TH1F*)c1->FindObject("total_bkg_rebined_ZZ_0");
  TH1F* Zgamma   = (TH1F*)c1->FindObject("total_bkg_rebined_Zgamma_0");
  TH1F* WV       = (TH1F*)c1->FindObject("total_bkg_rebined_WV_0");
  TH1F* VVV      = (TH1F*)c1->FindObject("total_bkg_rebined_VVV_0");

  WZ->SetFillColor(kOrange-2);
  WZ->SetLineColor(kOrange-2);

  Zgamma->SetFillColor(kRed+1);
  Zgamma->SetLineColor(kRed+1);

  ZZ->SetFillColor(kRed+1);
  ZZ->SetLineColor(kRed+1);

  fakes->SetFillColor(kGray+1);
  fakes->SetLineColor(kGray+1);

  WV->SetFillColor(kRed+1);
  WV->SetLineColor(kRed+1);

  VVV->SetFillColor(kRed+1);
  VVV->SetLineColor(kRed+1);


  // Draw
  //----------------------------------------------------------------------------
  TCanvas* canvas = new TCanvas("canvas", "canvas");

  canvas->SetLogy(logy);

  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.2);
  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->SetTitle("p_{T}^{Z} (GeV)");
  yaxis->SetTitle(Form("Events /  %.0f GeV", data->GetBinWidth(0)));


  // Adjust scale
  //----------------------------------------------------------------------------
  Float_t theMax   = GetMaximumIncludingErrors(data);
  Float_t theMaxMC = GetMaximumIncludingErrors(aTGC_dk);

  if (theMaxMC > theMax) theMax = theMaxMC;

  if (canvas->GetLogy()) {
    data->SetMaximum(15 * theMax);
    data->SetMinimum(1);
  } else {
    data->SetMaximum(1.2 * theMax);
  }


  // Legend
  //----------------------------------------------------------------------------
  Double_t x0;
  Double_t y0;

  if (logy)
    {
      x0 = 0.630;
      y0 = 0.765;

      DrawTLegend(x0 - 0.37, y0 + 2.*(_yoffset+0.001), data,     " Data",                              "ep");
      DrawTLegend(x0 - 0.37, y0 + 1.*(_yoffset+0.001), aTGC_dk,  " WZ aTGC (#Delta#kappa^{Z} = 0.6)",  "l");
      DrawTLegend(x0 - 0.37, y0,                       aTGC_dg,  " WZ aTGC (#Deltag^{Z}_{1} = -0.06)", "l");
      DrawTLegend(x0 - 0.37, y0 - 1.*(_yoffset+0.001), aTGC_lam, " WZ aTGC (#lambda = 0.04)",          "l");
      DrawTLegend(x0,        y0 + 2.*(_yoffset+0.001), WZ,       " WZ",                                "f");
      DrawTLegend(x0,        y0 + 1.*(_yoffset+0.001), fakes,    " Non-prompt leptons",                "f");
      DrawTLegend(x0,        y0,                       ZZ,       " MC background",                     "f");
    }
  else
    {
      x0 = 0.570;
      y0 = 0.755;

      DrawTLegend(x0, y0 + 2.*(_yoffset+0.001), data,     " Data",                              "ep");
      DrawTLegend(x0, y0 + 1.*(_yoffset+0.001), aTGC_dk,  " WZ aTGC (#Delta#kappa^{Z} = 0.6)",  "l");
      DrawTLegend(x0, y0,                       aTGC_dg,  " WZ aTGC (#Deltag^{Z}_{1} = -0.06)", "l");
      DrawTLegend(x0, y0 - 1.*(_yoffset+0.001), aTGC_lam, " WZ aTGC (#lambda = 0.04)",          "l");
      DrawTLegend(x0, y0 - 2.*(_yoffset+0.001), WZ,       " WZ",                                "f");
      DrawTLegend(x0, y0 - 3.*(_yoffset+0.001), fakes,    " Non-prompt leptons",                "f");
      DrawTLegend(x0, y0 - 4.*(_yoffset+0.001), ZZ,       " MC background",                     "f");
    }


  // Finish it
  //----------------------------------------------------------------------------
  data->SetTitle("");

  if (logy)
    {
      DrawTLatex(_cmsTextFont,   0.190, 0.94, 0.055, 11, "CMS");
      //      DrawTLatex(_extraTextFont, 0.315, 0.94, 0.030, 11, "Preliminary");
    }
  else
    {
      DrawTLatex(_cmsTextFont,   0.215, 0.891, 0.055, 13, "CMS");
      //      DrawTLatex(_extraTextFont, 0.215, 0.837, 0.030, 13, "Preliminary");
    }

  DrawTLatex(_lumiTextFont, 0.940, 0.94, 0.040, 31, "19.6 fb^{-1} (8 TeV)");

  WZ      ->Draw("hist,same");
  aTGC_dk ->Draw("hist,same");
  aTGC_lam->Draw("hist,same");
  aTGC_dg ->Draw("hist,same");
  fakes   ->Draw("hist,same");
  ZZ      ->Draw("hist,same");
  Zgamma  ->Draw("hist,same");
  WV      ->Draw("hist,same");
  VVV     ->Draw("hist,same");
  data    ->Draw("ep,same");

  canvas->GetFrame()->DrawClone();
  canvas->RedrawAxis();
  canvas->Update();
  
  TString cname = name;

  if (logy) cname += "_log_range";

  canvas->SaveAs("pdf/" + cname + ".pdf");
  canvas->SaveAs("png/" + cname + ".png");
}