Пример #1
0
void draw_cross_pt(bool sysByHand=false, bool noPtWeight=false, bool isScale=true, bool isLog=true, int isPA = 1, bool isPrompt=true)
{
	gROOT->Macro("./tdrstyle_kyo.C");
  gStyle->SetTitleYOffset(1.38); //KYO

	//int iPos=0.;//outOfFrame
	int iPos=33;//right corner
  //int iPos=11;//left corner

	//// pileup rejection!!
	Double_t pileReg;
  if (isPA==0) pileReg = 1;
  else pileReg = 128234./123240.;
	//const Double_t pileRegRelErr = 0.23;

	//// zvtx correction!!
	//const Double_t zvtxCor = 1.064; // not used anymore!!

	//// BR and lumi info.
	const Double_t br = 0.0593 ;
	const Double_t brErr = 0.0006;
	const Double_t pp_lumi_pb =27.972; // 28.0/pb
	const Double_t pp_lumi_pb_err = 0.643; // 2.3 %
	const Double_t pPb_lumi_nb = 34.622; // 34.6/nb
	const Double_t pPb_lumi_nb_err = 1.211; // 3.5 %
	Double_t lumi_mub;
	Double_t lumi_mub_err;
  if (isPA==0) {
    lumi_mub = pp_lumi_pb *1000*1000;
    lumi_mub_err = pp_lumi_pb_err *1000*1000;
  }
  else if (isPA==1) {
    lumi_mub = pPb_lumi_nb * 1000;
    lumi_mub_err = pPb_lumi_nb_err * 1000;
  } else {
    cout << "select among isPA = 0 or 1"<< endl; return ;
  }
	cout << "isPA = " << isPA << ", and lumi_mub = " << lumi_mub <<"+-" <<lumi_mub_err <<  endl;
	cout << " *** pileReg = " << pileReg << endl;

	/////////////////////////////////////////////////////////////////////////
	//// bin center & systematic uncertainties by hand  
	const int nRap = 8;	
	const int nPt = 9;
	const int nRapTmp = nRap + 1;
	const int nPtTmp = nPt + 1;
	const int nRapRFB = 3;	
	const int nPtRFB = 3;
	
	Double_t pxtmp[nRap][nPt]; //x point to fill remporarily
	Double_t pytmp[nRap][nPt]; //y point to fill remporarily
	Double_t eytmp[nRap][nPt]; //y point error to fill remporarily

	Double_t px[nRap][nPt];
  /*
  Double_t px_pp[nRap][nPt] = { //x point (mean pT) by JB -- from FW to BW
    {2.54567, 3.50886, 4.48508, 5.69331, 6.97532, 7.97107, 9.17601, 11.5322, 17.4867},
    {0, 0, 4.54938, 5.75633, 6.9727, 7.97359, 9.17558, 11.4729, 17.4391},
    {0, 0, 0, 0, 7.0061, 7.97991, 9.19355, 11.5729, 17.6818},
    {0, 0, 0, 0, 7.08557, 8.01392, 9.2137, 11.6042, 17.9741},
    {0, 0, 0, 0, 7.08944, 8.01343, 9.21616, 11.6091, 17.7608},
    {0, 0, 0, 0, 7.00408, 7.98632, 9.19122, 11.5535, 17.7004},
    {0, 0, 4.54198, 5.76465, 6.97492, 7.96787, 9.18318, 11.5223, 17.4279},
    {2.54164, 3.5085, 4.48298, 5.69705, 6.97263, 7.97372, 9.17313, 11.5032, 17.3023}
	};
	Double_t px_pA[nRap][nPt] = { //x point (mean pT) by JB -- from FW to BW
    {2.525, 3.51255, 4.4772, 5.70327, 6.96635, 7.96061, 9.17243, 11.5938, 18.0681},
    {0, 0, 4.52793, 5.74033, 6.97622, 7.98335, 9.19458, 11.4927, 17.6693},
    {0, 0, 0, 0, 7.018, 8.00224, 9.19714, 11.5483, 17.6577},
    {0, 0, 0, 0, 7.11111, 8.02103, 9.24485, 11.6204, 17.8454},
    {0, 0, 0, 0, 7.05329, 8.00998, 9.20583, 11.5222, 17.4633},
    {0, 0, 0, 5.84477, 6.98466, 7.97917, 9.17551, 11.5322, 17.34},
    {0, 0, 4.52204, 5.72881, 6.97074, 7.95284, 9.14157, 11.4976, 17.3058},
    {2.51699, 3.4959, 4.47636, 5.68624, 6.97338, 7.97824, 9.1805, 11.4841, 16.8762}
	};
	*/
  //// for middle
  Double_t px_pp[nRap][nPt] = {	
		{2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22}, 
		{0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22},
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22},
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22}, 
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22}, 
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22},
		{0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22}, 
		{2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22}
	};
	Double_t px_pA[nRap][nPt] = {	
		{2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22}, 
		{0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22},
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22},
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22}, 
		{0., 0., 0., 0., 7, 8, 9.25, 12., 22}, 
		{0., 0., 0., 5.75, 7, 8, 9.25, 12., 22},
		{0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22}, 
		{2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22}
	};
  
  Double_t ex[nPt] = {0,0,0,0,0,0,0,0,0}; // x stat error
	Double_t exlow[nRap][nPt]; // x binWidth 
	Double_t exhigh[nRap][nPt]; // x binWidth
	Double_t exsys[nPt] = {0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4}; // x sys error
	Double_t eysysrel[nRap][nPt]; //relative y sys error
	Double_t eysys[nRap][nPt]; //absolute y sys error
	for (Int_t iy=0; iy<nRap; iy++) {
	  for (Int_t ipt=0; ipt<nPt; ipt++) {
      if (isPA==0) { px[iy][ipt] = px_pp[iy][ipt]; }
      else { px[iy][ipt] = px_pA[iy][ipt]; }
    }
  }

	//// scaling for drawing
  double scaleF[nRap];
	double scaleF_pp[nRap] = {1000., 100., 10., 1., 1., 10., 100., 1000.};
	double scaleF_pA[nRap] = {100., 10., 1., 1., 10., 100., 1000., 10000.};
  for (int iy=0; iy<nRap; iy++){
    if (isPA==0) {scaleF[iy] = scaleF_pp[iy]; }
    else {scaleF[iy] = scaleF_pA[iy]; }
	  if (!isScale) { scaleF[iy] = 1.; };
    cout << "scaleF["<<iy<<"] = " << scaleF[iy] << endl;	
	}
  
  //// 1) y_CM array (from forward to backward)
	Double_t rapArrNumFB_pA[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
	//Double_t rapArrNumBF_pA[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
	Double_t rapArrNumFB_pp[nRapTmp] = {2.4, 1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4};// for pt dist.
	//Double_t rapArrNumBF_pp[nRapTmp] = {-2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93, 2.4};// for rap dist.
	Double_t rapArrNumFB[nRapTmp];
	for (Int_t iy=0; iy<nRapTmp; iy++) {
		if (isPA==0) { rapArrNumFB[iy] = rapArrNumFB_pp[iy]; }
		else { rapArrNumFB[iy] = rapArrNumFB_pA[iy]; }
	}
	Double_t rapBinW[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
    rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1];
    //rapBinW[iy] = rapArrNumBF[iy+1]-rapArrNumBF[iy];
	}
	//// 2) pt array
	Double_t ptArrNum[nPtTmp] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.};
	Double_t ptBinW[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; 
	}
	//// array string
	TString rapArr[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
		cout << iy <<"th rapArr = " << rapArr[iy] << endl;
	}
	TString ptArr[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
		cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
	}
  
  //// ex calculation
  for (Int_t iy=0; iy<nRap; iy++) {
    for (Int_t ipt=0; ipt<nPt; ipt++) {
      exlow[iy][ipt] = px[iy][ipt]-ptArrNum[ipt]; 
      exhigh[iy][ipt] = ptArrNum[ipt+1]-px[iy][ipt]; 
    }
  }

	//////////////////////////////////////////////////////////////	
	//// read-in sys. file 
	TFile * fSys;
  if (isPA==0) fSys = new TFile("../TotalSys/TotSys_8rap9pt_pp_etOpt0.root");
  else fSys = new TFile("../TotalSys/TotSys_8rap9pt_pA_etOpt0.root");
	TH2D* h2D_SysErr;
  if (isPrompt) h2D_SysErr = (TH2D*)fSys->Get("hTotalPR");
	else h2D_SysErr = (TH2D*)fSys->Get("hTotalNP");

	//////////////////////////////////////////////////////////////	
	//// read-in corr-yield file
	TFile * f2D;
  if (isPA==0) {
    if (noPtWeight) f2D = new TFile("../FittingResult/totalHist_pp_8rap9pt_newcut_nominal_Zvtx0_SF1_etOpt0_noPtWeight.root");
    else f2D = new TFile("../FittingResult/totalHist_pp_8rap9pt_newcut_nominal_Zvtx0_SF1_etOpt0.root");
  } else {
    if (noPtWeight) f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0_noPtWeight.root");
    else f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0.root");

  }
	//// read-in 2D hist for corrected yield
  TH2D* h2D_CorrY;
	if (isPA==0) {
    if (isPrompt) h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_PR_pp");
  	else h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_NP_pp");
  } else {
    if (isPrompt) h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_PR_pA");
  	else h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_NP_pA");
  }
	const int nbinsX = h2D_CorrY->GetNbinsX();
	const int nbinsY = h2D_CorrY->GetNbinsY();
	if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; };
	if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; };

	////  projection to 1D hist : iy=0 refers to forwards !!! (ordering here)
	TH1D* h1D_CorrY[nRap]; 
	TH1D* h1D_SysErr[nRap];
	for (Int_t iy = 0; iy < nRap; iy++) {
		if ( isPA==0) {
      h1D_CorrY[iy] = h2D_CorrY->ProjectionY(Form("h1D_CorrY_%d",iy),nRap-iy,nRap-iy);
		  h1D_SysErr[iy] = h2D_SysErr->ProjectionY(Form("h1D_SysErr_%d",iy),nRap-iy,nRap-iy);
		} else {
      h1D_CorrY[iy] = h2D_CorrY->ProjectionY(Form("h1D_CorrY_%d",iy),iy+1,iy+1);
		  h1D_SysErr[iy] = h2D_SysErr->ProjectionY(Form("h1D_SysErr_%d",iy),iy+1,iy+1);
		}
	}
  //// read sys values from hist	
	for (Int_t iy = 0; iy < nRap; iy++) {
		for (int ipt=0; ipt <nPt; ipt ++ ){ 
			eysysrel[iy][ipt] = h1D_SysErr[iy]->GetBinContent(ipt+1);
		}
	}
	
  //////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	//// calcualte cross-section = corrY/(dPt*dY*lumi)
	TH1D* h1D_cross[nRap]; 
	for (Int_t iy = 0; iy < nRap; iy++) {
		h1D_cross[iy] = (TH1D*)h1D_CorrY[iy]->Clone(Form("h1D_cross_%d",iy));
		//// normalization
		h1D_cross[iy]->Scale(1,"width"); //pT bin 
		h1D_cross[iy]->Scale(1./rapBinW[iy]); //rap bin
		h1D_cross[iy]->Scale(1./lumi_mub); // lumi
		// h1D_cross[iy]->Scale(1./br); //br
    h1D_cross[iy]->Scale(pileReg);	// pileup correction
		h1D_cross[iy]->Scale(scaleF[iy]); // scaling for drawing
	}
		
	//// set values as zero for unused bins
	for (Int_t iy = 0; iy < nRap; iy++) {
		if (iy>=1 && iy<=6) {
			h1D_cross[iy]->SetBinContent(1,-532);
			h1D_cross[iy]->SetBinError(1,0);
			h1D_cross[iy]->SetBinContent(2,-532);
			h1D_cross[iy]->SetBinError(2,0);
      exlow[iy][0]=0; exhigh[iy][0]=0;
      exlow[iy][1]=0; exhigh[iy][1]=0;
		}
		if (iy>=2 && iy<=5) {
			h1D_cross[iy]->SetBinContent(3,-532);
			h1D_cross[iy]->SetBinError(3,0);
      exlow[iy][2]=0; exhigh[iy][2]=0;
		}
    if (isPA==0) {
  		if (iy>=2 && iy<=5) {
	  		h1D_cross[iy]->SetBinContent(4,-532);
	  		h1D_cross[iy]->SetBinError(4,0);
        exlow[iy][3]=0; exhigh[iy][3]=0;
	  	}
    }
    else {
  		if (iy>=2 && iy<=4) {
	  		h1D_cross[iy]->SetBinContent(4,-532);
	  		h1D_cross[iy]->SetBinError(4,0);
        exlow[iy][3]=0; exhigh[iy][3]=0;
	  	}
    }
	}

	//////////////////////////////////////////////////////////////////

	TLegend *legBLFW; 
	TLegend *legBLBW;
  if (isPA==0) {
    //legBLFW = new TLegend(0.19, 0.160, 0.46, 0.320);
    //legBLBW = new TLegend(0.19, 0.160, 0.46, 0.320);
    legBLFW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*4+0.035*1.2);
    legBLBW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*4+0.035*1.2);
  } else {
    legBLFW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*3+0.035*1.2);
    legBLBW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*5+0.035*1.2);
  }
	SetLegendStyle(legBLFW);
	SetLegendStyle(legBLBW);
	//legBLFW->SetTextSize(0.034); 
	//legBLBW->SetTextSize(0.034); 
	 	
	TLatex* globtex = new TLatex();
	globtex->SetNDC();
	//globtex->SetTextAlign(12); //1:left, 2:vertical center
  globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
	globtex->SetTextSize(0.04);

	//////////////////////////////////////////////////////////////////////////////////////
	//// convert to TGraphAsymErrors
	TGraphAsymmErrors* g_cross_sys[nRap];	
	TGraphAsymmErrors* g_cross[nRap];	
	for (Int_t iy = 0; iy < nRap; iy++) {
		g_cross_sys[iy] = new TGraphAsymmErrors(h1D_cross[iy]);
		g_cross[iy] = new TGraphAsymmErrors(h1D_cross[iy]);
		g_cross_sys[iy]->SetName(Form("g_cross_sys_%d",iy));
		g_cross[iy]->SetName(Form("g_cross_%d",iy));
    cout << "::: for excel ::: iy= " << iy << endl;
		for (Int_t ipt=0; ipt<nPt; ipt++ ){
			g_cross_sys[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]);
			g_cross_sys[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]);
			//// absolute error calculation 
			eysys[iy][ipt]=eysysrel[iy][ipt]*pytmp[iy][ipt];
			//g_cross_sys[iy]->SetPointError(ipt, exsys[ipt], exsys[ipt], eysys[iy][ipt], eysys[iy][ipt]);
			g_cross_sys[iy]->SetPointError(ipt, exlow[iy][ipt], exhigh[iy][ipt], eysys[iy][ipt], eysys[iy][ipt]);
			g_cross[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]);
			eytmp[iy][ipt] = g_cross[iy]-> GetErrorY(ipt);
			g_cross[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]);
			g_cross[iy]->SetPointEXlow(ipt, ex[ipt]);
			g_cross[iy]->SetPointEXhigh(ipt, ex[ipt]);
			//cout << "" << endl;
      //cout << "cross["<<iy<<"]["<<ipt<<"] = " << pytmp[iy][ipt]<<endl;
			//cout << "stat.["<<iy<<"]["<<ipt<<"] = " << eytmp[iy][ipt]<<endl;
			//cout << "sys.["<<iy<<"]["<<ipt<<"] = " << eysys[iy][ipt]<<endl;
      cout << pytmp[iy][ipt] <<"\t"<<eytmp[iy][ipt] << "\t "<<eysys[iy][ipt]<<endl;
		}
	}

	//////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	//// Draw
	//////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	
  int fw_init_pp = 0, fw_init_pA = 0;
	int bw_init_pp = 4, bw_init_pA = 3;
  int fw_init, bw_init;
  if (isPA==0) { fw_init=fw_init_pp; bw_init=bw_init_pp; }
  else { fw_init=fw_init_pA; bw_init=bw_init_pA; }

  for (Int_t iy = 0; iy < nRap; iy++) {
	  g_cross_sys[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
	  g_cross_sys[iy]->GetXaxis()->CenterTitle("");
	  g_cross_sys[iy]->GetYaxis()->SetTitle("B d^{2}#sigma/dp_{T}dy (#mub/ GeV/c)");
	  g_cross_sys[iy]->GetYaxis()->CenterTitle("");
	  if (isLog) {
		  if (isPA==0) {
		    g_cross_sys[iy]->SetMinimum(0.0000001);
        g_cross_sys[iy]->SetMaximum(1000.);
		  } else {
		    g_cross_sys[iy]->SetMinimum(0.00001);
        //g_cross_sys[iy]->SetMaximum(1000000.);
        g_cross_sys[iy]->SetMaximum(500000.);
  	  }
  	}
  	else {
  		g_cross_sys[iy]->SetMinimum(0.0);
  		if (isPA==0) {
        if (isPrompt) g_cross_sys[iy]->SetMaximum(0.16);
        else g_cross_sys[iy]->SetMaximum(0.016);
  		} else {
        if (isPrompt) g_cross_sys[iy]->SetMaximum(20);
        else g_cross_sys[iy]->SetMaximum(2);
  	  }
  	}
	  //g_cross_sys[iy]->GetXaxis()->SetLimits(0.0, 20.);
	  g_cross_sys[iy]->GetXaxis()->SetLimits(0.0, 32.);
	}

  //// different color scheme for pp and pA
  if (isPA==0) {
	  g_cross_sys[0]->SetFillColorAlpha(kMagenta-10,0.5);
	  g_cross_sys[1]->SetFillColorAlpha(kGreen-10,0.5);
	  g_cross_sys[2]->SetFillColorAlpha(kBlue-10,0.5);
	  g_cross_sys[3]->SetFillColorAlpha(kRed-10,0.5);
	  g_cross_sys[4]->SetFillColorAlpha(kRed-10,0.5);
	  g_cross_sys[5]->SetFillColorAlpha(kBlue-10,0.5);
	  g_cross_sys[6]->SetFillColorAlpha(kGreen-10,0.5);
	  g_cross_sys[7]->SetFillColorAlpha(kMagenta-10,0.5);
	  
    g_cross_sys[0]->SetLineColor(kViolet-6);
	  g_cross_sys[1]->SetLineColor(kGreen+3);
	  g_cross_sys[2]->SetLineColor(kBlue-2);
	  g_cross_sys[3]->SetLineColor(kPink-6);
	  g_cross_sys[4]->SetLineColor(kPink-6);
	  g_cross_sys[5]->SetLineColor(kBlue-2);
	  g_cross_sys[6]->SetLineColor(kGreen+3);
	  g_cross_sys[7]->SetLineColor(kViolet-6);

	  SetGraphStyleFinal(g_cross[0],	8,6);
	  g_cross[0]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[1],	0,5);
	  g_cross[1]->SetMarkerSize(2.1);
	  SetGraphStyleFinal(g_cross[2],	2,3);
	  g_cross[2]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[3],	1,0);
	  g_cross[3]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[4],	1,0);
	  g_cross[4]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[5],	2,3);
	  g_cross[5]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[6],	0,5);
	  g_cross[6]->SetMarkerSize(2.1);
	  SetGraphStyleFinal(g_cross[7],	8,6);
	  g_cross[7]->SetMarkerSize(1.4);

  } else {
	  g_cross_sys[0]->SetFillColorAlpha(kGreen-10,0.5);
	  g_cross_sys[1]->SetFillColorAlpha(kBlue-10,0.5);
	  g_cross_sys[2]->SetFillColorAlpha(kRed-10,0.5);
	  g_cross_sys[3]->SetFillColorAlpha(kRed-10,0.5);
	  g_cross_sys[4]->SetFillColorAlpha(kBlue-10,0.5);
	  g_cross_sys[5]->SetFillColorAlpha(kGreen-10,0.5);
	  g_cross_sys[6]->SetFillColorAlpha(kMagenta-10,0.5);
	  g_cross_sys[7]->SetFillColorAlpha(kGray+1,0.5);
	  
    g_cross_sys[0]->SetLineColor(kGreen+3);
	  g_cross_sys[1]->SetLineColor(kBlue-2);
	  g_cross_sys[2]->SetLineColor(kPink-6);
	  g_cross_sys[3]->SetLineColor(kPink-6);
	  g_cross_sys[4]->SetLineColor(kBlue-2);
	  g_cross_sys[5]->SetLineColor(kGreen+3);
	  g_cross_sys[6]->SetLineColor(kViolet-6);
	  g_cross_sys[7]->SetLineColor(kBlack);

	  SetGraphStyleFinal(g_cross[0],	0,5);
	  g_cross[0]->SetMarkerSize(2.1);
	  SetGraphStyleFinal(g_cross[1],	2,3);
	  g_cross[1]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[2],	1,0);
	  g_cross[2]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[3],	1,0);
	  g_cross[3]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[4],	2,3);
	  g_cross[4]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[5],	0,5);
	  g_cross[5]->SetMarkerSize(2.1);
	  SetGraphStyleFinal(g_cross[6],	8,6);
	  g_cross[6]->SetMarkerSize(1.4);
	  SetGraphStyleFinal(g_cross[7],	9,4);
	  g_cross[7]->SetMarkerSize(2.1);
  }
	
  ////////  Forward
	TCanvas* c_fw = new TCanvas("c_fw","c_fw",200,10,600,600);
	c_fw->cd();
	if (isLog) gPad->SetLogy(1);
	else gPad->SetLogy(0);
	//// 1) cross_sys
	for (Int_t iy = fw_init; iy < bw_init; iy++) {
    if (iy==fw_init) g_cross_sys[iy]->Draw("A5");
    else g_cross_sys[iy]->Draw("5");
	}
	//// 2) cross
	for (Int_t iy = fw_init; iy < bw_init; iy++) {
	  g_cross[iy]->Draw("P");
	}
	//// leg
	legBLFW->SetTextSize(0.032*1.2); 
  legBLFW -> SetHeader("Forward rapidity");
	legBLFW->SetTextSize(0.032); 
  for (Int_t iy = fw_init; iy < bw_init; iy++) {
		if (isScale && scaleF[bw_init-iy-1]!=1.) legBLFW -> AddEntry(g_cross[bw_init-iy-1],Form("%s (x%.0f)",rapArr[bw_init-iy-1].Data(),scaleF[bw_init-iy-1]),"lp");
		else legBLFW -> AddEntry(g_cross[bw_init-iy-1],Form("%s",rapArr[bw_init-iy-1].Data()),"lp");
		//if (isScale && scaleF[iy]!=1.) legBLFW -> AddEntry(g_cross[iy],Form("%s (x%.0f)",rapArr[iy].Data(),scaleF[iy]),"lp");
		//else legBLFW -> AddEntry(g_cross[iy],Form("%s",rapArr[iy].Data()),"lp");
	}
	if (isLog) legBLFW->Draw();
  
  globtex->SetTextSize(0.048);
	globtex->SetTextFont(42);
	if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi");
	else globtex->DrawLatex(0.92, 0.77, "Nonprompt J/#psi");
