Logo ROOT  
Reference Guide
TF3.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 27/10/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TROOT.h"
13#include "TF3.h"
14#include "TBuffer.h"
15#include "TMath.h"
16#include "TH3.h"
17#include "TVirtualPad.h"
18#include "TRandom.h"
19#include "TVectorD.h"
20#include "Riostream.h"
21#include "TColor.h"
22#include "TVirtualFitter.h"
23#include "TVirtualHistPainter.h"
25#include <cassert>
26
28
29/** \class TF3
30 \ingroup Functions
31A 3-Dim function with parameters
32*/
33
34////////////////////////////////////////////////////////////////////////////////
35/// F3 default constructor
36
38{
39 fNpz = 0;
40 fZmin = 0;
41 fZmax = 1;
42}
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// F3 constructor using a formula definition
47///
48/// See TFormula constructor for explanation of the formula syntax.
49
50TF3::TF3(const char *name,const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Option_t * opt)
51 :TF2(name,formula,xmin,xmax,ymax,ymin,opt)
52{
53 fZmin = zmin;
54 fZmax = zmax;
55 fNpz = 30;
56 Int_t ndim = GetNdim();
57 // accept 1-d or 2-d formula
58 if (ndim < 3) fNdim = 3;
59 if (ndim > 3 && xmin < xmax && ymin < ymax && zmin < zmax) {
60 Error("TF3","function: %s/%s has dimension %d instead of 3",name,formula,ndim);
61 MakeZombie();
62 }
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// F3 constructor using a pointer to real function
67///
68/// \param[in] name object name
69/// \param[in] fcn pointer to real function
70/// \param[in] xmin,xmax x axis limits
71/// \param[in] ymin,ymax y axis limits
72/// \param[in] zmin,zmax z axis limits
73/// \param[in] npar is the number of free parameters used by the function
74/// \param[in] ndim number of dimensions
75///
76/// For example, for a 3-dim function with 3 parameters, the user function
77/// looks like:
78///
79/// Double_t fun1(Double_t *x, Double_t *par)
80/// return par[0]*x[2] + par[1]*exp(par[2]*x[0]*x[1]);
81///
82/// \warning A function created with this constructor cannot be Cloned.
83
85 :TF2(name,fcn,xmin,xmax,ymin,ymax,npar,ndim)
86{
87 fZmin = zmin;
88 fZmax = zmax;
89 fNpz = 30;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// F3 constructor using a pointer to real function---
94///
95/// \param[in] name object name
96/// \param[in] fcn pointer to real function
97/// \param[in] xmin,xmax x axis limits
98/// \param[in] ymin,ymax y axis limits
99/// \param[in] zmin,zmax z axis limits
100/// \param[in] npar is the number of free parameters used by the function
101/// \param[in] ndim number of dimensions
102///
103/// For example, for a 3-dim function with 3 parameters, the user function
104/// looks like:
105///
106/// Double_t fun1(Double_t *x, Double_t *par)
107/// return par[0]*x[2] + par[1]*exp(par[2]*x[0]*x[1]);
108///
109/// WARNING! A function created with this constructor cannot be Cloned.
110
111TF3::TF3(const char *name,Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar, Int_t ndim)
112 : TF2(name,fcn,xmin,xmax,ymin,ymax,npar,ndim),
113 fZmin(zmin),
114 fZmax(zmax),
115 fNpz(30)
116{
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// F3 constructor using a ParamFunctor
121///
122/// a functor class implementing operator() (double *, double *)
123///
124/// \param[in] name object name
125/// \param[in] f parameter functor
126/// \param[in] xmin,xmax x axis limits
127/// \param[in] ymin,ymax y axis limits
128/// \param[in] zmin,zmax z axis limits
129/// \param[in] npar is the number of free parameters used by the function
130/// \param[in] ndim number of dimensions
131///
132/// \warning A function created with this constructor cannot be Cloned.
133
135 : TF2(name, f, xmin, xmax, ymin, ymax, npar, ndim),
136 fZmin(zmin),
137 fZmax(zmax),
138 fNpz(30)
139{
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Operator =
144
146{
147 if (this != &rhs)
148 rhs.TF3::Copy(*this);
149 return *this;
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// F3 default destructor
154
156{
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Copy constructor.
161
162TF3::TF3(const TF3 &f3) : TF2()
163{
164 f3.TF3::Copy(*this);
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Copy this F3 to a new F3
169
170void TF3::Copy(TObject &obj) const
171{
172 TF2::Copy(obj);
173 ((TF3&)obj).fZmin = fZmin;
174 ((TF3&)obj).fZmax = fZmax;
175 ((TF3&)obj).fNpz = fNpz;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Compute distance from point px,py to a function
180///
181/// Compute the closest distance of approach from point px,py to this function.
182/// The distance is computed in pixels units.
183
184
186{
187 return TF1::DistancetoPrimitive(px, py);
188
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Draw this function with its current attributes
193
195{
196 TString opt = option;
197 opt.ToLower();
198 if (gPad && !opt.Contains("same")) gPad->Clear();
199
201
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Execute action corresponding to one event
206///
207/// This member function is called when a F3 is clicked with the locator
208
210{
211 TF1::ExecuteEvent(event, px, py);
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Return minimum/maximum value of the function
216///
217/// To find the minimum on a range, first set this range via the SetRange function
218/// If a vector x of coordinate is passed it will be used as starting point for the minimum.
219/// In addition on exit x will contain the coordinate values at the minimuma
220/// If x is NULL or x is inifinity or NaN, first, a grid search is performed to find the initial estimate of the
221/// minimum location. The range of the function is divided into fNpx and fNpy
222/// sub-ranges. If the function is "good" (or "bad"), these values can be changed
223/// by SetNpx and SetNpy functions
224///
225/// Then, a minimization is used with starting values found by the grid search
226/// The minimizer algorithm used (by default Minuit) can be changed by callinga
227/// ROOT::Math::Minimizer::SetDefaultMinimizerType("..")
228/// Other option for the minimizer can be set using the static method of the MinimizerOptions class
229
231{
232 //First do a grid search with step size fNpx and fNpy
233
234 Double_t xx[3];
235 Double_t rsign = (findmax) ? -1. : 1.;
236 TF3 & function = const_cast<TF3&>(*this); // needed since EvalPar is not const
237 Double_t xxmin = 0, yymin = 0, zzmin = 0, ttmin = 0;
238 if (x == NULL || ( (x!= NULL) && ( !TMath::Finite(x[0]) || !TMath::Finite(x[1]) || !TMath::Finite(x[2]) ) ) ){
239 Double_t dx = (fXmax - fXmin)/fNpx;
240 Double_t dy = (fYmax - fYmin)/fNpy;
241 Double_t dz = (fZmax - fZmin)/fNpz;
242 xxmin = fXmin;
243 yymin = fYmin;
244 zzmin = fZmin;
245 ttmin = rsign * TMath::Infinity();
246 for (Int_t i=0; i<fNpx; i++){
247 xx[0]=fXmin + (i+0.5)*dx;
248 for (Int_t j=0; j<fNpy; j++){
249 xx[1]=fYmin+(j+0.5)*dy;
250 for (Int_t k=0; k<fNpz; k++){
251 xx[2] = fZmin+(k+0.5)*dz;
252 Double_t tt = function(xx);
253 if (rsign*tt < rsign*ttmin) {xxmin = xx[0], yymin = xx[1]; zzmin = xx[2]; ttmin=tt;}
254 }
255 }
256 }
257
258 xxmin = TMath::Min(fXmax, xxmin);
259 yymin = TMath::Min(fYmax, yymin);
260 zzmin = TMath::Min(fZmax, zzmin);
261 }
262 else {
263 xxmin = x[0];
264 yymin = x[1];
265 zzmin = x[2];
266 zzmin = function(x);
267 }
268 xx[0] = xxmin;
269 xx[1] = yymin;
270 xx[2] = zzmin;
271
272 double fmin = GetMinMaxNDim(xx,findmax);
273 if (rsign*fmin < rsign*zzmin) {
274 if (x) {x[0] = xx[0]; x[1] = xx[1]; x[2] = xx[2];}
275 return fmin;
276 }
277 // here if minimization failed
278 if (x) { x[0] = xxmin; x[1] = yymin; x[2] = zzmin; }
279 return ttmin;
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Compute the X, Y and Z values corresponding to the minimum value of the function
284/// on its range.
285///
286/// Returns the function value at the minimum.
287/// To find the minimum on a subrange, use the SetRange() function first.
288///
289/// Method:
290/// First, a grid search is performed to find the initial estimate of the
291/// minimum location. The range of the function is divided
292/// into fNpx,fNpy and fNpz sub-ranges. If the function is "good" (or "bad"),
293/// these values can be changed by SetNpx(), SetNpy() and SetNpz() functions.
294/// Then, Minuit minimization is used with starting values found by the grid search
295///
296/// Note that this method will always do first a grid search in contrast to GetMinimum
297
299{
300 double xx[3] = { 0,0,0 };
301 xx[0] = TMath::QuietNaN(); // to force to do grid search in TF3::FindMinMax
302 double fmin = FindMinMax(xx, false);
303 x = xx[0]; y = xx[1]; z = xx[2];
304 return fmin;
305
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Compute the X, Y and Z values corresponding to the maximum value of the function
310/// on its range.
311///
312/// Return the function value at the maximum. See TF3::GetMinimumXYZ
313
315{
316 double xx[3] = { 0,0,0 };
317 xx[0] = TMath::QuietNaN(); // to force to do grid search in TF3::FindMinMax
318 double fmax = FindMinMax(xx, true);
319 x = xx[0]; y = xx[1]; z = xx[2];
320 return fmax;
321
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Return 3 random numbers following this function shape
326///
327/// The distribution contained in this TF3 function is integrated
328/// over the cell contents.
329/// It is normalized to 1.
330/// Getting the three random numbers implies:
331/// - Generating a random number between 0 and 1 (say r1)
332/// - Look in which cell in the normalized integral r1 corresponds to
333/// - make a linear interpolation in the returned cell
334///
335/// IMPORTANT NOTE
336///
337/// The integral of the function is computed at fNpx * fNpy * fNpz points.
338/// If the function has sharp peaks, you should increase the number of
339/// points (SetNpx, SetNpy, SetNpz) such that the peak is correctly tabulated
340/// at several points.
341
342void TF3::GetRandom3(Double_t &xrandom, Double_t &yrandom, Double_t &zrandom, TRandom * rng)
343{
344 // Check if integral array must be built
345 Int_t i,j,k,cell;
346 Double_t dx = (fXmax-fXmin)/fNpx;
347 Double_t dy = (fYmax-fYmin)/fNpy;
348 Double_t dz = (fZmax-fZmin)/fNpz;
349 Int_t ncells = fNpx*fNpy*fNpz;
350 Double_t xx[3];
351 Double_t *parameters = GetParameters();
352 InitArgs(xx,parameters);
353 if (fIntegral.empty() ) {
354 fIntegral.resize(ncells+1);
355 //fIntegral = new Double_t[ncells+1];
356 fIntegral[0] = 0;
357 Double_t integ;
358 Int_t intNegative = 0;
359 cell = 0;
360 for (k=0;k<fNpz;k++) {
361 xx[2] = fZmin+(k+0.5)*dz;
362 for (j=0;j<fNpy;j++) {
363 xx[1] = fYmin+(j+0.5)*dy;
364 for (i=0;i<fNpx;i++) {
365 xx[0] = fXmin+(i+0.5)*dx;
366 integ = EvalPar(xx,parameters);
367 if (integ < 0) {intNegative++; integ = -integ;}
368 fIntegral[cell+1] = fIntegral[cell] + integ;
369 cell++;
370 }
371 }
372 }
373 if (intNegative > 0) {
374 Warning("GetRandom3","function:%s has %d negative values: abs assumed",GetName(),intNegative);
375 }
376 if (fIntegral[ncells] == 0) {
377 Error("GetRandom3","Integral of function is zero");
378 return;
379 }
380 for (i=1;i<=ncells;i++) { // normalize integral to 1
381 fIntegral[i] /= fIntegral[ncells];
382 }
383 }
384
385// return random numbers
386 Double_t r;
387 if (!rng) rng = gRandom;
388 r = rng->Rndm();
389 cell = TMath::BinarySearch(ncells,fIntegral.data(),r);
390 k = cell/(fNpx*fNpy);
391 j = (cell -k*fNpx*fNpy)/fNpx;
392 i = cell -fNpx*(j +fNpy*k);
393 xrandom = fXmin +dx*i +dx*rng->Rndm();
394 yrandom = fYmin +dy*j +dy*rng->Rndm();
395 zrandom = fZmin +dz*k +dz*rng->Rndm();
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Return range of function
400
402{
403 xmin = fXmin;
404 xmax = fXmax;
405 ymin = fYmin;
406 ymax = fYmax;
407 zmin = fZmin;
408 zmax = fZmax;
409}
410
411
412////////////////////////////////////////////////////////////////////////////////
413/// Get value corresponding to X in array of fSave values
414
416{
417 //if (fNsave <= 0) return 0;
418 if (fSave.empty()) return 0;
419 Int_t np = fSave.size() - 9;
424 Double_t zmin = Double_t(fSave[np+4]);
425 Double_t zmax = Double_t(fSave[np+5]);
426 Int_t npx = Int_t(fSave[np+6]);
427 Int_t npy = Int_t(fSave[np+7]);
428 Int_t npz = Int_t(fSave[np+8]);
429 Double_t x = Double_t(xx[0]);
430 Double_t dx = (xmax-xmin)/npx;
431 if (x < xmin || x > xmax) return 0;
432 if (dx <= 0) return 0;
433 Double_t y = Double_t(xx[1]);
434 Double_t dy = (ymax-ymin)/npy;
435 if (y < ymin || y > ymax) return 0;
436 if (dy <= 0) return 0;
437 Double_t z = Double_t(xx[2]);
438 Double_t dz = (zmax-zmin)/npz;
439 if (z < zmin || z > zmax) return 0;
440 if (dz <= 0) return 0;
441
442 //we make a trilinear interpolation using the 8 points surrounding x,y,z
443 Int_t ibin = Int_t((x-xmin)/dx);
444 Int_t jbin = Int_t((y-ymin)/dy);
445 Int_t kbin = Int_t((z-zmin)/dz);
446 Double_t xlow = xmin + ibin*dx;
447 Double_t ylow = ymin + jbin*dy;
448 Double_t zlow = zmin + kbin*dz;
449 Double_t t = (x-xlow)/dx;
450 Double_t u = (y-ylow)/dy;
451 Double_t v = (z-zlow)/dz;
452 Int_t k1 = (ibin ) + (npx+1)*((jbin ) + (npy+1)*(kbin ));
453 Int_t k2 = (ibin+1) + (npx+1)*((jbin ) + (npy+1)*(kbin ));
454 Int_t k3 = (ibin+1) + (npx+1)*((jbin+1) + (npy+1)*(kbin ));
455 Int_t k4 = (ibin ) + (npx+1)*((jbin+1) + (npy+1)*(kbin ));
456 Int_t k5 = (ibin ) + (npx+1)*((jbin ) + (npy+1)*(kbin+1));
457 Int_t k6 = (ibin+1) + (npx+1)*((jbin ) + (npy+1)*(kbin+1));
458 Int_t k7 = (ibin+1) + (npx+1)*((jbin+1) + (npy+1)*(kbin+1));
459 Int_t k8 = (ibin ) + (npx+1)*((jbin+1) + (npy+1)*(kbin+1));
460 Double_t r = (1-t)*(1-u)*(1-v)*fSave[k1] + t*(1-u)*(1-v)*fSave[k2] + t*u*(1-v)*fSave[k3] + (1-t)*u*(1-v)*fSave[k4] +
461 (1-t)*(1-u)*v*fSave[k5] + t*(1-u)*v*fSave[k6] + t*u*v*fSave[k7] + (1-t)*u*v*fSave[k8];
462 return r;
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// Return Integral of a 3d function in range [ax,bx],[ay,by],[az,bz]
467/// with a desired relative accuracy.
468
470{
471 Double_t a[3], b[3];
472 a[0] = ax;
473 b[0] = bx;
474 a[1] = ay;
475 b[1] = by;
476 a[2] = az;
477 b[2] = bz;
478 Double_t relerr = 0;
479 Int_t n = 3;
481 Int_t nfnevl, ifail;
482 Double_t result = IntegralMultiple(n,a,b,maxpts,epsrel,epsrel, relerr,nfnevl,ifail);
483 if (ifail > 0) {
484 Warning("Integral","failed for %s code=%d, maxpts=%d, epsrel=%g, nfnevl=%d, relerr=%g ",GetName(),ifail,maxpts,epsrel,nfnevl,relerr);
485 }
486 if (gDebug) {
487 Info("Integral","Integral of %s using %d and tol=%f is %f , relerr=%f nfcn=%d",GetName(),maxpts,epsrel,result,relerr,nfnevl);
488 }
489 return result;
490}
491
492////////////////////////////////////////////////////////////////////////////////
493/// Return kTRUE is the point is inside the function range
494
496{
497 if (x[0] < fXmin || x[0] > fXmax) return kFALSE;
498 if (x[1] < fYmin || x[1] > fYmax) return kFALSE;
499 if (x[2] < fZmin || x[2] > fZmax) return kFALSE;
500 return kTRUE;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// Create a histogram for axis range.
505
507{
508 TH1* h = new TH3F("R__TF3",(char*)GetTitle(),fNpx,fXmin,fXmax
510 ,fNpz,fZmin,fZmax);
511 h->SetDirectory(0);
512 return h;
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// Paint this 3-D function with its current attributes
517
519{
520
521 TString opt = option;
522 opt.ToLower();
523
524//- Create a temporary histogram and fill each channel with the function value
525 if (!fHistogram) {
526 fHistogram = new TH3F("R__TF3",(char*)GetTitle(),fNpx,fXmin,fXmax
528 ,fNpz,fZmin,fZmax);
530 }
531
533
534 if (opt.Index("tf3") == kNPOS)
535 opt.Append("tf3");
536
537 fHistogram->Paint(opt.Data());
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Set the function clipping box (for drawing) "off".
542
544{
546 fClipBox[0] = fClipBox[1] = fClipBox[2] = 0;
547}
548
549////////////////////////////////////////////////////////////////////////////////
550/// Save values of function in array fSave
551
553{
554 if (!fSave.empty()) fSave.clear();
555 Int_t nsave = (fNpx+1)*(fNpy+1)*(fNpz+1);
556 Int_t fNsave = nsave+9;
557 assert(fNsave > 9);
558 //fSave = new Double_t[fNsave];
559 fSave.resize(fNsave);
560 Int_t i,j,k,l=0;
561 Double_t dx = (xmax-xmin)/fNpx;
562 Double_t dy = (ymax-ymin)/fNpy;
563 Double_t dz = (zmax-zmin)/fNpz;
564 if (dx <= 0) {
565 dx = (fXmax-fXmin)/fNpx;
566 xmin = fXmin +0.5*dx;
567 xmax = fXmax -0.5*dx;
568 }
569 if (dy <= 0) {
570 dy = (fYmax-fYmin)/fNpy;
571 ymin = fYmin +0.5*dy;
572 ymax = fYmax -0.5*dy;
573 }
574 if (dz <= 0) {
575 dz = (fZmax-fZmin)/fNpz;
576 zmin = fZmin +0.5*dz;
577 zmax = fZmax -0.5*dz;
578 }
579 Double_t xv[3];
580 Double_t *pp = GetParameters();
581 InitArgs(xv,pp);
582 for (k=0;k<=fNpz;k++) {
583 xv[2] = zmin + dz*k;
584 for (j=0;j<=fNpy;j++) {
585 xv[1] = ymin + dy*j;
586 for (i=0;i<=fNpx;i++) {
587 xv[0] = xmin + dx*i;
588 fSave[l] = EvalPar(xv,pp);
589 l++;
590 }
591 }
592 }
593 fSave[nsave+0] = xmin;
594 fSave[nsave+1] = xmax;
595 fSave[nsave+2] = ymin;
596 fSave[nsave+3] = ymax;
597 fSave[nsave+4] = zmin;
598 fSave[nsave+5] = zmax;
599 fSave[nsave+6] = fNpx;
600 fSave[nsave+7] = fNpy;
601 fSave[nsave+8] = fNpz;
602}
603
604////////////////////////////////////////////////////////////////////////////////
605/// Save primitive as a C++ statement(s) on output stream out
606
607void TF3::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
608{
609 char quote = '"';
610 out<<" "<<std::endl;
611 if (gROOT->ClassSaved(TF3::Class())) {
612 out<<" ";
613 } else {
614 out<<" TF3 *";
615 }
616 if (!fMethodCall) {
617 out<<GetName()<<" = new TF3("<<quote<<GetName()<<quote<<","<<quote<<GetTitle()<<quote<<","<<fXmin<<","<<fXmax<<","<<fYmin<<","<<fYmax<<","<<fZmin<<","<<fZmax<<");"<<std::endl;
618 } else {
619 out<<GetName()<<" = new TF3("<<quote<<GetName()<<quote<<","<<GetTitle()<<","<<fXmin<<","<<fXmax<<","<<fYmin<<","<<fYmax<<","<<fZmin<<","<<fZmax<<","<<GetNpar()<<");"<<std::endl;
620 }
621
622 if (GetFillColor() != 0) {
623 if (GetFillColor() > 228) {
625 out<<" "<<GetName()<<"->SetFillColor(ci);" << std::endl;
626 } else
627 out<<" "<<GetName()<<"->SetFillColor("<<GetFillColor()<<");"<<std::endl;
628 }
629 if (GetLineColor() != 1) {
630 if (GetLineColor() > 228) {
632 out<<" "<<GetName()<<"->SetLineColor(ci);" << std::endl;
633 } else
634 out<<" "<<GetName()<<"->SetLineColor("<<GetLineColor()<<");"<<std::endl;
635 }
636 if (GetNpz() != 100) {
637 out<<" "<<GetName()<<"->SetNpz("<<GetNpz()<<");"<<std::endl;
638 }
639 if (GetChisquare() != 0) {
640 out<<" "<<GetName()<<"->SetChisquare("<<GetChisquare()<<");"<<std::endl;
641 }
642 Double_t parmin, parmax;
643 for (Int_t i=0;i<GetNpar();i++) {
644 out<<" "<<GetName()<<"->SetParameter("<<i<<","<<GetParameter(i)<<");"<<std::endl;
645 out<<" "<<GetName()<<"->SetParError("<<i<<","<<GetParError(i)<<");"<<std::endl;
646 GetParLimits(i,parmin,parmax);
647 out<<" "<<GetName()<<"->SetParLimits("<<i<<","<<parmin<<","<<parmax<<");"<<std::endl;
648 }
649 out<<" "<<GetName()<<"->Draw("
650 <<quote<<option<<quote<<");"<<std::endl;
651}
652
653////////////////////////////////////////////////////////////////////////////////
654/// Set the function clipping box (for drawing) "on" and define the clipping box.
655/// xclip, yclip and zclip is a point within the function range. All the
656/// function values having x<=xclip and y<=yclip and z>=zclip are clipped.
657
659{
661 fClipBox[0] = xclip;
662 fClipBox[1] = yclip;
663 fClipBox[2] = zclip;
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Set the number of points used to draw the function
668///
669/// The default number of points along x is 30 for 2-d/3-d functions.
670/// You can increase this value to get a better resolution when drawing
671/// pictures with sharp peaks or to get a better result when using TF3::GetRandom2
672/// the minimum number of points is 4, the maximum is 10000 for 2-d/3-d functions
673
675{
676 if (npz < 4) {
677 Warning("SetNpz","Number of points must be >=4 && <= 10000, fNpz set to 4");
678 fNpz = 4;
679 } else if(npz > 10000) {
680 Warning("SetNpz","Number of points must be >=4 && <= 10000, fNpz set to 10000");
681 fNpz = 10000;
682 } else {
683 fNpz = npz;
684 }
685 Update();
686}
687
688////////////////////////////////////////////////////////////////////////////////
689/// Initialize the upper and lower bounds to draw the function
690
692{
693 fXmin = xmin;
694 fXmax = xmax;
695 fYmin = ymin;
696 fYmax = ymax;
697 fZmin = zmin;
698 fZmax = zmax;
699 Update();
700}
701
702////////////////////////////////////////////////////////////////////////////////
703/// Stream an object of class TF3.
704
706{
707 if (R__b.IsReading()) {
708 UInt_t R__s, R__c;
709 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
710 if (R__v > 0) {
711 R__b.ReadClassBuffer(TF3::Class(), this, R__v, R__s, R__c);
712 return;
713 }
714
715 } else {
716 Int_t saved = 0;
717 if (fType != EFType::kFormula && fSave.empty() ) { saved = 1; Save(fXmin,fXmax,fYmin,fYmax,fZmin,fZmax);}
718
719 R__b.WriteClassBuffer(TF3::Class(),this);
720
721 if (saved) { fSave.clear(); }
722 }
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Return x^nx * y^ny * z^nz moment of a 3d function in range [ax,bx],[ay,by],[az,bz]
727/// \author Gene Van Buren <gene@bnl.gov>
728
730{
731 Double_t norm = Integral(ax,bx,ay,by,az,bz,epsilon);
732 if (norm == 0) {
733 Error("Moment3", "Integral zero over range");
734 return 0;
735 }
736
737 // define integrand function as a lambda : g(x,y,z)= x^(nx) * y^(ny) * z^(nz) * f(x,y,z)
738 auto integrand = [&](double *x, double *) {
739 return std::pow(x[0], nx) * std::pow(x[1], ny) * std::pow(x[2], nz) * this->EvalPar(x, nullptr);
740 };
741 // compute integral of g(x,y,z)
742 TF3 fnc("TF3_ExpValHelper", integrand, ax, bx, ay, by, az, bz, 0);
743 // set same points as current function to get correct max points when computing the integral
744 fnc.fNpx = fNpx;
745 fnc.fNpy = fNpy;
746 fnc.fNpz = fNpz;
747 return fnc.Integral(ax, bx, ay, by, az, bz, epsilon) / norm;
748}
749
750////////////////////////////////////////////////////////////////////////////////
751/// Return x^nx * y^ny * z^nz central moment of a 3d function in range [ax,bx],[ay,by],[az,bz]
752/// \author Gene Van Buren <gene@bnl.gov>
753
755{
756 Double_t norm = Integral(ax,bx,ay,by,az,bz,epsilon);
757 if (norm == 0) {
758 Error("CentralMoment3", "Integral zero over range");
759 return 0;
760 }
761
762 Double_t xbar = 0;
763 Double_t ybar = 0;
764 Double_t zbar = 0;
765 if (nx!=0) {
766 // compute first momentum in x
767 auto integrandX = [&](double *x, double *) { return x[0] * this->EvalPar(x, nullptr); };
768 TF3 fncx("TF3_ExpValHelperx", integrandX, ax, bx, ay, by, az, bz, 0);
769 fncx.fNpx = fNpx;
770 fncx.fNpy = fNpy;
771 fncx.fNpz = fNpz;
772 xbar = fncx.Integral(ax, bx, ay, by, az, bz, epsilon) / norm;
773 }
774 if (ny!=0) {
775 auto integrandY = [&](double *x, double *) { return x[1] * this->EvalPar(x, nullptr); };
776 TF3 fncy("TF3_ExpValHelpery", integrandY, ax, bx, ay, by, az, bz, 0);
777 fncy.fNpx = fNpx;
778 fncy.fNpy = fNpy;
779 fncy.fNpz = fNpz;
780 ybar = fncy.Integral(ax,bx,ay,by,az,bz,epsilon)/norm;
781 }
782 if (nz!=0) {
783 auto integrandZ = [&](double *x, double *) { return x[2] * this->EvalPar(x, nullptr); };
784 TF3 fncz("TF3_ExpValHelperz", integrandZ, ax, bx, ay, by, az, bz, 0);
785 fncz.fNpx = fNpx;
786 fncz.fNpy = fNpy;
787 fncz.fNpz = fNpz;
788 zbar = fncz.Integral(ax,bx,ay,by,az,bz,epsilon)/norm;
789 }
790 // define integrand function as a lambda : g(x,y)= (x-xbar)^(nx) * (y-ybar)^(ny) * f(x,y)
791 auto integrand = [&](double *x, double *) {
792 double xxx = (nx != 0) ? std::pow(x[0] - xbar, nx) : 1.;
793 double yyy = (ny != 0) ? std::pow(x[1] - ybar, ny) : 1.;
794 double zzz = (nz != 0) ? std::pow(x[2] - zbar, nz) : 1.;
795 return xxx * yyy * zzz * this->EvalPar(x, nullptr);
796 };
797 // compute integral of g(x,y, z)
798 TF3 fnc("TF3_ExpValHelper",integrand,ax,bx,ay,by,az,bz,0) ;
799 fnc.fNpx = fNpx;
800 fnc.fNpy = fNpy;
801 fnc.fNpz = fNpz;
802 return fnc.Integral(ax,bx,ay,by,az,bz,epsilon)/norm;
803}
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
const Ssiz_t kNPOS
Definition: RtypesCore.h:124
int Int_t
Definition: RtypesCore.h:45
short Version_t
Definition: RtypesCore.h:65
const Bool_t kFALSE
Definition: RtypesCore.h:101
unsigned int UInt_t
Definition: RtypesCore.h:46
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition: TGX11.cxx:110
float xmin
Definition: THbookFile.cxx:95
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
Int_t gDebug
Definition: TROOT.cxx:585
#define gROOT
Definition: TROOT.h:404
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
#define gPad
Definition: TVirtualPad.h:288
Param Functor class for Multidimensional functions.
Definition: ParamFunctor.h:273
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition: TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2187
Int_t fNdim
Function dimension.
Definition: TF1.h:246
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition: TF1.cxx:1956
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition: TF1.cxx:1946
Double_t GetChisquare() const
Definition: TF1.h:449
Double_t fXmin
Lower bounds for the range.
Definition: TF1.h:243
std::unique_ptr< TMethodCall > fMethodCall
! Pointer to MethodCall in case of interpreted function
Definition: TF1.h:264
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition: TF1.cxx:3657
virtual Int_t GetNpar() const
Definition: TF1.h:486
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition: TF1.h:263
virtual Double_t * GetParameters() const
Definition: TF1.h:525
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition: TF1.cxx:2496
virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t maxpts, Double_t epsrel, Double_t epsabs, Double_t &relerr, Int_t &nfnevl, Int_t &ifail)
This function computes, to an attempted specified accuracy, the value of the integral.
Definition: TF1.cxx:2864
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a function.
Definition: TF1.cxx:1303
EFType fType
Definition: TF1.h:248
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition: TF1.cxx:1484
Int_t fNpx
Number of points used for the graphical representation.
Definition: TF1.h:247
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TF1.cxx:1552
std::vector< Double_t > fSave
Array of fNsave function values.
Definition: TF1.h:257
virtual Double_t GetMinMaxNDim(Double_t *x, Bool_t findmax, Double_t epsilon=0, Int_t maxiter=0) const
Find the minimum of a function of whatever dimension.
Definition: TF1.cxx:1739
std::vector< Double_t > fIntegral
! Integral of function binned on fNpx bins
Definition: TF1.h:258
Double_t fXmax
Upper bounds for the range.
Definition: TF1.h:244
virtual Int_t GetNdim() const
Definition: TF1.h:490
virtual Double_t GetParameter(Int_t ipar) const
Definition: TF1.h:517
A 2-Dim function with parameters.
Definition: TF2.h:29
void Copy(TObject &f2) const override
Copy this F2 to a new F2.
Definition: TF2.cxx:210
Int_t fNpy
Number of points along y used for the graphical representation.
Definition: TF2.h:34
Double_t fYmax
Upper bound for the range in y.
Definition: TF2.h:33
Double_t fYmin
Lower bound for the range in y.
Definition: TF2.h:32
A 3-Dim function with parameters.
Definition: TF3.h:28
void GetRange(Double_t &xmin, Double_t &xmax) const override
Return range of a 1-D function.
Definition: TF3.h:141
static TClass * Class()
TF3()
F3 default constructor.
Definition: TF3.cxx:37
void Paint(Option_t *option="") override
Paint this 3-D function with its current attributes.
Definition: TF3.cxx:518
Int_t GetNpz() const
Definition: TF3.h:93
virtual void GetRandom3(Double_t &xrandom, Double_t &yrandom, Double_t &zrandom, TRandom *rng=nullptr)
Return 3 random numbers following this function shape.
Definition: TF3.cxx:342
Bool_t IsInside(const Double_t *x) const override
Return kTRUE is the point is inside the function range.
Definition: TF3.cxx:495
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TF3.cxx:209
Double_t fZmin
Lower bound for the range in z.
Definition: TF3.h:31
TF3 & operator=(const TF3 &rhs)
Operator =.
Definition: TF3.cxx:145
virtual void SetNpz(Int_t npz=30)
Set the number of points used to draw the function.
Definition: TF3.cxx:674
virtual Double_t GetMaximumXYZ(Double_t &x, Double_t &y, Double_t &z)
Compute the X, Y and Z values corresponding to the maximum value of the function on its range.
Definition: TF3.cxx:314
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)
Return x^nx * y^ny * z^nz central moment of a 3d function in range [ax,bx],[ay,by],...
Definition: TF3.cxx:754
void Copy(TObject &f3) const override
Copy this F3 to a new F3.
Definition: TF3.cxx:170
Double_t FindMinMax(Double_t *x, bool findmax) const override
Return minimum/maximum value of the function.
Definition: TF3.cxx:230
~TF3() override
F3 default destructor.
Definition: TF3.cxx:155
Bool_t fClipBoxOn
! Is clip box on
Definition: TF3.h:34
virtual Double_t GetMinimumXYZ(Double_t &x, Double_t &y, Double_t &z)
Compute the X, Y and Z values corresponding to the minimum value of the function on its range.
Definition: TF3.cxx:298
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)
Return x^nx * y^ny * z^nz moment of a 3d function in range [ax,bx],[ay,by],[az,bz].
Definition: TF3.cxx:729
Int_t fNpz
Number of points along z used for the graphical representation.
Definition: TF3.h:33
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition: TF3.cxx:194
virtual void SetClippingBoxOn(Double_t xclip=0, Double_t yclip=0, Double_t zclip=0)
Set the function clipping box (for drawing) "on" and define the clipping box.
Definition: TF3.cxx:658
virtual void SetClippingBoxOff()
Set the function clipping box (for drawing) "off".
Definition: TF3.cxx:543
Double_t fZmax
Upper bound for the range in z.
Definition: TF3.h:32
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a function.
Definition: TF3.cxx:185
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)
Return Integral of a 3d function in range [ax,bx],[ay,by],[az,bz] with a desired relative accuracy.
Definition: TF3.cxx:469
void Streamer(TBuffer &) override
Stream an object of class TF3.
Definition: TF3.cxx:705
TH1 * CreateHistogram() override
Create a histogram for axis range.
Definition: TF3.cxx:506
void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override
Save values of function in array fSave.
Definition: TF3.cxx:552
Double_t GetSave(const Double_t *x) override
Get value corresponding to X in array of fSave values.
Definition: TF3.cxx:415
Double_t fClipBox[3]
! Coordinates of clipbox
Definition: TF3.h:35
void SetRange(Double_t xmin, Double_t xmax) override
Initialize the upper and lower bounds to draw the function.
Definition: TF3.h:145
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition: TF3.cxx:607
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8804
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition: TH1.cxx:4484
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition: TH1.cxx:6188
3-D histogram with a float per channel (see TH1 documentation)}
Definition: TH3.h:268
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:949
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:177
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:963
void MakeZombie()
Definition: TObject.h:53
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:937
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
Double_t Rndm() override
Machine independent random number generator.
Definition: TRandom.cxx:552
Basic string class.
Definition: TString.h:136
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1155
const char * Data() const
Definition: TString.h:369
TString & Append(const char *cs)
Definition: TString.h:564
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
virtual void ProcessMessage(const char *mess, const TObject *obj)=0
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
Definition: RVec.hxx:1770
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition: TMathBase.h:250
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Definition: TMath.h:900
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Definition: TMath.h:768
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition: TMathBase.h:198
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition: TMathBase.h:347
Double_t Infinity()
Returns an infinity as defined by the IEEE standard.
Definition: TMath.h:915
TLine l
Definition: textangle.C:4
TArc a
Definition: textangle.C:12
auto * tt
Definition: textangle.C:16
double epsilon
Definition: triangle.c:618