//################################################################################################################################
//################################################################################################################################
//################################################################################################################################
TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TString xTitle, TString filename){

  
  TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500);
  c->cd();
  float y = 0.3;

  TPad *pad1     = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99);
  TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01);

  TH1D *ratio = 0;

  ratio = (TH1D*) sr->Clone();
  ratio->Divide(prediction);
  ratio->GetYaxis()->SetTitle((TString) sr->GetName() + "/" + (TString) prediction->GetName());
  ratio->SetTitle("");
  ratio->SetLabelSize(0.1,"X");
  ratio->SetLabelSize(0.1,"Y");
  ratio->SetTitleOffset(0.5,"Y");
  ratio->SetTitleSize(0.15,"Y");


  padRatio->cd();
  ratio->GetYaxis()->SetRangeUser(0,2);
  ratio->Draw();

  // Draw line at one!
  float xmin = ratio->GetXaxis()->GetXmin();
  float xmax = ratio->GetXaxis()->GetXmax();
  TLine *line = new TLine(xmin,1,xmax,1);
  line->SetLineWidth(2);
  line->Draw("same");
  padRatio->Modified();

  TLegend *leg = new TLegend(0.6,0.8,0.9,0.9);
  leg->AddEntry(sr,"bkg","l"); 
  leg->AddEntry(prediction,prediction->GetName(),"pel"); 
  pad1->cd();
  //pad1->SetLogy();

  sr->SetLineColor(kRed);
  sr->SetMarkerColor(kRed);
  sr->SetTitle("");
  prediction->SetTitle("");
  prediction->GetXaxis()->SetTitle(xTitle);
  sr->GetXaxis()->SetTitle(xTitle);

  prediction->SetTitleSize(0.07,"X");
  prediction->GetXaxis()->SetTitleOffset(0.7);
  sr->SetTitleSize(0.07,"X");
  sr->GetXaxis()->SetTitleOffset(0.7);

  prediction->Draw("e");
  sr->Draw("e same");

  if(sr->GetMaximum()>prediction->GetMaximum()){

    sr->Draw("e");
    prediction->Draw("e same");

    }

  leg->Draw("same");




  // Draw both pads to canvas
  c->cd();
  pad1->Draw();
  padRatio->SetGridy();
  padRatio->Draw();

  c->SaveAs(filename);

  return c;

}
//################################################################################################################################
TCanvas *drawRatioPlotWithPurity(TH1D *prediction, TH1D *sr, TString xTitle, TString filename, double purity, bool LowECaloRegion){
  
  TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500);
  c->cd();
  float y = 0.3;

  TPad *pad1     = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99);
  TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01);

  TH1D *ratio = 0;

  ratio = (TH1D*) sr->Clone();
  ratio->Divide(prediction);
  ratio->GetYaxis()->SetTitle((TString) sr->GetName() + "/" + (TString) prediction->GetName());
  ratio->SetTitle("");
  ratio->SetLabelSize(0.1,"X");
  ratio->SetLabelSize(0.1,"Y");
  ratio->SetTitleOffset(0.5,"Y");
  ratio->SetTitleSize(0.11,"Y");
  ratio->SetLineColor(kBlack);
  ratio->SetMarkerColor(kBlack);


  padRatio->cd();
  ratio->GetYaxis()->SetRangeUser(0,2);
  ratio->Draw();

  // Draw line at one!
  float xmin = ratio->GetXaxis()->GetXmin();
  float xmax = ratio->GetXaxis()->GetXmax();
  TLine *line = new TLine(xmin,1,xmax,1);
  line->SetLineWidth(2);
  line->Draw("same");
  padRatio->Modified();

  TLegend *leg = new TLegend(0.5,0.8,0.85,0.9);
  leg->AddEntry(sr,sr->GetName(),"l"); 
  leg->AddEntry(prediction,prediction->GetName(),"pel"); 
  pad1->cd();
  //pad1->SetLogy();

  sr->SetLineColor(kRed);
  sr->SetMarkerColor(kRed);
  prediction->SetLineColor(kBlack);
  prediction->SetMarkerColor(kBlack);
  sr->SetTitle("");
  prediction->SetTitle("");
  prediction->GetXaxis()->SetTitle(xTitle);
  sr->GetXaxis()->SetTitle(xTitle);

  prediction->SetTitleSize(0.07,"X");
  prediction->GetXaxis()->SetTitleOffset(0.7);
  sr->SetTitleSize(0.07,"X");
  sr->GetXaxis()->SetTitleOffset(0.7);

  prediction->Draw("e");
  sr->Draw("e same");

  double maximum =prediction->GetMaximum()*1.2;
  double minimum = 0.00001;
  if(sr->GetMinimum()!=0) minimum=sr->GetMinimum()*0.9;
  if(prediction->GetMinimum()!=0) minimum=prediction->GetMinimum()*0.9;
  if(sr->GetMaximum()>prediction->GetMaximum()){

    maximum=sr->GetMaximum()*1.2;
  }



  //leg->Draw("same");


  //***********************
  TLatex*  info   = new TLatex();
  info->SetTextFont(132);
  info-> SetNDC();
  info->SetTextSize(0.06);
  TString AuxString = Form("Purity of fakes in CR = %4.1f ",purity*100);
  //info->DrawLatex(0.4,0.7,AuxString);

  TLatex*  info1   = new TLatex();
  info1->SetTextFont(132);
  info1-> SetNDC();
  info1->SetTextSize(0.06);
  if(LowECaloRegion) AuxString = "E_{calo}<10GeV";
  else               AuxString = "E_{calo}>10GeV"; 
  //info1->DrawLatex(0.2,0.82,AuxString);
  //***********************

  // Draw both pads to canvas
  c->cd();
  pad1->Draw();
  padRatio->SetGridy();
  c -> SetBottomMargin(0.55);
  //c->Modified();
  padRatio->Draw();

  c->SaveAs(filename);

  return c;

}
Ejemplo n.º 3
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");






}
Ejemplo n.º 4
0
void CombineCentralitiesForDirectory(TString pairType, TDirectory *dataDir)
{
  // Gather the cfs and counts to combine centrality bins


  vector<TString> centBins010 = {"05", "510"};
  vector<TString> centBins1030 = {"1015", "1520", "2025", "2530"};
  vector<TString> centBins3050 = {"3035", "3540", "4045", "4550"};
  vector<TString> finalCentBins = {"010", "1030", "3050"};
  vector<vector<TString> > centBins;
  centBins.push_back(centBins010);
  centBins.push_back(centBins1030);
  centBins.push_back(centBins3050);

  TDirectory *mergeDir = dataDir->GetDirectory("Merged");
  if(!mergeDir) {
    cout<<"Merge directory does not exist. Cannot merge."<<endl;
    return;
  }

  //For each merge group, get the necessary CFs and counts
  for(UInt_t iMerge = 0; iMerge < centBins.size(); iMerge++) {
    vector<TH1D*> cfs;
    vector<Double_t> counts;
    Double_t totalCounts = 0;
    for(UInt_t iCF = 0; iCF < centBins[iMerge].size(); iCF++) {
      TString cfName = "CF" + pairType + centBins[iMerge][iCF];
      TH1D *cf = (TH1D*)mergeDir->Get(cfName);
      if(!cf) {
	cout<<"Could not find CF named "<<cfName<<" in "<<mergeDir->GetName()<<endl;
	return;
      }
      cfs.push_back(cf);
      TString countName = "Count" + pairType + centBins[iMerge][iCF];
      TVectorD *count = (TVectorD*) mergeDir->Get(countName);
      totalCounts += count[0](0);
      counts.push_back(count[0](0));
    }

    // Finally, combine the CFs
    TH1D *combinedCF = CombineCFs(cfs, counts);
    if (!combinedCF) {
      cout << "Combine CF returned nothing. Continuing loop."
	   <<endl;
      continue;
    }
    TVectorD finalCount(1);
    finalCount[0] = totalCounts;

    // Set names
    TString combinedCFName = "CF" + pairType + finalCentBins[iMerge];
    TString combinedCountName = "Count" + pairType + finalCentBins[iMerge];
    combinedCF->SetName(combinedCFName);
    combinedCF->SetTitle(combinedCFName);

    // Set axis ranges
    combinedCF->SetAxisRange(0.9, 1.1, "Y");
    combinedCF->SetAxisRange(0., .5, "X");
    combinedCF->SetLabelSize(0.05, "X");
    combinedCF->SetLabelSize(0.05, "Y");
    combinedCF->SetTitleSize(0.05, "X");
    combinedCF->SetNdivisions(505, "X");
    combinedCF->SetNdivisions(505, "Y");
    
    cout<<"Writing combined CF "<<combinedCF->GetName()
    	<<" to "<<mergeDir->GetName()<<endl;
    combinedCF->SetDirectory(0);
    mergeDir->cd();
    combinedCF->Write(combinedCF->GetName(), TObject::kOverwrite);
    finalCount.Write(combinedCountName, TObject::kOverwrite);
  }
}
Ejemplo n.º 5
0
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();
}
Ejemplo n.º 6
0
TCanvas* DrawComparison(TH1D* prediction, TH1D* selection, TString Title, TString LumiTitle, TString xTitle, bool isData)
{
   double MinX = selection->GetXaxis()->GetXmin();
   double MaxX = selection->GetXaxis()->GetXmax();
   double MaxY = selection->GetMaximum();
   double YRangeMax = MaxY;
   TString titlePrediction;
   TString titleSelection;
   TString RatioTitle;
   
   if( isData ){
      titlePrediction = "Data";
      titleSelection = "MC";
      RatioTitle = "(Data-MC)/MC";
   }
   else {
      titlePrediction = "Data-driven Pred. from MC";
      titleSelection = "MC Expectation";
      RatioTitle = "(Pred-MC)/MC";
   }

   //static Int_t c_LightBrown   = TColor::GetColor( "#D9D9CC" );
   static Int_t c_LightGray    = TColor::GetColor( "#DDDDDD" );

   prediction->SetAxisRange(MinX, MaxX, "X");
   prediction->GetYaxis()->SetRangeUser(0.005, YRangeMax);
   prediction->SetMarkerStyle(20);
   prediction->SetMarkerSize(0.9);
   prediction->SetMarkerColor(kBlack);
   prediction->SetXTitle(xTitle);
   prediction->SetYTitle("Events");
   selection->SetAxisRange(MinX, MaxX, "X");
   selection->GetYaxis()->SetRangeUser(0.05, YRangeMax);
   // selection->SetFillColor(c_LightBrown);
   selection->SetFillColor(c_LightGray);
   selection->SetTitle("");
   selection->SetXTitle(xTitle);
   selection->SetYTitle("Events");
   TCanvas *c = new TCanvas("ca", "Comparison and ratio of two histos", 700, 700);
   TPad *pad1 = new TPad("pad1a", "pad1a", 0, 0.35, 1, 1);
   //pad1->SetLogy();
   pad1->SetBottomMargin(0);
   pad1->Draw();
   pad1->cd();
  
   selection->DrawCopy("hist");
   prediction->Draw("same");
   selection->SetFillColor(kAzure-3);
   selection->SetFillStyle(3354);
   selection->DrawCopy("e2same");
   selection->SetFillStyle(1001);
   //  selection->SetFillColor(c_LightBrown);
   selection->SetFillColor(c_LightGray);

   TLegend* leg1 = new TLegend(0.48, 0.63, 0.95, 0.83);
   leg1->SetFillStyle(0);
   leg1->SetLineStyle(1);
   leg1->SetTextFont(42);
   leg1->SetTextSize(0.04);
   leg1->AddEntry(selection, titleSelection, "lf");
   leg1->AddEntry(prediction, titlePrediction, "lep");
   leg1->Draw("same");
 
   TPaveText* pt = new TPaveText(0.11, 0.98, 0.95, 0.86, "NDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.045);
   pt->AddText(Title);
   pt->AddText(LumiTitle);
   pt->Draw();
   c->cd();
   TPad *pad2 = new TPad("pad2a", "pad2a", 0, 0, 1, 0.35);
   pad2->SetTopMargin(0);
   pad2->Draw();
   pad2->cd();
   TH1D* r = new TH1D(*selection);
   r->SetTitle("");
   r->SetLabelSize(0.08, "XYZ");
   r->SetLabelOffset(0.01, "XYZ");
   r->SetTitleSize(0.09, "XYZ");
   r->SetTitleOffset(0.65, "Y");
   r->SetTickLength(0.05);
   r->SetYTitle(RatioTitle);
   r->SetStats(0);
   r->SetMarkerStyle(20);
   r->SetMarkerSize(0.9);
   r->SetMarkerColor(kBlack);
   r->Reset();
   r->Add(prediction, 1);
   r->Add(selection, -1);
   r->Divide(selection);
   r->SetMaximum(1.2);
   r->SetMinimum(-1.2);
   r->Draw("ep");
   TLine l;
   l.DrawLine(MinX, 0., MaxX, 0.);
   c->cd();
   return c;
}
TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TString xTitle, TString filename){

  
  TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500);

  float y = 0.3;

  TPad *pad1     = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99);
  TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01);

  TH1D *ratio = 0;

  //ratio = (TH1D*) sr->Clone();
  //ratio->Divide(prediction);

  ratio = (TH1D*) prediction->Clone();
  ratio->Divide(sr);


  for(int i=1; i<=ratio->GetNbinsX();i++){

    cout<<"Scaling Factor in "<<i<<". bin ="<<ratio->GetBinContent(i)<<" +/- "<<ratio->GetBinError(i)<<endl; 

  }

  ratio->GetYaxis()->SetTitle("Pred/Bkg");
  ratio->SetTitle("");
  ratio->SetLabelSize(0.1,"X");
  ratio->SetLabelSize(0.1,"Y");
  ratio->SetTitleOffset(0.5,"Y");
  ratio->SetTitleSize(0.15,"Y");


  padRatio->cd();
  //ratio->GetYaxis()->SetRangeUser(0,2);
  ratio->Draw();

  // Draw line at one!
  float xmin = ratio->GetXaxis()->GetXmin();
  float xmax = ratio->GetXaxis()->GetXmax();
  TLine *line = new TLine(xmin,1,xmax,1);
  line->SetLineWidth(2);
  line->Draw("same");
  padRatio->Modified();

  TLegend *leg = new TLegend(0.6,0.8,0.9,0.9);
  leg->AddEntry(sr,"bkg","l"); 
  leg->AddEntry(prediction,"bkg prediction","pel"); 
  pad1->cd();
  pad1->SetLogy();

  sr->SetLineColor(kRed);
  sr->SetMarkerColor(kRed);
  sr->SetMarkerStyle(20);
  sr->SetTitle("");
  prediction->SetMarkerStyle(20);
  prediction->SetTitle("");
  prediction->GetXaxis()->SetTitle(xTitle);
  sr->GetXaxis()->SetTitle(xTitle);

  prediction->SetTitleSize(0.07,"X");
  prediction->GetXaxis()->SetTitleOffset(0.7);
  sr->SetTitleSize(0.07,"X");
  sr->GetXaxis()->SetTitleOffset(0.7);

  prediction->Draw("e");
  sr->Draw("e same");

  double maximum =prediction->GetMaximum()*2.5;
  double minimum = 0.00001;
  if(sr->GetMinimum()!=0) minimum=sr->GetMinimum()*0.5;
  if(prediction->GetMinimum()!=0) minimum=prediction->GetMinimum()*0.5;
  if(sr->GetMaximum()>prediction->GetMaximum()){

    maximum=sr->GetMaximum()*2.5;
  }

  prediction->GetYaxis()->SetRangeUser(minimum,maximum);

  leg->Draw("same");




  // Draw both pads to canvas
  c->cd();
  pad1->Draw();
  padRatio->SetGridy();
  padRatio->Draw();

  c->SaveAs(filename);

  return c;

}
TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TH1D *data, TString xTitle, TString filename, double ecaloCut){

  gStyle -> SetPadLeftMargin(0.20);

  data->SetMarkerStyle(20);
  data->SetMarkerColor(kGreen);
  data->SetLineColor(kGreen);


  
  TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500);

  float y = 0.3;

  TPad *pad1     = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99);
  TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01);

  pad1->SetNumber(100);
  pad1->SetTicks(0,1);
  cout<<"number pad1     = "<<pad1->GetNumber()<<endl;
  cout<<"number padRatio = "<<padRatio->GetNumber()<<endl;

  TH1D *ratio = 0;

  //ratio = (TH1D*) sr->Clone();
  //ratio->Divide(prediction);

  ratio = (TH1D*) prediction->Clone();
  ratio->Divide(data);



  for(int i=1; i<=ratio->GetNbinsX();i++){

    if(ratio->GetBinContent(i) != 0){
      cout<<"N in CR in "<<i<<". bin ="<<prediction->GetBinContent(i)<<endl;
      cout<<"N in SR in "<<i<<". bin ="<<sr->GetBinContent(i)<<endl;
      cout<<"Rel. difference in "<<i<<". bin ="<<(1./ratio->GetBinContent(i)-1.)*100<<"%"<<endl; 
    }
    else if(sr->GetBinContent(i) == 0 && prediction->GetBinContent(i) !=0)    cout<<"Scaling Factor in "<<i<<". bin <"<<prediction->GetBinContent(i)/1.15<<" +/- "<<ratio->GetBinError(i)<<endl;
    else if(sr->GetBinContent(i) != 0 && prediction->GetBinContent(i) ==0)    cout<<"Scaling Factor in "<<i<<". bin <"<<(sr->GetEntries()/prediction->GetEntries())/sr->GetBinContent(i)<<" +/- "<<ratio->GetBinError(i)<<endl;

  }

  ratio->GetYaxis()->SetTitle("#frac{CR (MC)}{CR (data)}");
  ratio->SetTitle("");
  ratio->SetLabelSize(0.1,"X");
  ratio->SetLabelSize(0.1,"Y");
  ratio->SetTitleOffset(0.5,"Y");
  ratio->SetTitleSize(0.15,"Y");


  padRatio->cd();
  //ratio->GetYaxis()->SetRangeUser(0,2);
  ratio->Draw("e");

  // Draw line at one!
  float xmin = ratio->GetXaxis()->GetXmin();
  float xmax = ratio->GetXaxis()->GetXmax();
  TLine *line = new TLine(xmin,1,xmax,1);
  line->SetLineWidth(2);
  line->Draw("same");
  padRatio->Modified();

  TLegend *leg = new TLegend(0.5,0.7,0.9,0.9);
  leg->AddEntry(sr,"SR (MC)","l"); 
  leg->AddEntry(prediction,"lepton CR (MC)","pel"); 
 
  pad1->cd();
  pad1->SetLogy();
  //  pad1->SetLogx();

  sr->SetLineColor(kRed);
  sr->SetMarkerColor(kRed);
  sr->SetMarkerStyle(20);
  sr->SetTitle("");
  prediction->SetMarkerStyle(20);
  prediction->SetTitle("");
  prediction->GetXaxis()->SetTitle(xTitle);
  sr->GetXaxis()->SetTitle(xTitle);

  
  

  prediction->SetTitleSize(0.07,"X");
  prediction->GetXaxis()->SetTitleOffset(0.7);
  sr->SetTitleSize(0.07,"X");
  sr->GetXaxis()->SetTitleOffset(0.7);

  double maximum = 0;
  double minimum = 1000000;
  if(sr->GetMinimum()!=0 && sr->GetMinimum()<minimum){
    minimum=sr->GetMinimum()*0.5;
  }
  if(prediction->GetMinimum()!=0 && prediction->GetMinimum()<minimum){
    minimum=prediction->GetMinimum()*0.5;
  }
  if(data->GetMinimum()!=0 && data->GetMinimum()<minimum){
    minimum=data->GetMinimum()*0.5;
  }
  if(sr->GetMaximum()>maximum){
    maximum=sr->GetMaximum()*2.5;
  }
  if(prediction->GetMaximum()>maximum){
    maximum=prediction->GetMaximum()*2.5;
  }
  if(data->GetMaximum()>maximum){
    maximum=data->GetMaximum()*2.5;
  }

  prediction->GetYaxis()->SetRangeUser(minimum,maximum);
  ratio->GetYaxis()->SetRangeUser(0,2);


  prediction->Draw("e");
  sr->Draw("e same");
  leg->AddEntry(data,"lepton CR (data)","pel"); 
  data->Draw("e same");

  
  leg->Draw("same");


  TLatex*  info1   = new TLatex();
  info1->SetTextFont(132);
  info1-> SetNDC();
  info1->SetTextSize(0.06);
  info1->DrawLatex(0.55,0.62,Form("E_{calo}<%.0fGeV",ecaloCut));

  // Draw both pads to canvas
  c->cd();
  pad1->Draw();
  padRatio->SetGridy();
  padRatio->Draw();

  c->SaveAs(filename);

  return c;

}
Ejemplo 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"));


}
Ejemplo n.º 10
0
void control(TString var,TString bin, TCut cuts, TCut cutsA, TString cutpoint,bool log,Double_t ymax){
setstyle();
 TH1::SetDefaultSumw2(true);
TCanvas *c2 = new TCanvas("canvas"+var+cutpoint,"canname"+var+cutpoint,700,800);

  TPad *mainPad = new TPad("","",0.01,0.25,0.99,0.99);
   mainPad->SetNumber(1);
   mainPad->Draw();
    TPad *ratioPad = new TPad("","",0.01,0.01,0.99,0.25);
   ratioPad->SetNumber(2);
   ratioPad->Draw();
 c2->cd(1);

 TCut lo = cuts && mu_pt_lo;
 TCut hi = cuts && mu_pt_hi;

 // TH1D *Ctrl_lo = GetHist("AS",kBlack,var,lo,bin,astQCD,cutpoint);
 // TH1D *Sig_lo = GetHist("S",kRed,var,lo,bin,stQCD,cutpoint);
  TH1D *Ctrl_hi = GetHist("AS",kBlack,var,cuts,bin,astQCD,cutpoint);
  TH1D *Sig_hi = GetHist("S",kRed,var,cuts,bin,stQCD,cutpoint);
  //  Ctrl_lo->Scale(1.94);
  //  Sig_lo->Scale(1.94);
  TH1D *Ctrl = Ctrl_hi->Clone();
  TH1D *Sig = Sig_hi->Clone();
  //  Ctrl->Add(Ctrl_hi);
  // Sig->Add(Sig_hi);

  Sig->Scale(intlumi);
  // TH1D *Ctrl = GetHist("AS",kBlack,var,cuts,bin,astQCD,cutpoint);
  if(Ctrl->Integral()!=0){
  Ctrl->Scale(Sig->Integral()/Ctrl->Integral());
  }
  
  if(log){ c2->cd(1)->SetLogy();}
  
 TLegend *leg = new TLegend(0.564,0.719,0.775,0.875);
 leg->SetTextSize(0.054);
  leg->SetFillColor(0);
  leg->SetLineColor(0);
  //  leg->AddEntry(Ctrl,"Anti-Selected","LF");
  leg->AddEntry(Sig,"Selected","LF");
    leg->AddEntry(Ctrl,"Anti-Selected","LF");

  Ctrl->Draw("EHIST9");
  Sig->Draw("E9same");

  Sig->SetMarkerStyle(20); Sig->SetMarkerColor(kRed);
  leg->Draw("same");
  Ctrl->SetTitle();
  Ctrl->GetXaxis()->SetTitle(var);
  if(log){
  Ctrl->GetYaxis()->SetRangeUser(0.001,ymax);
  }
  else{
    ymax=(Ctrl->GetMaximum()*1.6);
     Ctrl->GetYaxis()->SetRangeUser(0.,ymax);
  }
   TH1D *RatioBottom = (TH1D*)Ctrl->Clone("Ratiob");
   TH1D *RatioTop = (TH1D*)Sig->Clone("Ratiot");

  RatioTop->GetYaxis()->SetTitle("Selected / Anti-Selected");
 RatioTop->GetXaxis()->SetTitle();
 RatioTop->SetTitle();
      RatioTop->Divide(RatioBottom);

      c2->cd(2);
  gPad->SetGridx(); gPad->SetGridy();
   RatioTop->SetTitleSize(0.1, "XYZ");
    RatioTop->SetTitleOffset(0.55, "X");
    RatioTop->SetTitleOffset(0.3, "Y");
    RatioTop->SetLabelSize(0.06,"XY");
    RatioTop->GetYaxis()->SetRangeUser(-2.,5.0);
    RatioTop->SetLineColor(kBlack);
    RatioTop->Draw();
  TBox *unity = new TBox(RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetFirst()), 0.79,RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetLast()), 1.21);
			   unity->SetLineWidth(2);