//	globtex->SetTextSize(0.035);
//	globtex->SetTextFont(42);
//	if (isPA==0) globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 4 \%");
//	else globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 3.5 \%");

	CMS_lumi( c_fw, isPA, iPos );
	c_fw->Update();
  if (isPA==0){
    if (noPtWeight) {
    	c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale));
	  } else {
    	c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale));
    }
  } else {
    if (noPtWeight) {
    	c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale));
	  } else {
    	c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale));
    }
  }
  legBLFW->Clear();
	
  ////////  Backward
	TCanvas* c_bw = new TCanvas("c_bw","c_bw",200,10,600,600);
	c_bw->cd();
	if (isLog) gPad->SetLogy(1);
	else gPad->SetLogy(0);
	//// 1) cross_sys
	for (Int_t iy = bw_init; iy < nRap; iy++) {
    if (iy==bw_init) g_cross_sys[iy]->Draw("A5");
    else g_cross_sys[iy]->Draw("5");
	}
	//// 2) cross
	for (Int_t iy = bw_init; iy < nRap; iy++) {
	  g_cross[iy]->Draw("P");
	}
	//// leg
	legBLBW->SetTextSize(0.032*1.2); 
  legBLBW -> SetHeader("Backward rapidity");
	legBLBW->SetTextSize(0.032); 
  for (Int_t iy = bw_init; iy < nRap; iy++) {
		if (isScale && scaleF[iy]!=1.) legBLBW -> AddEntry(g_cross[iy],Form("%s (x%.0f)",rapArr[iy].Data(),scaleF[iy]),"lp");
		else legBLBW -> AddEntry(g_cross[iy],Form("%s",rapArr[iy].Data()),"lp");
	}
	if (isLog) legBLBW->Draw();
	
  globtex->SetTextSize(0.048);
	globtex->SetTextFont(42);
	if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi");
	else globtex->DrawLatex(0.92, 0.77, "Nonprompt J/#psi");
//	globtex->SetTextSize(0.035);
//	globtex->SetTextFont(42);
//	if (isPA==0) globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 4 \%");
//	else globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 3.5 \%");
	CMS_lumi( c_bw, isPA, iPos );
	c_bw->Update();
  if (isPA==0){
    if (noPtWeight) {
    	c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale));
	  } else {
    	c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale));
    }
  } else {
    if (noPtWeight) {
    	c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale));
	  } else {
    	c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale));
    	c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale));
    }
  }
	legBLBW->Clear();
  	
	///////////////////////////////////////////////////////////////////
	//// save as a root file
	TFile *outFile;
  if (isPA==0) {
    if (noPtWeight) {
      outFile = new TFile(Form("plot_cross/pp_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE");
    } else {
      outFile = new TFile(Form("plot_cross/pp_cross_pt_isPrompt%d_isLog%d_isScale%d.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE");
    }
  }else {
    if (noPtWeight) {
      outFile = new TFile(Form("plot_cross/pA_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE");
    } else {
      outFile = new TFile(Form("plot_cross/pA_cross_pt_isPrompt%d_isLog%d_isScale%d.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE");
    }
  }

	outFile->cd();
	for (Int_t iy = 0; iy < nRap; iy++) {
		g_cross_sys[iy]->Write();	
		g_cross[iy]->Write();	
	}
	outFile->Close();
	
  return;

} // end of main func.
Пример #2
0
//// runCode // 0=merged, 1=1stRun, 2=2ndRun
void draw_1D_RFB_rap(char* dirName = "8rap9pt2gev", int runCode=0, bool isPrompt = true)
{
	//gROOT->Macro("./JpsiStyleForFinalResult.C");
	gROOT->Macro("./tdrstyle_kyo.C");
	gStyle->SetTitleSize(0.046, "XYZ");
  gStyle->SetEndErrorSize(0);
// Margins:
/*
//  gStyle->SetPadTopMargin(0.05);
  gStyle->SetPadBottomMargin(0.132); //KYO
  gStyle->SetPadLeftMargin(0.132); //KYO
  //gStyle->SetPadRightMargin(0.04);
*/	
	gStyle->SetOptTitle(0);
  gStyle->SetPadTopMargin(0.075);
  gStyle->SetPadBottomMargin(0.13); //KYO
  gStyle->SetPadLeftMargin(0.13); //KYO
  gStyle->SetPadRightMargin(0.075);
	gStyle->SetTitleXOffset(1.15);
	gStyle->SetTitleYOffset(1.22);
	
	writeExtraText = true;
	extraText  = "Preliminary";
	lumi_502TeV  = "34.6 nb^{-1}";
	int iPeriod = 0; 
	int iPos=0;

	double pxshift = 0.06;

	// set info.
	const Double_t br = 0.0593 ;
	const Double_t brErr = 0.0006;
	Double_t lumi_nb;
	Double_t lumi_nb_err;
	Double_t lumi_mub;
	Double_t lumi_mub_err;
	string runstring;
	string lumistring;
	string cmsstring = "CMS preliminary";
	string beamstring = "pPb #sqrt{s_{NN}} = 5.02 TeV";
	if (runCode ==0) { runstring = "All"; lumi_nb =34.622; lumi_nb_err=1.2; }
	else if (runCode == 1) { runstring = "Pbp"; lumi_nb =20.7; lumi_nb_err=0.7; }//1stRun
	else if (runCode == 2) { runstring = "pPb"; lumi_nb = 14.0; lumi_nb_err=0.5; }//2ndRun
	else { cout << " *** Error!!! choose runCode 0, 1, or 2 " << endl; return ; }
	lumistring = Form("L_{int} = %.1f nb^{  -1}", lumi_nb);
	lumi_mub = lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1}
	lumi_mub_err = lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1}

	/////////////////////////////////////////////////////////////////////////
	/// systematic uncertainties by hand KYO
	const int nRap = 8;
	const int nPt = 9;
	const int nRapTmp = nRap + 1;
	const int nPtTmp = nPt + 1;
	const int nRapRFB=3;
	Double_t pxtmp_lowpt[nRapRFB]; // x point to fill tmp
	Double_t pxtmp_highpt[nRapRFB]; // x point to fill tmp
	Double_t pytmp_lowpt[nRapRFB]; // y point to fill tmp
	Double_t pytmp_highpt[nRapRFB]; // y point to fill tmp
	Double_t eytmp[nRapRFB]; // y point error to fill tmp
	Double_t ex[nRapRFB] = {0.0, 0.0, 0.0}; //x stat error
	Double_t exsys[nRapRFB] = {0.03, 0.03, 0.03}; //sys x error
	Double_t eysys_lowpt[nRapRFB]; //absolute y sys error
	Double_t eysys_highpt[nRapRFB]; //absolute y sys error
	Double_t eysysrelPR_lowpt[nRapRFB] = { //relative y sys error
		0.04694, //0-0.9
		0.04245, //0.9-1.5
		0.04795}; //1.5-1.93; 
	Double_t eysysrelNP_lowpt[nRapRFB] = {
		0.07412,
		0.06288,
		0.10487};
	Double_t eysysrelPR_highpt[nRapRFB] = { //relative y sys error
		0.03705,
		0.03360,
		0.06486};
	Double_t eysysrelNP_highpt[nRapRFB] = { //relative y sys error
		0.04483,
		0.05592,
		0.09280};
	Double_t eysysrel_lowpt[nRapRFB];
	Double_t eysysrel_highpt[nRapRFB];
	for (int iy=0; iy<nRapRFB; iy++){
		if (isPrompt) { 
			eysysrel_lowpt[iy] = eysysrelPR_lowpt[iy];
			eysysrel_highpt[iy] = eysysrelPR_highpt[iy];
		}
		else { 
			eysysrel_lowpt[iy] = eysysrelNP_lowpt[iy];
			eysysrel_highpt[iy] = eysysrelNP_highpt[iy];
		}
	}
			
	//y_CM array (from forward to backward)
	//Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
	Double_t rapArrNumBF[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
//	const Int_t nRap = sizeof(rapArrNumBF)/sizeof(Double_t)-1;
//	cout << "nRap = " << nRap << endl;
	Double_t rapBinW[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		//rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; 
		rapBinW[iy] = rapArrNumBF[iy+1]-rapArrNumBF[iy]; 
		cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
	}
	//pt array
	Double_t ptArrNum[nPtTmp] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.};
	Double_t ptBinW[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; 
		cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
	}

	// array string
	string rapArr[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		formRapArr(rapArrNumBF[iy], rapArrNumBF[iy+1], &rapArr[iy]);
		cout << iy <<"th rapArr = " << rapArr[iy] << endl;
	}
	string ptArr[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
		cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
	}

	// --- read-in file
	TFile * f2D = new TFile(Form("../fittingResult/total2Dhist_%s.root",dirName));
	cout << "dirName = " << dirName << endl;
	cout << "runCode = " << runCode << ", runstring = " << runstring.c_str() << endl;

	// --- read-in 2D hist for corrected yield
	TH2D* h2D_corrY_Pbp;
	TH2D* h2D_corrY_pPb;
	if (isPrompt) h2D_corrY_Pbp = (TH2D*)f2D->Get("h2D_corrY_PR_Pbp");
	else h2D_corrY_Pbp = (TH2D*)f2D->Get("h2D_corrY_NP_Pbp");
	if (isPrompt) h2D_corrY_pPb = (TH2D*)f2D->Get("h2D_corrY_PR_pPb");
	else h2D_corrY_pPb = (TH2D*)f2D->Get("h2D_corrY_NP_pPb");
	cout << "h2D_corrY_Pbp = " << h2D_corrY_Pbp << endl;
	cout << "h2D_corrY_pPb = " << h2D_corrY_pPb << endl;
	const int nbinsX = h2D_corrY_Pbp->GetNbinsX();
	const int nbinsY = h2D_corrY_Pbp->GetNbinsY();
	cout << "nbinsX = " << nbinsX << endl;
	cout << "nbinsY = " << nbinsY << endl;
	if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; };
	if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; };

	// ---  projection to 1D hist
	TH1D* h1D_corrY_Pbp_tmp[nPt]; // in y_lab(1st)
	TH1D* h1D_corrY_Pbp[nPt]; 
	TH1D* h1D_corrY_pPb_tmp[nPt]; // in y_lab(2nd)
	TH1D* h1D_corrY_pPb[nPt]; //in y_CM

	// iy=0 refers to forwards !!! (ordering here && in CM)
	int tmpbin;
	double tmpval=0;
	double tmperr=0;
	for (Int_t ipt = 0; ipt < nPt; ipt++) {
		h1D_corrY_Pbp_tmp[ipt] = h2D_corrY_Pbp->ProjectionX(Form("h1D_corrY_Pbp_tmp_%d",ipt),ipt+1,ipt+1);
		h1D_corrY_pPb_tmp[ipt] = h2D_corrY_pPb->ProjectionX(Form("h1D_corrY_pPb_tmp_%d",ipt),ipt+1,ipt+1);
		h1D_corrY_Pbp[ipt] = new TH1D(Form("h1D_corrY_Pbp_%d",ipt),Form("h1D_corrY_Pbp_%d",ipt),nRap,rapArrNumBF);
		h1D_corrY_pPb[ipt] = new TH1D(Form("h1D_corrY_pPb_%d",ipt),Form("h1D_corrY_pPb_%d",ipt),nRap,rapArrNumBF);
		h1D_corrY_Pbp[ipt]->Sumw2();
		h1D_corrY_pPb[ipt]->Sumw2();
		
		for (Int_t iy=0; iy<nRap; iy++){
			//1st run
			tmpval = h1D_corrY_Pbp_tmp[ipt]->GetBinContent(iy+1);
			tmperr = h1D_corrY_Pbp_tmp[ipt]->GetBinError(iy+1);
			h1D_corrY_Pbp[ipt]->SetBinContent(nRap-iy,tmpval);
			h1D_corrY_Pbp[ipt]->SetBinError(nRap-iy,tmperr);
			//2nd run
			tmpval = h1D_corrY_pPb_tmp[ipt]->GetBinContent(iy+1);
			tmperr = h1D_corrY_pPb_tmp[ipt]->GetBinError(iy+1);
			h1D_corrY_pPb[ipt]->SetBinContent(iy+1,tmpval);
			h1D_corrY_pPb[ipt]->SetBinError(iy+1,tmperr);
		}
	}
	
	//////////////////////////////////////////////////////////////////////////////////////
	// 1) merge Pbp+pPb corrected yield
	
	TH1D* h1D_corrY_tot[nPt]; 
	
	for (Int_t ipt = 0; ipt < nPt; ipt++) {
		// --- merging
		if (runCode ==0) {	
			h1D_corrY_tot[ipt] = (TH1D*)h1D_corrY_Pbp[ipt]->Clone(Form("h1D_corrY_tot_%d",ipt));
			h1D_corrY_tot[ipt]->Add(h1D_corrY_pPb[ipt]);	
		}
		else if (runCode ==1) {
			h1D_corrY_tot[ipt] = (TH1D*)h1D_corrY_Pbp[ipt]->Clone(Form("h1D_corrY_tot_%d",ipt));
		}
		else if (runCode ==2) {
			h1D_corrY_tot[ipt] = (TH1D*)h1D_corrY_pPb[ipt]->Clone(Form("h1D_corrY_tot_%d",ipt));
		}
		cout <<" "<<endl;
		cout <<ipt<<"th pt !!!"<<endl;
		for (int iy=0; iy <nRap; iy ++ ){ 
			cout << iy <<"th rap" << endl;
			cout << "h1D_corrY_tot = " << h1D_corrY_tot[ipt]->GetBinContent(iy+1)<<endl; 
		}		
	}
	//////////////////////////////////////////////////////////////////
	/////////// calculate RFB
	
	const int lowpt_init=4;
	const int highpt_init=7;	

	// *** pt bin merging
	cout << "*** low pT bin starts from : " << ptArr[lowpt_init].c_str() << endl;
	for (Int_t ipt = lowpt_init+1; ipt < highpt_init; ipt++) {
		h1D_corrY_tot[lowpt_init]->Add(h1D_corrY_tot[ipt]);
		cout << " *** and to low pT, merging : " << ptArr[ipt].c_str() << endl; 
	}
	cout << "*** high pT bin starts from : " << ptArr[highpt_init].c_str() << endl;
	for (Int_t ipt = highpt_init+1; ipt < nPt; ipt++) {
		h1D_corrY_tot[highpt_init]->Add(h1D_corrY_tot[ipt]);
		cout << " *** and to high pT, merging : " << ptArr[ipt].c_str() << endl; 
	}
		
	// |yCM| for drawing (actual binning)
	Double_t rapArrRFBNum[nRapRFB+1] = {0., 0.9, 1.5, 1.93};// for rap dist.
	//const Int_t nRapRFB = sizeof(rapArrRFBNum)/sizeof(Double_t)-1;
	//cout << "nRapRFB = " << nRapRFB << endl;

	TH1D* h1D_RFB[nPt]; //byHand	
	int rap_init = 2;

	// actual RFB calculation
	double tmpFWval[nRapRFB], tmpBWval[nRapRFB]; 
	double tmpFWerr[nRapRFB], tmpBWerr[nRapRFB];
	double actval[nRapRFB], acterr[nRapRFB];
	for (Int_t ipt = 0; ipt < nPt; ipt++) {
		if (ipt != lowpt_init && ipt != highpt_init) continue;
		cout << ipt <<"th pt -- actual RFB *** " << endl;
		h1D_RFB[ipt] = new TH1D(Form("h1D_RFB_%d",ipt),Form("h1D_RFB_%d",ipt),nRapRFB,rapArrRFBNum);
		h1D_RFB[ipt]->Sumw2();
		for (int iy=0; iy <nRapRFB; iy ++ ){ 
			cout << iy<< "th RFB calcul" <<endl;
			tmpFWval[iy] = h1D_corrY_tot[ipt]->GetBinContent(nRap-iy); 
			tmpFWerr[iy] = h1D_corrY_tot[ipt]->GetBinError(nRap-iy); 
			tmpBWval[iy] = h1D_corrY_tot[ipt]->GetBinContent(rap_init+iy+1); 
			tmpBWerr[iy] = h1D_corrY_tot[ipt]->GetBinError(rap_init+iy+1); 
			DivideValue(tmpFWval[iy],tmpFWerr[iy],tmpBWval[iy],tmpBWerr[iy],&actval[iy],&acterr[iy]);
			h1D_RFB[ipt]->SetBinContent(nRapRFB-iy,actval[iy]);	
			h1D_RFB[ipt]->SetBinError(nRapRFB-iy,acterr[iy]);	
		}
	}	
	
	//////////////////////////////////////////////////////////////////
	TLegend *legUR = new TLegend(0.52, 0.75, 0.86, 0.92); //upper left
	TLegend *legUL = new TLegend(0.16, 0.75, 0.45, 0.94, NULL, "brNDC");
	//TLegend *legBL = new TLegend(0.17,0.17,0.42,0.38,NULL,"brNDC");
	TLegend *legBL = new TLegend(0.16,0.17,0.42,0.38,NULL,"brNDC");
//	TLegend *legBR = new TLegend(0.54, 0.17, 0.87, 0.39); //upper left
	TLegend *legBR = new TLegend(0.51, 0.17, 0.85, 0.37); //upper left
	SetLegendStyle(legUR);
	SetLegendStyle(legUL);
	SetLegendStyle(legBL);
	SetLegendStyle(legBR);
	legBR->SetTextSize(0.037);
	 	
	//globtex box for beam, rapidity, pT info
	TLatex* globtex = new TLatex();
	globtex->SetNDC();
	//globtex->SetTextAlign(12); //1:left, 2:vertical center
  globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
	globtex->SetTextSize(0.04);

	// --- Draw histograms
		
	// ---- prompt
	TCanvas* c1 = new TCanvas("c1","c1",200,10,600,600);
	c1->cd();
	
	// --- scaling for drawing norm.
//	h1D_RFB[lowpt_init]->Scale(scalePR_lowpt);
//	h1D_RFB[highpt_init]->Scale(scalePR_highpt);
	string ptArr_lowpt;
	string ptArr_highpt;
	formPtArr(ptArrNum[lowpt_init], ptArrNum[highpt_init], &ptArr_lowpt);
	formPtArr(ptArrNum[highpt_init], ptArrNum[nPt], &ptArr_highpt);
	
	//////////////////////////////////////////////
	/// convert to TGraphErrors	
	
	//lowpt
	TGraphAsymmErrors* gRFB_lowpt = new TGraphAsymmErrors(h1D_RFB[lowpt_init]); 
	gRFB_lowpt->SetName("gRFB_lowpt");
	for (int iy=0; iy <nRapRFB; iy ++ ){ 
		gRFB_lowpt->	SetPointEXlow(iy, ex[iy]);
		gRFB_lowpt->	SetPointEXhigh(iy, ex[iy]);
		gRFB_lowpt->GetPoint(iy, pxtmp_lowpt[iy], pytmp_lowpt[iy]);
		eytmp[iy] = gRFB_lowpt-> GetErrorY(iy);
	}	
	
	//sys_lowpt
	TGraphAsymmErrors* gRFB_sys_lowpt = new TGraphAsymmErrors(h1D_RFB[lowpt_init]); 
	gRFB_sys_lowpt->SetName("gRFB_sys_lowpt");
	for (int iy=0; iy <nRapRFB; iy ++ ){ 
		//abs err calcul.
		eysys_lowpt[iy]=eysysrel_lowpt[iy]*pytmp_lowpt[iy];
		gRFB_sys_lowpt->SetPointError(iy, exsys[iy], exsys[iy], eysys_lowpt[iy], eysys_lowpt[iy]);
		cout << "pytmp_lowpt["<<iy<<"] = " << pytmp_lowpt[iy]<<endl;
		cout << "eytmp_lowpt["<<iy<<"] = " << eytmp[iy]<<endl;
		cout << "eysys_lowpt["<<iy<<"] = " << eysys_lowpt[iy]<<endl;
	}	

	//highpt
	TGraphAsymmErrors* gRFB_highpt = new TGraphAsymmErrors(h1D_RFB[highpt_init]); 
	gRFB_highpt->SetName("gRFB_highpt");
	for (int iy=0; iy <nRapRFB; iy ++ ){ 
		gRFB_highpt->	SetPointEXlow(iy, ex[iy]);
		gRFB_highpt->	SetPointEXhigh(iy, ex[iy]);
		gRFB_highpt->GetPoint(iy, pxtmp_highpt[iy], pytmp_highpt[iy]);
		gRFB_highpt->SetPoint(iy, pxtmp_highpt[iy]+pxshift, pytmp_highpt[iy]);
		eytmp[iy] = gRFB_highpt-> GetErrorY(iy);
	}	
	
	//sys_highpt
	TGraphAsymmErrors* gRFB_sys_highpt = new TGraphAsymmErrors(h1D_RFB[highpt_init]); 
	gRFB_sys_highpt->SetName("gRFB_sys_highpt");
	for (int iy=0; iy <nRapRFB; iy ++ ){ 
		//abs err calcul.
		eysys_highpt[iy]=eysysrel_highpt[iy]*pytmp_highpt[iy];
		gRFB_sys_highpt->GetPoint(iy, pxtmp_highpt[iy], pytmp_highpt[iy]);
		gRFB_sys_highpt->SetPoint(iy, pxtmp_highpt[iy]+pxshift, pytmp_highpt[iy]);
		gRFB_sys_highpt->SetPointError(iy, exsys[iy], exsys[iy], eysys_highpt[iy], eysys_highpt[iy]);
		cout << "pytmp_highpt["<<iy<<"] = " << pytmp_highpt[iy]<<endl;
		cout << "eytmp_highpt["<<iy<<"] = " << eytmp[iy]<<endl;
		cout << "eysys_highpt["<<iy<<"] = " << eysys_highpt[iy]<<endl;
	}	
	
	gRFB_sys_lowpt->GetXaxis()->SetTitle("|y_{CM}|");	
	gRFB_sys_lowpt->GetXaxis()->CenterTitle();	
	gRFB_sys_lowpt->GetYaxis()->SetTitle("R_{FB}");	
