当前位置: 首页>>代码示例>>C++>>正文


C++ TF1::GetParErrors方法代码示例

本文整理汇总了C++中TF1::GetParErrors方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::GetParErrors方法的具体用法?C++ TF1::GetParErrors怎么用?C++ TF1::GetParErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TF1的用法示例。


在下文中一共展示了TF1::GetParErrors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawPrunedJM_noDiboson

void drawPrunedJM_noDiboson(){

  gStyle->SetOptStat(0);
  gStyle->SetOptFit(11111111);

  TFile *f = TFile::Open("prunedJetMMu_noDiboson.root");

  TH1D* h_MCWW = (TH1D*)(f->Get("prunedJetMMu_WW_pythia_filtered"));
  TH1D* h_MCWZ = (TH1D*)(f->Get("prunedJetMMu_WZ_pythia_filtered"));
  TH1D* h_MCZZ = (TH1D*)(f->Get("prunedJetMMu_ZZ_pythia_filtered"));
  TH1D* h_dataMu = (TH1D*)(f->Get("prunedJetMMu_data_DoubleMu"));

  Double_t lumi_MCWW = 9959752/56.0;
  Double_t lumi_MCWZ = 9910267/22.4;
  Double_t lumi_MCZZ = 9769891/7.6;
  Double_t lumi_dataMu = 19671.225;
    
  h_MCWW->Scale(lumi_dataMu/lumi_MCWW);
  h_MCWZ->Scale(lumi_dataMu/lumi_MCWZ);
  h_MCZZ->Scale(lumi_dataMu/lumi_MCZZ);

  TH1D* h_allDibosonMC = new TH1D("h_allDibosonMC", "", 100, 40, 240);
  h_allDibosonMC->Add(h_MCWW);
  h_allDibosonMC->Add(h_MCWZ); 
  h_allDibosonMC->Add(h_MCZZ);

  TH1D* h_dataMu_noDiboson = new TH1D("h_dataMu_noDiboson", "", 100, 40, 240);
  h_dataMu_noDiboson->SetTitle("Pruned jet mass distribution (data)");
  h_dataMu_noDiboson->GetXaxis()->SetTitle("Mass");
  h_dataMu_noDiboson->GetYaxis()->SetTitle("Event numbers");  
  
  Int_t NBIN = h_allDibosonMC->GetNbinsX();
  
  for(Int_t i = 1; i < NBIN; i++){
    
    Int_t binCenter = h_dataMu_noDiboson->GetBinCenter(i);
    Int_t binContent = h_dataMu->GetBinContent(i) - h_allDibosonMC->GetBinContent(i);

    if( binCenter > 110 && binCenter < 140 ) continue;
    h_dataMu_noDiboson->SetBinContent(i, binContent);

  }

  TF1* fitCurve = new TF1("fitCurve", fitFunc, 40, 240, 4);
  h_dataMu_noDiboson->Fit(fitCurve, "", "", 40, 240);

  Double_t nBkgSig = fitCurve->Integral(110,140)/h_dataMu->GetBinWidth(1);
  
  vector<Double_t> par;
  vector<Double_t> posPar;
  vector<Double_t> negPar;
  
  for(Int_t i = 0; i < 4; i++){

    par.push_back(fitCurve->GetParameters()[i]);
    posPar.push_back(par[i] + fitCurve->GetParErrors()[i]);
    negPar.push_back(par[i] - fitCurve->GetParErrors()[i]);
    
  }
  
  Double_t x;
  TF1* posFit[4];

  posFit[0] = new TF1("posFit1",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",posPar[0],par[1],par[2],par[3]),
		      40, 240);
  posFit[1] = new TF1("posFit2",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",par[0],posPar[1],par[2],par[3]),
		      40, 240);
  posFit[2] = new TF1("posFit3",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",par[0],par[1],posPar[2],par[3]),
		      40, 240);
  posFit[3] = new TF1("posFit4",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",par[0],par[1],par[2],posPar[3]),
		      40, 240);

  TF1* negFit[4]; 
  
  negFit[0] = new TF1("negFit1",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",negPar[0],par[1],par[2],par[3]),
		      40, 240);
  negFit[1] = new TF1("negFit2",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",par[0],negPar[1],par[2],par[3]),
		      40, 240);
  negFit[2] = new TF1("negFit3",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",par[0],par[1],negPar[2],par[3]),
		      40, 240);
  negFit[3] = new TF1("negFit4",
		      Form("%f*TMath::Exp(%f*x)*0.5*(1+TMath::Erf((x-(%f))/%f))",par[0],par[1],par[2],negPar[3]),
		      40, 240);
  
  TMatrixD posColM(4,1);
  TMatrixD negColM(4,1);
  TMatrixD posRowM(1,4);
  TMatrixD negRowM(1,4);

  for(Int_t i = 0; i < 4; i++){
    
    posColM(i,0) = fabs(nBkgSig - posFit[i]->Integral(110,140)/h_dataMu->GetBinWidth(1));
    negColM(i,0) = fabs(nBkgSig - negFit[i]->Integral(110,140)/h_dataMu->GetBinWidth(1));
//.........这里部分代码省略.........
开发者ID:syuvivida,项目名称:xtozh_common,代码行数:101,代码来源:prunedJM_2.C

示例2: doFit

Stat_t AnalysisClass::doFit(Int_t RunNumber,Char_t *Variable, Char_t *SubDetName, Char_t *Layer,Char_t *label){
  TH1 *htoFit=0; 
  pLanGausS[0]=0; pLanGausS[1]=0; pLanGausS[2]=0; pLanGausS[3]=0;
  epLanGausS[0]=0; epLanGausS[1]=0; epLanGausS[2]=0; epLanGausS[3]=0;

  if (debug)   cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) cout << "Found " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		htoFit = (TH1*) d3;
		if (debug) cout << "Found " << Variable << endl;
		
		if (htoFit->GetEntries()!=0) {
		  cout<<"Fitting "<< htoFit->GetTitle() <<endl;
		  // Setting fit range and start values
		  Double_t fr[2];
		  Double_t sv[4], pllo[4], plhi[4];
		  fr[0]=0.5*htoFit->GetMean();
		  fr[1]=3.0*htoFit->GetMean();
	      
		  // (EM) parameters setting good for signal only 
		  Int_t imax=htoFit->GetMaximumBin();
		  Double_t xmax=htoFit->GetBinCenter(imax);
		  Double_t ymax=htoFit->GetBinContent(imax);
		  Int_t i[2];
		  Int_t iArea[2];
	      
		  i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
		  i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
		  
		  iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
		  iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
		  Double_t AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width");
		  
		  sv[1]=xmax;
		  sv[2]=htoFit->Integral(i[0],i[1],"width");
		  sv[3]=AreaFWHM/(4*ymax);
		  sv[0]=sv[3];
		  
		  plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0;
		  pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0      ; pllo[3]= 1.0;
		  
		  // create different landau+gaussians for different runs
		  Char_t FunName[100];
		  sprintf(FunName,"FitfcnLG_%s%d",htoFit->GetName(),fRun);  
		  TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
		  if (ffitold) delete ffitold;
		  
		  langausFit = new TF1(FunName,langaufun,fr[0],fr[1],4);
		  langausFit->SetParameters(sv);
		  langausFit->SetParNames("Width","MP","Area","GSigma");
		  
		  for (Int_t i=0; i<4; i++) {
		    langausFit->SetParLimits(i,pllo[i],plhi[i]);
		  }  
		  
		  htoFit->Fit(langausFit,"R0");  // "R" fit in a range,"0" quiet fit
		  
		  langausFit->SetRange(fr[0],fr[1]);
		  pLanGausS=langausFit->GetParameters();
		  epLanGausS=langausFit->GetParErrors();
		  
		  chi2GausS =langausFit->GetChisquare();  // obtain chi^2
		  nDofGausS = langausFit->GetNDF();           // obtain ndf
		  
		  Double_t sPeak, sFWHM;
		  langaupro(pLanGausS,sPeak,sFWHM);
		  pLanConv[0]=sPeak;
		  pLanConv[1]=sFWHM;
		  cout << "langaupro:  max  " << sPeak << endl;
		  cout << "langaupro:  FWHM " << sFWHM << endl;
		  
		  TCanvas *cAll = new TCanvas("Fit",htoFit->GetTitle(),1);
		  Char_t fitFileName[60];
		  sprintf(fitFileName,"Fits/Run_%d/%s/Fit_%s.png",RunNumber,SubDetName,htoFit->GetTitle());
		  htoFit->Draw("pe");
		  htoFit->SetStats(100);
		  langausFit->Draw("lsame");
		  gStyle->SetOptFit(1111111);
		  
		  cAll->Print(fitFileName,"png");
		}
		else {  
		  pLanGausS[0]=-10; pLanGausS[1]=-10; pLanGausS[2]=-10; pLanGausS[3]=-10;
//.........这里部分代码省略.........
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:101,代码来源:LayerTree.cpp

示例3: doNoiseFit

//Noise section
Stat_t AnalysisClass::doNoiseFit(Int_t RunNumber, Char_t *Variable, Char_t *SubDetName, Char_t *Layer, Char_t *label){
  TH1 *hNtoFit=0;
  if (debug) cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) cout << "Found " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		hNtoFit = (TH1*) d3;
		if (debug) cout << "Found " << Variable << endl;
		if (hNtoFit->GetEntries()!=0) {
		  cout<<"Fitting "<< hNtoFit->GetTitle() <<endl;
		  // Setting fit range and start values
		  Double_t fr[2];
		  Double_t sv[3], pllo[3], plhi[3];
		  fr[0]=hNtoFit->GetMean()-5*hNtoFit->GetRMS();
		  fr[1]=hNtoFit->GetMean()+5*hNtoFit->GetRMS();
		  
		  Int_t imax=hNtoFit->GetMaximumBin();
		  Double_t xmax=hNtoFit->GetBinCenter(imax);
		  Double_t ymax=hNtoFit->GetBinContent(imax);
		  Int_t i[2];
		  Int_t iArea[2];
		  
		  i[0]=hNtoFit->GetXaxis()->FindBin(fr[0]);
		  i[1]=hNtoFit->GetXaxis()->FindBin(fr[1]);
		  
		  iArea[0]=hNtoFit->GetXaxis()->FindBin(fr[0]);
		  iArea[1]=hNtoFit->GetXaxis()->FindBin(fr[1]);
		  Double_t AreaFWHM=hNtoFit->Integral(iArea[0],iArea[1],"width");
		  
		  sv[2]=AreaFWHM/(4*ymax);
		  sv[1]=xmax;
		  sv[0]=hNtoFit->Integral(i[0],i[1],"width");
		  
		  plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.;
		  pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3;
		  Char_t FunName[100];
		  sprintf(FunName,"FitfcnLG_%s%d",hNtoFit->GetName(),fRun);
		  TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
		  if (ffitold) delete ffitold;
		  
		  gausFit = new TF1(FunName,Gauss,fr[0],fr[1],3);
		  gausFit->SetParameters(sv);
		  gausFit->SetParNames("Constant","GaussPeak","Sigma");
		  
		  for (Int_t i=0; i<3; i++) {
		    gausFit->SetParLimits(i,pllo[i],plhi[i]);
		  }
		  hNtoFit->Fit(gausFit,"R0");
		  
		  gausFit->SetRange(fr[0],fr[1]);
		  pGausS=gausFit->GetParameters();
		  epGausS=gausFit->GetParErrors();
		  
		  chi2GausS =langausFit->GetChisquare(); // obtain chi^2
		  nDofGausS = langausFit->GetNDF();// obtain ndf
		  
		  TCanvas *cAllN = new TCanvas("NoiseFit",hNtoFit->GetTitle(),1);
		  Char_t fitFileName[60];
		  sprintf(fitFileName,"Fits/Run_%d/%s/Fit_%s.png",RunNumber,SubDetName,hNtoFit->GetTitle());
		  hNtoFit->Draw("pe");
		  gStyle->SetOptFit(1111111);
		  gausFit->Draw("lsame");
   
		  cAllN->Print(fitFileName,"png");
		}else {
		  pGausS[0]=-10; pGausS[1]=-10; pGausS[2]=-10;
		  epGausS[0]=-10; epGausS[1]=-10; epGausS[2]=-10;
		}
	      }
	    }
	  }
	}
      }
    }
 
  return hNtoFit->GetEntries();
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:94,代码来源:LayerTree.cpp

