TF1* fit(float ptmin, float ptmax, int s, int b, int widVar) { static int count=0; count++; TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",400,400); TFile* infile = new TFile(Form("%s/%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax)); TF1* f; TF1* background; TF1* bkpi; TF1* mass; if(b==0) f = new TF1(Form("f%d",count),Form("%s+%s+%s",sig[s].Data(),sig_bkg[s].Data(),bkgerf.Data()), 5.0, 6.0); else f = new TF1(Form("f%d",count),Form("%s+%s+%s",sig[s].Data(),bkg[b].Data(),bkgerf.Data()), 5.0, 6.0); clean0(h); h->Draw(); double hmin = h->GetBinContent(h->GetMinimumBin()); double hmax = h->GetBinContent(h->GetMaximumBin()); double havg = h->Integral(); double mcmin = hMCSignal->GetBinContent(h->GetMinimumBin()); double mcmax = hMCSignal->GetBinContent(h->GetMaximumBin()); double mcavg = hMCSignal->Integral(); f->SetParLimits(0,0,2*hmax); f->SetParLimits(1,5.27,5.29); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(6,0,1); if(s==1) f->SetParLimits(9,0,1); //if(s==2) f->SetParLimits(10,1,10); if(b==0 && sigmax[s]==8) { //f->SetParLimits(9,0.5*hmin,1.5*hmax); f->SetParLimits(10,-1000,0); } if(b==0 && sigmax[s]==10) { //f->SetParLimits(11,0.5*hmin,1.5*hmax); f->SetParLimits(12,-1000,0); } if(b==3) { //f->SetParLimits(9,0,1.5*hmax); f->SetParLimits(10,-100,0); } f->SetParLimits(3,0,1000); f->FixParameter(4,NPpar[0]); f->FixParameter(5,NPpar[1]); f->SetParameter(0,100); f->SetParameter(1,5.28); f->SetParameter(2,0.05); f->SetParameter(8,0.03); f->FixParameter(1,5.279); f->FixParameter(3,0); if(s==2) f->FixParameter(7,0); if(s>0 && bkgmax[b]>=11) f->FixParameter(11,0); if(s>0 && bkgmax[b]>=12) f->FixParameter(12,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,5.27,5.29); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->FixParameter(6,f->GetParameter(6)); if(sigmax[s]>=9) f->FixParameter(9,f->GetParameter(9)); if(sigmax[s]>=10) f->FixParameter(10,f->GetParameter(10)); if(s==2) { f->ReleaseParameter(7); f->SetParLimits(7,0,1); } if(s>0 && bkgmax[b]>=11) f->ReleaseParameter(11); if(s>0 && bkgmax[b]>=12) f->ReleaseParameter(12); f->ReleaseParameter(3); f->SetParLimits(3,0,1000); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,5.27,5.29); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); if(b==0) { background = new TF1(Form("background%d",count),bkg_new[b].Data(),minhisto,maxhisto); background->SetParameter(0,f->GetParameter(sigmax[s]+1)); background->SetParameter(1,f->GetParameter(sigmax[s]+2)); } else { background = new TF1(Form("background%d",count),bkg_new[b].Data(),minhisto,maxhisto); background->SetParameter(0,f->GetParameter(9)); background->SetParameter(1,f->GetParameter(10)); if(bkgmax[b]>=11) background->SetParameter(2,f->GetParameter(11)); if(bkgmax[b]>=12) background->SetParameter(3,f->GetParameter(12)); } bkpi = new TF1(Form("bpki%d",count),bkgerf_new.Data(),minhisto,maxhisto); bkpi->SetParameter(0,f->GetParameter(3)); bkpi->SetParameter(1,NPpar[0]); bkpi->SetParameter(2,NPpar[1]); mass = new TF1(Form("fmass%d",count),sig_new[s].Data(),minhisto,maxhisto); if(s==0 || s==3) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6)); if(s==1) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6),f->GetParameter(9)); if(s==2) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(8)); mass->SetParError(5,f->GetParError(6)); if(sigmax[s]>=9) mass->SetParError(6,f->GetParError(9)); if(sigmax[s]>=10) mass->SetParError(7,f->GetParError(10)); f->SetLineColor(kRed); f->SetLineWidth(2); background->SetLineColor(4); background->SetLineStyle(2); background->SetLineWidth(3); background->SetRange(minhisto,maxhisto); bkpi->SetFillColor(kGreen+4); bkpi->SetFillStyle(3005); bkpi->SetLineColor(kGreen+4); bkpi->SetLineWidth(3); mass->SetLineColor(kOrange-3); mass->SetLineStyle(2); mass->SetLineWidth(3); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.0); h->GetYaxis()->SetTitleOffset(1.5); h->GetXaxis()->SetLabelOffset(0.008); h->GetYaxis()->SetLabelOffset(0.008); h->GetXaxis()->SetTitleSize(0.060); h->GetYaxis()->SetTitleSize(0.060); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.06); h->GetYaxis()->SetLabelSize(0.06); h->Draw("e"); double axisymin = -0.05; h->SetAxisRange(axisymin,h->GetMaximum()*1.2,"Y"); h->GetXaxis()->SetNdivisions(-50205); int ci = TColor::GetColor("#000099"); h->SetLineColor(ci); h->SetStats(0); h->SetMarkerStyle(20); // 24? h->SetMarkerSize(0.8); h->Draw("e"); bkpi->Draw("same"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); f->Draw("same"); yield = mass->Integral(minhisto,maxhisto)/binwidthmass; yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); TLegend* leg = new TLegend(0.55,0.45,0.875,0.76,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.05); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"B^{+} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->AddEntry(bkpi,"B #rightarrow J/#psi X","f"); leg->Draw("same"); TLatex* texCms = new TLatex(0.225,0.87, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.39,0.94, Form("25.8 pb^{-1} (%s #sqrt{s_{NN}} = 5.02 TeV)","pp")); else texCol= new TLatex(0.35,0.94, Form("345 #mub^{-1} (%s #sqrt{s_{NN}} = 5.02 TeV)","PbPb")); texCol->SetNDC(); texCol->SetTextSize(0.05); texCol->SetLineWidth(2); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; tex = new TLatex(0.53,0.85,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); if(centmax>0){ TString texper="%"; tex = new TLatex(0.225,0.78,Form("Centrality %.0f-%.0f%s",centmin,centmax,texper.Data()));//0.2612903,0.8425793 tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); } tex = new TLatex(0.77,0.78,"|y_{lab}| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.30,0.54,"B^{+}"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.06); tex->SetLineWidth(2); tex->Draw(); if(widVar==0) c->SaveAs(Form("SystPDF/%s_%s_%s_%.0f_%.0f.pdf",collisionsystem.Data(),signame[s].Data(),bkgname[b].Data(),ptmin,ptmax)); else c->SaveAs(Form("SystPDF/%s_%s_%.0f_%.0f.pdf",collisionsystem.Data(),"widvar",ptmin,ptmax)); return mass; }
void testfit(int icut=3){ //gROOT->SetStyle("Plain"); //gStyle->SetOptStat(0); //gStyle->SetOptStat(0000); //gStyle->SetPalette(0); //gStyle->SetCanvasColor(0); //gStyle->SetFrameFillColor(0); //gStyle->SetOptTitle(0); TFile*fileoutput=new TFile(Form("Results/file_CutId%d.root",icut)); //TH1D*h=(TH1D*)fileoutput->Get("hInvMassSelectedWrongMethod_data"); TH1D*h=(TH1D*)fileoutput->Get("hInvMassSelected_data"); TH1D*hMC=(TH1D*)fileoutput->Get("hInvMassSelected_mc"); TH1D*hMCNP=(TH1D*)fileoutput->Get("hInvMassSelected_mcNP"); TCanvas *c= new TCanvas("canvas","",1350,500); c->Divide(3,1); c->cd(1); TString iNP="6.71675e+00*Gaus(x,5.30142e+00,8.42680e-02)/(sqrt(2*3.14159)*8.42680e-02)+4.06744e+01*Gaus(x,5.00954e+00,8.11305e-02)/(sqrt(2*3.14159)*8.11305e-02)+5.99974e-01*(2.376716*Gaus(x,5.640619,0.095530)/(sqrt(2*3.14159)*0.095530)+3.702342*Gaus(x,5.501706,0.046222)/(sqrt(2*3.14159)*0.046222))+1.31767e-01*(61.195688*Gaus(x,5.127566,0.087439)/(sqrt(2*3.14159)*0.087439)+58.943919*Gaus(x,5.246471,0.041983)/(sqrt(2*3.14159)*0.041983))"; TF1 *f = new TF1("f","[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[6]*("+iNP+")"); TF1 *fNP= new TF1("fNP","[0]*("+iNP+")"); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParLimits(6,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(6,0); h->GetEntries(); hMC->Fit("f","q","",5,6); hMC->Fit("f","q","",5,6); f->ReleaseParameter(1); hMC->Fit("f","L q","",5,6); hMC->Fit("f","L q","",5,6); hMC->Fit("f","L q","",5,6); hMC->Fit("f","L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(6); h->Fit("f","q","",5,6); h->Fit("f","q","",5,6); f->ReleaseParameter(1); h->Fit("f","L q","",5,6); h->Fit("f","L q","",5,6); h->Fit("f","L q","",5,6); h->Fit("f","L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1("background","[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1("fBkpi","[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1("fmass","[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (30 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); double yield = mass->Integral(5,6)/0.03; double yieldErr = mass->Integral(5,6)/0.03*mass->GetParError(0)/mass->GetParameter(0); TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); //leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); c->cd(2); hMC->SetMarkerSize(0.8); hMC->SetMarkerStyle(20); hMC->Draw("e"); c->cd(3); hMCNP->SetMarkerSize(0.8); hMCNP->SetMarkerStyle(20); //hMCNP->Fit("fNP","q","",5,6); hMCNP->Draw("e"); c->SaveAs(Form("Plots/canvascheck%d.pdf",icut)); TCanvas *cFit= new TCanvas("cFit","",650,500); cFit->cd(); h->Draw("e"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); leg->Draw(); leg2->Draw(); cFit->SaveAs(Form("Plots/canvasFit%d.pdf",icut)); }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax){ //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="(7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01)))"; TF1* fNP = new TF1("fNP",iNP); float normNP = fNP->Integral(5,6); TString signal = "([5]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[5])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))"; TF1 *f = new TF1(Form("f%d",count),Form("[0]*%s+[3]+[4]*x+(%s/%f)*([0]/%f)",signal.Data(),iNP.Data(),Ratio*(1+Change),normNP)); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(6,0.01,0.05); f->SetParLimits(5,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(6,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(5,f->GetParameter(5)); f->FixParameter(6,f->GetParameter(6)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); //cout<<"======="<<normNP<<"======="<<endl; // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),Form("([0]/(%f*%f))*%s",Ratio*(1+Change),normNP,iNP.Data())); Bkpi->SetParameter(0,f->GetParameter(0)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(5),f->GetParameter(6)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B^{+} meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); TLegend *leg3 = myLegend(0.02,0.83,0.37,0.92); if(Change==0) leg3->AddEntry((TObject*)0,Form("Ratio=%.2f",Ratio),""); else leg3->AddEntry((TObject*)0,Form("Ratio=%.2f(%.1f%)",Ratio*(1+Change),Change*100),""); leg3->Draw(); if(Change==0) c->SaveAs("BplusApplyRatio.pdf"); if(Change>0) c->SaveAs("BplusApplyRatioPlus.pdf"); if(Change<0) c->SaveAs("BplusApplyRatioMinus.pdf"); return mass; }
TF1* fitDstar(TTree* nt, TTree* ntMC, Float_t ptmin, Bool_t plotgenmatch) { TCanvas* c = new TCanvas(Form("c_5p_%.0f",ptmin),"",600,600); TH1D* h = new TH1D(Form("h_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSignal = new TH1D(Form("hMCSignal_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSignalplot = new TH1D(Form("hMCSignalplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TH1D* hMCSwappedplot = new TH1D(Form("hMCSwappedplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX); TF1* f = new TF1(Form("f_5p_%.0f",ptmin),"[0]*([4]*([6]*([12]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[12])*Gaus(x,[1],[11])/(sqrt(2*3.14159)*[11]))+(1-[6])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5]))+(1-[4])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3]))+[10]*((1-exp((0.13957-x)/[7]))*pow(x/0.13957,[8])+[9]*(x/0.13957-1))",BINMIN,BINMAX); nt->Project(Form("h_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightdata[isData].Data(),seldata5p[isData].Data(),triggerselectiondata[isData].Data(),ptmin)); ntMC->Project(Form("hMCSignal_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selmc5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin)); ntMC->Project(Form("hMCSwapped_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selswp5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin)); for(int ibin=0;ibin<BINNUM;ibin++) hMCSignalplot->SetBinContent(ibin+1,hMCSignal->GetBinContent(ibin+1)); for(int ibin=0;ibin<BINNUM;ibin++) hMCSwappedplot->SetBinContent(ibin+1,hMCSwapped->GetBinContent(ibin+1)); f->FixParameter(4,1.); f->FixParameter(1,0.145491); f->FixParameter(10,0); f->SetParLimits(0,0,1.e+5); f->SetParLimits(6,0,1.); f->SetParLimits(12,0,1.); f->SetParLimits(2,3.e-4,1.e-3); f->SetParameter(2,5.e-4); f->SetParLimits(11,1.6e-4,3.e-4);//1.5e-4 keyong f->SetParameter(11,2.e-4); f->SetParLimits(5,1.e-3,1.6e-3); f->SetParameter(5,1.e-3); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); f->ReleaseParameter(1); f->SetParLimits(1,minmass,maxmass); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass); hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(5,f->GetParameter(5)); f->FixParameter(11,f->GetParameter(11)); f->FixParameter(6,f->GetParameter(6)); f->FixParameter(12,f->GetParameter(12)); f->FixParameter(4,0); f->SetParLimits(3,2.e-4,2.e-3); f->SetParameter(3,1.e-3); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass); hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass); f->FixParameter(4,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(3,f->GetParameter(3)); f->SetParLimits(7,5.e-4,1.e-2); f->SetParameter(7,1.6e-3); f->SetParLimits(8,0.,15.); f->SetParameter(8,0.35); f->SetParLimits(9,-2.e+1,2.e+1); f->SetParameter(9,13.); f->ReleaseParameter(10); f->SetParLimits(10,0,1.e+6); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); f->ReleaseParameter(1); f->SetParLimits(1,minmass,maxmass); f->SetParameter(1,f->GetParameter(1)); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX); TF1* background = new TF1(Form("background_5p_%.0f",ptmin),"[3]*((1-exp((0.13957-x)/[0]))*pow(x/0.13957,[1])+[2]*(x/0.13957-1))"); background->SetParameters(f->GetParameter(7),f->GetParameter(8),f->GetParameter(9),f->GetParameter(10)); background->SetRange(BINMIN,BINMAX); background->SetLineColor(4); background->SetLineWidth(3); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_5p_%.0f",ptmin),"[0]*[3]*([5]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+(1-[5])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(11),f->GetParameter(12)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(4)); mass->SetParError(4,f->GetParError(5)); mass->SetParError(5,f->GetParError(6)); mass->SetRange(BINMIN,BINMAX); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_5p_%.0f",ptmin),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(4),f->GetParameter(3)); massSwap->SetRange(BINMIN,BINMAX); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (0.4 MeV/c^{2})"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3,"Y"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); mass->Draw("same"); massSwap->Draw("same"); background->Draw("same"); f->Draw("same"); if(plotgenmatch&&(isData==MC_MB||isData==MC)) { hMCSignalplot->SetMarkerSize(0.8); hMCSignalplot->SetMarkerColor(kMagenta+2); hMCSignalplot->Draw("psame"); hMCSwappedplot->SetMarkerSize(0.8); hMCSwappedplot->SetMarkerColor(kGray+2); hMCSwappedplot->Draw("psame"); } Float_t yield = mass->Integral(BINMIN,BINMAX)/BINWID; Float_t yieldErr = mass->Integral(BINMIN,BINMAX)/BINWID*mass->GetParError(0)/mass->GetParameter(0); cout<<mass->GetParameter(0)<<" "<<mass->Integral(BINMIN,BINMAX)<<endl; TLatex* tex; TLegend* leg = new TLegend(0.60,0.57,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.52,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("p_{T} > %.1f GeV/c",ptmin)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/fitDstar5p/DMass_%s_%.0f.pdf",texData[isData].Data(),ptmin)); return mass; }
TF1 *fit(TTree *nt, TTree *ntMC, double ptmin,double ptmax) { //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",30,5.03,5.93); // TH1D *hBck = new TH1D(Form("hBck%d",count),"",40,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",30,5.03,5.93); // Fit function //QM2014 //TString iNP="6.71675e+00*Gaus(x,5.30142e+00,8.42680e-02)/(sqrt(2*3.14159)*8.42680e-02)+4.06744e+01*Gaus(x,5.00954e+00,8.11305e-02)/(sqrt(2*3.14159)*8.11305e-02)+5.99974e-01*(2.376716*Gaus(x,5.640619,0.095530)/(sqrt(2*3.14159)*0.095530)+3.702342*Gaus(x,5.501706,0.046222)/(sqrt(2*3.14159)*0.046222))+1.31767e-01*(61.195688*Gaus(x,5.127566,0.087439)/(sqrt(2*3.14159)*0.087439)+58.943919*Gaus(x,5.246471,0.041983)/(sqrt(2*3.14159)*0.041983))"; TString iNP="2.28629e1*Gaus(x,5.02606,6.84e-2)/(sqrt(2*3.14159)*(6.84e-2))+3.85695*Gaus(x,5.27701,0.04305)/(sqrt(2*3.14159)*(0.04305))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[6]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax)); // nt->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax)); // nt2->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax)); // cout <<"nsig = "<<hBck->GetEntries(); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.08); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParLimits(6,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(6,0); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(6); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; cout<<"======= chi2 ======="<<endl; cout<<f->GetChisquare()<<endl; cout<<"===== chi2 end ====="<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (30 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); // hBck->Draw("hist same"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl; double yield = mass->Integral(5,6)/0.03; double yieldErr = mass->Integral(5,6)/0.03*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); //c->SaveAs(Form("../ResultsBzero/BMass-%d.pdf",count)); c->SaveAs("../../../BzeroDefault.pdf"); return mass; }
//TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, float NPpar[]) TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, TString npfit) { TString tMC; if(isMC==1) tMC="MC"; else tMC="Data"; TCanvas* c = new TCanvas(Form("c_%s_%.0f",tMC.Data(),ibin),"",600,600); TFile* infile = new TFile(Form("%s_%s_%s_%s_%.0f.root",infname.Data(),collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%s_%.0f",tMC.Data(),ibin)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%s_%.0f",tMC.Data(),ibin)); //TString iNP=Form("TMath::Erf((x-%f)/%f)+1", NPpar[0], NPpar[1]); TString iNP = npfit; TF1* f = new TF1(Form("f_%s_%.0f",tMC.Data(),ibin),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); f->SetParLimits(3,0,1e5); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); if(isMC) { f->SetParLimits(3,0,1e2); f->SetParLimits(4,-100,0); } f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(5,0); h->GetEntries(); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(5); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1 *background = new TF1(Form("background_%s_%.0f",tMC.Data(),ibin),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1 *Bkpi = new TF1(Form("fBkpi_%s_%.0f",tMC.Data(),ibin),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetRange(minhisto,maxhisto); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); Bkpi->SetFillColor(kGreen+1); TF1 *mass = new TF1(Form("fmass_%s_%.0f",tMC.Data(),ibin),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"B^{+} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp")); else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb")); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; if(ibin>0) { if(isLarger==1) tex = new TLatex(0.22,0.78,Form("%s > %.3f",vartex.Data(),varval)); else tex = new TLatex(0.22,0.78,Form("%s < %.3f",vartex.Data(),varval)); } else tex = new TLatex(0.22,0.78,Form("%s",_nominalcut.Data())); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.73,Form("N_{B} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plotFits/DMass_%s_%s_%s_%.0f.pdf",collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); return mass; }
TF1* fitDstar3prongs(TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax) { static int count3p=0; count3p++; TCanvas* c = new TCanvas(Form("c_3p_%d",count3p),"",600,600); TH1D* h = new TH1D(Form("h_3p_%d",count3p),"",60,0.14,0.16); TH1D* hMCSignal = new TH1D(Form("hMCSignal_3p_%d",count3p),"",60,0.14,0.16); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_3p_%d",count3p),"",60,0.14,0.16); TF1* f = new TF1(Form("f_3p_%d",count3p),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*([12]*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10])+(1-[12])*Gaus(x,[1],[13])/(sqrt(2*3.14159)*[13])))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x+[11]*x*x*x*x",0.14,0.16); f->SetLineColor(kRed); nt->Project(Form("h_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSignal_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23333))",weight.Data(),selmc3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); ntMC->Project(Form("hMCSwapped_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23344))",weight.Data(),selswp3p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); f->FixParameter(7,1.); f->FixParameter(1,0.145491); f->FixParameter(2,2.e-3); f->FixParameter(10,5.e-4); f->FixParameter(13,1.e-4); f->FixParameter(3,0.); f->FixParameter(4,0.); f->FixParameter(5,0.); f->FixParameter(6,0.); f->FixParameter(11,0.); f->SetParLimits(9,0,1); f->SetParLimits(12,0,1); f->SetParLimits(0,0,1000000); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL"); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL"); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.142,0.155); f->ReleaseParameter(1); f->ReleaseParameter(2); f->ReleaseParameter(10); f->ReleaseParameter(13); f->SetParLimits(1,0.144,0.147); if(isData==0||isData==2) f->SetParLimits(2,5.e-4,5.e-3); else f->SetParLimits(2,5.e-4,7.e-3); f->SetParLimits(10,1.e-4,2.e-3); if(isData==0||isData==2) f->SetParLimits(13,5.e-5,3.e-4); else if(ptmin>20) f->SetParLimits(13,5.e-5,4.e-4); else f->SetParLimits(13,5.e-5,5.e-4); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.143,0.147); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(13,f->GetParameter(13)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(12,f->GetParameter(12)); f->FixParameter(7,0); f->SetParLimits(8,2.e-4,2.e-3); hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16); hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->ReleaseParameter(11); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); f->ReleaseParameter(1); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16); TF1* background = new TF1(Form("background_3p_%d",count3p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetParameter(4,f->GetParameter(11)); background->SetLineColor(4); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_3p_%d",count3p),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*([6]*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])+(1-[6])*Gaus(x,[1],[7])/(sqrt(2*3.14159)*[7]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(12),f->GetParameter(13)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetParError(6,f->GetParError(12)); mass->SetParError(7,f->GetParError(13)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); h->SetXTitle("M_{K#pi#pi}-M_{K#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (1/3 MeV/c^{2})"); h->SetStats(0); h->SetAxisRange(1,h->GetMaximum()*1.3,"Y"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(0.142,0.152); mass->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(0.14,0.16)/binwidth3prong; Double_t yieldErr = mass->Integral(0.14,0.16)/binwidth3prong*mass->GetParError(0)/mass->GetParameter(0); TLatex* tex; TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/DMass_%s_3prongs-%d.pdf",texData[isData].Data(),count3p)); return mass; }
//void testFit(int count=3,Double_t ptmin=30.,Double_t ptmax=40,TString sample="PbPb") void compareUpgrade(int option=2) { int count; Double_t ptmin; Double_t ptmax; TString sample; int nmin,nmax,mymaxhisto; if (option==1) {count=3; ptmin=30.; ptmax=40; sample="PbPb"; mymaxhisto=2000; }; if (option==2) {count=1; ptmin=2.; ptmax=3; sample="PbPbMB"; mymaxhisto=600000;}; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TFile *file=new TFile(Form("FitsFiles/Fits_%s_%d.root",sample.Data(), count)); TH1D* h = (TH1D*)file->Get(Form("h-%d",count)); TH1D* hMCSignal = (TH1D*)file->Get(Form("hMCSignal-%d",count)); TH1D* hMCSwapped = (TH1D*)file->Get(Form("hMCSwapped-%d",count)); TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); /* TCanvas*mycanvas=new TCanvas("mycanvas","mycanvas",1000,500); mycanvas->Divide(2,1); mycanvas->cd(1); hMCSignal->Draw(); mycanvas->cd(2); hMCSwapped->Draw(); mycanvas->SaveAs("mycanvas.pdf"); */ h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); std::cout<<"parameter 10="<<f->GetParameter(10)<<std::endl; TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldtotal = f->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"yield signal="<<yield<<std::endl; std::cout<<"total counts="<<yieldtotal<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.04); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Performance"); Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); h->GetFunction(Form("f%d",count))->Delete(); TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun"); histo_copy_nofitfun->Draw("esame"); TH1D* hTest = new TH1D("hTest","",nbinsmasshisto,minhisto,maxhisto); for (int m=0;m<yieldtotal;m++){ double r = f->GetRandom(); hTest->Fill(r); } TF1* ffaketotal=(TF1*)f->Clone("ffake"); TF1* ffakemass=(TF1*)mass->Clone("ffakemass"); TF1* ffakebackground=(TF1*)background->Clone("ffakebackground"); TF1* ffakemassSwap=(TF1*)massSwap->Clone("ffakemassSwap"); Double_t yieldtotal_original = ffaketotal->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldmass_original = ffakemass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldbackground_original = ffakebackground->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldswapped_original = ffakemassSwap->Integral(minhisto,maxhisto)/binwidthmass; TH1D* hTestFake = new TH1D("hTestFake","",nbinsmasshisto,minhisto,maxhisto); ffakemass->SetParameter(2,ffaketotal->GetParameter(2)*0.8); ffakemass->SetParameter(10,ffaketotal->GetParameter(10)*0.8); Double_t yieldmass_modified= ffakemass->Integral(minhisto,maxhisto)/binwidthmass; cout<<"mass original="<<yieldmass_original<<endl; cout<<"mass modified="<<yieldmass_modified<<endl; for (int m=0;m<yieldmass_original*scalefactor;m++){ double r = ffakemass->GetRandom(); hTestFake->Fill(r); } for (int m=0;m<(int)(yieldbackground_original*scalefactor*bkgreduction);m++){ double r = ffakebackground->GetRandom(); hTestFake->Fill(r); } for (int m=0;m<(int)(yieldswapped_original*scalefactor*bkgreduction);m++){ double r = ffakemassSwap->GetRandom(); hTestFake->Fill(r); } TCanvas*c2=new TCanvas("c2","c2",500,500); c2->cd(); hTest->SetMaximum(2000); hTest->SetXTitle("m_{#piK} (GeV/c^{2})"); hTest->SetYTitle("Entries / (5 MeV/c^{2})"); hTest->GetXaxis()->CenterTitle(); hTest->GetYaxis()->CenterTitle(); hTest->SetAxisRange(0,hTest->GetMaximum()*1.*1.2,"Y"); hTest->GetXaxis()->SetTitleOffset(1.3); hTest->GetYaxis()->SetTitleOffset(1.8); hTest->GetXaxis()->SetLabelOffset(0.007); hTest->GetYaxis()->SetLabelOffset(0.007); hTest->GetXaxis()->SetTitleSize(0.045); hTest->GetYaxis()->SetTitleSize(0.045); hTest->GetXaxis()->SetTitleFont(42); hTest->GetYaxis()->SetTitleFont(42); hTest->GetXaxis()->SetLabelFont(42); hTest->GetYaxis()->SetLabelFont(42); hTest->GetXaxis()->SetLabelSize(0.04); hTest->GetYaxis()->SetLabelSize(0.04); hTest->SetMarkerSize(0.8); hTest->SetMarkerStyle(20); hTest->SetStats(0); hTest->Draw("e"); hTest->SetLineColor(1); hTest->SetMarkerColor(1); hTestFake->SetLineColor(2); hTestFake->SetMarkerColor(2); hTest->Draw("ep"); hTestFake->Draw("epsame"); TLegend* myleg = new TLegend(0.2177419,0.6292373,0.6633065,0.7266949,NULL,"brNDC"); myleg->SetBorderSize(0); myleg->SetTextSize(0.04); myleg->SetTextFont(42); myleg->SetFillStyle(0); myleg->AddEntry(hTest,"Current CMS, |y|<1, L_{int}=0.5/nb","pl"); myleg->AddEntry(hTestFake,"Upgraded CMS, |y|<2, L_{int}=1.5/nb","l"); myleg->Draw("same"); TLatex* mytex; mytex = new TLatex(0.22,0.83,Form("%.0f < p_{T} < %.0f GeV/c",ptmin,ptmax)); mytex->SetNDC(); mytex->SetTextFont(42); mytex->SetTextSize(0.04); mytex->SetLineWidth(2); mytex->Draw(); TLatex* mychannel; mychannel = new TLatex(0.22,0.765,"D^{0} #rightarrow K#pi"); mychannel->SetNDC(); mychannel->SetTextFont(42); mychannel->SetTextSize(0.055); mychannel->SetLineWidth(2); mychannel->Draw(); TLatex myTl; myTl.SetNDC(); myTl.SetTextAlign(12); myTl.SetTextSize(0.04); myTl.SetTextFont(42); myTl.DrawLatex(0.2,0.90, "#scale[1.25]{CMS} Performance"); myTl.DrawLatex(0.63,0.90, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TFile*foutput=new TFile(Form("foutput_%s.root",sample.Data()),"recreate"); foutput->cd(); hTest->SetName("hTest"); hTestFake->SetName("hTestFake"); hTest->SetMaximum(mymaxhisto); hTest->Write(); hTestFake->SetMaximum(mymaxhisto); hTestFake->Write(); hMCSignal->Write(); hMCSwapped->Write(); c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.pdf",sample.Data())); c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.png",sample.Data())); }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax) { //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",24,5.03,5.99); TH1D *hMC = new TH1D(Form("hMC%d",count),"",24,5.03,5.99); // Fit function TString iNP="Gaus(x,5.36800e+00,5.77122e-02)/(sqrt(2*3.14159)*abs(5.77122e-02))"; TF1 *f = new TF1(Form("f%d",count),"[0]*(Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]))+ [3]+[4]*x+[5]*x*x + [11]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->FixParameter(1,fixparam1); f->SetParLimits(11,0,1000); f->SetParameter(11,10); f->FixParameter(11,0); f->FixParameter(9,0); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(11)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*(Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (40 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); double yield = mass->Integral(5,6)/0.040; double yieldErr = mass->Integral(5,6)/0.04*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); // leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); c->SaveAs(Form("PDFVariation/data/2Gto1G/ResultsBs/BMass-%d.pdf",count)); return mass; }
TH1D* getYield(TTree* nt, TTree* ntMC, TString triggerpass, TString triggername, TString prescale, TString variable, TString varname, TString varlatex, Int_t BIN_NUM, Double_t BIN_MIN, Double_t BIN_MAX, TString addcut="") { TH1D* hDistrib = new TH1D(Form("h%s_Distrib_%s",triggername.Data(),varname.Data()),"",BIN_NUM,BIN_MIN,BIN_MAX); for(float ivar=0;ivar<BIN_NUM;ivar++) { TCanvas* c = new TCanvas(Form("c%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"",500,500); TH1D* h = new TH1D(Form("h%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),";D^{0} mass (GeV/c^{2});Candidates",60,1.7,2.0); TH1D* hMC = new TH1D(Form("hMC%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"",60,1.75,1.95); TH1D* hSW = new TH1D(Form("hSW%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"",60,1.75,1.95); Float_t varmin = BIN_MIN+ivar*((BIN_MAX-BIN_MIN)/BIN_NUM); Float_t varmax = BIN_MIN+(ivar+1)*((BIN_MAX-BIN_MIN)/BIN_NUM); nt->Project(Form("h%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),Form("Dmass%s",prescale.Data()),Form("%s%s&&(%s>%f&&%s<%f)%s",prefilter.Data(),addcut.Data(),variable.Data(),varmin,variable.Data(),varmax,triggerpass.Data())); ntMC->Project(Form("hMC%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"Dmass",Form("%s%s&&(%s>%f&&%s<%f)%s",prefilterMC.Data(),addcut.Data(),variable.Data(),varmin,variable.Data(),varmax,"&&1")); ntMC->Project(Form("hSW%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"Dmass",Form("%s%s&&(%s>%f&&%s<%f)%s",prefilterSW.Data(),addcut.Data(),variable.Data(),varmin,variable.Data(),varmax,"&&1")); h->SetMaximum(h->GetMaximum()*1.20); h->Draw(); TF1* f = new TF1(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.14159)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.14159)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.14159)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); h->GetEntries(); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); f->ReleaseParameter(1); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L m","",1.7,2.0); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L m","",1.7,2.0); f->FixParameter(7,hMC->Integral(0,1000)/(hSW->Integral(0,1000)+hMC->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); f->ReleaseParameter(11); f->SetParLimits(11,-1.,1.); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L m","",1.7,2.0); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1* background = new TF1(Form("background%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(1.7,2.0); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.14159)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.14159)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.14159)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(1.7,2.0); mass->Draw("same"); massSwap->SetRange(1.7,2.0); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(1.7,2.0)/0.005; Double_t yieldErr = (mass->Integral(1.7,2.0)/0.005)*(mass->GetParError(0)/mass->GetParameter(0)); std::cout<<"YIELD="<<yield<<std::endl; // Draw the legend:) TLegend* leg = myLegend(0.20,0.60,0.53,0.94); leg->SetFillColor(0); leg->SetBorderSize(0); leg->AddEntry((TObject*)0,"CMS Preliminary",""); if(isPbPb) leg->AddEntry((TObject*)0,"PbPb #sqrt{s_{NN}}= 5.02 TeV",""); else leg->AddEntry((TObject*)0,"pp #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry((TObject*)0,Form("%.1f<%s<%.1f",varmin,varlatex.Data(),varmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->Draw(); TLegend* leg2 = myLegend(0.45,0.80,0.90,0.94); leg2->SetFillColor(0); leg2->SetBorderSize(0); leg2->AddEntry(h,"D meson",""); leg2->AddEntry(h,Form("M_{D}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{D}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); hDistrib->SetBinContent(ivar+1,yield); hDistrib->SetBinError(ivar+1,yieldErr); if(isPbPb) c->SaveAs(Form("fitefficiencyPbPb/c%s_Fit_%s_%.0f.pdf",triggername.Data(),varname.Data(),ivar)); else c->SaveAs(Form("fitefficiencyPP/c%s_Fit_%s_%.0f.pdf",triggername.Data(),varname.Data(),ivar)); } TCanvas* cDistrib = new TCanvas(Form("c%s_Distrib_%s",triggername.Data(),varname.Data()),"",500,500); hDistrib->Draw(); hDistrib->SetStats(0); if(isPbPb) cDistrib->SaveAs(Form("fitefficiencyPbPb/c%s_Distrib_%s.pdf",triggername.Data(),varname.Data())); else cDistrib->SaveAs(Form("fitefficiencyPP/data/pp/c%s_Distrib_%s.pdf",triggername.Data(),varname.Data())); return hDistrib; }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax, bool ispPb, int count){ //cout<<cut.Data()<<endl; //static int count=0; //count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); TH1D *hraw = new TH1D(Form("hraw%d",count),"",50,5,6); clean0(hraw); hraw = (TH1D*)h->Clone(Form("hraw%d",count)); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi%d",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass%d",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); hraw->Draw("same"); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"pPb #sqrt{s_{NN}} = 5.02 TeV",""); leg->AddEntry(h,Form("%.0f < p_{T}^{B} < %.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B} = %.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B} = %.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); if(ispPb)c->SaveAs(Form("../ResultsBplus/BMass-%d.pdf",count)); else c->SaveAs(Form("../ResultsBplus_pp/BMass-%d.pdf",count)); h->Write(); hMC->Write(); f->Write(); background->Write(); Bkpi->Write(); mass->Write(); hraw->Write(); return mass; }
TF1* fit(TString variable, TString variableplot, TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax, int isMC) { static int count=0; count++; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TH1D* h = new TH1D(Form("h-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TH1D* hMCSignal = new TH1D(Form("hMCSignal-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); TString mycut=Form("(%s&&(%s)>%f&&(%s)<%f)",seldata.Data(),variable.Data(),ptmin,variable.Data(),ptmax); if(isMC==1) nt->Project(Form("h-%d",count),"Dmass",TCut(weight)*TCut(mycut)); else nt->Project(Form("h-%d",count),"Dmass",Form("(%s&&(%s)>%f&&(%s)<%f)",seldata.Data(),variable.Data(),ptmin,variable.Data(),ptmax)); ntMC->Project(Form("hMCSignal-%d",count),"Dmass",Form("%s*(%s&&(%s)>%f&&(%s)<%f&&(Dgen==23333))",weight.Data(),selmc.Data(),variable.Data(),ptmin,variable.Data(),ptmax)); ntMC->Project(Form("hMCSwapped-%d",count),"Dmass",Form("%s*(%s&&(%s)>%f&&(%s)<%f&&(Dgen==23344))",weight.Data(),selmc.Data(),variable.Data(),ptmin,variable.Data(),ptmax)); TFile *fout=new TFile(Form("FitsFiles/Fits_%s_%d.root",collisionsystem.Data(),count),"recreate"); fout->cd(); hMCSignal->Write(); hMCSwapped->Write(); h->Write(); fout->Close(); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<"and error"<<yieldErr<<std::endl; std::cout<<"relative error="<<yieldErr/yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.04); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < %s < %.1f",ptmin,variableplot.Data(),ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); h->GetFunction(Form("f%d",count))->Delete(); TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun"); histo_copy_nofitfun->Draw("esame"); // if(nBins==1) c->SaveAs(Form("DMass-inclusive%s_%d.pdf",collisionsystem.Data(),count)); else c->SaveAs(Form("DMass%s_%d.pdf",collisionsystem.Data(),count)); return mass; }
void SimpleFitter() { TFile*output=new TFile("histoX.root","read"); TH1D*h=(TH1D*)output->Get("h"); h->Sumw2(); TF1 *f = new TF1("f","[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) +[3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])+[6]+[7]*x+[8]*x*x+[9]*x*x*x"); f->SetLineColor(4); f->SetParameters(21,3.68,0.0057,1.34714e+00,3.86,0.006,-2.21334e+04,1.01661e+04,-1.05364e+03,1.95474e+04); f->FixParameter(1,3.686); f->FixParameter(2,0.00357); f->FixParameter(4,3.8725); f->FixParameter(5,0.005); h->Fit("f","LL"); h->Fit("f",""); h->Fit("f","LL"); h->Fit("f","LL","",3.65,3.94); h->Fit("f","LL","",3.65,3.94); f->ReleaseParameter(1); f->ReleaseParameter(2); f->ReleaseParameter(4); f->ReleaseParameter(5); h->Fit("f","LL","",3.65,3.94); h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y"); TF1 *f2 = new TF1("f2","[6]+[7]*x+[8]*x*x+[9]*x*x*x"); f2->SetParameter(6,f->GetParameter(6)); f2->SetParameter(7,f->GetParameter(7)); f2->SetParameter(8,f->GetParameter(8)); f2->SetParameter(9,f->GetParameter(9)); TF1 *f3 = new TF1("f3","[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])"); f3->SetParameter(0,f->GetParameter(0)); f3->SetParameter(1,f->GetParameter(1)); f3->SetParameter(2,f->GetParameter(2)); TF1 *f4 = new TF1("f4","[3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])"); f4->SetParameter(3,f->GetParameter(3)); f4->SetParameter(4,f->GetParameter(4)); f4->SetParameter(5,f->GetParameter(5)); f->SetLineColor(4); f2->SetLineColor(4); f3->SetRange(3.65,3.94); f4->SetRange(3.65,3.94); f2->SetRange(3.65,3.94); f2->SetLineStyle(2); f3->SetLineStyle(2); f4->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); f4->SetLineColor(2); f4->SetFillStyle(3004); f4->SetFillColor(2); f4->Draw("same"); TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)"); l->Draw(); TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)"); l2->Draw(); TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary"); l3->Draw(); TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV"); l4->Draw(); cout<<"********************* SIGNIFICANCE *********************"<<endl; double meanX=f4->GetParameter(4); double sigmaX=f4->GetParameter(5); double signalX=f4->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double bkgX=f2->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double signalpsi2=f4->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double bkgpsi2=f2->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0); double significanceX=signalX/TMath::Sqrt(signalX+bkgX); double meanpsi2=f3->GetParameter(1); double sigmapsi2=f3->GetParameter(2); double signalpsi2=f3->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double bkgpsi2=f2->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double signalpsi2=f3->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double bkgpsi2=f2->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0); double significancepsi2=signalpsi2/TMath::Sqrt(signalpsi2+bkgpsi2); cout<<"significance X ="<<significanceX<<endl; cout<<"significance psi(2S)="<<significancepsi2<<endl; cout<<"yield X="<<signalX<<endl; cout<<"yield 2S="<<signalpsi2<<endl; cout<<"yield X/yield 2S="<<signalX/signalpsi2<<endl; }
TF1* fit(TH1D* h, TH1D* hMCSignal, TH1D* hMCSwapped, Float_t ptmin, Float_t ptmax, Int_t j) { TCanvas* c = new TCanvas(Form("c_%.0f_%.0f_%d",ptmin,ptmax,j),"",600,600); TF1* f = new TF1(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.14159)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.14159)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.14159)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.5); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); h->GetEntries(); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); /* f->ReleaseParameter(11); f->SetParLimits(11,-1.,1.); */ h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("mass_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.14159)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.14159)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("massSwap_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.14159)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); DrawCmsTlatex("PbPb"); TLatex* tex; tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); TString texper="%"; tex = new TLatex(0.22,0.72,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data())); tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plots/Mass_cent_%.0f_%.0f_pt_%.0f_%.0f_%s.pdf",centMin,centMax,ptmin,ptmax,tfend[j].Data())); return mass; }
TF1 *fit(TH1D* h, TTree *ntMC, TTree *ntMC2,double ptmin,double ptmax) { static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); // Fit function TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])+(1-[7])*Gaus(x,[1],[8]))+[3]+[4]*x+[6]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata.Data(),ptmin,ptmax)); ntMC2->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[3]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); // TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*(1.24e2*Gaus(x,5.107,0.02987)+1.886e2*Gaus(x,5.0116,5.546e-2))"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*(38.42*Gaus(x,5.25,0.03473)+15.04*Gaus(x,5.25,0.1121)+104.3*Gaus(x,5.026,0.0935))"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,5.45); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])+(1-[3])*Gaus(x,[1],[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.4,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); // hBck->Draw("hist same"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl; double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); //c->SaveAs(Form("ResultsCheckStatErr/BMass-%d.C",count)); c->SaveAs(Form("ResultsCheckStatErr/BMass-%d.gif",count)); //c->SaveAs(Form("ResultsBzero/BMass-%d.eps",count)); return mass; }
TF1* fit_histo_poly3bkg_floatwidth_poly2bkg_combinemassvnfit( bool isPbPb, int centlow, int centhigh, TH1D * histo, TH1D * h_mc_matched_signal, TH1D * h_mc_matched_kpiswapped, int ipt, TString cfgname, bool get_sig_bkg_ratio = false, TH1D * Ratio_signal_foreground = NULL, TH1D * h_vnvsmass = NULL, TH1D * h_vnvspt = NULL, TString vnorder = "v2", TString EPorSP = "SP", TH1D * h_vnvspt_bkg = NULL) { Double_t setparam0=100.; Double_t setparam1=1.8648; Double_t setparam2=0.03; Double_t setparam3=0.005; Double_t setparam4=0.1; Double_t setparam7=0.1; Double_t fixparam1=1.8648; double fit_range_low = generalfitrange_masslow; double fit_range_high = generalfitrange_masshigh; double histomassbinsize = histo->GetBinWidth(10); float ptmin = ptbins[ipt]; float ptmax = ptbins[ipt+1]; //remove the fit function from v2 fit when perform v3 fit if( histo->GetListOfFunctions()->FindObject(Form("fmass_combinemassvnfit_%s_%d",cfgname.Data(),ipt)) ) histo->GetListOfFunctions()->Remove( histo->GetListOfFunctions()->FindObject(Form("fmass_combinemassvnfit_%s_%d",cfgname.Data(),ipt)) ); TH1F* histo_copy_nofitfun = ( TH1F * ) histo->Clone("histo_copy_nofitfun"); TH1F* histo_massfit = ( TH1F * ) histo->Clone("histo_massfit"); TCanvas* cfg= new TCanvas(Form("cfg_poly3bkg_floatwidth_poly2bkg_combinemassvnfit_%s_%d",cfgname.Data(),ipt),Form("cfg_poly3bkg_floatwidth_poly2bkg_combinemassvnfit_%s_%d",cfgname.Data(),ipt),600,600); gPad->SetRightMargin(0.043); gPad->SetLeftMargin(0.18); gPad->SetTopMargin(0.1); gPad->SetBottomMargin(0.145); TF1* f = new TF1(Form("f_%s_%d",cfgname.Data(),ipt),"[0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) + [9] + [10]*x + [11]*x*x + [12]*x*x*x", fit_range_low, fit_range_high); f->SetParLimits(10,-1000,1000); f->SetParLimits(3,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(7,0.02,0.2); f->SetParLimits(5,0,1); f->SetParLimits(4,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(3,setparam3); f->SetParameter(4,setparam4); f->FixParameter(7,setparam7); f->FixParameter(8,setparam1); f->FixParameter(5,1); f->FixParameter(1,fixparam1); f->FixParameter(9,0); f->FixParameter(10,0); f->FixParameter(11,0); f->FixParameter(12,0); f->FixParameter(6,0); h_mc_matched_signal->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"q","",fit_range_low,fit_range_high); h_mc_matched_signal->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"q","",fit_range_low,fit_range_high); f->ReleaseParameter(1); h_mc_matched_signal->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); h_mc_matched_signal->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); h_mc_matched_signal->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L m","",fit_range_low,fit_range_high); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(3,f->GetParameter(3)); f->FixParameter(4,f->GetParameter(4)); f->FixParameter(5,0); f->ReleaseParameter(7); f->ReleaseParameter(8); f->SetParameter(7,setparam7); f->SetParameter(8,setparam1);//mean for swapped candidates //if want to fix parameter 8 to parameter 1 //f->FixParameter(8,f->GetParameter(1)); h_mc_matched_kpiswapped->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); h_mc_matched_kpiswapped->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); h_mc_matched_kpiswapped->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); h_mc_matched_kpiswapped->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L m","",fit_range_low,fit_range_high); f->FixParameter(5,h_mc_matched_signal->Integral(0,1000)/(h_mc_matched_kpiswapped->Integral(0,1000)+h_mc_matched_signal->Integral(0,1000))); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(9); f->ReleaseParameter(10); f->ReleaseParameter(11); f->ReleaseParameter(12); f->SetLineColor(kRed); histo_massfit->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"q","",fit_range_low,fit_range_high); histo_massfit->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"q","",fit_range_low,fit_range_high); f->ReleaseParameter(1); ////Release Parameter 6 to float signal width f->ReleaseParameter(6); f->SetParameter(6,0); f->SetParLimits(6,-1.0,1.0); histo_massfit->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); histo_massfit->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); histo_massfit->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L q","",fit_range_low,fit_range_high); histo_massfit->Fit(Form("f_%s_%d",cfgname.Data(),ipt),"L m","",fit_range_low,fit_range_high); //begin combine fit TF1* fmass_combinemassvnfit = new TF1(Form("fmass_combinemassvnfit_%s_%d",cfgname.Data(),ipt),"[0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) + [9] + [10]*x + [11]*x*x + [12]*x*x*x", fit_range_low, fit_range_high); TF1* fvn_combinemassvnfit = new TF1(Form("fvn_combinemassvnfit_%s_%d",cfgname.Data(),ipt), "( ( [0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) ) / ( [0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) + [9] + [10]*x + [11]*x*x + [12]*x*x*x ) ) * [13] + ( 1.0 - ( ( [0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) ) / ( [0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) + [9] + [10]*x + [11]*x*x + [12]*x*x*x ) ) ) * ( [14] + [15] * x + [16] * x * x)", fit_range_low, fit_range_high); ROOT::Math::WrappedMultiTF1 wfmass_combinemassvnfit(*fmass_combinemassvnfit,1); ROOT::Math::WrappedMultiTF1 wfvn_combinemassvnfit(*fvn_combinemassvnfit,1); ROOT::Fit::DataOptions opt; ROOT::Fit::DataRange range_massfit; // set the data range range_massfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datamass(opt,range_massfit); ROOT::Fit::FillData(datamass, histo); ROOT::Fit::DataRange range_vnfit; range_vnfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datavn(opt,range_vnfit); ROOT::Fit::FillData(datavn, h_vnvsmass); ROOT::Fit::Chi2Function chi2_B(datamass, wfmass_combinemassvnfit); ROOT::Fit::Chi2Function chi2_SB(datavn, wfvn_combinemassvnfit); GlobalChi2_poly3bkg_floatwidth_poly2bkg globalChi2(chi2_B, chi2_SB); ROOT::Fit::Fitter fitter; const int Npar = 17; double par0[Npar]; for( int ipar = 0; ipar < f->GetNpar(); ipar++ ) par0[ipar] = f->GetParameter(ipar); par0[13] = 0.01; par0[14] = 0.10; par0[15] = 0.05; par0[16] = 0.05; // create before the parameter settings in order to fix or set range on them fitter.Config().SetParamsSettings(Npar,par0); // fix parameter fitter.Config().ParSettings(2).Fix(); fitter.Config().ParSettings(3).Fix(); fitter.Config().ParSettings(4).Fix(); fitter.Config().ParSettings(5).Fix(); fitter.Config().ParSettings(7).Fix(); fitter.Config().ParSettings(8).Fix(); // set limits on the third and 4-th parameter fitter.Config().ParSettings(1).SetLimits(1.7, 2.0); //fitter.Config().ParSettings(12).SetStepSize(0.005); //fitter.Config().UseWeightCorrection(); fitter.Config().MinimizerOptions().SetPrintLevel(0); fitter.Config().SetMinimizer("Minuit2","Migrad"); // fit FCN function directly // (specify optionally data size and flag to indicate that is a chi2 fit) //fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),false); fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),true); ROOT::Fit::FitResult result = fitter.Result(); result.Print(std::cout); fmass_combinemassvnfit->SetFitResult( result, iparmassfit_poly3bkg_floatwidth_poly2bkg); fmass_combinemassvnfit->SetRange(range_massfit().first, range_massfit().second); fmass_combinemassvnfit->SetLineColor(kRed); histo->GetListOfFunctions()->Add(fmass_combinemassvnfit); fvn_combinemassvnfit->SetFitResult( result, iparvnfit_poly3bkg_floatwidth_poly2bkg); fvn_combinemassvnfit->SetRange(range_vnfit().first, range_vnfit().second); fvn_combinemassvnfit->SetLineColor(4.0); fvn_combinemassvnfit->SetLineStyle(2); h_vnvsmass->GetListOfFunctions()->Add(fvn_combinemassvnfit); h_vnvspt->SetBinContent( ipt+1, fvn_combinemassvnfit->GetParameter(13)); h_vnvspt->SetBinError( ipt+1, fvn_combinemassvnfit->GetParError(13)); //double x[2] = {1.73, 1.864}; //double error[2]; //does not work //result.GetConfidenceIntervals(2, 1, 1, x, error, 0.683, false); //h_vnvspt_bkg->SetBinContent( ipt+1, fvn_combinemassvnfit->GetParameter(13) + fvn_combinemassvnfit->GetParameter(14) * 1.864); //h_vnvspt_bkg->SetBinError( ipt+1, error[0]); h_vnvspt_bkg->SetBinContent( ipt+1, fvn_combinemassvnfit->GetParameter(14) + fvn_combinemassvnfit->GetParameter(15) * 1.864 + fvn_combinemassvnfit->GetParameter(16) * 1.864 * 1.864); h_vnvspt_bkg->SetBinError( ipt+1, 0. ); TCanvas* cfg_massfit_combinemassvn = new TCanvas(Form("cfg_poly3bkg_floatwidth_poly2bkg_combinemassvnfit_massfit_combinemassvn_%s_%d_%s_%s",cfgname.Data(),ipt,vnorder.Data(),EPorSP.Data()),Form("cfg_poly3bkg_floatwidth_poly2bkg_combinemassvnfit_massfit_combinemassvn_%s_%d_%s_%s",cfgname.Data(),ipt,vnorder.Data(),EPorSP.Data()),600,600); gPad->SetRightMargin(0.043); gPad->SetLeftMargin(0.18); // gPad->SetTopMargin(0.1); gPad->SetBottomMargin(0.145); histo->SetXTitle("m_{#piK} (GeV/c^{2})"); histo->SetYTitle("Entries / (5 MeV/c^{2})"); histo->GetXaxis()->CenterTitle(); histo->GetYaxis()->CenterTitle(); //histo->SetAxisRange(0,histo->GetMaximum()*1.4*1.2,"Y"); histo->GetXaxis()->SetRangeUser(fit_range_low+0.0001,fit_range_high-0.0001); histo->GetXaxis()->SetTitleOffset(1.3); histo->GetYaxis()->SetTitleOffset(1.8); histo->GetXaxis()->SetLabelOffset(0.007); histo->GetYaxis()->SetLabelOffset(0.007); histo->GetXaxis()->SetTitleSize(0.045); histo->GetYaxis()->SetTitleSize(0.045); histo->GetXaxis()->SetTitleFont(42); histo->GetYaxis()->SetTitleFont(42); histo->GetXaxis()->SetLabelFont(42); histo->GetYaxis()->SetLabelFont(42); histo->GetXaxis()->SetLabelSize(0.04); histo->GetYaxis()->SetLabelSize(0.04); histo->SetMarkerSize(0.8); histo->SetMarkerStyle(20); histo->SetStats(0); histo->Draw("e"); TF1* background = new TF1(Form("background_%s_%d",cfgname.Data(),ipt),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,fmass_combinemassvnfit->GetParameter(9)); background->SetParameter(1,fmass_combinemassvnfit->GetParameter(10)); background->SetParameter(2,fmass_combinemassvnfit->GetParameter(11)); background->SetParameter(3,fmass_combinemassvnfit->GetParameter(12)); background->SetLineColor(4); background->SetRange(fit_range_low,fit_range_high); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_%s_%d",cfgname.Data(),ipt),"[0]*([5]*([4]*Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(3)); mass->SetParError(4,f->GetParError(4)); mass->SetParError(5,f->GetParError(5)); mass->SetParError(6,f->GetParError(6)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_%s_%d",cfgname.Data(),ipt),"[0]*(1-[2])*Gaus(x,[1],[3]*(1.0 +[4]))/(sqrt(2*3.14159)*[3]*(1.0 +[4]))"); massSwap->SetParameters(fmass_combinemassvnfit->GetParameter(0),fmass_combinemassvnfit->GetParameter(8),fmass_combinemassvnfit->GetParameter(5),fmass_combinemassvnfit->GetParameter(7),fmass_combinemassvnfit->GetParameter(6)); massSwap->SetParError(0,fmass_combinemassvnfit->GetParError(0)); massSwap->SetParError(1,fmass_combinemassvnfit->GetParError(8)); massSwap->SetParError(2,fmass_combinemassvnfit->GetParError(5)); massSwap->SetParError(3,fmass_combinemassvnfit->GetParError(7)); massSwap->SetParError(4,fmass_combinemassvnfit->GetParError(6)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); background->Draw("same"); mass->SetRange(fit_range_low,fit_range_high); mass->Draw("same"); massSwap->SetRange(fit_range_low,fit_range_high); massSwap->Draw("same"); Double_t yield = mass->Integral(fit_range_low,fit_range_high)/histomassbinsize; Double_t yieldErr = mass->Integral(fit_range_low,fit_range_high)/histomassbinsize*mass->GetParError(0)/mass->GetParameter(0); TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(histo,"Data","pl"); leg->AddEntry(fmass_combinemassvnfit,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.05); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.965, "#font[61]{CMS}"); if( isPbPb ) Tl.DrawLatex(0.61,0.965, "#scale[0.8]{PbPb #sqrt{s_{NN}} = 5.02 TeV}"); else Tl.DrawLatex(0.65,0.965, "#scale[0.8]{pp #sqrt{s_{NN}} = 5.02 TeV}"); TLatex* tex; if( isPbPb ) { tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.78,Form("Cent. %d-%d%%", centlow, centhigh)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,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(); tex = new TLatex(0.22,0.68,Form("N_{sig}: %d #pm %d",int(yield),int(yieldErr))); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); } else { tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.73,Form("N_{sig}: %d #pm %d",int(yield),int(yieldErr))); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); } histo_copy_nofitfun->Draw("esame"); if( get_sig_bkg_ratio ) { for(int ibin = 0; ibin < histo->GetNbinsX(); ibin++) { double foreground = 0.; double signal = 0.; double ratio = 0.; double ratioError = 999.; double massbinleftedge = massmin + histomassbinsize * ibin; double massbinrightedge = massmin + histomassbinsize * (ibin+1); if( massbinleftedge > (fit_range_low - 0.0002) && massbinrightedge < (fit_range_high + 0.0002) ) { foreground = f->Integral(massbinleftedge, massbinrightedge)/histomassbinsize; //foregroundErr = f->IntegralError(massbinleftedge, massbinrightedge)/histomassbinsize; //foreground = histo->Integral(ibin+1, ibin+1); signal = mass->Integral(massbinleftedge, massbinrightedge)/histomassbinsize + massSwap->Integral(massbinleftedge, massbinrightedge)/histomassbinsize; //signal = mass->Integral(massbinleftedge, massbinrightedge)/histomassbinsize; //signal = foreground - background->Integral(massbinleftedge, massbinrightedge)/histomassbinsize; //signalErr = signal * yieldErr/yield; if( foreground > 0 ) { ratio = signal/foreground; ratioError = TMath::Sqrt( foreground * ratio * (1.0 - ratio) ) / foreground; } else { ratio = 0.5; ratioError = 0.5; } } else { ratio = 0.0; ratioError = 1.0; } Ratio_signal_foreground->SetBinContent(ibin+1, ratio); Ratio_signal_foreground->SetBinError(ibin+1, ratioError); } TF1* Func_Ratio_signal_foreground = new TF1(Form("Func_Ratio_signal_foreground_%s_%d",cfgname.Data(),ipt),"([0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))))/([0]*([5]*([4]*TMath::Gaus(x,[1],[2]*(1.0 +[6]))/(sqrt(2*3.14159)*[2]*(1.0 +[6]))+(1-[4])*TMath::Gaus(x,[1],[3]*(1.0 +[6]))/(sqrt(2*3.14159)*[3]*(1.0 +[6])))+(1-[5])*TMath::Gaus(x,[8],[7]*(1.0 +[6]))/(sqrt(2*3.14159)*[7]*(1.0 +[6]))) + [9] + [10]*x + [11]*x*x + [12]*x*x*x)", generalfitrange_masslow, generalfitrange_masshigh); for( int ipar = 0; ipar < 13; ipar++ ) { Func_Ratio_signal_foreground->SetParameter( ipar, f->GetParameter(ipar)); Func_Ratio_signal_foreground->SetParError(ipar, f->GetParError(ipar)); } Func_Ratio_signal_foreground->SetLineColor(2.0); Ratio_signal_foreground->GetListOfFunctions()->Add(Func_Ratio_signal_foreground); } if(isPbPb) { cfg_massfit_combinemassvn->SaveAs(Form("Plots_vn/combinemassvnfit/DMass_combinemassvnfit_isPbPb%d_%s_cent%dto%d_%d_%s_%s_poly3bkg_floatwidth_poly2bkg_combinemassvnfit.pdf", isPbPb, cfgname.Data(), centlow, centhigh, ipt, vnorder.Data(),EPorSP.Data())); cfg_massfit_combinemassvn->SaveAs(Form("Plots_vn/combinemassvnfit/DMass_combinemassvnfit_isPbPb%d_%s_cent%dto%d_%d_%s_%s_poly3bkg_floatwidth_poly2bkg_combinemassvnfit.png", isPbPb, cfgname.Data(), centlow, centhigh, ipt, vnorder.Data(),EPorSP.Data())); } TCanvas* cfg_vnfit_combinemassvn = new TCanvas(Form("cfg_poly3bkg_floatwidth_poly2bkg_combinemassvnfit_vnfit_combinemassvn_%s_%d_%s_%s",cfgname.Data(),ipt,vnorder.Data(),EPorSP.Data()),Form("cfg_poly3bkg_floatwidth_poly2bkg_combinemassvnfit_vnfit_combinemassvn_%s_%d_%s_%s",cfgname.Data(),ipt,vnorder.Data(),EPorSP.Data()),600,600); h_vnvsmass->GetYaxis()->SetRangeUser(-0.2, 0.6); if( vnorder == "v2") h_vnvsmass->GetYaxis()->SetTitle("v_{2}"); if( vnorder == "v3") h_vnvsmass->GetYaxis()->SetTitle("v_{3}"); h_vnvsmass->GetXaxis()->SetTitle("m_{#piK} (GeV/c^{2})"); h_vnvsmass->GetXaxis()->SetTitleSize(0.05); h_vnvsmass->GetYaxis()->SetTitleSize(0.05); h_vnvsmass->SetMarkerColor(4.0); h_vnvsmass->SetLineColor(4.0); h_vnvsmass->SetMarkerStyle(21); h_vnvsmass->SetMarkerSize(1.3); h_vnvsmass->Draw(); TLatex Tl2; Tl2.SetNDC(); Tl2.SetTextAlign(12); Tl2.SetTextSize(0.05); Tl2.SetTextFont(42); Tl2.DrawLatex(0.125,0.965, "#font[61]{CMS}"); Tl2.DrawLatex(0.57,0.965, "#scale[0.8]{PbPb #sqrt{s_{NN}} = 5.02 TeV}"); tex = new TLatex(0.18,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.18,0.78,Form("Cent. %d-%d%%", centlow, centhigh)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.18,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( vnorder == "v2" ) tex = new TLatex(0.55,0.83,Form("v_{2}^{sig} = %.3f #pm %.3f",fvn_combinemassvnfit->GetParameter(13), fvn_combinemassvnfit->GetParError(13))); else if( vnorder == "v3" ) tex = new TLatex(0.55,0.83,Form("v_{3}^{sig} = %.3f #pm %.3f",fvn_combinemassvnfit->GetParameter(13), fvn_combinemassvnfit->GetParError(13))); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); if(isPbPb) { cfg_vnfit_combinemassvn->SaveAs(Form("Plots_vn/combinemassvnfit/cfg_vnfit_combinemassvn_%s_cent%dto%d_%d_%s_%s_poly3bkg_floatwidth_poly2bkg_combinemassvnfit.pdf",cfgname.Data(),centlow,centhigh,ipt,vnorder.Data(),EPorSP.Data())); cfg_vnfit_combinemassvn->SaveAs(Form("Plots_vn/combinemassvnfit/cfg_vnfit_combinemassvn_%s_cent%dto%d_%d_%s_%s_poly3bkg_floatwidth_poly2bkg_combinemassvnfit.png",cfgname.Data(),centlow,centhigh,ipt,vnorder.Data(),EPorSP.Data())); } return mass; }
TF1* fitMass(TH1D* hData, TH1D* hMCSignal, TH1D* hMCSwapped) { Double_t setparam0=100.; Double_t setparam1=1.865; Double_t setparam2=0.03; Double_t setparam10=0.005; Double_t setparam8=0.1; Double_t setparam9=0.1; Double_t fixparam1=1.865; Double_t minhisto=1.7; Double_t maxhisto=2.0; TF1* f = new TF1("fMass","[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.1415927)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.1415927)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.1415927)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.005,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); hData->Fit("fMass","q","",minhisto,maxhisto); hData->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); f->ReleaseParameter(11); f->SetParLimits(11,-0.2,0.2); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L m","",minhisto,maxhisto); TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1("fSignal","[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.1415927)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.1415927)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1("fBackground","[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.1415927)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); hData->SetXTitle("m_{#piK} (GeV/c^{2})"); hData->SetYTitle("Entries / (5 MeV/c^{2})"); hData->SetAxisRange(0,hData->GetBinContent(hData->GetMaximumBin())*1.4*1.2,"Y"); hData->SetMarkerSize(0.3); hData->Draw("e"); cout<<"hData->GetMaximum(): "<<hData->GetMaximum()<<endl; background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1); Double_t yieldErr = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1)*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"integral function yield: "<<yield<<" fit yield: "<<f->GetParameter(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<" +- "<<f->GetParError(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<std::endl; TLegend* leg = new TLegend(0.65,0.5,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.06); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(hData,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); hData->GetFunction("fMass")->Delete(); TH1D* hDataNoFitFun = (TH1D*) hData->Clone("hDataNoFitFun"); hDataNoFitFun->Draw("esame"); return f; }
TF1* fit(Double_t ptmin, Double_t ptmax) { TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",600,600); TFile* infile = new TFile(Form("%s_%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSwapped = (TH1D*)infile->Get("hMCSwapped"); hMCSwapped->SetName(Form("hMCSwapped_%.0f_%.0f",ptmin,ptmax)); TF1* f = new TF1(Form("f_%.0f_%.0f",ptmin,ptmax),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]*exp([4]*x)", 1.7, 2.0); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); h->GetEntries(); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); f->SetParLimits(0,0,1.e+6); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->SetParLimits(3,0,1.e+10); f->SetParameter(3,1.e+3); f->SetLineColor(kRed); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.85,1.90); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background_%.0f_%.0f",ptmin,ptmax),"[0]*exp([1]*x)"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_%.0f_%.0f",ptmin,ptmax),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_%.0f_%.0f",ptmin,ptmax),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol = new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* texPt = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); texPt->SetNDC(); texPt->SetTextFont(42); texPt->SetTextSize(0.04); texPt->SetLineWidth(2); texPt->Draw(); TLatex* texY = new TLatex(0.22,0.83,"|y| < 1.0"); texY->SetNDC(); texY->SetTextFont(42); texY->SetTextSize(0.04); texY->SetLineWidth(2); texY->Draw(); TLatex* texYield = new TLatex(0.22,0.73,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); texYield->SetNDC(); texYield->SetTextFont(42); texYield->SetTextSize(0.04); texYield->SetLineWidth(2); texYield->Draw(); c->SaveAs(Form("plotFits/DMass_expo_%s_%.0f_%.0f.pdf",collisionsystem.Data(),ptmin,ptmax)); TCanvas* cPull = new TCanvas(Form("cPull_%.0f_%.0f",ptmin,ptmax),"",600,700); TH1D* hPull = (TH1D*)h->Clone("hPull"); for(int i=0;i<h->GetNbinsX();i++) { Double_t nfit = f->Integral(h->GetBinLowEdge(i+1),h->GetBinLowEdge(i+1)+h->GetBinWidth(i+1))/h->GetBinWidth(i+1); hPull->SetBinContent(i+1,(h->GetBinContent(i+1)-nfit)/h->GetBinError(i+1)); hPull->SetBinError(i+1,0); } hPull->SetMinimum(-4.); hPull->SetMaximum(4.); hPull->SetYTitle("Pull"); hPull->GetXaxis()->SetTitleOffset(1.); hPull->GetYaxis()->SetTitleOffset(0.65); hPull->GetXaxis()->SetLabelOffset(0.007); hPull->GetYaxis()->SetLabelOffset(0.007); hPull->GetXaxis()->SetTitleSize(0.12); hPull->GetYaxis()->SetTitleSize(0.12); hPull->GetXaxis()->SetLabelSize(0.1); hPull->GetYaxis()->SetLabelSize(0.1); hPull->GetYaxis()->SetNdivisions(504); TLine* lPull = new TLine(1.7, 0, 2., 0); lPull->SetLineWidth(1); lPull->SetLineStyle(7); lPull->SetLineColor(1); TPad* pFit = new TPad("pFit","",0,0.3,1,1); pFit->SetBottomMargin(0); pFit->Draw(); pFit->cd(); h->Draw("e"); background->Draw("same"); mass->Draw("same"); massSwap->Draw("same"); f->Draw("same"); leg->Draw("same"); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); texYield->Draw(); cPull->cd(); TPad* pPull = new TPad("pPull","",0,0,1,0.3); pPull->SetTopMargin(0); pPull->SetBottomMargin(0.3); pPull->Draw(); pPull->cd(); hPull->Draw("p"); lPull->Draw(); cPull->cd(); cPull->SaveAs(Form("plotFits/DMass_expo_%s_%.0f_%.0f_Pull.pdf",collisionsystem.Data(),ptmin,ptmax)); return mass; }
void fitDstar(char *infname = "/data/wangj/MC2015/Dntuple/PbPb/ntD_Pythia8_5020GeV_DstarD0kpipipi_755patch3_GEN_SIM_PU_20151120_Dstar5p_tkPt2_20151126_Evt_All.root") { TFile *inf = new TFile(infname); //TTree *ntmix=(TTree*)inf->Get("ntDD0kpipipipi"); TTree *ntmix=(TTree*)inf->Get("ntDD0kpipi"); TH1D *h = new TH1D("h","",100,0.139,0.159); TCut cutTrk = "";//"trk1PixelHit>=2&&trk1StripHit>=10&&trk1Chi2ndf<5&&trk2PixelHit>=2&&trk2StripHit>=10&&trk2Chi2ndf<5"; TCanvas *c = new TCanvas("c","",750,750); ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&(DsvpvDistance/DsvpvDisErr)>0.&&Dchi2cl>0.05&&Dalpha<1."&&cutTrk,"",10000000); //ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&Dtrk1Pt>0.5&&DRestrk1Pt>0.5&&DRestrk2Pt>0.5&&DRestrk3Pt>0.5&&DRestrk4Pt>0.5&&Dchi2cl>0.1&&Dalpha<0.2&&(DsvpvDistance/DsvpvDisErr)>.0"&&cutTrk,"",10000000); h->Sumw2(); // TF1 *f = new TF1("f","(1-exp(-(x-[8])/[0]))*(((x)/[8])**[1]+[2]*(((x)/[8])-1))*[3]+[4]*(TMath::Voigt(x-[5],[6],[7]))"); TF1* f = new TF1("f","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong); // TF1 *f = new TF1("f","(1-exp(-(x-0.13957018)/[0]))*(((x)/0.13957018)**[1]+[2]*(((x)/0.13957018)-1))*[3]+[4]*(TMath::Gaus(x,[5],[6]))"); //TF1 *f = new TF1("f","(1-exp(-(x-1.86486-0.13957018)/[0]))*(((x-1.86486)/0.13957018)**[1]+[2]*(((x-1.86486)/0.13957018)-1))*[3]+[4]*TMath::Gaus(x,[5],[6])"); f->SetLineColor(4); // f->SetParameters(-2.3825e6,-7.99713e-1,-1.42957,-5.50069e10,5.33573,1.45491e-1,2.78677e-6,1.43145e-3,0.13957018); // f->SetParameters(-7.3e5,-2.2e1,5.24e-1,-7.18e9,2e2,1.45491e-1,9e-4,0.1,8e-4); f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4); f->FixParameter(9,15e-4); f->FixParameter(6,0.145491); f->FixParameter(7,8e-4); f->SetParLimits(8,0,1); h->Fit("f","LL"); h->Fit("f","LL"); h->Fit("f","LL","",0.142,0.147); f->ReleaseParameter(6); f->ReleaseParameter(7); f->ReleaseParameter(9); f->SetParLimits(7,1e-4,9e-4); f->SetParLimits(9,1e-4,9e-4); h->Fit("f","LL","",0.142,0.148); h->Fit("f","LL","",0.142,0.16); h->Fit("f","LL","",0.142,0.16); h->Fit("f","LL","",0.141,0.16); h->Fit("f","LL","",0.141,0.16); h->Fit("f","LL","",0.141,0.16); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(1,h->GetMaximum()*1.3,"Y"); TF1 *f2 = (TF1*)f->Clone("f2"); f2->SetParameter(5,0); f2->SetRange(0.141,0.16); TF1 *f3 = (TF1*)f->Clone("f3"); f3->SetParameter(0,0); f3->SetParameter(1,0); f3->SetParameter(2,0); f3->SetParameter(3,0); f3->SetParameter(4,0); f->SetLineColor(4); f2->SetLineColor(4); f2->SetLineStyle(2); f3->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); c->SaveAs("canvasDstar.pdf"); }
TH1D * GetTOFRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE) { /* pt limits for combined spectra */ Double_t ptMin_[9] = { 0.5, 0.5, 0.5, 0.45, 0.45, 0.45, 0.5, 0.5, 0.5 }; Double_t ptMax_[9] = { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 4.5, 4.5, 4.5 }; Double_t ptMin = TMath::Max(ptMin_[num], ptMin_[den]); Double_t ptMax = TMath::Min(ptMax_[num], ptMax_[den]); TH1D *hin = (TH1D *)file->Get(Form("hRatio_cent%d_%s_%s", cent, ratioName[num], ratioName[den])); if (!hin) return NULL; #if 0 /* get matching systematics */ TFile *fsys = TFile::Open(Form("MATCHSYS_TOF_%s.root", TOFChargeName[charge])); TH1 *hsys = fsys->Get(Form("hErr%sMatch", ITSsaPartName[part])); TF1 *ffsys = new TF1("fsys", "[0] + [1] * x + [2] * TMath::Exp(-[3] * x)"); ffsys->SetParameter(0, 0.02); ffsys->FixParameter(1, 0.); ffsys->SetParameter(2, 0.5); ffsys->SetParameter(3, 10.); hsys->Fit(ffsys, "W"); ffsys->ReleaseParameter(1); hsys->Fit(ffsys, "W"); hsys->Fit(ffsys, "W"); hsys->Fit(ffsys, "W"); hsys->Draw(); #endif TH1D *h = new TH1D(Form("hTOF_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "TOF", NptBins, ptBin); Double_t pt, width, value, error, sys; Int_t bin; for (Int_t ipt = 0; ipt < NptBins; ipt++) { /* get input bin */ pt = h->GetBinCenter(ipt + 1); width = h->GetBinWidth(ipt + 1); bin = hin->FindBin(pt); /* sanity check */ if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 || TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001) continue; /* check pt limits */ if (cutSpectrum && (pt < ptMin || pt > ptMax)) continue; /* copy bin */ value = hin->GetBinContent(bin); error = hin->GetBinError(bin); /*** TEMP ADD SYS ***/ // sys = ffsys->Eval(pt) * value; // error = TMath::Sqrt(error * error + sys * sys); // h->SetBinContent(ipt + 1, value); // h->SetBinError(ipt + 1, error); h->SetBinContent(ipt + 1, value); h->SetBinError(ipt + 1, error); } h->SetTitle("TOF"); h->SetLineWidth(1); h->SetLineColor(1); h->SetMarkerStyle(23); h->SetMarkerColor(4); h->SetFillStyle(0); h->SetFillColor(0); return h; }
TF1* fitDstar5prongs(TTree* nt, Double_t ptmin, Double_t ptmax) { static int count5p=0; count5p++; TCanvas* c = new TCanvas(Form("c_5p_%d",count5p),"",600,600); TH1D* h = new TH1D(Form("h_5p_%d",count5p),"",60,0.140,0.160); TF1* f = new TF1(Form("f_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong); nt->Project(Form("h_5p_%d",count5p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata5p.Data(),triggerselection[isData].Data(),ptmin,ptmax)); f->SetLineColor(4); f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4); f->FixParameter(9,15e-4); f->FixParameter(6,0.145491); f->FixParameter(7,8e-4); f->SetParLimits(8,0,1); f->SetParLimits(5,0,100000); h->Fit(Form("f_5p_%d",count5p),"LL"); h->Fit(Form("f_5p_%d",count5p),"LL"); h->Fit(Form("f_5p_%d",count5p),"LL","",minmass3prong,maxmass3prong); f->ReleaseParameter(6); f->ReleaseParameter(7); f->ReleaseParameter(9); f->SetParLimits(6,0.144,0.147); f->SetParLimits(7,1e-4,9e-4); f->SetParLimits(9,1e-4,9e-4); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.148); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16); TF1* background = new TF1(Form("background_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x"); background->SetParameter(0,f->GetParameter(0)); background->SetParameter(1,f->GetParameter(1)); background->SetParameter(2,f->GetParameter(2)); background->SetParameter(3,f->GetParameter(3)); background->SetParameter(4,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minmass3prong,maxmass3prong); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_5p_%d",count5p),"[0]*((1-[3])*TMath::Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+[3]*TMath::Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8),f->GetParameter(9)); mass->SetParError(0,f->GetParError(5)); mass->SetParError(1,f->GetParError(6)); mass->SetParError(2,f->GetParError(7)); mass->SetParError(3,f->GetParError(8)); mass->SetParError(4,f->GetParError(9)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})"); h->SetYTitle("Entries / (1/3 MeV/c^{2})"); h->SetStats(0); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(0.142,0.152); mass->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong; Double_t yieldErr = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong*mass->GetParError(0)/mass->GetParameter(0); TLatex* tex; TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextSize(0.04); tex->SetTextFont(42); tex->Draw(); tex = new TLatex(0.20,0.79,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->Draw(); c->SaveAs(Form("plots/pp/DMass_%s_5prongs-%d.pdf",texData[isData].Data(),count5p)); return mass; }
TF1 *fitSignal(TTree *ntMC,double ptmin,double ptmax){ //cout<<cut.Data()<<endl; TCanvas *cSignal= new TCanvas("cSignal","",600,600); TH1D *hMC = new TH1D("hMC","",50,5,6); // TString iNP="7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1("f1","[0]*([5]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[5])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+[3]+[4]*x"); ntMC->Project("hMC","mass",Form("%s&&pt>%f&&pt<%f",selmc.Data(),ptmin,ptmax)); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(6,0.01,0.05); f->SetParLimits(5,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(6,setparam3); f->FixParameter(1,fixparam1); hMC->Fit("f1","q","",5,6); hMC->Fit("f1","q","",5,6); f->ReleaseParameter(1); hMC->Fit("f1","L q","",5,6); hMC->Fit("f1","L q","",5,6); hMC->Fit("f1","L q","",5,6); hMC->Fit("f1","L m","",5,6); // function for background shape plotting. take the fit result from f TF1 *background = new TF1("backgroundSignal","[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1("fmassSignal","[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(5),f->GetParameter(6)); cout<<"[0]Signal: "<<f->GetParameter(0)<<endl; mass->SetLineColor(2); mass->SetLineStyle(2); hMC->SetMarkerStyle(24); hMC->SetStats(0); hMC->Draw("e"); hMC->SetXTitle("M_{B} (GeV/c^{2})"); hMC->SetYTitle("Entries / (20 MeV/c^{2})"); hMC->GetXaxis()->CenterTitle(); hMC->GetYaxis()->CenterTitle(); hMC->SetTitleOffset(1.,"Y"); hMC->SetAxisRange(0,hMC->GetMaximum()*1.2,"Y"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); double yield = mass->Integral(5,6)/0.02; // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(hMC,"CMS Preliminary",""); leg->AddEntry(hMC,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(hMC,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(hMC,"B meson",""); leg2->AddEntry(hMC,Form("N_{B}=%.0f", yield),""); leg2->Draw(); cSignal->SaveAs("NonpromptBplus/BMassSignal.gif"); return mass; }
void massfitvn_Jpsi() { double fit_range_low = 2.6; double fit_range_high = 3.5; double JPsi_mass = 3.097; int npt = 7; TFile* file1 = TFile::Open("HM185_JpsivnHist_etagap1p5_v30_eff_extdeta.root"); TFile ofile("v2vspt_fromfit_jpsi_HM185_250_deta1p5_doubleCB_v30_eff_exp_extdeta.root","RECREATE"); //v12 double alpha_fit[14] = {4.30986,3.50841,3.03436,2.73741,2.37934,2.10685,2.03615}; double n_fit[14] = {1.88853,1.9839,2.03198,2.07295,2.11001,2.15234,2.10154}; TF1* fmasssig[9]; TF1* fmassbkg[9]; TF1* fmasstotal[9]; TF1* fvn[9]; double pt[13]; double KET_ncq[13]; double v2[13]; double v2e[13]; double v2_bkg[13]; double v2_ncq[13]; double v2e_ncq[13]; double ptbin[14] = {0.2, 1.8, 3.0, 4.5, 6.0, 8.0, 10, 20}; double a[13]; double b[13]; double sigfrac[13]; TCanvas* c[10]; for(int i=0;i<npt;i++) { c[i] = new TCanvas(Form("c_%d",i),Form("c_%d",i),800,400); c[i]->Divide(2,1); } for(int i=0;i<npt;i++) { c[i]->cd(1)->SetTopMargin(0.06); c[i]->cd(1)->SetLeftMargin(0.18); c[i]->cd(1)->SetRightMargin(0.043); c[i]->cd(1)->SetBottomMargin(0.145); c[i]->cd(2)->SetTopMargin(0.06); c[i]->cd(2)->SetLeftMargin(0.18); c[i]->cd(2)->SetRightMargin(0.043); c[i]->cd(2)->SetBottomMargin(0.145); } TCanvas* c2 = new TCanvas("c2","c2",100,100); TLatex* tex = new TLatex; tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); TLatex* texCMS = new TLatex; texCMS->SetNDC(); texCMS->SetTextFont(42); texCMS->SetTextSize(0.05); texCMS->SetTextAlign(12); TH1D* hist = new TH1D("hist","",10,2.6,3.5); hist->SetLineWidth(0); //hist->GetYaxis()->SetRangeUser(0,0.3); hist->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); hist->GetYaxis()->SetTitle("v_{2}^{S+B}"); hist->GetXaxis()->CenterTitle(); hist->GetYaxis()->CenterTitle(); hist->GetXaxis()->SetTitleOffset(1.3); hist->GetYaxis()->SetTitleOffset(2); hist->GetXaxis()->SetLabelOffset(0.007); hist->GetYaxis()->SetLabelOffset(0.007); hist->GetXaxis()->SetTitleSize(0.045); hist->GetYaxis()->SetTitleSize(0.045); hist->GetXaxis()->SetTitleFont(42); hist->GetYaxis()->SetTitleFont(42); hist->GetXaxis()->SetLabelFont(42); hist->GetYaxis()->SetLabelFont(42); hist->GetXaxis()->SetLabelSize(0.04); hist->GetYaxis()->SetLabelSize(0.04); hist->SetMinimum(0.01); hist->SetMaximum(0.33); c2->cd(); hist->Draw(); for(int i=0;i<npt;i++) { TH1D* h_data = (TH1D*)file1->Get(Form("massjpsi_pt%d",i)); h_data->SetMinimum(0); h_data->SetMarkerSize(0.8); h_data->SetMarkerStyle(20); h_data->SetLineWidth(1); h_data->SetOption("e"); h_data->Rebin(2); h_data->GetXaxis()->SetRangeUser(2.6,3.5); h_data->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)"); h_data->GetYaxis()->SetTitle("Entries / 10 MeV"); h_data->GetXaxis()->CenterTitle(); h_data->GetYaxis()->CenterTitle(); h_data->GetXaxis()->SetTitleOffset(1.3); h_data->GetYaxis()->SetTitleOffset(2); h_data->GetXaxis()->SetLabelOffset(0.007); h_data->GetYaxis()->SetLabelOffset(0.007); h_data->GetXaxis()->SetTitleSize(0.045); h_data->GetYaxis()->SetTitleSize(0.045); h_data->GetXaxis()->SetTitleFont(42); h_data->GetYaxis()->SetTitleFont(42); h_data->GetXaxis()->SetLabelFont(42); h_data->GetYaxis()->SetLabelFont(42); h_data->GetXaxis()->SetLabelSize(0.04); h_data->GetYaxis()->SetLabelSize(0.04); h_data->GetXaxis()->SetNoExponent(true); ((TGaxis*)h_data->GetXaxis())->SetMaxDigits(7); h_data->SetMaximum(h_data->GetMaximum()*1.5); TH1D* h_pt = (TH1D*)file1->Get(Form("Ptjpsi_eff_pt%d",i)); TH1D* h_KET = (TH1D*)file1->Get(Form("KETjpsi_eff_pt%d",i)); pt[i] = h_pt->GetMean(); KET_ncq[i] = h_KET->GetMean()/2.0; c[i]->cd(1); /*p definitions [0] CB1 yield; [1] Common mean of CB and Gaus; [2] CB1 sigma; [3] CB n; [4] CB alpha; [5] CB2 yield; [6] CB2 sigma; [7-10] poly 3; [11] v2 signal; [12-13] v2 bkg; */ TF1* f = new TF1(Form("f_%d",i), crystalball_function_total, fit_range_low, fit_range_high, 11); f->SetLineColor(2); f->SetLineWidth(1); f->SetParNames("CB1_Yield","common_mean","CB1_sigma","CB_N","CB_Alpha","CB2_Yield","CB2_Sigma","Pol0","Pol1","Pol2","Pol3"); //first fit data mass signal + bkg f->SetParameter(0,10000.); f->SetParameter(1,JPsi_mass); f->SetParameter(2,0.03); f->SetParameter(3,1.0); f->SetParameter(4,1.0); f->SetParameter(5,10000); f->SetParameter(6,0.03); f->SetParLimits(2,0.01,0.1); f->SetParLimits(6,0.01,0.1); //fix alpha & n from MC f->FixParameter(4,alpha_fit[i]); f->FixParameter(3,n_fit[i]); f->FixParameter(1,JPsi_mass); //for first few attempt fix mean of gaussian to get reasonable estimation of other pars; later open it up h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high); f->ReleaseParameter(1); //now let gaussian mean float h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high); h_data->Fit(Form("f_%d",i),"L m","",fit_range_low,fit_range_high); //draw D0 signal separately TF1* f1 = new TF1(Form("f_sig_%d",i), crystalball_function_signal, fit_range_low, fit_range_high, 7); f1->SetLineColor(kOrange-3); f1->SetLineWidth(1); f1->SetLineStyle(2); f1->SetFillColorAlpha(kOrange-3,0.3); f1->SetFillStyle(1001); f1->FixParameter(0,f->GetParameter(0)); f1->FixParameter(1,f->GetParameter(1)); f1->FixParameter(2,f->GetParameter(2)); f1->FixParameter(3,f->GetParameter(3)); f1->FixParameter(4,f->GetParameter(4)); f1->FixParameter(5,f->GetParameter(5)); f1->FixParameter(6,f->GetParameter(6)); fmasssig[i] = (TF1*)f1->Clone(); fmasssig[i]->SetName(Form("masssigfcn_pt%d",i)); fmasssig[i]->Write(); f1->Draw("LSAME"); //draw poly bkg separately TF1* f3 = new TF1(Form("f_bkg_%d",i),"[7] + [8]*x + [9]*x*x + [10]*x*x*x", fit_range_low, fit_range_high); f3->SetLineColor(4); f3->SetLineWidth(1); f3->SetLineStyle(2); f3->FixParameter(7,f->GetParameter(7)); f3->FixParameter(8,f->GetParameter(8)); f3->FixParameter(9,f->GetParameter(9)); f3->FixParameter(10,f->GetParameter(10)); fmassbkg[i] = (TF1*)f3->Clone(); fmassbkg[i]->SetName(Form("massbkgfcn_pt%d",i)); fmassbkg[i]->Write(); f3->Draw("LSAME"); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); TLegend* leg = new TLegend(0.21,0.4,0.5,0.65,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.045); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h_data,"data","p"); leg->AddEntry(f,"Fit","L"); leg->AddEntry(f1,"J/#psi Signal","f"); leg->AddEntry(f3,"Combinatorial","l"); leg->Draw("SAME"); sigfrac[i] = f1->Integral(2.94,3.24)/f->Integral(2.94,3.24); //c->Print(Form("plots/massfit_pt%d.pdf",i)); //fit vn //[9] is vn_sig //[10-11] is vn bkg, const + linear vn(pT) TGraphErrors* vn_data = (TGraphErrors*)file1->Get(Form("v2_mass_pt%d",i)); c[i]->cd(2); hist->Draw(); TF1* fmass_combinemassvnfit = new TF1(Form("fmass_combinemassvnfit_%d",i),crystalball_function_total, fit_range_low, fit_range_high, 11); TF1* fvn_combinemassvnfit = new TF1(Form("fvn_combinemassvnfit_%d",i), crystalball_function_v2, fit_range_low, fit_range_high, 15); fmass_combinemassvnfit->SetLineColor(2); fmass_combinemassvnfit->SetLineWidth(1); fvn_combinemassvnfit->SetLineColor(2); fvn_combinemassvnfit->SetLineWidth(1); ROOT::Math::WrappedMultiTF1 wfmass_combinemassvnfit(*fmass_combinemassvnfit,1); ROOT::Math::WrappedMultiTF1 wfvn_combinemassvnfit(*fvn_combinemassvnfit,1); ROOT::Fit::DataOptions opt; ROOT::Fit::DataRange range_massfit; range_massfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datamass(opt,range_massfit); ROOT::Fit::FillData(datamass, h_data); ROOT::Fit::DataRange range_vnfit; range_vnfit.SetRange(fit_range_low,fit_range_high); ROOT::Fit::BinData datavn(opt,range_vnfit); ROOT::Fit::FillData(datavn, vn_data); ROOT::Fit::Chi2Function chi2_B(datamass, wfmass_combinemassvnfit); ROOT::Fit::Chi2Function chi2_SB(datavn, wfvn_combinemassvnfit); GlobalChi2_poly3bkg_floatwidth globalChi2(chi2_B, chi2_SB); ROOT::Fit::Fitter fitter; const int Npar = 15; double par0[Npar]; for( int ipar = 0; ipar < f->GetNpar(); ipar++ ) par0[ipar] = f->GetParameter(ipar); par0[11] = 0.01; par0[12] = 0.10; par0[13] = 0.05; par0[14] = 0.01; fitter.Config().SetParamsSettings(Npar,par0); // fix parameter fitter.Config().ParSettings(0).Fix(); fitter.Config().ParSettings(1).Fix(); fitter.Config().ParSettings(2).Fix(); fitter.Config().ParSettings(3).Fix(); fitter.Config().ParSettings(4).Fix(); fitter.Config().ParSettings(5).Fix(); fitter.Config().ParSettings(6).Fix(); fitter.Config().ParSettings(7).Fix(); fitter.Config().ParSettings(8).Fix(); fitter.Config().ParSettings(9).Fix(); fitter.Config().ParSettings(10).Fix(); fitter.Config().MinimizerOptions().SetPrintLevel(0); fitter.Config().SetMinimizer("Minuit2","Migrad"); fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),true); ROOT::Fit::FitResult result = fitter.Result(); result.Print(std::cout); fmass_combinemassvnfit->SetFitResult( result, iparmassfit_poly3bkg_floatwidth); fmass_combinemassvnfit->SetRange(range_massfit().first, range_massfit().second); fmass_combinemassvnfit->SetLineColor(kRed); h_data->GetListOfFunctions()->Add(fmass_combinemassvnfit); //c->cd(); //h_data->Draw(); fvn_combinemassvnfit->SetFitResult( result, iparvnfit_poly3bkg_floatwidth); fvn_combinemassvnfit->SetRange(range_vnfit().first, range_vnfit().second); fvn_combinemassvnfit->SetLineColor(2); //fvn_combinemassvnfit->SetLineStyle(2); vn_data->GetListOfFunctions()->Add(fvn_combinemassvnfit); vn_data->SetTitle(""); vn_data->SetMarkerSize(0.8); vn_data->SetLineWidth(1); //c1->cd(); vn_data->Draw("PESAME"); fvn[i] = (TF1*)fvn_combinemassvnfit->Clone(); fvn[i]->SetName(Form("vnfit_pt%d",i)); fvn[i]->Write(); fmasstotal[i] = (TF1*)fmass_combinemassvnfit->Clone(); fmasstotal[i]->SetName(Form("masstotalfcn_pt%d",i)); fmasstotal[i]->Write(); tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250"); tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1])); //tex->DrawLatex(0.22,0.74,"1.4 < |y_{cm}+0.46| < 2.4"); tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94"); //tex->DrawLatex(0.22,0.68,"|#Delta#eta| > 2"); //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}"); texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}"); texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}"); v2[i] = fvn_combinemassvnfit->GetParameter(11); v2e[i] = fvn_combinemassvnfit->GetParError(11); v2_bkg[i] = fvn_combinemassvnfit->GetParameter(12) + fvn_combinemassvnfit->GetParameter(13) * JPsi_mass; v2_ncq[i] = v2[i]/2.0; v2e_ncq[i] = v2e[i]/2.0; a[i] = fvn_combinemassvnfit->GetParameter(12); b[i] = fvn_combinemassvnfit->GetParameter(13); TF1* fvnbkg = new TF1(Form("fvnbkg_%d",1),"( [0] + [1] * x)", fit_range_low, fit_range_high); fvnbkg->FixParameter(0,fvn_combinemassvnfit->GetParameter(12)); fvnbkg->FixParameter(1,fvn_combinemassvnfit->GetParameter(13)); fvnbkg->SetName(Form("fvnbkg_fcn_pt%d",i)); fvnbkg->Write(); fvnbkg->SetLineStyle(7); //fvnbkg->Draw("LSAME"); TF1* fvnsig = new TF1(Form("fvnsig_%d",i),function_v2_sig,fit_range_low,fit_range_high,12); for(int k=0;k<12;k++) { fvnsig->FixParameter(k,fvn_combinemassvnfit->GetParameter(k)); } fvnsig->SetLineColor(kOrange-3); fvnsig->SetLineWidth(1); fvnsig->SetLineStyle(2); fvnsig->SetFillColorAlpha(kOrange-3,0.3); fvnsig->SetFillStyle(1001); //fvnsig->Draw("LSAME"); TLegend* leg1 = new TLegend(0.72,0.525,0.91,0.65,NULL,"brNDC"); leg1->SetBorderSize(0); leg1->SetTextSize(0.045); leg1->SetTextFont(42); leg1->SetFillStyle(0); leg1->AddEntry(h_data,"data","p"); leg1->AddEntry(fvn_combinemassvnfit,"Fit","l"); //leg1->AddEntry(fvnsig,"#alpha(#it{m}_{#mu#mu})v_{2}^{S}","f"); leg1->Draw("SAME"); double xmass[200]; double pullmass[200]; float Chi2=0; int ndf = (fit_range_high - fit_range_low)/0.01 - 8; for(int k=0;k<h_data->GetNbinsX();k++) { xmass[k] = h_data->GetBinCenter(k); pullmass[k] = (h_data->GetBinContent(k) - fmass_combinemassvnfit->Eval(xmass[k]))/h_data->GetBinError(k); if(fabs(pullmass[k])<5) { //cout<<pullmass[k]<<endl; Chi2 += pullmass[k]*pullmass[k]; } } c[i]->cd(1); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.0f/%d",Chi2,ndf)); double xv2[200]; double pullv2[200]; double v2y[200]; float Chi2v2=0; int ndfv2 = 8 - 4; //Nbin - Npar for(int k=0;k<vn_data->GetN()-1;k++) { vn_data->GetPoint(k,xv2[k],v2y[k]); //xv2[k] = vn_dara->GetBinCenter(k); pullv2[k] = (v2y[k] - fvn_combinemassvnfit->Eval(xv2[k]))/vn_data->GetErrorY(k); cout<<k<<": "<<pullv2[k]<<endl; if(fabs(pullv2[k])<1000) { //cout<<pullmass[k]<<endl; Chi2v2 += pullv2[k]*pullv2[k]; } cout<<"fcn: "<<fvn_combinemassvnfit->Eval(xv2[k])<<endl; cout<<"data: "<<v2y[k]<<endl; } c[i]->cd(2); tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.1f/%d",Chi2v2,ndfv2)); } for(int i=0;i<npt;i++) { c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.pdf",i)); c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.gif",i)); } TGraphErrors* v2plot = new TGraphErrors(npt,pt,v2,0,v2e); TGraphErrors* v2ncqplot = new TGraphErrors(npt,KET_ncq,v2_ncq,0,v2e_ncq); TGraphErrors* v2bkgplot = new TGraphErrors(npt,pt,v2_bkg,0,0); v2plot->SetName("v2vspt"); v2ncqplot->SetName("v2vsKET_ncq"); v2bkgplot->SetName("v2bkgvspt"); v2plot->Write(); v2ncqplot->Write(); v2bkgplot->Write(); }
void fitX(TString infname="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151202_bPt0jpsiPt0tkPt0p5/finder_pp_merged.root") { TFile *inf = new TFile(infname.Data()); TTree *ntmix = (TTree*) inf->Get("Bfinder/ntmix"); TH1D *h = new TH1D("h","",40,3.6,4); TCut cutTrk = "1"; //original YJ //TCut cutTrk = "Btrk1PixelHit>=2&&Btrk1StripHit>=7&&Btrk1Chi2ndf<5&&Btrk2PixelHit>=2&&Btrk2StripHit>=7&&Btrk2Chi2ndf<5"; TCut cutTotal="Btype==7&&Bpt>10&&abs(Beta)<10&&sqrt((Bmumueta-Btrk1Eta)*(Bmumueta-Btrk1Eta)+(Bmumuphi-Btrk1Phi)*(Bmumuphi-Btrk1Phi))<9999"&&cutTrk; TCanvas *c = new TCanvas("c","",750,600); ntmix->Draw("Bmass>>h",cutTotal); TFile*output=new TFile("histoX.root","recreate"); output->cd(); h->Write(); output->Close(); h->Sumw2(); TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x+[8]*x*x*x+[9]*x*x*x*x+[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f->SetLineColor(4); f->SetParameters(-2.2597e4,1.326e4,-1.727e3,50,3.686,0.00357,1,3.8725,0.0054); f->FixParameter(4,3.686); f->FixParameter(5,0.00357); f->FixParameter(7,3.8725); h->Fit("f","LL"); h->Fit("f",""); h->Fit("f","LL"); h->Fit("f","LL","",3.65,3.94); h->Fit("f","LL","",3.65,3.94); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(7); h->Fit("f","LL","",3.65,3.94); h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y"); TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+0*Gaus(x,[4],[5])+0*Gaus(x,[7],[5])"); f2->SetParameter(0,f->GetParameter(0)); f2->SetParameter(1,f->GetParameter(1)); f2->SetParameter(2,f->GetParameter(2)); TF1 *f3 = new TF1("f3","[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f3->SetParameter(3,f->GetParameter(3)); f3->SetParameter(4,f->GetParameter(4)); f3->SetParameter(5,f->GetParameter(5)); f3->SetParameter(6,f->GetParameter(6)); f3->SetParameter(7,f->GetParameter(7)); f3->SetParameter(8,f->GetParameter(8)); f->SetLineColor(4); f2->SetLineColor(4); f3->SetRange(3.65,3.94); f2->SetRange(3.65,3.94); f2->SetLineStyle(2); f3->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)"); l->Draw(); TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)"); l2->Draw(); TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary"); l3->Draw(); TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV"); l4->Draw(); cout<<ntmix->GetEntries()<<endl; TH1D *hProj = (TH1D*)h->Clone("hProj"); hProj->Clear(); f->SetRange(3.6,4); for (int i=0;i<h->GetEntries()*11;i++) { hProj->Fill(f->GetRandom()); } TCanvas *c2 = new TCanvas("c2","",750,600); hProj->SetTitle("Estimated Projection"); hProj->Draw("e"); }