Пример #1
0
void draw_R2m(void)
{
	const double er[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
	double ccnt[9];
	double eccnt[9];
	double dcnt[9];
	TGraphErrors *gr;
	TGraphErrors *grd;
	TH1D *hst;
	TH1D *hstd;
	double effUp, effDown, C, shift, size;
	double eeffUp, eeffDown, eC, eshift, esize;
	double fmin, fedm, errdef;
	int npari, nparx;
	int i, irc;
	char str[1024];
	TF1 *fR2;
	TVirtualPad *pd;
	
	gStyle->SetOptStat(0);
	gStyle->SetOptFit(0);
	
	MyMinuit = new TMinuit(5);
	MyMinuit->SetFCN(chi2fun);
	MyMinuit->DefineParameter(0, "Const", 1000, 10, 0, 1E10);
	MyMinuit->DefineParameter(1, "EffUp", 1, 0.1, 0.5, 1.5);
	MyMinuit->DefineParameter(2, "EffDown", 1, 0.1, 0.5, 1.5);
	MyMinuit->DefineParameter(3, "Shift", 0, 0.1, -10, 10);
	MyMinuit->DefineParameter(4, "Size", 3, 1, 0, 10);
	MyMinuit->FixParameter(3);
	MyMinuit->FixParameter(4);
	MyMinuit->Migrad();
	MyMinuit->GetParameter(0, C, eC);
	MyMinuit->GetParameter(1, effUp, eeffUp);
	MyMinuit->GetParameter(2, effDown, eeffDown);
	MyMinuit->GetParameter(3, shift, eshift);
	MyMinuit->GetParameter(4, size, esize);
	MyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, irc);

//		Renorm top and bottom sections to the middle
	for (i=0; i<3; i++) {
		ccnt[i] = DataArray.cnt[i] / effUp;
		ccnt[i+3] = DataArray.cnt[i+3];
		ccnt[i+6] = DataArray.cnt[i+6] / effDown;
		eccnt[i] = DataArray.ecnt[i] / effUp;
		eccnt[i+3] = DataArray.ecnt[i+3];
		eccnt[i+6] = DataArray.ecnt[i+6] / effDown;
	}
//	for (i=0; i<9; i++) printf("L = %8.3f    CNT = %6.1f +- %4.1f\n", r[i], cnt[i], ecnt[i]);
	gr = new TGraphErrors(9, DataArray.r, ccnt, er, eccnt);
	gr->SetLineColor(kBlue);
	gr->SetLineWidth(4);
	gr->SetMarkerStyle(20);
	gr->SetMarkerColor(kBlue);
	gr->SetMarkerSize(2);
	
	fR2 = new TF1("fR2", "[0] / ((x - [1]) * (x - [1]) - [2] * [2] / 4.0)", 1, 100);
	fR2->SetParameter(0, C);
	fR2->SetParameter(1, shift);
	fR2->SetParameter(2, size);
	fR2->SetLineColor(kRed);
	fR2->SetLineWidth(3);
	
	hst = new TH1D("H", ";Distance to reactor core center, m;Events per day", 35, 10, 13.5);
	hst->SetMinimum(DataArray.cnt[4] * 0.5);
	hst->SetMaximum(DataArray.cnt[4] * 1.5);
	hst->GetXaxis()->SetLabelSize(0.06);
	hst->GetYaxis()->SetLabelSize(0.06);
	hst->GetXaxis()->SetTitleSize(0.06);
	hst->GetYaxis()->SetTitleSize(0.06);
	hst->GetYaxis()->SetTitleOffset(1.25);

	hstd = new TH1D("H", ";Distance to reactor core center, m;Events per day", 35, 10, 13.5);
	hstd->SetMinimum(-40);
	hstd->SetMaximum(40);
	hstd->GetXaxis()->SetLabelSize(0.06);
	hstd->GetYaxis()->SetLabelSize(0.06);
	hstd->GetXaxis()->SetTitleSize(0.06);
	hstd->GetYaxis()->SetTitleSize(0.06);
	hstd->GetYaxis()->SetTitleOffset(1.25);
	
	TCanvas *cv = new TCanvas("CV", "R2", 800, 1200);
	cv->Divide(1, 2);
//		Do common fit and draw
	pd = cv->cd(1);
	pd->SetLeftMargin(0.15);
	pd->SetBottomMargin(0.15);
	pd->SetTopMargin(0.03);
	hst->Draw();
	gr->Draw("p");
	fR2->Draw("same");
	TLatex txt;
	txt.SetTextSize(0.07);
	sprintf(str, "#chi^{2}/n.d.f. = %6.2f/5", fmin);
	txt.DrawLatex(11.3, DataArray.cnt[4] * 1.3, str);
//		Draw difference
	for (i=0; i<9; i++) dcnt[i] = ccnt[i] - fR2->Eval(DataArray.r[i]);
	grd = new TGraphErrors(9, DataArray.r, dcnt, er, eccnt);
	grd->SetLineColor(kBlue);
	grd->SetLineWidth(4);
	grd->SetMarkerStyle(20);
	grd->SetMarkerColor(kBlue);
	grd->SetMarkerSize(2);
	
	pd = cv->cd(2);
	pd->SetLeftMargin(0.15);
	pd->SetBottomMargin(0.15);
	pd->SetTopMargin(0.03);
	hstd->Draw();
	grd->Draw("p");
}
Пример #2
0
void validation()
{
	msglvl[DBG] = SILENT;
	msglvl[INF] = VISUAL;
	msglvl[WRN] = VISUAL;
	msglvl[ERR] = VISUAL;
	msglvl[FAT] = VISUAL;

	TDirectory* oldDir = gDirectory; // remember old directory

	style();

	Int_t g4bin = (ng4bins/g4max+1); //==> g^4=1 ==> SSM !
	
	TString suffix = "";
	if(doTruth) suffix = "_truth";
	
	TString mctype  = (isMC11c) ? "mc11c" : "mc11a";
	
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_overallEWkF_noInAmpSigEWkF_noHighMbins_wthOfficialZP_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";

	TLegend* legR = new TLegend(0.15,0.75,0.35,0.85,NULL,"brNDC");
	legR->SetFillStyle(4000); //will be transparent
	legR->SetFillColor(0);
	legR->SetTextFont(42);
	TH1D* hDummy = new TH1D("","",1,0.,1.);
	hDummy->SetMarkerStyle(20);
	hDummy->SetMarkerSize(0.8);
	hDummy->SetMarkerColor(kBlack);
	if(!doResiduals) legR->AddEntry(hDummy,"#frac{template}{official}","lep");
	else             legR->AddEntry(hDummy,"#frac{template - official}{#sqrt{#delta^{2}template + #delta^{2}official}}","lep");
	
	TPaveText* ptxt = new TPaveText(0.145,0.35,0.245,0.55,"NDC");
	TText* txt;
	ptxt->SetTextSize(0.03);
	ptxt->SetBorderSize(0);
	ptxt->SetFillStyle(4000); //will be transparent
	ptxt->SetFillColor(0);
	ptxt->SetTextAlign(12);
	txt = ptxt->AddText("This range");
	txt = ptxt->AddText("is chopped");
	txt = ptxt->AddText("before the");
	txt = ptxt->AddText("template is");
	txt = ptxt->AddText("handed to");
	txt = ptxt->AddText("BAT (limit).");
	
	oldDir->cd();

	TString fBGname = "plots/validation/ZP_2dtemplates_mc11c_33st_noKKtmplates_wthOfficialZP_treeLevelMass_Xmass2000.root";
	TFile* fD = new TFile(fBGname,"READ");
	TH1D* hDY = NULL;
	if(doTruth) hDY = (TH1D*)fD->Get("hMass_DYmumu_truth")->Clone();
	else        hDY = (TH1D*)fD->Get("hMass_DYmumu")->Clone();
	hDY->SetLineColor(kMagenta-5);
	hDY->SetMarkerColor(kMagenta-5);

	oldDir->cd();

	TFile* fDYrozmin    = new TFile("plots/mass_plot_tables_3st.root","READ");
	TH1D* hDYrozmin = (TH1D*)fDYrozmin->Get("mass_log_dy")->Clone();
	hDYrozmin = (TH1D*)hGeV2TeV(hDYrozmin)->Clone();
	hDYrozmin = (TH1D*)hChopper(hDYrozmin,bins2chop)->Clone();
	oldDir->cd();
	TFile* f1dTemplates = new TFile("plots/ZpSignal_MM_MC11c_5points.root","READ");
	TObjArray* toarr1d = new TObjArray();
	toarr1d->Read("template");
	TMapTSP2TH1D h1dBrandeisTmpltMap;
	double Nflat = 399948;
	double sigmaflat = 4.3988E+07*nb2fb;
	double Lmcflat = Nflat/sigmaflat;
	double scale = luminosity/Lmcflat;
	TH1D* h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(0/*22*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(1/*28*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(2/*34*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(3/*40*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(4/*47*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();

	TMapTSP2TH1D h1Map;
	h1Map.insert( make_pair("1000o", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	h1Map.insert( make_pair("1000t", (TH1D*)fD->Get("hMass_Zprime_SSM1000_template"+suffix)->Clone()) );
	if(isMC11c)
	{
		h1Map.insert( make_pair("1250o", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
		h1Map.insert( make_pair("1250t", (TH1D*)fD->Get("hMass_Zprime_SSM1250_template"+suffix)->Clone()) );
	}
	h1Map.insert( make_pair("1500o", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1Map.insert( make_pair("1500t", (TH1D*)fD->Get("hMass_Zprime_SSM1500_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750o", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750t", (TH1D*)fD->Get("hMass_Zprime_SSM1750_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000o", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000t", (TH1D*)fD->Get("hMass_Zprime_SSM2000_template"+suffix)->Clone()) );

	TMapTSP2TH1D h1rMap;
	h1rMap.insert( make_pair("1000", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	if(isMC11c) h1rMap.insert( make_pair("1250", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1500", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1750", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1rMap.insert( make_pair("2000", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	for(TMapTSP2TH1D::iterator it=h1rMap.begin() ; it!=h1rMap.end() ; ++it)
	{
		it->second->Reset();
		if(!doResiduals) it->second->Divide(h1Map[it->first+"o"],h1Map[it->first+"t"],1.,1.,"B");
		else             residuals(h1Map[it->first+"o"], h1Map[it->first+"t"], it->second);
		
		// for(Int_t i=0 ; i<=it->second->GetNbinsX()+1 ; i++) it->second->SetBinError(i,0);
		it->second->SetMarkerStyle(20);
		it->second->SetMarkerSize(0.5);
		it->second->GetXaxis()->SetLabelSize(0.073);
		it->second->GetYaxis()->SetLabelSize(0.073);
		it->second->GetXaxis()->SetTitleSize(0.073);
		it->second->GetYaxis()->SetTitleSize(0.073);
		it->second->SetTitleSize(0.075);
		it->second->GetYaxis()->SetTitleOffset(0.5);
		if(!doResiduals)
		{
			it->second->SetMinimum(0.2);
			it->second->SetMaximum(1.8);
		}
		else
		{
			it->second->SetMinimum(-5.);
			it->second->SetMaximum(+5.);
		}
		it->second->SetTitle("");
		if(!doResiduals) it->second->GetYaxis()->SetTitle("ratio");
		else             it->second->GetYaxis()->SetTitle("residuals");
	}

	TMapTSP2TGAE poissonGraphMap;
	TMapTSP2TLeg legMap;


	_INFO("");

	oldDir->cd();

	fD->cd();	
	TH1D* h1Template = (TH1D*)fD->Get("hMass_DYmumu"+suffix)->Clone();
	h1Template->Reset();
	TObjArray* toarr = new TObjArray();
	if(doTruth) toarr->Read("truth_template2d");
	else        toarr->Read("template2d");
	TH2D* h2SSM2000 = (TH2D*)((TObjArray*)toarr->At(0))->Clone("hMass"+suffix+"_Zprime_SSM2000_template2d");
	for(Int_t bin=1 ; bin<=h2SSM2000->GetNbinsX() ; bin++)
	{
		h1Template->SetBinContent(bin, h2SSM2000->GetBinContent(bin,g4bin));
		h1Template->SetBinError(bin, h2SSM2000->GetBinError(bin,g4bin));
	}
	h1Template->SetLineColor(kViolet);
	h1Template->SetLineWidth(1);
	h1Template->SetMarkerStyle(20);
	h1Template->SetMarkerSize(0.3);
	h1Template->SetMarkerColor(kViolet);
	// the functions
	h2Template = (TH2D*)h2SSM2000->Clone();
	vector<TF1*> vfunc;
	unsigned int nmllbins = h2Template->GetNbinsX();
	for(unsigned int mll=1 ; mll<=(nmllbins-bins2chop) ; mll++) // 1...(56-9 = 47)
	{
		TString mllname = (TString)_s(mll);
		TString mllval  = (TString)_s(h2Template->GetXaxis()->GetBinCenter(mll+bins2chop));
		
		TF1* f = new TF1("fNominal_mll"+mllname,fTH1toTF1,g4min,g4max,1);
		f->SetParameter(0,mll);
		f->SetParNames("mll");
		// f->SetLineColor(kBlue);
		// f->SetLineWidth(1);
		f->SetNpx(400);
		vfunc.push_back(f);
	}
	TGraph* graphDY = new TGraph();
	graphDY->SetMarkerStyle(25);
	graphDY->SetMarkerSize(0.6);
	graphDY->SetMarkerColor(kGreen+2);
	TGraph* graphSSM = new TGraph();
	graphSSM->SetMarkerStyle(24);
	graphSSM->SetMarkerSize(0.6);
	graphSSM->SetMarkerColor(kOrange+8);
	for(unsigned int i=0 ; i<vfunc.size() ; i++)
	{
		double DY = vfunc[i]->Eval(0.0);
		double SSM = vfunc[i]->Eval(1.0);
		graphDY->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),DY);
		graphSSM->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),SSM);
	}
	
	
	oldDir->cd();

	TObjArray* toarr1dTLV = new TObjArray();
	TMapTSP2TH1D h1dTlvTmpltMap;
	TFile* fT = NULL;
	TString fTname = "plots/validation/ZP_2dtemplates_mc11c_33st_noInterference_noKKtmplates_noOverallEWkF_wthOfficialZP_treeLevelMass_Xmass";
	
	fT = new TFile(fTname+"1000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	fT = new TFile(fTname+"1250.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	fT = new TFile(fTname+"1500.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	fT = new TFile(fTname+"1750.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	fT = new TFile(fTname+"2000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();
	
	
	for(TMapTSP2TH1D::iterator it=h1Map.begin() ; it!=h1Map.end() ; ++it)
	{
		if(it->first.Contains("o"))
		{
			TString name = it->first;
			name.ReplaceAll("o","");
			it->second->SetFillColor(kAzure-9);
			if(doTruth) it->second->SetTitle("m_{Z'} = "+name+" GeV (truth)");
			else        it->second->SetTitle("m_{Z'} = "+name+" GeV");
		}
		if(it->first.Contains("t"))
		{
			//TGraphAsymmErrors* poisson(TH1D* h)
			it->second->SetLineColor(kBlue);
			it->second->SetMarkerStyle(20);
			it->second->SetMarkerSize(0.4);
			it->second->SetMarkerColor(kBlue);
			it->second->SetLineWidth(1);
			
			TString name = it->first;
			name.ReplaceAll("t","");
			poissonGraphMap.insert( make_pair(name, (TGraphAsymmErrors*)poisson(it->second)->Clone()) );
			poissonGraphMap[name]->SetMarkerStyle(20);
			poissonGraphMap[name]->SetMarkerSize(0.3);
			poissonGraphMap[name]->SetMarkerColor(kBlue);
			poissonGraphMap[name]->SetLineWidth(1);
			poissonGraphMap[name]->SetLineColor(kBlue);
		}
	}	

	Double_t yLine = (!doResiduals) ? 1. : 0.;

	TLine* line = new TLine(0.07,yLine,3.,yLine);	
	line->SetLineColor(kRed);
	line->SetLineWidth(2);
	
	TMapTSP2TCNV cnvMap;
	cnvMap.insert( make_pair("1000", new TCanvas("1000","1000",600,550)) );
	if(isMC11c) cnvMap.insert( make_pair("1250", new TCanvas("1250","1250",600,550)) );
	cnvMap.insert( make_pair("1500", new TCanvas("1500","1500",600,550)) );
	cnvMap.insert( make_pair("1750", new TCanvas("1750","1750",600,550)) );
	cnvMap.insert( make_pair("2000", new TCanvas("2000","2000",600,550)) );
	for(TMapTSP2TCNV::iterator it=cnvMap.begin() ; it!=cnvMap.end() ; ++it)
	{
		_INFO("starting "+(string)it->first);
		if(it->first=="2000") legMap.insert( make_pair(it->first, new TLegend(0.35,0.55,0.83,0.84,NULL,"brNDC")) );
		else                  legMap.insert( make_pair(it->first, new TLegend(0.35,0.60,0.83,0.84,NULL,"brNDC")) );
		legMap[it->first]->SetFillStyle(4000); //will be transparent
		legMap[it->first]->SetFillColor(0);
		legMap[it->first]->SetTextFont(42);
		legMap[it->first]->AddEntry(h1Map[it->first+"o"],"Official Z'_{SSM}","F");
		legMap[it->first]->AddEntry(hDY,"Official DY#mu#mu","lep");
		legMap[it->first]->AddEntry(h1Map[it->first+"t"],"ME^{2} method: Template w/o couplings scale","lep");
		if(it->first=="2000")
		{
			legMap[it->first]->AddEntry(h1Template,"ME^{2} method: Template histogram at  #it{g=1} (SSM)","lep");
			legMap[it->first]->AddEntry(graphSSM,  "ME^{2} method: Template function  at  #it{g=1} (SSM)","p");
			legMap[it->first]->AddEntry(graphDY,   "ME^{2} method: Template function  at  #it{g=0} (DY)","p");
		}
		if(!doTruth)
		{
			h1dTlvTmpltMap[it->first]->SetLineColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerStyle(5);
			h1dTlvTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dTlvTmpltMap[it->first],"ME^{2} method: DY+Template (no interference)","p");
		
			h1dBrandeisTmpltMap[it->first]->SetLineColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerStyle(27);
			h1dBrandeisTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dBrandeisTmpltMap[it->first],"Flat Z' method: DY+Template (no interference)","p");
		}

		it->second->Divide(1,2);
		TVirtualPad* ph = it->second->cd(1);
		TVirtualPad* pr = it->second->cd(2);	
		ph->SetPad(0.00, 0.35, 1.00, 1.00);
		pr->SetPad(0.00, 0.00, 1.00, 0.35);
		ph->SetBottomMargin(0.012);
		pr->SetBottomMargin(0.20);
		pr->SetTopMargin(0.012);
		
		ph->cd();
		ph->Draw();
		ph->SetTicks(1,1);
		ph->SetLogy();
		ph->SetLogx();
		// h1Map[it->first+"o"]->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		// h1Map[it->first+"o"]->Draw();
		TH1D* hTmpNoErr = (TH1D*)resetErrors(h1Map[it->first+"o"])->Clone();
		hTmpNoErr->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		hTmpNoErr->SetLineStyle(1);
		hTmpNoErr->SetLineColor(kBlack);
		hTmpNoErr->SetFillColor(kAzure-9);
		hTmpNoErr->Draw();
		TH1D* hTmpErr = (TH1D*)ShiftLog(h1Map[it->first+"o"],0.2)->Clone();
		hTmpErr->SetFillStyle(4000); //will be transparent
		hTmpErr->SetFillColor(0);
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		_INFO("");
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		
		TLine* chopline = new TLine(0.12805,getYmin(h1Map[it->first+"o"]),0.12805,7.e5);
		chopline->SetLineStyle(2);
		chopline->SetLineColor(kBlack);
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		
		legMap[it->first]->Draw("SAMES");
		ph->RedrawAxis();
		ph->Update();

		_INFO("");

		pr->cd();
		pr->Draw();
		pr->SetTicks(1,1);
		pr->SetGridy();
		pr->SetLogx();
		h1rMap[it->first]->Draw("ep");
		line->Draw("SAMES");
		h1rMap[it->first]->Draw("epSAMES");
		legR->Draw("SAMES");
		pr->RedrawAxis();
		pr->Update();

		unsigned int savestate = 1;
		if(it->first=="1000")      savestate = 0;
		else if(it->first=="2000") savestate = 2;
		else                       savestate = 1;
		TString testType = (doResiduals) ? "_residuals" : "_ratio";
		mutype   = (doTruth)     ? "_truth"     : "_recon";
		savemultipdf(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_all.pdf", savestate);
		saveas(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_"+it->first);
		
		TCanvas* c = new TCanvas(it->first,"",600,400);
		c->cd();
		c->Draw();
		c->SetTicks(1,1);
		c->SetLogy();
		c->SetLogx();
		hTmpNoErr->Draw();
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		legMap[it->first]->Draw("SAMES");
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		c->RedrawAxis();
		c->Update();
		saveas(c,"plots/validation/validation_"+it->first+"_"+mutype+testType);
		
		_INFO("done "+(string)it->first);
	}
}
Пример #3
0
void plot(char* v, int run, int cut, TCanvas* cvs, int fit=0, int bin1=-1, int bin2=-1, float ymax=0.0, int rebin=0){   
    int bin0=1;
    char c[100];
    char c2[100];
    readfile(OPT,run);
    gStyle->SetOptStat(0);
    gStyle->SetOptFit(0);
    gStyle->SetOptTitle(0);
    cvs->Clear();
    int b1=bin1, b2=bin1+1, b3=bin2, b4=b3;
    if(bin1<0) {cvs->Divide(kNPtBin-bin0,kNPtBin-bin0); b1=bin0; b2=kNPtBin; b3=bin0;}
    float ptcut[kNPtBin+1]={0.5,1.0,1.5,2.0,2.5,3.0,10.0};
    memset(PAR,0,sizeof(PAR));
    TText* t;
    for(int i=b1; i<b2; i++){
	if(bin1<0) b4=i;
	for(int j=b3; j<=b4; j++){
	    int cc=cut;
	    if(cut==99 && (v=="m1" || v=="m2")) cc=0;
	    if(cut==99 && v=="dphi") cc=1;
	    TH1F *h,*h2,*h3,*h4;
	    TH2F *h2d;

	    //get normalizations
	    float norm0=1.0;
	    float norm1=1.0;
	    float norm2=1.0;
	    float norm3=1.0;
	    if(v=="m0" || v=="phi0"){}
	    else{
		sprintf(c,"m0_%1d_c%d",i,cc);
		TH1F* h0 = (TH1F*)mTFile->Get(c);
		norm0 = h0->GetEntries();
		sprintf(c,"m2_%1d%1d_c%d",i,j,cc);
		TH1F* h1 = (TH1F*)mTFile->Get(c);
		norm1 = h1->GetEntries();
		printf("n0=%d n1=%d\n",norm0,norm1);
		norm2=norm1/norm0;
		norm3=norm2/ZggCut;
	    }

	    int opt=1, log=0;
	    if(v=="mix"){
		h3=mix(run,cc,i,j,0,1,h,h2);
		h1->SetLineColor(1);
		h2->SetLineColor(6);
	    }else if(v=="corr"){
		h = mix(run,cc,i,j,0,1);
		if(rebin>0) h->Rebin(rebin);
		if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0);
		int nbin = h->GetNbinsX();
                h->Sumw2();
                if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);}
                else       {h->Scale(1.0/norm0*nbin/2.0/PI);}
	    }else if(v=="norm"){
		sprintf(c,"dphi_%1d%1d_c%d",i,j,cc);
                h = (TH1F*)mTFile->Get(c);
		if(rebin>0) h->Rebin(rebin);
		if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0);
		int nbin = h->GetNbinsX();
		h->Sumw2();
		if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);}
		else       {h->Scale(1.0/norm0*nbin/2.0/PI);}
	    }else if(v=="mall"){
		sprintf(c,"m0_%1d_c%d",i,0);
		sprintf(c2,"m0_%1d%1d_c%d",i,j,0);
		h4 = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2);
		float norm4 = h4->Integral(h4->GetXaxis()->FindBin(MassCut0),h4->GetXaxis()->FindBin(MassCut1));
		h4->Scale(norm1/norm4);
		h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2);
		sprintf(c,"m0_%1d_c%d",i,cc);
		sprintf(c2,"m0_%1d%1d_c%d",i,j,cc);
		h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); h->SetLineColor(6);
		h->Scale(norm2); 
		sprintf(c,"m1_%1d%1d_c%d",i,j,cc);
                h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(2);
		sprintf(c,"m2_%1d%1d_c%d",i,j,cc); 
                h3 = (TH1F*)mTFile->Get(c); h3->SetLineColor(4);	   
	    }else if(v=="z12"){
		sprintf(c,"z1_%1d%1d_c%d",i,j,cc);
                h = (TH1F*)mTFile->Get(c); h->SetLineColor(2);
		sprintf(c,"z2_%1d%1d_c%d",i,j,cc); 
                h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(4);
	    }else if(v=="m0" || v=="phi0"){
		sprintf(c,"%s_%1d_c%d",v,i,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }else if(v=="bbce"){
		opt=1;
		log=1;
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
		h->SetMinimum(0.1);
	    }else if(v=="phi1" || v=="phi2"){
		opt=1;
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }else if(v=="phi1dphi"){
		opt=2;
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }else{
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }
	    if(bin1<0){
		TVirtualPad *pad = cvs->cd((i-bin0)*(kNPtBin-bin0)+(j-bin0)+1);
		pad->SetRightMargin(0.01);
		pad->SetLeftMargin(0);
		pad->SetTopMargin(0);
		pad->SetBottomMargin(0.01);
		pad->Draw();		
	    }
	    h->SetMinimum(0.0);
	    if(ymax>0.0) h->SetMaximum(ymax);
	    if(opt==0) h->Draw("e");
	    if(opt==1) h->Draw();
	    if(opt==2) h->Draw("colz");
	    if(v=="mall"){
		h4->Draw("same");
		h2->Draw("same");
		h3->Draw("same");
	    }
	    if(v=="z12" || v=="mix") h2->Draw("same");
	    TF1* f;
	    if((v=="norm" || v=="corr") && fit==1){
		f=new TF1("oneGaus",oneGaus,+PI/2.0,+PI*3.0/2.0,3);
		f->SetParameters(norm3/10.0,norm3/2.0,0.3);
		f->SetParNames("Const","IntFar","SigFar");
		f->SetParLimits(0,0.0,1.0);
		f->SetParLimits(1,0.0,1.0);
		f->SetParLimits(2,0.0,3.0);
		f->SetLineColor(2); f->SetLineWidth(1);
		h->Fit("oneGaus","Q");
		PAR[i][j][0]=f->GetParameter(0);
		PAR[i][j][1]=f->GetParameter(1);
		PAR[i][j][2]=f->GetParameter(2);
		printf("norm=%8.6f Int=%8.6f IntFar=%8.6 SigFar=%6.3f C=%8.6f\n",
		       norm3,PAR[i][j][1]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][2],PAR[i][j][0]);
	    }
	    if((v=="norm" || v="corr") && fit==2){
		f=new TF1("twoGaus",twoGaus,-PI/2.0,+PI*3.0/2.0,5);
		f->SetParameters(norm3/10.0,norm3/2.0,0.3,norm3/2.0,0.3);
		f->SetParNames("Const","IntNear","SigNear","IntFar","SigFar");
		f->SetParLimits(0,0.0,1.0);
		f->SetParLimits(1,0.0,1.0);
		f->SetParLimits(2,0.0,3.0);
		f->SetParLimits(3,0.0,1.0);
		f->SetParLimits(4,0.0,3.0);
		f->SetLineColor(2); f->SetLineWidth(1);
		h->Fit("twoGaus","Q");
		PAR[i][j][0]=f->GetParameter(0);
		PAR[i][j][1]=f->GetParameter(1);
		PAR[i][j][2]=f->GetParameter(2);
		PAR[i][j][3]=f->GetParameter(3);
		PAR[i][j][4]=f->GetParameter(4);
		printf("norm=%8.6f Int=%8.6f IntNear=%8.6f IntFar=%8.6f SigNear=%6.3f  SigFar=%6.3f C=%8.6f\n",
		       norm3,PAR[i][j][1]+PAR[i][j][3]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][3],
		       PAR[i][j][2],PAR[i][j][4],PAR[i][j][0]);
	    }

	    float xx=0.60, yy=0.85, dy=0.04, size=0.04;
	    if(bin1<0){xx=0.45, yy=0.90, dy=0.08, size=0.08;}
	    if(v=="z12") {xx=0.1; yy=0.35;}
	    t = new TText(xx, yy,    Form("pT1=%3.1f-%3.1f",ptcut[i],ptcut[i+1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    t = new TText(xx, yy-dy, Form("pT2=%3.1f-%3.1f",ptcut[j],ptcut[j+1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    if(norm3>0.0){
		t = new TText(xx, yy-dy*2, Form("P=%7.5f",norm3)); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    }
	    if((v=="norm" || v="corr")  && fit==1){
		t = new TText(xx, yy-dy*3, Form("PBg=%7.5f",  PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*5, Form("Saway=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    }
	    if((v=="norm" || v="corr")  && fit==2){
		t = new TText(xx, yy-dy*3, Form("Pnear=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][3])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*5, Form("PBg=%7.5f",  PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*6, Form("Snear=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*7, Form("Saway=%4.2f",PAR[i][j][4])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    }
	    if(cut==88) h->SetLineColor(2);
	    if(cut==99 && (v=="m1"|| v=="m2")){
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,1);
		h = (TH1F*)mTFile->Get(c);
		h->SetLineColor(4);
		h->Draw("same");
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,2);
		h = (TH1F*)mTFile->Get(c);
		h->SetLineColor(2);
		h->Draw("same");
	    }
	    if(cut==99 && v=="dphi"){
		h->SetLineColor(4);
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,2);
                h = (TH1F*)mTFile->Get(c);
                h->SetLineColor(2);
                h->Draw("same");		
	    }
	    if(bin1>0){
		t = new TText(0.1, 0.92,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(1); t->Draw();
		if     (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else                       {sprintf(c,"plot/dipi0_%d_%s_c%d_bin%d%d.png",run,v,cut,i,j);}
		printf("Saving %s\n",c);
		cvs->SaveAs(c);	       
	    }
	}
    }
    if(bin1<0){
	cvs->cd(2);
	t = new TText(0.0, 0.85,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(1); t->Draw();
    }
    if(v=="mall"){
	t = new TText(0.05, 0.65,"M1(no mass, scaled)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(1); t->Draw();
	t = new TText(0.05, 0.55,"M1(without M2)/P"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(6); t->Draw();
	t = new TText(0.05, 0.45,"M1(with M2)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw();
	t = new TText(0.05, 0.35,"M2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw();
    }
    if(v=="z12"){
	t = new TText(0.05, 0.65,"Zgg1"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw();
	t = new TText(0.05, 0.55,"Zgg2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw();
    }
    if(cut==99) {
	t = new TText(0.0, 0.65, "Inclusive Pair");  t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(4); t->Draw();
	t = new TText(0.0, 0.45, "Exclusive Pair");  t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(2); t->Draw();
    }
    if(bin1<0){
	if     (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d.png",v,cut);}
	else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d.png",v,cut);}
	else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d.png",v,cut);}
	else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d.png",v,cut);}
	else                       {sprintf(c,"plot/dipi0_%d_%s_c%d.png",run,v,cut);}
	printf("Saving %s\n",c);
	cvs->SaveAs(c);
    }
}
Пример #4
0
/** 
 * Draw the Poisson estimate of the occupancy
 * 
 * @param filename Input file name 
 * @param folder   Input folder name in file
 * 
 * @deprecated Use QATrender instead
 * @ingroup pwglf_forward_scripts_qa
 */
void
DrawOccupancy(const char* filename="forward.root", 
	      const char* folder="ForwardResults")
{
  gStyle->SetPalette(1);
  gStyle->SetOptFit(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  gStyle->SetTitleW(.4);
  gStyle->SetTitleH(.1);
  gStyle->SetTitleX(.4);
  // gStyle->SetTitleY(.1);
  gStyle->SetTitleColor(0);
  gStyle->SetTitleStyle(0);
  gStyle->SetTitleBorderSize(0);
  
  TFile* file = TFile::Open(filename, "READ");
  if (!file) { 
    Error("DrawOccupancy", "failed to open %s", filename);
    return;
  }

  TList* forward = static_cast<TList*>(file->Get(folder));
  if (!forward) { 
    Error("DrawOccupancy", "List %s not found in %s", folder, filename);
    return;
  }

  TList* dc = static_cast<TList*>(forward->FindObject("fmdDensityCalculator"));
  if (!dc) { 
    Error("DrawOccupancy", "List fmdDensityCalculator not found in Forward");
    return;
  }
  
  TCanvas* c = new TCanvas("occupancy", 
			   "Mean Occupancy", 900, 700);
  c->SetFillColor(0);
  c->SetBorderSize(0);
  c->SetBorderMode(0);
  c->SetHighLightColor(0);
  c->SetBottomMargin(.15);
  c->SetTopMargin(.02);
  c->SetRightMargin(.02);
  c->SetLeftMargin(.15);
  c->Divide(3, 2, 0, 0);
  

  Double_t corrs[5];
  c->cd(1); corrs[0] = DrawRingOccupancy(dc, 1, 'I');
  c->cd(2); corrs[1] = DrawRingOccupancy(dc, 2, 'I');
  c->cd(5); corrs[2] = DrawRingOccupancy(dc, 2, 'O');
  c->cd(3); corrs[3] = DrawRingOccupancy(dc, 3, 'I');
  c->cd(6); corrs[4] = DrawRingOccupancy(dc, 3, 'O');

  TVirtualPad* p = c->cd(4);
  p->SetTopMargin(0.05);
  p->SetRightMargin(0.10);
  p->SetLeftMargin(0.15);
  p->SetBottomMargin(0.15);
  p->SetFillColor(0);

  TH1D* hc = new TH1D("occ", "Mean occupancy", 5, .5, 5.5);
  hc->SetFillColor(kRed+1);
  hc->SetFillStyle(3001);
  hc->SetMinimum(0.0);
  hc->GetXaxis()->SetBinLabel(1,"FMD1i"); hc->SetBinContent(1,corrs[0]);
  hc->GetXaxis()->SetBinLabel(2,"FMD2i"); hc->SetBinContent(2,corrs[1]);
  hc->GetXaxis()->SetBinLabel(3,"FMD2o"); hc->SetBinContent(3,corrs[2]);
  hc->GetXaxis()->SetBinLabel(4,"FMD3i"); hc->SetBinContent(4,corrs[3]);
  hc->GetXaxis()->SetBinLabel(5,"FMD3o"); hc->SetBinContent(5,corrs[4]);
  hc->GetXaxis()->SetLabelSize(0.08);
  hc->GetYaxis()->SetTitle("#bar{occupancy}");
  hc->SetMarkerSize(1.5);
  hc->Draw("text hist");
  hc->SetMaximum(hc->GetMaximum()*1.5);

  // TH2D* highCuts = static_cast<TH2D*>(dc->FindObject("highCuts"));
  // if (highCuts) highCuts->Draw("colz");
  c->cd();
  c->SaveAs("occupancy.png");
}
void EstimateBg_76X(bool save=0, std::string in = "",
		std::string out = "/afs/cern.ch/user/j/jkarancs/public/NOTES/notes/AN-14-290/trunk/Plots/v1.0/", std::string ext="png") {
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  
  bool latex = save;
  
  bool ABCD_prime = 0;
  bool TT_only = 0;
  
  std::stringstream ss, ss2;
  ss<<DPHI_CUT; ss2<<R_CUT;
  std::string dphi_cut = ss.str().replace(ss.str().find("."),1,"p");
  std::string r_cut = ss2.str().replace(ss2.str().find("."),1,"p");
  
  std::string filename = in.size() ? in : 
    //"results/Plotter_out_2016_05_31_08h48m57_replot.root";
    "results/Plotter_out_2016_06_24_14h28m51.root";
  
  std::vector<std::string> samples[4];
  //samples[0].push_back("TTJetsMGHT");
  //samples[0].push_back("TTJetsMG");
  //samples[0].push_back("TTJetsNLOFXFX");
  //samples[0].push_back("TTNLO");
  //samples[0].push_back("TTNLOHerwig");
  //samples[0].push_back("TTPowheg");
  //samples[0].push_back("TTPowhegmpiOff");
  //samples[0].push_back("TTPowhegnoCR");
  //samples[0].push_back("TTPowhegHerwig");
  
  //+data+ samples[1].push_back("SingleElectron");
  //+data+ samples[1].push_back("SingleMuon");
  if (TT_only) {
    samples[1].push_back("TTJetsMGHT");
    samples[1].push_back("TTJetsMG");
    samples[1].push_back("TTJetsNLOFXFX");
    samples[1].push_back("TTNLO");
    samples[1].push_back("TTNLOHerwig");
    samples[1].push_back("TTPowheg");
    samples[1].push_back("TTPowhegmpiOFF");
    samples[1].push_back("TTPowhegnoCR");
    samples[1].push_back("TTPowhegHerwig");
  } else {
    samples[1].push_back("TTJetsMGHT");
    //samples[1].push_back("TTJetsMG");
    //samples[1].push_back("TTJetsNLOFXFX");
    //samples[1].push_back("TTNLO");
    //samples[1].push_back("TTNLOHerwig");
    //samples[1].push_back("TTPowheg");
    //samples[1].push_back("TTPowhegmpiOff");
    //samples[1].push_back("TTPowhegnoCR");
    //samples[1].push_back("TTPowhegHerwig");
    samples[1].push_back("ZJets");
    samples[1].push_back("TTX");
    samples[1].push_back("WJets");
    samples[1].push_back("Diboson");
    samples[1].push_back("Top");
    samples[1].push_back("QCD");
    //ZERO samples[1].push_back("TZQ");
    //ZERO samples[1].push_back("ZJetsToQQ"); // Also WJetsToQQ
    //ZERO samples[1].push_back("GJets");
  }
  //samples[1].push_back("Data");
  // NTop Sideband All background summed
  samples[2].push_back("All Bkg.");
    
  // Signal in NTop bins
  samples[3].push_back("T1tttt");
  
  bool baderror = false;
  double weight[] = { 0.32686, 0.0505037, 0.00921411, 6.80717, 0.354934, 0.00484915 };
  int rebin = /*(R_CUT*10-int(R_CUT*10))==0 ? 10 :*/ (R_CUT*20-int(R_CUT*20))==0 ? 5 : (R_CUT*50-int(R_CUT*50))==0 ? 2 : 1;
  double sideband_fit_low_range[] = { 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15 };
  
  int i_h_side[]   = { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  int i_h_signal[] = { 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  
  double scale_factors[] = { 1, 1, 1, 1, 1, 1, 1}; // All normal
  //double scale_factors[] = { /* TT */ 1, /* W */ 1, /* Z */ 1, /* T */ 1, /* TTV */ 1, /* QCD */ 2, /* VV */ 1 }; // QCD high
  //double scale_factors[] = { /* TT */ 5, /* W */ 1, /* Z */ 1, /* T */ 1, /* TTV */ 5, /* QCD */ 1, /* VV */ 1 }; // TT/TTV high
  //double scale_factors[] = { /* TT */ 1, /* W */ 2, /* Z */ 2, /* T */ 2, /* TTV */ 1, /* QCD */ 1, /* VV */ 2 }; // T/V/VV high
  
  Double_t Rranges_ABCD[][4] = 
    { { DPHI_CUT, 3.2, 0.0, DPHI_CUT  },
      { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 },
      { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 },
      { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 } };
  bool doFitting = false;
  double sum_a = 0, sum_b = 0, sum_c = 0, sum_d = 0, sum_d_abcd = 0, sum_d_nevt = 0;
  double sum_a_err = 0, sum_b_err = 0, sum_c_err = 0, sum_d_err = 0, sum_d_abcd_err = 0;
  double sum_b_fit = 0, sum_d_fit = 0, sum_d_fit_comb = 0;
  double sum_b_fit_err = 0, sum_d_fit_err = 0, sum_d_fit_comb_err = 0;
  double comb_d = 0, comb_d_err = 0, comb_d_abcd = 0, comb_d_abcd_err = 0;
  if (latex) {
    printf("\\begin{table*}[htbH]\n");
    printf("\\small\n");
    printf("\\begin{center}\n");
    printf("\\topcaption{Estimated Standard Model background yields in ABCD regions. A, B is in the sideband, C and D is the signal band, D is the signal region.\\label{tab:SMBkgEstimate}}\n");
    printf("\\begin{tabular}{lrrrrrrrr}\n");
  }
  TFile *f = TFile::Open(filename.c_str());
  for (size_t iMethod = 0; iMethod<4; ++iMethod) if (!(iMethod==0&&samples[0].size()==0)){
    // Print Top row for each method
    if (latex) {
      if (iMethod==0) {
        printf("\\hline\n");
        printf("Method 2 & A & B & C & D = B*C/A & D obs. & Ratio pred./obs. & Pull & KS test\\\\\n");
      }	else if (iMethod==1){
        printf("\\hline\n");
        printf("Method 1 & A & B & C & D = B*C/A & D obs. & Ratio pred./obs. & Pull & KS test\\\\\n");
      }
      printf("\\hline\n");
    } else {
      std::stringstream r_sb_cut;
      if (R_CUT_LOW==0) r_sb_cut<<"R<"<<R_CUT;
      else r_sb_cut<<R_CUT_LOW<<"<R<"<<R_CUT;
      const char* prime = ABCD_prime ? "'" : "";
      //if (iMethod==0) printf("| *Sample* | *A (DPhi>2.8, SB)* | *B (DPhi<2.8, SB)* | *C (DPhi>2.8, Sig.B.)* | - | *D = B*C/A pred.* | *D (DPhi<2.8, Sig.B.) obs.* | *Ratio pred./obs.* |\n");
      //else if (iMethod==1) printf("| *Sample* | *A (R<%1.1f, SB)* | *B (R>%1.1f, SB)* | *C (R<%1.1f, Sig.B.)* | *D = B (R fit, SB) * C/A pred.* | *D = B*C/A pred.* | *D (R>%1.1f, Sig.B.) obs.* | *Ratio pred./obs.* | \n", R_CUT, R_CUT, R_CUT, R_CUT);
      if (iMethod==0) printf("| *Sample* | *A (DPhi>%1.1f, %s)* | *B (DPhi<%1.1f, %s)* | *C (DPhi>%1.1f, R>0.4)* | *D = B*C/A pred.* | *D (DPhi<%1.1f, R>0.4) obs.* | *Ratio pred./obs.* | *Pull (pred-obs)/error* | *KS test* |\n", DPHI_CUT, r_sb_cut.str().c_str(), DPHI_CUT, r_sb_cut.str().c_str(), DPHI_CUT, DPHI_CUT);
      else if (iMethod==1) printf("| *Sample* | *A%s (%s, <2 tag)* | *B%s (R>%1.1f, <2 tag)* | *C%s (%s, 2 tag)* | *D%s = B%s*C%s/A%s pred.* | *D%s (R>%1.1f, 2 tag) obs.* | *Ratio pred./obs.* | *Pull (pred-obs)/error* | *KS test* |\n", prime, r_sb_cut.str().c_str(), prime, R_CUT, prime, r_sb_cut.str().c_str(), prime, prime, prime, prime, prime, R_CUT);
    }
    TH1D *h_side_sum, *h_signal_sum;
    for (size_t iSample = 0; iSample<samples[iMethod].size(); ++iSample)  {
      std::string canname = 
	iMethod==0 ? std::string("DPhiBins")+(ABCD_prime ? "/RBins_0To1HadTop_" : "/RBins_2HadTop_")+samples[iMethod][iSample] :
	iMethod==1 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_"+samples[iMethod][iSample] :
	iMethod==2 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_Background" :
	iMethod==3 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_"+samples[iMethod][iSample] : "";
      TCanvas *can = (TCanvas*)(f->Get(canname.c_str()));
      can = (TCanvas*)can->Clone();
      can->Draw();
      TH1D *h_side = (TH1D*)can->GetListOfPrimitives()->At(i_h_side[iMethod]);
      TH1D *h_signal = (TH1D*)can->GetListOfPrimitives()->At(i_h_signal[iMethod]);
      // Simulate different cross section by scaling a certain background
      if (iMethod==1) {
        TH1D *h_side_temp_scaled = (TH1D*)h_side->Clone(); h_side_temp_scaled->Scale(scale_factors[iSample]);
        TH1D *h_signal_temp_scaled = (TH1D*)h_signal->Clone(); h_signal_temp_scaled->Scale(scale_factors[iSample]);
        if (iSample==0) {
          h_side_sum = h_side_temp_scaled;
          h_signal_sum = h_signal_temp_scaled;
        } else {
          h_side_sum->Add(h_side_temp_scaled);
          h_signal_sum->Add(h_signal_temp_scaled);
        }
      } else if (iMethod==2) {
        h_side = h_side_sum;
        h_signal = h_signal_sum;
      }
      TH1D *h_pred =(TH1D*)h_side->Clone();
      if (iMethod!=0&&rebin>1) { h_side->Rebin(rebin); h_signal->Rebin(rebin); h_pred->Rebin(rebin); }
      TLegend *leg = (TLegend*)can->GetListOfPrimitives()->At(can->GetListOfPrimitives()->GetEntries()-1);
      leg->SetX1(0.35); leg->SetX2(0.65); leg->SetY1(0.6);
      
      // Add ratio plot
      int y1 = 350;
      int y2 = 150;
      int mid2 = 10;
      can->Divide(1,2);
      // Pad 1 (80+500+20 x 40+500)
      TVirtualPad* p = can->cd(1);
      p->SetPad(0,(y2+60+mid2)/(y1+y2+100.0+mid2),1,1);
      p->SetTopMargin(40.0/(y1+40));
      p->SetBottomMargin(0);
      p->SetRightMargin(0.05);
      p->SetLogy(1);
      h_side->GetYaxis()->SetRangeUser(1.00001e-4,1e4);
      h_side->Draw("HIST");
      h_signal->Draw("SAMEHISTE1");
      leg->Draw();
      // Pad 2 (80+500+20 x 200+60)
      p = can->cd(2);
      p->SetGrid(0,1);
      p->SetPad(0,0,1,(y2+60+mid2)/(y1+y2+100.0+mid2));
      p->SetTopMargin(((float)mid2)/(y2+60+mid2));
      p->SetBottomMargin(60.0/(y2+60+mid2));
      p->SetRightMargin(0.05);
      TH1D* ratio = (TH1D*)h_signal->Clone();
      TH1D* div = (TH1D*)h_side->Clone();
      //ratio->Scale(1/ratio->GetSumOfWeights());
      double sum_bins_ratio = iMethod==0 ? ratio->Integral():
	ratio->Integral(ratio->FindBin(R_CUT_LOW),ratio->FindBin(Rranges_ABCD[iMethod][3]));
      ratio->Scale(1/sum_bins_ratio);
      ratio->SetTitleSize(32.0/(y2+60+mid2),"xyz");
      ratio->SetLabelSize(20.0/(y2+60+mid2),"xyz");
      //ratio->Scale(1/div->GetSumOfWeights());
      double sum_bins_div = iMethod==0 ? div->Integral():
	div->Integral(div->FindBin(R_CUT_LOW),div->FindBin(Rranges_ABCD[iMethod][3]));
      div->Scale(1/sum_bins_div);
      ratio->Divide(div);
      //ratio->GetYaxis()->SetRangeUser(0,2);
      ratio->GetXaxis()->SetTitleOffset(0.7);
      ratio->GetYaxis()->SetNdivisions(305);
      ratio->GetYaxis()->SetTitle("Ratio (Norm.)");
      ratio->GetYaxis()->SetTitleOffset(0.4);
      ratio->SetTitleSize(24.0/(y2+60+mid2),"y");
      ratio->SetTitle("");
      ratio->SetMarkerStyle(20);
      ratio->SetMarkerColor(1);
      ratio->SetLineColor(1);
      ratio->GetYaxis()->SetRangeUser(0,4);
      ratio->Draw("PE1");
      TLine* l = new TLine(ratio->GetXaxis()->GetXmin(), 1, ratio->GetXaxis()->GetXmax(), 1);
      l->SetLineWidth(2);
      //l->SetLineColor(2);
      l->SetLineStyle(2);
      l->Draw();
      gPad->Update();
      // Fit ratio
      //TF1 *fit_ratio;
      //if (iMethod==1) {
      //  fit_ratio = new TF1("fit_ratio","pol0", Rranges_ABCD[iMethod][0], Rranges_ABCD[iMethod][1]);
      //  fit_ratio->SetLineColor(1);
      //  ratio->Fit("fit_ratio","RE");
      //  fit_ratio->SetRange(Rranges_ABCD[iMethod][0], Rranges_ABCD[iMethod][2]);
      //  fit_ratio->Draw("SAME");
      //}
      p = can->cd(1);
      
      // calculate integrals
      double integral[2][2] = { { 0, 0 }, { 0, 0 } };
      double integral_error[2][2] = { { 0, 0 }, { 0, 0 } };
      double nevt[2][2] = { { 0, 0 }, { 0, 0 } };
      //std::cout<<samples[iMethod][iSample]<<":"<<std::endl;
      for (int i=0; i<2; ++i) {
        for (int bin=1; bin<=h_side->GetNbinsX(); ++bin) {
          if (h_signal->GetXaxis()->GetBinLowEdge(bin)>=Rranges_ABCD[iMethod][i*2] && 
              h_signal->GetXaxis()->GetBinUpEdge(bin)<=Rranges_ABCD[iMethod][i*2+1]) {
	    //std::cout<<bin<<"="<<h_side->GetBinCenter(bin);
	    //if (i==0) std::cout<<" in, ";
	    //else std::cout<<" out, ";
            double c0 = h_side->GetBinContent(bin), c1 = h_signal->GetBinContent(bin);
            double e0 = h_side->GetBinError(bin),   e1 = h_signal->GetBinError(bin);
            //std::cout<<h_signal->GetBinError(bin)<<" "<<sqrt(c1*weight[iSample])<<std::endl;
            if (baderror&&iMethod==1) {
              e0 = sqrt(c0*weight[iSample]);
              e1 = sqrt(c1*weight[iSample]);
            }
            nevt[0][i] += (int)(c0*c0/(e0*e0) + 0.5);
            nevt[1][i] += (int)(c1*c1/(e1*e1) + 0.5);
            integral[0][i] += c0;
            integral[1][i] += c1;
            //if (iMethod==1) { // weight bin by projected ratio (correction)
            //  double bincent = h_signal->GetXaxis()->GetBinLowEdge(bin);
            //  integral[0][1] *= fit_ratio->Eval(bincent);
            //}
            integral_error[0][i] += e0*e0;
            integral_error[1][i] += e1*e1;
            //if (iSample==0&&e1>0) std::cout<<bin<<" "<<c1<<" +- "<<e1*e1<<" nevt = "<<((int)(c1*c1/(e1*e1) + 0.5))<<std::endl;
          }
        }
        //if (iSample==1&&i==1) std::cout<<integral[1][i]<<" +- "<<integral_error[1][i]<<std::endl;
        integral_error[0][i] = sqrt(integral_error[0][i]);
        integral_error[1][i] = sqrt(integral_error[1][i]);
      }
      //std::cout<<nevt[1][1]<<std::endl;
      
      // predict yields using 2 methods (ABCD and constrained R-shape fit method combined)
      // ABCD method
      double a = integral[0][0], b = integral[0][1], c = integral[1][0], d = integral[1][1];
      double a_err = integral_error[0][0], b_err = integral_error[0][1], c_err = integral_error[1][0], d_err = integral_error[1][1];
      // Calculate error
      // z = x / y -> z_err = sqrt( (x*x*y_err*y_err + y*y*x_err*x_err)/(y*y*y*y) )
      // z = x * y -> z_err = sqrt ( x*x*y_err*y_err + y*y*x_err*x_err )
      double c_per_a_err = sqrt((c*c*a_err*a_err + a*a*c_err*c_err)/(a*a*a*a));
      double d_abcd = b * (c/a), d_abcd_err = sqrt(b*b*c_per_a_err*c_per_a_err + (c/a)*(c/a)*b_err*b_err);
      double d_nevt = nevt[1][1];
      double d_ratio = d_abcd / d;
      double d_ratio_err = sqrt((d_err/d)*(d_err/d) + (d_abcd_err/d_abcd)*(d_abcd_err/d_abcd))*d_ratio;
      double d_pull = (d_abcd-d)/sqrt(d_abcd_err*d_abcd_err + d_err*d_err);
      // Scaled plot
      h_pred->Scale(c/a);
      h_pred->SetLineColor(1);
      h_pred->SetLineStyle(2);
      h_pred->Draw("SAMEHIST");
      leg->AddEntry(h_pred, "Prediction (ABCD)", "l");
      
      double fit_integral[2][2], fit_integral_error[2][2], d_fit_comb = 0, d_fit_comb_err = 0;
      if (iMethod==1) {
	// Fit in the full range of NTop Sideband
	// Do fitting and calculate integrals
	TF1 *fit_side = new TF1("NTopSide_fit","exp([0]+[1]*x)", iMethod==2 ? 0.2 : sideband_fit_low_range[iSample], Rranges_ABCD[iMethod][3]);
        fit_side->SetLineColor(h_side->GetLineColor());
        h_side->Fit("NTopSide_fit","QRE");
        //fit_side->Draw("SAME");
        double Rranges_ACfit[3] = { sideband_fit_low_range[iSample], Rranges_ABCD[iMethod][2], Rranges_ABCD[iMethod][3] };
        for (int i=0; i<2; ++i) {
          fit_integral[0][i] = fit_side->Integral(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
          fit_integral_error[0][i] = fit_side->IntegralError(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
        }
        double par0 = fit_side->GetParameter(0), par0_error = fit_side->GetParError(0);
        double par1 = fit_side->GetParameter(1), par1_error = fit_side->GetParError(1);
        double par1min, par1max; fit_side->GetParLimits(1, par1min, par1max);
	
        // Fit in the Signal region
        // Fitting in sideband, get B area under curve and scale by C/A
        TF1 *fit_signal = new TF1("NTopSignal_RSide_fit","exp([0]+[1]*x)", Rranges_ACfit[0], Rranges_ABCD[iMethod][3]);
        fit_signal->SetLineColor(h_signal->GetLineColor());
        //fit_signal->SetParameter(1, par1); 
        //fit_signal->SetParLimits(1, par1min, par1max);
        h_signal->Fit("NTopSignal_RSide_fit","QREB");
        //fit_signal->Draw("SAME");
        for (int i=0; i<2; ++i) {
          fit_integral[1][i] = fit_signal->Integral(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
          fit_integral_error[1][i] = fit_signal->IntegralError(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
        }
        d_fit_comb = fit_integral[0][1] * (c/a);
        d_fit_comb_err = sqrt(fit_integral[0][1]*fit_integral[0][1]*c_per_a_err*c_per_a_err + (c/a)*(c/a)*fit_integral_error[0][1]*fit_integral_error[0][1]);
        TF1 *fit_pred = new TF1("Predicted_fit","exp([0]+[1]*x)", Rranges_ACfit[0], Rranges_ACfit[2]);
        fit_pred->SetLineColor(1);
        fit_pred->SetLineStyle(2);
        fit_pred->FixParameter(0, par0+std::log(c/a)); 
        fit_pred->FixParameter(1, par1); 
        h_signal->Fit("Predicted_fit","QREB+");
        //fit_pred->Draw("SAME");
      }
      // Save plot
      if (iMethod==3) samples[iMethod][iSample] = "T1tttt";
      std::string name = samples[iMethod][iSample];
      if (iMethod==2) name = "AllBkg";
      if (save)	can->SaveAs((out+"BkgEst/ABCD_closure_"+name+"."+ext).c_str());
      
      // Check compatibility of prediction to observed distribution
      double ks_test = h_pred->KolmogorovTest(h_signal);
      
      if (iMethod==1) {
	sum_a += a; sum_b += b; sum_c += c; sum_d += d;
	sum_a_err += a_err*a_err; sum_b_err += b_err*b_err; sum_c_err += c_err*c_err; sum_d_err += d_err*d_err;
	sum_d_abcd += d_abcd; sum_d_abcd_err += d_abcd_err*d_abcd_err;
	sum_b_fit += fit_integral[0][1]; sum_b_fit_err += fit_integral_error[0][1]*fit_integral_error[0][1];
	sum_d_fit += fit_integral[1][1]; sum_d_fit_err += fit_integral_error[1][1]*fit_integral_error[1][1];
	sum_d_fit_comb += d_fit_comb; sum_d_fit_comb_err += d_fit_comb_err*d_fit_comb_err;
	sum_d_nevt += d_nevt;
	//printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |\n", d_fit_comb, d_fit_comb_err, d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err);
      }
      if (latex) {
	printf("%s &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &", samples[iMethod][iSample].c_str(), a, a_err, b, b_err, c, c_err);
	printf("  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  %.2f &  %.2f \\\\\n", d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err, d_pull, ks_test);
      } else {
	printf("| %s |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |", samples[iMethod][iSample].c_str(), a, a_err, b, b_err, c, c_err);
	printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f |  %.2f |\n", d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err, d_pull, ks_test);
      }
      // Combining best methods
      if ((iMethod==0&&iSample==0)||(iMethod==1&&iSample!=0)) {
	comb_d_abcd += d_abcd; comb_d += d; comb_d_abcd_err += d_abcd_err*d_abcd_err; comb_d_err += d_err*d_err;
      }
    }
    if (iMethod==1) {
      sum_a_err = sqrt(sum_a_err); sum_b_err = sqrt(sum_b_err); sum_c_err = sqrt(sum_c_err); sum_d_err = sqrt(sum_d_err);
      sum_b_fit_err = sqrt(sum_b_fit_err); sum_d_fit_err = sqrt(sum_d_fit_err); sum_d_fit_comb_err = sqrt(sum_d_fit_comb_err);
      double sum_d_ratio = sum_d_abcd / sum_d;
      double sum_d_ratio_err = sqrt((sum_d_err/sum_d)*(sum_d_err/sum_d) + (sum_d_abcd_err/sum_d_abcd)*(sum_d_abcd_err/sum_d_abcd))*sum_d_ratio;
      double sum_d_pull = (sum_d_abcd-sum_d)/sqrt(sum_d_abcd_err*sum_d_abcd_err + sum_d_err*sum_d_err);
      if (latex) {
	printf("\\hline\n");
	printf("Sum Bkg. &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &", sum_a, sum_a_err, sum_b, sum_b_err, sum_c, sum_c_err);
	printf("  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  %.2f & \\\\\n", sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err, sum_d_pull);
      } else {
	//printf("| Sum Bkg.|  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |", sum_a, sum_a_err, sum_b_fit, sum_b_fit_err, sum_b, sum_b_err, sum_c, sum_c_err);
	printf("| Sum Bkg.|  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |", sum_a, sum_a_err, sum_b, sum_b_err, sum_c, sum_c_err);
	//printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |\n", sum_d_fit_comb, sum_d_fit_comb_err, sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err);
	printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f |  - |\n", sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err, sum_d_pull);
      }
    } else if (iMethod==2&&samples[0].size()) {
      double comb_d_ratio = comb_d_abcd / comb_d;
      double comb_d_ratio_err = sqrt((comb_d_err/comb_d)*(comb_d_err/comb_d) + (comb_d_abcd_err/comb_d_abcd)*(comb_d_abcd_err/comb_d_abcd))*comb_d_ratio;
      double comb_d_pull = (comb_d_abcd-comb_d)/sqrt(comb_d_abcd_err*comb_d_abcd_err + comb_d_err*comb_d_err);
      if (latex) {
	printf("\\hline\n");
	printf("\\hline\n");
	printf("Combined Bkg. & & & &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  %.2f & \\\\\n", comb_d_abcd, comb_d_abcd_err, comb_d, comb_d_err, comb_d_ratio, comb_d_ratio_err, comb_d_pull);
	printf("\\hline\n");
      } else {
	printf("| Combined Bkg.| | | |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f | - |\n", comb_d_abcd, comb_d_abcd_err, comb_d, comb_d_err, comb_d_ratio, comb_d_ratio_err, comb_d_pull);
      }
    }
  }
  if (latex) {
    printf("\\hline\n");
    printf("\\end{tabular}\n");
    printf("\\end{center}\n");
    printf("\\end{table*}\n");
  }

  if (save) gApplication->Terminate();
}