unity->SetLineColor(2);
    unity->SetFillColor(2);
			   unity->SetFillStyle(3002);
			   unity->Draw();
  c2->Update();
  c2->SaveAs(plots+"SAS_Muon_10to25"+var+"_"+cutpoint+".png");
  // c2->Close();
}
Ejemplo n.º 11
0
TH1D* getResHist(const string& inFileName, const string& histName, 
		 double minResRatio) {

    cout<<"Creating histogram for "<<inFileName<<endl;

    // Get the hit-to-lpc residual for residuals > 30% of maximum residual
    int nR = 120;
    double rMin = 0.0;
    double rMax = 600.0;

    TH1D* theHist = new TH1D(histName.c_str(), "", nR, rMin, rMax);
    theHist->SetDirectory(0);

    theHist->SetXTitle("Hit-to-lpc residuals #delta r' larger than 30% of #delta r_{max} (mm)");

    theHist->GetYaxis()->SetTicks("+");
    theHist->GetYaxis()->SetLabelOffset(-0.03);
    theHist->SetTitleOffset(1.25, "Y");
    theHist->GetXaxis()->CenterTitle(kTRUE);
    theHist->SetTitleSize(0.045, "X");
    theHist->SetLabelSize(0.045, "X");
    theHist->SetLabelSize(0.05, "Y");

    TFile* theFile = TFile::Open(inFileName.c_str(), "read");

    TTree* lpcTree = dynamic_cast<TTree*>(theFile->Get("lpcTree"));

    vector<double>* hitResiduals = 0;
    lpcTree->SetBranchAddress("hitResiduals", &hitResiduals);

    int nEntries = lpcTree->GetEntries();

    for (int i = 0; i < nEntries; i++) {

	// Get the residual info
	lpcTree->GetEntry(i);

	// Sort the vector of hit residuals for this lpc cluster
	std::sort(hitResiduals->begin(), hitResiduals->end());

	// Get the maximum residual
	int nResiduals = hitResiduals->size();
	double maxResidual = (*hitResiduals)[nResiduals-1];

	// Only consider hit residuals that are larger than minResidual
	double minResidual = minResRatio*maxResidual;

	double nPassRes(0.0), nTotRes(0.0);
	for (int j = 0; j < nResiduals; j++) {

	    double resValue = (*hitResiduals)[j];
	    if (resValue > minResidual) {

		// We have a residual distance that is large enough
		theHist->Fill(resValue);

	    }

	} // Loop over residuals

    }

    // Normalise the histogram
    double scale(1.0);
    double integral = theHist->Integral();
    if (integral > 0.0) {scale = 1.0/integral;}
    
    theHist->Scale(scale);
    
    theFile->Close();

    return theHist;

}
Ejemplo n.º 12
0
int main(int argc, char** argv){

  TString chfile;
  TString chfileref;
  TString DirectoryLast;
  TString labelData;
  TString labelRef;


  int ntrueargs = 0;
  bool logyFlag = true;
  bool normalize = false;

  for (int i=1; i<argc; ++i) {
      if (argv[i][0] == '-') {
            if (argv[i][1]=='l') logyFlag = false;
            else if (argv[i][1]=='b') gROOT->SetBatch();
            else if (argv[i][1]=='h') return printUsage();
            else if (argv[i][1]=='n') normalize=true;
            else if (argv[i][1]=='D') labelData = argv[i+1];
            else if (argv[i][1]=='R') labelRef= argv[i+1];

      } else {
            ntrueargs += 1;
            if (ntrueargs==1) chfile = argv[i];
            else if (ntrueargs==2) chfileref = argv[i];
            else if (ntrueargs==3) DirectoryLast = argv[i];
      }
  }

  if (ntrueargs<3) return printUsage();

  TRint* app = new TRint("CMS Root Application", 0, 0);

  TString cmssw_version = gSystem->Getenv("CMSSW_VERSION");
  TString chsample = "EWKMu";
  TString chtitle = chsample + " validation for " + cmssw_version;




  //TCanvas* c1 = new TCanvas("c1",chtitle.Data());
  TCanvas* c1 = new TCanvas("c1",chtitle.Data(),0,0,1024,768);
  c1->SetFillColor(0);
  TPaveLabel* paveTitle = new TPaveLabel(0.1,0.93,0.9,0.99, chtitle.Data());
  paveTitle->Draw();
  paveTitle->SetFillColor(0);
  gStyle->SetOptLogy(logyFlag);
  gStyle->SetPadGridX(true);
  gStyle->SetPadGridY(true);
  gStyle->SetOptStat(0);
//  gStyle->SetFillColor(0);

  TPad* pad[4];
  pad[0] = new TPad("pad_tl","The top-left pad",0.01,0.48,0.49,0.92);
  pad[0]->SetFillColor(0); 
  pad[1] = new TPad("pad_tr","The top-right pad",0.51,0.48,0.99,0.92); 
  pad[1]->SetFillColor(0);
  pad[2] = new TPad("pad_bl","The bottom-left pad",0.01,0.01,0.49,0.46); 
  pad[2]->SetFillColor(0);
  pad[3] = new TPad("pad_br","The bottom-right pad",0.51,0.01,0.99,0.46); 
  pad[3]->SetFillColor(0);

  for (unsigned int i=0; i<4; ++i) pad[i]->Draw();
                                                                                
  TLegend* leg = new TLegend(0.6041667,0.7487715,0.9861111,0.9576167);
  leg->SetFillColor(0);
  TFile* input_file = new TFile(chfile.Data(),"READONLY");
  TFile* input_fileref = new TFile(chfileref.Data(),"READONLY");
  bool first_plots_done = false;

  TString directory = DirectoryLast + "/BeforeCuts";

  TDirectory* dir_before = input_file->GetDirectory(directory);
  TDirectory* dirref_before = input_fileref->GetDirectory(directory);
  TList* list_before = dir_before->GetListOfKeys();
  list_before->Print();

  unsigned int list_before_size = list_before->GetSize();
  TString auxTitle = chtitle + ": BEFORE CUTS";
  for (unsigned int i=0; i<list_before_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_before_size) continue;

            TH1D* h1 = (TH1D*)dir_before->Get(list_before->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineStyle(1);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString title=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetTitle();
            TString name=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetName(); 
            TString nameD =name+"_MC";
            h1->SetXTitle(title);
            h1->SetName(nameD);

            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_before->Get(list_before->At(i+j)->GetName()); 
            hr->SetLineColor(kPink-4);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kPink-4);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC =name+"_Data";
            h1->SetName(nameMC);

            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");



            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");
            
            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }


            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"Lp");
            leg->AddEntry(hr,labelRef.Data() ,"f");

            leg->Draw();




      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  TString directory2 = DirectoryLast + "/LastCut";

  TDirectory* dir_lastcut = input_file->GetDirectory(directory2);
  TDirectory* dirref_lastcut = input_fileref->GetDirectory(directory2);
  TList* list_lastcut = dir_lastcut->GetListOfKeys();
  list_lastcut->Print();

  unsigned int list_lastcut_size = list_lastcut->GetSize();
  auxTitle = chtitle + ": AFTER N-1 CUTS";
  for (unsigned int i=0; i<list_lastcut_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_lastcut_size) continue;

            TH1D* h1 = (TH1D*)dir_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString name=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetName();
            TString title=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetTitle();
            TString nameD=name+"_Data";
            h1->SetXTitle(title); 
            h1->SetName(nameD);
            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
            hr->SetLineColor(kAzure+5);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kAzure+5);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC=name+"_Data";
            h1->SetName(nameMC);
            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");


            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");

            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }
            

            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"lp");
            leg->AddEntry(hr,labelRef.Data(),"f");
            leg->Draw();
      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
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));




}
Ejemplo n.º 14
0
void ALICE_Comparison(){

	TFile *f = new TFile("~/Summer2016/rootfiles/FinalResult_0104/ALICE_Merged.root");


	const int NAchBins = 7;
	const double correction = 0.731;

	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;


	double x_alice[10] = {-0.09,-0.07,-0.05,-0.03,-0.01,0.01,0.03,0.05,0.07,0.09};


//	double v2_pos_alice[10] = {0.0995,0.0985+0.0005/4,0.098+0.0005/4,0.0975+0.0005*2/3,0.0975+0.0005/6,0.0975,0.097+0.0005/2,0.097+0.0005/2+0.0001};
//	double v2_neg_alice[10] = {0.097-0.0005/5,0.097+0.0005/4,0.097+0.0005/2,0.0975,0.0975+0.0005/2,0.098+0.0005/4,0.0985+0.0001,0.0985+0.0005*2/3};

	double v2_pos_alice[10] = {0.101486,0.099522,0.0986494,0.0981239,0.0978174,0.0975633,0.0974495,0.0972289,0.0972825,0.0976992};
	double v2_neg_alice[10]={0.0991805,0.0968823,0.0971381,0.0972906,0.0974951,0.0977261,0.0981123,0.0986047,0.0988509,0.10041};
	double err_pos_alice[10]={0.00199737,0.000688926,0.000277691,0.000144079,0.000101033,8.87595e-05,0.000109954,0.000176882,0.00037035,0.000996611};
	double err_neg_alice[10]={0.00196405,0.000663062,0.000268974,0.000141065,0.000100219,8.94285e-05,0.000112572,0.000183565,0.000386812,0.00106967};

	double err_diff_alice[10];
	double v2_diff_alice[10];

	for (int i = 0; i < 10; ++i)
	{
		v2_diff_alice[i] = (v2_neg_alice[i]-v2_pos_alice[i])/(v2_neg_alice[i]+v2_pos_alice[i]);

		sum = v2_pos_alice[i] + v2_neg_alice[i];
		variance_pos = err_pos_alice[i]*err_pos_alice[i];
		variance_neg = err_neg_alice[i]*err_neg_alice[i];

		variance_diff = (4*v2_neg_alice[i]*v2_neg_alice[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos_alice[i]*v2_pos_alice[i]*variance_neg)/(sum*sum*sum*sum);

		err_diff_alice[i] = sqrt(variance_diff);

	}
	

	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];
	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
		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.2,0.2);
	//pPb
	base->GetYaxis()->SetRangeUser(0.10, 0.11);
	base->GetXaxis()->SetTitle("Observed A_{ch}");
	base->GetYaxis()->SetTitle("v_{2}{SP}");
	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.05, 0.05);
	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);

	cout << v2_pos[0] << endl;


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

	
	TGraphErrors *gr_pos_alice = new TGraphErrors(10,x_alice,v2_pos_alice,NULL,err_pos_alice);
	TGraphErrors *gr_neg_alice = new TGraphErrors(10,x_alice,v2_neg_alice,NULL,err_neg_alice);
	TGraphErrors *gr_diff_alice = new TGraphErrors(10,x_alice,v2_diff_alice,NULL,err_diff_alice);

	TCanvas* c1 = new TCanvas("c1","c1");
	TCanvas* c2 = new TCanvas("c2","c2");
	gr_neg -> SetMarkerStyle(20);
	gr_neg -> SetMarkerColor(kBlue);
	gr_pos -> SetMarkerStyle(34);	
	gr_pos -> SetMarkerColor(kRed);




	c1->cd();
	base->Draw("");
	gr_pos->Draw("PSame");
	gr_neg->Draw("PSame");
	//text_a->Draw("Same");
	//text_b->Draw("Same");


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

	fit1->SetLineColor(kRed);
	fit1->SetLineStyle(2);
	fit2->SetLineColor(kBlue);
	fit2->SetLineStyle(2);
	gr_diff->Fit(fit1,"RN0");
	gr_diff_alice->Fit(fit2,"RN0");

	c2->cd();

	base2->Draw("");

	TLatex* text2 = makeLatex(Form("CMS Intercept(Red) : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.25) ;
	TLatex* text1 = makeLatex(Form("CMS slope(Red) : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ;
	TLatex* text3 = makeLatex(Form("ALICE Intercept(Blue) : %f #pm %f",fit2->GetParameter(0),fit2->GetParError(0)),0.45,0.35) ;
	TLatex* text4 = makeLatex(Form("ALICE slope(Blue) : %.4f #pm %.4f",fit2->GetParameter(1),fit2->GetParError(1)),0.45,0.30) ;
	text1->SetTextFont(42);
	text2->SetTextFont(42);
	text3->SetTextFont(42);
	text4->SetTextFont(42);
	gr_diff->Draw("PSame");

	gr_diff_alice -> SetMarkerStyle(24);

	gr_diff_alice->Draw("PSame");

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


	fit1->DrawClone("Same");
	fit2->DrawClone("Same");

	TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure_alicecomparison.root","RECREATE");
	gr_diff->Write();
	gr_diff_alice->Write();
	fit1->Write();
	fit2->Write();
	rebinned->Close();



	c2->Print("~/Summer2016/comparison_ALICE_ver2.pdf");
	c2->Print("~/Summer2016/comparison_ALICE_ver2.gif");

}
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]));




}
Ejemplo n.º 16
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"));




}
Ejemplo n.º 17
0
void Plot(TString var,TCut cut,TString bins,Double_t xmax,TString cutpoint){
  setstyle(); 
 TH1::SetDefaultSumw2(true);
TCanvas *c2 = new TCanvas("canvas"+var+cutpoint,"canname"+var+cutpoint,800,800);
  TPad *mainPad = new TPad("","",0.01,0.25,0.99,0.99);
   mainPad->SetNumber(1);
   mainPad->Draw();
    TPad *ratioPad = new TPad("","",0.01,0.01,0.99,0.25);
   ratioPad->SetNumber(2);
   ratioPad->Draw();
c2->cd(1);
//   if (cutpoint == "noHT"){ TCut cut = numpj; TCut cutData = numpjData;}
//  else if (cutpoint == "HT200"){ TCut cut = HT200; TCut cutData = HT200Data; }//
//  else if (cutpoint == "anoHT"){ TCut cut = anumpj; TCut cutData = anumpjData;}
//  else if (cutpoint == "aHT200"){ TCut cut = aHT200; TCut cutData = aHT200Data; }
// else if (cutpoint == "HT300"){ TCut cut = HT300;  TCut cutData = HT300Data;}
// else if (cutpoint == "HT350"){ TCut cut = HT350; TCut cutData = HT350Data; }
//  else if (cutpoint == "aT"){ TCut cut = aT;  TCut cutData = aTData;}
//  else if (cutpoint == "early"){TCut cut = earlyaT; TCut cutData = earlyaTData;}

//else{cout << "ERRORRRR: BRaaaaaaaaaaaaaaaaaains" << endl; }
  TCut cutData = trig && hbhe && cut;
  TH1D* lm0 = GetHist("LM0",kRed,var,cut,bins,tLM0,cutpoint);
  ///  cout << "lm0" << endl;
  TH1D* lm1 = GetHist("LM1",kRed,var,cut,bins,tLM1,cutpoint);
  //  cout << "lm1" << endl;
  TH1D* qcd = GetHist("QCD_AllPtBins_7TeV_Pythia",kOrange+4,var,cut && mu_pt_hi,bins,tQCD,cutpoint);
  // cout << "qcd" << endl;
  TH1D* data = GetHist("Data",1,var,cutData,bins,tData,cutpoint);
  // cout << "data" << endl;
  TH1D* W = GetHist("Wjets_vols",kBlue,var,cut,bins,tW,cutpoint);
  //cout << "W" << endl;
  TH1D* tt = GetHist("ttbarTauola",kGreen,var,cut,bins,tTT,cutpoint);
  // cout << "tt" << endl;
  TH1D* Z = GetHist("ZJets_madgraph",kYellow,var,cut,bins,tZ,cutpoint);
  // cout << "Z" << endl;


  //TH1D* qcd_lo = GetHist("QCD_AllPtBins_7TeV_Pythia",kOrange+4,var,cut && mu_pt_lo,bins,tQCD,cutpoint);
 

  //   qcd_lo->Scale(1.94);
  // qcd->Add(qcd_lo);
 // TH1D* SM = GetHist("SM",kGray+2,var,cut,binstLM0,cutpoint);
 lm1->SetLineStyle(2);
 W->Scale(1.29557302);
 tt->Scale(1.65789474);
 Z->Scale(3048./2400.);

 TH1::SetDefaultSumw2(true);

 TH1D *SM   = (TH1D*)qcd->Clone();
 SM->Add(Z);
 SM->Add(tt);
 SM->Add(W);
 //SM->SetLineColor(kGray+2);
 // SM->SetFillStyle(3001);
 // SM->SetFillColor(kGray+2);
 // SM->SetMarkerSize(0.);
 //for(int bnum = 1; bnum <9; bnum++){
 //  if(data->GetBinContent(bnum)>0){
 // cout << "Bin Number " << bnum << " has qcd " << qcd->GetBinContent(bnum) << " and data " << data->GetBinContent(bnum) <<  " and SM " << SM->GetBinContent(bnum) <<  " and scale factor to QCD " << data->GetBinContent(bnum)/qcd->GetBinContent(bnum) << " and scale factor to SM " << data->GetBinContent(bnum)/SM->GetBinContent(bnum) << endl; 
 // }
 //  }
 c2->cd(1)->SetLogy();
 //  data->Draw("PE0");
 SM->Draw("E");
   THStack bkg("bkg","test stacked histograms");
   bkg.Add(Z);
   bkg.Add(tt);
   bkg.Add(W);
   bkg.Add(qcd);

   bkg.Draw("HIST0SAME");
   //  data->Draw("PE0SAME");
   
   
   //qcd->Draw("HIST0same");
   /*  
      W->Draw("HIST0same");
         Z->Draw("HIST0same");
       tt->Draw("HIST0same");
   */
    lm0->Draw("HIST0same"); lm0->SetLineColor(1); lm0->SetFillColor(0);
    lm1->Draw("HIST0same"); lm1->SetLineColor(1); lm1->SetFillColor(0); lm1->SetLineStyle(2);
	//  data->Draw("EPSAME");  
  if(xmax == 1337){
      double ymax=SM->GetMaximum()*12.6;}
  else{
    double ymax=SM->GetMaximum()*10.6;}
	SM->GetYaxis()->SetRangeUser(0.05,ymax);
	if (var=="AlphaT_Lep") { data->GetXaxis()->SetRangeUser(0.,xmax);}
	SM->GetXaxis()->SetTitle(var);
	SM->SetTitle();
  TLegend *leg = new TLegend(0.73803,0.591026,0.88137,0.880819);
  // leg->SetShadowColor(0);
  //leg->SetBorderSize(0);
  //leg->SetFillStyle(4100);
  leg->SetTextSize(0.04);
  leg->SetFillColor(0);
  leg->SetLineColor(0);
  
  // leg->AddEntry(data,"DATA","PL");
   leg->AddEntry(qcd,"QCD","FL");
  leg->AddEntry(W,"W","FL");
  leg->AddEntry(Z,"Z","FL");
  leg->AddEntry(tt,"TTbar","FL");
  leg->AddEntry(lm0,"LM0","FL");
  leg->AddEntry(lm1,"LM1","FL");
  
  //leg->AddEntry(SM,"SM BKGD","FL");
  leg->Draw("same");
  
   TLatex  *prelim = new TLatex(0.1152,0.81981,"CMS preliminary 2010");



  TLatex *lumi = new TLatex(0.1015,.9403,"#scale[0.8]{#int L dt = " +luminum+ "pb^{-1}, #sqrt{s} = 7 TeV}");
    prelim->SetNDC();
    lumi->SetNDC();
    //   prelim->Draw("same");
   lumi->Draw("same");

   TH1D *RatioBottom = (TH1D*)SM->Clone("Ratiob");
   TH1D *RatioTop = (TH1D*)data->Clone("Ratiot");
   RatioTop->GetYaxis()->SetTitle("data / sim");
 RatioTop->GetXaxis()->SetTitle();
      RatioTop->Divide(RatioBottom);

      c2->cd(2);
      gPad->SetGridx(); gPad->SetGridy();
   RatioTop->SetTitleSize(0.1, "XYZ");
    RatioTop->SetTitleOffset(0.55, "X");
    RatioTop->SetTitleOffset(0.3, "Y");
    RatioTop->SetLabelSize(0.06,"XY");
    RatioTop->GetYaxis()->SetRangeUser(-2.,4.0);
    RatioTop->Draw();
    RatioTop->GetYaxis()->SetLabelSize(0.05);
    TBox *unity = new TBox(RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetFirst()), 0.89,RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetLast()), 1.11);
    unity->SetLineWidth(2);