//	gRFB_sys_lowpt->GetXaxis()->SetLimits(0.,1.93);	
	gRFB_sys_lowpt->GetXaxis()->SetLimits(0.,2.2);	
	//gRFB_sys_lowpt->SetMinimum(0.0);	
	//gRFB_sys_lowpt->SetMaximum(1.4);	
	gRFB_sys_lowpt->SetMinimum(0.5);
	gRFB_sys_lowpt->SetMaximum(1.15);
	gRFB_sys_lowpt->SetFillColor(kRed-9);	
	//gRFB_sys_lowpt->SetFillStyle(3001);
	gRFB_sys_lowpt->Draw("A2");
	
	gRFB_sys_highpt->SetFillColor(kTeal-9);
	//gRFB_sys_highpt->SetFillStyle(3001);
	gRFB_sys_highpt->Draw("2");
	
	SetGraphStyle(gRFB_lowpt, 1, 3);
	gRFB_lowpt->SetMarkerSize(1.2);
	gRFB_lowpt->Draw("P");	
	
	SetGraphStyle(gRFB_highpt, 0, 5);
	gRFB_highpt->SetMarkerSize(1.9);
	gRFB_highpt->Draw("P");	
	
//	dashedLine(0.,1.,1.93,1.,1,1);
	dashedLine(0.,1.,2.2,1.,1,1);
	//if (isPrompt) legBR -> SetHeader("Prompt J/#psi");
	//else legBR -> SetHeader("Non-prompt J/#psi");
	legBR -> AddEntry(gRFB_lowpt,Form("%s",ptArr_lowpt.c_str()));
	legBR -> AddEntry(gRFB_highpt,Form("%s",ptArr_highpt.c_str()));
	legBR->Draw();
//	latex->SetTextSize(0.05);
//	latex->DrawLatex(0.54, 0.35, cmsstring.c_str());	
//	latex->SetTextSize(0.04);
//	latex->DrawLatex(0.56, 0.27, beamstring.c_str());
//	latex->SetTextSize(0.04);
//	latex->DrawLatex(0.56, 0.20, lumistring.c_str());
	globtex->SetTextSize(0.045);
	globtex->SetTextFont(62);
	if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
	else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");
	CMS_lumi( c1, iPeriod, iPos );
	c1->Update();
	c1->SaveAs(Form("RFB_%s/RFB_rap_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
	c1->SaveAs(Form("RFB_%s/RFB_rap_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));
	
	///////////////////////////////////////////////////////////////////
	// save as a root file
	TFile *outFile = new TFile(Form("RFB_%s/RFB_rap_isPrompt%d.root",dirName,(int)isPrompt),"RECREATE");
	outFile->cd();
	gRFB_sys_lowpt->Write();	
	gRFB_lowpt->Write();	
	gRFB_sys_highpt->Write();	
	gRFB_highpt->Write();	
	outFile->Close();
	
	
	return;

} // end of main func.
int cndr_rootAna_meanPt_wBkg_2(TString szPA="pa", bool isSmall=true){
//int rootAna_muIDvariables(TString szPA = "pa", bool isScaled = true, bool isSmall =true){

	//const int nbin = 100; //arbitrary binning for each pT hist.
	const int nbin = 20; //arbitrary binning for each pT hist.
	const int nEntry = 10000;
		
	gROOT->Macro("../Style.C");

  //// read-in root file
  TFile *fData;
  TFile *fPRMC;
  TTree *treeData;
  TTree *treePRMC;
  if (strcmp(szPA,"pp")==0) {
    fData = new TFile("/storage/OniaTree/Onia5TeV/ppData/OniaTree_DoubleMu_Run2015E-PromptReco-v1_Run_262157_262328_noCUT_TRKMU.root");
    fPRMC = new TFile("/storage/OniaTree/Onia5TeV/ppOfficialMC/OniaTree_JpsiMM_5p02TeV_TuneCUETP8M1_Trk_HINppWinter16DR-75X_mcRun2_asymptotic_ppAt5TeV_v3-v1.root");
    treeData = (TTree*)fData->Get("hionia/myTree");
    treePRMC = (TTree*)fPRMC->Get("hionia/myTree");
  } else if (strcmp(szPA,"pa")==0) {
    fData = new TFile("/home/songkyo/kyo/pPbDataSample/Data/RD2013_pa_1st_run_210676-211256_GR_P_V43D_nocut.root");
    fPRMC = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySample/MCJPsiWithFSR_pa_1st_run_STARTHI53_V27_ext1_nocut.root");
    treeData = (TTree*)fData->Get("myTree");
    treePRMC = (TTree*)fPRMC->Get("myTree");
  }
  else { cout << "WARNING :: Select among szPA = \"pp\" or \"pa\" "; return 0; }

	/////////////////////////////////////////////////////////////	
	////////////// binning
	Double_t ptArr[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10.0, 14.0, 30.0}; // 8rap9pt
	const Int_t nPt = sizeof(ptArr)/sizeof(double)-1;
	cout << "nPt=" << nPt << endl;
	//// in Ycm (will be change to 1st lab and 2nd lab later)
	const int nRap = 1;
	const int nRapTmp = nRap+1;
	Double_t yArr[nRapTmp] = {0.9, 0.0};
	//Double_t yArr[] = {2.4, 1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4}; // 8rap9pt pp
	//Double_t yArr[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87}; // 8rap9pt pA
	//const Int_t nRap = sizeof(yArr)/sizeof(double)-1;
	cout << "nRap=" << nRap << endl;

	TString rapstrArr[nRap];
	for (int ir=0; ir<nRap; ir++){
		formRapArr(yArr[ir+1], yArr[ir], &rapstrArr[ir]);
		cout << "rap string arr = " << rapstrArr[ir].Data() << endl;
	}
	Double_t etArr[] = {0.0, 120.0}; // 8rap9pt
	//Double_t etArr[] = {0.0, 20., 30., 120.0}; // ethf
	const Int_t nEt = sizeof(etArr)/sizeof(double)-1;
	cout << "nEt=" << nEt << endl;
  TString etstrArr[nEt];
	for (int in=0; in<nEt; in++){
		 formEtArr(etArr[in], etArr[in+1], &etstrArr[in]);
		 cout << "et string arr = " << etstrArr[in].Data() << endl;
	}

	/////////////////////////////////////////////////////////////	
  //// cut definitions
  TCut trigCut = "((Reco_QQ_trig&1)==1 && (HLTriggers&1)==1 )";
  TCut recoPairCut = "Reco_QQ_sign==0 && Reco_QQ_VtxProb > 0.01";  
  TCut massNarrow = "Reco_QQ_4mom.M() >2.9 && Reco_QQ_4mom.M() < 3.3";
  TCut massWide = "Reco_QQ_4mom.M() >2.6 && Reco_QQ_4mom.M() < 3.5";
  TCut ctauCut = "-1.5 < Reco_QQ_ctau && Reco_QQ_ctau < 3.0 && 0 < Reco_QQ_ctauErr && Reco_QQ_ctauErr < 1";
  
  //// new cut
  TCut accNewRecoPlus = "(TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.4 && ((TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 1.2 && Reco_QQ_mupl_4mom.Pt() >=3.3) || (1.2 <= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.1 && Reco_QQ_mupl_4mom.Pt() >= 3.93-1.11*TMath::Abs(Reco_QQ_mupl_4mom.Eta())) || (2.1 <= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && Reco_QQ_mupl_4mom.Pt() >= 1.3)))";
  TCut accNewRecoMinus = "(TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.4 && ((TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 1.2 && Reco_QQ_mumi_4mom.Pt() >=3.3) || (1.2 <= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.1 && Reco_QQ_mumi_4mom.Pt() >= 3.93-1.11*TMath::Abs(Reco_QQ_mumi_4mom.Eta())) || (2.1 <= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && Reco_QQ_mumi_4mom.Pt() >= 1.3)))";

  //// muID
  TCut muIDPlus;
  TCut muIDMinus;
  if(strcmp(szPA,"pp")==0) {
    muIDPlus = "Reco_QQ_mupl_highPurity && Reco_QQ_mupl_TrkMuArb && Reco_QQ_mupl_TMOneStaTight && Reco_QQ_mupl_nTrkWMea > 5 && Reco_QQ_mupl_nPixWMea > 0 &&  TMath::Abs(Reco_QQ_mupl_dxy) < 0.3 && TMath::Abs(Reco_QQ_mupl_dz) < 20.";
    muIDMinus = "Reco_QQ_mumi_highPurity && Reco_QQ_mumi_TrkMuArb && Reco_QQ_mumi_TMOneStaTight && Reco_QQ_mumi_nTrkWMea > 5 && Reco_QQ_mumi_nPixWMea > 0 && TMath::Abs(Reco_QQ_mumi_dxy) < 0.3 && TMath::Abs(Reco_QQ_mumi_dz) < 20.";
  }
  else if (strcmp(szPA,"pa")==0) {
    muIDPlus = "Reco_QQ_mupl_isHighPurity && Reco_QQ_mupl_TrkMuArb && Reco_QQ_mupl_TMOneStaTight && Reco_QQ_mupl_nTrkWMea > 5 && Reco_QQ_mupl_nPixWMea > 0 &&  TMath::Abs(Reco_QQ_mupl_dxy) < 0.3 && TMath::Abs(Reco_QQ_mupl_dz) < 20.";
    muIDMinus = "Reco_QQ_mumi_isHighPurity && Reco_QQ_mumi_TrkMuArb && Reco_QQ_mumi_TMOneStaTight && Reco_QQ_mumi_nTrkWMea > 5 && Reco_QQ_mumi_nPixWMea > 0 && TMath::Abs(Reco_QQ_mumi_dxy) < 0.3 && TMath::Abs(Reco_QQ_mumi_dz) < 20.";
  }
  //TCut totalCut = recoPairCut && rapRange && ptRange && accNewRecoPlus && accNewRecoMinus;
  //TCut totalCutMC = recoPairCut && rapRange && ptRange && accNewRecoPlus && accNewRecoMinus;
  
	TCut ptRange[nEt][nRap][nPt];
	TCut rapRange[nEt][nRap][nPt];
	TCut totalCut[nEt][nRap][nPt];
	TCut totalCutBkg[nEt][nRap][nPt];

	//// forming TCut for diffential binning	
	for (int in=0; in<nEt; in++){
		for (int ir=0; ir<nRap; ir++ ) {
			for (int ipt=0; ipt<nPt; ipt++) {
				ptRange[in][ir][ipt] = Form("Reco_QQ_4mom.Pt()>%.1f && Reco_QQ_4mom.Pt()<%.1f",ptArr[ipt] , ptArr[ipt+1]);
				//// change y_CM to y_lab
				if(strcmp(szPA,"pp")==0) {
          rapRange[in][ir][ipt] = Form("Reco_QQ_4mom.Rapidity()>%.2f && Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]);
        } else {  
          rapRange[in][ir][ipt] = Form("-0.47-1.*Reco_QQ_4mom.Rapidity()>%.2f && -0.47-1.*Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]);
				  //rapRangepPb[in][ir][ipt] = Form("-0.47+Reco_QQ_4mom.Rapidity()>%.2f && -0.47+Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]);
        } 
				cout << "ptRange = " <<ptRange[in][ir][ipt] << endl;
				cout << "rapRange = " <<rapRange[in][ir][ipt] << endl;
				totalCut[in][ir][ipt] = trigCut && recoPairCut && massNarrow && ctauCut && accNewRecoPlus && accNewRecoMinus && muIDPlus && muIDMinus && rapRange[in][ir][ipt] && ptRange[in][ir][ipt];
				totalCutBkg[in][ir][ipt] = trigCut && recoPairCut && massWide && (!massNarrow) && ctauCut && accNewRecoPlus && accNewRecoMinus && muIDPlus && muIDMinus && rapRange[in][ir][ipt] && ptRange[in][ir][ipt];
			}
		}
	}
	/////////////////////////////////////////////////////////////	
	/////////////////////////////////////////////////////////////	
	//// define 1D hist
	TH1D *hMeanPt[nEt][nRap][nPt];
	TH1D *hMeanPtBkg[nEt][nRap][nPt];
	double meanVal[nEt][nRap][nPt];
	double maxVal[nEt][nRap][nPt];
	double meanValBkg[nEt][nRap][nPt];
	double maxValBkg[nEt][nRap][nPt];

	TCanvas* cmulti[nEt][nRap];
	TLegend *legUR = new TLegend(0.58,0.68,0.90,0.90,NULL,"brNDC");
	TLegend *legUM = new TLegend(0.30,0.68,0.65,0.90,NULL,"brNDC");
	TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC");
	TLegend *legBM = new TLegend(0.30,0.20,0.65,0.42,NULL,"brNDC");
	SetLegendStyle(legUR);
	SetLegendStyle(legUM);
	SetLegendStyle(legUL);
	SetLegendStyle(legBM);
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);

	for (int in=0; in<nEt; in++){
		for (int ir=0; ir<nRap; ir++ ) {
	 		cmulti[in][ir]= new TCanvas(Form("cmulti_%d_%d",in,ir),Form("%s",rapstrArr[ir].Data()),1500,600);
			cmulti[in][ir]->Divide(5,2);
			for (int ipt=0; ipt<nPt; ipt++) {
				hMeanPt[in][ir][ipt] = new TH1D(Form("hMeanPt_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]);
				hMeanPt[in][ir][ipt] ->Sumw2();
				SetHistStyle(hMeanPt[in][ir][ipt],4,0);
				hMeanPtBkg[in][ir][ipt] = new TH1D(Form("hMeanPtBkg_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]);
				hMeanPtBkg[in][ir][ipt] ->Sumw2();
				SetHistStyle(hMeanPtBkg[in][ir][ipt],3,10);
				cmulti[in][ir]->cd(ipt+1);
				gPad->SetLogy(1);
        if (isSmall) {
				  treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),totalCut[in][ir][ipt],"",nEntry);
				  treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkg[in][ir][ipt],"pe same",nEntry);
			  } else {
				  treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),totalCut[in][ir][ipt],"");
				  treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkg[in][ir][ipt],"pe same");
				}
				meanVal[in][ir][ipt] =  hMeanPt[in][ir][ipt]->GetMean(1);
				maxVal[in][ir][ipt] = 50*hMeanPt[in][ir][ipt]->GetMaximum();
				meanValBkg[in][ir][ipt] =  hMeanPtBkg[in][ir][ipt]->GetMean(1);
				maxValBkg[in][ir][ipt] = 50*hMeanPtBkg[in][ir][ipt]->GetMaximum();
				hMeanPt[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxVal[in][ir][ipt]);
				hMeanPtBkg[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxValBkg[in][ir][ipt]);
				std::cout << hMeanPt[in][ir][ipt]->GetName() <<" : entries = " << hMeanPt[in][ir][ipt]->GetEntries() << std::endl;
				cout << " Cand <p_{T}> = " << meanVal[in][ir][ipt] << endl;			
				cout << " Bkg <p_{T}> = " << meanValBkg[in][ir][ipt] << endl;			
				latex->DrawLatex(0.54, 0.87, rapstrArr[ir].Data());
				latex->DrawLatex(0.54, 0.80, Form("Cand <p_{T}> = %.2f (GeV/c)",meanVal[in][ir][ipt]));
				latex->DrawLatex(0.54, 0.72, Form("Bkg <p_{T}> = %.2f (GeV/c)",meanValBkg[in][ir][ipt]));
				//c1->Update();
				//c1->SaveAs(Form("%s.png",hMeanPt[in][ir][ipt]->GetName()));
				//c1->Clear();
			}
			cmulti[in][ir]->Update();
			cmulti[in][ir]->SaveAs(Form("dir_meanPt_n%d_%dpt/meanPt_%dpt_%d_%d_wBkg_2.pdf",nbin,nPt,nPt,in,ir));
			//cmulti[in][ir]->Clear();
		}
	}
	
	/// Save as a root file
	TFile *outFile = new TFile(Form("dir_meanPt_n%d_%dpt/meanPt_%dpt_wBkg_2.root",nbin,nPt,nPt),"RECREATE");
	outFile->cd();
	for (int in=0; in<nEt; in++){
		for (int ir=0; ir<nRap; ir++ ) {
			for (int ipt=0; ipt<nPt; ipt++) {
				hMeanPt[in][ir][ipt]->Write();
				hMeanPtBkg[in][ir][ipt]->Write();
			}
		}
	}
	outFile->Close();

	return 0;	

}
Пример #4
0
void fitRatio_kyo01(bool isPrompt=true, bool isPbp=true, char* dirName="8rap9pt2gev"){
    gRandom->SetSeed(time(0));
		gROOT->Macro("./JpsiStyle.C");

		//latex box for beam, rapidity, pT info
		TLatex* latex = new TLatex();
		latex->SetNDC();
		latex->SetTextAlign(12);
		latex->SetTextSize(0.04);

		string rapArr[nRap];
		for (Int_t iy=0; iy<nRap; iy++) {
			formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
			cout << iy <<"th rapArr = " << rapArr[iy] << endl;
		}


//    TFile* fin = new TFile(Form("../pPbJPsiAnalysis/2015/004_closure/DataMcReco_8rap9pt/DataMcRecoPt_isPropmt%d.root",(int)isPrompt));//in KNU 
    TFile* fin = new TFile(Form("../004_closure/DataMcReco_%s/DataMcRecoPt_isPropmt%d.root",dirName,(int)isPrompt));//in KNU  //KYO
    string runstring;
    string runstringOverlay;
    if(isPbp) {runstring="Pbp"; runstringOverlay="pPb";}
    else {runstring="pPb"; runstringOverlay="Pbp"; }

    TGraphAsymmErrors* gRatio[nRap];
    TGraphAsymmErrors* gRatioOverlay[nRap];
    for(int iy=0;iy<nRap;iy++){
        gRatio[iy]=(TGraphAsymmErrors*)fin->Get(Form("gRatio_%s_%d",runstring.c_str(),iy));
        gRatioOverlay[iy]=(TGraphAsymmErrors*)fin->Get(Form("gRatio_%s_%d",runstringOverlay.c_str(),iy));
				gRatio[iy]->SetName(Form("gRatio_%d",iy));
				gRatioOverlay[iy]->SetName(Form("gRatioOverlay_%d",iy));
    }

    //TFile* fout= new TFile(Form("ToyGaussian_isPrompt%d_%s.root",(int)isPrompt,runstring.c_str()),"recreate");
    //TFile* fout= new TFile(Form("ToyGaussian_isPrompt%d_%s_kyo01.root",(int)isPrompt,runstring.c_str()),"recreate");//KYO
    TFile* fout= new TFile(Form("fitRatio_isPrompt%d_%s_kyo01.root",(int)isPrompt,runstring.c_str()),"recreate");//KYO

    ////////////////////////////////////////////////////////////
    // Output gaussian parameter histograms

    TH1D* hWeight[nRap];
    // TH1D* hWeightSigma[nRap];
    for(int iy=0;iy<nRap;iy++){
//				if (iy!=0) continue ; //KYO
        hWeight[iy]=new TH1D(Form("hWeight_%s_%d",runstring.c_str(),iy), Form("hWeight_%s_%d",runstring.c_str(),iy), nPtFine, ptFineArrNum);
    //    hWeightSigma[iy]=new TH1D(Form("hWeightSigma_%s_%d",runstring.c_str(),iy), Form("hWeightSigma_%s_%d",runstring.c_str(),iy), nPtFine, ptFineArrNum);
    }
#if 0
    int rapiditybin[nRap],nfpt[nRap];
    double mean[nRap][nPtFine],sigma[nRap][nPtFine];

    TTree* toyGaus[nRap];
    for(int iy=0;iy<nRap;iy++){
        toyGaus[iy]=new TTree(Form("toyGaus%d",iy),Form("rapidity bin %dth",iy));
        toyGaus[iy]->Branch("rapiditybin", &rapiditybin[iy]);
        toyGaus[iy]->Branch("nfpt", &nfpt[iy]);
        toyGaus[iy]->Branch("mean", mean[iy],"mean[nfpt]/D");
        toyGaus[iy]->Branch("sigma", sigma[iy],"sigma[nfpt]/D");
    }
#endif

    ////////////////////////////////////////////////////////////
    // Fitting

//    TF1* fhevi= new TF1("fhevi","[0]/(exp((-x+[1])/[2] +1)+[3])+[4]",0,30);
//    fhevi->SetParameters(-4.795, 1.653, 0.923, 3.018, 2.369);
//    TF1* fexp= new TF1("fexp","[0]/(1+exp([1]*x))+[2]/x",0.0,30.0);//Prompt
    TF1* func[nRap];
   
//    TCanvas* c1 = new TCanvas("c1", "", 1200,1500);
//    c1 -> Divide(3,3);
    TCanvas* c1 = new TCanvas("c1", "", 1600,800); //KYO
    c1 -> Divide(4,2); // KYO
    for(int iy=0;iy<nRap;iy++){
        c1->cd(iy+1);
        if(iy==0 || iy==nRap-1){
            func[iy] = new TF1(Form("func_%d",iy), fitHevi,0.0,30.0,5);
            func[iy]->SetParameters(-4.795, 1.653, 0.923, 3.018, 2.369);
            if(isPrompt==1 && isPbp==0 && iy==0) { 
                //      func[iy]->SetParameters(-51.7167, -0.694876, 0.491544,4.55470,12.1672);
#if 1
                func[iy]->FixParameter(0,-5.17167e+01 );
                func[iy]->FixParameter(1,-6.94876e-01 );
                //func[iy]->FixParameter(2,4.91544e-01 );
                func[iy]->FixParameter(2,9.91544e-01 );
                //func[iy]->FixParameter(3,4.55470e+00 );
                //func[iy]->FixParameter(3,3.55470e+00 );
                //func[iy]->FixParameter(4,1.11672e+01 );
#endif
            }
            else if(isPrompt==1 && isPbp==1 && iy==0) { 
                //func[iy]->FixParameter(0,-5.17167e+01 );
                func[iy]->FixParameter(1,2.06705e+00 );
                func[iy]->FixParameter(2,3.72512e-01 );
                func[iy]->FixParameter(3,3.11521e+00 );
                //func[iy]->FixParameter(4,1.11672e+01 );
            }
           
            else if (isPrompt==0 && isPbp==1 && iy==7) {
                func[iy]->FixParameter(0, -3.40711e+02);
                func[iy]->FixParameter(1, 3.20176e+00); 
                func[iy]->FixParameter(2, 1.09760e+00);
            }


        }  
        //else if(isPrompt==1 && isPbp==0 && iy==4){
        //  func[iy] = new TF1(Form("func_%d",iy), fitHevi,0.0,30.0,5); 
        //  func[iy]->SetParameters(-3.40747e+02,3.32373e+00,6.51294e-01,2.98861e+00,1.14947e+02);
        //} 
        else{
            func[iy] = new TF1(Form("func_%d",iy), fitHevi,0.0,30.0,5); 
            //func[iy]->SetParameters(-3.40711e+02,-2.02319e+00,1.42753e+00,2.98897e+00,1.14958e+02); //yeonju 0509
            func[iy]->SetParameters(-3.40711e+02,-5.20176e+00,1.79760e+00,2.98896e+00,1.14958e+02); //yeonju 0509
            //func[iy]->SetParameters(-3.40747e+02,3.32373e+00,6.51294e-01,2.98861e+00,1.14947e+02); //yeonju
            //yeonju
            if (isPrompt==0 && iy==2) {
                func[iy]->FixParameter(0, -3.40711e+02);
                func[iy]->FixParameter(1, -5.20176e+00); 
                func[iy]->FixParameter(2, 1.79760e+00);
                func[iy]->FixParameter(3, 2.98896);

            } else if (isPrompt==0 && iy==6) {
                func[iy]->FixParameter(0, -3.40711e+02);
                func[iy]->FixParameter(1, 3.20176e+00); 
                func[iy]->FixParameter(2, 1.79760e+00);

            }        
            //KYO
            if (isPrompt && iy==6) {
                func[iy]->FixParameter(0,-3.40743e+02);
                func[iy]->FixParameter(1,-2.56691e+01);
                func[iy]->FixParameter(2,5.14736e+00); 
            }
            else if (isPrompt && (iy==2 || iy==1)) {
                func[iy]->FixParameter(0,-3.40743e+02);
                func[iy]->FixParameter(1,-1.37032e-01);
                func[iy]->FixParameter(2,1.19902);
            }

            /*
               func[iy] = new TF1(Form("func_%d",iy), fitExp,0.0,30.0,3);
               if(isPrompt==0 && isPbp==1 && (iy==2 || iy==3 || iy==4 || iy==5) ) func[iy]->SetParameters(-1.01556e+01,1.51712e-01,2.80282e+01);
               if(isPrompt==0 && isPbp==0 && (iy==2 || iy==3 || iy==4) ) func[iy]->SetParameters(-1.01556e+01,1.51712e-01,2.80282e+01);
               if(isPrompt==1 && isPbp==0 && (iy==3) ) func[iy]->SetParameters(-1.01556e+01,1.51712e-01,2.80282e+01);
               if(isPrompt==1 && isPbp==1 && (iy==3) ) func[iy]->SetParameters(-1.01556e+01,1.51712e-01,2.80282e+01);
               */
        }
        //KYO for TGraphAsymmErrors only
        if (!isPrompt && iy==0){
            func[iy]->SetParameters(-1.04829e+01,-5.38813e+00,2.10443e+00,1.74460e+00,6.89848e+02);
            func[iy]->FixParameter(0,-1.04829e+01);
            func[iy]->FixParameter(1,-5.38813e+00);
            func[iy]->FixParameter(2,2.10443e+00);
        }
        SetGraphStyle(gRatio[iy],2,0);
        SetGraphStyle(gRatioOverlay[iy],4,10);
        func[iy]->SetLineColor(kRed);
        gRatio[iy]->Fit(Form("func_%d",iy));
        gRatio[iy]->Draw("AP");
        gRatioOverlay[iy]->Draw("P");
        //func[iy]->Draw("same");
        if (iy==0){
            if (isPrompt) latex->DrawLatex(0.23,0.23,"Prompt J/#psi Pbp");
            else latex->DrawLatex(0.23, 0.23,"Non-prompt J/#psi Pbp");
        }
        latex->DrawLatex(0.56,0.80,Form("%s",rapArr[iy].c_str()));
        dashedLine(0.,1.,25.,1.,1,1);

        /*
				for(int ifpt=0;ifpt<nPtFine;ifpt++){
            int hBin = gRatio[iy]->FindBin(ptFineArrNum[ifpt+1]-0.1);
            double mean = func[iy]->Eval(ptFineArrNum[ifpt+1]);
            double sigma = gRatio[iy]->GetBinError(hBin) / mean;
            hWeight[iy]->SetBinContent(ifpt+1, mean);
            hWeight[iy]->SetBinError(ifpt+1, sigma);
            //cout <<"x : "<<ptFineArrNum[ifpt+1]-0.01<< ", gRatio bin : " <<hBin << ", Ratio error value : " <<  gRatio[iy]->GetBinError(hBin) << endl;
            //cout << iy+1 << "th rapidity, "<< ifpt<<"th fine ptbin, mean = "<< mean <<", sigma = "<<sigma<<endl;
        }
				*/
    }
    c1 -> Update();

    for(int iy=0;iy<nRap;iy++){
				cout << " **** " <<iy<< "th rap, values at min pT = " <<func[iy]->Eval(minPt[iy])<<endl;	
    }
    
		fout->cd();	
    for(int iy=0;iy<nRap;iy++){
        //hWeight[iy]->Write();
        gRatio[iy]->Write();
        func[iy]->Write();
    }
    c1->Write();
    fout->Close();

}//end of main func.
Пример #5
0
int rootAna_meanPt_wBkg(char *strBin = "8rap9pt"){

	//const int nbin = 100; //arbitrary binning for each pT hist.
	const int nbin = 20; //arbitrary binning for each pT hist.
	const int nEntry = 10000;
		
	gROOT->Macro("./JpsiStyle.C");

	// read-in root file (data)
	TFile *fDataPbp1; // 210498<= runNb <= 210658 should be rejected
	TFile *fDataPbp2; // only 210498<= runNb <= 210658 will be used : 1st 7 run (Reprocessed)
	TFile *fDatapPb;
	fDataPbp1 = new TFile("/home/songkyo/kyo/pPbDataSample/Data/pPbData_1st_ntuple_PromptReco-v1_GR_P_V43D_pileupRej_newAccCut_tot.root");
	fDataPbp2 = new TFile("/home/songkyo/kyo/pPbDataSample/Data/pPbData_1st_ntuple_PromptReco-v1_GR_P_V43F_pileupRej_newAccCut_tot.root");
	fDatapPb = new TFile("/home/songkyo/kyo/pPbDataSample/Data/pPbData_2nd_PromptReco-v1_GR_P_V43D_pileupRej_newAccCut_tot.root");

	TTree *treeDataPbp1 = (TTree*)fDataPbp1->Get("myTree");
	TTree *treeDataPbp2 = (TTree*)fDataPbp2->Get("myTree");
	TTree *treeDatapPb = (TTree*)fDatapPb->Get("myTree");

	/////////////////////////////////////////////////////////////	
	////////////// binning
	Double_t ptArr[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10.0, 14.0, 30.0}; // 8rap9pt
	const Int_t nPt = sizeof(ptArr)/sizeof(double)-1;
	cout << "nPt=" << nPt << endl;
	// in Ycm (will be change to 1st lab and 2nd lab later)
	Double_t yArr[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87}; // 8rap9pt
	const Int_t nRap = sizeof(yArr)/sizeof(double)-1;
	cout << "nRap=" << nRap << endl;
	string rapstrArr[nRap];
	for (int ir=0; ir<nRap; ir++){
		formRapArr(yArr[ir+1], yArr[ir], &rapstrArr[ir]);
		cout << "rap string arr = " << rapstrArr[ir].c_str() << endl;
	}
	Double_t etArr[] = {0.0, 120.0}; // 8rap9pt
	//Double_t etArr[] = {0.0, 20., 30., 120.0}; // ethf
	const Int_t nEt = sizeof(etArr)/sizeof(double)-1;
	cout << "nEt=" << nEt << endl;
	string etstrArr[nEt];
	for (int in=0; in<nEt; in++){
		 formEtArr(etArr[in], etArr[in+1], &etstrArr[in]);
		 cout << "et string arr = " << etstrArr[in].c_str() << endl;
	}

	/////////////////////////////////////////////////////////////	
	////////////// cut definitions
	TCut trigCut = "( (Reco_QQ_trig&1)==1 && (HLTriggers&1)==1 )"; 
	TCut recoCut = "Reco_QQ_size>=1 && Reco_QQ_sign==0";	
//	TCut massRange = "Reco_QQ_4mom.M() >2.6 && Reco_QQ_4mom.M() < 3.5";
	TCut massRange = "Reco_QQ_4mom.M() >2.9 && Reco_QQ_4mom.M() < 3.3";
	TCut massRangeBkg = "((2.6 < Reco_QQ_4mom.M() && Reco_QQ_4mom.M() <2.9) || (3.3 < Reco_QQ_4mom.M() && Reco_QQ_4mom.M() < 3.5))";
	TCut ctauRange = "Reco_QQ_ctau > -3.0 && Reco_QQ_ctau < 5.0 && Reco_QQ_ctauErr > 0.0 && Reco_QQ_ctauErr < 1.0"; 
	TCut accRecoPlus = "(TMath::Abs(Reco_QQ_mupl_4mom.Eta())<2.4) && ( (TMath::Abs(Reco_QQ_mupl_4mom.Eta())<1.2 && Reco_QQ_mupl_4mom.Pt()>=3.3) || ( 1.2<= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.1 && Reco_QQ_mupl_4mom.Pt() >= -(1.0/0.9)*TMath::Abs(Reco_QQ_mupl_4mom.Eta())+(1.2*(1.0/0.9)+2.6)) ||(2.1<=TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && Reco_QQ_mupl_4mom.Pt()>=1.3) )";
	TCut accRecoMinus = "(TMath::Abs(Reco_QQ_mumi_4mom.Eta())<2.4) && ( (TMath::Abs(Reco_QQ_mumi_4mom.Eta())<1.2 && Reco_QQ_mumi_4mom.Pt()>=3.3) || ( 1.2<= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.1 && Reco_QQ_mumi_4mom.Pt() >= -(1.0/0.9)*TMath::Abs(Reco_QQ_mumi_4mom.Eta())+(1.2*(1.0/0.9)+2.6)) ||(2.1<=TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && Reco_QQ_mumi_4mom.Pt()>=1.3) )";
	TCut ptRange[nEt][nRap][nPt];
	TCut rapRangePbp[nEt][nRap][nPt];
	TCut rapRangepPb[nEt][nRap][nPt];
	TCut totalCutPbp[nEt][nRap][nPt];
	TCut totalCutpPb[nEt][nRap][nPt];
	TCut totalCutBkgPbp[nEt][nRap][nPt];
	TCut totalCutBkgpPb[nEt][nRap][nPt];
	TCut runCut = "runNb >=210498 && runNb <= 210658"; //1st 7 run

	// forming TCut for diffential binning	
	for (int in=0; in<nEt; in++){
		for (int ir=0; ir<nRap; ir++ ) {
			for (int ipt=0; ipt<nPt; ipt++) {
				ptRange[in][ir][ipt] = Form("Reco_QQ_4mom.Pt()>%.1f && Reco_QQ_4mom.Pt()<%.1f",ptArr[ipt] , ptArr[ipt+1]);
				//change y_CM to  y_lab
				rapRangePbp[in][ir][ipt] = Form("-0.47-1.*Reco_QQ_4mom.Rapidity()>%.2f && -0.47-1.*Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]);
				rapRangepPb[in][ir][ipt] = Form("-0.47+Reco_QQ_4mom.Rapidity()>%.2f && -0.47+Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]);
				cout << "ptRange = " <<ptRange[in][ir][ipt] << endl;
				cout << "rapRangePbp = " <<rapRangePbp[in][ir][ipt] << endl;
				cout << "rapRangepPb = " <<rapRangepPb[in][ir][ipt] << endl;
				totalCutPbp[in][ir][ipt] = trigCut && recoCut && massRange && ctauRange && accRecoPlus && accRecoMinus && rapRangePbp[in][ir][ipt] && ptRange[in][ir][ipt];
				totalCutpPb[in][ir][ipt] = trigCut && recoCut && massRange && ctauRange && accRecoPlus && accRecoMinus && rapRangepPb[in][ir][ipt] && ptRange[in][ir][ipt];
				totalCutBkgPbp[in][ir][ipt] = trigCut && recoCut && massRangeBkg && ctauRange && accRecoPlus && accRecoMinus && rapRangePbp[in][ir][ipt] && ptRange[in][ir][ipt];
				totalCutBkgpPb[in][ir][ipt] = trigCut && recoCut && massRangeBkg && ctauRange && accRecoPlus && accRecoMinus && rapRangepPb[in][ir][ipt] && ptRange[in][ir][ipt];
			}
		}
	}


	/////////////////////////////////////////////////////////////	
	/////////////////////////////////////////////////////////////	
	// define 1D hist
	TH1D *hMeanPt[nEt][nRap][nPt];
	TH1D *hMeanPtBkg[nEt][nRap][nPt];
	double meanVal[nEt][nRap][nPt];
	double maxVal[nEt][nRap][nPt];
	double meanValBkg[nEt][nRap][nPt];
	double maxValBkg[nEt][nRap][nPt];

	//TCanvas* c1 = new TCanvas("c1","c1",600,600);
	TCanvas* cmulti[nEt][nRap];
	TLegend *legUR = new TLegend(0.58,0.68,0.90,0.90,NULL,"brNDC");
	TLegend *legUM = new TLegend(0.30,0.68,0.65,0.90,NULL,"brNDC");
	TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC");
	TLegend *legBM = new TLegend(0.30,0.20,0.65,0.42,NULL,"brNDC");
	SetLegendStyle(legUR);
	SetLegendStyle(legUM);
	SetLegendStyle(legUL);
	SetLegendStyle(legBM);
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);

	for (int in=0; in<nEt; in++){
		for (int ir=0; ir<nRap; ir++ ) {
	 		cmulti[in][ir]= new TCanvas(Form("cmulti_%d_%d",in,ir),Form("%s",rapstrArr[ir].c_str()),1500,600);
			cmulti[in][ir]->Divide(5,2);
			for (int ipt=0; ipt<nPt; ipt++) {
				hMeanPt[in][ir][ipt] = new TH1D(Form("hMeanPt_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]);
				hMeanPt[in][ir][ipt] ->Sumw2();
				SetHistStyle(hMeanPt[in][ir][ipt],4,0);
				hMeanPtBkg[in][ir][ipt] = new TH1D(Form("hMeanPtBkg_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]);
				hMeanPtBkg[in][ir][ipt] ->Sumw2();
				SetHistStyle(hMeanPtBkg[in][ir][ipt],3,10);
				cmulti[in][ir]->cd(ipt+1);
				gPad->SetLogy(1);
/*				
				treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&(!runCut)),"",nEntry);
				treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&runCut),"",nEntry);
				treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),totalCutpPb[in][ir][ipt],"",nEntry);
				treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&(!runCut)),"pe same",nEntry);
				treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&runCut),"pe same",nEntry);
				treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkgpPb[in][ir][ipt],"pe same",nEntry);
*/

				treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&(!runCut)),"");
				treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&runCut),"");
				treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),totalCutpPb[in][ir][ipt],"");
				treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&(!runCut)),"pe same");
				treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&runCut),"pe same");
				treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkgpPb[in][ir][ipt],"pe same");

				meanVal[in][ir][ipt] =  hMeanPt[in][ir][ipt]->GetMean(1);
				maxVal[in][ir][ipt] = 50*hMeanPt[in][ir][ipt]->GetMaximum();
				meanValBkg[in][ir][ipt] =  hMeanPtBkg[in][ir][ipt]->GetMean(1);
				maxValBkg[in][ir][ipt] = 50*hMeanPtBkg[in][ir][ipt]->GetMaximum();
				hMeanPt[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxVal[in][ir][ipt]);
				hMeanPtBkg[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxValBkg[in][ir][ipt]);
				std::cout << hMeanPt[in][ir][ipt]->GetName() <<" : entries = " << hMeanPt[in][ir][ipt]->GetEntries() << std::endl;
				cout << " Cand <p_{T}> = " << meanVal[in][ir][ipt] << endl;			
				cout << " Bkg <p_{T}> = " << meanValBkg[in][ir][ipt] << endl;			
				latex->DrawLatex(0.54, 0.87, rapstrArr[ir].c_str());
				latex->DrawLatex(0.54, 0.80, Form("Cand <p_{T}> = %.2f (GeV/c)",meanVal[in][ir][ipt]));
				latex->DrawLatex(0.54, 0.72, Form("Bkg <p_{T}> = %.2f (GeV/c)",meanValBkg[in][ir][ipt]));
				//c1->Update();
				//c1->SaveAs(Form("%s.png",hMeanPt[in][ir][ipt]->GetName()));
				//c1->Clear();
			}
			cmulti[in][ir]->Update();
			cmulti[in][ir]->SaveAs(Form("dir_meanPt/meanPt_%s_%d_%d_wBkg.pdf",strBin,in,ir));
			//cmulti[in][ir]->Clear();
		}
	}
	
	/// Save as a root file
	TFile *outFile = new TFile(Form("meanPt_%s_wBkg.root",strBin),"RECREATE");
	std::cout << "strBin : " << strBin << std::endl;
	outFile->cd();
	for (int in=0; in<nEt; in++){
		for (int ir=0; ir<nRap; ir++ ) {
			for (int ipt=0; ipt<nPt; ipt++) {
				hMeanPt[in][ir][ipt]->Write();
				hMeanPtBkg[in][ir][ipt]->Write();
			}
		}
	}
	outFile->Close();

	return 0;	

}
Пример #6
0
void draw_RFB_pt_mergedBin(bool sysByHand=false, bool noPtWeight=false, bool isPrompt=false)
{
  gROOT->Macro("./tdrstyle_kyo.C");
  //cmsTextFont   = 42;  // for b.hong
  //extraTextFont = 42;  // for b.hong
  int isPA = 1;  // 0:pp, 1:pPb
	//int iPos=0; //outside topleft
	int iPos=33; //right corner

  //// BR and lumi info.
  const Double_t br = 0.0593 ;
  const Double_t brErr = 0.0006;
  const Double_t pPb_lumi_nb = 34.622; // 34.6/nb
  const Double_t pPb_lumi_nb_err = 1.211; // 3.5 %
  const Double_t pPb_lumi_mub = pPb_lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1}
  const Double_t pPb_lumi_mub_err = pPb_lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1}
  
  /////////////////////////////////////////////////////////////////////////
  // bin center & systematic uncertainties by hand
  // for 1.5 - 1.93 
  const int nRap = 8; 
  const int nPt = 9;
  const int nRapTmp = nRap + 1;
  const int nPtTmp = nPt + 1;
  const int nRapRFB = 3;  
  const int nPtRFB = 3;
  
  Double_t pxtmp[nRapRFB][nPtRFB]; //x point to fill remporarily
  Double_t pytmp[nRapRFB][nPtRFB]; //y point to fill remporarily
  Double_t eytmp[nRapRFB][nPtRFB]; //y point error to fill remporarily
  /// 2015 PAS
  Double_t px[nRapRFB][nPtRFB] = { // x point (mean pT)
    {5.75945, 7.90077, 13.2826}, //1.5-1.93
    {-531, 7.98106, 13.2588}, //0.9-1.5
    {-531, 8.2616, 13.5598} //0.0-0.9
  };
  Double_t ex[nPtRFB] = {0.,0.,0.}; // x stat error (0)
  Double_t exlow[nRapRFB][nPtRFB];
  Double_t exhigh[nRapRFB][nPtRFB];
  //Double_t exsys[nPtRFB] = {0.25,0.25,0.25}; // x sys err (box width)
  Double_t exsys[nPtRFB] = {0.3,0.3,0.3}; // x sys err (box width)
  Double_t eysys[nRapRFB][nPtRFB]; //absolute y sys error
  //Double_t eysysrel[nRapRFB][nPtRFB]; //relative y sys error
  /*
  Double_t eysysrelPR[nRapRFB][nPtRFB] = {
    {0.04529, 0.04795, 0.06486}, //1.5-1.03
    {0.00, 0.04245, 0.03360}, //0.9-1.5
    {0.00, 0.04694, 0.03705} //0.0-0.9
  };
  Double_t eysysrelNP[nRapRFB][nPtRFB] = {
    {0.06133, 0.10487,  0.09280},
    {0.00, 0.06288, 0.05592},
    {0.00, 0.07412, 0.04483}
  };
  for (int iy=0; iy<nRapRFB; iy++){
    for (int ipt=0; ipt<nPtRFB; ipt++){
      if(isPrompt) eysysrel[iy][ipt] = eysysrelPR[iy][ipt];
      else eysysrel[iy][ipt] = eysysrelNP[iy][ipt];
    }
  }
*/
  //// 1) y_CM array (from forward to backward)
  Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
  //Double_t rapArrNumBF[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
  Double_t rapBinW[nRap];
  for (Int_t iy=0; iy<nRap; iy++) {
    rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1];
    //cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
  }
  //// 2) pt array
  Double_t ptArrNum[nPtTmp] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.};
  Double_t ptBinW[nPt];
  for (Int_t ipt=0; ipt<nPt; ipt++) {
    ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; 
    //cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
  }
  //// array string
  TString rapArr[nRap];
  for (Int_t iy=0; iy<nRap; iy++) {
    formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
    cout << iy <<"th rapArr = " << rapArr[iy] << endl;
  }
  TString ptArr[nPt];
  for (Int_t ipt=0; ipt<nPt; ipt++) {
    formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
    cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
  }

  //////////////////////////////////////////////////////////////  
  //// read-in sys. file 
  TFile * fSys;
  if (isPA==0) fSys = new TFile("../TotalSys/TotSys_8rap9pt_pp_etOpt0.root");
  else fSys = new TFile("../TotalSys/TotSys_8rap9pt_pA_etOpt0.root");
  TH2D* h2D_SysErr;
  if (isPrompt) h2D_SysErr = (TH2D*)fSys->Get("hTotalPR");
  else h2D_SysErr = (TH2D*)fSys->Get("hTotalNP");
