void derivefromprofile() { auto file = config.getfile_djt("mcPbqcd"); auto nt = (TTree *)file->Get("nt"); for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; auto p = new TProfile(Form("p%d%d",b1,b2),Form("prof"),100,0,200); nt->Project(p->GetName(),"(subid2 == 0 && refpt2 > 20):jtptSignal2",Form("weight*(jtpt1>100&&bin>=%d && bin<%d)",b1,b2)); profs.push_back(p); auto f = new TF1(Form("f%d%d",b1,b2),"exp(-[0]*exp(-[1]*x))"); f->SetParameters(100,0.1); p->Fit(f); fs.push_back(f); float median = -1/f->GetParameter(1)*log(-1/f->GetParameter(0)*log(0.5)); auto c = getc(); TLatex *Tl = new TLatex(); p->SetMinimum(0);p->SetMaximum(1); p->Draw(); f->Draw("same"); Tl->DrawLatexNDC(0.6,0.4,Form("PbPb bin %d-%d",b1,b2)); Tl->DrawLatexNDC(0.6,0.35,Form("median = %.2f",median)); TLine *l1 = new TLine(median,0,median, f->Eval(median)); l1->Draw(); TLine *l2 = new TLine(0,0.5,median, f->Eval(median)); l2->Draw(); SavePlot(c,Form("fit%d%d",b1,b2)); } }
void doPlotXJ(TString outname, int inc_or_bjet=1, bool useMC = true, bool addppunc = false) { macro m(outname); // bool useMC = true; // bool addppunc = false; TFile *fin = new TFile("results_redoana_default/xJdphi.root"); TFile *fpps1 = new TFile("results_redoana_ppsmear1/xJdphi.root"); TFile *fpps2 = new TFile("results_redoana_ppsmear2/xJdphi.root"); TFile *fpps3 = new TFile("results_redoana_ppsmear3/xJdphi.root"); string species = "inc"; if(inc_or_bjet) species = "bjt"; TH1F *hData010 = (TH1F*) fin->Get(Form("xJ_data_%s_0_10",species.c_str())); TH1F *hData1030 = (TH1F*) fin->Get(Form("xJ_data_%s_10_30",species.c_str())); TH1F *hData30100 = (TH1F*) fin->Get(Form("xJ_data_%s_30_100",species.c_str())); TH1F *hDataPP = (TH1F*) fin->Get(Form("xJ_data_%s_pp",species.c_str())); TH1F *hMC010; TH1F *hMC1030; TH1F *hMC30100; TH1F *hMCPP = (TH1F*) fin->Get(Form("xJ_mc_%s_pp",species.c_str())); if (useMC) { hMC010 = (TH1F*) fin->Get(Form("xJ_mc_%s_0_10",species.c_str())); hMC1030 = (TH1F*) fin->Get(Form("xJ_mc_%s_10_30",species.c_str())); hMC30100 = (TH1F*) fin->Get(Form("xJ_mc_%s_30_100",species.c_str())); } else { hMC010 = (TH1F*) fpps1->Get(Form("xJ_data_%s_pp",species.c_str())); hMC1030 = (TH1F*) fpps2->Get(Form("xJ_data_%s_pp",species.c_str())); hMC30100 = (TH1F*) fpps3->Get(Form("xJ_data_%s_pp",species.c_str())); } // if(inc_or_bjet) hMCPP = (TH1F*) fin->Get(Form("xJ_mc_%s_pp;1",species.c_str())); Normalize({hMC010,hMC1030,hMC30100,hMCPP}); //temporary fix vector<float> syserr; if (inc_or_bjet) syserr = {0.023,0.018,0.014,0.008}; //0-10%, 10-30%, 30-100%, pp else syserr = {0.023,0.016,0.010,0.007}; int syscolor = inc_or_bjet ? kredLight : kblueLight; int color = kblue; if(inc_or_bjet) color=kred; auto hData010sys = makesysplot(hData010,syserr[0],syscolor); auto hData1030sys = makesysplot(hData1030,syserr[1],syscolor); auto hData30100sys = makesysplot(hData30100,syserr[2],syscolor); auto hDataPPsys = makesysplot(hDataPP,syserr[3],syscolor); auto hSmPP010sys = makesysplot(hMC010,syserr[3],syscolor); auto hSmPP1030sys = makesysplot(hMC1030,syserr[3],syscolor); auto hSmPP30100sys = makesysplot(hMC30100,syserr[3],syscolor); hSmPP30100sys->SetFillStyle(3005); hSmPP30100sys->SetFillColor(color); hSmPP1030sys->SetFillStyle(3005); hSmPP1030sys->SetFillColor(color); hSmPP010sys->SetFillStyle(3005); hSmPP010sys->SetFillColor(color); lumi_sqrtS = lumi_sqrtSPbPb; TCanvas *c1=new TCanvas("c1","c1",600,600); hData010->SetMarkerColor(color); hData010->SetLineColor(color); hMC010->SetLineColor(color); hData010->GetXaxis()->CenterTitle(1); hData010->GetYaxis()->CenterTitle(1); hData010->SetYTitle("Event fraction"); hData010->Draw(); hData010sys->Draw("e2,same"); if (addppunc) hSmPP010sys->Draw("e2,same"); hData010->Draw("same"); //b/c systematics should be on the back hMC010->SetMarkerSize(0); hMC010->Draw("h,same"); CMS_lumi(c1, iPeriod, iPos ); TLegend *l =new TLegend(0.43,0.63,0.9,0.81); l->AddEntry(hData010,"Data","P"); l->AddEntry(hMC010,useMC ? "Pythia6" : "pp-based reference","l"); if(inc_or_bjet)l->SetHeader("b dijets"); else l->SetHeader("Inclusive dijets"); l->SetFillStyle(0); l->Draw(); SavePlot(c1,"xJ010"+species); TCanvas *c2=new TCanvas("c2","c2",600,600); hData1030->SetMarkerColor(color); hData1030->SetLineColor(color); hMC1030->SetLineColor(color); hData1030->GetXaxis()->CenterTitle(1); hData1030->GetYaxis()->CenterTitle(1); hData1030->SetYTitle("Event fraction"); hData1030->Draw(); hData1030sys->Draw("e2,same"); if (addppunc) hSmPP1030sys->Draw("e2,same"); hData1030->Draw("same"); hMC1030->SetMarkerSize(0); hMC1030->Draw("h,same"); CMS_lumi(c2, iPeriod, iPos ); l->Draw(); SavePlot(c2,"xJ1030"+species); TCanvas *c3=new TCanvas("c3","c3",600,600); hData30100->SetMarkerColor(color); hData30100->SetLineColor(color); hMC30100->SetLineColor(color); hData30100->GetXaxis()->CenterTitle(1); hData30100->GetYaxis()->CenterTitle(1); hData30100->SetYTitle("Event fraction"); hData30100->Draw(); hData30100sys->Draw("e2,same"); if (addppunc) hSmPP30100sys->Draw("e2,same"); hData30100->Draw("same"); hMC30100->SetMarkerSize(0); hMC30100->Draw("h,same"); CMS_lumi(c3, iPeriod, iPos ); l->Draw(); SavePlot(c3,"xJ30100"+species); lumi_sqrtS = lumi_sqrtSpp; TCanvas *c4=new TCanvas("c4","c4",600,600); hDataPP->SetMarkerColor(color); hDataPP->SetLineColor(color); hMCPP->SetLineColor(color); hDataPP->GetXaxis()->CenterTitle(1); hDataPP->GetYaxis()->CenterTitle(1); hDataPP->SetYTitle("Event fraction"); hDataPP->Draw(); hDataPPsys->Draw("e2,same"); hDataPP->Draw("same"); hMCPP->SetMarkerSize(0); hMCPP->Draw("h,same"); CMS_lumi(c4, iPeriod, iPos ); l->Clear(); l->AddEntry(hDataPP,"Data","P"); l->AddEntry(hMCPP,"Pythia6","l"); if(inc_or_bjet)l->SetHeader("b dijets"); else l->SetHeader("Inclusive dijets"); l->Draw(); SavePlot(c4,"xJpp"+species); }
void BKGPrediction_4(){ gROOT->Reset(); gStyle->SetCanvasColor(0); gStyle->SetFrameBorderMode(0); gStyle->SetOptStat(0); gStyle->SetPalette(1,0); gStyle->SetTitleX(0.5); gStyle->SetTitleY(0.96); gStyle->SetPaintTextFormat(".2f"); RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ; float XMassWidth=200; float XMassBin=15; float XMassMin=0; float XMassMax=XMassWidth; float MAX = XMassWidth*XMassBin;bool save=true; float lep1PtCut=10; float tauPtCut=35; int bTagCut=1; float deltaRCut=1; float MassSvfitCut=10000; float METCut1 = 100; float METCut2 = 50; float MassVisCut1=0; float MassVisCut2=0; const int N = 12; Double_t xbins[N] = {0,300,600,800,1000,1200,1400,1600,1900,2200,2500,3000}; for(int i=0; i<1; i++){ TH1F *histo_PRE1 = new TH1F("histo_PRE1","histo_PRE1",N-1,xbins); TH1F *histo_DAT1 = new TH1F("histo_DAT1","histo_DAT1",N-1,xbins); TH1F *ERR1 = new TH1F("ERR1", "ERR1", N-1,xbins); THStack *hs1 = new THStack("hs1","hs1"); TH1F *histo_PRE2 = new TH1F("histo_PRE2","histo_PRE2",N-1,xbins); TH1F *histo_DAT2 = new TH1F("histo_DAT2","histo_DAT2",N-1,xbins); TH1F *ERR2 = new TH1F("ERR2", "ERR2", N-1,xbins); THStack *hs2 = new THStack("hs2","hs2"); TH1F *histo_PRE3 = new TH1F("histo_PRE3","histo_PRE3",N-1,xbins); TH1F *histo_DAT3 = new TH1F("histo_DAT3","histo_DAT3",N-1,xbins); TH1F *ERR3 = new TH1F("ERR3", "ERR3", N-1,xbins); THStack *hs3 = new THStack("hs3","hs3"); TH1F *histo_PRE4 = new TH1F("histo_PRE4","histo_PRE4",N-1,xbins); TH1F *histo_DAT4 = new TH1F("histo_DAT4","histo_DAT4",N-1,xbins); TH1F *ERR4 = new TH1F("ERR4", "ERR4", N-1,xbins); THStack *hs4 = new THStack("hs4","hs4"); TH1F *histo_PRE5 = new TH1F("histo_PRE5","histo_PRE5",N-1,xbins); TH1F *histo_DAT5 = new TH1F("histo_DAT5","histo_DAT5",N-1,xbins); TH1F *ERR5 = new TH1F("ERR5", "ERR5", N-1,xbins); THStack *hs5 = new THStack("hs5","hs5"); TCanvas* c1 = new TCanvas("c1","c1",0,0,800,600); BackgroundEstimation("MuoMuo",XMassWidth,XMassBin,XMassMin,XMassMax,histo_PRE1,histo_DAT1,ERR1,hs1,lep1PtCut,tauPtCut,bTagCut,METCut1,deltaRCut,MassSvfitCut,MassVisCut2); SavePlot(c1,MAX,histo_PRE1,histo_DAT1,ERR1,hs1,XMassWidth,XMassBin,XMassMin,XMassMax,"MuoMuo",save,lep1PtCut,tauPtCut,bTagCut,METCut1,deltaRCut,MassSvfitCut,MassVisCut2); TCanvas* c2 = new TCanvas("c2","c2",0,0,800,600); BackgroundEstimation("EleMuo",XMassWidth,XMassBin,XMassMin,XMassMax,histo_PRE2,histo_DAT2,ERR2,hs2,lep1PtCut,tauPtCut,bTagCut,METCut1,deltaRCut,MassSvfitCut,MassVisCut1); SavePlot(c2,MAX,histo_PRE2,histo_DAT2,ERR2,hs2,XMassWidth,XMassBin,XMassMin,XMassMax,"EleMuo",save,lep1PtCut,tauPtCut,bTagCut,METCut1,deltaRCut,MassSvfitCut,MassVisCut1); TCanvas* c3 = new TCanvas("c3","c3",0,0,800,600); BackgroundEstimation("EleEle",XMassWidth,XMassBin,XMassMin,XMassMax,histo_PRE3,histo_DAT3,ERR3,hs3,lep1PtCut,tauPtCut,bTagCut,METCut1,deltaRCut,MassSvfitCut,MassVisCut2); SavePlot(c3,MAX,histo_PRE3,histo_DAT3,ERR3,hs3,XMassWidth,XMassBin,XMassMin,XMassMax,"EleEle",save,lep1PtCut,tauPtCut,bTagCut,METCut1,deltaRCut,MassSvfitCut,MassVisCut2); TCanvas* c4 = new TCanvas("c4","c4",0,0,800,600); BackgroundEstimation("EleTau",XMassWidth,XMassBin,XMassMin,XMassMax,histo_PRE4,histo_DAT4,ERR4,hs4,lep1PtCut,tauPtCut,bTagCut,METCut2,deltaRCut,MassSvfitCut,MassVisCut1); SavePlot(c4,MAX,histo_PRE4,histo_DAT4,ERR4,hs4,XMassWidth,XMassBin,XMassMin,XMassMax,"EleTau",save,lep1PtCut,tauPtCut,bTagCut,METCut2,deltaRCut,MassSvfitCut,MassVisCut1); TCanvas* c5 = new TCanvas("c5","c5",0,0,800,600); BackgroundEstimation("MuoTau",XMassWidth,XMassBin,XMassMin,XMassMax,histo_PRE5,histo_DAT5,ERR5,hs5,lep1PtCut,tauPtCut,bTagCut,METCut2,deltaRCut,MassSvfitCut,MassVisCut1); SavePlot(c5,MAX,histo_PRE5,histo_DAT5,ERR5,hs5,XMassWidth,XMassBin,XMassMin,XMassMax,"MuoTau",save,lep1PtCut,tauPtCut,bTagCut,METCut2,deltaRCut,MassSvfitCut,MassVisCut1); } }
void findfunc() { //dijet case // auto fmcppbjt = config.getfile_djt("mcppbfa"); // auto nt = (TTree *)fmcppbjt->Get("nt"); // seth(18,40,220); // auto hd = geth("hd"); // auto hn = geth("hn"); // nt->Project("hd","jtpt2","weight*(pthat>80 && jtpt1>100 && abs(refparton_flavorForB1)==5 && abs(refparton_flavorForB2)!=5 && dphi21>2.1)"); // nt->Project("hn","jtpt2","weight*(pthat>80 && jtpt1>100 && abs(refparton_flavorForB1)==5 && abs(refparton_flavorForB2)!=5 && dphi21>2.1 && discr_csvV1_2>0.9)"); // hn->Divide(hn,hd,1,1,"B") // hn->Fit(f) auto fpp = new TF1("fpp","expo",40,200); auto f1 = new TF1("fPb1","expo",40,200); auto f2 = new TF1("fPb2","expo",40,200); auto f3 = new TF1("fPb3","expo",40,200); seth(18,40,200); auto ntpp = (TTree *)config.getfile_inc("mcppqcd")->Get("nt"); auto hd = geth("hd"); auto hn = geth("hn",";p_{T} [GeV];mistag probability"); ntpp->Project("hd","jtpt","weight*(pthat>50 && refpt>20 && abs(refparton_flavorForB)!=5)"); ntpp->Project("hn","jtpt","weight*(pthat>50 && refpt>20 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn->Divide(hn,hd,1,1,"B"); // hn->Scale(1/hn->Integral()); hn->Fit(fpp); auto nt = (TTree *)config.getfile_inc("mcPbqcd")->Get("nt"); auto hd1 = geth("hd1"); auto hn1 = geth("hn1",";p_{T} [GeV];mistag probability"); nt->Project("hd1","jtpt","weight*(pthat>50 && refpt>20 && bin < 20 && abs(refparton_flavorForB)!=5)"); nt->Project("hn1","jtpt","weight*(pthat>50 && refpt>20 && bin < 20 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn1->Divide(hn1,hd1,1,1,"B"); // hn1->Scale(1/hn1->Integral()); hn1->Fit(f1); auto hd2 = geth("hd2"); auto hn2 = geth("hn2",";p_{T} [GeV];mistag probability"); nt->Project("hd2","jtpt","weight*(pthat>50 && refpt>20 && bin>=20 && bin<60 && abs(refparton_flavorForB)!=5)"); nt->Project("hn2","jtpt","weight*(pthat>50 && refpt>20 && bin>=20 && bin<60 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn2->Divide(hn2,hd2,1,1,"B"); // hn2->Scale(1/hn2->Integral()); hn2->Fit(f2); auto hd3 = geth("hd3"); auto hn3 = geth("hn3",";p_{T} [GeV];mistag probability"); nt->Project("hd3","jtpt","weight*(pthat>50 && refpt>20 && bin>=60 && abs(refparton_flavorForB)!=5)"); nt->Project("hn3","jtpt","weight*(pthat>50 && refpt>20 && bin>=60 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)"); hn3->Divide(hn3,hd3,1,1,"B"); // hn3->Scale(1/hn3->Integral()); hn3->Fit(f3); // because of backward imcompatibility with root version on polui cout<<"auto fpp = new TF1(\"fpp\",\"expo\","<<fpp->GetXmin()<<","<<fpp->GetXmax()<<");"<<endl; cout<<"auto fPb1 = new TF1(\"fPb1\",\"expo\","<<f1->GetXmin()<<","<<f1->GetXmax()<<");"<<endl; cout<<"auto fPb2 = new TF1(\"fPb2\",\"expo\","<<f2->GetXmin()<<","<<f2->GetXmax()<<");"<<endl; cout<<"auto fPb3 = new TF1(\"fPb3\",\"expo\","<<f3->GetXmin()<<","<<f3->GetXmax()<<");"<<endl; cout<<"fpp->SetParameters("<<fpp->GetParameter(0)<<","<<fpp->GetParameter(1)<<");"<<endl; cout<<"fPb1->SetParameters("<<f1->GetParameter(0)<<","<<f1->GetParameter(1)<<");"<<endl; cout<<"fPb2->SetParameters("<<f2->GetParameter(0)<<","<<f2->GetParameter(1)<<");"<<endl; cout<<"fPb3->SetParameters("<<f3->GetParameter(0)<<","<<f3->GetParameter(1)<<");"<<endl; // hn->SetMinimum(0); // hn1->SetMinimum(0); // hn2->SetMinimum(0); // hn3->SetMinimum(0); auto fout = new TFile("../correctionfiles/BXmistagfunc.root","recreate"); fout->cd(); fpp->Write(); f1->Write(); f2->Write(); f3->Write(); hn->Write(); hn1->Write(); hn2->Write(); hn3->Write(); auto c = getc(); f1->SetLineColor(kRed); f2->SetLineColor(kGreen); f3->SetLineColor(kOrange); fpp->SetLineColor(kBlue); auto l = getLegend(); l->AddEntry(fpp,"pp","L"); l->AddEntry(f1,"bin<20","L"); l->AddEntry(f2,"20<bin<60","L"); l->AddEntry(f3,"bin>60","L"); f1->GetXaxis()->SetTitle("p_{T} [GeV]"); f1->GetYaxis()->SetTitle("mistag probability"); f1->Draw(); f2->Draw("same"); f3->Draw("same"); fpp->Draw("same"); l->Draw(); SavePlot(c,"func"); float x = 0.55; float y = 0.75; auto t= new TLatex(); auto cpp = getc(); hn->Draw(); fpp->Draw("same"); t->DrawLatexNDC(x,y,"pp"); SavePlot(cpp,"pp"); auto c1 = getc(); hn1->Draw(); f1->Draw("same"); t->DrawLatexNDC(x,y,"PbPb 0-10%"); SavePlot(c1,"bin_0_20"); auto c2 = getc(); hn2->Draw(); f2->Draw("same"); t->DrawLatexNDC(x,y,"PbPb 10-30%"); SavePlot(c2,"bin_20_60"); auto c3 = getc(); hn3->Draw(); f3->Draw("same"); t->DrawLatexNDC(x,y,"PbPb 30-100%"); SavePlot(c3,"bin_60"); fout->Close(); }
void eclipsederive(bool data = false, int mode = 0) { TString mcdt(data ? "dt" : "mc"); macro m(Form("eclipsederive0707_%s_%d",mcdt.Data(),mode)); // //just to know NS fractions in b-jet data // deriveNSfractions(data,mode,true); // cout<<"NSfracinc"<<mcdt<<" = {"; // for (unsigned i=0;i<binbounds.size()-1;i++) { // cout<<NSfrac[i]; // if (i<binbounds.size()-2) cout<<","; // } // cout<<"};"<<endl; deriveNSfractions(data,mode); derivefromNS(data); //derivefromprofile(); auto ggg = new TGraph(meanb.size(),&meanb[0],&prob[0]); auto cc = getc(); ggg->Draw("AP"); SavePlot(cc,"probvsbin"); vector<float> x = binmean; vector<float> xerr; vector<float> y,yerr; vector<float> z,zerr; for (unsigned i=1;i<binbounds.size();i++) { // int b1 = binbounds[i-1]; // int b2 = binbounds[i]; // x.push_back((b1+b2)/2); xerr.push_back(0); y.push_back(fs[i-1]->GetParameter(0)); yerr.push_back(fs[i-1]->GetParError(0)); z.push_back(fs[i-1]->GetParameter(1)); zerr.push_back(fs[i-1]->GetParError(1)); } auto c2 = getc(); auto g= new TGraphErrors(x.size(),&x[0],&y[0],&xerr[0],&yerr[0]); g->Draw(); SavePlot(c2,"par0cent"); auto c3 = getc(); auto g2 = new TGraphErrors(x.size(),&x[0],&z[0],&xerr[0],&zerr[0]); g2->Draw(); SavePlot(c3,"par1cent"); std::ofstream res (plotfoldername+"/eclipserapams.txt", std::ofstream::out); res<<"binmean"<<mcdt<<" = {"; for (unsigned i=0;i<binmean.size();i++) { res<<binmean[i]; if (i<binmean.size()-1) res<<","; } res<<"};"<<endl; res<<"NSfracinc"<<mcdt<<" = {"; for (unsigned i=0;i<binbounds.size()-1;i++) { res<<NSfrac[i]; if (i<binbounds.size()-2) res<<","; } res<<"};"<<endl; res<<"par0"<<mcdt<<" = {"; for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; res<<fs[i-1]->GetParameter(0); if (i<binbounds.size()-1) res<<","; } res<<"};"<<endl; res<<"par1"<<mcdt<<" = {"; for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; res<<fs[i-1]->GetParameter(1); if (i<binbounds.size()-1) res<<","; } res<<"};"<<endl; res.close(); }
void deriveNSfractions(bool data, int mode, bool bjet = false) { if (mode==0) { for (unsigned i=0;i<binbounds.size()-1;i++) NSfrac.push_back(1); return; } if (mode==2) { for (unsigned i=0;i<binbounds.size()-1;i++) NSfrac.push_back(0.7); return; } if (mode==4) { for (unsigned i=0;i<binbounds.size()-1;i++) NSfrac.push_back(1.3); return; } TString fnpp; if (bjet) fnpp = data ? "dtppjpf" : "mcppbfa"; else fnpp = data ? "dtppjpf" : "mcppqcd"; auto filepp = config.getfile_djt(fnpp); seth(1,0,PI); auto hppNS = geth("hppNS"); auto hppAS = geth("hppAS"); Fill(filepp,[&] (dict &d) { if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return; if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hppNS->Fill(d["dphi21"],d["weight"]); if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hppAS->Fill(d["dphi21"],d["weight"]); }); float a_pp = hppNS->Integral()/hppAS->Integral(); cout<<"a_pp "<<a_pp<<endl; TString fnPbPb; if (bjet) fnPbPb = data ? "dtPbbjt" : "mcPbbfa"; else fnPbPb = data ? "dtPbjcl" : "mcPbqcd"; auto file = config.getfile_djt(fnPbPb); vector<TString> histn; for (unsigned i=0;i<binbounds.size()-1;i++) histn.push_back(Form("PbPb%d%d",binbounds[i],binbounds[i+1])); setv(histn); auto hPbPbNS = getv("hPbPbNS"); auto hPbPbAS = getv("hPbPbAS"); auto hPbPbNSsig = getv("hPbPbNSsig"); Fill(file,[&] (dict &d) { int b = getbin(d["bin"]); float w = d["weight"]; if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return; if (bjet && d["pairCode21"]==0) w*=processweight((int)d["bProdCode"]); if (!data && d["pthat"]<50) return; if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hPbPbNS[b]->Fill(d["dphi21"],d["weight"]); if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hPbPbAS[b]->Fill(d["dphi21"],d["weight"]); if (!data && d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13 && (d["subid2"]==0 && d["refpt2"]>20)) hPbPbNSsig[b]->Fill(d["dphi21"],d["weight"]); }); vector<double> binmean; vector<double> nsfractrue; vector<double> nsfracest; for (unsigned i=0;i<binbounds.size()-1;i++) { float a_PbPb = hPbPbNS[i]->Integral()/hPbPbAS[i]->Integral(); float x = (1-a_pp/a_PbPb)/(1-a_pp); NSfrac.push_back(mode==1 ? x : -1);// = old stupid adding of the signal : 2-x); // cout<<binbounds[i]<<" - "<<binbounds[i+1]<<" = "<<NSfrac[i]<<endl; nsfractrue.push_back(1-hPbPbNSsig[i]->Integral()/hPbPbNS[i]->Integral()); nsfracest.push_back(NSfrac[NSfrac.size()-1]); binmean.push_back((binbounds[i]+binbounds[i+1])/2); } auto c = getc(); TGraph *g = new TGraph(binbounds.size()-1,&binmean[0],&nsfractrue[0]); g->Draw(); SavePlot(c,bjet ? "bjetfractionofNS" : "incfractionofNS"); auto c2 = getc(); TGraph *g2 = new TGraph(binbounds.size()-1,&binmean[0],&nsfracest[0]); g2->Draw(); SavePlot(c2,bjet ? "bjetfractionofNSdata" : "incfractionofNSdata"); ///////////////////////////// DATA: // bin<20 : 0.93 // bin>=20 && bin<60 : 0.84 // bin>=60 : 0.39 //////////////////////////// }
void derivefromNS(bool data = false) { // float shift = mode == 2 ? -2 : mode*2; //mode = 0,1,2 shift = 0,2,-2 // cout<<"shift = "<<shift<<endl; auto file = config.getfile_djt(data ? "dtPbjcl" : "mcPbqcd"); auto nt = (TTree *)file->Get("nt"); for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; seth(71,38,180); //71,38 auto h = geth(Form("h%d%d",b1,b2)); //allowing one more bin for overflow seth(b2-b1,b1,b2); auto hb = geth(Form("hb%d%d",b1,b2)); TString mcappendix = data ? "" : "&& pthat>50";//"&& subid2!=0 && pthat>50"; //"&& pthat>50";//"&& !(subid2==0 && refpt2>20) && pthat>50"; //"&& pthat>80";// //Form("jtpt2+%f",shift) nt->Project(h->GetName(),"jtpt2", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data())); nt->Project(hb->GetName(),"bin", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data())); ScaleVisibleBins(h,NSfrac[i-1]); h->SetBinContent(1,h->GetBinContent(0)+h->GetBinContent(1)); // auto p = new TProfile(Form("p%d%d",b1,b2),Form("prof"),71,38,180); // nt->Project(p->GetName(),"(subid2 == 0 && refpt2 > 20):jtptSignal2",Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphiSignal21<1.05 && !(subid2==0 && refpt2>20) && pthat>80)",b1,b2)); auto g = getCDFgraph(h); g->GetXaxis()->SetTitle("p_{T,2} threshold [GeV]"); g->GetYaxis()->SetTitle("found fraction"); auto gtemp = getCDFgraph(h); meanb.push_back(hb->GetMean()); prob.push_back(gtemp->Eval(pt)); float c0=g->Eval(50); cout<<"prob at 50: "<<c0<<endl; auto gf = new TFile("graph.root","recreate"); gtemp->Write(); gf->Close(); // auto f = new TF1(Form("f%d%d",b1,b2),"1-[0]*exp(-[1]*(x-40))",40,180); // f->SetParameters(0.1,0.1); // // f->FixParameter(1,0.08); // auto f = new TF1(Form("f%d%d",b1,b2),"TMath::Erf((x-[0])/[1])",40,180); // f->SetParameters(40,10); // f->FixParameter(1,25); auto f = new TF1(Form("f%d%d",b1,b2),"exp(-[0]*exp(-[1]*x))",40,180); f->SetParameters(100,0.1); // f->FixParameter(1,0.11); //!!!!!!!!!! f->SetLineColor(kRed); f->SetLineWidth(2); g->Fit(f,"RM"); fs.push_back(f); binmean.push_back(hb->GetMean()); float median = -1/f->GetParameter(1)*log(-1/f->GetParameter(0)*log(0.5)); Draw({h}); // h->Rebin(2); auto gcoarse = getCDFgraph(h); auto c = getc(); TLatex *Tl = new TLatex(); gcoarse->SetMinimum(0);g->SetMaximum(1); gcoarse->Draw("AP"); f->Draw("same"); Tl->DrawLatexNDC(0.6,0.55,"y=e^{-a e^{-b x} }"); Tl->DrawLatexNDC(0.6,0.50,Form("a = %.1f",f->GetParameter(0))); Tl->DrawLatexNDC(0.6,0.45,Form("b = %.2f",f->GetParameter(1))); Tl->DrawLatexNDC(0.6,0.4,Form("PbPb bin %d-%d",b1,b2)); Tl->DrawLatexNDC(0.6,0.35,Form("median = %.2f",median)); TLine *l1 = new TLine(median,0,median, f->Eval(median)); l1->Draw(); TLine *l2 = new TLine(0,0.5,median, f->Eval(median)); l2->Draw(); // p->SetMarkerColor(kRed); // p->SetMarkerSize(1); // p->Draw("same"); SavePlot(c,Form("fit%d%d",b1,b2));//return; } }
void findtruthpp() { seth(10,0,1); auto hmcppxJTrue = geth("hmcppxJTrue","true;x_{J};Event fractions"); auto hmcppxJTrueTag = geth("hmcppxJTrueTag","true tagged;x_{J};Event fractions"); auto hmcppxJTrueTagCorr = geth("hmcppxJTrueTagCorr","true tagged corrected;x_{J};Event fractions"); TFile *fmcpp = new TFile(config.getFileName_djt("mcppbfa")); Fill(fmcpp,[&] (dict &m) { if (m["pthat"]<pthatcut) return; if (m[pairCodeSB1]!=0) return; // if (m["pthat"]<80) return; // if (m["bProdCode"]!=1) return; float w = m["weight"]*processweight((int)m["bProdCode"]); // float w = m["weight"]; // if (m["bProdCode"]==2) return; float corr = tageffcorrectionpp(m["jtpt1"],m["jteta1"],m[jtptSB],m[jtetaSB]); float wb = w*corr; if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[dphiSB1]>PI23) hmcppxJTrue->Fill(m[jtptSB]/m["jtpt1"],w); if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[dphiSB1]>PI23 && m["discr_csvV1_1"]>0.9 && m[discr_csvV1_SB]>0.9) { hmcppxJTrueTag->Fill(m[jtptSB]/m["jtpt1"],w); hmcppxJTrueTagCorr->Fill(m[jtptSB]/m["jtpt1"],wb); } }); NormalizeAllHists(); plotputmean = true; plotytitle = "Event fractions"; plotdivide = false; // aktstring += "R=0.4 |#eta|<2.0"; // plotsecondline = Form("p_{T,1}>%d GeV, p_{T,2}>%d GeV", (int)pt1cut, (int)pt2cut); // plotthirdline = "#Delta#phi>2/3#pi"; plottextposy = 0.8; plottextposx = 0.2; plotmeanposy = 0.43; plotymax = 0.2; plotymin = 0; plotlegendpos = BottomRight;//TopLeft; aktstring = "pp"; SetMC({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); SetData({hmcppxJTrue}); Draw({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); hmcppxJTrue->SetMinimum(0); hmcppxJTrue->SetMaximum(0.3); hmcppxJTrue->SetLineWidth(2); hmcppxJTrue->SetMarkerStyle(kNone); hmcppxJTrue->SetFillStyle(0); hmcppxJTrueTag->SetMarkerStyle(kOpenCircle); hmcppxJTrueTagCorr->SetMarkerStyle(kOpenSquare); plotymax = 0.3; SetB({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); float xjtrue = hmcppxJTrue->GetMean(); float xjtruetag = hmcppxJTrueTag->GetMean(); float xjtruetagcorr = hmcppxJTrueTagCorr->GetMean(); float exjtrue = hmcppxJTrue->GetMeanError(); float exjtruetag = hmcppxJTrueTag->GetMeanError(); float exjtruetagcorr = hmcppxJTrueTagCorr->GetMeanError(); auto c = getc(); hmcppxJTrue->Draw("hist"); hmcppxJTrueTag->Draw("E1,same"); hmcppxJTrueTagCorr->Draw("E1,same"); plotlegendpos = TopLeft; auto l = getLegend(); l->AddEntry(hmcppxJTrue,Form("b-dijets, #LTx_{J}#GT=%.3f#pm%.3f",xjtrue,exjtrue),"L"); l->AddEntry(hmcppxJTrueTag,Form("uncorrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetag,exjtruetag),"P"); l->AddEntry(hmcppxJTrueTagCorr,Form("corrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetagcorr,exjtruetagcorr),"P"); l->Draw(); TLatex *Tl = new TLatex(); Tl->DrawLatexNDC(0.2, 0.8, aktstring); SavePlot(c,"closurepp"); }
void findtruthPbPb(int binMin, int binMax) { TFile *fmc = new TFile(config.getFileName_djt("mcPbbfa")); buildNamesuffix = TString::Format("_bin_%d_%d",binMin, binMax); // buildTitlesuffix = TString::Format("%d-%d %%",binMin/2, binMax/2); seth(10,0,1); auto hmcPbPbxJTrue = geth("hmcPbPbxJTrue","PbPb true;x_{J};Event fractions"); auto hmcPbPbxJTrueTag = geth("hmcPbPbxJTrueTag","PbPb true tagged;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorr = geth("hmcPbPbxJTrueTagCorr","PbPb true tagged corrected;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrPt = geth("hmcPbPbxJTrueTagCorrPt","PbPb true tagged corrected pt;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrEta = geth("hmcPbPbxJTrueTagCorrEta","PbPb true tagged corrected eta;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrBin = geth("hmcPbPbxJTrueTagCorrBin","PbPb true tagged corrected bin;x_{J};Event fractions"); seth(12,20,140);//10,40,100); auto hpt2true = geth("hpt2true","true;p_{T,2} GeV"); auto hpt2truetag = geth("hpt2truetag","true tagged;p_{T,2} GeV"); auto hpt2truetagovertrue = geth("hpt2truetagovertrue","true tagged/true;p_{T,2} GeV"); auto hpt2truetagcorr = geth("hpt2truetagcorr","true tagged corrected;p_{T,2} GeV"); auto hpt2truetagcorrovertrue = geth("hpt2truetagcorrovertrue","true tagged corrected/true;p_{T,2} GeV"); seth(10,100,200); auto hpt1true = geth("hpt1true","true;p_{T,1} GeV"); auto hpt1truetag = geth("hpt1truetag","true tagged;p_{T,1} GeV"); auto hpt1truetagovertrue = geth("hpt1truetagovertrue","true tagged/true;p_{T,1} GeV"); auto hpt1truetagcorr = geth("hpt1truetagcorr","true tagged corrected;p_{T,1} GeV"); auto hpt1truetagcorrovertrue = geth("hpt1truetagcorrovertrue","true tagged corrected/true;p_{T,1} GeV"); seth(10,0,200); auto hbintrue = geth("hbintrue","true;bin"); auto hbintruetag = geth("hbintruetag","true tagged;bin"); auto hbintruetagovertrue = geth("hbintruetagovertrue","true tagged/true;bin"); auto hbintruetagcorr = geth("hbintruetagcorr","true tagged corrected;bin"); auto hbintruetagcorrovertrue = geth("hbintruetagcorrovertrue","true tagged corrected/true;bin"); seth(20,-2,2); auto heta2true = geth("heta2true","true;#eta_{2}"); auto heta2truetag = geth("heta2truetag","true tagged;#eta_{2}"); auto heta2truetagovertrue = geth("heta2truetagovertrue","true tagged/true;#eta_{2}"); auto heta2truetagcorr = geth("heta2truetagcorr","true tagged corrected;#eta_{2}"); auto heta2truetagcorrovertrue = geth("heta2truetagcorrovertrue","true tagged corrected/true;#eta_{2}"); auto heta1true = geth("heta1true","true;#eta_{1}"); auto heta1truetag = geth("heta1truetag","true tagged;#eta_{1}"); auto heta1truetagovertrue = geth("heta1truetagovertrue","true tagged/true;#eta_{1}"); auto heta1truetagcorr = geth("heta1truetagcorr","true tagged corrected;#eta_{1}"); auto heta1truetagcorrovertrue = geth("heta1truetagcorrovertrue","true tagged corrected/true;#eta_{1}"); unordered_set<int> eventstodiscard = {1805770,1116573,1084397};//, // 5755734,1599758,395810, // 1363321,211625,3195128}; // Fill(fmc,[&] (dict &m) { if (m["bin"]<binMin || m["bin"]>=binMax) return; if (m["pthat"]<pthatcut) return; if (m[pairCodeSB1]!=0) return; // if (m["bProdCode"]>1) return; if (eventstodiscard.find(m["event"])!=eventstodiscard.end()) return; //kill large-weight GSP event float w = m["weight"]*processweight((int)m["bProdCode"]); //because we have only b-dijets float corr = tageffcorrectionPbPb(m["jtpt1"],m["jteta1"],m[jtptSB],m[jtetaSB],m["bin"]); // float corrpt = getPbPbcorrectionPt(m["jtpt1"],m[jtptSB]); // float correta = getPbPbcorrectionEta(m["jteta1"],m[jtetaSB]); // float corrbin = getPbPbcorrectionBin(m["bin"]); float wb = w*corr; if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[refptSB]>20 && m[dphiSB1]>PI23) { hmcPbPbxJTrue->Fill(m[jtptSB]/m["jtpt1"],w); hpt2true->Fill(m[jtptSB],w); hpt1true->Fill(m["jtpt1"],w); heta2true->Fill(m[jtetaSB],w); heta1true->Fill(m["jteta1"],w); hbintrue->Fill(m["bin"],w); } if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[refptSB]>20 && m[dphiSB1]>PI23 && m["discr_csvV1_1"]>0.9 && m[discr_csvV1_SB]>0.9) { // //corrpt *= m[jtptSB] < 60 ? 1./0.7 : 1; //wb *= m[jtptSB] < 60 ? 1./0.7 : 1; hmcPbPbxJTrueTag->Fill(m[jtptSB]/m["jtpt1"],w); hmcPbPbxJTrueTagCorr->Fill(m[jtptSB]/m["jtpt1"],wb); // hmcPbPbxJTrueTagCorrPt->Fill(m[jtptSB]/m["jtpt1"],w*corrpt); // hmcPbPbxJTrueTagCorrEta->Fill(m[jtptSB]/m["jtpt1"],w*corrpt*correta); // hmcPbPbxJTrueTagCorrBin->Fill(m[jtptSB]/m["jtpt1"],w*corrpt*correta*corrbin); hpt2truetag->Fill(m[jtptSB],w); hpt1truetag->Fill(m["jtpt1"],w); heta2truetag->Fill(m[jtetaSB],w); heta1truetag->Fill(m["jteta1"],w); hbintruetag->Fill(m["bin"],w); hpt2truetagcorr->Fill(m[jtptSB],wb); hpt1truetagcorr->Fill(m["jtpt1"],wb); heta2truetagcorr->Fill(m[jtetaSB],wb); heta1truetagcorr->Fill(m["jteta1"],wb); hbintruetagcorr->Fill(m["bin"],wb); } }); NormalizeAllHists(); //plotymax = 9999; aktstring = TString::Format("PbPb %d-%d %%",binMin/2, binMax/2);//TString::Format("PbPb#Delta#phi>2/3#pi %d-%d %%",binMin/2, binMax/2); SetMC({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); SetData({hmcPbPbxJTrue}); hmcPbPbxJTrue->SetMinimum(0); hmcPbPbxJTrue->SetMaximum(0.3); hmcPbPbxJTrue->SetLineWidth(2); hmcPbPbxJTrue->SetMarkerStyle(kNone); hmcPbPbxJTrue->SetFillStyle(0); hmcPbPbxJTrueTag->SetMarkerStyle(kOpenCircle); hmcPbPbxJTrueTagCorr->SetMarkerStyle(kOpenSquare); plotymax = 0.3; Draw({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); SetB({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); float xjtrue = hmcPbPbxJTrue->GetMean(); float xjtruetag = hmcPbPbxJTrueTag->GetMean(); float xjtruetagcorr = hmcPbPbxJTrueTagCorr->GetMean(); float exjtrue = hmcPbPbxJTrue->GetMeanError(); float exjtruetag = hmcPbPbxJTrueTag->GetMeanError(); float exjtruetagcorr = hmcPbPbxJTrueTagCorr->GetMeanError(); auto c = getc(); hmcPbPbxJTrue->Draw("hist"); hmcPbPbxJTrueTag->Draw("E1,same"); hmcPbPbxJTrueTagCorr->Draw("E1,same"); plotlegendpos = TopLeft; auto l = getLegend(); l->AddEntry(hmcPbPbxJTrue,Form("b-dijets, #LTx_{J}#GT=%.3f#pm%.3f",xjtrue,exjtrue),"L"); l->AddEntry(hmcPbPbxJTrueTag,Form("uncorrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetag,exjtruetag),"P"); l->AddEntry(hmcPbPbxJTrueTagCorr,Form("corrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetagcorr,exjtruetagcorr),"P"); l->Draw(); TLatex *Tl = new TLatex(); Tl->DrawLatexNDC(0.2, 0.8, aktstring); SavePlot(c,Form("closure%d%d",binMin,binMax)); // //if (binMin==0 && binMax==200) { // Draw({hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorrPt,hmcPbPbxJTrueTagCorrEta,hmcPbPbxJTrueTagCorrBin}); // SetMC({hpt2truetag,hpt1truetag,heta2truetag,heta1truetag,hbintruetag}); // plotputmean = false; // plotymax = 0.2; // Draw({hpt2true,hpt2truetag,hpt2truetagcorr}); // plotymax = 0.3; // Draw({hpt1true,hpt1truetag,hpt1truetagcorr}); // plotymax = 0.2; // Draw({heta2true,heta2truetag,heta2truetagcorr}); // Draw({heta1true,heta1truetag,heta1truetagcorr}); // plotymax = 1; // Draw({hbintrue,hbintruetag,hbintruetagcorr}); plotymin = 0; plotymax = 0.2; Draw({hpt2truetag,hpt2true}); Draw({hpt2truetagcorr,hpt2true}); hpt2truetagovertrue->Divide(hpt2truetag,hpt2true,1,1); //"B" hpt1truetagovertrue->Divide(hpt1truetag,hpt1true,1,1); //"B" heta2truetagovertrue->Divide(heta2truetag,heta2true,1,1); //"B" heta1truetagovertrue->Divide(heta1truetag,heta1true,1,1); //"B" hbintruetagovertrue->Divide(hbintruetag,hbintrue,1,1); //"B" hpt2truetagcorrovertrue->Divide(hpt2truetagcorr,hpt2true,1,1); //"B" hpt1truetagcorrovertrue->Divide(hpt1truetagcorr,hpt1true,1,1); //"B" heta2truetagcorrovertrue->Divide(heta2truetagcorr,heta2true,1,1); //"B" heta1truetagcorrovertrue->Divide(heta1truetagcorr,heta1true,1,1); //"B" hbintruetagcorrovertrue->Divide(hbintruetagcorr,hbintrue,1,1); //"B" NormalizeAllHists(); Draw({hpt2truetagovertrue,hpt2truetagcorrovertrue}); Draw({hpt1truetagovertrue,hpt1truetagcorrovertrue}); Draw({heta2truetagovertrue,heta2truetagcorrovertrue}); Draw({heta1truetagovertrue,heta1truetagcorrovertrue}); Draw({hbintruetagovertrue,hbintruetagcorrovertrue}); // } }