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


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

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


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

示例1: shTest

void shTest(){
  Double_t par[] = {0.3164, 3., 1.5};   //  guesses
  Double_t points(24);
  TF1 * sT = new TF1("sT","0.3164*pow(x,4)*exp(-x*1.5)",0., points);
  sT->Draw();
  Double_t shapeInt = sT->Integral(0., points);
  Double_t shapeMax = sT->GetMaximum(0.,points);
  Double_t shapePeak= sT->GetMaximumX(0.,points);
  Double_t shapeRMS = sqrt(sT->Moment(2,0.,points)-sT->Moment(1,0.,points)*sT->Moment(1,0.,points));
  cout<<"SHAPE  Peak = "<<shapePeak<<"  Max = "<<shapeMax<<"  RMS = "<<shapeRMS<<"  Integral = "<<shapeInt<<endl;
  // return par[0]*pow(x1,4.)*(exp(-x1*16./fN));    //  fN is set to (float)NSAMPLES
}
开发者ID:haggerty,项目名称:analysis,代码行数:12,代码来源:shTest.C

示例2: GetFWHM

void GetFWHM(TF1* floo, double& mean, double& fwhm) {
	TF1* fgt = (TF1*) gROOT->FindObject("fgt");
	if (fgt != 0) delete fgt;
	fgt = new TF1("fgt", gaustail, 0, 6000, 5);
	for (int i=0;i<5;i++)
		fgt->SetParameter(i,floo->GetParameter(i));
	double mean = fgt->GetMaximumX();
	double max = fgt->GetMaximum();
	double left = fgt->GetX(max/2.,0,mean);
	double right = fgt->GetX(max/2.,mean,6000);
	fwhm = right - left;
	cout << "Found " << mean << " " << fwhm << endl;
}
开发者ID:losalamos,项目名称:UCNB_Analyzer,代码行数:13,代码来源:Example.C

示例3: produceTF


