本文整理汇总了C++中TF1::SetParError方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::SetParError方法的具体用法?C++ TF1::SetParError怎么用?C++ TF1::SetParError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TF1
的用法示例。
在下文中一共展示了TF1::SetParError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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})");
//.........这里部分代码省略.........
示例2: fit_dscb
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;
}
示例3: 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);
//.........这里部分代码省略.........
示例4: 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);
//.........这里部分代码省略.........
示例5: fitMass
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));
//.........这里部分代码省略.........
示例6: 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);
//.........这里部分代码省略.........
示例7: fit_dscb
//.........这里部分代码省略.........
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;
}
示例8: 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);
//.........这里部分代码省略.........
示例9: 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));
//.........这里部分代码省略.........
示例10: 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");
//.........这里部分代码省略.........
示例11: 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));
//.........这里部分代码省略.........
示例12: plotPedestalAnalysis
//.........这里部分代码省略.........
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();
示例13: 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);
//.........这里部分代码省略.........
示例14: 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");
//.........这里部分代码省略.........
示例15: compareUpgrade
//.........这里部分代码省略.........
/*
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);