// @(#)root/hist:$Id$
// Author: Rene Brun   27/10/95

/*************************************************************************
 * 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.             *
 *************************************************************************/
// ---------------------------------- F3.h

#ifndef ROOT_TF3
#define ROOT_TF3



//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TF3                                                                  //
//                                                                      //
// The Parametric 3-D function                                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TF2
#include "TF2.h"
#endif

class TF3 : public TF2 {

protected:
   Double_t  fZmin;        //Lower bound for the range in z
   Double_t  fZmax;        //Upper bound for the range in z
   Int_t     fNpz;         //Number of points along z used for the graphical representation

public:
   TF3();
   TF3(const char *name, const char *formula, Double_t xmin=0, Double_t xmax=1, Double_t ymin=0,
       Double_t ymax=1, Double_t zmin=0, Double_t zmax=1);
#ifndef __CINT__
   TF3(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0,
       Double_t ymax=1, Double_t zmin=0, Double_t zmax=1, Int_t npar=0);
   TF3(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0,
       Double_t ymax=1, Double_t zmin=0, Double_t zmax=1, Int_t npar=0);
#endif

   // constructor using a functor
   TF3(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin = 0, Double_t xmax = 1, Double_t ymin = 0, Double_t ymax = 1, Double_t zmin=0, Double_t zmax=1, Int_t npar = 0);

   // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
   // MemFn.
   template <class PtrObj, typename MemFn>
   TF3(const char *name, const  PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar, const char * c1, const char * c2) :
      TF2(name,p,memFn,xmin,xmax,ymin,ymax,npar,c1,c2),
      fZmin(zmin), fZmax(zmax), fNpz(30)
   {
      fNdim = 3;
   }
   // Template constructors from any  C++ callable object,  defining  the operator() (double * , double *)
   // and returning a double.
   template <typename Func>
   TF3(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar, const char * c1  ) :
      TF2(name,f,xmin,xmax,ymin,ymax,npar,c1),
      fZmin(zmin), fZmax(zmax), fNpz(30)
   {
      fNdim = 3;
   }

   TF3(const TF3 &f3);
   TF3& operator=(const TF3 &rhs);
   virtual   ~TF3();
   virtual void     Copy(TObject &f3) const;
   virtual Int_t    DistancetoPrimitive(Int_t px, Int_t py);
   virtual void     Draw(Option_t *option="");
   virtual TObject *DrawDerivative(Option_t * ="al") {return 0;}
   virtual TObject *DrawIntegral(Option_t * ="al")   {return 0;}
   virtual void     ExecuteEvent(Int_t event, Int_t px, Int_t py);
   virtual Double_t GetMinimumXYZ(Double_t &x, Double_t &y, Double_t &z);
   virtual Double_t GetMaximumXYZ(Double_t &x, Double_t &y, Double_t &z);
          Int_t     GetNpz() const {return fNpz;}
   virtual void     GetRandom3(Double_t &xrandom, Double_t &yrandom, Double_t &zrandom);
   using TF1::GetRange;
   virtual void     GetRange(Double_t &xmin, Double_t &xmax) const;
   virtual void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const ;
   virtual void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
   virtual Double_t GetSave(const Double_t *x);
   virtual Double_t GetZmin() const {return fZmin;}
   virtual Double_t GetZmax() const {return fZmax;}
   using TF2::Integral;
   virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsrel=1.e-6);
   virtual Bool_t   IsInside(const Double_t *x) const;
   virtual TH1     *CreateHistogram();
   virtual void     Paint(Option_t *option="");
   virtual void     Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax);
   virtual void     SavePrimitive(std::ostream &out, Option_t *option = "");
   virtual void     SetClippingBoxOff(); // *MENU*
   virtual void     SetClippingBoxOn(Double_t xclip=0, Double_t yclip=0, Double_t zclip=0); // *MENU*
   virtual void     SetNpz(Int_t npz=30);
   virtual void     SetRange(Double_t xmin, Double_t xmax);
   virtual void     SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax);
   virtual void     SetRange(Double_t xmin, Double_t ymin, Double_t zmin, Double_t xmax, Double_t ymax, Double_t zmax); // *MENU*

   //Moments
   virtual Double_t Moment3(Double_t nx, Double_t ax, Double_t bx, Double_t ny, Double_t ay, Double_t by, Double_t nz, Double_t az, Double_t bz, Double_t epsilon=0.000001);
   virtual Double_t CentralMoment3(Double_t nx, Double_t ax, Double_t bx, Double_t ny, Double_t ay, Double_t by, Double_t nz, Double_t az, Double_t bz, Double_t epsilon=0.000001);

   virtual Double_t Mean3X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return Moment3(1,ax,bx,0,ay,by,0,az,bz,epsilon);}
   virtual Double_t Mean3Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return Moment3(0,ax,bx,1,ay,by,0,az,bz,epsilon);}
   virtual Double_t Mean3Z(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return Moment3(0,ax,bx,0,ay,by,1,az,bz,epsilon);}

   virtual Double_t Variance3X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return CentralMoment3(2,ax,bx,0,ay,by,0,az,bz,epsilon);}
   virtual Double_t Variance3Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return CentralMoment3(0,ax,bx,2,ay,by,0,az,bz,epsilon);}
   virtual Double_t Variance3Z(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return CentralMoment3(0,ax,bx,0,ay,by,2,az,bz,epsilon);}

   virtual Double_t Covariance3XY(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return CentralMoment3(1,ax,bx,1,ay,by,0,az,bz,epsilon);}
   virtual Double_t Covariance3XZ(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return CentralMoment3(1,ax,bx,0,ay,by,1,az,bz,epsilon);}
   virtual Double_t Covariance3YZ(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=0.000001) {return CentralMoment3(0,ax,bx,1,ay,by,1,az,bz,epsilon);}

