Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 thread_local Int_t save_f2_id = 9000;
179
180 fF2->SavePrimitive(out, TString::Format("nodraw#%d", ++save_f2_id));
181
182 TString f2Name = gInterpreter->MapCppName(TString::Format("%s%d", fF2->GetName(), save_f2_id));
183
185
186 out << " \n";
187 out << " TF12 *" << f12Name << " = new TF12(\"" << "*" << GetName() << "\", " << f2Name << ", " << fXY << ", "
188 << (fCase ? "\"y\"" : "\"x\"") << ");\n";
189
191
192 SaveFillAttributes(out, f12Name, -1, 0);
193 SaveMarkerAttributes(out, f12Name, -1, -1, -1);
194 SaveLineAttributes(out, f12Name, -1, -1, -1);
195
196 if (fHistogram && !strstr(option, "same")) {
197 GetXaxis()->SaveAttributes(out, f12Name, "->GetXaxis()");
198 GetYaxis()->SaveAttributes(out, f12Name, "->GetYaxis()");
199 }
200
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Set the value of the constant for the TF2
206///
207/// constant in X when projecting along Y
208/// constant in Y when projecting along X
209/// The function title is set to include the value of the constant
210/// The current pad is updated
211
213{
214 fXY = xy;
215 if (!fF2) return;
216 if (fCase == 0) SetTitle(TString::Format("%s (y=%g)",fF2->GetTitle(),xy));
217 else SetTitle(TString::Format("%s (x=%g)",fF2->GetTitle(),xy));
219 if (gPad) gPad->Modified();
220}
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
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 xy
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
#define gPad
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:239
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:275
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
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:212
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:234
virtual Double_t GetXmax() const
Definition TF1.h:592
TAxis * GetYaxis() const
Get y axis of the function.
Definition TF1.cxx:2431
Double_t fXmin
Lower bounds for the range.
Definition TF1.h:264
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:3240
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition TF1.h:284
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:3584
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:2502
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:265
virtual Double_t GetXmin() const
Definition TF1.h:588
TAxis * GetXaxis() const
Get x axis of the function.
Definition TF1.cxx:2420
A 2-Dim function with parameters.
Definition TF2.h:29
virtual Double_t GetYmax() const
Definition TF2.h:113
virtual Double_t GetYmin() const
Definition TF2.h:112
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TF2.cxx:863
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6721
void SavePrimitiveNameTitle(std::ostream &out, const char *variable_name)
Save object name and title into the output stream "out".
Definition TNamed.cxx:136
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
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:150
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
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:822
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
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