Esempio n. 1
0
void fill_stack_eventcategories(TString variable_name, TString data_name, std::vector<TString> signal_names, std::vector<TString> names){
    TString canvas_name=variable_name+"_stack_canvas";
    CreateCanvas(canvas_name,"",900,600);
    TString stack_name=variable_name+"_stack";
    CreateStack(stack_name,"");

    int Nbkg=names.size();
    
    vector<int> colors;
    colors.push_back(4);
    colors.push_back(9);
    colors.push_back(5);
    colors.push_back(419);
    
    colors.push_back(7);
    if(colors.size()<Nbkg) {
        cout << "please specify colors" << endl;
        return;
    }
    
    TLegend *L = new TLegend(0.6,0.57,0.89,0.89);
	L->SetFillColor(10);
	L->SetLineColor(10);
	L->SetLineWidth(0);
    
    for(int ibkg=0; ibkg<Nbkg; ibkg++){
        TString histName=variable_name+names.at(ibkg);
        hName[histName]->SetFillColor(colors.at(ibkg));
        stackName[stack_name]->Add(hName[histName]);
        L->AddEntry(hName[histName], names.at(ibkg));
    }
    
    
	TString eventspad_name="eventspad_"+variable_name;
	TString ratiopad_name="ratiopad_"+variable_name;
	
	TPad *events_pad = new TPad(eventspad_name,"Events",0.0,0.3,1,1);
	TPad *ratio_pad = new TPad(ratiopad_name,"Ratio",0,0.,1,0.3);
	
	events_pad->SetTopMargin(0.1);
	events_pad->SetBottomMargin(0.05);
	ratio_pad->SetTopMargin(0.05);
	ratio_pad->SetBottomMargin(0.3);
	
	CName[canvas_name]->cd();
	events_pad->Draw();
	ratio_pad->Draw();
	
	events_pad->cd();
    gPad->SetLogy();
    
    hName[variable_name+data_name]->GetYaxis()->SetTitleOffset(0.65);
    hName[variable_name+data_name]->GetYaxis()->SetTitleSize(0.08);
    hName[variable_name+data_name]->GetYaxis()->SetLabelSize(0.05);
    hName[variable_name+data_name]->GetXaxis()->SetLabelSize(0);
    hName[variable_name+data_name]->GetXaxis()->SetTitleSize(0);
    
    hName[variable_name+data_name]->SetMarkerSize(0.5);
    hName[variable_name+data_name]->SetMarkerStyle(20);
    hName[variable_name+data_name]->DrawCopy("E1");
    stackName[stack_name]->DrawClone("histo same");
    hName[variable_name+data_name]->DrawCopy("E1 same");// draw data on top of MC and MC on top of data, so that data will always be visible

    
    TLatex txt;
    txt.SetNDC(kTRUE);
    txt.DrawLatex(0.2,0.85,"S_{T} > 300 GeV");
    txt.DrawLatex(0.4,0.75,"S_{T} > 500 GeV");
    txt.DrawLatex(0.65,0.42,"S_{T} > 1000 GeV");

    
    for(int isig=0; isig<signal_names.size();isig++){
        TString sigName=variable_name+signal_names.at(isig);
        hName[sigName]->SetLineWidth(3);
        hName[sigName]->SetLineStyle(kDashed);
        hName[sigName]->SetLineColor(1+isig);
        L->AddEntry(hName[sigName], signal_names.at(isig));
        hName[sigName]->DrawCopy("hist same");
    }
    L->DrawClone("same");
    ratio_pad->cd();
    TString dataMC=variable_name+"_RatioDataMC";

    hName[dataMC]->GetYaxis()->SetTitleOffset(0.45);
	hName[dataMC]->GetYaxis()->SetTitleSize(0.15);
	hName[dataMC]->GetYaxis()->SetTitleOffset(0.45);
	hName[dataMC]->GetYaxis()->SetLabelSize(0.08);
	
	
	hName[dataMC]->GetXaxis()->SetTitleSize(0.15);
	hName[dataMC]->GetXaxis()->SetLabelSize(0.12);
	hName[dataMC]->GetXaxis()->SetTitleSize(0.15);
    
    hName[dataMC]->DrawCopy("E1");
    
}
Esempio n. 2
0
void figure2_0_generator(){

	TFile *f;

	const int NAchBins = 7;

	const double correction = 0.687;
	//const double correction = 1.0;

	TH1D* c2_pos[NAchBins][2];
	TH1D* c2_neg[NAchBins][2];

	TH1D* ach_hist[NAchBins];
	double x[NAchBins];
	double v2_pos[NAchBins];
	double v2_neg[NAchBins];
	double v2_diff[NAchBins];
	double err_neg[NAchBins];
	double err_pos[NAchBins];
	double err_diff[NAchBins];
	double cmean;
	double errmean;
	double sum;
	double variance_pos;
	double variance_neg;
	double variance_diff;


	//f = new TFile("../../../rootfiles/systematics/trackselection/loose/Merged.root");
	//f = new TFile("../../../rootfiles/systematics/trackselection/tight/Merged.root");
	//f = new TFile("../../../rootfiles/systematics/vtz/wide/Merged.root");
	//f = new TFile("../../../rootfiles/systematics/vtz/narrow/Merged.root");
	//f = new TFile("../../../rootfiles/crosscheck/PbPb/v2/ntrk/185_220/Merged.root");
	//f = new TFile("../../../rootfiles/systematics_redo/v2_Cumulant_40.root");


	f = new TFile("~/Summer2016/rootfiles/FinalResult_0106/Main_pPb_Merged.root");

	// = new TFile("../../../rootfiles/closure/pPb/185_220/Merged.root");



	for (Int_t i = 0; i < NAchBins; i++){
		ach_hist[i] = (TH1D*)f->Get(Form("demo_n3/ach_%d",i+1));

		c2_pos[i][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_cos",i));
		c2_pos[i][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_sin",i));

		c2_neg[i][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_cos",i));
		c2_neg[i][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_sin",i));
		
	}
	for(Int_t i=0; i<NAchBins; i++){

		x[i]=ach_hist[i]->GetMean();
		x[i] *= correction; 

//v2 positive
		cmean = c2_pos[i][0] -> GetMean();
		v2_pos[i] = sqrt(cmean);

		errmean = c2_pos[i][0] -> GetMeanError();
		variance_pos = (errmean*errmean)/(4*cmean);

//negative
		cmean = c2_neg[i][0] -> GetMean();
		v2_neg[i] = sqrt(cmean);

		errmean = c2_neg[i][0] -> GetMeanError();
		variance_neg = (errmean*errmean)/(4*cmean);

		//difference
		v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]);

		sum = v2_pos[i] + v2_neg[i];

		variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum);


	//error bars

		cout << "xcoord " << x[i] << endl;

		err_pos[i] = sqrt(variance_pos);
		err_neg[i] = sqrt(variance_neg);
		err_diff[i] = sqrt(variance_diff);


	}
	
	gStyle->SetLegendFont(42);
	TH1D* base = new TH1D("base","base",1,-0.15,0.15);
	//pPb
	//base->GetYaxis()->SetRangeUser(0.065, 0.075);
	base->GetYaxis()->SetRangeUser(0.065, 0.075);

	//PbPb
	//base->GetYaxis()->SetRangeUser(0.093, 0.103);
	base->GetXaxis()->SetTitle("Observed A_{ch}");
	base->GetYaxis()->SetTitle("v_{2}{2}");
	base->GetXaxis()->CenterTitle();
	base->GetYaxis()->CenterTitle();
	base->SetTitleSize  (0.040,"X");
	base->SetTitleOffset(1.4,"X");
	base->SetTitleFont  (42,"X");
	base->SetLabelOffset(0.006,"X");
	base->SetLabelSize  (0.040,"X");
	base->SetLabelFont  (42   ,"X");

	base->SetTitleSize  (0.040,"Y");
	base->SetTitleOffset(2.2,"Y");
	base->SetTitleFont  (42,"Y");
	base->SetLabelOffset(0.006,"Y");
	base->SetLabelSize  (0.040,"Y");
	base->SetLabelFont  (42   ,"Y");
	base->SetLineWidth(0);

	TH1D* base2 = new TH1D("base2","base2",1,-0.15,0.15);
	base2->GetYaxis()->SetRangeUser(-0.03, 0.03);
	base2->GetXaxis()->SetTitle("Observed A_{ch}");
	base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) ");
	base2->GetXaxis()->CenterTitle();
	base2->GetYaxis()->CenterTitle();
	base2->SetTitleSize  (0.040,"X");
	base2->SetTitleOffset(1.4,"X");
	base2->SetTitleFont  (42,"X");
	base2->SetLabelOffset(0.006,"X");
	base2->SetLabelSize  (0.040,"X");
	base2->SetLabelFont  (42   ,"X");
	base2->SetTitleSize  (0.040,"Y");
	base2->SetTitleOffset(2.0,"Y");
	base2->SetTitleFont  (42,"Y");
	base2->SetLabelOffset(0.006,"Y");
	base2->SetLabelSize  (0.040,"Y");
	base2->SetLabelFont  (42   ,"Y");
	base2->SetLineWidth(0);

	TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure2_0.root","RECREATE");


	TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos);
	TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg);
	TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff);

	gr_pos->Write();
	gr_neg->Write();
	gr_diff->Write();



 //   TCanvas* c1 = new TCanvas("c1","c1");
 //   TCanvas* c2 = new TCanvas("c2","c2");
	TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600);
	c3->Divide(2,1,0.01,0.01);

	gr_neg -> SetMarkerStyle(20);
	gr_neg -> SetMarkerColor(kBlue);
	gr_pos -> SetMarkerStyle(34);	
	gr_pos -> SetMarkerColor(kRed);




	TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ;
	//TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 220",0.25,0.80) ;
	TLatex* text_b = makeLatex("30-40%",0.25,0.80) ;

	TLatex* text_c = makeLatex("0.8 < p_{T} < 0.85 GeV/c",0.25,0.75) ;
	TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.70) ;

	text_a->SetTextFont(42);
	text_b->SetTextFont(42);
	text_c->SetTextFont(42);
	text_d->SetTextFont(42);



	TLegend* leg = new TLegend(0.76,0.80,0.94,.88);
	leg->SetLineColor(kWhite);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);
	leg->AddEntry(gr_pos, "v_{2}^{#plus}{2}","p");
	leg->AddEntry(gr_neg , "v_{2}^{#minus}{2}","p");



	c3->cd(1);
	base->Draw("");
	gr_pos->Draw("PSame");
	gr_neg->Draw("PSame");
	text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	text_c->DrawClone("Same");
	text_d->DrawClone("Same");

	leg->DrawClone("Same");


    //Define a linear function
	TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.13, 0.13);

	fit1->SetLineColor(kRed);
	fit1->SetLineStyle(2);
	gr_diff->Fit(fit1,"RN0");
	fit1->Write();


	rebinned->Close();

	c3->cd(2);



	TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ;
	TLatex* text1 = makeLatex(Form("slope : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ;
	text1->SetTextFont(42);
	text2->SetTextFont(42);
	base2->Draw("");
	fit1->DrawClone("Same");
	gr_diff->SetMarkerStyle(20);
	gr_diff->Draw("PSame");

	text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	

	text1->DrawClone("Same");
	text2->DrawClone("Same");

	

	TF1 *fa1 = new TF1("fa1","0",-10,10); 
	fa1->SetLineColor(kBlack);
	fa1->SetLineWidth(0);
	fa1->DrawClone("Same");

	TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78);
	leg2->SetLineColor(kWhite);
	leg2->SetFillColor(0);
	leg2->SetFillStyle(0);
	leg2->AddEntry(fit1, "Linear fit","l");
	leg2->AddEntry(gr_diff , "data","p");
	leg2->DrawClone("Same");

	//SaveCanvas(c3,"pics",Form("30-40Narrowpt"));




}
Esempio n. 3
0
void getAiZ() 
{
  TFile *data1 = new TFile("results/CSFrame_ZJets_madgraph_0_inf_plus.root");
  TFile *data2 = new TFile("results/CSFrame_ZJets_madgraph_0_inf_minus.root");

  TString HistPA0 = "MC_CSFramePlots_0toinf/MC_CSWPlusA0Numerator";
  TString HistPA1 = "MC_CSFramePlots_0toinf/MC_CSWPlusA1Numerator";
  TString HistPA2 = "MC_CSFramePlots_0toinf/MC_CSWPlusA2Numerator";
  TString HistPA3 = "MC_CSFramePlots_0toinf/MC_CSWPlusA3Numerator";
  TString HistPA4 = "MC_CSFramePlots_0toinf/MC_CSWPlusA4Numerator";
  TString HistPD = "MC_CSFramePlots_0toinf/MC_CSWPlusAiDenominator";

  TString HistMA0 = "MC_CSFramePlots_0toinf/MC_CSWMinusA0Numerator";
  TString HistMA1 = "MC_CSFramePlots_0toinf/MC_CSWMinusA1Numerator";
  TString HistMA2 = "MC_CSFramePlots_0toinf/MC_CSWMinusA2Numerator";
  TString HistMA3 = "MC_CSFramePlots_0toinf/MC_CSWMinusA3Numerator";
  TString HistMA4 = "MC_CSFramePlots_0toinf/MC_CSWMinusA4Numerator";
  TString HistMD = "MC_CSFramePlots_0toinf/MC_CSWMinusAiDenominator";

  TH1D *hPA0 = (TH1D*)data1->Get(HistPA0);
  TH1D *hPA1 = (TH1D*)data1->Get(HistPA1);
  TH1D *hPA2 = (TH1D*)data1->Get(HistPA2);
  TH1D *hPA3 = (TH1D*)data1->Get(HistPA3);
  TH1D *hPA4 = (TH1D*)data1->Get(HistPA4);
  TH1D *hPD = (TH1D*)data1->Get(HistPD);

  TH1D *hMA0 = (TH1D*)data2->Get(HistMA0);
  TH1D *hMA1 = (TH1D*)data2->Get(HistMA1);
  TH1D *hMA2 = (TH1D*)data2->Get(HistMA2);
  TH1D *hMA3 = (TH1D*)data2->Get(HistMA3);
  TH1D *hMA4 = (TH1D*)data2->Get(HistMA4);
  TH1D *hMD = (TH1D*)data2->Get(HistMD);

  hPA0->Rebin(20);
  hPA1->Rebin(20);
  hPA2->Rebin(20);
  hPA3->Rebin(20);
  hPA4->Rebin(20);
  hPD->Rebin(20);

  hMA0->Rebin(20);
  hMA1->Rebin(20);
  hMA2->Rebin(20);
  hMA3->Rebin(20);
  hMA4->Rebin(20);
  hMD->Rebin(20);

  TCanvas * aCanvas = new TCanvas("CSAiZ", "CSAiZ", 1100, 500);
  aCanvas->SetFillColor(0);
  aCanvas->SetFrameFillColor(0);
  aCanvas->SetFrameBorderMode(0);
  aCanvas->Divide(2,1);

  setPadMargins(aCanvas->cd(1));

  TLegend * aLegend = new TLegend(0.23,0.92,0.4,0.62);
  aLegend->SetFillColor(0);
  aLegend->SetLineColor(0);
  aLegend->SetTextSize(0.0625);

  aLegend->AddEntry(hPA0,"A0", "L");
  //aLegend->AddEntry(hPA1,"A1", "L");
  aLegend->AddEntry(hPA2,"A2", "L");
  aLegend->AddEntry(hPA3,"A3", "L");
  //aLegend->AddEntry(hPA4,"A4", "L");

  hPA0->Scale(20.0/3.0);
  hPA0->Divide(hPD);
  for(unsigned int i=0; i<hPA0->GetNbinsX(); i++) {
    hPA0->SetBinContent(i, (2.0/3.0) + hPA0->GetBinContent(i));
  }
  hPA0->SetLineWidth(3);
  hPA0->GetYaxis()->SetRangeUser(-1.,2.);
  hPA0->GetXaxis()->SetTitle("P_{T}(Z) [GeV]");
  hPA0->GetXaxis()->SetRangeUser(0,220);
  hPA0->GetYaxis()->SetTitle("A_{i}");
  hPA0->GetXaxis()->SetTitleSize(0.0625);
  hPA0->GetYaxis()->SetTitleSize(0.0625);
  hPA0->GetXaxis()->SetTitleOffset(1.00);
  hPA0->GetYaxis()->SetTitleOffset(1.20);
  hPA0->GetXaxis()->SetLabelSize(0.052);
  hPA0->GetYaxis()->SetLabelSize(0.052);
  hPA0->GetXaxis()->SetLabelOffset(0.01);
  hPA0->GetYaxis()->SetLabelOffset(0.01);
  hPA0->DrawCopy("hist");

  hPA1->Scale(5.0);
  hPA1->Divide(hPD);
  hPA1->SetLineColor(kRed);
  hPA1->SetLineWidth(3);
  //hPA1->DrawCopy("histsame");//we don't have sensitivity to A1 - sign of cos(theta_CS)

  hPA2->Scale(10.0);
  hPA2->Divide(hPD);
  hPA2->SetLineColor(kBlue);
  hPA2->SetLineWidth(3);
  hPA2->DrawCopy("histsame");

  hPA3->Scale(4.0);
  hPA3->Divide(hPD);
  hPA3->SetLineColor(kGreen);
  hPA3->SetLineWidth(3);
  hPA3->DrawCopy("histsame");

  hPA4->Scale(4.0);
  hPA4->Divide(hPD);
  hPA4->SetLineColor(kCyan);
  hPA4->SetLineWidth(3);
  //hPA4->DrawCopy("histsame");//we don't have sensitivity to A4 - sign of cos(theta_CS)

  TLatex *tplus = labelLatex(0.25,0.25,"Lepton Plus Charge");
  tplus->DrawClone("same");

  aLegend->DrawClone("same");  

  setPadMargins(aCanvas->cd(2));

  hMA0->Scale(20.0/3.0);
  hMA0->Divide(hMD);
  for(unsigned int i=0; i<hMA0->GetNbinsX(); i++) {
    hMA0->SetBinContent(i, (2.0/3.0) + hMA0->GetBinContent(i));
  }
  hMA0->SetLineWidth(3);
  hMA0->GetYaxis()->SetRangeUser(-1.,2.);
  hMA0->GetXaxis()->SetTitle("P_{T}(Z) [GeV]");
  hMA0->GetXaxis()->SetRangeUser(0,220);
  hMA0->GetYaxis()->SetTitle("A_{i}");
  hMA0->GetXaxis()->SetTitleSize(0.0625);
  hMA0->GetYaxis()->SetTitleSize(0.0625);
  hMA0->GetXaxis()->SetTitleOffset(1.00);
  hMA0->GetYaxis()->SetTitleOffset(1.20);
  hMA0->GetXaxis()->SetLabelSize(0.052);
  hMA0->GetYaxis()->SetLabelSize(0.052);
  hMA0->GetXaxis()->SetLabelOffset(0.01);
  hMA0->GetYaxis()->SetLabelOffset(0.01);
  hMA0->DrawCopy("hist");

  hMA1->Scale(5.0);
  hMA1->Divide(hMD);
  hMA1->SetLineColor(kRed);
  hMA1->SetLineWidth(3);
  //hMA1->DrawCopy("histsame");

  hMA2->Scale(10.0);
  hMA2->Divide(hMD);
  hMA2->SetLineColor(kBlue);
  hMA2->SetLineWidth(3);
  hMA2->DrawCopy("histsame");

  hMA3->Scale(4.0);
  hMA3->Divide(hMD);
  hMA3->SetLineColor(kGreen);
  hMA3->SetLineWidth(3);
  hMA3->DrawCopy("histsame");

  hMA4->Scale(4.0);
  hMA4->Divide(hMD);
  hMA4->SetLineColor(kCyan);
  hMA4->SetLineWidth(3);
  //hMA4->DrawCopy("histsame");

  TLatex *tminus = labelLatex(0.25,0.25,"Lepton Minus Charge");
  tminus->DrawClone("same");

  aLegend->DrawClone("same");  

  aCanvas->Print(".png");

  return;
}
Esempio n. 4
0
void slopevscentrality(){
	TFile *f;
	TH1D* c2_pos[5][2];
	TH1D* c2_neg[5][2];
	TH1D* ach_hist[5];
	TH1D* cbinHist;
	TGraphErrors* gr_diff;
	TF1* fit1;

	double x_centrality[6] = {35, 45, 55, 65, 75, 85};
	double y_slope[6];
	double statErr[6];

	double variance_pos = 0.0;
	double variance_neg = 0.0;
	double variance_diff = 0.0;
	double err_neg[5];
	double err_pos[5];
	double err_diff[5];
	double cmean;
	double errmean;
	double sum;

	for (int n = 0; n <6; ++n)
	{

		f = new TFile(Form("../../../rootfiles/slope_vs_centrality/PbPb502_%d.root",n+1));
		for (Int_t i = 0; i < 5; i++){
			ach_hist[i] = (TH1D*)f->Get(Form("demo/ach_%d",i+1));

			c2_pos[i][0] = (TH1D*)f->Get(Form("demo/c2pos_%d_cos",i));
			c2_pos[i][1] = (TH1D*)f->Get(Form("demo/c2pos_%d_sin",i));


			c2_neg[i][0] = (TH1D*)f->Get(Form("demo/c2neg_%d_cos",i));
			c2_neg[i][1] = (TH1D*)f->Get(Form("demo/c2neg_%d_sin",i));

		}

		cbinHist = (TH1D*)f->Get("demo/cbinHist");
		double x[5];
		double v2_pos[5];
		double v2_neg[5];
		double v2_diff[5];
		double r;
		for(Int_t i=0; i<5; i++){

			x[i]=ach_hist[i]->GetMean();

			cmean = c2_pos[i][0] -> GetMean();
			v2_pos[i] = sqrt(cmean);
			errmean = c2_pos[i][0] -> GetMeanError();
			variance_pos = (errmean*errmean)/(4*cmean);


			cmean = c2_neg[i][0] -> GetMean();
			v2_neg[i] = sqrt(cmean);
			errmean = c2_neg[i][0] -> GetMeanError();
			variance_neg = (errmean*errmean)/(4*cmean);

			v2_diff[i] = (v2_neg[i] - v2_pos[i]);

			sum = v2_pos[i] + v2_neg[i];

			variance_diff = variance_pos+variance_neg;


//error calculation

			err_pos[i] = sqrt(variance_pos);
			err_neg[i] = sqrt(variance_neg);
			err_diff[i] = sqrt(variance_diff);




		}

		gr_diff = new TGraphErrors(5,x,v2_diff,NULL, err_diff);
		fit1 = new TF1("Linear fitting case 1", "[0]+x*[1]", -0.09, 0.09);
		gr_diff->Fit(fit1);
		r = fit1->GetParameter(1);
		statErr[n] = fit1->GetParError(1);
		cout << "slope is: " << r << endl; 
		y_slope[n] = r;

	}

	double x_alice[] = {5,15,25,35,45,55,65,75};
	double y_alice[] = { 0.0188127, 0.0252774, 0.0290478, 0.0315681, 0.0313678, 0.0334533, 0.0326948, 0.027709 };
	double alice_statErrors[] = { 0.00276672, 0.00491256, 0.00542907, 0.00499819, 0.00427076, 0.00421142, 0.00436631, 0.00480683 };
	double alice_sysminus[] = { 0.003345731066792428, 0.005524736668946313, 0.006157316616294797, 0.00591162859559022, 0.0052989413797474684, 0.0053784097301432885, 0.0054547376184835876, 0.005548288155719744 };
	double alice_sysplus[] = { 0.003345731066792428, 0.005524736668946313, 0.006157316616294797, 0.00591162859559022, 0.0052989413797474684, 0.0053784097301432885, 0.0054547376184835876, 0.005548288155719744 };
	double xsysalice[] = {1,1,1,1,1,1,1,1};


	double x_star[] = {2.5,7.5,15.0,25.0,35.0,45.0,55.0,65.0,75.0};
	double y_star[] = {-0.033529,0.001979,0.015917,0.028232,0.031986,0.026516,0.028016,0.012459,-0.02195};
	double star_statErrors[] = { 0.0010554, 0.00701, 0.003874, 0.003091, 0.002903, 0.002921, 0.003657, 0.005119, 0.009593 };
	double star_sysminus[] = { 2.156594920238847, 1.1474282374074642, 0.41413973487218053, 0.40721102637330436, 0.46464817873311415, 0.48750025641018896, 1.2743975557101481, 0.6065696744810114, 0.9645708786812922 };
	double star_sysplus[] = { 3.152323796820371, 1.1348034014753392, 0.6881948851887814, 0.3091, 0.3775553601791398, 0.6362180836788593, 0.39244649316817704, 1.060086081410373, 4.931994052105091 };
	double xsysstar[] = {1,1,1,1,1,1,1,1,1};

	for(i=0;i<9;i++){
		star_sysminus[i]/=100;
		star_sysplus[i]/=100;
	}
	gStyle->SetLegendFont(42);

	TGraphErrors* slopevscent = new TGraphErrors(6,x_centrality,y_slope,NULL,statErr);
	TGraphErrors* ALICE = new TGraphErrors(8,x_alice,y_alice,NULL,alice_statErrors);
	TGraphErrors* STAR = new TGraphErrors(9,x_star,y_star,NULL,star_statErrors);
	TGraphAsymmErrors* ALICE_sys = new TGraphAsymmErrors(8, x_alice, y_alice, xsysalice, xsysalice, alice_sysminus, alice_sysplus);
	TGraphAsymmErrors* STAR_sys = new TGraphAsymmErrors(9, x_star, y_star, xsysstar, xsysstar, star_sysminus, star_sysplus);


	slopevscent -> SetMarkerStyle(20);
	slopevscent -> SetMarkerColor(kBlack);

	ALICE -> SetMarkerStyle(25);
	ALICE -> SetMarkerColor(kRed);
	ALICE -> SetLineColor(kRed);

	STAR -> SetMarkerStyle(kOpenStar);
	STAR -> SetMarkerColor(kBlue);
	STAR -> SetLineColor(kBlue);

	TH1D* base = new TH1D("base","base",1,0,100);
	base->GetYaxis()->SetRangeUser(0.00,0.06);
	base->GetXaxis()->SetTitle("Centrality(%)");
	base->GetYaxis()->SetTitle("Slope parameter(v_{2})");
	base->GetXaxis()->CenterTitle();
	base->GetYaxis()->CenterTitle();
	base->SetTitleSize  (0.040,"X");
	base->SetTitleOffset(1.4,"X");
	base->SetTitleFont  (42,"X");
	base->SetLabelOffset(0.006,"X");
	base->SetLabelSize  (0.040,"X");
	base->SetLabelFont  (42   ,"X");

	base->SetTitleSize  (0.040,"Y");
	base->SetTitleOffset(2.2,"Y");
	base->SetTitleFont  (42,"Y");
	base->SetLabelOffset(0.006,"Y");
	base->SetLabelSize  (0.040,"Y");
	base->SetLabelFont  (42   ,"Y");
	base->SetLineWidth(0);

	TCanvas* c3 = MakeCanvas("c3","c3");
	TLatex* text_a = makeLatex("CMS pPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ;
	TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 260",0.25,0.80) ;
	TLatex* text_c = makeLatex("0.3 < p_{T} < 3 GeV/c",0.25,0.85) ;
	TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.80) ;

	text_a->SetTextFont(42);
	text_b->SetTextFont(42);
	text_c->SetTextFont(42);
	text_d->SetTextFont(42);
	slopevscent->SetFillStyle(0);
	slopevscent->SetFillColor(0);
	slopevscent->SetFillStyle(0);
	slopevscent->SetFillColor(0);

	gStyle->SetOptTitle(0);


	TLegend* leg = new TLegend(.58,.70,.93,.90);
	leg->SetLineColor(kWhite);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);
	leg->AddEntry(slopevscent, "CMS, Pb-Pb 5.02TeV","p");
	leg->AddEntry(ALICE, "ALICE, Pb-Pb 2.76TeV","p");
	leg->AddEntry(STAR, "STAR, Au-Au 200GeV","p");

	//leg->AddEntry(gr_neg, "neg","p");

	
	c3->cd();
	base->Draw("");
	ALICE->Draw("PSame");
	STAR->Draw("PSame");


	slopevscent->Draw("PSame");

