//WW_WZ_cross_section_8TeV.C 
// setup cdfsoft2
// root -l
// root[0] .x WW_WZ_cross_section_8TeV.C
// CMS-AN-12-464 (version 3)
// Main author  -- Ilya Osipnekov
//
// Old paper http://arxiv.org/pdf/1210.7544.pdf
// Measurement of the sum of WW and WZ production with W + dijet events
// in pp collisions at sqrt(s) = 7 TeV
//Eur. Phys. J. C73 (2013) 2283
//CMS Collaboration (Serguei Chatrchyan (Yerevan Phys. Inst.) et al.). Oct 2012. 
//                            SM = 65.6 +/- 2.2 pb (off by 0.25 sigma).
//Our measurement  68.9 +/- 8.7 (stat) +/- 9.7 (syst) +/- 1.5 lumi pb
//                           68.9 +/- 13.1 pb
//
// New result at  8 TeV   
//     Theory        (SM = 80.1 + 2.51/ -1.74 pb)  
//J.M. Campbell, R.K. Ellis and C. Williams, "Vector boson pair production at
// the LHC" , JHEP 07 (2011) 018
/ /SMP-13-008
//Ilya new     114.1 +/- 8.0 (stat) +/- 12.5(syst) +/-  5.0(lumi) 
//                 114.1 +/- 14.5(stat +syst) +5.0
//                 114.1 +/- 15.7
// Luminosity error  changed from 2.2% to 4.4% 
#include <iostream>
#include <iomanip>

#include "TAxis.h"
#include "TLatex.h"
#include "TTree.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH1F.h"
#include "TH2F.h"
#include "THStack.h"
#include "TString.h"
#include "TLegend.h"
#include "TLine.h"
#include "TPad.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TPaveText.h"


using std::cin;
using  std::cout;
using std::endl;
using std::setw;
using std::setprecision;

int WW_WZ_cross_section_8TeV()
    {

    // ------- Setup the canvas ------- 
    gStyle->SetOptStat(0);
    gStyle->SetPadTopMargin(0.1);
    gStyle->SetPadLeftMargin(0.16);
    // gStyle->SetPadRightMargin(0.2);
    // gStyle->SetPadBottomMargin(0.3);
    // gStyle->SetErrorX(0.5);


 TCanvas *c1 = new TCanvas( "c1", " Cross Section WW+WZ ", 200, 10, 500, 500);
 TPad*    c1_1 =(TPad*)c1->GetPrimitive("c1_1");
 c1->cd(1);
 c1->SetTicks(1,1);
 
   // see Table 3
    double Result[8], EResult[8];
    Result[0]   =  128.7;   // sigma(pb) muon anti-btagged 
    EResult[0] =   23.8;    // quadrature of  11.2 (stat) , 21.0(syst)
    Result[1]   =  142.3;   // sigma(pb) electron anti-btagged
    EResult[1] =   24.4;   // quadrature of 12.6 (stat), 20.9 (syst)
    Result[2]    =  126.2;  // sigma(pb) muon btagged 
    EResult[2]   =  46.9;  // quadrature of 46.0(stat), 9.3(syst)
    Result[3]     =  91.8;  // sigma(pb) electron btagged
    EResult[3]   =  51.6;  // quadrature 50.9(stat), 8.6(syst)
    Result[4]     =  65.7;  // sigma(pb) muon boosted
    EResult[4]   =  32.4;  // quadrature of 20.5(stat), 25.1(syst)
    Result[5]     = 86.3;  //  sigma(pb) electron boosted
    EResult[5]   =  34.1; // quadrature 21.5(stat),  26.5(syst)
    double x[8]   = {1., 2., 3., 4., 5., 6., 7., 8.};
    double ex[8] = {0., 0., 0., 0., 0., 0., 0., 0.} ;

/*
    double weight[8];
    double WT = 0. ;
    for (int i = 0; i < 6; i++){
    weight[i] = 1./(EResult[i]*EResult[i]);
    WT =WT + weight[i];
    cout << " i weight[i] " << i << " " << weight[i] << endl;
                                }
				
     double Error;
     Error = 1./TMath::Sqrt(WT);
     cout << "Error " << Error << endl;				
     for(int i = 0; i<6; i++){
     weight[i] = weight[i]/WT;
     cout << " i  weight[i] " << i << " " << weight[i] << endl;
                                  }
    double all = 0.;
    for(int i = 0; i<6; i++){
    all = all + weight[i]*Result[i];
                                }
  
    cout << " all " << all << endl;
    Result[6] = all;
*/
    Result[6] = 114.1;    
    EResult[6] = 15.8; 
    Result[7] = 80.1; // Standard Model (see Ref[46])
    EResult[7] = 2.5; //  line 228  of SMP-13-008	 (+2.51/-1.74)						
  
    TGraphErrors  *gr = new TGraphErrors(8, x, Result, ex, EResult);
    gr->SetMaximum(350.);
    gr->SetMinimum(0.00);
    gr -> GetYaxis() -> SetTitle("#sigma(pb)");
    gr -> GetYaxis() -> CenterTitle();
    gr->SetMarkerColor(kRed);
    gr->SetMarkerStyle(20);
    gr->SetMarkerSize(1.2);
    gr->SetLineWidth(2);

    gr -> GetYaxis() -> SetLabelSize(0.06);
    gr -> GetXaxis() -> SetLabelSize(0.06);


          gr->Draw("AP");

      TLatex l1;
      l1.SetTextSize(0.04);
      l1.DrawLatex(1.0, 320., "#sigma [pp #rightarrow W(#rightarrowl#nu) W/Z(#rightarrowq#bar{q})]");  
      TLatex l2;
      l2.SetTextSize(0.035);
      l2.DrawLatex(1.0, 290., " 1(2): #mu (ele), anti-btagged, jets resolved");  
      TLatex l3;
      l3.SetTextSize(0.035);
      l3.DrawLatex(1.0, 270., " 3(4): #mu (ele), btagged, jets resolved");  
      TLatex l4;
      l4.SetTextSize(0.035);
      l4.DrawLatex(1.0, 250., " 5(6): #mu (ele), boosted, jets merged");  
      TLatex l5;
      l5.SetTextSize(0.035);
      l5.DrawLatex(1.0, 230.., " 7: all channels combined  = 114.1 #pm 15.8 pb");  
      TLatex l6;
      l6.SetTextSize(0.035);
      l6.DrawLatex(1.0, 210.., " 8: Theory prediction (NLO) = 80.1 #pm 2.5 pb");  

      cmspre(); 

      c1->SaveAs("WW_WZ_cross_section_8TeV.pdf");
         return 0;
     }



void cmspre()
{
  TLatex latex;
  latex.SetNDC();
  latex.SetTextSize(0.05);

  latex.SetTextAlign(31); // align right
  latex.DrawLatex(0.9,0.93,"#sqrt{s} = 8 TeV");
  latex.SetTextAlign(31); // align right
  latex.DrawLatex(0.65,0.93,Form("#scale[0.5]{#lower[-0.15]{#it{#int}}}#it{L} dt = %0.1f#kern[0.2]{fb}^{-1}", 19.3));
  latex.SetTextAlign(11); // align left
//  latex.DrawLatex(0.15,0.93,"CMS,  #sqrt{s} = 7 TeV");//preliminary 2011");
  latex.DrawLatex(0.15,0.93,"CMS");

}
