Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TVirtualHistPainter.h"
21
22#include <cassert>
23#include <ostream>
24
25/** \class TF3
26 \ingroup Functions
27TF3 defines a 3D Function with Parameters.
28
293D implicit functions can be visualized as iso-surfaces. An implicit surface is defined
30by the equation f(x,y,z) = 0 and is rendered in Cartesian coordinates.
31
32In the example below, the drawing options "FB" and "BB" are used to remove the
33front box and back box of the 3D frame keeping only the three axes.
34
35Begin_Macro(source)
36{
37 auto C = new TCanvas("C","C",500,500);
38 auto f3 = new TF3("gyroid",
39 "sin(x)*cos(y) + sin(y)*cos(z) + sin(z)*cos(x)",
40 -4, 4, -4, 4, -4, 4);
41 f3->SetFillColor(50);
42 f3->SetLineColor(15);
43 f3->Draw("FBBB");
44}
45End_Macro
46
47*/
48
49////////////////////////////////////////////////////////////////////////////////
50/// F3 default constructor
51
53{
54 fNpz = 0;
55 fZmin = 0;
56 fZmax = 1;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// TF3 constructor using a formula definition and string option args
61///
62/// See TFormula constructor for explanation of the formula syntax.
63
65 Double_t zmin, Double_t zmax, Option_t *opt)
67 opt) // purposely swapped ymax, ymin to signal that TFormula may be 1D or 2D or 3D
68{
69 fZmin = zmin;
70 fZmax = zmax;
71 fNpz = 30;
72 Int_t ndim = GetNdim();
73 // accept 1-d or 2-d formula
74 if (ndim < 3) fNdim = 3;
75 if (ndim > 3 && xmin < xmax && ymin < ymax && zmin < zmax) {
76 Error("TF3","function: %s/%s has dimension %d instead of 3",name,formula,ndim);
77 MakeZombie();
78 }
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// TF3 constructor using a formula definition and explicit option args
83///
84/// See TFormula constructor for explanation of the formula syntax.
85
89 vectorize) // purposely swapped ymax, ymin to signal that TFormula may be 1D or 2D or 3D
90{
91 fZmin = zmin;
92 fZmax = zmax;
93 fNpz = 30;
94 Int_t ndim = GetNdim();
95 // accept 1-d or 2-d formula
96 if (ndim < 3)
97 fNdim = 3;
98 if (ndim > 3 && xmin < xmax && ymin < ymax && zmin < zmax) {
99 Error("TF3", "function: %s/%s has dimension %d instead of 3", name, formula, ndim);
100 MakeZombie();
101 }
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// TF3 constructor using a pointer to real function
106///
107/// \param[in] name object name
108/// \param[in] fcn pointer to real function
109/// \param[in] xmin,xmax x axis limits
110/// \param[in] ymin,ymax y axis limits
111/// \param[in] zmin,zmax z axis limits
112/// \param[in] npar is the number of free parameters used by the function
113/// \param[in] ndim number of dimensions
114///
115/// For example, for a 3-dim function with 3 parameters, the user function
116/// looks like:
117///
118/// Double_t fun1(Double_t *x, Double_t *par)
119/// return par[0]*x[2] + par[1]*exp(par[2]*x[0]*x[1]);
120///
121/// \warning A function created with this constructor cannot be Cloned.
122
125{
126 fZmin = zmin;
127 fZmax = zmax;
128 fNpz = 30;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// TF3 constructor using a pointer to real function---
133///
134/// \param[in] name object name
135/// \param[in] fcn pointer to real function
136/// \param[in] xmin,xmax x axis limits
137/// \param[in] ymin,ymax y axis limits
138/// \param[in] zmin,zmax z axis limits
139/// \param[in] npar is the number of free parameters used by the function
140/// \param[in] ndim number of dimensions
141///
142/// For example, for a 3-dim function with 3 parameters, the user function
143/// looks like:
144///
145/// Double_t fun1(Double_t *x, Double_t *par)
146/// return par[0]*x[2] + par[1]*exp(par[2]*x[0]*x[1]);
147///
148/// WARNING! A function created with this constructor cannot be Cloned.
149
152 fZmin(zmin),
153 fZmax(zmax),
154 fNpz(30)
155{
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// TF3 constructor using a ParamFunctor
160///
161/// a functor class implementing operator() (double *, double *)
162///
163/// \param[in] name object name
164/// \param[in] f parameter functor
165/// \param[in] xmin,xmax x axis limits
166/// \param[in] ymin,ymax y axis limits
167/// \param[in] zmin,zmax z axis limits
168/// \param[in] npar is the number of free parameters used by the function
169/// \param[in] ndim number of dimensions
170///
171/// \warning A function created with this constructor cannot be Cloned.
172
174 : TF2(name, f, xmin, xmax, ymin, ymax, npar, ndim, addToGlobList),
175 fZmin(zmin),
176 fZmax(zmax),
177 fNpz(30)
178{
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Operator =
183
185{
186 if (this != &rhs)
187 rhs.TF3::Copy(*this);
188 return *this;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// F3 default destructor
193
195{
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Copy constructor.
200
201TF3::TF3(const TF3 &f3) : TF2()
202{
203 f3.TF3::Copy(*this);
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Copy this F3 to a new F3
208
209void TF3::Copy(TObject &obj) const
210{
211 TF2::Copy(obj);
212 ((TF3&)obj).fZmin = fZmin;
213 ((TF3&)obj).fZmax = fZmax;
214 ((TF3&)obj).fNpz = fNpz;
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Compute distance from point px,py to a function
219///
220/// Compute the closest distance of approach from point px,py to this function.
221/// The distance is computed in pixels units.
222
223
225{
226 return TF1::DistancetoPrimitive(px, py);
227
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Draw this function with iso-surfaces.
232
234{
235 TString opt = option;
236 opt.ToLower();
237 if (gPad && !opt.Contains("same")) gPad->Clear();
238
240
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Execute action corresponding to one event
245///
246/// This member function is called when a F3 is clicked with the locator
247
249{
250 TF1::ExecuteEvent(event, px, py);
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Return minimum/maximum value of the function
255///
256/// To find the minimum on a range, first set this range via the SetRange function
257/// If a vector x of coordinate is passed it will be used as starting point for the minimum.
258/// In addition on exit x will contain the coordinate values at the minimuma
259/// If x is NULL or x is inifinity or NaN, first, a grid search is performed to find the initial estimate of the
260/// minimum location. The range of the function is divided into fNpx and fNpy
261/// sub-ranges. If the function is "good" (or "bad"), these values can be changed
262/// by SetNpx and SetNpy functions
263///
264/// Then, a minimization is used with starting values found by the grid search
265/// The minimizer algorithm used (by default Minuit) can be changed by callinga
266/// ROOT::Math::Minimizer::SetDefaultMinimizerType("..")
267/// Other option for the minimizer can be set using the static method of the MinimizerOptions class
268
270{
271 //First do a grid search with step size fNpx and fNpy
272
273 Double_t xx[3];
274 Double_t rsign = (findmax) ? -1. : 1.;
275 TF3 & function = const_cast<TF3&>(*this); // needed since EvalPar is not const
276 Double_t xxmin = 0, yymin = 0, zzmin = 0, ttmin = 0;
277 if (x == nullptr || ( (x!= nullptr) && ( !TMath::Finite(x[0]) || !TMath::Finite(x[1]) || !TMath::Finite(x[2]) ) ) ){
278 Double_t dx = (fXmax - fXmin)/fNpx;
279 Double_t dy = (fYmax - fYmin)/fNpy;
280 Double_t dz = (fZmax - fZmin)/fNpz;
281 xxmin = fXmin;
282 yymin = fYmin;
283 zzmin = fZmin;
285 for (Int_t i=0; i<fNpx; i++){
286 xx[0]=fXmin + (i+0.5)*dx;
287 for (Int_t j=0; j<fNpy; j++){
288 xx[1]=fYmin+(j+0.5)*dy;
289 for (Int_t k=0; k<fNpz; k++){
290 xx[2] = fZmin+(k+0.5)*dz;
291 Double_t tt = function(xx);
292 if (rsign*tt < rsign*ttmin) {xxmin = xx[0], yymin = xx[1]; zzmin = xx[2]; ttmin=tt;}
293 }
294 }
295 }
296
300 }
301 else {
302 xxmin = x[0];
303 yymin = x[1];
304 zzmin = x[2];
305 zzmin = function(x);
306 }
307 xx[0] = xxmin;
308 xx[1] = yymin;
309 xx[2] = zzmin;
310
311 double fmin = GetMinMaxNDim(xx,findmax);
312 if (rsign*fmin < rsign*zzmin) {
313 if (x) {x[0] = xx[0]; x[1] = xx[1]; x[2] = xx[2];}
314 return fmin;
315 }
316 // here if minimization failed
317 if (x) { x[0] = xxmin; x[1] = yymin; x[2] = zzmin; }
318 return ttmin;
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Compute the X, Y and Z values corresponding to the minimum value of the function
323/// on its range.
324///
325/// Returns the function value at the minimum.
326/// To find the minimum on a subrange, use the SetRange() function first.
327///
328/// Method:
329/// First, a grid search is performed to find the initial estimate of the
330/// minimum location. The range of the function is divided
331/// into fNpx,fNpy and fNpz sub-ranges. If the function is "good" (or "bad"),
332/// these values can be changed by SetNpx(), SetNpy() and SetNpz() functions.
333/// Then, Minuit minimization is used with starting values found by the grid search
334///
335/// Note that this method will always do first a grid search in contrast to GetMinimum
336
338{
339 double xx[3] = { 0,0,0 };
340 xx[0] = TMath::QuietNaN(); // to force to do grid search in TF3::FindMinMax
341 double fmin = FindMinMax(xx, false);
342 x = xx[0]; y = xx[1]; z = xx[2];
343 return fmin;
344
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Compute the X, Y and Z values corresponding to the maximum value of the function
349/// on its range.
350///
351/// Return the function value at the maximum. See TF3::GetMinimumXYZ
352
354{
355 double xx[3] = { 0,0,0 };
356 xx[0] = TMath::QuietNaN(); // to force to do grid search in TF3::FindMinMax
357 double fmax = FindMinMax(xx, true);
358 x = xx[0]; y = xx[1]; z = xx[2];
359 return fmax;
360
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Return 3 random numbers following this function shape
365///
366/// The distribution contained in this TF3 function is integrated
367/// over the cell contents.
368/// It is normalized to 1.
369/// Getting the three random numbers implies:
370/// - Generating a random number between 0 and 1 (say r1)
371/// - Look in which cell in the normalized integral r1 corresponds to
372/// - make a linear interpolation in the returned cell
373///
374/// IMPORTANT NOTE
375///
376/// The integral of the function is computed at fNpx * fNpy * fNpz points.
377/// If the function has sharp peaks, you should increase the number of
378/// points (SetNpx, SetNpy, SetNpz) such that the peak is correctly tabulated
379/// at several points.
380
382{
383 // Check if integral array must be built
384 Int_t i,j,k,cell;
389 Double_t xx[3];
390 Double_t *parameters = GetParameters();
391 InitArgs(xx,parameters);
392 if (fIntegral.empty() ) {
393 fIntegral.resize(ncells+1);
394 //fIntegral = new Double_t[ncells+1];
395 fIntegral[0] = 0;
397 Int_t intNegative = 0;
398 cell = 0;
399 for (k=0;k<fNpz;k++) {
400 xx[2] = fZmin+(k+0.5)*dz;
401 for (j=0;j<fNpy;j++) {
402 xx[1] = fYmin+(j+0.5)*dy;
403 for (i=0;i<fNpx;i++) {
404 xx[0] = fXmin+(i+0.5)*dx;
405 integ = EvalPar(xx,parameters);
406 if (integ < 0) {intNegative++; integ = -integ;}
408 cell++;
409 }
410 }
411 }
412 if (intNegative > 0) {
413 Warning("GetRandom3","function:%s has %d negative values: abs assumed",GetName(),intNegative);
414 }
415 if (fIntegral[ncells] == 0) {
416 Error("GetRandom3","Integral of function is zero");
417 return;
418 }
419 for (i=1;i<=ncells;i++) { // normalize integral to 1
421 }
422 }
423
424// return random numbers
425 Double_t r;
426 if (!rng) rng = gRandom;
427 r = rng->Rndm();
429 k = cell/(fNpx*fNpy);
430 j = (cell -k*fNpx*fNpy)/fNpx;
431 i = cell -fNpx*(j +fNpy*k);
432 xrandom = fXmin +dx*i +dx*rng->Rndm();
433 yrandom = fYmin +dy*j +dy*rng->Rndm();
434 zrandom = fZmin +dz*k +dz*rng->Rndm();
435}
436
437////////////////////////////////////////////////////////////////////////////////
438/// Return range of function
439
441{
442 xmin = fXmin;
443 xmax = fXmax;
444 ymin = fYmin;
445 ymax = fYmax;
446 zmin = fZmin;
447 zmax = fZmax;
448}
449
450
451////////////////////////////////////////////////////////////////////////////////
452/// Get value corresponding to X in array of fSave values
453
455{
456 if (fSave.size() < 9) return 0;
457 Int_t nsave = fSave.size() - 9;
462 Double_t zmin = fSave[nsave+4];
463 Double_t zmax = fSave[nsave+5];
464 Int_t npx = Int_t(fSave[nsave+6]);
465 Int_t npy = Int_t(fSave[nsave+7]);
466 Int_t npz = Int_t(fSave[nsave+8]);
467 Double_t x = xx[0];
468 Double_t dx = (xmax-xmin)/npx;
469 if (x < xmin || x > xmax) return 0;
470 if (dx <= 0) return 0;
471 Double_t y = xx[1];
472 Double_t dy = (ymax-ymin)/npy;
473 if (y < ymin || y > ymax) return 0;
474 if (dy <= 0) return 0;
475 Double_t z = xx[2];
476 Double_t dz = (zmax-zmin)/npz;
477 if (z < zmin || z > zmax) return 0;
478 if (dz <= 0) return 0;
479
480 //we make a trilinear interpolation using the 8 points surrounding x,y,z
483 Int_t kbin = TMath::Min(npz-1, Int_t((z-zmin)/dz));
484 Double_t xlow = xmin + ibin*dx;
485 Double_t ylow = ymin + jbin*dy;
486 Double_t zlow = zmin + kbin*dz;
487 Double_t t = (x-xlow)/dx;
488 Double_t u = (y-ylow)/dy;
489 Double_t v = (z-zlow)/dz;
490 Int_t k1 = (ibin ) + (npx+1)*((jbin ) + (npy+1)*(kbin ));
491 Int_t k2 = (ibin+1) + (npx+1)*((jbin ) + (npy+1)*(kbin ));
492 Int_t k3 = (ibin+1) + (npx+1)*((jbin+1) + (npy+1)*(kbin ));
493 Int_t k4 = (ibin ) + (npx+1)*((jbin+1) + (npy+1)*(kbin ));
494 Int_t k5 = (ibin ) + (npx+1)*((jbin ) + (npy+1)*(kbin+1));
495 Int_t k6 = (ibin+1) + (npx+1)*((jbin ) + (npy+1)*(kbin+1));
496 Int_t k7 = (ibin+1) + (npx+1)*((jbin+1) + (npy+1)*(kbin+1));
497 Int_t k8 = (ibin ) + (npx+1)*((jbin+1) + (npy+1)*(kbin+1));
498 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] +
499 (1-t)*(1-u)*v*fSave[k5] + t*(1-u)*v*fSave[k6] + t*u*v*fSave[k7] + (1-t)*u*v*fSave[k8];
500 return r;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// Create the basic function objects
505
507{
508 TF3 *f3;
510 if (!gROOT->GetListOfFunctions()->FindObject("xyzgaus")) {
511 f3 = new TF3("xyzgaus", "xyzgaus", -1, 1, -1, 1, -1, 1);
512 f3->SetParameters(1, 0, 1, 0, 1, 0, 1);
513 }
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// Return Integral of a 3d function in range [ax,bx],[ay,by],[az,bz]
518/// with a desired relative accuracy.
519
521{
522 Double_t a[3], b[3];
523 a[0] = ax;
524 b[0] = bx;
525 a[1] = ay;
526 b[1] = by;
527 a[2] = az;
528 b[2] = bz;
529 Double_t relerr = 0;
530 Int_t n = 3;
534 if (ifail > 0) {
535 Warning("Integral","failed for %s code=%d, maxpts=%d, epsrel=%g, nfnevl=%d, relerr=%g ",GetName(),ifail,maxpts,epsrel,nfnevl,relerr);
536 }
537 if (gDebug) {
538 Info("Integral","Integral of %s using %d and tol=%f is %f , relerr=%f nfcn=%d",GetName(),maxpts,epsrel,result,relerr,nfnevl);
539 }
540 return result;
541}
542
543////////////////////////////////////////////////////////////////////////////////
544/// Return kTRUE is the point is inside the function range
545
547{
548 if (x[0] < fXmin || x[0] > fXmax) return kFALSE;
549 if (x[1] < fYmin || x[1] > fYmax) return kFALSE;
550 if (x[2] < fZmin || x[2] > fZmax) return kFALSE;
551 return kTRUE;
552}
553
554////////////////////////////////////////////////////////////////////////////////
555/// Create a histogram for axis range.
556
558{
559 TH1* h = new TH3F("R__TF3",(char*)GetTitle(),fNpx,fXmin,fXmax
561 ,fNpz,fZmin,fZmax);
562 h->SetDirectory(nullptr);
563 return h;
564}
565
566////////////////////////////////////////////////////////////////////////////////
567/// Paint this 3-D function with its current attributes
568
570{
571
572 TString opt = option;
573 opt.ToLower();
574
575//- Create a temporary histogram and fill each channel with the function value
576 if (!fHistogram) {
577 fHistogram = new TH3F("R__TF3",(char*)GetTitle(),fNpx,fXmin,fXmax
579 ,fNpz,fZmin,fZmax);
580 fHistogram->SetDirectory(nullptr);
581 }
582
584
585 if (opt.Index("tf3") == kNPOS)
586 opt.Append("tf3");
587
588 fHistogram->Paint(opt.Data());
589}
590
591////////////////////////////////////////////////////////////////////////////////
592/// Set the function clipping box (for drawing) "off".
593
595{
597 fClipBox[0] = fClipBox[1] = fClipBox[2] = 0;
598}
599
600////////////////////////////////////////////////////////////////////////////////
601/// Save values of function in array fSave
602
604{
605 if (!fSave.empty()) fSave.clear();
606 Int_t npx = fNpx, npy = fNpy, npz = fNpz;
607 if ((npx < 2) || (npy < 2) || (npz < 2))
608 return;
609
612 Double_t dz = (zmax-zmin)/fNpz;
613 if (dx <= 0) {
614 dx = (fXmax-fXmin)/fNpx;
615 npx--;
616 xmin = fXmin + 0.5*dx;
617 xmax = fXmax - 0.5*dx;
618 }
619 if (dy <= 0) {
620 dy = (fYmax-fYmin)/fNpy;
621 npy--;
622 ymin = fYmin + 0.5*dy;
623 ymax = fYmax - 0.5*dy;
624 }
625 if (dz <= 0) {
626 dz = (fZmax-fZmin)/fNpz;
627 npz--;
628 zmin = fZmin + 0.5*dz;
629 zmax = fZmax - 0.5*dz;
630 }
631 Int_t nsave = (npx + 1)*(npy + 1)*(npz + 1);
632 fSave.resize(nsave + 9);
633 Double_t xv[3];
634 Double_t *pp = GetParameters();
635 InitArgs(xv,pp);
636 for (Int_t k = 0, l = 0; k <= npz; k++) {
637 xv[2] = zmin + dz*k;
638 for (Int_t j = 0; j <= npy; j++) {
639 xv[1] = ymin + dy*j;
640 for (Int_t i = 0; i <= npx; i++) {
641 xv[0] = xmin + dx*i;
642 fSave[l++] = EvalPar(xv, pp);
643 }
644 }
645 }
646 fSave[nsave+0] = xmin;
647 fSave[nsave+1] = xmax;
648 fSave[nsave+2] = ymin;
649 fSave[nsave+3] = ymax;
650 fSave[nsave+4] = zmin;
651 fSave[nsave+5] = zmax;
652 fSave[nsave+6] = npx;
653 fSave[nsave+7] = npy;
654 fSave[nsave+8] = npz;
655}
656
657////////////////////////////////////////////////////////////////////////////////
658/// Save primitive as a C++ statement(s) on output stream out
659
660void TF3::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
661{
663 out << " \n";
664 out << " TF3 *";
665
666 if (!fMethodCall)
667 out << f3Name << " = new TF3(\"" << GetName() << "\", \"" << TString(GetTitle()).ReplaceSpecialCppChars() << "\","
668 << fXmin << "," << fXmax << "," << fYmin << "," << fYmax << "," << fZmin << "," << fZmax << ");\n";
669 else
670 out << f3Name << " = new TF3(\"" << GetName() << "\", " << GetTitle() << "," << fXmin << "," << fXmax << ","
671 << fYmin << "," << fYmax << "," << fZmin << "," << fZmax << "," << GetNpar() << ");\n";
672
673 SaveFillAttributes(out, f3Name, -1, 0);
674 SaveMarkerAttributes(out, f3Name, 1, 1, 1);
675 SaveLineAttributes(out, f3Name, 1, 1, 4);
676
677 if (GetNpx() != 30)
678 out << " " << f3Name << "->SetNpx(" << GetNpx() << ");\n";
679 if (GetNpy() != 30)
680 out << " " << f3Name << "->SetNpy(" << GetNpy() << ");\n";
681 if (GetNpz() != 30)
682 out << " " << f3Name << "->SetNpz(" << GetNpz() << ");\n";
683
684 if (GetChisquare() != 0)
685 out << " " << f3Name << "->SetChisquare(" << GetChisquare() << ");\n";
686
688 for (Int_t i = 0; i < GetNpar(); i++) {
689 out << " " << f3Name << "->SetParameter(" << i << "," << GetParameter(i) << ");\n";
690 out << " " << f3Name << "->SetParError(" << i << "," << GetParError(i) << ");\n";
692 out << " " << f3Name << "->SetParLimits(" << i << "," << parmin << "," << parmax << ");\n";
693 }
694
695 if (GetXaxis())
696 GetXaxis()->SaveAttributes(out, f3Name, "->GetXaxis()");
697 if (GetYaxis())
698 GetYaxis()->SaveAttributes(out, f3Name, "->GetYaxis()");
699 if (GetZaxis())
700 GetZaxis()->SaveAttributes(out, f3Name, "->GetZaxis()");
701
703}
704
705////////////////////////////////////////////////////////////////////////////////
706/// Set the function clipping box (for drawing) "on" and define the clipping box.
707/// xclip, yclip and zclip is a point within the function range. All the
708/// function values having x<=xclip and y<=yclip and z>=zclip are clipped.
709
711{
713 fClipBox[0] = xclip;
714 fClipBox[1] = yclip;
715 fClipBox[2] = zclip;
716}
717
718////////////////////////////////////////////////////////////////////////////////
719/// Set the number of points used to draw the function
720///
721/// The default number of points along x is 30 for 2-d/3-d functions.
722/// You can increase this value to get a better resolution when drawing
723/// pictures with sharp peaks or to get a better result when using TF3::GetRandom2
724/// the minimum number of points is 4, the maximum is 10000 for 2-d/3-d functions
725
727{
728 if (npz < 4) {
729 Warning("SetNpz","Number of points must be >=4 && <= 10000, fNpz set to 4");
730 fNpz = 4;
731 } else if(npz > 10000) {
732 Warning("SetNpz","Number of points must be >=4 && <= 10000, fNpz set to 10000");
733 fNpz = 10000;
734 } else {
735 fNpz = npz;
736 }
737 Update();
738}
739
740////////////////////////////////////////////////////////////////////////////////
741/// Initialize the upper and lower bounds to draw the function
742
744{
745 fXmin = xmin;
746 fXmax = xmax;
747 fYmin = ymin;
748 fYmax = ymax;
749 fZmin = zmin;
750 fZmax = zmax;
751 Update();
752}
753
754////////////////////////////////////////////////////////////////////////////////
755/// Stream an object of class TF3.
756
758{
759 if (R__b.IsReading()) {
761 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
762 if (R__v > 0) {
763 R__b.ReadClassBuffer(TF3::Class(), this, R__v, R__s, R__c);
764 return;
765 }
766
767 } else {
768 Int_t saved = 0;
769 if (fType != EFType::kFormula && fSave.empty() ) { saved = 1; Save(fXmin,fXmax,fYmin,fYmax,fZmin,fZmax);}
770
771 R__b.WriteClassBuffer(TF3::Class(),this);
772
773 if (saved) { fSave.clear(); }
774 }
775}
776
777////////////////////////////////////////////////////////////////////////////////
778/// Return x^nx * y^ny * z^nz moment of a 3d function in range [ax,bx],[ay,by],[az,bz]
779/// \author Gene Van Buren <gene@bnl.gov>
780
782{
783 Double_t norm = Integral(ax,bx,ay,by,az,bz,epsilon);
784 if (norm == 0) {
785 Error("Moment3", "Integral zero over range");
786 return 0;
787 }
788
789 // define integrand function as a lambda : g(x,y,z)= x^(nx) * y^(ny) * z^(nz) * f(x,y,z)
790 auto integrand = [&](double *x, double *) {
791 return std::pow(x[0], nx) * std::pow(x[1], ny) * std::pow(x[2], nz) * this->EvalPar(x, nullptr);
792 };
793 // compute integral of g(x,y,z)
794 TF3 fnc("TF3_ExpValHelper", integrand, ax, bx, ay, by, az, bz, 0);
795 // set same points as current function to get correct max points when computing the integral
796 fnc.fNpx = fNpx;
797 fnc.fNpy = fNpy;
798 fnc.fNpz = fNpz;
799 return fnc.Integral(ax, bx, ay, by, az, bz, epsilon) / norm;
800}
801
802////////////////////////////////////////////////////////////////////////////////
803/// Return x^nx * y^ny * z^nz central moment of a 3d function in range [ax,bx],[ay,by],[az,bz]
804/// \author Gene Van Buren <gene@bnl.gov>
805
807{
808 Double_t norm = Integral(ax,bx,ay,by,az,bz,epsilon);
809 if (norm == 0) {
810 Error("CentralMoment3", "Integral zero over range");
811 return 0;
812 }
813
814 Double_t xbar = 0;
815 Double_t ybar = 0;
816 Double_t zbar = 0;
817 if (nx!=0) {
818 // compute first momentum in x
819 auto integrandX = [&](double *x, double *) { return x[0] * this->EvalPar(x, nullptr); };
820 TF3 fncx("TF3_ExpValHelperx", integrandX, ax, bx, ay, by, az, bz, 0);
821 fncx.fNpx = fNpx;
822 fncx.fNpy = fNpy;
823 fncx.fNpz = fNpz;
824 xbar = fncx.Integral(ax, bx, ay, by, az, bz, epsilon) / norm;
825 }
826 if (ny!=0) {
827 auto integrandY = [&](double *x, double *) { return x[1] * this->EvalPar(x, nullptr); };
828 TF3 fncy("TF3_ExpValHelpery", integrandY, ax, bx, ay, by, az, bz, 0);
829 fncy.fNpx = fNpx;
830 fncy.fNpy = fNpy;
831 fncy.fNpz = fNpz;
832 ybar = fncy.Integral(ax,bx,ay,by,az,bz,epsilon)/norm;
833 }
834 if (nz!=0) {
835 auto integrandZ = [&](double *x, double *) { return x[2] * this->EvalPar(x, nullptr); };
836 TF3 fncz("TF3_ExpValHelperz", integrandZ, ax, bx, ay, by, az, bz, 0);
837 fncz.fNpx = fNpx;
838 fncz.fNpy = fNpy;
839 fncz.fNpz = fNpz;
840 zbar = fncz.Integral(ax,bx,ay,by,az,bz,epsilon)/norm;
841 }
842 // define integrand function as a lambda : g(x,y)= (x-xbar)^(nx) * (y-ybar)^(ny) * f(x,y)
843 auto integrand = [&](double *x, double *) {
844 double xxx = (nx != 0) ? std::pow(x[0] - xbar, nx) : 1.;
845 double yyy = (ny != 0) ? std::pow(x[1] - ybar, ny) : 1.;
846 double zzz = (nz != 0) ? std::pow(x[2] - zbar, nz) : 1.;
847 return xxx * yyy * zzz * this->EvalPar(x, nullptr);
848 };
849 // compute integral of g(x,y, z)
850 TF3 fnc("TF3_ExpValHelper",integrand,ax,bx,ay,by,az,bz,0) ;
851 fnc.fNpx = fNpx;
852 fnc.fNpy = fNpy;
853 fnc.fNpz = fNpz;
854 return fnc.Integral(ax,bx,ay,by,az,bz,epsilon)/norm;
855}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
cudaEvent_t event
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Version_t
Class version identifier (short)
Definition RtypesCore.h:80
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:132
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 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:142
float xmin
float ymin
float xmax
float ymax
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:792
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:417
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
#define R__LOCKGUARD(mutex)
#define gPad
Param Functor class for Multidimensional functions.
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:240
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:289
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
void SaveAttributes(std::ostream &out, const char *name, const char *subname) override
Save axis attributes as C++ statement(s) on output stream out.
Definition TAxis.cxx:715
Buffer base class used for serializing objects.
Definition TBuffer.h:43
EAddToList
Add to list behavior.
Definition TF1.h:189
Int_t fNdim
Function dimension.
Definition TF1.h:215
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition TF1.cxx:1991
TAxis * GetYaxis() const
Get y axis of the function.
Definition TF1.cxx:2460
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1981
Double_t GetChisquare() const
Return the Chisquare after fitting. See ROOT::Fit::FitResult::Chi2()
Definition TF1.h:409
Double_t fXmin
Lower bounds for the range.
Definition TF1.h:212
std::unique_ptr< TMethodCall > fMethodCall
! Pointer to MethodCall in case of interpreted function
Definition TF1.h:233
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition TF1.cxx:3675
TAxis * GetZaxis() const
Get z axis of the function. (In case this object is a TF2 or TF3)
Definition TF1.cxx:2471
virtual Int_t GetNpar() const
Definition TF1.h:446
TString ProvideSaveName(Option_t *option)
Provide variable name for function for saving as primitive When TH1 or TGraph stores list of function...
Definition TF1.cxx:3270
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition TF1.h:232
virtual Double_t * GetParameters() const
Definition TF1.h:485
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2531
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:2901
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a function.
Definition TF1.cxx:1301
EFType fType
Definition TF1.h:217
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1499
Int_t fNpx
Number of points used for the graphical representation.
Definition TF1.h:216
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TF1.cxx:1587
std::vector< Double_t > fSave
Array of fNsave function values.
Definition TF1.h:226
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:1774
virtual void SetParameters(const Double_t *params)
Definition TF1.h:618
std::vector< Double_t > fIntegral
! Integral of function binned on fNpx bins
Definition TF1.h:227
@ kFormula
Formula functions which can be stored,.
Definition TF1.h:204
virtual Int_t GetNpx() const
Definition TF1.h:455
Double_t fXmax
Upper bounds for the range.
Definition TF1.h:213
virtual Int_t GetNdim() const
Definition TF1.h:450
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:477
TAxis * GetXaxis() const
Get x axis of the function.
Definition TF1.cxx:2449
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:253
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
Int_t GetNpy() const
Definition TF2.h:81
TF3 defines a 3D 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:127
static TClass * Class()
TF3()
F3 default constructor.
Definition TF3.cxx:52
void Paint(Option_t *option="") override
Paint this 3-D function with its current attributes.
Definition TF3.cxx:569
Int_t GetNpz() const
Definition TF3.h:78
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:381
Bool_t IsInside(const Double_t *x) const override
Return kTRUE is the point is inside the function range.
Definition TF3.cxx:546
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TF3.cxx:248
Double_t fZmin
Lower bound for the range in z.
Definition TF3.h:31
TF3 & operator=(const TF3 &rhs)
Operator =.
Definition TF3.cxx:184
virtual void SetNpz(Int_t npz=30)
Set the number of points used to draw the function.
Definition TF3.cxx:726
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:353
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:806
void Copy(TObject &f3) const override
Copy this F3 to a new F3.
Definition TF3.cxx:209
Double_t FindMinMax(Double_t *x, bool findmax) const override
Return minimum/maximum value of the function.
Definition TF3.cxx:269
~TF3() override
F3 default destructor.
Definition TF3.cxx:194
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:337
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:781
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 iso-surfaces.
Definition TF3.cxx:233
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:710
virtual void SetClippingBoxOff()
Set the function clipping box (for drawing) "off".
Definition TF3.cxx:594
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:224
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:520
void Streamer(TBuffer &) override
Stream an object of class TF3.
Definition TF3.cxx:757
static void InitStandardFunctions()
Create the basic function objects.
Definition TF3.cxx:506
TH1 * CreateHistogram() override
Create a histogram for axis range.
Definition TF3.cxx:557
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:603
Double_t GetSave(const Double_t *x) override
Get value corresponding to X in array of fSave values.
Definition TF3.cxx:454
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:131
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TF3.cxx:660
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
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:9170
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition TH1.cxx:4662
void Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6417
3-D histogram with a float per channel (see TH1 documentation)
Definition TH3.h:369
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Mother of all ROOT objects.
Definition TObject.h:42
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
void MakeZombie()
Definition TObject.h:55
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:844
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1070
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
Basic string class.
Definition TString.h:137
void ToLower()
Change string to lower-case.
Definition TString.cxx:1190
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1122
const char * Data() const
Definition TString.h:385
TString & Append(const char *cs)
Definition TString.h:582
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:661
virtual void ProcessMessage(const char *mess, const TObject *obj)=0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Definition TMath.h:915
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:783
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
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:329
Double_t Infinity()
Returns an infinity as defined by the IEEE standard.
Definition TMath.h:930
TLine l
Definition textangle.C:4
auto * tt
Definition textangle.C:16