//  cout << " *** h2D_SysErr = " <<  h2D_SysErr << endl;  

  /////////////////////////////////////////////////////////////////////////
  //// read-in file
  TFile * f2D;
  if (noPtWeight) f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0_noPtWeight.root");
  else f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0.root");
  //// read-in 2D hist
  TH2D* h2D_CorrY;
  if (isPrompt) h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_PR_pA");
  else h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_NP_pA");
  h2D_CorrY->SetName("h2D_CorrY");  
  const int nbinsX = h2D_CorrY->GetNbinsX();
  const int nbinsY = h2D_CorrY->GetNbinsY();
  if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; };
  if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; };
  
  //// projection to 1D hist : iy=0 refers to forwards !!! (ordering here)
  TH1D* h1D_CorrY[nRap]; 
  TH1D* h1D_SysErr[nRap];
  for (Int_t iy = 0; iy < nRap; iy++) {
    h1D_CorrY[iy] = h2D_CorrY->ProjectionY(Form("h1D_CorrY_%d",iy),iy+1,iy+1);
    h1D_SysErr[iy] = h2D_SysErr->ProjectionY(Form("h1D_SysErr_%d",iy),iy+1,iy+1);
  }
  
  //////////////////////////////////////////////////////////////////
  //// calculate RFB

  TH1D* h1D_RFB_tmp[nRap]; // CorrYield with merged pT    
  TH1D* h1D_RFB[nRapRFB]; // actual RFB   
  TH1D* h1D_RFBSys_tmp[nRap]; // Sys with merged pT   
  TH1D* h1D_RFBSys[nRapRFB]; // Sys F/B   
  
  //// RFB bin setting
  TString rapAbsArr[nRap];
  for (Int_t iy=0; iy<nRapRFB; iy++) {
    formAbsRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapAbsArr[iy]);
    cout << iy <<"th rapAbsArr = " << rapAbsArr[iy] << endl;
  }
  Double_t ptArrRFBNum[nPtRFB+1] = {5.0, 6.5, 10., 30.};
  
  //// ex calculation
  for (Int_t iy=0; iy<nRapRFB; iy++) {
    for (Int_t ipt=0; ipt<nPtRFB; ipt++) {
      exlow[iy][ipt] = px[iy][ipt]-ptArrRFBNum[ipt]; 
      exhigh[iy][ipt] = ptArrRFBNum[ipt+1]-px[iy][ipt]; 
      //cout << iy<<"th y, "<<ipt<<"th pt"<<endl;
      //cout << "exlow = "<< exlow[iy][ipt] << endl;
      //cout << "exhigh = " <<exhigh[iy][ipt] << endl;
    }
  }
  
  //// take proper error propagataion for sys (merge pT bins (KYO - byHand))
  double tmpsys01, tmpsys02, tmpsys03;
  double actsys01, actsys02, actsys03;
  for (int iy=0; iy<nRapRFB*2; iy++){
    h1D_RFBSys_tmp[iy]= new TH1D(Form("h1D_RFBSys_tmp_%d",iy),Form("h1D_RFBSys_tmp_%d",iy),nPtRFB,ptArrRFBNum);
    h1D_RFBSys_tmp[iy]->Sumw2();
    actsys01=0; actsys02=0; actsys03=0;
    //// 1) pT 5-6.5 GeV
    tmpsys01=0; tmpsys02=0;tmpsys03=0;
    if (iy==0 || iy==nRapRFB*2-1){
      //// from relative error to absolute error
      //actsys01=h1D_SysErr[iy]->GetBinContent(4);
      actsys01=h1D_SysErr[iy]->GetBinContent(4)*h1D_CorrY[iy]->GetBinContent(4);  
      h1D_RFBSys_tmp[iy]->SetBinContent(1,actsys01);
    } else {
      h1D_RFBSys_tmp[iy]->SetBinContent(1,0.);
    }
    //// 2) pT 6.5-10. GeV
    tmpsys01=0; tmpsys02=0;tmpsys03=0;
    //// from relative error to absolute error
    tmpsys01=h1D_SysErr[iy]->GetBinContent(5)*h1D_CorrY[iy]->GetBinContent(5);  
    tmpsys02=h1D_SysErr[iy]->GetBinContent(6)*h1D_CorrY[iy]->GetBinContent(6);  
    tmpsys03=h1D_SysErr[iy]->GetBinContent(7)*h1D_CorrY[iy]->GetBinContent(7);  
    //actsys02=TMath::Sqrt( TMath::Power(tmpsys01,2) + TMath::Power(tmpsys02,2) +TMath::Power(tmpsys03,2) );
    actsys02= TMath::Abs(tmpsys01) + TMath::Abs(tmpsys02) +TMath::Abs(tmpsys03) ;
    h1D_RFBSys_tmp[iy]->SetBinContent(2,actsys02);
    //// 3) pT 10.-30. GeV
    tmpsys01=0; tmpsys02=0;tmpsys03=0;
    //// from relative error to absolute error
    tmpsys01=h1D_SysErr[iy]->GetBinContent(8)*h1D_CorrY[iy]->GetBinContent(8);  
    tmpsys02=h1D_SysErr[iy]->GetBinContent(9)*h1D_CorrY[iy]->GetBinContent(9);  
    //actsys03=TMath::Sqrt( TMath::Power(tmpsys01,2) + TMath::Power(tmpsys02,2) );
    actsys03= TMath::Abs(tmpsys01) + TMath::Abs(tmpsys02) ;
    h1D_RFBSys_tmp[iy]->SetBinContent(3,actsys03);
  }
  //TCanvas *ctmp = new TCanvas("ctmp","",1200,800); ctmp->Divide(3,2);
  //for (int iy=0; iy<nRapRFB*2; iy++){
  //  ctmp->cd(iy+1);
  //  h1D_RFBSys_tmp[iy]->Draw("");
  //}
  
  //// merge pT bins (KYO - byHand)
  double tmpPRval01, tmpPRerr01, tmpPRval02, tmpPRerr02, tmpPRval03, tmpPRerr03;
  double actPRval01, actPRerr01, actPRval02, actPRerr02, actPRval03, actPRerr03;
  for (int iy=0; iy<nRapRFB*2; iy++){
    h1D_RFB_tmp[iy]= new TH1D(Form("h1D_RFB_tmp_%d",iy),Form("h1D_RFB_tmp_%d",iy),nPtRFB,ptArrRFBNum);
    h1D_RFB_tmp[iy]->Sumw2();
    actPRval01=0; actPRval02=0; actPRval03=0; actPRerr01=0; actPRerr02=0; actPRerr03=0;
    //// 1) pT 5-6.5 GeV
    tmpPRval01=0; tmpPRval02=0;tmpPRval03=0; tmpPRerr01=0; tmpPRerr02=0;tmpPRerr03=0;
    if (iy==0 || iy==nRapRFB*2-1){
      actPRval01=h1D_CorrY[iy]->GetBinContent(4); 
      actPRerr01=h1D_CorrY[iy]->GetBinError(4); 
      h1D_RFB_tmp[iy]->SetBinContent(1,actPRval01);
      h1D_RFB_tmp[iy]->SetBinError(1,actPRerr01);
    } else {
      h1D_RFB_tmp[iy]->SetBinContent(1,0.);
      h1D_RFB_tmp[iy]->SetBinError(1,0.);
    }
    //// 2) pT 6.5-10. GeV
    tmpPRval01=0; tmpPRval02=0;tmpPRval03=0; tmpPRerr01=0; tmpPRerr02=0;tmpPRerr03=0;
    tmpPRval01=h1D_CorrY[iy]->GetBinContent(5); 
    tmpPRerr01=h1D_CorrY[iy]->GetBinError(5); 
    tmpPRval02=h1D_CorrY[iy]->GetBinContent(6); 
    tmpPRerr02=h1D_CorrY[iy]->GetBinError(6); 
    tmpPRval03=h1D_CorrY[iy]->GetBinContent(7); 
    tmpPRerr03=h1D_CorrY[iy]->GetBinError(7); 
    actPRval02=tmpPRval01+tmpPRval02+tmpPRval03;
    actPRerr02=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) +TMath::Power(tmpPRerr03,2) );
    h1D_RFB_tmp[iy]->SetBinContent(2,actPRval02);
    h1D_RFB_tmp[iy]->SetBinError(2,actPRerr02);
    //// 3) pT 10.-30. GeV
    tmpPRval01=0; tmpPRval02=0;tmpPRval03=0; tmpPRerr01=0; tmpPRerr02=0;tmpPRerr03=0;
    tmpPRval01=h1D_CorrY[iy]->GetBinContent(8); 
    tmpPRerr01=h1D_CorrY[iy]->GetBinError(8); 
    tmpPRval02=h1D_CorrY[iy]->GetBinContent(9); 
    tmpPRerr02=h1D_CorrY[iy]->GetBinError(9); 
    actPRval03=tmpPRval01+tmpPRval02;
    actPRerr03=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) );
    h1D_RFB_tmp[iy]->SetBinContent(3,actPRval03);
    h1D_RFB_tmp[iy]->SetBinError(3,actPRerr03);
    //for (int ipt=0; ipt<nPtRFB; ipt++){
    //  cout << iy<<"th rap, pT merged PR CorrYield = " << h1D_RFB_tmp[iy]->GetBinContent(ipt+1) <<endl;
    //}
  }
  //////////////////////////////////////////////////////////////////
  //// actual RFB calculation 
  for (int iy=0; iy<nRapRFB; iy++){
    h1D_RFB[iy] = (TH1D*)h1D_RFB_tmp[iy]->Clone(Form("h1D_RFB_%d",iy));
    h1D_RFB[iy]->Divide(h1D_RFB_tmp[2*nRapRFB-iy-1]); 
  }
  //// sys F/B calculation
  Double_t dummy;
  for (int iy=0; iy<nRapRFB; iy++){
    for (int ipt=0; ipt<nPtRFB; ipt++){
      //eysysrel[iy][ipt] = TMath::Sqrt(h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1)*h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1)+ h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1)*h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1)); 
      DivideValue(h1D_RFB_tmp[iy]->GetBinContent(ipt+1),h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1),h1D_RFB_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1),h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1),&dummy,&eysys[iy][ipt]);
      //cout << "FW bin = " << h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1) << endl;
      //cout << "BW bin = " << h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1) << endl;
      //cout << "dummy = " << dummy << endl;
      //cout << "eysys["<<iy<<"]["<<ipt<<"] = " << eysys[iy][ipt] << endl;
    }
  }
  //////////////////////////////////////////////////////////////////

  TLegend *legBR = new TLegend(0.50, 0.18, 0.70, 0.39);
  SetLegendStyle(legBR);
  legBR->SetTextSize(0.05);
    
  TLatex* globtex = new TLatex();
  globtex->SetNDC();
  globtex->SetTextAlign(12); //1:left, 2:vertical center
  //globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
  globtex->SetTextSize(0.04);

  //TCanvas* c1 = new TCanvas("c1","c1",600,600);
  //c1->cd();
  
  //////////////////////////////////////////////////////////////////
  //// convert to TGraphAsymErrors
  const int fw_init = 0;
  
  //// 1) sys graph
  TGraphAsymmErrors*gRFB_sys[nRapRFB]; 
  for (int iy=0; iy<nRapRFB; iy++){
    gRFB_sys[iy] = new TGraphAsymmErrors(h1D_RFB[iy]);
    gRFB_sys[iy] -> SetName(Form("gRFB_sys_%d",iy));
    for (int ipt=0; ipt<nPtRFB; ipt++){
      gRFB_sys[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]);
      gRFB_sys[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]);
      //// absolute err calculation
      //eysys[iy][ipt]=eysysrel[iy][ipt]*pytmp[iy][ipt];
      //gRFB_sys[iy]->SetPointError(ipt, exsys[ipt], exsys[ipt], eysys[iy][ipt], eysys[iy][ipt]);
      gRFB_sys[iy]->SetPointError(ipt, exlow[iy][ipt], exhigh[iy][ipt], eysys[iy][ipt], eysys[iy][ipt]);
    }
    gRFB_sys[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
    gRFB_sys[iy]->GetXaxis()->CenterTitle();
    gRFB_sys[iy]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[iy]->GetYaxis()->CenterTitle();
    gRFB_sys[iy]->GetXaxis()->SetLimits(0.,32.0);
    gRFB_sys[iy]->SetMinimum(0.0);
    gRFB_sys[iy]->SetMaximum(1.8);
  }
  
  gRFB_sys[0]->SetFillColorAlpha(kGreen-10,0.5);
  gRFB_sys[1]->SetFillColorAlpha(kRed-10,0.5);
  gRFB_sys[2]->SetFillColorAlpha(kBlue-10,0.5);
  gRFB_sys[0]->SetLineColor(kGreen+3);
  gRFB_sys[1]->SetLineColor(kPink-6);
  gRFB_sys[2]->SetLineColor(kBlue-3);

  //// 2) RFB graph
  TGraphAsymmErrors*gRFB[nRapRFB]; 
  for (int iy=0; iy<nRapRFB; iy++){
    gRFB[iy] = new TGraphAsymmErrors(h1D_RFB[iy]);
    gRFB[iy] -> SetName(Form("gRFB_%d",iy));
    cout << "::: for excel ::: iy= " << iy << endl;
    for (int ipt=0; ipt<nPtRFB; ipt++){
      gRFB[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]);
      eytmp[iy][ipt] = gRFB[iy]-> GetErrorY(ipt);
      gRFB[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]);
      gRFB[iy]->SetPointEXlow(ipt, ex[iy]);
      gRFB[iy]->SetPointEXhigh(ipt, ex[iy]);
      cout << pytmp[iy][ipt] <<"\t"<<eytmp[iy][ipt] << "\t "<<eysys[iy][ipt]<<endl;
    }
  }
  SetGraphStyleFinal(gRFB[0], 0, 5); //1.5-1.93
  SetGraphStyleFinal(gRFB[1], 1, 3); //0.9-1.5
  SetGraphStyleFinal(gRFB[2], 2, 0); //0-0.9
  gRFB[0]->SetMarkerSize(2.6);
  gRFB[1]->SetMarkerSize(1.4);
  gRFB[2]->SetMarkerSize(1.4);

  ///////////////// CANVAS 1  
  TCanvas* c1 = new TCanvas("c1","c1",600,600);
  c1->cd(); 
  gRFB_sys[0]->Draw("A5");
  solidLine(0.,1.,32.,1.,1,1);
  gRFB[0]->Draw("P");
  
  TLegendEntry *le1=legBR->AddEntry("le1",Form("  %s", rapAbsArr[2].Data()),"lpf");
  le1->SetFillColorAlpha(kBlue-10,0.5);
  le1->SetFillStyle(1001);
  le1->SetLineColor(kBlue-3);
  le1->SetMarkerStyle(kFullCircle);
  le1->SetMarkerColor(kBlue-3);
  le1->SetMarkerSize(2.1);
  TLegendEntry *le2=legBR->AddEntry("le2",Form("  %s", rapAbsArr[1].Data()),"lpf");
  le2->SetFillColorAlpha(kRed-10,0.5);
  le2->SetFillStyle(1001);
  le2->SetLineColor(kPink-6);
  le2->SetMarkerStyle(kFullSquare);
  le2->SetMarkerColor(kPink-6);
  le2->SetMarkerSize(2.1);
  TLegendEntry *le3=legBR->AddEntry("le3",Form("  %s", rapAbsArr[0].Data()),"lpf");
  le3->SetFillColorAlpha(kGreen-10,0.5);
  le3->SetFillStyle(1001);
  le3->SetLineColor(kGreen+3);
  le3->SetMarkerStyle(kFullDiamond);
  le3->SetMarkerColor(kGreen+3);
  le3->SetMarkerSize(3.3);

  //legBR->Draw();

  globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
  globtex->SetTextSize(0.05);
  globtex->DrawLatex(0.9, 0.23, rapAbsArr[0].Data());
  
  globtex->SetTextAlign(12); //1:left, 2:vertical center
  globtex->SetTextSize(0.055);
  globtex->SetTextFont(42);
  if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi");
  else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi");

  CMS_lumi( c1, isPA, iPos );
  c1->Update();
  
  if (noPtWeight) { 
    c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap1.pdf",(int)isPrompt));
    c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap1.png",(int)isPrompt));
  } else {
    c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap1.pdf",(int)isPrompt));
    c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap1.png",(int)isPrompt));
  }

  ///////////////// CANVAS 2  
  
  TCanvas* c2 = new TCanvas("c2","c2",600,600);
  c2->cd();
  gRFB_sys[1]->Draw("A5");
  solidLine(0.,1.,32.,1.,1,1);
  gRFB[1]->Draw("P");
  //legBR->Draw();
  
  globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
  globtex->SetTextSize(0.05);
  globtex->DrawLatex(0.9, 0.23, rapAbsArr[1].Data());
  
  globtex->SetTextAlign(12); //1:left, 2:vertical center
  globtex->SetTextSize(0.055);
  globtex->SetTextFont(42);
  if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi");
  else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi");
  
  CMS_lumi( c2, isPA, iPos );
  c2->Update();
 
  if (noPtWeight) { 
    c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap2.pdf",(int)isPrompt));
    c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap2.png",(int)isPrompt));
  } else {
    c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap2.pdf",(int)isPrompt));
    c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap2.png",(int)isPrompt));
  }

  
  ///////////////// CANVAS 3  
  
  TCanvas* c3 = new TCanvas("c3","c3",600,600);
  c3->cd();
  gRFB_sys[2]->Draw("A5");
  solidLine(0.,1.,32.,1.,1,1);
  gRFB[2]->Draw("P");
  ///legBR->Draw();
  
  globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
  globtex->SetTextSize(0.05);
  globtex->DrawLatex(0.9, 0.23, rapAbsArr[2].Data());

  globtex->SetTextAlign(12); //1:left, 2:vertical center
  globtex->SetTextSize(0.055);
  globtex->SetTextFont(42);
  if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi");
  else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi");

  CMS_lumi( c3, isPA, iPos );
  c3->Update();

  if (noPtWeight) { 
    c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap3.pdf",(int)isPrompt));
    c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap3.png",(int)isPrompt));
  } else {
    c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap3.pdf",(int)isPrompt));
    c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap3.png",(int)isPrompt));
  }
  
  ///////////////////////////////////////////////////////////////////
  //// save as a root file
  TFile *outFile;
  if (noPtWeight) outFile = new TFile(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight.root",(int)isPrompt),"RECREATE");
  else outFile = new TFile(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d.root",(int)isPrompt),"RECREATE");
  outFile->cd();
  for (int iy=0; iy<nRapRFB; iy++){
    gRFB_sys[iy]->Write();  
    gRFB[iy]->Write();  
  }
  outFile->Close();
  
  return;

} // end of main func.
void draw_1D_eff_Zvtx1_Zvtx0_pp(TString szBinning="8rap9pt", bool isPrompt=false, bool isLog=false, bool isNoErr=true)
{
	gROOT->Macro("../Style.C");

  double ratiomin = 0.9;
  double ratiomax = 1.1;
  TString szPrompt;
  if (isPrompt) szPrompt = "PR";
  else szPrompt = "NP"; 
  	
	////rap array in yCM (from forward to backward)
	//Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
  Double_t rapArrNumFB[] = {2.4, 1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4};// for pt dist.
	//Double_t rapArrNumBF[] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
  //Double_t rapArrNumBF[] = {-2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93, 2.4};// for rap dist.
	const Int_t nRap = sizeof(rapArrNumFB)/sizeof(Double_t)-1;
	cout << "nRap = " << nRap << endl;
	Double_t rapBinW[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; 
	}
	////pt array
	Double_t ptArrNum[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.}; //8rap9pt
	//Double_t ptArrNum[] = {5.0, 6.5, 10., 30.}; //8rap3pt
	const Int_t nPt = sizeof(ptArrNum)/sizeof(Double_t)-1;
	cout << "nPt = " << nPt << endl;
	Double_t ptBinW[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; 
	}
	//// array TString
	TString rapArr[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
		cout << iy <<"th rapArr = " << rapArr[iy] << endl;
	}
	TString ptArr[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
		cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
	}
	
	// --- read-in file
	TFile * f2D_pp01 = new TFile(Form("../FittingResult/totalHist_pp_%s_newcut_nominal_Zvtx1_SF1_noPtWeight.root",szBinning.Data()));
	TFile * f2D_pp02 = new TFile(Form("../FittingResult/totalHist_pp_%s_newcut_nominal_Zvtx0_SF1_noPtWeight.root",szBinning.Data()));

	// --- read-in 2D hist for data reco dist
	TH2D* h2D_pp01 = (TH2D*)f2D_pp01->Get(Form("h2D_Eff_%s_pp",szPrompt.Data()));
	TH2D* h2D_pp02 = (TH2D*)f2D_pp02->Get(Form("h2D_Eff_%s_pp",szPrompt.Data()));
	cout << "h2D_pp01 = " << h2D_pp01 << endl;
	cout << "h2D_pp02 = " << h2D_pp02 << endl;

	const int nbinsX = h2D_pp01->GetNbinsX();
	const int nbinsY = h2D_pp01->GetNbinsY();
	cout << "nbinsX = " << nbinsX << endl;
	cout << "nbinsY = " << nbinsY << endl;
	if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; };
	if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; };
	
	// ---  projection to 1D hist
	TH1D* h1D_pp01[nbinsX]; 
	TH1D* h1D_pp02[nbinsX]; 
	//// iy=0 refers to forwards !!! (ordering here)
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		h1D_pp01[iy] = h2D_pp01->ProjectionY(Form("h1D_pp01_%d",iy),nbinsX-iy,nbinsX-iy);
		h1D_pp02[iy] = h2D_pp02->ProjectionY(Form("h1D_pp02_%d",iy),nbinsX-iy,nbinsX-iy);
	}
	
	//////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	//// --- set values as zero for unused bins
	//// 8rap9pt pp
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		if (iy>=1 && iy<=6) {
			h1D_pp01[iy]->SetBinContent(1,-532);
			h1D_pp01[iy]->SetBinError(1,0);
			h1D_pp02[iy]->SetBinContent(1,+532);
			h1D_pp02[iy]->SetBinError(1,0);
			h1D_pp01[iy]->SetBinContent(2,-532);
			h1D_pp01[iy]->SetBinError(2,0);
			h1D_pp02[iy]->SetBinContent(2,+532);
			h1D_pp02[iy]->SetBinError(2,0);
		}
		if (iy>=2 && iy<=5) {
			h1D_pp01[iy]->SetBinContent(3,-532);
			h1D_pp01[iy]->SetBinError(3,0);
			h1D_pp02[iy]->SetBinContent(3,+532);
			h1D_pp02[iy]->SetBinError(3,0);
		}
		//if (iy>=2 && iy<=4) {}//pp
    if (iy>=2 && iy<=5) { 
			h1D_pp01[iy]->SetBinContent(4,-532);
			h1D_pp01[iy]->SetBinError(4,0);
			h1D_pp02[iy]->SetBinContent(4,+532);
			h1D_pp02[iy]->SetBinError(4,0);
		}
	}
