예제 #1
0
scalePair energyCorrectionDiff(TCut centCut1, float lowPt, float highPt, float lowEta, float highEta,TCut addCut) { 
   
   TString fname1 = "forest/barrelHiForestPhoton_MCphoton50_51k.root";
   if ( lowPt > 90 ) 
      fname1 = "forest/barrelHiForestPhoton_MCphoton80_28k.root";
   TFile *f1  =new TFile(fname1.Data());
   TTree *photon1 = (TTree*)f1->Get("yongsunPhotonTree");
   photon1->AddFriend("yEvt=yongsunHiEvt"    ,fname1.Data());
   photon1->AddFriend("ySkim=yongsunSkimTree"   ,fname1.Data());
   photon1->AddFriend("yHlt=yongsunHltTree"     ,fname1.Data());
   
   TCut collisionCut = "ySkim.pcollisionEventSelection==1";
   
   TCut hoeCut = "hadronicOverEm<0.2";
   TCut isoCut = "cc4 + cr4 + ct4j20 < 5 && sigmaIetaIeta<0.011";
   TCut ptCut  = Form("genMatchedPt>%.f && genMatchedPt <%.f",lowPt, highPt);
   TCut etaCut = Form("abs(eta)>%f && abs(eta)<%f",lowEta,highEta);
      
   TCut finalCut1 = genMatchCut1 && collisionCut && centCut1 && hoeCut && isoCut && ptCut && etaCut && addCut ; 
   TString variable1 = "pt/genMatchedPt";
   
   TH1D* hScale = new TH1D("hScale","",100,.5,1.5);
   TH1D* hdpt = new TH1D("hdpt","",100,-20,20);
   photon1->Draw(Form("%s>>%s",variable1.Data(),hScale->GetName()), finalCut1);
   photon1->Draw(Form("pt-genMatchedPt>>%s",hdpt->GetName()),       finalCut1);
   cout << "cut = " << finalCut1.GetTitle() <<endl;
   hScale->Draw();
   hdpt->Draw();
   TF1* ff =  cleverGaus(hScale);
   
   scalePair ret;
   double *ps = ff->GetParameters();
   ret.val = ps[1];
   ret.err = ff->GetParError(1);
   // resErr = ff->GetParError(2);
   ret.res  = ps[2];
   ret.resErr = ff->GetParError(2);  
   ret.absVal = hdpt->GetMean();
   cout <<"scale = " << ret.val << " +-" << ret.err << endl;
   return ret;
}
void draw_filterEff_runDep(const char* trig = "HLT_HIL1MinimumBiasHF2AND"){ 
    ifstream in;
    in.open(Form("filterEff_%s.txt", trig));

    Float_t eff[nfilter];
    string run;
    Float_t entries;
    Int_t nlines = 0;

    TCanvas *c1 = new TCanvas("c1","",10,10,900,500);
    c1->SetGrid();
    TH1F *h[nfilter];
    TH1F *hgaus[nfilter];
    for(int i=0; i<nfilter; i++){
        h[i] = new TH1F(Form("h%d",i),"Evt selection efficiency vs. run",1,0,1);
        h[i]->SetStats(0);
        h[i]->SetTitle("Event selection efficiency vs. run; Run number; Event selection efficiency (%)");
        //h[i]->SetAxisRange(40,100,"Y");//for HF1AND trigger
        h[i]->SetAxisRange(85,100,"Y");
        h[i]->SetCanExtend(TH1::kAllAxes);
        h[i]->SetLineColor(colhere[i]);
        h[i]->SetLineWidth(2);
    
        hgaus[i] = new TH1F(Form("hgaus%d",i),"Evt selection efficiency",40,90,100);
        //hgaus[i] = new TH1F(Form("hgaus%d",i),"Evt selection efficiency",15,40,100);//for HF1AND trigger
        hgaus[i]->SetTitle(";Event selection effieiency (%);");
        //hgaus[i]->SetNdivisions(504);
    }

    while (1) {
        in >> run >> entries >> eff[0] >> eff[1] >> eff[2] >> eff[3] >> eff[4];
        if (!in.good()) break;
        for(int i=0; i<nfilter; i++){
            h[i]->Fill(run.data(),eff[i]);
            hgaus[i]->Fill(eff[i]);
        }
        nlines++;
    }
    in.close();
    c1->cd();

    TLegend* l1 = new TLegend(0.68, 0.18, 0.9, 0.35);
    //TLegend* l1 = new TLegend(0.68, 0.68, 0.9, 0.85);
    legStyle(l1);
    for(int i=1; i<nfilter; i++){
        h[i]->LabelsDeflate();
        l1->AddEntry(h[i], evtfilter[i]);
        if(i==1) h[i]->Draw("hist");
        else  h[i]->Draw("hist same");
    }
    l1->Draw("same");
    drawText(trig, 0.25, 0.18);
    c1->SaveAs(Form("pdf/evtfilterEff_runDep_%s.png",trig));

    double gausMean[nfilter], gausResol[nfilter];
    double histMean[nfilter], histResol[nfilter];
    TF1* fgaus[nfilter];
    TCanvas *c2[nfilter];
    
    for(int i=1; i<nfilter; i++){
        c2[i] = new TCanvas(Form("c2_%d",i),"",500,500);
        fgaus[i]= cleverGaus(hgaus[i]);
        gausMean[i] = fgaus[i]->GetParameter(1);
        gausResol[i] = fgaus[i]->GetParameter(2);
        histMean[i] = hgaus[i]->GetMean();
        histResol[i]= hgaus[i]->GetRMS();// GetRMS()=GetStdDev() only in ROOT!
        hgaus[i]->Draw("hist");
        fgaus[i]->Draw("same");

        float xpos(0.20), ypos(0.76);
        float dy=0.05;
        drawText(Form("from historgam"),xpos,ypos,kBlack,18);
        drawText(Form("mean = %.3f",histMean[i]),xpos,ypos-dy,kBlack,18);
        drawText(Form("sigma = %.3f",histResol[i]),xpos,ypos-2*dy,kBlack,18);
        ypos=0.55;
        drawText(Form("from gaus fit"),xpos,ypos,kBlack,18);
        drawText(Form("mean = %.3f",gausMean[i]),xpos,ypos-dy,kBlack,18);
        drawText(Form("sigma = %.3f",gausResol[i]),xpos,ypos-2*dy,kBlack,18);
        drawText(trig, 0.2, 0.18+dy);
        drawText(evtfilter[i], 0.2, 0.18);
        c2[i]->SaveAs(Form("pdf/evtfilterEff_runDep_gaus_%s_%s.png",trig,evtfilter[i]));

    }
}
예제 #3
0
void fitResolandScale(int collision = 2, int flvOpt = 0, int genOpt = 0){
    /*  const int kHIcentral = 0; // 0-30%
        const int kHIperipheral = 1;//30-100%
        const int kPP = 2;
        const int kPA = 3;
        const int kHI010 = 4; //0-10%
        const int kHI1030 = 5; //10-30%
        const int kHI3050 = 6;//30-50%
        const int kHI50100 = 7;//50-100%

*/
   // const int collision = 3;
    TLegend *l1 = new TLegend(0.4365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");

    TCut centCut = "";
    if ( (collision ==0) )   {   
        centCut = "cBin > 0 && cBin< 12";
        easyLeg(l1,"Pb+Pb 0-30%");
    }
    else if (  (collision ==1) ){  // if it's pp 
        centCut = "cBin >=12";
        easyLeg(l1,"Pb+Pb 30-100%");
    }
    else if (collision == 2 || collision == 3){ // pPb
        centCut = "";
        if (collision == 2) easyLeg(l1,"p+p");
        else easyLeg(l1, "p+Pb");
    }
    else if (  (collision ==4) ){  //HI
        centCut = "cBin > 0 && cBin < 4";
        easyLeg(l1,"Pb+Pb 0-10%");
    } else if (  (collision ==5) ){  //HI
        centCut = "cBin >= 4 && cBin < 12";
        easyLeg(l1,"Pb+Pb 10-30%");
    } else if (  (collision ==6) ){  //HI
        centCut = "cBin >= 12 && cBin < 20";
        easyLeg(l1,"Pb+Pb 30-50%");
    } else if (  (collision ==7) ){  //HI
        centCut = "cBin >= 20";
        easyLeg(l1,"Pb+Pb 50-100%");
    }    

    //        
    TH1::SetDefaultSumw2();

    // gStyle->SetOptFit(0);
    gStyle -> SetOptStat(0);
    //  gStyle -> SetTitleYOffset(2.35);
    gStyle -> SetTitleYSize(0.04);


    TCut partonCut = "";
    if (flvOpt ==0 ) partonCut = "";
    else if (flvOpt == 1 ) partonCut = "refPartonFlv == 21";
    else if (flvOpt == 2 ) partonCut = "abs(refPartonFlv) < 21";
    else partonCut = "refPartonFlv < -200";


    const int nPtBin = 12;
    //const int nPtBin = 17;
    //double ptBin[nPtBin+1] = {30.0, 40.0, 50.0, 80.0, 9999.0}; 
    //double AvePtBin[nPtBin+1] = { 35.0, 45.0, 65.0, 100.0};
    double ptBin[nPtBin+1];
    double AvePtBin[nPtBin];

    ptBin[0] = 30.0;
    ptBin[1] = 40.0;
    ptBin[2] = 50.0;
    ptBin[3] = 60.0;
    ptBin[4] = 70.0;
    ptBin[5] = 80.0;
    ptBin[6] = 90.0;
    ptBin[7] = 100.0;
    ptBin[8] = 120.0;
    ptBin[9] = 140.0;
    ptBin[10] = 160.0;
    ptBin[11] = 180.0;
    ptBin[12] = 200.0;

    /*
       for(int i=0;i<=nPtBin;i++){
       ptBin[i] = 30.0+i*10.0;
       }
       */  
    for(int i=0;i<nPtBin;i++){
        AvePtBin[i] = (ptBin[i+1]+ptBin[i])/2.0;
    }

    //    const int nCentBinPa = 3;
    //   double centBinPa[nCentBinPa+1] = {0,20,30,100};
    //
    // fake rate
    //
    int nJetmax = 100;
    float refPt[nJetmax], pt[nJetmax], eta[nJetmax], dphi[nJetmax];
    int nJet, cBin, refPartonFlv[nJetmax];
    EvtSel evtImb;
    TBranch *b_evt;

    multiTreeUtil* yJet = new multiTreeUtil();
    //:PbPb
    if(collision ==1 || collision == 0  || collision == 4 || collision == 5 || collision == 6|| collision == 7){
        yJet -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_qcdAllPhoton30to50_genPhotonPtCut40_allCent.root", "yJet", "",32796./32796);
        yJet -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_qcdAllPhoton50to80_genPhotonPtCut40_allCent.root", "yJet", "",21470./53876);
        yJet -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_qcdAllPhoton80to9999_genPhotonPtCut40_allCent.root", "yJet", "",6462./58781);  
    } else if (collision ==3){
        // pA
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton30to50_forestv85.root", "yJet","", 56669./50385);
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton50to80_forestv85.root", "yJet","", 41906./114136);
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton80to120_forestv85.root", "yJet","",12044./103562);
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton120to9999_forestv85.root", "yJet","", 4481./151511);
    } else if (collision ==2){
        //pp 
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton30to50_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "",29329. / 29329.);
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton50to80_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "",8098. / 87988.);
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton80to120_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "",1680. / 96756.);
        yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton120to9999_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "", 438.   / 90972.);
    }

    yJet -> AddFriend("tgj");
    yJet->AddFriend("yPhotonTree");


    TCanvas* c4 = new TCanvas("c4","",400,800);
    c4->Divide(1,2);
    c4->cd(1);
    TH1D* hpt1 = new TH1D("hpt1",";p_{T}^{RECO};Entries",20,0,200);
    TH1D* hpt0 = (TH1D*)hpt1->Clone("hpt2");
    TH1D* hpt2 = (TH1D*)hpt1->Clone("hpt2");
    TH1D* hpt3 = (TH1D*)hpt1->Clone("hpt3");

    yJet -> Draw2(hpt0, "refPt", Form(" photonEt>40 && genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) "),"");
    yJet -> Draw2(hpt1, "refPt", Form("  photonEt>40 &&  genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && refPartonFlv == 21"),"");
    yJet -> Draw2(hpt2, "refPt", Form(" photonEt>40 &&  genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && abs(refPartonFlv)<21 "),"");
    yJet -> Draw2(hpt3, "refPt", Form(" photonEt>40 &&  genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && refPartonFlv < -200"),"");

    handsomeTH1(hpt0,1);
    handsomeTH1(hpt1,1);
    handsomeTH1(hpt2,2);
    handsomeTH1(hpt3,4);

    hpt0->GetYaxis()->SetTitleOffset(1.8);

    hpt0->DrawCopy("hist");
    hpt1->DrawCopy("same");
    hpt2->DrawCopy("same");
    hpt3->DrawCopy("same");
    jumSun(30,0,30,7400,2);

    c4->cd(2);
    hpt1->Divide(hpt0);
    hpt2->Divide(hpt0);
    hpt3->Divide(hpt0);
    hpt1->SetAxisRange(0,1,"Y");
    hpt1->SetYTitle("Ratio");
    hpt1->DrawCopy();
    hpt2->DrawCopy("same");
    hpt3->DrawCopy("same");
    jumSun(30,0,30,1,2);

    //    return;


    // pt spectrum
    //    TCanvas* c1=  new TCanvas("c1", "", 500,500);
    //   TH1D* hptHat = new TH1D("hptHat",";pt hat;Entries",200,0,200);
    //   yJet->Draw3( hptHat, "yPhotonTree.ptHat"," photonEt>40 && genPhotonEt> 30 && abs(genMomId)<=22","");
    //yJet->Draw3( hptHat, "yPhotonTree.pt","","");
    //    return;


    // Energy Scale
    TCanvas* c2 = new TCanvas("c2", "pt/refPt distribution", 1200, 900); 
    TCanvas* ccc = new TCanvas("ccc", "pt/refpt 30-40GeV", 400, 400); 
    makeMultiPanelCanvas(c2,5,4,0.0,0.0,0.2,0.15,0.02);


    TH1D* Escale[nCentBinPa+5][nPtBin];
    double mean[nCentBinPa+5][nPtBin], var[nCentBinPa+5][nPtBin], resol[nCentBinPa+5][nPtBin], resolVar[nCentBinPa+5][nPtBin];
    int icent =1;
    // for(int icent=1; icent <= nCentBinPa ; icent++){
    for(int i=0; i < nPtBin ; i++){
        //  c2 -> cd((icent-1)*4+i+1);
        c2 -> cd(i+1);
        Escale[icent][i] = new TH1D(Form("Escale%d_%d",icent, i) , " ;  p_{T}^{RECO}/p_{T}^{GEN}", 50, 0, 2);

        if ( genOpt == 0 )  {
            yJet -> Draw2(Escale[icent][i], "pt/refPt", centCut && partonCut && Form(" (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && (refPt >= %d && refPt < %d)", (int)ptBin[i], (int)ptBin[i+1]),""); 
        }
        else if (genOpt == 1)  {
            yJet -> Draw2(Escale[icent][i], "pt/refPt", centCut && partonCut && Form(" (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && (pt >= %d && pt < %d) ", (int)ptBin[i], (int)ptBin[i+1]),"");
        }
        //         Escale[icent][i] -> Draw(); 
        TF1* ff = cleverGaus(Escale[icent][i]);
        gPad->SetLogy();
        mean[icent][i] = ff->GetParameter(1);
        var[icent][i] = ff->GetParError(1);
        resol[icent][i] = ff->GetParameter(2);
        resolVar[icent][i] = ff->GetParError(2);

        float dx1;    
        // ((icent==1)||(icent==4))? dx1=0.15 : dx1=0 ;
        dx1=0;
        //            if ( icent == nCentBinPa )
        //  drawText(Form("E_{T}^{HF|#eta|>4} > %dGeV, ", (int)centBinPa[icent-1]), 0.12+dx1,0.929118,1,15);//yeonju 130805
        //else
        //    drawText(Form("%dGeV < E_{T}^{HF|#eta|>4} < %dGeV, ", (int)centBinPa[icent-1], (int)centBinPa[icent]), 0.12+dx1,0.929118,1,15);

        if ( i+1 == nPtBin ) 
            drawText(Form("p_{T}^{GEN Jet} > %dGeV, ", (int)ptBin[i]), 0.17+dx1,0.84,1,15);//yeonju 130823
        else
            drawText(Form("%dGeV < p_{T}^{GEN Jet} < %dGeV, ", (int)ptBin[i], (int)ptBin[i+1]), 0.17+dx1,0.84,1,12);//yeonju 130823

        //            TLegend *l1 = new TLegend(0.6365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");
        //            easyLeg(l1,"p+Pb 5.02TeV");
        //    l1->AddEntry(hxjgNorm[kPADATA][icent + kPADATA*50][j],"pPb ","p");
        //                  if ( icent==1 && j==1)   l1->Draw();
    }
    // }
    c2 -> Update();

    ccc -> Divide(2,1);
    ccc -> cd(1);
    Escale[1][0]->Draw();
    ccc -> cd(2);
    Escale[1][1]->Draw();



    //
    // Energy Scale
    //

    TCanvas *c3 = new TCanvas("c3", "Energy Scale vs. jet pt",147,37,930,465);
    c3->Divide(2,1);
    c3->cd(1);
    
    double bin[nPtBin+1];
    
    for(int ibin=0; ibin<nPtBin+1; ibin++){
        bin[ibin]=ptBin[ibin];
    }
    
    TH1D* hscale = new TH1D("hscale", ";JetP_{T}^{GEN} (GeV); Energy Scale ", nPtBin, bin);
    l1 -> Draw();
    handsomeTH1(hscale,1);
    hscale -> SetAxisRange(0.9, 1.15, "Y");
    hscale -> Draw();
    jumSun(30,1,200,1);
    
    TLegend *l3=new TLegend(0,0,0.4490239,0.08695652,NULL,"brNDC");
    l3->SetTextFont(42);
    l3->SetTextSize(0.04);
    l3->SetFillColor(0);
    l3->SetLineColor(0);

    for(int i=0; i < nPtBin ; i++){ 
        hscale -> SetBinContent(i+1, mean[icent][i]);
        hscale -> SetBinError(i+1, var[icent][i]);
        hscale -> SetMarkerStyle(20);
        hscale -> SetMarkerSize(1);
        hscale -> Draw("same p");
    }

    TF1 *fs = new TF1("fs", myFunc, 30, 200, 3);
    fs -> SetParameters(0.9,0.8,0.001);
    fs -> SetParNames("scale_C", "scale_S", "scale_N");

    double params[3];

    hscale -> Fit("fs", "RLL");
    fs->GetParameters(params);
    cout << " scale C : " << params[0] << ", S : " << params[1] << ", N : : " << params[2] << endl;
    // cout << " N : " << param[0] << endl;

    fs->Draw("same");


    //
    // Energy Resolution
    //
    c3->cd(2);

    TH1D* hresol = new TH1D("hresol", ";JetP_{T} (GeV); Energy Resolution ", nPtBin, bin);
    handsomeTH1(hresol,1);
    hresol -> SetAxisRange(0.0, 0.3, "Y");
    hresol->GetYaxis()->CenterTitle();
    hresol -> Draw();

    jumSun(30,0.0,30,0.3,2);

    TLegend *l_resol=new TLegend(0.40,0.20,0.85,0.42);
    l_resol->SetTextFont(42);
    l_resol->SetTextSize(0.04);
    l_resol->SetFillColor(0);
    l_resol->SetLineColor(0);

    for(int i=0; i < nPtBin ; i++){ 
        hresol -> SetBinContent(i+1, resol[icent][i]);
        hresol -> SetBinError(i+1, resolVar[icent][i]);
        hresol -> SetMarkerStyle(20);
        hresol -> SetMarkerSize(1);
        hresol -> Draw("same p");
    }
    
    TF1 *f;
  //  if(collision==2){ 
        f = new TF1("f", myFunc3, 30, 200, 3);
        f -> SetParameters(0.03, 0.8, 0.01);
        f -> SetParNames("C", "S", "N");

    //   } else { 
 //       f = new TF1("f", myFunc3, 30, 200, 3);
   //     f -> SetParameters(0.041, 0.956,0.001);
  //      f -> SetParNames("N");
  //  }

    double param[3];

    hresol -> Fit("f", "RLL");
    f->GetParameters(param);
 //   cout << " resol_N : " << param[0]<< endl;
