Exemple #1
0
void drawPaPt(){
  
  TCanvas* c1 = new TCanvas("c1","",500,500);
 
  TFile* f1 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr40_to_50_jetPtThr30_20130906.root");
  TH1D* hd1 = (TH1D*)f1->Get("jetPt_icent1_final");
  TFile* f2 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr50_to_60_jetPtThr30_20130906.root");
  TH1D* hd2 = (TH1D*)f2->Get("jetPt_icent1_final");
  TFile* f3 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr60_to_80_jetPtThr30_20130906.root");
  TH1D* hd3 = (TH1D*)f3->Get("jetPt_icent1_final");
  TFile* f4 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr80_to_9999_jetPtThr30_20130906.root");
  TH1D* hd4 = (TH1D*)f4->Get("jetPt_icent1_final");

  TFile* f1m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr40_to_50_jetPtThr30_20130906.root");
  TH1D* hm1 = (TH1D*)f1m->Get("jetPt_icent1_final");
  TFile* f2m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr50_to_60_jetPtThr30_20130906.root");
  TH1D* hm2 = (TH1D*)f2m->Get("jetPt_icent1_final");
  TFile* f3m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr60_to_80_jetPtThr30_20130906.root");
  TH1D* hm3 = (TH1D*)f3m->Get("jetPt_icent1_final");
  TFile* f4m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr80_to_9999_jetPtThr30_20130906.root");
  TH1D* hm4 = (TH1D*)f4m->Get("jetPt_icent1_final");

  double ptBinPaDraw[5] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  TH1D* hd = new TH1D("ptmeanDAta",";p_{T}^{#gamma}; <p_{T}^{Jet}>",4,ptBinPaDraw);
  hd->SetBinContent(1, hd1->GetMean());
  hd->SetBinContent(2, hd2->GetMean());
  hd->SetBinContent(3, hd3->GetMean());
  hd->SetBinContent(4, hd4->GetMean());
  hd->SetBinError(1, hd1->GetMeanError());
  hd->SetBinError(2, hd2->GetMeanError());
  hd->SetBinError(3, hd3->GetMeanError());
  hd->SetBinError(4, hd4->GetMeanError());

  TH1D* hm = new TH1D("ptmeanDAta",";p_{T}^{#gamma}; <p_{T}^{Jet}>",4,ptBinPaDraw);
  hm->SetBinContent(1, hm1->GetMean());
  hm->SetBinContent(2, hm2->GetMean());
  hm->SetBinContent(3, hm3->GetMean());
  hm->SetBinContent(4, hm4->GetMean());
  hm->SetBinError(1, hm1->GetMeanError());
  hm->SetBinError(2, hm2->GetMeanError());
  hm->SetBinError(3, hm3->GetMeanError());
  hm->SetBinError(4, hm4->GetMeanError());



  handsomeTH1(hd,2);
  handsomeTH1(hm,1);
  hm->SetMarkerStyle(24);
  hd->SetAxisRange(30,95,"Y");
  hm->SetAxisRange(30,95,"Y");
  hm->Draw();
  hd->Draw("same");
  TLegend *l1 = new TLegend(0.2399194,0.7288136,0.7862903,0.9322034,NULL,"brNDC");
  easyLeg(l1,"5.02TeV pPb MinBias");
  l1->AddEntry(hd, "DATA","p");
  l1->AddEntry(hm, "MC","p");
  l1->Draw();

  c1->SaveAs("pT_dependence_jetPt_ppb.pdf");
}
void photonEnergyValidate   (sampleType collision = kHIMC) {
  TH1::SetDefaultSumw2(); 
  
  TFile* f = new TFile("photonEnergyScaleTable_lowPt_v6.root");
  TF1* curve[2][4];  // [ conversion 0 or 1 ] [ centrality bin 1,2,3] 
  for ( int icent = 1 ; icent<=3 ; icent++) {
    curve[0][icent] = (TF1*)f->Get(Form("fit_hscale_r9gt94_%d",icent));   // Not converted
    curve[1][icent] = (TF1*)f->Get(Form("fit_hscale_r9lt94_%d",icent));  // Converted
    curve[1][icent]->SetLineStyle(7);
  }
  TH1D* htemp = new TH1D("htemp",";p_{T}^{#gamma} (GeV); Residual correction",200,35,200);
  
  TCanvas* c1 = new TCanvas("c1","",500,500);

  handsomeTH1(htemp,0);
  htemp->SetAxisRange(0.97,1.12,"Y");
  htemp->DrawCopy();
  
  for (int icent = 1 ;icent<=3 ; icent++) {
    curve[0][icent]->Draw("same");
    curve[1][icent]->Draw("same");
    //    onSun(35,1,200,1);
  }
  TLegend *l0 =  new TLegend(0.4910859,0.5132576,1,0.7102273,NULL,"brNDC");
  easyLeg(l0,"r9 > 0.94 : Not Conv");
  l0->AddEntry(curve[0][1],"0-10%","l");
  l0->AddEntry(curve[0][2],"10-30%","l");
  l0->AddEntry(curve[0][3],"30-100%","l");
  l0->Draw();
  
  TLegend *l1 = new TLegend(0.4910859,0.7443182,1,0.9318182,NULL,"brNDC");
   easyLeg(l1,"r9 < 0.94 : Conv");
  l1->AddEntry(curve[1][1],"0-10%","l");
  l1->AddEntry(curve[1][2],"10-30%","l");
  l1->AddEntry(curve[1][3],"30-100%","l");
  l1->Draw();
  

       

}
Exemple #3
0
void zeeAnaDiff(TH1D* hsee, TCut addCut,TH1D* hseeMc) {
  
  TFile *f1=new TFile(fname1.Data());
  TTree *zp = (TTree*)f1->Get("tz");
  zp->AddFriend("yEvt=yongsunHiEvt"       ,fname1.Data());
  zp->AddFriend("ySkim=yongsunSkimTree"   ,fname1.Data());
  zp->AddFriend("yHlt=yongsunHltTree"     ,fname1.Data());
  zp->AddFriend("tgj",                     fname1.Data());
  
  TH1D* hmass = new TH1D("hmass",";inv. mass (GeV);event fraction",34,30,200);
  hmass->Sumw2();

  zp->Draw("invm>>hmass",addCut && "isEle1==1 && isEle2==1");
  TH1D* htemp = (TH1D*)hsee->Clone("htemp");   htemp->Reset();
  zp->Draw("see1>>htemp",addCut && "isEle1==1 && isEle2==1" && "invm>80 && invm<100" );
  hsee->Reset();
  hsee->Add(htemp);
  handsomeTH1(hmass,2);
  scaleInt(hmass);
  
  TH1D* htempMC;
  TFile *f1mc;
  TTree *zpmc ;
  f1mc=new TFile(fname1MC.Data());
  zpmc = (TTree*)f1mc->Get("tz");
  zpmc->AddFriend("yEvt=yongsunHiEvt"       ,fname1MC.Data());
  zpmc->AddFriend("ySkim=yongsunSkimTree"   ,fname1MC.Data());
  zpmc->AddFriend("yHlt=yongsunHltTree"     ,fname1MC.Data());
  zpmc->AddFriend("yPho=yongsunPhotonTree"     ,fname1MC.Data());
  zpmc->AddFriend("tgj",                     fname1MC.Data());
  hseeMc->Sumw2();
  htempMC = (TH1D*)hseeMc->Clone("htempMc");   htempMC->Reset();
  TH1D* hmassMC = new TH1D("hmassMC11",";inv. mass (GeV);event fraction",34,30,200);
  hmassMC->Sumw2();
  zpmc->Draw("invm>>hmassMC11",Form("(%s) *yPho.ncoll",addCut.GetTitle()));
  zpmc->Draw("see1>>htempMc",Form("(%s) *yPho.ncoll", (addCut && "invm>80 && invm<100").GetTitle()) );
  hseeMc->Reset();
  hseeMc->Add(htempMC);
  handsomeTH1(hmassMC,1);
  scaleInt(hmassMC);
  
  
  hmassMC->SetAxisRange(0,0.6,"Y");
  hmassMC->DrawCopy();
  hmass->DrawCopy("same");                                                                                             
  TLegend* leg1 =  new TLegend(0.5580645,0.5381356,0.8923387,0.7648305,NULL,"brNDC");
  easyLeg(leg1,"Z->ee mass");
  leg1->AddEntry(hmass,"DATA","pl");
  leg1->AddEntry(hmassMC,"MC","pl");
  leg1->Draw();
  
}
Exemple #4
0
void drawVarAllCent (double, double highPt, TH1D* hvar, TString var,TString varName,  TCut addCut, bool doLog, TString subName,bool onleMC, float maxY ) {
   
   TCanvas* c2 = new TCanvas(Form("c2_%s%s",var.Data(),subName.Data()),"",1000,400);
   makeMultiPanelCanvas(c2,3,1,0.0,0.0,0.2,0.15,0.02);
   for ( int icent = 1 ; icent<=3 ; icent++) {
      int lowCent = centBin_std[icent-1];
      int highCent = centBin_std[icent]-1; 
      c2->cd(4-icent);
      drawVariable(lowCent,highCent,60,10000,hvar, var, addCut,doLog,onleMC, maxY);
      if (doLog )    
	 gPad->SetLogy();
      
      drawText(Form("%.0f %% - %.0f %%", float((float)lowCent*2.5), float((float)(highCent+1)*2.5)),0.6580963,0.9069118,1,16);
      //  drawText("Photon E_{T} > 60GeV",0.3680963,0.6569118,1,15);
      if ( icent == 1 ) {
	 if (!onleMC) drawCMS2011(0.338,0.906,84,16);
      }
      if (icent==2) { 
	 TH1D* data = new TH1D("data11","",1,0,1);
	 data->Sumw2();
	 TH1D* mcSig = new TH1D("mcSig11","",1,0,1);
	 mcStyle(mcSig);
	 TH1D* mcBkg = new TH1D("mcBkg11","",1,0,1);
         dijetStyle(mcBkg);
	 TLegend* leg1 = new TLegend(0.1586395,0.7137837,0.9992263,0.9626509,NULL,"brNDC");
	 easyLeg(leg1,varName.Data());
	 if( !onleMC) leg1->AddEntry(data,"Data","pl");
	 leg1->AddEntry(mcSig,"MC #gamma-jet + HYDJET","fl");
	 leg1->AddEntry(mcBkg,"MC dijet Background","fl");
	 leg1->Draw();
      }
   
      drawPatch(0,0,0.05,0.14,0,1001,"NDC");
      drawPatch(0.93,0.05,1.01,0.14,0,1001,"NDC");

   }
   
   if (subName ==""){
      c2->SaveAs(Form("%s_MCvsDATA_allCent.pdf",var.Data()));
      c2->SaveAs(Form("%s_MCvsDATA_allCent.gif",var.Data()));
   }
   else {
      c2->SaveAs(Form("%s_MCvsDATA_allCent.pdf",subName.Data()));
      c2->SaveAs(Form("%s_MCvsDATA_allCent.gif",subName.Data()));
   }
   
   
}
Exemple #5
0
TH1F* templ(char* prx="")
{
   
   
   TCanvas* c0 = new TCanvas("c0","",800,400);
   c0->Divide(2,1);
   c0->Draw();
   c0->cd(1);
   TFile *f1=new TFile("../rootFiles/compPhoton_scan_0-105-120-150-200.root","r");
   char* _ntupleName_ = "_directory/photons_";
   TNtuple *nt1 = (TNtuple*)f1->Get(_ntupleName_);
   
   //TCut etaCut = "abs(eta)<1.45";
   //char* label  = "Barrel";
   
   int nBin = 100;
   float xMin = -1;
   float xMax = 20;
   TH1F* theHist = new TH1F("_theHist_",";Track Iso(GeV);Entries",nBin,xMin,xMax);
   
   
   nt1->Draw("_theVariable_>>_theHist_",etCut&&etaCut);
   
   theHist->Sumw2();
   handsomeTH1(theHist);
   theHist->Draw();
   
   TLegend* leg = new TLegend(0.56,0.85, 0.95, 0.90,NULL,"brNDC");
   easyLeg(leg,"the legend");
   //   leg->AddEntry(theHist,"compl. cone","l");
   leg->Draw();
   
   c0->SaveAs(Form("plots/thePlot_%s.gif",prx));
   
   
}
void energyCorrectionSet(TCut addCut, TString addName, bool drawRes) { 
   const int nPtBin = 5;
   double ptBin[nPtBin+1] = {40, 60,80,100,140,200};
   TH1D* hscale[10];
   //    const int nLt = 4;                                                                                                               
   // double ltBin[nLt+1] = {0,10,20,30,40};   for ( int icent = 1 ; icent<=nCent_std ; icent++) {
   // for ( int icent = 1 ; icent<=nLt ; icent++) {
   
   
   for ( int icent = 1 ; icent<=nCent_std ; icent++) {                                                                                  
      int lowCent = centBin_std[icent-1];
      int highCent = centBin_std[icent]-1;
      TCut centCut1      = Form("yEvt.hiBin >= %d && yEvt.hiBin<= %d",lowCent,highCent);
      //int lowCent = ltBin[icent-1];
      //int highCent = ltBin[icent]-1;
      // TCut centCut1  = Form("locNtrk >= %d && locNtrk<= %d",lowCent,highCent);        
      hscale[icent] = new TH1D(Form("hscale_%s_%d",addName.Data(),icent),";pT(GeV);scale",nPtBin,ptBin);
      if (drawRes) 
	 hscale[icent]->SetName(Form("hres_%s_%d",addName.Data(),icent));
      for ( int ipt = 1 ; ipt<=nPtBin ; ipt++) { 
	 float lowPt = ptBin[ipt-1]; 
	 float highPt= ptBin[ipt];
	 scalePair theScale = energyCorrectionDiff( centCut1, lowPt, highPt,0,1.44,addCut);
	 if (drawRes){ 
	    hscale[icent]->SetBinContent(ipt, theScale.res);
	    hscale[icent]->SetBinError  (ipt, theScale.resErr);
	 }
	 else {
            hscale[icent]->SetBinContent(ipt, theScale.val);
            hscale[icent]->SetBinError  (ipt, theScale.err);
	 }
      }
      
   }  
   TH1D* htemp = (TH1D*)hscale[1]->Clone("htemp");
   htemp->SetTitle(";Photon E_{T}^{Gen} (GeV) ; E_{T}^{Reco} / E_{T}^{Gen}");
   handsomeTH1(htemp);
   htemp->SetAxisRange(0.9,1.2,"Y");
   if ( drawRes )
      htemp->SetAxisRange(0,0.1,"Y");

   TF1 *func[10];
   for ( int icent = 1 ; icent<=nCent_std ; icent++) {
      // for ( int icent = 1 ; icent<=nLt ; icent++) {
      handsomeTH1(hscale[icent],color[icent]);
      func[icent] = new TF1(Form("fit_%s",hscale[icent]->GetName()),resFun,10,1000,3);
      func[icent]->SetParameters(0.03, 0.2, 0.7 );
      func[icent]->SetParNames("Constants","power");
      hscale[icent]->Fit( func[icent]->GetName(),"LL M O Q");
      func[icent]->SetLineColor(color[icent]);
   }
   
   htemp->Draw();
   for ( int icent = 1 ; icent<=nCent_std ; icent++) {
      int lowCent = centBin_std[icent-1];
      int highCent = centBin_std[icent]-1;
      hscale[icent]->Draw("same");
      func[icent]->Draw("same");
   }
   TLegend* leg1 = new TLegend(0.25,0.65,0.95,0.95,NULL,"brNDC");
   easyLeg(leg1,"");
   leg1->AddEntry(hscale[1],"0 - 10%","lp");
   leg1->AddEntry(hscale[2],"10 - 30%","lp");
   leg1->AddEntry(hscale[3],"30 - 100%","lp");
   leg1->Draw();

   TFile outf = TFile("photonEnergyScaleTable.root","UPDATE");
   for ( int icent = 1 ; icent<=nCent_std ; icent++) {
      hscale[icent]->Write();
      func[icent]->Write();
   }
   outf.Close();
   
   
   
   
}
void drawResults(bool drawSinglePanels = false) {
  // const int kPPcentral = 1;
  // const int kPPperipheral =2 ;
  // const int kHIcentral =  3;
  // const int kHIperipheral = 4;
  // const int kPADATA = 5;
  // const int kPAMC = 6;
  //const int nPtBin = 4;
  // double ptBin[nPtBin+1] = {40, 50,60,80,9999};

  TH1D* meanJetPt[8];   // [collision] [Before/After variation]
  TH1D* meanJetPtSys[8];   // [collision] [Before/After variation]

  TH1D* meanXjg[8];   // [collision] [Before/After variation]
  TH1D* meanXjgSys[8];   // [collision] [Before/After variation]

  TH1D* meanRjg[8];
  TH1D* meanRjgSys[8];

  TFile * f = new TFile("../resultHistograms/resultHistograms_ppSmeared10030.root");
  meanJetPt[1]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  meanXjg[1]    =(TH1D*)f->Get(Form("meanXjg_pp"));
  meanRjg[1]  =(TH1D*)f->Get(Form("meanRjg_pp"));

  f   = new TFile("../resultHistograms/resultHistograms_ppSmeared13099.root");
  meanJetPt[2]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  meanXjg[2]    =(TH1D*)f->Get(Form("meanXjg_pp"));
  meanRjg[2]  =(TH1D*)f->Get(Form("meanRjg_pp"));

  // pbpb
  f =   new TFile("../resultHistograms/resultHistograms_nominal_vtxCentWeighted.root");

  meanJetPt[7]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  meanXjg[7]  =(TH1D*)f->Get(Form("meanXjg_pp"));
  meanRjg[7]  =(TH1D*)f->Get(Form("meanRjg_pp"));

  meanJetPt[3]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin1"));
  meanXjg[3]  =(TH1D*)f->Get(Form("meanXjg_pbpb_centralityBin1"));
  meanRjg[3]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin1"));

  meanJetPt[4]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin2"));
  meanXjg[4]  =(TH1D*)f->Get(Form("meanXjg_pbpb_centralityBin2"));
  meanRjg[4]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin2"));

  // pPb
  meanJetPt[5]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  meanXjg[5]  =(TH1D*)f->Get(Form("meanXjg_ppb"));
  meanRjg[5]  =(TH1D*)f->Get(Form("meanRjg_ppb"));

  f =   new TFile("../resultHistograms/resultHistograms_MCrecoIso_vtxCentWeighted.root"); //pythia+hijing
  meanJetPt[6]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  meanXjg[6]  =(TH1D*)f->Get(Form("meanXjg_ppb"));
  meanRjg[6]  =(TH1D*)f->Get(Form("meanRjg_ppb"));


  TFile* fSys = new TFile("../relativeSys/relativeSys_merged.root");

  meanJetPtSys[1]  =(TH1D*)fSys->Get("meanJetPt_pp_uncertainty_merged");
  meanRjgSys[1]  =(TH1D*)fSys->Get(Form("meanRjg_pp_uncertainty_merged"));
  meanXjgSys[1]  =(TH1D*)fSys->Get(Form("meanXjg_pp_uncertainty_merged"));

  meanJetPtSys[2] = (TH1D*)meanJetPtSys[1]->Clone(Form("%s_2",meanJetPtSys[1]->GetName()));
  meanRjgSys[2] = (TH1D*)meanRjgSys[1]->Clone(Form("%s_2",meanRjgSys[1]->GetName()));
  meanXjgSys[2] = (TH1D*)meanXjgSys[1]->Clone(Form("%s_2",meanXjgSys[1]->GetName()));

  meanJetPtSys[3]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin1_uncertainty_merged");
  meanXjgSys[3]  =(TH1D*)fSys->Get(Form("meanXjg_pbpb_centralityBin1_uncertainty_merged"));
  meanRjgSys[3]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin1_uncertainty_merged"));

  meanJetPtSys[4]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin2_uncertainty_merged");
  meanXjgSys[4]  =(TH1D*)fSys->Get(Form("meanXjg_pbpb_centralityBin2_uncertainty_merged"));
  meanRjgSys[4]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin2_uncertainty_merged"));

  meanJetPtSys[5]  =(TH1D*)fSys->Get("meanJetPt_ppb_uncertainty_merged");
  meanXjgSys[5]  =(TH1D*)fSys->Get(Form("meanXjg_ppb_uncertainty_merged"));
  meanRjgSys[5]  =(TH1D*)fSys->Get(Form("meanRjg_ppb_uncertainty_merged"));


  // RJG!!
  TCanvas* c2; 
  //c2->Divide(3,1);
  if( !drawSinglePanels)
  {
    c2 = new TCanvas("c1","",1300,500);
    makeMultiPanelCanvas(c2,3,1,0.0,0.0, 0.15, 0.15, 0.025);
  }
  else
  {
    c2 = new TCanvas("c1","",1450,500);
    c2->Divide(3,1);
    //makeMultiPanelCanvas(c2,3,1,0.2,0.2, 0.15, 0.15, 0.025);
  }
  c2->cd(3);
  handsomeTH1(meanRjg[1],1,1,21);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempR = new TH1D("tempR",";p_{T}^{#gamma} (GeV);R_{J#gamma}",1000,40,130);
  tempR->Reset();
  handsomeTH1(tempR,0);
  //tempR->SetAxisRange(0,1.2,"Y");
  tempR->SetAxisRange(0,1.0,"Y");
  tempR->SetAxisRange(40.01,109.99,"X");
  tempR->GetYaxis()->SetNdivisions(505);
  tempR->Draw();
  drawSys(meanRjg[1], meanRjgSys[1], kGreen,3001);
  drawSys(meanRjg[3], meanRjgSys[3]);
  handsomeTH1(meanRjg[1],1,1,21);
  meanRjg[1]->DrawCopy("same");
  handsomeTH1(meanRjg[3],2,1,20);
  meanRjg[3]->DrawCopy("same");
  meanRjg[1]->SetFillStyle(3001);
  meanRjg[1]->SetFillColor(kGreen);
  meanRjg[3]->SetFillColor(90);
  meanRjg[3]->SetFillStyle(1001);
  meanRjg[1]->SetLineColor(0);
  meanRjg[3]->SetLineColor(0);
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4,0.2,0.75,0.4,NULL,"brNDC");
    //easyLeg(ly,"2.76TeV");
    easyLeg(ly);
    ly->AddEntry(meanRjg[3],"PbPb 0-30%","fp");
    ly->AddEntry(meanRjg[1],"Smeared pp reference","fp");
    ly->Draw();
  }
  if(!drawSinglePanels)
    drawCMSppPbPbDist(0.04,0.9);
  else
    drawCMSppPbPbDist(0.2,0.9);


  c2->cd(2);
  tempR->Draw();
  drawSys(meanRjg[2], meanRjgSys[2], kGreen,3001);
  drawSys(meanRjg[4], meanRjgSys[4]);
  //  meanRjg[2]->SetMarkerStyle(25);
  handsomeTH1(meanRjg[2],1,1,25);
  meanRjg[2]->DrawCopy("same");
  handsomeTH1(meanRjg[4],2,1,24);
  //  meanRjg[4]->SetMarkerStyle(24);
  meanRjg[4]->DrawCopy("same");
  meanRjg[2]->SetFillStyle(3001);
  meanRjg[2]->SetFillColor(kGreen);
  meanRjg[4]->SetFillColor(90);
  meanRjg[4]->SetFillStyle(1001);
  meanRjg[2]->SetLineColor(0);
  meanRjg[4]->SetLineColor(0);
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4,0.2,0.75,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanRjg[4],"PbPb 30-100%","fp");
    ly->AddEntry(meanRjg[2],"Smeared pp reference","fp");
    ly->Draw();
  }
  if(!drawSinglePanels)
    drawCMSppPbPbDist(0.04,0.9);
  else
    drawCMSppPbPbDist(0.2,0.9);

  c2->cd(1);
  tempR->SetAxisRange(40,109.99,"X");
  tempR->DrawCopy();
  tempR->SetAxisRange(40.01,109.99,"X");
  drawSys(meanRjg[5], meanRjgSys[5], newYellow);
  drawSys(meanRjg[7], meanRjgSys[2], kGreen, 3001);
  //  handsomeTH1(meanRjg[5],9,1,34);
  handsomeTH1(meanRjg[5],2,1,34);
  handsomeTH1(meanRjg[6],1,1,25);
  handsomeTH1(meanRjg[7],1,1);
  meanRjg[6]->DrawCopy("same");
  meanRjg[7]->DrawCopy("same");
  meanRjg[5]->DrawCopy("same");
  meanRjg[7]->SetFillStyle(3001);
  meanRjg[7]->SetFillColor(kGreen);
  meanRjg[5]->SetFillColor(90);
  meanRjg[5]->SetFillStyle(1001);
  meanRjg[7]->SetLineColor(0);
  meanRjg[5]->SetLineColor(0);

  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.5,0.2,0.85,0.42,NULL,"brNDC");//0.4,0.2,0.75,0.4
    easyLeg(ly);
    ly->AddEntry(meanRjg[5],"pPb DATA","fp");
    ly->AddEntry(meanRjg[7],"pp DATA (2.76 TeV)","fp");
    ly->AddEntry(meanRjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  drawCMSpPbDist(0.2,0.9);
  
  c2->SaveAs("pT_dependence_rjg_pp_pbpb.pdf");
  c2->SaveAs("pT_dependence_rjg_pp_pbpb.gif");
  //c2->SaveAs("pT_dependence_rjg_pp_pbpb.png");

  // ppPbPb meanJetPt
  TCanvas* c3 = new TCanvas("c3","",1300,500);
  if(!drawSinglePanels)
    makeMultiPanelCanvas(c3,3,1,0.0,0.0, 0.15, 0.15, 0.025);
  else
    c3->Divide(3,1);
    //makeMultiPanelCanvas(c3,3,1,0.2,0.2, 0.15, 0.15, 0.025);
  c3->cd(1);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  //  tempR->Draw();
  TH1D* tempJ = new TH1D("tempJ",";p_{T}^{#gamma}; <p_{T}^{Jet}>",10000,40,130);
  tempJ->Reset();
  handsomeTH1(tempJ,0);
  tempJ->SetAxisRange(40.01,109.99,"Y");
  tempJ->SetAxisRange(40.,109.99,"X");
  tempJ->DrawCopy();
  tempJ->SetAxisRange(40.01,109.99,"X");
  drawSys(meanJetPt[5], meanJetPtSys[5], newYellow);
  drawSys(meanJetPt[7], meanJetPtSys[1], kGreen,3001);
  //  handsomeTH1(meanJetPt[5],9,1,34);
  handsomeTH1(meanJetPt[5],2,1,34);
  handsomeTH1(meanJetPt[6],1,1,25);
  handsomeTH1(meanJetPt[7],1,1);
  meanJetPt[6]->DrawCopy("same");
  meanJetPt[7]->DrawCopy("same");
  meanJetPt[5]->DrawCopy("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.53,0.18,0.88,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanJetPt[5],"pPb DATA","p");
    ly->AddEntry(meanJetPt[7],"pp DATA (2.76 TeV)","p");
    ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  drawCMSpPbDist(0.2,0.9);

  
  c3->cd(3);
  handsomeTH1(meanJetPt[1],1,1,21);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  tempJ->Draw();
  drawSys(meanJetPt[3], meanJetPtSys[3]);
  drawSys(meanJetPt[1], meanJetPtSys[1], kGreen,3001);
  handsomeTH1(meanJetPt[3],2 );
  meanJetPt[1]->Draw("same");
  meanJetPt[3]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.58,0.18,0.93,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanJetPt[3],"PbPb 0-30%","p");
    ly->AddEntry(meanJetPt[1],"pp (smeared)","p");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.1,0.9);

  c3->cd(2);
  tempJ->Draw();
  drawSys(meanJetPt[2], meanJetPtSys[2], kGreen,3001);
  drawSys(meanJetPt[4], meanJetPtSys[4]);
  //  meanJetPt[2]->SetMarkerStyle(25);
  meanJetPt[2]->Draw("same");
  handsomeTH1(meanJetPt[4],2 );
  //  meanJetPt[4]->SetMarkerStyle(24);
  meanJetPt[4]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.58,0.18,0.93,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
    ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.1,0.9);
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.pdf");
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.gif");
  //c3->SaveAs("pT_dependence_jetPt_pp_pbpb.png");


  // mean xjg
  TCanvas* c7; 
  if(!drawSinglePanels)
  {
    c7 = new TCanvas("c7","",1300,500);
    makeMultiPanelCanvas(c7,3,1,0.0,0.0, 0.15, 0.15, 0.025);
  }
  else
  {
    c7 = new TCanvas("c7","",1450,500);
    c7->Divide(3,1);
    //makeMultiPanelCanvas(c7,3,1,0.2,0.2, 0.15, 0.15, 0.025);
  }
  c7->cd(3);
  handsomeTH1(meanXjg[1],1,1,24);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempX = new TH1D("tempX",";p_{T}^{#gamma} (GeV);<X_{J#gamma}>;",10000,40,130);
  tempX->Reset();
  handsomeTH1(tempX,0);
  tempX->SetAxisRange(0.6,1.1,"Y");
  tempX->SetAxisRange(40.01,109.99,"X");
  tempX->GetYaxis()->SetNdivisions(606);
  tempX->Draw();
  drawSys(meanXjg[3], meanXjgSys[3]);
  drawSys(meanXjg[1], meanXjgSys[1], kGreen,3001);
  //  meanXjg[1]->SetMarkerStyle(21);
  handsomeTH1(meanXjg[1],1,1,21);
  meanXjg[1]->DrawCopy("same");
  handsomeTH1(meanXjg[3],2,1,20);
  meanXjg[3]->DrawCopy("same");
  meanXjg[1]->SetFillStyle(3001);
  meanXjg[1]->SetFillColor(kGreen);
  meanXjg[3]->SetFillColor(90);
  meanXjg[3]->SetFillStyle(1001);
  meanXjg[1]->SetLineColor(0);
  meanXjg[3]->SetLineColor(0);

  Float_t xpos = 0.022;
  if(drawSinglePanels)
    xpos = 0.15;
  if ( 1==1 ){
    TLegend *ly = new TLegend(xpos,0.1861745,0.578901,0.3788434,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanXjg[3],"PbPb 0-30%","fp");
    ly->AddEntry(meanXjg[1],"Smeared pp reference","fp");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.6,0.9);


  c7->cd(2);
  tempX->Draw();
  drawSys(meanXjg[4], meanXjgSys[4]);
  drawSys(meanXjg[2], meanXjgSys[2], kGreen,3001);
  //  meanXjg[2]->SetMarkerStyle(25);
  handsomeTH1(meanXjg[2],1,1,25);
  meanXjg[2]->DrawCopy("same");
  handsomeTH1(meanXjg[4],2,1,24 );
  //  meanXjg[4]->SetMarkerStyle(24);
  meanXjg[4]->DrawCopy("same");
  meanXjg[2]->SetFillStyle(3001);
  meanXjg[2]->SetFillColor(kGreen);
  meanXjg[4]->SetFillColor(90);
  meanXjg[4]->SetFillStyle(1001);
  meanXjg[2]->SetLineColor(0);
  meanXjg[4]->SetLineColor(0);

  if ( 1==1 ){
    TLegend *ly = new TLegend(xpos,0.1861745,0.578901,0.3788434,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanXjg[4],"PbPb 30-100%","fp");
    ly->AddEntry(meanXjg[2],"Smeared pp reference","fp");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.6,0.9);

  c7->cd(1);
  tempX->SetAxisRange(40.0,109.99,"X");
  tempX->DrawCopy();
  tempX->SetAxisRange(40.01,109.99,"X");
  drawSys(meanXjg[5], meanXjgSys[5], newYellow);
  drawSys(meanXjg[7], meanXjgSys[2], kGreen, 3001);
  //  handsomeTH1(meanXjg[5],9,1,34);
  handsomeTH1(meanXjg[5],2,1,34);
  handsomeTH1(meanXjg[6],1,1,25);
  handsomeTH1(meanXjg[7],1,1);
  meanXjg[6]->DrawCopy("same");
  meanXjg[7]->DrawCopy("same");
  meanXjg[5]->DrawCopy("same");
  meanXjg[7]->SetFillStyle(3001);
  meanXjg[7]->SetFillColor(kGreen);
  meanXjg[5]->SetFillColor(90);
  meanXjg[5]->SetFillStyle(1001);
  meanXjg[7]->SetLineColor(0);
  meanXjg[5]->SetLineColor(0);

  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.1722123,0.1861,0.4788343,0.3788,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanXjg[5],"pPb DATA","fp");
    ly->AddEntry(meanXjg[7],"pp DATA (2.76 TeV)","fp");    
    ly->AddEntry(meanXjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  drawCMSpPbDist(0.65,0.90);
  
  c7->SaveAs("pT_dependence_meanXjg_pp_pbpb.pdf");
  c7->SaveAs("pT_dependence_meanXjg_pp_pbpb.gif");
  //c7->SaveAs("pT_dependence_meanXjg_pp_pbpb.png");

  // TCanvas* c10 = new TCanvas("c10","",1200,350);
  // makeMultiPanelCanvas(c10,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  // for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
  //   c10->cd(ipt);

  //   hTempPt->SetAxisRange(20,200,"X");
  //   hTempPt->SetAxisRange(0,2.5,"Y");
  //   hTempPt->SetYTitle("Yield^{JeT} Ratio");
  //   handsomeTH1(hTempPt,0);
  //   hTempPt->DrawCopy();
  //   IaaRatio[4][ipt] = (TH1D*)Iaa[4][ipt]->Clone(Form("%s_ratio",Iaa[4][ipt]->GetName()) );
  //   IaaRatio[4][ipt]->Divide(Iaa[2][ipt]);
  //   IaaRatioSys[4][ipt] = mergeSys( IaaSys[2][ipt], IaaSys[4][ipt]) ;

  //   drawSys(IaaRatio[4][ipt], IaaRatioSys[4][ipt], newYellow);
  //   jumSun(20,1,200,1);
  //   handsomeTH1(IaaRatio[4][ipt],2);
  //   IaaRatio[4][ipt]->SetMarkerStyle(24);
  //   IaaRatio[4][ipt]->Draw("same");
  //   double dx1=0.15;
  //   drawText(Form("p_{T}^{#gamma} > %dGeV ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
  //   drawText(Form("(PbPb)/(pp smeared)  30-100%%"), 0.12+dx1+0.05,0.69,1,15);//yeonju 130823
  // }

  // c10->SaveAs("pT_dependence_iAA_ratio2.pdf");



}
Exemple #8
0
void drawIaa( bool saveFigures=true) {

    const int nPtBin = 4;
    int ptBin[nPtBin+1] = {40, 50,60,80,9999};
    double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
    // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};
    
    const int nCentBinHI = 2;
    const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099}; 

    TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
    TH1D* hIaa[10][6]; // [centrality][pt]
    
    for (int icent=1 ; icent<= 10 ; icent++) {
      for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
	
	hIaa[icent][ipt] = NULL;
	for (int icoll=0 ; icoll<6  ; icoll++) {
	  hJetPt[icoll][icent][ipt] = NULL;
	}
	
      }
    }
    
    TFile* histFile[7][6];  // [Collision][pt]                                                                                          
    for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
      for (int icoll=0 ; icoll<6 ; icoll++) {
	TString sampleName = getSampleName( icoll ) ;

	char* fname =  Form("ffFiles/jetEnergyResL2L3_smeared/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131018.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/centralValue/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/centralOct16th/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131016.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergyResCorrectedOct16th/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131016.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergyScaledMinus2percentOct17/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131017.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/ak5Cone/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131017.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//char* fname =  Form("ffFiles/jetEnergyResCorrected/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//char* fname =  Form("ffFiles/jetEnergyScaledPlus2percent/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergyScaledMinus2percent/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/noElectronRejection/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//char* fname =  Form("ffFiles/leadingJetAnalysis/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergySmearedBy10percent/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/photonEnergyScaled/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011_photonEnergyScaledBy-0.015.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);


	histFile[icoll][ipt] = new TFile(fname) ;
	cout << " Reading file : " << fname << endl;
	if ( histFile[icoll][ipt]->IsZombie()  == false ) {
	  cout << " Success." << endl;
	  if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
	    int icent = 7 ; 
	    hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", icent)) ;
	    cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
	    //	    hJetPt[icoll][7][ipt]->Rebin(10);
	    // hJetPt[icoll][7][ipt]->Scale(1./10);
	    
	  }
	  if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
	    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
	      hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) );
	      cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
	      //	      hJetPt[icoll][icent][ipt]->Rebin(10);
	      //hJetPt[icoll][icent][ipt]->Scale(1/10.);
	    }
	  }
	}
	else  
	  cout << " no such file " << endl;
      }
    }

    // Calculation of IAA
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
	hIaa[icent][ipt] = (TH1D*)hJetPt[kHIDATA][icent][ipt]->Clone(Form("iaa_%s",hJetPt[kHIDATA][icent][ipt]->GetName()));
	hIaa[icent][ipt]->Divide(hJetPt[kPPDATA][7][ipt]);
      }
    }
    
    
    TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);
    
    TCanvas* c2 = new TCanvas("c2","",1000,450);
    makeMultiPanelCanvas(c2,nPtBin,2,0.0,0.0,0.2,0.15,0.02);
    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

        c2->cd(ipt);

        // draw pp
        hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
        hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N^{#gamma}}");
        hTempPt->SetAxisRange(30,200,"X");
	//        hTempPt->SetAxisRange(0,0.025,"Y");
	hTempPt->SetAxisRange(0.00007,0.11,"Y");
        handsomeTH1(hTempPt,0);
        hTempPt->DrawCopy();
	gPad->SetLogy();
	

        handsomeTH1(hJetPt[kPPDATA][7][ipt], 1);
        hJetPt[kPPDATA][7][ipt]->SetMarkerStyle(24);
	hJetPt[kPPDATA][7][ipt]->Draw("same");

        // draw pbpb 
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(hJetPt[kHIDATA][icent][ipt],kRed);
	    if ( icent == 2 ) hJetPt[kHIDATA][icent][ipt]->SetMarkerStyle(24);
	    hJetPt[kHIDATA][icent][ipt]->Draw("same");
        }
       
        double dx1=0.15;

	drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);
	/*
	  if ( ipt == nPtBin ) 
	  drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);
	  else
	  drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);
	*/
	
        onSun(30,0,200,0);

        c2->cd(ipt + nPtBin);
	hTempPt->SetAxisRange(0,2.5,"Y");
	hTempPt->SetYTitle("Ratio of Yield PbPb/pp");
	handsomeTH1(hTempPt,0);
        hTempPt->DrawCopy();
                                                                                                               
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
	  handsomeTH1(hIaa[icent][ipt],kRed);
	  if ( icent == 2 )         hIaa[icent][ipt]->SetMarkerStyle(24);
	  // if ( icent == 1 )   
	    hIaa[icent][ipt]->Draw("same");
	  jumSun(30,1,200,1);
        }
	
	
	
	
    }
    

    c2->cd(1);
    
    TLegend *l2 = new TLegend(0.5933981,0.3877892,0.9981436,0.7857262,NULL,"brNDC");
    easyLeg(l2,"2.76TeV");
    l2->AddEntry(hJetPt[kPPDATA][7][1],"pp", "p");
    l2->AddEntry(hJetPt[kHIDATA][2][1],"PbPb 30-100%", "p");
    l2->AddEntry(hJetPt[kHIDATA][1][1],"PbPb 0-30%", "p");
    l2->Draw();
    if (saveFigures)   c2->SaveAs("figures/pT_dependence_IAA_figure1.pdf");
    if (saveFigures)   c2->SaveAs("figures/pT_dependence_IAA_figure1.gif");


    TFile * fResults =  new TFile("resultHistograms.root","update");

    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
      hJetPt[kPPDATA][7][ipt]->SetName(Form("dNdJetPt_forIaa_pp_ptBin%dAndHigher",ipt));
      hJetPt[kPPDATA][7][ipt]->Write();

      for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        hJetPt[kHIDATA][icent][ipt]->SetName(Form("dNdJetPt_forIaa_pbpb_centralityBin%d_ptBin%dAndHigher",icent,ipt));
	hJetPt[kHIDATA][icent][ipt]->Write();
	
        hIaa[icent][ipt]->SetName(Form("Ryaa_centralityBin%d_ptBin%dAndHigher",icent,ipt));
	hIaa[icent][ipt]->Write();
      }

    }
    fResults->Close();
    
    
    
}
void drawPtDependencePA(TString dirName, int prodDate, int jetPtCut, TString fNameSuffix, TString outNameSuffix){
  bool saveFigures=true;

  const int nPtBin = 4;
  double ptBin[nPtBin+1] = {40, 50,60,80,9999};
  double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};

  const int nCentBinHI = 2;
  const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099};

  TH1D* hxjg[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPtIaaBin[7][10][6]; // [Collision][centrality][pt]
  TH1D* hDphi[7][10][6]; // [Collision][centrality][pt]
  TH1D* meanXjg[7][10];      // [Collision][centrality]
  TH1D* meanJetPt[7][10];      // [Collisi on][centrality]

  TH1D* rjg[7][5];     //  [Collision][centrality]
  for (int icoll=0 ; icoll<6  ; icoll++) {
      for (int icent=1 ; icent<= 10 ; icent++) {
          meanXjg[icoll][icent] = new TH1D( Form("meanXjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <X_{J#gamma}>",nPtBin,ptBinPaDraw);
          meanJetPt[icoll][icent] = new TH1D( Form("meanJetPt_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPtBin,ptBinPaDraw);
          rjg[icoll][icent] = new TH1D( Form("rjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPtBin,ptBinPaDraw);

          for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
              hxjg[icoll][icent][ipt] = NULL;
              hJetPt[icoll][icent][ipt] = NULL;
              hJetPtIaaBin[icoll][icent][ipt] = NULL;
              hDphi[icoll][icent][ipt] = NULL;
          }

      }
  }

  TFile* histFile[7][6];  // [Collision][pt]
  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
      for (int icoll=0 ; icoll<6 ; icoll++) {
          TString sampleName = getSampleName( icoll ) ;
          char* fname;
          if (fNameSuffix.EqualTo(""))  {  // if no explicit suffix for the input file name is specified
              fname =  Form("ffFiles/%s/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d.root",dirName.Data(), sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt], (int)jetPtCut, prodDate);
          }
          else {
              fname =  Form("ffFiles/%s/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d_%s.root",dirName.Data(), sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt], (int)jetPtCut, prodDate, fNameSuffix.Data());
          }

          histFile[icoll][ipt] = new TFile(fname) ;
          cout << " Reading file : " << fname << endl;

          if ( histFile[icoll][ipt]->IsZombie()  == false ) {
              cout << " Success." << endl;
              if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
                  int icent = 7 ;
                  hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
                  hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
                  hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", icent) << endl;
                  hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
                  //hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", icent)) ;
                  //cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent) << endl;

              }

              if ( (icoll == kPADATA) || (icoll == kPAMC) )   {  //  PA
                  int icent = 1 ;
                  hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
                  hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
                  hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", icent ) ) ;
                  cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", icent ) << endl;

                  hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
                  //hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", icent)) ;
                  //cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent) << endl;

              }

              if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
                  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
                      hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
                      cout << " Getting histogram : " << Form("xjg_icent%d_final", centBinHI[icent] ) << endl;
                      hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
                      cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
                      hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) );
                      cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) << endl;
                      hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBinHI[icent] ) ) ;
                      cout << " Getting histogram : " << Form("jetDphi_icent%d_final", centBinHI[icent])<< endl;
                      //hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBinHI[icent] ) ) ;
                      //cout << " Getting histogram : " << Form("etaJg_icent%d_final", centBinHI[icent])<< endl;
                  }
              }
          }
          else
              cout << " no such file " << endl;
      }
  }

  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
      for (int icoll=0 ; icoll<6 ; icoll++) {
          for (int icent=1 ; icent<= 10 ; icent++ ) {

              if ( hxjg[icoll][icent][ipt] == NULL )  continue;   // emtpy histogram

              double rVal, rErr;
              rVal = hxjg[icoll][icent][ipt]->IntegralAndError(1, hxjg[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
              rjg[icoll][icent]->SetBinContent( ipt, rVal );
              rjg[icoll][icent]->SetBinError  ( ipt, rErr );

              meanXjg[icoll][icent]->SetBinContent( ipt, hxjg[icoll][icent][ipt]->GetMean() );
              meanXjg[icoll][icent]->SetBinError  ( ipt, hxjg[icoll][icent][ipt]->GetMeanError() );

              meanJetPt[icoll][icent]->SetBinContent( ipt, hJetPt[icoll][icent][ipt]->GetMean() );
              meanJetPt[icoll][icent]->SetBinError  ( ipt, hJetPt[icoll][icent][ipt]->GetMeanError() );
          }
      }
  }

  TCanvas* c1 = new TCanvas("c1","",1200,350);
  makeMultiPanelCanvas(c1,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

      c1->cd(ipt);

      handsomeTH1(hDphi[kPAMC][1][ipt], 1);
      hDphi[kPAMC][1][ipt]->SetXTitle("#Delta#phi_{J#gamma}");
      hDphi[kPAMC][1][ipt]->SetYTitle("Normalized entries");
      hDphi[kPAMC][1][ipt]->SetMarkerStyle(24);
      hDphi[kPAMC][1][ipt]->Scale(1./hDphi[kPAMC][1][ipt]->Integral("width"));
      hDphi[kPAMC][1][ipt]->SetAxisRange(0,3.141592,"X");
      hDphi[kPAMC][1][ipt]->SetAxisRange(0.01,30,"Y");
      hDphi[kPAMC][1][ipt]->Draw();

      handsomeTH1(hDphi[kPADATA][1][ipt], kRed);
      hDphi[kPADATA][1][ipt]->Scale(1./hDphi[kPADATA][1][ipt]->Integral("width"));
      hDphi[kPADATA][1][ipt]->Draw("same");

      gPad->SetLogy();

      double dx1=0.15;
      if ( ipt == nPtBin )
          drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

  }
  c1->cd(1);

  TLegend *l1 = new TLegend(0.2199474,0.5971384,0.7283974,0.8119819,NULL,"brNDC");
  easyLeg(l1,"5.02TeV");
  l1->AddEntry(hDphi[kPAMC][1][1],"pA pythia+HIJING ","p");
  l1->AddEntry(hDphi[kPADATA][1][1],"pA Data","p");
  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c1->SaveAs("figures/pT_dependence_dphi_pA_figure1.pdf");
          c1->SaveAs("figures/pT_dependence_dphi_pA_figure1.gif");
      }
      else {
          c1->SaveAs(Form("figures/pT_dependence_dphi_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c1->SaveAs(Form("figures/pT_dependence_dphi_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }


  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);

  TCanvas* c2 = new TCanvas("c2","",1200,350);
  makeMultiPanelCanvas(c2,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

      c2->cd(ipt);

      hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
      hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
      hTempPt->SetAxisRange(10,150,"X");
      //        hTempPt->SetAxisRange(0,0.025,"Y");
      hTempPt->SetAxisRange(0,0.08,"Y");
      handsomeTH1(hTempPt,0);
      hTempPt->DrawCopy();

      //	hJetPt[kPAMC][1][ipt]->Scale(1./rjg[kPAMC][1]->GetBinContent(ipt)); // rjg normalization

      handsomeTH1(hJetPt[kPAMC][1][ipt], 1);
      hJetPt[kPAMC][1][ipt]->SetMarkerStyle(24);
      hJetPt[kPAMC][1][ipt]->Draw("same");

      handsomeTH1(hJetPt[kPADATA][1][ipt],kRed);
      //	hJetPt[kPADATA][1][ipt]->Scale(1./rjg[kPADATA][1]->GetBinContent(ipt));

      hJetPt[kPADATA][1][ipt]->Draw("same");


      double dx1=0.15;
      if ( ipt == nPtBin )
          drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

      onSun(30,0,200,0);
  }
  c2->cd(1);
  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c2->SaveAs("figures/pT_dependence_jetPt_pA_figure1.pdf");
          c2->SaveAs("figures/pT_dependence_jetPt_pA_figure1.gif");
      }
      else {
          c2->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c2->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }

  TLegend *l2 = new TLegend(0.2116935,0.7012712,0.6149194,0.904661,NULL,"brNDC");
  easyLeg(l2,"5.02TeV");

  l2->AddEntry(hDphi[kPAMC][1][1],"pPb pythia+HIJING","p");
  l2->AddEntry(hDphi[kPADATA][1][1],"pPb Data","p");


  TCanvas* c21 = new TCanvas("c21","",500,500);
  handsomeTH1(meanJetPt[kPAMC][1], 1);
  meanJetPt[kPAMC][1]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
  meanJetPt[kPAMC][1]->SetMarkerStyle(24);
  //  meanJetPt[kPAMC][1]->SetAxisRange(-2,2,"X");
  meanJetPt[kPAMC][1]->SetAxisRange(40,115,"Y");
  meanJetPt[kPAMC][1]->Draw();

  handsomeTH1(meanJetPt[kPADATA][1],kRed);
  meanJetPt[kPADATA][1]->Draw("same");

  l1 ->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c21->SaveAs("figures/pT_dependence_jetPt_pA_figure2.pdf");
          c21->SaveAs("figures/pT_dependence_jetPt_pA_figure2.gif");
      }
      else {
          c21->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure2_%s.pdf", outNameSuffix.Data()));
          c21->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure2_%s.gif", outNameSuffix.Data()));
      }
  }


  TCanvas* c3 = new TCanvas("c3","",1200,350);
  makeMultiPanelCanvas(c3,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

      c3->cd(ipt);

      handsomeTH1(hxjg[kPAMC][1][ipt], 1);
      hxjg[kPAMC][1][ipt]->SetXTitle("x_{J#gamma}");
      hxjg[kPAMC][1][ipt]->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
      hxjg[kPAMC][1][ipt]->SetMarkerStyle(24);

      //	hxjg[kPAMC][1][ipt]->Scale(1./rjg[kPAMC][1]->GetBinContent(ipt)); // rjg normalization


      hxjg[kPAMC][1][ipt]->SetAxisRange(0,2,"X");
      hxjg[kPAMC][1][ipt]->Draw();

      handsomeTH1(hxjg[kPADATA][1][ipt],kRed);
      //	hxjg[kPADATA][1][ipt]->Scale(1./rjg[kPADATA][1]->GetBinContent(ipt)); // rjg normalization


      hxjg[kPADATA][1][ipt]->Draw("same");

      double dx1=0.15;
      if ( ipt == nPtBin )
          drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823


      onSun(30,0,200,0);
  }
  c3->cd(1);
  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c3->SaveAs("figures/pT_dependence_xjg_pA_figure1.pdf");
          c3->SaveAs("figures/pT_dependence_xjg_pA_figure1.gif");
      }
      else {
          c3->SaveAs(Form("figures/pT_dependence_xjg_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c3->SaveAs(Form("figures/pT_dependence_xjg_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }

  TCanvas* c31 = new TCanvas("c31","",500,500);
  handsomeTH1(meanXjg[kPAMC][1], 1);
  meanXjg[kPAMC][1]->SetYTitle("<x_{J#gamma}>  (>30GeV)");
  meanXjg[kPAMC][1]->SetMarkerStyle(24);
  //  meanXjg[kPAMC][1]->SetAxisRange(-2,2,"X");
  meanXjg[kPAMC][1]->SetAxisRange(0.6,1.2,"Y");
  meanXjg[kPAMC][1]->Draw();

  handsomeTH1(meanXjg[kPADATA][1],kRed);
  meanXjg[kPADATA][1]->Draw("same");

  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c31->SaveAs("figures/pT_dependence_xjg_pA_figure2.pdf");
          c31->SaveAs("figures/pT_dependence_xjg_pA_figure2.gif");
      }
      else {
          c31->SaveAs(Form("figures/pT_dependence_xjg_pA_figure2_%s.pdf", outNameSuffix.Data()));
          c31->SaveAs(Form("figures/pT_dependence_xjg_pA_figure2_%s.gif", outNameSuffix.Data()));
      }
  }

  TCanvas* c_rjg = new TCanvas("c_rjg","",500,500);
  handsomeTH1(rjg[kPAMC][1], 1);
  rjg[kPAMC][1]->SetYTitle("R_{J#gamma}");
  rjg[kPAMC][1]->SetMarkerStyle(24);
  //  rjg[kPAMC][1]->SetAxisRange(-2,2,"X");
  rjg[kPAMC][1]->SetAxisRange(0.0,1.1,"Y");
  rjg[kPAMC][1]->Draw();

  handsomeTH1(rjg[kPADATA][1],kRed);
  rjg[kPADATA][1]->Draw("same");


  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c_rjg->SaveAs("figures/pT_dependence_rjg_pA_figure1.pdf");
          c_rjg->SaveAs("figures/pT_dependence_rjg_pA_figure1.gif");
      }
      else {
          c_rjg->SaveAs(Form("figures/pT_dependence_rjg_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c_rjg->SaveAs(Form("figures/pT_dependence_rjg_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }

  // Save the final root histogram files
  TFile* fResults;
  if(outNameSuffix.EqualTo("")){
      fResults =  new TFile("resultHistograms.root", "update");
  }
  else   {
      fResults =  new TFile(Form("resultHistograms_%s.root", outNameSuffix.Data()), "update");
  }
  //    TFile * fResults =  new TFile("resultHistograms_ppb_photonEnergy_ScaledBy0.015.root","update");

  meanJetPt[kPADATA][1]->SetName(Form("meanJetPt_ppb"));
  meanJetPt[kPADATA][1]->Write();

  meanXjg[kPADATA][1]->SetName(Form("meanXjg_ppb"));
  meanXjg[kPADATA][1]->Write();

  rjg[kPADATA][1]->SetName(Form("meanRjg_ppb"));
  rjg[kPADATA][1]->Write();

  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
      hJetPt[kPADATA][1][ipt]->SetName(Form("dNdJetPt_ppb_ptBin%d",ipt));
      hJetPt[kPADATA][1][ipt]->Write();

      hJetPtIaaBin[kPADATA][1][ipt]->SetName(Form("dNdJetPt_IaaBin_ppb_ptBin%d",ipt));
      hJetPtIaaBin[kPADATA][1][ipt]->Write();

      hxjg[kPADATA][1][ipt]->SetName(Form("dNdXjg_ppb_ptBin%d",ipt));
      hxjg[kPADATA][1][ipt]->Write();

      hDphi[kPADATA][1][ipt]->SetName(Form("dNdphi_ppb_ptBin%d",ipt));
      hDphi[kPADATA][1][ipt]->Write();
  }

  fResults->Close();
}
Exemple #10
0
void drawDijetPtHat() 
  
