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)); }
int fit_dscb(TH1F *&hrsp, const double nsigma, const double jtptmin, const int niter, const string alg) { if (0==hrsp) { cout<<"ERROR: Empty pointer to fit_dscb()"<<endl;return -1; } // first use a gaussian to constrain crystal ball gaussian core fit_gaussian(hrsp, nsigma, jtptmin, niter); TF1* fgaus = hrsp->GetFunction("fgaus"); if (0==fgaus) { hrsp->GetListOfFunctions()->Delete(); return -1; } // implementation of the low pt bias threshold string histname = hrsp->GetName(); //double ptRefMax(1.0),rspMax(0.0); double fitrange_min(0.4); double fitrange_max(1.6); //cout <<" \t \t xmin : " << fitrange_min << "\t" << fitrange_max << endl; TF1* fdscb = new TF1("fdscb",fnc_dscb,fitrange_min,fitrange_max,7); fdscb->SetLineWidth(2); fdscb->SetLineStyle(2); double norm = fgaus->GetParameter(0); double mean = fgaus->GetParameter(1); double sigma= fgaus->GetParameter(2); double aone(2.0),atwo(2.0),pone(10.0),ptwo(10.0); TVirtualFitter::SetDefaultFitter("Minuit"); int fitstatus(0); for (int i=0;i<niter;i++) { fdscb->SetParameter(0,norm); // N fdscb->SetParameter(1,mean); // mean fdscb->SetParameter(2,sigma);// sigma fdscb->SetParameter(3,aone); // a1 fdscb->SetParameter(4,pone); // p1 fdscb->SetParameter(5,atwo); // a2 fdscb->SetParameter(6,ptwo); // p2 fdscb->FixParameter(1,mean); fdscb->FixParameter(2,sigma); if (i>0) fdscb->FixParameter(3,aone); else fdscb->SetParLimits(3,1.,50.); if (i>1) fdscb->FixParameter(5,atwo); else fdscb->SetParLimits(5,1.,50.); fdscb->SetParLimits(4,0.,100.); fdscb->SetParLimits(6,0.,100.); fitstatus = hrsp->Fit(fdscb,"RQB+"); if (0==fitstatus) i=999; delete fdscb; fdscb = hrsp->GetFunction("fdscb"); if (0==fdscb) return -1; norm = fdscb->GetParameter(0); aone = fdscb->GetParameter(3); pone = fdscb->GetParameter(4); atwo = fdscb->GetParameter(5); ptwo = fdscb->GetParameter(6); // reset sigma and mean to gauss values... fdscb->SetParameter(1,fgaus->GetParameter(1)); fdscb->SetParError (1,fgaus->GetParError(1)); fdscb->SetParameter(2,fgaus->GetParameter(2)); fdscb->SetParError (2,fgaus->GetParError(2)); } if (0!=fitstatus){ cout<<"fit_fdscb() to "<<hrsp->GetName() <<" failed. Fitstatus: "<<fitstatus<<endl; hrsp->GetFunction("fdscb")->Delete(); } return fitstatus; }
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* 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* 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; }
int fit_dscb(TH1F*& hrsp, const double nsigma, const double jtptmin, const int niter, const string alg, const double fitmin, const double fitmax ) { if (0==hrsp) { cout<<"ERROR: Empty pointer to fit_dscb()"<<endl;return -1; } // first use a gaussian to constrain crystal ball gaussian core fit_gaussian(hrsp, nsigma, jtptmin, niter, alg); TF1* fgaus = hrsp->GetFunction("fgaus"); if (0==fgaus) { hrsp->GetListOfFunctions()->Delete(); return -1; } // implementation of the low pt bias threshold string histname = hrsp->GetName(); double ptRefMax(1.0),rspMax(0.0); int pos1 = histname.find("RefPt"); int pos2 = histname.find("to",pos1); string ss = histname.substr(pos1+5,pos2); if (from_string(ptRefMax,ss,std::dec)) { if (histname.find("RelRsp")==0) rspMax = jtptmin/ptRefMax; if (histname.find("AbsRsp")==0) rspMax = jtptmin-ptRefMax; } double fitrange_min(fitmin); double fitrange_max(fitmax); fitrange_min = std::max(rspMax,fitmin); adjust_fitrange(hrsp,fitrange_min,fitrange_max); TF1* fdscb = new TF1("fdscb",fnc_dscb,fitrange_min,fitrange_max,7); fdscb->SetLineWidth(2); fdscb->SetLineStyle(2); double norm = 2*fgaus->GetParameter(0); double mean = fgaus->GetParameter(1); double sigma= fgaus->GetParameter(2); //cout << hrsp->GetName() << " fgaus "<< mean << " \t " << hrsp->GetMean() << endl; // double norm = 2*hrsp->GetMaximum(); // double mean = hrsp->GetMean(); // //double mean = GetPeak(hrsp); // cout << " mean : " << mean << " hist mean : "<< hrsp->GetMean() << endl; // double sigma= hrsp->GetRMS(); double aone(2.0),atwo(2.0),pone(10.0),ptwo(10.0); //double aone(1.0),atwo(1.0),pone(10.0),ptwo(10.0); TVirtualFitter::SetDefaultFitter("Minuit"); int fitstatus(0); for (int i=0;i<niter;i++) { fdscb->SetParameter(0,norm); // N fdscb->SetParameter(1,mean); // mean fdscb->SetParameter(2,sigma);// sigma fdscb->SetParameter(3,aone); // a1 fdscb->SetParameter(4,pone); // p1 fdscb->SetParameter(5,atwo); // a2 fdscb->SetParameter(6,ptwo); // p2 fdscb->FixParameter(1,mean); fdscb->FixParameter(2,sigma); if (i>0) fdscb->FixParameter(3,aone); else{ fdscb->SetParLimits(3,0.,20.); //! best } if (i>1) fdscb->FixParameter(5,atwo); else{ fdscb->SetParLimits(5,0.,20.); //! best } //! best fdscb->SetParLimits(4,0.,60.); fdscb->SetParLimits(6,0.,60.); fitstatus = hrsp->Fit(fdscb,"RQ+"); if (0==fitstatus) i=999; delete fdscb; fdscb = hrsp->GetFunction("fdscb"); if (0==fdscb) return -1; norm = fdscb->GetParameter(0); aone = fdscb->GetParameter(3); pone = fdscb->GetParameter(4); atwo = fdscb->GetParameter(5); ptwo = fdscb->GetParameter(6); //cout << " aone : " << aone << " atwo : " << atwo << " pone : " << pone << " ptwo : " << ptwo << endl; //reset sigma and mean to gauss values... fdscb->SetParameter(1,fgaus->GetParameter(1)); fdscb->SetParError (1,fgaus->GetParError(1)); fdscb->SetParameter(2,fgaus->GetParameter(2)); fdscb->SetParError (2,fgaus->GetParError(2)); } if (0!=fitstatus){ cout<<"fit_fdscb() to "<<alg.c_str()<<" " <<hrsp->GetName() <<" failed. Fitstatus: "<<fitstatus<<endl; hrsp->GetFunction("fdscb")->Delete(); } else fdscb->ResetBit(TF1::kNotDraw); //cout << " aone : " << aone << " atwo : " << atwo << " pone : " << pone << " ptwo : " << ptwo << endl; return fitstatus; }
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; }
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 plotPedestalAnalysis(string inputFileName, string outputDIR, bool testDoubleGaussianChannels){ system(("mkdir -p "+outputDIR).c_str()); setTDRStyle(); gROOT->SetBatch(kTRUE); TFile* inputFile = TFile::Open(inputFileName.c_str(),"READ"); inputFile->cd(); TTree* tree = (TTree*) inputFile->Get("pedestalFullNoise"); uint32_t detid,fedKey; uint16_t fecCrate,fecSlot, fecRing, ccuAdd, ccuChan, lldChannel, fedId, fedCh, apvId, stripId; float fitChi2Probab, kSProbab, jBProbab, aDProbab, fitChi2; float noiseSkewness, noiseKurtosis; float fitGausMean, fitGausSigma, fitGausNormalization; float fitGausMeanError, fitGausSigmaError, fitGausNormalizationError; vector<float>* noiseDistribution = 0; vector<float>* noiseDistributionError = 0; float nBin, xMin, xMax; tree->SetBranchStatus("*",kFALSE); tree->SetBranchStatus("detid",kTRUE); tree->SetBranchStatus("fedKey",kTRUE); tree->SetBranchStatus("fecCrate",kTRUE); tree->SetBranchStatus("fecSlot",kTRUE); tree->SetBranchStatus("fecRing",kTRUE); tree->SetBranchStatus("ccuAdd",kTRUE); tree->SetBranchStatus("ccuChan",kTRUE); tree->SetBranchStatus("lldChannel",kTRUE); tree->SetBranchStatus("fedId",kTRUE); tree->SetBranchStatus("fedCh",kTRUE); tree->SetBranchStatus("apvId",kTRUE); tree->SetBranchStatus("stripId",kTRUE); tree->SetBranchStatus("fitChi2",kTRUE); tree->SetBranchStatus("fitChi2Probab",kTRUE); tree->SetBranchStatus("kSProbab",kTRUE); tree->SetBranchStatus("jBProbab",kTRUE); tree->SetBranchStatus("aDProbab",kTRUE); tree->SetBranchStatus("fitGausNormalization",kTRUE); tree->SetBranchStatus("fitGausMean",kTRUE); tree->SetBranchStatus("fitGausSigma",kTRUE); tree->SetBranchStatus("fitGausNormalizationError",kTRUE); tree->SetBranchStatus("fitGausMeanError",kTRUE); tree->SetBranchStatus("fitGausSigmaError",kTRUE); tree->SetBranchStatus("noiseSkewness",kTRUE); tree->SetBranchStatus("noiseKurtosis",kTRUE); tree->SetBranchStatus("noiseDistribution",kTRUE); tree->SetBranchStatus("noiseDistributionError",kTRUE); tree->SetBranchStatus("nBin",kTRUE); tree->SetBranchStatus("xMin",kTRUE); tree->SetBranchStatus("xMax",kTRUE); tree->SetBranchAddress("detid",&detid); tree->SetBranchAddress("fedKey",&fedKey); tree->SetBranchAddress("fecCrate",&fecCrate); tree->SetBranchAddress("fecSlot",&fecSlot); tree->SetBranchAddress("fecRing",&fecRing); tree->SetBranchAddress("ccuAdd",&ccuAdd); tree->SetBranchAddress("ccuChan",&ccuChan); tree->SetBranchAddress("lldChannel",&lldChannel); tree->SetBranchAddress("fedId",&fedId); tree->SetBranchAddress("fedCh",&fedCh); tree->SetBranchAddress("apvId",&apvId); tree->SetBranchAddress("stripId",&stripId); tree->SetBranchAddress("fitGausNormalization",&fitGausNormalization); tree->SetBranchAddress("fitGausMean",&fitGausMean); tree->SetBranchAddress("fitGausSigma",&fitGausSigma); tree->SetBranchAddress("fitGausNormalizationError",&fitGausNormalizationError); tree->SetBranchAddress("fitGausMeanError",&fitGausMeanError); tree->SetBranchAddress("fitGausSigmaError",&fitGausSigmaError); tree->SetBranchAddress("fitChi2",&fitChi2); tree->SetBranchAddress("fitChi2Probab",&fitChi2Probab); tree->SetBranchAddress("noiseSkewness",&noiseSkewness); tree->SetBranchAddress("noiseKurtosis",&noiseKurtosis); tree->SetBranchAddress("kSProbab",&kSProbab); tree->SetBranchAddress("aDProbab",&aDProbab); tree->SetBranchAddress("jBProbab",&jBProbab); tree->SetBranchAddress("noiseDistribution",&noiseDistribution); tree->SetBranchAddress("noiseDistributionError",&noiseDistributionError); tree->SetBranchAddress("nBin",&nBin); tree->SetBranchAddress("xMin",&xMin); tree->SetBranchAddress("xMax",&xMax); TFile* badStripsNFilledBins = new TFile((outputDIR+"/badStripsNFilledBins.root").c_str(),"RECREATE"); TFile* badKsTest = new TFile((outputDIR+"/badStripsKsTest.root").c_str(),"RECREATE"); TFile* badjBTest = new TFile((outputDIR+"/badStripsjBTest.root").c_str(),"RECREATE"); TFile* badChi2Test = new TFile((outputDIR+"/badStripsChi2Test.root").c_str(),"RECREATE"); TFile* badaDTest = new TFile((outputDIR+"/badStripsaDTest.root").c_str(),"RECREATE"); TFile* badCombinedTest = new TFile((outputDIR+"/badStripsCombined.root").c_str(),"RECREATE"); TFile* badJBNotKSTest = new TFile((outputDIR+"/badStripsjBNotKS.root").c_str(),"RECREATE"); TFile* badaDNotKSandjBTest = new TFile((outputDIR+"/badStripaDNotKSNotjB.root").c_str(),"RECREATE"); TFile* badChi2NotKSandjBandaDTest = new TFile((outputDIR+"/badStripsChi2NotKsandjBandaD.root").c_str(),"RECREATE"); long int nbadNFilledBins = 0; long int nbadKsTest = 0; long int nbadjBTest = 0; long int nbadaDTest = 0; long int nbadChi2Test = 0; long int nbadCombinedTest = 0; long int nbadJBNotKSTest = 0; long int nbadaDNotKSandjBTest = 0; long int nbadChi2NotKSandjBandaDTest = 0; long int nbadDoublePeakDistance = 0; long int nbadDoublePeakAshman = 0; long int nbadDoublePeakChi2 = 0; long int nbadDoublePeakAmplitude = 0; long int nbadDoublePeakBimodality = 0; long int nbadDoublePeakCombined = 0; TCanvas* canvas = new TCanvas("canvas","canvas",600,650); map<uint32_t,uint32_t> moduleDenominator; map<uint32_t,uint32_t> moduleNumerator; // map<uint32_t,uint32_t> moduleNonEdgeNumerator; // map<uint32_t,uint32_t> moduleAPVEdgeNumerator; map<uint32_t,uint32_t> moduleNumeratorFilledBins; map<uint32_t,uint32_t> moduleNumeratorKS; map<uint32_t,uint32_t> moduleNumeratorJB; map<uint32_t,uint32_t> moduleNumeratorDoublePeak; vector<TrackerStrip> badStrip; TH1F* noiseHist = NULL; TF1* noiseFit = NULL; TF1* noiseFit2Gaus = NULL; TFitResultPtr result; TH1F* chi2Distance = new TH1F("chi2Distance","",100,0,1); chi2Distance->Sumw2(); TH1F* peakDistance = new TH1F("peakDistance","",100,0,3); peakDistance->Sumw2(); TH1F* ashmanDistance = new TH1F("ashmanDistance","",100,0,5); ashmanDistance->Sumw2(); TH1F* bimodalityDistance = new TH1F("bimodalityDistance","",100,0,1); bimodalityDistance->Sumw2(); TH1F* amplitudeRatioDistance = new TH1F("amplitudeRatioDistance","",100,0,3); amplitudeRatioDistance->Sumw2(); TFile* multiPeakChannelsChi2 = new TFile((outputDIR+"/multiPeakChannelsChi2.root").c_str(),"RECREATE"); TFile* multiPeakChannelsDistance = new TFile((outputDIR+"/multiPeakChannelsDistance.root").c_str(),"RECREATE"); TFile* multiPeakChannelsAshman = new TFile((outputDIR+"/multiPeakChannelsAshman.root").c_str(),"RECREATE"); TFile* multiPeakChannelsAmplitude = new TFile((outputDIR+"/multiPeakChannelsAmplitude.root").c_str(),"RECREATE"); TFile* multiPeakChannelsBimodality = new TFile((outputDIR+"/multiPeakChannelsBimodality.root").c_str(),"RECREATE"); TFile* multiPeakChannelsCombined = new TFile((outputDIR+"/multiPeakChannelsCombined.root").c_str(),"RECREATE"); int nonNullBins = 0; float chi2Ratio = 0; float distance = 0; float ashman = 0; float bimodality = 0; float amplitudeRatio = 0; bool isfound = false; string fedKeyStr ; TString name ; std::map<string,string> fitParam; for(long int iChannel = 0; iChannel < tree->GetEntries(); iChannel++){ tree->GetEntry(iChannel); cout.flush(); if(iChannel %10000 == 0) cout<<"\r"<<"iChannel "<<100*double(iChannel)/(tree->GetEntries()/reductionFactor)<<" % "; if(iChannel > double(tree->GetEntries())/reductionFactor) break; // skip problematic fed id isfound = false; for(auto skipfed : skipFEDid){ if(fedId == skipfed) isfound = true; } if(isfound) continue; // make selections to identify bad noisy channels (not gaussian ones) std::stringstream stream; stream << std::hex << fedKey; fedKeyStr = stream.str(); if(fedKeyStr.size() == 4) name = Form("fecCrate%d_fecSlot%d_fecRing%d_ccuAdd%d_ccuCh%d_fedKey0x0000%s_lldCh%d_apv%d_strip%d",fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,fedKeyStr.c_str(),lldChannel,apvId,stripId); else if(fedKeyStr.size() == 5) name = Form("fecCrate%d_fecSlot%d_fecRing%d_ccuAdd%d_ccuCh%d_fedKey0x000%s_lldCh%d_apv%d_strip%d",fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,fedKeyStr.c_str(),lldChannel,apvId,stripId); fitParam.clear(); stringstream sMean; sMean << std::scientific << fitGausMean; fitParam["fitGausMean"] = sMean.str(); stringstream sSigma; sSigma << std::scientific << fitGausSigma; fitParam["fitGausSigma"] = sSigma.str(); stringstream sSkew; sSkew << std::scientific << noiseSkewness; fitParam["noiseSkewness"] = sSkew.str(); stringstream sKurt; sKurt << std::scientific << noiseKurtosis; fitParam["noiseKurtosis"] = sKurt.str(); stringstream sKS; sKS << std::scientific << kSProbab; fitParam["kSProbab"] = sKS.str(); stringstream sJB; sJB << std::scientific << jBProbab; fitParam["jBProbab"] = sJB.str(); stringstream sChi2; sChi2 << std::scientific << fitChi2Probab; fitParam["fitChi2Probab"] = sChi2.str(); stringstream sAD; sAD << std::scientific << aDProbab; fitParam["aDProbab"] = sAD.str(); moduleDenominator[detid] = moduleDenominator[detid]+1; if(noiseHist == NULL){ noiseHist = new TH1F ("noiseHist","",nBin,xMin,xMax); noiseHist->Sumw2(); } noiseHist->Reset(); for(int iBin = 0; iBin < noiseDistribution->size(); iBin++){ noiseHist->SetBinContent(iBin+1,noiseDistribution->at(iBin)); noiseHist->SetBinError(iBin+1,noiseDistributionError->at(iBin)); } if(noiseFit == NULL) noiseFit = new TF1 ("noiseFist","gaus(0)",xMin,xMax); noiseFit->SetRange(xMin,xMax); noiseFit->SetParameters(fitGausNormalization,fitGausMean,fitGausSigma); noiseFit->SetParError(0,fitGausNormalizationError); noiseFit->SetParError(1,fitGausMeanError); noiseFit->SetParError(2,fitGausSigmaError); nonNullBins = 0; for(int iBin = 0; iBin < noiseHist->GetNbinsX(); iBin++){ if(noiseHist->GetBinContent(iBin+1) != 0) nonNullBins++; } if(nonNullBins < nFilledBinSelection or noiseHist->GetRMS() < minimumRMS){ badStripsNFilledBins->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); nbadNFilledBins++; moduleNumeratorFilledBins[detid] +=1; continue; } if(kSProbab < quantile3sigma){ badKsTest->cd(); nbadKsTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); moduleNumeratorKS[detid] += 1; } if(jBProbab < quantile5sigma){ badjBTest->cd(); nbadjBTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(fitChi2Probab < quantile4sigma){ badChi2Test->cd(); nbadChi2Test++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(aDProbab < quantile3sigma){ badaDTest->cd(); nbadaDTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(jBProbab < quantile5sigma and kSProbab > quantile3sigma and kSProbab < quantile){ badJBNotKSTest->cd(); nbadJBNotKSTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); moduleNumeratorJB[detid] += 1; } if(aDProbab < quantile3sigma and jBProbab > quantile5sigma and kSProbab > quantile3sigma and kSProbab < quantile){ badaDNotKSandjBTest->cd(); nbadaDNotKSandjBTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(fitChi2Probab < quantile4sigma and jBProbab > quantile5sigma and kSProbab > quantile3sigma and kSProbab < quantile and aDProbab > quantile3sigma){ badChi2NotKSandjBandaDTest->cd(); nbadChi2NotKSandjBandaDTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(kSProbab < quantile3sigma or (kSProbab > quantile3sigma and kSProbab < quantile and jBProbab < quantile5sigma) or (kSProbab > quantile3sigma and kSProbab < quantile and jBProbab > quantile5sigma and aDProbab < quantile3sigma) or (kSProbab > quantile3sigma and kSProbab < quantile and jBProbab > quantile5sigma and aDProbab > quantile3sigma and fitChi2Probab < quantile4sigma)){ badCombinedTest->cd(); nbadCombinedTest++; moduleNumerator[detid] = moduleNumerator[detid]+1; //if(stripId == 1 or stripId == 128) // moduleAPVEdgeNumerator[detid] = moduleAPVEdgeNumerator[detid]+1; //else // moduleNonEdgeNumerator[detid] = moduleNonEdgeNumerator[detid]+1; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); name = Form("fecCrate%d_fecSlot%d_fecRing%d_ccuAdd%d_ccuCh%d_fedKey0x0000%s_lldCh%d_apv%d_strip%d",fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,fedKeyStr.c_str(),lldChannel,apvId,stripId); badStrip.push_back(TrackerStrip(fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,uint32_t(atoi(fedKeyStr.c_str())),lldChannel,apvId,stripId)); //try to identify double peaked channels if(testDoubleGaussianChannels){ if(noiseFit2Gaus == NULL) // double gaussian in which the sigma is constrained to be the same --> identifing clear two peak channels noiseFit2Gaus = new TF1("dgaus","[0]*exp(-((x-[1])*(x-[1]))/(2*[2]*[2]))+[3]*exp(-((x-[4])*(x-[4]))/(2*[5]*[5]))",xMin,xMax); noiseFit2Gaus->SetRange(xMin,xMax); noiseFit2Gaus->SetParameter(0,fitGausNormalization/2); noiseFit2Gaus->SetParameter(3,fitGausNormalization/2); noiseFit2Gaus->SetParameter(1,1.); noiseFit2Gaus->SetParameter(4,-1.); noiseFit2Gaus->SetParameter(2,fitGausSigma); noiseFit2Gaus->SetParameter(5,fitGausSigma); noiseFit2Gaus->SetParLimits(1,0.,xMax); noiseFit2Gaus->SetParLimits(4,xMin,0); result = noiseHist->Fit(noiseFit2Gaus,"QSR"); chi2Ratio = 0; distance = 0; ashman = 0; bimodality = 0; amplitudeRatio = 0; if(result.Get() or noiseHist->Integral() == 0){ //compute the chi2 ratio chi2Ratio = 0.5*ROOT::Math::chisquared_cdf_c((fitChi2/(result->Ndf()+3))/(result->Chi2()/result->Ndf()),1); chi2Distance->Fill(chi2Ratio); distance = fabs(noiseFit2Gaus->GetParameter(1)-noiseFit2Gaus->GetParameter(4))/(2*sqrt(noiseFit2Gaus->GetParameter(2)*noiseFit2Gaus->GetParameter(5))); peakDistance->Fill(distance); ashman = TMath::Power(2,0.5)*abs(noiseFit2Gaus->GetParameter(1)-noiseFit2Gaus->GetParameter(4))/(sqrt(pow(noiseFit2Gaus->GetParameter(2),2)+pow(noiseFit2Gaus->GetParameter(5),2))); ashmanDistance->Fill(ashman); if(nonNullBins > 3) bimodality = (noiseHist->GetSkewness()*noiseHist->GetSkewness()+1)/(noiseHist->GetKurtosis()+3*(nonNullBins-1)*(nonNullBins-1)/((nonNullBins-2)*(nonNullBins-3))); else bimodality = (noiseHist->GetSkewness()*noiseHist->GetSkewness()+1)/(noiseHist->GetKurtosis()); bimodalityDistance->Fill(bimodality); amplitudeRatio = std::min(noiseFit2Gaus->GetParameter(0),noiseFit2Gaus->GetParameter(3))/std::max(noiseFit2Gaus->GetParameter(0),noiseFit2Gaus->GetParameter(3)); amplitudeRatioDistance->Fill(amplitudeRatio); if(distance > 1){ multiPeakChannelsDistance->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakDistance++; } if(ashman > 2){ multiPeakChannelsAshman->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakAshman++; } if(chi2Ratio < 0.05){ multiPeakChannelsChi2->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakChi2++; } if(amplitudeRatio > 0.85){ multiPeakChannelsAmplitude->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakAmplitude++; } if(bimodality > 0.55){ multiPeakChannelsBimodality->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakBimodality++; } if(ashman > 2 && amplitudeRatio > 0.85){ multiPeakChannelsCombined->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakCombined++; moduleNumeratorDoublePeak[detid]++; } } } } } // plot the chi2 and peak distance if(testDoubleGaussianChannels){ storeOutputCanvas(canvas,chi2Distance,"chi2TestStatistics",outputDIR); storeOutputCanvas(canvas,peakDistance,"peakDistanceTestStatistics",outputDIR); storeOutputCanvas(canvas,ashmanDistance,"ashmanTestStatistics",outputDIR); storeOutputCanvas(canvas,amplitudeRatioDistance,"amplitudeRatioDistance",outputDIR); storeOutputCanvas(canvas,bimodalityDistance,"bimodalityDistance",outputDIR); } std::cout<<std::endl; badStripsNFilledBins->Close(); badKsTest->Close(); badaDTest->Close(); badjBTest->Close(); badChi2Test->Close(); badCombinedTest->Close(); badJBNotKSTest->Close(); badaDNotKSandjBTest->Close(); badChi2NotKSandjBandaDTest->Close(); multiPeakChannelsCombined->Close(); ////// multiPeakChannelsChi2->Close(); multiPeakChannelsDistance->Close(); multiPeakChannelsAshman->Close(); multiPeakChannelsAmplitude->Close(); multiPeakChannelsBimodality->Close(); cout<<"#### Bad Nfilled bins "<<nbadNFilledBins<<" --> "<<double(nbadNFilledBins)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad KS Test Channels "<<nbadKsTest<<" ---> "<<double(nbadKsTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad JB Test Channels "<<nbadjBTest<<" ---> "<<double(nbadjBTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad AD Test Channels "<<nbadaDTest<<" ---> "<<double(nbadaDTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad Chi2 Test Channels "<<nbadChi2Test<<" ---> "<<double(nbadChi2Test)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad JB but not KS Test Channels "<<nbadJBNotKSTest<<" ---> "<<double(nbadJBNotKSTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad AD but not KS and not JB Test Channels "<<nbadaDNotKSandjBTest<<" ---> "<<double(nbadaDNotKSandjBTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad Chi2 but not KS and JB and AD Test Channels "<<nbadChi2NotKSandjBandaDTest<<" ---> "<<double(nbadChi2NotKSandjBandaDTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad Combined Test Channels "<<nbadCombinedTest<<" ---> "<<double(nbadCombinedTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; if(testDoubleGaussianChannels){ cout<<"###############################"<<endl; cout<<"#### Multiple peak finder ####"<<endl; cout<<"##############################"<<endl; cout<<"Two peak by Chi2 "<<nbadDoublePeakChi2<<" --> "<<double(nbadDoublePeakChi2)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Distance "<<nbadDoublePeakDistance<<" --> "<<double(nbadDoublePeakDistance)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Ashman "<<nbadDoublePeakAshman<<" --> "<<double(nbadDoublePeakAshman)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Amplitude "<<nbadDoublePeakAmplitude<<" --> "<<double(nbadDoublePeakAmplitude)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Bimodality "<<nbadDoublePeakBimodality<<" --> "<<double(nbadDoublePeakBimodality)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Combibed "<<nbadDoublePeakCombined<<" ---> "<<double(nbadDoublePeakCombined)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; } /// -------> ofstream channelMap ((outputDIR+"/fractionOfGoodChannels.txt").c_str()); for(auto module : moduleDenominator) channelMap << module.first <<" "<< 1. - double(moduleNumerator[module.first])/double(moduleDenominator[module.first]) << "\n"; channelMap.close(); /// -------> ofstream nchannelMapFilledBins ((outputDIR+"/numberBadChannelsFilledBins.txt").c_str()); for(auto module : moduleNumeratorFilledBins) nchannelMapFilledBins << module.first <<" "<< moduleNumeratorFilledBins[module.first] << "\n"; nchannelMapFilledBins.close(); /// -------> ofstream nchannelMap ((outputDIR+"/numberBadChannels.txt").c_str()); for(auto module : moduleNumerator) nchannelMap << module.first <<" "<< moduleNumerator[module.first] << "\n"; nchannelMap.close(); /// -------> // ofstream nNonEdgechannelMap ((outputDIR+"/numberBadChannelsNonEdge.txt").c_str()); // for(auto module : moduleNonEdgeNumerator) // nNonEdgechannelMap << module.first <<" "<< moduleNonEdgeNumerator[module.first] << "\n"; // nNonEdgechannelMap.close(); /// -------> // ofstream nAPVEdgechannelMap ((outputDIR+"/numberBadChannelsAPVEdge.txt").c_str()); // for(auto module : moduleAPVEdgeNumerator) // nAPVEdgechannelMap << module.first <<" "<< moduleAPVEdgeNumerator[module.first] << "\n"; // nAPVEdgechannelMap.close(); /// -------> ofstream nchannelMapKS ((outputDIR+"/numberBadChannelsKS.txt").c_str()); for(auto module : moduleNumeratorKS) nchannelMapKS << module.first <<" "<< moduleNumeratorKS[module.first] << "\n"; nchannelMapKS.close(); /// -------> ofstream nchannelMapJB ((outputDIR+"/numberBadChannelsJB.txt").c_str()); for(auto module : moduleNumeratorJB) nchannelMapJB << module.first <<" "<< moduleNumeratorKS[module.first] << "\n"; nchannelMapJB.close(); /// -------> ofstream nchannelMapDoublePeak ((outputDIR+"/numberBadChannelsDoublePeak.txt").c_str()); for(auto module : moduleNumeratorDoublePeak) nchannelMapDoublePeak << module.first <<" "<< moduleNumeratorDoublePeak[module.first] << "\n"; nchannelMapDoublePeak.close(); // ------> detailed info of bad strips ofstream badStripDump ((outputDIR+"/badStripDump.txt").c_str()); for(auto badstrip : badStrip){ badStripDump<< badstrip.fecCrate_<<" "<<badstrip.fecSlot_<<" "<<badstrip.fecRing_<<" "<<badstrip.ccuAdd_<<" "<<badstrip.ccuCh_<<" "<<badstrip.fedKey_<<" "<<badstrip.lldCh_<<" "<<badstrip.apvid_<<" "<<badstrip.stripid_<<" \n"; } badStripDump.close(); }
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(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; }
//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(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; }
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; }
void bToDRawYield() { gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.04); gStyle->SetPadLeftMargin(0.14); gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.14); gStyle->SetTitleX(.0f); gStyle->SetOptFit(1111); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); TCanvas* c4 = new TCanvas("c4","",800,600); c4->Divide(2,2); TCanvas* c2 = new TCanvas("c2","",400,600); c2->Divide(1,2); TCanvas* c1 = new TCanvas(); TCanvas* c15 = new TCanvas("c15","",810,1000); c15->Divide(3,5); TFile* fPbPb = new TFile("bFeedDownPbPb.hist.root"); TFile* fPbPbMB = new TFile("bFeedDownPbPbMB.hist.root"); TFile* fPbPbMC = new TFile("bFeedDownPbPbMC.hist.root"); TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC.hist.root"); TH3D* hDataPbPb = (TH3D*)fPbPb->Get("hData"); TH3D* hSidebandPbPb = (TH3D*)fPbPb->Get("hSideband"); TH3D* hDataPbPbMB = (TH3D*)fPbPbMB->Get("hData"); TH3D* hSidebandPbPbMB = (TH3D*)fPbPbMB->Get("hSideband"); TH3D* hPtMD0DcaPbPb = (TH3D*)fPbPb->Get("hPtMD0Dca"); TH3D* hPtMD0DcaPbPbMB = (TH3D*)fPbPbMB->Get("hPtMD0Dca"); TH3D* hMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCPSignal"); TH3D* hMCNPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCNPSignal"); TH3D* hMCPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCPSignal"); TH3D* hMCNPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCNPSignal"); TH3D* hPtMD0DcaMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSignal"); TH3D* hPtMD0DcaMCPSwappedPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSwapped"); TH3D* hPtMD0DcaMCPSignalPbPbMB =(TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSignal"); TH3D* hPtMD0DcaMCPSwappedPbPbMB = (TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSwapped"); TH3D* hData = (TH3D*)hDataPbPb->Clone("hData"); hData->Sumw2(); hData->Add(hDataPbPbMB); TH3D* hSideband = (TH3D*)hSidebandPbPb->Clone("hSideband"); hSideband->Sumw2(); hSideband->Add(hSidebandPbPbMB); TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPbPb->Clone("hPtMD0Dca"); hPtMD0Dca->Sumw2(); hPtMD0Dca->Add(hPtMD0DcaPbPbMB); TH3D* hMCPSignal = (TH3D*)hMCPSignalPbPb->Clone("hMCPSignal"); hMCPSignal->Sumw2(); hMCPSignal->Add(hMCPSignalPbPbMB); TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPbPb->Clone("hMCNPSignal"); hMCNPSignal->Sumw2(); hMCNPSignal->Add(hMCNPSignalPbPbMB); TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPbPb->Clone("hPtMD0DcaMCPSignal"); hPtMD0DcaMCPSignal->Sumw2(); hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPbPbMB); TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPbPb->Clone("hPtMD0DcaMCPSwapped"); hPtMD0DcaMCPSwapped->Sumw2(); hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPbPbMB); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.06); texCms->SetTextFont(42); TLatex* texCol = new TLatex(0.96,0.93, "PbPb #sqrt{s_{NN}} = 5.02 TeV"); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.06); texCol->SetTextFont(42); const int nPtBins = 14; float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100}; float pts[nPtBins]; float ptErrors[nPtBins]; float promptFraction[nPtBins]; float totalYield[nPtBins]; float totalYieldInvMassFit[nPtBins]; float totalYieldInvMassFitError[nPtBins]; float bToDYield[nPtBins]; float bToDYieldError[nPtBins]; float bToDYieldErrorDataOnly[nPtBins]; float promptDYield[nPtBins]; float promptDYieldError[nPtBins]; float promptDYieldErrorDataOnly[nPtBins]; const int nBinY = 14; Float_t binsY[nBinY+1]; float firstBinYWidth = 0.001; float binYWidthRatio = 1.27; binsY[0]=0; for(int i=1; i<=nBinY; i++) binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1); cout<<"last y bin: "<<binsY[nBinY]<<endl; // for(int i=1; i<=nPtBins; i++) for(int i =7; i<=7; i++) { pts[i-1] = 0.5*(ptBins[i-1]+ptBins[i]); ptErrors[i-1] = 0.5*(ptBins[i]-ptBins[i-1]); float ptLow = ptBins[i-1]; float ptHigh = ptBins[i]; cout<<endl<<"======================================="<<endl; cout<<"pT range: "<<ptLow<<" "<<ptHigh<<endl; TLatex* texPtY = new TLatex(0.32,0.82,Form("%.1f < p_{T} < %.1f GeV/c |y| < 1.0",ptLow,ptHigh)); texPtY->SetNDC(); texPtY->SetTextFont(42); texPtY->SetTextSize(0.06); texPtY->SetLineWidth(2); TLatex* texPt = new TLatex(0.18,0.82,Form("%.1f < p_{T} < %.1f GeV/c",ptLow,ptHigh)); texPt->SetNDC(); texPt->SetTextFont(42); texPt->SetTextSize(0.06); texPt->SetLineWidth(2); TLatex* texY = new TLatex(0.18,0.74,Form("|y| < 1.0")); texY->SetNDC(); texY->SetTextFont(42); texY->SetTextSize(0.06); texY->SetLineWidth(2); c2->cd(1); hPtMD0Dca->GetZaxis()->SetRange(1,100); hPtMD0Dca->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hPtMD0DcaMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hPtMD0DcaMCPSwapped->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); TH1D* hMData = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_%1.1f_%1.1f", ptLow, ptHigh)); TH1D* hMMCSignal = (TH1D*)hPtMD0DcaMCPSignal->Project3D("y"); TH1D* hMMCSwapped = (TH1D*)hPtMD0DcaMCPSwapped->Project3D("y"); setColorTitleLabel(hMData); setColorTitleLabel(hMMCSignal); setColorTitleLabel(hMMCSwapped); TF1* fMass = fitMass(hMData, hMMCSignal, hMMCSwapped); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); TF1* fSignalAndSwapped = new TF1("fSignalAndSwapped","[0]*([3]*([5]*Gaus(x,[1],[2]*(1+[7]))/(sqrt(2*3.1415927)*[2]*(1+[7]))+(1-[5])*Gaus(x,[1],[6]*(1+[7]))/(sqrt(2*3.1415927)*[6]*(1+[7])))+(1-[3])*Gaus(x,[1],[4]*(1+[7]))/(sqrt(2*3.1415927)*[4]*(1+[7])))", 1.7, 2.0); fSignalAndSwapped->SetParameter(0,fMass->GetParameter(0)); fSignalAndSwapped->SetParameter(1,fMass->GetParameter(1)); fSignalAndSwapped->SetParameter(2,fMass->GetParameter(2)); fSignalAndSwapped->SetParameter(3,fMass->GetParameter(7)); fSignalAndSwapped->SetParameter(4,fMass->GetParameter(8)); fSignalAndSwapped->SetParameter(5,fMass->GetParameter(9)); fSignalAndSwapped->SetParameter(6,fMass->GetParameter(10)); fSignalAndSwapped->SetParameter(7,fMass->GetParameter(11)); TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,fMass->GetParameter(3)); background->SetParameter(1,fMass->GetParameter(4)); background->SetParameter(2,fMass->GetParameter(5)); background->SetParameter(3,fMass->GetParameter(6)); cout<<"MC signal width: "<<fMass->GetParameter(2)<<" "<<fMass->GetParameter(10)<<endl; cout<<"MC swapped width: "<<fMass->GetParameter(8)<<endl; float massD = 1.8649; float massSignal1 = massD-0.025; float massSignal2 = massD+0.025; float massSideBand1 = massD-0.1; float massSideBand2 = massD-0.075; float massSideBand3 = massD+0.075; float massSideBand4 = massD+0.1; float scaleSideBandBackground = background->Integral(massSignal1, massSignal2)/(background->Integral(massSideBand1, massSideBand2)+background->Integral(massSideBand3, massSideBand4)); cout<<"scaleSideBandBackground: "<<scaleSideBandBackground<<endl; totalYieldInvMassFit[i-1] = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1); totalYieldInvMassFitError[i-1] = fMass->GetParError(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1); cout<<"totalYieldInvMassFit: "<<totalYieldInvMassFit[i-1]<<" +- "<<totalYieldInvMassFitError[i-1]<<endl; float scaleSideBandMethodSignal = fSignalAndSwapped->GetParameter(0)*fSignalAndSwapped->GetParameter(3) / (fSignalAndSwapped->Integral(massSignal1, massSignal2)-fSignalAndSwapped->Integral(massSideBand1, massSideBand2)-fSignalAndSwapped->Integral(massSideBand3, massSideBand4)); cout<<"scaleSideBandMethodSignal: "<<scaleSideBandMethodSignal<<endl; TLatex* texScale = new TLatex(0.18,0.66,Form("side band bg scale: %1.3f", scaleSideBandBackground)); texScale->SetNDC(); texScale->SetTextFont(42); texScale->SetTextSize(0.06); texScale->SetLineWidth(2); texScale->Draw(); TLine* lineSignal1 = new TLine(massSignal1, 0, massSignal1, hMData->GetMaximum()*0.5); TLine* lineSignal2 = new TLine(massSignal2, 0, massSignal2, hMData->GetMaximum()*0.5); TLine* lineSideBand1 = new TLine(massSideBand1, 0, massSideBand1, hMData->GetMaximum()*0.5); TLine* lineSideBand2 = new TLine(massSideBand2, 0, massSideBand2, hMData->GetMaximum()*0.5); TLine* lineSideBand3 = new TLine(massSideBand3, 0, massSideBand3, hMData->GetMaximum()*0.5); TLine* lineSideBand4 = new TLine(massSideBand4, 0, massSideBand4, hMData->GetMaximum()*0.5); lineSignal1->Draw(); lineSignal2->Draw(); lineSideBand1->Draw(); lineSideBand2->Draw(); lineSideBand3->Draw(); lineSideBand4->Draw(); c2->cd(2); gPad->SetLogy(); hData->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hSideband->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hMCNPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); TH1D* hD0DcaData0 = (TH1D*)hData->Project3D("y")->Clone("hD0DcaData0"); TH1D* hD0DcaSideband = (TH1D*)hSideband->Project3D("y")->Clone("hD0DcaSideband"); TH1D* hD0DcaMCPSignal0 = (TH1D*)hMCPSignal->Project3D("y")->Clone("hD0DcaMCPSignal0"); TH1D* hD0DcaMCNPSignal0 = (TH1D*)hMCNPSignal->Project3D("y")->Clone("hD0DcaMCNPSignal0"); float integralRawYieldMCP = hD0DcaMCPSignal0->Integral(); float integralRawYieldMCNP = hD0DcaMCNPSignal0->Integral(); cout<<"integralRawYieldMCP: "<<integralRawYieldMCP<<endl; cout<<"integralRawYieldMCNP: "<<integralRawYieldMCNP<<endl; hD0DcaMCPSignal = hD0DcaMCPSignal0; hD0DcaMCNPSignal = hD0DcaMCNPSignal0; divideBinWidth(hD0DcaData0); divideBinWidth(hD0DcaSideband); setColorTitleLabel(hD0DcaData0, 1); hD0DcaData0->GetXaxis()->SetRangeUser(0,0.07); hD0DcaData0->GetYaxis()->SetTitle("counts per cm"); TH1D* hD0DcaSideband0 = (TH1D*)hD0DcaSideband->Clone("hD0DcaSideband0"); hD0DcaSideband->Scale(scaleSideBandBackground); TH1D* hD0DcaDataSubSideBand = (TH1D*)hD0DcaData0->Clone("hD0DcaDataSubSideBand"); hD0DcaDataSubSideBand->Add(hD0DcaSideband,-1); hD0DcaDataSubSideBand->Scale(scaleSideBandMethodSignal); hD0DcaData0->SetMarkerSize(0.6); hD0DcaData0->Draw(); hD0DcaSideband->Draw("hsame"); hD0DcaSideband0->SetLineStyle(2); hD0DcaSideband0->Draw("hsame"); TLegend* leg1 = new TLegend(0.44,0.6,0.90,0.76,NULL,"brNDC"); leg1->SetBorderSize(0); leg1->SetTextSize(0.06); leg1->SetTextFont(42); leg1->SetFillStyle(0); leg1->AddEntry(hD0DcaData0,"D^{0} candidate","pl"); leg1->AddEntry(hD0DcaSideband,"side band","l"); leg1->AddEntry(hD0DcaSideband0,"side band unscaled","l"); leg1->Draw("same"); texCms->Draw(); texCol->Draw(); texPtY->Draw(); c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_sideBand.pdf",ptLow,ptHigh)); c2->cd(1); hMMCSignal->Draw(); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); c2->cd(2); gPad->SetLogy(0); hMMCSwapped->Draw(); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_McInvMassFit.pdf",ptLow,ptHigh)); c15->cd(1); fitMass(hMData, hMMCSignal, hMMCSwapped); texPt->Draw(); texY->Draw(); TH1D* hD0DcaDataFit = new TH1D("hD0DcaDataFit", ";D^{0} DCA (cm);dN / d(D^{0} DCA) (cm^{-1})", nBinY, binsY); for(int j=1; j<=14; j++) { c15->cd(j+1); hPtMD0Dca->GetZaxis()->SetRange(j,j); float D0DcaLow = hPtMD0Dca->GetZaxis()->GetBinLowEdge(j); float D0DcaHigh = hPtMD0Dca->GetZaxis()->GetBinUpEdge(j); TH1D* hMData_D0Dca = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_pt_%1.1f_%1.1f_D0Dca_%1.4f_%1.4f", ptLow, ptHigh, D0DcaLow, D0DcaHigh)); setColorTitleLabel(hMData_D0Dca); fMass = fitMass(hMData_D0Dca, hMMCSignal, hMMCSwapped); float yield = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1); float yieldError = fMass->GetParError(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1); hD0DcaDataFit->SetBinContent(j, yield); hD0DcaDataFit->SetBinError(j, yieldError); TLatex* texD0Dca = new TLatex(0.18,0.82,Form("D^{0} DCA: %1.4f - %1.4f",D0DcaLow,D0DcaHigh)); texD0Dca->SetNDC(); texD0Dca->SetTextFont(42); texD0Dca->SetTextSize(0.06); texD0Dca->SetLineWidth(2); texD0Dca->Draw(); TLatex* texYield = new TLatex(0.18,0.74,Form("D^{0} yield: %1.0f #pm %1.0f",yield,yieldError)); texYield->SetNDC(); texYield->SetTextFont(42); texYield->SetTextSize(0.06); texYield->SetLineWidth(2); texYield->Draw(); } c15->SaveAs(Form("plots/PbPb_%.0f_%.0f_invMassFit.pdf",ptLow,ptHigh)); divideBinWidth(hD0DcaDataFit); c4->cd(1); gPad->SetLogy(); normalize(hD0DcaMCPSignal); setColorTitleLabel(hD0DcaMCPSignal, 2); hD0DcaMCPSignal->GetXaxis()->SetRangeUser(0,0.07); normalize(hD0DcaMCNPSignal); setColorTitleLabel(hD0DcaMCNPSignal, 4); hD0DcaMCNPSignal->GetXaxis()->SetRangeUser(0,0.07); hD0DcaMCNPSignal->GetYaxis()->SetTitle("dN / d(D^{0} DCA) (cm^{-1})"); hD0DcaMCNPSignal->GetXaxis()->SetTitle("D^{0} DCA (cm)"); hD0DcaMCNPSignal->SetMaximum(hD0DcaMCPSignal->GetMaximum()*3.); hD0DcaMCNPSignal->Draw(""); hD0DcaMCPSignal->Draw("same"); TLegend* leg2 = new TLegend(0.54,0.72,0.90,0.88,NULL,"brNDC"); leg2->SetBorderSize(0); leg2->SetTextSize(0.06); leg2->SetTextFont(42); leg2->SetFillStyle(0); leg2->AddEntry(hD0DcaMCPSignal,"MC Prompt D^{0}","pl"); leg2->AddEntry(hD0DcaMCNPSignal,"MC Non-prompt D^{0}","pl"); leg2->Draw("same"); c4->cd(2); gPad->SetLogy(); TH1D* hD0DcaData = hD0DcaDataFit; if(pts[i-1]>20) hD0DcaData = hD0DcaDataSubSideBand; setColorTitleLabel(hD0DcaData, 1); double integralTotalYield = hD0DcaData->Integral(1,hD0DcaData->GetXaxis()->GetNbins(),"width"); cout<<"integralTotalYield: "<<integralTotalYield<<endl; TF1* fMix = new TF1("fMix",&funMix, 0., 0.5, 2); fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield); fMix->SetParLimits(0,0,2*integralTotalYield); fMix->SetParLimits(1,0,2*integralTotalYield); fMix->SetLineColor(2); fMix->SetFillColor(kRed-9); fMix->SetFillStyle(1001); float fitRangeL = 0; float fitRangeH = 0.08; hD0DcaData->GetXaxis()->SetRangeUser(0,0.07); hD0DcaData->Draw(); int fitStatus = 1; TFitResultPtr fitResult; double fitPrecision = 1.e-6; while(fitStatus) { TFitter::SetPrecision(fitPrecision); fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield); fMix->SetParError(0,0.1*integralTotalYield); fMix->SetParError(1,0.1*integralTotalYield); fitResult = hD0DcaData->Fit("fMix","E SNQ0", "", fitRangeL, fitRangeH); fitStatus = fitResult->Status(); cout<<"fit precision: "<<TFitter::GetPrecision()<<" status: "<<fitStatus<<endl; if(fitStatus) fitPrecision *= 10; } cout<<"============== do main fit ============"<<endl; fMix->SetParameters(integralTotalYield,0.9); fMix->SetParError(0,0.1*integralTotalYield); fMix->SetParError(1,0.1); fMix->SetNpx(10000); fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH); hD0DcaData->GetFunction("fMix")->Draw("flsame"); fitStatus = fitResult->Status(); cout<<"fit precision: "<<TFitter::GetPrecision()<<" status: "<<fitStatus<<endl; TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2); fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1)); fNP->SetRange(fitRangeL,fitRangeH); fNP->SetLineColor(4); fNP->SetFillStyle(1001); fNP->SetFillColor(kBlue-9); fNP->SetNpx(10000); fNP->Draw("same"); hD0DcaData->Draw("same"); promptDYield[i-1] = fMix->GetParameter(0); promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0); bToDYield[i-1] = fMix->GetParameter(1); bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1); totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1]; promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1]; cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl; texCms->Draw(); texCol->Draw(); texPtY->Draw(); TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0))); texPrompt->SetNDC(); texPrompt->SetTextFont(42); texPrompt->SetTextSize(0.06); texPrompt->SetLineWidth(2); texPrompt->Draw(); TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1))); texNonPrompt->SetNDC(); texNonPrompt->SetTextFont(42); texNonPrompt->SetTextSize(0.06); texNonPrompt->SetLineWidth(2); texNonPrompt->Draw(); TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62); leg4->SetBorderSize(0); leg4->SetTextSize(0.06); leg4->SetTextFont(42); leg4->SetFillStyle(0); leg4->AddEntry(hD0DcaData,"Data","pl"); leg4->AddEntry(fMix,"Prompt D^{0}","f"); leg4->AddEntry(fNP,"B to D^{0}","f"); leg4->Draw("same"); //smear MC smaple with the error, to simulate the MC statistic error effect. c4->cd(3); hD0DcaMCPSignal = (TH1D*)hD0DcaMCPSignal0->Clone("hMCPSignal"); hD0DcaMCNPSignal = (TH1D*)hD0DcaMCNPSignal0->Clone("hMCNPSignal"); TH1D* hNPYield = new TH1D("hNPYield", ";hNPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1))); TH1D* hPYield = new TH1D("hPYield", ";hPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1))); setColorTitleLabel(hNPYield, 1); setColorTitleLabel(hPYield, 1); int nSmear = 1000; for(int j=0; j<nSmear; j++) { RandomSmear(hD0DcaMCPSignal0, hD0DcaMCPSignal); RandomSmear(hD0DcaMCNPSignal0, hD0DcaMCNPSignal); fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield); fMix->SetParError(0,0.1*integralTotalYield); fMix->SetParError(1,0.1*integralTotalYield); hD0DcaData->Fit("fMix","E QN0"); hPYield->Fill(fMix->GetParameter(0)); hNPYield->Fill(fMix->GetParameter(1)); } hPYield->GetXaxis()->SetTitle("prompt D^{0} yield"); hPYield->GetYaxis()->SetTitle("counts"); hPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hPYield->GetMaximum()); hPYield->SetMarkerStyle(20); hPYield->SetStats(0); hPYield->Draw("e"); hPYield->Fit("gaus"); TLatex* texGaussMeanSigmaP = new TLatex(0.27,0.83,Form("#mu: %.0f #sigma: %.0f",hPYield->GetFunction("gaus")->GetParameter(1),hPYield->GetFunction("gaus")->GetParameter(2))); texGaussMeanSigmaP->SetNDC(); texGaussMeanSigmaP->SetTextFont(42); texGaussMeanSigmaP->SetTextSize(0.06); texGaussMeanSigmaP->SetLineWidth(2); texGaussMeanSigmaP->Draw(); float promptYieldErrorMc = hPYield->GetFunction("gaus")->GetParameter(2); promptDYieldError[i-1] = sqrt(pow(promptDYieldErrorDataOnly[i-1],2)+pow(promptYieldErrorMc,2)); c4->cd(4); hNPYield->GetXaxis()->SetTitle("B to D^{0} yield"); hNPYield->GetYaxis()->SetTitle("counts"); hNPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hNPYield->GetMaximum()); hNPYield->SetMarkerStyle(20); hNPYield->SetStats(0); hNPYield->Draw("e"); hNPYield->Fit("gaus"); TLatex* texGaussMeanSigmaNP = new TLatex(0.27,0.83,Form("#mu: %.0f #sigma: %.0f",hNPYield->GetFunction("gaus")->GetParameter(1),hNPYield->GetFunction("gaus")->GetParameter(2))); texGaussMeanSigmaNP->SetNDC(); texGaussMeanSigmaNP->SetTextFont(42); texGaussMeanSigmaNP->SetTextSize(0.06); texGaussMeanSigmaNP->SetLineWidth(2); texGaussMeanSigmaNP->Draw(); float bToDYieldErrorMc = hNPYield->GetFunction("gaus")->GetParameter(2); bToDYieldError[i-1] = sqrt(pow(bToDYieldErrorDataOnly[i-1],2)+pow(bToDYieldErrorMc,2)); cout<<"prompt D yield: "<<promptDYield[i-1]<<" +- "<<promptDYieldError[i-1]<<" (+- "<<promptDYieldErrorDataOnly[i-1]<<" +- "<<promptYieldErrorMc<<" )"<<endl; cout<<"B to D yield: "<<bToDYield[i-1]<<" +- "<<bToDYieldError[i-1]<<" (+- "<<bToDYieldErrorDataOnly[i-1]<<" +- "<<bToDYieldErrorMc<<" )"<<endl; cout<<"total yield: "<<totalYield[i-1]<<endl; cout<<"prompt fraction: "<<promptFraction[i-1]<<endl; float promptMCScale = promptDYield[i-1]/integralRawYieldMCP; float nonPromptMCScale = bToDYield[i-1]/integralRawYieldMCNP; cout<<"promptMCScale: "<<promptMCScale<<endl; cout<<"nonPromptMCScale: "<<nonPromptMCScale<<endl; //restore original unsmeared histograms before saving plots delete hD0DcaMCPSignal; delete hD0DcaMCNPSignal; hD0DcaMCPSignal = hD0DcaMCPSignal0; hD0DcaMCNPSignal = hD0DcaMCNPSignal0; hD0DcaData->Fit("fMix","E QN0"); c4->SaveAs(Form("plots/PbPb_%.0f_%.0f_fit.pdf",ptLow,ptHigh)); c1->cd(); TH1D* hD0DcaDataOverFit = (TH1D*)hD0DcaData->Clone("hD0DcaDataOverFit"); hD0DcaDataOverFit->Divide(fMix); hD0DcaDataOverFit->GetYaxis()->SetTitle("data / fit"); hD0DcaDataOverFit->GetYaxis()->SetRangeUser(0,5); hD0DcaDataOverFit->GetXaxis()->SetRangeUser(0,0.07); setColorTitleLabel(hD0DcaDataOverFit, 1); hD0DcaDataOverFit->Draw("e"); TF1* fLine1 = new TF1("fLine1", "1", 0,1); fLine1->Draw("same"); hD0DcaDataOverFit->Draw("esame"); c1->SaveAs(Form("plots/dataOverFit_%.0f_%.0f_fit.pdf",ptLow,ptHigh)); delete hD0DcaMCPSignal; delete hD0DcaMCNPSignal; } // end for i ptbins c1->cd(); TH1D* hStupidJie = new TH1D("hStupidJie", "", 100, 0, 100); hStupidJie->GetYaxis()->SetRangeUser(0,1); hStupidJie->GetXaxis()->SetTitle("p_{T} (GeV/c)"); hStupidJie->GetYaxis()->SetTitle("prompt fraction"); hStupidJie->SetStats(0); hStupidJie->Draw(); TGraph* grFraction = new TGraph(nPtBins, pts, promptFraction); grFraction->SetName("grPromptFraction"); grFraction->SetMarkerStyle(20); grFraction->Draw("psame"); c1->SaveAs("promptFraction.pdf"); c1->SetLogy(); TH1D* hBtoDRawYield = new TH1D("hBtoDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins); for(int i=1; i<=nPtBins; i++) { if(bToDYield[i-1] <= 0) continue; hBtoDRawYield->SetBinContent(i, bToDYield[i-1]); hBtoDRawYield->SetBinError(i, bToDYieldError[i-1]); } divideBinWidth(hBtoDRawYield); setColorTitleLabel(hBtoDRawYield, 1); c1->SetBottomMargin(0.14); hBtoDRawYield->Draw("p"); c1->SaveAs("BtoD.pdf"); TH1D* hPromptDRawYield = new TH1D("hPromptDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins); for(int i=1; i<=nPtBins; i++) { if(promptDYield[i-1] <= 0) continue; hPromptDRawYield->SetBinContent(i, promptDYield[i-1]); hPromptDRawYield->SetBinError(i, promptDYieldError[i-1]); } divideBinWidth(hPromptDRawYield); setColorTitleLabel(hPromptDRawYield, 1); c1->SetBottomMargin(0.14); hPromptDRawYield->Draw("p"); c1->SaveAs("promptD.pdf"); TH1D* hTotalDYieldInvMassFit = new TH1D("hTotalDYieldInvMassFit", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins); for(int i=1; i<=nPtBins; i++) { if(totalYieldInvMassFit[i-1] <= 0) continue; hTotalDYieldInvMassFit->SetBinContent(i, totalYieldInvMassFit[i-1]); hTotalDYieldInvMassFit->SetBinError(i, totalYieldInvMassFitError[i-1]); } divideBinWidth(hTotalDYieldInvMassFit); setColorTitleLabel(hTotalDYieldInvMassFit, 1); hTotalDYieldInvMassFit->Draw("p"); c1->SaveAs("totalDInvMassFit.pdf"); TFile* fOut = new TFile("bFeedDownResult.root", "recreate"); fOut->WriteTObject(grFraction); fOut->WriteTObject(hBtoDRawYield); fOut->WriteTObject(hPromptDRawYield); fOut->WriteTObject(hTotalDYieldInvMassFit); fOut->Write(); fOut->Close(); }
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* 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* 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; }
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; }
void rsLimit7TeV(){ setTDRStyle(); //=========Macro generated from canvas: cLimit/Limit //========= (Mon Feb 22 22:44:48 2010) by ROOT version5.18/00a // TCanvas *cLimit = new TCanvas("cLimit", "Limit",450,40,800,550); // TCanvas *cLimit = new TCanvas("cLimit", "Limit",100,122,600,600); cLimit = new TCanvas("cLimit","cLimit",800,600); gStyle->SetOptStat(0); // cLimit->Range(595.5973,-0.03483694,1345.283,0.2539571); cLimit->SetFillColor(0); cLimit->SetBorderMode(0); cLimit->SetBorderSize(2); cLimit->SetLeftMargin(0.139262); cLimit->SetRightMargin(0.0604027); cLimit->SetTopMargin(0.0804196); cLimit->SetBottomMargin(0.120629); cLimit->SetFrameBorderMode(0); cLimit->SetFrameBorderMode(0); TGraph *graph = new TGraph(11); graph->SetName("Graph"); graph->SetTitle(""); graph->SetFillColor(1); Int_t ci; // for color index setting ci = TColor::GetColor("#ff0000"); graph->SetLineColor(ci); graph->SetLineWidth(3); ci = TColor::GetColor("#ff0000"); graph->SetMarkerColor(ci); graph->SetMarkerStyle(20); graph->SetMarkerSize(1.0); graph->SetPoint(0, 863,0.01); graph->SetPoint(1, 1132,0.02); graph->SetPoint(2, 1274,0.03); graph->SetPoint(3, 1395,0.04); graph->SetPoint(4, 1503,0.05); graph->SetPoint(5, 1597,0.06); graph->SetPoint(6, 1676,0.07); graph->SetPoint(7, 1742,0.08); graph->SetPoint(8, 1801,0.09); graph->SetPoint(9, 1844,0.1); graph->SetPoint(10,1881,0.11); cout << " Don't forget to change this..." << endl; TH1 *Graph6 = new TH1F("Graph6","",100,863,1881); Graph6->SetMinimum(0); Graph6->SetMaximum(0.12); Graph6->SetDirectory(0); Graph6->SetStats(0); Graph6->GetXaxis()->SetTitle("M_{1} [GeV]"); Graph6->GetYaxis()->SetTitle("Coupling k/#bar{M}_{Pl}"); Graph6->GetXaxis()->SetLabelFont(42); Graph6->GetYaxis()->SetLabelFont(42); Graph6->GetYaxis()->SetTitleOffset(1.8); graph->SetHistogram(Graph6); graph->GetYaxis()->SetTitleOffset(1.19); graph->Draw("al"); TGraph* graph2 = new TGraph(11); graph2->SetMarkerColor(ci); graph2->SetMarkerStyle(20); graph2->SetMarkerSize(0.0); graph2->SetPoint(0, 845,0.01); graph2->SetPoint(1, 1133,0.02); graph2->SetPoint(2, 1275,0.03); graph2->SetPoint(3, 1396,0.04); graph2->SetPoint(4, 1504,0.05); graph2->SetPoint(5, 1598,0.06); graph2->SetPoint(6, 1677,0.07); graph2->SetPoint(7, 1743,0.08); graph2->SetPoint(8, 1801,0.09); graph2->SetPoint(9, 1844,0.1); graph2->SetPoint(10,1881,0.11); graph2->SetLineStyle(kDashed); graph2->SetLineColor(ci); graph2->SetLineWidth(3); graph2->GetXaxis()->SetLabelFont(42); graph2->GetYaxis()->SetLabelFont(42); graph2->Draw("plsame"); // graph = new TGraph(3); // graph->SetName("Graph"); // graph->SetTitle(""); // graph->SetFillColor(1); // ci = TColor::GetColor("#0000ff"); // graph->SetLineColor(ci); // graph->SetLineWidth(3); // ci = TColor::GetColor("#0000ff"); // graph->SetMarkerColor(ci); // graph->SetMarkerStyle(22); // graph->SetMarkerSize(1.4); // graph->SetPoint(0,750,0.03355478); // graph->SetPoint(1,1000,0.07617687); // graph->SetPoint(2,1250,0.1542326); // TH1 *Graph7 = new TH1F("Graph7","",100,700,1300); // Graph7->SetMinimum(0.021487); // Graph7->SetMaximum(0.1663004); // Graph7->SetDirectory(0); // Graph7->SetStats(0); // Graph7->GetXaxis()->SetTitle("Graviton Mass (GeV)"); // Graph7->GetYaxis()->SetTitle("Coupling k/#bar{M}_{Pl}"); // graph->SetHistogram(Graph7); // graph->Draw("pc"); // graph = new TGraph(3); // graph->SetName("Graph"); // graph->SetTitle(""); // graph->SetFillColor(1); // ci = TColor::GetColor("#00ff00"); // graph->SetLineColor(ci); // graph->SetLineWidth(3); // ci = TColor::GetColor("#00ff00"); // graph->SetMarkerColor(ci); // graph->SetMarkerStyle(21); // graph->SetMarkerSize(1.3); // graph->SetPoint(0,750,0.02431275); // graph->SetPoint(1,1000,0.05519538); // graph->SetPoint(2,1250,0.1117521); // TH1 *Graph8 = new TH1F("Graph8","",100,700,1300); // Graph8->SetMinimum(0.01556881); // Graph8->SetMaximum(0.1204961); // Graph8->SetDirectory(0); // Graph8->SetStats(0); // Graph8->GetXaxis()->SetTitle("Graviton Mass (GeV/c^{2})"); // Graph8->GetYaxis()->SetTitle("Coupling k/#bar{M}_{Pl}"); // graph->SetHistogram(Graph8); // graph->Draw("pc"); // TF1 *LambdaPi = new TF1("LambdaPi","pol1",500,2500); // LambdaPi->SetFillColor(15); // LambdaPi->SetFillStyle(3004); // LambdaPi->SetLineColor(15); // LambdaPi->SetLineWidth(1); // LambdaPi->SetParameter(0,0); // LambdaPi->SetParError(0,0); // LambdaPi->SetParLimits(0,0,0); // LambdaPi->SetParameter(1,2.61097e-05); // LambdaPi->SetParError(1,0); // LambdaPi->SetParLimits(1,0,0); // LambdaPi->Draw("same"); // TF1 *LambdaPi = new TF1("LambdaPi","pol1",250,2500); LambdaPi->SetFillColor(15); LambdaPi->SetFillStyle(3004); LambdaPi->SetLineColor(15); LambdaPi->SetLineWidth(1); LambdaPi->SetParameter(0,0); LambdaPi->SetParError(0,0); LambdaPi->SetParLimits(0,0,0); LambdaPi->SetParameter(1,2.61097e-05); LambdaPi->SetParError(1,0); LambdaPi->SetParLimits(1,0,0); LambdaPi->GetXaxis()->SetLabelFont(42); LambdaPi->GetYaxis()->SetLabelFont(42); LambdaPi->Draw("same"); graph = new TGraph(27); graph->SetName("Graph"); graph->SetTitle("Graph"); graph->SetFillColor(1); graph->SetFillStyle(3004); graph->SetLineStyle(5); graph->SetLineWidth(3); graph->SetPoint(0,180,0.1071); graph->SetPoint(1,183,0.1062); graph->SetPoint(2,190,0.1043); graph->SetPoint(3,200,0.1016); graph->SetPoint(4,210,0.0989); graph->SetPoint(5,220,0.0963); graph->SetPoint(6,230,0.0938); graph->SetPoint(7,240,0.0913); graph->SetPoint(8,250,0.0889); graph->SetPoint(9,260,0.0866); graph->SetPoint(10,270,0.0843); graph->SetPoint(11,280,0.0821); graph->SetPoint(12,290,0.0799); graph->SetPoint(13,300,0.0778); graph->SetPoint(14,400,0.0603); graph->SetPoint(15,500,0.0481); graph->SetPoint(16,600,0.0397); graph->SetPoint(17,700,0.0337); graph->SetPoint(18,800,0.0292); graph->SetPoint(19,900,0.0258); graph->SetPoint(20,1000,0.0231); graph->SetPoint(21,1100,0.0209); graph->SetPoint(22,1200,0.0191); graph->SetPoint(23,1300,0.0176); graph->SetPoint(24,1400,0.0163); graph->SetPoint(25,1500,0.0152); graph->SetPoint(26,2200,0.01); graph->GetXaxis()->SetLabelFont(42); graph->GetYaxis()->SetLabelFont(42); graph->SetFillColor(kBlack); graph->SetFillStyle(3004); graph->SetLineWidth(1); graph->SetFillStyle(3002); graph->SetFillColor(kBlack); graph->SetLineWidth(-10000); graph->Draw("c"); // graph->Draw("same"); // TPaveText *pt = new TPaveText(0.194631,0.748252,0.436242,0.816434,"blNDC"); // pt->SetName("95% CL Limit"); // pt->SetFillColor(0); // pt->SetBorderSize(1); // pt->SetLineColor(0); // pt->SetTextSize(0.04); // TText *text = pt->AddText("95% CL Limit"); // pt->Draw(); TLegend *leg = new TLegend(0.2072864,0.4667832,0.4007538,0.7517483,NULL,"brNDC"); // TLegend *leg = new TLegend(0.2072864,0.5332168,0.4007538,0.7517483,NULL,"brNDC"); // TLegend *leg = new TLegend(0.2110553,0.4248252,0.4120603,0.6433566,NULL,"brNDC"); // TLegend *leg = new TLegend(0.2181208,0.5297203,0.4194631,0.7482517,NULL,"brNDC"); leg->SetBorderSize(1); leg->SetTextFont(62); leg->SetTextSize(0.05); leg->SetLineColor(0); leg->SetLineStyle(0); leg->SetLineWidth(0); leg->SetFillColor(0); leg->SetFillStyle(0); // TLegendEntry *entry=leg->AddEntry("graph","50/pb","pl"); // ci = TColor::GetColor("#ff0000"); // entry->SetLineColor(ci); // entry->SetLineStyle(1); // entry->SetLineWidth(3); entry=leg->AddEntry("graph","Electroweak Limits","lf"); entry->SetLineColor(1); entry->SetLineStyle(5); entry->SetLineWidth(3); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); ci = TColor::GetColor("#ff0000"); entry->SetMarkerColor(ci); entry->SetMarkerStyle(20); entry->SetMarkerSize(1.3); entry=leg->AddEntry("Graph","95% CL Limit","l"); leg->AddEntry(graph2,"Expected Limit","l"); ci = TColor::GetColor("#00ff00"); entry->SetMarkerColor(ci); entry->SetMarkerStyle(21); entry->SetMarkerSize(1.3); // entry=leg->AddEntry("LambdaPi","#Lambda_{#pi}> 10TeV","lf"); entry=leg->AddEntry("LambdaPi","M_{D} > 10TeV","lf"); // entry->SetFillColor(15); // entry->SetFillStyle(3004); // entry->SetLineColor(15); // entry->SetLineStyle(1); // entry->SetLineWidth(1); // entry->SetMarkerColor(1); // entry->SetMarkerStyle(1); // entry->SetMarkerSize(1); leg->Draw(); TPaveText *pt = new TPaveText(0.2236181,0.7884615,0.4736181,0.8583916,"blNDC"); // TPaveText *pt = new TPaveText(0.1959799,0.7954545,0.4459799,0.8653846,"blNDC"); // TPaveText *pt = new TPaveText(0.2130872,0.8339161,0.4630872,0.9038462,"blNDC"); pt->SetName("CMS Preliminary"); pt->SetBorderSize(1); pt->SetLineColor(0); pt->SetFillColor(0); // pt->SetTextFont(72); pt->SetTextSize(0.06); text = pt->AddText("CMS Preliminary"); pt->Draw(); pt = new TPaveText(0.629397,0.798951,0.8002513,0.8653846,"blNDC"); // pt = new TPaveText(0.6005025,0.8059441,0.7713568,0.8723776,"blNDC"); // pt = new TPaveText(0.2738693,0.7027972,0.4447236,0.7692308,"blNDC"); // pt = new TPaveText(0.2416107,0.7727273,0.4127517,0.8391608,"blNDC"); pt->SetFillColor(0); pt->SetBorderSize(1); pt->SetLineColor(0); pt->SetTextSize(0.06); text = pt->AddText("2.2 fb^{-1} at 7 TeV"); pt->Draw(); // pt = new TPaveText(0.6879195,0.8129371,0.7885906,0.9108392,"blNDC"); // pt->SetFillColor(0); // pt->SetBorderSize(1); // pt->SetLineColor(0); // pt->SetTextSize(0.0454545); // text = pt->AddText("L = 1091 pb^{-1}"); // pt->Draw(); cLimit->Modified(); cLimit->cd(); cLimit->SetSelected(cLimit); }
int main(int argc, char** argv) { //Check if all nedeed arguments to parse are there if( argc < 2 ) { std::cerr << ">>> linearityPlots_MZ::usage: " << argv[0] << " evtsPerPoint_cat0 (evtsPerPoint_cat1 evtsPerPoint_cat2 ...)" << std::endl; return -1; } int nCat = argc - 1; int* evtsPerPoint = new int[nCat]; for(int iCat = 0; iCat < nCat; ++iCat) evtsPerPoint[iCat] = atoi(argv[iCat+1]); std::vector<std::string> directories; if(drawSmearSys == false && drawScaleSys == false) directories.push_back( ("data/2012/Winter2013/MZ_"+analysis+"_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15").c_str() ); if(drawSmearSys == true || drawScaleSys == true) directories.push_back( ("data/2012/Winter2013/MZ_"+analysis+"_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_std").c_str() ); if(drawSmearSys == true){ directories.push_back(("data/2012/Winter2013/MZ_"+analysis+"_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_smearPlus1").c_str()); directories.push_back(("data/2012/Winter2013/MZ_"+analysis+"_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_smearMinus1").c_str()); } if(drawScaleSys == true){ directories.push_back(("data/2012/Winter2013/MZ_"+analysis+"_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_scalePlus1").c_str()); directories.push_back(("data/2012/Winter2013/MZ_"+analysis+"_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_scaleMinus1").c_str()); } //directories.push_back( "data/2012/Winter2013/MZ_CiC_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_10m4_BinErrsOK_P0" ); //directories.push_back( "data/2012/Winter2013/MZ_CiC_nonGlobe_powheg-runDependent_phoTunedRegV5_Dphi3p15_10m4_BinErrsOK_EXP" ); unsigned int nDir = directories.size(); std::cout << " >>>>>>>>>> nDir = " << nDir << std::endl; float PointY[nCat][4]; float PointX[nCat][4]; float PointYE[nCat][4]; float PointXE[nCat][4]; float SysError[nCat][7]; SysError[0][0] = 0.00380885; SysError[0][1] = -0.0366029; SysError[0][2] = -0.179775; SysError[0][3] = -0.289; SysError[0][4] = 0.0616593; SysError[0][5] = -0.00157475; SysError[0][6] = -0.00207482; SysError[1][0] = -0.0228756; SysError[1][1] = 0.00991204; SysError[1][2] = -0.196126; SysError[1][3] = -0.489761; SysError[1][4] = 0.0772905; SysError[1][5] = 0.016216; SysError[1][6] = -0.0143245; SysError[2][0] = -0.674561; SysError[2][1] = -1.22921; SysError[2][2] = -0.553516; SysError[2][3] = -0.392232; SysError[2][4] = 0.135323; SysError[2][5] = -0.0389127; SysError[2][6] = -0.0323834; SysError[3][0] = -0.931675; SysError[3][1] = -1.20162; SysError[3][2] = -0.576185; SysError[3][3] = -0.456856; SysError[3][4] = 0.182718; SysError[3][5] = -0.016453; SysError[3][6] = -0.00577606; //----------------------------- // Decide which methods to draw std::vector<std::string> methods; //methods.push_back( "fit" ); //methods.push_back( "gausFit" ); //methods.push_back( "mean" ); methods.push_back( "recursiveMean" ); // methods.push_back( "smallestInterval" ); int nMethods = methods.size(); std::vector<std::string> nameTrial; nameTrial.push_back("std"); if(drawSmearSys == true){ nameTrial.push_back("smearPlus1"); nameTrial.push_back("smearMinus1"); } if(drawScaleSys == true){ nameTrial.push_back("scalePlus1"); nameTrial.push_back("scaleMinus1"); } //-------------------- // Set fitting options TVirtualFitter::SetDefaultFitter("Minuit2"); setTDRStyle(); gStyle->SetPadTopMargin(0.05); gStyle->SetPadBottomMargin(0.13); gStyle->SetPadLeftMargin(0.13); gStyle->SetPadRightMargin(0.17); gStyle->SetLabelSize(0.04,"XYZ"); gStyle->SetTitleSize(0.05,"XYZ"); gStyle->SetOptStat(0); gStyle->SetOptFit(0); std::vector<int> colors; std::vector<int> linestyles; std::vector<int> markerstyles; colors.push_back(kRed+1); colors.push_back(kOrange+1); colors.push_back(kGreen+1); colors.push_back(kBlue+1); linestyles.push_back(1); linestyles.push_back(2); linestyles.push_back(2); markerstyles.push_back(20); markerstyles.push_back(26); markerstyles.push_back(32); //---------------- // Define canvases TCanvas* c_all = new TCanvas("c_all","c_all"); c_all -> Divide(2,2); TCanvas** c = new TCanvas*[nCat]; //---------------------------- // Define infiles and canvases for(unsigned int iDir = 0; iDir < directories.size(); ++iDir) { std::string directory = directories.at(iDir); std::string* inFileNames = new std::string[nCat]; std::string baseFileName = "studyLinearity_MZ_"; if( MCClosure == true) directory += "_MCClosure"+MCSyst; for(int iMeth = 0; iMeth < nMethods; ++iMeth) { std::cout << ">>> method: " << methods.at(iMeth) << std::endl; TLegend** legend = new TLegend*[nCat]; for(int iCat = 0; iCat < nCat; ++iCat) { legend[iCat] = new TLegend(0.16, 0.77, 0.30, 0.92); legend[iCat] -> SetFillColor(kWhite); legend[iCat] -> SetFillStyle(1001); legend[iCat] -> SetTextFont(42); legend[iCat] -> SetTextSize(0.05); } TLatex* latex = new TLatex(0.14,0.96,Form("analysis: %s scale estimator: %s",analysis.c_str(),(methods.at(iMeth)).c_str())); latex -> SetNDC(); latex -> SetTextFont(42); latex -> SetTextSize(0.04); double* scale_MZ = new double[nCat]; TGraphAsymmErrors** g = new TGraphAsymmErrors*[nCat]; TGraphAsymmErrors** gClone = new TGraphAsymmErrors*[nCat]; TF1** f_fit = new TF1*[nCat]; TH1F** hint = new TH1F*[nCat]; for(int iCat = 0; iCat < nCat; ++iCat) { std::cout << "\n***************** cat: " << iCat << " *****************" << std::endl; char EvtString[50]; sprintf(EvtString,"cat%d_%devtsPerPoint",iCat,evtsPerPoint[iCat]); inFileNames[iCat] = directory + "/" + baseFileName + std::string(EvtString) + ".root"; TFile* f = TFile::Open((inFileNames[iCat]).c_str(),"READ"); std::cout << ">>> inFileName: " << inFileNames[iCat] << std::endl; char graphName[50]; sprintf(graphName,"step1/scale_%s_DAOverMC",methods.at(iMeth).c_str()); g[iCat] = (TGraphAsymmErrors*)( f->Get(graphName) ); gClone[iCat] = (TGraphAsymmErrors*)( f->Get(graphName) ); if(addSyst == true){ for(int point = 0; point < g[iCat]->GetN(); ++point){ double ey = g[iCat] -> GetErrorY(point); double statE2 = pow(ey,2); double sysE2 = pow(0.01*SysError[iCat][point], 2); g[iCat] -> SetPointEYhigh(point, sqrt(statE2 + sysE2) ); g[iCat] -> SetPointEYlow (point, sqrt(statE2 + sysE2) ); } } if(writeFunctions == true && rescaleErrors == true){ gClone[iCat]->RemovePoint(7); gClone[iCat]->RemovePoint(6); gClone[iCat]->RemovePoint(5); gClone[iCat]->RemovePoint(4); /* g[iCat]->RemovePoint(7); g[iCat]->RemovePoint(6); g[iCat]->RemovePoint(5); g[iCat]->RemovePoint(4); */ } TF1* f_scaleVsEt = (TF1*)( f->Get("f_scaleVsEt") ); if( iDir == 0 ) c[iCat] = new TCanvas(); c[iCat] -> cd(); c[iCat] -> SetGridx(); c[iCat] -> SetGridy(); //c[iCat] -> SetLogx(); c_all -> cd(iCat+1); gPad -> SetGridx(); gPad -> SetGridy(); g[iCat] -> SetPoint(g[iCat]->GetN(),1500.,1.); g[iCat] -> GetXaxis() -> SetRangeUser(60,200.); g[iCat] -> GetXaxis() -> SetMoreLogLabels(); g[iCat] -> GetXaxis() -> SetTitle("H_{T} [GeV]"); g[iCat] -> GetYaxis() -> SetTitle("#LTm_{ee}#GT^{data} / #LTm_{ee}#GT^{MC}"); g[iCat] -> GetXaxis() -> SetTitleSize(0.05); g[iCat] -> GetYaxis() -> SetTitleSize(0.05); g[iCat] -> GetXaxis() -> SetTitleOffset(1.10); g[iCat] -> GetYaxis() -> SetTitleOffset(1.28); g[iCat] -> GetXaxis() -> SetLabelSize(0.04); g[iCat] -> GetYaxis() -> SetLabelSize(0.04); g[iCat] -> GetYaxis() -> SetNdivisions(405); g[iCat] -> SetMarkerSize(1.5); g[iCat] -> SetMarkerColor(colors.at(iCat)); g[iCat] -> SetMarkerStyle(markerstyles.at(iDir)); g[iCat] -> SetLineColor(kBlack); g[iCat] -> SetLineWidth(1); if(iCat == 0 || iCat == 1){ g[iCat] -> SetMinimum(0.9951); g[iCat] -> SetMaximum(1.0049); } else{ g[iCat] -> SetMinimum(0.985); g[iCat] -> SetMaximum(1.015); } if(MCClosure == true){ g[iCat] -> SetMinimum(0.98); g[iCat] -> SetMaximum(1.02); } if( drawFitFunc == false ) { if( iDir == 0 ) { c[iCat] -> cd(); g[iCat] -> Draw("AP"); c_all -> cd(iCat+1); g[iCat] -> Draw("AP"); } else { c[iCat] -> cd(); g[iCat] -> Draw("P,same"); c_all -> cd(iCat+1); g[iCat] -> Draw("P,same"); } if(MCClosure && drawFitFunc == false) { // TF1* f_scaleVsEt = new TF1("f_scaleVsEt", "1. + [0] * (1 - exp(-[1] * (0.5*x-45.)) )",0., 1000.); // f_scaleVsEt -> SetParameters(7.50e-03,2.00e-02); //TF1* f_scaleVsEt = new TF1("f_scaleVsEt", "1.+0.000",0., 1000.); f_scaleVsEt->SetLineColor(kBlack); c[iCat] -> cd(); f_scaleVsEt->Draw("same"); c_all -> cd(iCat+1); f_scaleVsEt->Draw("same"); } } else { if( iDir == 0 ) { c[iCat] -> cd(); g[iCat] -> Draw("AP"); c_all -> cd(iCat+1); g[iCat] -> Draw("AP"); } else { c[iCat] -> cd(); g[iCat] -> Draw("P,same"); c_all -> cd(iCat+1); g[iCat] -> Draw("P,same"); } } char funcName[150]; sprintf(funcName,"f_prefit_%s_%d",methods.at(iMeth).c_str(),iCat); TF1* f_prefit; if( fitMethod == "pol0") { f_prefit = new TF1(funcName,"[0]",55., 230.); f_prefit -> SetParameter(0,1.); } if( fitMethod == "pol1") { f_prefit = new TF1(funcName,"[0]+[1]*(x-90.)",55., 210.); f_prefit -> SetParameters(1.,0.00002); } if( fitMethod == "exp3par") { f_prefit = new TF1(funcName,"1.+[0]*(1.-exp(-1.*[1]*(x-90.)))+[2]",55., 230.); f_prefit -> SetParameters(0.005,0.02,0.); } if( fitMethod == "exp") { f_prefit = new TF1(funcName,"1.+[0]*(1.-exp(-1.*[1]*(x-90.)) )",55., 230.); f_prefit -> SetParameters(0.005,0.02); f_prefit -> SetParLimits(0,0.,1.); f_prefit -> SetParLimits(1,0.,0.05); } TFitResultPtr fitResult1; int fitStatus1 = -1; gClone[iCat] -> Fit(funcName,"QRHNS"); //g[iCat] -> Fit(funcName,"QRHNS"); fitStatus1 = fitResult1; //std::cout << " fitStatus1 = " << fitStatus1 << std::endl; //std::cout << " f_prefit->GetParameter(0) = " << f_prefit->GetParameter(0) << std::endl; //std::cout << " f_prefit->GetParameter(1) = " << f_prefit->GetParameter(1) << std::endl; std::cout << " f_prefit->GetChisquare()/f_prefit->GetNDF() = " << f_prefit->GetChisquare()/f_prefit->GetNDF() << std::endl; if( drawFitFunc == true && rescaleErrors == true ) { for(int point = 0; point < g[iCat]->GetN(); ++point) { double ey = g[iCat] -> GetErrorY(point); if(addSyst == false){ g[iCat] -> SetPointEYhigh(point,ey*sqrt(f_prefit->GetChisquare()/f_prefit->GetNDF())); g[iCat] -> SetPointEYlow (point,ey*sqrt(f_prefit->GetChisquare()/f_prefit->GetNDF())); if(point == 4 || point == 5 || point == 6 || point == 7){ g[iCat] -> SetPointEYhigh(point, sqrt(pow(g[iCat] -> GetErrorY(point),2)+pow(0.0005,2)) ); g[iCat] -> SetPointEYlow(point, sqrt(pow(g[iCat] -> GetErrorY(point),2)+pow(0.0005,2)) ); } } //std::cout << " >>> prima ey = " << ey << std::endl; if(SysError[iCat][point] != 0. && addSyst == true){ double statE2 = (pow(ey,2) - pow(0.01*SysError[iCat][point], 2)); //double statE2 = pow(ey,2); double sysE2 = pow(SysError[iCat][point], 2); //double sysE2 = pow(SysError[iCat][point], 2); double errorN2 = ( (statE2) * (f_prefit->GetChisquare()/f_prefit->GetNDF()) / sysE2 - statE2/sysE2 + 0.01*(f_prefit->GetChisquare()/f_prefit->GetNDF()) ); // // double errorN2 = (statE2 + sysE2) * f_prefit->GetChisquare()/f_prefit->GetNDF() / sysE2 - statE2/sysE2; // // double errorN2 = num2/ (f_prefit->GetChisquare()/f_prefit->GetNDF()) / sysE2 - statE2/sysE2; g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + errorN2*sysE2) ); g[iCat] -> SetPointEYlow (point, sqrt( statE2 + errorN2*sysE2) ); // g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + sysE2) ); // g[iCat] -> SetPointEYlow (point, sqrt( statE2 + sysE2) ); std::cout << " >>> dopo ey = " << sqrt(statE2 + sysE2) << std::endl; } /* double statE2 = (pow(ey,2) - pow(0.0001*SysError[iCat][point], 2)); double errorN2 = ( (pow(ey,2) * f_prefit->GetChisquare()/f_prefit->GetNDF() - statE2 ) / (pow(0.0001*SysError[iCat][point], 2)) ); if(iCat == 0){ g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + pow(0.0015*SysError[iCat][point], 2)) ); g[iCat] -> SetPointEYlow (point, sqrt( statE2 + pow(0.0015*SysError[iCat][point], 2)) ); } if(iCat == 1){ g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + pow(0.015*SysError[iCat][point], 2)) ); g[iCat] -> SetPointEYlow (point, sqrt( statE2 + pow(0.015*SysError[iCat][point], 2)) ); } if(iCat == 2){ g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + pow(0.003*SysError[iCat][point], 2)) ); g[iCat] -> SetPointEYlow (point, sqrt( statE2 + pow(0.003*SysError[iCat][point], 2)) ); } if(iCat == 3){ g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + pow(0.005*SysError[iCat][point], 2)) ); g[iCat] -> SetPointEYlow (point, sqrt( statE2 + pow(0.005*SysError[iCat][point], 2)) ); } */ // std::cout << " >>> cat >> " << iCat << " point = " << point << " k = " << errorN2 * sqrt(0.0001) << std::endl; // std::cout << " >>> cat >> " << iCat << " point = " << point << " stat = " << sqrt(statE2) << std::endl; // } } } if( drawFitFunc == false && rescaleErrors == true ) { if( MCClosure == true ) { for(int point = 0; point < g[iCat]->GetN(); ++point) { double ey = g[iCat] -> GetErrorY(point); if(addSyst == false){ g[iCat] -> SetPointEYhigh(point,ey*sqrt(f_prefit->GetChisquare()/f_prefit->GetNDF())); g[iCat] -> SetPointEYlow (point,ey*sqrt(f_prefit->GetChisquare()/f_prefit->GetNDF())); } if(SysError[iCat][point] != 0. && addSyst == true){ double statE2 = (pow(ey,2) - pow(0.0001*SysError[iCat][point], 2)); double sysE2 = pow(0.0001*SysError[iCat][point], 2); double errorN2 = (statE2 + sysE2) * f_prefit->GetChisquare()/f_prefit->GetNDF() / sysE2 - statE2/sysE2; g[iCat] -> SetPointEYhigh(point, sqrt( statE2 + errorN2*sysE2) ); g[iCat] -> SetPointEYlow (point, sqrt( statE2 + errorN2*sysE2) ); } } } } //////////////// int fitStatus1b = -1; g[iCat] -> Fit(funcName,"QRHNS"); fitStatus1b = fitResult1; std::cout << " f_prefit->GetChisquare()/f_prefit->GetNDF() = " << f_prefit->GetChisquare()/f_prefit->GetNDF() << std::endl; if( rescaleErrors == true ) { for(int point = 0; point < g[iCat]->GetN(); ++point) { double ey = g[iCat] -> GetErrorY(point); if(addSyst == false){ g[iCat] -> SetPointEYhigh(point,ey*sqrt(f_prefit->GetChisquare()/f_prefit->GetNDF())); g[iCat] -> SetPointEYlow (point,ey*sqrt(f_prefit->GetChisquare()/f_prefit->GetNDF())); } } } //////////// sprintf(funcName,"f_fit_%s_%d",methods.at(iMeth).c_str(),iCat); if( fitMethod == "pol0") { f_fit[iCat] = new TF1(funcName,"[0]",55., 230.); f_fit[iCat] -> SetParameter(0,1.); } if( fitMethod == "pol1" ) { f_fit[iCat] = new TF1(funcName,"[0]+[1]*(x-90.)",55., 230.); f_fit[iCat] -> SetParameters(1.,0.00001); } if( fitMethod == "exp3par") { f_fit[iCat] = new TF1(funcName,"1.+[0]*(1.-exp(-1.*[1]*(x-90.)))+[2]",55., 230.); f_fit[iCat] -> SetParameters(0.005,0.02,0.); } if( fitMethod == "exp") { f_fit[iCat] = new TF1(funcName,"1.+[0]*(1.-exp(-1.*[1]*(x-90.)))",55., 230.); f_fit[iCat] -> SetParameters(0.005,0.02); } f_fit[iCat] -> SetLineColor(kBlue+2); f_fit[iCat] -> SetLineWidth(3); f_fit[iCat] -> SetLineStyle(linestyles.at(iDir)); TFitResultPtr fitResult; int fitStatus = -1; int nTrials = 0; while( (fitStatus != 0) && (nTrials < 10) ) { fitResult = g[iCat] -> Fit(funcName,"QRHNS"); fitStatus = fitResult; if( fitStatus == 1 ) break; ++nTrials; } std::cout << " >>>> fitStatus = " << fitStatus << std::endl; std::cout << " >>>> nTrials = " << nTrials << std::endl; if( fitStatus == 0 && MCClosure == false ) { TMatrixDSym cov = fitResult->GetCovarianceMatrix(); TMatrixDSym cor = fitResult->GetCorrelationMatrix(); for(int aa=0; aa<f_fit[iCat]->GetNpar(); ++aa){ for(int bb=0; bb<f_fit[iCat]->GetNpar(); ++bb){ std::cout << " (corMatrix[" << aa << "])[" << bb << "] = " << cor[aa][bb] << "; " << std::endl; } } } // g[iCat]->AddPoint(0); std::cout << " f_fit[iCat]->GetChisquare()/f_fit[iCat]->GetNDF() = " << f_fit[iCat]->GetChisquare()/f_fit[iCat]->GetNDF() << std::endl; if( drawFitFunc == true ) { hint[iCat] = new TH1F("hint","",5000,55.,1055.); (TVirtualFitter::GetFitter()) -> GetConfidenceIntervals(hint[iCat],0.68); hint[iCat] -> SetMarkerSize(0); hint[iCat] -> SetFillColor(kAzure-9); hint[iCat] -> SetFillStyle(3001); c[iCat] -> cd(); f_fit[iCat] -> Draw("same"); if( iDir == 0 ) { hint[iCat] -> Draw("same,E4"); f_fit[iCat] -> Draw("same"); } g[iCat]->Draw("P,same"); c_all -> cd(iCat+1); f_fit[iCat] -> Draw("same"); if( iDir == 0 ) { hint[iCat] -> Draw("same,E4"); f_fit[iCat] -> Draw("same"); } g[iCat]->Draw("P,same"); } if( MCClosure == false && writeFunctions == true) { TFile TF1_defaultDiffNonLin((("TF1_pol1_EtScale/TF1_"+fitMethod+"_"+analysis+"_"+nameTrial.at(iDir)+Form("_cat%d.root",iCat))).c_str(), "recreate"); TF1* defaultDiffNonLinET; TF1* defaultDiffNonLinHT; if(fitMethod == "exp") { defaultDiffNonLinET = new TF1(Form("cat%d", iCat), "1.+[0]*(1.-exp(-1.*[1]*(x-45.)))", 20., 1000.); defaultDiffNonLinET->SetParameter(0, f_fit[iCat]->GetParameter(0)); defaultDiffNonLinET->SetParError(0, f_fit[iCat]->GetParError(0)); defaultDiffNonLinET->SetParameter(1, 2.*f_fit[iCat]->GetParameter(1)); defaultDiffNonLinET->SetParError(1, 2.*f_fit[iCat]->GetParError(1)); } if(fitMethod == "exp3par") { defaultDiffNonLinET = new TF1(Form("cat%d", iCat), "1.+[0]*(1.-exp(-1.*[1]*(x-45.)))+[2]", 20., 1000.); defaultDiffNonLinET->SetParameter(0, f_fit[iCat]->GetParameter(0)); defaultDiffNonLinET->SetParError(0, f_fit[iCat]->GetParError(0)); defaultDiffNonLinET->SetParameter(1, 2.*f_fit[iCat]->GetParameter(1)); defaultDiffNonLinET->SetParError(1, 2.*f_fit[iCat]->GetParError(1)); defaultDiffNonLinET->SetParameter(2, f_fit[iCat]->GetParameter(2)); defaultDiffNonLinET->SetParError(2, f_fit[iCat]->GetParError(2)); } if( fitMethod == "pol1" ) { defaultDiffNonLinET = new TF1(Form("ET_cat%d", iCat), "[0]+ [1] * (x-45.)", 20., 1000.); defaultDiffNonLinET->SetParameter(0, f_fit[iCat]->GetParameter(0)); defaultDiffNonLinET->SetParError(0, f_fit[iCat]->GetParError(0)); defaultDiffNonLinET->SetParameter(1, 2.*f_fit[iCat]->GetParameter(1)); defaultDiffNonLinET->SetParError(1, 2.*f_fit[iCat]->GetParError(1)); defaultDiffNonLinHT = new TF1(Form("HT_cat%d", iCat), "[0]+ [1] * (x-90.)", 20., 1000.); defaultDiffNonLinHT->SetParameter(0, f_fit[iCat]->GetParameter(0)); defaultDiffNonLinHT->SetParError(0, f_fit[iCat]->GetParError(0)); defaultDiffNonLinHT->SetParameter(1, f_fit[iCat]->GetParameter(1)); defaultDiffNonLinHT->SetParError(1, f_fit[iCat]->GetParError(1)); } if( fitMethod == "pol0" ) { defaultDiffNonLinET = new TF1(Form("ET_cat%d", iCat), "[0]", 20., 1000.); defaultDiffNonLinET->SetParameter(0, 0.5*f_fit[iCat]->GetParameter(0)); defaultDiffNonLinET->SetParError(0, 0.5*f_fit[iCat]->GetParError(0)); defaultDiffNonLinHT = new TF1(Form("HT_cat%d", iCat), "[0]+ [1] * (x-90.)", 20., 1000.); defaultDiffNonLinHT->SetParameter(0, f_fit[iCat]->GetParameter(0)); defaultDiffNonLinHT->SetParError(0, f_fit[iCat]->GetParError(0)); defaultDiffNonLinHT->SetParameter(1, f_fit[iCat]->GetParameter(1)); defaultDiffNonLinHT->SetParError(1, f_fit[iCat]->GetParError(1)); } defaultDiffNonLinET -> Write(); defaultDiffNonLinHT -> Write(); TF1_defaultDiffNonLin.Close(); } std::cout << " CIAOOOOOOOOO " << std::endl; std::cout << " iCat = " << iCat << std::endl; std::cout << " iDir = " << iDir << std::endl; if(iCat == 0 && iDir == 1){ TFile perTommaso("perRara.root","recreate"); // for(int i =0; i<4; ++i){ g[iCat]->Write(Form("graph_cat%d",iCat)); // } perTommaso.Close(); } legend[iCat] -> AddEntry(g[iCat],Form("cat. %d",iCat),"PL"); TH1F* h_Ht_MC = (TH1F*)( f->Get("h_Ht_MC") ); double HT_Z = h_Ht_MC->GetMean(); scale_MZ[iCat] = f_fit[iCat] -> Eval(HT_Z); std::cout << std::fixed << "rel. scale(MZ): " << std::setprecision(4) << scale_MZ[iCat] << std::endl; c[iCat] -> cd(); legend[iCat] -> Draw("same"); latex -> Draw("same"); c_all -> cd(iCat+1); legend[iCat] -> Draw("same"); latex -> Draw("same"); std::string MCClosureLabel; if( MCClosure == true ) MCClosureLabel = "MCClosure_"; else MCClosureLabel = "_"; if( iDir == nDir-1 ) { char pdfName[250]; sprintf(pdfName,"%s/scale_%s_%s_%s_cat%d_%sDAOverMC.pdf", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); if(drawScaleSys == true) sprintf(pdfName,"%s/scale_%s_%s_%s_cat%d_ScaleSys_%sDAOverMC.pdf", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); if(drawSmearSys == true) sprintf(pdfName,"%s/scale_%s_%s_%s_cat%d_SmearSys_%sDAOverMC.pdf", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); if(MCClosure == true) sprintf(pdfName,"%s/scale_%s_%s_%s_cat%d_%sDAOverMC.pdf", directory.c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); std::cout << ">>> saving file " << pdfName << std::endl; c[iCat] -> Print(pdfName,"pdf"); char pngName[250]; sprintf(pngName,"%s/scale_%s_%s_%s_cat%d_%sDAOverMC.png", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); if(drawScaleSys == true) sprintf(pngName,"%s/scale_%s_%s_%s_cat%d_ScaleSys_%sDAOverMC.png", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); if(drawSmearSys == true) sprintf(pngName,"%s/scale_%s_%s_%s_cat%d_SmearSys_%sDAOverMC.png", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); if(MCClosure == true) sprintf(pngName,"%s/scale_%s_%s_%s_cat%d_%sDAOverMC.png", directory.c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),iCat,MCClosureLabel.c_str()); std::cout << ">>> saving file " << pngName << std::endl; c[iCat] -> Print(pngName,"png"); std::cout << " >>> pngName = " << pngName << std::endl; if( iCat == nCat-1 ) { sprintf(pdfName,"%s/scale_%s_%s_%s_allCat_%sDAOverMC.pdf", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); if(drawScaleSys == true) sprintf(pdfName,"%s/scale_%s_%s_%s_allCat_ScaleSys_%sDAOverMC.pdf", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); if(drawSmearSys == true) sprintf(pdfName,"%s/scale_%s_%s_%s_allCat_SmearSys_%sDAOverMC.pdf", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); if(MCClosure == true) sprintf(pdfName,"%s/scale_%s_%s_%s_allCat_%sDAOverMC.pdf", directory.c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); std::cout << ">>> saving file " << pdfName << std::endl; c_all -> Print(pdfName,"pdf"); sprintf(pngName,"%s/scale_%s_%s_allCat_%sDAOverMC.png", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); if(drawScaleSys == true) sprintf(pngName,"%s/scale_%s_%s_%s_allCat_ScaleSys_%sDAOverMC.png", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); if(drawSmearSys == true) sprintf(pngName,"%s/scale_%s_%s_%s_allCat_SmearSys_%sDAOverMC.png", directories[0].c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); if(MCClosure == true) sprintf(pngName,"%s/scale_%s_%s_%s_allCat_%sDAOverMC.png", directory.c_str(),analysis.c_str(),(methods.at(iMeth)).c_str(),fitMethod.c_str(),MCClosureLabel.c_str()); std::cout << ">>> saving file " << pngName << std::endl; c_all -> Print(pngName,"png"); std::cout << " >>> All pngName = " << pngName << std::endl; } } } // TFile perTommaso("perTommaso_MZdiagonal_EtDep.root","recreate"); // for(int i =0; i<4; ++i){ // g[i]->Write(Form("graph_cat%d",i)); // } // perTommaso.Close(); } } }
void fitToys2(){ int count=0,countNotFail=0; gStyle->SetOptStat(0); TCanvas *c1 = new TCanvas("c1","c1",800,600);c1->cd(); //TCanvas *c2 = new TCanvas("c2","c2",800,600);c2->cd(); //c1->cd(); TF1* fit = new TF1("fit","[0]*pow(x,[1])",103,163); fit->SetParameters(1.28542e+08,-3.90422); fit->SetParError(0,1.27534e+09); fit->SetParError(1,2.06166); TH1F* h_counts = new TH1F("h_counts","",2,0,2); TH1F* h_HiggsWindowFit = new TH1F("h_HiggsWindowFit","# events in Higgs window from fit",80,0,40); TH1F* h_pull = new TH1F("h_pull","(fit - generated)/(fit error)",160,-8,8); TH1F* h_pull_fail = new TH1F("h_pull_fail","(fit - generated)/(fit error)",160,-8,8); TH1F* h_pull_lowErr = new TH1F("h_pull_lowErr","(fit - generated)/(fit error)",160,-8,8); TH1F* h_pull_highErr = new TH1F("h_pull_highErr","(fit - generated)/(fit error)",160,-8,8); TH1F* h_diff = new TH1F("h_diff","(fit - generated)",160,-40,40); TH1F* h_pullU = new TH1F("h_pullU","(fit - generated)/(fit error)",160,-8,8); TH1F* h_diffU = new TH1F("h_diffU","(fit - generated)",160,-40,40); TH1F* h_pullL = new TH1F("h_pullL","(fit - generated)/(fit error)",160,-8,8); TH1F* h_diffL = new TH1F("h_diffL","(fit - generated)",160,-40,40); h_pullL->SetLineColor(kRed);h_pullL->SetMarkerColor(kRed); h_diffL->SetLineColor(kRed);h_diffL->SetMarkerColor(kRed); h_pullU->SetLineColor(kBlue);h_pullU->SetMarkerColor(kBlue); h_diffU->SetLineColor(kBlue);h_diffU->SetMarkerColor(kBlue); h_pull_fail->SetFillColor(kRed); // TRandom3 rr; for(int j=0;j<10;j++){ TH1F* h = new TH1F("h","",60,103,163); for(int i=0;i<5200;i++){ //for(int i=0;i<rr.Poisson(52);i++){ h->Fill(fit->GetRandom(103,163)); } //h->Draw("PE"); reject=true; TF1* fitCurve = new TF1("fitCurve",fpow,103,163,2); Double_t avg_l = h->Integral(h->FindBin(103),h->FindBin(118))/float(118-103),avg_u = h->Integral(h->FindBin(133),h->FindBin(163))/float(163-133),avgX_l=(118-103)/2.,avgX_u=(163-133)/2.; cout<<avg_l<<" "<<avg_u<<" "<<avgX_l<<" "<<avgX_u<<endl; Double_t param1= (log(avg_l) - log(avg_u))/(log(avgX_l) - log(avgX_u)); Double_t param0= /*7e14;*/avg_l/pow(avgX_l, param1); cout<<"param0: "<<param0<<" param1: "<<param1<<endl; fitCurve->SetParameter(0,param0); fitCurve->SetParameter(1,param1); int status = h->Fit(fitCurve,"L","",103,163); //Then to get the result TFitResultPtr fitResult = h->Fit(fitCurve,"SLLMEV0","",103,163); TMatrixDSym cov = fitResult->GetCovarianceMatrix(); fitResult->Print("V"); h->GetXaxis()->SetRangeUser(100,164.9); reject=false; float YieldBinWidth=h->GetBinWidth(1); Double_t PowYieldSig = h->Integral(h->FindBin(120),h->FindBin(131-.1))/YieldBinWidth; Double_t PowYieldSigFit = fitCurve->Integral(120,131)/YieldBinWidth; Double_t PowYieldSigFitErr = fitCurve->IntegralError(120,131,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; Double_t PowSBloYield = h->Integral(h->FindBin(103),h->FindBin(118-.1))/YieldBinWidth; Double_t PowSBloYieldFit = fitCurve->Integral(103,118)/YieldBinWidth; Double_t PowSBloYieldFitErr = fitCurve->IntegralError(103,118,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; Double_t PowSBhiYield = h->Integral(h->FindBin(133),h->FindBin(163-.1))/YieldBinWidth; Double_t PowSBhiYieldFit = fitCurve->Integral(133,163)/YieldBinWidth; Double_t PowSBhiYieldFitErr = fitCurve->IntegralError(133,163,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; cout<<"gMinuit->fStatus : "<< gMinuit->fStatus <<" gMinuit->fCstatu : "<< gMinuit->fCstatu<<endl; cout<<" low sideband yield from histo: "<<PowSBloYield<<" and from fit: "<<PowSBloYieldFit<<" +- "<<PowSBloYieldFitErr<<endl; cout<<" higgs window yield from histo: "<<PowYieldSig <<" and from fit: "<<PowYieldSigFit<<" +- "<<PowYieldSigFitErr<<endl; cout<<" high sideband yield from histo: "<<PowSBhiYield<<" and from fit: "<<PowSBhiYieldFit<<" +- "<<PowSBhiYieldFitErr<<endl; reject=true; TString str = (TString)gMinuit->fCstatu; cout<<"str: "<<str; h_counts->Fill(0); if(str.Contains("FAILURE")){ double pull_fail = (PowYieldSigFit-9.11)/PowYieldSigFitErr; h_pull_fail->Fill(pull_fail); // continue; } h_counts->Fill(1); double pull = (PowYieldSigFit-9.11)/PowYieldSigFitErr; double pull_lowErr = (PowYieldSigFit-(9.11-1.6))/PowYieldSigFitErr; double pull_highErr = (PowYieldSigFit-(9.11+1.6))/PowYieldSigFitErr; double diff = (PowYieldSigFit-9.11); double pullL = (PowSBloYieldFit-PowSBloYield)/PowSBloYieldFitErr; double diffL = (PowSBloYieldFit-PowSBloYield); double pullU = (PowSBhiYieldFit-PowSBhiYield)/PowSBhiYieldFitErr; double diffU = (PowSBhiYieldFit-PowSBhiYield); h_pull->Fill(pull); h_pull_lowErr->Fill(pull_lowErr); h_pull_highErr->Fill(pull_highErr); h_diff->Fill(diff); h_pullU->Fill(pullU); h_diffU->Fill(diffU); h_pullL->Fill(pullL); h_diffL->Fill(diffL); h_HiggsWindowFit->Fill(PowYieldSigFit); } /* TFile fout("InvarMassFitToys.root","RECREATE"); fout.cd(); h_diff->Write(); h_diffL->Write(); h_diffU->Write(); h_pull->Write(); h_pull_lowErr->Write(); h_pull_highErr->Write(); h_pullL->Write(); h_pullU->Write(); h_HiggsWindowFit->Write(); h_counts->Write(); fout.Close(); */ //h->Draw(); h_diffU->Draw();h_diff->Draw("SAMES");h_diffL->Draw("SAMES"); TLegend *legd = new TLegend(.6,.55,.8,.85,"","brNDC"); legd->SetFillStyle(0);legd->SetBorderSize(0); legd->AddEntry(h_diff,"Higgs window","l"); legd->AddEntry(h_diffL,"lower sideband","l"); legd->AddEntry(h_diffU,"upper sideband","l"); legd->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff.pdf"); //c2->cd(); h_pullU->Draw();h_pull->Draw("SAMES");h_pullL->Draw("SAMES"); legd->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull.pdf"); h_diff->Fit("gaus");h_diff->SetTitle("Higgs window (fit - generated) with Gaussian fit"); h_diff->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff_gausFit.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff_gausFit.pdf"); h_pull->Fit("gaus");h_pull->SetTitle("Higgs window pull with Gaussian fit");//h_pull_fail->Fit("gaus"); h_pull->Draw();//h_pull_fail->Draw("SAMES"); c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull_gausFit_withFail.png"); c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull_gausFit_withFail.pdf"); h_HiggsWindowFit->Fit("gaus"); h_HiggsWindowFit->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__HiggsWindow_gausFit.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__HiggsWindow_gausFit.pdf"); h_counts->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__counts.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__counts.pdf"); }