//  if(collision==2) cout << " resol C : " << param[0] << ", S : " << param[1] << ", N : : " << param[2] << endl;
    cout << " resol C : " << param[0] << ", S : " << param[1] << ", N : : " << param[2] << endl;
 //  else cout << " N : " << param[0] << endl;

    f->Draw("same");
    l1 -> Draw();
    //  l_resol->Draw();
    //flvOpt = 0, int genOpt
    // c1 -> SaveAs(".gif");
    //c2 -> SaveAs(Form("./graph/CSnotFix_scale_distribution_collision%d.pdf",collision));
    //c3 -> SaveAs(Form("./graph/CSnotFix_scale_resolution_fit_collision%d.pdf",collision));
    //    c_fake -> SaveAs(".gif");
}
예제 #4
0
void fakerate(int flvOpt = 0, int genOpt = 0){
  TH1::SetDefaultSumw2();

    gStyle->SetOptFit(1011);
    gStyle -> SetOptStat(0);
    //  gStyle -> SetTitleYOffset(2.35);
    gStyle -> SetTitleYSize(0.04);




    
    TCut partonCut = "";
    if (flvOpt ==0 ) partonCut = "";
    else if (flvOpt == 1 ) partonCut = "refPartonFlv == 21";
    else if (flvOpt == 2 ) partonCut = "abs(refPartonFlv) < 21";
    else partonCut = "refPartonFlv < -200";


    const int nPtBin = 18;
    //double ptBin[nPtBin+1] = {30.0, 40.0, 50.0, 80.0, 9999.0}; 
    //double AvePtBin[nPtBin+1] = { 35.0, 45.0, 65.0, 100.0};
    double ptBin[nPtBin+1];
    double AvePtBin[nPtBin];

    for(int i=0;i<=nPtBin;i++){
        ptBin[i] = 20.0+i*10.0;
    }
    for(int i=0;i<nPtBin;i++){
        AvePtBin[i] = (ptBin[i+1]+ptBin[i])/2.0;
    }

    //    const int nCentBinPa = 3;
    //   double centBinPa[nCentBinPa+1] = {0,20,30,100};
    const int nCentBinPa = 1;
    double centBinPa[nCentBinPa+1] = {0,10000};
    //
    // fake rate
    //
    int nJetmax = 100;
    float refPt[nJetmax], pt[nJetmax], eta[nJetmax], dphi[nJetmax];
    int nJet, refPartonFlv[nJetmax];
    EvtSel evtImb;
    TBranch *b_evt;
    
    multiTreeUtil* yJet = new multiTreeUtil();
    // pA
    //yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton30to50_forestv85.root", "yJet","", 56669./50385);
    //   yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton50to80_forestv85.root", "yJet","", 41906./114136);
    //  yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton80to120_forestv85.root", "yJet","",12044./103562);
    //    yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_PA2013_pyquen_allQCDPhoton120to9999_forestv85.root", "yJet","", 4481./151511);
   
    //pp 
    yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton30to50_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "",29329. / 29329.);
    yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton50to80_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "",8098. / 87988.);
    yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton80to120_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "",1680. / 96756.);
    yJet->addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton120to9999_genPhotonPtCut30_CMSSW538HIp2.root", "yJet", "", 438.   / 90972.);


    yJet -> AddFriend("tgj");
    yJet->AddFriend("yPhotonTree");


    TCanvas* c4 = new TCanvas("c4","",400,800);
    c4->Divide(1,2);
    c4->cd(1);
    TH1D* hpt1 = new TH1D("hpt1",";p_{T}^{RECO};Entries",20,0,200);
    TH1D* hpt0 = (TH1D*)hpt1->Clone("hpt2");
    TH1D* hpt2 = (TH1D*)hpt1->Clone("hpt2");
    TH1D* hpt3 = (TH1D*)hpt1->Clone("hpt3");

    yJet -> Draw2(hpt0, "refPt", Form(" photonEt>40 && genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) "),"");
    yJet -> Draw2(hpt1, "refPt", Form("  photonEt>40 &&  genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && refPartonFlv == 21"),"");
    yJet -> Draw2(hpt2, "refPt", Form(" photonEt>40 &&  genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && abs(refPartonFlv)<21 "),"");
    yJet -> Draw2(hpt3, "refPt", Form(" photonEt>40 &&  genPhotonEt> 30 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && refPartonFlv < -200"),"");
    
    handsomeTH1(hpt0,1);
    handsomeTH1(hpt1,1);
    handsomeTH1(hpt2,2);
    handsomeTH1(hpt3,4);
    
    hpt0->GetYaxis()->SetTitleOffset(1.8);

    hpt0->DrawCopy("hist");
    hpt1->DrawCopy("same");
    hpt2->DrawCopy("same");
    hpt3->DrawCopy("same");
    jumSun(30,0,30,7400,2);

    c4->cd(2);
    hpt1->Divide(hpt0);
    hpt2->Divide(hpt0);
    hpt3->Divide(hpt0);
    hpt1->SetAxisRange(0,1,"Y");
    hpt1->SetYTitle("Ratio");
    hpt1->DrawCopy();
    hpt2->DrawCopy("same");
    hpt3->DrawCopy("same");
    jumSun(30,0,30,1,2);

    //    return;


    // pt spectrum
    TCanvas* c1=  new TCanvas("c1", "", 500,500);
    TH1D* hptHat = new TH1D("hptHat",";pt hat;Entries",200,0,200);
    yJet->Draw3( hptHat, "yPhotonTree.ptHat"," photonEt>40 && genPhotonEt> 30 && abs(genMomId)<=22","");
    //yJet->Draw3( hptHat, "yPhotonTree.pt","","");
    //    return;
    
    
    // Energy Scale
    TCanvas* c2 = new TCanvas("c2", "pt/refPt distribution", 1200, 900); 
    makeMultiPanelCanvas(c2,5,4,0.0,0.0,0.2,0.15,0.02);


    TH1D* Escale[nCentBinPa+5][nPtBin];
    double mean[nCentBinPa+5][nPtBin], var[nCentBinPa+5][nPtBin], resol[nCentBinPa+5][nPtBin], resolVar[nCentBinPa+5][nPtBin];
    for(int icent=1; icent <= nCentBinPa ; icent++){
        for(int i=0; i < nPtBin ; i++){
            c2 -> cd((icent-1)*4+i+1);
            Escale[icent][i] = new TH1D(Form("Escale%d_%d",icent, i) , " ;  p_{T}^{RECO}/p_{T}^{GEN}", 50, 0, 2);
            if ( genOpt == 0 )  {
	      yJet -> Draw2(Escale[icent][i], "pt/refPt", partonCut && Form(" (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && (refPt >= %d && refPt < %d) && (hf4Sum > %f && hf4Sum <= %f) ", (int)ptBin[i], (int)ptBin[i+1], (float)centBinPa[icent-1], (float)centBinPa[icent]),""); 
	    }
	    else if (genOpt == 1)  {
	      yJet -> Draw2(Escale[icent][i], "pt/refPt", partonCut && Form(" (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && (pt >= %d && pt < %d) && (hf4Sum > %f && hf4Sum <= %f) ", (int)ptBin[i], (int)ptBin[i+1], (float)centBinPa[icent-1], (float)centBinPa[icent]),"");
	    }
            Escale[icent][i] -> Draw(); 
            TF1* ff = cleverGaus(Escale[icent][i]);
	    gPad->SetLogy();
            mean[icent][i] = ff->GetParameter(1);
            var[icent][i] = ff->GetParError(1);
            resol[icent][i] = ff->GetParameter(2);
            resolVar[icent][i] = ff->GetParError(2);
            
            float dx1;    
           // ((icent==1)||(icent==4))? dx1=0.15 : dx1=0 ;
            dx1=0;
	    //            if ( icent == nCentBinPa )
	    //  drawText(Form("E_{T}^{HF|#eta|>4} > %dGeV, ", (int)centBinPa[icent-1]), 0.12+dx1,0.929118,1,15);//yeonju 130805
            //else
            //    drawText(Form("%dGeV < E_{T}^{HF|#eta|>4} < %dGeV, ", (int)centBinPa[icent-1], (int)centBinPa[icent]), 0.12+dx1,0.929118,1,15);

            if ( i+1 == nPtBin ) 
                drawText(Form("p_{T}^{GEN Jet} > %dGeV, ", (int)ptBin[i]), 0.12+dx1,0.84,1,15);//yeonju 130823
            else
                drawText(Form("%dGeV < p_{T}^{GEN Jet} < %dGeV, ", (int)ptBin[i], (int)ptBin[i+1]), 0.12+dx1,0.84,1,12);//yeonju 130823

            TLegend *l1 = new TLegend(0.6365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");
            easyLeg(l1,"p+Pb 5.02TeV");
            //    l1->AddEntry(hxjgNorm[kPADATA][icent + kPADATA*50][j],"pPb ","p");
            //                  if ( icent==1 && j==1)   l1->Draw();





        }
    }
    c2 -> Update();
    //
    // Energy Scale
    //

    TCanvas *c3 = new TCanvas("c3", "Energy Scale vs. jet pt",147,37,930,465);
    c3->Divide(2,1);
    c3->cd(1);
    TH1D* h = new TH1D("h",";JetP_{T}^{GEN} (GeV); Energy Scale ",1000,20,200);
    handsomeTH1(h,1);
    h -> SetAxisRange(0.8, 1.1, "Y");
    h -> Draw();
    jumSun(20,1,200,1);
    jumSun(30,0.8,30,1.1,2);

    TGraphAsymmErrors* g[nCentBinPa+5];
    g[1] = new TGraphAsymmErrors();
    g[2] = new TGraphAsymmErrors();
    g[3] = new TGraphAsymmErrors();
    TLegend *l3=new TLegend(0,0,0.4490239,0.08695652,NULL,"brNDC");
    l3->SetTextFont(42);
    l3->SetTextSize(0.04);
    l3->SetFillColor(0);
    l3->SetLineColor(0);


    for(int icent=1; icent <= nCentBinPa ; icent++){
        for(int i=0; i < nPtBin ; i++){ 
            g[icent] -> SetPoint(i+1, AvePtBin[i], mean[icent][i]);
            g[icent] -> SetPointError(i+1, 0.001,0.001, var[icent][i], var[icent][i]);
            g[icent] -> SetMarkerStyle(20);
            g[icent] -> SetMarkerSize(1);
            g[icent] -> SetMarkerColor(icent);
            g[icent] -> Draw("same p");
        }
        l3->AddEntry(g[icent], Form("%d GeV < E_{T}^{HF|#eta|>4} < %d GeV", (int)centBinPa[icent-1], (int)centBinPa[icent]), "p"); 
    }
    //    l3 -> Draw();

    //
    // Energy Resolution
    //

    c3->cd(2);
    TH1D* h_resol = new TH1D("h_resol",";JetP_{T} (GeV); Energy Resolution (GeV) ",1000,20,200);
    h_resol -> SetAxisRange(0.0, 0.2, "Y");
    h_resol->GetYaxis()->CenterTitle();
    h_resol -> Draw();
    jumSun(30,0.8,30,1.1,2);

    TGraphAsymmErrors* gResol[nCentBinPa+5];
    gResol[1] = new TGraphAsymmErrors();
    gResol[2] = new TGraphAsymmErrors();
    gResol[3] = new TGraphAsymmErrors();

    TLegend *l_resol=new TLegend(0.40,0.20,0.85,0.42);
    l_resol->SetTextFont(42);
    l_resol->SetTextSize(0.04);
    l_resol->SetFillColor(0);
    l_resol->SetLineColor(0);

    for(int icent=1; icent <= nCentBinPa ; icent++){
        for(int i=0; i < nPtBin ; i++){ 
//            cout << "resol : " << resol[icent][i] << ", resolVar : " << resolVar[icent][i]<< endl;
            gResol[icent] -> SetPoint(i+1, AvePtBin[i], resol[icent][i]);
            gResol[icent] -> SetPointError(i+1, 0.001,0.001, resolVar[icent][i], resolVar[icent][i]);
            gResol[icent] -> SetMarkerStyle(20);
            gResol[icent] -> SetMarkerSize(1);
            gResol[icent] -> SetMarkerColor(icent);
            gResol[icent] -> Draw("same p");
        }
        l_resol->AddEntry(gResol[icent], Form("%d GeV < E_{T}^{HF|#eta|>4} < %d GeV", (int)centBinPa[icent-1], (int)centBinPa[icent]), "p"); 
    }
    l_resol->Draw();
    //flvOpt = 0, int genOpt
   // c1 -> SaveAs(".gif");
    c2 -> SaveAs(Form("c2_flvOpt%d_genOpt%d.gif",flvOpt,genOpt));
    c3 -> SaveAs(Form("c3_flvOpt%d_genOpt%d.gif",flvOpt,genOpt));
    //    c_fake -> SaveAs(".gif");
    

}
void draw_centEff_fitResults(string cutname = "hiHF_hfCoinc3_pVtx") {

    ifstream in;
    //in.open("temp.txt");
    in.open(Form("centEff_fitResults_%s.txt",cutname.data()));

    string run;
    int runtemp;
    Float_t eff, chi2;
    Int_t nlines = 0;
    //TFile *f = new TFile("hist_effcon_runDep.root","RECREATE");
    TCanvas *c1 = new TCanvas("c1","",10,10,900,500);
    c1->SetGrid();
    TH1F *h = new TH1F("h1","Eff+Contamination vs. run",1,0,1);
    h->SetStats(0);
    h->SetTitle("Eff+Contamination vs. run; Run number;Efficiency+Contamination (%)");
    h->SetAxisRange(95,105,"Y");
    h->SetCanExtend(TH1::kAllAxes);
    h->SetLineColor(2);
    TH1F *hgaus = new TH1F("hgaus","Eff+Contamination",20,99,101);

    while (1) {
        in >> run>> eff >> chi2;
        //run = itoa(runtemp);
        if (!in.good()) break;
        if (nlines < 5) printf("run=%s, eff+contamination=%3f, reduced chi2=%3f\n",run.data(),eff,chi2);
        h->Fill(run.data(),eff);
        hgaus->Fill(eff);
        nlines++;
    }
    in.close();
    printf(" found %d points\n",nlines);
    c1->cd();
    h->LabelsDeflate();
    h->Draw("hist");
    c1->SaveAs(Form("figures/centEff_runDep_%s.png",cutname.data()));
 
    TCanvas *c2 = new TCanvas("c2","",500,500);
    double gausMean, gausResol;
    double histMean, histResol;
    TF1* fgaus = cleverGaus(hgaus);
    gausMean = fgaus->GetParameter(1);
    gausResol = fgaus->GetParameter(2);
    hgaus->SetTitle(";Efficiency+Contamination (%);");
    hgaus->SetNdivisions(504);
    hgaus->Draw("hist");
    fgaus->Draw("same");
    histMean = hgaus->GetMean();
    histResol= hgaus->GetRMS();// GetRMS()=GetStdDev() only in ROOT!
    float xpos(0.62), ypos(0.76);
    float dy=0.05;
    drawText(Form("from historgam"),xpos,ypos,kBlack,18);
    drawText(Form("mean = %.3f",histMean),xpos,ypos-dy,kBlack,18);
    drawText(Form("sigma = %.3f",histResol),xpos,ypos-2*dy,kBlack,18);
    ypos=0.55;
    drawText(Form("from gaus fit"),xpos,ypos,kBlack,18);
    drawText(Form("mean = %.3f",gausMean),xpos,ypos-dy,kBlack,18);
    drawText(Form("sigma = %.3f",gausResol),xpos,ypos-2*dy,kBlack,18);
    xpos=0.62-0.21;
    drawText("Dataset : HIMinimumBias2", xpos, 0.18+2*dy);
    drawText("Trig : HLT_HIL1MinimumBiasHF1AND_v1", xpos, 0.18+dy);
    drawText("Evt. sel. filter : hfCoinc3 && pVtx", xpos, 0.18);
    c2->SaveAs(Form("figures/centEff_runDep_gaus_%s.png",cutname.data()));

}