Beispiel #1
0
/*
void formatCanvas(TCanvas *c){
  c->Divide(1,2,0.01,0.01);
  c->cd(1);
  c->GetPad(1)->SetLogy();
  c->GetPad(1)->SetPad(0.,0.425,1.,1.);
  c->GetPad(2)->SetPad(0.,0.0,1.,0.425);
  c->GetPad(2)->SetBottomMargin(0.3);
  c->GetPad(2)->SetGridy(1);
}

// divide by bin width
void divideBinWidth(TH1 *h)
{
	h->Sumw2();
	for (int i=0;i<=h->GetNbinsX();i++)
	{
		Float_t val = h->GetBinContent(i);
		Float_t valErr = h->GetBinError(i);
		val/=h->GetBinWidth(i);
		valErr/=h->GetBinWidth(i);
		h->SetBinContent(i,val);
		h->SetBinError(i,valErr);
	}
	h->GetXaxis()->CenterTitle();
	h->GetYaxis()->CenterTitle();
}

void cleanup(TH1F *h)
{
	for (int i=1;i<=h->GetNbinsX();i++)
	{
		double val1 = h->GetBinContent(i);
		double valErr1 = h->GetBinError(i);
		if (valErr1>=val1) {
			h->SetBinContent(i,0);
			h->SetBinError(i,0);
		}
	}   
	
}


// rebin the spectra
TH1F *rebin(TH1F *h, char *histName)
{
	TH1F *hRebin = new TH1F(Form("%s_rebin",h->GetName()),Form("rebin %s",h->GetTitle()),nbins_recrebin,boundaries_recrebin);
	for (int i=1;i<=h->GetNbinsX();i++)
	{
		double val=h->GetBinContent(i);
		double valErr=h->GetBinError(i);
		int binNum = hRebin->FindBin(h->GetBinCenter(i));
		double val1 = hRebin->GetBinContent(binNum);
		double valErr1 = hRebin->GetBinError(binNum);
		hRebin->SetBinContent(binNum,val+val1);
		hRebin->SetBinError(binNum,sqrt(valErr1*valErr1+valErr*valErr));
	}
	cleanup(hRebin);
	hRebin->SetName(histName);
	return hRebin;
}

TH1F *rebin2(TH1F *h, char *histName)
{
	TH1F *hRebin = new TH1F(Form("%s_rebin",h->GetName()),Form("rebin %s",h->GetTitle()),nbins_recrebin_2,boundaries_recrebin_2);
	for (int i=1;i<=h->GetNbinsX();i++)
	{
		double val=h->GetBinContent(i);
		double valErr=h->GetBinError(i);
		int binNum = hRebin->FindBin(h->GetBinCenter(i));
		double val1 = hRebin->GetBinContent(binNum);
		double valErr1 = hRebin->GetBinError(binNum);
		hRebin->SetBinContent(binNum,val+val1);
		hRebin->SetBinError(binNum,sqrt(valErr1*valErr1+valErr*valErr));
	}
	cleanup(hRebin);
	hRebin->SetName(histName);
	return hRebin;
}

void drawText(const char *text, float xp, float yp, int size){
	TLatex *tex = new TLatex(xp,yp,text);
	tex->SetTextFont(63);
	tex->SetTextSize(size);
	tex->SetTextColor(kBlack);
	tex->SetLineWidth(1);
	//tex->SetTextFont(42);
	tex->SetNDC();
	tex->Draw();
}


void putCMSPrel(double x, double y, double size){
	TLatex *tex=0;
	tex = new TLatex(x,y,"CMS Preliminary");
	tex->SetTextSize(size);
	tex->SetLineWidth(2);
	tex->SetNDC();
	tex->Draw();
}

void putCMSSim(double x, double y, double size){
	TLatex *tex=0;
	tex = new TLatex(x,y,"CMS Simulation");
	tex->SetTextSize(size);
	tex->SetLineWidth(2);
	tex->SetNDC();
	tex->Draw();
}


TLegend *myLegend(double x1,double y1,double x2, double y2)
{
	TLegend *leg = new TLegend(x1,y1,x2,y2);
	leg->SetBorderSize(0);
	leg->SetFillStyle(0);
	return leg; 
	
}

*/
void nlo_comp_macro(int radius = 3){

  TH1::SetDefaultSumw2();
  gStyle->SetOptStat(0);
  
  TFile *fPP = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/result-2013-akVs3PF-cent-1-isFineBin-0/pbpb_pp_merged_chmx_pt_isMC_0_Unfo_2013_akVs3PF_cent_1_isFineBin_0.root");
  //TFile *fNLO_err = TFile::Open("fnl4350a_cteq");
  TFile *fNLO_nnpdf = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_nnpdf21-nlo_aspdf_new.root");
  TFile *fNLO_cteq = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_cteq66-nlo_aspdf_all_new.root");
  TFile *fNLO_ct10n = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_ct10n-nlo_aspdf_new.root");
  TFile *fNLO_hera = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_hera15all-nlo_aspdf_new.root");

  //alright lets get the unfolded data here: remember we need it for eta range -2 to +2 
  //TFile* fPP_unfo_R3 = TFile::Open("pp_2013_2760_abs_eta_2_mc_ak3PF.root");
  TFile* fPP_unfo_R4 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/pp_2013_2760_abs_eta_2_mc_ak4PF.root");
  TFile* fPP_unfo_R5 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/pp_2013_2760_abs_eta_2_mc_ak5PF.root");
  //TFile *f_unfold_R2 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_pp_unfold_marguerite_jet80_chMaxjtpt_norawptcut_test_65GeVCut_akPu2PF_20150205_test.root");
  TFile *f_unfold_R3 = TFile::Open(Form("Pawan_ntuple_PbPb_pp_calopfpt_ppNoJetidcut_nlobins_R0p%d_without80FakeRemoval_unfold_mcclosure_oppside_trgMC_noSmear_20_eta_20_%dGeVCut_akPF_20150522.root",3,40));
  //TFile *f_unfold_R4 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_pp_unfold_marguerite_jet80_chMaxjtpt_norawptcut_test_65GeVCut_akPu4PF_20150205_test.root");

  TH1F* hPP_data_R_3 = (TH1F*)f_unfold_R3->Get("PP_bayesian_unfolded_spectra");
  hPP_data_R_3->Print("base");
  
  hPP_data_R_3 = (TH1F*)hPP_data_R_3->Rebin(nbins_yaxian, "PP_bayesian_unfolded_spectra", boundaries_yaxian);
  divideBinWidth(hPP_data_R_3);
  hPP_data_R_3->Print("base");

  //PP_measured[0] = (TH1F*)f_unfold_R2->Get("PP_measured_unfolded_spectra");
  //PP_binbybin[0] = (TH1F*)f_unfold_R2->Get("PP_binbybin_unfolded_spectra");

  //TH1F* PP_bayesian[1] = (TH1F*)f_unfold_R4->Get("PP_bayesian_unfolded_spectra");
  //PP_measured[1] = (TH1F*)f_unfold_R3->Get("PP_measured_unfolded_spectra");
  //PP_binbybin[1] = (TH1F*)f_unfold_R3->Get("PP_binbybin_unfolded_spectra");

  TFile fout("pp_2760GeV_nlo_histos.root","RECREATE");
  fout.cd();

  TH1F* hPP_nnpdf_NLO = (TH1F*)fNLO_nnpdf->Get(Form("h100%d00",radius-1));
  TH1F* hPP_cteq_NLO = (TH1F*)fNLO_cteq->Get(Form("h100%d00",radius-1));
  TH1F* hPP_ct10n_NLO = (TH1F*)fNLO_ct10n->Get(Form("h100%d00",radius-1));
  TH1F* hPP_hera_NLO = (TH1F*)fNLO_hera->Get(Form("h100%d00",radius-1));

  //TH1F* hPP_data_R_3 = (TH1F*)fPP_unfo_R3->Get("Unfolded_cent1");
  TH1F* hPP_data_R_4 = (TH1F*)fPP_unfo_R4->Get("Unfolded_cent1");
  TH1F* hPP_data_R_5 = (TH1F*)fPP_unfo_R5->Get("Unfolded_cent1");

  hPP_data_R_3->Scale(5.3*1e3);
  hPP_data_R_3->Scale(1./5300e6);
  //hPP_data_R_3->Scale(1./4);
  //divideBinWidth(hPP_data_R_3);

  hPP_data_R_4->Scale(1./5300e6);
  hPP_data_R_4->Scale(1./4);
  divideBinWidth(hPP_data_R_4);

  hPP_data_R_5->Scale(1./5300e6);
  hPP_data_R_5->Scale(1./4);
  divideBinWidth(hPP_data_R_5);

  // NLO histograms without any R# at the end correspond to R=0.3 the standard. others are named accordingly

  TH1F* hPP_nnpdf_NLO_R4 = (TH1F*)fNLO_nnpdf->Get("h100300");
  TH1F* hPP_nnpdf_NLO_R2 = (TH1F*)fNLO_nnpdf->Get("h100100");

  TH1F* hPP_cteq_NLO_R4 = (TH1F*)fNLO_cteq->Get("h100300");
  TH1F* hPP_ct10n_NLO_R4 = (TH1F*)fNLO_ct10n->Get("h100300");
  TH1F* hPP_hera_NLO_R4 = (TH1F*)fNLO_hera->Get("h100300");

  TH1F* hPP_cteq_NLO_R2 = (TH1F*)fNLO_cteq->Get("h100100");
  TH1F* hPP_ct10n_NLO_R2 = (TH1F*)fNLO_ct10n->Get("h100100");
  TH1F* hPP_hera_NLO_R2 = (TH1F*)fNLO_hera->Get("h100100");

  TH1F* hPP_err = (TH1F*)fNLO_cteq->Get("h100203");
  TH1F* hPP_err_R4 = (TH1F*)fNLO_cteq->Get("h100303");
  TH1F* hPP_err_R2 = (TH1F*)fNLO_cteq->Get("h100103");
  
  for(int i = 0;i<hPP_nnpdf_NLO->GetNbinsX();i++){
    
    Float_t valErr = hPP_err->GetBinError(i);
    hPP_nnpdf_NLO->SetBinError(i,valErr);
    hPP_cteq_NLO->SetBinError(i,valErr);
    hPP_hera_NLO->SetBinError(i,valErr);
    hPP_ct10n_NLO->SetBinError(i,valErr);

    Float_t valErr_R4 = hPP_err_R4->GetBinError(i);
    hPP_nnpdf_NLO_R4->SetBinError(i,valErr_R4);
    hPP_cteq_NLO_R4->SetBinError(i,valErr_R4);
    hPP_ct10n_NLO_R4->SetBinError(i,valErr_R4);
    hPP_hera_NLO_R4->SetBinError(i,valErr_R4);

    Float_t valErr_R2 = hPP_err_R2->GetBinError(i);
    hPP_nnpdf_NLO_R2->SetBinError(i,valErr_R2);
    hPP_cteq_NLO_R2->SetBinError(i,valErr_R2);
    hPP_ct10n_NLO_R2->SetBinError(i,valErr_R2);
    hPP_hera_NLO_R2->SetBinError(i,valErr_R2);

  }

  //add the NPC factors 
  char etaWidth[dir][256] = {
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20"
  };
  
  char radius_lable[dir][256] = {
    "R2","R2","R2","R2","R2","R2","R2","R2","R2","R2",
    "R3","R3","R3","R3","R3","R3","R3","R3","R3","R3",
    "R4","R4","R4","R4","R4","R4","R4","R4","R4","R4",
    "R5","R5","R5","R5","R5","R5","R5","R5","R5","R5",
    "R7","R7","R7","R7","R7","R7","R7","R7","R7","R7"
  };
  
  ifstream fin_txt[dir];

  int energy = 2760;
  
  for(int i = 0;i<dir;i++){
    
    //ostringstream filename;
    //filename<<"/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_8_HI_patch2/src/Macros/RAA/nlo_files/input_np_txtfiles/NPC_ak_"<<radius_lable[i]<<etaWidth[i]<<"_energy"<<energy<<".txt";
    fin_txt[i].open(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_8_HI_patch2_old/src/Macros/RAA/nlo_files/input_np_txtfiles/NPC_ak_%s_%s_energy%d.txt",radius_lable[i],etaWidth[i],energy));
  }

  //apply the correction factors to the NLO histograms 

  Float_t npc = 0;
  Float_t bin = 0;

  //before applying the corrections, lets get a clone of the uncorrected histogram. 
  TH1F* hPP_nnpdf_NLO_noNPC = (TH1F*)hPP_nnpdf_NLO->Clone("hPP_nnpdf_NLO_noNPC");
  int counter = 0;
  while(1){

    fin_txt[11]>>bin>>npc;
    cout<<bin<<" "<<npc<<endl;
    if(!fin_txt[11].good())break;
    int bin_no = hPP_nnpdf_NLO->FindBin(bin);
    //cout<<"bin no = "<<bin_no<<endl;
    //cout<<"boundaries_pt of bin no"<<boundaries_yaxian_large[bin_no]<<endl;
    cout<<"value before applying = "<<hPP_nnpdf_NLO->GetBinContent(bin_no)<<endl;
    hPP_nnpdf_NLO->SetBinContent(bin_no,npc*hPP_nnpdf_NLO->GetBinContent(bin_no));
    cout<<"value after applying = "<<hPP_nnpdf_NLO->GetBinContent(bin_no)<<endl;
    hPP_cteq_NLO->SetBinContent(bin_no,npc*hPP_cteq_NLO->GetBinContent(bin_no));
    hPP_ct10n_NLO->SetBinContent(bin_no,npc*hPP_ct10n_NLO->GetBinContent(bin_no));
    hPP_hera_NLO->SetBinContent(bin_no,npc*hPP_hera_NLO->GetBinContent(bin_no));

    fin_txt[1]>>bin>>npc;
    if(!fin_txt[1].good())break;
    bin_no = hPP_nnpdf_NLO_R2->FindBin(bin);
    hPP_nnpdf_NLO_R2->SetBinContent(bin_no,npc*hPP_nnpdf_NLO_R2->GetBinContent(bin_no));
    hPP_cteq_NLO_R2->SetBinContent(bin_no,npc*hPP_cteq_NLO_R2->GetBinContent(bin_no));
    hPP_ct10n_NLO_R2->SetBinContent(bin_no,npc*hPP_ct10n_NLO_R2->GetBinContent(bin_no));
    hPP_hera_NLO_R2->SetBinContent(bin_no,npc*hPP_hera_NLO_R2->GetBinContent(bin_no));

    fin_txt[21]>>bin>>npc;
    if(!fin_txt[21].good())break;
    bin_no = hPP_nnpdf_NLO_R4->FindBin(bin);
    hPP_nnpdf_NLO_R4->SetBinContent(bin_no,npc*hPP_nnpdf_NLO_R4->GetBinContent(bin_no));
    hPP_cteq_NLO_R4->SetBinContent(bin_no,npc*hPP_cteq_NLO_R4->GetBinContent(bin_no));
    hPP_ct10n_NLO_R4->SetBinContent(bin_no,npc*hPP_ct10n_NLO_R4->GetBinContent(bin_no));
    hPP_hera_NLO_R4->SetBinContent(bin_no,npc*hPP_hera_NLO_R4->GetBinContent(bin_no));

    counter++;

  }

  cout<<"counter = "<<counter<<endl;

  //get a clone after applying the corrections, 
  TH1F* hPP_nnpdf_NLO_NPC = (TH1F*)hPP_nnpdf_NLO->Clone("hPP_nnpdf_NLO_NPC");

  TH1F* hPP_NPC_ratio = (TH1F*)hPP_nnpdf_NLO_NPC->Clone("hPP_NPC_ratio");
  hPP_NPC_ratio->Divide(hPP_nnpdf_NLO_noNPC);
  /*
  TCanvas *cnpc = new TCanvas("cnpc","",800,600);
  //cnpc->SetLogy();
  hPP_NPC_ratio->SetTitle("NPC 2.76 TeV R=0.3");
  hPP_NPC_ratio->SetXTitle("Jet p_{T} (GeV/c)");
  hPP_NPC_ratio->SetYTitle("NP factors");
  hPP_NPC_ratio->SetAxisRange(0.7,1.3,"Y");
  hPP_NPC_ratio->Draw();
  cnpc->SaveAs("pp_2760_npc_R3.pdf","RECREATE");
  */


  hPP_nnpdf_NLO->SetName("hPP_nnpdf_NLO");
  hPP_cteq_NLO->SetName("hPP_cteq_NLO");
  hPP_ct10n_NLO->SetName("hPP_ct10n_NLO");
  hPP_hera_NLO->SetName("hPP_hera_NLO");

  hPP_nnpdf_NLO_R2->SetName("hPP_nnpdf_NLO_R2");
  hPP_nnpdf_NLO_R2->Print("base");
  hPP_cteq_NLO_R2->SetName("hPP_cteq_NLO_R2");
  hPP_cteq_NLO_R2->Print("base");
  hPP_ct10n_NLO_R2->SetName("hPP_ct10n_NLO_R2");
  hPP_ct10n_NLO_R2->Print("base");
  hPP_hera_NLO_R2->SetName("hPP_hera_NLO_R2");

  hPP_nnpdf_NLO_R4->SetName("hPP_nnpdf_NLO_R4");
  hPP_cteq_NLO_R4->SetName("hPP_cteq_NLO_R4");
  hPP_ct10n_NLO_R4->SetName("hPP_ct10n_NLO_R4");
  hPP_hera_NLO_R4->SetName("hPP_hera_NLO_R4");

  hPP_nnpdf_NLO->Write();
  hPP_cteq_NLO->Write();
  hPP_ct10n_NLO->Write();
  hPP_hera_NLO->Write();
  hPP_nnpdf_NLO_R2->Write();
  hPP_cteq_NLO_R2->Write();
  hPP_ct10n_NLO_R2->Write();
  hPP_hera_NLO_R2->Write();
  hPP_nnpdf_NLO_R4->Write();
  hPP_cteq_NLO_R4->Write();
  hPP_ct10n_NLO_R4->Write();
  hPP_hera_NLO_R4->Write();

  TH1F* hPPrebin = (TH1F*)hPP_data_R_3->Clone("hPPrebin");
  //TH1F* hPPrebin_test = (TH1F*)faditya->Get("Corrected Jet Spectrum Aditya");
  //TH1F* hPPrebin = (TH1F*)hPPrebin_test->Rebin(nbins_yaxian_large,"hPPrebin",boundaries_yaxian_large);
  //TH1F* hPPunfo = (TH1F*)fPP->Get("Unfolded_cent6");
  TH1F* hPPgen = (TH1F*)fPP->Get("hGen_cent1");
  //hPPrebin->Scale(64);//remove the sigma scaling from the previous macros
  //dont need this now since we are taking it from a dedicated macro which gives us diff cross section 
  hPP_data_R_3->Scale(1e9);
  hPP_data_R_4->Scale(1e9);
  hPP_data_R_5->Scale(1e9);

  //hPP_nnpdf_NLO->Scale(1./4);
  //hPP_cteq_NLO->Scale(1./4);
  //hPP_hera_NLO->Scale(1./4);

  hPPrebin->Scale(1e9);
  //hPPrebin->Scale(1./5300e6);
  //hPPrebin->Scale(1./4);
  //divideBinWidth(hPPrebin);
 
  hPPgen->Scale(1./4);
  hPPgen->Scale(1e9);

  fout.Write();

  hPP_nnpdf_NLO = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"nnpdf_pp", boundaries_yaxian);
  hPP_nnpdf_NLO->Print("base");
  hPP_cteq_NLO = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"cteq_pp", boundaries_yaxian);
  hPP_cteq_NLO->Print("base");
  hPP_hera_NLO = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hera_pp", boundaries_yaxian);
  hPP_hera_NLO->Print("base");
  hPP_ct10n_NLO = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"ct10n_pp", boundaries_yaxian);
  hPP_ct10n_NLO->Print("base");


  TH1F* hRatio_nnpdf_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_nnpdf_mc",boundaries_yaxian);
  hRatio_nnpdf_mc->Divide(hPP_nnpdf_NLO);
  
  TH1F* hRatio_cteq_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_cteq_mc",boundaries_yaxian);
  hRatio_cteq_mc->Divide(hPP_cteq_NLO);

  TH1F* hRatio_hera_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_hera_mc",boundaries_yaxian);
  hRatio_hera_mc->Divide(hPP_hera_NLO);

  TH1F* hRatio_ct10n_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_ct10n_mc",boundaries_yaxian);
  hRatio_ct10n_mc->Divide(hPP_ct10n_NLO);

  TH1F* hRatio_nnpdf = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_nnpdf",boundaries_yaxian);
  hRatio_nnpdf->Divide(hPPrebin);

  TH1F* hRatio_cteq = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"hRatio_cteq",boundaries_yaxian);
  hRatio_cteq->Divide(hPPrebin);

  TH1F* hRatio_ct10n = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"hRatio_ct10n",boundaries_yaxian);
  hRatio_ct10n->Divide(hPPrebin);

  TH1F* hRatio_hera = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hRatio_hera",boundaries_yaxian);
  hRatio_hera->Divide(hPPrebin);

  TH1F* hRatio_ppgen = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_ppgen",boundaries_yaxian);
  hRatio_ppgen->Divide(hPPrebin);

  TH1F* hRatio_nnpdf_R_2_4 = (TH1F*)hPP_nnpdf_NLO_R2->Rebin(nbins_yaxian,"hRatio_nnpdf_R_2_4",boundaries_yaxian);
  hRatio_nnpdf_R_2_4->Divide(hPP_nnpdf_NLO_R4);

  TH1F* hRatio_nnpdf_R_3_4 = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_nnpdf_R_3_4",boundaries_yaxian);
  hRatio_nnpdf_R_3_4->Divide(hPP_nnpdf_NLO_R4);

  TH1F* hRatio_cteq_R_2_4 = (TH1F*)hPP_cteq_NLO_R2->Rebin(nbins_yaxian,"hRatio_cteq_R_2_4",boundaries_yaxian);
  hRatio_cteq_R_2_4->Divide(hPP_cteq_NLO_R4);

  TH1F* hRatio_cteq_R_3_4 = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"hRatio_cteq_R_3_4",boundaries_yaxian);
  hRatio_cteq_R_3_4->Divide(hPP_cteq_NLO_R4);

  TH1F* hRatio_ct10n_R_2_4 = (TH1F*)hPP_ct10n_NLO_R2->Rebin(nbins_yaxian,"hRatio_ct10n_R_2_4",boundaries_yaxian);
  hRatio_ct10n_R_2_4->Divide(hPP_ct10n_NLO_R4);

  TH1F* hRatio_ct10n_R_3_4 = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"hRatio_ct10n_R_3_4",boundaries_yaxian);
  hRatio_ct10n_R_3_4->Divide(hPP_ct10n_NLO_R4);

  TH1F* hRatio_hera_R_2_4 = (TH1F*)hPP_hera_NLO_R2->Rebin(nbins_yaxian,"hRatio_hera_R_2_4",boundaries_yaxian);
  hRatio_hera_R_2_4->Divide(hPP_hera_NLO_R4);

  TH1F* hRatio_hera_R_3_4 = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hRatio_hera_R_3_4",boundaries_yaxian);
  hRatio_hera_R_3_4->Divide(hPP_hera_NLO_R4);

  TH1F* hRatio_data_nnpdf_R_3 = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_data_nnpdf_R_3",boundaries_yaxian);
  hRatio_data_nnpdf_R_3->Divide(hPP_data_R_3);
  
  TH1F* hRatio_data_nnpdf_R_4 = (TH1F*)hPP_nnpdf_NLO_R4->Rebin(nbins_yaxian,"hRatio_data_nnpdf_R_4",boundaries_yaxian);
  hRatio_data_nnpdf_R_4->Divide(hPP_data_R_4);

  TH1F* hRatio_data_R_3_4 = (TH1F*)hPP_data_R_3->Clone("hRatio_data_R_3_4");
  hRatio_data_R_3_4->Divide(hPP_data_R_4);

  TH1F* hRatio_data_R_3_5 = (TH1F*)hPP_data_R_3->Clone("hRatio_data_R_3_5");
  hRatio_data_R_3_5->Divide(hPP_data_R_5);

  TH1F* hRatio_data_R_4_5 = (TH1F*)hPP_data_R_4->Clone("hRatio_data_R_4_5");
  hRatio_data_R_4_5->Divide(hPP_data_R_5);

  /*
  TCanvas *cnlo_mc = new TCanvas("cnlo_mc","",800,600);
  hRatio_nnpdf_mc->SetMarkerColor(kRed);
  hRatio_nnpdf_mc->SetMarkerStyle(20);
  hRatio_nnpdf_mc->SetXTitle("Jet p_{T} (GeV/c)");
  hRatio_nnpdf_mc->SetYTitle("MC/NLO");
  hRatio_nnpdf_mc->SetTitle(" ");
  hRatio_nnpdf_mc->SetAxisRange(0,1.5,"Y");
  hRatio_nnpdf_mc->Draw();

  hRatio_cteq_mc->SetMarkerColor(kBlue);
  hRatio_cteq_mc->SetMarkerStyle(20);
  hRatio_cteq_mc->Draw("same");

  hRatio_ct10n_mc->SetMarkerColor(9);
  hRatio_ct10n_mc->SetMarkerStyle(20);
  hRatio_ct10n_mc->Draw("same");

  hRatio_hera_mc->SetMarkerColor(kGreen);
  hRatio_hera_mc->SetMarkerStyle(20);
  hRatio_hera_mc->Draw("same");

  TLegend *titlenlomc = myLegend(0.10,0.10,0.30,0.30);
  titlenlomc->AddEntry(hRatio_nnpdf_mc,"nnpdf","pl");
  titlenlomc->AddEntry(hRatio_cteq_mc,"cteq","pl");
  titlenlomc->AddEntry(hRatio_ct10n_mc,"ct10n","pl");
  titlenlomc->AddEntry(hRatio_hera_mc,"hera","pl");
  titlenlomc->SetTextSize(0.04);
  titlenlomc->Draw();

  putCMSSim(0.1,0.92,0.06);
  drawText("pp #sqrt{s}=2.76(TeV)",0.65,0.92,16);
  drawText(Form("anti k_{T} R = 0.%d, NP corrections added to NLO",radius),0.15,0.83,16);

  cnlo_mc->SaveAs(Form("Ratio_mc_with_nlo_with_np_R%d.pdf",radius),"RECREATE");
  */

  TCanvas *c1 = new TCanvas("c1","",800,600);
  formatCanvas(c1);
  c1->cd(1);
  c1->cd(1)->SetLogy();
  hPP_nnpdf_NLO->SetMarkerColor(kRed);
  hPP_nnpdf_NLO->SetMarkerStyle(33);
  hPP_cteq_NLO->SetMarkerColor(kBlue);
  hPP_cteq_NLO->SetMarkerStyle(33);
  hPP_ct10n_NLO->SetMarkerColor(9);//purple
  hPP_ct10n_NLO->SetMarkerStyle(33);
  hPP_hera_NLO->SetMarkerColor(kGreen);
  hPP_hera_NLO->SetMarkerStyle(33);
  hPPrebin->SetMarkerColor(kBlack);
  hPPrebin->SetMarkerStyle(8);
  hPPgen->SetMarkerColor(kOrange);
  hPPgen->SetMarkerStyle(8);
  //hPPgen->SetMarkerColor(kRed);
  //hPPgen->SetMarkerStyle(8);
  
  makeHistTitle(hPP_nnpdf_NLO,"","p_{T} (GeV/c)","#frac{d^{2} #sigma}{d p_{T} d #eta} (pb#frac{GeV}{c})");
  //hPP_nnpdf_NLO->SetYTitle("#frac{d^{2} #sigma}{d p_{T} d #eta} (pb#frac{GeV}{c})");
  //hPP_nnpdf_NLO->SetXTitle("p_{T} (GeV/c)");
  hPP_nnpdf_NLO->SetAxisRange(22,500,"X");
  hPP_nnpdf_NLO->SetTitle(" ");
  hPP_nnpdf_NLO->Draw("p");
  hPP_cteq_NLO->Draw("same p");
  hPP_ct10n_NLO->Draw("same p");
  hPP_hera_NLO->Draw("same p");
  hPPrebin->Draw("same p");
  //hPPgen->Draw("same p");

  TLegend * title = myLegend(0.47, 0.50,0.67, 0.8);
  title->AddEntry(hPP_nnpdf_NLO,"NLO nnpdf","pl");
  title->AddEntry(hPP_cteq_NLO,"NLO cteq","pl");
  title->AddEntry(hPP_ct10n_NLO,"NLO ct10n","pl");
  title->AddEntry(hPP_hera_NLO,"NLO hera","pl");
  //title->AddEntry(hPPgen,"pp MC spectra","pl");
  title->AddEntry(hPPrebin,"pp unfolded 2013 data","pl");
  title->SetTextSize(0.04);
  title->Draw();

  putCMSPrel(0.1,0.92,0.06);
  drawText("pp 2013, #sqrt{s}=2.76(TeV), #int L dt = 5.3 (pb)^{-1}",0.35,0.92,16);
  drawText(Form("anti k_{T} R = 0.3, NP corrections added to NLO",radius),0.35,0.83,16);

  c1->cd(2);
  makeHistTitle(hRatio_nnpdf,"","p_{T} (GeV/c)","NLO / pp data");
  //hRatio_nnpdf->SetYTitle(" X / pp data");
  //hRatio_nnpdf->SetXTitle("p_{T} (GeV/c)");
  hRatio_nnpdf->SetTitle(" ");
  hRatio_nnpdf->SetAxisRange(0.8,2,"Y");
  hRatio_nnpdf->SetMarkerColor(kRed);
  hRatio_nnpdf->SetMarkerStyle(33);
  hRatio_hera->SetMarkerColor(kGreen);
  hRatio_hera->SetMarkerStyle(33);
  hRatio_cteq->SetMarkerColor(kBlue);
  hRatio_cteq->SetMarkerStyle(33);
  hRatio_ct10n->SetMarkerColor(9);
  hRatio_ct10n->SetMarkerStyle(33);
  hRatio_ppgen->SetMarkerColor(kOrange);
  hRatio_ppgen->SetMarkerStyle(33);
  hRatio_nnpdf->Draw("p");
  hRatio_nnpdf->SetAxisRange(22,500,"X");
  hRatio_hera->Draw("same p");
  hRatio_cteq->Draw("same p");
  hRatio_ct10n->Draw("same p");
  //hRatio_ppgen->Draw("same p");

  c1->SaveAs(Form("May22/pp_2760GeV_NLO_NPadded_ak%dPF_spectra.pdf",radius),"RECREATE");

  /*
  //get the information from the ratio per bins - to use to scale down the NLO in 5.02 TeV. 
  ofstream R_nnpdf,R_hera,R_cteq;
  R_nnpdf.open(Form("ratio_nnpdf_vs_pp_data_2760_ak%d.txt",radius));
  R_hera.open(Form("ratio_hera_vs_pp_data_2760_ak%d.txt",radius));
  R_cteq.open(Form("ratio_cteq_vs_pp_data_2760_ak%d.txt",radius)); 
  for(int i = 0;i<hRatio_nnpdf->GetNbinsX();i++){
    R_nnpdf<<i<<"\t"<<hRatio_nnpdf->GetBinContent(i)<<endl;
    R_hera<<i<<"\t"<<hRatio_hera->GetBinContent(i)<<endl;
    R_cteq<<i<<"\t"<<hRatio_cteq->GetBinContent(i)<<endl;
  }
  
  R_nnpdf.close();
  R_hera.close();
  R_cteq.close();

  
  //draw the results for NLO comparison within different radius at the same energy 
  TCanvas *c2 = new TCanvas("c2","",800,600);
  formatCanvas(c2);
  
  c2->cd(1);
  hPP_nnpdf_NLO->SetMarkerStyle(22);
  hPP_nnpdf_NLO->SetMarkerColor(3);
  hPP_nnpdf_NLO->Draw("p");
  hPP_nnpdf_NLO_R2->SetMarkerStyle(22);
  hPP_nnpdf_NLO_R2->SetMarkerColor(2);
  hPP_nnpdf_NLO_R2->Draw("same p");
  hPP_nnpdf_NLO_R4->SetMarkerStyle(22);
  hPP_nnpdf_NLO_R4->SetMarkerColor(4);
  hPP_nnpdf_NLO_R4->Draw("same p");
  hPP_data_R_4->SetMarkerStyle(23);
  hPP_data_R_4->SetMarkerColor(4);
  hPP_data_R_4->Draw("same p");
  hPP_data_R_3->SetMarkerStyle(23);
  hPP_data_R_3->SetMarkerColor(3);
  hPP_data_R_3->Draw("same p");
  hPP_data_R_5->SetMarkerStyle(23);
  hPP_data_R_5->SetMarkerColor(9);
  hPP_data_R_5->Draw("same p");

  TLegend * title2 = myLegend(0.47, 0.50,0.67, 0.8);
  title2->AddEntry(hPP_nnpdf_NLO_R2,"NNPDF21 R=0.2","pl");
  title2->AddEntry(hPP_nnpdf_NLO,"NNPDF21 R=0.3","pl");
  title2->AddEntry(hPP_nnpdf_NLO_R4,"NNPDF21 R=0.4","pl");
  title2->AddEntry(hPP_data_R_3,"Data R=0.3","pl");
  title2->AddEntry(hPP_data_R_4,"Data R=0.4","pl");
  title2->AddEntry(hPP_data_R_5,"Data R=0.5","pl");
  title2->SetTextSize(0.04);
  title2->Draw();

  putCMSPrel(0.1,0.92,0.06);
  drawText("pp 2013, #sqrt{s}=2.76(TeV), #int L dt = 5.3 (pb)^{-1}",0.35,0.92,16);
  drawText(Form("anti k_{T}, Data vs Theory",radius),0.47,0.83,16);

  c2->cd(2);
  hRatio_nnpdf_R_2_4->SetMarkerStyle(29);
  hRatio_nnpdf_R_2_4->SetMarkerColor(2);
  hRatio_nnpdf_R_2_4->SetAxisRange(0.6,1.6,"Y");
  hRatio_nnpdf_R_2_4->SetAxisRange(22,500,"X");
  hRatio_nnpdf_R_2_4->SetTitle(" ");
  hRatio_nnpdf_R_2_4->SetYTitle("Ratios");
  hRatio_nnpdf_R_2_4->SetXTitle("p_{T}(GeV/c)");
  hRatio_nnpdf_R_2_4->Draw("p");
  hRatio_nnpdf_R_3_4->SetMarkerStyle(29);
  hRatio_nnpdf_R_3_4->SetMarkerColor(3);
  hRatio_nnpdf_R_3_4->Draw("same p");
  hRatio_data_nnpdf_R_3->SetMarkerStyle(33);
  hRatio_data_nnpdf_R_3->SetMarkerColor(4);
  hRatio_data_nnpdf_R_3->Draw("same p");
  hRatio_data_nnpdf_R_4->SetMarkerStyle(33);
  hRatio_data_nnpdf_R_4->SetMarkerColor(7);
  hRatio_data_nnpdf_R_4->Draw("same p");
  hRatio_data_R_3_4->SetMarkerStyle(34);
  hRatio_data_R_3_4->SetMarkerColor(6);
  hRatio_data_R_3_4->Draw("same p");
  hRatio_data_R_3_5->SetMarkerStyle(34);
  hRatio_data_R_3_5->SetMarkerColor(7);
  hRatio_data_R_3_5->Draw("same p");
  hRatio_data_R_4_5->SetMarkerStyle(34);
  hRatio_data_R_4_5->SetMarkerColor(8);
  hRatio_data_R_4_5->Draw("same p");

  c2->cd(1);
  TLegend * title3 = myLegend(0.67, 0.40,0.77, 0.8);
  title3->AddEntry(hRatio_nnpdf_R_2_4,"NLO R=0.2/R=0.4","pl");
  title3->AddEntry(hRatio_nnpdf_R_3_4,"NLO R=0.3/R=0.4","pl");
  title3->AddEntry(hRatio_data_nnpdf_R_3,"R=0.3 NNPDF21/Data","pl");
  title3->AddEntry(hRatio_data_nnpdf_R_4,"R=0.4 NNPDF21/Data","pl");
  title3->AddEntry(hRatio_data_R_3_4,"Data R=0.3/R=0.4","pl");
  title3->AddEntry(hRatio_data_R_3_5,"Data R=0.3/R=0.5","pl");
  title3->AddEntry(hRatio_data_R_4_5,"Data R=0.4/R=0.5","pl");
  title3->SetTextSize(0.04);
  title3->Draw();
  
  c2->SaveAs("pp_2760GeV_data_NLO_NPCadded_radius_comparison.pdf","RECREATE");

  fout.Write();
  fout.Close();
  */
  
  /*
  TCanvas *c2 = new TCanvas("c2","",1000,800);
  c2->Divide(2,1);
  c2->cd(1);
  c2->cd(1)->SetLogy();
  hPPunfo->SetTitle("PP 2013 2.76 TeV Merged, Unfolded p_{T} Spectra");
  hPPunfo->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}");
  hPPunfo->GetYaxis()->SetTitleOffset(1.4);
  hPPunfo->SetXTitle("Jet p_{T} GeV/c");
  hPPunfo->GetXaxis()->SetRangeUser(50,500);
  hPPunfo->Draw();
  hPPmeas->GetXaxis()->SetRangeUser(50,500);
  hPPmeas->SetMarkerStyle(22);
  hPPmeas->SetMarkerColor(kBlack);
  hPPmeas->Draw("same");
  TLegend *titl = myLegend(0.54,0.65,0.85,0.9);
  titl->AddEntry(hPPmeas,"PP2013 Meas ak3PF","pl");
  titl->AddEntry(hPPunfo,"PP2013 Unfo Bayesian","pl");
  titl->SetTextSize(0.03);
  titl->Draw();
  drawText("Anti-k_{T}PF R = 0.3",0.43,0.6,22);
  drawText("|#eta|<2, |vz|<15",0.47,0.5,22);
  
  c2->cd(2);
  TH1F* hPPRatio = (TH1F*)hPPmeas->Clone("hPPRatio");
  hPPRatio->Divide(hPPunfo);
  hPPRatio->SetXTitle("Jet p_{T} GeV/c");
  hPPRatio->SetYTitle("Ratio Measured/Unfolded");
  hPPRatio->SetTitle("PP2013 ak3PF merged");
  hPPRatio->GetYaxis()->SetRangeUser(0,2);
  hPPRatio->Draw();
  c2->SaveAs("pp_2013_ak3_merged_unfolded_pt.pdf","RECREATE");
  
  */
  
  /*
  TH1F *hNLO_err = (TH1F*)fNLO->Get("h100203");
  for(int i = 0;i<hNLO_err->GetNbinsX();i++){
    Float_T valErr = hNLO_Err->GetBinError(i);
    hNLO->SetBinError(i,valErr);
  }
  */
  /*
  //h100300 - ak4PF, h100200 - ak3PF
  TH1F* hNLO_2 = (TH1F*)hNLO->Clone("hNLO_2");
  hNLO->Print("base");

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

  cComp->cd(1)->SetLogy();
  hPPrebin->SetMarkerStyle(22);
  hPPrebin->SetMarkerColor(kRed);

  hNLO->SetMarkerStyle(20);
  hNLO->SetMarkerColor(kBlack);
  hNLO->SetTitle("PP 2.76 TeV");
  hNLO->SetYTitle("#sigma pb");
  hNLO->SetXTitle("Jet p_{T} GeV/c");
  hNLO->Draw("pl");

  hPPMCrebin->SetMarkerStyle(21);
  hPPMCrebin->SetMarkerColor(kBlue);

  hPPMCrebin->Draw("same");

  hPPrebin->Draw("same");

  TLegend *title = myLegend(0.34,0.65,0.54,0.75);
  title->AddEntry(hNLO,"NLO nnpdf21","pl");
  title->AddEntry(hPPrebin,"PP ak3PF unfo","pl");
  title->AddEntry(hPPMCrebin,"PP ak3PF MC Gen","pl");
  title->SetTextSize(0.06);
  title->Draw();
  

  cComp->cd(2);
  TH1F *hPP = (TH1F*)hPPrebin->Clone("hPP");
  TH1F* hPPMC_v2 = (TH1F*)hPPMCrebin->Clone("hPPMC_v2");

  hPP->Print("base");
  hPPMC_v2->Print("base");
  
  hPP->Divide(hNLO);
  hPPMC_v2->Divide(hNLO);
  hPP->SetTitle("Ratio of PP ak3PF unfolded and MC Gen to NLO");
  //hPP->SetTitle("Ratio of PP ak4PF measured to NLO");
  hPP->SetYTitle("#frac{#sigma_{PP}}{#sigma_{NLO}}");
  hPP->SetXTitle("Jet p_{T} GeV/c");
  hPP->Draw();
  hPPMC_v2->Draw("same");

  cComp->SaveAs("fastNLO_comparison/ratio_pp_ak3_merged_NLO_nnpdf21nlo.pdf","RECREATE");

  TCanvas c1;
  c1.SetLogy();
  hPPrebin->SetAxisRange(50,500,"X");
  hPPrebin->SetYTitle("#sigma (pb)");
  hPPrebin->SetXTitle("Jet p_{T} GeV/c");
  hPPrebin->SetTitle("PP ak3PF unfolded");
  hPPrebin->Draw();
  c1.SaveAs("fastNLO_comparison/PP_2013_ak3_merged_Unfolded_crosssection.pdf","RECREATE");
  c1.SaveAs("fastNLO_comparison/PP_2013_ak3_merged_Unfolded_crosssection.C","RECREATE");
  
  TCanvas *c3 = new TCanvas("c3","",800,600);
  c3->SetGrid();
  c3->SetLogy();
  //TGraphErrors graph_Expected("./fastNLO_comparison/files/s2760_R0.3fine.tex","%lg %lg");
  //graph_Expected.SetTitle("Non Perturbative corrections (extrapolation from Atlas) s2760;p_{T} GeV/c;#sigma nb");
  //graph_Expected.DrawClone("E3AL");
  

  TFile *fNPC = TFile::Open("fastNLO_comparison/files/npc_extrapolation_ivan.root");
  TH1F* hNPC = (TH1F*)fNPC->Get("hNPC");
  hNPC->Scale(1000);// 1000 for the pb from nb 
  //hNPC->Print("base");
  //TH1F* hNPC_rebin1 = rebin2(hNPC,"hNPC_rebin1");
  //divideBinWidth(hNPC_rebin1);
  hNPC->SetTitle("Non Perturbative corrections (extrapolation from Atlas) s2760");
  hNPC->SetXTitle("p_{T} GeV/c");
  hNPC->SetYTitle("#sigma (pb)");
  hNPC->Draw();
  hPPrebin->Draw("same");

  c3->SaveAs("fastNLO_comparison/NPC_atlas_ak3.pdf","RECREATE");


  TCanvas *c4 = new TCanvas("c4","",800,600);
  c4->SetLogy();
  //TH1F* hNPC_rebin = (TH1F*)hNPC->Clone("hNPC_rebin");
  TH1F* hNPC_rebin = rebin2(hNPC,"hNPC_rebin");
  divideBinWidth(hNPC_rebin);
  hPPrebin_2->SetTitle("PP Cross sections Data and Theory comparisons");
  hPPrebin_2->SetYTitle("#sigma (pb)");
  hPPrebin_2->SetXTitle("p_{T} GeV/c");
  //hNPC_rebin->SetAxisRange(1e4,1e-2,"Y");  
  hPPrebin_2->SetMarkerStyle(23);
  hPPrebin_2->SetMarkerColor(kBlack);
  hPPrebin_2->SetAxisRange(50,450,"X");
  hPPrebin_2->Draw("E");
  //hPPrebin_2->SetAxisRange(50,450,"X");
  hNPC_rebin->SetMarkerStyle(21);
  hNPC_rebin->SetMarkerColor(kRed);
  hNPC_rebin->Draw("same");
  hNLO_2->SetMarkerStyle(25);
  hNLO_2->SetMarkerColor(kBlue);
  hNLO_2->Draw("same");

  TLegend *title2 = myLegend(0.54,0.65,0.85,0.9);
  title2->AddEntry(hNPC_rebin,"Ivan NPC - Atlas R=0.3","pl");
  title2->AddEntry(hPPrebin_2,"PP2013 ak3PF unfolded","pl");
  title2->AddEntry(hNLO_2,"CMS NLO nnpdf21 R=0.3","l");

  title2->SetTextSize(0.04);
  title2->Draw();
  gStyle->SetOptStat(0);
 
  c4->SaveAs("fastNLO_comparison/pp_ak3_nlo_overlay_hist.pdf","RECREATE");

  TCanvas *c6 = new TCanvas("c6","",800,600);
  TH1F* hPPratio = (TH1F*)hPPrebin_2->Clone("hPPratio");

  //add the error bars directly before dividing them and then set that as the error. 
  //FLoat_t delta_PP = 0;
  //Float_t delta_NPC = 0;
  //Float_t delta
  
  hPPratio->Divide(hNPC_rebin);
  hPPratio->SetTitle("Ratio of PP 2013 ak3 unfolded w/ Ivan's NPC Atlas");
  hPPratio->SetYTitle(" ");
  hPPratio->SetXTitle("p_{T} GeV/c");
  hPPratio->Draw();
  c6->SaveAs("pp_ak3_npc_ratio.pdf","RECREATE");

  TCanvas *c5 = new TCanvas("c5","",800,600);
  hNPC->Draw();
  hNPC_rebin->Draw("same");
  c5->SetLogy();
  c5->SaveAs("Ivan_plot_rebin_ak3.pdf","RECREATE");
 
  */


}
void MCefficiencyCent(int isPbPb=0,TString inputmc="/data/wangj/MC2015/Dntuple/pp/revised/ntD_pp_Dzero_kpi_prompt/ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))",TString selmcgenacceptance="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))&&abs(Gtk1eta)<2.0&&abs(Gtk2eta)<2.0&&Gtk1pt>2.0&&Gtk2pt>2.0", TString cut_recoonly="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11", TString cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)",TString label="PP",TString outputfile="test", int useweight=1,Float_t centmin=0., Float_t centmax=100.)
{ 
 
  hiBinMin = centmin*2;
  hiBinMax = centmax*2;
  centMin = centmin;
  centMax = centmax;
  
  if(isPbPb==1)
    {
      selmcgen = selmcgen+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
      selmcgenacceptance=selmcgenacceptance+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
      cut_recoonly=cut_recoonly+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
      cut=cut+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
    }

     std::cout<<"selmcgen="<<selmcgen<<std::endl;
     std::cout<<"selmcgenacceptance="<<selmcgenacceptance<<std::endl;
     std::cout<<"cut_recoonly"<<cut_recoonly<<std::endl;
     std::cout<<"cut="<<cut<<std::endl;

   std::cout<<"option="<<useweight<<std::endl;
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetEndErrorSize(0);
  gStyle->SetMarkerStyle(20);
 
  TFile* infMC = new TFile(inputmc.Data());
  TTree* ntMC = (TTree*)infMC->Get("ntKp");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree* ntSkim = (TTree*)infMC->Get("ntSkim");
  TTree* ntmvaTree = (TTree*)infMC->Get("mvaTree");
  TTree* ntHlt = (TTree*)infMC->Get("ntHlt");

  ntMC->AddFriend(ntmvaTree);
  ntMC->AddFriend(ntGen);
  ntMC->AddFriend(ntSkim);
  ntMC->AddFriend(ntHlt);

  TTree* nthi = (TTree*)infMC->Get("ntHi");
  ntGen->AddFriend(nthi);
  ntGen->AddFriend(ntSkim);
  ntGen->AddFriend(ntHlt);
  nthi->AddFriend(ntMC);
  ntMC->AddFriend(nthi);

  // optimal weigths
  TCut weighpthat = "1";
  TCut weightGpt = "1";
  TCut weightBgenpt = "1";
  TCut weightHiBin = "1";
  if(useweight==0) {
    weightfunctiongen="1";
    weightfunctionreco="1";
    weighpthat = "pthatweight";
    weightGpt = "(pow(10,-0.094152+0.008102*Gpt+Gpt*Gpt*0.000171+Gpt*Gpt*Gpt*-0.000005+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))";
    weightBgenpt = "(pow(10,-0.094152+0.008102*Bgenpt+Bgenpt*Bgenpt*0.000171+Bgenpt*Bgenpt*Bgenpt*-0.000005+Bgenpt*Bgenpt*Bgenpt*Bgenpt*-0.000000+Bgenpt*Bgenpt*Bgenpt*Bgenpt*Bgenpt*0.000000))";
    }
  
  if(useweight==1) {
    weightfunctiongen="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)";
    weightfunctionreco="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)";
    weighpthat = "pthatweight";
    weightGpt = "(pow(10,-0.107832+0.010248*Gpt+Gpt*Gpt*0.000079+Gpt*Gpt*Gpt*-0.000003+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))";
    weightBgenpt = "(pow(10,-0.107832+0.010248*Bgenpt+Bgenpt*Bgenpt*0.000079+Bgenpt*Bgenpt*Bgenpt*-0.000003+Bgenpt*Bgenpt*Bgenpt*Bgenpt*-0.000000+Bgenpt*Bgenpt*Bgenpt*Bgenpt*Bgenpt*0.000000))";
    weightHiBin = "(6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08))";
    }

  std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl;

  TH1D* hPtMC = new TH1D("hPtMC","",_nBins,_ptBins);
  TH1D* hPtMCrecoonly = new TH1D("hPtMCrecoonly","",_nBins,_ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",_nBins,_ptBins);
  TH1D* hPtGenAcc = new TH1D("hPtGenAcc","",_nBins,_ptBins);
  TH1D* hPtGenAccWeighted = new TH1D("hPtGenAccWeighted","",_nBins,_ptBins);
  TH1D* hPthat = new TH1D("hPthat","",100,0,500);
  TH1D* hPthatweight = new TH1D("hPthatweight","",100,0,500);

  //ntMC->Project("hPtMC","hiBin",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Bgen==23333)"));
  ntMC->Project("hPtMC","hiBin",TCut(weighpthat)*TCut(weightBgenpt)*TCut(weightHiBin)*(TCut(cut.Data())&&"(Bgen==23333)"));
  divideBinWidth(hPtMC);
  //ntMC->Project("hPtMCrecoonly","hiBin",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)"));
  ntMC->Project("hPtMCrecoonly","hiBin",TCut(weighpthat)*TCut(weightBgenpt)*TCut(weightHiBin)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)"));
  divideBinWidth(hPtMCrecoonly);
  //ntGen->Project("hPtGen","hiBin",(TCut(selmcgen.Data())));
  ntGen->Project("hPtGen","hiBin",TCut(weighpthat)*TCut(weightGpt)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);
  //ntGen->Project("hPtGenAcc","hiBin",(TCut(selmcgenacceptance.Data())));
  ntGen->Project("hPtGenAcc","hiBin",TCut(weighpthat)*TCut(weightGpt)*(TCut(selmcgenacceptance.Data())));
  divideBinWidth(hPtGenAcc);
  //ntGen->Project("hPtGenAccWeighted","hiBin",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data())));
  ntGen->Project("hPtGenAccWeighted","hiBin",TCut(weighpthat)*TCut(weightGpt)*TCut(weightHiBin)*(TCut(selmcgenacceptance.Data())));
  divideBinWidth(hPtGenAccWeighted);

  ntMC->Project("hPthat","pthat","1");
  ntMC->Project("hPthatweight","pthat",TCut("1"));

  hPtMC->Sumw2();
  hPtGenAcc->Sumw2();
  hPtMCrecoonly->Sumw2();
  //Acceptance
  TH1D* hEffAcc = (TH1D*)hPtGenAcc->Clone("hEffAcc");
  hEffAcc->Sumw2();
  hEffAcc->Divide(hEffAcc,hPtGen,1,1,"b");
  //Selection
  TH1D* hEffSelection = (TH1D*)hPtMC->Clone("hEffSelection");
  hEffSelection->Sumw2();
  hEffSelection->Divide(hEffSelection,hPtGenAccWeighted,1,1,"b");
  //Acc * Eff (one shot)
  TH1D* hEffReco = (TH1D*)hPtMCrecoonly->Clone("hEffReco");
  hEffReco->Sumw2();
  hEffReco->Divide(hEffReco,hPtGen,1,1,"b");
  //Acc * Eff
  TH1D* hEff = (TH1D*)hEffSelection->Clone("hEff");
  hEff->Sumw2();
  //hEff->Divide(hPtMC,hPtGen,1,1,"");
  hEff->Multiply(hEff,hEffAcc,1,1);

  TH2F* hemptyEff=new TH2F("hemptyEff","",50,_ptBins[0]-5.,_ptBins[_nBins]+5.,10.,0,1.0);  
  hemptyEff->GetXaxis()->CenterTitle();
  hemptyEff->GetYaxis()->CenterTitle();
  //hemptyEff->GetYaxis()->SetTitle("acceptance x #epsilon_{reco} x #epsilon_{sel} ");
  hemptyEff->GetYaxis()->SetTitle("#alpha x #epsilon");
  hemptyEff->GetXaxis()->SetTitle("Centrality");
  hemptyEff->GetXaxis()->SetTitleOffset(0.9);
  hemptyEff->GetYaxis()->SetTitleOffset(0.95);
  hemptyEff->GetXaxis()->SetTitleSize(0.05);
  hemptyEff->GetYaxis()->SetTitleSize(0.05);
  hemptyEff->GetXaxis()->SetTitleFont(42);
  hemptyEff->GetYaxis()->SetTitleFont(42);
  hemptyEff->GetXaxis()->SetLabelFont(42);
  hemptyEff->GetYaxis()->SetLabelFont(42);
  hemptyEff->GetXaxis()->SetLabelSize(0.035);
  hemptyEff->GetYaxis()->SetLabelSize(0.035);  
  hemptyEff->SetMaximum(2);
  hemptyEff->SetMinimum(0.);
  hemptyEff->Draw();

  TH2F* hemptyEffAcc=(TH2F*)hemptyEff->Clone("hemptyEffAcc");
  TH2F* hemptyEffReco=(TH2F*)hemptyEff->Clone("hemptyEffReco");
  TH2F* hemptyEffSelection=(TH2F*)hemptyEff->Clone("hemptyEffSelection");
 

  TCanvas*canvasEff=new TCanvas("canvasEff","canvasEff",1000.,500);
  canvasEff->Divide(2,1);
  canvasEff->cd(1);
  
  hemptyEffAcc->SetYTitle("#alpha");
  hemptyEffAcc->Draw();
  hEffAcc->Draw("same");
  canvasEff->cd(2);
  hemptyEff->Draw();
  hEff->Draw("same");
  canvasEff->SaveAs(Form("plotEff/canvasEff_study%s_Cent.pdf",Form(label.Data())));
  
  TH2F* hemptyPthat=new TH2F("hemptyPthat","",50,0.,500.,10,1e-5,1e9);  
  hemptyPthat->GetXaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->SetTitle("Entries");
  hemptyPthat->GetXaxis()->SetTitle("pthat");
  hemptyPthat->GetXaxis()->SetTitleOffset(0.9);
  hemptyPthat->GetYaxis()->SetTitleOffset(0.95);
  hemptyPthat->GetXaxis()->SetTitleSize(0.05);
  hemptyPthat->GetYaxis()->SetTitleSize(0.05);
  hemptyPthat->GetXaxis()->SetTitleFont(42);
  hemptyPthat->GetYaxis()->SetTitleFont(42);
  hemptyPthat->GetXaxis()->SetLabelFont(42);
  hemptyPthat->GetYaxis()->SetLabelFont(42);
  hemptyPthat->GetXaxis()->SetLabelSize(0.035);
  hemptyPthat->GetYaxis()->SetLabelSize(0.035);  
  hemptyPthat->SetMaximum(2);
  hemptyPthat->SetMinimum(0.);


  TH2F* hemptySpectra=new TH2F("hemptySpectra","",50,0.,130.,10,1,1e5);  
  hemptySpectra->GetXaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->SetTitle("Entries");
  hemptySpectra->GetXaxis()->SetTitle("Centrality");
  hemptySpectra->GetXaxis()->SetTitleOffset(0.9);
  hemptySpectra->GetYaxis()->SetTitleOffset(0.95);
  hemptySpectra->GetXaxis()->SetTitleSize(0.05);
  hemptySpectra->GetYaxis()->SetTitleSize(0.05);
  hemptySpectra->GetXaxis()->SetTitleFont(42);
  hemptySpectra->GetYaxis()->SetTitleFont(42);
  hemptySpectra->GetXaxis()->SetLabelFont(42);
  hemptySpectra->GetYaxis()->SetLabelFont(42);
  hemptySpectra->GetXaxis()->SetLabelSize(0.035);
  hemptySpectra->GetYaxis()->SetLabelSize(0.035);  

  TH2F* hemptyPthatWeighted=(TH2F*)hemptyPthat->Clone("hemptyPthatWeighted");
  hemptyPthatWeighted->GetXaxis()->SetTitle("pthat reweighted");
  
  TCanvas*canvasPthat=new TCanvas("canvasPthat","canvasPthat",1000.,500);
  canvasPthat->Divide(2,1);
  canvasPthat->cd(1);
  gPad->SetLogy();
  hemptyPthat->Draw("same");
  hPthat->Draw("same");
  canvasPthat->cd(2);
  gPad->SetLogy();
  hemptyPthatWeighted->Draw();
  hPthatweight->Draw("same");
  canvasPthat->SaveAs(Form("plotEff/canvasPthat_%s_Cent.pdf",Form(label.Data())));
  
  TCanvas*canvasSpectra=new TCanvas("canvasSpectra","canvasSpectra",1000.,500);
  canvasSpectra->Divide(2,1);
  canvasSpectra->cd(1);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtMC->Draw("same");
  canvasSpectra->cd(2);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtGen->Draw("same");
  canvasSpectra->SaveAs(Form("plotEff/canvasSpectra_%s_Cent.pdf",Form(label.Data())));

  //### 1D histogram
  //hEff = hPtMC / hPtGen
  //hEffReco = hPtMCrecoonly / hPtGen
  //hEffAcc = hPtGenAcc / hPtGen
  //hEffSelection = hPtMC / hPtMCrecoonly
 
/*
  ntMC->Project("hPtMC","hiBin",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Bgen==23333)"));
  ntMC->Project("hPtMCrecoonly","hiBin",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)"));
  ntGen->Project("hPtGen","hiBin",TCut(weightfunctiongen)*(TCut(selmcgen.Data())));
  ntGen->Project("hPtGenAcc","hiBin",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data())));
*/  
  TCanvas*canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtMC");
  hemptySpectra->Draw(); 
  hPtMC->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtMC_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtMCrecoonly");
  hemptySpectra->Draw(); 
  hPtMCrecoonly->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtMCrecoonly_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtGen");
  hemptySpectra->Draw(); 
  hPtGen->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtGen_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtGenAcc");
  hemptySpectra->Draw(); 
  hPtGenAcc->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtGenAcc_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy(0);
  hemptyEff->SetYTitle("hPtMC / hPtGen");
  hemptyEff->Draw(); 
  hEff->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEff_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  hemptyEff->SetYTitle("hPtMCrecoonly / hPtGen");
  hemptyEff->Draw(); 
  hEffReco->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEffReco_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  hemptyEff->SetYTitle("hPtGenAcc / hPtGen");
  hemptyEff->Draw(); 
  hEffAcc->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEffAcc_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  hemptyEff->SetYTitle("hPtMC / hPtGenAcc");
  hemptyEff->Draw(); 
  hEffSelection->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEffSelection_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  gStyle->SetPalette(55);
  TCanvas* canvas2D=new TCanvas("canvas2D","",600,600);

  TFile *fout=new TFile(outputfile.Data(),"recreate");
  fout->cd();
  hPtGen->Write();
  hEffAcc->Write();
  hEffReco->Write();
  hEffSelection->Write();
  hEff->Write();
  hPtMC->Write();
  fout->Close();  

}
Beispiel #3
0
void MCefficiency(int isPbPb=0,TString inputmc="/data/wangj/MC2015/Dntuple/pp/revised/ntD_pp_Dzero_kpi_prompt/ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))",TString selmcgenacceptance="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))&&abs(Gtk1eta)<2.0&&abs(Gtk2eta)<2.0&&Gtk1pt>2.0&&Gtk2pt>2.0", TString cut_recoonly="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11", TString cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)",TString label="PP",TString outputfile="test", int useweight=1,Float_t centmin=0., Float_t centmax=100.)
{ 
 
  hiBinMin = centmin*2;
  hiBinMax = centmax*2;
  centMin = centmin;
  centMax = centmax;
  
  if(isPbPb==1)
    {
      selmcgen = selmcgen+Form("&&hiBin>=%f&&hiBin<%f",hiBinMin,hiBinMax);
      selmcgenacceptance=selmcgenacceptance+Form("&&hiBin>=%f&&hiBin<%f",hiBinMin,hiBinMax);
      cut_recoonly=cut_recoonly+Form("&&hiBin>=%f&&hiBin<%f",hiBinMin,hiBinMax);
      cut=cut+Form("&&hiBin>=%f&&hiBin<%f",hiBinMin,hiBinMax);
    }

     std::cout<<"selmcgen="<<selmcgen<<std::endl;
     std::cout<<"selmcgenacceptance="<<selmcgenacceptance<<std::endl;
     std::cout<<"cut_recoonly"<<cut_recoonly<<std::endl;
     std::cout<<"AAAA cut="<<cut<<std::endl;

 std::cout<<"option="<<useweight<<std::endl;
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetEndErrorSize(0);
  gStyle->SetMarkerStyle(20);
 
  TFile* infMC = new TFile(inputmc.Data());
  TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree* ntSkim = (TTree*)infMC->Get("ntSkim");
  ntMC->AddFriend(ntGen);
  ntMC->AddFriend(ntSkim);
  

  TTree* nthi = (TTree*)infMC->Get("ntHi");
  ntGen->AddFriend(nthi);
  ntGen->AddFriend(ntSkim);
  nthi->AddFriend(ntMC);
  ntMC->AddFriend(nthi);

// optimal weigths
if(useweight==0) {
    weightfunctiongen="1";
    weightfunctionreco="1";
  }
  // pp weight
  if(useweight==1) {
     weightfunctiongen="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(0.0116437+Max$(Gpt)*(0.0602697)+Max$(Gpt)*Max$(Gpt)*(-0.00226879)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(3.91035e-05)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-3.0699e-07)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(8.73234e-10))";
     weightfunctionreco="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(0.0116437+Max$(Gpt)*(0.0602697)+Max$(Gpt)*Max$(Gpt)*(-0.00226879)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(3.91035e-05)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-3.0699e-07)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(8.73234e-10))";
  }
  //PbPb weight
  if(useweight==2) {
    weightfunctiongen="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))";
    weightfunctionreco="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))";
  }
  //PbPb low pt weight
  if(useweight==3) {
    weightfunctiongen="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))*(-0.00600791+Max$(Gpt)*(0.0838585)+Max$(Gpt)*Max$(Gpt)*(-0.00991096)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(0.000496019)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-8.50065e-06))";
    weightfunctionreco="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))*(-0.00600791+Max$(Gpt)*(0.0838585)+Max$(Gpt)*Max$(Gpt)*(-0.00991096)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(0.000496019)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-8.50065e-06))";
  }
  if(useweight==4) {
    weightfunctiongen="(pthatweight)*(Max$(Gpt)<pthat/1.2)";
    weightfunctionreco="(pthatweight)*(Max$(Gpt)<pthat/1.2)";
  }


   std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl;

  TH1D* hPtMC = new TH1D("hPtMC","",nBins,ptBins);
  TH1D* hPtMCrecoonly = new TH1D("hPtMCrecoonly","",nBins,ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",nBins,ptBins);
  TH1D* hPtGenAcc = new TH1D("hPtGenAcc","",nBins,ptBins);
  TH1D* hPthat = new TH1D("hPthat","",100,0,500);
  TH1D* hPthatweight = new TH1D("hPthatweight","",100,0,500);
  
  ntMC->Project("hPtMC","Dpt",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMC);
  std::cout<<"step1"<<std::endl;
  ntMC->Project("hPtMCrecoonly","Dpt",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMCrecoonly);
  std::cout<<"step2"<<std::endl;
  ntGen->Project("hPtGen","Gpt",TCut(weightfunctiongen)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);
  std::cout<<"step3"<<std::endl;
  ntGen->Project("hPtGenAcc","Gpt",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data())));
  divideBinWidth(hPtGenAcc);
  std::cout<<"step4"<<std::endl;


  ntMC->Project("hPthat","pthat","1");
  ntMC->Project("hPthatweight","pthat",TCut("1"));

  hPtMC->Sumw2();
  TH1D* hEff = (TH1D*)hPtMC->Clone("hEff");
  hEff->Divide(hPtGen);

  TH1D* hEffReco = (TH1D*)hPtMCrecoonly->Clone("hEffReco");
  hEffReco->Sumw2();
  hEffReco->Divide(hPtGen);

  TH1D* hEffAcc = (TH1D*)hPtGenAcc->Clone("hEffAcc");
  hEffAcc->Sumw2();
  hEffAcc->Divide(hEffAcc,hPtGen,1,1,"b");
  
  TH1D* hEffSelection = (TH1D*)hPtMC->Clone("hEffSelection");
  hEffSelection->Sumw2();
  hEffSelection->Divide(hEffSelection,hPtMCrecoonly,1,1,"b");
  
  TH2F* hemptyEff=new TH2F("hemptyEff","",50,ptBins[0]-5.,ptBins[nBins]+5.,10.,0,1.5);  
  hemptyEff->GetXaxis()->CenterTitle();
  hemptyEff->GetYaxis()->CenterTitle();
  hemptyEff->GetYaxis()->SetTitle("acceptance x #epsilon_{reco} x #epsilon_{sel} ");
  hemptyEff->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hemptyEff->GetXaxis()->SetTitleOffset(0.9);
  hemptyEff->GetYaxis()->SetTitleOffset(0.95);
  hemptyEff->GetXaxis()->SetTitleSize(0.05);
  hemptyEff->GetYaxis()->SetTitleSize(0.05);
  hemptyEff->GetXaxis()->SetTitleFont(42);
  hemptyEff->GetYaxis()->SetTitleFont(42);
  hemptyEff->GetXaxis()->SetLabelFont(42);
  hemptyEff->GetYaxis()->SetLabelFont(42);
  hemptyEff->GetXaxis()->SetLabelSize(0.035);
  hemptyEff->GetYaxis()->SetLabelSize(0.035);  
  hemptyEff->SetMaximum(2);
  hemptyEff->SetMinimum(0.);
  hemptyEff->Draw();

  TH2F* hemptyEffAcc=(TH2F*)hemptyEff->Clone("hemptyEffAcc");
  TH2F* hemptyEffReco=(TH2F*)hemptyEff->Clone("hemptyEffReco");
  TH2F* hemptyEffSelection=(TH2F*)hemptyEff->Clone("hemptyEffSelection");
  
  TCanvas*canvasEff=new TCanvas("canvasEff","canvasEff",1000.,500);
  canvasEff->Divide(2,1);
  canvasEff->cd(1);
  
  hemptyEffAcc->SetYTitle("#alpha");
  hemptyEffAcc->Draw();
  hEffAcc->Draw("same");
  canvasEff->cd(2);
  hemptyEff->Draw();
  hEff->Draw("same");
  canvasEff->SaveAs(Form("plotEff/canvasEff_study%s.pdf",Form(label.Data())));
  
  
  TH2F* hemptyPthat=new TH2F("hemptyPthat","",50,0.,500.,10,1e-5,1e9);  
  hemptyPthat->GetXaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->SetTitle("Entries");
  hemptyPthat->GetXaxis()->SetTitle("pthat");
  hemptyPthat->GetXaxis()->SetTitleOffset(0.9);
  hemptyPthat->GetYaxis()->SetTitleOffset(0.95);
  hemptyPthat->GetXaxis()->SetTitleSize(0.05);
  hemptyPthat->GetYaxis()->SetTitleSize(0.05);
  hemptyPthat->GetXaxis()->SetTitleFont(42);
  hemptyPthat->GetYaxis()->SetTitleFont(42);
  hemptyPthat->GetXaxis()->SetLabelFont(42);
  hemptyPthat->GetYaxis()->SetLabelFont(42);
  hemptyPthat->GetXaxis()->SetLabelSize(0.035);
  hemptyPthat->GetYaxis()->SetLabelSize(0.035);  
  hemptyPthat->SetMaximum(2);
  hemptyPthat->SetMinimum(0.);


  TH2F* hemptySpectra=new TH2F("hemptySpectra","",50,0.,130.,10,1,1e5);  
  hemptySpectra->GetXaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->SetTitle("Entries");
  hemptySpectra->GetXaxis()->SetTitle("p_{T}");
  hemptySpectra->GetXaxis()->SetTitleOffset(0.9);
  hemptySpectra->GetYaxis()->SetTitleOffset(0.95);
  hemptySpectra->GetXaxis()->SetTitleSize(0.05);
  hemptySpectra->GetYaxis()->SetTitleSize(0.05);
  hemptySpectra->GetXaxis()->SetTitleFont(42);
  hemptySpectra->GetYaxis()->SetTitleFont(42);
  hemptySpectra->GetXaxis()->SetLabelFont(42);
  hemptySpectra->GetYaxis()->SetLabelFont(42);
  hemptySpectra->GetXaxis()->SetLabelSize(0.035);
  hemptySpectra->GetYaxis()->SetLabelSize(0.035);  

  TH2F* hemptyPthatWeighted=(TH2F*)hemptyPthat->Clone("hemptyPthatWeighted");
  hemptyPthatWeighted->GetXaxis()->SetTitle("pthat reweighted");
  
  TCanvas*canvasPthat=new TCanvas("canvasPthat","canvasPthat",1000.,500);
  canvasPthat->Divide(2,1);
  canvasPthat->cd(1);
  gPad->SetLogy();
  hemptyPthat->Draw("same");
  hPthat->Draw("same");
  canvasPthat->cd(2);
  gPad->SetLogy();
  hemptyPthatWeighted->Draw();
  hPthatweight->Draw("same");
 // canvasPthat->SaveAs(Form("plotEff/canvasPthat_%s.pdf",Form(label.Data())));
  
  TCanvas*canvasSpectra=new TCanvas("canvasSpectra","canvasSpectra",1000.,500);
  canvasSpectra->Divide(2,1);
  canvasSpectra->cd(1);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtMC->Draw("same");
  canvasSpectra->cd(2);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtGen->Draw("same");

  TFile *fout=new TFile(outputfile.Data(),"recreate");
  fout->cd();
  hPtGen->Write();
  hEffAcc->Write();
  hEffReco->Write();
  hEffSelection->Write();
  hEff->Write();
  hPtMC->Write();
  fout->Close();  

}
Beispiel #4
0
void bToDRawYield()
{
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.04);
	gStyle->SetPadLeftMargin(0.14);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.14);
	gStyle->SetTitleX(.0f);
	gStyle->SetOptFit(1111);
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);

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

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

	TCanvas* c1 = new TCanvas();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		c2->cd(1);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;

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

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

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

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

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

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

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

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

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

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

		c15->cd(1);

		fitMass(hMData, hMMCSignal, hMMCSwapped);

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

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

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

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

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

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

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

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

		divideBinWidth(hD0DcaDataFit);

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

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

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

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

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

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

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

		setColorTitleLabel(hD0DcaData, 1);

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

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

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

		float fitRangeL = 0;
		float fitRangeH = 0.08;

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

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

		hD0DcaData->Draw("same");

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

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

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

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

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

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

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

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

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

		int nSmear = 1000;

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

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

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

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

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

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

		c4->cd(4);

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

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

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

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

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

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

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

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

		c1->cd();

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

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

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

		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;

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

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

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

	c1->SetLogy();

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

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

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

	TFile* fOut = new TFile("bFeedDownResult.root", "recreate");
	fOut->WriteTObject(grFraction);
	fOut->WriteTObject(hBtoDRawYield);
	fOut->WriteTObject(hPromptDRawYield);
	fOut->WriteTObject(hTotalDYieldInvMassFit);
	fOut->Write();
	fOut->Close();
}
Beispiel #5
0
void efficiency_D(){

//	TString inPbPbMCP_pthatFilter="/data/HeavyFlavourRun2/MC2015/Dntuple/PbPb/ntD_EvtBase_20160513_DfinderMC_PbPb_20160502_dPt1tkPt0p5_D0_prompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root" ;
	
//	TString inPbPbMCNP_pthatFilter="/data/HeavyFlavourRun2/MC2015/Dntuple/PbPb/ntD_EvtBase_20160513_DfinderMC_PbPb_20160502_dPt1tkPt0p5_D0_nonprompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root";

TString inppMCP_pthatFilter="/data/HeavyFlavourRun2/MC2015/Dntuple/pp/ntD_EvtBase_20160513_DfinderMC_pp_20160502_dPt0tkPt0p5_D0Dstar_prompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root";
TString inppMCNP_pthatFilter="/data/HeavyFlavourRun2/MC2015/Dntuple/pp/ntD_EvtBase_20160513_DfinderMC_pp_20160502_dPt0tkPt0p5_D0Dstar_nonprompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root";


  TString inppMCP_DptFilter="/data/chengchi/BtoD_MC2016/pp/Dntuple_pp_prompt_mergeAll.root" ;

  TString inppMCNP_DptFilter="/data/chengchi/BtoD_MC2016/pp/Dntuple_pp_Nonprompt_mergeAll.root";


	TString outfname="2015ppMCEffHis_PthatFilter.root";

	TString trgselection="1";

	TString cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>1.0&&Dtrk2Pt>1.0&&Dtrk1PtErr/Dtrk1Pt<0.3&&Dtrk2PtErr/Dtrk2Pt<0.3&&abs(Dtrk1Eta)<1.5&&abs(Dtrk2Eta)<1.5&&((DlxyBS/DlxyBSErr)>1.5&&Dalpha<0.12&&((Dpt>1&&Dpt<2&&(DsvpvDistance/DsvpvDisErr)>6.0&&Dchi2cl>0.25)||(Dpt>2&&Dpt<4&&(DsvpvDistance/DsvpvDisErr)>5.86&&Dchi2cl>0.224)||(Dpt>4&&Dpt<5&&(DsvpvDistance/DsvpvDisErr)>5.46&&Dchi2cl>0.196)||(Dpt>5&&Dpt<6&&(DsvpvDistance/DsvpvDisErr)>4.86&&Dchi2cl>0.170)||(Dpt>6&&Dpt<8&&(DsvpvDistance/DsvpvDisErr)>4.54&&Dchi2cl>0.125)||(Dpt>8&&Dpt<10&&(DsvpvDistance/DsvpvDisErr)>4.42&&Dchi2cl>0.091)||(Dpt>10&&Dpt<15&&(DsvpvDistance/DsvpvDisErr)>4.06&&Dchi2cl>0.069)||(Dpt>15&&Dpt<20&&(DsvpvDistance/DsvpvDisErr)>3.71&&Dchi2cl>0.056)||(Dpt>20&&Dpt<25&&(DsvpvDistance/DsvpvDisErr)>3.25&&Dchi2cl>0.054)||(Dpt>25&&(DsvpvDistance/DsvpvDisErr)>2.97&&Dchi2cl>0.050)))";

 TString cutmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))";

 TString outputfile="ROOTfiles/hPtSpectrumDzeroPbPbMBppMCClosureMYTEST.root";

	bool isPbPb=false;
	int doweight=0;


  if(!isPbPb)
  {
    seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
    selmceff = Form("%s",cut.Data());
    selmcgen = Form("%s",cutmcgen.Data());
  }
  else
  {
    seldata = Form("%s&&%s&&hiBin>%f&&hiBin<%f",trgselection.Data(),cut.Data(),hiBinMin,hiBinMax);
    selmceff = Form("%s&&hiBin>%f&&hiBin<%f",cut.Data(),hiBinMin,hiBinMax);
    selmcgen = Form("%s&&hiBin>%f&&hiBin<%f",cutmcgen.Data(),hiBinMin,hiBinMax);
  }

  selmc = Form("%s",cut.Data());

  gStyle->SetTextSize(0.05);
  gStyle->SetTextFont(42);
  gStyle->SetPadRightMargin(0.043);
  gStyle->SetPadLeftMargin(0.18);
  gStyle->SetPadTopMargin(0.1);
  gStyle->SetPadBottomMargin(0.145);
  gStyle->SetTitleX(.0f);
	gStyle->SetOptStat(0);

  if(doweight==0) {
    weightgen="1";
    weight="1";
  }

  // pp weight
  if(doweight==1) {
    weightgen="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(0.0116437+Max$(Gpt)*(0.0602697)+Max$(Gpt)*Max$(Gpt)*(-0.00226879)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(3.91035e-05)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-3.0699e-07)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(8.73234e-10))";
    weight="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(0.0116437+Max$(Gpt)*(0.0602697)+Max$(Gpt)*Max$(Gpt)*(-0.00226879)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(3.91035e-05)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-3.0699e-07)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(8.73234e-10))";
  }
  //PbPb weight
  if(doweight==2) {
    weightgen="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))";
    weight="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))";
  }
  //PbPb low pt weight
  if(doweight==3) {
    weightgen="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))*(-0.00600791+Max$(Gpt)*(0.0838585)+Max$(Gpt)*Max$(Gpt)*(-0.00991096)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(0.000496019)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-8.50065e-06))";
    weight="(pthatweight)*(Max$(Gpt)<pthat/1.2)*(6.14981+hiBin*(-0.156513)+hiBin*hiBin*(0.00149127)+hiBin*hiBin*hiBin*(-6.29087e-06)+hiBin*hiBin*hiBin*hiBin*(9.90029e-09))*(-0.00600791+Max$(Gpt)*(0.0838585)+Max$(Gpt)*Max$(Gpt)*(-0.00991096)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(0.000496019)+Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*Max$(Gpt)*(-8.50065e-06))";
  }
  if(doweight<0 || doweight>4) std::cout<<"ERROR, this weighting option is not defined"<<std::endl;

  std::cout<<"we are using weight="<<weight<<std::endl;

	weight="pthatweight";
	weightgen="pthatweight";

  TFile* infppMCP_pthatFilter = new TFile(inppMCP_pthatFilter.Data());
	
  TTree* ntGenppMCP_pthatFilter = (TTree*)infppMCP_pthatFilter->Get("ntGen");
  ntGenppMCP_pthatFilter->AddFriend("ntHlt");
  ntGenppMCP_pthatFilter->AddFriend("ntHi");

  TTree* ntppMCP_pthatFilter = (TTree*)infppMCP_pthatFilter->Get("ntDkpi");
  ntppMCP_pthatFilter->AddFriend("ntHlt");
  ntppMCP_pthatFilter->AddFriend("ntHi");
  ntppMCP_pthatFilter->AddFriend("ntSkim");
  ntppMCP_pthatFilter->AddFriend(ntGenppMCP_pthatFilter);


  TH1D* hPtppMCP_pthatFilter = new TH1D("hPtppMCP_pthatFilter","",nPtBins,ptBins);
  TH1D* hPtGenppMCP_pthatFilter = new TH1D("hPtGenppMCP_pthatFilter","",nPtBins,ptBins);

  ntppMCP_pthatFilter->Project("hPtppMCP_pthatFilter","Dpt",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtppMCP_pthatFilter);
  ntGenppMCP_pthatFilter->Project("hPtGenppMCP_pthatFilter","Gpt",TCut(weightgen)*(TCut(selmcgen.Data())));
	divideBinWidth(hPtGenppMCP_pthatFilter);

  hPtppMCP_pthatFilter->Sumw2();
  TH1D* hEffppMCP_pthatFilter = (TH1D*)hPtppMCP_pthatFilter->Clone("hEffppMCP_pthatFilter");
  hEffppMCP_pthatFilter->SetTitle(";D^{0} p_{T} (GeV/c);Efficiency");
  hEffppMCP_pthatFilter->Sumw2();
  hEffppMCP_pthatFilter->Divide(hPtGenppMCP_pthatFilter);
  TCanvas* cEffppMCP_pthatFilter = new TCanvas("cEffppMCP_pthatFilter","",600,600);
	hEffppMCP_pthatFilter->Draw();

	cEffppMCP_pthatFilter->SaveAs("EffppMCP_pthatFilter.png");



  TFile* infppMCNP_pthatFilter = new TFile(inppMCNP_pthatFilter.Data());

  TTree* ntGenppMCNP_pthatFilter = (TTree*)infppMCNP_pthatFilter->Get("ntGen");
  ntGenppMCNP_pthatFilter->AddFriend("ntHlt");
  ntGenppMCNP_pthatFilter->AddFriend("ntHi");

  TTree* ntppMCNP_pthatFilter = (TTree*)infppMCNP_pthatFilter->Get("ntDkpi");
  ntppMCNP_pthatFilter->AddFriend("ntHlt");
  ntppMCNP_pthatFilter->AddFriend("ntHi");
  ntppMCNP_pthatFilter->AddFriend("ntSkim");
  ntppMCNP_pthatFilter->AddFriend(ntGenppMCNP_pthatFilter);


  TH1D* hPtppMCNP_pthatFilter = new TH1D("hPtppMCNP_pthatFilter","",nPtBins,ptBins);
  TH1D* hPtGenppMCNP_pthatFilter = new TH1D("hPtGenppMCNP_pthatFilter","",nPtBins,ptBins);

  ntppMCNP_pthatFilter->Project("hPtppMCNP_pthatFilter","Dpt",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtppMCNP_pthatFilter);
  ntGenppMCNP_pthatFilter->Project("hPtGenppMCNP_pthatFilter","Gpt",TCut(weightgen)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGenppMCNP_pthatFilter);

  hPtppMCNP_pthatFilter->Sumw2();
  TH1D* hEffppMCNP_pthatFilter = (TH1D*)hPtppMCNP_pthatFilter->Clone("hEffppMCNP_pthatFilter");
  hEffppMCNP_pthatFilter->SetTitle(";D^{0} p_{T} (GeV/c);Efficiency");
  hEffppMCNP_pthatFilter->Sumw2();
  hEffppMCNP_pthatFilter->Divide(hPtGenppMCNP_pthatFilter);
  TCanvas* cEffppMCNP_pthatFilter = new TCanvas("cEffppMCNP_pthatFilter","",600,600);
  hEffppMCNP_pthatFilter->Draw();

  cEffppMCNP_pthatFilter->SaveAs("EffppMCNP_pthatFilter.png");

