本文整理汇总了C++中TRandom3::Circle方法的典型用法代码示例。如果您正苦于以下问题:C++ TRandom3::Circle方法的具体用法?C++ TRandom3::Circle怎么用?C++ TRandom3::Circle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TRandom3
的用法示例。
在下文中一共展示了TRandom3::Circle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fitCircle
//____________________________________________________________________
void fitCircle(Int_t n=10000) {
//generates n points around a circle and fit them
TCanvas *c1 = new TCanvas("c1","c1",600,600);
c1->SetGrid();
gr = new TGraph(n);
if (n> 999) gr->SetMarkerStyle(1);
else gr->SetMarkerStyle(3);
TRandom3 r;
Double_t x,y;
for (Int_t i=0;i<n;i++) {
r.Circle(x,y,r.Gaus(4,0.3));
gr->SetPoint(i,x,y);
}
c1->DrawFrame(-5,-5,5,5);
gr->Draw("p");
//Fit a circle to the graph points
TVirtualFitter::SetDefaultFitter("Minuit"); //default is Minuit
TVirtualFitter *fitter = TVirtualFitter::Fitter(0, 3);
fitter->SetFCN(myfcn);
fitter->SetParameter(0, "x0", 0, 0.1, 0,0);
fitter->SetParameter(1, "y0", 0, 0.1, 0,0);
fitter->SetParameter(2, "R", 1, 0.1, 0,0);
Double_t arglist[1] = {0};
fitter->ExecuteCommand("MIGRAD", arglist, 0);
//Draw the circle on top of the points
TArc *arc = new TArc(fitter->GetParameter(0),
fitter->GetParameter(1),fitter->GetParameter(2));
arc->SetLineColor(kRed);
arc->SetLineWidth(4);
arc->Draw();
}
示例2: fitCircle
//____________________________________________________________________
void fitCircle(Int_t n=10000) {
//generates n points around a circle and fit them
TCanvas *c1 = new TCanvas("c1","c1",600,600);
c1->SetGrid();
gr = new TGraph(n);
if (n> 999) gr->SetMarkerStyle(1);
else gr->SetMarkerStyle(3);
TRandom3 r;
Double_t x,y;
for (Int_t i=0;i<n;i++) {
r.Circle(x,y,r.Gaus(4,0.3));
gr->SetPoint(i,x,y);
}
c1->DrawFrame(-5,-5,5,5);
gr->Draw("p");
auto chi2Function = [&](const Double_t *par) {
//minimisation function computing the sum of squares of residuals
// looping at the graph points
Int_t np = gr->GetN();
Double_t f = 0;
Double_t *x = gr->GetX();
Double_t *y = gr->GetY();
for (Int_t i=0;i<np;i++) {
Double_t u = x[i] - par[0];
Double_t v = y[i] - par[1];
Double_t dr = par[2] - std::sqrt(u*u+v*v);
f += dr*dr;
}
return f;
};
// wrap chi2 funciton in a function object for the fit
// 3 is the number of fit parameters (size of array par)
ROOT::Math::Functor fcn(chi2Function,3);
ROOT::Fit::Fitter fitter;
double pStart[3] = {0,0,1};
fitter.SetFCN(fcn, pStart);
fitter.Config().ParSettings(0).SetName("x0");
fitter.Config().ParSettings(1).SetName("y0");
fitter.Config().ParSettings(2).SetName("R");
// do the fit
bool ok = fitter.FitFCN();
if (!ok) {
Error("line3Dfit","Line3D Fit failed");
}
const ROOT::Fit::FitResult & result = fitter.Result();
result.Print(std::cout);
//Draw the circle on top of the points
TArc *arc = new TArc(result.Parameter(0),result.Parameter(1),result.Parameter(2));
arc->SetLineColor(kRed);
arc->SetLineWidth(4);
arc->Draw();
}