// @(#)root/graf:$Id$
// Author: Guido Volpi, Olivier Couet 03/11/2006

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TPie.h"
#include "TPieSlice.h"

#include <Riostream.h>
#include <TROOT.h>
#include <TVirtualPad.h>
#include <TArc.h>
#include <TLegend.h>
#include <TMath.h>
#include <TStyle.h>
#include <TLatex.h>
#include <TPaveText.h>
#include <TH1.h>
#include <TColor.h>

ClassImp(TPie)


//______________________________________________________________________________
//
// Draw a Pie Chart
//
// The macro $ROOTSYS/tutorials/graphics/piechart.C produces the following
// picture:
//Begin_Html
/*
<img src="gif/piechart.gif">
*/
//End_Html
//

Double_t gX             = 0; // Temporary pie X position.
Double_t gY             = 0; // Temporary pie Y position.
Double_t gRadius        = 0; // Temporary pie Radius of the TPie.
Double_t gRadiusOffset  = 0; // Temporary slice's radial offset.
Double_t gAngularOffset = 0; // Temporary slice's angular offset.
Bool_t   gIsUptSlice    = kFALSE; // True if a slice in the TPie should
                                  // be updated.
Int_t    gCurrent_slice = -1;// Current slice under mouse.
Double_t gCurrent_phi1  = 0; // Phimin of the current slice.
Double_t gCurrent_phi2  = 0; // Phimax of the current slice.
Double_t gCurrent_rad   = 0; // Current distance from the vertex of the
                             // current slice.
Double_t gCurrent_x     = 0; // Current x in the pad metric.
Double_t gCurrent_y     = 0; // Current y in the pad metric.
Double_t gCurrent_ang   = 0; // Current angular, within current_phi1
                                    // and current_phi2.

//______________________________________________________________________________
TPie::TPie() : TNamed()
{
   // Default constructor.

   Init(1, 0, 0.5, 0.5, 0.4);
}


//______________________________________________________________________________
TPie::TPie(const char *name, const char *title, Int_t npoints) :
           TNamed(name,title)
{
   // This constructor creates a pie chart when only the number of
   // the slices is known. The number of slices is fixed.

   Init(npoints, 0, 0.5, 0.5, 0.4);
}


//______________________________________________________________________________
TPie::TPie(const char *name, const char *title,
           Int_t npoints, Double_t *vals,
           Int_t *colors, const char *lbls[]) : TNamed(name,title)
{
   // Normal constructor. The 1st and 2nd parameters are the name of the object
   // and its title.
   //
   // The number of points passed at this point is used to allocate the memory.
   //
   // Slices values are given as Double_t.
   //
   // The 4th elements is an array containing, in double precision format,
   // the value of each slice. It is also possible to specify the filled color
   // of each slice. If the color array is not specfied the slices are colored
   // using a color sequence in the standard palette.

   Init(npoints, 0, 0.5, 0.5, 0.4);
   for (Int_t i=0; i<fNvals; ++i) fPieSlices[i]->SetValue(vals[i]);

   SetFillColors(colors);
   SetLabels(lbls);
}


//______________________________________________________________________________
TPie::TPie(const char *name,
           const char *title,
           Int_t npoints, Float_t *vals,
           Int_t *colors, const char *lbls[]) : TNamed(name,title)
{
   // Normal constructor (Float_t).

   Init(npoints, 0, 0.5, 0.5, 0.4);
   for (Int_t i=0; i<fNvals; ++i) fPieSlices[i]->SetValue(vals[i]);

   SetFillColors(colors);
   SetLabels(lbls);
}


//______________________________________________________________________________
TPie::TPie(const TH1 *h) : TNamed(h->GetName(),h->GetTitle())
{
   // Constructor from a TH1

   Int_t i;

   const TAxis *axis = h->GetXaxis();
   Int_t first = axis->GetFirst();
   Int_t last  = axis->GetLast();
   Int_t np    = last-first+1;
   Init(np, 0, 0.5, 0.5, 0.4);

   for (i=first; i<=last; ++i) fPieSlices[i-first]->SetValue(h->GetBinContent(i));
   if (axis->GetLabels()) {
      for (i=first; i<=last; ++i) fPieSlices[i-first]->SetTitle(axis->GetBinLabel(i));
   } else {
      SetLabelFormat("%val");
   }
   SetTextSize(axis->GetLabelSize());
   SetTextColor(axis->GetLabelColor());
   SetTextFont(axis->GetLabelFont());
}


//______________________________________________________________________________
TPie::TPie(const TPie &cpy) : TNamed(cpy), TAttText(cpy)
{
   // Copy constructor.

   Init(cpy.fNvals, cpy.fAngularOffset, cpy.fX, cpy.fY, cpy.fRadius);

   for (Int_t i=0;i<fNvals;++i) {
      fPieSlices[i] = cpy.fPieSlices[i];
   }
}


//______________________________________________________________________________
TPie::~TPie()
{
   // Destructor.

   if (fNvals>0) {
      delete [] fPieSlices;
   }

   if (fSlices) delete [] fSlices;
   if (fLegend) delete fLegend;
}


//______________________________________________________________________________
Int_t TPie::DistancetoPrimitive(Int_t px, Int_t py)
{
   // Evaluate the distance to the chart in gPad.

   Int_t dist = 9999;

   gCurrent_slice = DistancetoSlice(px,py);
   if ( gCurrent_slice>=0 ) {
      if (gCurrent_rad<=fRadius) {
         dist = 0;
      }
   }

   return dist;
}


//______________________________________________________________________________
Int_t TPie::DistancetoSlice(Int_t px, Int_t py)
{
   // Returns the slice number at the pixel position (px,py).
   // Returns -1 if no slice is picked.
   //
   // Used by DistancetoPrimitive.

   MakeSlices();

   Int_t result(-1);

   // coordinates
   Double_t xx = gPad->AbsPixeltoX(px); //gPad->PadtoX(gPad->AbsPixeltoX(px));
   Double_t yy = gPad->AbsPixeltoY(py); //gPad->PadtoY(gPad->AbsPixeltoY(py));

   // XY metric
   Double_t radX  = fRadius;
   Double_t radY  = fRadius;
   Double_t radXY = 1.;
   if (fIs3D==kTRUE) {
      radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
      radY  = radXY*radX;
   }

   Double_t phimin;
   Double_t cphi;
   Double_t phimax;

   Float_t dPxl = (gPad->PixeltoY(0)-gPad->PixeltoY(1))/radY;
   for (Int_t i=0;i<fNvals;++i) {
      fPieSlices[i]->SetIsActive(kFALSE);

      if (gIsUptSlice && gCurrent_slice!=i) continue;

      // Angles' values for this slice
      phimin = fSlices[2*i  ]*TMath::Pi()/180.;
      cphi   = fSlices[2*i+1]*TMath::Pi()/180.;
      phimax = fSlices[2*i+2]*TMath::Pi()/180.;

      Double_t radOffset = fPieSlices[i]->GetRadiusOffset();

      Double_t dx  = (xx-fX-radOffset*TMath::Cos(cphi))/radX;
      Double_t dy  = (yy-fY-radOffset*TMath::Sin(cphi)*radXY)/radY;

      if (TMath::Abs(dy)<dPxl) dy = dPxl;

      Double_t ang = TMath::ATan2(dy,dx);
      if (ang<0) ang += TMath::TwoPi();

      Double_t dist = TMath::Sqrt(dx*dx+dy*dy);

      if ( ((ang>=phimin && ang <= phimax) || (phimax>TMath::TwoPi() &&
            ang+TMath::TwoPi()>=phimin && ang+TMath::TwoPi()<phimax)) &&
            dist<=1.) { // if true the pointer is in the slice region

         gCurrent_x    = dx;
         gCurrent_y    = dy;
         gCurrent_ang  = ang;
         gCurrent_phi1 = phimin;
         gCurrent_phi2 = phimax;
         gCurrent_rad  = dist*fRadius;

         if (dist<.95 && dist>.65) {
            Double_t range = phimax-phimin;
            Double_t lang = ang-phimin;
            Double_t rang = phimax-ang;
            if (lang<0) lang += TMath::TwoPi();
            else if (lang>=TMath::TwoPi()) lang -= TMath::TwoPi();
            if (rang<0) rang += TMath::TwoPi();
            else if (rang>=TMath::TwoPi()) rang -= TMath::TwoPi();

            if (lang/range<.25 || rang/range<.25) {
               fPieSlices[i]->SetIsActive(kTRUE);
               result = -1;
            }
            else result  = i;
         } else {
            result = i;
         }

         break;
      }
   }
   return result;
}


//______________________________________________________________________________
void TPie::Draw(Option_t *option)
{
   // Draw the pie chart.
   //
   // The possible options are listed in the TPie::Paint() method.

   TString soption(option);
   soption.ToLower();

   if (soption.Length()==0) soption = "l";

   if (gPad) {
      if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
      if (!soption.Contains("same")) {
         gPad->Clear();
         gPad->Range(0.,0.,1.,1.);
      }
   }

   for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->AppendPad();
   AppendPad(soption.Data());
}


//______________________________________________________________________________
void TPie::DrawGhost()
{
   // This method is for internal use. It is used by Execute event to draw the
   // outline of "this" TPie. Used when the opaque movements are not permitted.

   MakeSlices();

   // XY metric
   Double_t radXY = 1.;
   if (fIs3D) {
      radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
   }

   for (Int_t i=0;i<fNvals&&fIs3D==kTRUE;++i) {
      Float_t minphi = (fSlices[i*2]+gAngularOffset+.5)*TMath::Pi()/180.;
      Float_t avgphi = (fSlices[i*2+1]+gAngularOffset)*TMath::Pi()/180.;
      Float_t maxphi = (fSlices[i*2+2]+gAngularOffset-.5)*TMath::Pi()/180.;

      Double_t radOffset = (i == gCurrent_slice ? gRadiusOffset : fPieSlices[i]->GetRadiusOffset());
      Double_t x0 = gX+radOffset*TMath::Cos(avgphi);
      Double_t y0 = gY+radOffset*TMath::Sin(avgphi)*radXY-fHeight;

      gVirtualX->DrawLine( gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0),
                           gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
                           gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY) );

      Int_t ndiv = 10;
      Double_t dphi = (maxphi-minphi)/ndiv;

      if (dphi>.15) ndiv = (Int_t) ((maxphi-minphi)/.15);
      dphi = (maxphi-minphi)/ndiv;

      // Loop to draw the arc
      for (Int_t j=0;j<ndiv;++j) {
         Double_t phi = minphi+dphi*j;
         gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi)),
                              gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi)*radXY),
                              gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi+dphi)),
                              gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi+dphi)*radXY));
      }

      gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
                           gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY),
                           gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0) );

      gVirtualX->DrawLine(gPad->XtoAbsPixel(x0),
                          gPad->YtoAbsPixel(y0),
                          gPad->XtoAbsPixel(x0),
                          gPad->YtoAbsPixel(y0+fHeight));
      gVirtualX->DrawLine(gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
                          gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY),
                          gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
                          gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY+fHeight));
      gVirtualX->DrawLine(gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
                          gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY),
                          gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
                          gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY+fHeight));
   }


   // Loop over slices
   for (Int_t i=0;i<fNvals;++i) {
      Float_t minphi = (fSlices[i*2]+gAngularOffset+.5)*TMath::Pi()/180.;
      Float_t avgphi = (fSlices[i*2+1]+gAngularOffset)*TMath::Pi()/180.;
      Float_t maxphi = (fSlices[i*2+2]+gAngularOffset-.5)*TMath::Pi()/180.;

      Double_t radOffset = (i == gCurrent_slice ? gRadiusOffset : fPieSlices[i]->GetRadiusOffset());
      Double_t x0 = gX+radOffset*TMath::Cos(avgphi);
      Double_t y0 = gY+radOffset*TMath::Sin(avgphi)*radXY;

      gVirtualX->DrawLine( gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0),
                           gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
                           gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY) );


      Int_t ndiv = 10;
      Double_t dphi = (maxphi-minphi)/ndiv;

      if (dphi>.15) ndiv = (Int_t) ((maxphi-minphi)/.15);
      dphi = (maxphi-minphi)/ndiv;

      // Loop to draw the arc
      for (Int_t j=0;j<ndiv;++j) {
         Double_t phi = minphi+dphi*j;
         gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi)),
                              gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi)*radXY),
                              gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi+dphi)),
                              gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi+dphi)*radXY));
      }

      gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
                           gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY),
                           gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0) );
   }
}