//	STAR_sys->Draw("2Same");

	leg->DrawClone("PSame");
//	text_c->DrawClone("Same");
//	text_d->DrawClone("Same");

    //Define a linear function
	//SaveCanvas(c3,"pics","slopevscent_comparison");






}
void makePlots( const char * model, const char * src, const char * infile , const char * option )
{
  
  //Output path
  TString path("./paper01-plots/probs/");
  
  TString dataPee  = TString( model ) + TString("_") + TString( src ) + TString("_Pee/data");
  TString dataPem  = TString( model ) + TString("_") + TString( src ) + TString("_Pem/data");
  TString dataPet  = TString( model ) + TString("_") + TString( src ) + TString("_Pet/data");
  TString dataAPee = TString( model ) + TString("_") + TString( src ) + TString("_aPee/data");
  TString dataAPem = TString( model ) + TString("_") + TString( src ) + TString("_aPem/data");
  TString dataAPet = TString( model ) + TString("_") + TString( src ) + TString("_aPet/data");
    
  TList * v_Labels = new TList();
  TObjString *label;
  label = new TObjString( "Pee" );
  v_Labels->Add( label ); 
  label = new TObjString( "Pe#mu" );
  v_Labels->Add( label ); 
  label = new TObjString( "Pe#tau" );
  v_Labels->Add( label ); 
  
  TFile * f1 = new TFile(infile);
  
  f1->cd();
  
  TTree * PeeTreeNu = (TTree*)gDirectory->Get( dataPee.Data() );
  TTree * PemTreeNu = (TTree*)gDirectory->Get( dataPem.Data() );
  TTree * PetTreeNu = (TTree*)gDirectory->Get( dataPet.Data() );
  
  TTree * PeeTreeANu = (TTree*)gDirectory->Get( dataAPee.Data() );
  TTree * PemTreeANu = (TTree*)gDirectory->Get( dataAPem.Data() );
  TTree * PetTreeANu = (TTree*)gDirectory->Get( dataAPet.Data() );
  
  //Branches
  double xx = 0.0;
  double yy = 0.0;
  
  TCanvas * c1 = new TCanvas(model, "Oscillation probabilities", 184, 60, 861, 670);
  c1->Divide(1,3);
  
  TGraph * ProbNu[3];
  ProbNu[0] = new TGraph();
  ProbNu[1] = new TGraph();
  ProbNu[2] = new TGraph();
  
  TGraph * ProbANu[3];
  ProbANu[0] = new TGraph();
  ProbANu[1] = new TGraph();
  ProbANu[2] = new TGraph();
  
  TGraph * Psum = new TGraph();
  TGraph * aPsum = new TGraph();
  
  TLegend * leg = new TLegend(0.14,0.69,0.24,0.85);
    
  PeeTreeNu->SetBranchAddress("Ex",&xx);
  PeeTreeNu->SetBranchAddress("Pb",&yy);
  
  Long64_t nentries = PeeTreeNu->GetEntries();
  
  for (Long64_t i=0;i<nentries;i++) {
    PeeTreeNu->GetEntry(i);
    ProbNu[0]->SetPoint( i, xx, yy);
  }

  PeeTreeANu->SetBranchAddress("Ex",&xx);
  PeeTreeANu->SetBranchAddress("Pb",&yy);
  
  nentries = PeeTreeANu->GetEntries();
  
  for (Long64_t i=0;i<nentries;i++) {
    PeeTreeANu->GetEntry(i);
    ProbANu[0]->SetPoint( i, xx, yy);
  }

  ///Pem
  
  PemTreeNu->SetBranchAddress("Ex",&xx);
  PemTreeNu->SetBranchAddress("Pb",&yy);

  nentries = PemTreeNu->GetEntries();
  
  for (Long64_t i=0;i<nentries;i++) {
    PemTreeNu->GetEntry(i);
    ProbNu[1]->SetPoint( i, xx, yy);
  }
  
  PemTreeANu->SetBranchAddress("Ex",&xx);
  PemTreeANu->SetBranchAddress("Pb",&yy);
  
  nentries = PemTreeANu->GetEntries();
  
  for (Long64_t i=0;i<nentries;i++) {
    PemTreeANu->GetEntry(i);
    ProbANu[1]->SetPoint( i, xx, yy);
  }

  ///Pet

  PetTreeNu->SetBranchAddress("Ex",&xx);
  PetTreeNu->SetBranchAddress("Pb",&yy);

  nentries = PetTreeNu->GetEntries();
  
  for (Long64_t i=0;i<nentries;i++) {
    PetTreeNu->GetEntry(i);
    ProbNu[2]->SetPoint( i, xx, yy);
  }
  
  PetTreeANu->SetBranchAddress("Ex",&xx);
  PetTreeANu->SetBranchAddress("Pb",&yy);
  
  nentries = PetTreeANu->GetEntries();
  
  for (Long64_t i=0;i<nentries;i++) {
    PetTreeANu->GetEntry(i);
    ProbANu[2]->SetPoint( i, xx, yy);
  }

  for( int k=0; k < 3; ++k) 
  {
    
    ProbNu[k]->SetLineColor(4);
    ProbNu[k]->SetMarkerColor(4);
    ProbNu[k]->SetMarkerStyle(7);
    
    ProbNu[k]->SetFillColor(10);
    ProbNu[k]->SetMaximum(1.0);
    ProbNu[k]->SetMinimum(0.0);
    
    TString yaxis = ((TObjString*)v_Labels->At(k))->GetString();
    ProbNu[k]->GetYaxis()->SetTitle( yaxis.Data() );
    ProbNu[k]->GetXaxis()->SetTitle("E [eV]");
    ProbNu[k]->GetYaxis()->CenterTitle(true); 
    ProbNu[k]->GetXaxis()->CenterTitle(true); 
    ProbNu[k]->GetXaxis()->SetLabelOffset(0.007);
    ProbNu[k]->GetXaxis()->SetLabelSize(0.08);
    ProbNu[k]->GetXaxis()->SetTitleSize(0.07);
    ProbNu[k]->GetXaxis()->SetTitleOffset(0.9);
    ProbNu[k]->GetXaxis()->SetLabelFont(42);
    ProbNu[k]->GetYaxis()->SetLabelOffset(0.007);
    ProbNu[k]->GetYaxis()->SetLabelSize(0.08);
    ProbNu[k]->GetYaxis()->SetLabelFont(42);
    ProbNu[k]->GetYaxis()->SetTitleSize(0.09);
    ProbNu[k]->GetYaxis()->SetTitleOffset(0.45);
    ProbNu[k]->GetYaxis()->SetTitleFont(42);
    
    ProbANu[k]->SetMarkerColor(42);
    ProbANu[k]->SetMarkerStyle(23);
    ProbANu[k]->SetMarkerSize(0.3);
    
    ProbANu[k]->SetFillColor(10);
    ProbANu[k]->SetMaximum(1.0);
    ProbANu[k]->SetMinimum(0.0);
    

  }
  
  leg->AddEntry( ProbNu[0], "#nu");
  leg->AddEntry( ProbANu[0], "#bar{#nu}");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.1);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(0);
  leg->SetFillStyle(1001);


  c1->cd(1);
  gPad->SetGridx();
  gPad->SetGridy();
  gPad->SetLogx();

  if ( std::string(model).compare("EarthB") == 0 ) 
    ProbNu[0]->GetXaxis()->SetLimits(0.98e9, 1.0e10);

  ProbNu[0]->Draw("APL");
  ProbANu[0]->Draw("PL");
  topTitle(model);
  leg->DrawClone();
  
  c1->cd(2);
  gPad->SetGridx();
  gPad->SetGridy();
  gPad->SetLogx();
  
  if ( std::string(model).compare("EarthB") == 0 ) 
    ProbNu[1]->GetXaxis()->SetLimits(0.98e9, 1.0e10);
  
  ProbNu[1]->Draw("APL");
  ProbANu[1]->Draw("PL");
  leg->DrawClone();
    
  c1->cd(3);
  gPad->SetGridx();
  gPad->SetGridy();
  gPad->SetLogx();
  
  if ( std::string(model).compare("EarthB") == 0 ) 
    ProbNu[2]->GetXaxis()->SetLimits(0.98e9, 1.0e10);
  
  ProbNu[2]->Draw("APL");
  ProbANu[2]->Draw("PL");
  leg->DrawClone();

  c1->cd();

  std::stringstream saveAs;
    
  saveAs.str("");
  saveAs << path << model << "/pdf/" << "nueosc_probs_" << model << "_" << option << ".pdf";
  c1->SaveAs( saveAs.str().c_str() );
  
  saveAs.str("");
  saveAs << path << model << "/png/" << "nueosc_probs_" << model << "_" << option << ".png";
  c1->SaveAs( saveAs.str().c_str() );

  saveAs.str("");
  saveAs << path << model << "/eps/" << "nueosc_probs_" << model << "_" << option << ".eps";
  c1->SaveAs( saveAs.str().c_str() );

  TH1D * h_Psum = new TH1D("Psum.Histo","",100, 0.99999, 1.0001);
  TH1D * h_aPsum = h_Psum->Clone("aPsum.Histo");

  for (Long64_t i=0;i<nentries;i++) {
    
    double xx = 0.0;
    double yy = 0.0;
    double p1 = 0.0;
    double p2 = 0.0;
    double p3 = 0.0;
    
    ProbNu[0]->GetPoint(i, xx, p1);
    ProbNu[1]->GetPoint(i, xx, p2);
    ProbNu[2]->GetPoint(i, xx, p3);
    
    yy = p1 + p2 + p3;
    
    if ( xx < 1.0e14 ) 
    {
      Psum->SetPoint( i, xx, yy);
      h_Psum->Fill( yy );
    }
    else 
      break;
    
  }

  for (Long64_t i=0;i<nentries;i++) {
    
    double xx = 0.0;
    double yy = 0.0;
    double p1 = 0.0;
    double p2 = 0.0;
    double p3 = 0.0;
    
    ProbANu[0]->GetPoint(i, xx, p1);
    ProbANu[1]->GetPoint(i, xx, p2);
    ProbANu[2]->GetPoint(i, xx, p3);
    
    yy = p1 + p2 + p3;
    
    if ( xx < 1.0e14 ) 
    {
      aPsum->SetPoint( i, xx, yy);
      h_aPsum->Fill( yy );
    }
    
    else 
      break;
    
  }
  
  TCanvas * c2 = new TCanvas("Sums", "Oscillation probabilities - SUMS", 184,112,394,472);
  
  c2->Divide(2,2);
  
  c2->cd(1);
  
  gPad->SetLogx();
  Psum->SetMaximum(1.1);
  Psum->SetMinimum(0.0);
  Psum->SetMarkerStyle(21);
  Psum->SetMarkerSize(0.2); 
  
  if ( std::string(model).compare("EarthB") == 0 ) 
    Psum->GetXaxis()->SetLimits(0.98e9, 1.0e10);
  
   
  Psum->Draw("APL");

  TLatex *   tex = new TLatex(1.823945e+11,0.8753448,"Nu");
  tex->SetLineWidth(2);
  tex->Draw();

  c2->Modified();
  c2->cd();
  
  //Now the histogram
  
  c2->cd(2);
  // h_Psum->GetXaxis()->SetRange(6,14);
  h_Psum->GetXaxis()->SetNdivisions(501);
  h_Psum->GetXaxis()->SetLabelFont(42);
  h_Psum->GetXaxis()->SetLabelOffset(0.007);
  h_Psum->GetXaxis()->SetLabelSize(0.05);
  h_Psum->GetXaxis()->SetTitleSize(0.06);
  h_Psum->GetXaxis()->SetTitleOffset(0.9);
  h_Psum->GetXaxis()->SetTitleFont(42);
  h_Psum->Draw("");


  h_Psum->Draw();
  
  /////

  c2->cd(3);
  
  gPad->SetLogx();
  aPsum->SetMaximum(1.1);
  aPsum->SetMinimum(0.0);
  aPsum->SetMarkerStyle(21);
  aPsum->SetMarkerSize(0.2);
  aPsum->SetMarkerColor(2);
  aPsum->GetXaxis()->SetTitle("E [eV]");
  aPsum->GetXaxis()->CenterTitle(true);
  aPsum->GetXaxis()->SetLabelFont(42);
  aPsum->GetXaxis()->SetLabelOffset(0.007);
  aPsum->GetXaxis()->SetLabelSize(0.05);
  aPsum->GetXaxis()->SetTitleSize(0.06);
  aPsum->GetXaxis()->SetTitleOffset(1.06);
  
  if ( std::string(model).compare("EarthB") == 0 ) 
    aPsum->GetXaxis()->SetLimits(0.98e9, 1.0e10);
  
  aPsum->Draw("APL");
  tex = new TLatex(1.56236e+11,0.8214771,"anti-Nu");
  tex->SetLineWidth(2);
  tex->Draw();
  
  //Now the histogram
  
  c2->cd(4);
  h_aPsum->Draw();
  
  /////

  c2->Modified();
  c2->cd();

  


  
  saveAs.str("");
  saveAs << path << model << "/png/" << "nueosc_sum_of_probs_" << model << "_" << option << ".png";
  c2->SaveAs( saveAs.str().c_str() );

}
void CumulantErrGraph_v2_allgraphs_cent(){

	TFile *f;

	const int NAchBins = 7;
	//const double correction = 0.7463;
	//const double correction = 1.0;

	TH1D* c2_pos[NAchBins][2];
	TH1D* c2_neg[NAchBins][2];

	TH1D* ach_hist[NAchBins];
	double x[NAchBins];
	double v2_pos[NAchBins];
	double v2_neg[NAchBins];
	double v2_diff[NAchBins];
	double err_neg[NAchBins];
	double err_pos[NAchBins];
	double err_diff[NAchBins];
	double cmean;
	double errmean;
	double sum;
	double variance_pos;
	double variance_neg;
	double variance_diff;

	int index_v2_mult;
	int index_v3_mult;
	int index_v2_cent; 
	int index_v3_cent; 

	int mult_start[6] = {30,40,50,60,70,80}; 
	int mult_end[6] = {40,50,60,70,80,90};
	double correction[6] = {0.645, 0.663, 0.673, 0.689, 0.699, 0.623};
	int mult_index[6] = {9,10,11,12,13,14};

	double setrange_low[6] = {0.0965, 0.105, 0.1038,   0.0945, 0.076, 0.06};
	double setrange_upp[6] = {0.101,  0.11,  0.108    ,0.101  ,0.088,0.072};

	double range_start = 0.06;
	double range_end = 0.072;

	int num = 5;

	range_start = setrange_low[num];
	range_end = setrange_upp[num];



	f = new TFile("~/Summer2016/rootfiles/FinalResult_0106/Main_PbPb_Merged.root");

	// = new TFile("../../../rootfiles/closure/pPb/185_220/Merged.root");



	for (Int_t i = 0; i < NAchBins; i++){
		ach_hist[i] = (TH1D*)f->Get(Form("demo_n%d/ach_%d",mult_index[num],i+1));

		c2_pos[i][0] = (TH1D*)f->Get(Form("demo_n%d/c2pos_%d_cos",mult_index[num],i));
		c2_pos[i][1] = (TH1D*)f->Get(Form("demo_n%d/c2pos_%d_sin",mult_index[num],i));

		c2_neg[i][0] = (TH1D*)f->Get(Form("demo_n%d/c2neg_%d_cos",mult_index[num],i));
		c2_neg[i][1] = (TH1D*)f->Get(Form("demo_n%d/c2neg_%d_sin",mult_index[num],i));		
	}

	for(Int_t i=0; i<NAchBins; i++){

		x[i]=ach_hist[i]->GetMean();
		x[i] *= correction[num]; 

//v2 positive
		cmean = c2_pos[i][0] -> GetMean();
		v2_pos[i] = sqrt(cmean);

		errmean = c2_pos[i][0] -> GetMeanError();
		variance_pos = (errmean*errmean)/(4*cmean);

//negative
		cmean = c2_neg[i][0] -> GetMean();
		v2_neg[i] = sqrt(cmean);

		errmean = c2_neg[i][0] -> GetMeanError();
		variance_neg = (errmean*errmean)/(4*cmean);

		//difference
		v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]);

		sum = v2_pos[i] + v2_neg[i];

		variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum);


	//error bars

		cout << "xcoord " << x[i] << endl;

		err_pos[i] = sqrt(variance_pos);
		err_neg[i] = sqrt(variance_neg);
		err_diff[i] = sqrt(variance_diff);


	}
	
	gStyle->SetLegendFont(42);
	TH1D* base = new TH1D("base","base",1,-0.12,0.12);
	//pPb
	//base->GetYaxis()->SetRangeUser(0.065, 0.075);
	base->GetYaxis()->SetRangeUser(range_start, range_end);

	//PbPb
	//base->GetYaxis()->SetRangeUser(0.093, 0.103);
	base->GetXaxis()->SetTitle("Corrected A_{ch}");
	base->GetYaxis()->SetTitle("v_{2}{2}");
	base->GetXaxis()->CenterTitle();
	base->GetYaxis()->CenterTitle();
	base->SetTitleSize  (0.040,"X");
	base->SetTitleOffset(1.4,"X");
	base->SetTitleFont  (42,"X");
	base->SetLabelOffset(0.006,"X");
	base->SetLabelSize  (0.040,"X");
	base->SetLabelFont  (42   ,"X");

	base->SetTitleSize  (0.040,"Y");
	base->SetTitleOffset(2.2,"Y");
	base->SetTitleFont  (42,"Y");
	base->SetLabelOffset(0.006,"Y");
	base->SetLabelSize  (0.040,"Y");
	base->SetLabelFont  (42   ,"Y");
	base->SetLineWidth(0);

	TH1D* base2 = new TH1D("base2","base2",1,-0.12,0.12);
	base2->GetYaxis()->SetRangeUser(-0.03, 0.03);
	base2->GetXaxis()->SetTitle("Corrected A_{ch}");
	base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) ");
	base2->GetXaxis()->CenterTitle();
	base2->GetYaxis()->CenterTitle();
	base2->SetTitleSize  (0.040,"X");
	base2->SetTitleOffset(1.4,"X");
	base2->SetTitleFont  (42,"X");
	base2->SetLabelOffset(0.006,"X");
	base2->SetLabelSize  (0.040,"X");
	base2->SetLabelFont  (42   ,"X");
	base2->SetTitleSize  (0.040,"Y");
	base2->SetTitleOffset(2.0,"Y");
	base2->SetTitleFont  (42,"Y");
	base2->SetLabelOffset(0.006,"Y");
	base2->SetLabelSize  (0.040,"Y");
	base2->SetLabelFont  (42   ,"Y");
	base2->SetLineWidth(0);

	TFile *rebinned = new TFile(Form("~/Summer2016/root_forgraphs/v2_cent_%d_%d.root",mult_start[num],mult_end[num]),"RECREATE");


	TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos);
	TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg);
	TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff);

	if(num==0){
		gr_pos->RemovePoint(0);
		gr_pos->RemovePoint(5);
		gr_neg->RemovePoint(0);
		gr_neg->RemovePoint(5);
		gr_diff->RemovePoint(0);
		gr_diff->RemovePoint(5);

	}

	gr_pos->Write();
	gr_neg->Write();
	gr_diff->Write();



 //   TCanvas* c1 = new TCanvas("c1","c1");
 //   TCanvas* c2 = new TCanvas("c2","c2");
	TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600);
	c3->Divide(2,1,0.01,0.01);

	gr_neg -> SetMarkerStyle(20);
	gr_neg -> SetMarkerColor(kBlue);
	gr_pos -> SetMarkerStyle(34);	
	gr_pos -> SetMarkerColor(kRed);




	TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ;
	//TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 220",0.25,0.80) ;
	TLatex* text_b = makeLatex(Form("%d-%d centrality",mult_start[num],mult_end[num]),0.25,0.80) ;

	TLatex* text_c = makeLatex("0.3 < p_{T} < 3.0 GeV/c",0.25,0.75) ;
	TLatex* text_d = makeLatex("|#Delta#eta| > 1",0.25,0.70) ;

	text_a->SetTextFont(42);
	text_b->SetTextFont(42);
	text_c->SetTextFont(42);
	text_d->SetTextFont(42);



	TLegend* leg = new TLegend(0.76,0.80,0.94,.88);
	leg->SetLineColor(kWhite);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);
	leg->AddEntry(gr_pos, "v_{2}^{#plus}{2}","p");
	leg->AddEntry(gr_neg , "v_{2}^{#minus}{2}","p");



	c3->cd(1);
	base->Draw("");
	gr_pos->Draw("PSame");
	gr_neg->Draw("PSame");
	text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	text_c->DrawClone("Same");
	text_d->DrawClone("Same");

	leg->DrawClone("Same");


    //Define a linear function
	TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.13, 0.13);

	fit1->SetLineColor(kRed);
	fit1->SetLineStyle(2);
	gr_diff->Fit(fit1,"RN0");
	fit1->Write();


	rebinned->Close();

	c3->cd(2);



	TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ;
	TLatex* text1 = makeLatex(Form("slope : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ;
	text1->SetTextFont(42);
	text2->SetTextFont(42);
	base2->Draw("");
	fit1->DrawClone("Same");
	gr_diff->SetMarkerStyle(20);
	gr_diff->Draw("PSame");

	text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	

	text1->DrawClone("Same");
	text2->DrawClone("Same");

	

	TF1 *fa1 = new TF1("fa1","0",-10,10); 
	fa1->SetLineColor(kBlack);
	fa1->SetLineWidth(0);
	fa1->DrawClone("Same");

	TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78);
	leg2->SetLineColor(kWhite);
	leg2->SetFillColor(0);
	leg2->SetFillStyle(0);
	leg2->AddEntry(fit1, "Linear fit","l");
	leg2->AddEntry(gr_diff , "data","p");
	leg2->DrawClone("Same");

	cout << mult_start[num] << endl;
	cout << mult_end[num] << endl;

	c3->Print(Form("~/Summer2016/pics/v2_cent_%d_%d.pdf",mult_start[num],mult_end[num]));
	c3->Print(Form("~/Summer2016/pics/v2_cent_%d_%d.gif",mult_start[num],mult_end[num]));




}
void PlotWrite(TFile* input, TFile* output, TString output_folder, TString canvas, TString Hist_data, TString Hist_emu, TString XAxisLabel, TString YAxisLabel="Events", int rebin, int xAxisRange, TString Opt="")
{

  // Setup the canvas
  TCanvas *c1= new TCanvas(canvas,canvas,800,700);
  c1->SetLogy(1);

  // Get the histograms from the files
  if(Opt == "eta" || Opt == "phi")
  {
	if(Opt == "eta") {
	TH2F *Data2 = (TH2F*)input->Get(Hist_data);
	TH1D *Data = Data2->ProjectionX();
	if(rebin>0) Data->Rebin(rebin);
	if(xAxisRange>0) Data->GetXaxis()->SetRangeUser(0,xAxisRange);

	TH2F *Emu2 = (TH2F*)input->Get(Hist_emu);
	TH1D *Emu = Emu2->ProjectionX();
	if(rebin>0) Emu->Rebin(rebin);
	if(xAxisRange>0) Emu->GetXaxis()->SetRangeUser(0,xAxisRange);
	}
	if(Opt == "phi") {
	TH2F *Data2 = (TH2F*)input->Get(Hist_data);	
	TH1D *Data = Data2->ProjectionY();
	if(rebin>0) Data->Rebin(rebin);
    if(xAxisRange>0) Data->GetXaxis()->SetRangeUser(0,xAxisRange);

	TH2F *Emu2 = (TH2F*)input->Get(Hist_emu);
	TH1D *Emu = Emu2->ProjectionY();
	if(rebin>0) Emu->Rebin(rebin);
	if(xAxisRange>0) Emu->GetXaxis()->SetRangeUser(0,xAxisRange);
	}
  }
  else
  {
	TH1D *Data = (TH1D*)input->Get(Hist_data);
	if(rebin>0) Data->Rebin(rebin);
	if(xAxisRange>0) Data->GetXaxis()->SetRangeUser(0,xAxisRange);

	TH1D *Emu = (TH1D*)input->Get(Hist_emu);
	if(rebin>0) Emu->Rebin(rebin);
	if(xAxisRange>0) Emu->GetXaxis()->SetRangeUser(0,xAxisRange);
  }

  // Add the X axis label
  Emu->GetXaxis()->SetTitle(XAxisLabel);
  Emu->GetYaxis()->SetTitle(YAxisLabel);
  Emu->GetYaxis()->SetTitleSize(0.06);
  Emu->GetXaxis()->SetTitleSize(0.06);
  Emu->SetLineWidth(2);
  Emu->SetTitleOffset(1.10,"y");
  Emu->SetTitleOffset(0.80,"x");

  // Marker type for data
  Data->SetMarkerStyle(20);
  Data->SetMarkerColor(kRed);

  // plot them
  if (gPad->GetLogy()){
    Emu->SetMaximum(TMath::Max(Emu->GetMaximum(),Data->GetMaximum())*5);
  } else {
    Emu->SetMaximum(TMath::Max(Emu->GetMaximum(),Data->GetMaximum())*1.75);
  }
  Emu->DrawCopy("hist");
  Data->DrawCopy("psame");

  //make Legend
  TLegend * aLegend = new TLegend(0.646,0.768,0.746,0.868,NULL,"brNDC");
  aLegend->SetFillColor(0);
  aLegend->SetLineColor(0);
  aLegend->SetTextSize(0.05);
  aLegend->AddEntry(Emu,TString("Emulator"), "L");
  aLegend->AddEntry(Data,TString("Hardware"), "P");
  aLegend->DrawClone("same");
  gPad->RedrawAxis();

  //write canvas as png
  c1->Print(TString(output_folder+canvas+".png"));  

  //write canvas to output file
  output->cd();
  c1->Write();
  return;
}
Esempio n. 8
0
void photon_JEC()
{
    TH1::SetDefaultSumw2();

    Double_t alphabins[] = {0.075, 0.125, 0.175, .25, .35};

    TH1D *RdRmcalpha[nptbins];
    TProfile *Ratio[2][nptbins];

    for(int i = 0; i < nptbins; i++)
    {
        TString name;
        name = "RdRmcalpha_";
        name += ptbins[i];
        RdRmcalpha[i] = new TH1D(name,name+";#alpha;R_{data}/R_{MC}",4,alphabins);
        name = "Rd_";
        name += ptbins[i];
        Ratio[0][i] = new TProfile(name,"",4,alphabins);
        name = "Rmc_";
        name += ptbins[i];
        Ratio[1][i] = new TProfile(name,"",4,alphabins);
    }

    TH1D *alphas = new TH1D("alphas",";#alpha = p_{T}^{Jet3}/p_{T}^{#gamma}",100,0,0.8);

    TH1D *hPhotonPt[2];
    hPhotonPt[0] = new TH1D("hPhotonPt_data",";photon p_{T}",200,0,400);
    hPhotonPt[1] = (TH1D*)hPhotonPt[0]->Clone("hPhotonPt_mc");
    TH1D *hPhotonEta[2];
    hPhotonEta[0] = new TH1D("hPhotonEta_data",";photon #eta",26,-3,3);
    hPhotonEta[1] = (TH1D*)hPhotonEta[0]->Clone("hPhotonEta_mc");

    TH1D *hJet2Pt[2];
    hJet2Pt[0] = new TH1D("hJet2Pt_data",";jet 2 p_{T}",200,0,400);
    hJet2Pt[1] = (TH1D*)hJet2Pt[0]->Clone("hJet2Pt_mc");
    TH1D *hJet2Eta[2];
    hJet2Eta[0] = new TH1D("hJet2Eta_data",";jet 2 #eta",26,-3,3);
    hJet2Eta[1] = (TH1D*)hJet2Eta[0]->Clone("hJet2Eta_mc");

    TH1D *hJet3Pt[2];
    hJet3Pt[0] = new TH1D("hJet3Pt_data",";jet 3 p_{T}",200,0,400);
    hJet3Pt[1] = (TH1D*)hJet3Pt[0]->Clone("hJet3Pt_mc");
    TH1D *hJet3Eta[2];
    hJet3Eta[0] = new TH1D("hJet3Eta_data",";jet 3 #eta",26,-3,3);
    hJet3Eta[1] = (TH1D*)hJet3Eta[0]->Clone("hJet3Eta_mc");


    TString files[2];

    files[0] = "/mnt/hadoop/cms/store/user/luck/pA2013_forests/PA2013_HiForest_PromptReco_HLT_Photon40.root";
    files[1] = "/mnt/hadoop/cms/store/user/luck/pA2013_MC/HiForest2_QCDPhoton30_5020GeV_100k.root";

    bool montecarlo[2] = {false, true};

    //loop over files
    //do the smaller MC file first, for some reason I have segfaults when I process the MC second.
    for(int ii = 1; ii > -1; ii--)
    {
        HiForest *c = new HiForest(files[ii], "Forest", cPPb, montecarlo[ii]);
        c->InitTree();

        //loop over events in each file
        int nentries = c->GetEntries();
        for(int jentry = 0; jentry<nentries; jentry++)
        {
            if (jentry% 1000 == 0)  {
                printf("%d / %d\n",jentry,nentries);
            }

            c->GetEntry(jentry);

            //collision selection
            if( !((montecarlo[ii] || c->skim.pHBHENoiseFilter) && c->skim.phfPosFilter1 && c->skim.phfNegFilter1 && c->skim.phltPixelClusterShapeFilter && c->skim.pprimaryvertexFilter) )
                continue;

            if(c->photon.nPhotons == 0)
                continue;

            //loop over photons in the event
            Float_t leadingPt = 40; //minPt is 40GeV
            Int_t leadingIndex = -1;
            for(int i = 0; i<c->photon.nPhotons; i++)
            {
                if(c->photon.pt[i] > leadingPt)
                {
                    leadingPt = c->photon.pt[i];
                    leadingIndex = i;
                }
            }

            if(leadingIndex == -1) // no photons above minPt
                continue;
            if ( TMath::Abs(c->photon.eta[leadingIndex]) > 1.3 ) // barrel photons only
                continue;
            if(c->photon.ecalRecHitSumEtConeDR04[leadingIndex] > TMath::Min(3., 0.05*c->photon.energy[leadingIndex]) )
                continue;
            if(c->photon.hcalTowerSumEtConeDR04[leadingIndex] > TMath::Min(2.4, 0.05*c->photon.energy[leadingIndex]) )
                continue;
            //if(c->photon.trkSumPtHollowConeDR04[leadingIndex] > 0.10*leadingPt )
            //continue;
            //if ( (c->photon.sigmaIetaIeta[leadingIndex] < 0.15) || (c->photon.sigmaIetaIeta[leadingIndex] > 0.35) )
            //continue;
            //if ( (c->photon.sigmaIphiIphi[leadingIndex] < 0.15) || (c->photon.sigmaIphiIphi[leadingIndex] > 0.30) )
            //continue;
            if ( c->photon.sigmaIetaIeta[leadingIndex] > 0.01 )
                continue;

            //loop over 'away' jets
            int jet2index = -1;
            double jet2pt = 0;
            int jet3index = -1;
            double jet3pt = 0;
            for(int i = 0; i<c->akPu3PF.nref; i++)
            {
                if( TMath::Abs(c->akPu3PF.jteta[i]) > 3.0)
                    continue;
                Double_t dphi = TMath::ACos(TMath::Cos(c->photon.phi[leadingIndex] - c->akPu3PF.jtphi[i]));
                if(dphi < TMath::Pi()/2)
                    continue;
                if(c->akPu3PF.jtpt[i] > jet2pt)
                {
                    jet3pt = jet2pt;
                    jet3index = jet2index;
                    jet2pt = c->akPu3PF.jtpt[i];
                    jet2index = i;
                }
                else if(c->akPu3PF.jtpt[i] > jet3pt)
                {
                    jet3pt = c->akPu3PF.jtpt[i];
                    jet3index = i;
                }
            }

            if(jet3index == -1) //no 3rd jet means alpha = 0, we don't care
                continue;
            if( TMath::Abs(c->akPu3PF.jteta[jet2index]) > 1.3 )
                continue;
            Double_t dphi = TMath::ACos(TMath::Cos(c->photon.phi[leadingIndex] - c->akPu3PF.jtphi[jet2index]));
            if( dphi < 2.7 )
                continue;

            Double_t alpha = jet3pt/leadingPt;
            Double_t ratio = jet2pt/leadingPt;

            int ptbin = returnPtBin(leadingPt);
            if(ptbin != -1)
                Ratio[ii][ptbin]->Fill(alpha,ratio);

            alphas->Fill(alpha);
            hPhotonPt[ii]->Fill(leadingPt);
            hPhotonEta[ii]->Fill( c->photon.eta[leadingIndex] );
            hJet2Pt[ii]->Fill(jet2pt);
            hJet2Eta[ii]->Fill( c->akPu3PF.jteta[jet2index] );
            hJet3Pt[ii]->Fill(jet3pt);
            hJet3Eta[ii]->Fill( c->akPu3PF.jteta[jet3index] );
        }
    }

    TCanvas *canvas[nptbins];
    for(int i = 0; i < nptbins; i++)
    {
        TH1D *hRatiod = Ratio[0][i]->ProjectionX();
        TH1D *hRatiomc = Ratio[1][i]->ProjectionX();
        RdRmcalpha[i]->Divide(hRatiod,hRatiomc,1,1);

        canvas[i] = new TCanvas();
        RdRmcalpha[i]->Draw();
    }

    TCanvas *danvas = new TCanvas();
    alphas->Draw();
    danvas->SaveAs("alpha_counts.gif");


    hPhotonPt[0]->Scale( 1./hPhotonPt[0]->GetEntries() );
    hPhotonPt[1]->Scale( 1./hPhotonPt[1]->GetEntries() );
    TCanvas *d1 = new TCanvas();
    hPhotonPt[0]->Draw();
    hPhotonPt[1]->SetMarkerColor(kRed);
    hPhotonPt[1]->Draw("same");
    d1->SetLogy();
    TLegend *leg = new TLegend(0.75,0.75,0.9,0.9);
    leg->SetFillColor(0);
    leg->AddEntry(hPhotonPt[0], "Data","P");
    leg->AddEntry(hPhotonPt[1], "MC", "P");
    leg->DrawClone();
    d1->SaveAs("photon_pt.gif");

    hPhotonEta[0]->Scale( 1./hPhotonEta[0]->GetEntries() );
    hPhotonEta[1]->Scale( 1./hPhotonEta[1]->GetEntries() );
    TCanvas *d2 = new TCanvas();
    hPhotonEta[0]->Draw();
    hPhotonEta[1]->SetMarkerColor(kRed);
    hPhotonEta[1]->Draw("same");
    leg->DrawClone();
    d2->SaveAs("photon_eta.gif");

    hJet2Pt[0]->Scale( 1./hJet2Pt[0]->GetEntries() );
    hJet2Pt[1]->Scale( 1./hJet2Pt[1]->GetEntries() );
    TCanvas *d3 = new TCanvas();
    hJet2Pt[0]->Draw();
    hJet2Pt[1]->SetMarkerColor(kRed);
    hJet2Pt[1]->Draw("same");
    d3->SetLogy();
    leg->DrawClone();
    d3->SaveAs("jet2_pt.gif");

    hJet2Eta[0]->Scale( 1./hJet2Eta[0]->GetEntries() );
    hJet2Eta[1]->Scale( 1./hJet2Eta[1]->GetEntries() );
    TCanvas *d4 = new TCanvas();
    hJet2Eta[0]->Draw();
    hJet2Eta[1]->SetMarkerColor(kRed);
    hJet2Eta[1]->Draw("same");
    leg->DrawClone();
    d4->SaveAs("jet2_eta.gif");

    hJet3Pt[0]->Scale( 1./hJet3Pt[0]->GetEntries() );
    hJet3Pt[1]->Scale( 1./hJet3Pt[1]->GetEntries() );
    TCanvas *d5 = new TCanvas();
    hJet3Pt[0]->Draw();
    hJet3Pt[1]->SetMarkerColor(kRed);
    hJet3Pt[1]->Draw("same");
    d5->SetLogy();
    leg->DrawClone();
    d5->SaveAs("jet3_pt.gif");

    hJet3Eta[0]->Scale( 1./hJet3Eta[0]->GetEntries() );
    hJet3Eta[1]->Scale( 1./hJet3Eta[1]->GetEntries() );
    TCanvas *d6 = new TCanvas();
    hJet3Eta[0]->Draw();
    hJet3Eta[1]->SetMarkerColor(kRed);
    hJet3Eta[1]->Draw("same");
    leg->DrawClone();
    d6->SaveAs("jet3_eta.gif");
}
Esempio n. 9
0
void figure2_0_generate(){

	TFile* f;
	const int NAchBins = 7;
	const double correction = 1.0;


	//185-220 correction
	//const double correction = 0.675;

	
	//30-40% correction
	//const double correction = 0.641;



	TH1D* c2_pos_case1[100][4][2];
	TH1D* c2_neg_case1[100][4][2];
	TH1D* c2_tot_case1[100][4][2];

	TH1D* c2_pos_case2[100][4][2];
	TH1D* c2_neg_case2[100][4][2];
	TH1D* c2_tot_case2[100][4][2];


	TH1D* ach_hist[100];
	TH1D* c2_pos[100][4];
	TH1D* c2_neg[100][4];

	double x[NAchBins];
	double v2_pos[NAchBins];
	double v2_neg[NAchBins];
	double err_pos[NAchBins];
	double err_neg[NAchBins];
	double v2_diff[NAchBins];
	double err_diff[NAchBins];

	double numerator;
	double denominator;
	double q0,q1,q2,q3;

	double esquared;

	double v2_pos_sample[100][10];
	double v2_neg_sample[100][10];
	double v2_diff_sample[100][10];


	for (int m = 0; m < 10; ++m)
	{
		f = new TFile(Form("~/Summer2016/rootfiles/FinalResult_pPb/leaveout%d.root",m+1));
		for (Int_t i = 0; i < NAchBins; i++){
			for(Int_t j = 0 ; j < 4; j++){

				c2_tot_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case1",i,j));
				c2_tot_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case1",i,j));
				c2_pos_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case1",i,j));
				c2_pos_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case1",i,j));
				c2_neg_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case1",i,j));
				c2_neg_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case1",i,j));

				c2_tot_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case2",i,j));
				c2_tot_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case2",i,j));
				c2_pos_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case2",i,j));
				c2_pos_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case2",i,j));
				c2_neg_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case2",i,j));
				c2_neg_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case2",i,j));

			}
		}

		for (int i = 0; i < NAchBins; ++i)
		{
			c2_pos[i][0] =  new TH1D(*c2_pos_case1[i][0][0]);
			c2_pos[i][0] -> Add(c2_pos_case2[i][0][0],1.);

			c2_pos[i][1] =  new TH1D(*c2_pos_case1[i][1][0]);
			c2_pos[i][1] -> Add(c2_pos_case2[i][2][0],1.);

			c2_pos[i][2] =  new TH1D(*c2_pos_case1[i][2][0]);
			c2_pos[i][2] -> Add(c2_pos_case2[i][1][0],1.);

			c2_pos[i][3] =  new TH1D(*c2_pos_case1[i][3][0]);
			c2_pos[i][3] -> Add(c2_pos_case2[i][3][0],1.);

			c2_neg[i][0] =  new TH1D(*c2_neg_case1[i][0][0]);
			c2_neg[i][0] -> Add(c2_neg_case2[i][0][0],1.);

			c2_neg[i][1] =  new TH1D(*c2_neg_case1[i][1][0]);
			c2_neg[i][1] -> Add(c2_neg_case2[i][2][0],1.);

			c2_neg[i][2] =  new TH1D(*c2_neg_case1[i][2][0]);
			c2_neg[i][2] -> Add(c2_neg_case2[i][1][0],1.);

			c2_neg[i][3] =  new TH1D(*c2_neg_case1[i][3][0]);
			c2_neg[i][3] -> Add(c2_neg_case2[i][3][0],1.);

		}

		for(Int_t i=0; i<NAchBins; i++){

			
//positive
			q0 = c2_pos[i][0]->GetMean();
			q1 = c2_pos[i][1]->GetMean();
			q2 = c2_pos[i][2]->GetMean();
			q3 = c2_pos[i][3]->GetMean();

			numerator = q0;
			denominator = sqrt((q1*q2)/q3);
			v2_pos_sample[i][m] = numerator/denominator;

//negative
			q0 = c2_neg[i][0]->GetMean();
			q1 = c2_neg[i][1]->GetMean();
			q2 = c2_neg[i][2]->GetMean();
			q3 = c2_neg[i][3]->GetMean();
			numerator = q0;
			denominator = sqrt((q1*q2)/q3);
			v2_neg_sample[i][m] = numerator/denominator;

			v2_diff_sample[i][m] = (v2_neg_sample[i][m] - v2_pos_sample[i][m])/(v2_neg_sample[i][m] + v2_pos_sample[i][m]);


		}



	}

	f = new TFile("~/Summer2016/rootfiles/FinalResult_pPb/Merged.root");


	for (Int_t i = 0; i < NAchBins; i++){

		ach_hist[i] = (TH1D*)f->Get(Form("demo_n3/ach_%d",i+1));
		
		for(Int_t j = 0 ; j < 4; j++){
			
			c2_tot_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case1",i,j));
			c2_tot_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case1",i,j));
			c2_pos_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case1",i,j));
			c2_pos_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case1",i,j));
			c2_neg_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case1",i,j));
			c2_neg_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case1",i,j));

			c2_tot_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case2",i,j));
			c2_tot_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case2",i,j));
			c2_pos_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case2",i,j));
			c2_pos_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case2",i,j));
			c2_neg_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case2",i,j));
			c2_neg_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case2",i,j));

			//c2_pos_case2[i][j][0] ->Sumw2();
			//c2_neg_case2[i][j][0] ->Sumw2(); 

		}
	}

	for (int i = 0; i < NAchBins; ++i)
	{
		c2_pos[i][0] =  new TH1D(*c2_pos_case1[i][0][0]);
		c2_pos[i][0] -> Add(c2_pos_case2[i][0][0],1.);
		
		c2_pos[i][1] =  new TH1D(*c2_pos_case1[i][1][0]);
		c2_pos[i][1] -> Add(c2_pos_case2[i][2][0],1.);

		c2_pos[i][2] =  new TH1D(*c2_pos_case1[i][2][0]);
		c2_pos[i][2] -> Add(c2_pos_case2[i][1][0],1.);

		c2_pos[i][3] =  new TH1D(*c2_pos_case1[i][3][0]);
		c2_pos[i][3] -> Add(c2_pos_case2[i][3][0],1.);

		c2_neg[i][0] =  new TH1D(*c2_neg_case1[i][0][0]);
		c2_neg[i][0] -> Add(c2_neg_case2[i][0][0],1.);
		
		c2_neg[i][1] =  new TH1D(*c2_neg_case1[i][1][0]);
		c2_neg[i][1] -> Add(c2_neg_case2[i][2][0],1.);

		c2_neg[i][2] =  new TH1D(*c2_neg_case1[i][2][0]);
		c2_neg[i][2] -> Add(c2_neg_case2[i][1][0],1.);

		c2_neg[i][3] =  new TH1D(*c2_neg_case1[i][3][0]);
		c2_neg[i][3] -> Add(c2_neg_case2[i][3][0],1.);

	}



	
	
	for(Int_t i=0; i<NAchBins; i++){
		
//x coordinates
		x[i]=ach_hist[i]->GetMean();
		x[i]*=correction;

//positive
		q0 = c2_pos[i][0]->GetMean();
		q1 = c2_pos[i][1]->GetMean();
		q2 = c2_pos[i][2]->GetMean();
		q3 = c2_pos[i][3]->GetMean();


		numerator = q0;
		denominator = sqrt((q1*q2)/q3);
		v2_pos[i] = numerator/denominator;

//negative
		q0 = c2_neg[i][0]->GetMean();
		q1 = c2_neg[i][1]->GetMean();
		q2 = c2_neg[i][2]->GetMean();
		q3 = c2_neg[i][3]->GetMean();
		numerator = q0;
		denominator = sqrt((q1*q2)/q3);
		v2_neg[i] = numerator/denominator;

//difference
		v2_diff[i] = (v2_neg[i]-v2_pos[i])/(v2_neg[i]+v2_pos[i]);


//error bars
		double variance_pos = 0.0;
		double variance_neg = 0.0;
		double variance_diff = 0.0;
		double sum;

		for (int k = 0; k < 10; ++k)
		{
			variance_pos += (v2_pos_sample[i][k]-v2_pos[i])*(v2_pos_sample[i][k]-v2_pos[i]);
			variance_neg += (v2_neg_sample[i][k]-v2_neg[i])*(v2_neg_sample[i][k]-v2_neg[i]);
			variance_diff += (v2_diff_sample[i][k]-v2_diff[i])*(v2_diff_sample[i][k]-v2_diff[i]);
		}
		sum = v2_pos[i] + v2_neg[i];
		variance_pos *= 0.9;
		variance_neg *= 0.9;
		variance_diff *= 0.9;
		//variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum);

		err_pos[i] = sqrt(variance_pos);
		err_neg[i] = sqrt(variance_neg);
		err_diff[i] = sqrt(variance_diff);
		
	}
	

	TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos);
	TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg);
	TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff);

	TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure2_0_notcorrected.root","RECREATE");
	gr_pos->Write();
	gr_neg->Write();
	gr_diff->Write();
	