{
  TH1::SetDefaultSumw2();
 
  vector<int> ptHat_;
  vector<float> cs_;
  //  ptHat_.push_back(30);   cs_.push_back(1.079e-02);
  //  ptHat_.push_back(50);   cs_.push_back(1.021e-03);
  ptHat_.push_back(80);   cs_.push_back(9.913e-05);
  ptHat_.push_back(120);  cs_.push_back(1.128e-05);
  ptHat_.push_back(170);  cs_.push_back(1.470e-06);
  ptHat_.push_back(200);  cs_.push_back(5.310e-07);
  ptHat_.push_back(250);  cs_.push_back(1.192e-07);
  ptHat_.push_back(300);  cs_.push_back(3.176e-08);

  multiTreeUtil* tdj= new multiTreeUtil();
  /*  tdj->addFile("jskim_Dijet80_merged_nMix10_July-v1.root","tdj","pthat<120",1);
  tdj->addFile("jskim_Dijet120_merged_nMix10_July-v1.root","tdj","pthat<170",1);
  tdj->addFile("jskim_Dijet170_merged_nMix10_July-v1.root","tdj","pthat<200",1);
  tdj->addFile("jskim_Dijet200_merged_nMix10_July-v1.root","tdj","pthat<250",1);
  tdj->addFile("jskim_Dijet250_merged_nMix10_July-v1.root","tdj","pthat<300",1);
  tdj->addFile("jskim_Dijet300_merged_nMix10_July-v1.root","tdj","",1);
  
  */
    tdj->addFile("jskim_Dijet80_merged_nMix10_July-v1.root","tdj","pthat<120",(9.913e-05 )/78549);
    tdj->addFile("jskim_Dijet120_merged_nMix10_July-v1.root","tdj","pthat<170",( 1.128e-05)/34838);
    tdj->addFile("jskim_Dijet170_merged_nMix10_July-v1.root","tdj","pthat<200",( 1.470e-06)/6108);
    tdj->addFile("jskim_Dijet200_merged_nMix10_July-v1.root","tdj","pthat<250",(5.310e-07 )/35838);
    tdj->addFile("jskim_Dijet250_merged_nMix10_July-v1.root","tdj","pthat<300",( 1.192e-07)/29132);
    tdj->addFile("jskim_Dijet300_merged_nMix10_July-v1.root","tdj","",(3.176e-08)/43015);
  
  
  TH1D* htemp[10];
  int color[10];
  color[0]=1;
  color[1]=2;
  color[2]=4;
  color[3]=5;
  color[4]=6;
  color[5]=9;
  color[6]=1;
 
  TCanvas* c1= new TCanvas("c1","",1000,800);
  c1->Divide(1,2);
    c1->cd(1);
  TH1D* hptljet = new TH1D("hptljet",";leading jet pT (GeV);",48,120,600);
  tdj->Draw2(hptljet,"lJetPt","","");
  TLegend* l1 = new TLegend(0.6723432,0.670013,0.9206198,0.9506693,NULL,"brNDC");
  easyLeg(l1,"");

  for (int i=0;i<=5;i++) {
    htemp[i] = new TH1D(Form("htemp_%d",i),"",10,0,10);
    handsomeTH1(htemp[i], color[i]);
    l1->AddEntry(htemp[i],Form("pt-hat : %dGeV",ptHat_[i]),"l");
  }
  l1->Draw();
  drawText("Leading jet", 0.5,0.9);
  
  c1->cd(2);
  TH1D* hptsljet = new TH1D("hptsljet",";Subleading jet pT (GeV);",55,50,600);
  tdj->Draw2(hptsljet,"slJetPt","","");
  drawText("Subleading jet", 0.5,0.9);



}
void drawPtDependencePPSmeared(int centBin = 10030, TString dirName="nominal", int prodDate=20131021, int jetPtCut=30) {
  TH1::SetDefaultSumw2();

  const int nPtBin = 4;
  double ptBin[nPtBin+1] = {40, 50,60,80,9999}; 
  double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};
    
  const int nCentBinHI = 2;
  const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099}; 

  TH1D* hxjg[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPtIaaBin[7][10][6]; // [Collision][centrality][pt]
  TH1D* hDphi[7][10][6]; // [Collision][centrality][pt]
  TH1D* hEta[7][10][6]; // [Collision][centrality][pt]
  TH1D* meanXjg[7][10];      // [Collision][centrality]
  TH1D* meanJetPt[7][10];      // [Collisi on][centrality]

  TH1D* rjg[7][10];     //  [Collision][centrality]
  for (int icoll=0 ; icoll<6  ; icoll++) {
    for (int icent=1 ; icent<= 10 ; icent++) {
      meanXjg[icoll][icent] = new TH1D( Form("meanXjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <X_{J#gamma}>",nPtBin,ptBinPaDraw);
      meanJetPt[icoll][icent] = new TH1D( Form("meanJetPt_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPtBin,ptBinPaDraw);
      rjg[icoll][icent] = new TH1D( Form("rjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPtBin,ptBinPaDraw);

      for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
	hxjg[icoll][icent][ipt] = NULL;
	hJetPt[icoll][icent][ipt] = NULL;
	hJetPtIaaBin[icoll][icent][ipt] = NULL;
	hDphi[icoll][icent][ipt] = NULL;
	hEta[icoll][icent][ipt] = NULL;
      }

    }
  }

  TFile* histFile[7][6];  // [Collision][pt]                                                                                          
  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
    for (int icoll=0 ; icoll<6 ; icoll++) {
      TString sampleName = getSampleName( icoll ) ;
      char* fname =  Form("ffFiles/%s/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d.root",dirName.Data(), sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt], (int)jetPtCut, prodDate);

      histFile[icoll][ipt] = new TFile(fname) ;
      cout << " Reading file : " << fname << endl;

      if ( histFile[icoll][ipt]->IsZombie()  == false ) {
	cout << " Success." << endl;
	if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
	  int icent = 7 ; 
	  hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
	  hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
	  hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", icent) << endl;
	  hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
	  hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBin)) ;
	  cout << " Getting histogram : " << Form("etaJg_icent%d_final", centBin) << endl;

	}

	if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
	  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
	    hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
	    cout << " Getting histogram : " << Form("xjg_icent%d_final", centBinHI[icent] ) << endl;
	    hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
	    cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
	    hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) );
	    cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) << endl;
	    hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBinHI[icent] ) ) ;
	    cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent)<< endl;
	    hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBinHI[icent] ) ) ;
	    cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent)<< endl;
	  }
	}
      }
      else  
	cout << " no such file " << endl;
    }
  }

  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
    for (int icoll=0 ; icoll<6 ; icoll++) {
      for (int icent=1 ; icent<= 10 ; icent++ ) { 
	if ( hxjg[icoll][icent][ipt] == NULL ) 
	  continue;   // emtpy histogram 
	double rVal, rErr;

	rVal = hxjg[icoll][icent][ipt]->IntegralAndError(1, hxjg[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
	printf("icoll: %d icent: %d ipt: %d rval: %lf\n",icoll, icent, ipt, rVal);
	rjg[icoll][icent]->SetBinContent( ipt, rVal );
	rjg[icoll][icent]->SetBinError  ( ipt, rErr );

	meanXjg[icoll][icent]->SetBinContent( ipt, hxjg[icoll][icent][ipt]->GetMean() );
	meanXjg[icoll][icent]->SetBinError  ( ipt, hxjg[icoll][icent][ipt]->GetMeanError() );

	meanJetPt[icoll][icent]->SetBinContent( ipt, hJetPt[icoll][icent][ipt]->GetMean() );
	meanJetPt[icoll][icent]->SetBinError  ( ipt, hJetPt[icoll][icent][ipt]->GetMeanError() );


      }
    }
  }

  TCanvas* c1 = new TCanvas("c1","",1200,350);
  makeMultiPanelCanvas(c1,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

    c1->cd(ipt);

    // draw pp
    handsomeTH1(hDphi[kPPDATA][7][ipt], 1);
    hDphi[kPPDATA][7][ipt]->SetXTitle("#Delta#phi_{J#gamma}");
    hDphi[kPPDATA][7][ipt]->SetYTitle("Normalized entries");
    hDphi[kPPDATA][7][ipt]->SetMarkerStyle(24);
    hDphi[kPPDATA][7][ipt]->Scale(1./hDphi[kPPDATA][7][ipt]->Integral("width"));       
    hDphi[kPPDATA][7][ipt]->SetAxisRange(0,3.141592,"X");
    hDphi[kPPDATA][7][ipt]->SetAxisRange(0.01,30,"Y");
    hDphi[kPPDATA][7][ipt]->Draw();
    // draw pbpb 
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      handsomeTH1(hDphi[kHIDATA][icent][ipt],kRed);
      if ( icent == 2 ) hDphi[kHIDATA][icent][ipt]->SetMarkerStyle(24);
      hDphi[kHIDATA][icent][ipt]->Scale(1./hDphi[kHIDATA][icent][ipt]->Integral("width"));
      hDphi[kHIDATA][icent][ipt]->Draw("same");

    }

    gPad->SetLogy();
    //    onSun(30,0,200,0);
  }
  c1->cd(1);
  TLegend *ly = new TLegend(0.4913112,0.6561548,0.9997611,0.9431145,NULL,"brNDC");
  easyLeg(ly,"2.76TeV");
  ly->AddEntry(hDphi[kPPDATA][7][1],"pp ","p");
  ly->AddEntry(hDphi[kHIDATA][2][1],"PbPb 0-30%","p");

  TLegend *l1 = new TLegend(0.1995968,0.7097458,0.7076613,0.9237288,NULL,"brNDC");
  easyLeg(l1,"2.76TeV");
  l1->AddEntry(hDphi[kPPDATA][7][1],"pp ","p");
  l1->AddEntry(hDphi[kHIDATA][2][1],"PbPb 30-100%","p");
  l1->AddEntry(hDphi[kHIDATA][1][1],"PbPb 0-30%","p");
  l1->Draw();

  // c1->SaveAs("figures/pT_dependence_dphi_pp_pbpb_figure1.pdf");
  // c1->SaveAs("figures/pT_dependence_dphi_pp_pbpb_figure1.gif");





  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);

  TCanvas* c2 = new TCanvas("c2","",1200,350);
  makeMultiPanelCanvas(c2,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

    c2->cd(ipt);

    // draw pp
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");
    hTempPt->SetAxisRange(0,0.08,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();
	
    //    hJetPt[kPPDATA][7][ipt]->Scale(1./rjg[kPPDATA][7]->GetBinContent(ipt)); // rjg normalization                      
		

    handsomeTH1(hJetPt[kPPDATA][7][ipt], 1);
    hJetPt[kPPDATA][7][ipt]->SetMarkerStyle(24);
    hJetPt[kPPDATA][7][ipt]->Draw("same");

    // draw pbpb 
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      handsomeTH1(hJetPt[kHIDATA][icent][ipt],kRed);
      //      hJetPt[kHIDATA][icent][ipt]->Scale(1./rjg[kHIDATA][icent]->GetBinContent(ipt));  // rjg normalization
      //      hJetPt[kHIDATA][icent][ipt]->Rebin(10);
      //     hJetPt[kHIDATA][icent][ipt]->Scale(1/10.);
      if ( icent == 2 ) hJetPt[kHIDATA][icent][ipt]->SetMarkerStyle(24);
      if ( icent == 2 ) hJetPt[kHIDATA][icent][ipt]->Draw("same");
      if ( icent == 1 ) hJetPt[kHIDATA][icent][ipt]->Draw("same");
    }
       
    double dx1=0.15;
    if ( ipt == nPtBin ) 
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

    onSun(30,0,200,0);
  }
  c2->cd(1);
  l1->Draw();  

  c2->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure1.pdf");
  c2->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure1.gif");

  TLegend *l2 = new TLegend(0.2116935,0.7012712,0.6149194,0.904661,NULL,"brNDC");
  easyLeg(l2,"2.76TeV");
  l2->AddEntry(hDphi[kPPDATA][7][1],"pp ","p");
  l2->AddEntry(hDphi[kHIDATA][1][1],"PbPb 30-100%","p");
  l2->AddEntry(hDphi[kHIDATA][2][1],"PbPb 0-30%","p");

  TCanvas* c21 = new TCanvas("c21","",500,500);
  handsomeTH1(meanJetPt[kPPDATA][7], 1);
  meanJetPt[kPPDATA][7]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
  meanJetPt[kPPDATA][7]->SetMarkerStyle(24);
  //  meanJetPt[kPPDATA][7]->SetAxisRange(-2,2,"X");
  meanJetPt[kPPDATA][7]->SetAxisRange(40,90,"Y");
  meanJetPt[kPPDATA][7]->Draw();

  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    handsomeTH1(meanJetPt[kHIDATA][icent],kRed);
    if ( icent == 2 ) meanJetPt[kHIDATA][icent]->SetMarkerStyle(24);
    //if ( icent == 2 ) meanJetPt[kHIDATA][icent]->Draw("same");
    meanJetPt[kHIDATA][icent]->Draw("same");
  }
  l1 ->Draw();
  c21->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure2.pdf");
  c21->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure2.gif");

  TCanvas* c3 = new TCanvas("c3","",1200,350);
  makeMultiPanelCanvas(c3,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

    c3->cd(ipt);

    // draw pp
    handsomeTH1(hxjg[kPPDATA][7][ipt], 1);
    hxjg[kPPDATA][7][ipt]->SetXTitle("x_{J#gamma}");
    hxjg[kPPDATA][7][ipt]->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hxjg[kPPDATA][7][ipt]->SetMarkerStyle(24);

    //    hxjg[kPPDATA][7][ipt]->Scale(1./rjg[kPPDATA][7]->GetBinContent(ipt)); // rjg normalization 

    //    hxjg[kPPDATA][7][ipt]->Rebin(10);
    //    hxjg[kPPDATA][7][ipt]->Scale(1./10);
    hxjg[kPPDATA][7][ipt]->SetAxisRange(0,2.5,"X");
    hxjg[kPPDATA][7][ipt]->SetAxisRange(0,3,"Y");
    hxjg[kPPDATA][7][ipt]->Draw();

    // draw pbpb
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      handsomeTH1(hxjg[kHIDATA][icent][ipt],kRed);
      //      hxjg[kHIDATA][icent][ipt]->Scale(1./rjg[kHIDATA][icent]->GetBinContent(ipt)); // rjg normalization    
      //      hxjg[kHIDATA][icent][ipt]->Rebin(10);
      //   hxjg[kHIDATA][icent][ipt]->Scale(1./10);
      if ( icent == 2 ) hxjg[kHIDATA][icent][ipt]->SetMarkerStyle(24);
      if ( icent == 2 ) hxjg[kHIDATA][icent][ipt]->Draw("same");
      if ( icent == 1 ) hxjg[kHIDATA][icent][ipt]->Draw("same");

    }
    double dx1=0.15;
    if ( ipt == nPtBin ) 
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

 
    onSun(30,0,200,0);
  }
  c3->cd(1);
  l1->Draw();  

  c3->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.pdf");
  c3->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.gif");

  TCanvas* c31 = new TCanvas("c31","",500,500);
  handsomeTH1(meanXjg[kPPDATA][7], 1);
  meanXjg[kPPDATA][7]->SetYTitle("<x_{J#gamma}>  (>30GeV)");
  meanXjg[kPPDATA][7]->SetMarkerStyle(24);
  //  meanXjg[kPPDATA][7]->SetAxisRange(-2,2,"X");
  meanXjg[kPPDATA][7]->SetAxisRange(0.6,1.2,"Y");
  meanXjg[kPPDATA][7]->Draw();

  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    handsomeTH1(meanXjg[kHIDATA][icent],kRed);
    if ( icent == 2 ) meanXjg[kHIDATA][icent]->SetMarkerStyle(24);
    //if ( icent != 2 ) meanXjg[kHIDATA][icent]->Draw("same");
    meanXjg[kHIDATA][icent]->Draw("same");
  }
  l1->Draw();
     c31->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.pdf");
     c31->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.gif");
    

  TCanvas* c_rjg = new TCanvas("c_rjg","",500,500);
  handsomeTH1(rjg[kPPDATA][7], 1);
  rjg[kPPDATA][7]->SetYTitle("r_{J#gamma}");
  rjg[kPPDATA][7]->SetMarkerStyle(24);
  //  rjg[kPPDATA][7]->SetAxisRange(-2,2,"X");
  rjg[kPPDATA][7]->SetAxisRange(0.0,1.1,"Y");
  rjg[kPPDATA][7]->Draw();

  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    handsomeTH1(rjg[kHIDATA][icent],kRed);
    if ( icent == 2 ) rjg[kHIDATA][icent]->SetMarkerStyle(24);
    //        if ( icent != 2 ) rjg[kHIDATA][icent]->Draw("same");
    rjg[kHIDATA][icent]->Draw("same");
  }
  l1->Draw();
  c_rjg->SaveAs("figures/pT_dependence_rjg_pp_pbpb_figure1.pdf");
  c_rjg->SaveAs("figures/pT_dependence_rjg_pp_pbpb_figure1.gif");
  
  
  
  // Save the final root histogram files
  TFile * fResults =  new TFile(Form("resultHistograms_ppSmeared%d.root",centBin),"update");
  
  
  // pp 
    
  meanJetPt[kPPDATA][7]->SetName(Form("meanJetPt_pp"));
  meanJetPt[kPPDATA][7]->Write();

  meanXjg[kPPDATA][7]->SetName(Form("meanXjg_pp"));
  meanXjg[kPPDATA][7]->Write();
    
  rjg[kPPDATA][7]->SetName(Form("meanRjg_pp"));
  rjg[kPPDATA][7]->Write();
    
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    hJetPt[kPPDATA][7][ipt]->SetName(Form("dNdJetPt_pp_ptBin%d",ipt));
    hJetPt[kPPDATA][7][ipt]->Write();
    hJetPtIaaBin[kPPDATA][7][ipt]->SetName(Form("dNdJetPt_IaaBin_pp_ptBin%d",ipt));
    hJetPtIaaBin[kPPDATA][7][ipt]->Write();
      
    hxjg[kPPDATA][7][ipt]->SetName(Form("dNdXjg_pp_ptBin%d",ipt));
    hxjg[kPPDATA][7][ipt]->Write();

    hDphi[kPPDATA][7][ipt]->SetName(Form("dNdphi_pp_ptBin%d",ipt));
    hDphi[kPPDATA][7][ipt]->Write();
      
      
  }
    

  // PbPb 
    
  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
      hJetPt[kHIDATA][icent][ipt]->SetName(Form("dNdJetPt_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hJetPt[kHIDATA][icent][ipt]->Write();	
      hJetPtIaaBin[kHIDATA][icent][ipt]->SetName(Form("dNdJetPt_IaaBin_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hJetPtIaaBin[kHIDATA][icent][ipt]->Write();	
  
      hxjg[kHIDATA][icent][ipt]->SetName(Form("dNdXjg_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hxjg[kHIDATA][icent][ipt]->Write();

      hDphi[kHIDATA][icent][ipt]->SetName(Form("dNdphi_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hDphi[kHIDATA][icent][ipt]->Write();
	
    }
      
    meanJetPt[kHIDATA][icent]->SetName(Form("meanJetPt_pbpb_centralityBin%d",icent));
    meanJetPt[kHIDATA][icent]->Write();
    meanXjg[kHIDATA][icent]->SetName(Form("meanXjg_pbpb_centralityBin%d",icent));
    meanXjg[kHIDATA][icent]->Write();
      
    rjg[kHIDATA][icent]->SetName(Form("meanRjg_pbpb_centralityBin%d",icent));
    rjg[kHIDATA][icent]->Write();
  }
    
  fResults->Close();
    
    
}
void yeonju_drawPAFigures_0815(int xNorm = 1) { 
  gStyle -> SetOptStat(0); 
    //yeonju
  const int nCentBinPa = 3;
  double centBinPa[nCentBinPa+1] = {0,20,30,100};
  double AvePtBin[nCentBinPa+1] = {10, 25.0, 65.0, 9999};
  const int nPt = 5;
  const int nFile = 10;
  
  double PtBinPa[nPt+1] = {40,50,60,80,120,9999};

/*  const int nCentBinPa = 5;
  double centBinPa[nCentBinPa+1] = {0,20,25,30,40,100};
  double AvePtBin[nCentBinPa+1] = { 10, 22.5, 27.5, 35, 70, 9999};
  */
  TH1D* hxjg[7][1000][20]; // [species][centrality][pt_dependence]
  TH1D* hxjgNorm[7][1000][20];
  TH1D* hdphi[7][1000][20];
  
  valPair meanX[7][1000][20];
  valPair rjg[7][1000][20];
  TGraphAsymmErrors* gr[7][20];
  TGraphAsymmErrors* gx[7][20];
  for (int j=1;j<=nFile;j++){
      for (int i=1;i<=7;i++) {  
          gr[i][j] = new TGraphAsymmErrors();
          gr[i][j]->SetName(Form("gr_%d_%d",i,j));
          gx[i][j] = new TGraphAsymmErrors();
          gx[i][j]->SetName(Form("gx_%d_%d",i,j));
      }
  }
  TFile* fff[7][1000][20];
  double rError[20];
// cout << "ok!"<< endl;
  for ( int icent = 1 ; icent<=nCentBinPa  ; icent++) { 
    int iSpecies =kPADATA ; 
    
    int iglb = icent + iSpecies*50.;
    
    fff[iSpecies][iglb][1] = new TFile("ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr40_to_50_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][2] = new TFile("ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr50_to_60_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][3] = new TFile("ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr60_to_80_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][4] = new TFile("ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr80_to_120_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][5] = new TFile("ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr120_to_9999_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][6] = new TFile("ffFiles/photonTrackCorr_ppbMC_output_photonPtThr40_to_50_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][7] = new TFile("ffFiles/photonTrackCorr_ppbMC_output_photonPtThr50_to_60_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][8] = new TFile("ffFiles/photonTrackCorr_ppbMC_output_photonPtThr60_to_80_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][9] = new TFile("ffFiles/photonTrackCorr_ppbMC_output_photonPtThr80_to_120_jetPtThr30_20130815.root");
    fff[iSpecies][iglb][10] = new TFile("ffFiles/photonTrackCorr_ppbMC_output_photonPtThr120_to_9999_jetPtThr30_20130815.root");
  //          cout << "fffff" << endl;
    for(int j = 1; j <= nFile ; j++){
        hdphi[iSpecies][iglb][j] = (TH1D*)fff[iSpecies][iglb][j]->Get(Form("jetDphi_icent%d_final",icent));
//cout << "hdphi" <<endl;
        hxjg[iSpecies][iglb][j] = (TH1D*)fff[iSpecies][iglb][j]->Get(Form("xjg_icent%d_final",icent));
        hxjgNorm[iSpecies][iglb][j] = (TH1D*)hxjg[iSpecies][iglb][j]->Clone(Form("norm_%s",hxjg[iSpecies][iglb][j]->GetName()) );

//cout << "meanX" <<endl;
        meanX[iSpecies][iglb][j].val = hxjg[iSpecies][iglb][j]->GetMean();
        meanX[iSpecies][iglb][j].err = hxjg[iSpecies][iglb][j]->GetMeanError();
        gx[iSpecies][j]->SetPoint     (icent, AvePtBin[icent-1], meanX[iSpecies][iglb][j].val);
        gx[iSpecies][j]->SetPointError(icent, AvePtBin[icent-1] - centBinPa[icent-1], centBinPa[icent] - AvePtBin[icent-1], meanX[iSpecies][iglb][j].err, meanX[iSpecies][iglb][j].err);

//cout << "rjg" <<endl;
        rjg[iSpecies][iglb][j].val = hxjg[iSpecies][iglb][j]->IntegralAndError(1, hxjg[iSpecies][iglb][j]->GetNbinsX(), rError[j], "width");
        rjg[iSpecies][iglb][j].err = rError[j];
        gr[iSpecies][j]->SetPoint     (icent, AvePtBin[icent-1], rjg[iSpecies][iglb][j].val);
        gr[iSpecies][j]->SetPointError(icent,  AvePtBin[icent-1] - centBinPa[icent-1], centBinPa[icent] - AvePtBin[icent-1], rjg[iSpecies][iglb][j].err, rjg[iSpecies][iglb][j].err);
    }

  }

  cout << "Tcanvas c1 " << endl;
  TCanvas* c1 = new TCanvas("c1","xjg_distribution",900,1750);
  makeMultiPanelCanvas(c1,3,5,0.0,0.0,0.2,0.15,0.02);
  for ( int j = 1 ; j <= nPt ; j++){//pt
      for ( int icent = 1 ; icent<=nCentBinPa  ; icent++) {
          c1->cd(icent+3*(j-1));

          int iSpecies = kPADATA;
          int iglb = icent + iSpecies*50.;
          handsomeTH1(hxjgNorm[iSpecies][iglb][j],icent);
          hxjgNorm[iSpecies][iglb][j]->Scale(0.1);
          if (xNorm==1) scaleInt(hxjgNorm[iSpecies][iglb][j]);
          hxjgNorm[iSpecies][iglb][j]->SetXTitle("x_{J,#gamma}");
          hxjgNorm[iSpecies][iglb][j]->SetYTitle("#frac{dN}{dx} #frac{1}{N}");
          if (xNorm==1)     hxjgNorm[iSpecies][iglb][j]->SetAxisRange(-0.015,0.35,"Y");
          else              hxjgNorm[iSpecies][iglb][j]->SetAxisRange(-0.06,1.5,"Y");
          hxjgNorm[iSpecies][iglb][j]->SetMarkerStyle(19+j);
          hxjgNorm[iSpecies][iglb][j]->Draw();


          float dx1;    
          ((icent==1)||(icent==4))? dx1=0.15 : dx1=0 ;

          if ( icent == nCentBinPa )
              drawText(Form("E_{T}^{HF|#eta|>4} > %dGeV, ", (int)centBinPa[icent-1]), 0.12+dx1+0.25,0.889118,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.889118,1,15);
          
          if ( j == nPt ) 
              drawText(Form("p_{T}^{#gamma} < %dGeV, ", (int)PtBinPa[j-1]), 0.12+dx1+0.25,0.79,1,15);//yeonju 130823
          else
              drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)PtBinPa[j-1], (int)PtBinPa[j]), 0.12+dx1,0.79,1,15);//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();
              onSun(0,0,2,0);
              jumSun(1,0,1,1);
      }
  }

  c1 -> SaveAs("pPbData_xjgDistribution_pt_cent_dep.gif");
//cout<< "c11" << endl;
/*  TCanvas* c11 = new TCanvas("c11","xjgDist_onePanel_pt_cent_dep",500,500);
  for ( int j = 1 ; j <=nPt ; j++){
      for ( int icent = 1 ; icent<=nCentBinPa  ; icent++) {
          int iSpecies = kPADATA;
          int iglb = icent + iSpecies*50.;
          handsomeTH1(hxjgNorm[iSpecies][iglb][j],icent+3*(j-1));

          if ( icent == 1 && j == 1) hxjgNorm[iSpecies][iglb][j]->Draw();
          else     hxjgNorm[iSpecies][iglb][j]->Draw("same");
          onSun(0,0,2,0);
      }
  }

  c11 -> SaveAs("xjgDist_onePanel_by_pt_cent_dep.gif");
*/
  TCanvas* cDphi = new TCanvas("cDphi","",1200,350);
  makeMultiPanelCanvas(cDphi,5,1,0.0,0.0,0.2,0.15,0.02);

  TH1D* meanDphi[7][10];      // [iSpecies][pt]
  for (int j=1 ; j<=nPt  ; j++) {

          int iSpecies = kPADATA;
          meanDphi[iSpecies][j] = new TH1D(Form("meanDphi_iSpecies%d_pt%d",iSpecies,j), ";p_{T}^{#gamma} (GeV); <Dphi_{J#phi}>",nPt,AvePtBin);
  }

  for (int ipt=1 ; ipt<=nPt ; ipt++) {
      for (int icent=1 ; icent<= nCentBinPa ; icent++ ) { 
          int iSpecies = kPADATA;
          int iglb = icent + iSpecies*50.;

          if ( hdphi[iSpecies][iglb][ipt] == NULL ) 
              continue;   // emtpy histogram 

          meanDphi[iSpecies][ipt]->SetBinContent( ipt, hdphi[iSpecies][iglb][ipt]->GetMean() );
          meanDphi[iSpecies][ipt]->SetBinError  ( ipt, hdphi[iSpecies][iglb][ipt]->GetMeanError() );
      }
  }

  for ( int j = 1 ; j<=nPt ; j++){
      int icent=1;
      // for ( int icent = 1 ; icent<=nCentBinPa  ; icent++) {
      cDphi->cd(j-1);
      int iSpecies = kPADATA;
      int iglb = icent + iSpecies*50.;
      handsomeTH1(meanDphi[iSpecies][j]);
      meanDphi[iSpecies][j]->SetXTitle("#Delta#phi_{J,#gamma}");
      meanDphi[iSpecies][j]->Scale(1./meanDphi[iSpecies][j]->Integral("width"));
      meanDphi[iSpecies][j]->SetAxisRange(0.01,30,"Y");
      //    meanDphi[iSpecies][j]->SetMarkerStyle(24);
      //    handsomeTH1(meanDphi[iSpecies][j],icent+3*(j-1));
      meanDphi[iSpecies][j]->Draw();

      gPad->SetLogy();
      float dx1=0;    
 //     ((icent==1)||(icent==4))? dx1=0.15 : dx1=0 ;

      /*   if ( icent == nCentBinPa )
           drawText(Form("E_{T}^{HF|#eta|>4} > %dGeV", (int)centBinPa[icent-1]), 0.12+dx1+0.25,0.889118,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.889118,1,15);
           */   if ( j == nPt ) 
      drawText(Form("p_{T}^{#gamma} < %dGeV, ", (int)PtBinPa[j-1]), 0.12+dx1+0.25,0.79,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)PtBinPa[j-1], (int)PtBinPa[j]), 0.12+dx1,0.79,1,15);//yeonju 130823

      TLegend *l1 = new TLegend(0.6365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");
      easyLeg(l1,"p+Pb 5.02TeV");
          if ( icent==1 && j==1)   l1->Draw();
     // }
  }
  cDphi -> SaveAs("pPbData_Dphi_distribution_by_pt_dep.pdf");
  
  TCanvas* c2 = new TCanvas("c2","xjg_rjg_vs_pt",800,400);
  c2->Divide(2,1);
  
  TH1D* hr[15];
  TH1D* hx[15];

  for(int j=1; j<=nFile ; j++){
      c2->cd(2);
      hr[j] = new TH1D(Form("hr%d",j),";E_{T}^{HF|#eta|>4} (GeV);r_{J,#gamma}",200,0,100);
      handsomeTH1(hr[j],j+1);
      hr[j]->SetAxisRange(0.01,1.1,"Y");
      //  hr->SetNdivisions(5);
      if (j ==1 ) {hr[j]->Draw();}
      else  { hr[j]->Draw("same");}
      
      if (j < 4) { 
      handsomeTGraph(gr[kPADATA][j],j+1);
          gr[kPADATA][j]->SetMarkerStyle(20);
          gr[kPADATA][j]->SetMarkerSize(1);
          gr[kPADATA][j]->Draw("same p");
      } else {  
      handsomeTGraph(gr[kPADATA][j],j-2);
          gr[kPADATA][j]->SetMarkerStyle(24);
          gr[kPADATA][j]->SetMarkerSize(1.5);
          gr[kPADATA][j]->Draw("same p");
      }

      jumSun(0,1,100,1);

      c2->cd(1);
      hx[j] = (TH1D*)hr[j]->Clone(Form("hx%d",j));
      handsomeTH1(hx[j],j+1);
      hx[j]->SetYTitle("<x_{J,#gamma}>");
      hx[j]->SetAxisRange(0.6,1.05,"Y");
      //  hx->SetNdivisions(5);
      if (j==1) {hx[j]->Draw();}
      else {hx[j]->Draw("same");}
      if (j < 4) { 
      handsomeTGraph(gx[kPADATA][j],j+1);
          gx[kPADATA][j]->SetMarkerStyle(20);
          gx[kPADATA][j]->SetMarkerSize(1);
          gx[kPADATA][j]->Draw("same p");
      } else {  
      handsomeTGraph(gx[kPADATA][j],j-2);
          gx[kPADATA][j]->SetMarkerStyle(24);
          gx[kPADATA][j]->SetMarkerSize(0.2);
          gx[kPADATA][j]->Draw("same p");
      }
      jumSun(0,1,100,1);
  
      TLegend *l1 = new TLegend(0.5226071,0.6300415,0.9597724,0.8332584,NULL,"brNDC");
      easyLeg(l1,"5.02TeV");
      l1->AddEntry(gr[kPADATA][j],"pPb ","p");
      l1->Draw();  }
  

      c2 -> SaveAs("pPbMC_and_Data_comparison_xjg_rjg.gif");
  /* 
  for(int j=1; j<=nPt ; j++){
      c2->cd(2*j);
      hr[j] = new TH1D(Form("hr%d",j),";E_{T}^{HF|#eta|>4} (GeV);r_{J,#gamma}",200,0,100);
      handsomeTH1(hr[j],1);
      hr[j]->SetAxisRange(0.01,1.1,"Y");
      //  hr->SetNdivisions(5);
      hr[j]->Draw();
      handsomeTGraph(gr[kPADATA][j],1);
      gr[kPADATA][j]->SetMarkerStyle(20+j);
      gr[kPADATA][j]->Draw("same p");
      jumSun(0,1,100,1);

      c2->cd(2*j-1);
      hx[j] = (TH1D*)hr[j]->Clone(Form("hx%d",j));
      handsomeTH1(hx[j],1);
      hx[j]->SetYTitle("<x_{J,#gamma}>");
      hx[j]->SetAxisRange(0.6,1.05,"Y");
      //  hx->SetNdivisions(5);
      hx[j]->Draw();
      handsomeTGraph(gx[kPADATA][j],1);
      gx[kPADATA][j]->SetMarkerStyle(20+j);
      gx[kPADATA][j]->Draw("same p");
      jumSun(0,1,100,1);

      TLegend *l1 = new TLegend(0.5226071,0.6300415,0.9597724,0.8332584,NULL,"brNDC");
      easyLeg(l1,"5.02TeV");
      l1->AddEntry(gr[kPADATA][j],"pPb ","p");
      l1->Draw();

      c2 -> SaveAs("x_Jgamma.gif");
  }*/
}
Exemple #13
0
void zeeAna() {
  
  const int tempNbin = 2;
  int tempBin[tempNbin+1] = {0,12,40};
  
  TH1D* hsee[5];
  TH1D* hseeMC[5];
  TH1D* hseePho[5];
  
  TCanvas* c1 = new TCanvas("c1","",1000,500);
  c1->Divide(2,1);
  c1->Draw();
  for ( int icent = 1 ; icent<= tempNbin ; icent++) {
    c1->cd(icent);
    int lowCent = tempBin[icent-1];
    int highCent = tempBin[icent]-1;
    TCut centCut      = Form("yEvt.hiBin >= %d && yEvt.hiBin<= %d",lowCent,highCent);
    TCut firstCut = "pt1>30 && hoe1<0.1 && (cc4+cr4)<5";
    TCut secondCut = "pt2>30 && hoe2<0.2 && see2<0.011 && (cc4+cr4)<5";
    TCut generalCut  = centCut && firstCut && secondCut;
    hsee[icent]   = new TH1D(Form("hsee_icent%d",icent),";#sigma_{#eta#eta};event fraction",25,0,0.025);
    hseeMC[icent] = new TH1D(Form("hseeMC_icent%d",icent),";#sigma_{#eta#eta};event fraction",25,0,0.025);
    hsee[icent]->Sumw2();
    zeeAnaDiff(hsee[icent], generalCut, hseeMC[icent]);
    drawText(Form("%.0f%% - %.0f%%", float((float)lowCent*2.5), float((float)(highCent+1)*2.5)),0.6880963,0.8369118);
  }
  
  c1->SaveAs("invMassOfZ.pdf");

  TCanvas* c1a = new TCanvas("c1a","",1000,500);
  for ( int icent = 1 ; icent<= tempNbin ; icent++) {
    int lowCent = tempBin[icent-1];
    int highCent = tempBin[icent]-1;
    TCut centCut      = Form("yEvt.hiBin >= %d && yEvt.hiBin<= %d",lowCent,highCent);
    TCut generalCut  = "hadronicOverEm<0.1 && corrPt>40 && abs(eta)<1.44 && isGenMatched";
    hseePho[icent] =  new TH1D(Form("hseePho_icent%d",icent),";#sigma_{#eta#eta};event fraction",25,0,0.025);
    hseePho[icent]->Sumw2();
    getseePhoMC(hseePho[icent],generalCut && centCut);
  }
 
  
  TCanvas* c2 = new TCanvas("c2","",1000,500);
  c2->Divide(2,1);
  c2->Draw();
  for ( int icent = 1 ;icent<=tempNbin ; icent++) {
    int lowCent = tempBin[icent-1];
    int highCent = tempBin[icent]-1;
    c2->cd(icent);
    handsomeTH1(hsee[icent],2);
    handsomeTH1(hseeMC[icent],1);
    handsomeTH1(hseePho[icent],4);
    scaleInt(hsee[icent]);
    scaleInt(hseeMC[icent]);
    scaleInt(hseePho[icent]);
    hsee[icent]->SetAxisRange(0,0.8,"Y");
    hsee[icent]->Draw();
    hseeMC[icent]->Draw("same");
    hseePho[icent]->Draw("same hist");
    TLegend* leg1 =  new TLegend(0.5580645,0.5381356,0.8923387,0.7648305,NULL,"brNDC");
    easyLeg(leg1,"#sigma_{#eta#eta}");
    leg1->AddEntry(hsee[icent],"DATA electron","pl");
    leg1->AddEntry(hseeMC[icent],"MC electron","pl");
    leg1->AddEntry(hseePho[icent],"MC photon","l");
    leg1->Draw();
    drawText(Form("%.0f%% - %.0f%%", float((float)lowCent*2.5), float((float)(highCent+1)*2.5)),0.5880963,0.8369118);
    cout << "shift = " << getMean(hsee[icent],5,12) - getMean(hseeMC[icent],5,12) << endl;

  }

  c2->SaveAs("showerShapeComparison.pdf");
  
}
Exemple #14
0
void mcClosure(bool  isFW=1, bool isPrompt=1) { 
  
  TString direction;   
  if (isFW) direction="FW";
  else direction     ="BW";
				    
  TH1::SetDefaultSumw2();

  TFile* f1;
  if ( isPrompt)  f1 = new TFile("/home/samba/songkyo/efficiency/PRMC_eff_rootFile/merged_PRMC_eff_Histos.root"); 
  else f1 = new TFile("/home/samba/songkyo/efficiency/NPMC_eff_rootFile/merged_NPMC_eff_Histos.root");
  
  //read-in tree
  TTree *mytree = (TTree*)f1->Get("myTree");
  
  TFile * fEff;
  if ( isPrompt) fEff = new TFile("EffAna_PRMC_boosted.root");
  else           fEff = new TFile("EffAna_NPMC_boosted.root");

  TH1D* hEff[10];
  hEff[0] = (TH1D*)fEff->Get(Form("h1D_EffDimu_pt_bin_%s",direction.Data()));
  hEff[1] = (TH1D*)fEff->Get(Form("h1D_EffDimu_pt_bin_%s_trig",direction.Data()));
  hEff[2] = (TH1D*)fEff->Get(Form("h1D_EffDimu_pt_bin_%s_mupl",direction.Data()));
  hEff[3] = (TH1D*)fEff->Get(Form("h1D_EffDimu_pt_bin_%s_mumi",direction.Data()));
  hEff[4] = (TH1D*)fEff->Get(Form("h1D_EffDimu_pt_bin_%s_jpsi",direction.Data()));
  hEff[5] = (TH1D*)fEff->Get(Form("h1D_EffDimu_pt_bin_%s_mass",direction.Data()));
  cout << "///////////////////////////////////////////////////////////////////////" << endl;
  cout << " Acceptance is calculated by YONGSUN's code not from Hyunchul's code" << endl;
  cout << "///////////////////////////////////////////////////////////////////////" << endl;
  TH1D* hAcc  = (TH1D*)fEff->Get(Form("h1D_Acc_pt_bin_%s",direction.Data()));
  
  
  for ( int i=0 ; i<=5 ;i++) {
    handsomeTH1(hEff[i],i+1);
  }

  /*
  TFile * fAcc;
  if ( isPrompt) fAcc = new TFile("AccAna_20131219_PromptJpsi_boosted_binCode_1.root");
  else fAcc = new TFile("AccAna_20131219_PromptJpsi_boosted_binCode_1.root");
  
  TH1D* hAcc  = (TH1D*)fAcc->Get(Form("h1D_Acc_pt_bin2_%s_20131219",direction.Data()));
  */
  
  TCanvas* c0 = new TCanvas("c0","",1000,500);
  c0->Divide(2,1);
  c0->cd(1);
  hEff[0]->SetXTitle("p_{T} (GeV)");
  hEff[0]->SetYTitle("Efficiency");
  hEff[0]->SetAxisRange(0,1.1,"Y");
  hEff[0]->Draw();
  for (int i=1; i<=4 ;i++) {
    hEff[i]->Draw("same");
  }
  jumSun(6.5,1,30,1);
  
  c0->cd(2);

  handsomeTH1(hAcc,1);
  hAcc->SetXTitle("p_{T} (GeV)");
  hAcc->SetYTitle("Acceptance");
 
  hAcc->SetAxisRange(0,1.1,"Y");
  hAcc->Draw();
  jumSun(6.5,1,30,1);
  

  TCanvas* c1 = new TCanvas("c1","",500,500);
  c1->cd();

  double ptBin[] = {6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 13.0, 16.0, 20.0, 30.0};
  const int nPtBin = sizeof(ptBin)/sizeof(double) - 1;
  TH1D* hptGen = new TH1D("hptGen",";J/psi p_{T} (GeV)",nPtBin,ptBin);
  TH1D* hptReco = (TH1D*)hptGen->Clone("hptReco");

  // Cuts
  TCut genRapCut, recoRapCut; 
  if (isFW) {
    genRapCut = "(Gen_QQ_4mom[0].Rapidity()>-2.4) && (Gen_QQ_4mom[0].Rapidity()<-.47)";
    recoRapCut = "(Reco_QQ_4mom[0].Rapidity()>-2.4) && (Reco_QQ_4mom[0].Rapidity()<-.47) &&  (Reco_QQ_mupl_4mom[0].Rapidity()>-2.4) && (Reco_QQ_mupl_4mom[0].Rapidity()<-.47) && (Reco_QQ_mumi_4mom[0].Rapidity()>-2.4) && (Reco_QQ_mumi_4mom[0].Rapidity()<-.47) && (Reco_QQ_trig&1)==1"; 
  }
  else {
    genRapCut = "Gen_QQ_4mom[0].Rapidity()>-.47 && Gen_QQ_4mom[0].Rapidity()<1.47";
    recoRapCut = "(Reco_QQ_4mom[0].Rapidity()>-.47) && (Reco_QQ_4mom[0].Rapidity()<1.47) && (Reco_QQ_mupl_4mom[0].Rapidity()>-.47 && Reco_QQ_mupl_4mom[0].Rapidity()<1.47) && (Reco_QQ_mumi_4mom[0].Rapidity()>-.47 && Reco_QQ_mumi_4mom[0].Rapidity()<1.47) && (Reco_QQ_trig&1)==1";
  }
  TCut recoMassCut = "Reco_QQ_4mom[0].M()>2.95 && Reco_QQ_4mom[0].M()<3.25";
  TCut recoAccCutPlus  = ""; //" Reco_QQ_mupl_4mom[0].Eta()>-2.4 && Reco_QQ_mupl_4mom[0].Eta()<1.47 &&   (  ( abs(Reco_QQ_mupl_4mom[0].Eta())>2.2 && abs(Reco_QQ_mupl_4mom[0].Eta())<2.4 && Reco_QQ_mupl_4mom[0].Pt()>0.8 )   || ( abs(Reco_QQ_mupl_4mom[0].Eta())>1.3 && abs(Reco_QQ_mupl_4mom[0].Eta())<=2.2 && Reco_QQ_mupl_4mom[0].P()>2.9 )  || ( abs(Reco_QQ_mupl_4mom[0].Eta())<=1.3 && Reco_QQ_mupl_4mom[0].Pt()>3.3 ) )";
  TCut recoAccCutMinus  = ""; //" Reco_QQ_mumi_4mom[0].Eta()>-2.4 && Reco_QQ_mumi_4mom[0].Eta()<1.47 &&   (  ( abs(Reco_QQ_mumi_4mom[0].Eta())>2.2 && abs(Reco_QQ_mumi_4mom[0].Eta())<2.4 && Reco_QQ_mumi_4mom[0].Pt()>0.8 )   || ( abs(Reco_QQ_mumi_4mom[0].Eta())>1.3 && abs(Reco_QQ_mumi_4mom[0].Eta())<=2.2 && Reco_QQ_mumi_4mom[0].P()>2.9 )  || ( abs(Reco_QQ_mumi_4mom[0].Eta())<=1.3 && Reco_QQ_mumi_4mom[0].Pt()>3.3 ) )";
  TCut recoAccCut = recoAccCutPlus && recoAccCutMinus;
  
  Long64_t nEntry = 100000000;
  mytree->Draw(Form("Gen_QQ_4mom[0].Pt()>>%s",hptGen->GetName()), genRapCut, "",nEntry);
  mytree->Draw(Form("Reco_QQ_4mom[0].Pt()>>%s",hptReco->GetName()), recoRapCut && recoMassCut && recoAccCut, "",nEntry);

  TH1D* hptRecoCorr = (TH1D*)hptReco->Clone("hptRecoCorr");
  hptRecoCorr->Divide(hEff[0]);
  hptRecoCorr->Divide(hAcc);
  

  handsomeTH1(hptGen,1);
  hptGen->SetAxisRange(1,1.5e5,"Y");
  
  hptGen->Draw("hist");
  handsomeTH1(hptReco,2);
  hptReco->SetMarkerStyle(24);
  hptReco->Draw("same");
  handsomeTH1(hptRecoCorr,2);
  hptRecoCorr->Draw("same");
  
  TLegend *l = new TLegend(0.4233871,0.5042373,0.8689516,0.7521186,NULL,"brNDC");
  easyLeg(l,"Yield");
  l->AddEntry(hptGen,"Generated J/#psi","l");
  l->AddEntry(hptReco,"Reco yield","p");
  l->AddEntry(hptRecoCorr,"Reco/(Acc*Eff)","p");
  l->Draw();
}
void finalPlotsGammaTrack () {
  
  TH1D* hDphiF[5][10];
  TH1D* hXawayF[5][10];
  TH1D* hPtAwayF[5][10];

  TFile* inf = new TFile("photonTrackOutput_photonPt50GeV.root");
  for ( int icent =1 ; icent<=nCent_std ; icent++) {
    hXawayF[icent][kHIDATA] = (TH1D*)inf->Get(Form("hidata_icent%d_hTrkXAway_final",icent));
    handsomeTH1(hXawayF[icent][kHIDATA],color[icent]);
    hXawayF[icent][kHIMC] = (TH1D*)inf->Get(Form("himc_icent%d_hTrkXAway_final",icent));
    handsomeTH1(hXawayF[icent][kHIMC],color[icent]);

    TH1ScaleByWidth(hXawayF[icent][kHIDATA]);
    TH1ScaleByWidth(hXawayF[icent][kHIMC]);

  }
  
  TCanvas* c100 = new TCanvas("c100","",1000,500);
  c100->Divide(2,1);
  c100->cd(2);
  TH1D* htemp100 = (TH1D*)hXawayF[1][kHIDATA]->Clone("htemp100");
  htemp100->Reset();
  handsomeTH1(htemp100,1);
  htemp100->SetAxisRange(0.01,1e2,"Y");
  htemp100->SetYTitle("dN_{track}/dx_{T#gamma}   per #gamma");
  htemp100->DrawCopy();
  gPad->SetLogy();
  for ( int icent =1 ; icent<=nCent_std ; icent++) {
    hXawayF[nCent_std+1-icent][kHIDATA]->Draw("same");
  }  
  TLegend* l1 = new TLegend(0.4979083,0.4978381,0.9999163,0.7767209,NULL,"brNDC");
  easyLeg(l1,"");
  for ( int icent = nCent_std ; icent>=1 ; icent--) {
    int lowCent = centBin_std[icent-1];
    int highCent = centBin_std[icent]-1;
    l1->AddEntry(hXawayF[icent][kHIDATA], Form("%.0f%% - %.0f%%", float((float)lowCent*2.5), float((float)(highCent+1)*2.5)));
  } 

  drawText("CMS Preliminary",0.5,0.83,1);
  drawText("PbPb #int L dt = ~150 #mub^{-1}",0.5,0.75,1);
  
  c100->cd(1);
  htemp100->DrawCopy();
  gPad->SetLogy();
  for ( int icent =1 ; icent<=nCent_std ; icent++) {
    hXawayF[nCent_std+1-icent][kHIMC]->Draw("same");
  }
  drawText("MC",0.5,0.83,1);
  drawText("PYTHIA+HYDJET",0.5,0.75,1);
  l1->Draw();

  int percentBin[5] = {0,10,30,50,100};

  TCanvas* c102 = new TCanvas("c102","",1000,350);
  makeMultiPanelCanvas(c102,4,1,0.0,0.0,0.24,0.15,0.02);
  htemp100->SetYTitle("DATA/MC");
  htemp100->SetAxisRange(0,2,"Y");
  htemp100->SetNdivisions(505);
  for ( int icent =1 ; icent<=nCent_std ; icent++) {
    c102->cd(nCent_std+1-icent);
    htemp100->DrawCopy();
    jumSun(0,1,1,1);
    TH1D* tempRatio =  (TH1D*)hXawayF[icent][kHIDATA]->Clone(Form("tempRatio_icent%d",icent));
    tempRatio->Divide(hXawayF[icent][kHIMC]);
    tempRatio->Draw("same");
    if ( icent ==4 ) {
      drawText("CMS Preliminary",0.4,0.91,1,16);
      drawText("PbPb #int L dt = ~150 #mub^{-1}",0.4,0.82,1,16);
    }
    drawText(Form("%d%% - %d%%",percentBin[icent-1],percentBin[icent]),0.4,0.73,1,16);
  }
  
  
}
void drawDphi() { 
  
  TH1D* hdphi[5][5]; // [species][centrality] 
  TH1D* hxjg[5][5]; // [species][centrality] 
  TH1D* hxjgNorm[5][5];
  TFile* fff[5];
  
  fff[kHIDATA] = new TFile("ffFiles/photonTrackCorr_pbpbDATA_output_photonPtThr60_jetPtThr30_20130210_genLevel0.root");
  for ( int iSpecies =0 ; iSpecies<=5 ; iSpecies++) {
    if (iSpecies != kHIDATA)       continue;
    for ( int icent = 1 ; icent<=4 ; icent++) {
      hdphi[iSpecies][icent] = (TH1D*)fff[iSpecies]->Get(Form("jetDphi_icent%d_final",icent));
      hxjg[iSpecies][icent] = (TH1D*)fff[iSpecies]->Get(Form("jetXjg_icent%d_final",icent));
      hxjgNorm[iSpecies][icent] = (TH1D*)hxjg[iSpecies][icent]->Clone(Form("norm_%s",hxjg[iSpecies][icent]->GetName()));
      scaleInt(hxjgNorm[iSpecies][icent]);    
    }}
  
  fff[kHIMC]   = new TFile("ffFiles/photonTrackCorr_pbpbMC_output_photonPtThr60_jetPtThr30_20130210_genLevel0.root"); 
  for ( int iSpecies =0 ; iSpecies<=5 ; iSpecies++) {
    if (iSpecies != kHIMC)         continue;
    for ( int icent = 1 ; icent<=4 ; icent++) {
      hdphi[iSpecies][icent] = (TH1D*)fff[iSpecies]->Get(Form("jetDphi_icent%d_final",icent));
      hxjg[iSpecies][icent] = (TH1D*)fff[iSpecies]->Get(Form("jetXjg_icent%d_final",icent));
      hxjgNorm[iSpecies][icent] = (TH1D*)hxjg[iSpecies][icent]->Clone(Form("norm_%s",hxjg[iSpecies][icent]->GetName()));
      scaleInt(hxjgNorm[iSpecies][icent]);
    }}
  
  
  
  TCanvas* c1 = new TCanvas("c1","",1400,450);
  makeMultiPanelCanvas(c1,4,1,0.0,0.0,0.2,0.15,0.02);
  for ( int icent = 1 ; icent<=4 ; icent++) {
    c1->cd(5-icent);
    handsomeTH1(hdphi[kHIMC][icent],1);
    handsomeTH1(hdphi[kHIDATA][icent],2);
    hdphi[kHIMC][icent]->Scale(1./hdphi[kHIMC][icent]->Integral("width"));
    hdphi[kHIDATA][icent]->Scale(1./hdphi[kHIDATA][icent]->Integral("width"));
    hdphi[kHIMC][icent]->SetAxisRange(3.141592/3.,3.141592,"X");
    hdphi[kHIMC][icent]->SetAxisRange(0.01,5,"Y");
    hdphi[kHIMC][icent]->DrawCopy("hist");
    //  hdphi[kHIDATA][icent]->Draw("same");
    //    gPad->SetLogy();
    
    TF1 *fdphi = new TF1("fdphi","exp(-(TMath::Pi()-x)/[0]) / ([0]*(1-exp(-TMath::Pi()/[0]))) ",2.0*TMath::Pi()/3.0,TMath::Pi());
    fdphi->SetParName(0,"width");
    fdphi->SetParameter("width",0.22);
        
    float fitxmin=3.1415926*2./3;
    //    float fitxmin=2.5;
    hdphi[kHIMC][icent]->Fit("fdphi","0llm","",fitxmin,3.1415926);
    fdphi->SetLineWidth(1);
    fdphi->SetLineStyle(2);
    fdphi->SetLineColor(kBlue);
    float dphiWidth = fdphi->GetParameter("width");
    float dphiWidthErr = fdphi->GetParError(0);
    cout << " dphiWidth,dphiWidthErr = " << dphiWidth <<"   "<< dphiWidthErr << endl;
    fdphi->DrawCopy("same");
  }
  c1->SaveAs("pdfFiles/dPhi_MC_only.pdf");


  TCanvas* c2 = new TCanvas("c2","",1400,450);
  makeMultiPanelCanvas(c2,4,1,0.0,0.0,0.2,0.15,0.02);
  for ( int icent = 1 ; icent<=4 ; icent++) {
    c2->cd(5-icent);
    handsomeTH1(hxjgNorm[kHIMC][icent],1);
    handsomeTH1(hxjgNorm[kHIDATA][icent],2);
    hxjgNorm[kHIMC][icent]->SetAxisRange(-0.01,0.35,"Y");
    hxjgNorm[kHIMC][icent]->DrawCopy("");
    //    hxjgNorm[kHIDATA][5-icent]->Draw("same");
    int lowCent = centBin1[icent-1];    int highCent = centBin1[icent]-1;
    drawText(Form("%.0f%% - %.0f%%", float((float)lowCent*2.5), float((float)(highCent+1)*2.5)), 0.67,0.7,1);
  }
  TLegend *l12 = new TLegend(0.304355,0.755085,.8,0.9552542,NULL,"brNDC");
  easyLeg(l12,"p_{T}^{Jet}/p_{T}^{#gamma}");
  l12->AddEntry(hxjgNorm[kHIMC][1],"PYTHIA+HYDJET","pl");
  c2->cd(1);   l12->Draw();

  c2->SaveAs("pdfFiles/xgj_MC_only.pdf");

  TCanvas* c2MCover = new TCanvas("c2MCover","",500,500);
  bool drawn=false;
  for ( int icent = 1 ; icent<=4 ; icent++) {
    c2MCover->cd(icent);
    handsomeTH1(hxjgNorm[kHIMC][icent],ycolor[icent]);
    hxjgNorm[kHIMC][5-icent]->SetAxisRange(-0.01,0.38,"Y");
    if (drawn)  
      hxjgNorm[kHIMC][5-icent]->Draw("same");
    else       hxjgNorm[kHIMC][5-icent]->Draw("");
    
    
    drawn = true;
  }
  TLegend *l11 = new TLegend(0.1794355,0.7055085,1,0.9152542,NULL,"brNDC");
  easyLeg(l11,"p_{T}^{Jet}/p_{T}^{#gamma} of PYTHIA embedded in"); 
  l11->AddEntry(hxjgNorm[kHIMC][4],"HYDJET 50-100%","p");
  l11->AddEntry(hxjgNorm[kHIMC][3],"HYDJET 30-50%","p");
  l11->AddEntry(hxjgNorm[kHIMC][2],"HYDJET 10-30%","p");
  l11->AddEntry(hxjgNorm[kHIMC][1],"HYDJET 0 -10%","p");
  l11->Draw();
  c2MCover->SaveAs("pdfFiles/xgj_MC_OnePannel.pdf");


  
  TCanvas* c3 = new TCanvas("c3","",500,500);
  TH1D* npartTempHist = new TH1D("meanR",";N_{part}; R",100,0,400);
  
  double npart4[8] = { 43.6661-10, 43.6661+10, 116.36-10, 116.36+10, 235.769-10, 235.769+10, 359.22-10,359.22+10};
  double npart4_2[4] = { 43.6661, 116.36, 235.769, 359.22};
  TGraphAsymmErrors* gR[5];

  for ( int iSpec = 0 ; iSpec<5 ; iSpec++) {
    
    if ( (iSpec != kHIDATA) && (iSpec != kHIMC) )       continue;
    gR[iSpec] = new TGraphAsymmErrors();
    gR[iSpec]->SetName(Form("gR_%d",iSpec));
    for ( int icent =4 ; icent>=1 ; icent--) {
      double theRerror;
      double theR = hxjg[iSpec][icent]->IntegralAndError(1, hxjg[iSpec][5-icent]->GetNbinsX(), theRerror, "width");
      gR[iSpec]->SetPoint(icent, npart4_2[4 - icent], theR );
      gR[iSpec]->SetPointError(icent, 0.001,0.001, theRerror, theRerror);    
    }
  }
  handsomeTH1(npartTempHist,1);
  npartTempHist->SetAxisRange(0.3,1.0,"Y");
  npartTempHist->DrawCopy();
  gR[kHIDATA]->SetMarkerColor(2);
  gR[kHIDATA]->SetLineColor(2);
  gR[kHIMC]->Draw("same p");
  //  gR[kHIDATA]->Draw("same p");

  c3->SaveAs("pdfFiles/r_MC_only.pdf");

  TCanvas* c3a = new TCanvas("c3a","",500,500);
  npartTempHist->DrawCopy();
  gR[kHIMC]->Draw("same p");
  gR[kHIDATA]->Draw("same p");
  TLegend *l13 = new TLegend(0.1794355,0.7055085,1,0.9152542,NULL,"brNDC");
  easyLeg(l13,"R_{J,#gamma}");
  l13->AddEntry(gR[kHIDATA],"PbPb data","pl");
  l13->AddEntry(gR[kHIMC],"PYTHIA+HYDJET","pl");
  l13->Draw();
  c3a->SaveAs("pdfFiles/r_MC_Data.pdf");


  TCanvas* c4 = new TCanvas("c4","",500,500);
  
  TGraphAsymmErrors* gX[5];

  for ( int iSpec = 0 ; iSpec<5 ; iSpec++) {
    
    if ( (iSpec != kHIDATA) && (iSpec != kHIMC) )       continue;
    gX[iSpec] = new TGraphAsymmErrors();
    gX[iSpec]->SetName(Form("gX_%d",iSpec));
    for ( int icent =4 ; icent>=1 ; icent--) {
      double theX      = hxjg[iSpec][icent]->GetMean();
      double theXerror = hxjg[iSpec][icent]->GetMeanError();
      gX[iSpec]->SetPoint(icent, npart4_2[4 - icent], theX );
      gX[iSpec]->SetPointError(icent, 0.001,0.001, theXerror, theXerror);    
    }
  }
  handsomeTH1(npartTempHist,1);
  npartTempHist->SetYTitle("<X_{J,#gamma}>");
  npartTempHist->SetAxisRange(0.6,1.1,"Y");
  npartTempHist->DrawCopy();
  gX[kHIDATA]->SetMarkerColor(2);
  gX[kHIDATA]->SetLineColor(2);
  gX[kHIMC]->Draw("same p");
  //  gX[kHIDATA]->Draw("same p");

  c4->SaveAs("pdfFiles/meanX_MC_only.pdf");


 TCanvas* c4a = new TCanvas("c4a","",500,500);
  
 npartTempHist->DrawCopy();
 gX[kHIMC]->Draw("same p");
 gX[kHIDATA]->Draw("same p");
 TLegend *l14 = new TLegend(0.1794355,0.7055085,1,0.9152542,NULL,"brNDC");
 easyLeg(l14,"<X_{J,#gamma}>");
 l14->AddEntry(gX[kHIDATA],"PbPb data","pl");
 l14->AddEntry(gX[kHIMC],"PYTHIA+HYDJET","pl");
 l14->Draw();
 c4a->SaveAs("pdfFiles/meanX_MC_Data.pdf");




    
}
void drawTrackingClosure()
{
  TCut centCut = "cBin>=0&&cBin<4";
  TCut jetSelCut[2] = {"jetPt>100&&jetPt<300&&jetUnSmPt<100","jetPt>100&&jetPt<300&&jetUnSmPt<100"};
  // TCut jetSelCut[2] = {"jetUnSmPt>100&&jetUnSmPt<300","jetUnSmPt>100&&jetUnSmPt<300"};
  TString jetAlias[2] = {"jetPt","jetPt"};
  // TString jetAlias[2] = {"jetUnSmPt","jetUnSmPt"};

  multiTreeUtil vmt[2];

  // Mar 04
  // hi
  vmt[0].addFile("../ntout/jskim_hydj80_akPu3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut[0] && centCut && "pthat>=80&&pthat<100",9.913e-5*1.e9);
  vmt[0].addFile("../ntout/jskim_hydj100_akPu3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut[0] && centCut && "pthat>=100&&pthat<170",3.069e-5*1.e9);
  vmt[0].addFile("../ntout/jskim_hydj170_akPu3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut[0] && centCut && "pthat>=170&&pthat<9999",1.470e-6*1.e9);
  vmt[1].addFile("../ntout/jskim_hydj80_akPu3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut[1] && centCut && "pthat>=80&&pthat<100",9.913e-5*1.e9);
  vmt[1].addFile("../ntout/jskim_hydj100_akPu3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut[1] && centCut && "pthat>=100&&pthat<170",3.069e-5*1.e9);
  vmt[1].addFile("../ntout/jskim_hydj170_akPu3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut[1] && centCut && "pthat>=170&&pthat<9999",1.470e-6*1.e9);
  // pp
  // vmt[0].addFile("../ntout/jskim_dj80_ak3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin1_ak3PF_gj0.root", "tdj", jetSelCut[0] && "pthat>=80&&pthat<120",9.913e-5*1.e9);
  // vmt[0].addFile("../ntout/jskim_dj120_ak3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin1_ak3PF_gj0.root", "tdj", jetSelCut[0] && "pthat>=120&&pthat<170",1.128e-5*1.e9);
  // vmt[0].addFile("../ntout/jskim_dj170_ak3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin1_ak3PF_gj0.root", "tdj", jetSelCut[0] && "pthat>=170&&pthat<9999",1.470e-6*1.e9);
  // vmt[1].addFile("../ntout/jskim_dj80_ak3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin1_ak3PF_gj0.root", "tdj", jetSelCut[1] && "pthat>=80&&pthat<120",9.913e-5*1.e9);
  // vmt[1].addFile("../ntout/jskim_dj120_ak3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin1_ak3PF_gj0.root", "tdj", jetSelCut[1] && "pthat>=120&&pthat<170",1.128e-5*1.e9);
  // vmt[1].addFile("../ntout/jskim_dj170_ak3PF_Mar04job0_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin1_ak3PF_gj0.root", "tdj", jetSelCut[1] && "pthat>=170&&pthat<9999",1.470e-6*1.e9);

  for (int i=0; i<2; ++i) {
    vmt[i].NormalizeScales(2,"","hEvtCentNoSkim");
  }

  TString annotation="#DeltaR<0.3";
  TString tag="hiMar04job0trkcorr14d_dr3_limcorr_unsmptlt100";
  // TString tag="ppMar04job0trkcorr14d_dr3_limcorr_sm2bin1";

  for (int i=0; i<2; ++i) {
    vmt[i].AddFriend("yTrk=yongsunTrack");
    vmt[i].AddFriend("genPar");
    vmt[i].SetAlias("finalJetPt",jetAlias[i]);
    cout << "(input " << i << ") finalJetPt = " << vmt[i].trees_[0]->GetAlias("finalJetPt") << endl;
  }

  TFile * ouf = new TFile("hists.root","recreate");

  // Draw jet
  // TCut jetCut="abs(jetEta)<2";
  TCut jetCut="abs(jetEta)<2&&abs(jetEta)>0.3";
  TH1D * hJetPt[2];
  for (int i=0; i<2; ++i) {
    hJetPt[i] = new TH1D(Form("hJetPt_%d",i),";Jet p_{T} (GeV/c);",20,0,400);
    vmt[i].Draw(hJetPt[i],"finalJetPt",jetCut,"1");
  }

  // Check Normalization
  TCanvas * c0 = new TCanvas("c0","c0",805,0,800,400);
  c0->Divide(2,1);
  c0->cd(1);
  gPad->SetLogy();
  cleverRange(hJetPt[0],hJetPt[1],5);
  handsomeTH1(hJetPt[0],kBlack);
  handsomeTH1(hJetPt[1],kRed);
  hJetPt[0]->SetYTitle("# of Jets");
  hJetPt[0]->DrawCopy("E");
  hJetPt[1]->DrawCopy("same hist");
  c0->cd(2);
  TH1D * hJetPtUnNormRat = (TH1D*)hJetPt[0]->Clone(Form("%s_unnormrat",hJetPt[0]->GetName()));
  hJetPtUnNormRat->Divide(hJetPt[1]);
  hJetPtUnNormRat->SetAxisRange(0,2,"Y");
  hJetPtUnNormRat->Draw("E");
  jumSun(0,1,400,1);

  // Normalization
  float nJet[2] = {0,0};
  for (int i=0; i<2; ++i) {
    nJet[i] = hJetPt[i]->Integral();
    cout << "(input " << i << ") nJet = " << nJet[i] << endl;
  }

  // Draw Trk
  float xminpt=1, xmaxpt=119;
  TString trkVar[2]={"yTrk.pt","genPar.pt"};
  TString xiVar[2]={"log(finalJetPt/yTrk.pt)","log(finalJetPt/genPar.pt)"};
  // TCut trkCut[2]={
  //   "yTrk.jetMatch==1 && yTrk.jetDr<0.30 && yTrk.pt>1.00 && yTrk.pt<300.00 && yTrk.trkWeight<10",
  //   "abs(genPar.chg)>0 && genPar.jetMatch==1 && genPar.jetDr<0.30 && genPar.pt>1.00 && genPar.pt<300.00"
  // };
  // Signal Cone
  TCut trkCut[2]={"yTrk.jetMatch==1&&yTrk.jetDr<0.30","abs(genPar.chg)>0 && genPar.jetMatch==1 && genPar.jetDr<0.30"};
  // Bkg Cone
  // TCut trkCut[2]={"yTrk.jetMatch==-1&&yTrk.jetDr<0.30","abs(genPar.chg)>0 && genPar.jetMatch==-1 && genPar.jetDr<0.30"};
  // trkCut[1]=trkCut[1]&&"genPar.sube==0";
  // TString trkWeight[2]={"(yTrk.trkWeight)","1"};
  // TString trkWeight[2]={"((yTrk.trkWeight)*(1-yTrk.jetDr/0.3*0.08*(yTrk.jetDr<0.3)))","1"};
  TString trkWeight[2]={"(yTrk.trkWeight*(yTrk.trkWeight<10)+1.47*(yTrk.trkWeight>=10))","1"};
  TH1D * hTrkPt[2], * hXi[2];
  for (int i=0; i<2; ++i) {
    hTrkPt[i] = new TH1D(Form("hTrkPt_%d",i),";Track p_{T} (GeV/c);",nPtBin,ptBin);
    vmt[i].Draw(hTrkPt[i],trkVar[i],jetCut&&trkCut[i],trkWeight[i]);
    hXi[i] = new TH1D(Form("hXi_%d",i),";#xi = ln(1/z);",16,-1,7);
    vmt[i].Draw(hXi[i],xiVar[i],jetCut&&trkCut[i],trkWeight[i]);
  }

  // Normalize
  for (int i=0; i<2; ++i) {
    hJetPt[i]->Scale(1./nJet[i]);
    hJetPt[i]->SetYTitle("Jet Fraction");
    normHist(hTrkPt[i],0,true,1./nJet[i]);
    normHist(hXi[i],0,true,1./nJet[i]);
  }

  /////////////////////////////////////
  // Draw Jet
  /////////////////////////////////////
  TCanvas * c2 = new TCanvas("c2","c2",805,425,800,400);
  c2->Divide(2,1);
  c2->cd(1);
  gPad->SetLogy();
  hJetPt[0]->Draw("E");
  hJetPt[1]->Draw("same hist");
  c2->cd(2);
  TH1D * hJetPtRat = (TH1D*)hJetPt[0]->Clone(Form("%s_rat",hJetPt[0]->GetName()));
  hJetPtRat->Divide(hJetPt[1]);
  hJetPtRat->SetAxisRange(0,2,"Y");
  hJetPtRat->Draw("E");
  jumSun(0,1,400,1);

  /////////////////////////////////////
  // Draw Track Pt
  /////////////////////////////////////
  TCanvas * c3 = new TCanvas("c3","c3",10,0,800,400);
  c3->Divide(2,1);
  c3->cd(1);
  gPad->SetLogy();
  gPad->SetLogx();
  handsomeTH1(hTrkPt[0],kBlack);
  handsomeTH1(hTrkPt[1],kRed);
  hTrkPt[0]->SetTitle(";p_{T}^{ Track} (GeV/c);1/N_{ jet} dN_{ Track} /dp_{T}");
  hTrkPt[0]->Draw("E");
  hTrkPt[1]->Draw("same hist");

  TLegend * l1 = new TLegend(0.35,0.19,0.78,0.40,NULL,"brNDC");
  easyLeg(l1,"",20);
  l1->AddEntry(hTrkPt[0],annotation,"");
  l1->AddEntry(hTrkPt[0],"Rec. Tracks","p");
  l1->AddEntry(hTrkPt[1],"Gen. Partls","l");
  l1->Draw();

  c3->cd(2);
  gPad->SetLogx();
  TH1D * hTrkPtRat = (TH1D*)hTrkPt[0]->Clone(Form("%s_rat",hTrkPt[0]->GetName()));
  hTrkPtRat->Divide(hTrkPt[1]);
  hTrkPtRat->SetAxisRange(xminpt,xmaxpt,"X");
  hTrkPtRat->SetAxisRange(0.5,1.5,"Y");
  hTrkPtRat->SetYTitle("Ratio");
  hTrkPtRat->Draw("E");
  jumSun(xminpt,1,xmaxpt,1,kRed);
  c3->Print(Form("closure/trackingClosure_pt_%s.gif",tag.Data()));
  c3->Print(Form("closure/trackingClosure_pt_%s.pdf",tag.Data()));

  /////////////////////////////////////
  // Draw Xi
  /////////////////////////////////////
  TCanvas * c5 = new TCanvas("c5","c5",10,425,800,400);
  c5->Divide(2,1);
  c5->cd(1);
  gPad->SetLogy();
  handsomeTH1(hXi[0],kBlack);
  handsomeTH1(hXi[1],kRed);
  hXi[0]->SetTitle(";#xi = ln(1/z);1/N_{ jet} dN_{ track} /d#xi");
  hXi[0]->Draw("E");
  hXi[1]->Draw("same hist");
  l1->Draw();
  c5->cd(2);
  TH1D * hXiRat = (TH1D*)hXi[0]->Clone(Form("%s_rat",hXi[0]->GetName()));
  hXiRat->Divide(hXi[1]);
  hXiRat->SetAxisRange(0.5,1.5,"Y");
  hXiRat->SetYTitle("Ratio");
  hXiRat->Draw("E");
  jumSun(0,1,6,1,kRed);
  c5->Print(Form("closure/trackingClosure_xi_%s.gif",tag.Data()));
  c5->Print(Form("closure/trackingClosure_xi_%s.pdf",tag.Data()));
}
Exemple #18
0
void drawSingleVariable(TH1D* theHist, int lowCent, int highCent, TString variable1, TCut addCut1, TString variable2, TCut addCut2, int normChoice,bool overDraw, TH1D* theMCSig) { 
   theHist->Reset();   
   if (addCut2 =="")  
      addCut2 = addCut1;
   if (variable2 =="")
      variable2 = variable1;

   cout << "addCut2 = " << addCut2.GetTitle() << endl;
   cout << "variable2 = "<< variable2 << endl;

   TString fname1 = "rootFiles/barrelHiForestPhoton35_Skim2011-Dec04-withTracks.root";//barrelHiForestPhoton35_Skim2011-v2.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());

   TString fname2 = "rootFiles/barrelHiForestPhoton35_Skim2010.root";
   TFile *f2  =new TFile(fname2.Data());
   TTree *photon2 = (TTree*)f2->Get("yongsunPhotonTree");
   //  photon2->AddFriend("yEvt=yongsunHiEvt"    ,fname2.Data());
   photon2->AddFriend("yskim=yongsunSkimTree"   ,fname2.Data());
   photon2->AddFriend("yhlt=yongsunHltTree"     ,fname2.Data());
   
   TString fnameMC ;
   TFile *fMC;
   TTree *photonSig;
   if ( theMCSig){ 
      fnameMC = "rootFiles/barrelHiForestPhoton35_MCPhoton50_25k.root";
      fMC  =new TFile(fnameMC.Data());
      photonSig = (TTree*)fMC->Get("yongsunPhotonTree");
      photonSig->AddFriend("yEvt=yongsunHiEvt"    ,fnameMC.Data());
      cout << " MC is running " << endl;
   }
   //   photonSig->AddFriend("yskim=yongsunSkimTree"   ,fnameMC.Data());
   //  photonSig->AddFriend("yhlt=yongsunHltTree"     ,fnameMC.Data());
   
   //genMatchCut1 
   TCut collisionCut = "yskim.pcollisionEventSelection==1";
   
   TCut runCut1       = ""; //"yhlt.Run>= 181985 && yhlt.Run <=182099"; 
   
   TCut centCut1     = Form("(yEvt.hiBin >= %d) && (yEvt.hiBin<= %d)",lowCent,highCent);
   TCut centCut2     = Form("(cBin >= %d) && (cBin <= %d)",lowCent,highCent);
   
   TCut spikeCut1     = "abs(seedTime)<4 && swissCrx<0.90 && sigmaIetaIeta>0.002";
   TCut spikeCut2   = "abs(seedTime)<4 && (1 - (eRight+eLeft+eTop+eBottom)/eMax)<0.90 && sigmaIetaIeta>0.002";
   TCut spikeCutSig = "swissCrx<0.90 && sigmaIetaIeta>0.002";

   TCut nonElectron = "!isEle";
   
   TCut hltCut1       = "yhlt.HLT_HISinglePhoton30_v2==1"; // 181695 => H/E cut is removed from L1
   TCut hltCut2       = "yhlt.HLT_HIPhoton30==1";
      
   TCut basicCut1       = collisionCut && nonElectron && etaCut && spikeCut1 && centCut1 && runCut1 && hltCut1;
   TCut basicCut2       = collisionCut && nonElectron && etaCut && spikeCut2 && centCut2; //&& hltCut2;
   TCut basicCutSig     =                 nonElectron && etaCut && spikeCutSig && centCut1;
   
   
   TCut finalCut1     = basicCut1   && addCut1;
   TCut finalCut2     = basicCut2   && addCut2;
   TCut finalCutSig   = basicCutSig && addCut1 && genMatchCut1;
   
   TH1D* tempHist1 = (TH1D*)theHist->Clone("tempHist1");
   TH1D* tempHist2 = (TH1D*)theHist->Clone("tempHist2");
   TH1D* tempHistSig = (TH1D*)theHist->Clone("tempHistSig");
   
   
   photon1->Draw(Form("%s>>%s",variable1.Data(),tempHist1->GetName()),finalCut1);
   photon2->Draw(Form("%s>>%s",variable2.Data(),tempHist2->GetName()),finalCut2);
   if ( theMCSig) {
      photonSig->Draw(Form("%s>>%s",variable1.Data(),tempHistSig->GetName()),  Form("(%s)*ncoll",finalCutSig.GetTitle()));
      cout << " mc cut = " << finalCutSig.GetTitle() << endl;
   }

   tempHist1->Sumw2();
   tempHist2->Sumw2();
   if ( theMCSig)
      tempHistSig->Sumw2();
   
   handsomeTH1(tempHist1,2);
   handsomeTH1(tempHist2,1);
   tempHist2->SetMarkerStyle(24);
   if ( normChoice == 0) {
      scaleInt(tempHist1);
      scaleInt(tempHist2);
   }
   if ( normChoice == 1) {
      double nEvents1 = photon1->GetEntries("leading==1" && basicCut1 && "pt>40 && hadronicOverEm<0.2");
      double nEvents2 = photon2->GetEntries("leading==1" && basicCut2 && "pt>40 && hadronicOverEm<0.2");
      tempHist1->Scale(1./nEvents1);
      tempHist2->Scale(1./nEvents2);
      cout <<" this file is<<" << nEvents1/nEvents2 * 6.7 << "micro barn" << endl;
   }
   if ( normChoice == 2) {
      double nLumi1 = 17.4   ; //microb^-1
      double nLumi2 = 7.0  ;
      tempHist1->Scale(1./nLumi1);
      tempHist2->Scale(1./nLumi2);
   }
   
   cleverRange(tempHist2,1.5);
   if ( overDraw) 
      tempHist2->DrawCopy("same");//hist");
   else 
      tempHist2->DrawCopy("");//hist");                                                                                                  

   tempHist1->DrawCopy("same");
   
   TLegend* leg1 =  new TLegend(0.4012097,0.7584746,1,0.9300847,NULL,"brNDC");
   easyLeg(leg1,"");
   leg1->AddEntry(tempHist2,"2010 PbPb, 6.8 #mub^{-1}","pl");
   leg1->AddEntry(tempHist1,"2011 PbPb, 84  #mub^{-1}","pl");
   leg1->Draw();
   theHist->Reset();
   theHist->Add(tempHist1);
   if ( theMCSig)
      theMCSig->Add(tempHistSig);
   
}
void drawPtDependenceOfDpt(bool drawPbPb=1, int xNorm = 1) {
  gStyle -> SetOptStat(0);  
  const int nPtBin = 5;
  double ptBin[nPtBin+1] = {40, 50,60,80,120,9999}; 
  double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 150, 9999};
  
  TH1D* hxjg[7][1000]; // [species][centrality] 
  TH1D* hxjgNorm[7][1000];
  TH1D* hdpt[7][1000];
  TH1D* hdptNorm[7][1000];
  TH1D* hdphi[7][1000];
  
  valPair meanX[7][1000];
  valPair meanDpt[7][1000];
  valPair rjg[7][1000];
  TGraphAsymmErrors* gr[7];
  TGraphAsymmErrors* gx[7];
  TGraphAsymmErrors* gdpt[7];
  for (int i=0;i<7;i++) {  
    gr[i] = new TGraphAsymmErrors();
    gr[i]->SetName(Form("gr_%d",i));
    gx[i] = new TGraphAsymmErrors();
    gx[i]->SetName(Form("gx_%d",i));
    gdpt[i] = new TGraphAsymmErrors();
    gdpt[i]->SetName(Form("gdpt_%d",i));
  }
  TFile* fff[7][1000];
  
  for ( int ipt = 0 ; ipt<nPtBin  ; ipt++) { 
    for ( int iSpecies=0 ; iSpecies<=5 ; iSpecies++){ 
      if (  (iSpecies!=kPPDATA)&&(iSpecies!=kHIDATA) ) 
	continue;
      
      int iglb = ipt + iSpecies*50.;
      int icent = -1;
      
      if ( iSpecies == kPPDATA) { 
        icent = 7;
	fff[iSpecies][iglb] = new TFile(Form("photonTrackCorr_ppDATA_output_photonPtThr%d_to_%d_jetPtThr30_20130816.root",(int)ptBin[ipt],(int)ptBin[ipt+1]));
      }
      if ( iSpecies == kHIDATA) { 
	icent = 10030;
	//	icent = 13099;
	fff[iSpecies][iglb] = new TFile(Form("photonTrackCorr_pbpbDATA_output_photonPtThr%d_to_%d_jetPtThr30_20130816.root",(int)ptBin[ipt],(int)ptBin[ipt+1]));
      }
  cout << "hdphi" << endl;     
      hdphi[iSpecies][iglb] = (TH1D*)fff[iSpecies][iglb]->Get(Form("jetDphi_icent%d_final",icent));
      
      hxjg[iSpecies][iglb] = (TH1D*)fff[iSpecies][iglb]->Get(Form("xjg_icent%d_final",icent));
      hxjgNorm[iSpecies][iglb] = (TH1D*)hxjg[iSpecies][iglb]->Clone(Form("norm_%s",hxjg[iSpecies][iglb]->GetName()) );
      meanX[iSpecies][iglb].val = hxjg[iSpecies][iglb]->GetMean();
      meanX[iSpecies][iglb].err = hxjg[iSpecies][iglb]->GetMeanError();
      gx[iSpecies]->SetPoint     (ipt+1, AvePtBin[ipt], meanX[iSpecies][iglb].val);
      gx[iSpecies]->SetPointError(ipt+1, 0.001,0.001, meanX[iSpecies][iglb].err, meanX[iSpecies][iglb].err);

      hdpt[iSpecies][iglb] = (TH1D*)fff[iSpecies][iglb]->Get(Form("dpt_icent%d_final",icent));
      hdptNorm[iSpecies][iglb] = (TH1D*)hdpt[iSpecies][iglb]->Clone(Form("norm_%s",hdpt[iSpecies][iglb]->GetName()) );
      meanDpt[iSpecies][iglb].val = hdpt[iSpecies][iglb]->GetMean();
      meanDpt[iSpecies][iglb].err = hdpt[iSpecies][iglb]->GetMeanError();
      gdpt[iSpecies]->SetPoint     (ipt+1, AvePtBin[ipt], meanDpt[iSpecies][iglb].val);
      gdpt[iSpecies]->SetPointError(ipt+1, 0.001,0.001, meanDpt[iSpecies][iglb].err, meanDpt[iSpecies][iglb].err);

cout << "rError" << endl;      
      double rError;
      rjg[iSpecies][iglb].val = hxjg[iSpecies][iglb]->IntegralAndError(1, hxjg[iSpecies][iglb]->GetNbinsX(), rError, "width");
      rjg[iSpecies][iglb].err = rError;
      gr[iSpecies]->SetPoint     (ipt+1, AvePtBin[ipt], rjg[iSpecies][iglb].val);
      gr[iSpecies]->SetPointError(ipt+1, 0.001,0.001, rjg[iSpecies][iglb].err, rjg[iSpecies][iglb].err);

      
    }
  }
  
  cout << "finish!"<< endl; 
  //
  //for PbPb 30-100 % !!
  //
  for ( int ipt = 0 ; ipt<nPtBin  ; ipt++) { 
      cout << "in the for loop  " << endl;
      int iSpecies=6;
      int iglb = ipt + iSpecies*50.;
      int icent = 13099;
      fff[iSpecies][iglb] = new TFile(Form("photonTrackCorr_pbpbDATA_output_photonPtThr%d_to_%d_jetPtThr30_20130816.root",(int)ptBin[ipt],(int)ptBin[ipt+1]));
      hdphi[iSpecies][iglb] = (TH1D*)fff[iSpecies][iglb]->Get(Form("jetDphi_icent%d_final",icent));

      hxjg[iSpecies][iglb] = (TH1D*)fff[iSpecies][iglb]->Get(Form("xjg_icent%d_final",icent));
      hxjgNorm[iSpecies][iglb] = (TH1D*)hxjg[iSpecies][iglb]->Clone(Form("norm_%s",hxjg[iSpecies][iglb]->GetName()) );
      meanX[iSpecies][iglb].val = hxjg[iSpecies][iglb]->GetMean();
      meanX[iSpecies][iglb].err = hxjg[iSpecies][iglb]->GetMeanError();
      gx[iSpecies]->SetPoint     (ipt+1, AvePtBin[ipt], meanX[iSpecies][iglb].val);
      gx[iSpecies]->SetPointError(ipt+1, 0.001,0.001, meanX[iSpecies][iglb].err, meanX[iSpecies][iglb].err);

      hdpt[iSpecies][iglb] = (TH1D*)fff[iSpecies][iglb]->Get(Form("dpt_icent%d_final",icent));
      hdptNorm[iSpecies][iglb] = (TH1D*)hdpt[iSpecies][iglb]->Clone(Form("norm_%s",hdpt[iSpecies][iglb]->GetName()) );
      meanDpt[iSpecies][iglb].val = hdpt[iSpecies][iglb]->GetMean();
      meanDpt[iSpecies][iglb].err = hdpt[iSpecies][iglb]->GetMeanError();
      gdpt[iSpecies]->SetPoint     (ipt+1, AvePtBin[ipt], meanDpt[iSpecies][iglb].val);
      gdpt[iSpecies]->SetPointError(ipt+1, 0.001,0.001, meanDpt[iSpecies][iglb].err, meanDpt[iSpecies][iglb].err);

      double rError;
      rjg[iSpecies][iglb].val = hxjg[iSpecies][iglb]->IntegralAndError(1, hxjg[iSpecies][iglb]->GetNbinsX(), rError, "width");
      rjg[iSpecies][iglb].err = rError;
      gr[iSpecies]->SetPoint     (ipt+1, AvePtBin[ipt], rjg[iSpecies][iglb].val);
      gr[iSpecies]->SetPointError(ipt+1, 0.001,0.001, rjg[iSpecies][iglb].err, rjg[iSpecies][iglb].err);
  }

            
 

  TCanvas* c1 = new TCanvas("c1","",900,350);
  makeMultiPanelCanvas(c1,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 0 ; ipt<nPtBin  ; ipt++) {
    
    
    c1->cd(ipt+1);
    
    int iSpecies = kPPDATA;
    int iglb = ipt + iSpecies*50.;
    handsomeTH1(hdptNorm[iSpecies][iglb],1);
    if (xNorm==1) scaleInt(hdptNorm[iSpecies][iglb]);
    hdptNorm[iSpecies][iglb]->SetXTitle("x_{J,#gamma}");
    hdptNorm[iSpecies][iglb]->SetYTitle("#frac{dN}{dx} #frac{1}{N}");
    hdptNorm[iSpecies][iglb]->SetAxisRange(-100,100,"X");
    if (xNorm==1)     hdptNorm[iSpecies][iglb]->SetAxisRange(-.03,.6,"Y");
    else              hdptNorm[iSpecies][iglb]->SetAxisRange(-.03,.6,"Y");
    hdptNorm[iSpecies][iglb]->SetMarkerStyle(24);
    hdptNorm[iSpecies][iglb]->Draw();

    iSpecies = kHIDATA;
    iglb = ipt + iSpecies*50.;
    if (xNorm==1)  scaleInt(hdptNorm[iSpecies][iglb]);
    handsomeTH1(hdptNorm[iSpecies][iglb],2);
    if (drawPbPb) hdptNorm[iSpecies][iglb]->Draw("same");
    
    //for PbPb 30-100 % !! 
    iSpecies = 6;
    iglb = ipt + iSpecies*50.;
    if (xNorm==1)  scaleInt(hdptNorm[iSpecies][iglb]);
    handsomeTH1(hdptNorm[iSpecies][iglb],2);
    hdptNorm[iSpecies][iglb] -> SetMarkerStyle(24);

    if (drawPbPb) hdptNorm[iSpecies][iglb]->Draw("same");
    //    onSun(0,0,2,0);

    //    onSun(meanX[iSpecies][iglb].val - meanX[iSpecies][iglb].err, 0, meanX[iSpecies][iglb].val+meanX[iSpecies][iglb].err,0,ycolor[ipt+1],2);

    float dx1;    
    (ipt==0)? dx1=0.15 : dx1=0 ;
    
    if ( ipt == nPtBin-1 ) 
      drawText(Form("p_{T}^{#gamma} > %dGeV,   p_{T}^{jet}>30GeV", (int)ptBin[ipt]), 0.12+dx1+0.25,0.889118,1,15);
    else 
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV,   p_{T}^{jet}>30GeV", (int)ptBin[ipt], (int)ptBin[ipt+1]), 0.12+dx1,0.889118,1,15);

      
    TLegend *l1 = new TLegend(0.6365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");
    easyLeg(l1,"2.76TeV");
    l1->AddEntry(hdptNorm[kPPDATA][ipt + kPPDATA*50],"pp ","p");
    if (drawPbPb)    l1->AddEntry(hdptNorm[kHIDATA][iglb],"PbPb 0-30%","p");
    if (drawPbPb)    l1->AddEntry(hdptNorm[6][iglb],"PbPb 30-100%","p");
    if ( ipt==0 )   l1->Draw();

  }
  //  c1->SaveAs(Form("gifs/dpt_ptDependence_drawPbPb%d_norm%d.pdf",drawPbPb,xNorm));

  TCanvas* cDphi = new TCanvas("cDphi","",900,350);
  makeMultiPanelCanvas(cDphi,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 0 ; ipt<nPtBin  ; ipt++) {
    cDphi->cd(ipt+1);
    
    int iSpecies = kPPDATA;
    int iglb = ipt + iSpecies*50.;
    handsomeTH1(hdphi[iSpecies][iglb],1);
    hdphi[iSpecies][iglb]->SetYTitle("x_{J,#gamma}");
    hdphi[iSpecies][iglb]->SetXTitle("#Delta#phi_{J,#gamma}");
    hdphi[iSpecies][iglb]->Scale(1./hdphi[iSpecies][iglb]->Integral("width"));
    hdphi[iSpecies][iglb]->SetAxisRange(0.01,30,"Y");
    hdphi[iSpecies][iglb]->SetMarkerStyle(24);
    hdphi[iSpecies][iglb]->Draw();

    iSpecies = kHIDATA;
    iglb = ipt + iSpecies*50.;
    hdphi[iSpecies][iglb]->Scale(1./hdphi[iSpecies][iglb]->Integral("width"));
    handsomeTH1(hdphi[iSpecies][iglb],2);
    if (drawPbPb)     hdphi[iSpecies][iglb]->Draw("same");
    
    // for PbPb 30-100% !!!
    iSpecies = 6;
    iglb = ipt + iSpecies*50.;
    hdphi[iSpecies][iglb]->Scale(1./hdphi[iSpecies][iglb]->Integral("width"));
    handsomeTH1(hdphi[iSpecies][iglb],2);
    hdphi[iSpecies][iglb] -> SetMarkerStyle(24);
    if (drawPbPb)     hdphi[iSpecies][iglb]->Draw("same");
    
    gPad->SetLogy();
    float dx1;    
    (ipt==0)? dx1=0.15 : dx1=0 ;
    
    if ( ipt == nPtBin-1 ) 
      drawText(Form("%dGeV<p_{T}^{#gamma},   p_{T}^{jet}>30GeV", (int)ptBin[ipt]), 0.15+dx1+0.25,0.889118,1,15);
    else 
      drawText(Form("%dGeV<p_{T}^{#gamma}<%dGeV,   p_{T}^{jet}>30GeV", (int)ptBin[ipt], (int)ptBin[ipt+1]), 0.15+dx1,0.889118,1,15);
    
      
    TLegend *l1 = new TLegend(0.6365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");
    easyLeg(l1,"2.76TeV");
    l1->AddEntry(hdphi[kPPDATA][ipt + kPPDATA*50],"pp ","p");
    if (drawPbPb)    l1->AddEntry(hdphi[kHIDATA][iglb],"PbPb 0-30%","p");
    if (drawPbPb)    l1->AddEntry(hdphi[6][iglb],"PbPb 30-100%","p");
    if ( ipt==0 )   l1->Draw();

  }

  
  //  cDphi->SaveAs(Form("gifs/dphi_ptDependence_drawPbPb%d_norm%d.pdf",drawPbPb,xNorm));
  
  TCanvas* c2 = new TCanvas("c2","",800,400);
  c2->Divide(2,1);
  c2->cd(2);
  TH1D* hr = new TH1D("hr",";p_{T}^{#gamma};r_{J,#gamma}",200,20,180);
  handsomeTH1(hr,0);
  hr->SetAxisRange(0.0,1.3,"Y");
  //  hr->SetNdivisions(5);
  hr->Draw();
  handsomeTGraph(gr[kPPDATA],1);
  handsomeTGraph(gr[kHIDATA],2);
  handsomeTGraph(gr[6],2);
  gr[kPPDATA]->SetMarkerStyle(24);
  gr[kPPDATA]->Draw("same p");
  gr[6]->SetMarkerStyle(24);
  if (drawPbPb)   gr[kHIDATA]->Draw("same p");
  if (drawPbPb)   gr[6]->Draw("same p");
  jumSun(20,1,180,1);


  
  c2->cd(1);
  TH1D* hx = (TH1D*)hr->Clone("hx");
  handsomeTH1(hx,0);
  hx->SetYTitle("<#Deltap_{T}^{J,#gamma}>");
  hx->SetAxisRange(-60,10,"Y");
  //  hx->SetNdivisions(5);
  hx->Draw();
  handsomeTGraph(gdpt[kPPDATA],1);
  handsomeTGraph(gdpt[kHIDATA],2);
  handsomeTGraph(gdpt[6],2);
  gdpt[kPPDATA]->SetMarkerStyle(24);
  gdpt[6]->SetMarkerStyle(24);
  gdpt[kPPDATA]->Draw("same p");
  if (drawPbPb)   gdpt[kHIDATA]->Draw("same p");
  if (drawPbPb)   gdpt[6]->Draw("same p");
  jumSun(20,1,180,1);
 
  gStyle -> SetEndErrorSize(0);
  
  TLegend *l1=   new TLegend(0.5226071,0.6300415,0.9597724,0.8332584,NULL,"brNDC");
  easyLeg(l1,"2.76TeV");
  l1->AddEntry(gr[kPPDATA],"pp ","p");
  if (drawPbPb)     l1->AddEntry(gr[kHIDATA],"PbPb 0-30%","p");
  if (drawPbPb)     l1->AddEntry(gr[6],"PbPb 30-100%","p");
  l1->Draw();

  //  c2->SaveAs(Form("gifs/summaryPlot_ptDependence_drawPbPb%d_norm%d.pdf",drawPbPb,xNorm));

}
Exemple #20
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 updateHIN11010(int etPho = 60, int etJet = 30, bool scaleByR=true, bool drawMC=true, int prodDate=20131021) {
  bool mcOnly=false;

  int percentBin[5] = {0,10,30,50,100};
  TH1D* hxgj[5][10];   //[data kind] [ centrality] 
  TH1D* hxgjpp[20];
  TFile *fSum1 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclPtRatio_gamma%djet%ddphiSig2749_Isol0_Norm1.root",etPho,etJet));
  for ( int icent=0; icent<=3 ; icent++) { 
    hxgj[khimc][icent] =  (TH1D*)fSum1->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khimc,icent));
    hxgj[khidata][icent] =  (TH1D*)fSum1->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khidata,icent));
  }
  hxgjpp[kppdata] = (TH1D*)fSum1->Get("dataSrc2_reco1_cent0SubtractedExtrapExtrapNorm");

  TFile *fSum2 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclPtRatio_gamma%djet%ddphiSig2749_Isol0_Norm2.root",etPho,etJet));
  TGraphAsymmErrors* mxhimc = (TGraphAsymmErrors*)fSum2->Get("dataSrc0_reco1_x_Summary_0");
  TGraphAsymmErrors* mxhidata = (TGraphAsymmErrors*)fSum2->Get("dataSrc1_reco1_x_Summary_0");
  //  TGraphAsymmErrors* mxppdata = (TGraphAsymmErrors*)fSum2->Get("dataSrc2_reco1_x_Summary_0");
  TGraphAsymmErrors* mxppdata;
  TGraphAsymmErrors* mxppmc = (TGraphAsymmErrors*)fSum2->Get("dataSrc10_reco1_x_Summary_0");

  TGraphAsymmErrors* rxhimc = (TGraphAsymmErrors*)fSum2->Get("dataSrc0_reco1_R_Summary_0");
  TGraphAsymmErrors* rxhidata = (TGraphAsymmErrors*)fSum2->Get("dataSrc1_reco1_R_Summary_0");
  TGraphAsymmErrors* rxppdata = (TGraphAsymmErrors*)fSum2->Get("dataSrc2_reco1_R_Summary_0");
  TGraphAsymmErrors* rxppmc = (TGraphAsymmErrors*)fSum2->Get("dataSrc10_reco1_R_Summary_0");

  TFile *fSum3 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclDeltaPhi_gamma%djet%ddphiSig628_subJ1SS1_Isol0_Norm1.root",etPho,etJet));

  TFile *fSum4 = new TFile("histOutputFiles60GeVInclusive/HisSummary_Photonv7_v29_akPu3PF_InclDeltaPhi_gamma60jet30dphiSig628_subJ1SS1_Isol0_Norm1.root");
  TGraphAsymmErrors* dphihimc = (TGraphAsymmErrors*)fSum4->Get("dataSrc0_reco1_dphi_Summary");
  TGraphAsymmErrors* dphihidata = (TGraphAsymmErrors*)fSum4->Get("dataSrc1_reco1_dphi_Summary");
  TGraphAsymmErrors* dphippdata = (TGraphAsymmErrors*)fSum4->Get("dataSrc2_reco1_dphi_Summary");
  TGraphAsymmErrors* dphippmc = (TGraphAsymmErrors*)fSum4->Get("dataSrc10_reco1_dphi_Summary");

  // new dphihidata points
  //


  double sysDphi[4] = {0.032,0.03,0.045,0.077};
  //0.109940, 0.046998, 0.034206,0.142664};
  double sysDphipp[1] = {sysDphi[3]};
  
  double sysR[4] = {0.045,0.039,0.041,0.037};
  //0.017232,0.012847,0.011691,0.012724};
  double sysRpp[1] = {sysR[3]};
  
  double sysMx[4] = { 0.053,0.048,0.051,0.032};
  double sysMxpp[1] = {0.009};
  double corrSysMx =  0.028;

  TH1D* hdphi[5][5];   //[data kind] [ centrality]                                                                                     
  TH1D* hdphipp[20];
  for ( int icent=0; icent<=3 ; icent++) {
    hdphi[khimc][icent] =  (TH1D*)fSum3->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khimc,icent));
    hdphi[khidata][icent] =  (TH1D*)fSum3->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khidata,icent));
  }
  hdphipp[kppdata] = (TH1D*)fSum3->Get("dataSrc2_reco1_cent0SubtractedExtrapExtrapNorm");
  
  // 2013 pp data!!!!!!
  TFile* pp13 = new TFile(Form("ffFilesPP60GeVInclusive/photonTrackCorr_ppDATA_output_photonPtThr60_to_9999_jetPtThr30_%d.root", prodDate));
  // TFile* pp13 = new TFile("ffFilesPP60GeVInclusive/oldSmearing.root");

  hdphi[kppdata13][1] =  (TH1D*)pp13->Get("jetDphi_icent10010_final");
  hxgj[kppdata13][1] = (TH1D*)pp13->Get("xjg_icent10010_final");
  hdphi[kppdata13][2] =  (TH1D*)pp13->Get("jetDphi_icent11030_final");
  hxgj[kppdata13][2] = (TH1D*)pp13->Get("xjg_icent11030_final");
  hdphi[kppdata13][3] =  (TH1D*)pp13->Get("jetDphi_icent13050_final");
  hxgj[kppdata13][3] = (TH1D*)pp13->Get("xjg_icent13050_final");
  hdphi[kppdata13][4] =  (TH1D*)pp13->Get("jetDphi_icent15099_final");
  hxgj[kppdata13][4] = (TH1D*)pp13->Get("xjg_icent15099_final");
  hdphi[kppdata13][5] =  (TH1D*)pp13->Get("jetDphi_icent7_final");
  hxgj[kppdata13][5] = (TH1D*)pp13->Get("xjg_icent7_final");
  

  for ( int icent  = 1 ; icent<=5 ; icent++) {
    hdphi[kppdata13][icent]->Scale(1./hdphi[kppdata13][icent]->Integral());
    for ( int i = 1 ; i<=5 ; i++) {
      hdphi[kppdata13][icent]->SetBinContent(i,-1e4);
    }
    //    hxgj[kppdata13][icent]->Rebin(10);  // Now the bins are already rebined from photonTrackCorr_ppDATA_output_photonPtThr60_to_9999_jetPtThr30_20131021.root
    hxgj[kppdata13][icent]->Scale(1./hxgj[kppdata13][icent]->Integral("width"));
  }
  
  TH1D* hPtPP2013[10];  
  hPtPP2013[1] = (TH1D*)pp13->Get("jetPt_icent10010_final");
  hPtPP2013[2] = (TH1D*)pp13->Get("jetPt_icent11030_final");
  hPtPP2013[3] = (TH1D*)pp13->Get("jetPt_icent13050_final");
  hPtPP2013[4] = (TH1D*)pp13->Get("jetPt_icent15099_final");
  hPtPP2013[5] = (TH1D*)pp13->Get("jetPt_icent7_final");
  
  TH1D* hRpp2013[10]; 
  hRpp2013[1] = new TH1D("hrpp2013_icent1","",1, 359.1-10, 359.1+10);
  hRpp2013[2] = new TH1D("hrpp2013_icent2","",1, 235.6-10, 235.6+10);
  hRpp2013[3] = new TH1D("hrpp2013_icent3","",1, 116.4-10, 116.4+10);
  hRpp2013[4] = new TH1D("hrpp2013_icent4","",1, 43.6-10,  43.6 +10);
  hRpp2013[5] = new TH1D("hrpp2013_icent5","",1, -8,  18 );

  for ( int icent=1 ;  icent<=5; icent++) { 
    double temprPP13err;
    double temprPP13 = hPtPP2013[icent]->IntegralAndError(1,hPtPP2013[icent]->GetNbinsX(),temprPP13err,"width");
    hRpp2013[icent]->SetBinContent(1,temprPP13);
    hRpp2013[icent]->SetBinError(1,temprPP13err);
    handsomeTH1(hRpp2013[icent],1);
    hRpp2013[icent]->SetMarkerStyle(21);
  }
  
  TH1D* hMXpp2013[10];
  hMXpp2013[1] = new TH1D("hmxpp2013_icent1","",1, 359.1-10, 359.1+10);
  hMXpp2013[2] = new TH1D("hmxpp2013_icent2","",1, 235.6-10, 235.6+10);
  hMXpp2013[3] = new TH1D("hmxpp2013_icent3","",1, 116.4-10, 116.4+10);
  hMXpp2013[4] = new TH1D("hmxpp2013_icent4","",1, 43.6-10,  43.6 +10);
  hMXpp2013[5] = new TH1D("hmxpp2013_icent5","",1, -8, 18);
  for ( int icent=1 ;  icent<=5; icent++) {
    hMXpp2013[icent]->SetBinContent(1,hxgj[kppdata13][icent]->GetMean());
    hMXpp2013[icent]->SetBinError(1,hxgj[kppdata13][icent]->GetMeanError());
    handsomeTH1(hMXpp2013[icent],1);
    hMXpp2013[icent]->SetMarkerStyle(21);
  }


  TFile* fPPsys = new TFile("ffFilesPP60GeVInclusive/relativeSys_merged_pp60GeV.root");

  TH1D* hdphiWidth  = (TH1D*)fPPsys->Get("dphiWidth_uncertainty_merged");
  
  TH1D* hDphiPPUnc = new TH1D("hdphippunc","",1,0,1);
  hDphiPPUnc->SetBinContent(1, hdphiWidth->GetBinContent(1) );

  TH1D* ppSysX[4];
  ppSysX[0] = (TH1D*)fPPsys->Get("dNdXjg_uncertainty_merged");
  ppSysX[1] = (TH1D*)ppSysX[0]->Clone("ppSysx1");
  ppSysX[2] = (TH1D*)ppSysX[0]->Clone("ppSysx2");
  ppSysX[3] = (TH1D*)ppSysX[0]->Clone("ppSysx3");

  TH1D* meanXpp13Sys = (TH1D*)fPPsys->Get("meanXjg_uncertainty_merged");

  float ppSysMx60 = meanXpp13Sys->GetBinContent(1);    // UPDATED on Oct 22nd
  TH1D* ppSysMx = new TH1D("ppSysMx","",1,0,1);
  ppSysMx->SetBinContent(1,ppSysMx60);

  TH1D* meanRpp13Sys = (TH1D*)fPPsys->Get("meanRjg_uncertainty_merged");
  float ppSysR60 = meanRpp13Sys->GetBinContent(1); // UPDATED on Oct 22nd
  TH1D* ppSysR = new TH1D("ppSysR","",1,0,1);
  ppSysR->SetBinContent(1,ppSysR60);

  
  
  // xjg distributions
  TCanvas *c1 = new TCanvas("c1","",1100,330);
  makeMultiPanelCanvas(c1,4,1,0.0,0.0,0.24,0.15,0.075);
  c1->cd(0);
  drawCMSppPbPb(0.1,0.95);
  //c1->Divide(4,1,0.0,0.0);
  for ( int icent=0; icent<=3 ; icent++) {
    c1->cd( 4 - icent);
    //hxgj[khimc][icent]->SetAxisRange(-.2,2.5,"Y");
    hxgj[khimc][icent]->SetAxisRange(0,2.5,"Y");
    hxgj[khimc][icent]->SetNdivisions(505);
    //    hxgj[khimc][icent]->SetTitle(";x_{J#gamma} = p^{Jet}_{T}/p^{#gamma}_{T}; #frac{1}{N_{J#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}");
    hxgj[khimc][icent]->SetTitle(";x_{J#gamma}; #frac{1}{N_{J#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}");
    handsomeTH1(hxgj[khimc][icent]);
    fixedFontHist(hxgj[khimc][icent],1,1.35);
    mcStyle2(hxgj[khimc][icent]);
    handsomeTH1(hxgj[khidata][icent],2);
    
    hxgj[khimc][icent]->GetYaxis()->SetTitleOffset(1.5);
    TH1D * htemp41 = (TH1D*)hxgj[khimc][icent]->Clone(Form("htemp41_%d",icent));
    for ( int i=0 ; i<=20 ; i++) {
      htemp41->SetBinContent(i,0);
      htemp41->SetBinError(i,0);
    }
    if (scaleByR) {
      htemp41->SetAxisRange(0,2,"Y");
      htemp41->SetYTitle("#frac{1}{N_{#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}");
    }
    htemp41->DrawCopy("hist");

    if (scaleByR)    {
      hxgj[kppdata13][icent+1]->Scale(hRpp2013[icent+1]->GetBinContent(1));
      std::cout <<"  Scaled by pp R :" << hRpp2013[icent+1]->GetBinContent(1) << std::endl;
      
      double x,y;
      rxhidata->GetPoint(icent, x,y);
      hxgj[khidata][icent]->Scale(y);
      std::cout << " scaled by PbPb R: " << y << std::endl;

      rxhimc->GetPoint(icent, x,y);
      hxgj[khimc][icent]->Scale(y);
      std::cout << " scaled by PbPb R: " << y << std::endl;
    }
    if(drawMC) hxgj[khimc][icent]->DrawCopy("hist same");

    if ( !mcOnly )    drawXSys(icent,hxgj[khidata][icent]);
    //   if ( icent==3){ }
    
    handsomeTH1(hxgj[kppdata13][icent+1]);
    hxgj[kppdata13][icent+1]->SetMarkerStyle(21);

    drawSys(hxgj[kppdata13][icent+1],ppSysX[icent],kGreen,3001);

    hxgj[kppdata13][icent+1]->Draw("same ");
    
    if ( !mcOnly )   hxgj[khidata][icent]->Draw("same");
    //onSun(0,0,2,0);
 
    // if ( icent == 2) {
    //   TLegend *leg0  = new TLegend(0.2796373,0.7545885,0.9742202,0.9937661,NULL,"brNDC");
    //     easyLeg(leg0,"");
    //   //      if ( !mcOnly )       leg0->AddEntry(hxgj[khidata][icent],"PbPb Data","p");
    //   leg0->AddEntry(hxgj[khimc][icent],"PYTHIA + HYDJET","f");
    //   leg0->AddEntry(hxgjpp[kppdata],"","");

    //   leg0->Draw();
    // }
    
    if ( icent == 3) {
      TLegend *leg0 = new TLegend(0.2916647,0.7045885,0.9862476,0.9869226,NULL,"brNDC");
      easyLeg(leg0);
      leg0->AddEntry(hxgj[khidata][icent],"PbPb Data","p");
      if ( !mcOnly )       leg0->AddEntry(hxgj[kppdata13][icent+1],"Smeared pp reference","p");
      //    leg0->AddEntry(hxgj[khidata][icent],"","");
      if(drawMC) leg0->AddEntry(hxgj[khimc][icent],"PbPb PYTHIA + HYDJET","f");
      leg0->Draw();
      //drawText("#sqrt{s_{NN}}=2.76 TeV ",0.65,0.74,0,15);
    }
        
    if ( icent == 2) {
      drawText(Form("p^{#gamma}_{T} > %d GeV/c     |#eta^{#gamma}| < 1.44",etPho),0.2,0.85,0,15);
      drawText(Form("p^{Jet}_{T} > %d GeV/c    |#eta^{Jet}| < 1.6",etJet),0.2,0.77,0,15);
      drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.2,0.69,0,15);
    }
    if ( icent == 0 ) {
      //      drawText("CMS",0.8,0.9,1);
      //      drawText("pp       #int L dt = 231 nb^{-1}",0.4,0.68,1,15);
    }
    
    if ( icent == 3) 
      drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.72,0.5,0,15);
    else 
      drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.67,0.5,0,15);
    
    /*    if ( icent == 3)
      drawText("(a)",0.275,0.8,1);
    if ( icent == 2)
      drawText("(b)",0.05,0.8,1);  
    if ( icent == 1)
      drawText("(c)",0.05,0.8,1);   
    if ( icent == 0)
      drawText("(d)",0.05,0.8,1);
    */
    gPad->RedrawAxis();
  }

  c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.pdf");
  //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.png");
  //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.gif");
  //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.C");

  
  
  // TCanvas *c1all = new TCanvas("c1all","",500,500);

  // for ( int icent=0;icent<4;icent++){
  //   hxgj[khimc][icent]->SetFillStyle(0);
  //   hxgj[khimc][icent]->SetMarkerSize(1.5);
  // }
  // hxgj[khimc][0]->SetMarkerStyle(22);
  // hxgj[khimc][1]->SetMarkerStyle(26);
  // hxgj[khimc][2]->SetMarkerStyle(23);
  // hxgj[khimc][3]->SetMarkerStyle(32);
  // hxgj[khimc][0]->DrawCopy("");
  // hxgj[khimc][1]->DrawCopy(" same");
  // hxgj[khimc][2]->DrawCopy(" same");
  // hxgj[khimc][3]->DrawCopy(" same");
  // jumSun(0,0,2,0);

  // drawText("PYTHIA+HYDJET",0.2,0.80,0,25);
  // TLegend *legc1all = new TLegend(0.6149194,0.6716102,0.9435484,0.9555085,NULL,"brNDC");
  // easyLeg(legc1all,"");
  // legc1all->AddEntry(hxgj[khimc][3],"50-100%","p");
  // legc1all->AddEntry(hxgj[khimc][2],"30-50%","p");
  // legc1all->AddEntry(hxgj[khimc][1],"10-30%","p");
  // legc1all->AddEntry(hxgj[khimc][0],"0-10%","p");
  // legc1all->Draw();
  
  // dphi distributions
  TCanvas *c1ppDphi = new TCanvas("c1ppDphi","",500,500);
  TString fitFunc = "(TMath::Pi()/20.0)*exp(-(TMath::Pi()-x)/[0])/([0]*(1-exp(-TMath::Pi()/[0])))";
  float fitxmin=3.1415926*2./3;
  TF1 *fdphiPP[10];
  TH1D* hDphiPP2013[10];
  hDphiPP2013[1] = new TH1D("hDphiPP2013_icent1","",1, 359.1-10, 359.1+10);
  hDphiPP2013[2] = new TH1D("hDphiPP2013_icent2","",1, 235.6-10, 235.6+10);
  hDphiPP2013[3] = new TH1D("hDphiPP2013_icent3","",1, 116.4-10, 116.4+10);
  hDphiPP2013[4] = new TH1D("hDphiPP2013_icent4","",1, 43.6-10,  43.6 +10);
  hDphiPP2013[5] = new TH1D("hDphiPP2013_icent5","",1, -8, 18);
  
  for ( int icent=1; icent<=5 ; icent++) {
    fdphiPP[icent] = new TF1(Form("fdphiPP_icent%d",icent),fitFunc.Data(),2.0*TMath::Pi()/3.0,TMath::Pi());
    fdphiPP[icent]->SetParName(0,"width");
    fdphiPP[icent]->SetParameter("width",0.3);
    hdphi[kppdata13][icent]->Fit(Form("fdphiPP_icent%d",icent),"0","",fitxmin,3.1415926);
    fdphiPP[icent]->SetLineWidth(1);
    fdphiPP[icent]->SetLineStyle(2);
    fdphiPP[icent]->SetLineColor(1);
    hdphi[kppdata13][icent]->SetAxisRange(1.00001e-3,1,"Y");
    hdphi[kppdata13][icent]->SetStats(0);
    hdphi[kppdata13][icent]->Draw("");
    hdphi[kppdata13][icent]->SetAxisRange(1.00001e-3,1,"Y");
    hdphi[kppdata13][icent]->SetStats(0);
    fdphiPP[icent]->SetLineWidth(2);
    fdphiPP[icent]->SetLineStyle(7); 
    fdphiPP[icent]->DrawCopy("same");
    gPad->SetLogy();
  
    float dphiWidth13 = fdphiPP[icent]->GetParameter(0) ; 
    float dphiWidth13err = fdphiPP[icent]->GetParError(0);
    hDphiPP2013[icent]->SetBinContent(1,dphiWidth13);
    hDphiPP2013[icent]->SetBinError(  1,dphiWidth13err);
    handsomeTH1(hDphiPP2013[icent],1);
    hDphiPP2013[icent]->SetMarkerStyle(21);
  }

  TCanvas *c1dphi = new TCanvas("c1dphi","",1100,330);
  makeMultiPanelCanvas(c1dphi,4,1,0.0,0.0,0.24,0.18,0.075);
  c1dphi->cd(0);
  drawCMSppPbPb(0.1,0.95);

  for ( int icent=0; icent<=3 ; icent++) {
    c1dphi->cd( 4 - icent);
    hdphi[khimc][icent]->SetAxisRange(1.e-3,1,"Y");
    //   hdphi[khimc][icent]->SetNdivisions(505);
    hdphi[khimc][icent]->GetXaxis()->SetNdivisions(3,5,0,kFALSE);
    
    hdphi[khimc][icent]->SetTitle(";#Delta#phi_{J#gamma};Pair Fraction");

    handsomeTH1(hdphi[khimc][icent]);
    fixedFontHist(hdphi[khimc][icent],1,1.35);
    mcStyle2(hdphi[khimc][icent]);
    handsomeTH1(hdphi[khidata][icent],2);

    TF1 *fdphi = new TF1("fdphi",fitFunc.Data(),2.0*TMath::Pi()/3.0,TMath::Pi());
    fdphi->SetParName(0,"width");
    fdphi->SetParameter("width",0.3);
    
    hdphi[khimc][icent]->Fit("fdphi","0llm","",fitxmin,3.1415926);

    fdphi->SetLineWidth(1);
    fdphi->SetLineStyle(2);
    fdphi->SetLineColor(kBlue); 
    // float dphiWidth = fdphi->GetParameter("width");
    // float dphiWidthErr = fdphi->GetParError(0);
    // std::cout << " dphiWidth,dphiWidthErr = " << dphiWidth <<"   "<< dphiWidthErr << std::endl;
    hdphi[khimc][icent]->SetAxisRange(1.00001e-3,1,"Y");
    hdphi[khimc][icent]->SetStats(0);
    TH1D* hdphitemp = (TH1D*)hdphi[khimc][icent]->Clone(Form("hdphitemp55_%d",icent));
    if(!drawMC)
    {
      for ( int i=0;i<=30;i++) { 
	hdphitemp->SetBinContent(i,0);
	hdphitemp->SetBinError(i,0);
      }
    }
    hdphitemp->Draw("hist");
    hdphi[khidata][icent]->SetAxisRange(1.00001e-3,1,"Y");
    if (!mcOnly) hdphi[khidata][icent]->Draw("same ");
    hdphi[khidata][icent]->SetStats(0);
    fdphi->SetLineWidth(2);
    fdphi->SetLineStyle(7);
    if ( mcOnly )    fdphi->DrawCopy("same");


    gPad->SetLogy();
    handsomeTH1(hdphi[kppdata13][icent+1]);
    
    hdphi[kppdata13][icent+1]->SetMarkerStyle(21);
    hdphi[kppdata13][icent+1]->Draw("same");

    
    if ( icent == 3) {
      TLegend *leg0  = new TLegend(0.32,0.7,0.9,0.89,NULL,"brNDC");
      easyLeg(leg0);
      if ( !mcOnly )   leg0->AddEntry(hdphi[kppdata13][icent+1],"Smeared pp reference","p");
      if ( !mcOnly )      leg0->AddEntry(hdphi[khidata][icent],"PbPb Data","p");
      if(drawMC) leg0->AddEntry(hdphi[khimc][icent],"PYTHIA + HYDJET","f");
      leg0->Draw();
    }

    if (( !mcOnly ) && ( icent == 2)) {
      //drawText("#sqrt{s_{NN}}=2.76 TeV ",0.4,0.88,0,15);
      //drawText("#int L dt = 150 #mub^{-1}",0.4,0.75,0,15);
    }

    if ( icent == 1) {
      drawText(Form("p^{#gamma}_{T} > %d GeV/c     |#eta^{#gamma}| < 1.44",etPho),0.15,0.8,0,15);
      drawText(Form("p^{Jet}_{T} > %d GeV/c    |#eta^{Jet}| < 1.6",etJet),0.15,0.7,0,15);
    }

    if ( icent == 0 ) {
      //      drawText("CMS",0.8,0.9,1);
      //      drawText("pp       #int L dt = 231 nb^{-1}",0.4,0.68,1,15);                                                                     
    }


    if ( icent == 3)
      drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.313,0.6,0,15);
    else
      drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.1,0.6,0,15);

    if ( icent == 3)
      drawText("(a)",0.275,0.8,1);
    if ( icent == 2)
      drawText("(b)",0.05,0.8,1);
    if ( icent == 1)
      drawText("(c)",0.05,0.8,1);
    if ( icent == 0)
      drawText("(d)",0.05,0.8,1);
    
    double bottomY = 0.0009;
    double pi = TMath::Pi();

    drawPatch(-0.5,bottomY/100,pi+0.5,bottomY);

    bottomY = 0.0005;
    drawText("0",0.05,bottomY,0,18,false);
    drawText("#frac{1}{3}#pi",pi/3-0.05,bottomY,0,18,0);
    drawText("#frac{2}{3}#pi",2*pi/3-0.05,bottomY,0,18,0);
    if ( icent==0) 
      drawText("#pi",pi-0.1,bottomY,0,18,0);
    drawText("#Delta#phi_{J#gamma}",pi/2.-0.1,bottomY-0.0002,0,18,0);
    
  }
  


  gPad->RedrawAxis();
  c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.pdf");
  //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.png");
  //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.gif");
  //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.C");
  
  ////////////////////////////// summary plots
  TCanvas *c2 = new TCanvas("c2","",350,350);
  TH1D* hTemp2 = new TH1D("htemp2",";N_{part};<x_{J#gamma}>",100,-20,400);
  hTemp2->SetNdivisions(505);
  handsomeTH1(hTemp2,1);
  handsomeTGraph(mxhidata,2);
  mxhidata->SetMarkerStyle(20);
  handsomeTGraph(mxhimc,1);
  mxhimc->SetMarkerStyle(24);
  //  handsomeTGraph(mxppdata,1);
  //  mxppdata->SetMarkerStyle(21);
  handsomeTGraph(mxppmc,1);
  mxppmc->SetMarkerStyle(25);
  
    
  hTemp2->SetAxisRange(0.6,1.1,"Y");
  hTemp2->DrawCopy();
  //  TH1D* hMXpp2013_2 = new TH1D("hmxpp2013_2","",1,-10,370);
  //  hMXpp2013_2->SetBinContent(1,hMXpp2013->GetBinContent(1));
  //  if ( !mcOnly )   drawSys(hMXpp2013_2,sysMxpp,kGreen,3001);
  if ( !mcOnly )   drawSys(mxhidata,sysMx,10);
  
  // mxppmc->Draw("p");
  //  if ( !mcOnly )   mxppdata->Draw("p");
  if ( !mcOnly )  {
    hMXpp2013[5]->SetMarkerStyle(20);
    for ( int icent = 1 ; icent<=5 ; icent++) {
      drawSys(hMXpp2013[icent],ppSysMx,kGreen,3001);
      hMXpp2013[icent]->DrawCopy("p same");
    }
  }
  if(drawMC) mxhimc->Draw("p same");
  if ( !mcOnly )  mxhidata->Draw("p same");

  hMXpp2013[5]->SetFillStyle(3001);
  hMXpp2013[5]->SetFillColor(kGreen);
  hMXpp2013[5]->SetLineColor(0);
  hDphiPP2013[2]->SetFillStyle(3001);
  hDphiPP2013[2]->SetFillColor(kGreen);
  hDphiPP2013[2]->SetLineColor(0);
  TH1D *dummyHist = new TH1D("dummyHist","",10,0,1);
  dummyHist->SetFillStyle(1001);
  dummyHist->SetMarkerColor(kRed);
  dummyHist->SetFillColor(90);
  dummyHist->SetLineColor(0);
  
  //// sys bar by energy scale
  /*
  TBox *b1 = new TBox(400-20,0.85 - corrSysMx ,400,  0.85 + corrSysMx);
  b1->SetFillColor(1);
  b1->SetFillStyle(1001);
  if ( !mcOnly )   b1->Draw();
  TBox *b2 = new TBox(400-20+3,0.85 - corrSysMx+ 0.002 ,400-3,  0.85 + corrSysMx- 0.002);
  b2->SetFillColor(0);
  b2->SetFillStyle(1001);
  if ( !mcOnly )   b2->Draw();
  */
  //  drawText("Common uncertainty due to jet ",0.35,0.25,0,15);
  //  drawText("energy scale & photon purity",0.35,0.2,0,15);
  //  drawText("#sqrt{s_{NN}}=2.76 TeV ",0.5,0.85,0,15);
  //  drawText("#int L dt = 150 #mub^{-1}",0.5,0.72,0,15);
  //  drawText("(a)",0.22,0.87,1);
  drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.7,0.75,0);
  drawCMSppPbPb(0.1,0.95,12);
  //  drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.5,0.38,0);
  // drawText("CMS",0.78,0.88,1);

  TLegend *leg4 =  new TLegend(0.1630303,0.6054839,0.7590909,0.8931183,NULL,"brNDC");
  easyLeg(leg4,"");
  //  if ( !mcOnly )  leg4->AddEntry(mxppdata,"pp Data 231nb^{-1}","p");
  if ( !mcOnly ) leg4->AddEntry(dummyHist,"PbPb Data","fp");
  if ( !mcOnly )  leg4->AddEntry(hMXpp2013[5],"pp Data","fp");
  if ( !mcOnly )  leg4->AddEntry(hDphiPP2013[2],"Smeared pp reference","fp");
  if(drawMC) leg4->AddEntry(mxhimc,"PYTHIA + HYDJET","p");
  //  leg4->AddEntry(mxppmc,"PYTHIA","p");




  //  leg4->AddEntry(hSysTemp,"Sys. Uncertainty","f");                                                                                         
  leg4->Draw();


  gPad->RedrawAxis();
  
  c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.pdf");
  //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.png");
  //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.gif");
  //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.C");
  
  ////////////////////////////// rx 
  TCanvas *c3 = new TCanvas("c3","",350,350);

  TH1D* hTemp3 = new TH1D("htemp2",";N_{part};R_{J#gamma}",100,-20,400);
  hTemp3->SetNdivisions(505);
  handsomeTH1(hTemp3,1);
  handsomeTGraph(rxhidata,2);
  rxhidata->SetMarkerStyle(20);
  handsomeTGraph(rxhimc,1);
  rxhimc->SetMarkerStyle(24);
  handsomeTGraph(rxppdata,1);
  rxppdata->SetMarkerStyle(21);
  handsomeTGraph(rxppmc,1);
  rxppmc->SetMarkerStyle(25);

  hTemp3->SetAxisRange(0.41,1.,"Y");
  hTemp3->Draw();


  // Ratio
  // DivideTG(rxppdata,rxppmc);
  // DivideTG(rxhidata,rxhimc);
  //////////////////////////////////////////////
  //  TH1D* hdphi2013_2 = new TH1D("hdphi2013_2","",1,-10,370);
  //  hdphi2013_2->SetBinContent(1,hRpp2013->GetBinContent(1));
  //  if ( !mcOnly )   drawSys(hdphi2013_2,sysRpp,kGreen,3001);
  if ( !mcOnly )   drawSys(rxhidata,sysR,10);
  //  if ( !mcOnly )   drawSys(rxppdata,sysRpp,10);
  // jumSun(-10,1,400,1);
  if(drawMC) rxhimc->Draw("p");
  //  rxppmc->Draw("p");
  //  if ( !mcOnly )   rxppdata->Draw("p");
  if ( !mcOnly )   {
    hRpp2013[5]->SetMarkerStyle(20);
    for ( int icent =1 ; icent<=5 ; icent++) { 
      drawSys(hRpp2013[icent],ppSysR,kGreen,3001);
      hRpp2013[icent]->Draw("same");
    }
  }
  if ( !mcOnly )   rxhidata->Draw("p same");
  //  drawText(Form("p^{#gamma}_{T} > %d GeV/c",etPho),0.6,0.75,0,15);
  //  drawText(Form("p^{Jet}_{T} > %d GeV/c",etJet),0.6,0.67,0,15);
  //  drawText("CMS",0.78,0.88,1);
  //  drawText("(b)",0.22,0.87,1);
  drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.7,0.75,0);
  drawCMSppPbPb(0.1,0.95,12);

  leg4->Draw();
  gPad->RedrawAxis();

  c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.pdf");
  //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.png");
  //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.gif");
  //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.C");
  
  TCanvas *c4 = new TCanvas("c4","",350,350);

  TH1D* hTemp4 = new TH1D("htemp2",";N_{part};#sigma(#Delta#phi_{J#gamma})",100,-20,400);
  hTemp4->SetNdivisions(505);
  handsomeTH1(hTemp4,1);
  handsomeTGraph(dphihidata,2);
  dphihidata->SetMarkerStyle(20);
  handsomeTGraph(dphihimc,1);
  dphihimc->SetMarkerStyle(24);
  handsomeTGraph(dphippdata,1);
  dphippdata->SetMarkerStyle(21);
  handsomeTGraph(dphippmc,1);
  dphippmc->SetMarkerStyle(25);

  hTemp4->SetAxisRange(0,.5,"Y");
  hTemp4->Draw();
  
                                                                                 
  // TH1D* h2013_3 = new TH1D("hdphi2013_3","",1,-10,370);
  //  h2013_3->SetBinContent(1,hDphiPP2013->GetBinContent(1));

  //  if ( !mcOnly )  drawSys(h2013_3,sysDphipp,kGreen,3001);
  if ( !mcOnly )  drawSys(dphihidata,sysDphi,10);
  if(drawMC) dphihimc->Draw("p same");
  // dphippmc->Draw("p");
  //  if ( !mcOnly )  dphippdata->Draw("p");
  for ( int icent=1 ; icent<=5 ; icent++){
    drawSys(hDphiPP2013[icent], hDphiPPUnc, kGreen,3001);
  }
  
  TH1D* hDphiPP2013Temp = new TH1D("hDphiPP2013Temp","",1,380,400);
  hDphiPP2013Temp->SetBinContent(1,0.27);
  hDphiPP2013[5]->SetMarkerStyle(20);
  for ( int icent=1 ; icent<=5 ; icent++){ 
    hDphiPP2013[icent]->Draw("same");
  }
  if ( !mcOnly )  dphihidata->Draw("p");

  // TLegend *legDphi =  new TLegend(0.32,0.18,0.93,0.7,NULL,"brNDC");
  // easyLeg(legDphi,"");
  // legDphi->SetTextSize(17);
  // //  drawText("|#Delta#phi_{J#gamma}| > #frac{2}{3}#pi",0.5,0.38,0);
  // //  drawText("Fit : #frac{e^{#frac{|#Delta#phi_{J#gamma}|-#pi}{#sigma}}}{#sigma(1-e^{-#pi/#sigma})}",0.5,0.23,0);
  // legDphi->Draw();
  // //  drawText("(a)",0.22,0.87,1);
  // //  drawText("CMS",0.78,0.88,1);


  TH1D* hSysTemp = new TH1D("hSystemp","",1,0,1);
  hSysTemp->SetFillColor(newYellow);
  hSysTemp->SetLineColor(newYellow);

  leg4->Draw();

  drawText(Form("p^{#gamma}_{T} > %d GeV/c     |#eta^{#gamma}| < 1.44",etPho),0.25,0.3,0,15);
  drawText(Form("p^{Jet}_{T} > %d GeV/c    |#eta^{Jet}| < 1.6",etJet),0.25,0.2,0,15);
  drawCMSppPbPb(0.1,0.95,12);

  gPad->RedrawAxis();
  c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.pdf");
  //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.png");
  //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.gif");
  //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.C");

   // // print numbers
   // std::cout << " Summary of Points for PbPb " << std::endl;
   // PrintGraphAndSys(dphihidata,sysDphi);
   // PrintGraphAndSys(mxhidata,sysMx);
   // PrintGraphAndSys(rxhidata,sysR);

   // std::cout << " Summary of Points for PYTHIA + HYDJET " << std::endl;
   // PrintGraph(dphihimc);
   // PrintGraph(mxhimc);
   // PrintGraph(rxhimc);

   //   std::cout << " Summary of Points for pp " << std::endl;
   //  PrintGraphAndSys(dphippdata[5],sysDphipp);
   //  PrintGraphAndSys(mxppdata[5],sysMxpp);
   // PrintGraphAndSys(rxppdata[5],sysRpp);


   
   /*
   TCanvas *c5 = new TCanvas("c5","",500,500);
   hxgj[khidata][0]->SetAxisRange(-.2,2.5,"Y");
   hxgj[khidata][0]->SetNdivisions(505);
   fixedFontHist(hxgj[khidata][0],1,1.35);
   handsomeTH1(hxgj[khidata][0],2);
   hxgj[khidata][0]->GetYaxis()->SetTitleOffset(1.5);
   hxgj[khidata][0]->DrawCopy("");
   handsomeTH1(hxgj[kppdata13][5],4);
   hxgj[kppdata13][5]->Draw("same hist");
   onSun(0,0,2,0);
   */
}
void drawPbPb_pp_subEnergy( bool saveFigures=true) {

    const int nPtBin = 4;
    double ptBin[nPtBin+1] = {40, 50,60,80,9999};
    double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
    // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};

    const int nCentBinHI = 2;
    const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099};

    TH1D* hxjg[7][10][6]; // [Collision][centrality][pt]
    TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
    TH1D* hGenJetPt[7][10][6]; // [Collision][centrality][pt]
    TH1D* hIaa[7][10][6]; // [Collision][centrality][pt]
    TH1D* hDphi[7][10][6]; // [Collision][centrality][pt]
    TH1D* hEta[7][10][6]; // [Collision][centrality][pt]
    TH1D* meanXjg[7][10];      // [Collision][centrality]
    TH1D* meanJetPt[7][10];      // [Collisi on][centrality]
    TH1D* meanGenJetPt[7][10];      // [Collisi on][centrality]

    TH1D* rjg[7][5];     //  [Collision][centrality]
    TH1D* rGenjg[7][5];     //  [Collision][centrality]
    for (int icoll=0 ; icoll<4  ; icoll++) {   // only pp and PbPb
        for (int icent=1 ; icent<= 10 ; icent++) {
            meanXjg[icoll][icent] = new TH1D( Form("meanXjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <X_{J#gamma}>",nPtBin,ptBinPaDraw);
            meanJetPt[icoll][icent] = new TH1D( Form("meanJetPt_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPtBin,ptBinPaDraw);
            meanGenJetPt[icoll][icent] = new TH1D( Form("meanGenJetPt_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPtBin,ptBinPaDraw);
            rjg[icoll][icent] = new TH1D( Form("rjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPtBin,ptBinPaDraw);
            rGenjg[icoll][icent] = new TH1D( Form("rGenjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPtBin,ptBinPaDraw);


            for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
                hxjg[icoll][icent][ipt] = NULL;
                hJetPt[icoll][icent][ipt] = NULL;
                hGenJetPt[icoll][icent][ipt] = NULL;
                hIaa[icoll][icent][ipt] = NULL;
                hDphi[icoll][icent][ipt] = NULL;
                hEta[icoll][icent][ipt] = NULL;
            }

        }
    }

    TFile* histFile[7][6];  // [Collision][pt]
    for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
        for (int icoll=0 ; icoll<4 ; icoll++) {
            TString sampleName = getSampleName( icoll ) ;
            char* fname =  Form("ffFilesEnergySub/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20130917.root",sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt]);
            histFile[icoll][ipt] = new TFile(fname) ;
            cout << " Reading file : " << fname << endl;

            if ( histFile[icoll][ipt]->IsZombie()  == false ) {
                cout << " Success." << endl;
                if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
                    int icent = 7 ;
                    hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", icent)) ;
                    cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
                    hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", icent)) ;
                    cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
                    hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", icent)) ;
                    cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
                    hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", icent)) ;
                    cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent) << endl;

                    if ( icoll%2 == 1)  {  // if it is MC
                        hGenJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("genJetPt_icent%d_final", icent)) ;
                        cout << " Getting histogram : " << Form("genJetPt_icent%d_final", icent) << endl;
                    }
                }

                if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
                    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
                        hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
                        cout << " Getting histogram : " << Form("xjg_icent%d_final", centBinHI[icent] ) << endl;
                        hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
                        cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
                        hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBinHI[icent] ) ) ;
                        cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent)<< endl;
                        hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBinHI[icent] ) ) ;
                        cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent)<< endl;
                        if ( icoll%2 == 1)  {  // if it is MC
                            hGenJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("genJetPt_icent%d_final",centBinHI[icent]));
                            cout << " Getting histogram : " << Form("genJetPt_icent%d_final", centBinHI[icent] ) << endl;
                        }
                    }
                }
            }
            else
                cout << " no such file " << endl;
        }
    }

    for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
        for (int icoll=0 ; icoll<4 ; icoll++) {
            for (int icent=1 ; icent<= 10 ; icent++ ) {
                if ( hxjg[icoll][icent][ipt] == NULL )
                    continue;   // emtpy histogram
                double rVal, rErr;

                rVal = hxjg[icoll][icent][ipt]->IntegralAndError(1, hxjg[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
                rjg[icoll][icent]->SetBinContent( ipt, rVal );
                rjg[icoll][icent]->SetBinError  ( ipt, rErr );

                meanXjg[icoll][icent]->SetBinContent( ipt, hxjg[icoll][icent][ipt]->GetMean() );
                meanXjg[icoll][icent]->SetBinError  ( ipt, hxjg[icoll][icent][ipt]->GetMeanError() );

                meanJetPt[icoll][icent]->SetBinContent( ipt, hJetPt[icoll][icent][ipt]->GetMean() );
                meanJetPt[icoll][icent]->SetBinError  ( ipt, hJetPt[icoll][icent][ipt]->GetMeanError() );

                if ( icoll%2 == 1)  {  // if it is MC
                    meanGenJetPt[icoll][icent]->SetBinContent( ipt, hGenJetPt[icoll][icent][ipt]->GetMean() );
                    meanGenJetPt[icoll][icent]->SetBinError  ( ipt, hGenJetPt[icoll][icent][ipt]->GetMeanError() );
                    rVal = hGenJetPt[icoll][icent][ipt]->IntegralAndError(1, hGenJetPt[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
                    rGenjg[icoll][icent]->SetBinContent( ipt, rVal );
                    rGenjg[icoll][icent]->SetBinError  ( ipt, rErr );

                }

            }
        }
    }

    TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{Jet} (GeV);#frac{dN}{dp_{T}} #frac{1}{N}",200,10,150);
    hTempPt->SetAxisRange(30,150,"X");
    hTempPt->SetAxisRange(0,0.05,"Y");
    hTempPt->GetYaxis()->SetTitleOffset(1.35);
    handsomeTH1(hTempPt,0);

    TCanvas* c2 = new TCanvas("c2_jetPt","",1200,350);
    makeMultiPanelCanvas(c2,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

        c2->cd(ipt);

        // draw pp
        hTempPt->DrawCopy();
        hJetPt[kPPMC][7][ipt]->Scale(1./rjg[kPPMC][7]->GetBinContent(ipt)); // rjg normalization
        handsomeTH1(hJetPt[kPPMC][7][ipt], 1);
        hJetPt[kPPMC][7][ipt]->SetMarkerStyle(24);
        hJetPt[kPPMC][7][ipt]->Draw("same hist");
        // draw pbpb
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(hJetPt[kHIMC][icent][ipt],kRed);
            hJetPt[kHIMC][icent][ipt]->Scale(1./rjg[kHIMC][icent]->GetBinContent(ipt));  // rjg normalization
            if ( icent == 2 ) hJetPt[kHIMC][icent][ipt]->SetMarkerStyle(24);

            if ( icent == 2 ) hJetPt[kHIMC][icent][ipt]->Draw("same hist");
            if ( icent == 1 ) hJetPt[kHIMC][icent][ipt]->Draw("same");

        }

        double dx1=0.15;
        if ( ipt == nPtBin )
            drawText(Form("p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1]), 0.15+dx1+0.25,0.85,1,15);//yeonju 130823
        else
            drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.15+dx1,0.85,1,15);//yeonju 130823

        if ( ipt == nPtBin )  {
            TLegend *l0 = new TLegend(0.1542202,0.4928762,0.9769094,0.7803873,NULL,"brNDC");
            easyLeg(l0,"MC  2.76TeV");
            l0->AddEntry(hJetPt[kPPMC][7][ipt],"PYTHIA   pp ","l");
            l0->AddEntry(hJetPt[kHIMC][2][ipt],"PYTHIA+HYDJET 30-100%","l");
            l0->AddEntry(hJetPt[kHIMC][1][ipt],"PYTHIA+HYDJET 0-30%","p");
            l0->Draw();
        }

        onSun(30,0,200,0);
    }


    TCanvas* c3 = new TCanvas("c3_GenjetPt","",1200,350);
    makeMultiPanelCanvas(c3,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

        c3->cd(ipt);

        // draw pp
        hTempPt->DrawCopy();
        hGenJetPt[kPPMC][7][ipt]->Scale(1./rGenjg[kPPMC][7]->GetBinContent(ipt)); // rjg normalization
        handsomeTH1(hGenJetPt[kPPMC][7][ipt], 1);
        hGenJetPt[kPPMC][7][ipt]->SetMarkerStyle(24);
        hGenJetPt[kPPMC][7][ipt]->Draw("same hist");
        // draw pbpb
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(hGenJetPt[kHIMC][icent][ipt],kRed);
            hGenJetPt[kHIMC][icent][ipt]->Scale(1./rGenjg[kHIMC][icent]->GetBinContent(ipt));  // rjg normalization
            if ( icent == 2 ) hGenJetPt[kHIMC][icent][ipt]->SetMarkerStyle(24);

            if ( icent == 2 ) hGenJetPt[kHIMC][icent][ipt]->Draw("same hist");
            if ( icent == 1 ) hGenJetPt[kHIMC][icent][ipt]->Draw("same");

        }

        double dx1=0.15;
        if ( ipt == nPtBin )
            drawText(Form("p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1]), 0.15+dx1+0.25,0.85,1,15);//yeonju 130823
        else
            drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.15+dx1,0.85,1,15);//yeonju 130823

        if ( ipt == nPtBin )  {
            TLegend *l0 = new TLegend(0.1542202,0.4928762,0.9769094,0.7803873,NULL,"brNDC");
            easyLeg(l0,"Gen Jet Used");
            l0->AddEntry(hGenJetPt[kPPMC][7][ipt],"PYTHIA   pp ","l");
            l0->AddEntry(hGenJetPt[kHIMC][2][ipt],"PYTHIA+HYDJET 30-100%","l");
            l0->AddEntry(hGenJetPt[kHIMC][1][ipt],"PYTHIA+HYDJET 0-30%","p");
            l0->Draw();
        }

        onSun(30,0,200,0);
    }



    TCanvas* c101 = new TCanvas("c101_xjg","",1200,350);
    makeMultiPanelCanvas(c101,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
    TH1D* hTempXjg = new TH1D("htempxjg",";x_{J#gamma};#frac{dN}{dp_{T}} #frac{1}{N}",200,0,2);
    hTempXjg->SetAxisRange(0,2,"X");
    hTempXjg->SetAxisRange(0,3,"Y");
    hTempXjg->GetYaxis()->SetTitleOffset(1.35);
    handsomeTH1(hTempXjg,0);

    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

        c101->cd(ipt);

        // draw pp
        hTempXjg->DrawCopy();
        hxjg[kPPMC][7][ipt]->Scale(1./rjg[kPPMC][7]->GetBinContent(ipt)); // rjg normalization
        handsomeTH1(hxjg[kPPMC][7][ipt], 1);
        hxjg[kPPMC][7][ipt]->SetMarkerStyle(24);
        hxjg[kPPMC][7][ipt]->Draw("same hist");
        // draw pbpb
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(hxjg[kHIMC][icent][ipt],kRed);
            hxjg[kHIMC][icent][ipt]->Scale(1./rjg[kHIMC][icent]->GetBinContent(ipt));  // rjg normalization
            if ( icent == 2 ) hxjg[kHIMC][icent][ipt]->SetMarkerStyle(24);

            if ( icent == 2 ) hxjg[kHIMC][icent][ipt]->Draw("same hist");
            if ( icent == 1 ) hxjg[kHIMC][icent][ipt]->Draw("same");

        }


        double dx1=0.15;
        if ( ipt == nPtBin )
            drawText(Form("p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1]), 0.15+dx1+0.25,0.85,1,15);//yeonju 130823
        else
            drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.15+dx1,0.85,1,15);//yeonju 130823

        if ( ipt == nPtBin )  {
            TLegend *l0 = new TLegend(-0.0007607977,0.6729655,0.8215427,0.9383604,NULL,"brNDC");
            easyLeg(l0,"MC  2.76TeV");
            l0->AddEntry(hxjg[kPPMC][7][ipt],"PYTHIA   pp ","l");
            l0->AddEntry(hxjg[kHIMC][2][ipt],"PYTHIA+HYDJET 30-100%","l");
            l0->AddEntry(hxjg[kHIMC][1][ipt],"PYTHIA+HYDJET 0-30%","p");
            l0->Draw();
        }

        onSun(30,0,200,0);
    }


    TCanvas* c32 = new TCanvas("c32","",500,500);
    handsomeTH1(meanXjg[kPPMC][7], 1);
    meanXjg[kPPMC][7]->SetYTitle("<x_{J#gamma}>  (>30GeV)");
    meanXjg[kPPMC][7]->SetMarkerStyle(24);
    //  meanXjg[kPPMC][7]->SetAxisRange(-2,2,"X");
    meanXjg[kPPMC][7]->SetAxisRange(0.8,1.05,"Y");
    meanXjg[kPPMC][7]->Draw();

    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        handsomeTH1(meanXjg[kHIMC][icent],kRed);
        if ( icent == 2 ) meanXjg[kHIMC][icent]->SetMarkerStyle(24);
        meanXjg[kHIMC][icent]->Draw("same");
    }

    if (1 == 1) {
        TLegend *l1mc = new TLegend(0.3387097,0.6864407,0.8729839,0.9004237,NULL,"brNDC");
        easyLeg(l1mc,"MC  2.76TeV");
        l1mc->AddEntry(meanXjg[kPPMC][7],"PYTHIA   pp ","l");
        l1mc->AddEntry(meanXjg[kHIMC][2],"PYTHIA+HYDJET 30-100%","l");
        l1mc->AddEntry(meanXjg[kHIMC][1],"PYTHIA+HYDJET 0-30%","p");
        l1mc->Draw();
    }

    TCanvas* c33 = new TCanvas("c33","",500,500);
    handsomeTH1(meanJetPt[kPPMC][7], 1);
    meanJetPt[kPPMC][7]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
    meanJetPt[kPPMC][7]->SetMarkerStyle(24);
    //  meanJetPt[kPPMC][7]->SetAxisRange(-2,2,"X");
    meanJetPt[kPPMC][7]->SetAxisRange(40,80,"Y");
    meanJetPt[kPPMC][7]->Draw();

    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        handsomeTH1(meanJetPt[kHIMC][icent],kRed);
        if ( icent == 2 ) meanJetPt[kHIMC][icent]->SetMarkerStyle(24);
        meanJetPt[kHIMC][icent]->Draw("same");
    }

    if (1 == 1) {
        TLegend *l1mc = new TLegend(0.3810484,0.1864407,0.891129,0.4004237,NULL,"brNDC");
        easyLeg(l1mc,"MC  2.76TeV");
        l1mc->AddEntry(meanJetPt[kPPMC][7],"PYTHIA   pp ","p");
        l1mc->AddEntry(meanJetPt[kHIMC][2],"PYTHIA+HYDJET 30-100%","p");
        l1mc->AddEntry(meanJetPt[kHIMC][1],"PYTHIA+HYDJET 0-30%","p");
        l1mc->Draw();
    }

    TCanvas* c33_genJet = new TCanvas("c33_genJet","",500,500);
    handsomeTH1(meanGenJetPt[kPPMC][7], 1);
    meanGenJetPt[kPPMC][7]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
    meanGenJetPt[kPPMC][7]->SetMarkerStyle(24);
    //  meanGenJetPt[kPPMC][7]->SetAxisRange(-2,2,"X");
    meanGenJetPt[kPPMC][7]->SetAxisRange(40,80,"Y");
    meanGenJetPt[kPPMC][7]->Draw();

    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        handsomeTH1(meanGenJetPt[kHIMC][icent],kRed);
        if ( icent == 2 ) meanGenJetPt[kHIMC][icent]->SetMarkerStyle(24);
        meanGenJetPt[kHIMC][icent]->Draw("same");
    }

    if (1 == 1) {
        TLegend *l1mc = new TLegend(0.3810484,0.1864407,0.891129,0.4004237,NULL,"brNDC");
        easyLeg(l1mc,"Gen Jet Used");
        l1mc->AddEntry(meanGenJetPt[kPPMC][7],"PYTHIA   pp ","p");
        l1mc->AddEntry(meanGenJetPt[kHIMC][2],"PYTHIA+HYDJET 30-100%","p");
        l1mc->AddEntry(meanGenJetPt[kHIMC][1],"PYTHIA+HYDJET 0-30%","p");
        l1mc->Draw();
    }

    TCanvas* c34 = new TCanvas("c34","",500,500);
    handsomeTH1(rjg[kPPMC][7], 1);
    rjg[kPPMC][7]->SetYTitle("r_{j#gamma}  (>30GeV)");
    rjg[kPPMC][7]->SetMarkerStyle(24);
    //  rjg[kPPMC][7]->SetAxisRange(-2,2,"X");
    rjg[kPPMC][7]->SetAxisRange(.2,1,"Y");
    rjg[kPPMC][7]->Draw();

    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        handsomeTH1(rjg[kHIMC][icent],kRed);
        if ( icent == 2 ) rjg[kHIMC][icent]->SetMarkerStyle(24);
        rjg[kHIMC][icent]->Draw("same");
    }

    if (1 == 1) {
        TLegend *l1mc = new TLegend(0.3810484,0.1864407,0.891129,0.4004237,NULL,"brNDC");
        easyLeg(l1mc,"MC  2.76TeV");
        l1mc->AddEntry(rjg[kPPMC][7],"PYTHIA   pp ","p");
        l1mc->AddEntry(rjg[kHIMC][2],"PYTHIA+HYDJET 30-100%","p");
        l1mc->AddEntry(rjg[kHIMC][1],"PYTHIA+HYDJET 0-30%","p");
        l1mc->Draw();
    }

    TCanvas* c34_genJet = new TCanvas("c34_genJet","",500,500);
    handsomeTH1(rGenjg[kPPMC][7], 1);
    rGenjg[kPPMC][7]->SetYTitle("r_{j#gamma}  (>30GeV)");
    rGenjg[kPPMC][7]->SetMarkerStyle(24);
    //  rGenjg[kPPMC][7]->SetAxisRange(-2,2,"X");
    rGenjg[kPPMC][7]->SetAxisRange(.2,1,"Y");
    rGenjg[kPPMC][7]->Draw();

    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        handsomeTH1(rGenjg[kHIMC][icent],kRed);
        if ( icent == 2 ) rGenjg[kHIMC][icent]->SetMarkerStyle(24);
        rGenjg[kHIMC][icent]->Draw("same");
    }

    if (1 == 1) {
        TLegend *l1mc = new TLegend(0.3810484,0.1864407,0.891129,0.4004237,NULL,"brNDC");
        easyLeg(l1mc,"Gen Jet Used");
        l1mc->AddEntry(rGenjg[kPPMC][7],"PYTHIA   pp ","p");
        l1mc->AddEntry(rGenjg[kHIMC][2],"PYTHIA+HYDJET 30-100%","p");
        l1mc->AddEntry(rGenjg[kHIMC][1],"PYTHIA+HYDJET 0-30%","p");
        l1mc->Draw();
    }


}
void drawInclJetFragSingle( TH1D* htrkPt[3][5],
			  int dataset,
			  int icent,
			  int irj,
			  int fragMode,
			  float trackPtMin,
			  float trackPtMax,
			  int doClosure,
			  bool usingPara,
        int rewtJet
        ) {
  /////////////////////////////////////////////////////////////////
  // This function is given the booked histograms
  // and does the real work of filling the histograms
  // for each dataset and each analysis setup
  /////////////////////////////////////////////////////////////////
  TString datasetName;
  if (dataset == kHIDATA)       datasetName = "hidata";
  else if (dataset == kHIMC)    datasetName = "himc";
  else if (dataset == kPPDATA)  datasetName = "ppdata";
  else if (dataset == kPPMC)  datasetName = "ppmc";
  TString attPara = ( (usingPara == true) ? "Para" : "" ) ;
  
  TString suffix = Form("%s_icent%d_irj%d_fragMode%d_closure%d_jtrewt%d_%s",datasetName.Data(),icent,irj,fragMode,doClosure,rewtJet,tag.Data());
  
  TString clsText = "evtMixing";
  TString clsText_ = "event mixing method";
  if ( doClosure >= 100 ) {
    clsText = "etaRefl";
    clsText_ = "#eta reflection method";
  }

  ///////////////////////////////////////////////////////
  // Book histograms for Intermediate checks
  ///////////////////////////////////////////////////////
  TH1D* hjetPt = new TH1D(Form("hjetPt_%s",suffix.Data()),";Jet p_{T} (GeV/c);Entries;",50,0,500);

  ///////////////////////////////////////////////////////
  // Setup cuts
  ///////////////////////////////////////////////////////
  float finalEtaCut = 2.0;
  // float finalEtaCut = 1.2;
  float finalJetPtMin = 100;
  float finalJetPtMax = 300;
  TCut jetSelCut = Form("finalJetPt>=%.0f&&finalJetPt<%.0f",finalJetPtMin,finalJetPtMax);
  // TCut jetSelCut = Form("finalJetPt>=%.0f&&finalJetPt<%.0f&&jetPtGM>100",finalJetPtMin,finalJetPtMax);
  // TCut jetSelCut = Form("jetPtGM>=%.0f&&jetPtGM<%.0f",finalJetPtMin,finalJetPtMax);
  // jetSelCut=jetSelCut&&"abs(vz)<4";
  
  TCut centCut = "1==1";
  if ( (icent >= 1) && (icent<=4) )
    centCut = Form("cBin>=%d && cBin<%d", (int)centBin1[icent-1], (int)centBin1[icent]);

  ////////////////////////////////////////////////////////  
  // Jet Selection
  ////////////////////////////////////////////////////////  
  // inclusive /////////
  TString jet1Cut = Form("abs(jetEta)<%.2f",finalEtaCut);
  // if (doClosure>=100&&doClosure!=101) {
  if (doClosure>=100) {
    jet1Cut = Form("%s && abs(jetEta)>0.3",jet1Cut.Data());
  }

  ////////////////////////////////////////////////////////  
  // Weights
  ////////////////////////////////////////////////////////  
  float jetDrCut = 0.3;
  TString jetRewt= "1";
  if ( rewtJet==1 ) {
    jetRewt = Form("rewtPt");
    // jetRewt = Form("(1+0.5*(rewtPt-1))");
  }
  
  ///////////////////////////////////////////////////////
  // Input trees
  ///////////////////////////////////////////////////////
  multiTreeUtil* dj  = new multiTreeUtil();
  if ( dataset == kHIDATA) {
    // dj->addFile("../ntout/jskim_hltjet80-pt90-v20_akPu3PF_Jan16_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root",
    dj->addFile("../ntout/jskim_hltjet80-pt90-v20_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0_addedReweight.root","tdj", jetSelCut && centCut,1);
    // dj->addFile("../ntout/jskim_hltjet80-pt90-v20_akPu3PF_Jan26_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm3bin0_akPu3PF_gj0.root","tdj", jetSelCut && centCut,1);
  } else if ( dataset == kHIMC) {
    // pythia+hydjet
    // dj->addFile("../ntout/jskim_hydj80_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root","tdj", jetSelCut && centCut && "pthat>=80&&pthat<9999", 9.913e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj50_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root","tdj", jetSelCut && centCut && "pthat>=50&&pthat<80", 1.021e-3*1.e9);
    // dj->addFile("../ntout/jskim_hydj80_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=80&&pthat<100",9.913e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj100_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=100&&pthat<120",3.069e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj120_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=120&&pthat<9999",1.128e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj80_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=80&&pthat<100",9.913e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj100_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=100&&pthat<9999",3.069e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj80_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root","tdj", jetSelCut && centCut && "pthat>=80&&pthat<100", 9.913e-5*1.e9);
    // dj->addFile("../ntout/jskim_hydj80_akPu3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root","tdj", jetSelCut && centCut && "pthat>=80&&pthat<9999", 3.069e-5*1.e9);
    // pyquen+hydjet
    dj->addFile("../ntout/jskim_hydj80quenwide_akPu3PF_Jan26_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=80&&pthat<100",9.913e-5*1.e9);
    dj->addFile("../ntout/jskim_hydj100quenwide_akPu3PF_Jan26_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm1bin0_akPu3PF_gj0.root", "tdj", jetSelCut && centCut && "pthat>=100&&pthat<9999",3.069e-5*1.e9);
  } else if ( dataset == kPPDATA) {
    // dj->addFile(Form("../ntout/jskim_pp-full_ak3PF_Dec5newsmgt60steps_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0.root",icent),
    // dj->addFile(Form("../ntout/jskim_pp-full_ak3PF_Jan16_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0_addedReweight.root",icent),
    // dj->addFile(Form("../ntout/jskim_pp-full_ak3PF_Jan16_4bin_sm18_seed2_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0.root",icent),
    dj->addFile(Form("../ntout/jskim_pp-full_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0_addedReweight.root",icent),
    // dj->addFile(Form("../ntout/jskim_pp-full_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0_addedFitRewt.root",icent),
    "tdj", jetSelCut, 1); // no centrality cut
  } else if ( dataset == kPPMC) {
    // dj->addFile(Form("../ntout/jskim_dj80_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm0bin0_ak3PF_gj0.root"),"tdj", jetSelCut && "pthat>=80&&pthat<9999", 9.913e-5*1.e9); // no centrality cut
    // dj->addFile(Form("../ntout/jskim_dj50_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm0bin0_ak3PF_gj0.root"),"tdj", jetSelCut && "pthat>=50&&pthat<80", 1.021e-3*1.e9); // no centrality cut
    dj->addFile(Form("../ntout/jskim_dj80_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0.root",icent),"tdj", jetSelCut && "pthat>=80&&pthat<120", 9.913e-5*1.e9); // no centrality cut
    dj->addFile(Form("../ntout/jskim_dj120_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0.root",icent),"tdj", jetSelCut && "pthat>=120&&pthat<9999", 1.128e-5*1.e9); // no centrality cut
    // dj->addFile(Form("../ntout/jskim_dj80_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0.root",icent),"tdj", jetSelCut, 1); // no centrality cut
    // dj->addFile(Form("../ntout/jskim_dj80_ak3PF_Jan17_4bin_sm18_jetPt_60_jetEtaCut_2.00_noPbin_sm2bin%d_ak3PF_gj0_addedReweight.root",icent),"tdj", jetSelCut, 1); // no centrality cut
  }
  // pthat scaling normalization
  if ( dataset == kHIMC || dataset == kPPMC) dj->NormalizeScales(2,"","hEvtCentNoSkim");
  
  // Friend Trees
  dj->AddFriend("yTrk=yongsunTrack");
//   dj->AddFriend("mTrk");
  if ( (doClosure > 0) && ( doClosure != 100 ) && doClosure!=200 && doClosure!=210 && doClosure!=240 && doClosure!=250) {
    dj->AddFriend("genPar");
//     dj->AddFriend("mGenPar");
  }
  dj->SetAlias("finalJetPt","jetPt");
  // dj->SetAlias("finalJetPt","(jetPt*(0.935+0.065*cBin/40.))"); // systematic check for uncertainty in jes
  cout << "finalJetPt = " << dj->trees_[0]->GetAlias("finalJetPt") << endl;
  
  cout << " ================================================= " << endl;
  cout << " working on dataset, icent, irj = " << datasetName << ", "<<icent<<", "<<irj<<endl;
  cout << " doClosure: " << doClosure << " rewtJet: " << rewtJet << endl;
  cout << " ================================================= " << endl;

  ////////////////////////////////////////////////////////  
  // Draw From Tree
  ////////////////////////////////////////////////////////  
  dj->Draw(hjetPt, "finalJetPt" ,jet1Cut.Data() ,jetRewt);
  
  double NoE1 = hjetPt->Integral();
  
  ////////////////////////////////////////////////////////  
  // Track Selection
  ////////////////////////////////////////////////////////  
  TString trkCutJet1 = Form("yTrk.jetMatch==1 && yTrk.jetDr<%.2f && yTrk.pt>%.2f && yTrk.pt<%.2f", jetDrCut,trackPtMin,trackPtMax);
  TString bkgTrkCutJet1;
  if (doClosure==0) {
    bkgTrkCutJet1 = Form("mTrk.jetMatch==1 && mTrk.jetDr<%.2f && mTrk.pt>%.2f && mTrk.pt<%.2f", jetDrCut,trackPtMin,trackPtMax);
  } else if (doClosure==100) {
    bkgTrkCutJet1 = Form("yTrk.jetMatch==-1 && yTrk.jetDr<%.2f && yTrk.pt>%.2f && yTrk.pt<%.2f", jetDrCut,trackPtMin,trackPtMax);
  } else if (doClosure==1 || doClosure==101) {
    trkCutJet1    = Form("(abs(genPar.chg)>0) && (genPar.jetMatch==1) && (genPar.jetDr<%.2f) && (genPar.pt>%.2f && genPar.pt<%.2f)", jetDrCut,trackPtMin,trackPtMax);
    bkgTrkCutJet1 = Form("(genPar.sube!=0) && (abs(genPar.chg)>0) && (genPar.jetMatch==1) && (genPar.jetDr<%.2f) && (genPar.pt>%.2f && genPar.pt<%.2f)", jetDrCut,trackPtMin,trackPtMax);
  } else if (doClosure==102) {
    trkCutJet1    = Form("(abs(genPar.chg)>0) && (genPar.jetMatch==1) && (genPar.jetDr<%.2f) && (genPar.pt>%.2f && genPar.pt<%.2f)", jetDrCut,trackPtMin,trackPtMax);
    bkgTrkCutJet1 = Form("(abs(genPar.chg)>0) && (genPar.jetMatch==-1) && (genPar.jetDr<%.2f) && (genPar.pt>%.2f && genPar.pt<%.2f)", jetDrCut,trackPtMin,trackPtMax);
  } else if (doClosure ==2) {
    trkCutJet1    = Form("(abs(genPar.chg)>0) && (genPar.jetMatch==1) && (genPar.jetDr<%.2f) && (genPar.pt>%.2f && genPar.pt<%.2f)", jetDrCut,trackPtMin,trackPtMax);
    bkgTrkCutJet1 = Form("(abs(mGenPar.chg)>0) && (mGenPar.jetMatch==1) && (mGenPar.jetDr<%.2f) && (mGenPar.pt>%.2f && mGenPar.pt<%.2f)", jetDrCut,trackPtMin,trackPtMax);
  }

  ////////////////////////////////////////////////////////  
  // Track Weights
  ////////////////////////////////////////////////////////  
  TString trackWeight[3];
  TString matchedTrackWeight[3];
  TString genpWeight[3];
  // initialize
  for (int j=0; j<3; ++j) {
    // trackWeight[j] = jetRewt;
    // matchedTrackWeight[j] = jetRewt;
    trackWeight[j] = jetRewt+"*(yTrk.trkWeight*(yTrk.trkWeight<3.5)+1.47*(yTrk.trkWeight>=3.5))";
    matchedTrackWeight[j] = jetRewt+"*(mTrk.trkWeight*(mTrk.trkWeight<3.5)+1.47*(mTrk.trkWeight>=3.5))";
    genpWeight[j] = jetRewt;
    if (weightMode==1) {
      trackWeight[j]+="*yTrk.pt*";
      matchedTrackWeight[j]+="*mTrk.pt";
      genpWeight[j] += "*genPar.pt";
    } else if (weightMode==2) {
      trackWeight[j]+="*yTrk.pt/finalJetPt";
      matchedTrackWeight[j]+="*mTrk.pt/finalJetPt";
      genpWeight[j] += "*genPar.pt/finalJetPt";
    }
  }

  for (int j=0; j<1; ++j) {
    if ( fragMode   == 1 ) {
      if (doClosure == 0) {
        dj->Draw(htrkPt[j][kRAW],"yTrk.pt",    Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), trackWeight[j] );
        dj->Draw(htrkPt[j][kBKG],"mTrk.pt",    Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), matchedTrackWeight[j]);
      }
      else if ( doClosure == 100 ) {
        dj->Draw(htrkPt[j][kRAW],"yTrk.pt",    Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), trackWeight[j]);
        dj->Draw(htrkPt[j][kBKG], "yTrk.pt",   Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), trackWeight[j]);
      } 
      else if ( doClosure == 1 || doClosure == 101 || doClosure == 102) {
        dj->Draw(htrkPt[j][kRAW], "genPar.pt", Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), genpWeight[j]);
        dj->Draw(htrkPt[j][kBKG], "genPar.pt", Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), genpWeight[j]);
      }