//______________________________________________________________________________
void TPie::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
   // Execute the mouse events.

   if (!gPad) return;
   if (!gPad->IsEditable() && event != kMouseEnter) return;

   if (gCurrent_slice<=-10) {
      gPad->SetCursor(kCross);
      return;
   }

   MakeSlices();

   static bool isMovingPie(kFALSE);
   static bool isMovingSlice(kFALSE);
   static bool isResizing(kFALSE);
   static bool isRotating(kFALSE);
   static bool onBorder(kFALSE);
   bool isRedrawing(kFALSE);
   static Int_t prev_event(-1);
   static Int_t oldpx, oldpy;

   // Portion of pie considered as "border"
   const Double_t dr     = gPad->PixeltoX(3);
   const Double_t minRad = gPad->PixeltoX(10);

   // Angular divisions in radial direction
   const Double_t angstep1 = 0.5*TMath::PiOver4();
   const Double_t angstep2 = 1.5*TMath::PiOver4();
   const Double_t angstep3 = 2.5*TMath::PiOver4();
   const Double_t angstep4 = 3.5*TMath::PiOver4();
   const Double_t angstep5 = 4.5*TMath::PiOver4();
   const Double_t angstep6 = 5.5*TMath::PiOver4();
   const Double_t angstep7 = 6.5*TMath::PiOver4();
   const Double_t angstep8 = 7.5*TMath::PiOver4();

   // XY metric
   Double_t radXY = 1.;
   if (fIs3D==kTRUE) {
      radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
   }

   Int_t dx, dy;
   Double_t mdx, mdy;

   switch(event) {
      case kArrowKeyPress:
      case kButton1Down:
         // Change cursor to show pie's movement.
         gVirtualX->SetLineColor(1);
         gVirtualX->SetLineWidth(2);

         // Current center and radius.
         gX             = fX;
         gY             = fY;
         gRadius        = fRadius;
         gRadiusOffset  = fPieSlices[gCurrent_slice]->GetRadiusOffset();
         gAngularOffset = 0;
         gIsUptSlice    = kTRUE;

         prev_event = kButton1Down;

      case kMouseMotion:
         if (gCurrent_rad>=fRadius-2.*dr && gCurrent_rad<=fRadius+dr
               && !isMovingPie && !isMovingSlice && !isResizing) {
            if (gCurrent_ang>=angstep8 || gCurrent_ang<angstep1)
               gPad->SetCursor(kRightSide);
            else if (gCurrent_ang>=angstep1 && gCurrent_ang<angstep2)
               gPad->SetCursor(kTopRight);
            else if (gCurrent_ang>=angstep2 && gCurrent_ang<angstep3)
               gPad->SetCursor(kTopSide);
            else if (gCurrent_ang>=angstep3 && gCurrent_ang<angstep4)
               gPad->SetCursor(kTopLeft);
            else if (gCurrent_ang>=angstep4 && gCurrent_ang<=angstep5)
               gPad->SetCursor(kLeftSide);
            else if (gCurrent_ang>=angstep5 && gCurrent_ang<angstep6)
               gPad->SetCursor(kBottomLeft);
            else if (gCurrent_ang>=angstep6 && gCurrent_ang<angstep7)
               gPad->SetCursor(kBottomSide);
            else if (gCurrent_ang>=angstep7 && gCurrent_ang<angstep8)
               gPad->SetCursor(kBottomRight);
            onBorder = kTRUE;
         } else {
            onBorder = kFALSE;
            if (gCurrent_rad>fRadius*.6) {
               gPad->SetCursor(kPointer);
            } else if (gCurrent_rad<=fRadius*.3) {
               gPad->SetCursor(kHand);
            } else if (gCurrent_rad<=fRadius*.6 && gCurrent_rad>=fRadius*.3) {
               gPad->SetCursor(kRotate);
            }
         }
         oldpx = px;
         oldpy = py;
         if (isMovingPie || isMovingSlice) gPad->SetCursor(kMove);
         break;

      case kArrowKeyRelease:
      case kButton1Motion:
         if (!isMovingSlice || !isMovingPie || !isResizing || !isRotating) {
            if (prev_event==kButton1Down) {
               if (onBorder) {
                  isResizing = kTRUE;
               } else if (gCurrent_rad>=fRadius*.6 && gCurrent_slice>=0) {
                  isMovingSlice = kTRUE;
               } else if (gCurrent_rad<=fRadius*.3) {
                  isMovingPie = kTRUE;
               } else if (gCurrent_rad<fRadius*.6 && gCurrent_rad>fRadius*.3) {
                  isRotating = kTRUE;
               }
            }
         }

         dx = px-oldpx;
         dy = py-oldpy;

         mdx = gPad->PixeltoX(dx);
         mdy = gPad->PixeltoY(dy);

         if (isMovingPie || isMovingSlice) {
            gPad->SetCursor(kMove);
            if (isMovingSlice) {
               Float_t avgphi = fSlices[gCurrent_slice*2+1]*TMath::Pi()/180.;

               if (!gPad->OpaqueMoving()) DrawGhost();

               gRadiusOffset += TMath::Cos(avgphi)*mdx +TMath::Sin(avgphi)*mdy/radXY;
               if (gRadiusOffset<0) gRadiusOffset = .0;
               gIsUptSlice         = kTRUE;

               if (!gPad->OpaqueMoving()) DrawGhost();
            } else {
               if (!gPad->OpaqueMoving()) DrawGhost();

               gX += mdx;
               gY += mdy;

               if (!gPad->OpaqueMoving()) DrawGhost();
            }
         } else if (isResizing) {
            if (!gPad->OpaqueResizing()) DrawGhost();

            Float_t dr1 = mdx*TMath::Cos(gCurrent_ang)+mdy*TMath::Sin(gCurrent_ang)/radXY;
            if (gRadius+dr1>=minRad) {
               gRadius += dr1;
            } else {
               gRadius = minRad;
            }

            if (!gPad->OpaqueResizing()) DrawGhost();
         } else if (isRotating) {
            if (!gPad->OpaqueMoving()) DrawGhost();

            Double_t xx = gPad->AbsPixeltoX(px);
            Double_t yy = gPad->AbsPixeltoY(py);

            Double_t dx1  = xx-gX;
            Double_t dy1  = yy-gY;

            Double_t ang = TMath::ATan2(dy1,dx1);
            if (ang<0) ang += TMath::TwoPi();

            gAngularOffset = (ang-gCurrent_ang)*180/TMath::Pi();

            if (!gPad->OpaqueMoving()) DrawGhost();
         }

         oldpx = px;
         oldpy = py;

         if ( ((isMovingPie || isMovingSlice || isRotating) && gPad->OpaqueMoving()) ||
               (isResizing && gPad->OpaqueResizing()) ) {
            isRedrawing = kTRUE;
            event = kButton1Up;
         }
         else break;

      case kButton1Up:
         if (!isRedrawing) {
            prev_event = kButton1Up;
            gIsUptSlice = kFALSE;
         }

         if (gROOT->IsEscaped()) {
            gROOT->SetEscape(kFALSE);
            gIsUptSlice = kFALSE;
            isRedrawing = kFALSE;
            break;
         }

         fX      = gX;
         fY      = gY;
         fRadius = gRadius;
         fPieSlices[gCurrent_slice]->SetRadiusOffset(gRadiusOffset);
         SetAngularOffset(fAngularOffset+gAngularOffset);

         if (isRedrawing && (isMovingPie || isMovingSlice)) gPad->SetCursor(kMove);

         if (isMovingPie)   isMovingPie   = kFALSE;
         if (isMovingSlice) isMovingSlice = kFALSE;
         if (isResizing)    isResizing    = kFALSE;
         if (isRotating)    {
            isRotating = kFALSE;
            // this is important mainly when OpaqueMoving==kTRUE
            gCurrent_ang += gAngularOffset/180.*TMath::Pi();
         }

         gPad->Modified(kTRUE);


         isRedrawing = kFALSE;
         gIsUptSlice = kFALSE;

         gVirtualX->SetLineColor(-1);
         gVirtualX->SetLineWidth(-1);

         break;
      case kButton1Locate:

         ExecuteEvent(kButton1Down, px, py);

         while (1) {
            px = py = 0;
            event = gVirtualX->RequestLocator(1, 1, px, py);

            ExecuteEvent(kButton1Motion, px, py);

            if (event != -1) {                     // button is released
               ExecuteEvent(kButton1Up, px, py);
               return;
            }
         }
         break;

      case kMouseEnter:
         break;

      default:
         // unknown event
         break;
   }
}


//______________________________________________________________________________
const char* TPie::GetEntryLabel(Int_t i)
{
   // Returns the label of the entry number "i".

   return GetSlice(i)->GetTitle();
}


//______________________________________________________________________________
Int_t TPie::GetEntryFillColor(Int_t i)
{
   // Return the color of the slice number "i".

   return GetSlice(i)->GetFillColor();
}


//______________________________________________________________________________
Int_t TPie::GetEntryFillStyle(Int_t i)
{
   // Return the style use to fill the slice number "i".

   return GetSlice(i)->GetFillStyle();
}


//______________________________________________________________________________
Int_t TPie::GetEntryLineColor(Int_t i)
{
   // Return the line color used to outline thi "i" slice

   return GetSlice(i)->GetLineColor();
}


//______________________________________________________________________________
Int_t TPie::GetEntryLineStyle(Int_t i)
{
   // Return the style used to outline thi "i" slice

   return GetSlice(i)->GetLineStyle();
}


//______________________________________________________________________________
Int_t TPie::GetEntryLineWidth(Int_t i)
{
   // Return the line width used to outline thi "i" slice

   return GetSlice(i)->GetLineWidth();
}


//______________________________________________________________________________
Double_t TPie::GetEntryRadiusOffset(Int_t i)
{
   // Return the radial offset's value for the slice number "i".

   return GetSlice(i)->GetRadiusOffset();
}


//______________________________________________________________________________
Double_t TPie::GetEntryVal(Int_t i)
{
   // Return the value associated with the slice number "i".

   return GetSlice(i)->GetValue();
}


//______________________________________________________________________________
TLegend* TPie::GetLegend()
{
   // If created before by Paint option or by MakeLegend method return
   // the pointer to the legend, otherwise return 0;

   return fLegend;
}


//______________________________________________________________________________
TPieSlice* TPie::GetSlice(Int_t id)
{
   // Return the reference to the slice of index 'id'. There are no controls
   // of memory corruption, be carefull.

   return fPieSlices[id];
}


//______________________________________________________________________________
void TPie::Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r)
{
   // Common initialization for all constructors.
   // This is a private function called to allocate the memory.

   gIsUptSlice = kFALSE;

   fAngularOffset = ao;
   fX             = x;
   fY             = y;
   fRadius        = r;
   fNvals         = np;
   fSum           = 0.;
   fSlices        = 0;
   fLegend        = 0;
   fHeight        = 0.08;
   fAngle3D       = 30;

   fLabelsOffset = gStyle->GetLabelOffset();

   fPieSlices = new TPieSlice*[fNvals];

   for (Int_t i=0;i<fNvals;++i) {
      TString tmplbl = "Slice";
      tmplbl += i;
      fPieSlices[i] = new TPieSlice(tmplbl.Data(), tmplbl.Data(), this);
      fPieSlices[i]->SetRadiusOffset(0.);
      fPieSlices[i]->SetLineColor(1);
      fPieSlices[i]->SetLineStyle(1);
      fPieSlices[i]->SetLineWidth(1);
      fPieSlices[i]->SetFillColor(gStyle->GetColorPalette(i));
      fPieSlices[i]->SetFillStyle(1001);
   }

   fLabelFormat    = "%txt";
   fFractionFormat = "%3.2f";
   fValueFormat    = "%4.2f";
   fPercentFormat  = "%3.1f";
}