/*	
  ////// after zero-bin setting, normalize!
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		h1D_pp01[iy]->Scale(1./h1D_pp01[iy]->Integral());
		h1D_pp01[iy]->Scale(1,"width");
		h1D_pp02[iy]->Scale(1./h1D_pp02[iy]->Integral());
		h1D_pp02[iy]->Scale(1,"width");
	}
*/
  
  //// calculate ratio
  TH1D* hRatio_pp[nRap];
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		hRatio_pp[iy]=(TH1D*)h1D_pp01[iy]->Clone(Form("hRatio_pp_%d",iy));
		hRatio_pp[iy]->Divide(h1D_pp02[iy]);
    if (isNoErr) {
      for (int ipt=0; ipt<nbinsY; ipt++) {
        hRatio_pp[iy]->SetBinError(ipt+1,0.);
        cout << iy <<"th rap, "<<ipt<<"th pT, ratio = "<<hRatio_pp[iy]->GetBinContent(ipt+1)<<endl;
      }
    }
  }
	
	//////////////////////////////////////////////////////////////////
	//// Draw plots
	//////////////////////////////////////////////////////////////////
  TGraphAsymmErrors* g_pp01[nbinsX];
  TGraphAsymmErrors* g_pp02[nbinsX];

	TLegend *legBR = new TLegend(0.55, 0.28, 0.86, 0.40);
	SetLegendStyle(legBR);
	 	
	//latex box for beam, rapidity, pT info
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);

	TCanvas* c01 = new TCanvas("c01","c01",200,10,1600,800);
	c01->Divide(4,2);
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		g_pp01[iy]=new TGraphAsymmErrors(h1D_pp01[iy]);
		g_pp01[iy]->SetName(Form("g_pp01_%d",iy));
		g_pp02[iy]=new TGraphAsymmErrors(h1D_pp02[iy]);
		g_pp02[iy]->SetName(Form("g_pp02_%d",iy));
		
    c01->cd(iy+1);
		if (isLog) gPad->SetLogy(1);
		else gPad->SetLogy(0);
		SetGraphStyle(g_pp01[iy],3,0);
		SetGraphStyle(g_pp02[iy],4,10);
		
		g_pp01[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
		g_pp01[iy]->GetXaxis()->CenterTitle();
		g_pp01[iy]->GetXaxis()->SetLimits(0.0,30.0);
		g_pp01[iy]->GetYaxis()->SetTitle("Efficiency");
		g_pp01[iy]->GetYaxis()->SetRangeUser(0,1.0);
		
		g_pp01[iy]->Draw("AP");
		g_pp02[iy]->Draw("P");
		if (iy==0) {
			legBR -> AddEntry(g_pp01[iy],"z vtx weight","lp");
			legBR -> AddEntry(g_pp02[iy],"no weight","lp");
			legBR->Draw();
			if (isPrompt) latex->DrawLatex(0.19,0.23,"pp Prompt J/#psi");
			else latex->DrawLatex(0.19, 0.23,"pp Nonprompt J/#psi");
		}
		latex->DrawLatex(0.55,0.23,Form("%s",rapArr[iy].Data()));
	}
	c01->Modified();
	c01->Update();
	c01->SaveAs(Form("dir_1D_%s/eff_isPrompt%d_isLog%d_Zvtx1_Zvtx0_pp.pdf",szBinning.Data(),(int)isPrompt,(int)isLog));

  //////////////////////////////////////////////////////////////////
	//// hRatio, and convert to gRatio (TGraphAsymErrors)
	//////////////////////////////////////////////////////////////////
	
  TCanvas* c02 = new TCanvas("c02","c02",200,10,1600,800);
	c02->Divide(4,2);	
	
	TGraphAsymmErrors* gRatio_pp[nbinsX];
	
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		gRatio_pp[iy]=new TGraphAsymmErrors(hRatio_pp[iy]);
		gRatio_pp[iy]->SetName(Form("gRatio_pp_%d",iy));
	  SetGraphStyle(gRatio_pp[iy],1,0);
