How avoid "steps" in the contour/surf plot of a 2D function?

Hello, I plotted a 2D function as a surf plot (and also as a contour plot, see below). Normally, it should show an elliptical area that falls off quite steeply which it roughly does, however there are some steps in the plot. Can you advise how I can avoid them?


Thanks!

Increase the number of bins.

1 Like

@couet

How can I increase the number of bins in a function? I tried with SetNpx( ) and for a similar function to the one above I get oscillations on the rim of the function, see surface plot to the left. I do not see the oscillations if I randomly fill a histogram with the function values, see plot on the right hand-side. Therefore I do believe that the oscillations are an artefact. Can you advise?

Can you post the small script producing this plot ?

Here it is:

rotateAnnulusFunc.C (3.1 KB)

try:

Double_t g3(Double_t *x, Double_t *par) {
   Double_t x1 = Double_t((x[0]-par[7])*cos(par[3])+(x[1]-par[8])*sin(par[3]));
   Double_t x2 = Double_t(-(x[0]-par[7])*sin(par[3])+(x[1]-par[8])*cos(par[3]));
   Double_t  a = Double_t(par[1]);
   Double_t  b = Double_t(par[2]);
   Double_t r1 = Double_t((x1)*(x1)/(a*a));
   Double_t r2 = Double_t((x2)*(x2)/(b*b));
   Double_t A1 = Double_t((r1+r2-par[5])/par[4]);
   Double_t A2 = Double_t((r1+r2-par[6])/par[4]);
   return par[0]*(-(1/(exp(A2)+1))+1/(exp(A1)+1));
}

 Double_t fun3(Double_t *x, Double_t *par) {                     // Both x and par are vectors.
    Double_t *p1 = &par[0];                                      // p1 is a pointer to the address of parameter 0.
    Double_t result = g3(x,p1);
    return result;
 }

void rotateAnnulusFunc() {
   Double_t w = 1400;
   Double_t h = 700;
   TCanvas * can_fun = new TCanvas("Puck1", "Puck2", w, h );         // name, title, width, height.
   can_fun  ->Divide(2,1);
   Double_t pi = 3.14159265359;
   const Int_t npar = 9;
   Double_t clip = 1.;
   Double_t x0 = 2.8; Double_t x1 = clip*13.2;
   Double_t y0 = 4.2; Double_t y1 = clip*13.6;
   TF2 *f3 = new TF2("f3",fun3,x0,x1,y0,y1, npar);
   Double_t fitPass[npar] =
   {clip*4., clip*1.5, clip*1.0, pi/8., clip*0.3,clip*1.5,clip*1.3, clip*6.3, clip*7.}; //2*pi/180*60.
   f3->SetParameters(fitPass);

   //Create an histogram and fill it randomly with f3
   TH2F *h3       = new TH2F("h3","from f3",100,x0,x1,100,y0, y1);
   Int_t nentries = 10000000;
   h3->FillRandom("f3",nentries);
   
   // Write histogram into root file.
   char nameFile[60];
   sprintf(nameFile, "%d_TransformAnnulus.root", 22222);
   TFile* file1 = new TFile( nameFile, "RECREATE");
   h3->Write();
   file1->Close();
   delete file1;

   // Read histogram from root file.
   char nameFile1[30];
   sprintf(nameFile1, "%d_TransformAnnulus.root", 22222);
   TFile* file = new TFile(nameFile1, "READ");
   TH2F * histo = (TH2F*)file->Get("h3");
   can_fun->cd(1);

   //histo->Draw("surf2");
   f3->SetNpx(100);
   f3->SetNpy(100);
   f3->Draw("surf2");
   can_fun->cd(2);
   h3->Draw("surf2");
}

Okay, I see. Can you give me a checklist of things worth checking before consulting the forum? Maybe a question catalogue … like
1.) Is the method you used meant to be used with 1D, 2D, 3D histograms, respectively?
2.) …

Here is the general help locations:

There is no special checklist. Your question was valid.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.