/*
	gr_pos->RemovePoint(0);
	gr_pos->RemovePoint(5);

	gr_neg->RemovePoint(0);
	gr_neg->RemovePoint(5);

	gr_diff->RemovePoint(0);
	gr_diff->RemovePoint(5);
*/




	gStyle->SetLegendFont(42);
	TH1D* base = new TH1D("base","base",1,-0.20,0.20);
	//pPb
	//base->GetYaxis()->SetRangeUser(0.065, 0.075);
	base->GetYaxis()->SetRangeUser(0.06, 0.12);

	//PbPb
	//base->GetYaxis()->SetRangeUser(0.093, 0.103);
	base->GetXaxis()->SetTitle("Observed A_{ch}");
	base->GetYaxis()->SetTitle("v_{2}{2}");
	base->GetXaxis()->CenterTitle();
	base->GetYaxis()->CenterTitle();
	base->SetTitleSize  (0.040,"X");
	base->SetTitleOffset(1.4,"X");
	base->SetTitleFont  (42,"X");
	base->SetLabelOffset(0.006,"X");
	base->SetLabelSize  (0.040,"X");
	base->SetLabelFont  (42   ,"X");

	base->SetTitleSize  (0.040,"Y");
	base->SetTitleOffset(2.2,"Y");
	base->SetTitleFont  (42,"Y");
	base->SetLabelOffset(0.006,"Y");
	base->SetLabelSize  (0.040,"Y");
	base->SetLabelFont  (42   ,"Y");
	base->SetLineWidth(0);

	TH1D* base2 = new TH1D("base2","base2",1,-0.2,0.2);
	base2->GetYaxis()->SetRangeUser(-0.03, 0.03);
	base2->GetXaxis()->SetTitle("Observed A_{ch}");
	base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) ");
	base2->GetXaxis()->CenterTitle();
	base2->GetYaxis()->CenterTitle();
	base2->SetTitleSize  (0.040,"X");
	base2->SetTitleOffset(1.4,"X");
	base2->SetTitleFont  (42,"X");
	base2->SetLabelOffset(0.006,"X");
	base2->SetLabelSize  (0.040,"X");
	base2->SetLabelFont  (42   ,"X");
	base2->SetTitleSize  (0.040,"Y");
	base2->SetTitleOffset(2.0,"Y");
	base2->SetTitleFont  (42,"Y");
	base2->SetLabelOffset(0.006,"Y");
	base2->SetLabelSize  (0.040,"Y");
	base2->SetLabelFont  (42   ,"Y");
	base2->SetLineWidth(0);

	

 //   TCanvas* c1 = new TCanvas("c1","c1");
 //   TCanvas* c2 = new TCanvas("c2","c2");
	TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600);
	c3->Divide(2,1,0.01,0.01);

	gr_neg -> SetMarkerStyle(20);
	gr_neg -> SetMarkerColor(kBlue);
	gr_pos -> SetMarkerStyle(34);	
	gr_pos -> SetMarkerColor(kRed);




	TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ;
	//TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 220",0.25,0.80) ;
	TLatex* text_b = makeLatex("30-40%",0.25,0.80) ;

	TLatex* text_c = makeLatex("0.3 < p_{T} < 3.0 GeV/c",0.25,0.75) ;
	TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.70) ;

	text_a->SetTextFont(42);
	text_b->SetTextFont(42);
	text_c->SetTextFont(42);
	text_d->SetTextFont(42);



	TLegend* leg = new TLegend(0.76,0.80,0.94,.88);
	leg->SetLineColor(kWhite);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);
	leg->AddEntry(gr_pos, "v_{2}^{#plus}{2}","p");
	leg->AddEntry(gr_neg , "v_{2}^{#minus}{2}","p");



	c3->cd(1);
	base->Draw("");
	gr_pos->Draw("PSame");
	gr_neg->Draw("PSame");
	text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	text_c->DrawClone("Same");
	text_d->DrawClone("Same");

	leg->DrawClone("Same");


    //Define a linear function
	TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.13, 0.13);



	fit1->SetLineColor(kRed);
	fit1->SetLineStyle(2);
	gr_diff->Fit(fit1,"RN0");