// no pthat weight for new MC sample
  weight="1";
  weightgen="1";


  TFile* infppMCP_DptFilter = new TFile(inppMCP_DptFilter.Data());
	
  TTree* ntGenppMCP_DptFilter = (TTree*)infppMCP_DptFilter->Get("ntGen");
  ntGenppMCP_DptFilter->AddFriend("ntHlt");
  ntGenppMCP_DptFilter->AddFriend("ntHi");

  TTree* ntppMCP_DptFilter = (TTree*)infppMCP_DptFilter->Get("ntDkpi");
  ntppMCP_DptFilter->AddFriend("ntHlt");
  ntppMCP_DptFilter->AddFriend("ntHi");
  ntppMCP_DptFilter->AddFriend("ntSkim");
  ntppMCP_DptFilter->AddFriend(ntGenppMCP_DptFilter);


  TH1D* hPtppMCP_DptFilter = new TH1D("hPtppMCP_DptFilter","",nPtBins,ptBins);
  TH1D* hPtGenppMCP_DptFilter = new TH1D("hPtGenppMCP_DptFilter","",nPtBins,ptBins);

  ntppMCP_DptFilter->Project("hPtppMCP_DptFilter","Dpt",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtppMCP_DptFilter);
  ntGenppMCP_DptFilter->Project("hPtGenppMCP_DptFilter","Gpt",TCut(weightgen)*(TCut(selmcgen.Data())));
	divideBinWidth(hPtGenppMCP_DptFilter);

  hPtppMCP_DptFilter->Sumw2();
  TH1D* hEffppMCP_DptFilter = (TH1D*)hPtppMCP_DptFilter->Clone("hEffppMCP_DptFilter");
  hEffppMCP_DptFilter->SetTitle(";D^{0} p_{T} (GeV/c);Efficiency");
  hEffppMCP_DptFilter->Sumw2();
  hEffppMCP_DptFilter->Divide(hPtGenppMCP_DptFilter);
  TCanvas* cEffppMCP_DptFilter = new TCanvas("cEffppMCP_DptFilter","",600,600);
	hEffppMCP_DptFilter->Draw();

	cEffppMCP_DptFilter->SaveAs("EffppMCP_DptFilter.png");

  TFile* infppMCNP_DptFilter = new TFile(inppMCNP_DptFilter.Data());

  TTree* ntGenppMCNP_DptFilter = (TTree*)infppMCNP_DptFilter->Get("ntGen");
  ntGenppMCNP_DptFilter->AddFriend("ntHlt");
  ntGenppMCNP_DptFilter->AddFriend("ntHi");

  TTree* ntppMCNP_DptFilter = (TTree*)infppMCNP_DptFilter->Get("ntDkpi");
  ntppMCNP_DptFilter->AddFriend("ntHlt");
  ntppMCNP_DptFilter->AddFriend("ntHi");
  ntppMCNP_DptFilter->AddFriend("ntSkim");
  ntppMCNP_DptFilter->AddFriend(ntGenppMCNP_DptFilter);


  TH1D* hPtppMCNP_DptFilter = new TH1D("hPtppMCNP_DptFilter","",nPtBins,ptBins);
  TH1D* hPtGenppMCNP_DptFilter = new TH1D("hPtGenppMCNP_DptFilter","",nPtBins,ptBins);

  ntppMCNP_DptFilter->Project("hPtppMCNP_DptFilter","Dpt",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtppMCNP_DptFilter);
  ntGenppMCNP_DptFilter->Project("hPtGenppMCNP_DptFilter","Gpt",TCut(weightgen)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGenppMCNP_DptFilter);

  hPtppMCNP_DptFilter->Sumw2();
  TH1D* hEffppMCNP_DptFilter = (TH1D*)hPtppMCNP_DptFilter->Clone("hEffppMCNP_DptFilter");
  hEffppMCNP_DptFilter->SetTitle(";D^{0} p_{T} (GeV/c);Efficiency");
  hEffppMCNP_DptFilter->Sumw2();
  hEffppMCNP_DptFilter->Divide(hPtGenppMCNP_DptFilter);
  TCanvas* cEffppMCNP_DptFilter = new TCanvas("cEffppMCNP_DptFilter","",600,600);
  hEffppMCNP_DptFilter->Draw();

  cEffppMCNP_DptFilter->SaveAs("EffppMCNP_DptFilter.png");


	TCanvas *c_effAll = new TCanvas("c_effAll","c_effAll",1000,1000);
	c_effAll->Divide(2,2);

	TH1D *hEffppMCP_ratio=(TH1D*)hEffppMCP_DptFilter->Clone("hEffppMCP_ratio");
	hEffppMCP_ratio->Sumw2();
	hEffppMCP_ratio->Divide(hEffppMCP_pthatFilter);

  TH1D *hEffppMCNP_ratio=(TH1D*)hEffppMCNP_DptFilter->Clone("hEffppMCNP_ratio");
  hEffppMCNP_ratio->Sumw2();
  hEffppMCNP_ratio->Divide(hEffppMCNP_pthatFilter);

  c_effAll->cd(1);
	gPad->SetLogx();
	hEffppMCP_DptFilter->Draw();
	hEffppMCP_DptFilter->SetLineColor(2);
	hEffppMCP_pthatFilter->Draw("eSAME");
	hEffppMCP_pthatFilter->SetLineColor(4);

	TLegend *le_hEffppMCP = new TLegend(0.24,0.68,0.48,0.88,NULL,"brNDC");
	le_hEffppMCP->SetBorderSize(0);
  le_hEffppMCP->AddEntry((TObject*)0,"pp MC efficiency","");
	le_hEffppMCP->AddEntry(hEffppMCP_DptFilter,"Prompt new MC");
	le_hEffppMCP->AddEntry(hEffppMCP_pthatFilter,"Prompt old MC");
	le_hEffppMCP->Draw("same");

  c_effAll->cd(2);
  gPad->SetLogx();
  hEffppMCNP_DptFilter->Draw();
  hEffppMCNP_DptFilter->SetLineColor(2);
  hEffppMCNP_pthatFilter->Draw("eSAME");
  hEffppMCNP_pthatFilter->SetLineColor(4);

  TLegend *le_hEffppMCNP = new TLegend(0.24,0.68,0.48,0.88,NULL,"brNDC");
  le_hEffppMCNP->SetBorderSize(0);
	le_hEffppMCNP->AddEntry((TObject*)0,"pp MC efficiency","");
  le_hEffppMCNP->AddEntry(hEffppMCNP_DptFilter,"Nonprompt new MC");
  le_hEffppMCNP->AddEntry(hEffppMCNP_pthatFilter,"Nonrompt old MC");
  le_hEffppMCNP->Draw("same");

	TLine *line1= new TLine(0,1,100,1);
	line1->SetLineStyle(7);

	c_effAll->cd(3);
  gPad->SetLogx();
	hEffppMCP_ratio->GetYaxis()->SetTitle("Eff Ratio");
	hEffppMCP_ratio->SetMarkerStyle(20);
	hEffppMCP_ratio->SetMarkerSize(0.8);
	hEffppMCP_ratio->SetMarkerColor(4);
	hEffppMCP_ratio->SetLineColor(4);
	hEffppMCP_ratio->Draw();
	line1->Draw("SAME");	
	TLatex* texppMCPratio = new TLatex(0.4,0.4,"pp Prompt D eff ratio new/old");
	texppMCPratio->SetNDC();
	texppMCPratio->SetTextSize(0.035);
	texppMCPratio->Draw();

	
	
	c_effAll->cd(4);
  gPad->SetLogx();
  hEffppMCNP_ratio->GetYaxis()->SetTitle("Eff Ratio");
  hEffppMCNP_ratio->SetMarkerStyle(20);
	hEffppMCNP_ratio->SetMarkerSize(0.8);
  hEffppMCNP_ratio->SetMarkerColor(4);
	hEffppMCNP_ratio->SetLineColor(4);
	hEffppMCNP_ratio->Draw();
  line1->Draw("SAME");
  TLatex* texppMCNPratio = new TLatex(0.4,0.4,"pp Nonrompt D eff ratio new/old");
  texppMCNPratio->SetNDC();
  texppMCNPratio->SetTextSize(0.035);
  texppMCNPratio->Draw();


	
	c_effAll->SaveAs("effAll.png");

