Ejemplo n.º 1
0
int main() {

    DrawTools::setStyle();

    std::string qgfileName = "pdfsOnlyPt.root";
    QGLikelihoodCalculator2* qglc = new QGLikelihoodCalculator2(qgfileName);

    std::string qgfileName_old = "/afs/cern.ch/user/t/tomc/public/QG_pdfs_13TeV_2014-10-12/pdfQG_AK4chs_antib_NoQC_13TeV.root";
    QGLikelihoodCalculator* qglc_old = new QGLikelihoodCalculator(qgfileName_old);


    TFile* file = TFile::Open("/afs/cern.ch/work/t/tomc/public/qgMiniTuples/qgMiniTuple_QCD_Pt-15to3000_Tune4C_Flat_13TeV_pythia8_S14.root");
    std::cout << "-> Opened file: " << file->GetName() << std::endl;
    TTree* tree = (TTree*)file->Get("qgMiniTupleAK4chs/qgMiniTuple");

    //TFile* file = TFile::Open("/afs/cern.ch/work/t/tomc/public/qgMiniTuples/qgMiniTupleForMiniAOD_TTJets.root");
    //std::cout << "-> Opened file: " << file->GetName() << std::endl;
    //TTree* tree = (TTree*)file->Get("qgMiniTupleMiniAOD/qgMiniTupleForMiniAOD");


    int event;
    tree->SetBranchAddress("nEvent", &event);
    float rho;
    tree->SetBranchAddress("rho", &rho);
    float pt;
    tree->SetBranchAddress("pt", &pt);
    float eta;
    tree->SetBranchAddress("eta", &eta);
    float ptD;
    tree->SetBranchAddress("ptD", &ptD);
    float axis2;
    tree->SetBranchAddress("axis2", &axis2);
    int mult;
    tree->SetBranchAddress("mult", &mult);
    int partonId;
    tree->SetBranchAddress("partonId", &partonId);
    float bTag;
    tree->SetBranchAddress("bTag", &bTag);
    //int jetIdLevel;
    //tree->SetBranchAddress("jetIdLevel", &jetIdLevel);
    bool hasGenJet;
    tree->SetBranchAddress("hasGenJet", &hasGenJet);
    bool balanced;
    tree->SetBranchAddress("balanced", &balanced);
    int nGenJetsInCone;
    tree->SetBranchAddress("nGenJetsInCone", &nGenJetsInCone);

    std::vector<float> etaBins = {0,2.5};
    std::vector<float> ptBinsC;
    getBins(ptBinsC, 100, 20, 2000, true);
    ptBinsC.push_back(4000);


    int nbins = 50;

    std::vector< TH1F* > vh1_mult_quark;
    std::vector< TH1F* > vh1_mult_gluon;

    std::vector< TH1F* > vh1_ptD_quark;
    std::vector< TH1F* > vh1_ptD_gluon;

    std::vector< TH1F* > vh1_axis2_quark;
    std::vector< TH1F* > vh1_axis2_gluon;

    std::vector< TH1F* > vh1_qgl_quark;
    std::vector< TH1F* > vh1_qgl_gluon;

    std::vector< TH1F* > vh1_qgl_old_quark;
    std::vector< TH1F* > vh1_qgl_old_gluon;


    for( unsigned i=0; i<ptBinsC.size()-1; ++i ) { // integrated in rho

        TH1F* h1_mult_quark = new TH1F(Form("mult_quark_pt%d", i), "", 100, 0., 100);
        TH1F* h1_mult_gluon = new TH1F(Form("mult_gluon_pt%d", i), "", 100, 0., 100);

        vh1_mult_quark.push_back(h1_mult_quark);
        vh1_mult_gluon.push_back(h1_mult_gluon);


        TH1F* h1_ptD_quark = new TH1F(Form("ptD_quark_pt%d", i), "", nbins, 0., 1.0001);
        TH1F* h1_ptD_gluon = new TH1F(Form("ptD_gluon_pt%d", i), "", nbins, 0., 1.0001);

        vh1_ptD_quark.push_back(h1_ptD_quark);
        vh1_ptD_gluon.push_back(h1_ptD_gluon);


        TH1F* h1_axis2_quark = new TH1F(Form("axis2_quark_pt%d", i), "", nbins, 0., 10);
        TH1F* h1_axis2_gluon = new TH1F(Form("axis2_gluon_pt%d", i), "", nbins, 0., 10);

        vh1_axis2_quark.push_back(h1_axis2_quark);
        vh1_axis2_gluon.push_back(h1_axis2_gluon);



        TH1F* h1_qgl_quark = new TH1F(Form("qgl_quark_pt%d", i), "", nbins, 0., 1.0001);
        TH1F* h1_qgl_gluon = new TH1F(Form("qgl_gluon_pt%d", i), "", nbins, 0., 1.0001);

        vh1_qgl_quark.push_back(h1_qgl_quark);
        vh1_qgl_gluon.push_back(h1_qgl_gluon);


        TH1F* h1_qgl_old_quark = new TH1F(Form("qgl_old_quark_pt%d", i), "", nbins, 0., 1.0001);
        TH1F* h1_qgl_old_gluon = new TH1F(Form("qgl_old_gluon_pt%d", i), "", nbins, 0., 1.0001);

        vh1_qgl_old_quark.push_back(h1_qgl_old_quark);
        vh1_qgl_old_gluon.push_back(h1_qgl_old_gluon);

    }








    std::string outputdir = "RoCs_onlyPt";
    system( Form("mkdir -p %s", outputdir.c_str()));

    int nentries = tree->GetEntries();
    int nentries_max = 10000000;
    if( nentries_max>0 && nentries>nentries_max ) nentries = nentries_max;

    int njets_tot = 0;
    int njets_uds = 0;
    int njets_g = 0;

    int cachedEvent = -1;

    for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {

        tree->GetEntry(iEntry);

        if( iEntry % 500000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;

        if( pt<20. ) continue;
        if( fabs(eta)>2.5 ) continue;
        //if( !hasGenJet ) continue;
        if( nGenJetsInCone!=1 ) continue;
        if( !balanced ) continue;
        if( bTag > 0.244 ) continue; // CSVL

        //if( event!=cachedEvent ) {
        //  cachedEvent = event;
        //} else {
        //  continue;
        //}

        bool is_uds = (partonId!=0 && abs(partonId)<4);
        bool is_g   = partonId==21;
        njets_tot += 1;
        if( is_uds ) njets_uds += 1;
        if( is_g ) njets_g += 1;
        if( !is_uds && !is_g ) continue;	// Keep only udsg

        std::vector<float> vars;
        vars.push_back( mult );
        vars.push_back( ptD );
        vars.push_back( axis2 );

        float qgl = qglc->computeQGLikelihood     ( pt, eta, vars );
        float qgl_old = qglc_old->computeQGLikelihood     ( pt, eta, rho, vars );

        int ibin = -1;
        if( !getBinNumber( ptBinsC, pt, ibin) ) continue;


        if( ibin<0 ) {
            std::cout << "CONTINUING (pt: " << pt << " )" << std::endl;
            continue;
        }


        if( is_uds ) {

            vh1_mult_quark[ibin]->Fill( mult );
            vh1_ptD_quark[ibin]->Fill( ptD );
            vh1_axis2_quark[ibin]->Fill( axis2 );

            vh1_qgl_quark[ibin]->Fill( qgl );
            vh1_qgl_old_quark[ibin]->Fill( qgl_old );

        } else if( is_g ) {

            vh1_mult_gluon[ibin]->Fill( mult );
            vh1_ptD_gluon[ibin]->Fill( ptD );
            vh1_axis2_gluon[ibin]->Fill( axis2 );

            vh1_qgl_gluon[ibin]->Fill( qgl );
            vh1_qgl_old_gluon[ibin]->Fill( qgl_old );

        }


    } // for entries


    std::cout << "quark fraction: " << (float)njets_uds/njets_tot << std::endl;
    std::cout << "gluon fraction: " << (float)njets_g/njets_tot << std::endl;

    for( unsigned i=0; i<vh1_qgl_quark.size(); ++i ) {

        drawSingleRoC( outputdir, "vsRhoBins", ptBinsC[i], ptBinsC[i+1], "QG Likelihood", vh1_qgl_quark[i], vh1_qgl_gluon[i], "QG Likelihood (#rho bins)", vh1_qgl_old_quark[i], vh1_qgl_old_gluon[i] );
        //drawSingleRoC( outputdir, "vsNoQC", ptBinsC[i], ptBinsC[i+1], "QG Likelihood", vh1_qgl_quark[i], vh1_qgl_gluon[i], "QG Likelihood (no QC)", vh1_qgl_noQC_quark[i], vh1_qgl_noQC_gluon[i] );

        drawQuarkVsGluon( outputdir, "mult", "Jet Multiplicity", ptBinsC[i], ptBinsC[i+1], vh1_mult_quark[i], vh1_mult_gluon[i] );
        drawQuarkVsGluon( outputdir, "ptD", "p_{T}D", ptBinsC[i], ptBinsC[i+1], vh1_ptD_quark[i], vh1_ptD_gluon[i] );
        drawQuarkVsGluon( outputdir, "axis2", "-log( #sigma_{2} )", ptBinsC[i], ptBinsC[i+1], vh1_axis2_quark[i], vh1_axis2_gluon[i] );
        drawQuarkVsGluon( outputdir, "qgl", "Quark-Gluon Likelihood", ptBinsC[i], ptBinsC[i+1], vh1_qgl_quark[i], vh1_qgl_gluon[i] );
        drawQuarkVsGluon( outputdir, "qgl_old", "Quark-Gluon Likelihood (#rho bins)", ptBinsC[i], ptBinsC[i+1], vh1_qgl_old_quark[i], vh1_qgl_old_gluon[i] );
    }


    std::string outfilename = "pdfs_plus_qgl_onlyPt.root";

    TFile* outfile = TFile::Open(outfilename.c_str(), "recreate");
    outfile->cd();
    outfile->mkdir("qgl");
    outfile->cd("qgl");
    for( unsigned i=0; i<vh1_qgl_quark.size(); ++i ) {
        vh1_qgl_quark.at(i)->Write();
        vh1_qgl_gluon.at(i)->Write();
    }
    //outfile->cd();
    //outfile->mkdir("mult");
    //outfile->cd("mult");
    //for( unsigned i=0; i<vvh1_mult_quark.size(); ++i ) {
    //  for( unsigned j=0; j<vvh1_mult_quark[i].size(); ++j ) {
    //    vvh1_mult_quark.at(i).at(j)->Write();
    //    vvh1_mult_gluon.at(i).at(j)->Write();
    //  }
    //}
    //outfile->cd();
    //outfile->mkdir("ptD");
    //outfile->cd("ptD");
    //for( unsigned i=0; i<vvh1_ptD_quark.size(); ++i ) {
    //  for( unsigned j=0; j<vvh1_ptD_quark[i].size(); ++j ) {
    //    vvh1_ptD_quark.at(i).at(j)->Write();
    //    vvh1_ptD_gluon.at(i).at(j)->Write();
    //  }
    //}
    //outfile->cd();
    //outfile->mkdir("axis2");
    //outfile->cd("axis2");
    //for( unsigned i=0; i<vvh1_axis2_quark.size(); ++i ) {
    //  for( unsigned j=0; j<vvh1_axis2_quark[i].size(); ++j ) {
    //    vvh1_axis2_quark.at(i).at(j)->Write();
    //    vvh1_axis2_gluon.at(i).at(j)->Write();
    //  }
    //}

    //outfile->cd();

    TVectorT<float> etaBins_t(etaBins.size(), &etaBins[0]);
    etaBins_t.Write("etaBins");
    TVectorT<float> ptBinsC_t(ptBinsC.size(), &ptBinsC[0]);
    ptBinsC_t.Write("ptBinsC");

    outfile->Close();

    return 0;

}
Ejemplo n.º 2
0
int main() {

  // just to set the style:
  DrawBase* db = new DrawBase("LeptonStudies");
  db->set_lumiOnRightSide();
  db->set_shapeNormalization();

  system("mkdir -p LeptonStudiesPlots");


  TFile* file_ttZ = TFile::Open("LeptonStudies_2ndLevelTree_TTZJets_8TeV-madgraph_v2_Summer12_DR53X-PU_S10_START53_V7A-v1.root");
  TFile* file_tt  = TFile::Open("LeptonStudies_2ndLevelTree_TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola.root");
  TFile* file_dy  = TFile::Open("LeptonStudies_2ndLevelTree_DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball.root");

  db->add_mcFile(file_ttZ, "ttZ", "tt+Z", kOrange+1);
  db->add_mcFile(file_tt, "tt", "Top", 38);
  db->add_mcFile(file_dy, "dy", "DY", 46);

  db->set_outputdir("LeptonStudiesPlots");
  db->drawHisto_fromTree( "reducedTree", "ptEle", "matchedToGenEle", 50, 0., 120., "ptEle_prompt", "Electron p_{T}", "GeV");

  TH1D* h1_prompt_signal;
  std::vector<TH1D*> vh1_lastHistos_prompt = db->get_lastHistos_mc();
  for(unsigned i=0; i<vh1_lastHistos_prompt.size(); ++i ) {
    if( db->get_mcFile(i).datasetName=="ttZ" ) {
      h1_prompt_signal = new TH1D( *(vh1_lastHistos_prompt[i]) );
    }
  }


  db->drawHisto_fromTree( "reducedTree", "ptEle", "isFakeEle", 50, 0., 120., "ptEle_nonprompt", "Electron p_{T}", "GeV");
  TH1D* h1_nonprompt_dy;
  TH1D* h1_nonprompt_tt;
  std::vector<TH1D*> vh1_lastHistos_nonprompt = db->get_lastHistos_mc();
  for(unsigned i=0; i<vh1_lastHistos_nonprompt.size(); ++i ) {
    if( db->get_mcFile(i).datasetName=="dy" ) {
      h1_nonprompt_dy = new TH1D( *(vh1_lastHistos_nonprompt[i]) );
    }
    if( db->get_mcFile(i).datasetName=="tt" ) {
      h1_nonprompt_tt = new TH1D( *(vh1_lastHistos_nonprompt[i]) );
    }
  }


  TCanvas* c_pt = new TCanvas("c_pt", "", 600, 600);
  c_pt->cd();

  float xMin = h1_nonprompt_tt->GetXaxis()->GetXmin();
  float xMax = h1_nonprompt_tt->GetXaxis()->GetXmax();
  float yMin = 0.;
  float yMax = h1_nonprompt_dy->GetMaximum()*1.4;

  TH2D* h2_axes_pt = new TH2D("axes_pt", "", 10, xMin, xMax, 10, yMin, yMax);
  h2_axes_pt->SetXTitle("Electron p_{T} [GeV]");
  h2_axes_pt->SetYTitle("Normalized to Unity");


  h2_axes_pt->Draw();
  h1_nonprompt_tt->Draw("same");
  h1_nonprompt_dy->Draw("same");
  h1_prompt_signal->Draw("same");

  TLegend* legend_pt = new TLegend( 0.5, 0.6, 0.88, 0.88 );
  legend_pt->SetTextSize(0.04);
  legend_pt->SetFillColor(0);
  legend_pt->AddEntry( h1_prompt_signal, "tt+Z (prompt)", "F");
  legend_pt->AddEntry( h1_nonprompt_tt, "Top (non-prompt)", "F");
  legend_pt->AddEntry( h1_nonprompt_dy, "DY (non-prompt)", "F");

  legend_pt->Draw("same");

  TPaveText* label = db->get_labelSqrt();
  label->Draw("same");

  gPad->RedrawAxis();
  
  std::string canvasName_pt = db->get_outputdir() + "/ptEle.eps";
  c_pt->SaveAs(canvasName_pt.c_str()); 

  delete h1_prompt_signal;
  delete h1_nonprompt_dy;
  delete h1_nonprompt_tt;

  TH1F::AddDirectory(kTRUE);

  TTree* tree_ttZ = (TTree*)file_ttZ->Get("reducedTree");
  TTree* tree_tt  = (TTree*)file_tt->Get("reducedTree");
  TTree* tree_dy  = (TTree*)file_dy->Get("reducedTree");


  drawSingleRoC( db, tree_ttZ, tree_tt, "tt", "", 10., 20. );
  drawSingleRoC( db, tree_ttZ, tree_tt, "tt_iso", "pfIsoEle/ptEle < 0.15", 10., 20. );
  drawSingleRoC( db, tree_ttZ, tree_tt, "tt_passedHLT", "passedHLTEle", 10., 20. );
  drawSingleRoC( db, tree_ttZ, tree_tt, "tt_passedHLT_iso", "passedHLTEle && pfIsoEle/ptEle < 0.15", 10., 20. );

  drawSingleRoC( db, tree_ttZ, tree_tt, "tt", "", 20., 5000. );
  drawSingleRoC( db, tree_ttZ, tree_tt, "tt_iso", "pfIsoEle/ptEle < 0.15", 20., 5000.);
  drawSingleRoC( db, tree_ttZ, tree_tt, "tt_passedHLT", "passedHLTEle", 20., 5000. );
  drawSingleRoC( db, tree_ttZ, tree_tt, "tt_passedHLT_iso", "passedHLTEle && pfIsoEle/ptEle < 0.15", 20., 5000. );

  drawSingleRoC( db, tree_ttZ, tree_dy, "dy", "", 10., 20.);
  drawSingleRoC( db, tree_ttZ, tree_dy, "dy_iso", "pfIsoEle/ptEle < 0.15", 10., 20.);
  drawSingleRoC( db, tree_ttZ, tree_dy, "dy_passedHLT", "passedHLTEle", 10., 20.);
  drawSingleRoC( db, tree_ttZ, tree_dy, "dy_passedHLT_iso", "passedHLTEle && pfIsoEle/ptEle < 0.15", 10., 20.);

  drawSingleRoC( db, tree_ttZ, tree_dy, "dy", "", 20., 5000. );
  drawSingleRoC( db, tree_ttZ, tree_dy, "dy_iso", "pfIsoEle/ptEle < 0.15", 20., 5000.);
  drawSingleRoC( db, tree_ttZ, tree_dy, "dy_passedHLT", "passedHLTEle", 20., 5000. );
  drawSingleRoC( db, tree_ttZ, tree_dy, "dy_passedHLT_iso", "passedHLTEle && pfIsoEle/ptEle < 0.15", 20., 5000. );

  return 0;

}