/*  	for (Int_t ipt=0; ipt<nbinsY; ipt++ ){
			gRatio_pp[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]);	
			gRatio_pp[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]);
			gRatio_pp[iy]->SetPointEXlow(ipt, ex[ipt]);
			gRatio_pp[iy]->SetPointEXhigh(ipt, ex[ipt]);
		}*/
		c02->cd(iy+1);
		gRatio_pp[iy]->GetXaxis()->SetLimits(0.0,30.0);
		gRatio_pp[iy]->GetXaxis()->CenterTitle();
		gRatio_pp[iy]->SetMinimum(ratiomin);
		gRatio_pp[iy]->SetMaximum(ratiomax);
		gRatio_pp[iy]->GetYaxis()->CenterTitle();
		gRatio_pp[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
		gRatio_pp[iy]->GetYaxis()->SetTitle("[Weight] / [No weight]");
		gRatio_pp[iy]->Draw("AP");
		if (iy==0){
			if (isPrompt) latex->DrawLatex(0.19,0.23,"pp Prompt J/#psi");
			else latex->DrawLatex(0.19, 0.23,"pp Nonprompt J/#psi");
		}
		latex->DrawLatex(0.55,0.23,Form("%s",rapArr[iy].Data()));
		dashedLine(0.,1.,30.,1.,1,1);
	}	
	c02->SaveAs(Form("dir_1D_%s/effRatio_isPrompt%d_isLog%d_Zvtx1_Zvtx0_pp.pdf",szBinning.Data(),(int)isPrompt,(int)isLog));





	return;

} // end of main func.
Пример #8
0
//// runCode // 0=merged, 1=1stRun, 2=2ndRun
void draw_1D_acceff_pt_Pbp(char* dirName = "8rap9pt2gev", bool isLog=false)
{
	gROOT->Macro("./JpsiStyle.C");
	
	//rap array in yCM (from forward to backward)
	Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
	//Double_t rapArrNumBF[] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
	const Int_t nRap = sizeof(rapArrNumFB)/sizeof(Double_t)-1;
	cout << "nRap = " << nRap << endl;
	Double_t rapBinW[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; 
		cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
	}
	//pt array
	//Double_t ptArrNum[] = {0.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.};
	Double_t ptArrNum[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.};
	const Int_t nPt = sizeof(ptArrNum)/sizeof(Double_t)-1;
	cout << "nPt = " << nPt << endl;
	Double_t ptBinW[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; 
		cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
	}

	// array string
	string rapArr[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
		cout << iy <<"th rapArr = " << rapArr[iy] << endl;
	}
	string ptArr[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
		cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
	}
	
	// --- read-in file
	TFile * f2D = new TFile(Form("../total2Dhist_%s.root",dirName));
	cout << "dirName = " << dirName << endl;

	// --- read-in 2D hist for data reco dist
	TH2D* h2D_Acc_pt_y_PRMC_Pbp;
	TH2D* h2D_Acc_pt_y_NPMC_Pbp;
	h2D_Acc_pt_y_PRMC_Pbp = (TH2D*)f2D->Get("h2D_Acc_pt_y_PRMC_Pbp");
	h2D_Acc_pt_y_NPMC_Pbp = (TH2D*)f2D->Get("h2D_Acc_pt_y_NPMC_Pbp");
	h2D_Acc_pt_y_PRMC_Pbp->SetName("h2D_Acc_pt_y_PRMC_Pbp");
	h2D_Acc_pt_y_NPMC_Pbp->SetName("h2D_Acc_pt_y_NPMC_Pbp");
	cout << "h2D_Acc_pt_y_PRMC_Pbp = " << h2D_Acc_pt_y_PRMC_Pbp << endl;
	cout << "h2D_Acc_pt_y_NPMC_Pbp = " << h2D_Acc_pt_y_NPMC_Pbp << endl;
	TH2D* h2D_Eff_pt_y_PRMC_Pbp;
	TH2D* h2D_Eff_pt_y_NPMC_Pbp;
	h2D_Eff_pt_y_PRMC_Pbp = (TH2D*)f2D->Get("h2D_Eff_pt_y_PRMC_Pbp");
	h2D_Eff_pt_y_NPMC_Pbp = (TH2D*)f2D->Get("h2D_Eff_pt_y_NPMC_Pbp");
	h2D_Eff_pt_y_PRMC_Pbp->SetName("h2D_Eff_pt_y_PRMC_Pbp");
	h2D_Eff_pt_y_NPMC_Pbp->SetName("h2D_Eff_pt_y_NPMC_Pbp");

	// Acc*Eff
	h2D_Acc_pt_y_PRMC_Pbp->Multiply(h2D_Eff_pt_y_PRMC_Pbp);	
	h2D_Acc_pt_y_NPMC_Pbp->Multiply(h2D_Eff_pt_y_NPMC_Pbp);	

	const int nbinsX = h2D_Acc_pt_y_PRMC_Pbp->GetNbinsX();
	const int nbinsY = h2D_Acc_pt_y_PRMC_Pbp->GetNbinsY();
	cout << "nbinsX = " << nbinsX << endl;
	cout << "nbinsY = " << nbinsY << endl;
	if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; };
	if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; };
	
	// ---  projection to 1D hist
	TH1D* h1D_acceff_PRMC[nbinsX]; 
	TH1D* h1D_acceff_NPMC[nbinsX]; 
	
	// iy=0 refers to forwards !!! (ordering here)
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		////// for the 1st run
		h1D_acceff_PRMC[iy] = h2D_Acc_pt_y_PRMC_Pbp->ProjectionY(Form("h1D_acceff_PRMC_%d",iy),iy+1,iy+1);
		h1D_acceff_NPMC[iy] = h2D_Acc_pt_y_NPMC_Pbp->ProjectionY(Form("h1D_acceff_NPMC_%d",iy),iy+1,iy+1);
		////// for the 2nd run
		//h1D_acceff_PRMC[iy] = h2D_Acc_pt_y_PRMC_pPb->ProjectionY(Form("h1D_acceff_PRMC_%d",iy),nbinsX-iy,nbinsX-iy);
		//h1D_acceff_NPMC[iy] = h2D_Acc_pt_y_NPMC_pPb->ProjectionY(Form("h1D_acceff_NPMC_%d",iy),nbinsX-iy,nbinsX-iy);
	}
	
	//////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	
	// set values as zero for unused bins
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		if (iy>=1 && iy<=6) {
			h1D_acceff_PRMC[iy]->SetBinContent(1,0);
			h1D_acceff_PRMC[iy]->SetBinError(1,0);
			h1D_acceff_NPMC[iy]->SetBinContent(1,0);
			h1D_acceff_NPMC[iy]->SetBinError(1,0);
		}
		if (iy>=2 && iy<=5) {
			h1D_acceff_PRMC[iy]->SetBinContent(2,0);
			h1D_acceff_PRMC[iy]->SetBinContent(3,0);
			h1D_acceff_PRMC[iy]->SetBinError(2,0);
			h1D_acceff_PRMC[iy]->SetBinError(3,0);
			h1D_acceff_NPMC[iy]->SetBinContent(2,0);
			h1D_acceff_NPMC[iy]->SetBinContent(3,0);
			h1D_acceff_NPMC[iy]->SetBinError(2,0);
			h1D_acceff_NPMC[iy]->SetBinError(3,0);
		}
		if (iy>=2 && iy<=4) {
			h1D_acceff_PRMC[iy]->SetBinContent(4,0);
			h1D_acceff_PRMC[iy]->SetBinError(4,0);
			h1D_acceff_NPMC[iy]->SetBinContent(4,0);
			h1D_acceff_NPMC[iy]->SetBinError(4,0);
		}
	}
	
	////// after zero-bin setting, normalize!
//	for (Int_t iy = 0; iy < nbinsX; iy++) {
//		h1D_acceff_PRMC[iy]->Scale(1./h1D_acceff_PRMC[iy]->Integral());
//		h1D_acceff_NPMC[iy]->Scale(1./h1D_acceff_NPMC[iy]->Integral());
//		h1D_acceff_PRMC[iy]->Scale(1,"width");
//		h1D_acceff_NPMC[iy]->Scale(1,"width");
//	}
	
	//////////////////////////////////////////////////////////////////
	//// --- Draw histograms

	//TLegend *legUR = new TLegend(0.52, 0.55, 0.86, 0.92); //upper left
	TLegend *legUR = new TLegend(0.45, 0.75, 0.86, 0.92); //upper left
	TLegend *legUL = new TLegend(0.18, 0.75, 0.59, 0.92); //upper left
	TLegend *legBL = new TLegend(0.18, 0.18, 0.59, 0.35); //upper left
	TLegend *legBR = new TLegend(0.49, 0.28, 0.86, 0.40); //upper left
	SetLegendStyle(legUR);
	SetLegendStyle(legUL);
	SetLegendStyle(legBL);
	SetLegendStyle(legBR);
	 	
	//latex box for beam, rapidity, pT info
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);

	//TCanvas* c_multi = new TCanvas("c_multi","c_multi",200,10,600,600);
	//TCanvas* c_multi = new TCanvas("c_multi","c_multi",200,10,1500,600);
	//c_multi->Divide(5,2);
	TCanvas* c_multi = new TCanvas("c_multi","c_multi",200,10,1600,800);
	c_multi->Divide(4,2);
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		c_multi->cd(iy+1);
		if (isLog) gPad->SetLogy(1);
		else gPad->SetLogy(0);
		SetHistStyle(h1D_acceff_PRMC[iy],1,0);
		//SetHistStyle(h1D_acceff_NPMC[iy],2,0);
		SetHistStyle(h1D_acceff_NPMC[iy],2,10);
		h1D_acceff_PRMC[iy]->GetXaxis()->SetTitle("p_{T} [GeV/c]");
		h1D_acceff_PRMC[iy]->GetXaxis()->CenterTitle();
		h1D_acceff_PRMC[iy]->GetXaxis()->SetRangeUser(0.,30.);
		h1D_acceff_PRMC[iy]->GetYaxis()->SetTitle("Acceptance*Efficiency");
		//h1D_acceff_PRMC[iy]->GetYaxis()->SetRangeUser(0,1.0);
//		h1D_acceff_PRMC[iy]->GetYaxis()->SetRangeUser(0,0.6);
		h1D_acceff_PRMC[iy]->GetYaxis()->SetRangeUser(0,0.7);
		h1D_acceff_PRMC[iy]->Draw("pe");
		h1D_acceff_NPMC[iy]->Draw("pe same");
		if (iy==0) {
//			if (isPrompt) legBR -> SetHeader("Prompt J/#psi ");
//			else legBR -> SetHeader("Non-prompt J/#psi ");
//			legBR -> AddEntry(h1D_acceff_PRMC[iy],"1st run (Pbp)","lp");
//			legBR -> AddEntry(h1D_acceff_NPMC[iy],"2nd run (pPb)","lp");
			legUL -> SetHeader("1st run");
			legUL -> AddEntry(h1D_acceff_PRMC[iy],"Prompt J/#psi","lp");
			legUL -> AddEntry(h1D_acceff_NPMC[iy],"Non-prompt J/#psi","lp");
			legUL->Draw();
		}
		//latex->DrawLatex(0.46,0.68,Form("%s",rapArr[iy].c_str()));
		//latex->DrawLatex(0.46,0.85,Form("%s",rapArr[iy].c_str()));
		//latex->DrawLatex(0.46,0.20,Form("%s",rapArr[iy].c_str()));
		latex->DrawLatex(0.49,0.20,Form("%s",rapArr[iy].c_str()));
	}
//	c_multi->cd(10);//tmp
//	legBR->Draw();
	c_multi->SaveAs(Form("acc_%s/acceff_pt_Pbp_isLog%d.pdf",dirName,(int)isLog));







/*
	// root file
	TFile *fOut = new TFile(Form("1Dhist_%s/crossSection_pt_%s.root",dirName,runstring.c_str()),"RECREATE");
	fOut->cd();
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		h1D_fit_pt_y_NP_Pbp[iy]->Write();
		h1D_fit_pt_y_NP_pPb[iy]->Write();
		h1D_fit_pt_y_NP_tot[iy]->Write();
	}
	//tRap->Write();
	fOut->Close();
*/
	return;

} // end of main func.
Пример #9
0
void comp_RpPb_rap_Overlay(bool isPoint=true, bool isSmoothened=false)
{
	gROOT->Macro("./tdrstyle_kyo.C");
	int isPA = 10;  // 0:pp, 1:pPb, 10 : pp & pPb together for RpPb plot
	int iPos=33;

  bool isPrompt=true;
	
  const Double_t pp_lumi_relerr = 0.023; // 2.3 %
  const Double_t pPb_lumi_relerr = 0.035; // 3.5 %
  const Double_t glb_err = TMath::Sqrt(pp_lumi_relerr*pp_lumi_relerr+pPb_lumi_relerr*pPb_lumi_relerr);
  //cout << "glb_err = " << glb_err << endl;
  
  ///////////////////////////////////////////////////
  const int nRap = 8; 
  const int nRapTmp = nRap + 1;
	const int nRapRpPb = 7;
	const int nRapRpPbTheory = 6; //Ramona..
	//const int nPtRpPb = 49;
	const int nPtRpPb = 2;
  Double_t theory_px[nPtRpPb][nRapRpPbTheory]; 
	Double_t theory_py[nPtRpPb][nRapRpPbTheory];
	//Double_t theory_exlow_tmp[nPtRpPb][nRapRpPbTheory];
	//Double_t theory_exhigh_tmp[nPtRpPb][nRapRpPbTheory];
  Double_t theory_exlow[nPtRpPb][nRapRpPbTheory];
  Double_t theory_exhigh[nPtRpPb][nRapRpPbTheory];
	Double_t theory_eylow_tmp[nPtRpPb][nRapRpPbTheory];
	Double_t theory_eyhigh_tmp[nPtRpPb][nRapRpPbTheory];
  Double_t theory_eylow[nPtRpPb][nRapRpPbTheory];
	Double_t theory_eyhigh[nPtRpPb][nRapRpPbTheory];
  
  //// 1) y_CM array (from forward to backward)
  Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
  //Double_t rapArrNumBF[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
  //// array string
  TString rapArr[nRap];
  for (Int_t iy=0; iy<nRap; iy++) {
    formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
    cout << iy <<"th rapArr = " << rapArr[iy] << endl;
  }
  
	///////////////////////////////////////////////////
  //////// experimental points	
  TFile *inFile = new TFile("../DrawFinalPlot/plot_RpPb/RpPb_rap_isPrompt1.root");
  
  TGraphAsymmErrors* g_RpPb_sys[nRapRpPb];
  TGraphAsymmErrors* g_RpPb_sys_line[nRapRpPb];
  TGraphAsymmErrors* g_RpPb[nRapRpPb];
  g_RpPb_sys[0] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_lowpt");
  g_RpPb_sys_line[0] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_lowpt_line");
  g_RpPb[0] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_lowpt");
  g_RpPb_sys[1] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_highpt");
  g_RpPb_sys_line[1] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_highpt_line");
  g_RpPb[1] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_highpt");
  g_RpPb_sys[0]->SetName("g_RpPb_sys_lowpt");
  g_RpPb_sys_line[0]->SetName("g_RpPb_sys_lowpt_line");
  g_RpPb_sys[1]->SetName("g_RpPb_sys_highpt");
  g_RpPb_sys_line[1]->SetName("g_RpPb_sys_highpt_line");
  //g_RpPb_sys[0]->SetFillColorAlpha(kRed-10,0.5);
  //g_RpPb_sys_line[0]->SetFillColorAlpha(kRed-10,0.);
  //g_RpPb_sys_line[0]->SetLineColor(kPink-6);
  //g_RpPb_sys[1]->SetFillColorAlpha(kGreen-10,0.5);
  //g_RpPb_sys_line[1]->SetFillColorAlpha(kGreen-10,0.);
  //g_RpPb_sys_line[1]->SetLineColor(kGreen+3);
  g_RpPb_sys_line[0]->SetFillColorAlpha(kRed-10,0.);
  g_RpPb_sys_line[1]->SetFillColorAlpha(kRed-10,0.);
  for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
    if (isPoint) {
      g_RpPb_sys[ipt]->SetFillColorAlpha(kRed-10,0.5);
      g_RpPb_sys[ipt]->SetLineColor(kPink-6);
    } else {
      g_RpPb_sys[ipt]->SetFillColor(kWhite);
      g_RpPb_sys[ipt]->SetLineColor(kWhite);
    }
    g_RpPb[ipt]->SetMarkerColor(kPink-6);
    g_RpPb[ipt]->SetLineColor(kPink-6);
    g_RpPb[ipt]->SetMarkerStyle(kFullCircle);
    g_RpPb[ipt]->SetMarkerSize(1.4);
  }
  
  ///////////////////////////////////////////////////
  //////// theory curves	
//  const int nTheory = 4;
  const int nTheory = 3;
  TFile *inFileTh[nTheory];
  inFileTh[0]= new TFile("./plot_theory/comp_RpPb_rap_isSmoothened0_Vogt.root","READ");
  inFileTh[1]= new TFile("./plot_theory/comp_RpPb_rap_isSmoothened0_Lansberg_EPS09NLO.root","READ");
  inFileTh[2]= new TFile("./plot_theory/comp_RpPb_rap_isSmoothened0_Lansberg_nCTEQ15.root","READ");
  
  TGraphAsymmErrors* g_RpPb_theory[nTheory][nPtRpPb];
  TGraphAsymmErrors* g_RpPb_theory_line[nTheory][nPtRpPb];
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
      g_RpPb_theory[ith][ipt] = (TGraphAsymmErrors*)inFileTh[ith]->Get(Form("g_RpPb_theory_%d",ipt));
      g_RpPb_theory[ith][ipt]->SetName(Form("g_RpPb_theory_%d_%d",ith,ipt));
      g_RpPb_theory_line[ith][ipt] = (TGraphAsymmErrors*)inFileTh[ith]->Get(Form("g_RpPb_theory_%d",ipt));
      g_RpPb_theory_line[ith][ipt]->SetName(Form("g_RpPb_theory_line_%d_%d",ith,ipt));
    } 
  } 

  //// color
  for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
    g_RpPb_theory[0][ipt]->SetFillColorAlpha(kAzure+1,0.5);
    g_RpPb_theory[0][ipt]->SetLineColor(kAzure+1);
    g_RpPb_theory[0][ipt]->SetFillStyle(1001);
    g_RpPb_theory_line[0][ipt]->SetFillColorAlpha(kAzure+5,0.0);
    g_RpPb_theory_line[0][ipt]->SetLineColor(kAzure+5);
    g_RpPb_theory_line[0][ipt]->SetFillStyle(1001);
    g_RpPb_theory[1][ipt]->SetFillColor(kOrange+2);
    g_RpPb_theory[1][ipt]->SetLineColor(kOrange+2);
    g_RpPb_theory[1][ipt]->SetFillStyle(3345);
    //g_RpPb_theory[1][ipt]->SetFillStyle(3004);
    g_RpPb_theory_line[1][ipt]->SetFillColorAlpha(kOrange+2,0.);
    g_RpPb_theory_line[1][ipt]->SetLineColor(kOrange+2);
    g_RpPb_theory_line[1][ipt]->SetFillStyle(1001);
    g_RpPb_theory[2][ipt]->SetFillColor(kGreen+2);
    g_RpPb_theory[2][ipt]->SetLineColor(kGreen+2);
    g_RpPb_theory[2][ipt]->SetFillStyle(3454);
    //g_RpPb_theory[2][ipt]->SetFillStyle(3005);
    g_RpPb_theory_line[2][ipt]->SetFillColorAlpha(kGreen+2,0.);
    g_RpPb_theory_line[2][ipt]->SetLineColor(kGreen+2);
    g_RpPb_theory_line[2][ipt]->SetFillStyle(1001);
  } 
	///////////////////////////////////////////////////
	//// Draw
  ///////////////////////////////////////////////////
	
	//TLegend *legBL1 = new TLegend(0.195, 0.168, 0.38, 0.333);
	TLegend *legBL1 = new TLegend(0.195, 0.168, 0.38, 0.388);
	SetLegendStyle(legBL1);
	//legBL1->SetTextSize(0.05);
	legBL1->SetTextSize(0.037);
  
  TLatex* globtex = new TLatex();
	globtex->SetNDC();
	globtex->SetTextAlign(12); //1:left, 2:vertical center
  //globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
	globtex->SetTextSize(0.075);
 
  //// global uncertainty from lumi
	TBox * globbox_pp = new TBox(-3.0, 1-pp_lumi_relerr, -2.8, 1+pp_lumi_relerr);
	globbox_pp->SetFillColorAlpha(kGray+2,0.5);
	globbox_pp->SetLineColor(kBlack);
	TBox * globbox_pa = new TBox(-2.8, 1-pPb_lumi_relerr, -2.6, 1+pPb_lumi_relerr);
	globbox_pa->SetFillColorAlpha(kWhite,0.5);
	globbox_pa->SetLineColor(kBlack);
	TBox * globbox_all = new TBox(-2.7, 1-glb_err, -2.5, 1+glb_err);
	globbox_all->SetFillColorAlpha(kGray+2,0.5);
	globbox_all->SetLineColor(kBlack);

  TCanvas* c1 = new TCanvas("c1","c1",600,600);
  c1->cd();
  
  g_RpPb_sys[0]->Draw("A5"); 
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith==0){
      g_RpPb_theory[ith][0]->Draw("5");
      g_RpPb_theory_line[ith][0]->Draw("5");
    }
  }