// continue work here		

	weight="pthatweight";

	TH1D *h_ptMCP_pthatFilter = new TH1D("h_ptMCP_pthatFilter","h_ptMCP_pthatFilter",40,2,4);
  ntppMCP_pthatFilter->Project("h_ptMCP_pthatFilter","Dpt",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)"));
	h_ptMCP_pthatFilter->Sumw2();
	h_ptMCP_pthatFilter->Scale(1.0/h_ptMCP_pthatFilter->Integral());

  TH1D *h_ptMCP_DptFilter = new TH1D("h_ptMCP_DptFilter","h_ptMCP_DptFilter",40,2,4);
  ntppMCP_DptFilter->Project("h_ptMCP_DptFilter","Dpt",(TCut(selmceff.Data())&&"(Dgen==23333)"));
	h_ptMCP_DptFilter->Sumw2();
  h_ptMCP_DptFilter->Scale(1.0/h_ptMCP_DptFilter->Integral());

	TCanvas *c_Dptdis = new TCanvas("c_Dptdis","c_Dptdis",600,600);
	c_Dptdis->cd();
	h_ptMCP_pthatFilter->Draw();
	h_ptMCP_pthatFilter->SetLineColor(4);
	h_ptMCP_DptFilter->SetLineColor(2);
	h_ptMCP_DptFilter->Draw("SAME");
	c_Dptdis->SaveAs("plot/c_Dptdis.png");


  TH1D *h_yMCP_pthatFilter = new TH1D("h_yMCP_pthatFilter","h_yMCP_pthatFilter",20,-1,1);
  ntppMCP_pthatFilter->Project("h_yMCP_pthatFilter","Dy",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)&&(Dpt>2 && Dpt< 4)"));
  h_yMCP_pthatFilter->Sumw2();
  h_yMCP_pthatFilter->Scale(1.0/h_yMCP_pthatFilter->Integral());

  TH1D *h_yMCP_DptFilter = new TH1D("h_yMCP_DptFilter","h_yMCP_DptFilter",20,-1,1);
  ntppMCP_DptFilter->Project("h_yMCP_DptFilter","Dy",(TCut(selmceff.Data())&&"(Dgen==23333)&&(Dpt>2 && Dpt< 4)"));
  h_yMCP_DptFilter->Sumw2();
  h_yMCP_DptFilter->Scale(1.0/h_yMCP_DptFilter->Integral());

  TCanvas *c_Dydis = new TCanvas("c_Dydis","c_Dydis",600,600);
  c_Dydis->cd();
  h_yMCP_pthatFilter->Draw();
  h_yMCP_pthatFilter->SetLineColor(4);
  h_yMCP_DptFilter->SetLineColor(2);
  h_yMCP_DptFilter->Draw("SAME");
  c_Dydis->SaveAs("plot/c_Dydis.png");


  TH1D *h_DcaMCP_pthatFilter = new TH1D("h_DcaMCP_pthatFilter","h_DcaMCP_pthatFilter",nDcaBins,dcaBins);
  ntppMCP_pthatFilter->Project("h_DcaMCP_pthatFilter","DsvpvDistance*sin(Dalpha)",TCut(weight)*(TCut(selmceff.Data())&&"(Dgen==23333)&&(Dpt>2 && Dpt< 4)"));
  h_DcaMCP_pthatFilter->Sumw2();
  h_DcaMCP_pthatFilter->Scale(1.0/h_DcaMCP_pthatFilter->Integral());

  TH1D *h_DcaMCP_DptFilter = new TH1D("h_DcaMCP_DptFilter","h_DcaMCP_DptFilter",nDcaBins,dcaBins);
  ntppMCP_DptFilter->Project("h_DcaMCP_DptFilter","DsvpvDistance*sin(Dalpha)",(TCut(selmceff.Data())&&"(Dgen==23333)&&(Dpt>2 && Dpt< 4)"));
  h_DcaMCP_DptFilter->Sumw2();
  h_DcaMCP_DptFilter->Scale(1.0/h_DcaMCP_DptFilter->Integral());

  TCanvas *c_DDcadis = new TCanvas("c_DDcadis","c_DDcadis",600,600);
  c_DDcadis->cd();
	gPad->SetLogy();
  h_DcaMCP_pthatFilter->Draw();
  h_DcaMCP_pthatFilter->SetLineColor(4);
  h_DcaMCP_DptFilter->SetLineColor(2);
  h_DcaMCP_DptFilter->Draw("SAME");
  c_DDcadis->SaveAs("plot/c_DDcadis.png");