//______________________________________________________________________________
TLegend* TPie::MakeLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char *leg_header)
{
   // This method create a legend that explains the contents
   // of the slice for this pie-chart.
   //
   // The parameter passed reppresents the option passed to shown the slices,
   // see TLegend::AddEntry() for futher details.
   //
   // The pointer of the TLegend is returned.

   if (!fLegend) fLegend = new TLegend(x1,y1,x2,y2,leg_header);
   else fLegend->Clear();

   for (Int_t i=0;i<fNvals;++i) {
      fLegend->AddEntry(*(fPieSlices+i),fPieSlices[i]->GetTitle(),"f");
   }

   if (gPad) fLegend->Draw();

   return fLegend;
}


//______________________________________________________________________________
void TPie::Paint(Option_t *option)
{
   // Paint a Pie chart in a canvas.
   // The possible option are:
   //
   // "R"   Print the labels along the central "R"adius of slices.
   // "T"   Print the label in a direction "T"angent to circle that describes
   //       the TPie.
   // "SC"  Paint the the labels with the "S"ame "C"olor as the slices.
   // "3D"  Draw the pie-chart with a pseudo 3D effect.
   // "NOL" No OutLine: Don't draw the slices' outlines, any property over the
   //       slices' line is ignored.
   // ">"   Sort the slices in increasing order.
   // "<"   Sort the slices in decreasing order.
   //
   // After the use of > or < options the internal order of the TPieSlices
   // is changed.
   //
   // Other options changing the labels' format are described in
   // TPie::SetLabelFormat().

   MakeSlices();

   TString soption(option);

   bool optionSame(kFALSE);

   // if true the lines around the slices are drawn, if false not
   Bool_t optionLine(kTRUE);

   // if true the labels' colors are the same as the slices' colors
   Bool_t optionSameColor(kFALSE);

   // For the label orientation there are 3 possibilities:
   //   0: horizontal
   //   1: radial
   //   2: tangent
   Int_t lblor(0);

   // Parse the options
   Int_t idx;
   // Paint the TPie in an existing canvas
   if ( (idx=soption.Index("same"))>=0 ) {
      optionSame = kTRUE;
      soption.Remove(idx,4);
   }

   if ( (idx=soption.Index("nol"))>=0 ) {
      optionLine = kFALSE;
      soption.Remove(idx,3);
   }

   if ( (idx=soption.Index("sc"))>=0 ) {
      optionSameColor = kTRUE;
      soption.Remove(idx,2);
   }

   // check if is active the pseudo-3d
   if ( (idx=soption.Index("3d"))>=0 ) {
      fIs3D = kTRUE;
      soption.Remove(idx,2);
   } else {
      fIs3D = kFALSE;
   }

   // seek if have to draw the labels around the pie chart
   if ( (idx=soption.Index("t"))>=0 ) {
      lblor = 2;
      soption.Remove(idx,1);
   }

   // Seek if have to paint the labels along the radii
   if ( (idx=soption.Index("r"))>=0 ) {
      lblor = 1;
      soption.Remove(idx,1);
   }

   // Seeks if has to paint sort the slices in increasing mode
   if ( (idx=soption.Index(">"))>=0 ) {
      SortSlices(kTRUE);
      soption.Remove(idx,1);
   }

   // Seeks if has to paint sort the slices in decreasing mode
   if ( (idx=soption.Index("<"))>=0 ) {
      SortSlices(kFALSE);
      soption.Remove(idx,1);
   }

   if (fNvals<=0) {
      Warning("Paint","No vals");
      return;
   }

   if (!fPieSlices) {
      Warning("Paint","No valid arrays of values");
      return;
   }

   // Check if gPad exists and define the drawing range.
   if (!gPad) return;

   // Objects useful to draw labels and slices
   TLatex *textlabel = new TLatex();
   TArc *arc = new TArc();
   TLine *line = new TLine();

   // XY metric
   Double_t radX  = fRadius;
   Double_t radY  = fRadius;
   Double_t radXY = 1.;

   if (fIs3D) {
      radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
      radY = fRadius*radXY;
   }

   // Draw the slices.
   Int_t pixelHeight = gPad->YtoPixel(0)-gPad->YtoPixel(fHeight);
   for (Int_t pi=0;pi<pixelHeight&&fIs3D==kTRUE; ++pi) { // loop for pseudo-3d effect
      for (Int_t i=0;i<fNvals;++i) {
         // draw the arc
         // set the color of the next slice
         if (pi>0) {
            arc->SetFillStyle(0);
            arc->SetLineColor(TColor::GetColorDark((fPieSlices[i]->GetFillColor())));
         } else {
            arc->SetFillStyle(0);
            if (optionLine==kTRUE) {
               arc->SetLineColor(fPieSlices[i]->GetLineColor());
               arc->SetLineStyle(fPieSlices[i]->GetLineStyle());
               arc->SetLineWidth(fPieSlices[i]->GetLineWidth());
            } else {
               arc->SetLineWidth(0);
               arc->SetLineColor(TColor::GetColorDark((fPieSlices[i]->GetFillColor())));
            }
         }
         // Paint the slice
         Float_t aphi = fSlices[2*i+1]*TMath::Pi()/180.;

         Double_t ax = fX+TMath::Cos(aphi)*fPieSlices[i]->GetRadiusOffset();
         Double_t ay = fY+TMath::Sin(aphi)*fPieSlices[i]->GetRadiusOffset()*radXY+gPad->PixeltoY(pixelHeight-pi);

         arc->PaintEllipse(ax, ay, radX, radY, fSlices[2*i],
                                               fSlices[2*i+2], 0.);

         if (optionLine==kTRUE) {
            line->SetLineColor(fPieSlices[i]->GetLineColor());
            line->SetLineStyle(fPieSlices[i]->GetLineStyle());
            line->SetLineWidth(fPieSlices[i]->GetLineWidth());
            line->PaintLine(ax,ay,ax,ay);

            Double_t x0, y0;
            x0 = ax+radX*TMath::Cos(fSlices[2*i]/180.*TMath::Pi());
            y0 = ay+radY*TMath::Sin(fSlices[2*i]/180.*TMath::Pi());
            line->PaintLine(x0,y0,x0,y0);

            x0 = ax+radX*TMath::Cos(fSlices[2*i+2]/180.*TMath::Pi());
            y0 = ay+radY*TMath::Sin(fSlices[2*i+2]/180.*TMath::Pi());
            line->PaintLine(x0,y0,x0,y0);
         }
      }
   } // end loop for pseudo-3d effect

   for (Int_t i=0;i<fNvals;++i) { // loop for the piechart
      // Set the color of the next slice
      arc->SetFillColor(fPieSlices[i]->GetFillColor());
      arc->SetFillStyle(fPieSlices[i]->GetFillStyle());
      if (optionLine==kTRUE) {
         arc->SetLineColor(fPieSlices[i]->GetLineColor());
         arc->SetLineStyle(fPieSlices[i]->GetLineStyle());
         arc->SetLineWidth(fPieSlices[i]->GetLineWidth());
      } else {
         arc->SetLineWidth(0);
         arc->SetLineColor(fPieSlices[i]->GetFillColor());
      }

      // Paint the slice
      Float_t aphi = fSlices[2*i+1]*TMath::Pi()/180.;

      Double_t ax = fX+TMath::Cos(aphi)*fPieSlices[i]->GetRadiusOffset();
      Double_t ay = fY+TMath::Sin(aphi)*fPieSlices[i]->GetRadiusOffset()*radXY;
      arc->PaintEllipse(ax, ay, radX, radY, fSlices[2*i],
                                            fSlices[2*i+2], 0.);

   } // end loop to draw the slices


   // Set the font
   textlabel->SetTextFont(GetTextFont());
   textlabel->SetTextSize(GetTextSize());
   textlabel->SetTextColor(GetTextColor());

   // Loop to place the labels.
   for (Int_t i=0;i<fNvals;++i) {
      Float_t aphi = fSlices[2*i+1]*TMath::Pi()/180.;
      //aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));

      Float_t label_off = fLabelsOffset;


      // Paint the text in the pad
      TString tmptxt  = fLabelFormat;

      tmptxt.ReplaceAll("%txt",fPieSlices[i]->GetTitle());
      tmptxt.ReplaceAll("%val",Form(fValueFormat.Data(),fPieSlices[i]->GetValue()));
      tmptxt.ReplaceAll("%frac",Form(fFractionFormat.Data(),fPieSlices[i]->GetValue()/fSum));
      tmptxt.ReplaceAll("%perc",Form("%3.1f %s",(fPieSlices[i]->GetValue()/fSum)*100,"%"));

      textlabel->SetTitle(tmptxt.Data());
      Double_t h = textlabel->GetYsize();
      Double_t w = textlabel->GetXsize();

      Float_t lx = fX+(fRadius+fPieSlices[i]->GetRadiusOffset()+label_off)*TMath::Cos(aphi);
      Float_t ly = fY+(fRadius+fPieSlices[i]->GetRadiusOffset()+label_off)*TMath::Sin(aphi)*radXY;

      Double_t lblang = 0;

      if (lblor==1) { // radial direction for the label
         aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
         lblang += aphi;
         if (lblang<=0) lblang += TMath::TwoPi();
         if (lblang>TMath::TwoPi()) lblang-= TMath::TwoPi();

         lx += h/2.*TMath::Sin(lblang);
         ly -= h/2.*TMath::Cos(lblang);

         // This control prevent text up-side
         if (lblang>TMath::PiOver2() && lblang<=3.*TMath::PiOver2()) {
            lx     += w*TMath::Cos(lblang)-h*TMath::Sin(lblang);
            ly     += w*TMath::Sin(lblang)+h*TMath::Cos(lblang);
            lblang -= TMath::Pi();
         }
      } else if (lblor==2) { // tangential direction of the labels
         aphi -=TMath::PiOver2();
         aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
         lblang += aphi;//-TMath::PiOver2();
         if (lblang<0) lblang+=TMath::TwoPi();

         lx -= w/2.*TMath::Cos(lblang);
         ly -= w/2.*TMath::Sin(lblang);

         if (lblang>TMath::PiOver2() && lblang<3.*TMath::PiOver2()) {
            lx     += w*TMath::Cos(lblang)-h*TMath::Sin(lblang);
            ly     += w*TMath::Sin(lblang)+h*TMath::Cos(lblang);
            lblang -= TMath::Pi();
         }
      } else { // horizontal labels (default direction)
         aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
         if (aphi>TMath::PiOver2() || aphi<=-TMath::PiOver2()) lx -= w;
         if (aphi<0)                                           ly -= h;
      }

      Float_t rphi = TMath::ATan2((ly-fY)*radXY,lx-fX);
      if (rphi < 0 && fIs3D && label_off>=0.)
         ly -= fHeight;

      if (optionSameColor) textlabel->SetTextColor((fPieSlices[i]->GetFillColor()));
      textlabel->PaintLatex(lx,ly,
                            lblang*180/TMath::Pi()+GetTextAngle(),
                            GetTextSize(), tmptxt.Data());
   }

   delete arc;
   delete line;
   delete textlabel;

   if (optionSame) return;

   // Draw title
   TPaveText *title = 0;
   TObject *obj;
   if ((obj = gPad->GetListOfPrimitives()->FindObject("title"))) {
      title = dynamic_cast<TPaveText*>(obj);
   }

   // Check the OptTitle option
   if (strlen(GetTitle()) == 0 || gStyle->GetOptTitle() <= 0) {
      if (title) delete title;
      return;
   }

   // Height and width of the title
   Double_t ht = gStyle->GetTitleH();
   Double_t wt = gStyle->GetTitleW();
   if (ht<=0) ht = 1.1*gStyle->GetTitleFontSize();
   if (ht<=0) ht = 0.05; // minum height
   if (wt<=0) { // eval the width of the title
      TLatex l;
      l.SetTextSize(ht);
      l.SetTitle(GetTitle());
      // adjustment in case the title has several lines (#splitline)
      ht = TMath::Max(ht, 1.2*l.GetYsize()/(gPad->GetY2() - gPad->GetY1()));
      Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
      wt = TMath::Min(0.7, 0.02+wndc);
   }

   if (title) {
      TText *t0 = (TText*)title->GetLine(0);
      if (t0) {
         if (!strcmp(t0->GetTitle(),GetTitle())) return;
         t0->SetTitle(GetTitle());
         if (wt > 0) title->SetX2NDC(title->GetX1NDC()+wt);
      }
      return;
   }

   Int_t talh = gStyle->GetTitleAlign()/10;
   if (talh < 1) talh = 1; if (talh > 3) talh = 3;
   Int_t talv = gStyle->GetTitleAlign()%10;
   if (talv < 1) talv = 1; if (talv > 3) talv = 3;
   Double_t xpos, ypos;
   xpos = gStyle->GetTitleX();
   ypos = gStyle->GetTitleY();
   if (talh == 2) xpos = xpos-wt/2.;
   if (talh == 3) xpos = xpos-wt;
   if (talv == 2) ypos = ypos+ht/2.;
   if (talv == 1) ypos = ypos+ht;

   title = new TPaveText(xpos,ypos-ht,xpos+wt,ypos,"blNDC");
   title->SetFillColor(gStyle->GetTitleFillColor());
   title->SetFillStyle(gStyle->GetTitleStyle());
   title->SetName("title");

   title->SetBorderSize(gStyle->GetTitleBorderSize());
   title->SetTextColor(gStyle->GetTitleTextColor());
   title->SetTextFont(gStyle->GetTitleFont(""));
   if (gStyle->GetTitleFont("")%10 > 2)
      title->SetTextSize(gStyle->GetTitleFontSize());
   title->AddText(GetTitle());

   title->SetBit(kCanDelete);

   title->Draw();
   title->Paint();
}