//  if (isPoint) { g_RpPb_sys[0]->Draw("5"); }
  globbox_all->Draw("lf");
  solidLine(-2.7,1.,2.1,1.,1,1);
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith!=0){
      g_RpPb_theory[ith][0]->Draw("5");
    }
    g_RpPb_theory_line[ith][0]->Draw("5");
  }
  if (isPoint) {
    g_RpPb_sys_line[0]->Draw("5");
    g_RpPb[0]->Draw("p");
  }

  globtex->SetTextAlign(12);
	globtex->SetTextSize(0.045);
	globtex->SetTextFont(42);
  globtex->DrawLatex(0.21, 0.84, "6.5 < p_{T} < 10 GeV/c");
  
  TLegendEntry *ent_data=legBL1->AddEntry("ent_data"," Data","pf");
	ent_data->SetFillColorAlpha(kRed-10,0.5);
	ent_data->SetLineColor(kPink-6);
	ent_data->SetMarkerColor(kPink-6);
  ent_data->SetMarkerStyle(kFullCircle);
  ent_data->SetLineWidth(1);
//  ent_data->SetMarkerSize(1.9);
  ent_data->SetFillStyle(1001);
  TLegendEntry *ent1_thr=legBL1->AddEntry("ent1_thr"," EPS09 NLO (Vogt)","f");
	ent1_thr->SetFillColorAlpha(kAzure+1,0.5);
	ent1_thr->SetLineColor(kAzure+5);
  ent1_thr->SetFillStyle(1001);
  TLegendEntry *ent2_thr=legBL1->AddEntry("ent2_thr"," EPS09 NLO (Lansberg-Shao)","f");
	ent2_thr->SetFillColor(kOrange+2);
	ent2_thr->SetLineColor(kOrange+2);
  ent2_thr->SetFillStyle(3345);
  TLegendEntry *ent3_thr=legBL1->AddEntry("ent3_thr"," nCTEQ15 NLO (Lansberg-Shao)","f");
	ent3_thr->SetFillColor(kGreen+2);
	ent3_thr->SetLineColor(kGreen+2);
  ent3_thr->SetFillStyle(3454);
//  TLegendEntry *ent5_thr=legBL1->AddEntry("ent5_thr","(Lansberg-Shao)","f");
//	ent5_thr->SetFillColor(kWhite);
//	ent5_thr->SetLineColor(kWhite);
//  ent5_thr->SetFillStyle(1001);
	legBL1->Draw();

  globtex->SetTextAlign(32); //3:right 2:vertical center	
  globtex->SetTextSize(0.048);
	globtex->SetTextFont(42);
	if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi");
	else globtex->DrawLatex(0.92, 0.77, "Non-prompt J/#psi");
	
  CMS_lumi( c1, isPA, iPos );
    
  c1->SaveAs(Form("plot_theory/comp_RpPb_rap_pt1_isSmoothened%d_Overlay.pdf",(int)isSmoothened));
  c1->SaveAs(Form("plot_theory/comp_RpPb_rap_pt1_isSmoothened%d_Overlay.png",(int)isSmoothened));
 
 
  TCanvas* c2 = new TCanvas("c2","c2",600,600);
  c2->cd();
  
  g_RpPb_sys[1]->Draw("A5"); 
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith==0){
      g_RpPb_theory[ith][1]->Draw("5");
      g_RpPb_theory_line[ith][1]->Draw("5");
    }
  }
//  if (isPoint) { g_RpPb_sys[1]->Draw("5"); }
  globbox_all->Draw("lf");
  solidLine(-2.7,1.,2.1,1.,1,1);
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith!=0){
      g_RpPb_theory[ith][1]->Draw("5");
    }
    g_RpPb_theory_line[ith][1]->Draw("5");
  }
  if (isPoint) {
    g_RpPb_sys_line[1]->Draw("5");
    g_RpPb[1]->Draw("p");
  }
  
  globtex->SetTextAlign(12);
	globtex->SetTextSize(0.045);
	globtex->SetTextFont(42);
  globtex->DrawLatex(0.21, 0.84, "10 < p_{T} < 30 GeV/c");
  
  legBL1->Draw();
  
  globtex->SetTextAlign(32); //3:right 2:vertical center	
  globtex->SetTextSize(0.048);
	globtex->SetTextFont(42);
	if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi");
	else globtex->DrawLatex(0.92, 0.77, "Non-prompt J/#psi");
	
  CMS_lumi( c2, isPA, iPos );
    
  c2->SaveAs(Form("plot_theory/comp_RpPb_rap_pt2_isSmoothened%d_Overlay.pdf",(int)isSmoothened));
  c2->SaveAs(Form("plot_theory/comp_RpPb_rap_pt2_isSmoothened%d_Overlay.png",(int)isSmoothened));
 
 
 
  
  ///////////////////////////////////////////////////////////////////
  // save as a root file
//  TFile* outFile = new TFile(Form("plot_theory/comp_RpPb_rap_isSmoothened%d_Overlay.root",(int)isSmoothened),"RECREATE");
//  outFile->cd();
//  for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
//    g_RpPb_theory[ipt]->Write();
//  } 

  return;
}
//// runCode // 0=merged, 1=1stRun, 2=2ndRun
void draw_1D_RFB_ETHF_tworange(char* dirName = "6rap3pt", int runCode=0,  bool isPrompt=false)
{
    gROOT->Macro("./tdrstyle_kyo.C");
    gStyle->SetTitleSize(0.046, "XYZ");
    gStyle->SetEndErrorSize(0);
    gStyle->SetOptTitle(0);
    gStyle->SetPadTopMargin(0.075);
    gStyle->SetPadBottomMargin(0.13); //KYO
    gStyle->SetPadLeftMargin(0.13); //KYO
    gStyle->SetPadRightMargin(0.075);
    gStyle->SetTitleXOffset(1.15);
    gStyle->SetTitleYOffset(1.22);

    writeExtraText = true;
    extraText  = "Preliminary";
    lumi_502TeV  = "34.6 nb^{-1}";
    int iPeriod = 0;
    int iPos=0;

    //double pxshift = 0.5;
    double pxshift = 1.;

    // set info.
    const Double_t br = 0.0593 ;
    const Double_t brErr = 0.0006;
    Double_t lumi_nb;
    Double_t lumi_nb_err;
    Double_t lumi_mub;
    Double_t lumi_mub_err;
    string runstring;
    string lumistring;
    string cmsstring = "CMS preliminary";
    string beamstring = "pPb #sqrt{s_{NN}} = 5.02 TeV";
    if (runCode ==0) {
        runstring = "All";
        lumi_nb =34.622;
        lumi_nb_err=1.2;
    }
    else if (runCode == 1) {
        runstring = "Pbp";    //1stRun
        lumi_nb =20.7;
        lumi_nb_err=0.7;
    }
    else if (runCode == 2) {
        runstring = "pPb";    //2ndRun
        lumi_nb = 14.0;
        lumi_nb_err=0.5;
    }
    else {
        cout << " *** Error!!! choose runCode 0, 1, or 2 " << endl;
        return ;
    }
    lumistring = Form("L_{int} = %.1f nb^{  -1}", lumi_nb);
    lumi_mub = lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1}
    lumi_mub_err = lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1}

    /////////////////////////////////////////////////////////////////////////
    // bin center & systematic uncertainties by hand
    //inh=0 : pT 5-6.5, rap 1.5-1.93
    //inh=1 : pT 6.5-30, rap 1.5-1.93
    //inh=2 : pT 6.5-30, rap 0.9-1.5
    //inh=3 : pT 6.5-30, rap 0.0-0.9
    const int nRap = 6;
    const int nRapTmp = nRap+1;
    const int nPt = 3;
    const int nPtTmp = nPt+1;
    const int nEt = 3;
    const int nEtTmp = nEt+1;
    const int nHist = 4;
    const int nHistTmp = nHist+1;
    Double_t pxtmp[nHist][nEt]; //x point to fill temp
    Double_t pytmp[nHist][nEt]; //y point to fill temp
    Double_t eytmp[nHist][nEt]; //y stat error to fill temp
    Double_t px[nEt] = {9.4, 24.3, 37.2}; // x point
    Double_t ex[nEt] = {0.,0.,0.}; // x stat error
    Double_t exsys[nEt] = {0.5, 0.5, 0.5};; //x sys error
    Double_t eysys[nHist][nEt]; //absolute y sys error
    Double_t eysysrel[nHist][nEt]; //relative y sys error
    Double_t eysysrelPR[nHist][nEt] = {
        {0.05299,0.06155,0.06715}, //1.5-1.93 low
        {0.05088,0.05442,0.05913}, //1.5-1.93
        {0.03741,0.04958,0.04227}, //0.9-1.5
        {0.04425,0.04528,0.05314} //0.0-0.9
    };
    Double_t eysysrelNP[nHist][nEt] = {
        {0.04971,0.06138,0.06459}, // 1.5-1.93 low
        {0.05188,0.05442,0.05999}, //0.5-1.93
        {0.03694,0.04952,0.04221}, //0.9-1.5
        {0.04242,0.04349,0.05162} //0.0-0.9
    };

    for (int inh = 0; inh < nHist; inh++ ) {
        for (int iet = 0; iet < nEt; iet++ ) {
            if (isPrompt) eysysrel[inh][iet] = eysysrelPR[inh][iet];
            else eysysrel[inh][iet] = eysysrelNP[inh][iet];
        }
    }

    //rap array in yCM (from forward to backward)
    Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93};// for pt dist.
    //Double_t rapArrNumBF[nRapTmp] = {-1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
    Double_t rapBinW[nRap];
    for (Int_t iy=0; iy<nRap; iy++) {
        rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1];
        cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
    }
    //pt array
    Double_t ptArrNum[nPtTmp] = {5.0, 6.5, 10., 30.}; //6rap3pt
    Double_t ptBinW[nPt];
    for (Int_t ipt=0; ipt<nPt; ipt++) {
        ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt];
        cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
    }
    //ethf array
    Double_t etArrNum[nEtTmp] = {0.0, 20.0, 30.0, 120.0};

    // array string
    string rapArr[nRap];
    for (Int_t iy=0; iy<nRap; iy++) {
        formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
        cout << iy <<"th rapArr = " << rapArr[iy] << endl;
    }
    string ptArr[nPt];
    for (Int_t ipt=0; ipt<nPt; ipt++) {
        formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
        cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
    }
    string etArr[nEt];
    for (Int_t i=0; i<nEt; i++) {
        formEtArr(etArrNum[i], etArrNum[i+1], &etArr[i]);
        cout << "etArr["<<i<<"] = "<< etArr[i].c_str() << endl;
    }

    // --- read-in file
    TFile * f2D = new TFile(Form("../fittingResult/total2Dhist_%s.root",dirName));
    cout << "dirName = " << dirName << endl;
    cout << "runCode = " << runCode << ", runstring = " << runstring.c_str() << endl;

    // --- read-in 2D hist for corrected yield
    TH2D* h2D_corrY_Pbp[nEt];
    TH2D* h2D_corrY_pPb[nEt];
    for (int iet=0; iet<nEt; iet++) {
        if (isPrompt) {
            h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_PR_Pbp_%d",iet));
            h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_PR_pPb_%d",iet));
        }
        else {
            h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_NP_Pbp_%d",iet));
            h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_NP_pPb_%d",iet));
        }
        cout << iet << "th h2D_corrY_Pbp = " << h2D_corrY_Pbp[iet] << endl;
        cout << iet << "th h2D_corrY_pPb = " << h2D_corrY_pPb[iet] << endl;
    }

    const int nbinsX = h2D_corrY_Pbp[0]->GetNbinsX();
    const int nbinsY = h2D_corrY_Pbp[0]->GetNbinsY();
    cout << "nbinsX = " << nbinsX << endl;
    cout << "nbinsY = " << nbinsY << endl;
    if (nbinsX != nRap) {
        cout << " *** Error!!! nbinsX != nRap";
        return;
    };
    if (nbinsY != nPt) {
        cout << " *** Error!!! nbinsY != nPt";
        return;
    };

    // ---  projection to 1D hist
    TH1D* h1D_corrY_Pbp[nEt][nbinsX];
    TH1D* h1D_corrY_pPb[nEt][nbinsX];
    // iy=0 refers to forwards !!! (ordering here)
    for (Int_t iet=0; iet<nEt; iet++) {
        for (Int_t iy = 0; iy < nbinsX; iy++) {
            h1D_corrY_Pbp[iet][iy] = h2D_corrY_Pbp[iet]->ProjectionY(Form("h1D_corrY_Pbp_%d_%d",iet,iy),iy+1,iy+1);
            h1D_corrY_Pbp[iet][iy]->SetName(Form("h1D_corrY_Pbp_%d_%d",iet,iy));
            //for 2nd run
            h1D_corrY_pPb[iet][iy] = h2D_corrY_pPb[iet]->ProjectionY(Form("h1D_corrY_pPb_%d_%d",iet,iy),nbinsX-iy,nbinsX-iy);
            h1D_corrY_pPb[iet][iy]->SetName(Form("h1D_corrY_pPb_%d_%d",iet,iy));
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////
    // 1) merge Pbp+pPb corrected yield
    TH1D* h1D_corrY_tot[nEt][nbinsX];
    for (Int_t iet=0; iet<nEt; iet++) {
        for (Int_t iy = 0; iy < nbinsX; iy++) {
            if (runCode ==0) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
                h1D_corrY_tot[iet][iy]->Add(h1D_corrY_pPb[iet][iy]);
            }
            else if (runCode ==1) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
            }
            else if (runCode ==2) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_pPb[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
            }
        }
    }

    //////////////////////////////////////////////////////////////////
    /////////// calculate RFB

    const int nRapRFB = 3;
    TH1D* h1D_RFB_tmp[nEt][nbinsX]; // corrYield with merged pT
    TH1D* h1D_RFB[nEt][nRapRFB]; // actual RFB vs pt

    // bin settingg
    string rapAbsArr[nRap];
    for (Int_t iy=0; iy<nRapRFB; iy++) {
        formAbsRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapAbsArr[iy]);
        cout << iy <<"th rapAbsArr = " << rapAbsArr[iy] << endl;
    }
    Double_t ptArrRFBNum[] = {5.0, 6.5, 30.};
    const Int_t nPtRFB = sizeof(ptArrRFBNum)/sizeof(Double_t)-1;
    cout << "nPtRFB = " << nPtRFB << endl;

    // merging pT bins (KYO - byHand)
    double tmpPRval01, tmpPRerr01, tmpPRval02, tmpPRerr02;
    double actPRval01, actPRerr01, actPRval02, actPRerr02;
    for (int iet=0; iet<nEt; iet++) {
        for (int iy=0; iy<nRapRFB*2; iy++) {
            h1D_RFB_tmp[iet][iy]= new TH1D(Form("h1D_RFB_tmp_%d_%d",iet,iy),Form("h1D_RFB_tmp_%d_%d",iet,iy),nPtRFB,ptArrRFBNum);
            h1D_RFB_tmp[iet][iy]->Sumw2();
            actPRval01=0;
            actPRval02=0;
            actPRerr01=0;
            actPRerr02=0;
            // 1) pT 5-6.5 GeV
            tmpPRval01=0;
            tmpPRval02=0;
            tmpPRerr01=0;
            tmpPRerr02=0;
            if (iy==0 || iy==nRapRFB*2-1) {
                actPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(1);
                actPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(1);
                h1D_RFB_tmp[iet][iy]->SetBinContent(1,actPRval01);
                h1D_RFB_tmp[iet][iy]->SetBinError(1,actPRerr01);
            } else {
                h1D_RFB_tmp[iet][iy]->SetBinContent(1,0.);
                h1D_RFB_tmp[iet][iy]->SetBinError(1,0.);
            }
            // 2) pT 6.5-30. GeV
            tmpPRval01=0;
            tmpPRval02=0;
            tmpPRerr01=0;
            tmpPRerr02=0;
            tmpPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(2);
            tmpPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(2);
            tmpPRval02=h1D_corrY_tot[iet][iy]->GetBinContent(3);
            tmpPRerr02=h1D_corrY_tot[iet][iy]->GetBinError(3);
            actPRval02=tmpPRval01+tmpPRval02;
            actPRerr02=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) );
            h1D_RFB_tmp[iet][iy]->SetBinContent(2,actPRval02);
            h1D_RFB_tmp[iet][iy]->SetBinError(2,actPRerr02);
        }
    }

    // actual RFB calculation	vs pT!!
    for (int iet=0; iet<nEt; iet++) {
        for (int iy=0; iy<nRapRFB; iy++) {
            h1D_RFB[iet][iy] = (TH1D*)h1D_RFB_tmp[iet][iy]->Clone(Form("h1D_RFB_%d_%d",iet,iy));
            h1D_RFB[iet][iy]->Divide(h1D_RFB_tmp[iet][2*nRapRFB-iy-1]);
            cout << iet<<"th, "<<iy<<"th h1D_RFB = "<<h1D_RFB[iet][iy]<<endl;
        }
    }

    ///////////////////////////////////////////////
    //////// --- RFB vs ETHF : 4 histograms
    //inh=0 : pT 5-6.5, rap 1.5-1.93
    //inh=1 : pT 6.5-30, rap 1.5-1.93
    //inh=2 : pT 6.5-30, rap 0.9-1.5
    //inh=3 : pT 6.5-30, rap 0.0-0.9
    double tmpRFBval01, tmpRFBerr01, tmpRFBval02, tmpRFBerr02, tmpRFBval03, tmpRFBerr03;
    TH1D* h1D_RFB_ETHF[nHist];

    for (int inh=0; inh< nHist; inh++) {
        h1D_RFB_ETHF[inh]= new TH1D(Form("h1D_RFB_ETHF_%d",inh),Form("h1D_RFB_ETHF_%d",inh),nEt,etArrNum);
        h1D_RFB_ETHF[inh]->Sumw2();
        tmpRFBval01=0;
        tmpRFBerr01=0;
        tmpRFBval02=0;
        tmpRFBerr02=0;
        tmpRFBval03=0;
        tmpRFBerr03=0;
        for (int iet=0; iet<nEt; iet++) {
            if (inh==0) {
                tmpRFBval01=h1D_RFB[iet][0]->GetBinContent(1);
                tmpRFBerr01=h1D_RFB[iet][0]->GetBinError(1);
                h1D_RFB_ETHF[inh]->SetBinContent(iet+1,tmpRFBval01);
                h1D_RFB_ETHF[inh]->SetBinError(iet+1,tmpRFBerr01);
            }
            else {
                tmpRFBval01=h1D_RFB[iet][inh-1]->GetBinContent(2);
                tmpRFBerr01=h1D_RFB[iet][inh-1]->GetBinError(2);
                h1D_RFB_ETHF[inh]->SetBinContent(iet+1,tmpRFBval01);
                h1D_RFB_ETHF[inh]->SetBinError(iet+1,tmpRFBerr01);
            }
        }
    }

    //////////////////////////////////////////////////////////////////
    /////////// samey
    //////////////////////////////////////////////////////////////////
    TCanvas* c1 = new TCanvas("c1","c1",600,600);
    c1->cd();

//	TLegend *legBL = new TLegend(0.16, 0.16, 0.43, 0.41); //bottom left
    TLegend *legBL = new TLegend(0.16, 0.16, 0.40, 0.36); //bottom left
    TLegend *legBL2 = new TLegend(0.16, 0.16, 0.40, 0.40); //bottom left
