Example #1
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.
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.
Example #3
0
// no ordering in rap (just y_lab)
void draw_compRatio(bool isPrompt = true, bool is1st = true, char* dirName02 = "draw_compRatio_newcut", bool isNoError=true)
{
	gROOT->Macro("./JpsiStyle.C");

	// --- read-in file
	// hRatio = f01 / f02
	TFile * f01;
	TFile * f02;
	char* f01name="old cut";
	char* f02name="new cut";
	
	double ratiomin=0.85; 
	double ratiomax=1.45; 

	char* strPrompt;
	char* str1st;
	if (isPrompt) strPrompt = "PRMC";
	else strPrompt = "NPMC";
	if (is1st) str1st = "Pbp";
	else str1st = "pPb";

	const char* sampleName = Form("%spythia_%s",strPrompt,str1st);
	cout << "sampleName = " << sampleName << endl;

	f01 = new TFile(Form("./draw_1D_acc/8rap9pt2gev_%s_AccPt.root",strPrompt));
	f02 = new TFile(Form("./draw_1D_acc_newcut/8rap9pt2gev_newcut_%s_AccPt.root",strPrompt));

	cout << "sampleName = " << sampleName << endl;

	// --- read-in tree
	TTree *tr = (TTree*)f01->Get("tRap");
	int nEdge;
	double rapEdge[531];
	TBranch *b_nEdge;
	TBranch *b_rapEdge;
	tr->SetBranchAddress("nEdge",&nEdge,&b_nEdge);
	tr->SetBranchAddress("rapEdge",&rapEdge,&b_rapEdge);
	cout << "tr entries = " << tr->GetEntries() << endl;
	for (int ev=0; ev <tr->GetEntries(); ev++){
		tr->GetEntry(ev);
	}
	cout << "nEdge = " << nEdge << endl;
	for (Int_t i=0; i< nEdge; i++) {
		cout << "rapEdge["<<i<<"] = " << rapEdge[i] << endl;
	}

	// --- read-in eff hist
	const int nRap = nEdge -1 ; 
	cout << "nRap = " << nRap << endl;
	TH1D* h1D_AccPt01[nRap]; 
	TH1D* h1D_AccPt02[nRap]; 
	TH1D *hRatio[nRap]; //f01/f02
	TH1D *hRel[nRap]; // (f01-f02)/f02
	for (int iy=0; iy < nRap; iy ++){
		h1D_AccPt01[iy] = (TH1D*)f01->Get(Form("h1D_AccPt_%d",iy));
		h1D_AccPt02[iy] = (TH1D*)f02->Get(Form("h1D_AccPt_%d",iy));
	cout << "h1D_AccPt01["<<iy<<"] = " << h1D_AccPt01[iy] << endl;
	cout << "h1D_AccPt02["<<iy<<"] = " << h1D_AccPt02[iy] << endl;
		hRatio[iy]=(TH1D*)h1D_AccPt01[iy]->Clone(Form("hRatio_%d",iy));
		hRatio[iy]->Divide(h1D_AccPt02[iy]);
		hRel[iy]=(TH1D*)h1D_AccPt01[iy]->Clone(Form("hRel_%d",iy));
		hRel[iy]->Add(h1D_AccPt02[iy],-1);
		hRel[iy]->Divide(h1D_AccPt02[iy]);
	}
	
	//latex box for beam, rapidity, pT info
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);

	//////////////////////////////////////////////////////////////////
	// --- Draw histograms

	TCanvas* c1 = new TCanvas("c1","c1",1600,800);
	c1->Divide(4,2);
//	TCanvas* c2 = new TCanvas("c2","c2",1600,800);
//	c2->Divide(4,2);
//	TCanvas* c3 = new TCanvas("c3","c3",1600,800);
//	c3->Divide(4,2);
	//TLegend *legBR = new TLegend(0.58,0.30,0.85,0.40,NULL,"brNDC");
	TLegend *legBR = new TLegend(0.50,0.30,0.80,0.41,NULL,"brNDC");
	SetLegendStyle(legBR);

	for (Int_t iy = 0; iy < nRap; iy++) {
		//// 1)  distributions
		//c1->cd();
		c1->cd(iy+1);
		SetHistStyle(h1D_AccPt01[iy],3,0);
		//SetHistStyle(h1D_AccPt02[iy],4,0);
		SetHistStyle(h1D_AccPt02[iy],4,10);
		h1D_AccPt01[iy]->GetXaxis()->SetTitle("p_{T} (GeV)");
		h1D_AccPt01[iy]->GetYaxis()->SetTitle("Acceptance");
		h1D_AccPt01[iy]->SetMinimum(0.);
		h1D_AccPt01[iy]->SetMaximum(1.);
		h1D_AccPt01[iy]->GetXaxis()->SetRangeUser(0., 30.);
		h1D_AccPt01[iy]->Draw("pe");
		h1D_AccPt02[iy]->Draw("pe same");
		if (is1st) {
			if (iy==0 || iy==7) dashedLine (2.,0.,2.,1.,2,.8);
			else if (iy==1 || iy==6) dashedLine (3.,0.,3.,1.,2,.8);
			else if (iy==5)  dashedLine (5.,0.,5.,1.,2,.8);
			else if (iy==2 || iy==3 || iy==4)  dashedLine (6.5,0.,6.5,1.,2,.8);
		}
		else {
			if (iy==0 || iy==7) dashedLine (2.,0.,2.,1.,2,.8);
			else if (iy==1 || iy==6) dashedLine (3.,0.,3.,1.,2,.8);
			else if (iy==2)  dashedLine (5.,0.,5.,1.,2,.8);
			else if (iy==3 || iy==4 || iy==5)  dashedLine (6.5,0.,6.5,1.,2,.8);
		}
		latex->DrawLatex(0.53,0.25,sampleName);
		latex->DrawLatex(0.53,0.19,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1]));
		if (iy==0) {
//			legBR->AddEntry(h1D_AccPt01[iy],f01name,"lp");
//			legBR->AddEntry(h1D_AccPt02[iy],f02name,"lp");
//			legBR->Draw();
		}
		//c1->SaveAs(Form("%s/%s_compEff_%d.pdf",dirName02,sampleName,iy));
		//legBR->Clear();
		//c1->Clear();
/*
		//// 2) ratio f01/f02
		//c2->cd();
		c2->cd(iy+1);
		SetHistStyle(hRatio[iy],5,0);
		hRatio[iy]->GetXaxis()->SetTitle("p_{T} (GeV)");
		hRatio[iy]->GetYaxis()->SetTitle(Form("[ %s ]/[ %s ]",f01name,f02name));
		hRatio[iy]->SetMinimum(ratiomin);
		hRatio[iy]->SetMaximum(ratiomax);
		hRatio[iy]->GetXaxis()->SetRangeUser(0.,30.);
		if (isNoError) {
			for (int ipt=0; ipt<9; ipt++) {
				hRatio[iy]->SetBinError(ipt+1,0.);
			}
		}
		hRatio[iy]->Draw("pe");
		dashedLine(0.,1.,30.,1.,1,.8);
		if (is1st) {
			if (iy==0 || iy==7) dashedLine (2.,ratiomin,2.,ratiomax,2,.8);
			else if (iy==1 || iy==6) dashedLine (3.,ratiomin,3.,ratiomax,2,.8);
			else if (iy==5)  dashedLine (5.,ratiomin,5.,ratiomax,2,.8);
			else if (iy==2 || iy==3 || iy==4)  dashedLine (6.5,ratiomin,6.5,ratiomax,2,.8);
		}
		else {
			if (iy==0 || iy==7) dashedLine (2.,ratiomin,2.,ratiomax,2,.8);
			else if (iy==1 || iy==6) dashedLine (3.,ratiomin,3.,ratiomax,2,.8);
			else if (iy==2)  dashedLine (5.,ratiomin,5.,ratiomax,2,.8);
			else if (iy==3 || iy==4 || iy==5)  dashedLine (6.5,ratiomin,6.5,ratiomax,2,.8);
		}
		latex->DrawLatex(0.53,0.25,sampleName);
		latex->DrawLatex(0.53,0.19,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1]));
		//c2->SaveAs(Form("%s/%s_compRatio_%d.pdf",dirName02,sampleName,iy));
		//c2->Clear();

		//// 3) relative (f01-f02)/f02
		//c3->cd();
		c3->cd(iy+1);
		SetHistStyle(hRel[iy],5,0);
		hRel[iy]->GetXaxis()->SetTitle("p_{T} (GeV)");
		hRel[iy]->GetYaxis()->SetTitle(Form("(%s-%s) / %s",f01name,f02name,f02name));
		hRel[iy]->SetMinimum(relmin);
		hRel[iy]->SetMaximum(relmax);
		hRel[iy]->Draw("pe");
		dashedLine(0.,0.,30.,0.,1,.8);
		if (iy==1 || iy==6) dashedLine (3.,relmin,3.,relmax,2,.8);
		else if (iy==2)  dashedLine (5.,relmin,5.,relmax,2,.8);
		else if (iy==3 || iy==4 || iy==5)  dashedLine (6.5,relmin,6.5,relmax,2,.8);
		latex->DrawLatex(0.53,0.25,sampleName);
		latex->DrawLatex(0.53,0.19,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1]));
		//c3->SaveAs(Form("%s/%s_compRel_%d.pdf",dirName02,sampleName,iy));
		//c3->Clear();
*/
	}

	c1->SaveAs(Form("%s/%s_compAcc.pdf",dirName02,strPrompt));
