Re: incorrect scaling in TPGON

From: Valeri Fine (Faine) (fine@bnl.gov)
Date: Sun Apr 02 2000 - 22:51:02 MEST


 Dear Robert

----- Original Message -----
From: <rhatcher@SLAC.stanford.edu>
To: <roottalk@pcroot.cern.ch>
Subject: incorrect scaling in TPGON


> There seems to be a error in the drawing of PGCON objects under
> ROOT 2.23/12 (and I believe it was wrong before that as well).

You are right.  It is a bug. But I have a small "excuse";-)
I hope people find this story useful to teach the students

The story is:

  Sometimes ago ROOT team forwarded me  a bug report #477 from:

> > Full_Name: Trypiniotis Theodossis
> > Version: 2.20/06
> > Hardware: PC
> > OS: Redhat Linux
> > Severity: normal
> > Reproducable: always
> > Submission from: neutralino.fnal.gov (131.225.53.162)

This report contained a macro (see attachment) to prove TPGON object is wrong.
I fixed it *quickly* ;-(  and tested with that macro. As you can find out yourself
that macro did provided a *proof*  that everything fine now and I sent the fix
to ROOT team without extra check.

 As one can see that test made the object:

   TPGON *pgon = new TPGON("PGON","PGON","void",0,360,6,2);

 For this *particular* case the angstep = 60 deg and one got  
 a confusion with:

     factor = 1/cos(angstep/2) = 1/sin(angstep)

The end of story.

  Thank you very.
               With my regards,
                                              Valery


> Under GEANT3, PGON radii corresponded to the "radius of the circle
> tangent to the sides of the inner/outer polygon in the cross-section".
> In other words the radius of the _inscribed_ circle.

  Yes very this feature was mentioned by the bug report #477.

> The "FillTableOfCoSin" method inherited from TPCON has recently been
> overridden but the calculation is incorrect.  The resulting CoSin values
> are scaled by the radii to determine the vertices of the polygon.
> If "dphi1" (degrees) is the opening angle of the volume and "npdv" is the
> number of sides, then
>   angstep = pi/180 * dphi1 / npdv
> and the relevant scale is:
>     factor = 1/cos(angstep/2)
> which is the ratio of the circumscribed to inscribed radii.
> The TPCON does not scale by any additional factor (which is right for cones)
> but TPGON uses 1/sin(angstep) which is wrong.
>
> -robert
>
> The following macro will show the effect.
>
> =================================================
>
> {
> TGeometry *testgeom = new TGeometry("testgeom","test octogon");
>
> Float_t size = 1.;
> Float_t rin  = 0.;
> Float_t rout, zmin, zmax;
>
> // draw a box that the octogon should fit within
> TBRIK *mybrik = new TBRIK("box","box","void",size,size,size);
> TNode *mybriknode = new TNode("box","box","box");
> cout << "draw brick of size dx = dy = " << size << endl;
>
> // For GEANT3 PGON
> //      RMIN/MAX: radius of the circle tangent to the sides of the
> //                inner/outer polygon in the cross-section
> //
> // ... so this means that "r" is the _incribed_ circle radius
> //     (tangent to the sides).
>
> // draw an octogon with no scaling ... DOESN'T FIT!
> TPGON *oct1 = new TPGON("oct1","oct1","void",-22.5,360.,8,2);
> rout = size;
> zmin = -size;
> zmax = zmin + .1*size;
> oct1->DefineSection(0,zmin,rin,rout);
> oct1->DefineSection(1,zmax,rin,rout);
> TNode *oct1node = new TNode("oct1","oct1","oct1");
> oct1node->SetLineColor(2);
> cout <<  "draw a red octogon with outer radius = "
> << rout << " (no scaling) " << endl;
>
> Float_t deg2rad  = TMath::Pi()/180;
> Float_t cos22p5  = TMath::Cos(deg2rad*45/2);
> Float_t sin45    = TMath::Sin(deg2rad*45);
>
> // draw an octogon with a scaled radius
> // take out the incorrect factor, put in the correct factor
> TPGON *oct2 = new TPGON("oct2","oct2","void",-22.5,360.,8,2);
> rout = size * sin45 / cos22p5;
> zmax = size;
> zmin = zmax - .1*size;
> oct2->DefineSection(0,zmin,rin,rout);
> oct2->DefineSection(1,zmax,rin,rout);
> TNode *oct2node = new TNode("oct2","oct2","oct2");
> oct2node->SetLineColor(3);
> cout <<  "draw a green octogon with outer radius = "
> << rout << " (to correct scaling) " <<  endl;
>
> TCanvas *c1 = new TCanvas("c1","test octogon size",200,10,700,700);
> testgeom->Draw();
> }





n.gif



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:22 MET