//	TLegend *legUR = new TLegend(0.36, 0.77, 0.89, 0.95); //upper left
    TLegend *legUR = new TLegend(0.34, 0.71, 0.89, 0.88); //upper left
    SetLegendStyle(legBL);
    SetLegendStyle(legBL2);
    //legBL->SetTextSize(0.032);
    legBL->SetTextSize(0.037);
    legBL2->SetTextSize(0.037);

    //globtex box for beam, rapidity, pT info
    TLatex* globtex = new TLatex();
    globtex->SetNDC();
    //globtex->SetTextAlign(12); //1:left, 2:vertical center
    globtex->SetTextAlign(32); //3:right 2:vertical center
    globtex->SetTextFont(42);
    globtex->SetTextSize(0.04);

    // convert to TGraphAsymErrors
    //RFB
    TGraphAsymmErrors*gRFB[nHist];
    for (int inh=0; inh< nHist; inh++) {
        gRFB[inh] = new TGraphAsymmErrors(h1D_RFB_ETHF[inh]);
        gRFB[inh]->SetName(Form("gRFB_%d",inh));
        for (int iet=0; iet<nEt; iet++) {
            gRFB[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            eytmp[inh][iet] = gRFB[inh] -> GetErrorY(iet);
//			gRFB[inh]->SetPoint(iet, px[iet], pytmp[inh][iet]);
            gRFB[inh]->SetPoint(iet, px[iet]+pxshift*inh, pytmp[inh][iet]);
            gRFB[inh]->SetPointEXlow(iet, ex[inh]);
            gRFB[inh]->SetPointEXhigh(iet, ex[inh]);
        }
    }

    //sys
    TGraphAsymmErrors* gRFB_sys[nHist];
    for (int inh=0; inh< nHist; inh++) {
        gRFB_sys[inh] = new TGraphAsymmErrors(h1D_RFB_ETHF[inh]);
        gRFB_sys[inh]->SetName(Form("gRFB_sys_%d",inh));
        for (int iet=0; iet<nEt; iet++) {
            gRFB_sys[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            //abs err calcul.
            eysys[inh][iet] = eysysrel[inh][iet]*pytmp[inh][iet];
            //gRFB_sys[inh]->SetPoint(iet, px[iet], pytmp[inh][iet]);
            gRFB_sys[inh]->SetPoint(iet, px[iet]+pxshift*inh, pytmp[inh][iet]);
            gRFB_sys[inh]->SetPointError(iet, exsys[iet], exsys[iet], eysys[inh][iet], eysys[inh][iet]);
            cout << "" << endl;
            cout << "pytmp["<<inh<<"]["<<iet<<"] = " << pytmp[inh][iet]<<endl;
            cout << "eytmp["<<inh<<"]["<<iet<<"] = " << eytmp[inh][iet]<<endl;
            cout << "eysys["<<inh<<"]["<<iet<<"] = " << eysys[inh][iet]<<endl;
        }
    }

    gRFB_sys[0]->GetXaxis()->SetTitle("E_{T}^{HF |#eta|>4} [GeV]");
    gRFB_sys[0]->GetXaxis()->CenterTitle();
    gRFB_sys[0]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[0]->GetXaxis()->SetLimits(0.,50.0);
    gRFB_sys[0]->SetMinimum(0.5);
    gRFB_sys[0]->SetMaximum(1.15);
    gRFB_sys[0]->SetFillColor(kViolet-9);
    gRFB_sys[0]->Draw("A2");
    gRFB_sys[1]->SetFillColor(kTeal-9);
    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->SetFillColor(kRed-9);
//	gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->SetFillColor(kAzure-9);
//	gRFB_sys[3]->Draw("2");

    SetGraphStyle(gRFB[0], 8, 2); //1.5-1.93 low
    SetGraphStyle(gRFB[1], 0, 5); //1.5-1.93
    SetGraphStyle(gRFB[2], 1, 3); //0.9-1.5
    SetGraphStyle(gRFB[3], 2, 0); //0-0.9
    gRFB[0]->SetMarkerSize(1.6);
    gRFB[0]->Draw("P");
    gRFB[1]->SetMarkerSize(2.1);
    gRFB[1]->Draw("P");

    dashedLine(0.,1.,50.,1.,1,1);
    legBL -> SetHeader ("1.5 < |y_{CM}| < 1.93");
    legBL -> AddEntry(gRFB[0],"5 < p_{T} < 6.5 GeV/c","lp");
    legBL -> AddEntry(gRFB[1],"6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[0],"1.5 < |y_{CM}| < 1.93,   5 < p_{T} < 6.5 GeV/c","lp");
//	legBL -> AddEntry(gRFB[1],"1.5 < |y_{CM}| < 1.93,  6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[2],"0.9 < |y_{CM}| < 1.5,   6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[3],"0.0 < |y_{CM}| < 0.9,   6.5 < p_{T} < 30 GeV/c","lp");
    legBL->Draw();
    globtex->SetTextSize(0.045);
    globtex->SetTextFont(62);
    if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
    else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");

    CMS_lumi( c1, iPeriod, iPos );
    c1->Update();
    c1->SaveAs(Form("RFB_%s/RFB_ETHF_samey_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
    c1->SaveAs(Form("RFB_%s/RFB_ETHF_samey_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));
    legBL->Clear();


    //////////////////////////////////////////////////////////////////
    /////////// samept
    //////////////////////////////////////////////////////////////////
    TCanvas* c2 = new TCanvas("c2","c2",600,600);
    c2->cd();

    for (int inh=1; inh< nHist; inh++) {
        for (int iet=0; iet<nEt; iet++) {
            gRFB[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            eytmp[inh][iet] = gRFB[inh] -> GetErrorY(iet);
            gRFB[inh]->SetPoint(iet, px[iet]+pxshift*(nHist-1-inh), pytmp[inh][iet]);
            //sys
            gRFB_sys[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            gRFB_sys[inh]->SetPoint(iet, px[iet]+pxshift*(nHist-1-inh), pytmp[inh][iet]);
        }
    }

    gRFB_sys[0]->GetXaxis()->SetTitle("E_{T}^{HF |#eta|>4} [GeV]");
    gRFB_sys[0]->GetXaxis()->CenterTitle();
    gRFB_sys[0]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[0]->GetXaxis()->SetLimits(0.,50.0);
    gRFB_sys[0]->SetMinimum(0.5);
    gRFB_sys[0]->SetMaximum(1.15);
    gRFB_sys[0]->SetFillColor(kViolet-9);
    gRFB_sys[0]->Draw("A2");
    gRFB_sys[1]->SetFillColor(kTeal-9);
    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->SetFillColor(kRed-9);
//	gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->SetFillColor(kAzure-9);
//	gRFB_sys[3]->Draw("2");

    SetGraphStyle(gRFB[0], 8, 2); //1.5-1.93 low
    SetGraphStyle(gRFB[1], 0, 5); //1.5-1.93
    SetGraphStyle(gRFB[2], 1, 3); //0.9-1.5
    SetGraphStyle(gRFB[3], 2, 0); //0-0.9
    gRFB[0]->SetMarkerSize(1.6);
    gRFB[0]->Draw("P");
    gRFB[1]->SetMarkerSize(2.1);
    gRFB[1]->Draw("P");








    // just for drawing
    gRFB_sys[0]->SetFillColor(kWhite);
    gRFB_sys[0]->Draw("A2");

    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->Draw("2");

    gRFB[1]->Draw("P");
    gRFB[2]->Draw("P");
    gRFB[3]->Draw("P");

    dashedLine(0.,1.,50.,1.,1,1);
    legBL2 -> SetHeader ("6.5 < p_{T} < 30 GeV/c");
    legBL2 -> AddEntry(gRFB[3],"0.0 < |y_{CM}| < 0.9","lp");
    legBL2 -> AddEntry(gRFB[2],"0.9 < |y_{CM}| < 1.5","lp");
    legBL2 -> AddEntry(gRFB[1],"1.5 < |y_{CM}| < 1.93","lp");
    legBL2 ->Draw();
    globtex->SetTextSize(0.045);
    globtex->SetTextFont(62);
    if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
    else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");

    CMS_lumi( c2, iPeriod, iPos );
    c2->Update();
    c2->SaveAs(Form("RFB_%s/RFB_ETHF_samept_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
    c2->SaveAs(Form("RFB_%s/RFB_ETHF_samept_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));

#if 0
    ///////////////////////////////////////////////////////////////////
    // save as a root file
    TFile *outFile = new TFile(Form("RFB_%s/RFB_ETHF_FWonly_isPrompt%d.root",dirName,(int)isPrompt),"RECREATE");
    outFile->cd();
    for (int inh=0; inh< nHist; inh++) {
        gRFB_sys[inh]->Write();
        gRFB[inh]->Write();
    }
    outFile->Close();
#endif

    return;

} // end of main func.
Пример #11
0
//// runCode // 0=merged, 1=1stRun, 2=2ndRun
void draw_1D_bfrac_pt_ETHF(char* dirName = "6rap3pt", int runCode=1, bool isScale = false,bool isLog = false)
{
	gROOT->Macro("./JpsiStyle.C");
	//TCanvas *ctmp0 = new TCanvas("ctmp0","RFB vs ET",900,600);
	//ctmp0->Divide(3,2);	
	
	TCanvas *ctmp0 = new TCanvas("ctmp0","ET 0-20",900,600);
	ctmp0->Divide(3,2);	
	TCanvas *ctmp1 = new TCanvas("ctmp1","ET 20-30",900,600);
	ctmp1->Divide(3,2);	
	TCanvas *ctmp2 = new TCanvas("ctmp2","ET30-120",900,600);
	ctmp2->Divide(3,2);	
	

	// set info.
	const Double_t br = 0.0593 ;
	const Double_t brErr = 0.0006;
	Double_t lumi_nb;
	Double_t lumi_nb_err;
	Double_t lumi_mub;
	Double_t lumi_mub_err;
	string runstring;
	string lumistring;
	string cmsstring = "CMS preliminary";
	string beamstring = "pPb #sqrt{s_{NN}} = 5.02 TeV";
	if (runCode ==0) { runstring = "All"; lumi_nb =34.622; lumi_nb_err=1.2; }
	else if (runCode == 1) { runstring = "Pbp"; lumi_nb =20.7; lumi_nb_err=0.7; }//1stRun
	else if (runCode == 2) { runstring = "pPb"; lumi_nb = 14.0; lumi_nb_err=0.5; }//2ndRun
	else { cout << " *** Error!!! choose runCode 0, 1, or 2 " << endl; return ; }
	lumistring = Form("L_{int} = %.1f nb^{  -1}", lumi_nb);
	lumi_mub = lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1}
	lumi_mub_err = lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1}
	
	//rap array in yCM (from forward to backward)
	//Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
	//Double_t rapArrNumBF[] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
	Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93};// for pt dist.
	//Double_t rapArrNumBF[] = {-1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
	const Int_t nRap = sizeof(rapArrNumFB)/sizeof(Double_t)-1;
	cout << "nRap = " << nRap << endl;
	Double_t rapBinW[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; 
		cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
	}
	//pt array
	//Double_t ptArrNum[] = {0.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.};
	Double_t ptArrNum[] = {5.0, 6.5, 10., 30.}; //6rap3pt
	const Int_t nPt = sizeof(ptArrNum)/sizeof(Double_t)-1;
	cout << "nPt = " << nPt << endl;
	Double_t ptBinW[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; 
		cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
	}
	//ethf array
	Double_t etArrNum[] = {0.0, 20.0, 30.0, 120.0};
	const Int_t nEtBins = sizeof(etArrNum)/sizeof(double)-1;
	cout << "nEtBins=" << nEtBins << endl;

	// array string
	string rapArr[nRap];
	for (Int_t iy=0; iy<nRap; iy++) {
		formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
		cout << iy <<"th rapArr = " << rapArr[iy] << endl;
	}
	string ptArr[nPt];
	for (Int_t ipt=0; ipt<nPt; ipt++) {
		formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
		cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
	}
	string etArr[nEtBins];
	for (Int_t i=0; i<nEtBins; i++){
		formEtArr(etArrNum[i], etArrNum[i+1], &etArr[i]);
		cout << "etArr["<<i<<"] = "<< etArr[i].c_str() << endl;
	}	
	
	// --- read-in file
	TFile * f2D = new TFile(Form("../total2Dhist_%s.root",dirName));
	cout << "dirName = " << dirName << endl;
	cout << "runCode = " << runCode << ", runstring = " << runstring.c_str() << endl;

	// --- read-in 2D hist for corrected yield
	TH2D* h2D_corrY_Pbp[nEtBins];
	TH2D* h2D_corrY_pPb[nEtBins];
	for (int iet=0; iet<nEtBins; iet++){
			h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("otherFitInfo/h2D_fit_pt_y_bFrac_Pbp_%d",iet));
			h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("otherFitInfo/h2D_fit_pt_y_bFrac_pPb_%d",iet));
		cout << iet << "th h2D_corrY_Pbp = " << h2D_corrY_Pbp[iet] << endl;
		cout << iet << "th h2D_corrY_pPb = " << h2D_corrY_pPb[iet] << endl;
	}	

	const int nbinsX = h2D_corrY_Pbp[0]->GetNbinsX();
	const int nbinsY = h2D_corrY_Pbp[0]->GetNbinsY();
	cout << "nbinsX = " << nbinsX << endl;
	cout << "nbinsY = " << nbinsY << endl;
	if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; };
	if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; };

	// ---  projection to 1D hist
	TH1D* h1D_corrY_Pbp[nEtBins][nbinsX]; 
	TH1D* h1D_corrY_pPb[nEtBins][nbinsX]; 
	// iy=0 refers to forwards !!! (ordering here)
	for (Int_t iet=0; iet<nEtBins; iet++){
		for (Int_t iy = 0; iy < nbinsX; iy++) {
			h1D_corrY_Pbp[iet][iy] = h2D_corrY_Pbp[iet]->ProjectionY(Form("h1D_corrY_Pbp_%d_%d",iet,iy),iy+1,iy+1);
			h1D_corrY_Pbp[iet][iy]->SetName(Form("h1D_corrY_Pbp_%d_%d",iet,iy));
			//for 2nd run
			h1D_corrY_pPb[iet][iy] = h2D_corrY_pPb[iet]->ProjectionY(Form("h1D_corrY_pPb_%d_%d",iet,iy),nbinsX-iy,nbinsX-iy);
			h1D_corrY_pPb[iet][iy]->SetName(Form("h1D_corrY_pPb_%d_%d",iet,iy));
			
		}
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// set values as zero for unused bins
	for (Int_t iet=0; iet<nEtBins; iet++){
		for (Int_t iy = 0; iy < nbinsX; iy++) {
			if (iy>=1 && iy<=4) {
				h1D_corrY_Pbp[iet][iy]->SetBinContent(1,0);
				h1D_corrY_Pbp[iet][iy]->SetBinError(1,0);
				h1D_corrY_pPb[iet][iy]->SetBinContent(1,0);
				h1D_corrY_pPb[iet][iy]->SetBinError(1,0);
			}
		}
	}
/*
	 ////// after zero-bin setting, normalize!
	for (Int_t iet=0; iet<nEtBins; iet++){
		for (Int_t iy = 0; iy < nbinsX; iy++) {
			h1D_corrY_Pbp[iet][iy]->Scale(1./h1D_corrY_Pbp[iet][iy]->Integral());	
			h1D_corrY_pPb[iet][iy]->Scale(1./h1D_corrY_pPb[iet][iy]->Integral());	
			h1D_corrY_Pbp[iet][iy]->Scale(1,"width");
			h1D_corrY_pPb[iet][iy]->Scale(1,"width");
		}
	}
*/
	//////////////////////////////////////////////////////////////////
	//// --- Draw histograms
	TLegend *legUR = new TLegend(0.45, 0.75, 0.86, 0.92); //upper left	
	TLegend *legBL = new TLegend(0.18, 0.18, 0.59, 0.35); //upper left
	SetLegendStyle(legUR);
	SetLegendStyle(legBL);

	//latex box for beam, rapidity, pT info
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);	

	for (Int_t iet=0; iet<nEtBins; iet++){
		for (Int_t iy = 0; iy < nbinsX; iy++) {
			if (iet==0) { ctmp0->cd(iy+1);}
			else if (iet==1) { ctmp1->cd(iy+1); }
			else if (iet==2) { ctmp2->cd(iy+1); }
			 
			SetHistStyle(h1D_corrY_Pbp[iet][iy],1,0);
			SetHistStyle(h1D_corrY_pPb[iet][iy],2,0);
			h1D_corrY_Pbp[iet][iy]->GetYaxis()->SetRangeUser(0,0.6);
			h1D_corrY_Pbp[iet][iy]->Draw("pe"); 
			h1D_corrY_pPb[iet][iy]->Draw("pe same"); 
			//h1D_corrY_pPb[iet][iy]->Draw("pe"); 
		}
	}



/*	
	//////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	// 1) merge Pbp+pPb corrected yield
	TH1D* h1D_corrY_tot[nEtBins][nbinsX]; 
	for (Int_t iet=0; iet<nEtBins; iet++){
		for (Int_t iy = 0; iy < nbinsX; iy++) {
			if (runCode ==0) {	
				h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
				h1D_corrY_tot[iet][iy]->Add(h1D_corrY_pPb[iet][iy]);	
			}
			else if (runCode ==1) {
				h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
			}
			else if (runCode ==2) {
				h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_pPb[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
			}
//			if (iet==0) { ctmp0->cd(iy+1); h1D_corrY_tot[iet][iy]->Draw("pe"); }
//			if (iet==1) { ctmp1->cd(iy+1); h1D_corrY_tot[iet][iy]->Draw("pe"); }
//			if (iet==2) { ctmp2->cd(iy+1); h1D_corrY_tot[iet][iy]->Draw("pe"); }
		}
	}
	
	//////////////////////////////////////////////////////////////////
	/////////// calculate RFB
	
	const int nRapRFB = 3;	
	TH1D* h1D_RFB_tot_tmp[nEtBins][nbinsX]; // corrYield with merged pT		
	TH1D* h1D_RFB_tot[nEtBins][nRapRFB]; // actual RFB vs pt	
	
	// bin settingg
	string rapAbsArr[nRap];
	for (Int_t iy=0; iy<nRapRFB; iy++) {
		formAbsRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapAbsArr[iy]);
		cout << iy <<"th rapAbsArr = " << rapAbsArr[iy] << endl;
	}
	Double_t ptArrRFBNum[] = {5.0, 6.5, 30.};
	const Int_t nPtRFB = sizeof(ptArrRFBNum)/sizeof(Double_t)-1;
	cout << "nPtRFB = " << nPtRFB << endl;

	// merging pT bins (KYO - byHand)
	double tmpPRval01, tmpPRerr01, tmpPRval02, tmpPRerr02;
	double actPRval01, actPRerr01, actPRval02, actPRerr02;
	for (int iet=0; iet<nEtBins; iet++){
		for (int iy=0; iy<nRapRFB*2; iy++){
			h1D_RFB_tot_tmp[iet][iy]= new TH1D(Form("h1D_RFB_tot_tmp_%d_%d",iet,iy),Form("h1D_RFB_tot_tmp_%d_%d",iet,iy),nPtRFB,ptArrRFBNum);
			h1D_RFB_tot_tmp[iet][iy]->Sumw2();
			actPRval01=0; actPRval02=0; actPRerr01=0; actPRerr02=0;
			// 1) pT 5-6.5 GeV
			tmpPRval01=0; tmpPRval02=0; tmpPRerr01=0; tmpPRerr02=0;
			if (iy==0 || iy==nRapRFB*2-1){
				actPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(1);	
				actPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(1);	
				h1D_RFB_tot_tmp[iet][iy]->SetBinContent(1,actPRval01);
				h1D_RFB_tot_tmp[iet][iy]->SetBinError(1,actPRerr01);
			} else {
				h1D_RFB_tot_tmp[iet][iy]->SetBinContent(1,0.);
				h1D_RFB_tot_tmp[iet][iy]->SetBinError(1,0.);
			}
			// 2) pT 6.5-30. GeV
			tmpPRval01=0; tmpPRval02=0; tmpPRerr01=0; tmpPRerr02=0;
			tmpPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(2);	
			tmpPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(2);	
			tmpPRval02=h1D_corrY_tot[iet][iy]->GetBinContent(3);	
			tmpPRerr02=h1D_corrY_tot[iet][iy]->GetBinError(3);	
			actPRval02=tmpPRval01+tmpPRval02;
			actPRerr02=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) );
			h1D_RFB_tot_tmp[iet][iy]->SetBinContent(2,actPRval02);
			h1D_RFB_tot_tmp[iet][iy]->SetBinError(2,actPRerr02);
			//cout << iet<<"th,"<<iy<<"th h1D_RFB_tot_tmp = "<<h1D_RFB_tot_tmp[iet][iy]<<endl;
//			if (iet==0) { ctmp0->cd(iy+1); h1D_RFB_tot_tmp[iet][iy]->Draw("pe"); }
//			if (iet==1) { ctmp1->cd(iy+1); h1D_RFB_tot_tmp[iet][iy]->Draw("pe"); }
//			if (iet==2) { ctmp2->cd(iy+1); h1D_RFB_tot_tmp[iet][iy]->Draw("pe"); }
		}
	}

	// actual RFB calculation	vs pT!!
	for (int iet=0; iet<nEtBins; iet++){
		for (int iy=0; iy<nRapRFB; iy++){
			h1D_RFB_tot[iet][iy] = (TH1D*)h1D_RFB_tot_tmp[iet][iy]->Clone(Form("h1D_RFB_tot_%d_%d",iet,iy));
			h1D_RFB_tot[iet][iy]->Divide(h1D_RFB_tot_tmp[iet][2*nRapRFB-iy-1]); 
			cout << iet<<"th, "<<iy<<"th h1D_RFB_tot = "<<h1D_RFB_tot[iet][iy]<<endl;
			//if (iet==0) { ctmp0->cd(iy+1); h1D_RFB_tot[iet][iy]->Draw("pe"); }
			//if (iet==1) { ctmp1->cd(iy+1); h1D_RFB_tot[iet][iy]->Draw("pe"); }
			//if (iet==2) { ctmp2->cd(iy+1); h1D_RFB_tot[iet][iy]->Draw("pe"); }
		}
	}	

	///////////////////////////////////////////////
	//////// --- RFB vs ETHF : 4 histograms
	//in=0 : pT 5-6.5, rap 1.5-1.93 
	//in=1 : pT 6.5-30, rap 1.5-1.93 
	//in=2 : pT 6.5-30, rap 0.9-1.5 
	//in=3 : pT 6.5-30, rap 0.0-0.9 
	const int nHist=4; 
	double tmpRFBval01, tmpRFBerr01, tmpRFBval02, tmpRFBerr02, tmpRFBval03, tmpRFBerr03;
	TH1D* h1D_RFB_ETHF_tot[nHist];
	
	for (int in=0; in< nHist; in++){
		h1D_RFB_ETHF_tot[in]= new TH1D(Form("h1D_RFB_ETHF_tot_%d",in),Form("h1D_RFB_ETHF_tot_%d",in),nEtBins,etArrNum);
		h1D_RFB_ETHF_tot[in]->Sumw2();
		tmpRFBval01=0;tmpRFBerr01=0;tmpRFBval02=0;tmpRFBerr02=0;tmpRFBval03=0;tmpRFBerr03=0;
		for (int iet=0; iet<nEtBins;iet++){
			if (in==0) {
				tmpRFBval01=h1D_RFB_tot[iet][0]->GetBinContent(1);	
				tmpRFBerr01=h1D_RFB_tot[iet][0]->GetBinError(1);	
				h1D_RFB_ETHF_tot[in]->SetBinContent(iet+1,tmpRFBval01);
				h1D_RFB_ETHF_tot[in]->SetBinError(iet+1,tmpRFBerr01);
			}			
			else {
				tmpRFBval01=h1D_RFB_tot[iet][in-1]->GetBinContent(2);	
				tmpRFBerr01=h1D_RFB_tot[iet][in-1]->GetBinError(2);	
				h1D_RFB_ETHF_tot[in]->SetBinContent(iet+1,tmpRFBval01);
				h1D_RFB_ETHF_tot[in]->SetBinError(iet+1,tmpRFBerr01);
			}
		}
		 h1D_RFB_ETHF_tot[in]->SetMinimum(0.0);
		 h1D_RFB_ETHF_tot[in]->SetMaximum(1.4);
		ctmp0->cd(in+1); h1D_RFB_ETHF_tot[in]->Draw("pe");
	dashedLine(0.,1.,120.,1.,1,1);
	}		
*/













	// convert to TGraphAsymErrors




/*
	// root file
	//TFile *fOut = new TFile(Form("1Dhist_%s/tmp_crossSection_pt.root",dirName),"RECREATE");
	TFile *fOut = new TFile(Form("1Dhist_%s/crossSection_pt_%s.root",dirName,runstring.c_str()),"RECREATE");
	fOut->cd();
	for (Int_t iy = 0; iy < nbinsX; iy++) {
		h1D_corrY_NP_Pbp[iy]->Write();
		h1D_corrY_NP_pPb[iy]->Write();
		h1D_corrY_NP_tot[iy]->Write();
	}
	//tRap->Write();
	fOut->Close();
*/
	return;

} // end of main func.