//	c2->SaveAs(Form("%s/%s_compRatio.pdf",dirName02,strPrompt));
//	c3->SaveAs(Form("%s/%s_compRel.pdf",dirName02,sampleName));

	return;

}
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.
//szPA = "pp" or "pa"
int draw_bkgSubtracted(TString szPA = "pp")
{
	gROOT->Macro("../Style.C");
	
	// read-in root file
	TFile *fIn = new TFile(Form("dir_muID/%s_muIDvariables_isScaled0.root",szPA.Data()));

  //// define 1D hist
  const int nbin[] = {2, 2, 2, 20, 6, 90, 88};
  const double minbin[] = {0, 0., 0., 0, 0, -4.5, -22.};
  const double maxbin[] = {2, 2., 2., 20, 6, 4.5, 22.};
  //// for dashedLine (valid for isScaled)
  double xmin[] = {1., 1., 1., 6., 1., -0.3, -20.};
  double xmax[] = {531., 531., 531., 531., 531., 0.3, 20.};
  double ymin[] = {0., 0., 0., 0., 0., 0.00001, 0.00001};
  double ymax[] = {1.1, 1.1, 1.1, 0.25, 0.8, 1, 1};
  TString histName[] = {"highPurity", "TrkMuArb", "TMOneStaTight", "nTrkWMea", "nPixWMea", "dxy", "dz"};
  if (strcmp(szPA,"pa")==0) {histName[0]="isHighPurity";}
  TString histTitle[] = {"high purity flag", "tracker muon arbitrated flag", "TMOneStationTight flag", "# of trk layers w/ measurement", "# of pixel layers w/ measurement", "dxy (cm)", "dz (cm)"};
  const int nHist = sizeof(nbin)/sizeof(int);
  cout << "nHist = "<<nHist<<endl;

  
  TH1D *hMass[nHist]; //mass distibution for yield checks
  TH1D *hSig[nHist]; // in 2.9 - 3.3 GeV
	TH1D *hSigSub[nHist]; // Sig - scaledBkg
  TH1D *hBkg[nHist]; // out of 2.9 - 3.3 GeV
  TH1D *hPRMC[nHist]; // in 2.9 - 3.3 GeV

	TCanvas* c1[nHist];
	//TLegend *legUR = new TLegend(0.58,0.75,0.88,0.90,NULL,"brNDC");
	TLegend *legUR = new TLegend(0.58,0.70,0.88,0.90,NULL,"brNDC");
	SetLegendStyle(legUR);
	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextFont(42);
	latex->SetTextSize(0.04);

	for (int ih=0; ih<nHist; ih++) {
		hMass[ih] = (TH1D*)fIn->Get(Form("hMass_%s",histName[ih].Data()));
		hSig[ih] = (TH1D*)fIn->Get(Form("hSig_%s",histName[ih].Data()));
		hBkg[ih] = (TH1D*)fIn->Get(Form("hBkg_%s",histName[ih].Data()));
		hPRMC[ih] = (TH1D*)fIn->Get(Form("hPRMC_%s",histName[ih].Data()));
    //// get yields from mass distributions  for scaling
    double nSig = calculInteg(hMass[ih],2.9,3.3);
    double nBkg = calculInteg(hMass[ih],2.6,2.9);
	  cout << "1) nBkg = " << nBkg << endl;
    nBkg += calculInteg(hMass[ih],3.3,3.5);
	  cout << "2 nBkg = " << nBkg << endl;
    nBkg *= (0.4/0.5); // in 2.9-3.3
	  double nBkgToSig = nBkg/nSig;
		cout << ih <<"th hist name = " << histName[ih].Data() << endl;
	  cout << "nSig = " << nSig << endl;
	  cout << "nBkg = " << nBkg << endl;
	  cout << "nBkgToSig = " << nBkgToSig << endl;
		
		////// background subtraction
		/// 1) subtracted signal hist.	
		hSigSub[ih] = (TH1D*)hSig[ih]->Clone(Form("hSigSub_%s",histName[ih].Data()));
		/// 2) First, normalized by their integral
		hSig[ih]->Scale(1/hSig[ih]->Integral());
		hSigSub[ih]->Scale(1/hSigSub[ih]->Integral());
		hBkg[ih]->Scale(1/hBkg[ih]->Integral());
		/// 3) Bkg normalized to nBkgToSig and subtract from the signal
		hBkg[ih] ->Scale(nBkgToSig);
		//hBkg[ih] ->Scale(0.4/0.5);
		hSigSub[ih]->Add(hBkg[ih],-1);
		/// 4) set zero if BinContent is negative 
    double tmpbin;
    for (int ibin=0; ibin < hSigSub[ih]->GetNbinsX(); ibin++) {
      tmpbin = hSigSub[ih]->GetBinContent(ibin+1);
      if (tmpbin < 0.) {cout << " **** "<<ibin<<"th tmpbin = " << tmpbin<< endl; hSigSub[ih]->SetBinContent(ibin+1,0.);}
    } 
    /// 5) normalize again by integral
		hSig[ih]->Scale(1/hSig[ih]->Integral());
		hSigSub[ih]->Scale(1/hSigSub[ih]->Integral());
		hBkg[ih]->Scale(1/hBkg[ih]->Integral());
		hPRMC[ih]->Scale(1/hPRMC[ih]->Integral());
		
		c1[ih] = new TCanvas(Form("c1_%s",histName[ih].Data()),"",600,600);
		c1[ih]->cd();
    if (strcmp(histName[ih],"dxy")==0 || strcmp(histName[ih],"dz")==0) {gPad->SetLogy(1);}
    else { gPad->SetLogy(0);}
    SetHistStyle(hSigSub[ih],1,0);
    SetHistStyle(hBkg[ih],2,10);
    SetHistStyle(hPRMC[ih],4,0);
		hPRMC[ih]->SetFillColor(kGreen+9);
		hPRMC[ih]->SetFillStyle(3003);
		hPRMC[ih]->SetAxisRange(ymin[ih],ymax[ih],"Y");
		hPRMC[ih]->Draw("hist");
		hSigSub[ih]->Draw("pe same");
		hBkg[ih]->Draw("pe same");
    if (ih==nHist-1){
      legUR->AddEntry(hSigSub[ih],"RD: Signal","lp");
      legUR->AddEntry(hSigSub[ih],"(Bkg subtracted)","");
      legUR->AddEntry(hBkg[ih],"RD: Background","lp");
      legUR->AddEntry(hPRMC[ih],"MC","f");
			legUR->Draw();
		}
		//// line for actual cut regions
		dashedLine(xmin[ih],ymin[ih],xmin[ih],ymax[ih]);
		dashedLine(xmax[ih],ymin[ih],xmax[ih],ymax[ih]);
		//// check integral over cut regions
		double nsig=-999, nmc=-999, nratio=-999;
		nsig = calculInteg(hSigSub[ih],xmin[ih],xmax[ih]);
		nmc = calculInteg(hPRMC[ih],xmin[ih],xmax[ih]);
		//nratio = nsig/nmc;
    //nratio = (1.-nsig)/(1.-nmc);
    nratio = (1.-nmc)/(1.-nsig);
    cout << "nsig = " << nsig << ", nmc = " << nmc << ", nratio = " << nratio << endl;
    //latex->DrawLatex(0.16,0.80,"#int_{out}Data/#int_{out}MC");    
    //latex->DrawLatex(0.16,0.70,Form("= %.3f / %.3f = %.2f",1.-nsig,1.-nmc,nratio));    
    latex->DrawLatex(0.16,0.80,"#int_{out}MC/#int_{out}Data");    
    latex->DrawLatex(0.16,0.70,Form("= %.3f / %.3f = %.2f",1.-nmc,1.-nsig,nratio));    
		c1[ih]->SaveAs(Form("dir_muID/%s_muIDvariables_%s_bkgSubtracted.pdf",szPA.Data(),histName[ih].Data()));
	}
	
	return 0;	

}
Example #6
0
void draw_2D(bool isPrompt = true, bool is8rap9pt2gev = true)
{
	gROOT->Macro("./JpsiStyle2D.C");
	gStyle->SetPaintTextFormat(".3f");

	// --- read-in file
	TFile * f2D;
	char* sampleName;
	char* strPrompt;
	char* strBin;

	if (isPrompt) { strPrompt = "PRMC";}
	else { strPrompt = "NPMC";}
	if (is8rap9pt2gev) { strBin = "8rap9pt2gev";}
	else { strBin = "6rap3pt";}

//	f2D = new TFile(Form("./EffCounting_%s_%spythia_Pbp_useCtErr_1_useDataDriven_1_useZvtxStep1_0_Step2_1.root",strBin,strPrompt));
	f2D = new TFile(Form("./EffCounting_%s_%spythia_Pbp_useCtErr_1_useDataDriven_0_useZvtxStep1_0_Step2_1.root",strBin,strPrompt));
	
	sampleName = Form("%s_%s",strBin,strPrompt);
	cout << "sampleName = " << sampleName << endl;

	// --- read-in 2D hist
	TH2D* h2D_Den = (TH2D*)f2D->Get("h2D_Den_pt_y");
	TH2D* h2D_Num = (TH2D*)f2D->Get("h2D_Num_pt_y");
	TH2D* h2D_Eff = (TH2D*)f2D->Get("h2D_Eff_pt_y");

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

	//////////////////////////////////////////////////////////////////
	// --- Draw histograms
	TCanvas* c1 = new TCanvas("c1","c1",700,600);
	TPaletteAxis* pal; 
	c1->cd();
/*
	h2D_Den->GetXaxis()->SetTitle("y_{lab}");
	h2D_Den->GetXaxis()->CenterTitle();
	h2D_Den->GetYaxis()->SetTitle("p_{T} (GeV/c)");
	h2D_Den->Draw("colz");
	c1->Update();
	pal = (TPaletteAxis*)h2D_Den->GetListOfFunctions()->FindObject("palette"); 
	pal->SetX2NDC(0.92);
	c1->Modified();
	c1->Update();
	c1->SaveAs(Form("acc2Dplots/h2D_Den_isPrompt%d.pdf",(int)isPrompt));

	h2D_Num->GetXaxis()->SetTitle("y_{lab}");
	h2D_Num->GetXaxis()->CenterTitle();
	h2D_Num->GetYaxis()->SetTitle("p_{T} (GeV/c)");
	h2D_Num->Draw("colz");
	c1->Update();
	pal = (TPaletteAxis*)h2D_Num->GetListOfFunctions()->FindObject("palette"); 
	pal->SetX2NDC(0.92);
	c1->Modified();
	c1->Update();
	c1->SaveAs(Form("acc2Dplots/h2D_Num_isPrompt%d.pdf",(int)isPrompt));
*/
	h2D_Eff->GetXaxis()->SetTitle("y_{lab}");
	h2D_Eff->GetXaxis()->CenterTitle();
	h2D_Eff->GetYaxis()->SetTitle("p_{T} (GeV/c)");
	h2D_Eff->SetMaximum(1.);
	h2D_Eff->Draw("colz");
	//h2D_Eff->SetMarkerSize(0.8);
	//h2D_Eff->Draw("text e colz");
	c1->Update();
	pal = (TPaletteAxis*)h2D_Eff->GetListOfFunctions()->FindObject("palette"); 
	pal->SetX2NDC(0.92);
	c1->Modified();
	c1->Update();
	if (is8rap9pt2gev) {
		dashedLine(-2.4,2.0,-1.97,2.0,1,4);
		dashedLine(-1.97,2.0,-1.97,3.0,1,4);
		dashedLine(-1.97,3.0,-1.37,3.0,1,4);
		dashedLine(-1.37,3.0,-1.37,6.5,1,4);
		dashedLine(-1.37,6.5,1.03,6.5,1,4);
		dashedLine(1.03,5.0,1.03,6.5,1,4);
		dashedLine(1.03,5.0,1.46,5.0,1,4);
		dashedLine(1.46,3.0,1.46,5.0,1,4);
		dashedLine(1.46,3.0,1.93,3.0,1,4);
		dashedLine(1.93,2.0,1.93,3.0,1,4);
		dashedLine(1.93,2.0,2.4,2.0,1,4);
		dashedLine(2.4,2.0,2.4,30.0,1,4);
		dashedLine(-2.4,30.0,2.4,30.0,1,4);
		dashedLine(-2.4,2.0,-2.4,30.0,1,4);
	}
	else {
		dashedLine(-2.4,5.0,-1.97,5.0,1,4);
		dashedLine(-1.97,5.0,-1.97,6.5,1,4);
		dashedLine(-1.97,6.5,1.03,6.5,1,4);
		dashedLine(1.03,5.0,1.03,6.5,1,4);
		dashedLine(1.03,5.0,1.46,5.0,1,4);
		dashedLine(1.46,5.0,1.46,30.0,1,4);
		dashedLine(-2.4,30.0,1.46,30.0,1,4);
		dashedLine(-2.4,5.0,-2.4,30.0,1,4);
	}
	c1->SaveAs(Form("eff2Dplots/h2D_Eff_%s.pdf",sampleName));

	return;

}
//// EPS09LO, EPS09NLO, nCTEQ15
void comp_RpPb_pt_Lansberg(double ptmax=32, bool isLine=true, bool isSmoothened=false, TString szPDF= "nCTEQ15")
{
	gROOT->Macro("./tdrstyle_kyo.C");
	int isPA = 10;  // 0:pp, 1:pPb, 10 : pp & pPb together for RpPb plot
	int iPos=0;

  bool isPrompt=true;
	
  ///////////////////////////////////////////////////
	///////// from Ramona
	const int nRapRpPb = 7;
	//const int nPtRpPb = 49;
	const int nPtRpPb = 7; // 4, 5, 6.5, 7.5, 8.5, 10, 14,  30 GeV
  Double_t theory_px[nRapRpPb][nPtRpPb]; 
	Double_t theory_py[nRapRpPb][nPtRpPb];
	Double_t theory_exlow_tmp[nRapRpPb][nPtRpPb];
	Double_t theory_exhigh_tmp[nRapRpPb][nPtRpPb];
  Double_t theory_exlow[nRapRpPb][nPtRpPb];
  Double_t theory_exhigh[nRapRpPb][nPtRpPb];
	Double_t theory_eylow_tmp[nRapRpPb][nPtRpPb];
	Double_t theory_eyhigh_tmp[nRapRpPb][nPtRpPb];
  Double_t theory_eylow[nRapRpPb][nPtRpPb];
	Double_t theory_eyhigh[nRapRpPb][nPtRpPb];
  Double_t ptlimit[nRapRpPb] = {4.0, 6.5, 6.5, 6.5, 6.5, 5.0, 4.0};
  int ipt_init[nRapRpPb] = {0, 2, 2, 2, 2, 1, 0}; // take into acount different pT limit for each rapidity bin (0=4.0, 1=5.0, 2=6.5 GeV)
  
  ///////////////////////////////////////////////////////////////////
  //// read-in txt
  ///////////////////////////////////////////////////////////////////
  
  /// iy=0 (1.5 < y < 1.93) 
  TString inText[nRapRpPb];
  for (int iy=0; iy<nRapRpPb; iy++) {
    inText[iy] = Form("./fromLansberg/pt_%1d_%s.dat",iy+1,szPDF.Data());
    cout << "inText["<<iy<<"] = " << inText[iy] << endl;
  }
  
  string headers;
  TString pxmindum, pxmaxdum, ppbdum, eylow_tmpdum, eyhigh_tmpdum, ppdum;
  int counts=0;
  
  for (int iy=0; iy<nRapRpPb; iy++) {
    cout << endl << " ************* iy = " << iy << endl;
    std::ifstream f0(inText[iy].Data(),std::ios::in);
    getline(f0, headers); // remove prefix
    getline(f0, headers); // remove prefix
    counts=0;
    while(!f0.eof()) {
      f0 >> pxmindum >> pxmaxdum >> ppbdum >> eylow_tmpdum >> eyhigh_tmpdum >> ppdum;
      //cout << pxmindum <<"\t"<< pxmaxdum <<"\t"<< ppbdum <<"\t"<< eylow_tmpdum <<"\t"<< eyhigh_tmpdum<<"\t"<< ppdum << endl;
      theory_px[iy][counts+ipt_init[iy]] =(atof(pxmindum) + atof(pxmaxdum))/2.;
      theory_py[iy][counts+ipt_init[iy]] = (atof(ppbdum) / atof(ppdum) );
      theory_exlow_tmp[iy][counts+ipt_init[iy]] = atof(pxmindum);
      theory_exhigh_tmp[iy][counts+ipt_init[iy]] = atof(pxmaxdum);
      theory_eylow_tmp[iy][counts+ipt_init[iy]] = ( atof(eylow_tmpdum) / atof(ppdum) );
      theory_eyhigh_tmp[iy][counts+ipt_init[iy]] = ( atof(eyhigh_tmpdum) / atof(ppdum) );
      counts++;
      //cout << "counts = " << counts << endl;
    } //end of while file open
  } 
 
  /////////////////////////////////////////////////////////////////////////////////
  
  //// set unused values as zero 
  for (int iy = 0 ; iy < nRapRpPb; iy ++ ) {
    for (Int_t ipt=nPtRpPb-1; ipt>=0; ipt--) {
      if (ipt <ipt_init[iy]) {
        theory_px[iy][ipt] = theory_px[iy][ipt+1];
        theory_py[iy][ipt] = theory_py[iy][ipt+1];
        theory_exlow_tmp[iy][ipt] = theory_exlow_tmp[iy][ipt+1];
        theory_exhigh_tmp[iy][ipt] = theory_exhigh_tmp[iy][ipt+1];
        theory_eylow_tmp[iy][ipt] = theory_eylow_tmp[iy][ipt+1];
        theory_eyhigh_tmp[iy][ipt] = theory_eyhigh_tmp[iy][ipt+1];
      }
    }
  }

  //// set proper ex and ey
  for (int iy = 0 ; iy < nRapRpPb; iy ++ ) {
    cout << endl << " ************* iy = " << iy << endl;
    for (Int_t ipt=0; ipt<nPtRpPb; ipt++) {
		  theory_exlow[iy][ipt] = fabs(theory_px[iy][ipt] - theory_exlow_tmp[iy][ipt]);
		  theory_exhigh[iy][ipt] = fabs(theory_px[iy][ipt] - theory_exhigh_tmp[iy][ipt]);
      //theory_exlow[iy][ipt] = 0.5;
      //theory_exhigh[iy][ipt] = 0.5;
		  theory_eylow[iy][ipt] = fabs(theory_py[iy][ipt] - theory_eylow_tmp[iy][ipt]);
		  theory_eyhigh[iy][ipt] = fabs(theory_py[iy][ipt] - theory_eyhigh_tmp[iy][ipt]);
      cout << "theory_px = " << theory_px[iy][ipt] << ", theory_py = " << theory_py[iy][ipt] << endl; 	
      cout << "theory_eylow_tmp = " << theory_eylow_tmp[iy][ipt] <<", theory_eyhigh_tmp = " << theory_eyhigh_tmp[iy][ipt] << endl; 	
    }
  }
  
  /////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////
  
  TGraphAsymmErrors* g_RpPb_theory[nRapRpPb];
  for (int iy = 0 ; iy < nRapRpPb; iy ++ ) {
    g_RpPb_theory[iy]= new TGraphAsymmErrors(nPtRpPb, theory_px[iy], theory_py[iy], theory_exlow[iy], theory_exhigh[iy], theory_eylow[iy], theory_eyhigh[iy]);	
    g_RpPb_theory[iy]->SetName(Form("g_RpPb_theory_%d",iy));
  }
 /* 
  for (int iy=0; iy<nRapRpPb; iy++) {
	  g_RpPb_theory_dummy[iy]->GetXaxis()->SetLimits(0.,ptmax);
	  g_RpPb_theory_dummy[iy]->SetMinimum(0.0);
	  g_RpPb_theory_dummy[iy]->SetMaximum(1.8);
    g_RpPb_theory_dummy[iy]->GetXaxis()->SetTitle("p_{T} [GeV/c]");
    g_RpPb_theory_dummy[iy]->GetXaxis()->CenterTitle();
    g_RpPb_theory_dummy[iy]->GetYaxis()->SetTitle("R_{FB}");
    g_RpPb_theory_dummy[iy]->GetYaxis()->CenterTitle();
    //g_RpPb_theory_dummy[iy]->SetFillColorAlpha(kYellow,0.5);
    g_RpPb_theory_dummy[iy]->SetFillColorAlpha(kWhite,0.5);
	  //g_RpPb_theory_dummy[iy]->SetLineColor(kOrange+7);
	  //g_RpPb_theory_dummy[iy]->SetFillStyle(3004);
    if(!isLine) g_RpPb_theory_dummy[iy]->SetLineWidth(0);
  }
 */ 
  
	///////////////////////////////////////////////////
  //////// experimental points	
  TFile *inFile = new TFile("../DrawFinalPlot/plot_RpPb/RpPb_pt_isPrompt1.root");
  
  TGraphAsymmErrors* g_RpPb_sys[nRapRpPb];
  TGraphAsymmErrors* g_RpPb[nRapRpPb];
  for (int iy = 0 ; iy < nRapRpPb; iy ++ ) {
    g_RpPb_sys[iy] = (TGraphAsymmErrors*)inFile->Get(Form("g_RpPb_sys_%d",iy));
    g_RpPb[iy] = (TGraphAsymmErrors*)inFile->Get(Form("g_RpPb_%d",iy));
  } 
  
	///////////////////////////////////////////////////
	//// Draw
  ///////////////////////////////////////////////////
  
  TCanvas* c_all = new TCanvas("c_all","c_all",1200,680);
  //CMS_lumi( c_all, isPA, iPos );
  c_all->Divide(5,2);
  const int nPad = 10;
  double xmargin = 0.00;
  double ymargin = 0.00;
  double xpad0 = 0.060;
  double xpadw = 0.233;
  TVirtualPad* pad_all[nPad]; // 2 pads for y axis, 8 pads for actual plots
  pad_all[0] = new TPad("pad_all_0", "",0, 0.506, xpad0, 1.0);
  pad_all[1] = new TPad("pad_all_1", "",xpad0, 0.506, xpad0+xpadw, 1.0);
  pad_all[2] = new TPad("pad_all_2", "",xpad0+xpadw, 0.506, xpad0+2*xpadw, 1.0);
  pad_all[3] = new TPad("pad_all_3", "",xpad0+2*xpadw, 0.506, xpad0+3*xpadw, 1.0);
  pad_all[4] = new TPad("pad_all_4", "",xpad0+3*xpadw, 0.506, xpad0+4*xpadw, 1.0);
  pad_all[5] = new TPad("pad_all_5", "",0, 0.0, xpad0, 0.506);
  pad_all[6] = new TPad("pad_all_6", "",xpad0, 0.0, xpad0+xpadw, 0.506);
  pad_all[7] = new TPad("pad_all_7", "",xpad0+xpadw, 0.0, xpad0+2*xpadw, 0.506);
  pad_all[8] = new TPad("pad_all_8", "",xpad0+2*xpadw, 0.0, xpad0+3*xpadw, 0.506);
  pad_all[9] = new TPad("pad_all_9", "",xpad0+3*xpadw, 0.0, xpad0+4*xpadw, 0.506);
  
  double topmargin = 0.14;
  double bottommargin = 0.161;
  for (Int_t iy = 0; iy < nPad; iy++) { 
    pad_all[iy]->Draw();
    if (iy<=4) { 
      pad_all[iy]->SetTopMargin(topmargin); 
      pad_all[iy]->SetBottomMargin(0.0); 
    }
    else { 
      pad_all[iy]->SetTopMargin(0.0); 
      pad_all[iy]->SetBottomMargin(bottommargin); 
    }
    pad_all[iy]->SetLeftMargin(0.0);
    pad_all[iy]->SetRightMargin(0.0);
  }
  
  for (int iy=0; iy<nRapRpPb; iy++) {
    if (iy==0) pad_all[3]->cd();
    else if (iy==1) pad_all[2]->cd();
    else if (iy==2) pad_all[1]->cd();
    else pad_all[iy+3]->cd();
    g_RpPb_sys[iy]->Draw("A5");
	  g_RpPb_theory[iy]->GetXaxis()->SetLimits(ptlimit[iy],ptmax);
	  //g_RpPb_theory[iy]->SetRange(ptlimit[iy],ptmax);
    //g_RpPb_theory[iy]->SetFillColorAlpha(kGray,0.5);
    g_RpPb_theory[iy]->SetFillColorAlpha(kYellow,0.5);
	  g_RpPb_theory[iy]->SetLineColor(kOrange+7);
    g_RpPb[iy]->Draw("p");
    if (isSmoothened) g_RpPb_theory[iy]->Draw("3");
    else g_RpPb_theory[iy]->Draw("5");
    dashedLine(0.,1.,32.,1.,1,1);
  }
    
  c_all->SaveAs(Form("plot_theory/comp_RpPb_pt_isSmoothened%d_Lansberg_%s.pdf",(int)isSmoothened,szPDF.Data()));
  c_all->SaveAs(Form("plot_theory/comp_RpPb_pt_isSmoothened%d_Lansberg_%s.png",(int)isSmoothened,szPDF.Data()));
 
  ///////////////////////////////////////////////////////////////////
  // save as a root file
  TFile* outFile = new TFile(Form("plot_theory/comp_RpPb_pt_isSmoothened%d_Lansberg_%s.root",(int)isSmoothened,szPDF.Data()),"RECREATE");
  outFile->cd();
  for (int iy = 0 ; iy < nRapRpPb; iy ++ ) {
    g_RpPb_theory[iy]->Write();
  } 
  
  return;
}
int rootAna_zVtxFit_step1(char *stringA = "20141218step1", bool isPrompt = false, bool is1st =true){

	gROOT->Macro("./JpsiStyle.C");
	//gStyle->SetCanvasDefW(800);

	// read-in root file
	char *stringB;
	TFile *f01 = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySample/merged_PromptJpsi_PYTHIAboosted_1st_STARTHI53_V27_1Mevt.root");
	TFile *f02;

	if (isPrompt){
		if (is1st) {
			f02 = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySampleEmbedded/tot_PromptJpsi_HIJINGembedding_1st_STARTHI53_V27_20141218.root");
			stringB = "pr_1st"; 
		} else {
			f02 = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySampleEmbedded/tot_PromptJpsi_HIJINGembedding_2nd_STARTHI53_V27_20141218_v2.root");
			stringB = "pr_2nd"; 
		}
	}else{
		if (is1st) {
			f02 = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySampleEmbedded/tot_B2Jpsi_HIJINGembedding_1st_STARTHI53_V27_20141218.root");
			stringB = "np_1st"; 
		} else {
			f02 = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySampleEmbedded/tot_B2Jpsi_HIJINGembedding_2nd_STARTHI53_V27_20141218.root");
			stringB = "np_2nd"; 
		}
	}
	
	int nevt_01 = -1;
	int nevt_02 = -1;
//	int nevt_01 = 1000;
//	int nevt_02 = 1000;
		

	TTree *tree_01 = (TTree*)f01->Get("myTree");
	TTree *tree_02 = (TTree*)f02->Get("myTree");

	///////////////////////////////////////////////////////////////////////////////////////////////
	/////// read-in tree

	UInt_t          eventNb_01;
	Int_t           Centrality_01;
  Int_t           HLTriggers_01;
	Float_t					zVtx_01;
	Int_t           Reco_QQ_size_01;
	Int_t           Reco_QQ_type_01[20];   //[Reco_QQ_size] : for Data GG, GT, TT?
	Int_t           Reco_QQ_sign_01[20];   //[Reco_QQ_size] : 0=+,- / 1=+/+, 2=-/-
	Int_t           Reco_QQ_trig_01[20];   //[Reco_QQ_size] : DoubleMuOpen ==1
	Float_t 				Reco_QQ_ctau_01[20];
	Float_t 				Reco_QQ_ctauErr_01[20];
	TClonesArray    *Reco_QQ_4mom_01;
	TClonesArray    *Reco_QQ_mupl_4mom_01;
	TClonesArray    *Reco_QQ_mumi_4mom_01;
	Int_t           Gen_QQ_size_01;
	Int_t           Gen_QQ_type_01[20];	//[Gen_QQ_size] : for MC PR=0 / NP=1
  TClonesArray    *Gen_QQ_4mom_01;
  TClonesArray    *Gen_QQ_mupl_4mom_01;
  TClonesArray    *Gen_QQ_mumi_4mom_01;

  TBranch        *b_eventNb_01;
  TBranch        *b_Centrality_01;   //!
  TBranch        *b_HLTriggers_01;
  TBranch        *b_zVtx_01;
  TBranch        *b_Reco_QQ_size_01;   //!
  TBranch        *b_Reco_QQ_type_01;   //!
  TBranch        *b_Reco_QQ_sign_01;   //!
  TBranch        *b_Reco_QQ_trig_01;   //!
  TBranch        *b_Reco_QQ_ctau_01;   //!
  TBranch        *b_Reco_QQ_ctauErr_01;   //!
	TBranch        *b_Reco_QQ_4mom_01;   //!
  TBranch        *b_Reco_QQ_mupl_4mom_01;   //!
  TBranch        *b_Reco_QQ_mumi_4mom_01;   //!
  TBranch        *b_Gen_QQ_size_01;   //!
  TBranch        *b_Gen_QQ_type_01;
  TBranch        *b_Gen_QQ_4mom_01;   //!
  TBranch        *b_Gen_QQ_mupl_4mom_01;   //!
  TBranch        *b_Gen_QQ_mumi_4mom_01;   //!

  TLorentzVector* JP_Reco_01 = new TLorentzVector;
  TLorentzVector* m1P_Reco_01 = new TLorentzVector;
  TLorentzVector* m2P_Reco_01 = new TLorentzVector;
  TLorentzVector* JP_Gen_tmp_01 = new TLorentzVector; // GEN dimuon - NoCut
  TLorentzVector* JP_Gen_tmp_qq_01 = new TLorentzVector; // GEN Jpsi - NoCut
  TLorentzVector* JP_Gen_01 = new TLorentzVector; //for GEN dimuon - Actual Denominator
  TLorentzVector* m1P_Gen_01 = new TLorentzVector;
  TLorentzVector* m2P_Gen_01 = new TLorentzVector;
	
	Reco_QQ_4mom_01 =0;
	Reco_QQ_mupl_4mom_01 =0;
	Reco_QQ_mumi_4mom_01 =0;
	Gen_QQ_4mom_01 =0;
	Gen_QQ_mupl_4mom_01 =0;
	Gen_QQ_mumi_4mom_01 =0;

	// read-in branches
	tree_01->SetBranchAddress("eventNb", &eventNb_01, &b_eventNb_01);
	tree_01->SetBranchAddress("Centrality", &Centrality_01, &b_Centrality_01);
  tree_01->SetBranchAddress("HLTriggers", &HLTriggers_01, &b_HLTriggers_01);
  tree_01->SetBranchAddress("zVtx", &zVtx_01, &b_zVtx_01);
  tree_01->SetBranchAddress("Reco_QQ_size", &Reco_QQ_size_01, &b_Reco_QQ_size_01);
  tree_01->SetBranchAddress("Reco_QQ_type", Reco_QQ_type_01, &b_Reco_QQ_type_01);
  tree_01->SetBranchAddress("Reco_QQ_sign", Reco_QQ_sign_01, &b_Reco_QQ_sign_01);
  tree_01->SetBranchAddress("Reco_QQ_trig", Reco_QQ_trig_01, &b_Reco_QQ_trig_01);
  tree_01->SetBranchAddress("Reco_QQ_ctau", Reco_QQ_ctau_01, &b_Reco_QQ_ctau_01);
  tree_01->SetBranchAddress("Reco_QQ_ctauErr", Reco_QQ_ctauErr_01, &b_Reco_QQ_ctauErr_01);
  tree_01->SetBranchAddress("Reco_QQ_4mom", &Reco_QQ_4mom_01, &b_Reco_QQ_4mom_01);
  tree_01->SetBranchAddress("Reco_QQ_mupl_4mom", &Reco_QQ_mupl_4mom_01, &b_Reco_QQ_mupl_4mom_01);
  tree_01->SetBranchAddress("Reco_QQ_mumi_4mom", &Reco_QQ_mumi_4mom_01, &b_Reco_QQ_mumi_4mom_01);
  tree_01->SetBranchAddress("Gen_QQ_size", &Gen_QQ_size_01, &b_Gen_QQ_size_01);
  tree_01->SetBranchAddress("Gen_QQ_type", Gen_QQ_type_01, &b_Gen_QQ_type_01);
  tree_01->SetBranchAddress("Gen_QQ_4mom", &Gen_QQ_4mom_01, &b_Gen_QQ_4mom_01);
  tree_01->SetBranchAddress("Gen_QQ_mupl_4mom", &Gen_QQ_mupl_4mom_01, &b_Gen_QQ_mupl_4mom_01);
  tree_01->SetBranchAddress("Gen_QQ_mumi_4mom", &Gen_QQ_mumi_4mom_01, &b_Gen_QQ_mumi_4mom_01);

	///////////////////////////////////////////////////////////////////////////////////////////////
	/////// read-in tree

	UInt_t          eventNb_02;
	Int_t           Centrality_02;
  Int_t           HLTriggers_02;
	Float_t					zVtx_02;
	Int_t           Reco_QQ_size_02;
	Int_t           Reco_QQ_type_02[20];   //[Reco_QQ_size] : for Data GG, GT, TT?
	Int_t           Reco_QQ_sign_02[20];   //[Reco_QQ_size] : 0=+,- / 1=+/+, 2=-/-
	Int_t           Reco_QQ_trig_02[20];   //[Reco_QQ_size] : DoubleMuOpen ==1
	Float_t 				Reco_QQ_ctau_02[20];
	Float_t 				Reco_QQ_ctauErr_02[20];
	TClonesArray    *Reco_QQ_4mom_02;
	TClonesArray    *Reco_QQ_mupl_4mom_02;
	TClonesArray    *Reco_QQ_mumi_4mom_02;
	Int_t           Gen_QQ_size_02;
	Int_t           Gen_QQ_type_02[20];	//[Gen_QQ_size] : for MC PR=0 / NP=1
  TClonesArray    *Gen_QQ_4mom_02;
  TClonesArray    *Gen_QQ_mupl_4mom_02;
  TClonesArray    *Gen_QQ_mumi_4mom_02;

  TBranch        *b_eventNb_02;
  TBranch        *b_Centrality_02;   //!
  TBranch        *b_HLTriggers_02;
  TBranch        *b_zVtx_02;
  TBranch        *b_Reco_QQ_size_02;   //!
  TBranch        *b_Reco_QQ_type_02;   //!
  TBranch        *b_Reco_QQ_sign_02;   //!
  TBranch        *b_Reco_QQ_trig_02;   //!
  TBranch        *b_Reco_QQ_ctau_02;   //!
  TBranch        *b_Reco_QQ_ctauErr_02;   //!
	TBranch        *b_Reco_QQ_4mom_02;   //!
  TBranch        *b_Reco_QQ_mupl_4mom_02;   //!
  TBranch        *b_Reco_QQ_mumi_4mom_02;   //!
  TBranch        *b_Gen_QQ_size_02;   //!
  TBranch        *b_Gen_QQ_type_02;
  TBranch        *b_Gen_QQ_4mom_02;   //!
  TBranch        *b_Gen_QQ_mupl_4mom_02;   //!
  TBranch        *b_Gen_QQ_mumi_4mom_02;   //!

  TLorentzVector* JP_Reco_02 = new TLorentzVector;
  TLorentzVector* m1P_Reco_02 = new TLorentzVector;
  TLorentzVector* m2P_Reco_02 = new TLorentzVector;
  TLorentzVector* JP_Gen_tmp_02 = new TLorentzVector; // GEN dimuon - NoCut
  TLorentzVector* JP_Gen_tmp_qq_02 = new TLorentzVector; // GEN Jpsi - NoCut
  TLorentzVector* JP_Gen_02 = new TLorentzVector; //for GEN dimuon - Actual Denominator
  TLorentzVector* m1P_Gen_02 = new TLorentzVector;
  TLorentzVector* m2P_Gen_02 = new TLorentzVector;
	
	Reco_QQ_4mom_02 =0;
	Reco_QQ_mupl_4mom_02 =0;
	Reco_QQ_mumi_4mom_02 =0;
	Gen_QQ_4mom_02 =0;
	Gen_QQ_mupl_4mom_02 =0;
	Gen_QQ_mumi_4mom_02 =0;

	// read-in branches
	tree_02->SetBranchAddress("eventNb", &eventNb_02, &b_eventNb_02);
	tree_02->SetBranchAddress("Centrality", &Centrality_02, &b_Centrality_02);
  tree_02->SetBranchAddress("HLTriggers", &HLTriggers_02, &b_HLTriggers_02);
  tree_02->SetBranchAddress("zVtx", &zVtx_02, &b_zVtx_02);
  tree_02->SetBranchAddress("Reco_QQ_size", &Reco_QQ_size_02, &b_Reco_QQ_size_02);
  tree_02->SetBranchAddress("Reco_QQ_type", Reco_QQ_type_02, &b_Reco_QQ_type_02);
  tree_02->SetBranchAddress("Reco_QQ_sign", Reco_QQ_sign_02, &b_Reco_QQ_sign_02);
  tree_02->SetBranchAddress("Reco_QQ_trig", Reco_QQ_trig_02, &b_Reco_QQ_trig_02);
  tree_02->SetBranchAddress("Reco_QQ_ctau", Reco_QQ_ctau_02, &b_Reco_QQ_ctau_02);
  tree_02->SetBranchAddress("Reco_QQ_ctauErr", Reco_QQ_ctauErr_02, &b_Reco_QQ_ctauErr_02);
  tree_02->SetBranchAddress("Reco_QQ_4mom", &Reco_QQ_4mom_02, &b_Reco_QQ_4mom_02);
  tree_02->SetBranchAddress("Reco_QQ_mupl_4mom", &Reco_QQ_mupl_4mom_02, &b_Reco_QQ_mupl_4mom_02);
  tree_02->SetBranchAddress("Reco_QQ_mumi_4mom", &Reco_QQ_mumi_4mom_02, &b_Reco_QQ_mumi_4mom_02);
  tree_02->SetBranchAddress("Gen_QQ_size", &Gen_QQ_size_02, &b_Gen_QQ_size_02);
  tree_02->SetBranchAddress("Gen_QQ_type", Gen_QQ_type_02, &b_Gen_QQ_type_02);
  tree_02->SetBranchAddress("Gen_QQ_4mom", &Gen_QQ_4mom_02, &b_Gen_QQ_4mom_02);
  tree_02->SetBranchAddress("Gen_QQ_mupl_4mom", &Gen_QQ_mupl_4mom_02, &b_Gen_QQ_mupl_4mom_02);
  tree_02->SetBranchAddress("Gen_QQ_mumi_4mom", &Gen_QQ_mumi_4mom_02, &b_Gen_QQ_mumi_4mom_02);

	// cut definitions
/*
	TCut trigCut = "((Reco_QQ_trig&1)==1 && (HLTriggers&1)==1 )";
	//TCut recoCut = "Reco_QQ_size>=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 rapRangePbp = "Reco_QQ_4mom.Rapidity() > -2.4 && Reco_QQ_4mom.Rapidity() < 2.4";
	TCut rapRangepPb = "Reco_QQ_4mom.Rapidity() > -2.4 && Reco_QQ_4mom.Rapidity() < 2.4";
	TCut ptRange = "Reco_QQ_4mom.Pt() > 0.0 && Reco_QQ_4mom.Pt() < 30.0";
	TCut etaPbp = "Reco_QQ_mupl_4mom.Eta()>-2.4 && Reco_QQ_mupl_4mom.Eta()<2.4 && Reco_QQ_mumi_4mom.Eta()>-2.4 && Reco_QQ_mumi_4mom.Eta()<2.4";
	TCut etapPb = "Reco_QQ_mupl_4mom.Eta()>-2.4 && Reco_QQ_mupl_4mom.Eta()<2.4 && Reco_QQ_mumi_4mom.Eta()>-2.4 && Reco_QQ_mumi_4mom.Eta()<2.4";
	TCut accRecoPlus = "(TMath::Abs(Reco_QQ_mupl_4mom.Eta())<2.4) && ( (TMath::Abs(Reco_QQ_mupl_4mom.Eta())<1.3 && Reco_QQ_mupl_4mom.Pt()>=3.3) || ( 1.3<= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.2 && sqrt(Reco_QQ_mupl_4mom.Px()*Reco_QQ_mupl_4mom.Px()+ Reco_QQ_mupl_4mom.Py()*Reco_QQ_mupl_4mom.Py() + Reco_QQ_mupl_4mom.Pz()*Reco_QQ_mupl_4mom.Pz())>=2.9 ) || (2.2<=TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && Reco_QQ_mupl_4mom.Pt()>=0.8) )";
	TCut accRecoMinus = "(TMath::Abs(Reco_QQ_mumi_4mom.Eta())<2.4) && ( (TMath::Abs(Reco_QQ_mumi_4mom.Eta())<1.3 && Reco_QQ_mumi_4mom.Pt()>=3.3) || ( 1.3<= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.2 && sqrt(Reco_QQ_mumi_4mom.Px()*Reco_QQ_mumi_4mom.Px()+ Reco_QQ_mumi_4mom.Py()*Reco_QQ_mumi_4mom.Py() + Reco_QQ_mumi_4mom.Pz()*Reco_QQ_mumi_4mom.Pz())>=2.9 ) || (2.2<=TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && Reco_QQ_mumi_4mom.Pt()>=0.8) )";
	TCut accReco = accRecoPlus && accRecoMinus;

	TCut runCut = "runNb >=210498 && runNb <= 210658"; 
	TCut totalCutPbp = trigCut && recoCut && massRange && rapRangePbp && etaPbp && ptRange && accReco;
	TCut totalCutpPb = trigCut && recoCut && massRange && rapRangepPb && etapPb && ptRange && accReco;
*/

	// define 1D hist
	const int nbin[] = {80};
	//const int nbin[] = {30};
	const double minbin[] = {-30};
	const double maxbin[] = {+30};
	TString histName[] = {"zVtx"};
	TString histTitle[] = {"primary vertex Z (cm)"};
	const int nHist = sizeof(nbin)/sizeof(int);
	cout << "nHist = "<<nHist<<endl;
	TH1D *h01[nHist];
	TH1D *h02_before[nHist];
	TH1D *hRatio[nHist];
	TH1D *h02_after[nHist];

	//define fitting function
	TF1* gCommon = new TF1("gCommon","gaus",-30., 30.); //prefit to extract param
	TF1* g1 = new TF1("g1",tfGaus,-30., 30.,3);
	TF1* g2 = new TF1("g2",tfGaus,-30., 30.,3);
	TF1* g3 = new TF1("g3",tfGaus,-30., 30.,3);
	Double_t parC[3]; // for Common
	Double_t par01[3]; //for h01
	Double_t par02[3]; //for h02_before
	Double_t par03[3]; //for hRatio
	
	TF1* gRatio = new TF1("gRatio",tfDivideGaus,-30., 30.,6);
	Double_t parRatio[6]; //for hRatio

	const int nEntry = 5000;
	TCanvas* c0[nHist];
	TCanvas* c1[nHist];
	//TLegend *legU = new TLegend(0.17,0.71,0.75,0.90,NULL,"brNDC");
	TLegend *legU = new TLegend(0.17,0.76,0.80,0.90,NULL,"brNDC");
	legU-> SetNColumns(2);
	SetLegendStyle(legU);

	TLatex* latex = new TLatex();
	latex->SetNDC();
	latex->SetTextAlign(12);
	latex->SetTextSize(0.04);


	for (int i=0; i<nHist; i++) {
		h01[i] = new TH1D(Form("h01_%s_%d",histName[i].Data(),i),Form(";%s;",histTitle[i].Data()),nbin[i],minbin[i],maxbin[i]);
		h02_before[i] = new TH1D(Form("h02_before_%s_%d",histName[i].Data(),i),Form(";%s;",histTitle[i].Data()),nbin[i],minbin[i],maxbin[i]);
		h02_after[i] = new TH1D(Form("h02_after_%s_%d",histName[i].Data(),i),Form(";%s;",histTitle[i].Data()),nbin[i],minbin[i],maxbin[i]);
		h01[i]->Sumw2();
		h02_before[i]->Sumw2();
		h02_after[i]->Sumw2();
		std::cout << i <<"th hist name = " << histName[i].Data() << std::endl;
		
		if(nevt_01 == -1) nevt_01 = tree_01->GetEntries();
		if(nevt_02 == -1) nevt_02 = tree_02->GetEntries();

		for (int iev_01=0; iev_01<nevt_01; ++iev_01) {
			tree_01->GetEntry(iev_01);	
			h01[i]->Fill(zVtx_01);	
		}
		cout << "*** h01 is filled ! " << endl;
		for (int iev_02=0; iev_02<nevt_02; ++iev_02) {
			tree_02->GetEntry(iev_02);	
			h02_before[i]->Fill(zVtx_02);	
		}
		cout << "*** h02_before is filled! " << endl;
		
		//tree_01->Draw(Form("%s>>%s",histName[i].Data(),h01[i]->GetName()),"","");
		//tree_02->Draw(Form("%s>>%s",histName[i].Data(),h02_before[i]->GetName()),"","");
		std::cout << histName[i].Data() <<" : h01 entries = " << h01[i]->GetEntries() << std::endl;
		std::cout << histName[i].Data() <<" : h02_before entries = " << h02_before[i]->GetEntries() << std::endl;
		//std::cout << histName[i].Data() <<" : h01 integral = " << h01[i]->Integral() << std::endl;
		//std::cout << histName[i].Data() <<" : h02_before integral = " << h02_before[i]->Integral() << std::endl;
		h01[i]->Scale(1/h01[i]->Integral());
		h02_before[i]->Scale(1/h02_before[i]->Integral());

		/*
		//prefit
		h01[i]->Fit("gCommon", "N");
		gCommon->GetParameters(&parC[0]);
		g1->SetParLimits(0, parC[0]-0.01,parC[0]+0.01);
		g1->SetParLimits(1, parC[1]-0.01,parC[1]+0.01);
		g1->SetParLimits(2, parC[2]-0.01,parC[2]+0.01);
		h02_before[i]->Fit("gCommon", "N");
		gCommon->GetParameters(&parC[0]);
		g2->SetParLimits(0, parC[0]-0.01,parC[0]+0.01);
		g2->SetParLimits(1, parC[1]-0.01,parC[1]+0.01);
		g2->SetParLimits(2, parC[2]-0.01,parC[2]+0.01);
		*/

		//Draw and Fit
		c1[i] = new TCanvas(Form("c1_%s",histName[i].Data()),"",600,600);
		c1[i]->Clear();
		c1[i]->cd();
		gPad->SetLogy(0);
		SetHistStyle(h01[i],3,10);
		SetHistStyle(h02_before[i],4,11);
		h01[i]->SetFillColor(kOrange+7);
		h01[i]->SetFillStyle(3003);
		h02_before[i]->SetFillColor(kGreen+3);
		h02_before[i]->SetFillStyle(3005);
		h01[i]->SetAxisRange(0.0,0.08,"Y");

		h01[i]->Draw("pe");
		//g1->SetLineColor(kOrange+7);
		//h01[i]->Fit("g1","N");
		//g1->Draw("same");
		//g1->GetParameters(&par01[0]);
		//latex->DrawLatex(0.20, 0.77, Form("mean : %.2f",par01[1]));	
		//latex->DrawLatex(0.20, 0.71, Form("sigma : %.2f",par01[2]));
		
		h02_before[i]->Draw("pe same");
		//g2->SetLineColor(kGreen+3);
		//h02_before[i]->Fit("g2","N");
		//g2->Draw("same");
		//g2->GetParameters(&par02[0]);
		//latex->DrawLatex(0.67, 0.77, Form("mean : %.2f",par02[1]));	
		//latex->DrawLatex(0.67, 0.71, Form("sigma : %.2f",par02[2]));
		
		legU->AddEntry(h01[i],"MC_pythia      ","lp");
		legU->AddEntry(h02_before[i],"MC_embedded","lp");
		latex->DrawLatex(0.67, 0.77, "(no weight)");	
		legU->Draw();

		c1[i]->SaveAs(Form("zVtxFit_%s_%s_%s.pdf",histName[i].Data(),stringA,stringB));
		c1[i]->SaveAs(Form("zVtxFit_%s_%s_%s.png",histName[i].Data(),stringA,stringB));
		c1[i]->Clear();
		legU->Clear();
	/*
	// divide two TF
	gRatio->SetParameters(par01[0],par01[1],par01[2],par02[0],par02[1],par02[2]);
	//cout <<"check param 0 = " << gRatio->GetParameter(0) << endl;		
	//cout <<"check param 1 = " << gRatio->GetParameter(1) << endl;		
	//cout <<"check param 2 = " << gRatio->GetParameter(2) << endl;		
	//cout <<"check param 3 = " << gRatio->GetParameter(3) << endl;		
	//cout <<"check param 4 = " << gRatio->GetParameter(4) << endl;		
	//cout <<"check param 5 = " << gRatio->GetParameter(5) << endl;		
	gRatio->SetLineColor(kViolet-4);
	*/

	// get ratio
	gPad->SetLogy(0);
	hRatio[i] = (TH1D*)h01[i]->Clone(Form("hRatio_%d",i));
	hRatio[i]->Divide(h02_before[i]);
	hRatio[i]->GetYaxis()->SetRangeUser(0.,2.0);
	hRatio[i]->GetYaxis()->SetTitle("Ratio = MC_pythia/MC_embedded");
	SetHistStyle(hRatio[i],1,0);
	//hRatio[i]->SetMarkerColor(kWhite);
	hRatio[i]->Draw("pe");
/*	
	//just cross check w/ gaussian : fit the ratio itself
	hRatio[i]->Fit("gCommon", "N");
	gCommon->GetParameters(&parC[0]);
	g3->SetParLimits(0, parC[0]-0.01,parC[0]+0.01);
	g3->SetParLimits(1, parC[1]-0.01,parC[1]+0.01);
	g3->SetParLimits(2, parC[2]-0.01,parC[2]+0.01);
	g3->SetLineColor(kBlack);
	hRatio[i]->Fit("g3","N");
	g3->GetParameters(&par03[0]);
	//latex->DrawLatex(0.20, 0.77, Form("mean : %.2f",par03[1]));	
	//latex->DrawLatex(0.20, 0.71, Form("sigma : %.2f",par03[2]));
	//g3->Draw("same");
	//gRatio->Draw("same");
*/
	
	dashedLine(minbin[i],1.,maxbin[i],1.,1,1);
	c1[i]->SaveAs(Form("zVtxFit_ratio_%s_%s_%s.pdf",histName[i].Data(),stringA,stringB));
	c1[i]->SaveAs(Form("zVtxFit_ratio_%s_%s_%s.png",histName[i].Data(),stringA,stringB));
	c1[i]->Clear();

	////////////////////////////////////////////////////////////////////////////////
	/// KYO test weighting!!!!
	
	int tmpbin = 531;
	double tmpweight = 531.;
	for (int iev_02=0; iev_02<nevt_02; ++iev_02) {
		tree_02->GetEntry(iev_02);	
		tmpbin = hRatio[i]->FindBin(zVtx_02);
		tmpweight = hRatio[i]->GetBinContent(tmpbin);
		//cout << "zVtx_02 = " << zVtx_02 << endl;
		//cout << "tmpbin = " << tmpbin << endl;
		//cout << "tmpweight = " << tmpweight << endl;
		h02_after[i]->Fill(zVtx_02,tmpweight);	
		}
		cout << "*** h02_after is filled! " << endl;
		std::cout << histName[i].Data() <<" : h02_after entries = " << h02_after[i]->GetEntries() << std::endl;
		//std::cout << histName[i].Data() <<" : h02_after integral = " << h02_after[i]->Integral() << std::endl;
		h02_after[i]->Scale(1/h02_after[i]->Integral());

	
		c1[i]->cd();
		gPad->SetLogy(0);
		SetHistStyle(h01[i],3,10);
		SetHistStyle(h02_after[i],4,11);
		h01[i]->SetFillColor(kOrange+7);
		h01[i]->SetFillStyle(3003);
		h02_after[i]->SetFillColor(kGreen+3);
		h02_after[i]->SetFillStyle(3005);
		h01[i]->SetAxisRange(0.0,0.08,"Y");

		//h01[i]->GetYaxis()->SetRangeUser(0.,10.0);
		h01[i]->Draw("pe");
		h02_after[i]->Draw("pe same");
		legU->AddEntry(h01[i],"MC_pythia      ","lp");
		legU->AddEntry(h02_after[i],"MC_embedded","lp");
		latex->DrawLatex(0.67, 0.77, "(weight)");	
		legU->Draw();
		c1[i]->SaveAs(Form("zVtxFit_weight_%s_%s_%s.pdf",histName[i].Data(),stringA,stringB));
		c1[i]->SaveAs(Form("zVtxFit_weight_%s_%s_%s.png",histName[i].Data(),stringA,stringB));
		//c1[i]->Clear();
		//legU->Clear();

	}

	//Save as a root file
	TFile *outFile = new TFile(Form("zVtxFit_%s_%s.root",stringA,stringB),"RECREATE");		
	outFile->cd();
	for (int i=0; i<nHist; i++) {
		h01[i]->Write();
		h02_before[i]->Write();
		h02_after[i]->Write();
		//hRatio[i]->SetMarkerColor(kRed);
		hRatio[i]->Write();
	}
	//g1->Write();
	//g2->Write();
	//gRatio->Write();
	outFile->Close();
	
	return 0;	

}
//// 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.
Example #10
0
void draw_comp_cent(bool isPrompt=true, bool isPair=true, bool isEmbedded=true, bool isBinomial=true, char *dirName = "drawComprm3step")
{

	gROOT->Macro("./JpsiStyle.C");
	gStyle->SetPaintTextFormat(".3f"); // for text colz

	char* ntuple01 = "default 7_4_0";
	char* ntuple02 = "3 steps removed";
	//char* ntuple02 = "muonSeeded";

	double ymin = 0.85;
	double ymax = 1.15;

	string strPrompt;
	string strEmbd;
	string strPair;
	if(isPrompt){ strPrompt = "prompt"; }
	else { strPrompt = "nonprompt"; }
	if(isEmbedded){ strEmbd = "embd";	}
	else { strEmbd = "nonembd"; }
	if(isPair){ strPair = "Pair"; }
	else { strPair = "Trk"; }
	cout << "strPrompt = " << strPrompt.c_str() << endl;
	cout << "strEmbd = " << strEmbd.c_str() << endl;
	cout << "strPair = " << strPair.c_str() << endl;

	TFile * refFile01;
	TFile * refFile02;

	//refFile01 = new TFile(Form("./eff_74X_setBr_wDetached/Eff_isPtCut0_doWeight0_isEmbedded1_%s_embd_%s.root",strPrompt.c_str(),strPair.c_str()));
	refFile01 = new TFile(Form("./eff_cent_setBr_goni/Eff_%s_embd_%s.root",strPrompt.c_str(),strPair.c_str()));
	refFile02 = new TFile(Form("./eff_cent_setBr_rm3step/Eff_%s_embd_%s.root",strPrompt.c_str(),strPair.c_str()));
	//refFile02 = new TFile(Form("./eff_cent_setBr_muonSeeded/Eff_%s_embd_%s.root",strPrompt.c_str(),strPair.c_str()));

	TH1D * h1D_EffPt_01 = (TH1D*)refFile01->Get("hEffPt");
	TH1D * h1D_EffPt_02 = (TH1D*)refFile02->Get("hEffPt");
	TH1D * h1D_EffRap_01 = (TH1D*)refFile01->Get("hEffRap");
	TH1D * h1D_EffRap_02 = (TH1D*)refFile02->Get("hEffRap");
	TH1D * h1D_EffLxy_01 = (TH1D*)refFile01->Get("hEffLxy");
	TH1D * h1D_EffLxy_02 = (TH1D*)refFile02->Get("hEffLxy");
	TH1D * h1D_EffCent_01 = (TH1D*)refFile01->Get("hEffCent");
	TH1D * h1D_EffCent_02 = (TH1D*)refFile02->Get("hEffCent");
	h1D_EffPt_01->SetName("h1D_EffPt_01");
	h1D_EffPt_02->SetName("h1D_EffPt_02");
	h1D_EffRap_01->SetName("h1D_EffRap_01");
	h1D_EffRap_02->SetName("h1D_EffRap_02");
	h1D_EffLxy_01->SetName("h1D_EffLxy_01");
	h1D_EffLxy_02->SetName("h1D_EffLxy_02");
	h1D_EffCent_01->SetName("h1D_EffCent_01");
	h1D_EffCent_02->SetName("h1D_EffCent_02");

	TH1D* hRatio_EffPt = (TH1D*)h1D_EffPt_02->Clone("hRatio_EffPt");
	if (isBinomial) hRatio_EffPt->Divide(h1D_EffPt_02,h1D_EffPt_01,1,1,"B");
	else hRatio_EffPt->Divide(h1D_EffPt_01);
	TH1D* hRatio_EffRap = (TH1D*)h1D_EffRap_02->Clone("hRatio_EffRap");
	if (isBinomial) hRatio_EffRap->Divide(h1D_EffRap_02,h1D_EffRap_01,1,1,"B");
	else hRatio_EffRap->Divide(h1D_EffRap_01);
	TH1D* hRatio_EffLxy = (TH1D*)h1D_EffLxy_02->Clone("hRatio_EffLxy");
	if (isBinomial) hRatio_EffLxy->Divide(h1D_EffLxy_02,h1D_EffLxy_01,1,1,"B");
	else hRatio_EffLxy->Divide(h1D_EffLxy_01);
	TH1D* hRatio_EffCent = (TH1D*)h1D_EffCent_02->Clone("hRatio_EffCent");
	if (isBinomial) hRatio_EffCent->Divide(h1D_EffCent_02,h1D_EffCent_01,1,1,"B");
	else hRatio_EffCent->Divide(h1D_EffCent_01);

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

	//Legend
	TLegend *legUR = new TLegend(0.56,0.68,0.90,0.90,NULL,"brNDC");
	//TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC");
	TLegend *legUL = new TLegend(0.20,0.71,0.51,0.90,NULL,"brNDC");
	TLegend *legBM = new TLegend(0.40,0.20,0.75,0.35,NULL,"brNDC");
	TLegend *legBR = new TLegend(0.56,0.20,0.90,0.42,NULL,"brNDC");
	SetLegendStyle(legUR);
	SetLegendStyle(legUL);
	SetLegendStyle(legBM);
	SetLegendStyle(legBR);

	//////////////////////////////////////////////////////////////////
	// --- Draw histograms
	TCanvas* c1 = new TCanvas("c1","c1",600,600);
	
	////// 01 Pt
	c1->cd();
	h1D_EffPt_01->GetXaxis()->SetTitle("p_{T} (GeV/c)");
	h1D_EffPt_01->GetXaxis()->CenterTitle();
	h1D_EffPt_01->GetYaxis()->SetTitle("Efficiency");
	//h1D_EffPt_01->GetXaxis()->SetRangeUser(0,16);
	if (isPrompt) h1D_EffPt_01->GetXaxis()->SetRangeUser(0,12);
	else  h1D_EffPt_01->GetXaxis()->SetRangeUser(0,22);
	h1D_EffPt_01->SetMinimum(0);	
	h1D_EffPt_01->SetMaximum(1);	
	SetHistStyle(h1D_EffPt_01,3,0);
	SetHistStyle(h1D_EffPt_02,4,10);
	h1D_EffPt_01->Draw("");
	h1D_EffPt_02->Draw("same");
	if (isPair){
		legUL->SetHeader(strPrompt.c_str());
		legUL->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legUL->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legUL->Draw();
	}else{
		legBR->SetHeader(strPrompt.c_str());
		legBR->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legBR->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legBR->Draw();
	}
	c1->SaveAs(Form("%s/comp_EffPt_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));
//	c1->SaveAs(Form("%s/comp_EffPt_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));	
	legUL->Clear();
	legBR->Clear();
	c1->Clear();

	if (isPair) hRatio_EffPt->GetXaxis()->SetTitle("p_{T}^{#mu#mu} (GeV/c)");	
	else hRatio_EffPt->GetXaxis()->SetTitle("p_{T}^{#mu} (GeV/c)");	
	hRatio_EffPt->GetXaxis()->CenterTitle();	
	if (isPrompt) hRatio_EffPt->GetXaxis()->SetRangeUser(0,12);
	else  hRatio_EffPt->GetXaxis()->SetRangeUser(0,22);
	hRatio_EffPt->GetYaxis()->SetTitle(Form("Ratio = [ %s ]/[ %s ]",ntuple02,ntuple01));	
	hRatio_EffPt->SetMinimum(ymin);	
	hRatio_EffPt->SetMaximum(ymax);	
	hRatio_EffPt->Draw();	
	SetHistStyle(hRatio_EffPt,2,0);
	//dashedLine(0.,1.,16.,1.,1,1);
	if (isPrompt) dashedLine(0.,1.,12.,1.,1,1);
	else dashedLine(0.,1.,22.,1.,1,1);
	c1->SaveAs(Form("%s/compRatio_EffPt_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));	
//	c1->SaveAs(Form("%s/compRatio_EffPt_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));
	c1->Clear();

	////// 02 Y
	c1->cd();
	if (isPair) h1D_EffRap_01->GetXaxis()->SetTitle("y");
	else  h1D_EffRap_01->GetXaxis()->SetTitle("#eta");
	h1D_EffRap_01->GetXaxis()->CenterTitle();
	h1D_EffRap_01->GetYaxis()->SetTitle("Efficiency");
	h1D_EffRap_01->GetXaxis()->SetRangeUser(-2.5,2.5);
	h1D_EffRap_01->SetMinimum(0);	
	h1D_EffRap_01->SetMaximum(1);	
	SetHistStyle(h1D_EffRap_01,3,0);
	SetHistStyle(h1D_EffRap_02,4,10);
	h1D_EffRap_01->Draw("");
	h1D_EffRap_02->Draw("same");
	if (isPair){
		legUL->SetHeader(strPrompt.c_str());
		legUL->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legUL->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legUL->Draw();
	}else{
		legBM->SetHeader(strPrompt.c_str());
		legBM->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legBM->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legBM->Draw();
	}
	c1->SaveAs(Form("%s/comp_EffRap_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));
//	c1->SaveAs(Form("%s/comp_EffRap_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));	
	legUL->Clear();
	legBM->Clear();
	c1->Clear();

	if (isPair) hRatio_EffRap->GetXaxis()->SetTitle("y");
	else  hRatio_EffRap->GetXaxis()->SetTitle("#eta");
	hRatio_EffRap->GetXaxis()->CenterTitle();	
	hRatio_EffRap->GetXaxis()->SetRangeUser(-2.5,2.5);
	hRatio_EffRap->GetYaxis()->SetTitle(Form("Ratio = [ %s ]/[ %s ]",ntuple02,ntuple01));	
	hRatio_EffRap->SetMinimum(ymin);	
	hRatio_EffRap->SetMaximum(ymax);	
	hRatio_EffRap->Draw();	
	SetHistStyle(hRatio_EffRap,2,0);
	dashedLine(-2.5,1.,2.5,1.,1,1);
	c1->SaveAs(Form("%s/compRatio_EffRap_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));	
//	c1->SaveAs(Form("%s/compRatio_EffRap_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));
	c1->Clear();

	////// 03 Lxy
	c1->cd();
	h1D_EffLxy_01->GetXaxis()->SetTitle("L_{xy}");
	h1D_EffLxy_01->GetXaxis()->CenterTitle();
	h1D_EffLxy_01->GetYaxis()->SetTitle("Efficiency");
	h1D_EffLxy_01->GetXaxis()->SetRangeUser(0,1);
	h1D_EffLxy_01->SetMinimum(0);	
	h1D_EffLxy_01->SetMaximum(1);	
	SetHistStyle(h1D_EffLxy_01,3,0);
	SetHistStyle(h1D_EffLxy_02,4,10);
	h1D_EffLxy_01->Draw("");
	h1D_EffLxy_02->Draw("same");
	if (isPair){
		legUL->SetHeader(strPrompt.c_str());
		legUL->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legUL->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legUL->Draw();
	}else{
		legBM->SetHeader(strPrompt.c_str());
		legBM->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legBM->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legBM->Draw();
	}
	c1->SaveAs(Form("%s/comp_EffLxy_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));
//	c1->SaveAs(Form("%s/comp_EffLxy_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));	
	legUL->Clear();
	legBM->Clear();
	c1->Clear();

	hRatio_EffLxy->GetXaxis()->SetTitle("L_{xy}");	
	hRatio_EffLxy->GetXaxis()->CenterTitle();	
	hRatio_EffLxy->GetXaxis()->SetRangeUser(0,1);
	hRatio_EffLxy->GetYaxis()->SetTitle(Form("Ratio = [ %s ]/[ %s ]",ntuple02,ntuple01));	
	hRatio_EffLxy->SetMinimum(ymin);	
	hRatio_EffLxy->SetMaximum(ymax);	
	hRatio_EffLxy->Draw();	
	SetHistStyle(hRatio_EffLxy,2,0);
	dashedLine(0.,1.,1.,1.,1,1);
	c1->SaveAs(Form("%s/compRatio_EffLxy_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));	
//	c1->SaveAs(Form("%s/compRatio_EffLxy_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));
	c1->Clear();

	////// 04 Cent
	c1->cd();
	h1D_EffCent_01->GetXaxis()->SetTitle("Centrality");
	h1D_EffCent_01->GetXaxis()->CenterTitle();
	h1D_EffCent_01->GetYaxis()->SetTitle("Efficiency");
	h1D_EffCent_01->GetXaxis()->SetRangeUser(0,200);
	h1D_EffCent_01->SetMinimum(0);	
	h1D_EffCent_01->SetMaximum(1);	
	SetHistStyle(h1D_EffCent_01,3,0);
	SetHistStyle(h1D_EffCent_02,4,10);
	h1D_EffCent_01->Draw("");
	h1D_EffCent_02->Draw("same");
	if (isPair){
		legUL->SetHeader(strPrompt.c_str());
		legUL->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legUL->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legUL->Draw();
	}else{
		legBM->SetHeader(strPrompt.c_str());
		legBM->AddEntry(h1D_EffPt_01,ntuple01,"lp");
		legBM->AddEntry(h1D_EffPt_02,ntuple02,"lp");
		legBM->Draw();
	}
	c1->SaveAs(Form("%s/comp_EffCent_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));
//	c1->SaveAs(Form("%s/comp_EffCent_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));	
	legUL->Clear();
	legBM->Clear();
	c1->Clear();

	hRatio_EffCent->GetXaxis()->SetTitle("Centrality");	
	hRatio_EffCent->GetXaxis()->CenterTitle();	
	hRatio_EffCent->GetXaxis()->SetRangeUser(0,200);
	hRatio_EffCent->GetYaxis()->SetTitle(Form("Ratio = [ %s ]/[ %s ]",ntuple02,ntuple01));	
	hRatio_EffCent->SetMinimum(ymin);	
	hRatio_EffCent->SetMaximum(ymax);	
	hRatio_EffCent->Draw();	
	SetHistStyle(hRatio_EffCent,2,0);
	dashedLine(0.,1.,200.,1.,1,1);
	c1->SaveAs(Form("%s/compRatio_EffCent_%s_%s.pdf",dirName,strPrompt.c_str(),strPair.c_str()));	
//	c1->SaveAs(Form("%s/compRatio_EffCent_%s_%s.png",dirName,strPrompt.c_str(),strPair.c_str()));
	c1->Clear();



	TFile* outFile = new TFile(Form("%s/compRatio_%s_%s.root",dirName,strPrompt.c_str(),strPair.c_str()), "RECREATE");
	outFile->cd();
	hRatio_EffPt->Write();
	hRatio_EffRap->Write();
	hRatio_EffLxy->Write();
	hRatio_EffCent->Write();
	outFile->Close();

	return;

}