Exemplo n.º 1
0
void finalize_oneDataset( const std::string& redntpProdVersion, const std::string& dataset, const std::string& selectionType, const std::string& bTaggerType, std::vector<std::string> *datasets ) {

  TString dataset_tstr(dataset);

  std::cout << std::endl << std::endl << std::endl << "####     Finalizing " << dataset << std::endl;
  std::cout << "####     Selection: " << selectionType << std::endl;
  std::cout << "####     b-Tagger: " << bTaggerType << std::endl << std::endl;

  RedntpDirStruct dirs = get_dirs( redntpProdVersion );

  RedNtpFinalizer_VHgg* rf = new RedNtpFinalizer_VHgg( dataset, selectionType, bTaggerType );
  //rf->set_redNtpDir("/xrootdfs/cms/local/pandolf/HiggsGammaGamma/reduced/redntp.52xv5_VH_feasibility_signalOnly.cicpfloose.regrPho_eCorr_20062012.VH_feasibility_v0/merged");

  bool isData = ( dataset_tstr.Contains("Run2011") || dataset_tstr.Contains("Run2012") );

  std::string redNtpDir = dirs.maindir;
  if( isData ) redNtpDir = redNtpDir + "/" + dirs.datadir;
  else         redNtpDir = redNtpDir + "/" + dirs.mcdir;

  rf->set_redNtpDir(redNtpDir);
  rf->set_outputDir("finalizedTrees_"+redntpProdVersion);
  rf->addFile(dataset);
  rf->finalize();
  delete rf;

  datasets->push_back(dataset);

}
void finalize_oneDataset_commonNtp( const std::string& redntpProdVersion, const std::string& dataset, const std::string& selectionType, const std::string& bTaggerType, std::vector<std::string> *datasets ) {

  TString dataset_tstr(dataset);
  
  std::cout << std::endl << std::endl << std::endl << "####     Finalizing " << dataset << std::endl;
  std::cout << "####  Selection: " << selectionType << std::endl;
  std::cout << "####  b-Tagger: "  << bTaggerType << std::endl << std::endl;

  RedntpDirStruct dirs = get_dirs_commonNtp( redntpProdVersion );

  bestJets_commonNtp* rf = new bestJets_commonNtp( dataset, selectionType, bTaggerType );

  bool isData = ( dataset_tstr.Contains("2011") || dataset_tstr.Contains("2012") ); 

  std::string redNtpDir;
  if( isData ) {
    redNtpDir = dirs.maindatadir;
    redNtpDir = redNtpDir + "/" + dirs.datadir;
    cout << "Running on redNtpDir = " << redNtpDir << endl;
  } else {
    redNtpDir = dirs.mainmcdir;
    redNtpDir = redNtpDir + "/" + dirs.mcdir;
    cout << "Running on redNtpDir = " << redNtpDir << endl;
  }

  rf->set_redNtpDir(redNtpDir);
  rf->set_outputDir("finalizedTrees_"+redntpProdVersion);
  rf->addFile(dataset);
  rf->finalize();
  delete rf;

  datasets->push_back(dataset);
}
Exemplo n.º 3
0
void finalize_oneDataset( const std::string& redntpProdVersion, const std::string& dataset, const std::string& selectionType, const std::string& bTaggerType, std::vector<std::string> *datasets ) {

  TString dataset_tstr(dataset);

  std::cout << std::endl << std::endl << std::endl << "####     Finalizing " << dataset << std::endl;
  std::cout << "####     Selection: " << selectionType << std::endl;
  std::cout << "####     Ntuple version: " << redntpProdVersion << std::endl;
  std::cout << "####     b-Tagger: " << bTaggerType << std::endl << std::endl;

  RedntpDirStruct dirs = get_dirs( redntpProdVersion );

  // lousy patch
  bool use_mcdir2=false;
  if( dataset=="tHqLeptonic_mH125_8TeV_testtest" || dataset=="tHqHadronic_mH125_8TeV_testtest" || dataset_tstr.BeginsWith("TT_CT10") || dataset_tstr.BeginsWith("T_") || dataset_tstr.BeginsWith("Tbar_") )
    if( dirs.mcdir2!="" )
      use_mcdir2 = true;

  RedNtpFinalizer_THq* rf = new RedNtpFinalizer_THq( dataset, selectionType, bTaggerType );
  //rf->set_redNtpDir("/xrootdfs/cms/local/pandolf/HiggsGammaGamma/reduced/redntp.52xv5_VH_feasibility_signalOnly.cicpfloose.regrPho_eCorr_20062012.VH_feasibility_v0/merged");

  bool isData = ( dataset_tstr.Contains("Run2011") || dataset_tstr.Contains("Run2012") );

  std::string redNtpDir = dirs.maindir;
  if( isData ) redNtpDir = redNtpDir + "/" + dirs.datadir;
  else {
    if( use_mcdir2 )       redNtpDir = redNtpDir + "/" + dirs.mcdir2;
    else                   redNtpDir = redNtpDir + "/" + dirs.mcdir;
  }


  rf->set_redNtpDir(redNtpDir);
  rf->set_outputDir("finalizedTrees_"+redntpProdVersion);
  rf->addFile(dataset);
  if( use_inverted_photID ) 
    rf->invertPhotID();
  rf->finalize();
  delete rf;

  datasets->push_back(dataset);

}
float getWeight( const std::string& dataset, int nEvents ) {

  float xSection = -1.;
  TString dataset_tstr(dataset);



  if( dataset_tstr.Contains("8TeV") ) {

    if( dataset_tstr.BeginsWith("G_Pt_15to30") || dataset_tstr.BeginsWith("G_Pt-15to30") ) {
      xSection = 200061.7;
    } else if( dataset_tstr.BeginsWith("G_Pt_30to50") || dataset_tstr.BeginsWith("G_Pt-30to50") ) {
      xSection = 19931.62;
    } else if( dataset_tstr.BeginsWith("G_Pt_50to80") || dataset_tstr.BeginsWith("G_Pt-50to80") ) {
      xSection = 3322.309;
    } else if( dataset_tstr.BeginsWith("G_Pt_80to120") || dataset_tstr.BeginsWith("G_Pt-80to120") ) {
      xSection = 558.2865;
    } else if( dataset_tstr.BeginsWith("G_Pt_120to170") || dataset_tstr.BeginsWith("G_Pt-120to170") ) {
      xSection = 108.0068;
    } else if( dataset_tstr.BeginsWith("G_Pt_170to300") || dataset_tstr.BeginsWith("G_Pt-170to300") ) {
      xSection = 30.12207;
    } else if( dataset_tstr.BeginsWith("G_Pt_300to470") || dataset_tstr.BeginsWith("G_Pt-300to470") ) {
      xSection = 2.138632;
    } else if( dataset_tstr.BeginsWith("G_Pt_470to800") || dataset_tstr.BeginsWith("G_Pt-470to800") ) {
      xSection = 0.2119244;
    } else if( dataset_tstr.BeginsWith("G_Pt_800to1400") || dataset_tstr.BeginsWith("G_Pt-800to1400") ) {
      xSection = 0.007077847;
    } else if( dataset_tstr.BeginsWith("G_Pt_1400to1800") || dataset_tstr.BeginsWith("G_Pt-1400to1800") ) {
      xSection = 4.510327E-5;
    } else if( dataset_tstr.BeginsWith("G_Pt_1800") || dataset_tstr.BeginsWith("G_Pt-1800") ) {
      xSection = 1.867141E-6;
    } else {
      std::cout << std::endl;
      std::cout << "-> WARNING!! Dataset: '" << dataset << "' not present in database. Cross section unknown." << std::endl;
      std::cout << "-> Will set unitary weights." << std::endl;
      return 1.;
    }


  } else {

    if( dataset=="Zjets-madgraph" ) {
      xSection = 2800.;
    } else if( dataset=="HZZ_qqll_gluonfusion_M130" ) {
      xSection = 25.560*0.03913; //sigma x BR
    } else if( dataset=="HZZ_qqll_gluonfusion_M150" ) {
      xSection = 19.568*0.08234; //sigma x BR
    } else if( dataset=="HZZ_qqll_gluonfusion_M500" ) {
      xSection = 2.1914*0.2602; //sigma x BR
    } else if( dataset=="QCD_Spring10_Pt0to15" ) {
      xSection = 48445000000.;
    } else if( dataset=="QCD_Spring10_Pt5to15" ) {
      xSection = 36640000000.;
    } else if( dataset=="QCD_Spring10_Pt15" ) {
      xSection = 876215000.-60411000.;
    } else if( dataset=="QCD_Spring10_Pt15to20" ) {
      xSection = 579411000.;
    } else if( dataset=="QCD_Spring10_Pt20to30" ) {
      xSection = 236051000.;
    } else if( dataset=="QCD_Spring10_Pt30" ) {
      xSection = 60411000.-923821.;
    } else if( dataset=="QCD_Spring10_Pt30to50" ) {
      xSection = 53114800.;
    } else if( dataset=="QCD_Spring10_Pt50to80" ) {
      xSection = 6358210.;
    } else if( dataset=="QCD_Spring10_Pt80" ) {
      xSection = 923821.-25474.9;
    } else if( dataset=="QCD_Spring10_Pt170" ) {
      xSection = 25474.9-1255.87;
    } else if( dataset=="QCD_Spring10_Pt300" ) {
      xSection = 1255.87-87.9799;
    } else if( dataset=="QCD_Spring10_Pt470" ) {
      xSection = 87.9799-2.18608;
    } else if( dataset=="QCD_Spring10_Pt800" ) {
      xSection = 2.18608-0.0112233;
    } else if( dataset=="QCD_Spring10_Pt1400" ) {
      xSection = 0.0112233;
    } else if( dataset_tstr.BeginsWith("G_Pt_0to15") ) {
      xSection = 8.420e+07;
    //} else if( dataset=="G_Pt_15to30_TuneZ2_7TeV_pythia6" || dataset=="G_Pt_15to30_TuneZ2_7TeV_pythia6_CORR" ) {
    } else if( dataset_tstr.BeginsWith("G_Pt_15to30") || dataset_tstr.BeginsWith("G_Pt-15to30") ) {
      xSection = 1.717e+05;
    } else if( dataset_tstr.BeginsWith("G_Pt_30to50") || dataset_tstr.BeginsWith("G_Pt-30to50") ) {
      xSection = 1.669e+04;
    } else if( dataset_tstr.BeginsWith("G_Pt_50to80") || dataset_tstr.BeginsWith("G_Pt-50to80") ) {
      xSection = 2.722e+03;
    } else if( dataset_tstr.BeginsWith("G_Pt_80to120") || dataset_tstr.BeginsWith("G_Pt-80to120") ) {
      xSection = 4.472e+02;
    } else if( dataset_tstr.BeginsWith("G_Pt_120to170") || dataset_tstr.BeginsWith("G_Pt-120to170") ) {
      xSection = 8.417e+01;
    } else if( dataset_tstr.BeginsWith("G_Pt_170to300") || dataset_tstr.BeginsWith("G_Pt-170to300") ) {
      xSection = 2.264e+01;
    } else if( dataset_tstr.BeginsWith("G_Pt_300to470") || dataset_tstr.BeginsWith("G_Pt-300to470") ) {
      xSection = 1.493e+00;
    } else if( dataset_tstr.BeginsWith("G_Pt_470to800") || dataset_tstr.BeginsWith("G_Pt-470to800") ) {
      xSection = 1.323e-01;
    } else if( dataset_tstr.BeginsWith("G_Pt_800to1400") || dataset_tstr.BeginsWith("G_Pt-800to1400") ) {
      xSection = 3.481e-03;
    } else if( dataset_tstr.BeginsWith("G_Pt_1400to1800") || dataset_tstr.BeginsWith("G_Pt-1400to1800") ) {
      xSection = 1.270e-05;
    } else if( dataset_tstr.BeginsWith("G_Pt_1800") || dataset_tstr.BeginsWith("G_Pt-1800") ) {
      xSection = 2.936e-07;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_15to30") || dataset_tstr.BeginsWith("QCD_Pt-15to30") ) {
      xSection = 8.159e+08;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_30to50") || dataset_tstr.BeginsWith("QCD_Pt-30to50")) {
      xSection = 5.312e+07;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_50to80") || dataset_tstr.BeginsWith("QCD_Pt-50to80")) {
      xSection = 6.359e+06;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_80to120") || dataset_tstr.BeginsWith("QCD_Pt-80to120")) {
      xSection = 7.843e+05;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_120to170") || dataset_tstr.BeginsWith("QCD_Pt-120to170")) {
      xSection = 1.151e+05;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_170to300") || dataset_tstr.BeginsWith("QCD_Pt-170to300")) {
      xSection = 2.426e+04;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_300to470") || dataset_tstr.BeginsWith("QCD_Pt-300to470")) {
      xSection = 1.168e+03;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_470to600") || dataset_tstr.BeginsWith("QCD_Pt-470to600")) {
      xSection = 7.022e+01;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_600to800") || dataset_tstr.BeginsWith("QCD_Pt-600to800")) {
      xSection = 1.555e+01;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_800to1000") || dataset_tstr.BeginsWith("QCD_Pt-800to1000")) {
      xSection = 1.844e+00;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_1000to1400") || dataset_tstr.BeginsWith("QCD_Pt-1000to1400")) {
      xSection = 3.321e-01;
    } else if( dataset_tstr.BeginsWith("QCD_Pt_1400to1800") || dataset_tstr.BeginsWith("QCD_Pt-1400to1800")) {
      xSection = 1.087e-02;
    } else if( dataset_tstr.BeginsWith("QCD_Pt1800") || dataset_tstr.BeginsWith("QCD_Pt-1800")) {
      xSection = 3.575e-04;
    } else if( dataset=="PhotonJet_Summer1036X_Pt5to15" ) {
      xSection = 4030000.;
    } else if( dataset=="PhotonJet_Summer1036X_Pt15to20" ) {
      xSection = 114700.;
    } else if( dataset=="PhotonJet_Summer1036X_Pt20to30" ) {
      xSection = 57180.;
    } else if( dataset=="PhotonJet_Summer1036X_Pt30to50" ) {
      xSection = 16520.;
    } else if( dataset=="PhotonJet_Summer1036X_Pt50to80" ) {
      xSection = 2723.;
    } else if( dataset=="PhotonJet_Summer1036X_Pt80to120" ) {
      xSection = 446.2;
    } else if( dataset=="PhotonJet_Summer1036X_Pt120to170" ) {
      xSection = 84.43;
    } else if( dataset=="PhotonJet_Summer1036X_Pt170to300" ) {
      xSection = 22.55;
    } else if( dataset=="PhotonJet_Summer1036X_Pt300to500" ) {
      xSection = 1.545;
    } else if( dataset=="PhotonJet_Summer1036X_Pt500toInf" ) {
      xSection = 0.0923;
    } else if( dataset_tstr.BeginsWith("QCD_Pt-20to30_BCtoE") ) {
      xSection = 236000000.*0.00056;
    } else if( dataset_tstr.BeginsWith("QCD_Pt-20to30_EMEnriched") ) {
      xSection = 236000000.*0.0104;
    } else if( dataset_tstr.BeginsWith("QCD_Pt-30to80_BCtoE") ) {
      xSection = 59480000.*0.00230;
    } else if( dataset_tstr.BeginsWith("QCD_Pt-30to80_EMEnriched") ) {
      xSection = 59480000.*0.065;
    } else if( dataset_tstr.BeginsWith("QCD_Pt-80to170_BCtoE") ) {
      xSection = 900000.*0.0104;
    } else if( dataset_tstr.BeginsWith("QCD_Pt-80to170_EMEnriched") ) {
      xSection = 900000.*0.155;
    } else if( dataset_tstr.BeginsWith("WH_ZH_HToGG_M-120") ) {
      xSection = (0.6561 + 0.3551)* 0.0231; //fermiophobic BR!!
    } else if( dataset_tstr.BeginsWith("WH_ZH_HToGG_M-125") ) {
      xSection = (0.5729 + 0.3158)* 0.0231; //fermiophobic BR!!
    } else if( dataset_tstr.BeginsWith("DiPhotonJets") ) {
      xSection = 134 * 1.15;
    } else if( dataset_tstr.BeginsWith("DiPhotonBox_Pt-25To250") ) {
      xSection = 12.37 * 1.3;

    } else if( dataset_tstr.BeginsWith("G1Jet_Pt-20to60") ) {
      xSection = 2.270e+04;
    } else if( dataset_tstr.BeginsWith("G1Jet_Pt-60to120") ) {
      xSection = 7.993e+02;
    } else if( dataset_tstr.BeginsWith("G1Jet_Pt-120to180") ) {
      xSection = 4.011e+01 ;
    } else if( dataset_tstr.BeginsWith("G1Jet_Pt-180to240") ) {
      xSection = 5.612e+00 ;
    } else if( dataset_tstr.BeginsWith("G1Jet_Pt-240to300") ) {
      xSection = 1.224e+00 ;
    } else if( dataset_tstr.BeginsWith("G1Jet_Pt-300to5000") ) {
      xSection = 5.450e-01 ;


    } else if( dataset_tstr.BeginsWith("G2Jet_Pt-20to60") ) {
      xSection = 4.080e+03;
    } else if( dataset_tstr.BeginsWith("G2Jet_Pt-60to120") ) {
      xSection = 4.258e+02 ;
    } else if( dataset_tstr.BeginsWith("G2Jet_Pt-120to180") ) {
      xSection = 3.556e+01 ;
    } else if( dataset_tstr.BeginsWith("G2Jet_Pt-180to240") ) {
      xSection = 5.941e+00 ;
    } else if( dataset_tstr.BeginsWith("G2Jet_Pt-240to300") ) {
      xSection = 1.448e+00 ;
    } else if( dataset_tstr.BeginsWith("G2Jet_Pt-300to5000") ) {
      xSection = 7.233e-01 ;

    } else if( dataset_tstr.BeginsWith("QCD") && dataset_tstr.Contains("HT-100To250_7TeV") ) {
      xSection = 4194000.0;
    } else if( dataset_tstr.BeginsWith("QCD") && dataset_tstr.Contains("HT-250To500_7TeV") ) {
      xSection = 198500.;
    } else if( dataset_tstr.BeginsWith("QCD") && dataset_tstr.Contains("HT-500To1000_7TeV") ) {
      xSection = 5856.;
    } else if( dataset_tstr.BeginsWith("QCD") && dataset_tstr.Contains("HT-1000_7TeV") ) {
      xSection = 122.6;

    } else {
      std::cout << std::endl;
      std::cout << "-> WARNING!! Dataset: '" << dataset << "' not present in database. Cross section unknown." << std::endl;
      std::cout << "-> Will set unitary weights." << std::endl;
      return 1.;
    }

  }

  float weight = xSection/((float)nEvents);

  return weight;

}
Exemplo n.º 5
0
void TreeFinalizerC_ZJet::finalize() {



    TString dataset_tstr(dataset_);

    gROOT->cd();

    std::string outfileName;

    if( DEBUG_ ) outfileName = "provaZJet_"+dataset_;
    else {
        if(dataset_!="") outfileName = "ZJet_"+dataset_;
        else outfileName = "ZJet";
    }

    outfileName = outfileName;


    if( nBlocks_ >1 ) {
        char blockText[100];
        sprintf( blockText, "_%d", iBlock_ );
        std::string iBlockString(blockText);
        outfileName = outfileName + iBlockString;
    }
    outfileName += ".root";


    TFile* outFile = new TFile(outfileName.c_str(), "RECREATE");
    outFile->cd();

    TTree* tree_passedEvents = new TTree("tree_passedEvents", "Unbinned data for statistical treatment");



    TH1D* h1_cutflow_50100 = new TH1D("cutflow_50100", "", 6, 0, 6);
    h1_cutflow_50100->Sumw2();


    TH1F* h1_nvertex = new TH1F("nvertex", "", 21, -0.5, 20.5);
    h1_nvertex->Sumw2();
    TH1F* h1_nvertex_PUW = new TH1F("nvertex_PUW", "", 21, -0.5, 20.5);
    h1_nvertex_PUW->Sumw2();

    TH1D* h1_quarkFraction_3050 = new TH1D("quarkFraction_3050", "", 1, 0., 1.);
    h1_quarkFraction_3050->Sumw2();
    TH1D* h1_quarkFraction_5080 = new TH1D("quarkFraction_5080", "", 1, 0., 1.);
    h1_quarkFraction_5080->Sumw2();
    TH1D* h1_quarkFraction_80120 = new TH1D("quarkFraction_80120", "", 1, 0., 1.);
    h1_quarkFraction_80120->Sumw2();

    TH1D* h1_quarkFraction_antibtag_3050 = new TH1D("quarkFraction_antibtag_3050", "", 1, 0., 1.);
    h1_quarkFraction_antibtag_3050->Sumw2();
    TH1D* h1_quarkFraction_antibtag_5080 = new TH1D("quarkFraction_antibtag_5080", "", 1, 0., 1.);
    h1_quarkFraction_antibtag_5080->Sumw2();
    TH1D* h1_quarkFraction_antibtag_80120 = new TH1D("quarkFraction_antibtag_80120", "", 1, 0., 1.);
    h1_quarkFraction_antibtag_80120->Sumw2();

    TH1D* h1_ptJetReco = new TH1D("ptJetReco", "", 100, 0., 300);
    h1_ptJetReco->Sumw2();
    TH1D* h1_pt2ndJetReco = new TH1D("pt2ndJetReco", "", 100, 5., 400);
    h1_pt2ndJetReco->Sumw2();

    TH1D* h1_ptDJetReco_3050 = new TH1D("ptDJetReco_3050", "", 50, 0., 1.0001);
    h1_ptDJetReco_3050->Sumw2();
    TH1D* h1_nChargedJetReco_3050 = new TH1D("nChargedJetReco_3050", "", 51, -0.5, 50.5);
    h1_nChargedJetReco_3050->Sumw2();
    TH1D* h1_nNeutralJetReco_3050 = new TH1D("nNeutralJetReco_3050", "", 51, -0.5, 50.5);
    h1_nNeutralJetReco_3050->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_3050 = new TH1D("QGLikelihoodJetReco_3050", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_3050->Sumw2();

    TH1D* h1_ptDJetReco_antibtag_3050 = new TH1D("ptDJetReco_antibtag_3050", "", 50, 0., 1.0001);
    h1_ptDJetReco_antibtag_3050->Sumw2();
    TH1D* h1_nChargedJetReco_antibtag_3050 = new TH1D("nChargedJetReco_antibtag_3050", "", 51, -0.5, 50.5);
    h1_nChargedJetReco_antibtag_3050->Sumw2();
    TH1D* h1_nNeutralJetReco_antibtag_3050 = new TH1D("nNeutralJetReco_antibtag_3050", "", 51, -0.5, 50.5);
    h1_nNeutralJetReco_antibtag_3050->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_3050 = new TH1D("QGLikelihoodJetReco_antibtag_3050", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_3050->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_gluon_3050 = new TH1D("QGLikelihoodJetReco_antibtag_gluon_3050", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_gluon_3050->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_quark_3050 = new TH1D("QGLikelihoodJetReco_antibtag_quark_3050", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_quark_3050->Sumw2();

    TH1D* h1_ptDJetReco_5080 = new TH1D("ptDJetReco_5080", "", 50, 0., 1.0001);
    h1_ptDJetReco_5080->Sumw2();
    TH1D* h1_nChargedJetReco_5080 = new TH1D("nChargedJetReco_5080", "", 51, -0.5, 50.5);
    h1_nChargedJetReco_5080->Sumw2();
    TH1D* h1_nNeutralJetReco_5080 = new TH1D("nNeutralJetReco_5080", "", 51, -0.5, 50.5);
    h1_nNeutralJetReco_5080->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_5080 = new TH1D("QGLikelihoodJetReco_5080", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_5080->Sumw2();

    TH1D* h1_ptDJetReco_antibtag_5080 = new TH1D("ptDJetReco_antibtag_5080", "", 50, 0., 1.0001);
    h1_ptDJetReco_antibtag_5080->Sumw2();
    TH1D* h1_nChargedJetReco_antibtag_5080 = new TH1D("nChargedJetReco_antibtag_5080", "", 51, -0.5, 50.5);
    h1_nChargedJetReco_antibtag_5080->Sumw2();
    TH1D* h1_nNeutralJetReco_antibtag_5080 = new TH1D("nNeutralJetReco_antibtag_5080", "", 51, -0.5, 50.5);
    h1_nNeutralJetReco_antibtag_5080->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_5080 = new TH1D("QGLikelihoodJetReco_antibtag_5080", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_5080->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_gluon_5080 = new TH1D("QGLikelihoodJetReco_antibtag_gluon_5080", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_gluon_5080->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_quark_5080 = new TH1D("QGLikelihoodJetReco_antibtag_quark_5080", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_quark_5080->Sumw2();

    TH1D* h1_ptDJetReco_80120 = new TH1D("ptDJetReco_80120", "", 50, 0., 1.0001);
    h1_ptDJetReco_80120->Sumw2();
    TH1D* h1_nChargedJetReco_80120 = new TH1D("nChargedJetReco_80120", "", 51, -0.5, 50.5);
    h1_nChargedJetReco_80120->Sumw2();
    TH1D* h1_nNeutralJetReco_80120 = new TH1D("nNeutralJetReco_80120", "", 51, -0.5, 50.5);
    h1_nNeutralJetReco_80120->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_80120 = new TH1D("QGLikelihoodJetReco_80120", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_80120->Sumw2();

    TH1D* h1_ptDJetReco_antibtag_80120 = new TH1D("ptDJetReco_antibtag_80120", "", 50, 0., 1.0001);
    h1_ptDJetReco_antibtag_80120->Sumw2();
    TH1D* h1_nChargedJetReco_antibtag_80120 = new TH1D("nChargedJetReco_antibtag_80120", "", 51, -0.5, 50.5);
    h1_nChargedJetReco_antibtag_80120->Sumw2();
    TH1D* h1_nNeutralJetReco_antibtag_80120 = new TH1D("nNeutralJetReco_antibtag_80120", "", 51, -0.5, 50.5);
    h1_nNeutralJetReco_antibtag_80120->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_80120 = new TH1D("QGLikelihoodJetReco_antibtag_80120", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_80120->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_gluon_80120 = new TH1D("QGLikelihoodJetReco_antibtag_gluon_80120", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_gluon_80120->Sumw2();
    TH1D* h1_QGLikelihoodJetReco_antibtag_quark_80120 = new TH1D("QGLikelihoodJetReco_antibtag_quark_80120", "", 50, 0., 1.0001);
    h1_QGLikelihoodJetReco_antibtag_quark_80120->Sumw2();


    Double_t ptBinning[4];
    ptBinning[0] = 30.;
    ptBinning[1] = 50.;
    ptBinning[2] = 80.;
    ptBinning[3] = 120.;

    TH1D* h1_nEvents_passed = new TH1D("nEvents_passed", "", 3, ptBinning);
    h1_nEvents_passed->Sumw2();
    TH1D* h1_nEvents_passed_quark = new TH1D("nEvents_passed_quark", "", 3, ptBinning);
    h1_nEvents_passed_quark->Sumw2();


    TH1D* h1_ptZ = new TH1D("ptZ", "", 500, 0., 500.);
    h1_ptZ->Sumw2();
    TH1D* h1_mZ = new TH1D("mZ", "", 100, 50., 150.);
    h1_mZ->Sumw2();
    TH1D* h1_etaZ = new TH1D("etaZ", "", 15, -1.3, 1.3);
    h1_etaZ->Sumw2();
    TH1D* h1_phiZ = new TH1D("phiZ", "", 15, -3.1416, 3.1416);
    h1_phiZ->Sumw2();





    Int_t run;
    tree_->SetBranchAddress("run", &run);
    Int_t LS;
    tree_->SetBranchAddress("LS", &LS);
    Int_t event;
    tree_->SetBranchAddress("event", &event);
    Int_t nvertex;
    tree_->SetBranchAddress("nvertex", &nvertex);
    Float_t eventWeight;
    tree_->SetBranchAddress("eventWeight", &eventWeight);
    Float_t eventWeight_genjets;

    Float_t eMet;
    Float_t phiMet;
    tree_->SetBranchAddress("epfMet", &eMet);
    tree_->SetBranchAddress("phipfMet", &phiMet);


    Float_t ptHat;
    tree_->SetBranchAddress("ptHat", &ptHat);

    Int_t nPU;
    tree_->SetBranchAddress("nPU", &nPU);
    Int_t PUReWeight;
    tree_->SetBranchAddress("PUReWeight", &PUReWeight);
    Float_t rhoPF;
    tree_->SetBranchAddress("rhoPF", &rhoPF);
    Float_t rhoJetPF;
    tree_->SetBranchAddress("rhoJetPF", &rhoJetPF);

    Float_t eLeptZ1;
    tree_->SetBranchAddress("eLeptZ1", &eLeptZ1);
    Float_t ptLeptZ1;
    tree_->SetBranchAddress("ptLeptZ1", &ptLeptZ1);
    Float_t etaLeptZ1;
    tree_->SetBranchAddress("etaLeptZ1", &etaLeptZ1);
    Float_t phiLeptZ1;
    tree_->SetBranchAddress("phiLeptZ1", &phiLeptZ1);

    Float_t eLeptZ2;
    tree_->SetBranchAddress("eLeptZ2", &eLeptZ2);
    Float_t ptLeptZ2;
    tree_->SetBranchAddress("ptLeptZ2", &ptLeptZ2);
    Float_t etaLeptZ2;
    tree_->SetBranchAddress("etaLeptZ2", &etaLeptZ2);
    Float_t phiLeptZ2;
    tree_->SetBranchAddress("phiLeptZ2", &phiLeptZ2);



    Bool_t matchedToMC;
    tree_->SetBranchAddress("matchedToMC", &matchedToMC);

    Int_t nJets;
    tree_->SetBranchAddress("nJets", &nJets);
    Float_t eJet[50];
    tree_->SetBranchAddress("eJet", eJet);
    Float_t ptJet[50];
    tree_->SetBranchAddress("ptJet", ptJet);
    Float_t etaJet[50];
    tree_->SetBranchAddress("etaJet", etaJet);
    Float_t phiJet[50];
    tree_->SetBranchAddress("phiJet", phiJet);
    Int_t nChargedJet[50];
    tree_->SetBranchAddress("nChargedJet", nChargedJet);
    Int_t nNeutralJet[50];
    tree_->SetBranchAddress("nNeutralJet", nNeutralJet);
    Float_t eChargedHadronsJet[50];
    tree_->SetBranchAddress("eChargedHadronsJet", eChargedHadronsJet);
    Float_t eNeutralHadronsJet[50];
    tree_->SetBranchAddress("eNeutralHadronsJet", eNeutralHadronsJet);
    Float_t ePhotonsJet[50];
    tree_->SetBranchAddress("ePhotonsJet", ePhotonsJet);
    Float_t eHFHadronsJet[50];
    tree_->SetBranchAddress("eHFHadronsJet", eHFHadronsJet);
    Float_t eHFEMJet[50];
    tree_->SetBranchAddress("eHFEMJet", eHFEMJet);
    Float_t ptDJet[50];
    tree_->SetBranchAddress("ptDJet", ptDJet);
    Float_t rmsCandJet[50];
    tree_->SetBranchAddress("rmsCandJet", rmsCandJet);
    Float_t betaStarJet[50];
    tree_->SetBranchAddress("betaStarJet", betaStarJet);
    Float_t QGLikelihoodJet[50];
    tree_->SetBranchAddress("QGLikelihoodJet", QGLikelihoodJet);
    Float_t trackCountingHighEffBJetTagsJet[50];
    tree_->SetBranchAddress("trackCountingHighEffBJetTagsJet", trackCountingHighEffBJetTagsJet);
    Float_t combinedSecondaryVertexBJetTagJet[50];
    tree_->SetBranchAddress("combinedSecondaryVertexBJetTagJet", combinedSecondaryVertexBJetTagJet);
    Int_t pdgIdPartJet[50];
    tree_->SetBranchAddress("pdgIdPartJet", pdgIdPartJet);
    Float_t ptPartJet[50];
    tree_->SetBranchAddress("ptPartJet", ptPartJet);
    Float_t etaPartJet[50];
    tree_->SetBranchAddress("etaPartJet", etaPartJet);
    Float_t phiPartJet[50];
    tree_->SetBranchAddress("phiPartJet", phiPartJet);
    Float_t ptGenJet[50];
    tree_->SetBranchAddress("ptGenJet", ptGenJet);
    Float_t etaGenJet[50];
    tree_->SetBranchAddress("etaGenJet", etaGenJet);
    Float_t phiGenJet[50];
    tree_->SetBranchAddress("phiGenJet", phiGenJet);


    Float_t axis1Jet[50];
    tree_->SetBranchAddress("axis1Jet",axis1Jet);
    Float_t axis2Jet[50];
    tree_->SetBranchAddress("axis2Jet",axis2Jet);
    Float_t pullJet[50];
    tree_->SetBranchAddress("pullJet",pullJet);
    Float_t tanaJet[50];
    tree_->SetBranchAddress("tanaJet",tanaJet);
    Float_t ptD_QCJet[50];
    tree_->SetBranchAddress("ptD_QCJet",ptD_QCJet);
    Float_t rmsCand_QCJet[50];
    tree_->SetBranchAddress("rmsCand_QCJet",rmsCand_QCJet);
    Float_t axis1_QCJet[50];
    tree_->SetBranchAddress("axis1_QCJet",axis1_QCJet);
    Float_t axis2_QCJet[50];
    tree_->SetBranchAddress("axis2_QCJet",axis2_QCJet);
    Float_t pull_QCJet[50];
    tree_->SetBranchAddress("pull_QCJet",pull_QCJet);
    Float_t tana_QCJet[50];
    tree_->SetBranchAddress("tana_QCJet",tana_QCJet);
    Int_t   nPFCand_QC_ptCutJet[50];
    tree_->SetBranchAddress("nPFCand_QC_ptCutJet",nPFCand_QC_ptCutJet);
    //Float_t nChg_ptCutJet[50];	tree_->SetBranchAddress("nChg_ptCutJet",nChg_ptCutJet);
    //Float_t nChg_QCJet[50];		tree_->SetBranchAddress("nChg_QCJet",nChg_QCJet);
    //Float_t nChg_ptCut_QCJet[50];	tree_->SetBranchAddress("nChg_ptCut_QCJet",nChg_ptCut_QCJet);
    //Float_t nNeutral_ptCutJet[50];	tree_->SetBranchAddress("nNeutral_ptCutJet",nNeutral_ptCutJet);
    Float_t RchgJet[50];
    tree_->SetBranchAddress("RchgJet",RchgJet);
    Float_t RneutralJet[50];
    tree_->SetBranchAddress("RneutralJet",RneutralJet);
    Float_t RJet[50];
    tree_->SetBranchAddress("RJet",RJet);
    Float_t Rchg_QCJet[50];
    tree_->SetBranchAddress("Rchg_QCJet",Rchg_QCJet);







    Bool_t secondJetOK;
    Bool_t btagged;
    Bool_t matchedToGenJet;
    Float_t deltaPhi_jet;
    Float_t eventWeight_noPU;
    Float_t ptZ, etaZ, mZ;
    Float_t QGlikelihood, QGlikelihood2012;

    Float_t ptJet0_t;
    Float_t etaJet0_t;
    Int_t nChargedJet0_t;
    Int_t nNeutralJet0_t;
    Float_t ptDJet0_t;
    Float_t ptD_QCJet0_t;
    Float_t axis1_QCJet0_t;
    Float_t axis2_QCJet0_t;
    Int_t nPFCand_QC_ptCutJet0_t;
    Int_t pdgIdPartJet_t;
    Float_t betaStarJet0_t;

    Float_t ptJet1_t;
    Float_t etaJet1_t;



    tree_passedEvents->Branch( "run", &run, "run/I" );
    tree_passedEvents->Branch( "LS", &LS, "LS/I" );
    tree_passedEvents->Branch( "nPU", &nPU, "nPU/I" );
    tree_passedEvents->Branch( "PUReWeight", &PUReWeight, "PUReWeight/F" );
    tree_passedEvents->Branch( "event", &event, "event/I" );
    tree_passedEvents->Branch( "eventWeight", &eventWeight, "eventWeight/F");
    tree_passedEvents->Branch( "eventWeight_noPU", &eventWeight_noPU, "eventWeight_noPU/F");
    tree_passedEvents->Branch( "nvertex", &nvertex, "nvertex/I");
    tree_passedEvents->Branch( "rhoPF", &rhoPF, "rhoPF/F");
    tree_passedEvents->Branch( "rhoJetPF", &rhoJetPF, "rhoJetPF/F");
    tree_passedEvents->Branch( "secondJetOK", &secondJetOK, "secondJetOK/O");
    tree_passedEvents->Branch( "btagged", &btagged, "btagged/O");
    tree_passedEvents->Branch( "mZ", &mZ, "mZ/F");
    tree_passedEvents->Branch( "ptZ", &ptZ, "ptZ/F");
    tree_passedEvents->Branch( "etaZ", &etaZ, "etaZ/F");
    tree_passedEvents->Branch( "ptJet0", &ptJet0_t, "ptJet0_t/F");
    tree_passedEvents->Branch( "etaJet0", &etaJet0_t, "etaJet0_t/F");
    tree_passedEvents->Branch( "ptJet1", &ptJet1_t, "ptJet1_t/F");
    tree_passedEvents->Branch( "etaJet1", &etaJet1_t, "etaJet1_t/F");
    tree_passedEvents->Branch( "nChargedJet0", &nChargedJet0_t, "nChargedJet0_t/I");
    tree_passedEvents->Branch( "nNeutralJet0", &nNeutralJet0_t, "nNeutralJet0_t/I");
    tree_passedEvents->Branch( "ptDJet0", &ptDJet0_t, "ptDJet0_t/F");
    //tree_passedEvents->Branch( "rmsCandJet0", &rmsCandJet0_t, "rmsCandJet[0]/F");
    //tree_passedEvents->Branch( "betaStarJet0", &betaStarJet0_t, "betaStarJet[0]/F");
    tree_passedEvents->Branch( "QGLikelihoodJet0", &QGlikelihood, "QGlikelihood/F");
    tree_passedEvents->Branch( "QGLikelihood2012Jet0", &QGlikelihood2012, "QGlikelihood2012/F");
    tree_passedEvents->Branch( "pdgIdPartJet0", &pdgIdPartJet_t, "pdgIdPart_t/I");
    tree_passedEvents->Branch( "deltaPhi_jet", &deltaPhi_jet, "deltaPhi_jet/F");

    //tree_passedEvents->Branch( "axis1Jet0"		, &axis1Jet[0]			, "axis1Jet[0]/F");
    //tree_passedEvents->Branch( "axis2Jet0"		, &axis2Jet[0]			, "axis2Jet[0]/F");
    //tree_passedEvents->Branch( "pullJet0"			, &pullJet[0]			, "pullJet[0]/F");
    //tree_passedEvents->Branch( "tanaJet0"			, &tanaJet[0]			, "tanaJet[0]/F");

    tree_passedEvents->Branch( "ptD_QCJet0"		, &ptD_QCJet0_t		, "ptD_QCJet0_t/F");
    //tree_passedEvents->Branch( "rmsCand_QCJet0"		, &rmsCand_QCJet[0]		, "rmsCand_QCJet[0]/F");
    tree_passedEvents->Branch( "axis1_QCJet0"		, &axis1_QCJet0_t		, "axis1_QCJet0_t/F");
    tree_passedEvents->Branch( "axis2_QCJet0"		, &axis2_QCJet0_t		, "axis2_QCJet0_t/F");
    //tree_passedEvents->Branch( "pull_QCJet0"		, &pull_QCJet[0]		, "pull_QCJet[0]/F");
    //tree_passedEvents->Branch( "tana_QCJet0"		, &tana_QCJet[0]		, "tana_QCJet[0]/F");

    tree_passedEvents->Branch( "nPFCand_QC_ptCutJet"		, &nPFCand_QC_ptCutJet0_t		, "nPFCand_QC_ptCutJet0_t/I");
    //tree_passedEvents->Branch( "nChg_ptCutJet0"		, &nChg_ptCutJet[0]		, "nChg_ptCutJet[0]/I");
    //tree_passedEvents->Branch( "nChg_QCJet0"		, &nChg_QCJet[0]		, "nChg_QCJet[0]/I");
    //tree_passedEvents->Branch( "nChg_ptCut_QCJet0"	, &nChg_ptCut_QCJet[0]	 	, "nChg_ptCut_QCJet[0]/I");
    //tree_passedEvents->Branch( "nNeutral_ptCutJet0"	, &nNeutral_ptCutJet[0]	, "nNeutral_ptCutJet[0]/I");

    //tree_passedEvents->Branch( "RchgJet0"			, &RchgJet[0]			, "RchgJet[0]/F");
    //tree_passedEvents->Branch( "RneutralJet0"		, &RneutralJet[0]		, "RneutralJet[0]/F");
    //tree_passedEvents->Branch( "RJet0"			, &RJet[0]			, "RJet[0]/F");
    //tree_passedEvents->Branch( "Rchg_QCJet0"		, &Rchg_QCJet[0]		, "Rchg_QCJet[0]/F");

    tree_passedEvents->Branch( "betaStarJet0"		, &betaStarJet0_t		, "betaStarJet0_t/F");



    QGLikelihoodCalculator* qglikeli = new QGLikelihoodCalculator("/afs/cern.ch/work/p/pandolf/public/QG/QG_QCD_Pt-15to3000_TuneZ2_Flat_8TeV_pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1.root");






    TRandom3* rand = new TRandom3(13);



    int nEntries = tree_->GetEntries();
//nEntries = 100000;

    std::map< int, std::map<int, std::vector<int> > > run_lumi_ev_map;


    int blockSize = TMath::Floor( (float)nEntries/nBlocks_ );
    int iEventMin = iBlock_*blockSize;
    int iEventMax = (iBlock_+1)*blockSize;
    if( iEventMax>nEntries ) iEventMax = nEntries;

    std::cout << "-> Running on events: " << iEventMin << " - " << iEventMax << std::endl;

    for(int iEntry=iEventMin; iEntry<iEventMax; ++iEntry) {

        if( ((iEntry-iEventMin) % 100000)==0 ) std::cout << "Entry: " << (iEntry-iEventMin) << " /" << blockSize << std::endl;

        tree_->GetEntry(iEntry);


        if( eventWeight <= 0. ) eventWeight = 1.;

        int icut = 0;
        h1_cutflow_50100->Fill( icut++, eventWeight );
        h1_nvertex->Fill( nvertex, eventWeight);

        bool isMC = run<5;

        if( isMC ) {

            // PU reweighting:
            eventWeight_noPU = eventWeight;

        } else { //it's data: remove duplicate events (if any):

            std::map<int, std::map<int, std::vector<int> > >::iterator it;

            it = run_lumi_ev_map.find(run);


            if( it==run_lumi_ev_map.end() ) {

                std::vector<int> events;
                events.push_back(event);
                std::map<int, std::vector<int> > lumi_ev_map;
                lumi_ev_map.insert( std::pair<int,std::vector<int> >(LS, events));
                run_lumi_ev_map.insert( std::pair<int, std::map<int, std::vector<int> > > (run, lumi_ev_map) );

            } else { //run exists, look for LS


                std::map<int, std::vector<int> >::iterator it_LS;
                it_LS = it->second.find( LS );

                if( it_LS==(it->second.end())  ) {

                    std::vector<int> events;
                    events.push_back(event);
                    it->second.insert( std::pair<int, std::vector<int> > (LS, events) );

                } else { //LS exists, look for event

                    std::vector<int>::iterator ev;
                    for( ev=it_LS->second.begin(); ev!=it_LS->second.end(); ++ev )
                        if( *ev==event ) break;


                    if( ev==it_LS->second.end() ) {

                        it_LS->second.push_back(event);

                    } else {

                        std::cout << "DISCARDING DUPLICATE EVENT!! Run: " << run << " LS: " << LS << " event: " << event << std::endl;

                        continue;

                    }
                }
            }

        } //if is mc




        h1_nvertex_PUW->Fill( nvertex, eventWeight);


        TLorentzVector lept1, lept2;
        lept1.SetPtEtaPhiE( ptLeptZ1, etaLeptZ1, phiLeptZ1, eLeptZ1 );
        lept2.SetPtEtaPhiE( ptLeptZ2, etaLeptZ2, phiLeptZ2, eLeptZ2 );

        TLorentzVector Z = lept1 + lept2;

        ptZ = Z.Pt();
        mZ = Z.M();
        etaZ = Z.Eta();

        h1_mZ->Fill( Z.M(), eventWeight );

        if( Z.M()<70. || Z.M()>110. ) continue;

        if( nJets==0 ) continue;
        if( ptJet[0] < 20. ) continue;


        // jet id:
        TLorentzVector jet;
        jet.SetPtEtaPhiE( ptJet[0], etaJet[0], phiJet[0], eJet[0] );

        if( fabs(jet.Eta())<2.4 && nChargedJet[0]==0 ) continue;
        if( (nNeutralJet[0]+nChargedJet[0])==1 ) continue;
        if( (ePhotonsJet[0]+eHFEMJet[0])/jet.E()>0.99 ) continue;
        if( (eNeutralHadronsJet[0])/jet.E()>0.99 ) continue;


        pdgIdPartJet_t = 0;

        if( isMC ) {

            // check if matched to parton/genjet
            TLorentzVector part;
            part.SetPtEtaPhiE( ptPartJet[0], etaPartJet[0], phiPartJet[0], ptPartJet[0] );

            TLorentzVector genJet;
            genJet.SetPtEtaPhiE( ptGenJet[0], etaGenJet[0], phiGenJet[0], ptGenJet[0] );

            float deltaR_jet_part = jet.DeltaR(part);

            if( deltaR_jet_part<0.3 ) {

                pdgIdPartJet_t = pdgIdPartJet[0];

            } else {

                float deltaR_jet_genjet = jet.DeltaR(genJet);

                if( deltaR_jet_genjet < 0.3 ) { //undefined
                    pdgIdPartJet_t = -999;
                } else {
                    pdgIdPartJet_t = 0;  //PU
                }

            } // else (if not matched to parton)

        } // if is MC



        //leading jet and Z back2back in transverse plane
        bool back2back = true;
        deltaPhi_jet = fabs(delta_phi(Z.Phi(), phiJet[0]));
        Float_t pi = TMath::Pi();
        float deltaPhiThreshold = 1.;
        if( fabs(deltaPhi_jet) < (pi - deltaPhiThreshold) ) back2back = false; //loose back to back for now


        // cut away b-jets:
        //if( trackCountingHighEffBJetTagsJetReco>1.7 ) continue;
        btagged = combinedSecondaryVertexBJetTagJet[0]>0.244;
        if( btagged ) continue;

        if( nJets>1 )
            secondJetOK = ( ptJet[1] < secondJetThreshold_*Z.Pt() || ptJet[1] < 10. );
        else
            secondJetOK = true;


        ptJet0_t = jet.Pt();
        etaJet0_t = jet.Eta();
        nChargedJet0_t = nChargedJet[0];
        nNeutralJet0_t = nNeutralJet[0];
        ptDJet0_t = ptDJet[0];
        ptD_QCJet0_t = ptD_QCJet[0];
        axis1_QCJet0_t = axis1_QCJet[0];
        axis2_QCJet0_t = axis2_QCJet[0];
        betaStarJet0_t= betaStarJet[0];
        nPFCand_QC_ptCutJet0_t = nPFCand_QC_ptCutJet[0];

        ptJet1_t  = (nJets>0) ? ptJet[1] : 0.;
        etaJet1_t = (nJets>0) ? etaJet[1] : 10.;




        QGlikelihood = qglikeli->computeQGLikelihoodPU( ptJet[0], rhoPF, nChargedJet[0], nNeutralJet[0], ptDJet[0], -1. );
        QGlikelihood2012 = qglikeli->computeQGLikelihood2012( ptJet[0], etaJet[0], rhoPF, nPFCand_QC_ptCutJet[0], ptD_QCJet[0], axis2_QCJet[0] );


        tree_passedEvents->Fill();

    }


    outFile->cd();

    tree_passedEvents->Write();

    h1_cutflow_50100->Write();

    h1_nvertex->Write();
    h1_nvertex_PUW->Write();

    h1_ptZ->Write();
    h1_mZ->Write();
    h1_phiZ->Write();
    h1_etaZ->Write();
    h1_ptJetReco->Write();
    h1_pt2ndJetReco->Write();

    h1_nEvents_passed_quark->Write();
    h1_nEvents_passed->Write();




    outFile->Close();


}
Exemplo n.º 6
0
int main(int argc, char* argv[]) {

  if( argc!=3 && argc!=4 && argc!=5 ) {
    std::cout << "USAGE: ./drawMZZ_with_curve [(string)data_dataset] [(int)signalScaleFactor] [(string)data_mc] [(string)flags=\"\"]" << std::endl;
    exit(23);
  }

  std::string leptType = "ALL";

  std::string data_prefix(argv[1]);
  std::string data_dataset = "DATA_" + data_prefix;

  float signalScaleFactor=3.;
  if( argc>2 ) {
    std::string signalScaleFactor_str(argv[2]);
    signalScaleFactor = (float)atoi(signalScaleFactor_str.c_str());;
  }

  std::string data_mc="MC";
  if( argc>3 ) {
    std::string data_mc_tmp(argv[3]);
    data_mc = data_mc_tmp;
  }


  std::string flags = "";
  if( argc>4 ) {
    std::string flags_tmp(argv[4]);
    flags = "_" + flags_tmp;
  }


  std::string selType = "optLD_looseBTags_v2";

  TString dataset_tstr(data_prefix);
  std::string PUType = "Run2011A";
  if( data_prefix=="HR11" )
    PUType = "HR11";
  if( data_prefix=="HR11_v2" )
    PUType = "HR11_73pb";
  if( dataset_tstr.BeginsWith("Run2011B") )
    PUType = "HR11_73pb";





  DrawBase* db = new DrawBase("HZZlljjRM");
  db->set_pdf_aussi((bool)false);

  db->set_isCMSArticle(true);
  db->set_lumiOnRightSide(true);


  std::string outputdir_str = "HZZlljjRMPlots_" + data_dataset;
  if( withSignal_ ) {
    outputdir_str += "_plusSignal";
    if( signalScaleFactor!=1. ) {
      char scaleFactorText[100];
      sprintf( scaleFactorText, "_times%.0f", signalScaleFactor );
      std::string scaleFactorText_str(scaleFactorText);
      outputdir_str += scaleFactorText_str;
    }
  }
  outputdir_str += "_" + selType + "_PU" + PUType + "_" + leptType + "_fit" + data_mc;
  if( use_sherpa ) outputdir_str += "_sherpa";
  outputdir_str += flags;
  db->set_outputdir(outputdir_str);


  std::string dataFileName = "HZZlljjRM_" + data_dataset + "_"+selType+"_"+leptType+".root";
  TFile* dataFile = TFile::Open(dataFileName.c_str());
  db->add_dataFile( dataFile, "THEDATA" );

  std::string signalFileName = "HZZlljjRM_GluGluToHToZZTo2L2Q_M-400_7TeV-powheg-pythia6_Summer11-PU_S4_START42_V11-v1";
  //std::string signalFileName = "HZZlljjRM_GluGluToHToZZTo2L2Q_M-230_7TeV-powheg-pythia6_Summer11-PU_S4_START42_V11-v1";
  signalFileName += "_" + selType;
  signalFileName += "_PU" + PUType;
  signalFileName += "_" + leptType;
  signalFileName += ".root";
  TFile* signalFile = TFile::Open(signalFileName.c_str());
  if( withSignal_ ) {
    char signalLegendText[400];
    if( signalScaleFactor==1. ) 
      sprintf( signalLegendText, "H(400 GeV)" );
    else
      sprintf( signalLegendText, "H(400 GeV) #times %.0f", signalScaleFactor);
    std::string signalLegendText_str(signalLegendText);
    db->add_mcFile( signalFile, signalScaleFactor, "H400", signalLegendText_str, kYellow, 3004);
    //db->add_mcFile_superimp( signalFile, "H400", signalLegendText_str, 5., kRed+3, 2 );
  }

  std::string mcZJetsFileName;
  mcZJetsFileName = "HZZlljjRM_DYJetsToLL_TuneZ2_M-50_7TeV-madgraph-tauola_Summer11-PU_S4_START42_V11-v1";
  mcZJetsFileName += "_" + selType;
  mcZJetsFileName += "_PU" + PUType;
  mcZJetsFileName += "_" + leptType;
  mcZJetsFileName += ".root";
  TFile* mcZJetsFile = TFile::Open(mcZJetsFileName.c_str());
  db->add_mcFile( mcZJetsFile, "ZJets", "Z + jets", 29, 3001);
  //db->add_mcFile( mcZJetsFile, "ZJets", "Z + jets", 10, 0);



  std::string mcVVFileName = "HZZlljjRM_VV_TuneZ2_7TeV-pythia6-tauola_Summer11-PU_S4_START42_V11-v1";
  mcVVFileName += "_" + selType;
  mcVVFileName += "_PU" + PUType;
  mcVVFileName += "_" + leptType;
  mcVVFileName += ".root";
  TFile* mcVVFile = TFile::Open(mcVVFileName.c_str());
  db->add_mcFile( mcVVFile, "VVtoAnything_TuneZ2", "ZZ/WZ/WW", 38, 3003);


  std::string mcTTbarFileName = "HZZlljjRM_TT_TW_TuneZ2_7TeV-powheg-tauola_Summer11-PU_S4_START42_V11-v1";
  mcTTbarFileName += "_" + selType;
  mcTTbarFileName += "_PU" + PUType;
  mcTTbarFileName += "_" + leptType;
  mcTTbarFileName += ".root";
  TFile* mcTTbarFile = TFile::Open(mcTTbarFileName.c_str());
  db->add_mcFile( mcTTbarFile, "TTtW", "t#bar{t}/tW", 39, 3002);






  if( data_dataset=="DATA_Run2011A_v2_Sub2" )
    db->set_lumiNormalization(175.);
  else if( data_dataset=="DATA_1fb" )
    db->set_lumiNormalization(859.);
  else if( data_dataset=="DATA_EPS" )
    db->set_lumiNormalization(960.); 
  else if( data_dataset=="DATA_EPS_FINAL" )
    db->set_lumiNormalization(1000.); 
  else if( data_dataset=="DATA_EPS_FINAL_FULL" )
    db->set_lumiNormalization(1143.); 
  else if( data_dataset=="DATA_EPS_FINAL_FULL_plusSingleMu" )
    db->set_lumiNormalization(1143.); 
  else if( data_dataset=="DoubleElectron_Aug05ReReco" )
    db->set_lumiNormalization(227.); 
  else if( data_dataset=="DoubleMu_Aug05ReReco" )
    db->set_lumiNormalization(285.); 
  else if( data_dataset=="DATA_EPS_FINAL_plusSingleMu" )
    db->set_lumiNormalization(1143.);
  else if( data_dataset=="DATA_LP11" )
    db->set_lumiNormalization(1580.);
  else if( data_dataset=="DATA_Run2011A_FULL" )
    db->set_lumiNormalization(2100.);
  else if( data_dataset=="DATA_HR11" )
    db->set_lumiNormalization(4200.);
  else if( data_dataset=="DATA_HR11_v2" )
    db->set_lumiNormalization(4600.);
  else if( data_dataset=="DATA_Run2011B_v2" )
    db->set_lumiNormalization(2500.);




  bool log = true;


  db->set_legendTitle("Gluon- and 0 b-tag");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags<=0)", 30, 150., 750., "mZZ_g0btag", "m_{ZZ}", "GeV");
  db->set_legendTitle("0 b-tag category");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==0)", 30, 150., 750., "mZZ_0btag", "m_{ZZ}", "GeV");
  db->set_legendTitle("Gluon-tag category");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==-1)", 30, 150., 750., "mZZ_gtag", "m_{ZZ}", "GeV");


  float binWidth = 20.;
  float xMin = 183.;
  float xMax = 803.;
  int nBins = (int)((xMax-xMin)/binWidth);


  // signal box plots:
  db->set_legendTitle("0 b-tag category");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==0)", nBins, xMin, xMax, "mZZ_0btag", "m_{ZZ}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 0);
  drawSidebandsWithCurve( db, data_prefix, PUType, data_mc, flags, 0, "ALL");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==0)", 14, 183., 253., "mZZ_0btag_turnOnZOOM", "m_{ZZ}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 0, "ALL", "turnOnZOOM");
  drawSidebandsWithCurve( db, data_prefix, PUType, data_mc, flags, 0, "ALL", "turnOnZOOM");
  db->set_legendTitle("0 b-tag category (muons)");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==0 && leptType==0)", nBins, xMin, xMax, "mZZ_0btag_mm", "m_{#mu#mujj}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 0, "MU");
  db->set_legendTitle("0 b-tag category (electrons)");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==0 && leptType==1)", nBins, xMin, xMax, "mZZ_0btag_ee", "m_{eejj}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 0, "ELE");

  db->set_legendTitle("1 b-tag category");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==1)", nBins, xMin, xMax, "mZZ_1btag", "m_{ZZ}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 1 );
  drawSidebandsWithCurve( db, data_prefix, PUType, data_mc, flags, 1, "ALL");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==1)", 14, 183., 253., "mZZ_1btag_turnOnZOOM", "m_{ZZ}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 1, "ALL", "turnOnZOOM");
  drawSidebandsWithCurve( db, data_prefix, PUType, data_mc, flags, 1, "ALL", "turnOnZOOM");
  db->set_legendTitle("1 b-tag category (muons)");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==1 && leptType==0)", nBins, xMin, xMax, "mZZ_0btag_mm", "m_{#mu#mujj}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 1, "MU");
  db->set_legendTitle("1 b-tag category (electrons)");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==1 && leptType==1)", nBins, xMin, xMax, "mZZ_0btag_ee", "m_{eejj}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 1, "ELE");

  db->set_legendTitle("2 b-tag category");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==2)", nBins, xMin, xMax, "mZZ_2btag", "m_{ZZ}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 2 );
  drawSidebandsWithCurve( db, data_prefix, PUType, data_mc, flags, 2, "ALL");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==2)", 14, 183., 253., "mZZ_2btag_turnOnZOOM", "m_{ZZ}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 2, "ALL", "turnOnZOOM");
  drawSidebandsWithCurve( db, data_prefix, PUType, data_mc, flags, 2, "ALL", "turnOnZOOM");
  db->set_legendTitle("2 b-tag category (muons)");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==2 && leptType==0)", nBins, xMin, xMax, "mZZ_0btag_mm", "m_{#mu#mujj}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 2, "MU");
  db->set_legendTitle("2 b-tag category (electrons)");
  db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==2 && leptType==1)", nBins, xMin, xMax, "mZZ_0btag_ee", "m_{eejj}", "GeV");
  drawHistoWithCurve( db, data_prefix, PUType, data_mc, flags, 2, "ELE");


  //xMin = 160.;
  //xMax = 1350.;
  //nBins = (int)((xMax-xMin)/binWidth);

  //// long range (up to 1300 gev):
  //db->set_legendTitle("0 b-tag category");
  //db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==0)", nBins, xMin, xMax, "mZZ_0btag_longRange", "m_{ZZ}", "GeV");
  //drawHistoWithCurve( db, data_prefix, PUType, 0, "longRange");

  //db->set_legendTitle("1 b-tag category");
  //db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==1)", nBins, xMin, xMax, "mZZ_1btag_longRange", "m_{ZZ}", "GeV");
  //drawHistoWithCurve( db, data_prefix, PUType, 1, "longRange");

  //db->set_legendTitle("2 b-tag category");
  //db->drawHisto_fromTree("tree_passedEvents", "CMS_hzz2l2q_mZZ", "eventWeight*(mZjj>75. && mZjj<105. && nBTags==2)", nBins, xMin, xMax, "mZZ_2btag_longRange", "m_{ZZ}", "GeV");
  //drawHistoWithCurve( db, data_prefix, PUType, 2, "longRange");


//db->set_legendTitle("0 b-tag Sidebands");
//db->drawHisto("mZZ_kinfit_hiMass_sidebands_0btag", "m_{lljj}", "GeV", "Events", log);

//db->set_legendTitle("1 b-tag Sidebands");
//db->drawHisto("mZZ_kinfit_hiMass_sidebands_1btag", "m_{lljj}", "GeV", "Events", log);

//db->set_legendTitle("2 b-tag Sidebands");
//db->drawHisto("mZZ_kinfit_hiMass_sidebands_2btag", "m_{lljj}", "GeV", "Events", log);



  delete db;
  db = 0;

  return 0;

}