protected:

   virtual Double_t FindMinMax(Double_t* x, bool findmax) const;

   ClassDef(TF3,3)  //The Parametric 3-D function
};

inline void TF3::GetRange(Double_t &xmin, Double_t &xmax) const
   { TF2::GetRange(xmin, xmax); }
inline void TF3::GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
   { TF2::GetRange(xmin, ymin, xmax, ymax); }
inline void TF3::SetRange(Double_t xmin, Double_t xmax)
   { TF2::SetRange(xmin, xmax); }
inline void TF3::SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
   { TF2::SetRange(xmin, ymin, xmax, ymax); }

#endif
 TF3.h:1
 TF3.h:2
 TF3.h:3
 TF3.h:4
 TF3.h:5
 TF3.h:6
 TF3.h:7
 TF3.h:8
 TF3.h:9
 TF3.h:10
 TF3.h:11
 TF3.h:12
 TF3.h:13
 TF3.h:14
 TF3.h:15
 TF3.h:16
 TF3.h:17
 TF3.h:18
 TF3.h:19
 TF3.h:20
 TF3.h:21
 TF3.h:22
 TF3.h:23
 TF3.h:24
 TF3.h:25
 TF3.h:26
 TF3.h:27
 TF3.h:28
 TF3.h:29
 TF3.h:30
 TF3.h:31
 TF3.h:32
 TF3.h:33
 TF3.h:34
 TF3.h:35
 TF3.h:36
 TF3.h:37
 TF3.h:38
 TF3.h:39
 TF3.h:40
 TF3.h:41
 TF3.h:42
 TF3.h:43
 TF3.h:44
 TF3.h:45
 TF3.h:46
 TF3.h:47
 TF3.h:48
 TF3.h:49
 TF3.h:50
 TF3.h:51
 TF3.h:52
 TF3.h:53
 TF3.h:54
 TF3.h:55
 TF3.h:56
 TF3.h:57
 TF3.h:58
 TF3.h:59
 TF3.h:60
 TF3.h:61
 TF3.h:62
 TF3.h:63
 TF3.h:64
 TF3.h:65
 TF3.h:66
 TF3.h:67
 TF3.h:68
 TF3.h:69
 TF3.h:70
 TF3.h:71
 TF3.h:72
 TF3.h:73
 TF3.h:74
 TF3.h:75
 TF3.h:76
 TF3.h:77
 TF3.h:78
 TF3.h:79
 TF3.h:80
 TF3.h:81
 TF3.h:82
 TF3.h:83
 TF3.h:84
 TF3.h:85
 TF3.h:86
 TF3.h:87
 TF3.h:88
 TF3.h:89
 TF3.h:90
 TF3.h:91
 TF3.h:92
 TF3.h:93
 TF3.h:94
 TF3.h:95
 TF3.h:96
 TF3.h:97
 TF3.h:98
 TF3.h:99
 TF3.h:100
 TF3.h:101
 TF3.h:102
 TF3.h:103
 TF3.h:104
 TF3.h:105
 TF3.h:106
 TF3.h:107
 TF3.h:108
 TF3.h:109
 TF3.h:110
 TF3.h:111
 TF3.h:112
 TF3.h:113
 TF3.h:114
 TF3.h:115
 TF3.h:116
 TF3.h:117
 TF3.h:118
 TF3.h:119
 TF3.h:120
 TF3.h:121
 TF3.h:122
 TF3.h:123
 TF3.h:124
 TF3.h:125
 TF3.h:126
 TF3.h:127
 TF3.h:128
 TF3.h:129
 TF3.h:130
 TF3.h:131
 TF3.h:132
 TF3.h:133
 TF3.h:134
 TF3.h:135
 TF3.h:136