Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TF12.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 05/04/2003
3
4/*************************************************************************
5 * Copyright (C) 1995-2003, 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 "TF12.h"
13#include "TH1.h"
14#include "TVirtualPad.h"
15
17
18/** \class TF12
19 \ingroup Functions
20 A projection of a TF2 along X or Y
21
22It has the same behaviour as a TF1
23
24Example of a function
25
26Begin_Macro(source)
27{
28 auto f2 = new TF2("f2","sin(x)*sin(y)/(x*y)",0,5,0,5);
29 auto f12 = new TF12("f12",f2,0.1,"y");
30 f12->Draw();
31}
32End_Macro
33
34*/
35
36////////////////////////////////////////////////////////////////////////////////
37/// TF12 default constructor
38
40{
41 fCase = 0;
42 fF2 = nullptr;
43 fXY = 0;
44}
45
46
47////////////////////////////////////////////////////////////////////////////////
48/// TF12 normal constructor.
49///
50/// Create a TF12 (special TF1) from a projection of a TF2
51/// for a fix value of Y if option="X" or X if option="Y"
52/// This value may be changed at any time via TF12::SetXY(xy)
53
55 :TF1(name,"x",0,0)
56{
58 fF2 = f2;
59 TString opt=option;
60 opt.ToLower();
61 if (!f2) {
62 Error("TF12","Pointer to TF2 is null");
63 return;
64 }
65 SetXY(xy);
66 if (opt.Contains("y")) {
67 fXmin = f2->GetYmin();
68 fXmax = f2->GetYmax();
69 fCase = 1;
70 } else {
71 fXmin = f2->GetXmin();
72 fXmax = f2->GetXmax();
73 fCase = 0;
74 }
75}
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// F2 default destructor.
80
82{
83}
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Copy constructor.
88
89TF12::TF12(const TF12 &f12) : TF1(f12)
90{
91 f12.TF12::Copy(*this);
92}
93
94
95////////////////////////////////////////////////////////////////////////////////
96/// Copy this F2 to a new F2.
97
98void TF12::Copy(TObject &obj) const
99{
100 TF1::Copy(obj);
101 ((TF12&)obj).fXY = fXY;
102 ((TF12&)obj).fCase = fCase;
103 ((TF12&)obj).fF2 = fF2;
104}
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Draw a copy of this function with its current attributes.
109///
110/// This function MUST be used instead of Draw when you want to draw
111/// the same function with different parameters settings in the same canvas.
112///
113/// Possible option values are:
114///
115/// option | description
116/// -------|----------------------------------------
117/// "SAME" | superimpose on top of existing picture
118/// "L" | connect all computed points with a straight line
119/// "C" | connect all computed points with a smooth curve
120///
121/// Note that the default value is "F". Therefore to draw on top
122/// of an existing picture, specify option "SL"
123
125{
126 TF12 *newf2 = new TF12();
127 Copy(*newf2);
128 newf2->AppendPad(option);
129 newf2->SetBit(kCanDelete);
130 return newf2;
131}
132
133
134////////////////////////////////////////////////////////////////////////////////
135/// Evaluate this formula
136///
137/// Computes the value of the referenced TF2 for a fix value of X or Y
138
140{
141 if (!fF2) return 0;
142 if (fCase == 0) {
143 return fF2->Eval(x,fXY,0);
144 } else {
145 return fF2->Eval(fXY,x,0);
146 }
147}
148
149
150////////////////////////////////////////////////////////////////////////////////
151/// Evaluate this function at point x[0]
152///
153/// x[0] is the value along X if fCase =0, the value along Y if fCase=1
154/// if params is non null, the array will be used instead of the internal TF2
155/// parameters
156
158{
159 if (!fF2) return 0;
160 Double_t xx[2];
161 if (fCase == 0) {
162 xx[0] = x[0];
163 xx[1] = fXY;
164 } else {
165 xx[0] = fXY;
166 xx[1] = x[0];
167 }
168 fF2->InitArgs(xx,params);
169 return fF2->EvalPar(xx,params);
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Save primitive as a C++ statement(s) on output stream out
175
176void TF12::SavePrimitive(std::ostream & /*out*/, Option_t * /*option*/ /*= ""*/)
177{
178 Error("SavePrimitive","Function not yet implemented");
179}
180
181
182////////////////////////////////////////////////////////////////////////////////
183/// Set the value of the constant for the TF2
184///
185/// constant in X when projecting along Y
186/// constant in Y when projecting along X
187/// The function title is set to include the value of the constant
188/// The current pad is updated
189
191{
192 fXY = xy;
193 if (!fF2) return;
194 if (fCase == 0) SetTitle(TString::Format("%s (y=%g)",fF2->GetTitle(),xy));
195 else SetTitle(TString::Format("%s (x=%g)",fF2->GetTitle(),xy));
197 if (gPad) gPad->Modified();
198}
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t option
Option_t Option_t TPoint xy
char name[80]
Definition TGX11.cxx:110
#define gPad
A projection of a TF2 along X or Y.
Definition TF12.h:25
Int_t fCase
Projection along X(0), or Y(1)
Definition TF12.h:29
Double_t fXY
Value along Y (if projection X) or X (if projection Y)
Definition TF12.h:28
Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr) override
Evaluate this function at point x[0].
Definition TF12.cxx:157
TF12()
TF12 default constructor.
Definition TF12.cxx:39
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TF12.cxx:176
void Copy(TObject &f12) const override
Copy this F2 to a new F2.
Definition TF12.cxx:98
~TF12() override
F2 default destructor.
Definition TF12.cxx:81
virtual void SetXY(Double_t xy)
Set the value of the constant for the TF2.
Definition TF12.cxx:190
TF1 * DrawCopy(Option_t *option="") const override
Draw a copy of this function with its current attributes.
Definition TF12.cxx:124
TF2 * fF2
Pointer to the mother TF2.
Definition TF12.h:30
Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const override
Evaluate this formula.
Definition TF12.cxx:139
1-Dim function class
Definition TF1.h:233
virtual Double_t GetXmax() const
Definition TF1.h:582
Double_t fXmin
Lower bounds for the range.
Definition TF1.h:263
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition TF1.h:283
void SetTitle(const char *title="") override
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
Definition TF1.cxx:3558
void Copy(TObject &f1) const override
Copy this F1 to a new F1.
Definition TF1.cxx:1007
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2482
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1470
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition TF1.cxx:1441
Double_t fXmax
Upper bounds for the range.
Definition TF1.h:264
virtual Double_t GetXmin() const
Definition TF1.h:578
A 2-Dim function with parameters.
Definition TF2.h:29
virtual Double_t GetYmax() const
Definition TF2.h:112
virtual Double_t GetYmin() const
Definition TF2.h:111
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6686
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Mother of all ROOT objects.
Definition TObject.h:41
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Double_t x[n]
Definition legend1.C:17