//.........这里部分代码省略.........
	     else if( hName[ih] == "dMetPy" ) h[ih]->Fill(dMetPy);
	     else if( hName[ih] == "dBJetPx" ) {h[ih]->Fill(dHiggsBJet1Px);h[ih]->Fill(dHiggsBJet2Px);h[ih]->Fill(dTopLepBJetPx);}
	     else if( hName[ih] == "dBJetPy" ) {h[ih]->Fill(dHiggsBJet1Py);h[ih]->Fill(dHiggsBJet2Py);h[ih]->Fill(dTopLepBJetPy);}
	     else if( hName[ih] == "dBJetPz" ) {h[ih]->Fill(dHiggsBJet1Pz);h[ih]->Fill(dHiggsBJet2Pz);h[ih]->Fill(dTopLepBJetPz);}
	     else if( hName[ih] == "dBJetE" ) {h[ih]->Fill(dHiggsBJet1E);h[ih]->Fill(dHiggsBJet2E);h[ih]->Fill(dTopLepBJetE);}
	     else if( hName[ih] == "dElecPx" ) {h[ih]->Fill(dElecPx);}
	     else if( hName[ih] == "dElecPy" ) {h[ih]->Fill(dElecPy);}
	     else if( hName[ih] == "dElecPz" ) {h[ih]->Fill(dElecPz);}
	     else if( hName[ih] == "dElecE" ) {h[ih]->Fill(dElecE);}
	     else if( hName[ih] == "dMuonPx" ) {h[ih]->Fill(dMuonPx);}
	     else if( hName[ih] == "dMuonPy" ) {h[ih]->Fill(dMuonPy);}
	     else if( hName[ih] == "dMuonPz" ) {h[ih]->Fill(dMuonPz);}
	     else if( hName[ih] == "dMuonE" ) {h[ih]->Fill(dMuonE);}
	  }	
     }
   
   delete rnd;

   // Plots
   
   TCanvas *c1 = new TCanvas();
   c1->Draw();
   c1->cd();

   TPad *c1_1;
   
   gStyle->SetHistTopMargin(0);

   for(int i=0;i<nHist;i++)
     {	
//	addbin(h[i]);

	h[i]->Scale(1./h[i]->Integral());
	h[i]->Scale(1./h[i]->GetMaximum());
   
	h[i]->SetLineWidth(2);	
	h[i]->SetLineColor(kRed);
	h[i]->SetMarkerColor(kRed);
	h[i]->SetMarkerStyle(20);
	h[i]->Draw("hist e1");
	h[i]->GetXaxis()->SetTitle(hLab[i].c_str());
//	h[i]->GetYaxis()->SetTitle("Normalized to unity");
	
	float max = h[i]->GetMaximum();
	
	h[i]->SetMaximum(1.2*max);

	if( hName[i] == "TopLepWM" || hName[i] == "TopLepM" )
	  {
	     std::string funcName = hName[i]+"_Fit";
	     TF1 *func = new TF1(funcName.c_str(),BW,h[i]->GetXaxis()->GetBinLowEdge(1),
				 h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins()),3);
	     
	     double mean = 80.4;
	     if( hName[i] == "TopLepM" ) mean = 173.0;
	     double sigma = 2.0;
	     if( hName[i] == "TopLepM" ) sigma = 2.0;
	     
	     func->SetParameter(0,mean);
	     func->SetParName(0,"mean");	     
	     func->SetParameter(1,sigma);
	     func->SetParName(1,"sigma");
	     func->SetParameter(2,1.0);
	     func->SetParName(2,"constant");
	     
	     func->FixParameter(2,1.);
开发者ID:kskovpen,项目名称:TopKinFit,代码行数:67,代码来源:produceTF.C

示例4: MatchPeaks

void SiCalibrator::MatchPeaks() {
	Load();
	char tmpname[255];
	sprintf(tmpname,"/SumCalData_th%dd%ds%dt%d.root",thresh,decay,shaping,top);
	std::string fname = tmpname;
	std::string filename = mypath;
	filename.append(fname);
	TFile *myfile = new TFile(filename.c_str(),"RECREATE");
	int nbins;
	for (int src=0; src < CalData.size(); src++) {
		if (CalData[src].hSource != 0) {
			CalData[src].hSource->SetDirectory(myfile);
			CalData[src].hSource->Write();
			for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) {
				TH1D* hbi = CalData[src].hSource->ProjectionY("hb",ch+1,ch+1);
				nbins = hbi->GetNbinsX();
				CalData[src].sourcedata[ch].fpol1 = 0;
				if (hbi->Integral(1,nbins) > 0) {
					sprintf(tmpname,"fs%dch%d",src,ch);
					TF1* f = new TF1(tmpname,fitf,0,16000,4);
					CalData[src].sourcedata[ch].fpol1 = f;
					// Build spectrum fit function
					f->FixParameter(0,src);
					f->FixParameter(1,0);
					//f->SetParLimits(1,-30,30);
					f->SetParameter(2,0.2);
					f->SetParameter(3,1);
					f->SetNpx(1000);
					double scale = hbi->GetMaximum()/f->GetMaximum();
					f->FixParameter(3,scale);
					f->SetParameter(2,minimize(f,hbi,2,0.1,0.3));
					//f->ReleaseParameter(2);
					//f->ReleaseParameter(1);
					//hbi->Draw();
					//hbi->Fit(f,"LL","",thresh+50,16000);
					//cout << f->GetChisquare()/f->GetNDF() << endl;
					//f->FixParameter(1,f->GetParameter(1));
					//f->FixParameter(2,f->GetParameter(2));
					//f->SetParameter(3,minimize(f,hbi,3,scale*0.1,scale*5));
					//f->ReleaseParameter(3);
					//f->SetParLimits(3,scale*0.1,scale*5);
					/*
					double slope = f->GetParameter(2);
					if (slope < 0.2 || slope > 0.25) {
						cout << "src " << src;
						cout << " ch " << ch;
						cout << " cnts " << hbi->Integral(1,nbins);
						cout << " pol1" << slope << endl;
						//hbi->Draw();
						//return;
					}
					*/
				//hbi->Fit(f,"LL","",thresh+50,16000);
				//cout << f->GetChisquare()/f->GetNDF() << endl;
				//hbi->Fit(f,"","",150,16000);
				//f->Draw("same");
				/*
					if (src == 1 && ch==13) {
						hbi->Draw();
						f->Draw("same");
						return;
					}
				*/
					f->Write();
				}
			}
		}
	}
	for (int src=0; src < CalData.size(); src++) {
		if (CalData[src].hSource != 0) {
			sprintf(tmpname,"hp1_%d",src);
			CalData[src].hp1 = new TH1D(tmpname,tmpname,CalData[src].sourcedata.size(),0,CalData[src].sourcedata.size());
			for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) {
				if (CalData[src].sourcedata[ch].fpol1 != 0) {
					TF1* f = CalData[src].sourcedata[ch].fpol1;
					CalData[src].hp1->SetBinContent(ch+1,f->GetParameter(2));
				}
			}
			CalData[src].hp1->Write();
			/*
			TCanvas* c = new TCanvas();
			c->Divide(1,2);
			c->cd(1);
			CalData[src].hSource->Draw("COLZ");
			c->cd(2);
			CalData[src].hp1->Draw();
			*/
		}
	}
	myfile->Close();
	delete myfile;
}
开发者ID:losalamos,项目名称:UCNB_Analyzer,代码行数:92,代码来源:SiCalibrator.cpp

示例5: fitTF1