unity->SetLineColor(2);
    unity->SetFillColor(2);
    unity->SetFillStyle(3002);
    unity->Draw();

    c2->Update();
    if(cutpoint == "early"){
      c2->SaveAs(plots+erlee+"Muon_ND"+selec+var+"_"+cutpoint+".png");
    }
    else if (xmax == 90003){
      c2->SaveAs(plots+"Muon_ND"+selec+"_zooomed_"+var+"_"+cutpoint+".png");}
    else{
      c2->SaveAs(plots+"Muon_ND"+ptsec++selec+var+"_"+cutpoint+".png");}



 
       c2->Close();
}
Ejemplo n.º 18
0
void etaPlotter(){

  double HFbins[6] = {0,10,15,20,30,70};
  double multBins[7] = {0,35,60,90,110,150,1000};
  
  TFile *f0 = new TFile("FullForest_v77_etaLT3_akPu3PF.root","OLD");
  if(!f0){ cout << "You don't have this jet collection yet!!" << endl; exit(0);}
  TTree *dijetTree = (TTree*)f0->Get("dijetTree");

  TFile *f2 = new TFile("PythiaPP_MC_akPu3PF.root","OLD");
  TTree *ppTree = (TTree*)f2->Get("dijetTree");

  TFile *f3 = new TFile("YaxianPPData_etaLT3_akPu3PF.root","OLD");
  TTree *ppDatTree = (TTree*)f3->Get("dijetTree");
  
  TFile *f4 = new TFile("PythiaMIT_out_v77_etaLT3_akPu3PF.root","OLD");
  TTree *mcTree = (TTree*)f4->Get("dijetTree");

  TFile *f5 = new TFile("PbPb_ReReco_Full_etaLT3_akPu3PF.root","OLD");
  TTree *pbpbtree = (TTree*)f5->Get("dijetTree");

  TH1D *etaDistropPb[6];
  TH1D *etaDistroppData[6];
  TH1D *etaDistroppMC[6];
  TH1D *etaDistropPbMC[6];
  TH1D *etaDistroPbPb[6];

  TH2D *avgEtapPb[3];
  TH2D *avgEtapp[3];
  TH2D *avgEtapPbMC[3];
  TH2D *avgEtappMC[3];

  char* histoname = new char[30];
  char* histotitle = new char[50];
  for(int i=0; i<6; i++){
    sprintf(histoname,"%s%d","etaDistropPb_",i+1);
    sprintf(histotitle,"%s%d","Dijet Eta distro, HF bin",i+1);
    if(i==5){ sprintf(histoname,"%s%d","etaDistropPb_",0); sprintf(histotitle,"%s%d","Dijet Eta distro, HF bin",0); }
    etaDistropPb[i] = new TH1D(histoname,histotitle,12,-3,3);
    etaDistropPb[i]->Sumw2();
    sprintf(histoname,"%s%d","etaDistroppData_",i);
    etaDistroppData[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroppData[i]->Sumw2();
    etaDistroppData[i]->SetMarkerColor(2);
    etaDistroppData[i]->SetLineColor(2);
    sprintf(histoname,"%s%d","etaDistroppMC_",i);
    etaDistroppMC[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroppMC[i]->Sumw2();
    etaDistroppMC[i]->SetMarkerColor(4);
    etaDistroppMC[i]->SetLineColor(4);
    sprintf(histoname,"%s%d","etaDistropPbMC_",i);
    etaDistropPbMC[i] = new TH1D(histoname,"",12,-3,3);
    etaDistropPbMC[i]->Sumw2();
    etaDistropPbMC[i]->SetMarkerColor(8);
    etaDistropPbMC[i]->SetLineColor(8);
    sprintf(histoname,"%s%d","etaDistroPbPb_",i);
    etaDistroPbPb[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroPbPb[i]->Sumw2();
    etaDistroPbPb[i]->SetMarkerColor(8);
    etaDistroPbPb[i]->SetLineColor(8);
  }
  for(int i=0; i<3; i++){
    sprintf(histoname,"%s%d","avgEtapPb_",i);
    avgEtapPb[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapPb[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtapp_",i);
    avgEtapp[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapp[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtapPbMC_",i);
    avgEtapPbMC[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapPbMC[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtappMC_",i);
    avgEtappMC[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtappMC[i]->Sumw2();
  }
  
  //pPb Data
  double pt1,pt2,phi1,phi2,eta1,eta2,hiHF,rawPt1,rawPt2, hiHFminus;
  bool PU;
  int tracks;
  dijetTree->SetBranchAddress("pt1",&pt1);
  dijetTree->SetBranchAddress("pt2",&pt2);
  dijetTree->SetBranchAddress("rawPt1",&rawPt1);
  dijetTree->SetBranchAddress("rawPt2",&rawPt2);
  dijetTree->SetBranchAddress("phi1",&phi1);
  dijetTree->SetBranchAddress("phi2",&phi2);
  dijetTree->SetBranchAddress("eta1",&eta1);
  dijetTree->SetBranchAddress("eta2",&eta2);
  dijetTree->SetBranchAddress("tracks",&tracks);
  dijetTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  dijetTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  dijetTree->SetBranchAddress("PUFilterGplus",&PU);
  for(int i=0; i<dijetTree->GetEntries(); i++){
    dijetTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && hiHF<70){
      avgEtapPb[0]->Fill(eta1,acos(cos(phi1-phi2)));
      avgEtapPb[1]->Fill(eta2,acos(cos(phi1-phi2)));
      avgEtapPb[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[0] && tracks<multBins[1] && */hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[2] && tracks<multBins[3] && */hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[3] && tracks<multBins[4] && */hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[4] && tracks<multBins[5] && */hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[5] && tracks<multBins[6] && */hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[4]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && acos(cos(phi1-phi2))>2.0944){
      etaDistropPb[5]->Fill((eta1+eta2)/2);
    }
  }

  //pPb MC
  double weight, MCentries, pthat;
  mcTree->SetBranchAddress("pt1",&pt1);
  mcTree->SetBranchAddress("pt2",&pt2);
  mcTree->SetBranchAddress("rawPt1",&rawPt1);
  mcTree->SetBranchAddress("rawPt2",&rawPt2);
  mcTree->SetBranchAddress("tracks",&tracks);
  mcTree->SetBranchAddress("pthat",&pthat);
  mcTree->SetBranchAddress("phi1",&phi1);
  mcTree->SetBranchAddress("phi2",&phi2);
  mcTree->SetBranchAddress("eta1",&eta1);
  mcTree->SetBranchAddress("eta2",&eta2);
  mcTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  mcTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  mcTree->SetBranchAddress("weight",&weight);
  mcTree->SetBranchAddress("MCpthatEntries",&MCentries);
  for(int i=0; i<mcTree->GetEntries(); i++){
    mcTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>50 && hiHF<70){
      avgEtapPbMC[0]->Fill(eta1,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtapPbMC[1]->Fill(eta2,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtapPbMC[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)),(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[0] && tracks<multBins[1] &&*/ hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[0]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[2] && tracks<multBins[3] && */hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[1]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[3] && tracks<multBins[4] && */hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[2]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[4] && tracks<multBins[5] && */hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[3]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[5] && tracks<multBins[6] && */hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[4]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
  }

  //pp MC
  ppTree->SetBranchAddress("pt1",&pt1);
  ppTree->SetBranchAddress("pt2",&pt2);
  ppTree->SetBranchAddress("rawPt1",&rawPt1);
  ppTree->SetBranchAddress("rawPt2",&rawPt2);
  ppTree->SetBranchAddress("weight",&weight);
  ppTree->SetBranchAddress("MCpthatEntries",&MCentries);
  ppTree->SetBranchAddress("phi1",&phi1);
  ppTree->SetBranchAddress("phi2",&phi2);
  ppTree->SetBranchAddress("eta1",&eta1);
  ppTree->SetBranchAddress("eta2",&eta2);
  ppTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  ppTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<ppTree->GetEntries(); i++){
    ppTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>50 && hiHF<70 && acos(cos(phi1-phi2)>2.0944)){
      avgEtappMC[0]->Fill(eta1,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtappMC[1]->Fill(eta2,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtappMC[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)),(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[0]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[1]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[2]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[3]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[4]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
  }

  //pp data
  ppDatTree->SetBranchAddress("pt1",&pt1);
  ppDatTree->SetBranchAddress("pt2",&pt2);
  ppDatTree->SetBranchAddress("rawPt1",&rawPt1);
  ppDatTree->SetBranchAddress("rawPt2",&rawPt2);
  ppDatTree->SetBranchAddress("phi1",&phi1);
  ppDatTree->SetBranchAddress("phi2",&phi2);
  ppDatTree->SetBranchAddress("eta1",&eta1);
  ppDatTree->SetBranchAddress("eta2",&eta2);
  ppDatTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  ppDatTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<ppDatTree->GetEntries(); i++){
    ppDatTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF<70){
      avgEtapp[0]->Fill(eta1,acos(cos(phi1-phi2)));
      avgEtapp[1]->Fill(eta2,acos(cos(phi1-phi2)));
      avgEtapp[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[4]->Fill((eta1+eta2)/2);
    }
  }

  pbpbtree->SetBranchAddress("pt1",&pt1);
  pbpbtree->SetBranchAddress("pt2",&pt2);
  pbpbtree->SetBranchAddress("rawPt1",&rawPt1);
  pbpbtree->SetBranchAddress("rawPt2",&rawPt2);
  pbpbtree->SetBranchAddress("phi1",&phi1);
  pbpbtree->SetBranchAddress("phi2",&phi2);
  pbpbtree->SetBranchAddress("eta1",&eta1);
  pbpbtree->SetBranchAddress("eta2",&eta2);
  pbpbtree->SetBranchAddress("hiHFplusEta4",&hiHF);
  pbpbtree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<pbpbtree->GetEntries(); i++){
    pbpbtree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<50 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=50 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[4]->Fill((eta1+eta2)/2);
    }
  }

  TCanvas *c2 = new TCanvas("c2","",1400,800);
  c2->cd();
  makeMultiPanelCanvas(c2,3,2,0.,0.,0.2,0.2,0.05);
  for(int i=0; i<5; i++){
    c2->cd(i+1);
    cout << "pPb:  " << etaDistropPb[i]->Integral() << endl;
    etaDistropPb[i]->Scale(1./etaDistropPb[i]->Integral());
    etaDistropPb[i]->SetMaximum(0.2);
    etaDistropPb[i]->SetYTitle("Event Fraction");
    etaDistropPb[i]->SetXTitle("(#eta_{1}+#eta_{2})/2");
    //etaDistropPb[i]->SetXTitle("#eta_{leading}");
    etaDistropPb[i]->Draw();
    cout << "ppMC:  " << etaDistroppMC[i]->Integral() << endl;
    etaDistroppMC[i]->Scale(1./etaDistroppMC[i]->Integral());
    etaDistroppMC[i]->Draw("same");
    etaDistropPbMC[i]->Scale(1./etaDistropPbMC[i]->Integral());
    etaDistropPbMC[i]->Draw("same");
    //if(etaDistroppData[i]->Integral() != 0){
    cout << "pp:  " << etaDistroppData[i]->Integral() << endl;
    etaDistroppData[i]->Scale(1./etaDistroppData[i]->Integral());
    etaDistroppData[i]->Draw("same");
    //}
    if(i==0){
      TLatex *l1 = new TLatex(0.5, 0.15,"E_{T}^{|#eta|<4}<20");
      l1->Draw();
    }
    if(i==1){
      TLatex *l2 = new TLatex(0.5, 0.15, "20#leqE_{T}^{|#eta|<4}<25");
      l2->Draw();
    }
    if(i==2){
      TLatex *l3 = new TLatex(0.5, 0.15, "25#leqE_{T}^{|#eta|<4}<30");
      l3->Draw();
    }
    if(i==3){
      TLatex *l4 = new TLatex(0.5, 0.15, "30#leqE_{T}^{|#eta|<4}<40");
      l4->Draw();
    }
    if(i==4){
      TLatex *l5 = new TLatex(0.5, 0.15, "40#leqE_{T}^{|#eta|<4}");
      l5->Draw();
    }
    if(i==0){
      TLegend *leg = new TLegend(0.2,0.77,0.80,0.91);
      leg->AddEntry(etaDistropPb[i],"pPb Data, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistroppMC[i], "pp PYTHIA MC, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistropPbMC[i], "pPb HIJING+PYTHIA MC, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistroppData[i], "pp Data, #sqrt{s}=2.76 TeV");
      leg->SetFillColor(0);
      leg->SetBorderSize(0);
      leg->Draw();
    }
  }
  
  TCanvas *c3 = new TCanvas("c3","",1400,600);
  c3->Divide(3,1);
  TH1D *profpPb[3];
  TH1D *profpp[3];
  TH1D *profpPbMC[3];
  TH1D *profppMC[3];
  for(int i=0; i<3; i++){
    c3->cd(i+1);
    profpPb[i] = avgEtapPb[i]->ProfileX();
    profpPb[i]->SetMaximum(3.0);
    profpPb[i]->SetMinimum(2.81);
    if(i==0) profpPb[i]->SetXTitle("#eta_{leading}");
    if(i==1) profpPb[i]->SetXTitle("#eta_{subleading}");
    if(i==2) profpPb[i]->SetXTitle("(#eta_{1}+#eta_{2})/2");
    profpPb[i]->SetYTitle("<#Delta#phi>");
    //profpPb[i]->Scale(1./profpPb[i]->Integral());
    profpPb[i]->Draw();
    profpp[i] = avgEtapp[i]->ProfileX();
    //profpp[i]->Scale(1./profpp[i]->Integral());
    profpp[i]->SetMarkerColor(4);
    profpp[i]->SetLineColor(4);
    profpp[i]->Draw("same");
    profpPbMC[i] = avgEtapPbMC[i]->ProfileX();
    //profpPbMC[i]->Scale(1./profpPbMC[i]->Integral());
    profpPbMC[i]->SetMarkerColor(2);
    profpPbMC[i]->SetLineColor(2);
    profpPbMC[i]->Draw("same");
    profppMC[i] = avgEtappMC[i]->ProfileX();
    // profppMC[i]->Scale(1./profppMC[i]->Integral());
    profppMC[i]->SetMarkerColor(8);
    profppMC[i]->SetLineColor(8);
    profppMC[i]->Draw("same");
  }

  //Plot mean
  /*Double_t pPb_nmult[5] = {5.658, 12.3924,17.3349,24.0448,36.3906};
  Double_t pPb_avgPt[5] = {etaDistropPb[0]->GetMean(), etaDistropPb[1]->GetMean(), etaDistropPb[2]->GetMean(), etaDistropPb[3]->GetMean(), etaDistropPb[4]->GetMean()};
  Double_t pPb_nmultErr[5] = {0.0097,0.01997,0.028038,0.0343,0.07198};
  Double_t pPb_avgPtErr[5] = {etaDistropPb[0]->GetMeanError(), etaDistropPb[1]->GetMeanError(), etaDistropPb[2]->GetMeanError(), etaDistropPb[3]->GetMeanError(), etaDistropPb[4]->GetMeanError()};

  Double_t MC_nmult[5] = {5.20261,12.3461,17.3005,23.8401,34.7769};
  Double_t MC_avgPt[5] = {etaDistropPbMC[0]->GetMean(), etaDistropPbMC[1]->GetMean(), etaDistropPbMC[2]->GetMean(), etaDistropPbMC[3]->GetMean(), etaDistropPbMC[4]->GetMean()};
  Double_t MC_nmultErr[5] = {0.0043,0.01139,0.01656.0.0211,0.0549};
  Double_t MC_avgPtErr[5] = {etaDistropPbMC[0]->GetMeanError(), etaDistropPbMC[1]->GetMeanError(), etaDistropPbMC[2]->GetMeanError(), etaDistropPbMC[3]->GetMeanError(), etaDistropPbMC[4]->GetMeanError()};

  Double_t PbPb_nmult[4] = {11.6405,30.6015,49.7908,64.897};
  Double_t PbPb_avgPt[4] = {etaDistroPbPb[0]->GetMean(), etaDistroPbPb[1]->GetMean(), etaDistroPbPb[2]->GetMean(), etaDistroPbPb[3]->GetMean()};
  Double_t PbPb_nmultErr[4] = {0.2618,0.2188,0.1961,0.1493};
  Double_t PbPb_avgPtErr[4] = {etaDistroPbPb[0]->GetMeanError(), etaDistroPbPb[1]->GetMeanError(), etaDistroPbPb[2]->GetMeanError(), etaDistroPbPb[3]->GetMeanError()};*/

 
  //Double_t pPb_nmult[5] = {5.658, 12.3924,17.3349,24.0448,36.3906}; //for hiHFplusEta4
  Double_t pPb_nmult[5] = {12.699,22.424,27.356,34.192,47.624}; //for HFplusEta4 + HFminusEta4
  Double_t pPb_avgPt[5] = {findDelPhiAngle(etaDistropPb[0],1), findDelPhiAngle(etaDistropPb[1],1), findDelPhiAngle(etaDistropPb[2],1), findDelPhiAngle(etaDistropPb[3],1), findDelPhiAngle(etaDistropPb[4],1)};
  Double_t pPb_nmultErr[5] = {0.012, 0.0296, 0.0375, 0.0406, 0.0715};
  Double_t pPb_avgPtErr[5] = {findDelPhiAngle(etaDistropPb[0],2), findDelPhiAngle(etaDistropPb[1],2), findDelPhiAngle(etaDistropPb[2],2), findDelPhiAngle(etaDistropPb[3],2), findDelPhiAngle(etaDistropPb[4],2)};

  //Double_t MC_nmult[5] = {5.20261,12.3461,17.3005,23.8401,34.7769}; //for hiHFplusEta4
  Double_t MC_nmult[5] = {11.9707, 22.4454, 27.4279, 34.4833, 47.2613}; //for hiHFplusEta4 + hiHFminusEta4
  //Double_t MC_nmult[5] = {1,3,5,8,12}; //for signal only sample
  Double_t MC_avgPt[5] = {findDelPhiAngle(etaDistropPbMC[0],1), findDelPhiAngle(etaDistropPbMC[1],1), findDelPhiAngle(etaDistropPbMC[2],1), findDelPhiAngle(etaDistropPbMC[3],1), findDelPhiAngle(etaDistropPbMC[4],1)};
  Double_t MC_nmultErr[5] = {0.004,0.013,0.015,0.015,0.022};
  Double_t MC_avgPtErr[5] = {findDelPhiAngle(etaDistropPbMC[0],2), findDelPhiAngle(etaDistropPbMC[1],2), findDelPhiAngle(etaDistropPbMC[2],2), findDelPhiAngle(etaDistropPbMC[3],2), findDelPhiAngle(etaDistropPbMC[4],2)};

  Double_t PbPb_nmult[3] = {15.1924, 37.45, 71.267};
  Double_t PbPb_avgPt[3] = {findDelPhiAngle(etaDistroPbPb[0],1), findDelPhiAngle(etaDistroPbPb[1],1), findDelPhiAngle(etaDistroPbPb[2],1)};
  Double_t PbPb_nmultErr[3] = {0.274, 0.296, 0.262};
  Double_t PbPb_avgPtErr[3] = {findDelPhiAngle(etaDistroPbPb[0],2), findDelPhiAngle(etaDistroPbPb[1],2), findDelPhiAngle(etaDistroPbPb[2],2)};

  Double_t pp_nmult[4] = {6.504, 21.78, 26.17, 31.65};
  Double_t pp_avgPt[4] = {findDelPhiAngle(etaDistroppData[0],1), findDelPhiAngle(etaDistroppData[1],1), findDelPhiAngle(etaDistroppData[2],1), findDelPhiAngle(etaDistroppData[3],1)};
  Double_t pp_nmultErr[4] = {0.04, 1.29, 3.62, 5.63};
  Double_t pp_avgPtErr[4] = {findDelPhiAngle(etaDistroppData[0],2), findDelPhiAngle(etaDistroppData[1],2), findDelPhiAngle(etaDistroppData[2],2), findDelPhiAngle(etaDistroppData[3],2)};

  /* TH1D *ppSum = etaDistroppData[0]->Clone("ppSum");
  for(int i=1; i<5; i++){
    ppSum->Add(etaDistroppData[i]);
  }
  Double_t pp_nmult[1] = {3.5};
  Double_t pp_nmultErr[1] = {0.1};
  Double_t pp_avgPt[1] = {findDelPhiAngle(ppSum,1)};
  Double_t pp_avgPtErr[1] = {findDelPhiAngle(ppSum,2)};*/

  TGraphErrors *centr2[3];
  centr2[0] = new TGraphErrors(5,pPb_nmult, pPb_avgPt, pPb_nmultErr, pPb_avgPtErr);
  centr2[1] = new TGraphErrors(3,PbPb_nmult, PbPb_avgPt, PbPb_nmultErr, PbPb_avgPtErr);
  centr2[2] = new TGraphErrors(5,MC_nmult, MC_avgPt, MC_nmultErr, MC_avgPtErr);
  centr2[3] = new TGraphErrors(1,pp_nmult, pp_avgPt, pp_nmultErr, pp_avgPtErr);
  TLatex *label1 = new TLatex(40,0.1,"|#eta|< 3");
  TH1D *temp = new TH1D("temp","",1,0,60);
  temp->SetMaximum(-0.1);
  temp->SetMinimum(-0.7);
  temp->SetXTitle("E_{T}^{HF[|#eta|>4]}");
  temp->SetYTitle("((#eta_{1}+#eta_{2})/2)_{#mu}");
  temp->GetXaxis()->CenterTitle();
  temp->GetYaxis()->CenterTitle();
  temp->GetYaxis()->SetLabelSize(0.08);
  temp->GetYaxis()->SetTitleOffset(0.5);
  temp->SetTitleSize(0.1, "y");
  temp->GetXaxis()->SetLabelSize(0.08);
  //temp->GetXaxis()->SetTitleOffset(0.5);
  temp->SetTitleSize(0.1, "x");
  TCanvas *c4 = new TCanvas("c4","",600,600);
  c4->cd();
  temp->Draw();
  centr2[0]->Draw("P,same");
  centr2[1]->SetLineColor(8);
  centr2[1]->SetMarkerColor(8);
  centr2[1]->SetMarkerStyle(25);
  //centr2[1]->Draw("P,same");
  centr2[2]->SetLineColor(2);
  centr2[2]->SetMarkerColor(2);
  centr2[2]->Draw("P,same");
  centr2[3]->SetMarkerColor(4);
  centr2[3]->SetLineColor(4);
  centr2[3]->SetMarkerStyle(24);
  //centr2[3]->Draw("P,same");
  //label1->Draw();

  etaDistropPb[0]->Scale(1./etaDistropPb[0]->Integral());
  TFile *fout = new TFile("hist_output_etaLT3_akPu3PF_ForPawan.root","UPDATE");
  fout->cd();
  for(int i=0; i<6; i++){
    etaDistropPb[i]->Write();
  }
  centr2[0]->SetNameTitle("dijEta","Dijet Eta vs Hf");
  centr2[0]->Write();
  fout->Close();
}
Ejemplo n.º 19
0
  // DATA vs MC comparison
void createDataVsMCcompRatio(double intLumi,TFile *fQCD,TFile *fZ,TFile *fW,TFile *fTT,TFile *flm1,TFile *fDATA,TCanvas *cCanvas,int cPad,int maxPads,
			     TString folderName,TString histoName,int rebin,float xMin,float xMax,TString xName, TString yName,bool useLog) {
  

  ostringstream tmpLumi;
  tmpLumi << intLumi;
  TString lumi = tmpLumi.str();
  


  cCanvas->cd(cPad);
  
  if (useLog) { gPad->SetLogy(); }
  
  
  // SM backgrounds
  TH1D *hQCD = plot1Dhisto(intLumi,fQCD,folderName,histoName,kYellow+3,rebin,xMin,xMax,xName,yName,"QCD",true); // hQCD->SetName("hQCD");
  TH1D *hZ   = plot1Dhisto(intLumi,fZ,folderName,histoName,kMagenta,rebin,xMin,xMax,xName,yName,"Z",true); // hQCD->SetName("hQCD");
  TH1D *hW   = plot1Dhisto(intLumi,fW,folderName,histoName,4,rebin,xMin,xMax,xName,yName,"W",true); // hQCD->SetName("hQCD");
  TH1D *hTT  = plot1Dhisto(intLumi,fTT,folderName,histoName,kGreen+2,rebin,xMin,xMax,xName,yName,"TT",true); // hQCD->SetName("hQCD");
  TH1D *hSM  = (TH1D*)hTT->Clone("hSM"); hSM->SetName("hSM");  hSM->Add(hW); hSM->Add(hQCD); hSM->Add(hZ);
  hSM->SetLineWidth(4); hSM->SetLineColor(kGray+3); hSM->SetMarkerSize(0.);
  
  // Data
  TH1D *hData = plot1Dhisto(intLumi,fDATA,folderName,histoName,1,rebin,xMin,xMax,xName,yName,"Data",false); // hQCD->SetName("hQCD");
  hData->SetMarkerSize(1); hData->SetMarkerColor(1); hData->SetMarkerStyle(21);
  
  // Signal
  TH1D *hLM1 = plot1Dhisto(intLumi,flm1,folderName,histoName,2,rebin,xMin,xMax,xName,yName,"LM1",true); // hQCD->SetName("hQCD");


  
  // y-axis range
  if (useLog) { hData->GetYaxis()->SetRangeUser(0.1,30.*(hData->GetBinContent(hData->GetMaximumBin()))); }
  else { hData->GetYaxis()->SetRangeUser(0.1,1.4*(hData->GetBinContent(hData->GetMaximumBin()))); }


  
  // Draw the histograms
  hData->Draw("P E0");
  hSM->Draw("HIST E0 sames");
  hQCD->Draw("HIST E0 sames");
  hZ->Draw("HIST E0 sames");
  hW->Draw("HIST E0 sames");                                                                                                                                                                               
  hTT->Draw("HIST E0 sames");
  hLM1->Draw("HIST E0 sames");                                                                                                                                                                             
  hData->Draw("P E0 sames"); // re-draw to be on top
  
  
  
  // Draw Legend
  TLegend *lSamples = legendRAW();
  lSamples->AddEntry(hData,"DATA","PL");
  lSamples->AddEntry(hQCD,"QCD","FL");
  lSamples->AddEntry(hZ,"Z","FL");
  lSamples->AddEntry(hW,"W","FL");
  lSamples->AddEntry(hTT,"TTbar","FL");
  lSamples->AddEntry(hLM1,"LM1","FL");
  lSamples->AddEntry(hSM,"SM","FL");
  lSamples->Draw("same");
  
  
  
  TLatex *lPreliminary = new TLatex(0.2,0.82,"Preliminary 2011");
  //    TLatex *lIntLumi = new TLatex(0.2,0.89,"#scale[0.8]{#int L dt = " +intLumi+"pb^{-1}, #sqrt{s} = 7 TeV}");
  TLatex *lIntLumi = new TLatex(0.2,0.89,"#scale[0.8]{#int L dt = "+lumi+" pb^{-1}, #sqrt{s} = 7 TeV}");
  lPreliminary->SetNDC();
  lIntLumi->SetNDC();
  lPreliminary->Draw("same");
  lIntLumi->Draw("same");
  
  cCanvas->cd(cPad+maxPads);
  //  cCanvas->cd(cPad+1);
  
  gPad->SetGridx(); gPad->SetGridy();
  TH1D *hRatio = (TH1D*)hData->Clone("hRatio");
  //  hRatio->Sumw2();
  hRatio->Divide(hData,hSM);
  hRatio->GetYaxis()->SetTitle("DATA / MC [SM]");
  hRatio->GetXaxis()->SetTitle("");
  hRatio->GetYaxis()->SetRangeUser(0.,2.);
  hRatio->SetTitleSize(0.1, "XYZ");
  hRatio->SetTitleOffset(0.65, "X");
  hRatio->SetTitleOffset(0.6, "Y");
  hRatio->SetLabelSize(0.08,"XY");
  
  
  
  //Draw a line though the perfectly matching point
  TBox *unity = new TBox(hRatio->GetXaxis()->GetBinLowEdge(hRatio->GetXaxis()->GetFirst()),
			 0.89,hRatio->GetXaxis()->GetXmax(), 1.11);
  unity->SetLineWidth(2);
  //unity.SetLineStyle(Root.kDashed);
  unity->SetLineColor(2);
  unity->SetFillColor(2);
  unity->SetFillStyle(3002);
  unity->Draw();
  
  hRatio->Draw("P E0");
  unity->Draw();
  
  cCanvas->Update();
  
  
} // ~ end of createDataVsMCcompRatio function