fit1->Write();
rebinned->Close();

	c3->cd(2);



	TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ;
	TLatex* text1 = makeLatex(Form("slope : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ;
	text1->SetTextFont(42);
	text2->SetTextFont(42);
	base2->Draw("");
	fit1->DrawClone("Same");
	gr_diff->SetMarkerStyle(20);
	gr_diff->Draw("PSame");

	text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	

	text1->DrawClone("Same");
	text2->DrawClone("Same");

	

	TF1 *fa1 = new TF1("fa1","0",-10,10); 
	fa1->SetLineColor(kBlack);
	fa1->SetLineWidth(0);
	fa1->DrawClone("Same");

	TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78);
	leg2->SetLineColor(kWhite);
	leg2->SetFillColor(0);
	leg2->SetFillStyle(0);
	leg2->AddEntry(fit1, "Linear fit","l");
	leg2->AddEntry(gr_diff , "data","p");
	leg2->DrawClone("Same");

	//SaveCanvas(c3,"pics",Form("30-40SP"));


}
Esempio n. 10
0
void compareWeights(const char* fileName, const std::string plotTitle,
                    const std::string plotType, const std::string plot,
                    const std::string xlabel, const float xMin, const float xMax) {
    gStyle->SetOptStat(0);
    gROOT->ForceStyle();
 
    THStack* histStack = new THStack("histStack", plotTitle.c_str());
    TLegend* legend = new TLegend(.55 ,.55 ,.885 ,.875);
    legend->SetFillColor(kWhite);
     
    std::vector<std::string> weightNames = {"unit wgt = 0.000001"};
                                            //{"f_{T1} = 5e-12 ", "f_{T1} = 4e-12 ", 
                                            //"f_{T1} = 1.5e-12 ", "Standard Model"};
    std::vector<int> colors = {kRed-7, kAzure-3, kGreen-6, kBlack, kBlue-4};

    TFile signal_file(fileName);
    TCanvas* canvas = new TCanvas("canvas","Weight Comparison",150,10,990,660);
    canvas->cd();

    int numBins = 13;
    float rebinPoint = 0;
    double variableBins[numBins+1];
    for (int i = 0; i <= numBins; i++)
    {
        if (i < 10)
            rebinPoint += 75.;
        else if (i < 11)
            rebinPoint += 150.;
        else
            rebinPoint += 200;
        variableBins[i] = rebinPoint;
    }

    std::string bg_path = "/nfs_scratch/kdlong/wpz_zg_qcdbkgd/Events/run_01/";
    bg_path += fileName; 
    addBackground(histStack, bg_path, plotType, plot, legend, "WZ EWK + QCD",
                  variableBins, numBins);

    for (unsigned int i = 0; i < weightNames.size(); i++)
    {
        std::string path = weightNames[i] + "/" + plotType + "/" + plot;
        TH1F* hist = static_cast<TH1F*>(signal_file.GetObjectChecked(path.c_str(), 
                                                                     "TH1F"));
        //hist->SetFillColor(colors[i]);
        hist->SetLineColor(colors[i]);
        hist->SetLineWidth(2);
        TH1* histRebin = hist->Rebin(numBins, "histRebin", variableBins);
        histRebin->Sumw2();
        histStack->Add(histRebin, "hist E1");
        std::string legendName = "WZ EWK (" + weightNames[i] + ")";
        legend->AddEntry(hist, legendName.c_str(), "l");
    }
    
    histStack->Draw("nostack");
    histStack->GetXaxis()->SetTitle(xlabel.c_str());
    histStack->GetYaxis()->SetTitle("Events");
    //histStack->GetXaxis()->SetRangeUser(xMin, xMax); 
    //histStack->SetMaximum(125); 
    histStack->DrawClone("nostack");
    legend->DrawClone("same");
    canvas->Update();
    canvas->Print("WZTMassComp_zg_bg_cuts.pdf");
}
void CumulantErrGraph_v2_normalized(){

	TFile *f;

	const int NAchBins = 7;

	TH1D* c2_pos[NAchBins][2];
	TH1D* c2_neg[NAchBins][2];

	TH1D* ach_hist[NAchBins];
	double x[NAchBins];

	double v2_pos[NAchBins];
	double v2_neg[NAchBins];
	double v2_diff[NAchBins];
	double err_neg[NAchBins];
	double err_pos[NAchBins];
	double err_diff[NAchBins];
	double cmean;
	double errmean;
	double sum;
	double variance_pos;
	double variance_neg;
	double variance_diff;

	int low = 60;
	int upp = 90;


	f = new TFile(Form("../../../rootfiles/crosscheck/PbPb/v3/%d_%d/Merged.root",low,upp));
	TLatex* text_b = makeLatex(Form("centrality %d-%d",low,upp),0.25,0.88) ;



	for (Int_t i = 0; i < NAchBins; i++){
		ach_hist[i] = (TH1D*)f->Get(Form("demo/ach_%d",i+1));

		c2_pos[i][0] = (TH1D*)f->Get(Form("demo/c2pos_%d_cos",i));
		c2_pos[i][1] = (TH1D*)f->Get(Form("demo/c2pos_%d_sin",i));

		c2_neg[i][0] = (TH1D*)f->Get(Form("demo/c2neg_%d_cos",i));
		c2_neg[i][1] = (TH1D*)f->Get(Form("demo/c2neg_%d_sin",i));
		
	}
	for(Int_t i=0; i<NAchBins; i++){

		x[i]=ach_hist[i]->GetMean();

//v2 positive
		cmean = c2_pos[i][0] -> GetMean();
		v2_pos[i] = sqrt(cmean);

		errmean = c2_pos[i][0] -> GetMeanError();
		variance_pos = (errmean*errmean)/(4*cmean);

//negative
		cmean = c2_neg[i][0] -> GetMean();
		v2_neg[i] = sqrt(cmean);

		errmean = c2_neg[i][0] -> GetMeanError();
		variance_neg = (errmean*errmean)/(4*cmean);

		//difference
		v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]);

		sum = v2_pos[i] + v2_neg[i];

		variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum);


	//error bars

		err_pos[i] = sqrt(variance_pos);
		err_neg[i] = sqrt(variance_neg);
		err_diff[i] = sqrt(variance_diff);


	}
	cout << low << upp << endl;
	for(i=0;i<NAchBins;i++){
		cout << x[i] << ", ";
	}	
	cout << endl << "v2" << endl;
	for(i=0;i<NAchBins;i++){
		cout << v2_diff[i] << ", ";
	}
	cout << endl << "v2 error" <<endl;
	for(i=0;i<NAchBins;i++){
		cout << "error is: " << err_pos[i] << endl;
	}		
	gStyle->SetLegendFont(42);
	TH1D* base = new TH1D("base","base",1,-0.3,0.3);
	//pPb
	//base->GetYaxis()->SetRangeUser(0.065, 0.075);

	//PbPb
	base->GetYaxis()->SetRangeUser(0.018, 0.03);
	base->GetXaxis()->SetTitle("Observed A_{ch}");
	base->GetYaxis()->SetTitle("v_{3}{2}");
	base->GetXaxis()->CenterTitle();
	base->GetYaxis()->CenterTitle();
	base->SetTitleSize  (0.040,"X");
	base->SetTitleOffset(1.4,"X");
	base->SetTitleFont  (42,"X");
	base->SetLabelOffset(0.006,"X");
	base->SetLabelSize  (0.040,"X");
	base->SetLabelFont  (42   ,"X");

	base->SetTitleSize  (0.040,"Y");
	base->SetTitleOffset(2.2,"Y");
	base->SetTitleFont  (42,"Y");
	base->SetLabelOffset(0.006,"Y");
	base->SetLabelSize  (0.040,"Y");
	base->SetLabelFont  (42   ,"Y");
	base->SetLineWidth(0);

	TH1D* base2 = new TH1D("base2","base2",1,-0.4,0.4);
	base2->GetYaxis()->SetRangeUser(-0.06, 0.06);
	base2->GetXaxis()->SetTitle("Observed A_{ch}");
	base2->GetYaxis()->SetTitle(" #frac{ v_{3}^{#minus} #minus v_{3}^{#plus} }{ v_{3}^{#minus} #plus v_{3}^{#plus} } ");
	base2->GetXaxis()->CenterTitle();
	base2->GetYaxis()->CenterTitle();
	base2->SetTitleSize  (0.040,"X");
	base2->SetTitleOffset(1.4,"X");
	base2->SetTitleFont  (42,"X");
	base2->SetLabelOffset(0.006,"X");
	base2->SetLabelSize  (0.040,"X");
	base2->SetLabelFont  (42   ,"X");
	base2->SetTitleSize  (0.040,"Y");
	base2->SetTitleOffset(2.0,"Y");
	base2->SetTitleFont  (42,"Y");
	base2->SetLabelOffset(0.006,"Y");
	base2->SetLabelSize  (0.040,"Y");
	base2->SetLabelFont  (42   ,"Y");
	base2->SetLineWidth(0);

	TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure2_1.root","RECREATE");

	TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos);
	TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg);
	TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff);

	gr_pos->Write();
	gr_neg->Write();
	gr_diff->Write();



 //   TCanvas* c1 = new TCanvas("c1","c1");
 //   TCanvas* c2 = new TCanvas("c2","c2");
	TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600);
	c3->Divide(2,1,0.01,0.01);

	gr_neg -> SetMarkerStyle(20);
	gr_neg -> SetMarkerColor(kBlue);
	gr_pos -> SetMarkerStyle(34);	
	gr_pos -> SetMarkerColor(kRed);




	TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ;
	//TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 260",0.25,0.80) ;

	TLatex* text_c = makeLatex("0.3 < p_{T} < 3 GeV/c",0.25,0.75) ;
	TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.70) ;

	text_a->SetTextFont(42);
	text_b->SetTextFont(42);
	text_c->SetTextFont(42);
	text_d->SetTextFont(42);



	TLegend* leg = new TLegend(0.76,0.80,0.94,.88);
	leg->SetLineColor(kWhite);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);
	leg->AddEntry(gr_pos, "v_{3}^{#plus}{2}","p");
	leg->AddEntry(gr_neg , "v_{3}^{#minus}{2}","p");



	c3->cd(1);
	base->Draw("");
	gr_pos->Draw("PSame");
	gr_neg->Draw("PSame");
	//text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	//text_c->DrawClone("Same");
	//text_d->DrawClone("Same");

	leg->DrawClone("Same");


    //Define a linear function
	TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.2, 0.2);
	fit1->SetLineColor(kRed);
	fit1->SetLineStyle(2);
	gr_diff->Fit(fit1,"N0");
	fit1->Write();
	rebinned->Close();



	c3->cd(2);



	TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ;
	TLatex* text1 = makeLatex(Form("slope : %.3f #pm %.3f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ;
	text1->SetTextFont(42);
	text2->SetTextFont(42);
	base2->Draw("");
	fit1->DrawClone("Same");
	gr_diff->SetMarkerStyle(20);
	gr_diff->Draw("PSame");

	//text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	

	text1->DrawClone("Same");
	text2->DrawClone("Same");

	

	TF1 *fa1 = new TF1("fa1","0",-10,10); 
	fa1->SetLineColor(kBlack);
	fa1->SetLineWidth(0);
	fa1->DrawClone("Same");

	TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78);
	leg2->SetLineColor(kWhite);
	leg2->SetFillColor(0);
	leg2->SetFillStyle(0);
	leg2->AddEntry(fit1, "Linear fit","l");
	leg2->AddEntry(gr_diff , "data","p");
	leg2->DrawClone("Same");

	SaveCanvas(c3,"pics",Form("PbPb_crosscheck_v3_%d_%d",low,upp));




}