Esempio n. 1
0
//------------------------------------------------------------------------------
// Top
//------------------------------------------------------------------------------
void Top(Double_t &yield,
	 Double_t &statError,
	 Double_t &systError,
	 Double_t &topScaleFactor,
	 Double_t  dyScaleFactor,
	 Int_t     njet,
	 TString   channel,
	 TString   directory,
	 Bool_t    useDataDriven,
	 Int_t     printLevel )
{
  TString path = Form("%s/%djet/%s/", directory.Data(), njet, channel.Data());

  TFile* inputTT   = new TFile(path + "TTbar.root");  
  TFile* inputTW   = new TFile(path + "TW.root");  
  TFile* inputWW   = new TFile(path + "WW.root");  
  TFile* inputWZ   = new TFile(path + "WZ.root");  
  TFile* inputWG   = new TFile(path + "Wgamma.root");
  TFile* inputH125 = new TFile(path + "HWW125.root");
  TFile* inputZZ   = new TFile(path + "ZZ.root");  
  TFile* inputZjnt = new TFile(path + "DY.root");
  TFile* inputWj   = new TFile(path + "WJetsFakes_Total.root");
  TFile* inputData = new TFile(path + "DataRun2012_Total.root");  

  
  //----------------------------------------------------------------------------
  //
  // From LatinosTreeScript.C
  //
  // Float_t pMetCut        = 20 + 25*sameflav;
  // Bool_t  commonCutsTrue = (ptll > 45 && nextra == 0 && (dphilljet < 165.*TMath::Pi()/180. || !sameflav) && mll > 12);
  // Bool_t  topTagged_1jet = (commonCutsTrue && pfmet > 20 && zveto == 1 && mpmet > pMetCut && njet == 1 && nbjet == 1);
  // Bool_t  topTagged_0jet = (commonCutsTrue && pfmet > 20 && zveto == 1 && mpmet > pMetCut && njet  < 1 && !bveto);
  // Bool_t  analysisCuts   = (commonCutsTrue && pfmet > 20 && zveto == 1 && mpmet > pMetCut && njet == 0 && bveto_mu == 1 && bveto_ip == 1);
  // Bool_t  jetVetoCut     = (mll > 12       && pfmet > 20 && zveto == 1 && mpmet > pMetCut && njet == 0);
  //
  // From step3_cff.py
  //
  // nbjet is the number of jets with pt > 30 and jetBProbabilityBJetTags > 1.05
  //
  // bveto_nj30 is true if there are
  // 0 jets b-tagged (trackCountingHighEffBJetTags > 2.1) with 10 < pt <= 30 GeV
  // and
  // 0 soft muons with pt > 3 GeV and deltaR(muon, jets) >= 0.3, for jets with pt > 30 GeV
  //
  // bveto is true if there are 
  // 0 jets b-tagged (trackCountingHighEffBJetTags > 2.1) with 10 < pt < = 30 GeV
  // and
  // 0 soft muons with pt > 30 GeV
  //
  //----------------------------------------------------------------------------
  //
  //                               eff_2b                                  = 1b-tagging (TCHE or soft muon) efficiency in control (b-enriched) sample
  //                           1 - eff_2b                                  = 1b-veto efficiency in control (b-enriched) sample
  //                          (1 - eff_2b) * (1 - eff_2b)                  = 2b-veto efficiency in control (b-enriched) sample
  // eff_0b_tt  =         1 - (1 - eff_2b) * (1 - eff_2b)                  = efficiency for a      tt         event to pass the veto efficiency
  // eff_0b_top = f_tt * [1 - (1 - eff_2b) * (1 - eff_2b)] + f_tW * eff_2b = efficiency for a top (tt and tW) event to pass the veto efficiency
  //
  // N_top_0jet = (N_top_tagged_data - N_top_tagged_mc_bkg) * (1 - eff_0b_top) / eff_0b_top
  // 
  //----------------------------------------------------------------------------


  TH1F* hNTopTaggedEventsControlRegionTT = (TH1F*) inputTT->Get("hNTopTaggedTopControlRegion");  // if (topTagged_1jet && bveto_nj30 == 0)
  TH1F* hNTopControlRegionTT             = (TH1F*) inputTT->Get("hNTopControlRegion");           // if (topTagged_1jet)
  TH1F* hTopTaggedEventsTT               = (TH1F*) inputTT->Get("hTopTaggedEvents");             // if (topTagged_0jet)
  TH1F* hTopTaggingTT                    = (TH1F*) inputTT->Get("hWTopTagging");                 // if (analysisCuts)
  TH1F* hJetVetoTT                       = (TH1F*) inputTT->Get("hWJetVeto");                    // if (jetVetoCut)

  TH1F* hNTopTaggedEventsControlRegionTW = (TH1F*) inputTW->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionTW             = (TH1F*) inputTW->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsTW               = (TH1F*) inputTW->Get("hTopTaggedEvents");
  TH1F* hTopTaggingTW                    = (TH1F*) inputTW->Get("hWTopTagging");
  TH1F* hJetVetoTW                       = (TH1F*) inputTW->Get("hWJetVeto");

  TH1F* hNTopTaggedEventsControlRegionWW = (TH1F*) inputWW->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionWW             = (TH1F*) inputWW->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsWW               = (TH1F*) inputWW->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionWZ = (TH1F*) inputWZ->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionWZ             = (TH1F*) inputWZ->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsWZ               = (TH1F*) inputWZ->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionWG = (TH1F*) inputWG->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionWG             = (TH1F*) inputWG->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsWG               = (TH1F*) inputWG->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionH125 = (TH1F*) inputH125->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionH125             = (TH1F*) inputH125->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsH125               = (TH1F*) inputH125->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionZZ = (TH1F*) inputZZ->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionZZ             = (TH1F*) inputZZ->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsZZ               = (TH1F*) inputZZ->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionWj = (TH1F*) inputWj->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionWj             = (TH1F*) inputWj->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsWj               = (TH1F*) inputWj->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionZjnt = (TH1F*) inputZjnt->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionZjnt		   = (TH1F*) inputZjnt->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsZjnt               = (TH1F*) inputZjnt->Get("hTopTaggedEvents");

  TH1F* hNTopTaggedEventsControlRegionDATA = (TH1F*) inputData->Get("hNTopTaggedTopControlRegion");
  TH1F* hNTopControlRegionDATA             = (TH1F*) inputData->Get("hNTopControlRegion");
  TH1F* hTopTaggedEventsData               = (TH1F*) inputData->Get("hTopTaggedEvents");


  // Yields in (topTagged_1jet && bveto_nj30 == 0)
  //----------------------------------------------------------------------------
  Double_t NnumTT   = hNTopTaggedEventsControlRegionTT  ->GetBinContent(2);
  Double_t NnumTW   = hNTopTaggedEventsControlRegionTW  ->GetBinContent(2) * twScaleFactor;
  Double_t NnumWW   = hNTopTaggedEventsControlRegionWW  ->GetBinContent(2);
  Double_t NnumWZ   = hNTopTaggedEventsControlRegionWZ  ->GetBinContent(2);
  Double_t NnumWG   = hNTopTaggedEventsControlRegionWG  ->GetBinContent(2);
  Double_t NnumH125 = hNTopTaggedEventsControlRegionH125->GetBinContent(2);
  Double_t NnumZZ   = hNTopTaggedEventsControlRegionZZ  ->GetBinContent(2);
  Double_t NnumWj   = hNTopTaggedEventsControlRegionWj  ->GetBinContent(2);
  Double_t NnumZjnt = hNTopTaggedEventsControlRegionZjnt->GetBinContent(2) * dyScaleFactor;
  Double_t NnumData = hNTopTaggedEventsControlRegionDATA->GetBinContent(2);

  Double_t NnumBkg       = NnumTW + NnumWW + NnumWZ + NnumWG + NnumH125 + NnumZZ + NnumWj + NnumZjnt;
  Double_t NnumDataFinal = NnumData - NnumBkg;

  Double_t errNnumTT   = hNTopTaggedEventsControlRegionTT  ->GetBinError(2);
  Double_t errNnumTW   = hNTopTaggedEventsControlRegionTW  ->GetBinError(2) * twScaleFactor;
  Double_t errNnumWW   = hNTopTaggedEventsControlRegionWW  ->GetBinError(2);
  Double_t errNnumWZ   = hNTopTaggedEventsControlRegionWZ  ->GetBinError(2);
  Double_t errNnumWG   = hNTopTaggedEventsControlRegionWG  ->GetBinError(2);
  Double_t errNnumH125 = hNTopTaggedEventsControlRegionH125->GetBinError(2);
  Double_t errNnumZZ   = hNTopTaggedEventsControlRegionZZ  ->GetBinError(2);
  Double_t errNnumWj   = hNTopTaggedEventsControlRegionWj  ->GetBinError(2);
  Double_t errNnumZjnt = hNTopTaggedEventsControlRegionZjnt->GetBinError(2) * dyScaleFactor;
  Double_t errNnumData = hNTopTaggedEventsControlRegionDATA->GetBinError(2);

  Double_t errNnumBkg = 0;
  errNnumBkg += errNnumTW   * errNnumTW;
  errNnumBkg += errNnumWW   * errNnumWW;
  errNnumBkg += errNnumWZ   * errNnumWZ;
  errNnumBkg += errNnumWG   * errNnumWG;
  errNnumBkg += errNnumH125 * errNnumH125;
  errNnumBkg += errNnumZZ   * errNnumZZ;
  errNnumBkg += errNnumWj   * errNnumWj;
  errNnumBkg += errNnumZjnt * errNnumZjnt;
  errNnumBkg  = sqrt(errNnumBkg);

  Double_t errNnumDataFinal = sqrt(errNnumData*errNnumData + errNnumBkg*errNnumBkg);


  // Yields in (topTagged_1jet)
  //----------------------------------------------------------------------------
  Double_t NdenTT   = hNTopControlRegionTT  ->GetBinContent(2);
  Double_t NdenTW   = hNTopControlRegionTW  ->GetBinContent(2) * twScaleFactor;
  Double_t NdenWW   = hNTopControlRegionWW  ->GetBinContent(2);
  Double_t NdenWZ   = hNTopControlRegionWZ  ->GetBinContent(2);
  Double_t NdenWG   = hNTopControlRegionWG  ->GetBinContent(2);
  Double_t NdenH125 = hNTopControlRegionH125->GetBinContent(2);
  Double_t NdenZZ   = hNTopControlRegionZZ  ->GetBinContent(2);
  Double_t NdenWj   = hNTopControlRegionWj  ->GetBinContent(2);
  Double_t NdenZjnt = hNTopControlRegionZjnt->GetBinContent(2) * dyScaleFactor;
  Double_t NdenData = hNTopControlRegionDATA->GetBinContent(2);

  Double_t NdenBkg       = NdenTW + NdenWW + NdenWZ + NdenWG + NdenH125 + NdenZZ + NdenWj + NdenZjnt;
  Double_t NdenDataFinal = NdenData - NdenBkg;

  Double_t errNdenTT   = hNTopControlRegionTT  ->GetBinError(2);
  Double_t errNdenTW   = hNTopControlRegionTW  ->GetBinError(2) * twScaleFactor;
  Double_t errNdenWW   = hNTopControlRegionWW  ->GetBinError(2);
  Double_t errNdenWZ   = hNTopControlRegionWZ  ->GetBinError(2);
  Double_t errNdenWG   = hNTopControlRegionWG  ->GetBinError(2);
  Double_t errNdenH125 = hNTopControlRegionH125->GetBinError(2);
  Double_t errNdenZZ   = hNTopControlRegionZZ  ->GetBinError(2);
  Double_t errNdenWj   = hNTopControlRegionWj  ->GetBinError(2);
  Double_t errNdenZjnt = hNTopControlRegionZjnt->GetBinError(2) * dyScaleFactor;
  Double_t errNdenData = hNTopControlRegionDATA->GetBinError(2);

  Double_t errNdenBkg = 0;
  errNdenBkg += errNdenTW   * errNdenTW;
  errNdenBkg += errNdenWW   * errNdenWW;
  errNdenBkg += errNdenWZ   * errNdenWZ;
  errNdenBkg += errNdenWG   * errNdenWG;
  errNdenBkg += errNdenH125 * errNdenH125;
  errNdenBkg += errNdenZZ   * errNdenZZ;
  errNdenBkg += errNdenWj   * errNdenWj;
  errNdenBkg += errNdenZjnt * errNdenZjnt;
  errNdenBkg  = sqrt(errNdenBkg);

  Double_t errNdenDataFinal = sqrt(errNdenData*errNdenData + errNdenBkg*errNdenBkg);


  // tt and tW yields at jet veto (njet == 0) level
  //----------------------------------------------------------------------------
  Double_t NJetVetott         = hJetVetoTT->GetBinContent(2);
  Double_t NJetVetotW         = hJetVetoTW->GetBinContent(2);
  Double_t NJetVetoTopTotalMC = NJetVetott + NJetVetotW;
  Double_t fTT                = NJetVetott / NJetVetoTopTotalMC;


  // Compute efficiencies
  //----------------------------------------------------------------------------
  Double_t eff2bTT                 = NnumTT / NdenTT;
  Double_t eff2bTW                 = NnumTW / NdenTW;
  Double_t eff2bDataFinal          = NnumDataFinal / NdenDataFinal;
  Double_t eff0b                   = 1 - (1 - eff2bTT)        * (1 - eff2bTT);
  Double_t eff0bDataFinal          = 1 - (1 - eff2bDataFinal) * (1 - eff2bDataFinal);
  Double_t eff0b_fraction          = fTT * eff0b          + (1 - fTT) * eff2bTT;
  Double_t eff0bDataFinal_fraction = fTT * eff0bDataFinal + (1 - fTT) * eff2bDataFinal;

  Double_t erreff2bTT                 = ratioError(NnumTT, NdenTT, errNnumTT, errNdenTT);
  Double_t erreff2bTW                 = ratioError(NnumTW, NdenTW, errNnumTW, errNdenTW);
  Double_t erreff2bDataFinal          = ratioError(NnumDataFinal, NdenDataFinal, errNnumDataFinal, errNdenDataFinal);
  Double_t erreff0b                   = 2 * (1 - eff2bTT)        * erreff2bTT;
  Double_t erreff0bDataFinal          = 2 * (1 - eff2bDataFinal) * erreff2bDataFinal;

  Double_t erreff0b_fraction          = erreff0b;
  Double_t erreff0bDataFinal_fraction = erreff0bDataFinal;




  if (printLevel > 1) {
    printf("\n");
    printf(" N^{control}_{2b} (numerators)\n ------------------------------------\n");
    printf("       tt                = %9.4f +- %8.4f\n", NnumTT,        errNnumTT);
    printf("       tW                = %9.4f +- %8.4f\n", NnumTW,        errNnumTW);
    printf("       WW                = %9.4f +- %8.4f\n", NnumWW,        errNnumWW);
    printf("       WZ                = %9.4f +- %8.4f\n", NnumWZ,        errNnumWZ);
    printf("       Wg                = %9.4f +- %8.4f\n", NnumWG,        errNnumWG);
    printf("       H125              = %9.4f +- %8.4f\n", NnumH125,      errNnumH125);
    printf("       ZZ                = %9.4f +- %8.4f\n", NnumZZ,        errNnumZZ);
    printf("       Wj                = %9.4f +- %8.4f\n", NnumWj,        errNnumWj);
    printf("       Zjnt              = %9.4f +- %8.4f\n", NnumZjnt,      errNnumZjnt);
    printf("       bkg (includes tW) = %9.4f +- %8.4f\n", NnumBkg,       errNnumBkg);
    printf("       data              = %9.0f +- %8.0f\n", NnumData,      errNnumData);
    printf("       data - bkg        = %9.4f +- %8.4f\n", NnumDataFinal, errNnumDataFinal);

    printf("\n\n");
    printf(" N^{control} (denominators)\n ------------------------------------\n");
    printf("       tt                = %9.4f +- %8.4f\n", NdenTT,        errNdenTT);
    printf("       tW                = %9.4f +- %8.4f\n", NdenTW,        errNdenTW);
    printf("       WW                = %9.4f +- %8.4f\n", NdenWW,        errNdenWW);
    printf("       WZ                = %9.4f +- %8.4f\n", NdenWZ,        errNdenWZ);
    printf("       Wg                = %9.4f +- %8.4f\n", NdenWG,        errNdenWG);
    printf("       H125              = %9.4f +- %8.4f\n", NdenH125,      errNdenH125);
    printf("       ZZ                = %9.4f +- %8.4f\n", NdenZZ,        errNdenZZ);
    printf("       Wj                = %9.4f +- %8.4f\n", NdenWj,        errNdenWj);
    printf("       Zjnt              = %9.4f +- %8.4f\n", NdenZjnt,      errNdenZjnt);
    printf("       bkg (includes tW) = %9.4f +- %8.4f\n", NdenBkg,       errNdenBkg);
    printf("       data              = %9.0f +- %8.0f\n", NdenData,      errNdenData);
    printf("       data - bkg        = %9.4f +- %8.4f\n", NdenDataFinal, errNdenDataFinal);

    printf("\n\n");
    printf(" efficiencies\n ------------------------------------\n");
    printf("       eff^{soft}_{2b}_tW   = (%5.2f +- %4.2f)%s\n", 1e2*eff2bTW,                 1e2*erreff2bTW,                 "%");
    printf("       eff^{soft}_{2b}_tt   = (%5.2f +- %4.2f)%s\n", 1e2*eff2bTT,                 1e2*erreff2bTT,                 "%");
    printf("       eff^{soft}_{2b}_data = (%5.2f +- %4.2f)%s\n", 1e2*eff2bDataFinal,          1e2*erreff2bDataFinal,          "%");
    printf("       eff_{0b}_tt          = (%5.2f +- %4.2f)%s\n", 1e2*eff0b,                   1e2*erreff0b,                   "%");
    printf("       eff_{0b}_data        = (%5.2f +- %4.2f)%s\n", 1e2*eff0bDataFinal,          1e2*erreff0bDataFinal,          "%");
    printf(" >>>>> eff_{0b}_top,MC      = (%5.2f +- %4.2f)%s\n", 1e2*eff0b_fraction,          1e2*erreff0b_fraction,          "%");
    printf(" >>>>> eff_{0b}_top,data    = (%5.2f +- %4.2f)%s\n", 1e2*eff0bDataFinal_fraction, 1e2*erreff0bDataFinal_fraction, "%");
  }


  // tt and tW yields at analysis level
  //----------------------------------------------------------------------------
  Double_t Ntt         = hTopTaggingTT->GetBinContent(2);
  Double_t NtW         = hTopTaggingTW->GetBinContent(2);
  Double_t NTopTotalMC = Ntt + NtW;

  Double_t errNtt         = hTopTaggingTT->GetBinError(2);
  Double_t errNtW         = hTopTaggingTW->GetBinError(2);
  Double_t errNTopTotalMC = sqrt(errNtt*errNtt + errNtW*errNtW);


  // Yields in (topTagged_0jet)
  //----------------------------------------------------------------------------
  Double_t NTaggedTT    = hTopTaggedEventsTT  ->GetBinContent(2);
  Double_t NTaggedTW    = hTopTaggedEventsTW  ->GetBinContent(2);
  Double_t NTaggedWW    = hTopTaggedEventsWW  ->GetBinContent(2);
  Double_t NTaggedWZ    = hTopTaggedEventsWZ  ->GetBinContent(2);
  Double_t NTaggedWG    = hTopTaggedEventsWG  ->GetBinContent(2);
  Double_t NTaggedH125  = hTopTaggedEventsH125->GetBinContent(2);
  Double_t NTaggedZZ    = hTopTaggedEventsZZ  ->GetBinContent(2);
  Double_t NTaggedWj    = hTopTaggedEventsWj  ->GetBinContent(2);
  Double_t NTaggedZjnt  = hTopTaggedEventsZjnt->GetBinContent(2) * dyScaleFactor;
  Double_t NTaggedDATA  = hTopTaggedEventsData->GetBinContent(2);

  Double_t errNTaggedTT   = hTopTaggedEventsTT  ->GetBinError(2);
  Double_t errNTaggedTW   = hTopTaggedEventsTW  ->GetBinError(2);
  Double_t errNTaggedWW   = hTopTaggedEventsWW  ->GetBinError(2);
  Double_t errNTaggedWZ   = hTopTaggedEventsWZ  ->GetBinError(2);
  Double_t errNTaggedWG   = hTopTaggedEventsWG  ->GetBinError(2);
  Double_t errNTaggedH125 = hTopTaggedEventsH125->GetBinError(2);
  Double_t errNTaggedZZ   = hTopTaggedEventsZZ  ->GetBinError(2);
  Double_t errNTaggedWj   = hTopTaggedEventsWj  ->GetBinError(2);
  Double_t errNTaggedZjnt = hTopTaggedEventsZjnt->GetBinError(2) * dyScaleFactor;
  Double_t errNTaggedDATA = hTopTaggedEventsData->GetBinError(2);
				   
  Double_t Nbkg = NTaggedWW + NTaggedWZ + NTaggedWG + NTaggedH125 + NTaggedZZ + NTaggedWj + NTaggedZjnt;

  Double_t errNbkg = 0;
  errNbkg += errNTaggedWW     * errNTaggedWW;
  errNbkg += errNTaggedWZ     * errNTaggedWZ;
  errNbkg += errNTaggedWG     * errNTaggedWG;
  errNbkg += errNTaggedH125   * errNTaggedH125;
  errNbkg += errNTaggedZZ     * errNTaggedZZ;
  errNbkg += errNTaggedWj     * errNTaggedWj;
  errNbkg += wjSyst*NTaggedWj * wjSyst*NTaggedWj;
  errNbkg += errNTaggedZjnt   * errNTaggedZjnt;
  errNbkg = sqrt(errNbkg);

  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////
  if (njet == 1) {

    eff0bDataFinal_fraction    = eff2bDataFinal;
    erreff0bDataFinal_fraction = erreff2bDataFinal;

  }
  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////

  

  // Estimate the top yield in the 0-jet bin
  //----------------------------------------------------------------------------
  Double_t NTopEstimatedDataFinal_fraction = (NTaggedDATA - Nbkg) * (1 - eff0bDataFinal_fraction) / eff0bDataFinal_fraction;

  Double_t err1DataFinal_f = errNTaggedDATA * (1 - eff0bDataFinal_fraction) / eff0bDataFinal_fraction;
  Double_t err2DataFinal_f = errNbkg        * (1 - eff0bDataFinal_fraction) / eff0bDataFinal_fraction; 
  Double_t err3DataFinal_f = (NTaggedDATA - Nbkg) * erreff0bDataFinal_fraction / eff0bDataFinal_fraction;
  Double_t err4DataFinal_f = NTopEstimatedDataFinal_fraction * erreff0bDataFinal_fraction / eff0bDataFinal_fraction;

  Double_t errNTopEstimatedDataFinal_fraction = 0;
  errNTopEstimatedDataFinal_fraction += err1DataFinal_f * err1DataFinal_f;
  errNTopEstimatedDataFinal_fraction += err2DataFinal_f * err2DataFinal_f;
  errNTopEstimatedDataFinal_fraction += err3DataFinal_f * err3DataFinal_f;
  errNTopEstimatedDataFinal_fraction += err4DataFinal_f * err4DataFinal_f;
  errNTopEstimatedDataFinal_fraction = sqrt(errNTopEstimatedDataFinal_fraction);

  Double_t SFDataFinal_f = NTopEstimatedDataFinal_fraction / NTopTotalMC;
  


  // Closure test on MC
  //----------------------------------------------------------------------------
  Double_t NTaggedTopMC    = NTaggedTT  + NTaggedTW;
  Double_t errNTaggedTopMC = sqrt(errNTaggedTT*errNTaggedTT + errNTaggedTW*errNTaggedTW);

  Double_t NTopEstimatedClosureMC = NTaggedTopMC * (1 - eff0b_fraction) / eff0b_fraction;

  Double_t err1MC = errNTaggedTopMC * (1 - eff0b_fraction) / eff0b_fraction;
  Double_t err3MC = NTaggedTopMC * erreff0b / eff0b_fraction; 
  Double_t err4MC = NTaggedTopMC * (1 - eff0b_fraction) * erreff0b / (eff0b_fraction * eff0b_fraction);

  Double_t errNTopEstimatedClosureMC = sqrt(err1MC*err1MC + err3MC*err3MC + err4MC*err4MC);



  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////
  if (njet == 1) {
    
    NTopEstimatedClosureMC = NTaggedTopMC * ( 1 - eff2bTT ) / eff2bTT;
    
  }
  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////



  if (printLevel > 1) {
    printf("\n\n");
    printf(" yields in (topTagged_0jet)\n ------------------------------------\n");
    printf("       tt   = %9.4f +- %8.4f\n", NTaggedTT,   errNTaggedTW);
    printf("       tW   = %9.4f +- %8.4f\n", NTaggedTW,   errNTaggedTW);
    printf("       WW   = %9.4f +- %8.4f\n", NTaggedWW,   errNTaggedWW);
    printf("       WZ   = %9.4f +- %8.4f\n", NTaggedWZ,   errNTaggedWZ);
    printf("       Wg   = %9.4f +- %8.4f\n", NTaggedWG,   errNTaggedWG);
    printf("       H125 = %9.4f +- %8.4f\n", NTaggedH125, errNTaggedH125);
    printf("       ZZ   = %9.4f +- %8.4f\n", NTaggedZZ,   errNTaggedZZ);
    printf("       Wj   = %9.4f +- %8.4f\n", NTaggedWj,   errNTaggedWj);
    printf("       Zjnt = %9.4f +- %8.4f\n", NTaggedZjnt, errNTaggedZjnt);
    printf("       bkg  = %9.4f +- %8.4f\n", Nbkg,        errNbkg);
    printf("       data = %9.0f +- %8.0f\n", NTaggedDATA, errNTaggedDATA);

    printf("\n\n");
    printf(" top yield estimation\n ------------------------------------\n");
    printf("       N_top_data                 = %9.4f +- %8.4f\n", NTopEstimatedDataFinal_fraction, errNTopEstimatedDataFinal_fraction);
    printf("       N_top_mc^{cut based}       = %9.4f +- %8.4f\n", NTopTotalMC, errNTopTotalMC);
    printf("       N_top_mc^{data driven}     = %9.4f +- %8.4f\n", NTopEstimatedClosureMC, errNTopEstimatedClosureMC);
    printf(" >>>>> SF (data / mc^{cut based}) = %9.4f\n",          SFDataFinal_f);
  }


  // Final numbers
  //----------------------------------------------------------------------------
  Double_t xtw           = eff2bTW;
  Double_t finalfTT      = fTT + (1-fTT)*xtw;
  Double_t errorfinalfTT = twSyst*fTT*(1 - xtw);


  if (printLevel > 1) {
    printf("\n\n");
    printf(" tt and tW numbers before applying top veto cuts (jet veto level)\n");
    printf(" ------------------------------------\n");
    printf("          x =  %5.2f\n",   xtw);
    printf("       N_tt =  %5.2f\n",   NJetVetott);
    printf("       N_tW =  %5.2f\n",   NJetVetotW);
    printf("       f_tt =  %5.2f%s\n", 1e2*fTT,       "%");
    printf(" final f_tt = (%5.2f +- %4.2f)%s\n", 1e2*finalfTT, 1e2*errorfinalfTT, "%");

    printf("\n\n");
    printf(" final values\n ------------------------------------\n");
    printf("       eff_{0b}_top,data = (%5.2f +- %4.2f (stat.))%s", 1e2*eff0bDataFinal_fraction, 1e2*erreff0bDataFinal_fraction, "%");
    printf("                 (without tW correction)\n");
  }


  eff0bDataFinal_fraction =  finalfTT*eff0bDataFinal + (1-finalfTT)*eff2bDataFinal;

  Double_t stat_error = erreff2bDataFinal * (1 + finalfTT*(1 - 2*eff2bDataFinal));
  Double_t syst_error = errorfinalfTT * (eff0bDataFinal - eff2bDataFinal);

  erreff0bDataFinal_fraction = sqrt(stat_error*stat_error + syst_error*syst_error);

  
  if (printLevel > 1) {
    printf("       eff_{0b}_top,data = (%5.2f +- %4.2f (stat.) +- %4.2f (syst.))%s",
	   1e2*eff0bDataFinal_fraction, 1e2*stat_error, 1e2*syst_error, "%");
    printf(" (with    tW correction)\n");
    printf("       eff_{0b}_top,data = (%5.2f +- %4.2f (total))%s\n",
	   1e2*eff0bDataFinal_fraction, 1e2*erreff0bDataFinal_fraction, "%");
  }


  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////
  if (njet == 1) {

    eff0bDataFinal_fraction    = eff2bDataFinal;
    erreff0bDataFinal_fraction = erreff2bDataFinal;
  }
  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////


  // Final top yield estimation
  //----------------------------------------------------------------------------
  NTopEstimatedDataFinal_fraction = (NTaggedDATA - Nbkg) * (1 - eff0bDataFinal_fraction) / eff0bDataFinal_fraction;

  err1DataFinal_f = errNTaggedDATA * (1 - eff0bDataFinal_fraction) / eff0bDataFinal_fraction;
  err2DataFinal_f =        errNbkg * (1 - eff0bDataFinal_fraction) / eff0bDataFinal_fraction;

  errNTopEstimatedDataFinal_fraction = sqrt(err1DataFinal_f*err1DataFinal_f + err2DataFinal_f*err2DataFinal_f);  // Final statistical error

  Double_t errtotal_syst = (NTaggedDATA - Nbkg) * erreff0bDataFinal_fraction / (eff0bDataFinal_fraction*eff0bDataFinal_fraction);  // Final systematic error


  // Save the result
  //----------------------------------------------------------------------------
  yield          = (useDataDriven) ? NTopEstimatedDataFinal_fraction : NTopTotalMC;
  statError      = errNTopEstimatedDataFinal_fraction;
  systError      = errtotal_syst;
  topScaleFactor = yield / NTopTotalMC;


  Double_t topScaleFactorError = ratioError(yield,
					    NTopTotalMC,
					    sqrt(statError*statError + systError*systError),
					    errNTopTotalMC);


  // For the note
  //----------------------------------------------------------------------------
  if (printLevel > 0) {
    printf("\n \\hline \n"); 
    printf("[%s] Top values \\\\ \n", channel.Data());
    printf("\\hline \n"); 
    printf(" $N^{control,data}$                    &   %4.0f \\\\ \n",                      NdenData);
    printf(" $N^{control,data}_{tag}$              &   %4.0f \\\\ \n",                      NnumData);
    printf(" $eff_{top-tag}^{data}$  ($\%s$)           & %6.1f $\\pm$ %4.1f \\\\ \n", "%", 1e2*eff2bDataFinal,          1e2*erreff2bDataFinal);
    printf(" $eff_{top-tag}^{tW}$    ($\%s$)           & %6.1f $\\pm$ %4.1f \\\\ \n", "%", 1e2*eff2bTW,                 1e2*erreff2bTW);
    printf(" $f_{tt}$                ($\%s$)           & %6.1f $\\pm$ %4.1f \\\\ \n", "%", 1e2*finalfTT,                1e2*errorfinalfTT);
    printf(" $eff_{top-tag}^{0-jet}$ ($\%s$)           & %6.1f $\\pm$ %4.1f \\\\ \n", "%", 1e2*eff0bDataFinal_fraction, 1e2*erreff0bDataFinal_fraction);
    printf(" data top-tagged events              &   %4.0f \\\\ \n",                      NTaggedDATA);
    printf(" background events in control region & %6.1f $\\pm$ %4.1f \\\\ \n",           Nbkg,                        errNbkg);
    printf("\\hline \n"); 
    printf(" estimated top events in simulation  & %6.1f $\\pm$ %4.1f \\\\ \n",           NTopTotalMC,                 errNTopTotalMC);
    printf(" data-driven top estimate            & %6.1f $\\pm$ %4.1f $\\pm$ %4.1f\\\\ \n",           yield,                       statError,systError  );
    printf(" data/MC                             & %6.2f $\\pm$ %4.2f \\\\ \n",         topScaleFactor,              topScaleFactorError);
    printf("\\hline \n \n"); 
    printf("\n [%s] Top relative systematic uncertainties\n", channel.Data());
    printf(" -------------------------------------------------\n");
    printf(" top normalisation = %.0f (stat.) $\\bigoplus$ %.0f (syst.)\n\n",
	   1e2*statError/yield, 1e2*systError/yield);
  }
Esempio n. 2
0
void SampleDiagnostics::write() const
{
  if (passedRate == 0) {
    std::cerr << "WARNING :  No accumulated rate for " << name << ". Maybe you just didn't run over it/them?" << std::endl;
    return;
  }


  //.. Histogram output .......................................................
  const Int_t       numDatasets   = static_cast<Int_t>(size());
  const UInt_t      numBins       = numDatasets + 3;
  TH2*              hCorrelation  = new TH2F("h_correlation_" + name, name, numBins, 0, numBins, numBins, 0, numBins);
  TH2*              hSharedRate   = new TH2F("h_shared_rate_" + name, name, numBins, 0, numBins, numBins, 0, numBins);
  //...........................................................................


  Double_t          overhead      = 0;
  Double_t          overheadErr   = 0;
  for (Int_t iSet = 0, xBin = 1; iSet < numDatasets; ++iSet, ++xBin) {
    const Dataset&  dataset       = at(iSet);
    if (!dataset.isNewTrigger) {
      overhead     += dataset.rate;
      overheadErr  += dataset.rateUncertainty2;      // I think this is over-estimating it because the values are NOT uncorrelated, but oh well
    }

    if (iSet == firstNewTrigger)    ++xBin;
    if (dataset.rate == 0)          continue;
    for (Int_t jSet = 0, yBin = 1; jSet <= numDatasets; ++jSet, ++yBin) {
      if (jSet == firstNewTrigger)  ++yBin;
      if (jSet == numDatasets)      ++yBin;

      hCorrelation->SetBinContent (xBin, yBin, commonRates[iSet][jSet] / dataset.rate);
      hCorrelation->SetBinError   (xBin, yBin, ratioError(commonRates[iSet][jSet], commonRateUncertainties2[iSet][jSet], dataset.rate, dataset.rateUncertainty2));
      hSharedRate ->SetBinContent (xBin, yBin, commonRates[iSet][jSet]);
      hSharedRate ->SetBinError   (xBin, yBin, TMath::Sqrt(commonRateUncertainties2[iSet][jSet]));
    } // end loop over other datasets

    // Rightmost column is the fraction of rate out of the total
    hCorrelation->SetBinContent   (numBins, xBin, dataset.rate / passedRate);
    hCorrelation->SetBinError     (numBins, xBin, ratioError(dataset.rate, dataset.rateUncertainty2, passedRate, passedRateUncertainty2));
    hSharedRate ->SetBinContent   (numBins, xBin, dataset.rate);
    hSharedRate ->SetBinError     (numBins, xBin, TMath::Sqrt(dataset.rateUncertainty2));
  } // end loop over datasets

  // Top-right cell is the total overhead for the _current_ datasets (not including new triggers)
  hSharedRate ->SetBinContent     (numBins, numBins, overhead);
  hSharedRate ->SetBinError       (numBins, numBins, TMath::Sqrt(overheadErr));
  overheadErr       = ratioError  (overhead, overheadErr, passedRate, passedRateUncertainty2);
  overhead         /= passedRate; // Can only do this after error is computed
  overhead         -= 1;
  hCorrelation->SetBinContent     (numBins, numBins, overhead);
  hCorrelation->SetBinError       (numBins, numBins, overheadErr);



  //...........................................................................
  // Histogram format
  hCorrelation->SetTitle  (TString::Format("%s (overhead = %.3g%% #pm %.3g%%)" , hCorrelation->GetTitle(), 100*overhead, 100*overheadErr));
  hSharedRate ->SetTitle  (TString::Format("%s (total rate = %.3g #pm %.3g Hz)", hSharedRate ->GetTitle(), passedRate, TMath::Sqrt(passedRateUncertainty2)));
  hCorrelation->SetZTitle ("(X #cap Y) / X");   hSharedRate->SetZTitle ("X #cap Y");
  hCorrelation->SetOption ("colz");             hSharedRate->SetOption ("colz");
  hCorrelation->SetStats  (kFALSE);             hSharedRate->SetStats  (kFALSE);
  hCorrelation->SetMinimum(0);                  hSharedRate->SetMinimum(0);
  hCorrelation->SetMaximum(1);

  std::vector<TAxis*>     axes;
  axes.push_back(hCorrelation->GetXaxis());     axes.push_back(hCorrelation->GetYaxis());
  axes.push_back(hSharedRate ->GetXaxis());     axes.push_back(hSharedRate ->GetYaxis());
  const UInt_t            numAxes   = axes.size();
  for (UInt_t iAxis = 0; iAxis < numAxes; ++iAxis) {
    TAxis*                axis      = axes[iAxis];
    for (Int_t iSet = 0, bin = 1; iSet < numDatasets; ++iSet, ++bin) {
      if (iSet == firstNewTrigger)  ++bin;
      axis->SetBinLabel(bin, at(iSet).name);
    } // end loop over datasets
    axis->SetLabelSize    (0.04f);
    axis->LabelsOption    ("v");
    axis->SetTitle        (iAxis % 2 == 0 ? "X" : "Y");
  } // end loop over axes to format
  hCorrelation->GetXaxis()->SetBinLabel(numBins, "rate / total");
  hCorrelation->GetYaxis()->SetBinLabel(numBins, "overlap / rate");
  hSharedRate ->GetXaxis()->SetBinLabel(numBins, "rate");
  hSharedRate ->GetYaxis()->SetBinLabel(numBins, "overlap");

  if (gDirectory->GetDirectory("unnormalized") == 0)
    gDirectory->mkdir("unnormalized");
  gDirectory->cd("unnormalized");     hSharedRate ->Write();
  gDirectory->cd("/");                hCorrelation->Write();
  //...........................................................................
}
Esempio n. 3
0
//------------------------------------------------------------------------------
// XS
//------------------------------------------------------------------------------
void XS(Double_t &xsValue,
	Double_t &xsStat,
	Double_t &xsSyst,
	Double_t &xsLumi,
	Double_t  luminosity,
	Int_t     njet,
	TString   channel,
	TString   cutLevel,
	Bool_t    useNM1,
	TString   directory,
	Bool_t    useDataDriven,
	Int_t     printLevel)
{


  Int_t defineChannel = -1; 

  if ( njet == 0 && channel == "SF")  defineChannel  = jet0_SF;
  if ( njet == 0 && channel == "OF")  defineChannel  = jet0_OF;
  if ( njet == 1 && channel == "SF")  defineChannel  = jet1_SF;
  if ( njet == 1 && channel == "OF")  defineChannel  = jet1_OF;
  if ( njet == 0 && channel == "All")  defineChannel  = jet0;
  if ( njet == 1 && channel == "All")  defineChannel  = jet1;

  analysisLevel = cutLevel;

  if (useNM1) analysisLevel += "_NM1";

  TString dyChannel = "SF";

  if (channel.Contains("All") && printLevel > 0) {
    printf("\n");
    printf("   WWFull xs = %.2f pb;   WWto2L xs = %.2f pb\n", nlo8tev, nlo8tev*BR_WW_to_lnln);
    printf(" qqWWFull xs = %.2f pb; qqWWto2L xs = %.2f pb\n", nlo8tev*0.97, nlo8tev*0.97*BR_WW_to_lnln);
  }

  if (channel.Contains("EE"))   dyChannel = "EE";
  if (channel.Contains("MuMu")) dyChannel = "MuMu";

  Double_t dyScaleFactor       = -999;
  Double_t dyScaleFactorForTop = -999;
  Double_t topScaleFactor      = -999;

  Double_t NDY [3];
  Double_t NTop[3];


  // Needed to always have the SF DY scale factor in the top estimation
  //----------------------------------------------------------------------------
  DY(NDY[0],
     NDY[1],
     NDY[2],
     dyScaleFactorForTop,
     njet,
     "SF",  // "SF" --> dyChannel (individual topScaleFactor)
     directory,
     useDataDriven,
     0,
     false);

    Top(NTop[0],
      NTop[1],
      NTop[2],
      topScaleFactor,
      dyScaleFactorForTop, /// should be 1 in case of OF 0nly??? 
      njet,
      "All",  // "All" --> channel (individual topScaleFactor)
      directory,
      useDataDriven,
      printLevel);

  
    DY(NDY[0],
     NDY[1],
     NDY[2],
     dyScaleFactor,
     njet,
     dyChannel,
     directory,
     useDataDriven,
     printLevel,
     false);
  

  // Input files
  //----------------------------------------------------------------------------
  TString path = Form("%s/%djet/%s/", directory.Data(), njet, channel.Data());

  TFile* inputWW       = new TFile(path + "WW_pow_nnll.root");  
  TFile* inputggWW     = new TFile(path + "ggWWto2L.root");  
  TFile* inputqqWW     = new TFile(path + "WWTo2L2Nu_pow_nnll.root");  
  TFile* inputTT       = new TFile(path + "TTbar.root");  
  TFile* inputTW       = new TFile(path + "TW.root");  
  TFile* inputWj       = new TFile(path + "WJetsFakes_Total.root");
  TFile* inputWZ       = new TFile(path + "WZ.root");  
  TFile* inputZZ       = new TFile(path + "ZZ.root");  
  TFile* inputDY       = new TFile(path + "DY.root");  
  TFile* inputDYtautau = new TFile(path + "DYtautau.root");  
  TFile* inputWg       = new TFile(path + "Wgamma.root");  
  TFile* inputWgS      = new TFile(path + "WgammaStar.root"); 
  TFile* inputWgNoS    = new TFile(path + "WgammaNoStar.root");  
  TFile* inputH125     = new TFile(path + "HWW125.root"); 
  TFile* inputZgamma   = new TFile(path + "Zgamma.root");  
  TFile* inputVVV      = new TFile(path + "VVV.root");  

  TFile* inputData     = new TFile(path + "DataRun2012_Total.root");

  TFile* inputDYOF = new TFile(Form("%s/%djet/OF/DY.root", directory.Data(), njet));


  //----------------------------------------------------------------------------
  //
  // Estimate WW cross-section
  //
  //----------------------------------------------------------------------------
  TH1F* hNWW       = (TH1F*) inputWW      ->Get("hW" + analysisLevel);
  TH1F* hNggWW     = (TH1F*) inputggWW    ->Get("hW" + analysisLevel);
  TH1F* hNqqWW     = (TH1F*) inputqqWW    ->Get("hW" + analysisLevel);
  TH1F* hNTT       = (TH1F*) inputTT      ->Get("hW" + analysisLevel);
  TH1F* hNTW       = (TH1F*) inputTW      ->Get("hW" + analysisLevel);
  TH1F* hNWj       = (TH1F*) inputWj      ->Get("hW" + analysisLevel);
  TH1F* hNWZ       = (TH1F*) inputWZ      ->Get("hW" + analysisLevel);
  TH1F* hNZZ       = (TH1F*) inputZZ      ->Get("hW" + analysisLevel);
  TH1F* hNDY       = (TH1F*) inputDY      ->Get("hW" + analysisLevel);
  TH1F* hNDYtautau = (TH1F*) inputDYtautau->Get("hW" + analysisLevel);
  TH1F* hNWg       = (TH1F*) inputWg      ->Get("hW" + analysisLevel);
  TH1F* hNWgS      = (TH1F*) inputWgS     ->Get("hW" + analysisLevel);
  TH1F* hNWgNoS    = (TH1F*) inputWgNoS   ->Get("hW" + analysisLevel);
  TH1F* hNH125     = (TH1F*) inputH125    ->Get("hW" + analysisLevel);
  TH1F* hNZgamma   = (TH1F*) inputZgamma  ->Get("hW" + analysisLevel);
  TH1F* hNVVV      = (TH1F*) inputVVV     ->Get("hW" + analysisLevel);
  TH1F* hNData     = (TH1F*) inputData    ->Get("hW" + analysisLevel);
  TH1F* hNDYOF     = (TH1F*) inputDYOF    ->Get("hW" + analysisLevel);


  // Yields
  //----------------------------------------------------------------------------
  Double_t NggWW[]     = {hNggWW    ->GetBinContent(2), hNggWW    ->GetBinError(2), 0.00};
  Double_t NqqWW[]     = {hNqqWW    ->GetBinContent(2), hNqqWW    ->GetBinError(2), 0.00};
  Double_t NWW[]       = {hNWW      ->GetBinContent(2), hNWW      ->GetBinError(2), 0.00};
  Double_t NWj[]       = {hNWj      ->GetBinContent(2), hNWj      ->GetBinError(2), 0.36*hNWj->GetBinContent(2)};
  Double_t NWZ[]       = {hNWZ      ->GetBinContent(2), hNWZ      ->GetBinError(2), 0.00};
  Double_t NZZ[]       = {hNZZ      ->GetBinContent(2), hNZZ      ->GetBinError(2), 0.00};
  Double_t NDYtautau[] = {hNDYtautau->GetBinContent(2), hNDYtautau->GetBinError(2), 0.50*hNDYtautau->GetBinContent(2)}; // [*]
  Double_t NWg[]       = {hNWg      ->GetBinContent(2), hNWg      ->GetBinError(2), 0.00};
  Double_t NWgS[]      = {hNWgS     ->GetBinContent(2), hNWgS     ->GetBinError(2), 0.00};
  Double_t NWgNoS[]    = {hNWgNoS   ->GetBinContent(2), hNWgNoS   ->GetBinError(2), 0.00};
  Double_t NH125[]     = {hNH125    ->GetBinContent(2), hNH125    ->GetBinError(2), 0.00};
  Double_t NZgamma[]   = {hNZgamma  ->GetBinContent(2), hNZgamma  ->GetBinError(2), 0.00};
  Double_t NVVV[]      = {hNVVV     ->GetBinContent(2), hNVVV     ->GetBinError(2), 0.00};
  Double_t NData[]     = {hNData    ->GetBinContent(2), hNData    ->GetBinError(2)};


  // [*] Andrea: A normalization uncertainty of 50% has been added on final estimation of dytautau.
   

  // Top yields for the non-inclusive channels
  //----------------------------------------------------------------------------
  if (!channel.Contains("All")) {

    Double_t NTT[] = {hNTT->GetBinContent(2), hNTT->GetBinError(2), 0.0};
    Double_t NTW[] = {hNTW->GetBinContent(2), hNTW->GetBinError(2), 0.0};

    NTop[2] = NTop[2] * topScaleFactor * (NTT[0] + NTW[0]) / NTop[0];  // syst.
    NTop[0] = topScaleFactor * (NTT[0] + NTW[0]);                      // yield
    NTop[1] = topScaleFactor * sqrt(NTT[1]*NTT[1] + NTW[1]*NTW[1]);    // stat.
    }


  // DY yields for the {OF, EMu, MuE} channels
  //----------------------------------------------------------------------------
  if (channel.Contains("OF")  ||
      channel.Contains("EMu") ||
      channel.Contains("MuE")) {

    NDY[2] = NDY[2] * hNDY->GetBinContent(2) / NDY[0];  // syst.
    NDY[0] = hNDY->GetBinContent(2);                    // yield  // ---> use MC because is OF 
    NDY[1] = hNDY->GetBinError(2);                      // stat.
  }


  // DY yield for the All channel
  //----------------------------------------------------------------------------
  if (channel.Contains("All")) {

    NDY[2] = NDY[2] * (NDY[0] + hNDYOF->GetBinContent(2)) / NDY[0];                // syst.
    NDY[0] = NDY[0] + hNDYOF->GetBinContent(2);                                    // yield
    NDY[1] = sqrt(NDY[1]*NDY[1] + hNDYOF->GetBinError(2)*hNDYOF->GetBinError(2));  // stat.
  }


  // Add relative systematic uncertainties
  //----------------------------------------------------------------------------
  

  NggWW[2] = Systematics [ggWW+defineChannel]   ;  // Relative systematic uncertainty
  NqqWW[2] = Systematics [WW+defineChannel]   ;  // Relative systematic uncertainty

  cout << WW+defineChannel << endl;

  NWW[2]  = (NggWW[2]*NggWW[0] * NggWW[2]*NggWW[0]);
  NWW[2] += (NqqWW[2]*NqqWW[0] * NqqWW[2]*NqqWW[0]);
  NWW[2]  = sqrt(NWW[2]) / NWW[0];  // Relative systematic uncertainty

  NWZ    [2] =  Systematics [VV+defineChannel] * NWZ    [0] / 1e2;  // Absolute systematic uncertainty
  NZZ    [2] =  Systematics [VV+defineChannel] * NZZ    [0] / 1e2;  // Absolute systematic uncertainty

  NWgNoS [2] =  Systematics [Vg+defineChannel];  // Relative systematic uncertainty
  NWgS   [2] =  Systematics [VgS+defineChannel]; // Relative systematic uncertainty

  NWg    [2] = (NWgNoS [2]*NWgNoS [0] * NWgNoS [2]*NWgNoS [0]) / 1e4;  
  NWg    [2] += (NWgS [2]*NWgS [0] * NWgS [2]*NWgS [0]) / 1e4;
  NWg    [2] = sqrt(NWg [2]);// Absolute systematic uncertainty

  NH125  [2] =  Systematics [ggH+defineChannel]* NH125  [0] / 1e2;  // Absolute systematic uncertainty
  NZgamma[2] =  Systematics [Vg+defineChannel] * NZgamma[0] / 1e2;  // Absolute systematic uncertainty
  NVVV   [2] =  Systematics [VVV+defineChannel]* NVVV   [0] / 1e2;  // Absolute systematic uncertainty




  Double_t Background = NWj[0] + NWZ[0] + NZZ[0] + NWg[0] + NTop[0] + NDY[0] + NDYtautau[0] + NH125[0]  + NZgamma[0] + NVVV[0];
  
  Double_t statErrorB = sqrt(NWj      [1]*NWj      [1] +
			     NWZ      [1]*NWZ      [1] +
			     NZZ      [1]*NZZ      [1] +
			     NWg      [1]*NWg      [1] +
			     NTop     [1]*NTop     [1] +
			     NDY      [1]*NDY      [1] +
			     NDYtautau[1]*NDYtautau[1] +
			     NH125    [1]*NH125    [1] +
			     NZgamma  [1]*NZgamma  [1] +
			     NVVV     [1]*NVVV     [1]);

  Double_t systErrorB = sqrt(NWj      [2]*NWj      [2] +
			     NWZ      [2]*NWZ      [2] +
			     NZZ      [2]*NZZ      [2] +
			     NWg      [2]*NWg      [2] +
			     NTop     [2]*NTop     [2] +
			     NDY      [2]*NDY      [2] +
			     NDYtautau[2]*NDYtautau[2] +
			     NH125    [2]*NH125    [2] +
			     NZgamma  [2]*NZgamma  [2] +
			     NVVV     [2]*NVVV     [2]);

  Double_t totalErrorB = sqrt(statErrorB*statErrorB + systErrorB*systErrorB);


  //----------------------------------------------------------------------------
  //
  // Estimate WW efficiency
  //
  //----------------------------------------------------------------------------
  TH1F* hgg = (TH1F*) inputggWW->Get("hWeff" + analysisLevel);
  TH1F* hqq = (TH1F*) inputqqWW->Get("hWeff" + analysisLevel);

  Double_t NGenggWW = NTotalggWW;
  Double_t NGenqqWW = NTotalqqWW;

  Double_t f_gg = ggWW_xs / (ggWW_xs + qqWW_xs);
  Double_t f_qq = 1 - f_gg;


  Printf("%5.3f, %5.3f" ,hqq->GetBinContent(2),  NGenqqWW);

  Double_t ggWW_efficiency = ratioValue(hgg->GetBinContent(2), NGenggWW);
  Double_t qqWW_efficiency = ratioValue(hqq->GetBinContent(2), NGenqqWW);
  Double_t   WW_efficiency = f_gg*ggWW_efficiency + f_qq*qqWW_efficiency;

  Double_t ggWW_efficiencyErr = ratioError(hgg->GetBinContent(2), NGenggWW, hgg->GetBinError(2), sqrt(NGenggWW));
  Double_t qqWW_efficiencyErr = ratioError(hqq->GetBinContent(2), NGenqqWW, hqq->GetBinError(2), sqrt(NGenqqWW));

  // Systematic component
  Double_t WW_efficiencyErr = (f_gg*NggWW[2]*NggWW[0] + f_qq*NqqWW[2]*NqqWW[0]) / NWW[0];
  WW_efficiencyErr *= WW_efficiency / 1e2;
  WW_efficiencyErr *= WW_efficiencyErr;

  // Statistical component (negligible)
  WW_efficiencyErr += (f_gg*ggWW_efficiencyErr)*(f_gg*ggWW_efficiencyErr);
  WW_efficiencyErr += (f_qq*qqWW_efficiencyErr)*(f_qq*qqWW_efficiencyErr);

  // Absolute efficiency uncertainty
  WW_efficiencyErr = sqrt(WW_efficiencyErr);


  if (printLevel > 0) {
    printf("\n signal efficiencies\n");
    printf(" -------------------------------------------------\n");
    printf("       ggWW efficiency = (%6.3f +- %5.3f)%s (stat.)\n", 1e2*ggWW_efficiency, 1e2*ggWW_efficiencyErr, "%");
    printf("       qqWW efficiency = (%6.3f +- %5.3f)%s (stat.)\n", 1e2*qqWW_efficiency, 1e2*qqWW_efficiencyErr, "%");
    printf("         WW efficiency = (%6.3f +- %5.3f)%s (total)\n", 1e2*  WW_efficiency, 1e2*  WW_efficiencyErr, "%");
  }


  // Estimate WW cross-section
  //----------------------------------------------------------------------------
  Double_t xs = (NData[0] - Background) / (luminosity * WW_efficiency);

  xs /= BR_WW_to_lnln;

  //cout << "datos!! " << (NData[0] - Background) << endl;

  // Relative errors
  //----------------------------------------------------------------------------
  Double_t errxsStats = 1e2 * sqrt(NData[0]) / (NData[0] - Background);
  Double_t errxsBkg   = 1e2 * totalErrorB    / (NData[0] - Background);
  Double_t errxsEff   = 1e2 * WW_efficiencyErr / WW_efficiency;
  Double_t errxsSyst  = sqrt(errxsBkg*errxsBkg + errxsEff*errxsEff);
  Double_t errxsLumi  = 2.6;


  if (printLevel > 0) {
    printf("\n [PAS]");
    printf(" The total uncertainty on the background estimation is about %.0f%s,",
	   1e2 * totalErrorB / Background, "%");
    printf(" [PAS]\n");
  }


  // Save the result
  //----------------------------------------------------------------------------
  xsValue = xs;
  xsStat  = xs * errxsStats / 1e2;
  xsSyst  = xs * errxsSyst  / 1e2;
  xsLumi  = xs * errxsLumi  / 1e2;


  // Print
  //----------------------------------------------------------------------------
  Double_t statErrorVV = sqrt(NWZ[1]*NWZ[1] + NZZ[1]*NZZ[1]);
  Double_t systErrorVV = sqrt(NWZ[2]*NWZ[2] + NZZ[2]*NZZ[2]);

  Double_t statErrorDYAll = sqrt(NDY[1]*NDY[1] + NDYtautau[1]*NDYtautau[1]);
  Double_t systErrorDYAll = sqrt(NDY[2]*NDY[2] + NDYtautau[2]*NDYtautau[2]);

  Double_t statErrorSPlusB = sqrt(NWW[1]*NWW[1]                           + statErrorB*statErrorB);
  Double_t systErrorSPlusB = sqrt((NWW[2]*NWW[0]/1e2)*(NWW[2]*NWW[0]/1e2) + systErrorB*systErrorB);


  if (printLevel > 0) {
    printf("\n \\hline \n");
    printf("[%s] yields \\\\ \n", channel.Data());
    printf(" \\hline \n");
    printf("       sample              &  yield $\\pm$ stat. $\\pm$ syst.\\\\ \n ");
    printf(" \\hline \n");
    printf("       gg to WW            & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NggWW[0],            NggWW[1],        NggWW[2]*NggWW[0]/1e2);
    printf("       qq to WW            & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NqqWW[0],            NqqWW[1],        NqqWW[2]*NqqWW[0]/1e2);
    printf(" \\hline \n");
    printf("       tt+tW               & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NTop[0],             NTop[1],         NTop[2]);
    printf("       W+jets              & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NWj[0],              NWj[1],          NWj[2]);
    printf("       WZ+ZZ               & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NWZ[0]+NZZ[0],       statErrorVV,     systErrorVV);
    printf("       Z/g*                & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n",   NDY[0]+NDYtautau[0], statErrorDYAll,  systErrorDYAll);
    //printf(" (%.1f Z/g* + %.1f Z/g* -> tautau)\n",                           NDY[0],              NDYtautau[0]);
    printf("       Wg+Wg*              & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NWg[0],              NWg[1],          NWg[2]);
    printf("       Zgamma              & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NZgamma[0],          NZgamma[1],      NZgamma[2]);
    printf("       VVV              & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NVVV[0],          NVVV[1],      NVVV[2]);
    printf("       H125                & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NH125[0],            NH125[1],        NH125[2]);
    printf(" \\hline \n");
    printf("       total background    & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", Background,          statErrorB,      systErrorB);
    printf("       signal              & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NWW[0],              NWW[1],          NWW[2]*NWW[0]/1e2);
    printf(" \\hline \n");
    printf("       signal + background & %6.1f $\\pm$ %5.1f $\\pm$ %5.1f \\\\ \n", NWW[0]+Background,   statErrorSPlusB, systErrorSPlusB);
    printf(" \\hline \n");
    printf("       data                & %4.0f \\\\ \n",                           NData[0]);
    printf(" \\hline \n");
    printf("\n [%s] WW cross-section\n", channel.Data());
    printf(" -------------------------------------------------\n");
  }

  printf("       sigmaWW(%s,%s) = %5.2f +- %5.2f (stat.) +- %5.2f (syst.) +- %5.2f (lumi.) pb\n",
    	 channel.Data(), analysisLevel.Data(), xsValue, xsStat, xsSyst, xsLumi);


  // Difference wrt. the theoretical value
  //----------------------------------------------------------------------------
  if (channel.Contains("All") && printLevel > 0) {

    Double_t deltaXS    = xsValue - nlo8tev;
    Double_t deltaXSErr = xsStat*xsStat + xsSyst*xsSyst + xsLumi*xsLumi + nlo8tevPlus*nlo8tevPlus;

    deltaXSErr = sqrt(deltaXSErr);

    printf("\n       sigma(NLO) = %.2f + %.2f - %.2f pb\n", nlo8tev, nlo8tevPlus, nlo8tevMinus);
    printf("\n       sigmaWW(%s) - sigma(NLO) = %.2f +- %.2f pb", channel.Data(), deltaXS, deltaXSErr);
    printf(" = (%.0f +- %.0f)\%s of the theoretical value\n\n", 1e2*deltaXS/nlo8tev, 1e2*deltaXSErr/nlo8tev, "%");
  }