naraew
1
Hi,
I have defined a TF2 in root like this
TF2 *ell = new TF2(“ell”,“pow(y/sqrt(a) + x/sqrt(b) ,2)+pow(y/sqrt© + x/sqrt(d) ,2)<e”,-6.,6.,-10.0,10.0);
a, b, c, d, e are known and I just replaced them to focus on the interesting part.
So my problem is:
I want to fill an ascii file with for example 1000 pairs of x and y values.
How can I do that?
Thanks a lot,
Stephan
brun
2
Here is an example with 1000 points taken randomly from your function
{
TF2 *ell = new TF2("ell","pow(y/sqrt([0]) + x/sqrt([1]) ,2)+pow(y/sqrt(3) + x/sqrt(4) ,2)",-6.,6.,-10.0,10.0);
ell->SetParameters(0,1,0.5,1.5);
double x,y;
for (int i=0;i<1000;i++) {
ell->GetRandom2(x,y);
printf("%4d, %g, %g\n",i,x,y);
}
}
Rene
naraew
3
Ok, I see what you mean. But my TF2 is restricted, so will it work for this case too, since not all x and y points are allowed?
Stephan
brun
4
You must precise your question. In my example, I was getting random points. You can call TF2::Eval to compute points in any given sub-range.
Rene
naraew
5
Oh, ok.
My definition is:
TF2 *ell = new TF2(“ell”,“pow(y/sqrt(a) + x/sqrt(b) ,2)+pow(y/sqrt© + x/sqrt(d) ,2)=e”,-6.,6.,-10.0,10.0);
So I just accept those values for x and y that fulfill the equation defined above. And I would like to have exactly those points in a list.
I hope this helps.
Thanks,
Stephan
brun
6
see code below and also $ROOTSYS/tutorials/hist/FirstContour.C
[code]{
TF2 *ell = new TF2(“ell”,“pow(y/sqrt([0]) + x/sqrt([1]) ,2)+pow(y/sqrt(3) + x/sqrt(4) ,2)”,-6.,6.,-10.0,10.0);
ell->SetParameters(0,1,0.5,1.5);
ell->SetContour(2);
ell->SetContourLevel(0,0);
ell->SetContourLevel(1,6);
printf(“cl1=%g\n”,ell->GetContourLevel(1));
TCanvas c1;
ell->Draw(“cont list”);
c1->Update();
TObjArray contours =
(TObjArray)gROOT->GetListOfSpecials()->FindObject(“contours”);
TList lcontour1 = (TList)contours->At(0);
TGraph gc1 = (TGraph)lcontour1->First();
gc1->SetMarkerStyle(21);
c1->Clear();
gc1->Draw(“alp”);
}[/code]
Rene