//       else if ( doClosure == 2 ) {
//         dj->Draw(htrkPt[j][kRAW], "genPar.pt", Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), genpWeight[j]);
//         dj->Draw(htrkPt[j][kBKG], "mGenPar.pt",Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), genpWeight[j]);
//       }
    } else if ( fragMode   == 2 ) {
      if (doClosure == 0) {
        dj->Draw(htrkPt[j][kRAW],"-log(yTrk.pt * cos(yTrk.jetDr)  *(cosh(yTrk.eta)/cosh(jetEta)) /finalJetPt )",
          Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), trackWeight[j]);
        dj->Draw(htrkPt[j][kBKG],"-log(mTrk.pt * cos(mTrk.jetDr) * (cosh(mTrk.eta)/cosh(jetEta)) /finalJetPt )",
          Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), matchedTrackWeight[j]);
      }
      else if ( doClosure == 100 ) {
        dj->Draw(htrkPt[j][kRAW],"-log(yTrk.pt * cos(yTrk.jetDr) *(cosh(yTrk.eta)/cosh(jetEta)) /finalJetPt)",
          Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), trackWeight[j]);
        dj->Draw(htrkPt[j][kBKG], "-log(yTrk.pt * cos(yTrk.jetDr) * (cosh(yTrk.eta)/cosh(jetEta)) /finalJetPt)",
          Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), trackWeight[j]);
      }
      else if ( doClosure == 1|| doClosure == 101 || doClosure == 102) {
        dj->Draw(htrkPt[j][kRAW], "-log( genPar.pt * cos(genPar.jetDr)  *(cosh(genPar.eta)/cosh(jetEta)) /finalJetPt)", Form("%s && %s",
          jet1Cut.Data(), trkCutJet1.Data()), genpWeight[j]);
        dj->Draw(htrkPt[j][kBKG], "-log( genPar.pt * cos(genPar.jetDr)  *(cosh(genPar.eta)/cosh(jetEta))  /finalJetPt)", Form("%s && %s",
          jet1Cut.Data(), bkgTrkCutJet1.Data()), genpWeight[j]);
      }