// end of main, save all into output file

  TFile *outf = TFile::Open(outfname.Data(),"recreate");
	outf->cd();
	hEffppMCP_pthatFilter->Write();
  hEffppMCNP_pthatFilter->Write();
  hEffppMCP_DptFilter->Write();
  hEffppMCNP_DptFilter->Write();
	hEffppMCP_ratio->Write();
	hEffppMCNP_ratio->Write();
	outf->Write();
	outf->Close();


}
Beispiel #6
0
void weightPbPbFONLL(int minfit=2,int maxfit=100,TString pthat="pthatall")
{
  TString label;
  TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))";
  TString myweightfunctiongen,myweightfunctionreco;
  
  //TCut weighpthat="pow(10,-0.075415*Gpt+1.748668+Gpt*Gpt*0.000388)+pow(10,-0.166406*Gpt+2.887856+Gpt*Gpt*0.000105) +0.003157";
  TCut weighpthat="1";

  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetEndErrorSize(0);
  gStyle->SetMarkerStyle(20);
 
  TFile*infMC=new TFile("/data/HeavyFlavourRun2/MC2015/Dntuple/PbPb/ntD_EvtBase_20160513_DfinderMC_PbPb_20160502_dPt1tkPt0p5_D0_prompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree *ntHiMC = (TTree*)infMC->Get("ntHi");
  ntGen->AddFriend(ntHiMC);
  
  TH1D* hPtGenFONLL = new TH1D("hPtGenFONLL","",nBinsReweight,ptBinsReweight);
  ntGen->Project("hPtGenFONLL","Gpt",(TCut(weighpthat)*TCut(selmcgen.Data())));
  divideBinWidth(hPtGenFONLL);
    
  TString fonll="/afs/cern.ch/work/g/ginnocen/public/output_pp_d0meson_5TeV_y1.root";
  TFile* filePPReference = new TFile(fonll.Data());  
  TGraphAsymmErrors* gaeBplusReference = (TGraphAsymmErrors*)filePPReference->Get("gaeSigmaDzero");

  TH1D* hFONLL = new TH1D("hFONLL","",nBinsReweight,ptBinsReweight);
  double x,y;
  for(int i=0;i<nBinsReweight;i++){
    gaeBplusReference->GetPoint(i,x,y);
    hFONLL->SetBinContent(i+1,y);
  }
  TH1D* hFONLLOverPt=(TH1D*)hFONLL->Clone("hFONLLOverPt");
  TH1D* hFONLLOverPtWeight=(TH1D*)hFONLL->Clone("hFONLLOverPtWeight");

  hFONLLOverPt->Divide(hPtGenFONLL);

/*
  TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]+x*x*x*x*[4]+x*x*x*x*x*[5]",0, 100);  
  hFONLLOverPt->Fit("myfit","","",0,100);

  double par0=myfit->GetParameter(0);
  double par1=myfit->GetParameter(1);
  double par2=myfit->GetParameter(2);
  double par3=myfit->GetParameter(3);
  double par4=myfit->GetParameter(4);
  double par5=myfit->GetParameter(5);

  std::cout<<"weight="<<par0<<"+Gpt*("<<par1<<")+Gpt*Gpt*("<<par2<<")+Gpt*Gpt*Gpt*("<<par3<<")"<<"+Gpt*Gpt*Gpt*Gpt*("<<par4<<")+Gpt*Gpt*Gpt*Gpt*Gpt*("<<par5<<")"<<endl;
  std::cout<<"weight="<<par0<<"+Dgenpt*("<<par1<<")+Dgenpt*Dgenpt*("<<par2<<")+Dgenpt*Dgenpt*Dgenpt*("<<par3<<")"<<"+Dgenpt*Dgenpt*Dgenpt*Dgenpt*("<<par4<<")+Dgenpt*Dgenpt*Dgenpt*Dgenpt*Dgenpt*("<<par5<<")"<<endl;
  
  std::cout<<myweightfunctiongen<<std::endl;
  std::cout<<myweightfunctionreco<<std::endl;
  std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl;
*/
    TF1 *myfit = new TF1("myfit","pow(10,[0]*x+[1]+x*x*[2])+pow(10,[3]*x+[4]+x*x*[5])+[6]", 2, 100);
    hFONLLOverPt->Fit("myfit","","",minfit,maxfit);
    double par0=myfit->GetParameter(0);
    double par1=myfit->GetParameter(1);
    double par2=myfit->GetParameter(2);
    double par3=myfit->GetParameter(3);
    double par4=myfit->GetParameter(4);
    double par5=myfit->GetParameter(5);
    double par6=myfit->GetParameter(6);

   myweightfunctiongen=Form("pow(10,%f*Gpt+%f+Gpt*Gpt*%f)+pow(10,%f*Gpt+%f+Gpt*Gpt*%f)+%f",par0,par1,par2,par3,par4,par5,par6);
   myweightfunctionreco=Form("pow(10,%f*Gpt+%f+Gpt*Gpt*%f)+pow(10,%f*Gpt+%f+Gpt*Gpt*%f)+%f",par0,par1,par2,par3,par4,par5,par6);
   std::cout<<myweightfunctiongen<<std::endl;
   std::cout<<myweightfunctionreco<<std::endl;

  TCanvas*canvasPtReweight=new TCanvas("canvasPtReweight","canvasPtReweight",1000.,500.); 
  canvasPtReweight->Divide(3,1);
  canvasPtReweight->cd(1);
  gPad->SetLogy();
  hPtGenFONLL->SetXTitle("Gen p_{T}");
  hPtGenFONLL->SetYTitle("#entries");
  hPtGenFONLL->SetMinimum(1e-4);  
  hPtGenFONLL->SetMaximum(1e11);  
  hPtGenFONLL->GetYaxis()->SetTitleOffset(1.4);
  hPtGenFONLL->Draw();
  canvasPtReweight->cd(2);
  gPad->SetLogy();
  hFONLL->SetXTitle("p_{T}");
  hFONLL->SetYTitle("FONLL, #entries");
  hFONLL->SetMinimum(1e-4);  
  hFONLL->SetMaximum(1e11);  
  hFONLL->GetYaxis()->SetTitleOffset(1.4);
  hFONLL->Draw();
  canvasPtReweight->cd(3);
  hFONLLOverPt->SetXTitle("Gen p_{T}");
  hFONLLOverPt->SetYTitle("FONLL/PYTHIA ");
  hFONLLOverPt->SetMinimum(0.01);  
  hFONLLOverPt->SetMaximum(10.);  
  hFONLLOverPt->GetYaxis()->SetTitleOffset(1.4);
  hFONLLOverPt->Draw();

}
Beispiel #7
0
void fitBsSingGau(TString infname="",bool doweight = 1)
{
   if (doweight==0) weight="1";
   if (infname=="") infname=inputdata.Data();
   TFile *inf = new TFile(infname.Data());
   TTree *nt = (TTree*) inf->Get("ntphi");

   TFile *infMC = new TFile(inputmc.Data());
   TTree *ntGen = (TTree*)infMC->Get("ntGen");
   TTree *ntMC = (TTree*)infMC->Get("ntphi");

   ntGen->AddFriend(ntMC);

   const int nBins = 1;
   double ptBins[nBins+1] = {10,60};
   TH1D *hPt = new TH1D("hPt","",nBins,ptBins);
   TH1D *hPtMC = new TH1D("hPtMC","",nBins,ptBins);
   TH1D *hPtGen = new TH1D("hPtGen","",nBins,ptBins);
   TH1D *hRecoTruth = new TH1D("hRecoTruth","",nBins,ptBins);
   ntMC->Project("hPtMC","pt",TCut(weight)*(selmc.Data()));
   nt->Project("hRecoTruth","pt",TCut(seldata_2y.Data())&&"(gen==23333)");
   ntGen->Project("hPtGen","pt",TCut(weight)*(selmcgen.Data()));
   divideBinWidth(hRecoTruth);
   
   for (int i=0;i<nBins;i++)
   {
      TF1 *f = fit(nt,ntMC,ptBins[i],ptBins[i+1]);
      double yield = f->Integral(5,6)/0.04;
      double yieldErr = f->Integral(5,6)/0.04*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
   }  

   /*
   divideBinWidth(hPtMC);
   divideBinWidth(hPtGen);

   TCanvas *c=  new TCanvas("cResult","",600,600);
   hPt->SetXTitle("B_{s} p_{T} (GeV/c)");
   hPt->SetYTitle("Uncorrected B_{s} dN/dp_{T}");
   hPt->Draw();
   hRecoTruth->Draw("same hist");
   
   hPtMC->Sumw2();
   TH1D *hEff = (TH1D*)hPtMC->Clone("hEff");
   hPtMC->Sumw2();
   hEff->Divide(hPtGen);
  
  TH1D *hPtCor = (TH1D*)hPt->Clone("hPtCor");
  hPtCor->Divide(hEff);
  TCanvas *cCor=  new TCanvas("cCorResult","",600,600);
  hPtCor->SetYTitle("Correctd B_{s} dN/dp_{T}");
  hPtCor->Draw();
  hPtGen->Draw("same");

  TH1D *hPtSigma= (TH1D*)hPtCor->Clone("hPtSigma");
  double BRchain=2.89977e-5;
  hPtSigma->Scale(1./(2*luminosity*BRchain));
  hPtSigma->SetYTitle("d#sigma/dp_{T} (B_{s})");

  TCanvas *cSigma=  new TCanvas("cSigma","",600,600);

  hPtSigma->Draw();
  
  TFile *outf = new TFile("ResultsBs/SigmaBs.root","recreate");
  outf->cd();
  hPt->Write();
  hEff->Write();
  hPtCor->Write();
  hPtSigma->Write();
  outf->Close();
  delete outf;
   */
}
Beispiel #8
0
void fitD(TString inputdata="/data/dmeson2015/DataDntuple/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2.root", TString inputmc="/afs/cern.ch/work/w/wangj/public/Dmeson/ntD_20151110_DfinderMC_20151110_EvtMatching_Pythia_D0pt15p0_Pthat15_TuneZ2_5020GeV_GENSIM_75x_1015_20151110_ppGlobaTrackingPPmenuHFlowpuv11_MBseed_twang-Pythia_1107.root", TString trgselection="((HLT_DmesonPPTrackingGlobal_Dpt15_v1&&Dpt>25&&Dpt<40)||(HLT_DmesonPPTrackingGlobal_Dpt30_v1&&Dpt>40&&Dpt<60)||(HLT_DmesonPPTrackingGlobal_Dpt50_v1&&Dpt>60))",  TString cut="Dy>-1.&&Dy<1.&&(Dtrk1highPurity&&Dtrk2highPurity)&&(DsvpvDistance/DsvpvDisErr)>3.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1Pt>1.5&&Dtrk2Pt>1.5", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))", int isMC=0, Double_t luminosity=26., int doweight=0, TString collsyst="PbPb", TString outputfile="mytest.root")
{
  collisionsystem=collsyst;
  seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
  selmc = Form("%s",cut.Data());

  gStyle->SetTextSize(0.05);
  gStyle->SetTextFont(42);
  gStyle->SetPadRightMargin(0.043);
  gStyle->SetPadLeftMargin(0.18);
  gStyle->SetPadTopMargin(0.1);
  gStyle->SetPadBottomMargin(0.145);
  gStyle->SetTitleX(.0f);

  void clean0 (TH1D* h);
  TF1* fit (TTree* nt, TTree* ntMC, double ptmin, double ptmax, int isMC);

  if(!doweight) weight="1";
  TFile* inf = new TFile(inputdata.Data());
  TFile* infMC = new TFile(inputmc.Data());

  TTree* nt = (TTree*) inf->Get("ntDkpi");
  TTree* HltTree= (TTree*) inf->Get("ntHlt");
  HltTree->AddFriend(nt);
  nt->AddFriend(HltTree);
  TTree* ntHid = (TTree*) inf->Get("ntHi");
  nt->AddFriend(ntHid);
  
  TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree* ntHi = (TTree*)infMC->Get("ntHi");
  
  ntGen->AddFriend(ntMC);
  ntGen->AddFriend(ntHi);
  ntMC->AddFriend(ntGen);
  ntMC->AddFriend(ntHi);
  ntHi->AddFriend(ntMC);
  
  TH1D* hPt = new TH1D("hPt","",nBins,ptBins);
  TH1D* hPtRecoTruth = new TH1D("hPtRecoTruth","",nBins,ptBins);
  TH1D* hPtMC = new TH1D("hPtMC","",nBins,ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",nBins,ptBins);

  TH1D* hMean = new TH1D("hMean","",nBins,ptBins);                       
  TH1D* hSigmaGaus1 = new TH1D("hSigmaGaus1","",nBins,ptBins); 
  TH1D* hSigmaGaus2 = new TH1D("hSigmaGaus2","",nBins,ptBins); 
  TH1D* hRelMagnGaus1Gaus2 = new TH1D("hRelMagnGaus1Gaus2","",nBins,ptBins); 
  
  for(int i=0;i<nBins;i++)
    {
      TF1* f = fit(nt,ntMC,ptBins[i],ptBins[i+1],isMC);
      double yield = f->Integral(minhisto,maxhisto)/binwidthmass;
      double yieldErr = f->Integral(minhisto,maxhisto)/binwidthmass*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
      hMean->SetBinContent(i+1,f->GetParameter(1));
      hMean->SetBinError(i+1,f->GetParError(1));
      hSigmaGaus1->SetBinContent(i+1,f->GetParameter(2));
      hSigmaGaus1->SetBinError(i+1,f->GetParError(2));
      hSigmaGaus2->SetBinContent(i+1,f->GetParameter(5));
      hSigmaGaus2->SetBinError(i+1,f->GetParError(5));
      hRelMagnGaus1Gaus2->SetBinContent(i+1,f->GetParameter(4));
      hRelMagnGaus1Gaus2->SetBinError(i+1,f->GetParError(4));
    }  

  ntMC->Project("hPtMC","Dpt",TCut(weight)*(TCut(selmc.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMC);
  ntMC->Project("hPtRecoTruth","Dpt",TCut(selmc.Data())&&"(Dgen==23333)");
  divideBinWidth(hPtRecoTruth);
  ntGen->Project("hPtGen","Gpt",TCut(weight)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);

  TCanvas* cPt =  new TCanvas("cPt","",600,600);
  cPt->SetLogy();
  hPt->SetXTitle("D^{0} p_{T} (GeV/c)");
  hPt->SetYTitle("Uncorrected dN(D^{0})/dp_{T}");
  hPt->Sumw2();
  hPt->Draw();
  if(isMC)
    {
      hPtMC->Draw("same hist");
      TLegend* legPt = myLegend(0.55,0.80,0.90,0.94);
      legPt->AddEntry(hPt,"Signal extraction","pl");
      legPt->AddEntry(hPtMC,"Matched reco","lf");
      legPt->Draw("same");  
    }
  hPtMC->Sumw2();
  TH1D* hEff = (TH1D*)hPtMC->Clone("hEff");
  hEff->SetTitle(";D^{0} p_{T} (GeV/c);Efficiency");
  hEff->Sumw2();
  hEff->Divide(hPtGen);
  TCanvas* cEff = new TCanvas("cEff","",600,600);
  hEff->Draw();
  
  TH1D* hPtCor = (TH1D*)hPt->Clone("hPtCor");
  hPtCor->SetTitle(";D^{0} p_{T} (GeV/c);Corrected dN(D^{0})/dp_{T}");
  hPtCor->Divide(hEff);
  TCanvas* cPtCor=  new TCanvas("cCorResult","",600,600);
  cPtCor->SetLogy();
  hPtCor->Draw();
  if(isMC)
    {
      hPtGen->Draw("same hist");
      TLegend* legPtCor = myLegend(0.55,0.80,0.90,0.94);
      legPtCor->AddEntry(hPtCor,"Corrected signal","pl");
      legPtCor->AddEntry(hPtGen,"Generated D^{0}","lf");
      legPtCor->Draw("same");  
    }

  TH1D* hPtSigma= (TH1D*)hPtCor->Clone("hPtSigma");
  hPtSigma->SetTitle(";D^{0} p_{T} (GeV/c);d#sigma(D^{0})/dp_{T} (pb/GeV)");
  hPtSigma->Scale(1./(2*luminosity*BRchain));
  TCanvas* cPtSigma=  new TCanvas("cPtSigma","",600,600);
  cPtSigma->SetLogy();
  hPtSigma->Draw();
  
  TFile* outf = new TFile(outputfile.Data(),"recreate");
  outf->cd();
  hPt->Write();
  hEff->Write();
  hPtGen->Write();
  hPtMC->Write();
  hPtCor->Write();
  hPtSigma->Write();
  hMean->Write();
  hSigmaGaus1->Write();
  hSigmaGaus2->Write();
  hRelMagnGaus1Gaus2->Write();
  outf->Close();
}
Beispiel #9
0
void weightPPFONLLpthat(int minfit=2,int maxfit=100,TString pthat="pthatall")
{
  TString label;
  //TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))";
  TString selmcgen="TMath::Abs(Gy)<2.4&&abs(GpdgId)==521&&GisSignal==1";
  TString myweightfunctiongen,myweightfunctionreco;
  
  //TCut weighpthat="pow(10,-0.075415*Gpt+1.748668+Gpt*Gpt*0.000388)+pow(10,-0.166406*Gpt+2.887856+Gpt*Gpt*0.000105) +0.003157";
  //TCut weighpthat="1";
  //TCut weighpthat="pthatweight*(pow(10,-0.107832+0.010248*Gpt+Gpt*Gpt*0.000079+Gpt*Gpt*Gpt*-0.000003+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))";//cross check
  TCut weighpthat="pthatweight";
  
  TCut weightCentrality="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)";

  gStyle->SetOptTitle(1);
  //gStyle->SetOptStat(111111);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  gStyle->SetEndErrorSize(0);
  gStyle->SetMarkerStyle(20);

  gStyle->SetStatX(0.9);
  gStyle->SetStatY(0.9);
  gStyle->SetStatW(0.30);
  gStyle->SetStatH(0.04);
  gStyle->SetStatFontSize(0.03); 
  //TFile*infMC=new TFile("/data/HeavyFlavourRun2/MC2015/Bntuple/PbPb/Bntuple20160816_Bpt7svpv5p5Bpt10svpv3p5_BfinderMC_PbPb_Pythia8_BuToJpsiK_Bpt0_Pthat5_TuneCUEP8M1_20160816_bPt5jpsiPt0tkPt0p8_Bp.root");
  TFile*infMC=new TFile("/data/HeavyFlavourRun2/MC2015/Bntuple/PbPb/Bntuple20160816_Bpt7svpv5p5Bpt10svpv3p5_BfinderMC_PbPb_Pythia8_BuToJpsiK_TuneCUEP8M1_20160816_bPt5jpsiPt0tkPt0p8_Bp_pthatweight.root");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree *ntHiMC = (TTree*)infMC->Get("ntHi");
  ntGen->AddFriend(ntHiMC);
  
  TH1D* hPtGenFONLL = new TH1D("hPtGenFONLL","",nBinsReweight,ptBinsReweight);
  ntGen->Project("hPtGenFONLL","Gpt",(TCut(weighpthat)*TCut(selmcgen.Data())));
  //ntGen->Project("hPtGenFONLL","Gpt",(TCut(weighpthat)*TCut(weightCentrality)*TCut(selmcgen.Data())));
  divideBinWidth(hPtGenFONLL);
    
  TString fonll="ROOTfiles/fonllOutput_pp_Bplus_5p03TeV_y2p4.root";
  TFile* filePPReference = new TFile(fonll.Data());  
  TGraphAsymmErrors* gaeBplusReference = (TGraphAsymmErrors*)filePPReference->Get("gaeSigmaBplus");

  TH1D* hFONLL = new TH1D("hFONLL","",nBinsReweight,ptBinsReweight);
  double x,y;
  for(int i=0;i<nBinsReweight;i++){
    gaeBplusReference->GetPoint(i,x,y);
    hFONLL->SetBinContent(i+1,y);
  }
  TH1D* hFONLLOverPt=(TH1D*)hFONLL->Clone("hFONLLOverPt");
  TH1D* hFONLLOverPtWeight=(TH1D*)hFONLL->Clone("hFONLLOverPtWeight");
  
  hFONLL->Sumw2();
  hPtGenFONLL->Sumw2();
  hFONLLOverPt->Sumw2();
  hFONLL->Scale(1/hFONLL->Integral());
  hFONLLOverPt->Scale(1/hFONLLOverPt->Integral());
  hPtGenFONLL->Scale(1/hPtGenFONLL->Integral());
  hFONLLOverPt->Divide(hPtGenFONLL);
  
  //TF1 *myfit = new TF1("myfit","pow(10,[0]+[1]*x+x*x*[2])+pow(10,[3]*x*x+[4]*x*x*x+x*[5])", 2, 100);
  TF1 *myfit = new TF1("myfit","pow(10,[0]+[1]*x+x*x*[2]+x*x*x*[3]+x*x*x*x*[4]+x*x*x*x*x*[5])",0, 100);  
  //TF1 *myfit = new TF1("myfit","pow(10,[0]+[1]*x+x*x*[2]+x*x*x*[3])",0, 100);  
  //TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]+x*x*x*x*[4]+x*x*x*x*x*[5]",0, 100);  
   
  TCanvas*c1=new TCanvas("c1","c1",1000.,600.);
  c1->cd();
  gPad->SetLogy();
  gStyle->SetOptStat(111111111);
  hFONLLOverPt->Fit("myfit","","",minfit,maxfit);
  hFONLLOverPt->Fit("myfit","L m","",minfit,maxfit);
  TLegend* leg0 = myLegend(0.13,0.83,0.40,0.89);
  leg0->AddEntry(hFONLLOverPt,"Pythia8 MC_2015 B^{+}","");
  leg0->Draw();
  TLegend* leg1 = myLegend(0.15,0.75,0.40,0.88);
  leg1->AddEntry(hFONLLOverPt,"PbPb #sqrt{s}= 5.02 TeV","");
  leg1->Draw();

  double par0=myfit->GetParameter(0);
  double par1=myfit->GetParameter(1);
  double par2=myfit->GetParameter(2);
  double par3=myfit->GetParameter(3);
  double par4=myfit->GetParameter(4);
  double par5=myfit->GetParameter(5);
  //double par6=myfit->GetParameter(6);

  //myweightfunctiongen=Form("pow(10,%f*Gpt+%f+Gpt*Gpt*%f)+pow(10,%f*Gpt+%f+Gpt*Gpt*%f)",par0,par1,par2,par3,par4,par5);
  //myweightfunctiongen=Form("%f+%f*x+x*x*%f+x*x*x*%f+x*x*x*x*%f+x*x*x*x*x*%f",par0,par1,par2,par3,par4,par5);
  myweightfunctiongen=Form("pow(10,%f+%f*x+x*x*%f+x*x*x*%f+x*x*x*x*%f+x*x*x*x*x*%f)",par0,par1,par2,par3,par4,par5);
  std::cout<<"myweightfunctiongen="<<myweightfunctiongen<<std::endl;

  //myweightfunctionreco=Form("pow(10,%f*Gpt+%f+Gpt*Gpt*%f)+pow(10,%f*Gpt+%f+Gpt*Gpt*%f)",par0,par1,par2,par3,par4,par5);
  //std::cout<<"myweightfunctionreco="<<myweightfunctionreco<<std::endl;
  //std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl;

  TCanvas*canvasPtReweight=new TCanvas("canvasPtReweight","canvasPtReweight_PbPb_MC_B+",1253.,494.); 
  canvasPtReweight->Divide(3,1);
  canvasPtReweight->cd(1);
  gPad->SetLogy();
  gPad->SetLeftMargin(0.15);
  hPtGenFONLL->SetXTitle("Gen p_{T}(GeV)");
  hPtGenFONLL->SetYTitle("PYTHIA, #entries");
  hPtGenFONLL->SetMinimum(1e-4);  
  hPtGenFONLL->SetMaximum(1e2);  
  hPtGenFONLL->GetYaxis()->SetTitleOffset(1.2);
  hPtGenFONLL->Draw();
  canvasPtReweight->cd(2);
  gPad->SetLogy();
  gPad->SetLeftMargin(0.15);
  hFONLL->SetXTitle("Gen, p_{T}(GeV)");
  hFONLL->SetYTitle("FONLL_PbPb, #entries");
  hFONLL->SetMinimum(1e-4);  
  hFONLL->SetMaximum(1e2);  
  hFONLL->GetYaxis()->SetTitleOffset(1.2);
  hFONLL->GetYaxis()->CenterTitle();
  hFONLL->GetXaxis()->CenterTitle();
  hFONLL->Draw();
  canvasPtReweight->cd(3);
  gPad->SetLogy();
  gPad->SetLeftMargin(0.15);
  hFONLLOverPt->SetXTitle("Gen p_{T}(GeV)");
  hFONLLOverPt->SetYTitle("FONLL_PbPb/PYTHIA ");
  hFONLLOverPt->SetMinimum(0.01);  
  hFONLLOverPt->SetMaximum(10.);  
  hFONLLOverPt->GetYaxis()->SetTitleOffset(1.2);
  hFONLLOverPt->GetYaxis()->CenterTitle();
  hFONLLOverPt->GetXaxis()->CenterTitle();
  hFONLLOverPt->Draw();
  canvasPtReweight->SaveAs("Reweightplots/canvasPtReweightPbPb.pdf");
}
Beispiel #10
0
void fitB_extend(bool ispPb=true,TString infname="",bool doweight = 1)
{

  
  if(ispPb==true){
  
    inputdata="/afs/cern.ch/work/w/wangj/public/nt_20140727_PAMuon_HIRun2013_Merged_y24_Using03090319Bfinder.root";
    inputmc="/afs/cern.ch/work/w/wangj/public/nt_20140801_mixed_fromQMBFinder_Kp.root";
    luminosity=34.6*1e-3;
    outputname="../ResultsBplus/SigmaBplus_extend.root";
    cut="abs(y)<2.4&&(HLT_PAMu3_v1)&&abs(mumumass-3.096916)<0.15&&mass>5&&mass<6&& isbestchi2&&trk1Pt>0.9&&chi2cl>1.32e-02&&(d0/d0Err)>3.41&&cos(dtheta)>-3.46e01&&mu1pt>1.5&&mu2pt>1.5";

  }
  else{
  
    //inputdata="/data/bmeson/data//nt_20141022_PPMuon_Run2013A_PromptReco_v1_resub20141126.root";
    //inputmc="/afs/cern.ch/work/w/wangj/public/nt_20140801_mixed_fromQMBFinder_Kp.root";
    inputdata="/data/bmeson/data/nt_20141022_PPMuon_Run2013A_PromptReco_v1_resub20141126_HLT_PAL1DoubleMu0_HighQ_v1.root";
    inputmc="/data/bmeson/MC/nt_2015251_PYTHIA6_BuJpsiK_pp_PAL1DoubleMu0_HighQ_v1.root";

    luminosity=5400*1e-3;
    outputname="../ResultsBplus_pp/SigmaBplus_extend.root";
    cut="abs(y)<2.4&&(HLT_PAL1DoubleMu0_HighQ_v1)&&abs(mumumass-3.096916)<0.15&&mass>5&&mass<6&& isbestchi2&&trk1Pt>0.9&&chi2cl>1.32e-02&&(d0/d0Err)>3.41&&cos(dtheta)>-3.46e01&&mu1pt>1.5&&mu2pt>1.5";
  }
  
  seldata_2y=Form("%s",cut.Data());
  selmc=Form("abs(y)<2.4&&gen==23333&&%s",cut.Data());
  selmcgen="abs(y)<2.4&&abs(pdgId)==521&&isSignal==1";

  if (doweight==0) weight="1";
  if (infname=="") infname=inputdata.Data();
  TFile *inf = new TFile(infname.Data());
  TTree *nt = (TTree*) inf->Get("ntKp");

  TFile *infMC = new TFile(inputmc.Data());
  TTree *ntGen = (TTree*)infMC->Get("ntGen");
  TTree *ntGen2 = (TTree*)inf->Get("ntGen");
  TTree *ntMC = (TTree*)infMC->Get("ntKp");
    
  ntGen->AddFriend(ntMC);
  ntGen2->AddFriend(ntMC);
    
  const int nBins = 5;
  double ptBins[nBins+1] = {10,15,20,25,30,60};
  //const int nBins = 1;
  //double ptBins[nBins+1] = {10,60};
  TH1D *hPt = new TH1D("hPt","",nBins,ptBins);
  TH1D *hPtRecoTruth = new TH1D("hPtRecoTruth","",nBins,ptBins);
  TH1D *hGenPtSelected = new TH1D("hGenPtSelected","",nBins,ptBins);
  TH1D *hPtMC = new TH1D("hPtMC","",nBins,ptBins);
  TH1D *hPtGen = new TH1D("hPtGen","",nBins,ptBins);
  TH1D *hPtGen2 = new TH1D("hPtGen2","",nBins,ptBins);

  TFile *outf = new TFile(outputname.Data(),"recreate");

  for (int i=0;i<nBins+1;i++)
    {
      if (i==nBins) {fit(nt,ntMC,10,60,ispPb,i);continue;}
      TF1 *f = fit(nt,ntMC,ptBins[i],ptBins[i+1],ispPb,i);
      double yield = f->Integral(5,6)/0.02;
      double yieldErr = f->Integral(5,6)/0.02*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
    }  

  TCanvas *c=  new TCanvas("cResult","",600,600);
  hPt->SetXTitle("B^{+} p_{T} (GeV/c)");
  hPt->SetYTitle("Uncorrected B^{+} dN/dp_{T}");
  hPt->Sumw2();
  hPt->Draw();
  
  ntMC->Project("hPtMC","pt",TCut(weight)*(TCut(selmc.Data())&&"gen==23333"));
  nt->Project("hPtRecoTruth","pt",TCut(seldata_2y.Data())&&"gen==23333");
  ntGen->Project("hPtGen","pt",TCut(weight)*(TCut(selmcgen.Data())));
  ntGen2->Project("hPtGen2","pt",(TCut(selmcgen.Data())));
  divideBinWidth(hPtRecoTruth);
  
  hPtRecoTruth->Draw("same hist");
  divideBinWidth(hPtMC);
  divideBinWidth(hPtGen);
  divideBinWidth(hPtGen2);
  
  hPtMC->Sumw2();
  TH1D *hEff = (TH1D*)hPtMC->Clone("hEff");
  hPtMC->Sumw2();
  hEff->Divide(hPtGen);
  
  TH1D *hPtCor = (TH1D*)hPt->Clone("hPtCor");
  hPtCor->Divide(hEff);
  TCanvas *cCor=  new TCanvas("cCorResult","",600,600);
  hPtCor->SetYTitle("Corrected B^{+} dN/dp_{T}");
  hPtCor->Draw();
  hPtGen->Draw("same hist");
  hPtGen2->Draw("same hist");

  TH1D *hPtSigma= (TH1D*)hPtCor->Clone("hPtSigma");
  double BRchain=6.09604e-5;

  hPtSigma->Scale(1./(2*luminosity*BRchain));
  hPtSigma->SetYTitle("d#sigma (B^{+})/dp_{T}");

  TCanvas *cSigma=  new TCanvas("cSigma","",600,600);

  hPtSigma->Draw();
  
  outf->cd();
  hPt->Write();
  hEff->Write();
  hPtGen->Write();
  hPtCor->Write();
  hPtSigma->Write();
  outf->Close();
  delete outf;
}
void fitDVariable(TString variable="DsvpvDistance/DsvpvDisErr",TString variableplot="d_{xy}/#sigma(d_{xy})", TString inputdata="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi/ntD_EvtBase_20160203_Dfinder_20160201_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi/ntD_EvtBase_20160203_Dfinder_20160201_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString trgselection="1",  TString cut="Dpt>20&&Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))", int isMC=1, Double_t luminosity=26., int doweight=0, TString collsyst="PbPb", TString outputfile="mytest.root")
{
  collisionsystem=collsyst;
  seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
  selmc = Form("%s",cut.Data());

  gStyle->SetTextSize(0.05);
  gStyle->SetTextFont(42);
  gStyle->SetPadRightMargin(0.043);
  gStyle->SetPadLeftMargin(0.18);
  gStyle->SetPadTopMargin(0.1);
  gStyle->SetPadBottomMargin(0.145);
  gStyle->SetTitleX(.0f);

  void clean0 (TH1D* h);
  TF1* fit (TString variable, TString variableplot, TTree* nt, TTree* ntMC, double ptmin, double ptmax, int isMC);

  if(!doweight) weight="1";
  TFile* inf = new TFile(inputdata.Data());
  TFile* infMC = new TFile(inputmc.Data());

  TTree* nt = (TTree*) inf->Get("ntDkpi");
  TTree* HltTree= (TTree*) inf->Get("ntHlt");
  HltTree->AddFriend(nt);
  nt->AddFriend(HltTree);
  TTree* ntHid = (TTree*) inf->Get("ntHi");
  nt->AddFriend(ntHid);
  
  TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree* ntHi = (TTree*)infMC->Get("ntHi");
  
  ntGen->AddFriend(ntMC);
  ntGen->AddFriend(ntHi);
  ntMC->AddFriend(ntGen);
  ntMC->AddFriend(ntHi);
  ntHi->AddFriend(ntMC);
  
  TH1D* hPt = new TH1D("hPt","",nBins,ptBins);
  TH1D* hPtRecoTruth = new TH1D("hPtRecoTruth","",nBins,ptBins);
  TH1D* hPtMC = new TH1D("hPtMC","",nBins,ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",nBins,ptBins);

  TH1D* hMean = new TH1D("hMean","",nBins,ptBins);                       
  TH1D* hSigmaGaus1 = new TH1D("hSigmaGaus1","",nBins,ptBins); 
  TH1D* hSigmaGaus2 = new TH1D("hSigmaGaus2","",nBins,ptBins); 
  TH1D* hRelMagnGaus1Gaus2 = new TH1D("hRelMagnGaus1Gaus2","",nBins,ptBins); 
  
  for(int i=0;i<nBins;i++)
    {
      TF1* f = fit(variable,variableplot,nt,ntMC,ptBins[i],ptBins[i+1],isMC);
      double yield = f->Integral(minhisto,maxhisto)/binwidthmass;
      double yieldErr = f->Integral(minhisto,maxhisto)/binwidthmass*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
      hMean->SetBinContent(i+1,f->GetParameter(1));
      hMean->SetBinError(i+1,f->GetParError(1));
      hSigmaGaus1->SetBinContent(i+1,f->GetParameter(2));
      hSigmaGaus1->SetBinError(i+1,f->GetParError(2));
      hSigmaGaus2->SetBinContent(i+1,f->GetParameter(5));
      hSigmaGaus2->SetBinError(i+1,f->GetParError(5));
      hRelMagnGaus1Gaus2->SetBinContent(i+1,f->GetParameter(4));
      hRelMagnGaus1Gaus2->SetBinError(i+1,f->GetParError(4));
    }  

  ntMC->Project("hPtMC",variable.Data(),TCut(weight)*(TCut(selmc.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMC);
  ntMC->Project("hPtRecoTruth",variable.Data(),TCut(selmc.Data())&&"(Dgen==23333)");
  divideBinWidth(hPtRecoTruth);
  ntGen->Project("hPtGen","Gpt",TCut(weight)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);

  TCanvas* cPt =  new TCanvas("cPt","",600,600);
  cPt->SetLogy();
  hPt->SetXTitle(Form("D^{0} %s",variable.Data()));
  hPt->SetYTitle("Uncorrected dN(D^{0})/dp_{T}");
  hPt->Sumw2();
  hPt->Draw();
  if(isMC)
    {
      hPtMC->Draw("same hist");
      TLegend* legPt = myLegend(0.55,0.80,0.90,0.94);
      legPt->AddEntry(hPt,"Signal extraction","pl");
      legPt->AddEntry(hPtMC,"Matched reco","lf");
      legPt->Draw("same");  
    }
  hPtMC->Sumw2();
  TH1D* hEff = (TH1D*)hPtMC->Clone("hEff");
  hEff->SetTitle(Form(";D^{0} %s",variable.Data()));
  hEff->Sumw2();
  hEff->Divide(hPtGen);
  TCanvas* cEff = new TCanvas("cEff","",600,600);
  hEff->Draw();
  
  TH1D* hPtCor = (TH1D*)hPt->Clone("hPtCor");
  hPtCor->SetTitle(Form(";D^{0} %s;Corrected dN(D^{0})/dp_{T}",variable.Data()));
  hPtCor->Divide(hEff);
  TCanvas* cPtCor=  new TCanvas("cCorResult","",600,600);
  cPtCor->SetLogy();
  hPtCor->Draw();
  if(isMC)
    {
      hPtGen->Draw("same hist");
      TLegend* legPtCor = myLegend(0.55,0.80,0.90,0.94);
      legPtCor->AddEntry(hPtCor,"Corrected signal","pl");
      legPtCor->AddEntry(hPtGen,"Generated D^{0}","lf");
      legPtCor->Draw("same");  
    }

  TH1D* hPtSigma= (TH1D*)hPtCor->Clone("hPtSigma");
  hPtSigma->SetTitle(Form(";D^{0} %s;d#sigma(D^{0})/d%s (pb/{units})",variable.Data(),variable.Data()));
  hPtSigma->Scale(1./(2*luminosity*BRchain));
  TCanvas* cPtSigma=  new TCanvas("cPtSigma","",600,600);
  cPtSigma->SetLogy();
  hPtSigma->Draw();
  
  TFile* outf = new TFile(outputfile.Data(),"recreate");
  outf->cd();
  hPt->Write();
  hEff->Write();
  hPtGen->Write();
  hPtMC->Write();
  hPtCor->Write();
  hPtSigma->Write();
  hMean->Write();
  hSigmaGaus1->Write();
  hSigmaGaus2->Write();
  hRelMagnGaus1Gaus2->Write();
  outf->Close();
}
void Fit_dNdpt_phibins_in_oneptbin( int ipt, TH1D * dNdpt_phibins_in_oneptbin, TH1D * vn_morephibin, TString trigname, TString vnname, int cent_low, int cent_high, TString fitoption, bool effcorrected)
{
	divideBinWidth( dNdpt_phibins_in_oneptbin );
	double phirange = -999;
	if( vnname == "v2" )  phirange = PI/2.;
	else if( vnname == "v3" ) phirange = PI/3.;

	TCanvas * cfg = new TCanvas(Form("cfg_fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), Form("cfg_fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), 600, 600);
	cfg->SetLeftMargin(0.20);

	TF1 * fit_dNdpt_phibins_in_oneptbin = NULL;
	if( vnname == "v2" ) 
		fit_dNdpt_phibins_in_oneptbin = new TF1( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "[0] * (1.0 + 2.0 * [1] * cos( 2.0 * x ) )", 0, phirange);
	else if( vnname == "v3" )
		fit_dNdpt_phibins_in_oneptbin = new TF1( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "[0] * (1.0 + 2.0 * [1] * cos( 3.0 * x ) )", 0, phirange);

	fit_dNdpt_phibins_in_oneptbin->SetLineColor(2.0);
	fit_dNdpt_phibins_in_oneptbin->SetLineStyle(2);

	dNdpt_phibins_in_oneptbin->Fit( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "I q", "", 0, phirange);
	dNdpt_phibins_in_oneptbin->Fit( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "I q", "", 0, phirange);
	dNdpt_phibins_in_oneptbin->Fit( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "I q", "", 0, phirange);
	dNdpt_phibins_in_oneptbin->Fit( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "I q m", "", 0, phirange);
	dNdpt_phibins_in_oneptbin->Fit( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "I q m", "", 0, phirange);
	dNdpt_phibins_in_oneptbin->Fit( Form("fit_dNdpt_phibins_in_oneptbin_%s_%d", (trigname+vnname).Data(), ipt), "I m", "", 0, phirange);

	dNdpt_phibins_in_oneptbin->GetXaxis()->SetTitle("#Delta#Phi");
	dNdpt_phibins_in_oneptbin->GetYaxis()->SetTitle("#frac{d^{2}N}{dp_{T}d#Delta#Phi}");
	dNdpt_phibins_in_oneptbin->GetYaxis()->SetTitleOffset(2.0);

	vn_morephibin->SetBinContent( ipt+1, fit_dNdpt_phibins_in_oneptbin->GetParameter(1));
	vn_morephibin->SetBinError( ipt+1, fit_dNdpt_phibins_in_oneptbin->GetParError(1));

    TLatex Tl; 
    Tl.SetNDC();
    Tl.SetTextAlign(12);
    Tl.SetTextSize(0.05);
    Tl.SetTextFont(42);
    Tl.DrawLatex(0.20,0.965, "#font[61]{CMS} #scale[0.8]{Preliminary}");
    Tl.DrawLatex(0.57,0.965, "#scale[0.8]{PbPb #sqrt{s_{NN}} = 5.02 TeV}");

	TLatex* tex;
	tex = new TLatex(0.55,0.83,"|y| < 1.0");
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
	tex->Draw();

	tex = new TLatex(0.55,0.78,Form("Cent. %d-%d%%", cent_low, cent_high));
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
	tex->Draw();

	float ptmin = ptbins[ipt];
	float ptmax = ptbins[ipt+1];

	tex = new TLatex(0.55,0.73,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
	tex->Draw();

	if( vnname == "v2" ) 
		tex = new TLatex(0.55,0.68,Form("v_{2}^{obs} = %.3f #pm %.3f",fit_dNdpt_phibins_in_oneptbin->GetParameter(1), fit_dNdpt_phibins_in_oneptbin->GetParError(1)));
	else if( vnname == "v3" )
		tex = new TLatex(0.55,0.68,Form("v_{3}^{obs} = %.3f #pm %.3f",fit_dNdpt_phibins_in_oneptbin->GetParameter(1), fit_dNdpt_phibins_in_oneptbin->GetParError(1)));

	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
	tex->Draw();

	float fitchi2 = fit_dNdpt_phibins_in_oneptbin->GetChisquare();
    int NDFfit = fit_dNdpt_phibins_in_oneptbin->GetNDF();

    tex = new TLatex(0.55,0.63,Form("#chi^{2}#/NDF: %.1f/%d", fitchi2, NDFfit));
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetTextSize(0.04);
	tex->SetLineWidth(2);
//	tex->Draw();
	
	cfg->SaveAs(Form("Plots_vn/fitmorephibin/cfg_bkg_fit_dNdpt_phibins_in_oneptbin_%s_cent%dto%d_%d_%s_effcorrected%d.pdf", (trigname+vnname).Data(), cent_low, cent_high, ipt, fitoption.Data(), effcorrected));
}
Beispiel #13
0
void fitB(bool isData,int myvariationoption)
{
  TString infname;
  if(isData)infname=inputdata.Data();
  if(!isData)infname=inputmc.Data();
  
  if(!isData)seldata_2y=seldata;
  
  TFile *inf = new TFile(infname.Data());
  TTree *nt = (TTree*) inf->Get("ntKp");

  TFile *infMC = new TFile(inputmc.Data());
  TTree *ntGen = (TTree*)infMC->Get("ntGen");
  TTree *ntMC = (TTree*)infMC->Get("ntKp");
    
  const int nBins = 1;
  double ptBins[nBins+1] = {10,60};
  TH1D *hPt = new TH1D("hPt","",nBins,ptBins);
  TH1D *hPtRecoTruth = new TH1D("hPtRecoTruth","",nBins,ptBins);
  TH1D *hGenPtSelected = new TH1D("hGenPtSelected","",nBins,ptBins);
  TH1D *hPtMC = new TH1D("hPtMC","",nBins,ptBins);
  TH1D *hPtGen = new TH1D("hPtGen","",nBins,ptBins);

  for (int i=0;i<nBins;i++)
    {
      TF1 *f = fit(nt,ntMC,ptBins[i],ptBins[i+1],isData,myvariationoption);
      double yield = f->Integral(5,6)/0.02;
      double yieldErr = f->Integral(5,6)/0.02*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
    }  
  
  TCanvas *c=  new TCanvas("cResult","",600,600);
  hPt->SetXTitle("B^{+} p_{T} (GeV/c)");
  hPt->SetYTitle("Uncorrected B^{+} dN/dp_{T}");
  hPt->Sumw2();
  hPt->Draw();
  
  ntMC->Project("hPtMC","pt",TCut(weight)*(TCut(selmc.Data())&&"gen==23333"));
  nt->Project("hPtRecoTruth","pt",TCut(seldata.Data())&&"gen==23333");
  ntGen->Project("hPtGen","pt",TCut(weight)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtRecoTruth);
  
  hPtRecoTruth->Draw("same hist");
  divideBinWidth(hPtMC);
  divideBinWidth(hPtGen);
  
  hPtMC->Sumw2();
  TH1D *hEff = (TH1D*)hPtMC->Clone("hEff");
  hPtMC->Sumw2();
  hEff->Divide(hPtGen);
  
  TH1D *hPtCor = (TH1D*)hPt->Clone("hPtCor");
  hPtCor->Divide(hEff);
  TCanvas *cCor=  new TCanvas("cCorResult","",600,600);
  hPtCor->SetYTitle("Corrected B^{+} dN/dp_{T}");
  hPtCor->Draw();
  hPtGen->Draw("same hist");

  TH1D *hPtSigma= (TH1D*)hPtCor->Clone("hPtSigma");
  hPtSigma->Scale(1./(2*luminosity));
  hPtSigma->SetYTitle("d#sigma (B^{+})/dp_{T}");

  TCanvas *cSigma=  new TCanvas("cSigma","",600,600);

  hPtSigma->Draw(); 
  
  TFile *outf = new TFile(Form("Results/CutId%d/SigmaBplusCutId%d_isData%d.root",myvariationoption,myvariationoption,isData),"recreate");
  outf->cd();
  hPt->Write();
  hEff->Write();
  hPtGen->Write();
  hPtCor->Write();
  hPtSigma->Write();
  outf->Close();
  delete outf;
}
void studydoubleratio(Bool_t doweight=true)
{
  gStyle->SetTextSize(0.05);
  gStyle->SetTextFont(42);
  gStyle->SetPadRightMargin(0.043);
  gStyle->SetPadLeftMargin(0.18);
  gStyle->SetPadTopMargin(0.1);
  gStyle->SetPadBottomMargin(0.145);
  gStyle->SetTitleX(.0f);

  void clean0 (TH1D* h);  
  TF1* fitDstar3prongs (TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax);
  TF1* fitDstar5prongs (TTree* nt, Double_t ptmin, Double_t ptmax);

  TFile* infData3prong = new TFile(infnameData3p[isData].Data());
  TFile* infData5prong = new TFile(infnameData5p[isData].Data());
  TFile* infMC3prong = new TFile(infnameMC3p[isData].Data());
  TFile* infMC5prong = new TFile(infnameMC5p[isData].Data());

  TTree* ntData3prong = (TTree*)infData3prong->Get("ntDD0kpipi");
  TTree* ntData5prong = (TTree*)infData5prong->Get("ntDD0kpipipipi");
  TTree* ntMC3prong = (TTree*)infMC3prong->Get("ntDD0kpipi");
  TTree* ntMC5prong = (TTree*)infMC5prong->Get("ntDD0kpipipipi");
  TTree* ntGen3prong = (TTree*)infMC3prong->Get("ntGen");
  TTree* ntGen5prong = (TTree*)infMC5prong->Get("ntGen");
  
  TTree* HltTreeData3prong = (TTree*)infData3prong->Get("ntHlt");
  TTree* HltTreeData5prong = (TTree*)infData5prong->Get("ntHlt");
  ntData3prong->AddFriend(HltTreeData3prong);
  ntData5prong->AddFriend(HltTreeData5prong);
  TTree* HltTreeMC3prong = (TTree*)infMC3prong->Get("ntHlt");
  TTree* HltTreeMC5prong = (TTree*)infMC5prong->Get("ntHlt");
  ntMC3prong->AddFriend(HltTreeMC3prong);
  ntMC5prong->AddFriend(HltTreeMC5prong);
  ntGen3prong->AddFriend(HltTreeMC3prong);
  ntGen5prong->AddFriend(HltTreeMC5prong);

  TH1D* hPt3prong = new TH1D("hPt3prong","",nBins,ptBins);
  TH1D* hPt5prong = new TH1D("hPt5prong","",nBins,ptBins);  
  hPt3prong->Sumw2();
  hPt5prong->Sumw2();
  TH1D* hPtMC3prong = new TH1D("hPtMC3prong","",nBins,ptBins);
  TH1D* hPtMC5prong = new TH1D("hPtMC5prong","",nBins,ptBins);
  hPtMC3prong->Sumw2();
  hPtMC5prong->Sumw2();
  TH1D* hPtGen3prong = new TH1D("hPtGen3prong","",nBins,ptBins);
  TH1D* hPtGen5prong = new TH1D("hPtGen5prong","",nBins,ptBins);
  hPtGen3prong->Sumw2();
  hPtGen5prong->Sumw2();

  for(int i=0;i<nBins;i++)
    {
      TF1* fData3prong = fitDstar3prongs(ntData3prong,ntMC3prong, ptBins[i],ptBins[i+1]);
      TF1* fData5prong = fitDstar5prongs(ntData5prong,ptBins[i],ptBins[i+1]);
      Double_t yieldData3prong = fData3prong->Integral(minmass3prong,maxmass3prong)/binwidth3prong;
      Double_t yieldData3prongErr = fData3prong->Integral(minmass3prong,maxmass3prong)/binwidth3prong*fData3prong->GetParError(0)/fData3prong->GetParameter(0);
      Double_t yieldData5prong = fData5prong->Integral(minmass5prong,maxmass5prong)/binwidth5prong;
      Double_t yieldData5prongErr = fData5prong->Integral(minmass5prong,maxmass5prong)/binwidth5prong*fData5prong->GetParError(0)/fData5prong->GetParameter(0);
      
      hPt3prong->SetBinContent(i+1,yieldData3prong/(ptBins[i+1]-ptBins[i]));
      hPt3prong->SetBinError(i+1,yieldData3prongErr/(ptBins[i+1]-ptBins[i]));
      hPt5prong->SetBinContent(i+1,yieldData5prong/(ptBins[i+1]-ptBins[i]));
      hPt5prong->SetBinError(i+1,yieldData5prongErr/(ptBins[i+1]-ptBins[i]));
    }
  ntMC3prong->Project("hPtMC3prong","Dpt",Form("%s&&%s",selmc3p.Data(),triggerselection[isData].Data()));
  divideBinWidth(hPtMC3prong);
  ntGen3prong->Project("hPtGen3prong","Gpt",Form("%s&&%s",selgen3p.Data(),triggerselection[isData].Data()));
  divideBinWidth(hPtGen3prong);  
  ntMC5prong->Project("hPtMC5prong","Dpt",Form("%s&&%s",selmc5p.Data(),triggerselection[isData].Data()));
  divideBinWidth(hPtMC5prong);
  ntGen5prong->Project("hPtGen5prong","Gpt",Form("%s&&%s",selgen5p.Data(),triggerselection[isData].Data()));
  divideBinWidth(hPtGen5prong);  

  TCanvas* cPt3prong =  new TCanvas("cPt3prong","",600,600);
  cPt3prong->SetLogy();
  hPt3prong->SetXTitle("D p_{T} (GeV/c)");
  hPt3prong->SetYTitle(Form("%s Uncorrected 3-prong N(D*)/dp_{T}",texData[isData].Data()));
  hPt3prong->Draw();
  cPt3prong->SaveAs(Form("plots/pp/c_%s_Pt3prong.pdf",texData[isData].Data()));
  hPt3prong->Scale(scaleMC3p[isData]);
  TCanvas* cPt5prong =  new TCanvas("cPt5prong","",600,600);
  cPt5prong->SetLogy();
  hPt5prong->SetXTitle("D p_{T} (GeV/c)");
  hPt5prong->SetYTitle(Form("%s Uncorrected 5-prong N(D*)/dp_{T}",texData[isData].Data()));
  hPt5prong->Draw();
  cPt5prong->SaveAs(Form("plots/pp/c_%s_Pt5prong.pdf",texData[isData].Data()));
  hPt5prong->Scale(scaleMC5p[isData]);
  TH1D* hRatio = (TH1D*)hPt5prong->Clone("hRatio");
  hRatio->SetTitle(Form(";D p_{T} (GeV/c);%s Raw dN(D*)/dp_{T} 5/3 prong Ratio",texData[isData].Data()));
  hRatio->Divide(hPt3prong);
  TCanvas* cRatio = new TCanvas("cRatio","",600,600);
  hRatio->Draw();
  cRatio->SaveAs(Form("plots/pp/c_%s_Ratio.pdf",texData[isData].Data()));

  TH1D* hEff3prong = (TH1D*)hPtMC3prong->Clone("hEff3prong");
  hEff3prong->SetTitle(Form(";D p_{T} (GeV/c);%s 3-prong Efficiency",texData[isData].Data()));
  hEff3prong->Divide(hPtGen3prong);
  TCanvas* cEff3prong = new TCanvas("cEff3prong","",600,600);
  hEff3prong->Draw();
  cEff3prong->SaveAs("plots/pp/cEff3prong.pdf");
  TH1D* hEff5prong = (TH1D*)hPtMC5prong->Clone("hEff5prong");
  hEff5prong->SetTitle(Form(";D p_{T} (GeV/c);%s 5-prong Efficiency",texData[isData].Data()));
  hEff5prong->Divide(hPtGen5prong);
  TCanvas* cEff5prong = new TCanvas("cEff5prong","",600,600);
  hEff5prong->Draw();
  cEff5prong->SaveAs("plots/pp/cEff5prong.pdf");
  
  TH1D* hPtCor3prong = (TH1D*)hPt3prong->Clone("hPtCor3prong");
  hPtCor3prong->SetTitle(Form(";D p_{T} (GeV/c);%s Corrected 3-prong dN(D*)/dp_{T}",texData[isData].Data()));
  hPtCor3prong->Divide(hEff3prong);
  TCanvas* cPtCor3prong = new TCanvas("cCor3prong","",600,600);
  cPtCor3prong->SetLogy();
  hPtCor3prong->Draw();
  if(isData==0||isData==2)
    {
      hPtGen3prong->SetLineColor(kRed);
      hPtGen3prong->Draw("same hist");
      TLegend* legPtCor3prong = myLegend(0.55,0.70,0.90,0.84);
      legPtCor3prong->AddEntry(hPtCor3prong,"Corrected signal","pl");
      legPtCor3prong->AddEntry(hPtGen3prong,"Generated D*","lf");
      legPtCor3prong->Draw("same");
    }
  cPtCor3prong->SaveAs(Form("plots/pp/c_%s_PtCor3prong.pdf",texData[isData].Data()));
  TH1D* hPtCor5prong = (TH1D*)hPt5prong->Clone("hPtCor3prong");
  hPtCor5prong->SetTitle(Form(";D p_{T} (GeV/c);%s Corrected 5-prong dN(D*)/dp_{T}",texData[isData].Data()));
  hPtCor5prong->Divide(hEff5prong);
  TCanvas* cPtCor5prong = new TCanvas("cCor5prong","",600,600);
  cPtCor5prong->SetLogy();
  hPtCor5prong->SetMinimum(hPtGen5prong->GetMinimum()*0.1);
  hPtCor5prong->Draw();
  if(isData==0||isData==2)
    {
      hPtGen5prong->SetLineColor(kRed);
      hPtGen5prong->Draw("same hist");
      TLegend* legPtCor5prong = myLegend(0.55,0.70,0.90,0.84);
      legPtCor5prong->AddEntry(hPtCor5prong,"Corrected signal","pl");
      legPtCor5prong->AddEntry(hPtGen5prong,"Generated D*","lf");
      legPtCor5prong->Draw("same");
    }
  cPtCor5prong->SaveAs(Form("plots/pp/c_%s_PtCor5prong.pdf",texData[isData].Data()));
  TH1D* hRatioCor = (TH1D*)hPtCor5prong->Clone("hRatioCor");
  hRatioCor->SetTitle(Form(";D p_{T} (GeV/c);%s Corrected dN(D*)/dp_{T} 5/3 prong Ratio",texData[isData].Data()));
  hRatioCor->Divide(hPtCor3prong);
  TCanvas* cRatioCor = new TCanvas("cRatioCor","",600,600);
  hRatioCor->Draw();
  cRatioCor->SaveAs(Form("plots/pp/c_%s_RatioCor.pdf",texData[isData].Data()));

  TFile *outputfile=new TFile(outputfilename.Data(),"recreate");
  outputfile->cd();
  hPt3prong->Write();
  hPt5prong->Write();
  hRatio->Write();
  outputfile->Close();
}
Beispiel #15
0
void RAA_dataDrivenUnfoldingErrorCheck_new(int radius = 3, bool isATLASCut = true)
{

  TStopwatch timer; 
  timer.Start();
  
  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();
  
  bool printDebug = true;
  bool dofakeremove = false;
  bool do10GeVBins = true;

  char * scale = (char*)"NeqScale";
  // 944Scale
  // NeqScale
  // NeqScalePerCent
  
  int unfoldingCut = 20;
  char * outLocation = (char*) "July20/";
  if(isATLASCut) outLocation = (char*)"July20/ATLASCut/";
  
  // get the data and mc histograms from the output of the read macro. 
  
  TDatime date;//this is just here to get them to run optimized. 

  // Pawan's files:
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_muMaxOverSumcandMaxLT0p975_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_trkMaxOverpfptGT0p02_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_noPrescl_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_noPrescl_MC_subid0_spectra_JetID_CutA_7GeVTrackCut_finebinscut_%s_R0p%d.root", etaWidth, radius));
  // get the files to perform MC closure from the fixed ntuples
  TFile * fPbPb_in, *fMinBias, *fPbPb_MC_in, * fTrig;
  
  if(isATLASCut) fPbPb_in    = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_histograms_FromForest_trkMax7OrNeMax8GeVCut_akPu%d_20_eta_20.root",radius),"r");
  if(!isATLASCut) fPbPb_in    = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_histograms_FromForest_akPu%d_20_eta_20.root",radius),"r");
  if(isATLASCut) fMinBias    = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MB_Data_histograms_FromForest_trkMax7OrNeMax8GeVCut_fix_pt15GeVCut_akPu%d_20_eta_20.root",radius));
  if(!isATLASCut) fMinBias    = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MB_Data_histograms_FromForest_fix_pt15GeVCut_akPu%d_20_eta_20.root",radius));
  //TFile * fPbPb_MC_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_pthat50andabove_akPu%d_20_eta_20.root",radius));
  if(isATLASCut) fPbPb_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_trkMax7OrNeMax8GeVCut_akPu%d_20_eta_20.root",radius),"r");
  if(!isATLASCut) fPbPb_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_akPu%d_20_eta_20.root",radius),"r");
  TFile * fPP_in      = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_Data_histograms_FromForest_ak%d_20_eta_20.root",radius),"r");
  TFile * fPP_MC_in   = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_MC_histograms_FromForest_ak%d_20_eta_20.root",radius),"r");
  if(isATLASCut) fTrig       = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_nofkSub_trkMax7OrNeMax8GeVCut_new_MC_turnonCurves_R%d_20_eta_20_20150715.root",radius),"r");
  if(!isATLASCut) fTrig       = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_nofkSub_new_MC_turnonCurves_R%d_20_eta_20_20150715.root",radius),"r");
  TFile * fTrig_pp = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_MC_turnonCurves_R%d_20_eta_20_20150702.root", radius),"r");
  // TFile * fPPMCTrig = new TFile(Form("PP_Data_MC_turnonCurves_R%d_20_eta_20_20150618.root",radius),"r");

  TH1F * hMC_turnon[nbins_cent+1], * hData_turnon[nbins_cent+1];
  cout<<"after input file declaration"<<endl;
  
  
  // histogram declarations with the following initial appendage: d - Data, m - MC, u- Unfolded
  // for the MC closure test, ive kept separate 

  TH1F *dPbPb_TrgComb[nbins_cent+1], *dPbPb_TrgCombInput[nbins_cent+1], *dPbPb_Comb[nbins_cent+1], *dPbPb_Trg80[nbins_cent+1], *dPbPb_Trg65[nbins_cent+1], *dPbPb_Trg55[nbins_cent+1], *dPbPb_1[nbins_cent+1], *dPbPb_2[nbins_cent+1], *dPbPb_3[nbins_cent+1], *dPbPb_80[nbins_cent+1], *dPbPb_65[nbins_cent+1], *dPbPb_55[nbins_cent+1];
  
  TH1F *mPbPb_GenInput[nbins_cent+1], *mPbPb_RecoInput[nbins_cent+1];
  TH1F *mPbPb_Gen[nbins_cent+1], *mPbPb_Reco[nbins_cent+1];
  TH2F *mPbPb_Matrix[nbins_cent+1], * mPbPb_MatrixInput[nbins_cent+1], *mPbPb_Response[nbins_cent+1], *mPbPb_ResponseNorm[nbins_cent+1];
  TH1F *mPbPb_mcclosure_data[nbins_cent+1];
  TH2F *mPbPb_mcclosure_Matrix[nbins_cent+1],*mPbPb_mcclosure_Response[nbins_cent+1], *mPbPb_mcclosure_ResponseNorm[nbins_cent+1];
  TH1F *mPbPb_mcclosure_gen[nbins_cent+1];
  const int Iterations = 20; //for unfolding systematics. 
  const int BayesIter = 4;
  TH1F *uPbPb_Bayes[nbins_cent+1], *uPbPb_BinByBin[nbins_cent+1], *uPbPb_SVD[nbins_cent+1]; 
  TH1F *uPbPb_BayesianIter[nbins_cent+1][Iterations];
  TH1F *dPbPb_MinBias[nbins_cent];
  TH1F *hMinBias[nbins_cent];
  
  TH1F *dPP_1, *dPP_2, *dPP_3, *dPP_Comb, * dPP_CombInput;
  TH1F *mPP_Gen, *mPP_Reco, *mPP_GenInput, *mPP_RecoInput;
  TH2F *mPP_Matrix, *mPP_MatrixInput, *mPP_Response,*mPP_ResponseNorm;
  TH1F *mPP_mcclosure_data;
  TH2F *mPP_mcclosure_Matrix, *mPP_mcclosure_Response,*mPP_mcclosure_ResponseNorm;
  TH1F *mPP_mcclosure_Gen;
  TH1F *uPP_Bayes, *uPP_BinByBin, *uPP_SVD;
  TH1F *uPP_BayesianIter[Iterations];

  TH1F * hData_FaketoSub_fullbin[nbins_cent+1];
  
  // would be better to read in the histograms and rebin them. come to think of it, it would be better to have them already rebinned (and properly scaled - to the level of differential cross section in what ever barns (inverse micro barns) but keep it consistent) from the read macro. 

  if(radius == 2) unfoldingCut = unfoldingCut_R2;
  if(radius == 3) unfoldingCut = unfoldingCut_R3;
  if(radius == 4) unfoldingCut = unfoldingCut_R4;
  
  // TH1F * htest = new TH1F("htest","",nbins, ptbins_long);
  // Int_t unfoldingCutBin = htest->FindBin(unfoldingCut);
  
  //Float_t cutarray[6]={50,50,40,35,35,35};
  float cutarray[nbins_cent] = {0.0,0.0,0.0,0.0,0.0,0.0};
  
  if(radius == 2){
    cutarray[0] = 50;
    cutarray[1] = 40;
    cutarray[2] = 40;
    cutarray[3] = 40;
    cutarray[4] = 30;
    cutarray[5] = 30;
  }
  if(radius == 3){
    cutarray[0] = 55;
    cutarray[1] = 50;
    cutarray[2] = 50;
    cutarray[3] = 40;
    cutarray[4] = 35;
    cutarray[5] = 40;
  }
    
  if(radius == 4){
    cutarray[0] = 70;
    cutarray[1] = 60;
    cutarray[2] = 60;
    cutarray[3] = 45;
    cutarray[4] = 40;
    cutarray[5] = 30;
  }
    
  TH1F * hDataBeforeSub[nbins_cent], * hDataAfterSub[nbins_cent];
  
  // get PbPb data
  for(int i = 0;i<nbins_cent;++i){
    if(printDebug) cout<<"cent_"<<i<<endl;

    hData_turnon[i] = (TH1F*)fTrig->Get(Form("hHist_Data_Turnon_cent%d",i));
    
    hData_turnon[i] = (TH1F*)hData_turnon[i]->Rebin(nbins_short, Form("hData_turnon_cent%d",i), boundaries_short);
    //hData_turnon[i] = (TH1F*)hData_turnon[i]->Rebin(10);

    divideBinWidth(hData_turnon[i]);

     //  hMinBias[i]     = (TH1F*)fMinBias->Get(Form("hpbpb_noTrg_R%d_%s_cent%d",radius,etaWidth,i)); //MinBias Histo
    hMinBias[i]     = (TH1F*)fMinBias->Get(Form("hpbpb_HLTMBwoLJSbJ_R%d_%s_cent%d",radius,etaWidth,i)); //MinBias Histo
    hMinBias[i]->Print("base");

    dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLTComb_%s_R%d_%s_cent%d",scale, radius,etaWidth,i));
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_%s_cent%d",radius,etaWidth,i));
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_%s_cent%d",radius,etaWidth,i));
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_%s_cent%d",radius,etaWidth,i));
    // dPbPb_TrgComb[i]->Scale(1./(1+0.898+0.494)/1e16);
    // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    dPbPb_TrgComb[i]->Print("base");

    hDataBeforeSub[i] = (TH1F*)dPbPb_TrgComb[i]->Clone(Form("hData_Before_Sub_cent%d",i));
    
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_DataCorr_in->Get(Form("Data_TrigEffCorrected_FakeSub_cent%d",i));
    //dPbPb_TrgComb[i]->Print("base");
    
    // dPbPb_JEC_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JEC_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));
    // // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    // dPbPb_JEC_TrgComb[i]->Print("base");
    // dPbPb_Smear_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_Smear_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));
    // // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    // dPbPb_Smear_TrgComb[i]->Print("base");
    // dPbPb_Trg80[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_%s_cent%d",radius,etaWidth,i));
    // //dPbPb_Trg80[i]->Scale(4*145.156*1e6);
    // dPbPb_Trg80[i]->Print("base");
    // dPbPb_Trg65[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_%s_cent%d",radius,etaWidth,i));
    // //dPbPb_Trg65[i]->Scale(4*145.156*1e6);
    // dPbPb_Trg65[i]->Print("base");
    // dPbPb_Trg55[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_%s_cent%d",radius,etaWidth,i));
    // //dPbPb_Trg55[i]->Scale(4*145.156*1e6);
    // dPbPb_Trg55[i]->Print("base");

    // if(dotrigcor){
      
    //   doTrigCorr(dPbPb_TrgComb[i], hData_turnon[i]);
    //   doTrigCorr(dPbPb_JEC_TrgComb[i], hData_turnon[i]);
    //   doTrigCorr(dPbPb_Smear_TrgComb[i], hData_turnon[i]);

    // }
    
    //Lets do the subtraction here _Sevil 

      // Float_t bincon=cutarray[i]; 
      // Int_t bincut= hMinBias[i]->FindBin(bincon); 
      
      // for(int k = bincut;k<=hMinBias[i]->GetNbinsX();k++) { 
      // 	hMinBias[i]->SetBinContent(k,0); 
      // 	hMinBias[i]->SetBinError(k,0);
      // } 

      // for(int k = 1;k<=15;k++) { 
      // 	hMinBias[i]->SetBinContent(k,0); 
      // 	hMinBias[i]->SetBinError(k,0);
      // }
      
      Float_t   bin_no = dPbPb_TrgComb[i]->FindBin(15);
      Float_t bin_end=dPbPb_TrgComb[i]->FindBin(25);
      
      Float_t   bin_nomb = hMinBias[i]->FindBin(15);
      Float_t bin_endmb=hMinBias[i]->FindBin(25);
      
      float scalerangeweight=dPbPb_TrgComb[i]->Integral(bin_no,bin_end)/hMinBias[i]->Integral(bin_nomb,bin_endmb);

      // for(int j = 0; j<hMinBias[i]->GetNbinsX(); ++j)
      // 	hMinBias[i]->SetBinError(j+1, (Float_t)hMinBias[i]->GetBinError(j+1)/scalerangeweight);
      
      hMinBias[i]->Scale(scalerangeweight);
      if(dofakeremove) dPbPb_TrgComb[i]->Add(hMinBias[i], -1);

      hDataAfterSub[i] = (TH1F*)dPbPb_TrgComb[i]->Clone(Form("hData_After_Sub_cent%d",i));
      
      // dPbPb_JEC_TrgComb[i]->Add(hMinBias[i], -1);
      // dPbPb_Smear_TrgComb[i]->Add(hMinBias[i], -1);

      // for(int j = 1; j<dPbPb_TrgComb[i]->GetNbinsX(); ++j){

      // 	if(dPbPb_TrgComb[i]->GetBinContent(j) <= 0 ||dPbPb_JEC_TrgComb[i]->GetBinContent(j) <= 0||dPbPb_Smear_TrgComb[i]->GetBinContent(j) <= 0){
      // 	  dPbPb_TrgComb[i]->SetBinContent(j, 0);
      // 	  dPbPb_JEC_TrgComb[i]->SetBinContent(j, 0);
      // 	  dPbPb_Smear_TrgComb[i]->SetBinContent(j, 0);
      // 	  dPbPb_TrgComb[i]->SetBinError(j, 0);
      // 	  dPbPb_JEC_TrgComb[i]->SetBinError(j, 0);
      // 	  dPbPb_Smear_TrgComb[i]->SetBinError(j, 0);
      // 	}
      // }
      
    

    // // lets truncate the histograms here:
    // cout<<" going to truncate Data histogram here cent "<<i<<endl;
    // dPbPb_TrgCombInput[i]->Print("base");

    // dPbPb_TrgComb[i] = new TH1F(Form("PbPb_data_minbiasSub_cent%d",i),"",365, 30, 395);
    // Truncate1D(dPbPb_TrgCombInput[i], dPbPb_TrgComb[i]);    
    
    // // dPbPb_TrgComb[i] = (TH1F*)Truncate1D(dPbPb_TrgComb[i], 340, unfoldingCutBin, 395);
    // // dPbPb_TrgComb[i]->Print("base");
    
    //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins, Form("PbPb_data_minbiasSub_cent%d",i), ptbins_long);
    dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(10);
    dPbPb_TrgComb[i]->SetName(Form("PbPb_data_minbiasSub_cent%d",i));
    divideBinWidth(dPbPb_TrgComb[i]);
    
    hMinBias[i] = (TH1F*)hMinBias[i]->Rebin(10);
    hDataAfterSub[i] = (TH1F*)hDataAfterSub[i]->Rebin(10);
    hDataBeforeSub[i] = (TH1F*)hDataBeforeSub[i]->Rebin(10);

    divideBinWidth(hMinBias[i]);
    divideBinWidth(hDataAfterSub[i]);
    divideBinWidth(hDataBeforeSub[i]);
    
    dPbPb_TrgComb[i]->Scale(1./(166 * 1e9));
    
    // dPbPb_TrgComb[i]->Print("base");
    
  }

  if(printDebug)cout<<"loaded the data histograms PbPb"<<endl;
  // get PbPb MC
  for(int i = 0;i<nbins_cent;i++){
    
    // mPbPb_GenInput[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_JetComb_gen_R%d_%s_cent%d",radius,etaWidth,i));
    // mPbPb_GenInput[i]->Print("base");
    // mPbPb_RecoInput[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_JetComb_reco_R%d_%s_cent%d",radius,etaWidth,i));
    // mPbPb_RecoInput[i]->Print("base");
    // mPbPb_MatrixInput[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i));
    // mPbPb_MatrixInput[i]->Print("base");

    mPbPb_Gen[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_JetComb_gen_R%d_%s_cent%d",radius,etaWidth,i));
    //mPbPb_Gen[i]->Rebin(nbins, Form("mPbPb_Gen_cent%d",i), ptbins_long);
    mPbPb_Gen[i]->Rebin(10);
    divideBinWidth(mPbPb_Gen[i]);
    mPbPb_Gen[i]->Print("base");
    mPbPb_Reco[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_JetComb_reco_R%d_%s_cent%d",radius,etaWidth,i));
    //mPbPb_Reco[i]->Rebin(nbins, Form("mPbPb_Reco_cent%d",i), ptbins_long);
    mPbPb_Reco[i]->Rebin(10);
    divideBinWidth(mPbPb_Reco[i]);
    mPbPb_Reco[i]->Print("base");
    mPbPb_Matrix[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i));
    //mPbPb_Matrix[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i));
    mPbPb_Matrix[i]->Rebin2D(10, 10);
    mPbPb_Matrix[i]->Print("base");
    
    // if(etaWidth == "10_eta_10"){
    //   if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30);
    // }

    // if(etaWidth == "10_eta_18"){
    //   if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(70);
    //   if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30);
    // }

    // if(etaWidth == "20_eta_20"){
    //   if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(70);
    //   if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(70);
    //   if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(80);
    //   if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30);
    // }

    int bincut = mPbPb_Gen[i]->FindBin(50);
    for(int k = 1;k<=bincut;k++){

    //   mPbPb_Gen[i]->SetBinContent(k,0);
    //   mPbPb_Reco[i]->SetBinContent(k,0);
    //   mPbPb_Gen[i]->SetBinError(k,0);
    //   mPbPb_Reco[i]->SetBinError(k,0);
    //   // set bin content matrix l,k works 
      for(int l = 1;l<=mPbPb_Gen[i]->GetNbinsX();l++){
	mPbPb_Matrix[i]->SetBinContent(l,k,0);
	mPbPb_Matrix[i]->SetBinError(l,k,0);
      }
      
    }

    SetUnfoldBins1D(dPbPb_TrgComb[i], 50, 350);
    
    // cout<<"going to truncate the MC histograms here."<<endl;
    
    // // mPbPb_Reco[i]->Print("base");
    // // mPbPb_Reco[i] = (TH1F*)Truncate1D_anaBin(mPbPb_Reco[i], nbins, ptbins_long);
    // // mPbPb_Reco[i]->Print("base");

    // mPbPb_GenInput[i]->Print("base");
    // mPbPb_Gen[i] = new TH1F(Form("mPbPb_Gen_spectra_cent%d",i),"",nbins, ptbins_long);
    // Truncate1D(mPbPb_GenInput[i], mPbPb_Gen[i]);
    // mPbPb_Gen[i]->Print("base");
    
    // mPbPb_RecoInput[i]->Print("base");
    // mPbPb_Reco[i] = new TH1F(Form("mPbPb_REco_spectra_cent%d",i),"",nbins, ptbins_long);
    // Truncate1D(mPbPb_RecoInput[i], mPbPb_Reco[i]);
    // mPbPb_Reco[i]->Print("base");
    
    // mPbPb_MatrixInput[i]->Print("base");
    // mPbPb_Matrix[i] = new TH2F(Form("mPbPb_Response_Matrix_cent%d",i),"",nbins_truncated, ptbins_long_truncated, nbins_truncated, ptbins_long_truncated);
    // Truncate2D(mPbPb_MatrixInput[i], mPbPb_Matrix[i]);
    // mPbPb_Matrix[i]->Print("base");
 
  }
  
  if(printDebug) cout<<"loaded the data and mc PbPb histograms from the files"<<endl;

  // get PP data
  if(printDebug) cout<<"Getting PP data and MC"<<endl;

  //fPP_in->ls();

  // dPP_1 = (TH1F*)fPP_in->Get(Form("hpp_HLT80_R%d_%s",radius,etaWidth)); 
  // dPP_1->Print("base");
  // dPP_2 = (TH1F*)fPP_in->Get(Form("hpp_HLT60_R%d_%s",radius,etaWidth));
  // dPP_2->Print("base");
  // dPP_3 = (TH1F*)fPP_in->Get(Form("hpp_HLT40_R%d_%s",radius,etaWidth));
  // dPP_3->Print("base");
  dPP_Comb = (TH1F*)fPP_in->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth));
  //dPP_Comb = (TH1F*)dPP_1->Clone(Form("hpp_TrgComb_R%d_n20_eta_p20",radius,etaWidth));   
  //dPP_CombInput->Print("base");
  dPP_Comb->Scale(1./(5.3 * 1e9));
  
  // dPP_Comb = new TH1F("PP_MeasuredSpectra","",365, 30, 395);
  // Truncate1D(dPP_CombInput, dPP_Comb);

  //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins, "PP_MeasuredSpectra", ptbins_long);
  dPP_Comb = (TH1F*)dPP_Comb->Rebin(10);
  dPP_Comb->SetName("PP_MeasuredSpectra");
  divideBinWidth(dPP_Comb);
  dPP_Comb->Print("base");
  
  // get PP MC
  // mPP_GenInput = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_gen_R%d_%s",radius,etaWidth));
  // mPP_GenInput->Print("base");
  // mPP_Gen = new TH1F("mPP_Gen_spectra","",nbins, ptbins_long);
  // Truncate1D(mPP_GenInput, mPP_Gen);
  // mPP_Gen->Print("base");
  
  // mPP_RecoInput = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_reco_R%d_%s",radius,etaWidth));
  // mPP_RecoInput->Print("base");
  // mPP_Reco = new TH1F("mPP_Reco_spectra","",nbins, ptbins_long);
  // Truncate1D(mPP_RecoInput, mPP_Reco);
  // mPP_Reco->Print("base");
  
  // mPP_MatrixInput = (TH2F*)fPP_MC_in->Get(Form("hpp_anaBin_matrix_HLT_R%d_%s",radius,etaWidth));
  // mPP_MatrixInput->Print("base");
  // mPP_Matrix = new TH2F("mPP_response_Matrix","",nbins_truncated, ptbins_long_truncated, nbins_truncated, ptbins_long_truncated);
  // Truncate2D(mPP_MatrixInput, mPP_Matrix);
  // mPP_Matrix->Print("base");

  // get PP MC
  // change from fPP_MC_in to fPP_in to run finebinscut
  //mPP_Gen = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_gen_R%d_20_eta_20",radius));
  mPP_Gen = (TH1F*)fPP_MC_in->Get(Form("hpp_JetComb_gen_R%d_20_eta_20",radius));
  //mPP_Gen->Rebin(nbins, "mPP_Gen", ptbins_long);
  mPP_Gen->Rebin(10);
  divideBinWidth(mPP_Gen);
  mPP_Gen->Print("base");

  //mPP_Reco = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_reco_R%d_20_eta_20",radius));
  mPP_Reco = (TH1F*)fPP_MC_in->Get(Form("hpp_JetComb_reco_R%d_20_eta_20",radius));
  //mPP_Gen->Rebin(nbins, "mPP_Gen", ptbins_long);
  mPP_Reco->Rebin(10);
  divideBinWidth(mPP_Reco);
  mPP_Reco->Print("base");

  //mPP_Matrix = (TH2F*)fPP_MC_in->Get(Form("hpp_anaBin_matrix_HLT_R%d_20_eta_20",radius));
  mPP_Matrix = (TH2F*)fPP_MC_in->Get(Form("hpp_matrix_HLT_R%d_20_eta_20",radius));
  mPP_Matrix->Rebin2D(10, 10);
  mPP_Matrix->Print("base");

  if(printDebug) cout<<"Filling the PbPb response Matrix"<<endl;

  // response matrix and unfolding for PbPb 
  // going to try it the way kurt has its. 

  for(int i = 0;i<nbins_cent;i++){
    if(printDebug) cout<<"centrality bin iteration = "<<i<<endl;
    TF1 *f = new TF1("f","[0]*pow(x+[2],[1])");
    f->SetParameters(1e10,-8.8,40);
    // TH1F *hGenSpectraCorr = (TH1F*)mPbPb_Matrix[i]->ProjectionX()->Clone(Form("hGenSpectraCorr_cent%d",i));
    // hGenSpectraCorr->Fit("f"," ");
    // hGenSpectraCorr->Fit("f","","");
    // hGenSpectraCorr->Fit("f","LL");
    // TH1F *fHist = functionHist(f,hGenSpectraCorr,Form("fHist_cent%d",i));// function that you get from the fitting 
    // hGenSpectraCorr->Divide(fHist);
    for (int y=1;y<=mPbPb_Matrix[i]->GetNbinsY();y++) {
      double sum=0;
      for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) {
	if (mPbPb_Matrix[i]->GetBinContent(x,y)<=1*mPbPb_Matrix[i]->GetBinError(x,y)) {
	  //in the above line mine had 0*getbinerror while Kurt's had 1*. 
	  mPbPb_Matrix[i]->SetBinContent(x,y,0);
	  mPbPb_Matrix[i]->SetBinError(x,y,0);
	}
	sum+=mPbPb_Matrix[i]->GetBinContent(x,y);
      }
      
      for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) {	   
	double ratio = 1;
	// if (hGenSpectraCorr->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorr->GetBinContent(x);
	mPbPb_Matrix[i]->SetBinContent(x,y,mPbPb_Matrix[i]->GetBinContent(x,y)*ratio);
	mPbPb_Matrix[i]->SetBinError(x,y,mPbPb_Matrix[i]->GetBinError(x,y)*ratio);
      }
    }
    //mPbPb_Matrix[i]->Smooth(0);
    // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above.  
    
    mPbPb_Response[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_Response_cent%d",i));
    TH1F *hProj = (TH1F*)mPbPb_Response[i]->ProjectionY()->Clone(Form("hProj_cent%d",i));

    for (int y=1;y<=mPbPb_Response[i]->GetNbinsY();y++) {
      double sum=0;
      for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) {
	if (mPbPb_Response[i]->GetBinContent(x,y)<=1*mPbPb_Response[i]->GetBinError(x,y)) {
	  // in the above if loop, kurt has 1*error and my old had 0*error
	  mPbPb_Response[i]->SetBinContent(x,y,0);
	  mPbPb_Response[i]->SetBinError(x,y,0);
	}
	sum+=mPbPb_Response[i]->GetBinContent(x,y);
      }
      
      for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) {  	
	if (sum==0) continue;
	double ratio = 1;
	//if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum;
	// else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum
	ratio = 1./sum;
	if (hProj->GetBinContent(y)==0) ratio = 1e-100/sum;
	else ratio = hProj->GetBinContent(y)/sum;
	mPbPb_Response[i]->SetBinContent(x,y,mPbPb_Response[i]->GetBinContent(x,y)*ratio);
	mPbPb_Response[i]->SetBinError(x,y,mPbPb_Response[i]->GetBinError(x,y)*ratio);
      }
    }
    
    mPbPb_ResponseNorm[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_ResponseNorm_cent%d",i));
    for (int x=1;x<=mPbPb_ResponseNorm[i]->GetNbinsX();x++) {
      double sum=0;
      for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) {
	if (mPbPb_ResponseNorm[i]->GetBinContent(x,y)<=1*mPbPb_ResponseNorm[i]->GetBinError(x,y)) {
	  mPbPb_ResponseNorm[i]->SetBinContent(x,y,0);
	  mPbPb_ResponseNorm[i]->SetBinError(x,y,0);
	}
	sum+=mPbPb_ResponseNorm[i]->GetBinContent(x,y);
      }
      
      for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) {  	
	if (sum==0) continue;
	double ratio = 1./sum;
	mPbPb_ResponseNorm[i]->SetBinContent(x,y,mPbPb_ResponseNorm[i]->GetBinContent(x,y)*ratio);
	mPbPb_ResponseNorm[i]->SetBinError(x,y,mPbPb_ResponseNorm[i]->GetBinError(x,y)*ratio);
      }
      
    }
    
    
  }

  
  if(printDebug) cout<<"Filling PP response Matrix"<<endl;

  // response matrix for pp.  
  // Kurt doesnt have this whole hGenSpectraCorr thing in his macro. need to check why the difference exists between out codes
  
  TF1 *fpp = new TF1("fpp","[0]*pow(x+[2],[1])");
  fpp->SetParameters(1e10,-8.8,40);
  // if(printDebug) cout<<"before getting the gen spectra corr matrix"<<endl;
  // TH1F *hGenSpectraCorrPP = (TH1F*)mPP_Matrix->ProjectionX()->Clone("hGenSpectraCorrPP");
  // if(printDebug) cout<<"after gettign the gen spectra corr matrix"<<endl;
  // hGenSpectraCorrPP->Fit("f"," ");
  // hGenSpectraCorrPP->Fit("f","","");
  // hGenSpectraCorrPP->Fit("f","LL");
  // TH1F *fHistPP = functionHist(fpp,hGenSpectraCorrPP,"fHistPP");// that the function that you get from the fitting 
  // hGenSpectraCorrPP->Divide(fHistPP);
  
  for (int y=1;y<=mPP_Matrix->GetNbinsY();y++) {
    double sum=0;
    for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) {
      if (mPP_Matrix->GetBinContent(x,y)<=1*mPP_Matrix->GetBinError(x,y)) {
	mPP_Matrix->SetBinContent(x,y,0);
	mPP_Matrix->SetBinError(x,y,0);
      }
      sum+=mPP_Matrix->GetBinContent(x,y);
    }
    
    for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) {	   
      double ratio = 1;
      // if (hGenSpectraCorrPP->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorrPP->GetBinContent(x);
      mPP_Matrix->SetBinContent(x,y,mPP_Matrix->GetBinContent(x,y)*ratio);
      mPP_Matrix->SetBinError(x,y,mPP_Matrix->GetBinError(x,y)*ratio);
    }
  }
  // mPbPb_Matrix[i]->Smooth(0);
  
  // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above.  

  if(printDebug) cout<<"getting the response matrix"<<endl;

  mPP_Response = (TH2F*)mPP_Matrix->Clone("mPP_Response");
  TH1F *hProjPP = (TH1F*)mPP_Response->ProjectionY()->Clone("hProjPP");
  
  
  for (int y=1;y<=mPP_Response->GetNbinsY();y++) {
    double sum=0;
    for (int x=1;x<=mPP_Response->GetNbinsX();x++) {
      if (mPP_Response->GetBinContent(x,y)<=1*mPP_Response->GetBinError(x,y)) {
	// in the above if statement, kurt has 1*error and my old has 0*error
	mPP_Response->SetBinContent(x,y,0);
	mPP_Response->SetBinError(x,y,0);
      }
      sum+=mPP_Response->GetBinContent(x,y);
    }
    
    for (int x=1;x<=mPP_Response->GetNbinsX();x++) {  	
      if (sum==0) continue;
      double ratio = 1;
      //if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum;
      // else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum
      ratio = 1./sum;
      if (hProjPP->GetBinContent(y)==0) ratio = 1e-100/sum;
      else ratio = hProjPP->GetBinContent(y)/sum;
      mPP_Response->SetBinContent(x,y,mPP_Response->GetBinContent(x,y)*ratio);
      mPP_Response->SetBinError(x,y,mPP_Response->GetBinError(x,y)*ratio);
    }
  }
  if(printDebug) cout<<"getting the normalized response matrix"<<endl;
  mPP_ResponseNorm = (TH2F*)mPP_Matrix->Clone("mPP_ResponseNorm");
  for (int x=1;x<=mPP_ResponseNorm->GetNbinsX();x++) {
    double sum=0;
    for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) {
      if (mPP_ResponseNorm->GetBinContent(x,y)<=1*mPP_ResponseNorm->GetBinError(x,y)) {
	mPP_ResponseNorm->SetBinContent(x,y,0);
	mPP_ResponseNorm->SetBinError(x,y,0);
      }
      sum+=mPP_ResponseNorm->GetBinContent(x,y);
    }
    
    for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) {  	
      if (sum==0) continue;
      double ratio = 1./sum;
      mPP_ResponseNorm->SetBinContent(x,y,mPP_ResponseNorm->GetBinContent(x,y)*ratio);
      mPP_ResponseNorm->SetBinError(x,y,mPP_ResponseNorm->GetBinError(x,y)*ratio);
    }
    
    
  }
  
  // scale the spectra to the respective units

  // for(int i = 0;i<nbins_cent;++i){
  //   dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins,Form("PbPb_measured_spectra_combined_cent%d",i),ptbins_long);
  //   divideBinWidth(dPbPb_TrgComb[i]);
  // }

  // dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins,"pp_measured_spectra_combined",ptbins_long);
  // divideBinWidth(dPP_Comb);
  // dPP_Comb->Scale(1./ dPP_Comb->GetBinContent(nbins));
  
  // Now that we have all the response matrix for the 6 centralities in PbPb and one pp spectra lets start doing the steps:
  // we have 39 pt bins, so we need 1000 gaussian functions for each pt bin.
  
  Int_t unfoldingTrials = 1000;
  Double_t meanMeasPbPb[nbins][nbins_cent], sigmaMeasPbPb[nbins][nbins_cent];
  Double_t meanMeasPP[nbins], sigmaMeasPP[nbins];
  Double_t meanUnfoldPbPb[nbins][nbins_cent][unfoldingTrials], sigmaUnfoldPbPb[nbins][nbins_cent][unfoldingTrials];
  Double_t meanUnfoldPP[nbins][unfoldingTrials], sigmaUnfoldPP[nbins][unfoldingTrials]; 
  
  TRandom3 *random = new TRandom3(0);

  TH1F * hPbPb_beforeUnfold_Gaussian_pt150[nbins_cent];
  TH1F * hPP_beforeUnfold_Gaussian_pt150; 
  hPP_beforeUnfold_Gaussian_pt150 = new TH1F("hPP_beforeUnfold_Gaussian_pt150","",1000, 0.1 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)) , 1.9 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)));
  
  for(int i = 0; i<nbins_cent; ++i)
    hPbPb_beforeUnfold_Gaussian_pt150[i] = new TH1F(Form("hPbPb_beforeUnfold_Gaussian_pt150_cent%d",i),"Before Unfolding pt bin at 150 value spectra",1000, 0.1 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)), 1.9 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)));
  

  for(int u = 0;u<unfoldingTrials;++u){
    cout<<"unfolding trial no = "<<u+1<<endl;
  
    for(int j = 0;j<nbins;++j){
      for(int i = 0;i<nbins_cent;++i){
      
	meanMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinContent(j+1);
	sigmaMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinError(j+1);

      }// centrality loop

      meanMeasPP[j] = dPP_Comb->GetBinContent(j+1);
      sigmaMeasPP[j] = dPP_Comb->GetBinError(j+1);
      
    }// nbins loop

    // now proceed to unfolding for each trial.

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

      TH1F * hPreUnfoldingSpectra = new TH1F("hPreUnfoldingSpectra","",nbins,0, 1000);
      TH1F * hAfterUnfoldingSpectra;

      for(int j = 0;j<nbins;++j){
	
	hPreUnfoldingSpectra->SetBinContent(j+1, random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i]));
	hPreUnfoldingSpectra->SetBinError(j+1, sigmaMeasPbPb[j][i]/sqrt(unfoldingTrials));
	if(j+1 == dPbPb_TrgComb[i]->FindBin(150)) hPbPb_beforeUnfold_Gaussian_pt150[i]->Fill(random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i]));
	
      }// nbins loop

      TH1F* hMCGen          = (TH1F*)mPbPb_Response[i]->ProjectionX();
      removeZero(hMCGen);
      bayesianUnfold myUnfoldingMulti(mPbPb_Matrix[i], hMCGen, 0);
      myUnfoldingMulti.unfold(hPreUnfoldingSpectra, BayesIter);

      hAfterUnfoldingSpectra = (TH1F*) myUnfoldingMulti.hPrior->Clone("hAfterUnfoldingSpectra");

      for(int j = 0;j<nbins;++j){

	meanUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinContent(j+1);
	sigmaUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinError(j+1);

      }// nbins loop
      
      delete hPreUnfoldingSpectra;
      delete hAfterUnfoldingSpectra;
      delete hMCGen; 
      
    }// centrality loop

    cout<<"pp "<<endl;

    // now do it for the pp:
    TH1F * hPreUnfoldingSpectraPP = new TH1F("hPreUnfoldingSpectraPP","",nbins,0, 1000);
    TH1F * hAfterUnfoldingSpectraPP;
    
    for(int j = 0;j<nbins;++j){
	
      hPreUnfoldingSpectraPP->SetBinContent(j+1, random->Gaus(meanMeasPP[j], sigmaMeasPP[j]));
      hPreUnfoldingSpectraPP->SetBinError(j+1, sigmaMeasPP[j]/sqrt(unfoldingTrials));
      if(j+1 == dPP_Comb->FindBin(150)) hPP_beforeUnfold_Gaussian_pt150->Fill(random->Gaus(meanMeasPP[j], sigmaMeasPP[j]));
      
    }// nbins loop
    TH1F* hMCGenPP          = (TH1F*)mPP_Response->ProjectionX();
    removeZero(hMCGenPP);
    bayesianUnfold myUnfoldingMultiPP(mPP_Matrix, hMCGenPP, 0);
    myUnfoldingMultiPP.unfold(hPreUnfoldingSpectraPP, BayesIter);

    hAfterUnfoldingSpectraPP = (TH1F*) myUnfoldingMultiPP.hPrior->Clone("hAfterUnfoldingSpectraPP");

    for(int j = 0;j<nbins;++j){

      meanUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinContent(j+1);
      sigmaUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinError(j+1);

    }// nbins loop

    delete hPreUnfoldingSpectraPP;
    delete hAfterUnfoldingSpectraPP;
    delete hMCGenPP; 
    
  }// unfolding trials loop


  // Now that we have all the necesary values we need, lets proceed to fill a histogram with the mean values for each ptbin and get the corrected values.
  TH1F * hAfterUnfoldingptBinDistribution[nbins];
  TH1F * hCorrUnfoldingPbPb[nbins_cent];

  // we need to store one gaussian histogram in the root file which we can plot 
  TH1F * hPbPb_Gaussian_pt150[nbins_cent];
  TH1F * hPP_Gaussian_pt150;


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

    hCorrUnfoldingPbPb[i] = new TH1F(Form("PbPb_BayesianUnfolded_cent%d",i),"Spectra after correction", nbins,0, 1000);
    hPbPb_Gaussian_pt150[i] = new TH1F(Form("PbPb_Gaussian_pt150_cent%d",i),"gaussian distribution of values at pt bin at 150",1000, 0.1 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)), 1.9 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)));

    for(int j = 0;j<nbins;++j){
      
      hAfterUnfoldingptBinDistribution[j] = new TH1F(Form("hAfterUnfoldingptBinDistribution_ptBin%d",j),"",100,	0, 1);
      for(int u = 0;u<unfoldingTrials;++u){

	hAfterUnfoldingptBinDistribution[j]->Fill(meanUnfoldPbPb[j][i][u]);
	if(j+1 == dPbPb_TrgComb[i]->FindBin(150)) hPbPb_Gaussian_pt150[i]->Fill(meanUnfoldPbPb[j][i][u]);

      }// unfolding trials loop

      hCorrUnfoldingPbPb[i]->SetBinContent(j+1, hAfterUnfoldingptBinDistribution[j]->GetMean());
      hCorrUnfoldingPbPb[i]->SetBinError(j+1, hAfterUnfoldingptBinDistribution[j]->GetRMS());

      delete hAfterUnfoldingptBinDistribution[j];
      
    }// nbins loop

  }// centrality loop

  // similar for the pp:
  TH1F * hAfterUnfoldingptBinDistributionPP[nbins];
  TH1F * hCorrUnfoldingPP;
  
  hCorrUnfoldingPP = new TH1F("PP_BayesianUnfolded","Spectra after unfolding error correction",nbins,0, 1000);
  hPP_Gaussian_pt150 = new TH1F("PP_Gaussian_pt100","gaussian distribution of values at pt bin at 150",1000, 0.1 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)) , 1.9 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)));
  
  for(int j = 0;j<nbins;++j){
    
    hAfterUnfoldingptBinDistributionPP[j] = new TH1F(Form("hAfterUnfoldingptBinDistributionPP_ptBin%d",j),"",100, 0, 1);
    for(int u = 0;u<unfoldingTrials;++u){
      
      hAfterUnfoldingptBinDistributionPP[j]->Fill(meanUnfoldPP[j][u]);
      if(j+1 == dPP_Comb->FindBin(150)) hPP_Gaussian_pt150->Fill(meanUnfoldPP[j][u]);
      
    }// unfolding trials loop
    
    hCorrUnfoldingPP->SetBinContent(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetMean());
    hCorrUnfoldingPP->SetBinError(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetRMS());
    
    delete hAfterUnfoldingptBinDistributionPP[j];
    
  }// nbins loop
    
  TFile f(Form("July20/HiForest_%disATLASCut_%ddo10GeVBins_data_driven_correction_ak%d.root" , isATLASCut, do10GeVBins, radius),"RECREATE");
  f.cd();

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

    //hCorrUnfoldingPbPb[i] = (TH1F*)hCorrUnfoldingPbPb[i]->Rebin(nbins_coarse, Form("PbPb_BayesianUnfolded_cent%d",i), ptbins_long_coarse);
    //divideBinWidth(hCorrUnfoldingPbPb[i]);
    //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_coarse, Form("PbPb_measured_cent%d",i), ptbins_long_coarse);
    //divideBinWidth(dPbPb_TrgComb[i]);

    hMinBias[i]->Write();
    hDataBeforeSub[i]->Write();
    hDataAfterSub[i]->Write();
    
    hCorrUnfoldingPbPb[i]->Scale(166 * 1e9);
    hCorrUnfoldingPbPb[i]->Write();
    hCorrUnfoldingPbPb[i]->Print("base");

    dPbPb_TrgComb[i]->Scale(166 * 1e9);
    dPbPb_TrgComb[i]->SetName(Form("PbPb_data_minbiasSub_cent%d",i));
    //dPbPb_TrgComb[i]->Scale(145.156 * 1e9);
    dPbPb_TrgComb[i]->Write();
    dPbPb_TrgComb[i]->Print("base");

    hPbPb_beforeUnfold_Gaussian_pt150[i]->Write();
    hPbPb_beforeUnfold_Gaussian_pt150[i]->Print("base");
    
    hPbPb_Gaussian_pt150[i]->Write();
    hPbPb_Gaussian_pt150[i]->Print("base");

    mPbPb_Matrix[i]->Write();
    
  }

  //hCorrUnfoldingPP = (TH1F*)hCorrUnfoldingPP->Rebin(nbins_coarse, "PP_BayesianUnfolded", ptbins_long_coarse);
  //divideBinWidth(hCorrUnfoldingPP);
  //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_coarse, "PP_measured", ptbins_long_coarse);  
  //divideBinWidth(dPP_Comb);
  
  hCorrUnfoldingPP->Scale(5.3 * 1e9);
  hCorrUnfoldingPP->Write();
  hCorrUnfoldingPP->Print("base");

  dPP_Comb->Scale(5.3 * 1e9);
  dPP_Comb->Write();
  dPP_Comb->Print("base");

  hPP_beforeUnfold_Gaussian_pt150->Write();
  hPP_beforeUnfold_Gaussian_pt150->Print("base");
  
  hPP_Gaussian_pt150->Write();
  hPP_Gaussian_pt150->Print("base");
  mPP_Matrix->Write();

  f.Write();
  f.Close();

  // make the data driven Error correction histograms and plots here:
  
  TH1F * hError_Meas[nbins_cent+1], * hError_Fixed[nbins_cent+1];
  for(int i = 0; i<nbins_cent+1; ++i){
    cout<<"centrality "<<i<<endl;
    if(i < nbins_cent){
      hError_Meas[i]  = new TH1F(Form("hError_Meas_cent%d",i),"",nbins, 0, 1000);
      hError_Fixed[i] = new TH1F(Form("hError_Fixed_cent%d",i),"",nbins, 0, 1000);
    }
    if(i == nbins_cent){
      hError_Meas[i]  = new TH1F(Form("hError_PP_Meas_cent%d",i),"",nbins, 0, 1000);
      hError_Fixed[i] = new TH1F(Form("hError_PP_Fixed_cent%d",i),"",nbins, 0, 1000);
    }

    for(int j = 1; j<=nbins; ++j){
      //cout<<"ptbins "<<j<<endl;
      if(i < nbins_cent){
	if(dPbPb_TrgComb[i]->GetBinContent(j)!=0) hError_Meas[i]->SetBinContent(j, (float)dPbPb_TrgComb[i]->GetBinError(j)/dPbPb_TrgComb[i]->GetBinContent(j));
        //hError_Meas[i]->SetBinContent(j, (float)dPbPb_TrgComb[i]->GetBinError(j));
	if(hCorrUnfoldingPbPb[i]->GetBinContent(j)!=0)hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPbPb[i]->GetBinError(j)/hCorrUnfoldingPbPb[i]->GetBinContent(j));
	cout<<j<<" "<<hError_Fixed[i]->GetBinContent(j)<<endl;
	//hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPbPb[i]->GetBinError(j));
      }
      if(i == nbins_cent){
	hError_Meas[i]->SetBinContent(j, (float)dPP_Comb->GetBinError(j)/dPP_Comb->GetBinContent(j));
	//hError_Meas[i]->SetBinContent(j, (float)dPP_Comb->GetBinError(j));
	hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPP->GetBinError(j)/hCorrUnfoldingPP->GetBinContent(j));
	//hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPP->GetBinError(j));
      }
    }
    
    hError_Meas[i]->SetAxisRange(50, 299, "X");
    //hError_Meas[i]->Print("base");
    //hError_Fixed[i]->Print("base");
    //hError_Meas[i]->SetAxisRange(1e-12, 1, "Y");
  }
  //cout<<" passed the loop"<<endl;

  TCanvas * cSpectra = new TCanvas("cSpectra","",1200,1000);
  makeMultiPanelCanvas(cSpectra,3,2,0.0,0.0,0.2,0.15,0.07);  
  for(int i = 0; i<nbins_cent; ++i){
    //cout<<i<<endl;
    cSpectra->cd(nbins_cent-i);
    cSpectra->cd(nbins_cent-i)->SetLogy();
    dPbPb_TrgComb[i]->SetMarkerStyle(24);
    dPbPb_TrgComb[i]->SetMarkerColor(kBlack);
    makeHistTitle(dPbPb_TrgComb[i]," ","jet pT","dN/dpT");
    dPbPb_TrgComb[i]->SetAxisRange(50, 299, "X");
    dPbPb_TrgComb[i]->Draw("p");

    hCorrUnfoldingPbPb[i]->SetMarkerStyle(33);
    hCorrUnfoldingPbPb[i]->SetMarkerColor(kRed);
    hCorrUnfoldingPbPb[i]->Draw("psame");

  }
  TLegend * Spec = myLegend(0.55,0.55,0.75,0.75);
  cSpectra->cd(1);
  putCMSPrel();
  Spec->AddEntry(dPbPb_TrgComb[0],"Measured","pl");
  Spec->AddEntry(hCorrUnfoldingPbPb[0],"Data Driven Correction","pl");
  Spec->SetTextSize(0.04);
  Spec->Draw();
  
  cSpectra->SaveAs(Form("%sUnfoldingSpectra_fromDataDrivenMacro_PbPb_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE");

  
  TCanvas * cErrorFix = new TCanvas("cErrorFix","",1200,1000);
  makeMultiPanelCanvas(cErrorFix,3,2,0.0,0.0,0.2,0.15,0.07);  
  for(int i = 0; i<nbins_cent; ++i){
    //cout<<i<<endl;
    cErrorFix->cd(nbins_cent-i);
    cErrorFix->cd(nbins_cent-i)->SetLogy();
    makeHistTitle(hError_Meas[i]," ","jet pT","Error/Content");
    hError_Meas[i]->SetMarkerStyle(24);
    hError_Meas[i]->SetMarkerColor(kBlack);
    hError_Meas[i]->Draw("p");

    hError_Fixed[i]->SetMarkerStyle(33);
    hError_Fixed[i]->SetMarkerColor(kRed);
    hError_Fixed[i]->Draw("psame");

  }
  TLegend * err = myLegend(0.55,0.55,0.75,0.75);
  cErrorFix->cd(1);
  putCMSPrel();
  err->AddEntry(hError_Meas[0],"Measured","pl");
  err->AddEntry(hError_Fixed[0],"Data Driven Correction","pl");
  err->SetTextSize(0.04);
  err->Draw();
  
  cErrorFix->SaveAs(Form("%sUnfoldingErrorFix_fromDataDrivenMacro_PbPb_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE");

  TCanvas * cErrorFixPP = new TCanvas("cErrorFixPP","",800,600);
  cErrorFixPP->SetLogy();
  hError_Meas[nbins_cent]->SetMarkerStyle(24);
  hError_Meas[nbins_cent]->SetMarkerColor(kBlack);
  hError_Meas[nbins_cent]->Draw("p");
  
  hError_Fixed[nbins_cent]->SetMarkerStyle(33);
  hError_Fixed[nbins_cent]->SetMarkerColor(kRed);
  hError_Fixed[nbins_cent]->Draw("psame");
  TLegend * errPP = myLegend(0.55,0.55,0.75,0.75);
  putCMSPrel();
  errPP->AddEntry(hError_Meas[nbins_cent],"Measured","pl");
  errPP->AddEntry(hError_Fixed[nbins_cent],"Data Driven Correction","pl");
  errPP->SetTextSize(0.04);
  errPP->Draw();
  
  cErrorFixPP->SaveAs(Form("%sUnfoldingErrorFix_fromDataDrivenMacro_PP_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE");
  
  timer.Stop();
  if(printDebug) cout<<"CPU time (mins) = "<<(Float_t)timer.CpuTime()/60<<endl;
  if(printDebug) cout<<"Real tile (mins) = "<<(Float_t)timer.RealTime()/60<<endl;


}
Beispiel #16
0
void merge_pbpb_pp_HLT(){
  
  TH1::SetDefaultSumw2();
  
  //TFile *fpbpb1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet80_v2.root");
  //TFile *fpbpb2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet65_v2.root");
  //TFile *fpbpb3 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet55_v2.root");
  
  //TFile *fpp1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet80.root");
  //TFile *fpp2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet40.root");
  
  TFile *fpp1_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet80_v2.root");
  TFile *fpp2_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet40_v2.root");

  /*
  TTree *jetpbpb1_v2 = (TTree*)fpbpb1->Get("jetR3");
  TTree *jetpbpb2_v2 = (TTree*)fpbpb2->Get("jetR3");
  TTree *jetpbpb3_v2 = (TTree*)fpbpb3->Get("jetR3");

  TTree *evtpbpb1_v2 = (TTree*)fpbpb1->Get("evt");
  TTree *evtpbpb2_v2 = (TTree*)fpbpb2->Get("evt");
  TTree *evtpbpb3_v2 = (TTree*)fpbpb3->Get("evt");  

  jetpbpb1_v2->AddFriend(evtpbpb1_v2);
  jetpbpb2_v2->AddFriend(evtpbpb2_v2);
  jetpbpb3_v2->AddFriend(evtpbpb3_v2);
  */
  //TTree *jetpp1 = (TTree*)fpp1->Get("ntjet");
  // TTree *jetpp2 = (TTree*)fpp2->Get("ntjet");

  TTree *jetpp1_v2 = (TTree*)fpp1_v2->Get("jetR3");
  TTree *jetpp2_v2 = (TTree*)fpp2_v2->Get("jetR3");

  TTree *evtpp1_v2 = (TTree*)fpp1_v2->Get("evt");
  TTree *evtpp2_v2 = (TTree*)fpp2_v2->Get("evt");

  jetpp1_v2->AddFriend(evtpp1_v2);
  jetpp2_v2->AddFriend(evtpp2_v2);

  //TCut pbpb3 = "abs(eta)<2&&jet55&&!jet65&&!jet80&&chMax/pt>0.01";
  TCut pp3 = "abs(eta)<2&&jet40&&!jet60&&!jet80&&chMax/pt>0.01";
  
  //TH1F *hpbpb1 = new TH1F("hpbpb1","",30,0,300);
  //TH1F *hpbpb2 = new TH1F("hpbpb2","",30,0,300);
  //TH1F *hpbpb3 = new TH1F("hpbpb3","",30,0,300);
  //TH1F *hpbpbComb = new TH1F("hpbpbComb","",30,0,300);
  
  TH1F *hpp1 = new TH1F("hpp1","",nbins_jetPtBin,boundaries_jetPtBin);
  TH1F *hpp2 = new TH1F("hpp2","",nbins_jetPtBin,boundaries_jetPtBin);
  TH1F *hpp3 = new TH1F("hpp3","",nbins_jetPtBin,boundaries_jetPtBin);
  TH1F *hppComb = new TH1F("hppComb","",nbins_jetPtBin,boundaries_jetPtBin);
  
  //get the prescl factor information. 
  //Float_t presclpbpb3 = (Float_t)jetpbpb1_v2->GetEntries("jet80")/jetpbpb1_v2->GetEntries("jet55&&jet80");
  //cout<<"pbpb prescl3 = "<<presclpbpb3<<endl;//1.99871
  Float_t presclpp3 = (Float_t)jetpp1_v2->GetEntries("jet80")/jetpp1_v2->GetEntries("jet40&&jet80");
  cout<<"pp prescl3 = "<<presclpp3<<endl; //9.24968
  /*
  jetpbpb1_v2->Project("hpbpb1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01");
  hpbpb1->Print("base");
  divideBinWidth(hpbpb1);

  jetpbpb2_v2->Project("hpbpb2","pt","abs(eta)<2&&jet65&&!jet80&&chMax/pt>0.01");
  hpbpb2->Print("base");
  divideBinWidth(hpbpb2);

  jetpbpb3_v2->Project("hpbpb3","pt","1.9987"*pbpb3);
  hpbpb3->Print("base");
  divideBinWidth(hpbpb3);
  */
  jetpp1_v2->Project("hpp1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01");
  hpp1->Print("base");
  //divideBinWidth(hpp1);
  //hpp1->Scale(1./3.083e11);
  //hpp1->Scale(1./4);

  jetpp2_v2->Project("hpp2","pt","abs(eta)<2&&jet60&&!jet80&&chMax/pt>0.01");
  hpp2->Print("base");
  //divideBinWidth(hpp2);
  //hpp2->Scale(1./3.083e11);
  //hpp2->Scale(1./4);

  jetpp2_v2->Project("hpp3","pt","9.25038"*pp3);
  //9.25038 - ak5
  //9.24955 - ak4
  //9.24968 - ak3
  hpp3->Print("base");
  //divideBinWidth(hpp3);
  //hpp3->Scale(1./3.083e11);
  //hpp3->Scale(1./4);

  //scale the PbPb histograms before adding them
  //we have to scale them according to the lumi of the Jet80 file. 
  // HLT file  |   Lumi
  // HLT_80    |   150 mub-1
  // HLT_65    |   12.1 mub-1
  // HLT_55    |   0.38 mub-1
  // 
  // therefore scale for HLT_55 = 150/0.38 = 394.73684
  // scale for HLT_65 = 150/12.1 = 12.3967

  //hpbpb2->Scale(12.3867);
  //hpbpb3->Scale(394.7368);

  //add the histograms
  /*
  hpbpbComb->Add(hpbpb1,1);
  hpbpbComb->Add(hpbpb2,1);
  hpbpbComb->Add(hpbpb3,1);
  hpbpbComb->Print("base");
  */
  hppComb->Add(hpp1,1);
  hppComb->Add(hpp2,1);
  hppComb->Add(hpp3,1);
  hppComb->Print("base");

  

  /*
  TCanvas *c1 = new TCanvas("c1","",800,600);
  c1->SetLogy();
  hpbpbComb->SetMarkerStyle(29);
  //hpbpbComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}");
  hpbpbComb->SetYTitle("counts");
  hpbpbComb->SetXTitle("Jet p_{T} GeV/c");

  TF1 *fPowerLaw = new TF1("fPowerLaw","[0]*pow(x+[1],[2])");
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Fit("fPowerLaw","","",30,300);
  hpbpbComb->Draw();
  hpbpb3->SetMarkerStyle(24);
  hpbpb3->SetMarkerColor(kRed);
  hpbpb3->Draw("same");
  hpbpb2->SetMarkerStyle(25);
  hpbpb2->SetMarkerColor(kBlue);
  hpbpb2->Draw("same");
  hpbpb1->SetMarkerStyle(26);
  hpbpb1->SetMarkerColor(kGreen);
  hpbpb1->Draw("same");
  TLegend *title = myLegend(0.54,0.65,0.85,0.9);
  title->AddEntry(hpbpbComb,"PbPb Merged","pl");
  title->AddEntry(hpbpb3,"w_{3} * (HLT_55 && !HLT_65 && !HLT_80)","pl");
  title->AddEntry(hpbpb2,"HLT_65 && !HLT_80","pl");
  title->AddEntry(hpbpb1,"HLT_80","pl");
  title->SetTextSize(0.03);
  title->Draw();
  drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20);  
  drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20);
  c1->SaveAs("pbpb_2013_pt_combined.gif","RECREATE");
  */

  //plot the statistical uncertainty here
  //statistical error/meanvalue as a function of pt for the combined spectra. 
  /*
  TCanvas *c2 = new TCanvas("c2","",800,600);
  //TH1F* hPbPb_Uncert = (TH1F*)hpbpbComb->Clone("hPbPb_Uncert");
 
  TH1F* hPbPb_Uncert = new TH1F("hPbPb_Uncert","",30,0,300);
 
  for(int i = 1;i<=hpbpbComb->GetNbinsX();i++){
    
    double val = hpbpbComb->GetBinContent(i);
    double valErr = hpbpbComb->GetBinError(i);
    double uncert = (double)valErr/val;
    cout<<"uncert = "<<uncert<<endl;
    hPbPb_Uncert->SetBinContent(i,uncert);
    hPbPb_Uncert->SetBinError(i,0);
  }

  hPbPb_Uncert->SetYTitle("uncertainty");
  hPbPb_Uncert->SetXTitle("p_{T} GeV/c");
  hPbPb_Uncert->Draw();
  drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20);  
  drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20);
  c2->SaveAs("pbpb_2013_hlt_merge_scaled_uncert.gif","RECREATE");
  */
  
  
  TCanvas *c2 = new TCanvas("c2","",800,600);
  c2->SetLogy();
  TH1F* hPPComb = (TH1F*)hppComb->Clone("hPPComb");
  //TH1F* hPPComb_bins = rebin_yaxian(hppComb,"hPPComb_bins");
  
  hPPComb->Scale(1./3.083e11);
  hPPComb->Print("base");
  hPPComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}");
  hPPComb->SetXTitle("Jet p_{T} GeV/c");
  //hPPComb_bins->Scale(1./3.083e11);
  //hPPComb_bins->Print("base");
  //hPPComb_bins->Scale(1./4);
  //divideBinWidth(hPPComb_bins);

  hPPComb->Scale(1./4);
  divideBinWidth(hPPComb);

  TF1 *fPowerLaw = new TF1("fPowerLaw","[0]/pow(x,[1])");
  hPPComb->Fit("fPowerLaw","","",25,500);
  hPPComb->Fit("fPowerLaw","","",25,500);
  hPPComb->Fit("fPowerLaw","","",25,500);
  hPPComb->Fit("fPowerLaw","","",25,500);
  hPPComb->Fit("fPowerLaw","","",25,500);
  hPPComb->SetMarkerColor(kBlue);
  hPPComb->SetMarkerStyle(26);
  hPPComb->SetTitle("PP2013 ak3PF");
  hPPComb->Draw();

  //hPPComb_bins->SetMarkerColor(kRed);
  //hPPComb_bins->SetMarkerStyle(23);
  //hPPComb_bins->Draw("same");

  c2->SaveAs("pp_2013_ak3_pt_evt_frac_merged.gif","RECREATE");

  TCanvas *c5 = new TCanvas("c5","",800,600);
  TH1F* hppFunc = (TH1F*)functionHist(fPowerLaw,hppComb,"Fit Function p_{T} spectra PP 2013 merged");
  TH1F* hPPRatio = (TH1F*)hppComb->Clone("hPPRatio");
  hPPRatio->Divide(hppFunc);
  hPPRatio->SetTitle("Spectra to Fit Ratio");
  hPPRatio->SetXTitle("Jet p_{T} GeV/c");
  hPPRatio->SetYTitle("Measured data/Fit");
  hPPRatio->SetMarkerStyle(8);
  hPPRatio->SetMarkerColor(4);
  hPPRatio->Draw();
  c5->SaveAs("pp_2013_merged_spectra_fit_comp.gif","RECREATE");
  

  
  TFile *fpbpbunfo = TFile::Open("result-2013-akPu3PF-cent-6-isFineBin-0/pbpb_pp_merged_chmx_pt_Unfo_2013_akPu3PF_cent_6_isFineBin_0.root");
  TH1F* hppUnfo = (TH1F*)fpbpbunfo->Get("Unfolded_cent6");
  TH1F* hPPGen = (TH1F*)fpbpbunfo->Get("hGen_cent6");
  hppUnfo->Print("base");
  hPPGen->Print("base");

  hPPGen->Scale(1./4);
  divideBinWidth(hPPGen);

  hppUnfo->Scale(1./3.083e11);
  hppUnfo->Scale(1./4);
  divideBinWidth(hppUnfo);

  hppUnfo->Divide(hPPGen);

  TCanvas *c6 = new TCanvas("c6","",800,600);
  hppUnfo->SetMarkerStyle(21);
  hppUnfo->SetMarkerColor(kRed);
  hPPGen->SetMarkerStyle(21);
  hPPGen->SetMarkerColor(kBlue);
  hppUnfo->Draw();
  // hPPGen->Draw("same");
  c6->SaveAs("pp_2760GeV_unfold_vs_mc.gif","RECREATE");
  
  
  /*
  TCanvas *c7 = new TCanvas("c7","",800,600);
  c7->SetLogy();
  hPPComb->Draw();
  hPPComb->SetYTitle("");
  hPPComb->SetXTitle("p_{T} GeV/c");
  //hppComb->SetTitle("PP 2013 2.76 TeV ak4PF measured vs unfolded");
  hPPComb->SetMarkerStyle(23);
  hPPComb->SetMarkerColor(kBlue);
  //hppUnfo->SetAxisRange(10,500,"X");
  //hppUnfo->SetMarkerStyle(24);
  //hppUnfo->SetMarkerColor(kRed);
  //hppUnfo->Draw("same");
  
  
  
  TLegend *title5 = myLegend(0.54,0.65,0.85,0.9);
  title5->AddEntry(hppComb,"Measured","pl");
  title5->AddEntry(hppUnfo,"Bayesian iter = 4","pl");
  title5->SetTextSize(0.06);
  title5->Draw();
  gStyle->SetOptStat(0);
  c7->SaveAs("PP2013_measured_vs_unfolded.gif","RECREATE");
  
  //TCanvas 
  */

  //Create output file and save them. 
  TFile f("merge_pp_ak3_HLT_V2.root","RECREATE");
  //hpbpb1->Write();
  //hpbpb2->Write();
  //hpbpb3->Write();
  //hPPComb_bins->Write();
  hpp1->Write();
  hpp2->Write();
  hpp3->Write();
  //hpbpbComb->Write();
  hppComb->Write();
  //hPPComb->Write();
  //hPbPb_Uncert->Write();
  hPPComb->Write();
  hPPGen->Write();
  f.Close();
  
  


}
Beispiel #17
0
void MCefficiency(TString inputmc="/data/wangj/MC2015/Dntuple/pp/revised/ntD_pp_Dzero_kpi_prompt/ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))",TString selmcgenacceptance="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))&&abs(Gtk1eta)<2.0&&abs(Gtk2eta)<2.0&&Gtk1pt>2.0&&Gtk2pt>2.0", TString cut_recoonly="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11", TString cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)",TString label="PP",TString outputfile="test", int useweight=1, int minfit=2,int maxfit=100)
{
 std::cout<<"option="<<useweight<<std::endl;
 selmc=cut;
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetEndErrorSize(0);
  gStyle->SetMarkerStyle(20);
 
  TFile* infMC = new TFile(inputmc.Data());
  TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  ntMC->AddFriend(ntGen);
  

  TTree* nthi = (TTree*)infMC->Get("ntHi");
  ntGen->AddFriend(nthi);
  nthi->AddFriend(ntMC);
  ntMC->AddFriend(nthi);

  if (useweight==0){
       weightfunctiongen="1"; 
       weightfunctionreco="1";  
   }   
  if (useweight==1){
     weightfunctiongen="pthatweight";
     weightfunctionreco="pthatweight";  
  }
  
  //ptweight pp
  if (useweight==2){
    weightfunctiongen="pow(10,-0.168499*Gpt+3.872855+Gpt*Gpt*0.000556)+pow(10,-0.068599*Gpt+2.512265+Gpt*Gpt*0.000331)";  
    weightfunctionreco="pow(10,-0.168499*Dgenpt+3.872855+Dgenpt*Dgenpt*0.000556)+pow(10,-0.068599*Dgenpt+2.512265+Dgenpt*Dgenpt*0.000331)"; 
  }
  //ptweight pbpb 
  if (useweight==3){
    weightfunctiongen="pow(10,-0.091618*Gpt+2.966262+Gpt*Gpt*0.000524)+pow(10,-0.167553*Gpt+3.800779+Gpt*Gpt*-0.000798) +1.437905+-0.029141*Gpt+0.000146*Gpt*Gpt"; 
    weightfunctionreco="pow(10,-0.091618*Dgenpt+2.966262+Dgenpt*Dgenpt*0.000524)+pow(10,-0.167553*Dgenpt+3.800779+Dgenpt*Dgenpt*-0.000798) +1.437905+-0.029141*Dgenpt+0.000146*Dgenpt*Dgenpt";
  }
  
   std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl;

  TH1D* hPtMC = new TH1D("hPtMC","",nBins,ptBins);
  TH1D* hPtMCrecoonly = new TH1D("hPtMCrecoonly","",nBins,ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",nBins,ptBins);
  TH1D* hPtGenAcc = new TH1D("hPtGenAcc","",nBins,ptBins);
  TH1D* hPthat = new TH1D("hPthat","",100,0,500);
  TH1D* hPthatweight = new TH1D("hPthatweight","",100,0,500);
  
  ntMC->Project("hPtMC","Dpt",TCut(weightfunctionreco)*(TCut(selmc.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMC);
  ntMC->Project("hPtMCrecoonly","Dpt",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMCrecoonly);
  ntGen->Project("hPtGen","Gpt",TCut(weightfunctiongen)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);
  ntGen->Project("hPtGenAcc","Gpt",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data())));
  divideBinWidth(hPtGenAcc);

  ntMC->Project("hPthat","pthat","1");
  ntMC->Project("hPthatweight","pthat",TCut("1"));

  hPtMC->Sumw2();
  TH1D* hEff = (TH1D*)hPtMC->Clone("hEff");
  hEff->Divide(hPtGen);

  TH1D* hEffReco = (TH1D*)hPtMCrecoonly->Clone("hEffReco");
  hEffReco->Sumw2();
  hEffReco->Divide(hPtGen);

  TH1D* hEffAcc = (TH1D*)hPtGenAcc->Clone("hEffAcc");
  hEffAcc->Sumw2();
  hEffAcc->Divide(hEffAcc,hPtGen,1,1,"b");
  
  TH1D* hEffSelection = (TH1D*)hPtMC->Clone("hEffSelection");
  hEffSelection->Sumw2();
  hEffSelection->Divide(hEffSelection,hPtMCrecoonly,1,1,"b");
  
  TH2F* hemptyEff=new TH2F("hemptyEff","",50,ptBins[0]-5.,ptBins[nBins]+5.,10.,0,1.5);  
  hemptyEff->GetXaxis()->CenterTitle();
  hemptyEff->GetYaxis()->CenterTitle();
  hemptyEff->GetYaxis()->SetTitle("acceptance x #epsilon_{reco} x #epsilon_{sel} ");
  hemptyEff->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hemptyEff->GetXaxis()->SetTitleOffset(0.9);
  hemptyEff->GetYaxis()->SetTitleOffset(0.95);
  hemptyEff->GetXaxis()->SetTitleSize(0.05);
  hemptyEff->GetYaxis()->SetTitleSize(0.05);
  hemptyEff->GetXaxis()->SetTitleFont(42);
  hemptyEff->GetYaxis()->SetTitleFont(42);
  hemptyEff->GetXaxis()->SetLabelFont(42);
  hemptyEff->GetYaxis()->SetLabelFont(42);
  hemptyEff->GetXaxis()->SetLabelSize(0.035);
  hemptyEff->GetYaxis()->SetLabelSize(0.035);  
  hemptyEff->SetMaximum(2);
  hemptyEff->SetMinimum(0.);
  hemptyEff->Draw();

  TH2F* hemptyEffAcc=(TH2F*)hemptyEff->Clone("hemptyEffAcc");
  TH2F* hemptyEffReco=(TH2F*)hemptyEff->Clone("hemptyEffReco");
  TH2F* hemptyEffSelection=(TH2F*)hemptyEff->Clone("hemptyEffSelection");
  
  TCanvas*canvasEff=new TCanvas("canvasEff","canvasEff",1000.,500);
  canvasEff->Divide(2,1);
  canvasEff->cd(1);
  
  hemptyEffAcc->SetYTitle("#alpha");
  hemptyEffAcc->Draw();
  hEffAcc->Draw("same");
  /*
  canvasEff->cd(2);
  hEffReco->GetYaxis()->SetTitleOffset(1.2);
  hemptyEffReco->SetYTitle("#alpha x #epsilon_{reco} ");
  hemptyEffReco->Draw();
  hEffReco->Draw("same");
  canvasEff->cd(3);
  hemptyEffSelection->SetYTitle(" #epsilon_{sel}");
  hemptyEffSelection->Draw();  
  hEffSelection->Draw("same");  
  */
  canvasEff->cd(2);
  hemptyEff->Draw();
  hEff->Draw("same");
  canvasEff->SaveAs(Form("canvasEff_study%s.pdf",Form(label.Data())));
  
  
  TH2F* hemptyPthat=new TH2F("hemptyPthat","",50,0.,500.,10,1e-5,1e9);  
  hemptyPthat->GetXaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->SetTitle("Entries");
  hemptyPthat->GetXaxis()->SetTitle("pthat");
  hemptyPthat->GetXaxis()->SetTitleOffset(0.9);
  hemptyPthat->GetYaxis()->SetTitleOffset(0.95);
  hemptyPthat->GetXaxis()->SetTitleSize(0.05);
  hemptyPthat->GetYaxis()->SetTitleSize(0.05);
  hemptyPthat->GetXaxis()->SetTitleFont(42);
  hemptyPthat->GetYaxis()->SetTitleFont(42);
  hemptyPthat->GetXaxis()->SetLabelFont(42);
  hemptyPthat->GetYaxis()->SetLabelFont(42);
  hemptyPthat->GetXaxis()->SetLabelSize(0.035);
  hemptyPthat->GetYaxis()->SetLabelSize(0.035);  
  hemptyPthat->SetMaximum(2);
  hemptyPthat->SetMinimum(0.);


  TH2F* hemptySpectra=new TH2F("hemptySpectra","",50,0.,130.,10,1,1e5);  
  hemptySpectra->GetXaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->SetTitle("Entries");
  hemptySpectra->GetXaxis()->SetTitle("p_{T}");
  hemptySpectra->GetXaxis()->SetTitleOffset(0.9);
  hemptySpectra->GetYaxis()->SetTitleOffset(0.95);
  hemptySpectra->GetXaxis()->SetTitleSize(0.05);
  hemptySpectra->GetYaxis()->SetTitleSize(0.05);
  hemptySpectra->GetXaxis()->SetTitleFont(42);
  hemptySpectra->GetYaxis()->SetTitleFont(42);
  hemptySpectra->GetXaxis()->SetLabelFont(42);
  hemptySpectra->GetYaxis()->SetLabelFont(42);
  hemptySpectra->GetXaxis()->SetLabelSize(0.035);
  hemptySpectra->GetYaxis()->SetLabelSize(0.035);  

  TH2F* hemptyPthatWeighted=(TH2F*)hemptyPthat->Clone("hemptyPthatWeighted");
  hemptyPthatWeighted->GetXaxis()->SetTitle("pthat reweighted");
  
  TCanvas*canvasPthat=new TCanvas("canvasPthat","canvasPthat",1000.,500);
  canvasPthat->Divide(2,1);
  canvasPthat->cd(1);
  gPad->SetLogy();
  hemptyPthat->Draw("same");
  hPthat->Draw("same");
  canvasPthat->cd(2);
  gPad->SetLogy();
  hemptyPthatWeighted->Draw();
  hPthatweight->Draw("same");
 // canvasPthat->SaveAs(Form("canvasPthat_%s.pdf",Form(label.Data())));
  
  TCanvas*canvasSpectra=new TCanvas("canvasSpectra","canvasSpectra",1000.,500);
  canvasSpectra->Divide(2,1);
  canvasSpectra->cd(1);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtMC->Draw("same");
  canvasSpectra->cd(2);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtGen->Draw("same");
  //canvasSpectra->SaveAs(Form("canvasSpectra_%s.pdf",Form(label.Data())));

  TFile *fout=new TFile(outputfile.Data(),"recreate");
  fout->cd();
  hPtGen->Write();
  hEffAcc->Write();
  hEffReco->Write();
  hEffSelection->Write();
  hEff->Write();
  hPtMC->Write();
  fout->Close();  

}