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