//______________________________________________________________________________
void TPie::SavePrimitive(std::ostream &out, Option_t *option)
{
   // Save primitive as a C++ statement(s) on output stream out

   out << "   " << std::endl;
   if (gROOT->ClassSaved(TPie::Class())) {
      out << "   ";
   } else {
      out << "   TPie *";
   }
   out << GetName() << " = new TPie(\"" << GetName() << "\", \"" << GetTitle()
       << "\", " << fNvals << ");" << std::endl;
   out << "   " << GetName() << "->SetCircle(" << fX << ", " << fY << ", "
       << fRadius << ");" << std::endl;
   out << "   " << GetName() << "->SetValueFormat(\"" << GetValueFormat()
       << "\");" << std::endl;
   out << "   " << GetName() << "->SetLabelFormat(\"" << GetLabelFormat()
       << "\");" << std::endl;
   out << "   " << GetName() << "->SetPercentFormat(\"" << GetPercentFormat()
       << "\");" << std::endl;
   out << "   " << GetName() << "->SetLabelsOffset(" << GetLabelsOffset()
       << ");" << std::endl;
   out << "   " << GetName() << "->SetAngularOffset(" << GetAngularOffset()
       << ");" << std::endl;
   out << "   " << GetName() << "->SetTextAngle(" << GetTextAngle() << ");" << std::endl;
   out << "   " << GetName() << "->SetTextColor(" << GetTextColor() << ");" << std::endl;
   out << "   " << GetName() << "->SetTextFont(" << GetTextFont() << ");" << std::endl;
   out << "   " << GetName() << "->SetTextSize(" << GetTextSize() << ");" << std::endl;


   // Save the values for the slices
   for (Int_t i=0;i<fNvals;++i) {
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetTitle(\""
          << fPieSlices[i]->GetTitle() << "\");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetValue("
          << fPieSlices[i]->GetValue() << ");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetRadiusOffset("
          << fPieSlices[i]->GetRadiusOffset() << ");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetFillColor("
          << fPieSlices[i]->GetFillColor() << ");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetFillStyle("
          << fPieSlices[i]->GetFillStyle() << ");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetLineColor("
          << fPieSlices[i]->GetLineColor() << ");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetLineStyle("
          << fPieSlices[i]->GetLineStyle() << ");" << std::endl;
      out << "   " << GetName() << "->GetSlice(" << i << ")->SetLineWidth("
          << fPieSlices[i]->GetLineWidth() << ");" << std::endl;
   }

   out << "   " << GetName() << "->Draw(\"" << option << "\");" << std::endl;
}



//______________________________________________________________________________
void TPie::SetAngle3D(Float_t val) {
   // Set the value of for the pseudo 3D view angle, in degree.
   // The range of the permitted values is: [0,90]

   // check if val is in the permitted range
   while (val>360.) val -= 360.;
   while (val<0)    val += 360.;
   if      (val>=90 && val<180)   val = 180-val;
   else if (val>=180 && val<=360) val = 360-val;

   fAngle3D = val;
}


//______________________________________________________________________________
void TPie::SetAngularOffset(Double_t offset)
{
   // Set the global angular offset for slices in degree [0,360]

   fAngularOffset = offset;

   while (fAngularOffset>=360.) fAngularOffset -= 360.;
   while (fAngularOffset<0.)    fAngularOffset += 360.;

   MakeSlices(kTRUE);
}


//______________________________________________________________________________
void TPie::SetCircle(Double_t x, Double_t y, Double_t rad)
{
   // Set the coordinates of the circle that describe the pie:
   // - the 1st and the 2nd arguments are the x and y center's coordinates.
   // - the 3rd value is the pie-chart's radius.
   //
   // All the coordinates are in NDC space.

   fX      = x;
   fY      = y;
   fRadius = rad;
}


//______________________________________________________________________________
void TPie::SetEntryLabel(Int_t i, const char *text)
{
   // Set slice number "i" label. The first parameter is the index of the slice,
   // the other is the label text.

   // Set the Label of a single slice
   if (i>=0 && i<fNvals) fPieSlices[i]->SetTitle(text);
}


//______________________________________________________________________________
void TPie::SetEntryLineColor(Int_t i, Int_t color)
{
   // Set the color for the slice's outline. "i" is the slice number.

   if (i>=0 && i<fNvals) fPieSlices[i]->SetLineColor(color);
}


//______________________________________________________________________________
void TPie::SetEntryLineStyle(Int_t i, Int_t style)
{
   // Set the style for the slice's outline. "i" is the slice number.

   if (i>=0 && i<fNvals) fPieSlices[i]->SetLineStyle(style);
}


//______________________________________________________________________________
void TPie::SetEntryLineWidth(Int_t i, Int_t width)
{
   // Set the width of the slice's outline. "i" is the slice number.

   if (i>=0 && i<fNvals) fPieSlices[i]->SetLineWidth(width);
}


//______________________________________________________________________________
void TPie::SetEntryFillColor(Int_t i, Int_t color)
{
   // Set the color for the slice "i".

   if (i>=0 && i<fNvals) fPieSlices[i]->SetFillColor(color);
}


//______________________________________________________________________________
void TPie::SetEntryFillStyle(Int_t i, Int_t style)
{
   // Set the fill style for the "i" slice

   if (i>=0 && i<fNvals) fPieSlices[i]->SetFillStyle(style);
}


//______________________________________________________________________________
void TPie::SetEntryRadiusOffset(Int_t i, Double_t shift)
{
   // Set the distance, in the direction of the radius of the slice.

   if (i>=0 && i<fNvals) fPieSlices[i]->SetRadiusOffset(shift);
}


//______________________________________________________________________________
void TPie::SetEntryVal(Int_t i, Double_t val)
{
   // Set the value of a slice

   if (i>=0 && i<fNvals) fPieSlices[i]->SetValue(val);

   MakeSlices(kTRUE);
}


//______________________________________________________________________________
void TPie::SetFillColors(Int_t *colors)
{
   // Set the fill colors for all the TPie's slices.

   if (!colors) return;
   for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->SetFillColor(colors[i]);
}


//______________________________________________________________________________
void TPie::SetHeight(Double_t val/*=20*/)
{
   // Set the height, in pixel, for the piechart if is drawn using
   // the pseudo-3d mode.
   //
   // The default value is 20 pixel.

   fHeight = val;
}


//______________________________________________________________________________
void TPie::SetLabelFormat(const char *fmt)
{
   // This method is used to customize the label format. The format string
   // must contain one of these modifiers:
   //
   // - %txt  : to print the text label associated with the slice
   // - %val  : to print the numeric value of the slice
   // - %frac : to print the relative fraction of this slice
   // - %perc : to print the % of this slice
   //
   // ex. : mypie->SetLabelFormat("%txt (%frac)");

   fLabelFormat = fmt;
}


//______________________________________________________________________________
void TPie::SetFractionFormat(const char *fmt)
{
   // Set numeric format in the label, is used if the label format
   // there is the modifier %frac, in this case the value is printed
   // using this format.
   //
   // The numeric format use the standard C modifier used in stdio library:
   // %f, %2.1$, %e... for further documentation you can use the printf
   // mapage ("man 3 printf" on linux)
   //
   // ex. : mypie->SetLabelFormat("%txt (%frac)");
   //       mypie->SetFractionFormat("2.1f");

   fFractionFormat = fmt;
}


//______________________________________________________________________________
void TPie::SetLabels(const char *lbls[])
{
   // Set the labels for all the slices.

   if (!lbls) return;
   for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->SetTitle(lbls[i]);
}


//______________________________________________________________________________
void TPie::SetLabelsOffset(Float_t labelsoffset)
{
   // Set the distance between the label end the external line of the TPie.

   fLabelsOffset = labelsoffset;
}


//______________________________________________________________________________
void TPie::SetPercentFormat(const char *fmt)
{
   // Set the numeric format for the percent value of a slice, default: %3.1f

   fPercentFormat = fmt;
}


//______________________________________________________________________________
void TPie::SetRadius(Double_t rad)
{
   // Set the pie chart's radius' value.

   if (rad>0) {
      fRadius = rad;
   } else {
      Warning("SetRadius",
              "It's not possible set the radius to a negative value");
   }
}


//______________________________________________________________________________
void TPie::SetValueFormat(const char *fmt)
{
   // Set the numeric format the slices' values.
   // Used by %val (see SetLabelFormat()).

   fValueFormat = fmt;
}


//______________________________________________________________________________
void TPie::SetX(Double_t x)
{
   // Set X value.

   fX = x;
}


//______________________________________________________________________________
void TPie::SetY(Double_t y)
{
   // Set Y value.

   fY = y;
}


//______________________________________________________________________________
void TPie::MakeSlices(Bool_t force)
{
   // Make the slices.
   // If they already exist it does nothing unless force=kTRUE.

   if (fSlices && !force) return;

   fSum = .0;

   for (Int_t i=0;i<fNvals;++i) {
      if (fPieSlices[i]->GetValue()<0) {
         Warning("MakeSlices",
                 "Negative values in TPie, absolute value will be used");
         fPieSlices[i]->SetValue(-1.*fPieSlices[i]->GetValue());
      }
      fSum += fPieSlices[i]->GetValue();
   }

   if (fSum<=.0) return;

   if (!fSlices) fSlices = new Float_t[2*fNvals+1];

   // Compute the slices size and position (2 angles for each slice)
   fSlices[0] = fAngularOffset;
   for (Int_t i=0;i<fNvals;++i) {
      Float_t dphi   = fPieSlices[i]->GetValue()/fSum*360.;
      fSlices[2*i+1] = fSlices[2*i]+dphi/2.;
      fSlices[2*i+2] = fSlices[2*i]+dphi;
   }
}


//______________________________________________________________________________
void TPie::SortSlices(Bool_t amode, Float_t merge_threshold)
{
   // This method, mainly intended for internal use, ordered the  slices accoording their values.
   // The default (amode=kTRUE) is inscreasing order, but is also possible in decreasing order (amode=kFALSE).
   //
   // If the merge_thresold>0 the slice that contains a quantity smaller than merge_thresold are merged
   // togheter


   // main loop to order, bubble sort, the array
   Bool_t isDone = kFALSE;

   while (isDone==kFALSE) {
      isDone = kTRUE;

      for (Int_t i=0;i<fNvals-1;++i) { // loop over the values
         if ( (amode && (fPieSlices[i]->GetValue()>fPieSlices[i+1]->GetValue())) ||
              (!amode && (fPieSlices[i]->GetValue()<fPieSlices[i+1]->GetValue()))
            )
         {
            // exchange the order
            TPieSlice *tmpcpy = fPieSlices[i];
            fPieSlices[i] = fPieSlices[i+1];
            fPieSlices[i+1] = tmpcpy;

            isDone = kFALSE;
         }
      }  // end loop the values
   } // end main ordering loop

   if (merge_threshold>0) {
      // merge smallest slices
      TPieSlice *merged_slice = new TPieSlice("merged","other",this);
      merged_slice->SetRadiusOffset(0.);
      merged_slice->SetLineColor(1);
      merged_slice->SetLineStyle(1);
      merged_slice->SetLineWidth(1);
      merged_slice->SetFillColor(gStyle->GetColorPalette( (amode ? 0 : fNvals-1) ));
      merged_slice->SetFillStyle(1001);

      if (amode) {
         // search slices under the threshold
         Int_t iMerged = 0;
         for (;iMerged<fNvals&&fPieSlices[iMerged]->GetValue()<merge_threshold;++iMerged) {
            merged_slice->SetValue( merged_slice->GetValue()+fPieSlices[iMerged]->GetValue() );
         }

         // evaluate number of valid slices
         if (iMerged<=1) { // no slices to merge
            delete merged_slice;
         }
         else { // write a new array with the right dimension
            Int_t old_fNvals = fNvals;
            fNvals = fNvals-iMerged+1;
            TPieSlice **new_array = new TPieSlice*[fNvals];
            new_array[0] = merged_slice;
            for (Int_t i=0;i<old_fNvals;++i) {
               if (i<iMerged) delete fPieSlices[i];
               else new_array[i-iMerged+1] = fPieSlices[i];
            }
            delete [] fPieSlices;
            fPieSlices = new_array;
         }
      }
      else {
         Int_t iMerged = fNvals-1;
         for (;iMerged>=0&&fPieSlices[iMerged]->GetValue()<merge_threshold;--iMerged) {
            merged_slice->SetValue( merged_slice->GetValue()+fPieSlices[iMerged]->GetValue() );
         }

         // evaluate number of valid slices
         Int_t nMerged = fNvals-1-iMerged;
         if (nMerged<=1) { // no slices to merge
            delete merged_slice;
         }
         else { // write a new array with the right dimension
            Int_t old_fNvals = fNvals;
            fNvals = fNvals-nMerged+1;
            TPieSlice **new_array = new TPieSlice*[fNvals];
            new_array[fNvals-1] = merged_slice;
            for (Int_t i=old_fNvals-1;i>=0;--i) {
               if (i>iMerged) delete fPieSlices[i];
               else new_array[i-nMerged-1] = fPieSlices[i];
            }
            delete [] fPieSlices;
            fPieSlices = new_array;
         }

      }
   }

   MakeSlices(kTRUE);
}

 TPie.cxx:1
 TPie.cxx:2
 TPie.cxx:3
 TPie.cxx:4
 TPie.cxx:5
 TPie.cxx:6
 TPie.cxx:7
 TPie.cxx:8
 TPie.cxx:9
 TPie.cxx:10
 TPie.cxx:11
 TPie.cxx:12
 TPie.cxx:13
 TPie.cxx:14
 TPie.cxx:15
 TPie.cxx:16
 TPie.cxx:17
 TPie.cxx:18
 TPie.cxx:19
 TPie.cxx:20
 TPie.cxx:21
 TPie.cxx:22
 TPie.cxx:23
 TPie.cxx:24
 TPie.cxx:25
 TPie.cxx:26
 TPie.cxx:27
 TPie.cxx:28
 TPie.cxx:29
 TPie.cxx:30
 TPie.cxx:31
 TPie.cxx:32
 TPie.cxx:33
 TPie.cxx:34
 TPie.cxx:35
 TPie.cxx:36
 TPie.cxx:37
 TPie.cxx:38
 TPie.cxx:39
 TPie.cxx:40
 TPie.cxx:41
 TPie.cxx:42
 TPie.cxx:43
 TPie.cxx:44
 TPie.cxx:45
 TPie.cxx:46
 TPie.cxx:47
 TPie.cxx:48
 TPie.cxx:49
 TPie.cxx:50
 TPie.cxx:51
 TPie.cxx:52
 TPie.cxx:53
 TPie.cxx:54
 TPie.cxx:55
 TPie.cxx:56
 TPie.cxx:57
 TPie.cxx:58
 TPie.cxx:59
 TPie.cxx:60
 TPie.cxx:61
 TPie.cxx:62
 TPie.cxx:63
 TPie.cxx:64
 TPie.cxx:65
 TPie.cxx:66
 TPie.cxx:67
 TPie.cxx:68
 TPie.cxx:69
 TPie.cxx:70
 TPie.cxx:71
 TPie.cxx:72
 TPie.cxx:73
 TPie.cxx:74
 TPie.cxx:75
 TPie.cxx:76
 TPie.cxx:77
 TPie.cxx:78
 TPie.cxx:79
 TPie.cxx:80
 TPie.cxx:81
 TPie.cxx:82
 TPie.cxx:83
 TPie.cxx:84
 TPie.cxx:85
 TPie.cxx:86
 TPie.cxx:87
 TPie.cxx:88
 TPie.cxx:89
 TPie.cxx:90
 TPie.cxx:91
 TPie.cxx:92
 TPie.cxx:93
 TPie.cxx:94
 TPie.cxx:95
 TPie.cxx:96
 TPie.cxx:97
 TPie.cxx:98
 TPie.cxx:99
 TPie.cxx:100
 TPie.cxx:101
 TPie.cxx:102
 TPie.cxx:103
 TPie.cxx:104
 TPie.cxx:105
 TPie.cxx:106
 TPie.cxx:107
 TPie.cxx:108
 TPie.cxx:109
 TPie.cxx:110
 TPie.cxx:111
 TPie.cxx:112
 TPie.cxx:113
 TPie.cxx:114
 TPie.cxx:115
 TPie.cxx:116
 TPie.cxx:117
 TPie.cxx:118
 TPie.cxx:119
 TPie.cxx:120
 TPie.cxx:121
 TPie.cxx:122
 TPie.cxx:123
 TPie.cxx:124
 TPie.cxx:125
 TPie.cxx:126
 TPie.cxx:127
 TPie.cxx:128
 TPie.cxx:129
 TPie.cxx:130
 TPie.cxx:131
 TPie.cxx:132
 TPie.cxx:133
 TPie.cxx:134
 TPie.cxx:135
 TPie.cxx:136
 TPie.cxx:137
 TPie.cxx:138
 TPie.cxx:139
 TPie.cxx:140
 TPie.cxx:141
 TPie.cxx:142
 TPie.cxx:143
 TPie.cxx:144
 TPie.cxx:145
 TPie.cxx:146
 TPie.cxx:147
 TPie.cxx:148
 TPie.cxx:149
 TPie.cxx:150
 TPie.cxx:151
 TPie.cxx:152
 TPie.cxx:153
 TPie.cxx:154
 TPie.cxx:155
 TPie.cxx:156
 TPie.cxx:157
 TPie.cxx:158
 TPie.cxx:159
 TPie.cxx:160
 TPie.cxx:161
 TPie.cxx:162
 TPie.cxx:163
 TPie.cxx:164
 TPie.cxx:165
 TPie.cxx:166
 TPie.cxx:167
 TPie.cxx:168
 TPie.cxx:169
 TPie.cxx:170
 TPie.cxx:171
 TPie.cxx:172
 TPie.cxx:173
 TPie.cxx:174
 TPie.cxx:175
 TPie.cxx:176
 TPie.cxx:177
 TPie.cxx:178
 TPie.cxx:179
 TPie.cxx:180
 TPie.cxx:181
 TPie.cxx:182
 TPie.cxx:183
 TPie.cxx:184
 TPie.cxx:185
 TPie.cxx:186
 TPie.cxx:187
 TPie.cxx:188
 TPie.cxx:189
 TPie.cxx:190
 TPie.cxx:191
 TPie.cxx:192
 TPie.cxx:193
 TPie.cxx:194
 TPie.cxx:195
 TPie.cxx:196
 TPie.cxx:197
 TPie.cxx:198
 TPie.cxx:199
 TPie.cxx:200
 TPie.cxx:201
 TPie.cxx:202
 TPie.cxx:203
 TPie.cxx:204
 TPie.cxx:205
 TPie.cxx:206
 TPie.cxx:207
 TPie.cxx:208
 TPie.cxx:209
 TPie.cxx:210
 TPie.cxx:211
 TPie.cxx:212
 TPie.cxx:213
 TPie.cxx:214
 TPie.cxx:215
 TPie.cxx:216
 TPie.cxx:217
 TPie.cxx:218
 TPie.cxx:219
 TPie.cxx:220
 TPie.cxx:221
 TPie.cxx:222
 TPie.cxx:223
 TPie.cxx:224
 TPie.cxx:225
 TPie.cxx:226
 TPie.cxx:227
 TPie.cxx:228
 TPie.cxx:229
 TPie.cxx:230
 TPie.cxx:231
 TPie.cxx:232
 TPie.cxx:233
 TPie.cxx:234
 TPie.cxx:235
 TPie.cxx:236
 TPie.cxx:237
 TPie.cxx:238
 TPie.cxx:239
 TPie.cxx:240
 TPie.cxx:241
 TPie.cxx:242
 TPie.cxx:243
 TPie.cxx:244
 TPie.cxx:245
 TPie.cxx:246
 TPie.cxx:247
 TPie.cxx:248
 TPie.cxx:249
 TPie.cxx:250
 TPie.cxx:251
 TPie.cxx:252
 TPie.cxx:253
 TPie.cxx:254
 TPie.cxx:255
 TPie.cxx:256
 TPie.cxx:257
 TPie.cxx:258
 TPie.cxx:259
 TPie.cxx:260
 TPie.cxx:261
 TPie.cxx:262
 TPie.cxx:263
 TPie.cxx:264
 TPie.cxx:265
 TPie.cxx:266
 TPie.cxx:267
 TPie.cxx:268
 TPie.cxx:269
 TPie.cxx:270
 TPie.cxx:271
 TPie.cxx:272
 TPie.cxx:273
 TPie.cxx:274
 TPie.cxx:275
 TPie.cxx:276
 TPie.cxx:277
 TPie.cxx:278
 TPie.cxx:279
 TPie.cxx:280
 TPie.cxx:281
 TPie.cxx:282
 TPie.cxx:283
 TPie.cxx:284
 TPie.cxx:285
 TPie.cxx:286
 TPie.cxx:287
 TPie.cxx:288
 TPie.cxx:289
 TPie.cxx:290
 TPie.cxx:291
 TPie.cxx:292
 TPie.cxx:293
 TPie.cxx:294
 TPie.cxx:295
 TPie.cxx:296
 TPie.cxx:297
 TPie.cxx:298
 TPie.cxx:299
 TPie.cxx:300
 TPie.cxx:301
 TPie.cxx:302
 TPie.cxx:303
 TPie.cxx:304
 TPie.cxx:305
 TPie.cxx:306
 TPie.cxx:307
 TPie.cxx:308
 TPie.cxx:309
 TPie.cxx:310
 TPie.cxx:311
 TPie.cxx:312
 TPie.cxx:313
 TPie.cxx:314
 TPie.cxx:315
 TPie.cxx:316
 TPie.cxx:317
 TPie.cxx:318
 TPie.cxx:319
 TPie.cxx:320
 TPie.cxx:321
 TPie.cxx:322
 TPie.cxx:323
 TPie.cxx:324
 TPie.cxx:325
 TPie.cxx:326
 TPie.cxx:327
 TPie.cxx:328
 TPie.cxx:329
 TPie.cxx:330
 TPie.cxx:331
 TPie.cxx:332
 TPie.cxx:333
 TPie.cxx:334
 TPie.cxx:335
 TPie.cxx:336
 TPie.cxx:337
 TPie.cxx:338
 TPie.cxx:339
 TPie.cxx:340
 TPie.cxx:341
 TPie.cxx:342
 TPie.cxx:343
 TPie.cxx:344
 TPie.cxx:345
 TPie.cxx:346
 TPie.cxx:347
 TPie.cxx:348
 TPie.cxx:349
 TPie.cxx:350
 TPie.cxx:351
 TPie.cxx:352
 TPie.cxx:353
 TPie.cxx:354
 TPie.cxx:355
 TPie.cxx:356
 TPie.cxx:357
 TPie.cxx:358
 TPie.cxx:359
 TPie.cxx:360
 TPie.cxx:361
 TPie.cxx:362
 TPie.cxx:363
 TPie.cxx:364
 TPie.cxx:365
 TPie.cxx:366
 TPie.cxx:367
 TPie.cxx:368
 TPie.cxx:369
 TPie.cxx:370
 TPie.cxx:371
 TPie.cxx:372
 TPie.cxx:373
 TPie.cxx:374
 TPie.cxx:375
 TPie.cxx:376
 TPie.cxx:377
 TPie.cxx:378
 TPie.cxx:379
 TPie.cxx:380
 TPie.cxx:381
 TPie.cxx:382
 TPie.cxx:383
 TPie.cxx:384
 TPie.cxx:385
 TPie.cxx:386
 TPie.cxx:387
 TPie.cxx:388
 TPie.cxx:389
 TPie.cxx:390
 TPie.cxx:391
 TPie.cxx:392
 TPie.cxx:393
 TPie.cxx:394
 TPie.cxx:395
 TPie.cxx:396
 TPie.cxx:397
 TPie.cxx:398
 TPie.cxx:399
 TPie.cxx:400
 TPie.cxx:401
 TPie.cxx:402
 TPie.cxx:403
 TPie.cxx:404
 TPie.cxx:405
 TPie.cxx:406
 TPie.cxx:407
 TPie.cxx:408
 TPie.cxx:409
 TPie.cxx:410
 TPie.cxx:411
 TPie.cxx:412
 TPie.cxx:413
 TPie.cxx:414
 TPie.cxx:415
 TPie.cxx:416
 TPie.cxx:417
 TPie.cxx:418
 TPie.cxx:419
 TPie.cxx:420
 TPie.cxx:421
 TPie.cxx:422
 TPie.cxx:423
 TPie.cxx:424
 TPie.cxx:425
 TPie.cxx:426
 TPie.cxx:427
 TPie.cxx:428
 TPie.cxx:429
 TPie.cxx:430
 TPie.cxx:431
 TPie.cxx:432
 TPie.cxx:433
 TPie.cxx:434
 TPie.cxx:435
 TPie.cxx:436
 TPie.cxx:437
 TPie.cxx:438
 TPie.cxx:439
 TPie.cxx:440
 TPie.cxx:441
 TPie.cxx:442
 TPie.cxx:443
 TPie.cxx:444
 TPie.cxx:445
 TPie.cxx:446
 TPie.cxx:447
 TPie.cxx:448
 TPie.cxx:449
 TPie.cxx:450
 TPie.cxx:451
 TPie.cxx:452
 TPie.cxx:453
 TPie.cxx:454
 TPie.cxx:455
 TPie.cxx:456
 TPie.cxx:457
 TPie.cxx:458
 TPie.cxx:459
 TPie.cxx:460
 TPie.cxx:461
 TPie.cxx:462
 TPie.cxx:463
 TPie.cxx:464
 TPie.cxx:465
 TPie.cxx:466
 TPie.cxx:467
 TPie.cxx:468
 TPie.cxx:469
 TPie.cxx:470
 TPie.cxx:471
 TPie.cxx:472
 TPie.cxx:473
 TPie.cxx:474
 TPie.cxx:475
 TPie.cxx:476
 TPie.cxx:477
 TPie.cxx:478
 TPie.cxx:479
 TPie.cxx:480
 TPie.cxx:481
 TPie.cxx:482
 TPie.cxx:483
 TPie.cxx:484
 TPie.cxx:485
 TPie.cxx:486
 TPie.cxx:487
 TPie.cxx:488
 TPie.cxx:489
 TPie.cxx:490
 TPie.cxx:491
 TPie.cxx:492
 TPie.cxx:493
 TPie.cxx:494
 TPie.cxx:495
 TPie.cxx:496
 TPie.cxx:497
 TPie.cxx:498
 TPie.cxx:499
 TPie.cxx:500
 TPie.cxx:501
 TPie.cxx:502
 TPie.cxx:503
 TPie.cxx:504
 TPie.cxx:505
 TPie.cxx:506
 TPie.cxx:507
 TPie.cxx:508
 TPie.cxx:509
 TPie.cxx:510
 TPie.cxx:511
 TPie.cxx:512
 TPie.cxx:513
 TPie.cxx:514
 TPie.cxx:515
 TPie.cxx:516
 TPie.cxx:517
 TPie.cxx:518
 TPie.cxx:519
 TPie.cxx:520
 TPie.cxx:521
 TPie.cxx:522
 TPie.cxx:523
 TPie.cxx:524
 TPie.cxx:525
 TPie.cxx:526
 TPie.cxx:527
 TPie.cxx:528
 TPie.cxx:529
 TPie.cxx:530
 TPie.cxx:531
 TPie.cxx:532
 TPie.cxx:533
 TPie.cxx:534
 TPie.cxx:535
 TPie.cxx:536
 TPie.cxx:537
 TPie.cxx:538
 TPie.cxx:539
 TPie.cxx:540
 TPie.cxx:541
 TPie.cxx:542
 TPie.cxx:543
 TPie.cxx:544
 TPie.cxx:545
 TPie.cxx:546
 TPie.cxx:547
 TPie.cxx:548
 TPie.cxx:549
 TPie.cxx:550
 TPie.cxx:551
 TPie.cxx:552
 TPie.cxx:553
 TPie.cxx:554
 TPie.cxx:555
 TPie.cxx:556
 TPie.cxx:557
 TPie.cxx:558
 TPie.cxx:559
 TPie.cxx:560
 TPie.cxx:561
 TPie.cxx:562
 TPie.cxx:563
 TPie.cxx:564
 TPie.cxx:565
 TPie.cxx:566
 TPie.cxx:567
 TPie.cxx:568
 TPie.cxx:569
 TPie.cxx:570
 TPie.cxx:571
 TPie.cxx:572
 TPie.cxx:573
 TPie.cxx:574
 TPie.cxx:575
 TPie.cxx:576
 TPie.cxx:577
 TPie.cxx:578
 TPie.cxx:579
 TPie.cxx:580
 TPie.cxx:581
 TPie.cxx:582
 TPie.cxx:583
 TPie.cxx:584
 TPie.cxx:585
 TPie.cxx:586
 TPie.cxx:587
 TPie.cxx:588
 TPie.cxx:589
 TPie.cxx:590
 TPie.cxx:591
 TPie.cxx:592
 TPie.cxx:593
 TPie.cxx:594
 TPie.cxx:595
 TPie.cxx:596
 TPie.cxx:597
 TPie.cxx:598
 TPie.cxx:599
 TPie.cxx:600
 TPie.cxx:601
 TPie.cxx:602
 TPie.cxx:603
 TPie.cxx:604
 TPie.cxx:605
 TPie.cxx:606
 TPie.cxx:607
 TPie.cxx:608
 TPie.cxx:609
 TPie.cxx:610
 TPie.cxx:611
 TPie.cxx:612
 TPie.cxx:613
 TPie.cxx:614
 TPie.cxx:615
 TPie.cxx:616
 TPie.cxx:617
 TPie.cxx:618
 TPie.cxx:619
 TPie.cxx:620
 TPie.cxx:621
 TPie.cxx:622
 TPie.cxx:623
 TPie.cxx:624
 TPie.cxx:625
 TPie.cxx:626
 TPie.cxx:627
 TPie.cxx:628
 TPie.cxx:629
 TPie.cxx:630
 TPie.cxx:631
 TPie.cxx:632
 TPie.cxx:633
 TPie.cxx:634
 TPie.cxx:635
 TPie.cxx:636
 TPie.cxx:637
 TPie.cxx:638
 TPie.cxx:639
 TPie.cxx:640
 TPie.cxx:641
 TPie.cxx:642
 TPie.cxx:643
 TPie.cxx:644
 TPie.cxx:645
 TPie.cxx:646
 TPie.cxx:647
 TPie.cxx:648
 TPie.cxx:649
 TPie.cxx:650
 TPie.cxx:651
 TPie.cxx:652
 TPie.cxx:653
 TPie.cxx:654
 TPie.cxx:655
 TPie.cxx:656
 TPie.cxx:657
 TPie.cxx:658
 TPie.cxx:659
 TPie.cxx:660
 TPie.cxx:661
 TPie.cxx:662
 TPie.cxx:663
 TPie.cxx:664
 TPie.cxx:665
 TPie.cxx:666
 TPie.cxx:667
 TPie.cxx:668
 TPie.cxx:669
 TPie.cxx:670
 TPie.cxx:671
 TPie.cxx:672
 TPie.cxx:673
 TPie.cxx:674
 TPie.cxx:675
 TPie.cxx:676
 TPie.cxx:677
 TPie.cxx:678
 TPie.cxx:679
 TPie.cxx:680
 TPie.cxx:681
 TPie.cxx:682
 TPie.cxx:683
 TPie.cxx:684
 TPie.cxx:685
 TPie.cxx:686
 TPie.cxx:687
 TPie.cxx:688
 TPie.cxx:689
 TPie.cxx:690
 TPie.cxx:691
 TPie.cxx:692
 TPie.cxx:693
 TPie.cxx:694
 TPie.cxx:695
 TPie.cxx:696
 TPie.cxx:697
 TPie.cxx:698
 TPie.cxx:699
 TPie.cxx:700
 TPie.cxx:701
 TPie.cxx:702
 TPie.cxx:703
 TPie.cxx:704
 TPie.cxx:705
 TPie.cxx:706
 TPie.cxx:707
 TPie.cxx:708
 TPie.cxx:709
 TPie.cxx:710
 TPie.cxx:711
 TPie.cxx:712
 TPie.cxx:713
 TPie.cxx:714
 TPie.cxx:715
 TPie.cxx:716
 TPie.cxx:717
 TPie.cxx:718
 TPie.cxx:719
 TPie.cxx:720
 TPie.cxx:721
 TPie.cxx:722
 TPie.cxx:723
 TPie.cxx:724
 TPie.cxx:725
 TPie.cxx:726
 TPie.cxx:727
 TPie.cxx:728
 TPie.cxx:729
 TPie.cxx:730
 TPie.cxx:731
 TPie.cxx:732
 TPie.cxx:733
 TPie.cxx:734
 TPie.cxx:735
 TPie.cxx:736
 TPie.cxx:737
 TPie.cxx:738
 TPie.cxx:739
 TPie.cxx:740
 TPie.cxx:741
 TPie.cxx:742
 TPie.cxx:743
 TPie.cxx:744
 TPie.cxx:745
 TPie.cxx:746
 TPie.cxx:747
 TPie.cxx:748
 TPie.cxx:749
 TPie.cxx:750
 TPie.cxx:751
 TPie.cxx:752
 TPie.cxx:753
 TPie.cxx:754
 TPie.cxx:755
 TPie.cxx:756
 TPie.cxx:757
 TPie.cxx:758
 TPie.cxx:759
 TPie.cxx:760
 TPie.cxx:761
 TPie.cxx:762
 TPie.cxx:763
 TPie.cxx:764
 TPie.cxx:765
 TPie.cxx:766
 TPie.cxx:767
 TPie.cxx:768
 TPie.cxx:769
 TPie.cxx:770
 TPie.cxx:771
 TPie.cxx:772
 TPie.cxx:773
 TPie.cxx:774
 TPie.cxx:775
 TPie.cxx:776
 TPie.cxx:777
 TPie.cxx:778
 TPie.cxx:779
 TPie.cxx:780
 TPie.cxx:781
 TPie.cxx:782
 TPie.cxx:783
 TPie.cxx:784
 TPie.cxx:785
 TPie.cxx:786
 TPie.cxx:787
 TPie.cxx:788
 TPie.cxx:789
 TPie.cxx:790
 TPie.cxx:791
 TPie.cxx:792
 TPie.cxx:793
 TPie.cxx:794
 TPie.cxx:795
 TPie.cxx:796
 TPie.cxx:797
 TPie.cxx:798
 TPie.cxx:799
 TPie.cxx:800
 TPie.cxx:801
 TPie.cxx:802
 TPie.cxx:803
 TPie.cxx:804
 TPie.cxx:805
 TPie.cxx:806
 TPie.cxx:807
 TPie.cxx:808
 TPie.cxx:809
 TPie.cxx:810
 TPie.cxx:811
 TPie.cxx:812
 TPie.cxx:813
 TPie.cxx:814
 TPie.cxx:815
 TPie.cxx:816
 TPie.cxx:817
 TPie.cxx:818
 TPie.cxx:819
 TPie.cxx:820
 TPie.cxx:821
 TPie.cxx:822
 TPie.cxx:823
 TPie.cxx:824
 TPie.cxx:825
 TPie.cxx:826
 TPie.cxx:827
 TPie.cxx:828
 TPie.cxx:829
 TPie.cxx:830
 TPie.cxx:831
 TPie.cxx:832
 TPie.cxx:833
 TPie.cxx:834
 TPie.cxx:835
 TPie.cxx:836
 TPie.cxx:837
 TPie.cxx:838
 TPie.cxx:839
 TPie.cxx:840
 TPie.cxx:841
 TPie.cxx:842
 TPie.cxx:843
 TPie.cxx:844
 TPie.cxx:845
 TPie.cxx:846
 TPie.cxx:847
 TPie.cxx:848
 TPie.cxx:849
 TPie.cxx:850
 TPie.cxx:851
 TPie.cxx:852
 TPie.cxx:853
 TPie.cxx:854
 TPie.cxx:855
 TPie.cxx:856
 TPie.cxx:857
 TPie.cxx:858
 TPie.cxx:859
 TPie.cxx:860
 TPie.cxx:861
 TPie.cxx:862
 TPie.cxx:863
 TPie.cxx:864
 TPie.cxx:865
 TPie.cxx:866
 TPie.cxx:867
 TPie.cxx:868
 TPie.cxx:869
 TPie.cxx:870
 TPie.cxx:871
 TPie.cxx:872
 TPie.cxx:873
 TPie.cxx:874
 TPie.cxx:875
 TPie.cxx:876
 TPie.cxx:877
 TPie.cxx:878
 TPie.cxx:879
 TPie.cxx:880
 TPie.cxx:881
 TPie.cxx:882
 TPie.cxx:883
 TPie.cxx:884
 TPie.cxx:885
 TPie.cxx:886
 TPie.cxx:887
 TPie.cxx:888
 TPie.cxx:889
 TPie.cxx:890
 TPie.cxx:891
 TPie.cxx:892
 TPie.cxx:893
 TPie.cxx:894
 TPie.cxx:895
 TPie.cxx:896
 TPie.cxx:897
 TPie.cxx:898
 TPie.cxx:899
 TPie.cxx:900
 TPie.cxx:901
 TPie.cxx:902
 TPie.cxx:903
 TPie.cxx:904
 TPie.cxx:905
 TPie.cxx:906
 TPie.cxx:907
 TPie.cxx:908
 TPie.cxx:909
 TPie.cxx:910
 TPie.cxx:911
 TPie.cxx:912
 TPie.cxx:913
 TPie.cxx:914
 TPie.cxx:915
 TPie.cxx:916
 TPie.cxx:917
 TPie.cxx:918
 TPie.cxx:919
 TPie.cxx:920
 TPie.cxx:921
 TPie.cxx:922
 TPie.cxx:923
 TPie.cxx:924
 TPie.cxx:925
 TPie.cxx:926
 TPie.cxx:927
 TPie.cxx:928
 TPie.cxx:929
 TPie.cxx:930
 TPie.cxx:931
 TPie.cxx:932
 TPie.cxx:933
 TPie.cxx:934
 TPie.cxx:935
 TPie.cxx:936
 TPie.cxx:937
 TPie.cxx:938
 TPie.cxx:939
 TPie.cxx:940
 TPie.cxx:941
 TPie.cxx:942
 TPie.cxx:943
 TPie.cxx:944
 TPie.cxx:945
 TPie.cxx:946
 TPie.cxx:947
 TPie.cxx:948
 TPie.cxx:949
 TPie.cxx:950
 TPie.cxx:951
 TPie.cxx:952
 TPie.cxx:953
 TPie.cxx:954
 TPie.cxx:955
 TPie.cxx:956
 TPie.cxx:957
 TPie.cxx:958
 TPie.cxx:959
 TPie.cxx:960
 TPie.cxx:961
 TPie.cxx:962
 TPie.cxx:963
 TPie.cxx:964
 TPie.cxx:965
 TPie.cxx:966
 TPie.cxx:967
 TPie.cxx:968
 TPie.cxx:969
 TPie.cxx:970
 TPie.cxx:971
 TPie.cxx:972
 TPie.cxx:973
 TPie.cxx:974
 TPie.cxx:975
 TPie.cxx:976
 TPie.cxx:977
 TPie.cxx:978
 TPie.cxx:979
 TPie.cxx:980
 TPie.cxx:981
 TPie.cxx:982
 TPie.cxx:983
 TPie.cxx:984
 TPie.cxx:985
 TPie.cxx:986
 TPie.cxx:987
 TPie.cxx:988
 TPie.cxx:989
 TPie.cxx:990
 TPie.cxx:991
 TPie.cxx:992
 TPie.cxx:993
 TPie.cxx:994
 TPie.cxx:995
 TPie.cxx:996
 TPie.cxx:997
 TPie.cxx:998
 TPie.cxx:999
 TPie.cxx:1000
 TPie.cxx:1001
 TPie.cxx:1002
 TPie.cxx:1003
 TPie.cxx:1004
 TPie.cxx:1005
 TPie.cxx:1006
 TPie.cxx:1007
 TPie.cxx:1008
 TPie.cxx:1009
 TPie.cxx:1010
 TPie.cxx:1011
 TPie.cxx:1012
 TPie.cxx:1013
 TPie.cxx:1014
 TPie.cxx:1015
 TPie.cxx:1016
 TPie.cxx:1017
 TPie.cxx:1018
 TPie.cxx:1019
 TPie.cxx:1020
 TPie.cxx:1021
 TPie.cxx:1022
 TPie.cxx:1023
 TPie.cxx:1024
 TPie.cxx:1025
 TPie.cxx:1026
 TPie.cxx:1027
 TPie.cxx:1028
 TPie.cxx:1029
 TPie.cxx:1030
 TPie.cxx:1031
 TPie.cxx:1032
 TPie.cxx:1033
 TPie.cxx:1034
 TPie.cxx:1035
 TPie.cxx:1036
 TPie.cxx:1037
 TPie.cxx:1038
 TPie.cxx:1039
 TPie.cxx:1040
 TPie.cxx:1041
 TPie.cxx:1042
 TPie.cxx:1043
 TPie.cxx:1044
 TPie.cxx:1045
 TPie.cxx:1046
 TPie.cxx:1047
 TPie.cxx:1048
 TPie.cxx:1049
 TPie.cxx:1050
 TPie.cxx:1051
 TPie.cxx:1052
 TPie.cxx:1053
 TPie.cxx:1054
 TPie.cxx:1055
 TPie.cxx:1056
 TPie.cxx:1057
 TPie.cxx:1058
 TPie.cxx:1059
 TPie.cxx:1060
 TPie.cxx:1061
 TPie.cxx:1062
 TPie.cxx:1063
 TPie.cxx:1064
 TPie.cxx:1065
 TPie.cxx:1066
 TPie.cxx:1067
 TPie.cxx:1068
 TPie.cxx:1069
 TPie.cxx:1070
 TPie.cxx:1071
 TPie.cxx:1072
 TPie.cxx:1073
 TPie.cxx:1074
 TPie.cxx:1075
 TPie.cxx:1076
 TPie.cxx:1077
 TPie.cxx:1078
 TPie.cxx:1079
 TPie.cxx:1080
 TPie.cxx:1081
 TPie.cxx:1082
 TPie.cxx:1083
 TPie.cxx:1084
 TPie.cxx:1085
 TPie.cxx:1086
 TPie.cxx:1087
 TPie.cxx:1088
 TPie.cxx:1089
 TPie.cxx:1090
 TPie.cxx:1091
 TPie.cxx:1092
 TPie.cxx:1093
 TPie.cxx:1094
 TPie.cxx:1095
 TPie.cxx:1096
 TPie.cxx:1097
 TPie.cxx:1098
 TPie.cxx:1099
 TPie.cxx:1100
 TPie.cxx:1101
 TPie.cxx:1102
 TPie.cxx:1103
 TPie.cxx:1104
 TPie.cxx:1105
 TPie.cxx:1106
 TPie.cxx:1107
 TPie.cxx:1108
 TPie.cxx:1109
 TPie.cxx:1110
 TPie.cxx:1111
 TPie.cxx:1112
 TPie.cxx:1113
 TPie.cxx:1114
 TPie.cxx:1115
 TPie.cxx:1116
 TPie.cxx:1117
 TPie.cxx:1118
 TPie.cxx:1119
 TPie.cxx:1120
 TPie.cxx:1121
 TPie.cxx:1122
 TPie.cxx:1123
 TPie.cxx:1124
 TPie.cxx:1125
 TPie.cxx:1126
 TPie.cxx:1127
 TPie.cxx:1128
 TPie.cxx:1129
 TPie.cxx:1130
 TPie.cxx:1131
 TPie.cxx:1132
 TPie.cxx:1133
 TPie.cxx:1134
 TPie.cxx:1135
 TPie.cxx:1136
 TPie.cxx:1137
 TPie.cxx:1138
 TPie.cxx:1139
 TPie.cxx:1140
 TPie.cxx:1141
 TPie.cxx:1142
 TPie.cxx:1143
 TPie.cxx:1144
 TPie.cxx:1145
 TPie.cxx:1146
 TPie.cxx:1147
 TPie.cxx:1148
 TPie.cxx:1149
 TPie.cxx:1150
 TPie.cxx:1151
 TPie.cxx:1152
 TPie.cxx:1153
 TPie.cxx:1154
 TPie.cxx:1155
 TPie.cxx:1156
 TPie.cxx:1157
 TPie.cxx:1158
 TPie.cxx:1159
 TPie.cxx:1160
 TPie.cxx:1161
 TPie.cxx:1162
 TPie.cxx:1163
 TPie.cxx:1164
 TPie.cxx:1165
 TPie.cxx:1166
 TPie.cxx:1167
 TPie.cxx:1168
 TPie.cxx:1169
 TPie.cxx:1170
 TPie.cxx:1171
 TPie.cxx:1172
 TPie.cxx:1173
 TPie.cxx:1174
 TPie.cxx:1175
 TPie.cxx:1176
 TPie.cxx:1177
 TPie.cxx:1178
 TPie.cxx:1179
 TPie.cxx:1180
 TPie.cxx:1181
 TPie.cxx:1182
 TPie.cxx:1183
 TPie.cxx:1184
 TPie.cxx:1185
 TPie.cxx:1186
 TPie.cxx:1187
 TPie.cxx:1188
 TPie.cxx:1189
 TPie.cxx:1190
 TPie.cxx:1191
 TPie.cxx:1192
 TPie.cxx:1193
 TPie.cxx:1194
 TPie.cxx:1195
 TPie.cxx:1196
 TPie.cxx:1197
 TPie.cxx:1198
 TPie.cxx:1199
 TPie.cxx:1200
 TPie.cxx:1201
 TPie.cxx:1202
 TPie.cxx:1203
 TPie.cxx:1204
 TPie.cxx:1205
 TPie.cxx:1206
 TPie.cxx:1207
 TPie.cxx:1208
 TPie.cxx:1209
 TPie.cxx:1210
 TPie.cxx:1211
 TPie.cxx:1212
 TPie.cxx:1213
 TPie.cxx:1214
 TPie.cxx:1215
 TPie.cxx:1216
 TPie.cxx:1217
 TPie.cxx:1218
 TPie.cxx:1219
 TPie.cxx:1220
 TPie.cxx:1221
 TPie.cxx:1222
 TPie.cxx:1223
 TPie.cxx:1224
 TPie.cxx:1225
 TPie.cxx:1226
 TPie.cxx:1227
 TPie.cxx:1228
 TPie.cxx:1229
 TPie.cxx:1230
 TPie.cxx:1231
 TPie.cxx:1232
 TPie.cxx:1233
 TPie.cxx:1234
 TPie.cxx:1235
 TPie.cxx:1236
 TPie.cxx:1237
 TPie.cxx:1238
 TPie.cxx:1239
 TPie.cxx:1240
 TPie.cxx:1241
 TPie.cxx:1242
 TPie.cxx:1243
 TPie.cxx:1244
 TPie.cxx:1245
 TPie.cxx:1246
 TPie.cxx:1247
 TPie.cxx:1248
 TPie.cxx:1249
 TPie.cxx:1250
 TPie.cxx:1251
 TPie.cxx:1252
 TPie.cxx:1253
 TPie.cxx:1254
 TPie.cxx:1255
 TPie.cxx:1256
 TPie.cxx:1257
 TPie.cxx:1258
 TPie.cxx:1259
 TPie.cxx:1260
 TPie.cxx:1261
 TPie.cxx:1262
 TPie.cxx:1263
 TPie.cxx:1264
 TPie.cxx:1265
 TPie.cxx:1266
 TPie.cxx:1267
 TPie.cxx:1268
 TPie.cxx:1269
 TPie.cxx:1270
 TPie.cxx:1271
 TPie.cxx:1272
 TPie.cxx:1273
 TPie.cxx:1274
 TPie.cxx:1275
 TPie.cxx:1276
 TPie.cxx:1277
 TPie.cxx:1278
 TPie.cxx:1279
 TPie.cxx:1280
 TPie.cxx:1281
 TPie.cxx:1282
 TPie.cxx:1283
 TPie.cxx:1284
 TPie.cxx:1285
 TPie.cxx:1286
 TPie.cxx:1287
 TPie.cxx:1288
 TPie.cxx:1289
 TPie.cxx:1290
 TPie.cxx:1291
 TPie.cxx:1292
 TPie.cxx:1293
 TPie.cxx:1294
 TPie.cxx:1295
 TPie.cxx:1296
 TPie.cxx:1297
 TPie.cxx:1298
 TPie.cxx:1299
 TPie.cxx:1300
 TPie.cxx:1301
 TPie.cxx:1302
 TPie.cxx:1303
 TPie.cxx:1304
 TPie.cxx:1305
 TPie.cxx:1306
 TPie.cxx:1307
 TPie.cxx:1308
 TPie.cxx:1309
 TPie.cxx:1310
 TPie.cxx:1311
 TPie.cxx:1312
 TPie.cxx:1313
 TPie.cxx:1314
 TPie.cxx:1315
 TPie.cxx:1316
 TPie.cxx:1317
 TPie.cxx:1318
 TPie.cxx:1319
 TPie.cxx:1320
 TPie.cxx:1321
 TPie.cxx:1322
 TPie.cxx:1323
 TPie.cxx:1324
 TPie.cxx:1325
 TPie.cxx:1326
 TPie.cxx:1327
 TPie.cxx:1328
 TPie.cxx:1329
 TPie.cxx:1330
 TPie.cxx:1331
 TPie.cxx:1332
 TPie.cxx:1333
 TPie.cxx:1334
 TPie.cxx:1335
 TPie.cxx:1336
 TPie.cxx:1337
 TPie.cxx:1338
 TPie.cxx:1339
 TPie.cxx:1340
 TPie.cxx:1341
 TPie.cxx:1342
 TPie.cxx:1343
 TPie.cxx:1344
 TPie.cxx:1345
 TPie.cxx:1346
 TPie.cxx:1347
 TPie.cxx:1348
 TPie.cxx:1349
 TPie.cxx:1350
 TPie.cxx:1351
 TPie.cxx:1352
 TPie.cxx:1353
 TPie.cxx:1354
 TPie.cxx:1355
 TPie.cxx:1356
 TPie.cxx:1357
 TPie.cxx:1358
 TPie.cxx:1359
 TPie.cxx:1360
 TPie.cxx:1361
 TPie.cxx:1362
 TPie.cxx:1363
 TPie.cxx:1364
 TPie.cxx:1365
 TPie.cxx:1366
 TPie.cxx:1367
 TPie.cxx:1368
 TPie.cxx:1369
 TPie.cxx:1370
 TPie.cxx:1371
 TPie.cxx:1372
 TPie.cxx:1373
 TPie.cxx:1374
 TPie.cxx:1375
 TPie.cxx:1376
 TPie.cxx:1377
 TPie.cxx:1378
 TPie.cxx:1379
 TPie.cxx:1380
 TPie.cxx:1381
 TPie.cxx:1382
 TPie.cxx:1383
 TPie.cxx:1384
 TPie.cxx:1385
 TPie.cxx:1386
 TPie.cxx:1387
 TPie.cxx:1388
 TPie.cxx:1389
 TPie.cxx:1390
 TPie.cxx:1391
 TPie.cxx:1392
 TPie.cxx:1393
 TPie.cxx:1394
 TPie.cxx:1395
 TPie.cxx:1396
 TPie.cxx:1397
 TPie.cxx:1398
 TPie.cxx:1399
 TPie.cxx:1400
 TPie.cxx:1401
 TPie.cxx:1402
 TPie.cxx:1403
 TPie.cxx:1404
 TPie.cxx:1405
 TPie.cxx:1406
 TPie.cxx:1407
 TPie.cxx:1408
 TPie.cxx:1409
 TPie.cxx:1410
 TPie.cxx:1411
 TPie.cxx:1412
 TPie.cxx:1413
 TPie.cxx:1414
 TPie.cxx:1415
 TPie.cxx:1416
 TPie.cxx:1417
 TPie.cxx:1418
 TPie.cxx:1419
 TPie.cxx:1420
 TPie.cxx:1421
 TPie.cxx:1422
 TPie.cxx:1423
 TPie.cxx:1424
 TPie.cxx:1425
 TPie.cxx:1426
 TPie.cxx:1427
 TPie.cxx:1428
 TPie.cxx:1429
 TPie.cxx:1430
 TPie.cxx:1431
 TPie.cxx:1432
 TPie.cxx:1433
 TPie.cxx:1434
 TPie.cxx:1435
 TPie.cxx:1436
 TPie.cxx:1437
 TPie.cxx:1438
 TPie.cxx:1439
 TPie.cxx:1440
 TPie.cxx:1441
 TPie.cxx:1442
 TPie.cxx:1443
 TPie.cxx:1444
 TPie.cxx:1445
 TPie.cxx:1446
 TPie.cxx:1447
 TPie.cxx:1448
 TPie.cxx:1449
 TPie.cxx:1450
 TPie.cxx:1451
 TPie.cxx:1452
 TPie.cxx:1453
 TPie.cxx:1454
 TPie.cxx:1455
 TPie.cxx:1456
 TPie.cxx:1457
 TPie.cxx:1458
 TPie.cxx:1459
 TPie.cxx:1460
 TPie.cxx:1461
 TPie.cxx:1462
 TPie.cxx:1463
 TPie.cxx:1464
 TPie.cxx:1465
 TPie.cxx:1466
 TPie.cxx:1467
 TPie.cxx:1468
 TPie.cxx:1469
 TPie.cxx:1470
 TPie.cxx:1471
 TPie.cxx:1472
 TPie.cxx:1473
 TPie.cxx:1474
 TPie.cxx:1475
 TPie.cxx:1476
 TPie.cxx:1477
 TPie.cxx:1478
 TPie.cxx:1479
 TPie.cxx:1480
 TPie.cxx:1481
 TPie.cxx:1482
 TPie.cxx:1483
 TPie.cxx:1484
 TPie.cxx:1485
 TPie.cxx:1486
 TPie.cxx:1487
 TPie.cxx:1488
 TPie.cxx:1489
 TPie.cxx:1490
 TPie.cxx:1491
 TPie.cxx:1492
 TPie.cxx:1493
 TPie.cxx:1494
 TPie.cxx:1495
 TPie.cxx:1496
 TPie.cxx:1497
 TPie.cxx:1498
 TPie.cxx:1499
 TPie.cxx:1500
 TPie.cxx:1501
 TPie.cxx:1502
 TPie.cxx:1503
 TPie.cxx:1504
 TPie.cxx:1505
 TPie.cxx:1506
 TPie.cxx:1507
 TPie.cxx:1508
 TPie.cxx:1509
 TPie.cxx:1510
 TPie.cxx:1511
 TPie.cxx:1512
 TPie.cxx:1513
 TPie.cxx:1514
 TPie.cxx:1515
 TPie.cxx:1516
 TPie.cxx:1517
 TPie.cxx:1518
 TPie.cxx:1519
 TPie.cxx:1520
 TPie.cxx:1521
 TPie.cxx:1522
 TPie.cxx:1523
 TPie.cxx:1524
 TPie.cxx:1525
 TPie.cxx:1526
 TPie.cxx:1527
 TPie.cxx:1528
 TPie.cxx:1529
 TPie.cxx:1530
 TPie.cxx:1531
 TPie.cxx:1532
 TPie.cxx:1533
 TPie.cxx:1534
 TPie.cxx:1535
 TPie.cxx:1536
 TPie.cxx:1537
 TPie.cxx:1538
 TPie.cxx:1539
 TPie.cxx:1540
 TPie.cxx:1541
 TPie.cxx:1542
 TPie.cxx:1543
 TPie.cxx:1544
 TPie.cxx:1545
 TPie.cxx:1546
 TPie.cxx:1547
 TPie.cxx:1548
 TPie.cxx:1549
 TPie.cxx:1550
 TPie.cxx:1551
 TPie.cxx:1552
 TPie.cxx:1553
 TPie.cxx:1554
 TPie.cxx:1555
 TPie.cxx:1556
 TPie.cxx:1557
 TPie.cxx:1558
 TPie.cxx:1559
 TPie.cxx:1560
 TPie.cxx:1561
 TPie.cxx:1562
 TPie.cxx:1563
 TPie.cxx:1564
 TPie.cxx:1565
 TPie.cxx:1566
 TPie.cxx:1567
 TPie.cxx:1568
 TPie.cxx:1569
 TPie.cxx:1570
 TPie.cxx:1571
 TPie.cxx:1572
 TPie.cxx:1573
 TPie.cxx:1574
 TPie.cxx:1575