示例4: fileOutName

/**
 * This function fits TH2F slices with a selected fitType function (gaussian, lorentz, ...).
 */
TGraphErrors* fit2DProj(TString name, TString path, int minEntries, int rebinX, int rebinY, int fitType,
                        TFile * outputFile, const TString & resonanceType, const double & xDisplace, const TString & append) {

  //Read the TH2 from file
  TFile *inputFile = new TFile(path);
  TH2 * histo = (TH2*) inputFile->Get(name);
  if( rebinX > 0 ) histo->RebinX(rebinX);
  if( rebinY > 0 ) histo->RebinY(rebinY);

  //Declare some variables
  TH1 * histoY;
  TString nameY;
  std::vector<double> Ftop;
  std::vector<double> Fwidth;
  std::vector<double> Fmass;
  std::vector<double> Etop;
  std::vector<double> Ewidth;
  std::vector<double> Emass;
  std::vector<double> Fchi2;
  std::vector<double> Xcenter;
  std::vector<double> Ex;

  TString fileOutName("fitCompare2"+name);
  fileOutName += append;
  fileOutName += ".root";
  TFile *fileOut=new TFile(fileOutName,"RECREATE");

  for (int i=1; i<=(histo->GetXaxis()->GetNbins());i++) {

    //Project on Y (set name and title)
    std::stringstream number;
    number << i;
    TString numberString(number.str());
    nameY = name + "_" + numberString;
    // std::cout << "nameY  " << nameY << std::endl;

    histoY = histo->ProjectionY(nameY, i, i);

    double xBin = histo->GetXaxis()->GetBinCenter(i);
    std::stringstream xBinString;
    xBinString << xBin;
    TString title("Projection of x = ");
    title += xBinString.str();

    histoY->SetName(title);

    if (histoY->GetEntries() > minEntries) {

      //Make the dirty work!
      TF1 *fit;
      std::cout << "fitType = " << fitType << std::endl;
      if(fitType == 1) fit = gaussianFit(histoY, resonanceType);
      else if(fitType == 2) fit = lorentzianFit(histoY, resonanceType);
      else if(fitType == 3) fit = linLorentzianFit(histoY);
      else {
	std::cout<<"Wrong fit type: 1=gaussian, 2=lorentzian, 3=lorentzian+linear."<<std::endl;
	abort();
      }

      double *par = fit->GetParameters();
      double *err = fit->GetParErrors();

      // Check the histogram alone
      TCanvas *canvas = new TCanvas(nameY+"alone", nameY+" alone");
      histoY->Draw();
      canvas->Write();

      // Only for check
      TCanvas *c = new TCanvas(nameY, nameY);

      histoY->Draw();
      fit->Draw("same");
      fileOut->cd();
      c->Write();

      if( par[0] == par[0] ) {
        //Store the fit results
        Ftop.push_back(par[0]);
        Fwidth.push_back(fabs(par[1]));//sometimes the gaussian has negative width (checked with Rene Brun)
        Fmass.push_back(par[2]);
        Etop.push_back(err[0]);
        Ewidth.push_back(err[1]);
        Emass.push_back(err[2]);

        Fchi2.push_back(fit->GetChisquare()/fit->GetNDF());

        double xx= histo->GetXaxis()->GetBinCenter(i);
        Xcenter.push_back(xx);
        double ex = 0;
        Ex.push_back(ex); 
      }
      else {
        // Skip nan
        std::cout << "Skipping nan" << std::endl;
        Ftop.push_back(0);
        Fwidth.push_back(0);
        Fmass.push_back(0);
//.........这里部分代码省略.........
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:101,代码来源:fit2DProj.C


注:本文中的TF1::GetParErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。