void fitTF1(TCanvas *canvas, TH1F h, double XMIN_, double XMAX_, double dX_, double params[], Color_t LC_=kBlack) { //double& FWHM_, double& x0_, double& x1_, double& x2_, double& y0_, double& y1_, double& INT_, double& YIELD_) {
//TCanvas* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) {
//TF1* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) {
	gROOT->ForceStyle();
	RooMsgService::instance().setSilentMode(kTRUE);
	for(int i=0;i<2;i++) RooMsgService::instance().setStreamStatus(i,kFALSE);

	//TCanvas *canvas = new TCanvas(TString::Format("canvas_%s",h.GetName()),TString::Format("canvas_%s",h.GetName()),1800,1200);

	RooDataHist *RooHistFit = 0;
	RooAddPdf *model = 0;

	RooWorkspace w = RooWorkspace("w","workspace");

	RooRealVar x("mbbReg","mbbReg",XMIN_,XMAX_);
	RooRealVar kJES("CMS_scale_j","CMS_scale_j",1,0.9,1.1);
	RooRealVar kJER("CMS_res_j","CMS_res_j",1,0.8,1.2);
	kJES.setConstant(kTRUE);
	kJER.setConstant(kTRUE);

	TString hname = h.GetName();

	RooHistFit = new RooDataHist("fit_"+hname,"fit_"+hname,x,&h);


	RooRealVar YieldVBF = RooRealVar("yield_"+hname,"yield_"+hname,h.Integral());
	RooRealVar m("mean_"+hname,"mean_"+hname,125,100,150);
	RooRealVar s("sigma_"+hname,"sigma_"+hname,12,3,30);
	RooFormulaVar mShift("mShift_"+hname,"@0*@1",RooArgList(m,kJES));
	RooFormulaVar sShift("sShift_"+hname,"@0*@1",RooArgList(m,kJER));
	RooRealVar a("alpha_"+hname,"alpha_"+hname,1,-10,10);
	RooRealVar n("exp_"+hname,"exp_"+hname,1,0,100);
	RooRealVar b0("b0_"+hname,"b0_"+hname,0.5,0.,1.);
	RooRealVar b1("b1_"+hname,"b1_"+hname,0.5,0.,1.);
	RooRealVar b2("b2_"+hname,"b2_"+hname,0.5,0.,1.);
	RooRealVar b3("b3_"+hname,"b3_"+hname,0.5,0.,1.);
	
	RooBernstein bkg("signal_bkg_"+hname,"signal_bkg_"+hname,x,RooArgSet(b0,b1,b2));
	RooRealVar fsig("fsig_"+hname,"fsig_"+hname,0.7,0.0,1.0);
	RooCBShape sig("signal_gauss_"+hname,"signal_gauss_"+hname,x,mShift,sShift,a,n);

	model = new RooAddPdf("signal_model_"+hname,"signal_model_"+hname,RooArgList(sig,bkg),fsig);

	//RooFitResult *res = model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q");
	model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q");

	//res->Print();
	//model->Print();
	
	canvas->cd();
	canvas->SetTopMargin(0.1);
	RooPlot *frame = x.frame();
// no scale
	RooHistFit->plotOn(frame);
	model->plotOn(frame,RooFit::LineColor(LC_),RooFit::LineWidth(2));//,RooFit::LineStyle(kDotted));
	model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(LC_),RooFit::LineWidth(2),RooFit::LineStyle(kDashed));
// with scale
//	RooHistFit->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent));
//	model->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent),RooFit::LineWidth(1));
//	model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(kBlue),RooFit::LineWidth(1),RooFit::LineStyle(kDashed),RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent));
	 
	frame->GetXaxis()->SetLimits(50,200);
	frame->GetXaxis()->SetNdivisions(505);
	frame->GetXaxis()->SetTitle("M_{b#bar{b}} (GeV)");
	frame->GetYaxis()->SetTitle("Events");
	frame->Draw();
	h.SetFillColor(kGray);
	h.Draw("hist,same");
	frame->Draw("same");
	gPad->RedrawAxis();

	TF1 *tmp = model->asTF(x,fsig,x);
	//tmp->Print();

	double y0_ = tmp->GetMaximum();
	double x0_ = tmp->GetMaximumX();
	double x1_ = tmp->GetX(y0_/2.,XMIN_,x0_);
	double x2_ = tmp->GetX(y0_/2.,x0_,XMAX_);
	double FWHM_ = x2_-x1_;
	double INT_ = tmp->Integral(XMIN_,XMAX_);
	double YIELD_= YieldVBF.getVal();
	double y1_ = dX_*0.5*y0_*(YieldVBF.getVal()/tmp->Integral(XMIN_,XMAX_));

	params[0] = x0_;
	params[1] = x1_;
	params[2] = x2_;
	params[3] = y0_;
	params[4] = y1_;
	params[5] = FWHM_;
	params[6] = INT_;
	params[7] = YIELD_;

	//cout<<"Int = "<<tmp->Integral(XMIN_,XMAX_)<<", Yield = "<<YieldVBF.getVal()<<", y0 = "<<y0_<<", y1 = "<<y1_ <<", x0 = "<< x0_ << ", x1 = "<<x1_<<", x2 = "<<x2_<<", FWHM = "<<FWHM_<<endl;

	TLine ln = TLine(x1_,y1_,x2_,y1_);
	ln.SetLineColor(kMagenta+3);
	ln.SetLineStyle(7);
	ln.SetLineWidth(2);
	ln.Draw();
	
//.........这里部分代码省略.........
开发者ID:UAEDF,项目名称:vbfHbb,代码行数:101,代码来源:fitTF1Self.C


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