//       else if ( doClosure == 2 ) {
//         dj->Draw(htrkPt[j][kRAW], "-log( genPar.pt * cos(genPar.jetDr)  *(cosh(genPar.eta)/cosh(jetEta)) /finalJetPt)", Form("%s && %s",
//           jet1Cut.Data(), trkCutJet1.Data()), genpWeight[j]);
//         dj->Draw(htrkPt[j][kBKG], "-log(mGenPar.pt * cos(mGenPar.jetDr)  *(cosh(mGenPar.eta)/cosh(jetEta)) /finalJetPt)", Form("%s && %s",
//           jet1Cut.Data(), bkgTrkCutJet1.Data()), genpWeight[j]);
//       }
    }
    // Rockets!
//     else if ( fragMode   == 10 ) {
//       if (doClosure <= 0) {
//         dj->Draw(htrkPt[j][kRAW],"yTrk.jetDr",    Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), trackWeight[j]);
//         dj->Draw(htrkPt[j][kBKG],"mTrk.jetDr",    Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), matchedTrackWeight[j]);
//       }
//       else if ( doClosure == 100 ) {
//         dj->Draw(htrkPt[j][kRAW],"yTrk.jetDr",    Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), trackWeight[j]);
//         dj->Draw(htrkPt[j][kBKG], "yTrk.jetDr",   Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), trackWeight[j]);
//       } 
//       else if ( doClosure == 1 || doClosure == 101 || doClosure == 102) {
//         dj->Draw(htrkPt[j][kRAW], "genPar.jetDr", Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), genpWeight[j]);
//         dj->Draw(htrkPt[j][kBKG], "genPar.jetDr", Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), genpWeight[j]);
//       }
//       else if ( doClosure == 2 ) {
//         dj->Draw(htrkPt[j][kRAW], "genPar.jetDr", Form("%s && %s", jet1Cut.Data(), trkCutJet1.Data()), genpWeight[j]);
//         dj->Draw(htrkPt[j][kBKG], "mGenPar.jetDr",Form("%s && %s", jet1Cut.Data(), bkgTrkCutJet1.Data()), genpWeight[j]);
//       }  
//     }

    // Normalize Histograms
    if (fragMode<10) {
       TH1ScaleByWidth(htrkPt[j][kRAW]);
       TH1ScaleByWidth(htrkPt[j][kBKG]);
    }
    // Signal
    htrkPt[j][kRAW]->Scale(1./NoE1);
    // Background
    if ( (doClosure == 1)  || (doClosure>99) ) {
      htrkPt[j][kBKG]->Scale(1./(NoE1));
    }
    else {
      htrkPt[j][kBKG]->Scale(1./(NoE1*nMixing1));
    }
    htrkPt[j][kSIG]->Add(htrkPt[j][kRAW]);
    htrkPt[j][kSIG]->Add(htrkPt[j][kBKG],-1);
    handsomeTH1(htrkPt[j][kRAW],1,1,24);
    handsomeTH1(htrkPt[j][kBKG],1);
    handsomeTH1(htrkPt[j][kSIG],1,1,20);
  }

  // Inspect
  TCanvas* c1 = new TCanvas(Form("c1_icent%d_irj%d",icent,irj),"",900,450);
  int iJetInsp=0;
  c1->Divide(2,1);
  c1->cd(1);
  if (fragMode<10) {
    gPad->SetLogy();
    htrkPt[iJetInsp][kRAW]->SetAxisRange(1e-5,10000,"Y");
  } else {
    gPad->SetLogy();
    if (weightMode==0) htrkPt[iJetInsp][kRAW]->SetAxisRange(1e-4,100,"Y");
    if (weightMode==1) htrkPt[iJetInsp][kRAW]->SetAxisRange(1e-4,1e5,"Y");
    if (weightMode==2) htrkPt[iJetInsp][kRAW]->SetAxisRange(1e-4,10,"Y");
  }
  htrkPt[iJetInsp][kRAW]->Draw();
  htrkPt[iJetInsp][kBKG]->Draw("same hist");
  htrkPt[iJetInsp][kSIG]->Draw("same");
  TLegend* l1 = new TLegend(0.3678213,0.7702352,0.9162483,0.9296714,NULL,"brNDC");
  easyLeg(l1,clsText_.Data()) ;
  l1->AddEntry(htrkPt[iJetInsp][kRAW],"All tracks in jet cone","p");
  l1->AddEntry(htrkPt[iJetInsp][kBKG], "tracks from underlying events","l");
  l1->AddEntry(htrkPt[iJetInsp][kSIG], "After subtraction","p");
  l1->Draw();
  drawText("jet p_{T} > 100GeV/c,  |#eta|<2", 0.26,0.3,1,17);
  drawText(Form("%d jets",(int)hjetPt->GetEntries()), 0.26,0.23,1,17);
  if ( fragMode   == 1 )      gPad->SetLogx();
  
  if       ( dataset == kHIDATA) 
    drawText("PbPb DATA", 0.2,0.8,1,15);
  else  if ( dataset == kHIMC)
    drawText("MC", 0.2,0.8,1);
  else if ( dataset == kPPDATA)
    drawText("pp DATA", 0.2,0.8,1,15);
  else if ( dataset == kPPMC)
    drawText("pp MC", 0.2,0.8,1,15);
  
  if ( (icent>=1) && (icent<=4) ) {
    int lowCent = centBin1[icent-1];
    int highCent = centBin1[icent]-1;
    drawText(Form("%.0f%% - %.0f%%", float((float)lowCent*2.5), float((float)(highCent+1)*2.5)), 0.2,0.73,1);
  }
  if ( (irj>=1) && (irj<=4) ) {
    drawText("0-30%", 0.2,0.73,1);
    drawText(Form("%.2f < pt_{2}/pt_{1} < %.2f             %.0f < p_{T}^{track} < %.0f", float(rjBin1[irj-1]), float(rjBin1[irj]),trackPtMin,trackPtMax), 0.2,0.66,1);    
  }
  if (fragMode==10) {
    drawText(Form("%.0f < p_{T}^{track} < %.0f GeV/c", trackPtMin,trackPtMax), 0.5,0.66,1);
  }
  c1->cd(2);
  cleverRange(hjetPt,10,1e-1);
  handsomeTH1(hjetPt,1);
  hjetPt->Draw();
  gPad->SetLogy();
  drawText("Jet p_{T}", 0.55,0.63,1);
  
  TString outnameTag=Form("trackPtCut%.0f_FinalJetPt%.0fto%.0feta%.2f_Jan17mcquenwide80and100_hi",ptranges[0],finalJetPtMin,finalJetPtMax,finalEtaCut);

  if ( fragMode==2) {
    c1->SaveAs(Form("plotsOfInclJetFF/inclJetFF_xi_doClosure%d_icent%d_irj%d_%s_%s%s_%s.pdf",doClosure,icent,irj,datasetName.Data(),clsText.Data(),tag.Data(),outnameTag.Data()));
  }
  else if ( fragMode==1) {
    c1->SaveAs(Form("plotsOfInclJetFF/inclJetFF_pt_doClosure%d_icent%d_irj%d_%s_%s%s_%s.pdf",doClosure,icent,irj,datasetName.Data(),clsText.Data(),tag.Data(),outnameTag.Data()));
  }
  else if ( fragMode==10) {
    c1->SaveAs(Form("plotsOfInclJetFF/inclJetFF_dr_pt%.0fto%.0f_doClosure%d_wtMode%d_icent%d_irj%d_%s_%s%s_%s.pdf",trackPtMin,trackPtMax,doClosure,weightMode,icent,irj,datasetName.Data(),clsText.Data(),tag.Data(),outnameTag.Data()));
  }

  // All Done, write output  
  TFile outf = TFile(Form("inclJetFF_output_%s.root",outnameTag.Data()),"update");
  hjetPt->Write();
  htrkPt[0][kRAW]->Write();
  htrkPt[0][kSIG]->Write();
  htrkPt[0][kBKG]->Write();
  outf.Close();

  // clean up
  delete dj;
}
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");
}
void systErrCal(){
    gStyle -> SetOptStat(0);
    const int nPt = 4;
    const int nPurity = 3; // 
    double purity[nPurity] = {0.9, 1., 1.1} ;// purity*0.9 and so on.. 
    double AvePtBin[nPt+1] = {45.0, 55.0, 70.0, 100.0};
    double ptBin[nPt+1] = {40,50,60,80,9999};
    double ptBinPaDraw[nPt+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;

    const int nCentBinHI = 2;
    const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099}; 

    TH1D* hxjg10[7][10][6]; // [species][centrality][pt_dependence]
    TH1D* hxjg09[7][10][6]; // [species][centrality][pt_dependence]
    TH1D* hxjg11[7][10][6]; // [species][centrality][pt_dependence]
    TH1D* hJetPt10[7][10][6];
    TH1D* hJetPt09[7][10][6];
    TH1D* hJetPt11[7][10][6];
    TH1D* meanXjg[7][10][nPurity+1];      // [Collision][centrality][purity]
    TH1D* meanJetPt[7][10][nPurity+1];      // [Collision][centrality]
    TH1D* rjg[7][5][nPurity+1];     //  [Collision][centrality]

    for (int icoll=0 ; icoll<6  ; icoll++) {
        for (int icent=1 ; icent<= 10 ; icent++) {
            for(int ipu=0 ; ipu<nPurity ; ipu++) {
                meanXjg[icoll][icent][ipu] = new TH1D( Form("meanXjg_icoll%d_icent%d_ipu%d",icoll,icent,ipu), ";p_{T}^{#gamma} (GeV); <X_{J#gamma}>",nPt,ptBinPaDraw);
                meanJetPt[icoll][icent][ipu] = new TH1D( Form("meanJetPt_icoll%d_icent%d_ipu%d",icoll,icent,ipu), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPt,ptBinPaDraw);
                rjg[icoll][icent][ipu]= new TH1D( Form("rjg_icoll%d_icent%d_ipu%d",icoll,icent,ipu), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPt,ptBinPaDraw);
                for (int ipt=1 ; ipt<=nPt ; ipt++) {
                    hxjg10[icoll][icent][ipt] = NULL;
                    hxjg09[icoll][icent][ipt] = NULL;
                    hxjg11[icoll][icent][ipt] = NULL;
                    hJetPt10[icoll][icent][ipt] = NULL;
                    hJetPt09[icoll][icent][ipt] = NULL;
                    hJetPt11[icoll][icent][ipt] = NULL;
                }
            }
        }
    }
//    cout << "dlfja " << endl;
    
    TFile* histFile[7][6][nPurity+1];  // [Collision][pt]                                                                                      

    for (int ipt=1 ; ipt<=nPt ; ipt++) {
        for (int icoll=0 ; icoll<6 ; icoll++) {
            for (int ipu=0 ; ipu < nPurity ; ipu++) {
                TString sampleName = getSampleName( icoll ) ;
                char* fname = "";
                if (ipu==1) {fname =  Form("./ffFiles/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20130909_purity09.root",sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt]);
                } else if (ipu==0) {fname =  Form("./ffFiles/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20130909.root",sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt]);
                } else {fname =  Form("./ffFiles/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20130909_purity1.1.root",sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt]);
                }
                histFile[icoll][ipt][ipu] = new TFile(fname) ;
    //               cout << " Reading file : " << fname << endl;

                if ( histFile[icoll][ipt][ipu]->IsZombie()  == false ) {
      //                 cout << " Success." << endl;
                    if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
                        int icent = 7 ; 
                        if (ipu==0) { hxjg10[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("xjg_icent%d_final", icent)) ;
                                        hJetPt10[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("jetPt_icent%d_final", icent)) ;
                        } else if (ipu==1) {hxjg09[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("xjg_icent%d_final", icent)) ;
                                        hJetPt09[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("jetPt_icent%d_final", icent)) ;
                        } else { hxjg11[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("xjg_icent%d_final", icent)) ;
                                        hJetPt11[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("jetPt_icent%d_final", icent)) ;
                        }
  //                      cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
  //                      cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
                    }
                
                    if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
                        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
                            if (ipu==0) { hxjg10[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
                                            hJetPt10[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
                            } else if (ipu==1) { hxjg09[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
                                            hJetPt09[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
                            } else { hxjg11[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
                                    hJetPt11[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt][ipu]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
                            }
                            //  cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
                            //  cout << " Getting histogram : " << Form("xjg_icent%d_final", centBinHI[icent] ) << endl;
                        histFile[icoll][ipt][ipu] -> Close();
                        }
                    }
                }
                else  
                    cout << " no such file " << endl;
            }
        }
    }

    for (int ipt=1 ; ipt<=nPt ; ipt++) {
        for (int icoll=0 ; icoll<6 ; icoll++) {
            for (int icent=1 ; icent<= 10 ; icent++ ) { 
                for (int ipu=0 ; ipu< nPurity ; ipu++ ) { 
                    if ( (hxjg10[icoll][icent][ipt] == NULL) && (hxjg09[icoll][icent][ipt] == NULL) && (hxjg11[icoll][icent][ipt] == NULL) ) 
                        continue;   // emtpy histogram 
                    double rVal, rErr;

                    if (ipu==0) rVal = hxjg10[icoll][icent][ipt]->IntegralAndError(1, hxjg10[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
                    else if (ipu==1) rVal = hxjg09[icoll][icent][ipt]->IntegralAndError(1, hxjg09[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
                    else rVal = hxjg11[icoll][icent][ipt]->IntegralAndError(1, hxjg11[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
                    rjg[icoll][icent][ipu]->SetBinContent( ipt, rVal );
                    rjg[icoll][icent][ipu]->SetBinError  ( ipt, rErr );
                    cout << "ipt : " << ipt << " icoll : " << icoll << " icent : " << icent << " ipu : " << ipu << " rVal : " << rVal << endl;            
                    if (ipu==0){
                        meanXjg[icoll][icent][ipu]->SetBinContent( ipt, hxjg10[icoll][icent][ipt]->GetMean() );
                        meanXjg[icoll][icent][ipu]->SetBinError  ( ipt, hxjg10[icoll][icent][ipt]->GetMeanError() );
                        meanJetPt[icoll][icent][ipu]->SetBinContent( ipt, hJetPt10[icoll][icent][ipt]->GetMean() );
                        meanJetPt[icoll][icent][ipu]->SetBinError  ( ipt, hJetPt10[icoll][icent][ipt]->GetMeanError() );
                    }else if (ipu==1){
                        meanXjg[icoll][icent][ipu]->SetBinContent( ipt, hxjg09[icoll][icent][ipt]->GetMean() );
                        meanXjg[icoll][icent][ipu]->SetBinError  ( ipt, hxjg09[icoll][icent][ipt]->GetMeanError() );
                        meanJetPt[icoll][icent][ipu]->SetBinContent( ipt, hJetPt09[icoll][icent][ipt]->GetMean() );
                        meanJetPt[icoll][icent][ipu]->SetBinError  ( ipt, hJetPt09[icoll][icent][ipt]->GetMeanError() );
                    } else {
                        meanXjg[icoll][icent][ipu]->SetBinContent( ipt, hxjg11[icoll][icent][ipt]->GetMean() );
                        meanXjg[icoll][icent][ipu]->SetBinError  ( ipt, hxjg11[icoll][icent][ipt]->GetMeanError() );
                        meanJetPt[icoll][icent][ipu]->SetBinContent( ipt, hJetPt11[icoll][icent][ipt]->GetMean() );
                        meanJetPt[icoll][icent][ipu]->SetBinError  ( ipt, hJetPt11[icoll][icent][ipt]->GetMeanError() );
                    } 
                }
            }
        }
    }
    
    TLegend *ly = new TLegend(0.4913112,0.6561548,0.9997611,0.9431145,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[kPPDATA][7][1],"pp ","p");
    ly->AddEntry(meanJetPt[kHIDATA][2][1],"PbPb 0-30%","p");

    TLegend *l1 = new TLegend(0.4913112,0.6561548,0.9997611,0.9431145,NULL,"brNDC");
    easyLeg(l1,"2.76TeV");
    l1->AddEntry(meanJetPt[kPPDATA][7][1],"pp ","p");
    l1->AddEntry(meanJetPt[kHIDATA][1][1],"PbPb 30-100%","p");
    l1->AddEntry(meanJetPt[kHIDATA][2][1],"PbPb 0-30%","p");


    TCanvas* cJetpt = new TCanvas("c21","",500,500);
    for(int ipu=0; ipu<nPurity; ipu++){
        handsomeTH1(meanJetPt[kPPDATA][7][ipu]);
        if (ipu==0){
            meanJetPt[kPPDATA][7][ipu]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
            //  meanJetPt[kPPDATA][7][ipu]->SetAxisRange(-2,2,"X");
            meanJetPt[kPPDATA][7][ipu]->SetAxisRange(30,95,"Y");
            meanJetPt[kPPDATA][7][ipu]->Draw();
        } else { 
            meanJetPt[kPPDATA][7][ipu]->Draw("same");
        }

    //    meanJetPt[kPPDATA][7][ipu]->SetMarkerStyle(24);
        meanJetPt[kPPDATA][7][ipu]->SetMarkerColor(kTeal+ipu);
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(meanJetPt[kHIDATA][icent][ipu]);
            if ( icent == 2 ) meanJetPt[kHIDATA][icent][ipu]->SetMarkerStyle(24);
            //if ( icent != 2 ) meanJetPt[kHIDATA][icent]->Draw("same");
            meanJetPt[kHIDATA][icent][ipu]->Draw("same");
        }
    }

    l1 ->Draw();

    TCanvas* cXjg = new TCanvas("c31","",500,500);
    for(int ipu=0; ipu<nPurity; ipu++){
        handsomeTH1(meanXjg[kPPDATA][7][ipu]);
        if (ipu==0){
            meanXjg[kPPDATA][7][ipu]->SetYTitle("<x_{J#gamma}>  (>30GeV)");
            meanXjg[kPPDATA][7][ipu]->SetMarkerStyle(24);
            //  meanXjg[kPPDATA][7]->SetAxisRange(-2,2,"X");
            meanXjg[kPPDATA][7][ipu]->SetAxisRange(0.6,1.2,"Y");
            meanXjg[kPPDATA][7][ipu]->Draw();
        } else {
            meanXjg[kPPDATA][7][ipu]->Draw("same");
        }

        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(meanXjg[kHIDATA][icent][ipu]);
            if ( icent == 2 ) meanXjg[kHIDATA][icent][ipu]->SetMarkerStyle(24);
            //if ( icent != 2 ) meanXjg[kHIDATA][icent]->Draw("same");
            meanXjg[kHIDATA][icent][ipu]->Draw("same");
        }
    }
    l1->Draw();

    TCanvas* cRjg = new TCanvas("c_rjg","",500,500);

    for(int ipu=0; ipu<nPurity; ipu++){
        handsomeTH1(rjg[kPPDATA][7][ipu]);
        if (ipu==0){
            rjg[kPPDATA][7][ipu]->SetYTitle("r_{J#gamma}");
            rjg[kPPDATA][7][ipu]->SetMarkerStyle(24);
            //  rjg[kPPDATA][7]->SetAxisRange(-2,2,"X");
            rjg[kPPDATA][7][ipu]->SetAxisRange(0.0,1.1,"Y");
            rjg[kPPDATA][7][ipu]->Draw();
        } else {
            rjg[kPPDATA][7][ipu]->Draw("same");
        }

        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(rjg[kHIDATA][icent][ipu],kRed);
            if ( icent == 2 ) rjg[kHIDATA][icent][ipu]->SetMarkerStyle(24);
            //       if ( icent != 2 ) rjg[kHIDATA][icent]->Draw("same");
            rjg[kHIDATA][icent][ipu]->Draw("same");
        }
    }
    ly->Draw();

}
void drawPhotonSpec(){
  


  TH1::SetDefaultSumw2();
  
  TFile* f1 = new TFile("/mnt/hadoop/cms/store/user/luck/2014-photon-forests/pPb_DATA_photon30trig_localJEC_v1.root");
  TTree* photon = (TTree*)f1->Get("multiPhotonAnalyzer/photon");
  TTree* hlt    = (TTree*)f1->Get("hltanalysis/HltTree");
  hlt->SetName("hlt");
  photon->AddFriend(hlt);
  
  TH1D* h1 = new TH1D("h1",";p_{T} of photon;Entries (Arb. Norm.)",200,0,200);
  // TCut ccut = "abs(eta)<1.44 && hlt.HLT_PAPhoton20_NoCaloIdVL_v1 && hadronicOverEm<0.1";
  TCut ccut = "abs(eta)<1.44 && hadronicOverEm<0.1";
  photon->Draw("pt>>h1",ccut);
  TH1D* h2 = (TH1D*)h1->Clone("h2");
  photon->Draw("pt>>h2",ccut && "!isEle");

  TCut isocut = "sigmaIetaIeta<0.011 && ecalRecHitSumEtConeDR04<4.2 && hcalTowerSumEtConeDR04< 2.2 && trkSumPtHollowConeDR04 <2";

  TH1D* h3 = (TH1D*)h1->Clone("h3");
  photon->Draw("pt>>h3",ccut && isocut);
  
  TH1D* h4 = (TH1D*)h1->Clone("h4");
  photon->Draw("pt>>h4",ccut && isocut && "!isEle");

  
  handsomeTH1(h1,1);
  handsomeTH1(h2,2);
  handsomeTH1(h3,1);
  handsomeTH1(h4,2);
  

  TCanvas* c1 = new TCanvas("c1","",1000,500);
  c1->Divide(2,1);
  c1->cd(1);
  //h1->SetAxisRange(0.5, 80000,"Y");
  h1->Draw("hist" );
  h2->Draw("same hist");

  TLegend *l1 = new TLegend(0.6365615,0.6445304,0.9577623,0.846736,NULL,"brNDC");
  easyLeg(l1,"5.02TeV pA Data");
  l1->SetTextFont(43);
  l1->SetTextSize(16);
  l1->Draw();
  TLegend *l2 = new TLegend(0.6365615,0.4445304,0.9577623,0.646736,NULL,"brNDC");
  easyLeg(l2,"Barrel photons H/E<0.1");
  l2->SetTextFont(43);
  l2->SetTextSize(16);
  l2->AddEntry(h1, "All");
  l2->AddEntry(h2, "Electrons excluded");
  l2->Draw();

  
  c1->cd(2);
  //h3->SetAxisRange(0.5, 2500,"Y");
  h3->Draw("hist");
  h4->Draw("same hist");
  TLegend *l3 = new TLegend(0.6365615,0.4445304,0.9577623,0.646736,NULL,"brNDC");
  easyLeg(l3,"Isolated photons");
  l3->SetTextFont(43);
  l3->SetTextSize(16);
  l3->AddEntry(h3, "All");
  l3->AddEntry(h4, "Electrons excluded");
  l3->Draw();

  
}
void drawSys_merged() {
  //  TH1::SetDefaultSumw2();
    gStyle -> SetOptStat(0);
    const int kPPcentral = 1;
    const int kPPperipheral =2 ;
    const int kHIcentral =  3;
    const int kHIperipheral = 4;
    const int kPADATA = 5;
    const int kPAMC = 6;

  TH1D* dNdJetPt[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* dNdJetPtSys[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* dNdJetPtSysIaa[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* meanJetPt[7];   // [collision] [Before/After variation]
  TH1D* meanJetPtSys[7];   // [collision] [Before/After variation]
  TH1D* meanRjg[7];
  TH1D* meanRjgSys[7];
  
  TH1D* bmeanJetPt[7];   // [collision] [Before/After variation]
  TH1D* bmeanJetPtSys[7];   // [collision] [Before/After variation]
  TH1D* bmeanRjg[7];
  TH1D* bmeanRjgSys[7];
  
  TFile * f = new TFile("../resultHistograms_ppSmeared10030.root");
  bmeanJetPt[1]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  bmeanRjg[1]  =(TH1D*)f->Get(Form("meanRjg_pp"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[1][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pp_ptBin%d", ipt ));
  }  

  f   = new TFile("../resultHistograms_ppSmeared13099.root");
  bmeanJetPt[2]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  bmeanRjg[2]  =(TH1D*)f->Get(Form("meanRjg_pp"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[2][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pp_ptBin%d", ipt ));
  }  
  
  // pbpb
  f =   new TFile("../resultHistograms_jetResCorrection.root");
  bmeanJetPt[3]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin1"));
  bmeanRjg[3]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin1"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[3][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pbpb_centralityBin1_ptBin%d", ipt ));
  }
  bmeanJetPt[4]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin2"));
  bmeanRjg[4]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin2"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[4][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pbpb_centralityBin2_ptBin%d", ipt ));
  }
  // pPb
  f =   new TFile("../resultHistograms_jetResCorrection.root");
  bmeanJetPt[5]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  bmeanRjg[5]  =(TH1D*)f->Get(Form("meanRjg_ppb"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[5][ipt] = (TH1D*)f->Get(Form("dNdJetPt_ppb_ptBin%d", ipt ));
  }
  
  f =   new TFile("../resultHistograms_MC_recoIsoPhoton.root");
  bmeanJetPt[6]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  bmeanRjg[6]  =(TH1D*)f->Get(Form("meanRjg_ppb"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[6][ipt] = (TH1D*)f->Get(Form("dNdJetPt_ppb_ptBin%d", ipt ));
  }  
  
  
  TFile* fSys = new TFile("../merged/relativeSys_merged.root");
  
  bmeanJetPtSys[1]  =(TH1D*)fSys->Get("meanJetPt_pp_uncertainty_merged");
  bmeanRjgSys[1]  =(TH1D*)fSys->Get(Form("meanRjg_pp_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[1][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pp_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[2] = (TH1D*)bmeanJetPtSys[1]->Clone(Form("%s_2",bmeanJetPtSys[1]->GetName()));
  bmeanRjgSys[2] = (TH1D*)bmeanRjgSys[1]->Clone(Form("%s_2",bmeanRjgSys[1]->GetName()));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[2][ipt] = (TH1D*)dNdJetPtSysIaa[1][ipt]->Clone(Form("%s_2",dNdJetPtSysIaa[1][ipt]->GetName()));
  }
  bmeanJetPtSys[3]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin1_uncertainty_merged");
  bmeanRjgSys[3]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin1_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[3][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pbpb_centralityBin1_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[4]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin2_uncertainty_merged");
  bmeanRjgSys[4]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin2_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[4][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pbpb_centralityBin2_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[5]  =(TH1D*)fSys->Get("meanJetPt_ppb_uncertainty_merged");
  bmeanRjgSys[5]  =(TH1D*)fSys->Get(Form("meanRjg_ppb_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[5][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_ppb_ptBin%d_uncertainty_merged",  ipt ));
  }


  
  // transplant the uncertainty  
  for ( int coll = 1 ; coll<=5 ; coll++) {
    for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
      dNdJetPtSys[coll][ipt] = (TH1D*) dNdJetPt[coll][ipt]->Clone(Form("dNdJetPtSys_coll%d_ipt%d",coll,ipt));
      dNdJetPtSys[coll][ipt]->Reset();
      for ( int ibin = 1 ; ibin<= dNdJetPtSys[coll][ipt]->GetNbinsX() ; ibin++) {
	float xx = dNdJetPtSys[coll][ipt]->GetBinCenter(ibin);
	float yy = dNdJetPtSysIaa[coll][ipt]->GetBinContent ( dNdJetPtSysIaa[coll][ipt]->FindBin(xx) );
	if ( yy>1 ) yy = 1;
	dNdJetPtSys[coll][ipt]->SetBinContent(ibin,yy);

      }
    }
  }

  for(int icoll=1; icoll<=6; icoll++){
      meanJetPt[icoll] = new TH1D(Form("%s_corrected", bmeanJetPt[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      meanRjg[icoll] = new TH1D(Form("%s_corrected", bmeanRjg[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      if(icoll<6){
          meanJetPtSys[icoll] = new TH1D(Form("%s_corrected", bmeanJetPtSys[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
          meanRjgSys[icoll] = new TH1D(Form("%s_corrected", bmeanRjgSys[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      }
  }

  for(int icoll=1; icoll<=6; icoll++){ 
      meanPtHist(bmeanJetPt[icoll], meanJetPt[icoll]);    
      meanPtHist(bmeanRjg[icoll],  meanRjg[icoll]); 
      if(icoll<6){
          meanPtHist(bmeanJetPtSys[icoll],meanJetPtSys[icoll]) ;  
          meanPtHist(bmeanRjgSys[icoll], meanRjgSys[icoll]); 
      }
  } 

  // RJG!!
  TCanvas* c2 = new TCanvas("c1","",1000,500);
  c2->Divide(2,1);
  c2->cd(2);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempR = new TH1D("tempR",";p_{T}^{#gamma};R_{j#gamma}",100,40,130);
  tempR->Reset();  
  handsomeTH1(tempR,0);
  tempR->SetAxisRange(0,1.2,"Y");
  tempR->Draw();
  drawSys(meanRjg[1], meanRjgSys[1], kGreen);
  drawSys(meanRjg[3], meanRjgSys[3]);
  meanRjg[1]->Draw("same");
  handsomeTH1(meanRjg[3],2 );
//  meanRjg[3]->SetMarkerStyle(24);
  meanRjg[3]->Draw("same");
  if ( 1==1 ){ 
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");    
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanRjg[3],"PbPb 0-30%","p");
    ly->AddEntry(meanRjg[1],"pp (smeared)","p");
    ly->Draw();
  }


  c2->cd(1);
  tempR->Draw();
  handsomeTH1(meanRjg[2],1 );
  drawSys(meanRjg[2], meanRjgSys[2], kGreen);
  drawSys(meanRjg[4], meanRjgSys[4]);
  meanRjg[2]->Draw("same");
  handsomeTH1(meanRjg[4],2 );
  meanRjg[4]->SetMarkerStyle(24);
  meanRjg[4]->Draw("same");
  if ( 1==1 ){ 
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");    
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanRjg[4],"PbPb 30-100%","p");
    ly->AddEntry(meanRjg[2],"pp (smeared)","p");
    ly->Draw();
  }
  c2->SaveAs("pT_depedence_rjg_pp_pbpb.pdf");

  
  TCanvas* c2pa = new TCanvas("c1pa","",500,500);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)                         
  //  tempR->Draw();
  TH1D* tempJ = new TH1D("tempJ",";p_{T}^{#gamma}; <p_{T}^{Jet}>",100,40,130);
  tempJ->Reset();
  handsomeTH1(tempJ,0);
  tempJ->SetAxisRange(0,100,"Y");
  tempJ->Draw();
  drawSys(meanJetPt[5], meanJetPtSys[5], kYellow);
  handsomeTH1(meanJetPt[5],2);
  handsomeTH1(meanJetPt[6],1);
  meanJetPt[5]->Draw("same");
  meanJetPt[6]->Draw("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.4484643,0.3088445,0.9140673,0.50102941,NULL,"brNDC");
    easyLeg(ly,"5.02TeV pPb");
    ly->AddEntry(meanJetPt[5],"DATA","p");
    ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  c2pa->SaveAs("pT_dependence_rjg_pA_figure1.pdf");

  TCanvas* c3pa = new TCanvas("c3pa","",500,500);
  tempR->Draw();
  drawSys(meanRjg[5], meanRjgSys[5], kYellow);
  handsomeTH1(meanRjg[5],2);
  handsomeTH1(meanRjg[6],1);
  meanRjg[5]->Draw("same");
  meanRjg[6]->Draw("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.4484643,0.3088445,0.9140673,0.50102941,NULL,"brNDC");
    easyLeg(ly,"5.02TeV pPb");
    ly->AddEntry(meanRjg[5],"DATA","p");
    ly->AddEntry(meanRjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }  
  c3pa->SaveAs("pT_dependence_jetPt_pA_figure2.pdf");

  TCanvas* c3 = new TCanvas("c3","",1000,500);
  c3->Divide(2,1);
  c3->cd(2);
  handsomeTH1(meanJetPt[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)                                                       
   tempJ->Draw();
  drawSys(meanJetPt[1], meanJetPtSys[1], kGreen);
  drawSys(meanJetPt[3], meanJetPtSys[3]);
  meanJetPt[1]->Draw("same");
  handsomeTH1(meanJetPt[3],2 );
  meanJetPt[3]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[3],"PbPb 0-30%","p");
    ly->AddEntry(meanJetPt[1],"pp (smeared)","p");
    ly->Draw();
  }
  
  c3->cd(1);
  tempJ->Draw();
  handsomeTH1(meanJetPt[2],1 );
//  meanJetPt[2]->Draw();
  drawSys(meanJetPt[2], meanJetPtSys[2], kGreen);
  drawSys(meanJetPt[4], meanJetPtSys[4]);
  meanJetPt[2]->Draw("same");
  handsomeTH1(meanJetPt[4],2 );
  meanJetPt[4]->SetMarkerStyle(24);
  meanJetPt[4]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
    ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
    ly->Draw();
  }
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.pdf");
  
  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);
  TCanvas* c5 = new TCanvas("c5","",1200,700);
  makeMultiPanelCanvas(c5,nPtBin,2,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    c5->cd(ipt+nPtBin);
    // draw pp                                                                                                                                           
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");                                                                                                        
    hTempPt->SetAxisRange(0,0.07,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[1][ipt], dNdJetPtSys[1][ipt], kGreen);
    drawSys(dNdJetPt[3][ipt], dNdJetPtSys[3][ipt], kYellow);
    handsomeTH1(dNdJetPt[3][ipt],2);
    dNdJetPt[1][ipt]->Draw("same");
    dNdJetPt[3][ipt]->Draw("same");
    if ( ipt == 1 ) {
      TLegend *ly = new TLegend(0.4484643,0.6988445,0.9140673,0.9102941,NULL,"brNDC");
      easyLeg(ly,"2.76TeV");
      ly->AddEntry(meanJetPt[1],"PbPb 0-30%","p");
      ly->AddEntry(meanJetPt[3],"pp (smeared)","p");
      ly->Draw();
    }
 

    c5->cd(ipt);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[2][ipt], dNdJetPtSys[2][ipt], kGreen);
    drawSys(dNdJetPt[4][ipt], dNdJetPtSys[4][ipt], kYellow);
    handsomeTH1(dNdJetPt[4][ipt],2);
    dNdJetPt[4][ipt]->SetMarkerStyle(24);
    dNdJetPt[2][ipt]->Draw("same");
    dNdJetPt[4][ipt]->Draw("same");
    if ( ipt==1 ){
      TLegend *ly = new TLegend(0.4484643,0.5088445,0.9140673,0.75102941,NULL,"brNDC");
      easyLeg(ly,"2.76TeV");
      ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
      ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
      ly->Draw();
    }

    double dx1=0.15;
    if ( ipt == nPtBin )
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823                                           
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823                       

    
  }
  c5->SaveAs("pT_dependence_jetPt_pp_pbpb_distribution.pdf");

  TCanvas* c5pa = new TCanvas("c5pa","",1200,350);
  makeMultiPanelCanvas(c5pa,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    c5pa->cd(ipt);
    // draw pp                                                                                                                                           
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");                                                                                                        
    hTempPt->SetAxisRange(0,0.07,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[5][ipt], dNdJetPtSys[5][ipt], kYellow);
    handsomeTH1(dNdJetPt[5][ipt],2);
    dNdJetPt[6][ipt]->Draw("same");
    dNdJetPt[5][ipt]->Draw("same");
    if ( ipt == 1 ) {
      TLegend *ly = new TLegend(0.4855983,0.5529059,0.9512013,0.7645899,NULL,"brNDC");
      easyLeg(ly,"5.02TeV pPb");
      ly->AddEntry(meanJetPt[5],"Data","p");
      ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
      ly->Draw();
    }
    double dx1=0.15;
    if ( ipt == nPtBin )
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823                                           
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823                       
    
    
  }
  c5pa->SaveAs("pT_dependence_jetPt_pA_distribution.pdf");
  
  
  
}
void eachDataSmearing(int fixOpt=1){
    TH1::SetDefaultSumw2();

    gStyle -> SetOptFit(0);
    gStyle -> SetOptStat(0);
    gStyle -> SetTitleYSize(0.065);
    gStyle -> SetTitleXSize(0.065);

    TLegend *l2 = new TLegend(0.111127,0.7241099,0.8205091,0.8773607,NULL,"brNDC");
    if(fixOpt==0) easyLeg(l2,"fixed");
    else easyLeg(l2,"Smeared");
    //
    // cuts!!!
    //  
    TCut centCut[5];
    centCut[0] = "";//pp
    centCut[1] = "cBin > 0 && cBin < 4";//HI 0-10 %
    centCut[2] = "cBin >= 4 && cBin < 12"; // HI 10-30 %
    centCut[3] = "cBin >= 12 && cBin < 20";// HI 30-50 %
    centCut[4] = "cBin >= 20";// HI 50-100 %

    TCut totalCut = "photonEt>40 && abs(genMomId)<=22 && (abs(eta) < 1.6) && (dphi > 7*3.141592/8.0) && (refPt > 0)"; 

    multiTreeUtil* yJetpp = new multiTreeUtil();
    multiTreeUtil* yJetpb = new multiTreeUtil();
    // PbPb
    yJetpb -> addFile("/home/goyeonju/recent2013/jetAnalysis/files/yskimfiles/yskim_PbPb_pythiaHYDJET_forest_AllQCDPhotons30.root", "yJet", totalCut);
    yJetpb -> addFile("/home/goyeonju/recent2013/jetAnalysis/files/yskimfiles/yskim_PbPb_pythiaHYDJET_forest_AllQCDPhotons50.root", "yJet", totalCut);
    yJetpb -> addFile("/home/goyeonju/recent2013/jetAnalysis/files/yskimfiles/yskim_PbPb_pythiaHYDJET_forest_AllQCDPhotons80.root", "yJet", totalCut);
    yJetpb -> addFile("/home/goyeonju/recent2013/jetAnalysis/files/yskimfiles/yskim_PbPb_pythiaHYDJET_forest_AllQCDPhotons120.root", "yJet", totalCut);
    yJetpb -> addFile("/home/goyeonju/recent2013/jetAnalysis/files/yskimfiles/yskim_PbPb_pythiaHYDJET_forest_AllQCDPhotons170.root", "yJet", totalCut);
    //pp
    yJetpp -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton30to50_genPhotonPtCut30_CMSSW538HIp2.root", "yJet",totalCut, 29329. / 29329.);
    yJetpp -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton50to80_genPhotonPtCut30_CMSSW538HIp2.root", "yJet",totalCut, 8098. / 87988.);
    yJetpp -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton80to120_genPhotonPtCut30_CMSSW538HIp2.root", "yJet",totalCut, 1680. / 96756.);
    yJetpp -> addFile("/home/jazzitup/forestFiles/yskimmedFiles/yskim_merged_allQCDPhoton120to9999_genPhotonPtCut30_CMSSW538HIp2.root", "yJet",totalCut, 438.   / 90972.);

    yJetpb -> AddFriend("tgj");
    yJetpp -> AddFriend("tgj");

    const int nbin = 13;
    double ptbin[nbin];
    ptbin[0]=0.0;
    ptbin[1]=10.0;
    ptbin[2]=20.0;
    ptbin[3]=30.0;
    ptbin[4]=40.0;
    ptbin[5]=50.0;
    ptbin[6]=60.0;
    ptbin[7]=70.0;
    ptbin[8]=80.0;
    ptbin[9]=90.0;
    ptbin[10]=100.0;
    ptbin[11]=140.0;
    ptbin[12]=180.0;
    ptbin[13]=220.0;
 
//
//smearing factor
//
    
    double sigma[5]; 
    double cc[5]; 
    double ss[5]; 
    double nn[5]; 

    cc[0] =0.056762;//pp
    ss[0] =0.808114;
    nn[0] =0.000244992;
    if(fixOpt==0) {
        cc[1] =0.056762;//PbPb 0-10%
        ss[1] =0.808114;
        nn[1] =9.6876;
        cc[2] =0.056762;//PbPb 10-30%
        ss[2] =0.808114;
        nn[2] =8.21968;
        cc[3] =0.056762;
        ss[3] =0.808114;
        nn[3] =7.02911;
        cc[4] =0.056762;
        ss[4] =0.808114;
        nn[4] =6.10214;
    } else if(fixOpt==1){ // 131209 modified
        cc[1] =0.0363269;
        ss[1] =1.3291;
        nn[1] =6.49405;
        cc[2] =0.0147739;
        ss[2] =1.33037;
        nn[2] =5.00827;
        cc[3] =0.0264179;
        ss[3] =1.27536;
        nn[3] =2.70035;
        cc[4] =0.0608379;
        ss[4] =0.911933;
        nn[4] =5.70016;
    }

// pp smearing

    TH1D* gen[5];
    TH1D* reco[5];
    TH1D* smeared[5];//smeared reco!! 
    
    for(int i=0; i<5; i++){
        gen[i] = new TH1D(Form("gen%d",i),"; GenJet p_{T}^{#gamma} (GeV) ; Normalized Entries", nbin, ptbin);
        reco[i] = new TH1D(Form("reco%d",i),"; RecoJet p_{T}^{#gamma} (GeV) ; Normalized Entries", nbin, ptbin);
        smeared[i] = new TH1D(Form("smeared%d",i),"; SmearedJet p_{T}^{#gamma} (GeV) ; Normalized Entries", nbin, ptbin);
    }

    yJetpp -> Draw2(gen[0], "refPt", centCut[0], "");
    yJetpp -> Draw2(reco[0], "pt", centCut[0], "");
    for(int i=1; i<5; i++){
        yJetPbPb -> Draw2(Form("gen[%d]",i), "refPt", Form("centCut[%d]",i), "");
        yJetPbPb -> Draw2(Form("reco[%d]",i), "pt", Form("centCut[%d]",i), "");
    }

}
void photonTemplateProducer(int cutOpt=3, int ppHI = kHI, int isoChoice = kSumIso, int isoCut = -100, bool onlygjEvents=false, float specialSbCut=10, float mcSigShift=0, float sbBkgShift=0) {
  
  CutAndBinCollection cab;
  cab.setCuts(cutOpt);
  int nPtBin = cab.getNPtBin();
  vector<double> ptBinVector = cab.getPtBin();
  double ptBin[100];
  for ( int i = 0 ; i<=nPtBin ;i++) {
    ptBin[i] = ptBinVector[i];
  }
  
  int nCentBin = cab.getNCentBin();
  vector<double> centBinVector = cab.getCentBin();
  double centBin[100];
  for ( int i = 0 ; i<=nCentBin ;i++) {
    centBin[i] = centBinVector[i];
  }
  
  TString pphiLabel = "";
  if ( ppHI == kPP) pphiLabel = "pp";
  
  TCanvas* c1[5];
    
   TH1D* hData[5][5];
   TH1D* hSig[5][5];
   TH1D* hBkg[5][5];
   
   //   TH1D* hDatapp[5];
   //   TH1D* hSigpp[5];
   //   TH1D* hBkgpp[5];
   
   TH1D* hBkgMCsr[5][5];
   TH1D* hBkgMCsb[5][5];
      
   TH1D* rawSpectra[5];
   TH1D* finSpectra[5];
    
   TH2D* hPurity2D = new TH2D("hPurity2D",";pT(GeV);Centrality bin",nPtBin,ptBin,nCentBin,centBin);
   
   int nCent(-1);
   if ( ppHI == kHI ) nCent = nCentBin;
   if ( ppHI == kPP ) nCent = 1;
   
   for ( int icent = 1 ; icent<=nCent ; icent++) {
      rawSpectra[icent] = new TH1D(Form("rawSpec_icent%d_%s",icent,getIsoLabel(isoChoice).Data()),"",nPtBin,ptBin);
   }

   
   for (int ipt = 1; ipt <= nPtBin ; ipt++) { 
      c1[ipt] = new TCanvas(Form("c1_ipt%d",ipt),"",700,700);
      if ( ppHI == kHI )  makeMultiPanelCanvas(c1[ipt],nCent/2,2,0.0,0.0,0.2,0.15,0.02);

      TCut ptCut = Form("corrPt>%.2f && corrPt<%.2f",(float)ptBin[ipt-1],(float)ptBin[ipt]); 
      

      for ( int icent = 1 ; icent<=nCent ; icent++) { 
	 int lowCent =  centBinVector[icent-1];    
	 int highCent = centBinVector[icent]-1;
	 
	 hData[icent][ipt]  = new TH1D(Form("hData_cent%d_pt%d",icent,ipt),";shower shape (#sigma_{#eta#eta});Entries per photon candidate;",25,0,0.025);
	 hSig[icent][ipt]   = (TH1D*)hData[icent][ipt]->Clone(Form("hSig_cent%d_pt%d",icent,ipt));
	 hBkg[icent][ipt]   = (TH1D*)hData[icent][ipt]->Clone(Form("hBkg_cent%d_pt%d",icent,ipt));
	 hBkgMCsr[icent][ipt] = (TH1D*)hData[icent][ipt]->Clone(Form("hBkgMCsr_cent%d_pt%d",icent,ipt));
	 hBkgMCsb[icent][ipt] =(TH1D*)hData[icent][ipt]->Clone(Form("hBkgMCsb_cent%d_pt%d",icent,ipt));
	
	 TString fNamedata = fNameHIdata;
	 if ( ppHI == kPP ) fNamedata = fNamePPdata;
	 
	 getTemplate(ppHI, hSig[icent][ipt],"meaningless",isoChoice,isoCut, kSig,lowCent,highCent,ptCut,onlygjEvents,specialSbCut,mcSigShift);
	 getTemplate(ppHI, hData[icent][ipt],fNamedata ,isoChoice,isoCut, kData,lowCent,highCent,ptCut,onlygjEvents,specialSbCut);
	 if ( ppHI == kHI) {
	   getTemplate(ppHI, hBkg[icent][ipt], fNamedata ,isoChoice,isoCut, kSBB,lowCent,highCent,ptCut,onlygjEvents,specialSbCut,sbBkgShift);
	 }
	 if ( ppHI == kPP)
           getTemplate(ppHI, hBkg[icent][ipt], fNamedata ,isoChoice,isoCut, kSBBpp,lowCent,highCent,ptCut,onlygjEvents,specialSbCut);
	 
      }
            
      
      for ( int icent = 1 ; icent<=nCent ; icent++) {
	int lowerCent = centBinVector[icent-1];
	int upperCent =centBinVector[icent]-1;
	 
	 c1[ipt]->cd(nCent - icent+1);
	 fitResult fitr = doFit ( hSig[icent][ipt], hBkg[icent][ipt], hData[icent][ipt], 0.005,0.025);
	 if ( icent== nCent) drawPatch(0,0,0.05,0.14,0,1001, "ndc");
	 
	 cout << " shift = " << mcSigShift << endl;
	 cout << " purity = " << fitr.purity010 << endl;

	 
	 if ( ptBin[ipt]> 200)
	    drawText(Form(" E_{T}^{#gamma} > %d GeV", (int)ptBin[ipt-1]),0.5680963,0.529118);
	 else
	    drawText(Form("%d - %d GeV", (int)ptBin[ipt-1], (int)ptBin[ipt]),0.5680963,0.529118);
	 
	 if ( ppHI == kHI) {
	   drawText(Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),0.5680963,0.4369118);
	 }
	 else if ( ppHI == kPP) {
	   drawText("7TeV pp",0.5680963,0.4369118);
         }
	 
	 
	 
	 if ( (icent == nCent) || (icent == 2)) 
	   drawText(Form("Purity(#sigma_{#eta#eta} < 0.01) : %.0f%%", (float)fitr.purity010*100),0.5680963,0.3569118,1,15);
	 else 
	   drawText(Form("Purity(#sigma_{#eta#eta} < 0.01) : %.0f%%", (float)fitr.purity010*100),0.4980963,0.3569118,1,15);
	 
	 drawText(Form("#pm %.0f%% (stat)", float( 100. * fitr.purity010 * (float)fitr.nSigErr / (float)fitr.nSig ) ),0.6680963,0.2869118,1,15);
	 
	 
	 hPurity2D->SetBinContent(ipt,icent,fitr.purity010);
	 hPurity2D->SetBinError  (ipt,icent,fitr.purity010* fitr.nSigErr/fitr.nSig);

	 rawSpectra[icent]->SetBinContent( ipt, fitr.nSig);
	 rawSpectra[icent]->SetBinError(   ipt,fitr.nSigErr);

	 TString aa = "";
	 if (isoChoice == kSumIso)  aa = "Sum Iso Method";
	 if (isoChoice == k3dIso)   aa = "3d Cut Method";
	 if (isoChoice == kFisher)  aa = "Fisher Method";
	 
	 if ( (ppHI == kHI)  && ( icent==nCent -1) )
	   drawText(aa.Data(),0.1980963,0.8569118,1,20);
	 else if ( ppHI == kPP) 
	   drawText(aa.Data(),0.1980963,0.8569118,1,20);
	 
	 if ( icent<= 2) drawPatch(0,0,0.05,0.14,0,1001, ndcOpt);
	 //	 drawPatch(0.9,0.05,1.01,0.14,0,1001,ndcOpt);
	 if  ( (ppHI == kPP) && ( mcSigShift != 0 )) 
           drawText(Form("Signal template shifted by %f",mcSigShift),0.1980963,0.7569118,1,15);
	 if  ( (ppHI == kHI) && ( mcSigShift != 0 ) && (icent==3))
	   drawText(Form("Signal template shifted by %f",mcSigShift),0.1980963,0.7569118,1,15);


      }   
      
      TString ppLabel ="";  
      if ( ppHI == kPP) ppLabel = "_pp";
      TString shiftLabel="";
      if ( mcSigShift != 0 )  shiftLabel = Form("_%fSigShifted",(float)mcSigShift);
      c1[ipt]->SaveAs(Form("fittingPurity%s_%s_pt%d%s.pdf",ppLabel.Data(), getIsoLabel(isoChoice).Data(),ipt,shiftLabel.Data()));

   }
   
   // efficiency plots          
   TCanvas* c2  = new TCanvas("c2","",700,700); //100 + nCent_std*300,400);
   if ( ppHI == kHI) makeMultiPanelCanvas(c2,nCent/2,2,0.0,0.0,0.2,0.15,0.02);
   
   TH1D* heff[7][5];
   TH1D* heffGj[5];
   TH1D* heffDphi[5];
   TH1D* effSingleBin = new TH1D("effSingleBin","",1,60,100000);
   TGraphAsymmErrors* geff[7][5];
   TGraphAsymmErrors* gSingleBin = new TGraphAsymmErrors();
   TGraphAsymmErrors* geffGj[5];
   TGraphAsymmErrors* geffDphi[5];
   
   for (int icent = 1; icent <=nCent; icent++) {
     for ( int iid=1 ; iid<=5; iid++) {
       heff[icent][iid] = new TH1D(Form("heff_icent%d_id%d",icent,iid),";photon E_{T} (GeV);Efficiency",nPtBin, ptBin);
       if ( isoChoice == kSumIso2)
	 heff[icent][iid]->SetName(Form("heff_icent%d_id%d_isoCut%d",icent,iid,(int)isoCut));
       if ( isoChoice == kSumIso3)
	 heff[icent][iid]->SetName(Form("heff_icent%d_id%d_sbIsoCut%d",icent,iid,(int)specialSbCut));
       
       geff[icent][iid] = new TGraphAsymmErrors();
       geff[icent][iid]->SetName(Form("geff_%s",heff[icent][iid]->GetName()));
     }
     heffGj[icent]   = new TH1D(Form("heff_icent%d_Gj",  icent),";x_J#gamma;Efficiency",10,0,2);
     heffDphi[icent] = new TH1D(Form("heff_icent%d_Dphi",icent),";#Delta#phi of pair;Efficiency",9,0.3141592,3.141592);
     geffGj[icent] = new TGraphAsymmErrors();
     geffDphi[icent] = new TGraphAsymmErrors();

   }
   
   TCut srIsoCut = getIsoCut(isoChoice,isoCut);
   int nId=4;
   for (int icent = 1; icent <=nCent ; icent++) {
     int lowCent = centBinVector[icent-1];
     int highCent = centBinVector[icent]-1;
     TCut centCut      = Form("yEvt.hiBin >= %d && yEvt.hiBin<= %d",lowCent,highCent);
     if ( ppHI == kPP ) centCut = "";
     getEff("genMatchedPt",heff[icent][1],geff[icent][1],centCut, "swissCrx<0.90 && seedTime<4");
     getEff("genMatchedPt",heff[icent][2],geff[icent][2],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1");
     getEff("genMatchedPt",heff[icent][3],geff[icent][3],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1" && srIsoCut);
     getEff("genMatchedPt",heff[icent][4],geff[icent][4],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1 && sigmaIetaIeta<0.010"&& srIsoCut);
     effSingleBin->Reset();
     getEff("genMatchedPt",effSingleBin, gSingleBin, centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1" && srIsoCut);
     
     
     cout << " here Gj" << endl;
     getEff("yJet.jtpt/photonEt",heffGj[icent],geffGj[icent], centCut && " genIso<5 && abs(genMomId)<=22 && photonEt>60 && abs(yJet.jteta)<2 && yJet.jtpt>30 && acos(cos(photonPhi-yJet.jtphi))>2.749", "hovere<0.1 && sigmaIetaIeta<0.010 && (cc4+cr4+ct4PtCut20)/0.9<1",true);
     getEff("acos(cos(photonPhi-yJet.jtphi))",heffDphi[icent],geffDphi[icent],centCut && " genIso<5 && abs(genMomId)<=22 && photonEt>60 && abs(yJet.jteta)<2 && yJet.jtpt>30", "hovere<0.1 && sigmaIetaIeta<0.010 && (cc4+cr4+ct4PtCut20)/0.9<1",true);
   }
   
   for (int icent = 1; icent <=nCent; icent++) {
     for ( int iid=1 ; iid<=nId ; iid++) {
       handsomeTH1(heff[icent][iid],ycolor[iid]);
       handsomeTGraph(geff[icent][iid],ycolor[iid]);
     }
   }
   

   
   
   
   TH1D* htmp = (TH1D*)heff[1][1]->Clone("htmp");
   htmp->Reset();
   htmp->SetAxisRange(0,1.3,"Y");
   htmp->SetYTitle("Efficiency");
   handsomeTH1(htmp);
   
   for (int icent = 1; icent <=nCent; icent++) {
      int lowerCent = centBinVector[icent-1];
      int upperCent = centBinVector[icent]-1;
      if ( ppHI == kHI) c2->cd(nCent - icent + 1);
      htmp->DrawCopy();
      for ( int iid=1 ; iid<=nId ; iid++) {
         heff[icent][iid]->Draw("p same");
         geff[icent][iid]->Draw("p");
	 
      }
      if ( ( icent == nCent ) ||   ( ppHI == kPP)  )
         {
            TLegend* leg1 =  new TLegend(0.25,0.20,0.95,0.55,NULL,"brNDC");
            easyLeg(leg1,"Photon ID efficiency");
            leg1->AddEntry(heff[icent][1],"spike rejection","lp");
            leg1->AddEntry(heff[icent][2],"+ H/E < 0.1","lp");
	    if (isoChoice == kSumIso)
	      leg1->AddEntry(heff[icent][3],"+ SumIso cut","lp");
	    if (isoChoice == kFisher) 
	      leg1->AddEntry(heff[icent][3],"+ Fisher cut","lp");
	    leg1->AddEntry(heff[icent][4],"+ #sigma_{#eta#eta} <0.010","lp");
            leg1->Draw();
         }
      drawText(Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),0.5680963,0.8369118);
      if ( icent<=2) drawPatch(0,0,0.05,0.14,0,1001,ndcOpt);
      //  drawPatch(0.9,0.05,1.01,0.14,0,1001,ndcOpt);
      
   }
   
   
   c2->SaveAs(Form("photonID_efficiency_%s.pdf",getIsoLabel(isoChoice).Data()));  

   TCanvas* c2b  = new TCanvas("c2b","",1000,500); //100 + nCent_std*300,400);                                             
   c2b->Divide(2,1);
   c2b->cd(1);
   TH1D* htmpG = (TH1D*)heffGj[1]->Clone("htmpG");
   htmpG->Reset();
   htmpG->SetAxisRange(0,1.3,"Y");
   htmpG->SetYTitle("Efficiency");
   handsomeTH1(htmpG);   
      
   TLegend* legCent = new TLegend(0.4657258,0.2245763,1,0.4512712,NULL,"brNDC");
   easyLeg(legCent,"Centrality");
   if (isoChoice == kSumIso)  easyLeg(legCent,"SumIso Method");
   if (isoChoice == kFisher)  easyLeg(legCent,"Fisher Method");
   cout<< " heffGj "<< endl << endl<< endl;
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(heffGj[icent],ycolor[icent]);
     heffGj[icent]->Fit("pol1");
     heffGj[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     heffGj[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   htmpG->DrawCopy();
   for (int icent = 1; icent <=nCent; icent++) {
     heffGj[icent]->Draw("same");
     int lowerCent = centBinVector[icent-1];     int upperCent = centBinVector[icent]-1;
     legCent->AddEntry(heffGj[icent],Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),"pl");
   }
   legCent->Draw();

   c2b->cd(2);
   TH1D* htmpDp = new TH1D("htmpDp",";#Delta#phi of pair;Efficiency",10,0,3.14);
   htmpDp->Reset();
   htmpDp->SetAxisRange(0,1.3,"Y");
   htmpDp->SetYTitle("Efficiency");
   handsomeTH1(htmpDp);
   cout << " heffDphi " << endl << endl << endl ;
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(heffDphi[icent],ycolor[icent]);
     heffDphi[icent]->Fit("pol1");
     heffDphi[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     heffDphi[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   htmpDp->DrawCopy();
   for (int icent = 1; icent <=nCent; icent++) {
     heffDphi[icent]->Draw("same");
   }
   legCent->Draw();
   
   c2b->SaveAs(Form("photonID_efficiency_%s_2.pdf",getIsoLabel(isoChoice).Data()));
   
   
   TCanvas* c3 = new TCanvas("cPurity","",500,500);

   TH1D* hPurity[10];
   for (int icent = 1; icent <=nCent; icent++) {
     hPurity[icent] = (TH1D*)hPurity2D->ProjectionX(Form("purity1D_icent%d",icent),icent,icent);
     hPurity[icent]->Fit("pol1");
     hPurity[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     hPurity[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   TH1D* tempPurity = (TH1D*)hPurity[1]->Clone("purityTemp");
   tempPurity->Reset();
   handsomeTH1(tempPurity,1);
   tempPurity->SetXTitle("pT (Gev)");
   tempPurity->SetYTitle("Purity");
   tempPurity->SetAxisRange(0.45,1.2,"Y");

   tempPurity->Draw();
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(hPurity[icent],ycolor[icent]);
     hPurity[icent]->Draw("same");
   }
   TLegend* legPurity = new TLegend(0.4657258,0.2245763,1,0.4512712,NULL,"brNDC");
   easyLeg(legPurity,"Purity");
   if (isoChoice == kSumIso)  easyLeg(legPurity,"SumIso Method");
   if (isoChoice == kFisher)  easyLeg(legPurity,"Fisher Method");
   for (int icent = 1; icent <=nCent; icent++){
     int lowerCent = centBinVector[icent-1];     int upperCent = centBinVector[icent]-1;
     legPurity->AddEntry(hPurity[icent],Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),"pl");
   }
   legPurity->Draw();
   
   if ( !onlygjEvents) 
     drawText("inclusive photon",0.25,0.2);
   
   c3->SaveAs(Form("purity_%s.pdf",getIsoLabel(isoChoice).Data()));
  
   
   TCanvas* c4 = new TCanvas("efficiencyCorrection","",1000,500);
   c4->Divide(2,1);
   c4->cd(1);
   for (int icent = 1; icent <=nCent; icent++) {
      TH1ScaleByWidth(rawSpectra[icent]);    // divide by width
      finSpectra[icent] = (TH1D*)rawSpectra[icent]->Clone(Form("finSpec_icent%d_%s",icent,getIsoLabel(isoChoice).Data()));
      if ( isoChoice == kSumIso2)
	 finSpectra[icent]->SetName(Form("finSpec_icent%d_%s_isoCut%d",icent,getIsoLabel(isoChoice).Data(),(int)isoCut));
      if ( isoChoice == kSumIso3)
         finSpectra[icent]->SetName(Form("finSpec_icent%d_%s_sbisoCut%d",icent,getIsoLabel(isoChoice).Data(),(int)specialSbCut));
      
      finSpectra[icent]->Divide(heff[icent][3]);
      handsomeTH1(finSpectra[icent],ycolor[icent]);
   }
   // TAA and centrality 
   //

   TFile outf = TFile(cab.getPurityFileName(),"recreate");
   hPurity2D->Write();
   for ( int icent=1 ; icent<=nCent ; icent++) {
      heff[icent][3]->Write();
      heff[icent][4]->Write();
      finSpectra[icent]->Write();
      hPurity[icent]->Write();
      for (int ipt = 1; ipt <= nPtBin ; ipt++) {
	hData[icent][ipt]->Write();
      }
      //      hBkgMCRatioFit[icent][1]->Write();

   }



   outf.Close();
}
Exemple #30
0
void hfCentrality(char* fname = "r151878.root",  char* trg="anaPixelHitJet50U")
{
   
   TFile *f1=new TFile(Form("/d101/kimy/macro/pixelTrees/rootFiles/%s",fname),"r");
   TTree *trPixMB = (TTree*)f1->Get("anaPixelHitMB/PixelTree");
   TTree *trPixJet = (TTree*)f1->Get("anaPixelHitJet50U/PixelTree");
   
   //   const int nscEtBin = 10;
   //   double scetBin[nscEtBin+1] = { 15.1,18,21,24,28,32,36,40,48,55,70};
   
   TH1D* hhfMB  = new TH1D(Form("hhfMB",trg),";Sum HF Energy (TeV);Fraction of minimum bias events",70,0,160);
   TH1D* hhfMB1  = (TH1D*)hhfMB->Clone("hhfMB1");
   TH1D* hhfMB2  = (TH1D*)hhfMB->Clone("hhfMB2");
   TH1D* hhfMB3  = (TH1D*)hhfMB->Clone("hhfMB3");
   TH1D* hhfJET  = (TH1D*)hhfMB->Clone("hhfJET");

   TCanvas* c1 = new TCanvas(Form("c1_%s",trg),"",400,400);

   trPixMB->Draw("hf/1000.>>hhfMB");
   trPixMB->Draw("hf/1000.>>hhfMB1","cBin<=4");
   trPixMB->Draw("hf/1000.>>hhfMB2","cBin>=4 && cBin<=12");
   trPixMB->Draw("hf/1000.>>hhfMB3","cBin>=12 && cBin<=35");
   
   trPixJet->Draw("hf/1000.>>hhfJET");

   
   handsomeTH1(hhfMB1,1);
   handsomeTH1(hhfMB2,2);
   handsomeTH1(hhfMB3,4);
   hhfMB1->SetFillColor(1);
   hhfMB2->SetFillColor(2);
   hhfMB3->SetFillColor(4);

   
   hhfMB->Scale(1./hhfMB->GetEntries());
   hhfMB->SetAxisRange(1e-5,1,"Y");
   hhfJET->Scale(1./hhfJET->GetEntries());
   hhfJET->SetAxisRange(1e-5,1,"Y");

   hhfMB->SetLineWidth(2);
   handsomeTH1(hhfMB);
   hhfMB->DrawCopy();
   
   //   TLine* t1 = new TLine(.511,1e-5,.511,hhfMB->GetBinContent(hhfMB->FindBin(0.511)));
   TLine* t1 = new TLine(0,1e-5,.511,hhfMB->GetBinContent(hhfMB->FindBin(0.511)));
   TLine* t2 = new TLine(35.397,1e-5,35.397,hhfMB->GetBinContent(hhfMB->FindBin(35.397)));
   TLine* t3 = new TLine(79.370,1e-5,79.370,hhfMB->GetBinContent(hhfMB->FindBin(79.370)));
   t1->SetLineWidth(1);
   t2->SetLineWidth(1);
   t3->SetLineWidth(1);
   t1->SetLineStyle(7);
   t2->SetLineStyle(7);
   t3->SetLineStyle(7);
   t1->Draw();
   t2->Draw();
   t3->Draw();
   
   //  hhfMB3->DrawCopy();
   //  hhfMB2->DrawCopy("same");
   //  hhfMB1->DrawCopy("same");
   gPad->SetLogy();

   TLegend* leg0 = new TLegend(0.2813131,0.7115054,0.9,0.8439785,NULL,"brNDC");
   TLegend* leg0b =new TLegend(0.3813131,0.7115054,1,0.8439785,NULL,"brNDC");
   TLegend* leg1 = new TLegend(0.1767677,0.3826344,0.4467677,0.5875591,NULL,"brNDC");
   TLegend* leg2 = new TLegend(0.3611111,0.3876344,0.6111111,0.5865591,NULL,"brNDC");
   TLegend* leg3 = new TLegend(0.5606061,0.3876344,0.8106061,0.5865591,NULL,"brNDC");

   easyLeg(leg0b,"Centrality, HLT_HIJet50U");

   easyLeg(leg1,"30%-100%");
   easyLeg(leg2,"10%-30% ");
   easyLeg(leg3," 0%-10% ");

   //   TCanvas* c2 = new TCanvas(Form("c2_%s",trg),"",400,400);
   
   float triggerRatio = 0.29 / 49.;
   
   hhfJET->SetLineWidth(2);
   hhfJET->SetLineColor(2);
   hhfJET->SetFillColor(2);
   hhfJET->SetFillStyle(3544);
   hhfJET->Scale(triggerRatio);
   hhfJET->DrawCopy("same");
   
   easyLeg(leg0,"Centrality");
   leg0->AddEntry(hhfMB,"HLT_MinBiasHForBSC_Core","l");
   leg0->AddEntry(hhfJET,"HLT_HiJet50U","l");
   leg0->Draw();
   //   leg1->Draw();
   //   leg2->Draw();
   //   leg3->Draw();
     
   TLatex *bint = new TLatex(0.1867677,0.4876344,"30%-100%");
   bint->SetTextFont(63);
   bint->SetTextSize(13);
   bint->SetNDC();
   bint->Draw();

   bint = new TLatex(0.4011111,0.4876344,"10%-30% ");
   bint->SetTextFont(63);
   bint->SetTextSize(13);
   bint->SetNDC();
   bint->Draw();

   bint = new TLatex(0.6006061,0.4876344," 0%-10% ");
   bint->SetTextFont(63);
   bint->SetTextSize(13);
   bint->SetNDC();
   bint->Draw();

 
   TLatex *cms = new TLatex(0.6013,0.89,"CMS Preliminary");
   cms->SetTextFont(63);
   cms->SetTextSize(16);
   cms->SetNDC();
   cms->Draw();
   c1->SaveAs("hf_centrality_distribution_mb_jet50_20101126_v1.eps");
   c1->SaveAs("hf_centrality_distribution_mb_jet50_20101126_v1.gif");
   c1->SaveAs("hf_centrality_distribution_mb_jet50_20101126_v1.C");

   // TCanvas* c2 = new TCanvas(Form("c2_%s",trg),"",400,400);
   //  hhfJET->Divide(hhfMB);
   //  hhfJET->Draw();
   //   c2->SaveAs("ratio.gif");
   
   //  TLine* t1j = new TLine(.511,1e-5,.511,hhfJET->GetBinContent(hhfJET->FindBin(0.511)));
   //  TLine* t2j = new TLine(35.397,1e-5,35.397,hhfJET->GetBinContent(hhfJET->FindBin(35.397)));
   //  TLine* t3j = new TLine(79.370,1e-5,79.370,hhfJET->GetBinContent(hhfJET->FindBin(79.370)));
   //  t1j->SetLineWidth(2);
   // t2j->SetLineWidth(2);
   //  t3j->SetLineWidth(2);
   //  t1j->Draw();
   //  t2j->Draw();
   // t3j->Draw();
   

   
   //   TLegend* leg0 = new TLegend(0.46,0.80, 0.99, 0.95,NULL,"brNDC");
   //  easyLeg(leg0,"offline cleaned Superlclusters");
   //   leg0->AddEntry(hetSc,"HLT_HIPhoton15");
   //  leg0->AddEntry(hetScClean,"HLT_HICleanPhoton15");
   // leg0->Draw();
   
}