本文整理汇总了C++中TF1::ReleaseParameter方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::ReleaseParameter方法的具体用法?C++ TF1::ReleaseParameter怎么用?C++ TF1::ReleaseParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TF1
的用法示例。
在下文中一共展示了TF1::ReleaseParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fit
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);
//.........这里部分代码省略.........
示例2: testfit
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})");
//.........这里部分代码省略.........
示例3: TCanvas
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");
//.........这里部分代码省略.........
示例4: fitDstar
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);
//.........这里部分代码省略.........
示例5: TCanvas
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);
//.........这里部分代码省略.........
示例6: fit
//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);
//.........这里部分代码省略.........
示例7: if
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);
//.........这里部分代码省略.........
示例8: compareUpgrade
//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));
//.........这里部分代码省略.........
示例9: TCanvas
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);
//.........这里部分代码省略.........
示例10: getYield
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));
//.........这里部分代码省略.........
示例11: TCanvas
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");
//.........这里部分代码省略.........
示例12: fit
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));
//.........这里部分代码省略.........
示例13: SimpleFitter
void SimpleFitter()
{
TFile*output=new TFile("histoX.root","read");
TH1D*h=(TH1D*)output->Get("h");
h->Sumw2();
TF1 *f = new TF1("f","[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) +[3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])+[6]+[7]*x+[8]*x*x+[9]*x*x*x");
f->SetLineColor(4);
f->SetParameters(21,3.68,0.0057,1.34714e+00,3.86,0.006,-2.21334e+04,1.01661e+04,-1.05364e+03,1.95474e+04);
f->FixParameter(1,3.686);
f->FixParameter(2,0.00357);
f->FixParameter(4,3.8725);
f->FixParameter(5,0.005);
h->Fit("f","LL");
h->Fit("f","");
h->Fit("f","LL");
h->Fit("f","LL","",3.65,3.94);
h->Fit("f","LL","",3.65,3.94);
f->ReleaseParameter(1);
f->ReleaseParameter(2);
f->ReleaseParameter(4);
f->ReleaseParameter(5);
h->Fit("f","LL","",3.65,3.94);
h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]");
h->SetYTitle("Entries");
h->SetStats(0);
h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y");
TF1 *f2 = new TF1("f2","[6]+[7]*x+[8]*x*x+[9]*x*x*x");
f2->SetParameter(6,f->GetParameter(6));
f2->SetParameter(7,f->GetParameter(7));
f2->SetParameter(8,f->GetParameter(8));
f2->SetParameter(9,f->GetParameter(9));
TF1 *f3 = new TF1("f3","[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])");
f3->SetParameter(0,f->GetParameter(0));
f3->SetParameter(1,f->GetParameter(1));
f3->SetParameter(2,f->GetParameter(2));
TF1 *f4 = new TF1("f4","[3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])");
f4->SetParameter(3,f->GetParameter(3));
f4->SetParameter(4,f->GetParameter(4));
f4->SetParameter(5,f->GetParameter(5));
f->SetLineColor(4);
f2->SetLineColor(4);
f3->SetRange(3.65,3.94);
f4->SetRange(3.65,3.94);
f2->SetRange(3.65,3.94);
f2->SetLineStyle(2);
f3->SetLineStyle(2);
f4->SetLineStyle(2);
f2->Draw("same");
f3->SetLineColor(2);
f3->SetFillStyle(3004);
f3->SetFillColor(2);
f3->Draw("same");
f4->SetLineColor(2);
f4->SetFillStyle(3004);
f4->SetFillColor(2);
f4->Draw("same");
TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)");
l->Draw();
TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)");
l2->Draw();
TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary");
l3->Draw();
TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV");
l4->Draw();
cout<<"********************* SIGNIFICANCE *********************"<<endl;
double meanX=f4->GetParameter(4);
double sigmaX=f4->GetParameter(5);
double signalX=f4->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0);
double bkgX=f2->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0);
double signalpsi2=f4->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0);
double bkgpsi2=f2->Integral(meanX-3*sigmaX,meanX+3*sigmaX)/h->GetBinWidth(0);
double significanceX=signalX/TMath::Sqrt(signalX+bkgX);
double meanpsi2=f3->GetParameter(1);
double sigmapsi2=f3->GetParameter(2);
double signalpsi2=f3->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0);
double bkgpsi2=f2->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0);
double signalpsi2=f3->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0);
double bkgpsi2=f2->Integral(meanpsi2-3*sigmapsi2,meanpsi2+3*sigmapsi2)/h->GetBinWidth(0);
double significancepsi2=signalpsi2/TMath::Sqrt(signalpsi2+bkgpsi2);
cout<<"significance X ="<<significanceX<<endl;
cout<<"significance psi(2S)="<<significancepsi2<<endl;
cout<<"yield X="<<signalX<<endl;
cout<<"yield 2S="<<signalpsi2<<endl;
cout<<"yield X/yield 2S="<<signalX/signalpsi2<<endl;
//.........这里部分代码省略.........
示例14: fit
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);
//.........这里部分代码省略.........
示例15: TCanvas
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);
//.........这里部分代码省略.........