Ejemplo n.º 1
0
// 
// GetHistFile
//
// Sets pointers to the scaler and random-subtracted asymmetry 3D histograms
// for a certain input file (full/empty and perp/para).  Results are NOT
// dead-time corrected.
//
void GetHistFile( TFile* file, Bool_t cthflag = kFALSE)
{
	Double_t pa;
	TString prompt, random, scalers;

	TH3D* hP;
	TH3D* hR;

	pa = 0.0833;

	if ( cthflag == kFALSE ) {
//		prompt = "PhiCMCut2P_v_ThetaCMCut2P_v_TChanCut2P";
//		random = "PhiCMCut2R_v_ThetaCMCut2R_v_TChanCut2R";
		prompt = "PhiCMCut1P_v_ThetaCMCut1P_v_TChanCut1P";
		random = "PhiCMCut1R_v_ThetaCMCut1R_v_TChanCut1R";
	}
	else {
		prompt = "PhiCMCut1P_v_CosThetaCMCut1P_v_TChanCut1P";
		random = "PhiCMCut1R_v_CosThetaCMCut1R_v_TChanCut1R";
	}
	scalers = "SumScalers152to503";

	hP = (TH3D*) file->Get( prompt);
	hR = (TH3D*) file->Get( random);
	hsc = (TH1D*) file->Get( scalers);

	hS = (TH3D*) hP->Clone( "sub");
	hS->Sumw2();
	hS->Add( hR, -pa);
}
Ejemplo n.º 2
0
void bToDRawYield()
{
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.04);
	gStyle->SetPadLeftMargin(0.14);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.14);
	gStyle->SetTitleX(.0f);
	gStyle->SetOptFit(1111);
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);

	TCanvas* c4 = new TCanvas("c4","",800,600);
	c4->Divide(2,2);

	TCanvas* c2 = new TCanvas("c2","",400,600);
	c2->Divide(1,2);

	TCanvas* c1 = new TCanvas();

	TCanvas* c15 = new TCanvas("c15","",810,1000);
	c15->Divide(3,5);

	TFile* fPbPb = new TFile("bFeedDownPbPb.hist.root");
	TFile* fPbPbMB = new TFile("bFeedDownPbPbMB.hist.root");
	TFile* fPbPbMC = new TFile("bFeedDownPbPbMC.hist.root");
	TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC.hist.root");

	TH3D* hDataPbPb = (TH3D*)fPbPb->Get("hData");
	TH3D* hSidebandPbPb = (TH3D*)fPbPb->Get("hSideband");
	TH3D* hDataPbPbMB = (TH3D*)fPbPbMB->Get("hData");
	TH3D* hSidebandPbPbMB = (TH3D*)fPbPbMB->Get("hSideband");
	TH3D* hPtMD0DcaPbPb = (TH3D*)fPbPb->Get("hPtMD0Dca");
	TH3D* hPtMD0DcaPbPbMB = (TH3D*)fPbPbMB->Get("hPtMD0Dca");

	TH3D* hMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCNPSignal");
	TH3D* hMCPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCNPSignal");
	TH3D* hPtMD0DcaMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSwapped");
	TH3D* hPtMD0DcaMCPSignalPbPbMB =(TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPbMB = (TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSwapped");

	TH3D* hData = (TH3D*)hDataPbPb->Clone("hData");
	hData->Sumw2();
	hData->Add(hDataPbPbMB);

	TH3D* hSideband = (TH3D*)hSidebandPbPb->Clone("hSideband");
	hSideband->Sumw2();
	hSideband->Add(hSidebandPbPbMB);

	TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPbPb->Clone("hPtMD0Dca");
	hPtMD0Dca->Sumw2();
	hPtMD0Dca->Add(hPtMD0DcaPbPbMB);

	TH3D* hMCPSignal = (TH3D*)hMCPSignalPbPb->Clone("hMCPSignal");
	hMCPSignal->Sumw2();
	hMCPSignal->Add(hMCPSignalPbPbMB);

	TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPbPb->Clone("hMCNPSignal");
	hMCNPSignal->Sumw2();
	hMCNPSignal->Add(hMCNPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPbPb->Clone("hPtMD0DcaMCPSignal");
	hPtMD0DcaMCPSignal->Sumw2();
	hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPbPb->Clone("hPtMD0DcaMCPSwapped");
	hPtMD0DcaMCPSwapped->Sumw2();
	hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPbPbMB);

	TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
	texCms->SetNDC();
	texCms->SetTextAlign(12);
	texCms->SetTextSize(0.06);
	texCms->SetTextFont(42);

	TLatex* texCol = new TLatex(0.96,0.93, "PbPb #sqrt{s_{NN}} = 5.02 TeV");
	texCol->SetNDC();
	texCol->SetTextAlign(32);
	texCol->SetTextSize(0.06);
	texCol->SetTextFont(42);

	const int nPtBins = 14;
	float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100};

	float pts[nPtBins];
	float ptErrors[nPtBins];
	float promptFraction[nPtBins];
	float totalYield[nPtBins];
	float totalYieldInvMassFit[nPtBins];
	float totalYieldInvMassFitError[nPtBins];
	float bToDYield[nPtBins];
	float bToDYieldError[nPtBins];
	float bToDYieldErrorDataOnly[nPtBins];
	float promptDYield[nPtBins];
	float promptDYieldError[nPtBins];
	float promptDYieldErrorDataOnly[nPtBins];

	const int nBinY = 14;
	Float_t binsY[nBinY+1];
	float firstBinYWidth = 0.001;
	float binYWidthRatio = 1.27;
	binsY[0]=0;
	for(int i=1; i<=nBinY; i++)
		binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1);
	cout<<"last y bin: "<<binsY[nBinY]<<endl;

	//  for(int i=1; i<=nPtBins; i++)
	for(int i =7; i<=7; i++)
	{
		pts[i-1] = 0.5*(ptBins[i-1]+ptBins[i]);
		ptErrors[i-1] = 0.5*(ptBins[i]-ptBins[i-1]);
		float ptLow = ptBins[i-1];
		float ptHigh = ptBins[i];
		cout<<endl<<"======================================="<<endl;
		cout<<"pT range: "<<ptLow<<" "<<ptHigh<<endl;

		TLatex* texPtY = new TLatex(0.32,0.82,Form("%.1f < p_{T} < %.1f GeV/c      |y| < 1.0",ptLow,ptHigh));
		texPtY->SetNDC();
		texPtY->SetTextFont(42);
		texPtY->SetTextSize(0.06);
		texPtY->SetLineWidth(2);

		TLatex* texPt = new TLatex(0.18,0.82,Form("%.1f < p_{T} < %.1f GeV/c",ptLow,ptHigh));
		texPt->SetNDC();
		texPt->SetTextFont(42);
		texPt->SetTextSize(0.06);
		texPt->SetLineWidth(2);

		TLatex* texY = new TLatex(0.18,0.74,Form("|y| < 1.0"));
		texY->SetNDC();
		texY->SetTextFont(42);
		texY->SetTextSize(0.06);
		texY->SetLineWidth(2);

		c2->cd(1);

		hPtMD0Dca->GetZaxis()->SetRange(1,100);
		hPtMD0Dca->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSwapped->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		TH1D* hMData = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_%1.1f_%1.1f", ptLow, ptHigh));
		TH1D* hMMCSignal = (TH1D*)hPtMD0DcaMCPSignal->Project3D("y");
		TH1D* hMMCSwapped = (TH1D*)hPtMD0DcaMCPSwapped->Project3D("y");

		setColorTitleLabel(hMData);
		setColorTitleLabel(hMMCSignal);
		setColorTitleLabel(hMMCSwapped);

		TF1* fMass = fitMass(hMData, hMMCSignal, hMMCSwapped);

		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		TF1* fSignalAndSwapped = new TF1("fSignalAndSwapped","[0]*([3]*([5]*Gaus(x,[1],[2]*(1+[7]))/(sqrt(2*3.1415927)*[2]*(1+[7]))+(1-[5])*Gaus(x,[1],[6]*(1+[7]))/(sqrt(2*3.1415927)*[6]*(1+[7])))+(1-[3])*Gaus(x,[1],[4]*(1+[7]))/(sqrt(2*3.1415927)*[4]*(1+[7])))", 1.7, 2.0);      
		fSignalAndSwapped->SetParameter(0,fMass->GetParameter(0));
		fSignalAndSwapped->SetParameter(1,fMass->GetParameter(1));
		fSignalAndSwapped->SetParameter(2,fMass->GetParameter(2));
		fSignalAndSwapped->SetParameter(3,fMass->GetParameter(7));
		fSignalAndSwapped->SetParameter(4,fMass->GetParameter(8));
		fSignalAndSwapped->SetParameter(5,fMass->GetParameter(9));
		fSignalAndSwapped->SetParameter(6,fMass->GetParameter(10));
		fSignalAndSwapped->SetParameter(7,fMass->GetParameter(11));

		TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x");
		background->SetParameter(0,fMass->GetParameter(3));
		background->SetParameter(1,fMass->GetParameter(4));
		background->SetParameter(2,fMass->GetParameter(5));
		background->SetParameter(3,fMass->GetParameter(6));

		cout<<"MC signal width: "<<fMass->GetParameter(2)<<"   "<<fMass->GetParameter(10)<<endl;
		cout<<"MC swapped width: "<<fMass->GetParameter(8)<<endl;

		float massD = 1.8649;
		float massSignal1 = massD-0.025;
		float massSignal2 = massD+0.025;
		float massSideBand1 = massD-0.1;
		float massSideBand2 = massD-0.075;
		float massSideBand3 = massD+0.075;
		float massSideBand4 = massD+0.1;

		float scaleSideBandBackground = background->Integral(massSignal1, massSignal2)/(background->Integral(massSideBand1, massSideBand2)+background->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandBackground: "<<scaleSideBandBackground<<endl;
		totalYieldInvMassFit[i-1] = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		totalYieldInvMassFitError[i-1] = fMass->GetParError(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		cout<<"totalYieldInvMassFit: "<<totalYieldInvMassFit[i-1]<<" +- "<<totalYieldInvMassFitError[i-1]<<endl;
		float scaleSideBandMethodSignal = fSignalAndSwapped->GetParameter(0)*fSignalAndSwapped->GetParameter(3) / (fSignalAndSwapped->Integral(massSignal1, massSignal2)-fSignalAndSwapped->Integral(massSideBand1, massSideBand2)-fSignalAndSwapped->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandMethodSignal: "<<scaleSideBandMethodSignal<<endl;

		TLatex* texScale = new TLatex(0.18,0.66,Form("side band bg scale: %1.3f", scaleSideBandBackground));
		texScale->SetNDC();
		texScale->SetTextFont(42);
		texScale->SetTextSize(0.06);
		texScale->SetLineWidth(2);
		texScale->Draw();

		TLine* lineSignal1 = new TLine(massSignal1, 0, massSignal1, hMData->GetMaximum()*0.5);
		TLine* lineSignal2 = new TLine(massSignal2, 0, massSignal2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand1 = new TLine(massSideBand1, 0, massSideBand1, hMData->GetMaximum()*0.5);
		TLine* lineSideBand2 = new TLine(massSideBand2, 0, massSideBand2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand3 = new TLine(massSideBand3, 0, massSideBand3, hMData->GetMaximum()*0.5);
		TLine* lineSideBand4 = new TLine(massSideBand4, 0, massSideBand4, hMData->GetMaximum()*0.5);
		lineSignal1->Draw();
		lineSignal2->Draw();
		lineSideBand1->Draw();
		lineSideBand2->Draw();
		lineSideBand3->Draw();
		lineSideBand4->Draw();

		c2->cd(2);
		gPad->SetLogy();

		hData->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hSideband->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCNPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);

		TH1D* hD0DcaData0 = (TH1D*)hData->Project3D("y")->Clone("hD0DcaData0");
		TH1D* hD0DcaSideband = (TH1D*)hSideband->Project3D("y")->Clone("hD0DcaSideband");
		TH1D* hD0DcaMCPSignal0 = (TH1D*)hMCPSignal->Project3D("y")->Clone("hD0DcaMCPSignal0");
		TH1D* hD0DcaMCNPSignal0 = (TH1D*)hMCNPSignal->Project3D("y")->Clone("hD0DcaMCNPSignal0");

		float integralRawYieldMCP = hD0DcaMCPSignal0->Integral();
		float integralRawYieldMCNP = hD0DcaMCNPSignal0->Integral();
		cout<<"integralRawYieldMCP: "<<integralRawYieldMCP<<endl;
		cout<<"integralRawYieldMCNP: "<<integralRawYieldMCNP<<endl;

		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;

		divideBinWidth(hD0DcaData0);
		divideBinWidth(hD0DcaSideband);
		setColorTitleLabel(hD0DcaData0, 1);
		hD0DcaData0->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData0->GetYaxis()->SetTitle("counts per cm");

		TH1D* hD0DcaSideband0 = (TH1D*)hD0DcaSideband->Clone("hD0DcaSideband0");
		hD0DcaSideband->Scale(scaleSideBandBackground);

		TH1D* hD0DcaDataSubSideBand = (TH1D*)hD0DcaData0->Clone("hD0DcaDataSubSideBand");
		hD0DcaDataSubSideBand->Add(hD0DcaSideband,-1);
		hD0DcaDataSubSideBand->Scale(scaleSideBandMethodSignal);

		hD0DcaData0->SetMarkerSize(0.6);
		hD0DcaData0->Draw();
		hD0DcaSideband->Draw("hsame");
		hD0DcaSideband0->SetLineStyle(2);
		hD0DcaSideband0->Draw("hsame");

		TLegend* leg1 = new TLegend(0.44,0.6,0.90,0.76,NULL,"brNDC");
		leg1->SetBorderSize(0);
		leg1->SetTextSize(0.06);
		leg1->SetTextFont(42);
		leg1->SetFillStyle(0);
		leg1->AddEntry(hD0DcaData0,"D^{0} candidate","pl");
		leg1->AddEntry(hD0DcaSideband,"side band","l");
		leg1->AddEntry(hD0DcaSideband0,"side band unscaled","l");
		leg1->Draw("same");

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_sideBand.pdf",ptLow,ptHigh));

		c2->cd(1);
		hMMCSignal->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->cd(2);
		gPad->SetLogy(0);
		hMMCSwapped->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_McInvMassFit.pdf",ptLow,ptHigh));

		c15->cd(1);

		fitMass(hMData, hMMCSignal, hMMCSwapped);

		texPt->Draw();
		texY->Draw();

		TH1D* hD0DcaDataFit = new TH1D("hD0DcaDataFit", ";D^{0} DCA (cm);dN / d(D^{0} DCA) (cm^{-1})", nBinY, binsY);

		for(int j=1; j<=14; j++)
		{
			c15->cd(j+1);
			hPtMD0Dca->GetZaxis()->SetRange(j,j);
			float D0DcaLow = hPtMD0Dca->GetZaxis()->GetBinLowEdge(j);
			float D0DcaHigh = hPtMD0Dca->GetZaxis()->GetBinUpEdge(j);
			TH1D* hMData_D0Dca = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_pt_%1.1f_%1.1f_D0Dca_%1.4f_%1.4f", ptLow, ptHigh, D0DcaLow, D0DcaHigh));
			setColorTitleLabel(hMData_D0Dca);
			fMass = fitMass(hMData_D0Dca, hMMCSignal, hMMCSwapped);

			float yield = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);
			float yieldError = fMass->GetParError(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);

			hD0DcaDataFit->SetBinContent(j, yield);
			hD0DcaDataFit->SetBinError(j, yieldError);

			TLatex* texD0Dca = new TLatex(0.18,0.82,Form("D^{0} DCA: %1.4f - %1.4f",D0DcaLow,D0DcaHigh));
			texD0Dca->SetNDC();
			texD0Dca->SetTextFont(42);
			texD0Dca->SetTextSize(0.06);
			texD0Dca->SetLineWidth(2);
			texD0Dca->Draw();

			TLatex* texYield = new TLatex(0.18,0.74,Form("D^{0} yield: %1.0f #pm %1.0f",yield,yieldError));
			texYield->SetNDC();
			texYield->SetTextFont(42);
			texYield->SetTextSize(0.06);
			texYield->SetLineWidth(2);
			texYield->Draw();
		}

		c15->SaveAs(Form("plots/PbPb_%.0f_%.0f_invMassFit.pdf",ptLow,ptHigh));

		divideBinWidth(hD0DcaDataFit);

		c4->cd(1);
		gPad->SetLogy();

		normalize(hD0DcaMCPSignal);
		setColorTitleLabel(hD0DcaMCPSignal, 2);
		hD0DcaMCPSignal->GetXaxis()->SetRangeUser(0,0.07);

		normalize(hD0DcaMCNPSignal);
		setColorTitleLabel(hD0DcaMCNPSignal, 4);
		hD0DcaMCNPSignal->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaMCNPSignal->GetYaxis()->SetTitle("dN / d(D^{0} DCA) (cm^{-1})");
		hD0DcaMCNPSignal->GetXaxis()->SetTitle("D^{0} DCA (cm)");
		hD0DcaMCNPSignal->SetMaximum(hD0DcaMCPSignal->GetMaximum()*3.);

		hD0DcaMCNPSignal->Draw("");
		hD0DcaMCPSignal->Draw("same");

		TLegend* leg2 = new TLegend(0.54,0.72,0.90,0.88,NULL,"brNDC");
		leg2->SetBorderSize(0);
		leg2->SetTextSize(0.06);
		leg2->SetTextFont(42);
		leg2->SetFillStyle(0);
		leg2->AddEntry(hD0DcaMCPSignal,"MC Prompt D^{0}","pl");
		leg2->AddEntry(hD0DcaMCNPSignal,"MC Non-prompt D^{0}","pl");
		leg2->Draw("same");

		c4->cd(2);
		gPad->SetLogy();

		TH1D* hD0DcaData = hD0DcaDataFit;
		if(pts[i-1]>20) hD0DcaData = hD0DcaDataSubSideBand;

		setColorTitleLabel(hD0DcaData, 1);

		double integralTotalYield = hD0DcaData->Integral(1,hD0DcaData->GetXaxis()->GetNbins(),"width");
		cout<<"integralTotalYield: "<<integralTotalYield<<endl;

		TF1* fMix = new TF1("fMix",&funMix, 0., 0.5, 2);
		fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
		fMix->SetParLimits(0,0,2*integralTotalYield);
		fMix->SetParLimits(1,0,2*integralTotalYield);

		fMix->SetLineColor(2);
		fMix->SetFillColor(kRed-9);
		fMix->SetFillStyle(1001);

		float fitRangeL = 0;
		float fitRangeH = 0.08;

		hD0DcaData->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData->Draw();
		int fitStatus = 1;
		TFitResultPtr fitResult;
		double fitPrecision = 1.e-6;
		while(fitStatus)
		{
			TFitter::SetPrecision(fitPrecision);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);
			fitResult = hD0DcaData->Fit("fMix","E SNQ0", "", fitRangeL, fitRangeH);
			fitStatus = fitResult->Status();
			cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;
			if(fitStatus)
				fitPrecision *= 10;
		}
		cout<<"============== do main fit ============"<<endl;
		fMix->SetParameters(integralTotalYield,0.9);
		fMix->SetParError(0,0.1*integralTotalYield);
		fMix->SetParError(1,0.1);
		fMix->SetNpx(10000);
		fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH);
		hD0DcaData->GetFunction("fMix")->Draw("flsame");
		fitStatus = fitResult->Status();
		cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;

		TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2);
		fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1));
		fNP->SetRange(fitRangeL,fitRangeH);
		fNP->SetLineColor(4);
		fNP->SetFillStyle(1001);
		fNP->SetFillColor(kBlue-9);
		fNP->SetNpx(10000);
		fNP->Draw("same");  

		hD0DcaData->Draw("same");

		promptDYield[i-1] = fMix->GetParameter(0);
		promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0);
		bToDYield[i-1] = fMix->GetParameter(1);
		bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1);
		totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1];
		promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1];

		cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl;

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0)));
		texPrompt->SetNDC();
		texPrompt->SetTextFont(42);
		texPrompt->SetTextSize(0.06);
		texPrompt->SetLineWidth(2);
		texPrompt->Draw();

		TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1)));
		texNonPrompt->SetNDC();
		texNonPrompt->SetTextFont(42);
		texNonPrompt->SetTextSize(0.06);
		texNonPrompt->SetLineWidth(2);
		texNonPrompt->Draw();

		TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62);
		leg4->SetBorderSize(0);
		leg4->SetTextSize(0.06);
		leg4->SetTextFont(42);
		leg4->SetFillStyle(0);
		leg4->AddEntry(hD0DcaData,"Data","pl");
		leg4->AddEntry(fMix,"Prompt D^{0}","f");
		leg4->AddEntry(fNP,"B to D^{0}","f");
		leg4->Draw("same");

		//smear MC smaple with the error, to simulate the MC statistic error effect.
		c4->cd(3);

		hD0DcaMCPSignal = (TH1D*)hD0DcaMCPSignal0->Clone("hMCPSignal");
		hD0DcaMCNPSignal = (TH1D*)hD0DcaMCNPSignal0->Clone("hMCNPSignal");

		TH1D* hNPYield = new TH1D("hNPYield", ";hNPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		TH1D* hPYield = new TH1D("hPYield", ";hPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		setColorTitleLabel(hNPYield, 1);
		setColorTitleLabel(hPYield, 1);

		int nSmear = 1000;

		for(int j=0; j<nSmear; j++)
		{
			RandomSmear(hD0DcaMCPSignal0, hD0DcaMCPSignal);
			RandomSmear(hD0DcaMCNPSignal0, hD0DcaMCNPSignal);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);

			hD0DcaData->Fit("fMix","E QN0");

			hPYield->Fill(fMix->GetParameter(0));
			hNPYield->Fill(fMix->GetParameter(1));
		}

		hPYield->GetXaxis()->SetTitle("prompt D^{0} yield");
		hPYield->GetYaxis()->SetTitle("counts");
		hPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hPYield->GetMaximum());
		hPYield->SetMarkerStyle(20);
		hPYield->SetStats(0);
		hPYield->Draw("e");
		hPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hPYield->GetFunction("gaus")->GetParameter(1),hPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaP->SetNDC();
		texGaussMeanSigmaP->SetTextFont(42);
		texGaussMeanSigmaP->SetTextSize(0.06);
		texGaussMeanSigmaP->SetLineWidth(2);
		texGaussMeanSigmaP->Draw();

		float promptYieldErrorMc = hPYield->GetFunction("gaus")->GetParameter(2);
		promptDYieldError[i-1] = sqrt(pow(promptDYieldErrorDataOnly[i-1],2)+pow(promptYieldErrorMc,2));

		c4->cd(4);

		hNPYield->GetXaxis()->SetTitle("B to D^{0} yield");
		hNPYield->GetYaxis()->SetTitle("counts");
		hNPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hNPYield->GetMaximum());
		hNPYield->SetMarkerStyle(20);
		hNPYield->SetStats(0);
		hNPYield->Draw("e");
		hNPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaNP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hNPYield->GetFunction("gaus")->GetParameter(1),hNPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaNP->SetNDC();
		texGaussMeanSigmaNP->SetTextFont(42);
		texGaussMeanSigmaNP->SetTextSize(0.06);
		texGaussMeanSigmaNP->SetLineWidth(2);
		texGaussMeanSigmaNP->Draw();

		float bToDYieldErrorMc = hNPYield->GetFunction("gaus")->GetParameter(2);
		bToDYieldError[i-1] = sqrt(pow(bToDYieldErrorDataOnly[i-1],2)+pow(bToDYieldErrorMc,2));

		cout<<"prompt D yield: "<<promptDYield[i-1]<<" +- "<<promptDYieldError[i-1]<<" (+- "<<promptDYieldErrorDataOnly[i-1]<<" +- "<<promptYieldErrorMc<<" )"<<endl;
		cout<<"B to D yield: "<<bToDYield[i-1]<<" +- "<<bToDYieldError[i-1]<<" (+- "<<bToDYieldErrorDataOnly[i-1]<<" +- "<<bToDYieldErrorMc<<" )"<<endl;
		cout<<"total yield: "<<totalYield[i-1]<<endl;
		cout<<"prompt fraction: "<<promptFraction[i-1]<<endl;

		float promptMCScale = promptDYield[i-1]/integralRawYieldMCP;
		float nonPromptMCScale = bToDYield[i-1]/integralRawYieldMCNP;

		cout<<"promptMCScale: "<<promptMCScale<<endl;
		cout<<"nonPromptMCScale: "<<nonPromptMCScale<<endl;

		//restore original unsmeared histograms before saving plots
		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;
		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;
		hD0DcaData->Fit("fMix","E QN0");

		c4->SaveAs(Form("plots/PbPb_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		c1->cd();

		TH1D* hD0DcaDataOverFit = (TH1D*)hD0DcaData->Clone("hD0DcaDataOverFit");
		hD0DcaDataOverFit->Divide(fMix);
		hD0DcaDataOverFit->GetYaxis()->SetTitle("data / fit");
		hD0DcaDataOverFit->GetYaxis()->SetRangeUser(0,5);
		hD0DcaDataOverFit->GetXaxis()->SetRangeUser(0,0.07);
		setColorTitleLabel(hD0DcaDataOverFit, 1);
		hD0DcaDataOverFit->Draw("e");

		TF1* fLine1 = new TF1("fLine1", "1", 0,1);
		fLine1->Draw("same");
		hD0DcaDataOverFit->Draw("esame");

		c1->SaveAs(Form("plots/dataOverFit_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;

	} // end for i ptbins
	c1->cd();

	TH1D* hStupidJie = new TH1D("hStupidJie", "", 100, 0, 100);
	hStupidJie->GetYaxis()->SetRangeUser(0,1);
	hStupidJie->GetXaxis()->SetTitle("p_{T} (GeV/c)");
	hStupidJie->GetYaxis()->SetTitle("prompt fraction");
	hStupidJie->SetStats(0);
	hStupidJie->Draw();
	TGraph* grFraction = new TGraph(nPtBins, pts, promptFraction);
	grFraction->SetName("grPromptFraction");
	grFraction->SetMarkerStyle(20);
	grFraction->Draw("psame");

	c1->SaveAs("promptFraction.pdf");

	c1->SetLogy();

	TH1D* hBtoDRawYield = new TH1D("hBtoDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(bToDYield[i-1] <= 0) continue;
		hBtoDRawYield->SetBinContent(i, bToDYield[i-1]);
		hBtoDRawYield->SetBinError(i, bToDYieldError[i-1]);
	}
	divideBinWidth(hBtoDRawYield);
	setColorTitleLabel(hBtoDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hBtoDRawYield->Draw("p");
	c1->SaveAs("BtoD.pdf");

	TH1D* hPromptDRawYield = new TH1D("hPromptDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(promptDYield[i-1] <= 0) continue;
		hPromptDRawYield->SetBinContent(i, promptDYield[i-1]);
		hPromptDRawYield->SetBinError(i, promptDYieldError[i-1]);
	}
	divideBinWidth(hPromptDRawYield);
	setColorTitleLabel(hPromptDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hPromptDRawYield->Draw("p");
	c1->SaveAs("promptD.pdf");

	TH1D* hTotalDYieldInvMassFit = new TH1D("hTotalDYieldInvMassFit", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(totalYieldInvMassFit[i-1] <= 0) continue;
		hTotalDYieldInvMassFit->SetBinContent(i, totalYieldInvMassFit[i-1]);
		hTotalDYieldInvMassFit->SetBinError(i, totalYieldInvMassFitError[i-1]);
	}
	divideBinWidth(hTotalDYieldInvMassFit);
	setColorTitleLabel(hTotalDYieldInvMassFit, 1);
	hTotalDYieldInvMassFit->Draw("p");
	c1->SaveAs("totalDInvMassFit.pdf");

	TFile* fOut = new TFile("bFeedDownResult.root", "recreate");
	fOut->WriteTObject(grFraction);
	fOut->WriteTObject(hBtoDRawYield);
	fOut->WriteTObject(hPromptDRawYield);
	fOut->WriteTObject(hTotalDYieldInvMassFit);
	fOut->Write();
	fOut->Close();
}
Ejemplo n.º 3
0
void function_fit(){

	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.04);
	gStyle->SetPadLeftMargin(0.14);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.14);
	gStyle->SetTitleX(.0f);
	gStyle->SetOptFit(1111);
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);

	TFile* fPbPb = new TFile("bFeedDownPbPb.hist.root");
	TFile* fPbPbMB = new TFile("bFeedDownPbPbMB.hist.root");
//	TFile* fPbPbMC = new TFile("bFeedDownPbPbMC_funfit.hist.root");
//	TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC_funfit.hist.root");

	  TFile* fPbPbMC = new TFile("bFeedDownPbPbMC.hist.root");
	  TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC.hist.root");

	TH3D* hDataPbPb = (TH3D*)fPbPb->Get("hData");
	TH3D* hSidebandPbPb = (TH3D*)fPbPb->Get("hSideband");
	TH3D* hDataPbPbMB = (TH3D*)fPbPbMB->Get("hData");
	TH3D* hSidebandPbPbMB = (TH3D*)fPbPbMB->Get("hSideband");
	TH3D* hPtMD0DcaPbPb = (TH3D*)fPbPb->Get("hPtMD0Dca");
	TH3D* hPtMD0DcaPbPbMB = (TH3D*)fPbPbMB->Get("hPtMD0Dca");

	TH3D* hMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCNPSignal");
	TH3D* hMCPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCNPSignal");
	TH3D* hPtMD0DcaMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSwapped");
	TH3D* hPtMD0DcaMCPSignalPbPbMB =(TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPbMB = (TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSwapped");

	TH3D* hData = (TH3D*)hDataPbPb->Clone("hData");
	hData->Sumw2();
	hData->Add(hDataPbPbMB);

	TH3D* hSideband = (TH3D*)hSidebandPbPb->Clone("hSideband");
	hSideband->Sumw2();
	hSideband->Add(hSidebandPbPbMB);

	TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPbPb->Clone("hPtMD0Dca");
	hPtMD0Dca->Sumw2();
	hPtMD0Dca->Add(hPtMD0DcaPbPbMB);

	TH3D* hMCPSignal = (TH3D*)hMCPSignalPbPb->Clone("hMCPSignal");
	hMCPSignal->Sumw2();
	hMCPSignal->Add(hMCPSignalPbPbMB);

	TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPbPb->Clone("hMCNPSignal");
	hMCNPSignal->Sumw2();
	hMCNPSignal->Add(hMCNPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPbPb->Clone("hPtMD0DcaMCPSignal");
	hPtMD0DcaMCPSignal->Sumw2();
	hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPbPb->Clone("hPtMD0DcaMCPSwapped");
	hPtMD0DcaMCPSwapped->Sumw2();
	hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPbPbMB);


//	TH1D *h_DcaData = (TH1D*)fDcaData->Get("D0DcaDatafitOut_pt5");

//	const int nPtBins = 14;
//	float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100};

  const int nPtBins = 9;
  float ptBins[nPtBins+1] = {2.,4.,6.,8.,10.,12.5,20.,40.,60.,100};

  const int nBinY = 20;
  const Double_t binsY[nBinY+1] = {-0.0734,-0.0562,-0.0428,-0.0320,-0.0236,-0.0170,-0.0118,-0.0078,-0.0046,-0.002,0.0,0.002,0.0046,0.0078,0.0118,0.0170,0.0236,0.0320,0.0428,0.0562,0.0734};

  TFile *fDcaData = new TFile("bFeedDownResult.root");
  TH1D *h_DcaData[nPtBins];
//  TH1D *h_DcaData = (TH1D*)fDcaData->Get("D0DcaDatafitOut_pt5");


	RooBinning bin_dcaxy(nBinY,binsY);

	//	TH1D* h_MCP_DCAxy = new TH1D("h_MCP_DCAxy", "h_MCP_DCAxy", nBinY, binsY);
	//  TH1D* h_MCNP_DCAxy = new TH1D("h_MCNP_DCAxy", "h_MCNP_DCAxy", nBinY, binsY);

	TFile *fout= new TFile("function_fit_result.root","RECREATE");
	TH1D *h_PromptYield_fix = new TH1D("h_PromptYield_fix","h_PromptYield_fix",nPtBins,ptBins);
  TH1D *h_NonPromptYield_fix = new TH1D("h_NonPromptYield_fix","h_NonPromptYield_fix",nPtBins,ptBins);
	TH1D *h_NonPromptFraction_fix= new TH1D("h_NonPromptFraction_fix","h_NonPromptFraction_fix",nPtBins,ptBins);

  TH1D *h_PromptYield_float = new TH1D("h_PromptYield_float","h_PromptYield_float",nPtBins,ptBins);
  TH1D *h_NonPromptYield_float = new TH1D("h_NonPromptYield_float","h_NonPromptYield_float",nPtBins,ptBins);
  TH1D *h_NonPromptFraction_float= new TH1D("h_NonPromptFraction_float","h_NonPromptFraction_float",nPtBins,ptBins);

	


	hMCPSignal->GetXaxis()->SetRangeUser(8,10);
	hMCNPSignal->GetXaxis()->SetRangeUser(8,10);

	TH1D* h_MCP_DCAxy= (TH1D*)hMCPSignal->Project3D("y")->Clone("h_MCP_DCAxy");
	TH1D* h_MCNP_DCAxy= (TH1D*)hMCNPSignal->Project3D("y")->Clone("h_MCNP_DCAxy");


	TH1D* h_MCP_DCAxy_ptArr[nPtBins];
	TH1D* h_MCNP_DCAxy_ptArr[nPtBins];

	TCanvas *c_MCP_ptArr[nPtBins];
	TCanvas *c_MCNP_ptArr[nPtBins];

	double max,min;
	double MCPsigmaVal;

	TCanvas *c_MCP_gauss = new TCanvas("c_MCP_gauss","c_MCP_gauss",1000,600);
	c_MCP_gauss->Divide(5,3);

	TCanvas *c_MCP_gauss2 = new TCanvas("c_MCP_gauss2","c_MCP_gauss2",1000,600);
	c_MCP_gauss2->Divide(5,3);

	TCanvas *c_MCNP_gauss = new TCanvas("c_MCNP_gauss","c_MCNP_gauss",1000,600);
	c_MCNP_gauss->Divide(5,3);

	TCanvas *c_data[nPtBins];// = new TCanvas("c_data","c_data",600,600);


		for(int iPtBins=0; iPtBins<nPtBins; iPtBins++)
//	for(int iPtBins=1; iPtBins<2; iPtBins++)
	{
		// Fill the TH1D

		Float_t ptLow=ptBins[iPtBins];
		Float_t ptHigh=ptBins[iPtBins+1];

		hMCPSignal->GetXaxis()->SetRangeUser(ptLow,ptHigh);
		hMCNPSignal->GetXaxis()->SetRangeUser(ptLow,ptHigh);

		h_MCP_DCAxy_ptArr[iPtBins]= (TH1D*)hMCPSignal->Project3D("y")->Clone(Form("h_MCP_DCAxy_Dpt%.1fto%.1f",ptLow,ptHigh));
		h_MCNP_DCAxy_ptArr[iPtBins]= (TH1D*)hMCNPSignal->Project3D("y")->Clone(Form("h_MCNP_DCAxy_Dpt%.1fto%.1f",ptLow,ptHigh));


		// MCP fit and plot

		c_MCP_ptArr[iPtBins] = new TCanvas(Form("c_MCP_%i",iPtBins),Form("c_MCP_%i",iPtBins), 800,400 ); 	
		c_MCP_ptArr[iPtBins]->Divide(2,1);
		c_MCP_ptArr[iPtBins]->cd(1);		


		RooRealVar x("x","Dca_xy",-0.07,0.07);
		//  RooRealVar mean("mean","mean",0,-0.02,0.02);
		RooRealVar mean("mean","mean",0);

		RooRealVar sigma("sigma","sigma",0.003,0.0000001,0.02);
		RooGaussian MCP_pdf("gauss","gaussian PDF",x,mean,sigma);
		RooPlot* MCP_frame = x.frame();

		RooDataHist h_MCP("h_MCP","h_MCP",RooArgList(x),h_MCP_DCAxy_ptArr[iPtBins]);

		MCP_pdf.fitTo(h_MCP);
		MCPsigmaVal=sigma.getVal();

		h_MCP.plotOn(MCP_frame,Binning(bin_dcaxy));


		MCP_pdf.plotOn(MCP_frame,LineColor(2));
		MCP_pdf.paramOn(MCP_frame);
		//	MCP_frame->SetTitle("test Title");
		max = MCP_frame->GetMaximum();
		min = MCP_frame->GetMinimum();
		MCP_frame->SetMaximum(max+0.2*(max-min));
		MCP_frame->Draw();

		TLatex *tex_MCP= new TLatex(0.18,0.82,Form("Prompt D"));
		tex_MCP->SetNDC();
		tex_MCP->SetTextFont(42);
		tex_MCP->SetTextSize(0.035);
		tex_MCP->SetLineWidth(2);
		tex_MCP->Draw();
		TLatex *tex_MCPGauss= new TLatex(0.18,0.75,"Gaussian Fit");
		tex_MCPGauss->SetNDC();
		tex_MCPGauss->SetTextFont(42);
		tex_MCPGauss->SetTextSize(0.035);
		tex_MCPGauss->SetLineWidth(2);
		tex_MCPGauss->Draw();


		c_MCP_gauss->cd(iPtBins+1);
		MCP_frame->Draw();
		if(iPtBins==0){
			TLatex *tex_MCP_Gauss = new TLatex(0.18,0.75,Form("Prompt D, Gauss"));
			tex_MCP_Gauss->SetNDC();
			tex_MCP_Gauss->SetTextFont(42);
			tex_MCP_Gauss->SetTextSize(0.035);
			tex_MCP_Gauss->SetLineWidth(2);
			tex_MCP_Gauss->Draw();
		}
		TLatex *tex_MCP_Gausspt = new TLatex(0.18,0.82,Form("%.1f<pt<%.1f",ptLow,ptHigh));
		tex_MCP_Gausspt->SetNDC();
		tex_MCP_Gausspt->SetTextFont(42);
		tex_MCP_Gausspt->SetTextSize(0.035);
		tex_MCP_Gausspt->SetLineWidth(2);
		tex_MCP_Gausspt->Draw();



/*
		c_MCP_ptArr[iPtBins]->cd(2);

		RooRealVar ARatio("ARatio","ARatio",0.5,0,1);
		RooRealVar sigmaRatio("sigmaRatio","sigmaRatio",1.24,1.000001,100000);
		RooGenericPdf dgauss("dgauss","Double Gaussian","ARatio*exp(-pow((x-mean)/sigma,2)/2)+(1-ARatio)*exp(-pow((x-mean)/(sigma*sigmaRatio),2)/2)",RooArgSet(x,mean,sigma,ARatio,sigmaRatio));

		dgauss.fitTo(h_MCP);
		RooPlot* MCP_frame2 = x.frame();
		h_MCP.plotOn(MCP_frame2);
		dgauss.plotOn(MCP_frame2);
		dgauss.paramOn(MCP_frame2);
		max = MCP_frame2->GetMaximum();
		min = MCP_frame2->GetMinimum();
		MCP_frame2->SetMaximum(max+0.2*(max-min));

		MCP_frame2->Draw();

		TLatex *tex_MCPpt= new TLatex(0.18,0.82,Form("%.1f<D P_{T}<%.1f",ptLow,ptHigh));
		tex_MCPpt->SetNDC();
		tex_MCPpt->SetTextFont(42);
		tex_MCPpt->SetTextSize(0.035);
		tex_MCPpt->SetLineWidth(2);
		tex_MCPpt->Draw();
		TLatex *tex_MCPGauss2= new TLatex(0.18,0.75,"Double Gaussian Fit");
		tex_MCPGauss2->SetNDC();
		tex_MCPGauss2->SetTextFont(42);
		tex_MCPGauss2->SetTextSize(0.035);
		tex_MCPGauss2->SetLineWidth(2);
		tex_MCPGauss2->Draw();

		c_MCP_ptArr[iPtBins]->SaveAs(Form("plots_functionfit/MCP_FunCom_pt%dto%d.pdf",(int)ptLow,(int)ptHigh));

		c_MCP_gauss2->cd(iPtBins+1);
		MCP_frame2->Draw();
		if(iPtBins==0){
			TLatex *tex_MCP_Gauss2 = new TLatex(0.18,0.75,Form("Prompt D,Double Gauss"));
			tex_MCP_Gauss2->SetNDC();
			tex_MCP_Gauss2->SetTextFont(42);
			tex_MCP_Gauss2->SetTextSize(0.035);
			tex_MCP_Gauss2->SetLineWidth(2);
			tex_MCP_Gauss2->Draw();
		}
		TLatex *tex_MCP_Gauss2pt = new TLatex(0.18,0.82,Form("%.1f<pt<%.1f",ptLow,ptHigh));
		tex_MCP_Gauss2pt->SetNDC();
		tex_MCP_Gauss2pt->SetTextFont(42);
		tex_MCP_Gauss2pt->SetTextSize(0.035);
		tex_MCP_Gauss2pt->SetLineWidth(2);
		tex_MCP_Gauss2pt->Draw();
*/


		/////////////////////
		// MCNP fit and plot 
		/////////////////////

		c_MCNP_ptArr[iPtBins] = new TCanvas(Form("c_MCNP_%i",iPtBins),Form("c_MCNP_%i",iPtBins), 800,800 ); 
		c_MCNP_ptArr[iPtBins]->Divide(2,2);
		c_MCNP_ptArr[iPtBins]->cd(1);


    gPad->SetLogy();

		//  RooRealVar dca("dca","dca_xy",-0.05,0.05);
		RooRealVar alpha("alpha","alpha",-100,-20000,-0.00001);
		RooGenericPdf gp("gp","Generic PDF","exp(abs(x)*alpha)",RooArgSet(x,alpha));

		RooRealVar mg("mg","mg",0);
		RooRealVar sg("sg","sg",MCPsigmaVal,0.0000001,0.1);
		RooGaussian gauss2("gauss2","gauss2",x,mg,sg);
		x.setBins(10000,"cache");
		//  RooFFTConvPdf gpxg("gpxg","exp (x) gauss",x,gp,gauss2);
		RooFFTConvPdf *MCNP_pdf = new RooFFTConvPdf("MCNP_pdf","exp (x) gauss",x,gp,gauss2);

//		sg.setConstant(kTRUE);

		RooPlot * MCNP_frame = x.frame();
		//  RooDataHist h_MCNP("h_MCNP","h_MCNP",RooArgSet(dca),h_MCNP_DCAxy);
		RooDataHist h_MCNP("h_MCNP","h_MCNP",RooArgSet(x),h_MCNP_DCAxy_ptArr[iPtBins]);
		RooFitResult * fitres = MCNP_pdf->fitTo(h_MCNP);
		h_MCNP.plotOn(MCNP_frame,Binning(bin_dcaxy));
		MCNP_pdf->plotOn(MCNP_frame);
		MCNP_pdf->paramOn(MCNP_frame);
		//  MCNP_frame2->GetXaxis()->SetTitle("set x title");
		max = MCNP_frame->GetMaximum();
		min = MCNP_frame->GetMinimum();
//		MCNP_frame->SetMaximum(max+0.2*(max-min));
		MCNP_frame->SetMaximum(max*10);
		MCNP_frame->SetMinimum(0.5);
		MCNP_frame->Draw();
		cout<<"sg = "<<sg.getVal();

		TLatex *tex_MCNP= new TLatex(0.18,0.82,Form("Non Prompt D"));
		tex_MCNP->SetNDC();
		tex_MCNP->SetTextFont(42);
		tex_MCNP->SetTextSize(0.035);
		tex_MCNP->SetLineWidth(2);
		tex_MCNP->Draw();
		TLatex *tex_MCNPGauss= new TLatex(0.18,0.75,"Exp (x) Gaussian");
		tex_MCNPGauss->SetNDC();
		tex_MCNPGauss->SetTextFont(42);
		tex_MCNPGauss->SetTextSize(0.035);
		tex_MCNPGauss->SetLineWidth(2);
		tex_MCNPGauss->Draw();

    TLatex *tex_MCNP_Gausspt = new TLatex(0.18,0.68,Form("%.1f<pt<%.1f",ptLow,ptHigh));
    tex_MCNP_Gausspt->SetNDC();
    tex_MCNP_Gausspt->SetTextFont(42);
    tex_MCNP_Gausspt->SetTextSize(0.035);
    tex_MCNP_Gausspt->SetLineWidth(2);
    tex_MCNP_Gausspt->Draw();



		// test other function
		c_MCNP_ptArr[iPtBins]->cd(2);
    gPad->SetLogy();
	
		RooRealVar power_a("power_a","power_a",10,0.000001,100000);
		RooRealVar power_n("power_n","power_n",3,0.001,100000);	
		RooGenericPdf power_pdf("power_pdf","power_odf","1/pow((1+power_a*abs(x)),power_n)",RooArgSet(x,power_a,power_n)); 
	
		RooPlot * MCNP_frame2 = x.frame();
		power_pdf.fitTo(h_MCNP);
		h_MCNP.plotOn(MCNP_frame2,Binning(bin_dcaxy));
		power_pdf.plotOn(MCNP_frame2);
		power_pdf.paramOn(MCNP_frame2);
		MCNP_frame2->SetMaximum(max*10);	
		MCNP_frame2->SetMinimum(0.5);
		MCNP_frame2->Draw();

    TLatex *tex_MCNPpower= new TLatex(0.18,0.75,"1/(1+a*x)^{n}");
    tex_MCNPpower->SetNDC();
    tex_MCNPpower->SetTextFont(42);
    tex_MCNPpower->SetTextSize(0.035);
    tex_MCNPpower->SetLineWidth(2);
    tex_MCNPpower->Draw();

	

		c_MCNP_ptArr[iPtBins]->cd(3);
		    gPad->SetLogy();
		RooRealVar twoExpA("twoExpA","twoExpA",-100,-100000,-10);
		RooRealVar twoExpB("twoExpB","twoExpB",-10,-300,-0.01);
		RooRealVar twoExpAfrac("twoExpAfrac","twoExpAfrac",0.5,0.0,1.0);
		RooGenericPdf twoExp_pdf("twoExp_pdf","twoExp_pdf","twoExpAfrac*exp(twoExpA*abs(x))+(1-twoExpAfrac)*exp(twoExpB*abs(x))",RooArgSet(x,twoExpA,twoExpB,twoExpAfrac));

		RooPlot *MCNP_frame3 = x.frame();
		twoExp_pdf.fitTo(h_MCNP);
		h_MCNP.plotOn(MCNP_frame3,Binning(bin_dcaxy));
		twoExp_pdf.plotOn(MCNP_frame3);
		twoExp_pdf.paramOn(MCNP_frame3);
		MCNP_frame3->SetMaximum(max*10);
		MCNP_frame3->SetMinimum(0.5);
		MCNP_frame3->Draw();

    TLatex *tex_MCNPtwoExp= new TLatex(0.18,0.75,"A*exp1+(1-A)exp2 ");
    tex_MCNPtwoExp->SetNDC();
    tex_MCNPtwoExp->SetTextFont(42);
    tex_MCNPtwoExp->SetTextSize(0.035);
    tex_MCNPtwoExp->SetLineWidth(2);
    tex_MCNPtwoExp->Draw();


/*
		c_MCNP_ptArr[iPtBins]->cd(4);
		gPad->SetLogy();

		RooRealVar doubleExpA("doubleExpA","doubleExpA",-100,-10000,-0.00001);
		RooRealVar doubleExpB("doubleExpB","doubleExpB",-1,-5000,-0.000001);
		RooGenericPdf doubleExp_pdf("doubleExp_pdf","doubleExp_pdf","exp(doubleExpA*exp(doubleExpB*abs(x)))",RooArgSet(x,doubleExpA,doubleExpB));

    RooPlot *MCNP_frame4 = x.frame();
    doubleExp_pdf.fitTo(h_MCNP);
    h_MCNP.plotOn(MCNP_frame4,Binning(bin_dcaxy));
    doubleExp_pdf.plotOn(MCNP_frame4);
    doubleExp_pdf.paramOn(MCNP_frame4);
    MCNP_frame4->SetMaximum(max*10);
    MCNP_frame4->SetMinimum(0.5);
    MCNP_frame4->Draw();

*/
    c_MCNP_ptArr[iPtBins]->SaveAs(Form("plots_functionfit/MCNP_FunCom_pt%dto%d.pdf",(int)ptLow,(int)ptHigh));
		

		//	fitres->Print(); not work for unknown reason.

/*
		c_MCNP_ptArr[iPtBins]->cd(3);
		RooPlot *MCNP_frame3= x.frame();
		sg.setConstant(kFALSE);
		gpxg->fitTo(h_MCNP);
		h_MCNP.plotOn(MCNP_frame3);
		gpxg->plotOn(MCNP_frame3);
		gpxg->paramOn(MCNP_frame3);
		MCNP_frame3->SetMaximum(max+0.2*(max-min));
		MCNP_frame3->Draw();

		TLatex *tex_MCNPGaussF= new TLatex(0.18,0.75,"Exp.(x)Gaus.");
		tex_MCNPGaussF->SetNDC();
		tex_MCNPGaussF->SetTextFont(42);
		tex_MCNPGaussF->SetTextSize(0.035);
		tex_MCNPGaussF->SetLineWidth(2);
		tex_MCNPGaussF->Draw();


		c_MCNP_gauss->cd(iPtBins+1);
		MCNP_frame3->Draw();
		if(iPtBins==0){
			TLatex *tex_MCNP_Gauss = new TLatex(0.18,0.75,Form("Non Prompt D, Gauss"));
			tex_MCNP_Gauss->SetNDC();
			tex_MCNP_Gauss->SetTextFont(42);
			tex_MCNP_Gauss->SetTextSize(0.035);
			tex_MCNP_Gauss->SetLineWidth(2);
			tex_MCNP_Gauss->Draw();
		}
		TLatex *tex_MCNP_Gausspt = new TLatex(0.18,0.82,Form("%.1f<pt<%.1f",ptLow,ptHigh));
		tex_MCNP_Gausspt->SetNDC();
		tex_MCNP_Gausspt->SetTextFont(42);
		tex_MCNP_Gausspt->SetTextSize(0.035);
		tex_MCNP_Gausspt->SetLineWidth(2);
		tex_MCNP_Gausspt->Draw();



		c_MCNP_ptArr[iPtBins]->cd(2);

		//  RooFFTConvPdf gpxg2("gpxg2","exp (x) gauss2",x,gp,dgauss); dgauss can not perform FFT
		RooNumConvPdf gpxg2("gpxg2","exp (x) gauss2",x,gp,dgauss);

		sigma.setConstant(kTRUE);
		ARatio.setConstant(kTRUE);
		sigmaRatio.setConstant(kTRUE);


		RooPlot *MCNP_frame2= x.frame();
		//	sg.setRange(0.0000001,0.1);
		gpxg2.fitTo(h_MCNP);
		h_MCNP.plotOn(MCNP_frame2);
		gpxg2.plotOn(MCNP_frame2);
		gpxg2.paramOn(MCNP_frame2);

		MCNP_frame2->SetMaximum(max+0.2*(max-min));
		MCNP_frame2->Draw();

		TLatex *tex_MCNPpt= new TLatex(0.18,0.82,Form("%.1f<D P_{T}<%.1f",ptLow,ptHigh));
		tex_MCNPpt->SetNDC();
		tex_MCNPpt->SetTextFont(42);
		tex_MCNPpt->SetTextSize(0.035);
		tex_MCNPpt->SetLineWidth(2);
		tex_MCNPpt->Draw();
		TLatex *tex_MCNPGauss2= new TLatex(0.18,0.75,"Exp (x) Double Gass.");
		tex_MCNPGauss2->SetNDC();
		tex_MCNPGauss2->SetTextFont(42);
		tex_MCNPGauss2->SetTextSize(0.035);
		tex_MCNPGauss2->SetLineWidth(2);
		tex_MCNPGauss2->Draw();



		// double exponential fit
		c_MCNP_ptArr[iPtBins]->cd(4);

*/
/*
		c_MCNP_ptArr[iPtBins]->cd(4);
		sigma.setConstant(kFALSE);
		ARatio.setConstant(kFALSE);
		sigmaRatio.setConstant(kFALSE);

		RooPlot *MCNP_frame4= x.frame();
		//  sg.setRange(0.0000001,0.1);
		gpxg2.fitTo(h_MCNP);
		gpxg2.fitTo(h_MCNP);
		h_MCNP.plotOn(MCNP_frame4);
		gpxg2.plotOn(MCNP_frame4);
		gpxg2.paramOn(MCNP_frame4);

		MCNP_frame4->SetMaximum(max+0.2*(max-min));
		MCNP_frame4->Draw();

		TLatex *tex_MCNP2GaussF= new TLatex(0.18,0.75,"(x)Double Gauss;float");
		tex_MCNP2GaussF->SetNDC();
		tex_MCNP2GaussF->SetTextFont(42);
		tex_MCNP2GaussF->SetTextSize(0.035);
		tex_MCNP2GaussF->SetLineWidth(2);
		tex_MCNP2GaussF->Draw();

*/

//		c_MCNP_ptArr[iPtBins]->SaveAs(Form("plots_functionfit/MCNP_FunCom_pt%dto%d.pdf",(int)ptLow,(int)ptHigh));


		////////////////////
		///// fit to data //
		////////////////////

		c_data[iPtBins] = new TCanvas(Form("c_data_pt%i",iPtBins),Form("c_data_pt%i",iPtBins),1200,800);
		c_data[iPtBins]->Divide(3,2);

		c_data[iPtBins]->cd(1); //plot MC prompt fit
		gPad->SetLogy();
		MCP_frame->SetMaximum(MCP_frame->GetMaximum()*10);
		MCP_frame->SetMinimum(1);
//    gauss.plotOn(MCP_frame,LineColor(2));
    MCP_frame->Draw();
    tex_MCP->Draw();
    tex_MCPGauss->Draw();

    TLatex *tex_Datapt= new TLatex(0.18,0.68,Form("%.1f<D P_{T}<%.1f",ptLow,ptHigh));
    tex_Datapt->SetNDC();
    tex_Datapt->SetTextFont(42);
    tex_Datapt->SetTextSize(0.035);
    tex_Datapt->SetLineWidth(2);
    tex_Datapt->Draw();



		c_data[iPtBins]->cd(4);	//plot MC Non prompt fit
		gPad->SetLogy();

		MCNP_frame2->Draw();
		tex_MCNPpower->Draw();
		tex_MCNP->Draw();
/*
		MCNP_frame->SetMaximum(MCNP_frame->GetMaximum()*10);
		MCNP_frame->SetMinimum(1);
    MCNP_frame->Draw();
    tex_MCNP->Draw();
    TLatex *tex_MCNPGaussF= new TLatex(0.18,0.75,"Exp.(x)Gaus.");
    tex_MCNPGaussF->SetNDC();
    tex_MCNPGaussF->SetTextFont(42);
    tex_MCNPGaussF->SetTextSize(0.035);
    tex_MCNPGaussF->SetLineWidth(2);
    tex_MCNPGaussF->Draw();
*/
		c_data[iPtBins]->cd(2); //plot data fit , parameter fixed

		h_DcaData[iPtBins]=(TH1D*)fDcaData->Get(Form("D0DcaDataOut_pt%i",iPtBins));
/*
		TCanvas *c_dcadata = new TCanvas("c_dcadta");
		c_dcadata->cd();
		h_DcaData->

		c_data[iPtBins]->cd(3);
*/
//		gPad->SetLogy();	// not work .... <THistPainter::PaintInit>: log scale requested with a negative argument
//		fixZeroBin(h_DcaData[iPtBins]);
//		double maxdatah = h_DcaData[iPtBins]->GetMaximum();
//		h_DcaData[iPtBins]->GetYaxis()->SetRangeUser(0.00001,maxdatah);
//		h_DcaData[iPtBins]->SetMinimum(0.001);

		RooDataHist h_Data("h_Data","h_Data",RooArgSet(x),h_DcaData[iPtBins]);

/* fraction fit
		RooRealVar pfrac("pfrac","pfrac",0.5,0,1);
//		RooRealVar npfrac("npfrac","npfrac",0.1);
		RooAddPdf MCDCAmix_pdf("MCDCAmix_pdf","P+NP",RooArgList(gauss,gp),RooArgList(pfrac));
*/

//		RooArgSet * comps=gpxp.getComponents();

		RooRealVar pNum("Prompt","Prompt",20000,0,100000);
		RooRealVar npNum("NonPrompt","NonPrompt",9000,0,100000);

//		RooAddPdf MCDCAmix_pdf("MCDCAmix_pdf","P+NP exML",RooArgList(MCP_pdf,*MCNP_pdf),RooArgList(pNum,npNum));
		RooAddPdf MCDCAmix_pdf("MCDCAmix_pdf","P+NP exML",RooArgList(MCP_pdf,power_pdf),RooArgList(pNum,npNum));

		sigma.setConstant(kTRUE);
		power_a.setConstant(kTRUE);
		power_n.setConstant(kTRUE);

//		alpha.setConstant(kTRUE);
//		sg.setConstant(kTRUE);

//		MCDCAmix_pdf.fitTo(h_Data);
		MCDCAmix_pdf.fitTo(h_Data,Extended(kTRUE));	

		RooPlot* data_frame = x.frame();
		h_Data.plotOn(data_frame,Binning(bin_dcaxy));

		MCDCAmix_pdf.plotOn(data_frame,Components(RooArgSet(MCP_pdf,power_pdf)),LineColor(3));
		MCDCAmix_pdf.plotOn(data_frame,Components(power_pdf),LineStyle(kDashed),LineColor(4));
    MCDCAmix_pdf.plotOn(data_frame,Components(MCP_pdf),LineStyle(kDashed),LineColor(2));
		MCDCAmix_pdf.paramOn(data_frame);

    max = data_frame->GetMaximum();
    min = data_frame->GetMinimum();
    data_frame->SetMaximum(max+0.2*(max-min));
		// data_frame->SetMinimum(0.1); // must after the plotOn
		data_frame->Draw();	

    TLatex *tex_datafix= new TLatex(0.18,0.82,"Data, param. fix");
    tex_datafix->SetNDC();
    tex_datafix->SetTextFont(42);
    tex_datafix->SetTextSize(0.035);
    tex_datafix->SetLineWidth(2);
    tex_datafix->Draw();

		// fill in output
		h_PromptYield_fix->SetBinContent(iPtBins+1,pNum.getVal());
		h_PromptYield_fix->SetBinError(iPtBins+1,pNum.getError());
    h_NonPromptYield_fix->SetBinContent(iPtBins+1,npNum.getVal());
    h_NonPromptYield_fix->SetBinError(iPtBins+1,npNum.getError());

    h_NonPromptFraction_fix->SetBinContent(iPtBins+1,npNum.getVal()/(pNum.getVal()+npNum.getVal()));
    h_NonPromptFraction_fix->SetBinError(iPtBins+1,npNum.getError()/(pNum.getVal()+npNum.getVal()));

	
		c_data[iPtBins]->cd(5);
		gPad->SetLogy();
		RooPlot* data_framelog = x.frame();
    h_Data.plotOn(data_framelog,Binning(bin_dcaxy));
    MCDCAmix_pdf.plotOn(data_framelog,Components(RooArgSet(MCP_pdf,power_pdf)),LineColor(3));
    MCDCAmix_pdf.plotOn(data_framelog,Components(power_pdf),LineStyle(kDashed),LineColor(4));
    MCDCAmix_pdf.plotOn(data_framelog,Components(MCP_pdf),LineStyle(kDashed),LineColor(2));
//    MCDCAmix_pdf.paramOn(data_framelog);
    max = data_framelog->GetMaximum();
    min = data_frame->GetMinimum();
    data_framelog->SetMaximum(10*max);
    data_framelog->SetMinimum(0.5); // must after the plotOn
    data_framelog->Draw();
    tex_datafix->Draw();
			
	  			

		c_data[iPtBins]->cd(3);

		sigma.setConstant(kFALSE);
		power_a.setConstant(kFALSE);
		power_n.setConstant(kFALSE);

		MCDCAmix_pdf.fitTo(h_Data,Extended(kTRUE));		
    RooPlot* data_frame2 = x.frame();
    h_Data.plotOn(data_frame2,Binning(bin_dcaxy));
    MCDCAmix_pdf.plotOn(data_frame2,Components(RooArgSet(MCP_pdf,power_pdf)),LineColor(3));
    MCDCAmix_pdf.plotOn(data_frame2,Components(power_pdf),LineStyle(kDashed),LineColor(4));
    MCDCAmix_pdf.plotOn(data_frame2,Components(MCP_pdf),LineStyle(kDashed),LineColor(2));
    MCDCAmix_pdf.paramOn(data_frame2);

	  max = data_frame2->GetMaximum();
    min = data_frame2->GetMinimum();
    data_frame2->SetMaximum(max+0.2*(max-min));
    data_frame2->Draw();

    TLatex *tex_datafloat= new TLatex(0.18,0.82,"Data, param. float");
    tex_datafloat->SetNDC();
    tex_datafloat->SetTextFont(42);
    tex_datafloat->SetTextSize(0.035);
    tex_datafloat->SetLineWidth(2);
    tex_datafloat->Draw();


    // fill in output
    h_PromptYield_float->SetBinContent(iPtBins+1,pNum.getVal());
    h_PromptYield_float->SetBinError(iPtBins+1,pNum.getError());
    h_NonPromptYield_float->SetBinContent(iPtBins+1,npNum.getVal());
    h_NonPromptYield_float->SetBinError(iPtBins+1,npNum.getError());

    h_NonPromptFraction_float->SetBinContent(iPtBins+1,npNum.getVal()/(pNum.getVal()+npNum.getVal()));
    h_NonPromptFraction_float->SetBinError(iPtBins+1,npNum.getError()/(pNum.getVal()+npNum.getVal()));

		c_data[iPtBins]->cd(6);
		gPad->SetLogy();
		RooPlot *data_frame2log = x.frame();
    h_Data.plotOn(data_frame2log,Binning(bin_dcaxy));
    MCDCAmix_pdf.plotOn(data_frame2log,Components(RooArgSet(MCP_pdf,power_pdf)),LineColor(3));
    MCDCAmix_pdf.plotOn(data_frame2log,Components(power_pdf),LineStyle(kDashed),LineColor(4));
    MCDCAmix_pdf.plotOn(data_frame2log,Components(MCP_pdf),LineStyle(kDashed),LineColor(2));
//    MCDCAmix_pdf.paramOn(data_frame2);
    max = data_frame2log->GetMaximum();
//    min = data_frame2->GetMinimum();
    data_frame2log->SetMaximum(10*max);
		data_frame2log->SetMinimum(0.5);
    data_frame2log->Draw();
    tex_datafloat->Draw();
	



		c_data[iPtBins]->SaveAs(Form("plots_functionfit/fitdata_pt%dto%d.pdf",(int)ptLow,(int)ptHigh));


	} // end for iPtBins
/*
	c_MCP_gauss->SaveAs("plots_functionfit/MCP_Gauss_Ptall.pdf");
	c_MCP_gauss2->SaveAs("plots_functionfit/MCP_Gauss2_Ptall.pdf");
	c_MCNP_gauss->SaveAs("plots_functionfit/MCNP_Gauss_Ptall.pdf");
*/

	divideBinWidth(h_PromptYield_fix);
	divideBinWidth(h_NonPromptYield_fix);
	divideBinWidth(h_PromptYield_float);
	divideBinWidth(h_NonPromptYield_float);

	TCanvas *c_dataPtall = new TCanvas("c_dataPtall","c_dataPtall",1000,600);
	c_dataPtall->Divide(3,2);
	c_dataPtall->cd(1);
	gPad->SetLogy();
	h_PromptYield_fix->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_PromptYield_fix->GetYaxis()->SetTitle("Prompt Yield (fix)");
	h_PromptYield_fix->Draw();
	c_dataPtall->cd(2);
  gPad->SetLogy();
  h_NonPromptYield_fix->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_NonPromptYield_fix->GetYaxis()->SetTitle("NonPrompt Yield (fix)");
	h_NonPromptYield_fix->Draw();
	c_dataPtall->cd(3);
  h_NonPromptFraction_fix->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_NonPromptFraction_fix->GetYaxis()->SetTitle("NonPrompt Fraction (fix)");
	h_NonPromptFraction_fix->Draw();
  c_dataPtall->cd(4);
  gPad->SetLogy();
  h_PromptYield_float->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_PromptYield_float->GetYaxis()->SetTitle("Prompt Yield (float)");
  h_PromptYield_float->Draw();
  c_dataPtall->cd(5);
  gPad->SetLogy();
  h_NonPromptYield_float->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_NonPromptYield_float->GetYaxis()->SetTitle("NonPrompt Yield (float)");
  h_NonPromptYield_float->Draw();
  c_dataPtall->cd(6);
  h_NonPromptFraction_float->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_NonPromptFraction_float->GetYaxis()->SetTitle("NonPrompt Fraction (float)");
//	h_NonPromptFraction_float->SetMaximum(1);;
  h_NonPromptFraction_float->Draw();

	c_dataPtall->SaveAs("plots_functionfit/fitPt_spectrum.pdf");

	
	TH1D *h_PromptYield_tmp = (TH1D*)fDcaData->Get("hPromptDRawYield");
	TH1D *h_NonPromptYield_tmp = (TH1D*)fDcaData->Get("hBtoDRawYield");

	TH1D *h_PromptYield_diff = new TH1D("h_PromptYield_diff","h_PromptYield_diff",nPtBins,ptBins);
  TH1D *h_NonPromptYield_diff = new TH1D("h_PromptYield_diff","h_PromptYield_diff",nPtBins,ptBins);

	TH1D *h_PromptYield_RelErr = new TH1D("h_PromptYield_RelErr","h_PromptYield_RelErr",nPtBins,ptBins);
  TH1D *h_NonPromptYield_RelErr = new TH1D("h_NonPromptYield_RelErr","h_NonPromptYield_RelErr",nPtBins,ptBins);

	for(int iPtBins =0;iPtBins<nPtBins; iPtBins++){
	
		h_PromptYield_diff->SetBinContent(iPtBins+1,h_PromptYield_float->GetBinContent(iPtBins+1)-h_PromptYield_tmp->GetBinContent(iPtBins+1));
    h_NonPromptYield_diff->SetBinContent(iPtBins+1,h_NonPromptYield_float->GetBinContent(iPtBins+1)-h_NonPromptYield_tmp->GetBinContent(iPtBins+1));
	
    h_PromptYield_RelErr->SetBinContent(iPtBins+1,abs((h_PromptYield_float->GetBinContent(iPtBins+1)-h_PromptYield_tmp->GetBinContent(iPtBins+1))/h_PromptYield_tmp->GetBinContent(iPtBins+1)));
    h_NonPromptYield_RelErr->SetBinContent(iPtBins+1,abs((h_NonPromptYield_float->GetBinContent(iPtBins+1)-h_NonPromptYield_tmp->GetBinContent(iPtBins+1))/h_NonPromptYield_tmp->GetBinContent(iPtBins+1)));

	}

	TCanvas *c_yield_sys = new TCanvas("c_yield_sys","c_yield_sys",800,800);
	c_yield_sys->Divide(2,2);

	c_yield_sys->cd(1);
	gPad->SetLogy();
//	h_PromptYield_tmp->SetMarkerStyle(24);
//	h_PromptYield_tmp->SetMarkerColor(4);
//	h_PromptYield_tmp->SetLinceColor(4);
	SetHistStyle(h_PromptYield_tmp,4);
	h_PromptYield_tmp->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
	h_PromptYield_tmp->Draw();
//	h_PromptYield_float->SetMarkerStyle(24);
//  h_PromptYield_float->SetMarkerColor(2);
//	h_PromptYield_float->SetLineColor(2);
	SetHistStyle(h_PromptYield_float,2);
	h_PromptYield_float->Draw("same");

	TLegend *le_PromptYield = new TLegend(0.65,0.65,0.88,0.88);
	le_PromptYield->SetBorderSize(0);
	le_PromptYield->AddEntry((TObject*)0,"Prompt Yield","");
	le_PromptYield->AddEntry(h_PromptYield_tmp,"template fit","l");
  le_PromptYield->AddEntry(h_PromptYield_float,"function fit","l");
	le_PromptYield->Draw();

  c_yield_sys->cd(2);
	gPad->SetLogy();
//  h_NonPromptYield_tmp->SetMarkerStyle(24);
//  h_NonPromptYield_tmp->SetMarkerColor(4);
//  h_NonPromptYield_tmp->SetLinceColor(4);
  SetHistStyle(h_NonPromptYield_tmp,4);
  h_NonPromptYield_tmp->GetXaxis()->SetTitle("D P_{T} (GeV/c)");
  h_NonPromptYield_tmp->Draw();
//  h_NonPromptYield_float->SetMarkerStyle(24);
//  h_NonPromptYield_float->SetMarkerColor(2);
//  h_NonPromptYield_float->SetLineColor(2);
  SetHistStyle(h_NonPromptYield_float,2);
  h_NonPromptYield_float->Draw("same");

  TLegend *le_NonPromptYield = new TLegend(0.65,0.65,0.88,0.88);
  le_NonPromptYield->SetBorderSize(0);
  le_NonPromptYield->AddEntry((TObject*)0,"NonPrompt Yield","");
  le_NonPromptYield->AddEntry(h_NonPromptYield_tmp,"template fit","l");
  le_NonPromptYield->AddEntry(h_NonPromptYield_float,"function fit","l");
  le_NonPromptYield->Draw();

	c_yield_sys->cd(3);
	h_PromptYield_RelErr->Draw();
  TLatex *tex_promptY_RelErr= new TLatex(0.18,0.82,"Prompt Yield rel.Err");
  tex_promptY_RelErr->SetNDC();
  tex_promptY_RelErr->SetTextFont(42);
  tex_promptY_RelErr->SetTextSize(0.035);
  tex_promptY_RelErr->SetLineWidth(2);
  tex_promptY_RelErr->Draw();



	c_yield_sys->cd(4);
//	h_NonPromptYield_RelErr->SetMaximum(1);
	h_NonPromptYield_RelErr->Draw();
  TLatex *tex_NonpromptY_RelErr= new TLatex(0.18,0.82,"NonPrompt Yield rel.Err");
  tex_NonpromptY_RelErr->SetNDC();
  tex_NonpromptY_RelErr->SetTextFont(42);
  tex_NonpromptY_RelErr->SetTextSize(0.035);
  tex_NonpromptY_RelErr->SetLineWidth(2);
  tex_NonpromptY_RelErr->Draw();




	c_yield_sys->SaveAs("plots_functionfit/Yield_sys.pdf");




	fout->cd();
  h_PromptYield_fix->Write();
  h_NonPromptYield_fix->Write();
  h_NonPromptFraction_fix->Write();

	h_PromptYield_float->Write();
	h_NonPromptYield_float->Write();
	h_NonPromptFraction_float->Write();


	h_PromptYield_diff->Write();
	h_NonPromptYield_diff->Write();
	h_PromptYield_RelErr->Write();
	h_NonPromptYield_RelErr->Write();	



	fout->Write();
	fout->Close(); // this will delete all object on plot


	cout<<"end of main"<<endl;
	

	/*


		 TCanvas *c_DCA_xy = new TCanvas("c_DCA_xy","c_DCA_xy",600,600);
		 c_DCA_xy->cd();
		 h_MCP_DCAxy->SetLineColor(1);
		 h_MCP_DCAxy->Draw();
		 h_MCNP_DCAxy->SetLineColor(4);
		 h_MCNP_DCAxy->Draw("SAME");



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

		 TF1 *f_MCP = new TF1("f_MCP",&fun_MCP,-0.05,0.0,5);
	//	f_MCP->SetParameters(h_MCP_DCAxy->Integral(), 0, h_MCP_DCAxy->GetRMS());


	f_MCP->SetParameters(77770, 0.7, 0,0.002726,2);
	f_MCP->FixParameter(2,0);
	f_MCP->SetParLimits(1,0,1);
	f_MCP->SetParLimits(4,1,1000);
	cout<<"integral = "<<h_MCP_DCAxy->Integral()<<" , RMS = "<<h_MCP_DCAxy->GetRMS()<<endl;

	TFitResultPtr fitResult;
	fitResult = h_MCP_DCAxy->Fit("f_MCP","MR","",-0.05,0.05);
	int fitStatus=1;
	fitStatus= fitResult->Status();
	cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;

	h_MCP_DCAxy->Draw();
	f_MCP->Draw("flsame");



	TCanvas *c_RoofitMCP = new TCanvas("c_RoofitMCP","c_RoofitMCP",800,800);
	c_RoofitMCP->Divide(2,2);
	c_RoofitMCP->cd(1);

	RooRealVar x("x","dca_xy",-0.05,0.05);
	//	RooRealVar mean("mean","mean",0,-0.02,0.02);
	RooRealVar mean("mean","mean",0);
	RooRealVar sigma("sigma","sigma",0.003,0.00001,0.02);
	RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma);
	RooPlot* MCP_frame = x.frame();

	RooDataHist h_MCP("h_MCP","h_MCP",RooArgList(x),h_MCP_DCAxy);

	gauss.fitTo(h_MCP);
	h_MCP.plotOn(MCP_frame);
	gauss.plotOn(MCP_frame);
	gauss.paramOn(MCP_frame);
	MCP_frame->Draw();

	c_RoofitMCP->cd(2);
	gPad->SetLogy();
	MCP_frame->Draw();


	c_RoofitMCP->cd(3);
	RooRealVar ARatio("ARatio","ARatio",0.5,0,1);
	RooRealVar sigmaRatio("sigmaRatio","sigmaRatio",1.24,1.000001,100000);
	RooGenericPdf dgauss("dgauss","Double Gaussian","ARatio*exp(-pow((x-mean)/sigma,2)/2)+(1-ARatio)*exp(-pow((x-mean)/(sigma*sigmaRatio),2)/2)",RooArgSet(x,mean,sigma,ARatio,sigmaRatio));
	//	RooGenericPdf dgauss("dgauss","Double Gaussian", "exp(-pow((x-mean)/sigma,2)/2)" ,RooArgSet(x,mean,sigma));

	dgauss.fitTo(h_MCP);
	RooPlot* MCP_frame2 = x.frame();
	h_MCP.plotOn(MCP_frame2);
	dgauss.plotOn(MCP_frame2);
	dgauss.paramOn(MCP_frame2);
	MCP_frame2->Draw();

	c_RoofitMCP->cd(4);
	gPad->SetLogy();
	MCP_frame2->Draw();




	TCanvas *c_RoofitMCNP = new TCanvas("c_RoofitMCNP","c_RoofitMCNP",800,800);
	c_RoofitMCNP->Divide(2,2);
	c_RoofitMCNP->cd(1);

	RooRealVar dca("dca","dca_xy",-0.05,0.05);
	RooRealVar alpha("alpha","alpha",-100,-20000,-0.00001);
	RooGenericPdf gp("gp","Generic PDF","exp(abs(dca)*alpha)",RooArgSet(dca,alpha));
	RooPlot * MCNP_frame = dca.frame();

	RooDataHist h_MCNP("h_MCNP","h_MCNP",RooArgSet(dca),h_MCNP_DCAxy);
	gp.fitTo(h_MCNP);
	h_MCNP.plotOn(MCNP_frame);
	gp.plotOn(MCNP_frame);
	MCNP_frame->Draw();

	c_RoofitMCNP->cd(2);
	gPad->SetLogy();
	MCNP_frame->Draw();


	//	TCanvas *c_RoofitMCNP_Conv = new TCanvas("c_RoofitMCNP_Conv","c_RoofitMCNP_Conv",600,600);
	//  RooRealVar dca("dca","dca",-0.05,0.05);
	//  RooRealVar alpha("alpha","alpha",-100,-20000,-0.00001);
	//  RooGenericPdf gp("gp","Generic PDF","exp(abs(dca)*alpha)",RooArgSet(dca,alpha));

	c_RoofitMCNP->cd(3);	
	RooRealVar mg("mg","mg",0);
	RooRealVar sg("sg","sg",0.0001,0.0000001,0.1);
	RooGaussian gauss2("gauss2","gauss2",dca,mg,sg);
	dca.setBins(10000,"cache");
	RooFFTConvPdf gpxg("gpxg","exp (x) gauss",dca,gp,gauss2);


	RooPlot * MCNP_frame2 = dca.frame();
	//  RooDataHist h_MCNP("h_MCNP","h_MCNP",RooArgSet(dca),h_MCNP_DCAxy);
	gpxg.fitTo(h_MCNP);
	h_MCNP.plotOn(MCNP_frame2);
	gpxg.plotOn(MCNP_frame2);
	gpxg.paramOn(MCNP_frame2);
	//	MCNP_frame2->GetXaxis()->SetTitle("set x title");
	MCNP_frame2->Draw();

	c_RoofitMCNP->cd(4);
	gPad->SetLogy();
	MCNP_frame2->Draw();





	TCanvas *c_MCNP = new TCanvas("c_MCNP","c_MCNP",600,600);
	c_MCNP->cd();
	TF1 *f_MCNP = new TF1("f_MCNP",&fun_MCNP,-0.05,0.05,2);
	f_MCNP->SetParameters(1000,-3);

	TFitResultPtr fitResult_MCNP;
	fitResult_MCNP = h_MCNP_DCAxy->Fit("f_MCNP","MR","",-0.05,0.05);
	int fitStatus_MCNP=1;
	fitStatus_MCNP = fitResult_MCNP->Status();
	h_MCNP_DCAxy->Draw();
	f_MCNP->Draw("flsame");

	*/
		////
		cout<<"MCPsigmaVal ="<<MCPsigmaVal<<endl;

}
Ejemplo n.º 4
0
void much_pol_histo(){
  TString dir = "data/";
  TString accFileName = dir+"polHisto.root";
  TString genFileName = dir+"polHisto.root";  
  TString recFileName = dir+"recHisto.root";
  hyperon_style();

  TFile* f = new TFile(accFileName,"read");
  TH3D* hJpsiAllYPtCost = (TH3D*) f->Get("fhJpsiAllYPtCost");
  TH3D* hJpsiRecYPtCost = (TH3D*) f->Get("fhJpsiRecYPtCost");
  hJpsiAllYPtCost->Sumw2();
  hJpsiRecYPtCost->Sumw2();
  TH3D* hJpsiEffYPtCost = (TH3D*) hJpsiRecYPtCost->Clone();
  hJpsiEffYPtCost->Divide(hJpsiAllYPtCost);
  
  Int_t binsY   = hJpsiAllYPtCost->GetXaxis()->GetNbins();
  Double_t minY = hJpsiAllYPtCost->GetXaxis()->GetXmin();
  Double_t maxY = hJpsiAllYPtCost->GetXaxis()->GetXmax();
  
  Int_t binsPt   = hJpsiAllYPtCost->GetYaxis()->GetNbins();
  Double_t minPt = hJpsiAllYPtCost->GetYaxis()->GetXmin();
  Double_t maxPt = hJpsiAllYPtCost->GetYaxis()->GetXmax();
  
  Int_t binsCost   = hJpsiAllYPtCost->GetZaxis()->GetNbins();
  Double_t minCost = hJpsiAllYPtCost->GetZaxis()->GetXmin();
  Double_t maxCost = hJpsiAllYPtCost->GetZaxis()->GetXmax();

  TH2D** hFidYPt = new TH2D*[binsCost];
  TH2D** hAndYPt = new TH2D*[binsCost];
  
  // Create fiducial regions
  for (Int_t icost=1;icost<=binsCost;icost++){
    hFidYPt[icost-1] = new TH2D(Form("hFidYPt%2i",icost),Form("hFidYPt%2i",icost),binsY,minY,maxY,binsPt,minPt,maxPt);
    hAndYPt[icost-1] = new TH2D(Form("hAndYPt%2i",icost),Form("hAndYPt%2i",icost),binsY,minY,maxY,binsPt,minPt,maxPt);
    for (Int_t iy=1;iy<=binsY;iy++){
      for (Int_t ipt=1;ipt<=binsPt;ipt++){
        Double_t rec = hJpsiRecYPtCost->GetBinContent(iy,ipt,icost);
        hFidYPt[icost-1]->SetBinContent(iy,ipt,1);
        hAndYPt[icost-1]->SetBinContent(iy,ipt,1);
        if (rec>200) continue;
        hJpsiEffYPtCost->SetBinContent(iy,ipt,icost,0.);
        hFidYPt[icost-1]->SetBinContent(iy,ipt,0);
      }
    }
  }
  
  for (Int_t icost=1;icost<=binsCost/2;icost++){
    for (Int_t i=icost;i<=binsCost+1-icost;i++)
      hAndYPt[icost-1]->Multiply(hFidYPt[i-1]);
  }

  TCanvas* cFiducial = new TCanvas("cFiducial","cFiducial",200*5,200*4);
  cFiducial->Divide(5,4);
  for (Int_t icost=1;icost<=binsCost;icost++){
    cFiducial->cd(icost);
    gPad->SetRightMargin(0.1);
    hFidYPt[icost-1]->Draw("colz");
  }

  TCanvas* cAnd = new TCanvas("cAnd","cAnd",200*5,200*2);
  cAnd->Divide(5,2);
  for (Int_t icost=1;icost<=binsCost/2;icost++){
    cAnd->cd(icost);
    gPad->SetRightMargin(0.1);
    hAndYPt[icost-1]->Draw("colz");
  }

  
  TH3D* hJpsiRecEffCorrectedYPtCost = (TH3D*) hJpsiRecYPtCost->Clone();
  hJpsiRecEffCorrectedYPtCost->Divide(hJpsiEffYPtCost);
  
//  TH1D* hJpsiAllCost = hJpsiAllYPtCost->ProjectionZ();
  
  
//  TH1D* hJpsiRecEffCorrectedCost = hJpsiRecEffCorrectedYPtCost->ProjectionZ();
//  TH1D** hJpsiRecEffCorrectedCost = new TH1D*[nBinsPt];
  
  
//  hJpsiAllCost->SetMinimum(0);
//  hJpsiAllCost->SetLineColor(kBlue);
//  hJpsiRecEffCorrectedCost->SetLineColor(kRed);
//  
//  TCanvas* cCost = new TCanvas("cCost","Cos #theta distributions",400,400);
//  hJpsiAllCost->Draw();
//  hJpsiRecEffCorrectedCost->Draw("same");


  TH1D* hRecCost[nBinsPt];
  TH1D* hAccCost[nBinsPt];
  TH1D* hAllCost[nBinsPt];
  TH1D* haccRecCost[nBinsPt];
  TH1D* haccAllCost[nBinsPt];
  TH1D* hResCost[nBinsPt];
  
  for (Int_t i=0;i<nBinsPt;i++){
    hRecCost[i] = new TH1D(Form("hRecCost%d",i),Form("hRecCost%d",i),binsCost,minCost,maxCost);
    hAllCost[i] = new TH1D(Form("hAllCost%d",i),Form("hAllCost%d",i),binsCost,minCost,maxCost);
    hAccCost[i] = new TH1D(Form("hAccCost%d",i),Form("hAccCost%d",i),binsCost,minCost,maxCost);
    hResCost[i] = new TH1D(Form("hResCost%d",i),Form("hResCost%d",i),binsCost,minCost,maxCost);
    haccRecCost[i] = new TH1D(Form("haccRecCost%d",i),Form("haccRecCost%d",i),binsCost,minCost,maxCost);
    haccAllCost[i] = new TH1D(Form("haccAllCost%d",i),Form("haccAllCost%d",i),binsCost,minCost,maxCost);
  }
  
  TH2D* vhAndYPt[nBinsPt];
//  TH2D* vhAndGenYPt[nBinsPt];
  for (Int_t iBin=0;iBin<nBinsPt;iBin++){
    vhAndYPt[iBin]=hAndYPt[minCosBin[iBin]];
//    vhAndGenYPt[iBin]=hAndGenYPt[minCosBin[iBin]];
  }
  
  TFile* accFile = new TFile(accFileName.Data());
  TH3D* haccAllYPtCost = (TH3D*) accFile->Get("fhJpsiAllYPtCost");
  TH3D* haccRecYPtCost = (TH3D*) accFile->Get("fhJpsiRecYPtCost");
  FillCos(haccRecCost,haccRecYPtCost,vhAndYPt,0);
  FillCos(haccAllCost,haccAllYPtCost,vhAndYPt,0);
  
  TFile* genFile = new TFile(genFileName.Data());
  TH3D* hAllYPtCost = (TH3D*) genFile->Get("fhJpsiAllYPtCost");
  TH3D* hRecYPtCost = (TH3D*) genFile->Get("fhJpsiRecYPtCost");
  FillCos(hRecCost,hRecYPtCost,vhAndYPt,1);
  FillCos(hAllCost,hAllYPtCost,vhAndYPt,0);
  
  for (Int_t i=0;i<nBinsPt;i++){
    hAccCost[i]->Divide(haccRecCost[i],haccAllCost[i]);
    hResCost[i]->Divide(hRecCost[i],hAccCost[i]);
  }
  
  Int_t nEntries[nBinsPt];
  for (Int_t i=0;i<nBinsPt;i++){
    nEntries[i]=0;
    for (Int_t j=0;j<=20;j++){ nEntries[i]+= (Int_t) hRecCost[i]->GetBinContent(j);}
//    nEntries[i] = hRecCos[i]->Integral();
//    cout << "bin: " << i+1 << "rec: " << nEntries[i] << endl;
  }

  TCanvas* c1 = new TCanvas("c1","",nBinsPt*240,2*240);
  c1->Divide(nBinsPt,2);
  Double_t alpha[nBinsPt];
  Double_t error[nBinsPt];
  for (Int_t i=0;i<nBinsPt;i++){
    c1->cd(i+1+nBinsPt*0);
    hAccCost[i]->SetTitle(Form("Acceptance vs cos #theta: %3.1f < pt < %3.1f; cos #theta;  Acceptance",rangePt[i],rangePt[i+1]));
    hAccCost[i]->Draw();
    c1->cd(i+1+nBinsPt*1);
    Float_t cosMin=-1+(minCosBin[i]-1)*0.1;
    Float_t cosMax=-1+maxCosBin[i]*0.1;
    TF1* fPolar = new TF1(Form("fPolar%i_pt",i+1),"[0]*(1+[1]*x*x)",cosMin,cosMax);
    fPolar->SetLineColor(kRed);
    //fPolar->SetLineWidth(1);
    hResCost[i]->Fit(fPolar,"R");
    hAllCost[i]->SetMinimum(0);
    hAllCost[i]->SetTitle(Form("Reconstructed vs cos #theta: %3.1f < pt < %3.1f; cos #theta;",rangePt[i],rangePt[i+1]));
    hAllCost[i]->Draw();
    hResCost[i]->SetLineColor(kBlue);
    hResCost[i]->SetLineWidth(1);
    hResCost[i]->Draw("e same");
    alpha[i] = fPolar->GetParameter(1);
    error[i] = fPolar->GetParError(1);
    TLegend* l1 = new TLegend(0.22,0.15,0.78,0.38);
    l1->AddEntry(hAllCost[i],"Simulated, #alpha=-1.0");
    l1->AddEntry(hResCost[i],"Reconstructed");
    l1->AddEntry(fPolar,Form("Rec. fit: #alpha=%4.3f #pm %4.3f", alpha[i], error[i]));
    l1->Draw();
    gPad->Print(Form("%i.png",i));
  }

  printf("====  Alpha  ==================================\n");
  for (Int_t i=0;i<nBinsPt;i++)  printf(" %6.3f ",alpha[i]);
  printf("\n");
  printf("===============================================\n");

  printf("====  Error  ==================================\n");
  for (Int_t i=0;i<nBinsPt;i++)  printf(" %6.3f ",error[i]);
  printf("\n");
  printf("===============================================\n");
  
  TH1D* hAlpha = new TH1D("hAlpha","#alpha vs p_{t};p_{t} [GeV/c];#alpha",nBinsPt,rangePt);
  for (Int_t i=0;i<nBinsPt;i++) {
    hAlpha->SetBinContent(i+1,alpha[i]);
    hAlpha->SetBinError  (i+1,error[i]);
  }
  TCanvas* cAlpha = new TCanvas("cAlpha");
  cAlpha->cd();
  hAlpha->SetMinimum(-1);
  hAlpha->SetMaximum(1);
  hAlpha->SetLineColor(kBlue);
  hAlpha->SetLineWidth(1);
  hAlpha->GetXaxis()->SetRangeUser(0.,10.);
  hAlpha->Draw();
  
  TFile* recFile = new TFile(recFileName,"recreate");
  for (Int_t i=0;i<nBinsPt;i++){
    hAccCost[i]->Write();
    hAllCost[i]->Write();
    hRecCost[i]->Write();
    hResCost[i]->Write();
  }
  hAlpha->Write();
  recFile->Close();
}