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
16
17/** \class TF12
18 \ingroup Functions
19 A projection of a TF2 along X or Y
20
21It has the same behaviour as a TF1
22
23Example of a function
24
25Begin_Macro(source)
26{
27 auto f2 = new TF2("f2","sin(x)*sin(y)/(x*y)",0,5,0,5);
28 auto f12 = new TF12("f12",f2,0.1,"y");
29 f12->Draw();
30}
31End_Macro
32
33*/
34
35////////////////////////////////////////////////////////////////////////////////
36/// TF12 default constructor
37
39{
40 fCase = 0;
41 fF2 = nullptr;
42 fXY = 0;
43}
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// TF12 normal constructor.
48///
49/// Create a TF12 (special TF1) from a projection of a TF2
50/// for a fix value of Y if option="X" or X if option="Y"
51/// This value may be changed at any time via TF12::SetXY(xy)
52
54 :TF1(name, "x", 0, 0, addToGlobList)
55{
57 fF2 = f2;
58 TString opt=option;
59 opt.ToLower();
60 if (!f2) {
61 Error("TF12","Pointer to TF2 is null");
62 return;
63 }
64 SetXY(xy);
65 if (opt.Contains("y")) {
66 fXmin = f2->GetYmin();
67 fXmax = f2->GetYmax();
68 fCase = 1;
69 } else {
70 fXmin = f2->GetXmin();
71 fXmax = f2->GetXmax();
72 fCase = 0;
73 }
74}
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// F2 default destructor.
79
81{
82}
83
84
85////////////////////////////////////////////////////////////////////////////////
86/// Copy constructor.
87
88TF12::TF12(const TF12 &f12) : TF1(f12)
89{
90 f12.TF12::Copy(*this);
91}
92
93
94////////////////////////////////////////////////////////////////////////////////
95/// Copy this F2 to a new F2.
96
97void TF12::Copy(TObject &obj) const
98{
99 TF1::Copy(obj);
100 ((TF12&)obj).fXY = fXY;
101 ((TF12&)obj).fCase = fCase;
102 ((TF12&)obj).fF2 = fF2;
103}
104
105
106////////////////////////////////////////////////////////////////////////////////
107/// Draw a copy of this function with its current attributes.
108///
109/// This function MUST be used instead of Draw when you want to draw
110/// the same function with different parameters settings in the same canvas.
111///
112/// Possible option values are:
113///
114/// option | description
115/// -------|----------------------------------------
116/// "SAME" | superimpose on top of existing picture
117/// "L" | connect all computed points with a straight line
118/// "C" | connect all computed points with a smooth curve
119///
120/// Note that the default value is "F". Therefore to draw on top
121/// of an existing picture, specify option "SL"
122
124{
125 TF12 *newf2 = new TF12();
126 Copy(*newf2);
127 newf2->AppendPad(option);
128 newf2->SetBit(kCanDelete);
129 return newf2;
130}
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Evaluate this formula
135///
136/// Computes the value of the referenced TF2 for a fix value of X or Y
137
139{
140 if (!fF2) return 0;
141 if (fCase == 0) {
142 return fF2->Eval(x,fXY,0);
143 } else {
144 return fF2->Eval(fXY,x,0);
145 }
146}
147
148
149////////////////////////////////////////////////////////////////////////////////
150/// Evaluate this function at point x[0]
151///
152/// x[0] is the value along X if fCase =0, the value along Y if fCase=1
153/// if params is non null, the array will be used instead of the internal TF2
154/// parameters
155
157{
158 if (!fF2) return 0;
159 Double_t xx[2];
160 if (fCase == 0) {
161 xx[0] = x[0];
162 xx[1] = fXY;
163 } else {
164 xx[0] = fXY;
165 xx[1] = x[0];
166 }
167 fF2->InitArgs(xx,params);
168 return fF2->EvalPar(xx,params);
169}
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Save primitive as a C++ statement(s) on output stream out
174
175void TF12::SavePrimitive(std::ostream &out, Option_t *option)
176{
177 thread_local Int_t save_f2_id = 9000;
178
179 fF2->SavePrimitive(out, TString::Format("nodraw#%d", ++save_f2_id));
180
181 TString f2Name = gInterpreter->MapCppName(TString::Format("%s%d", fF2->GetName(), save_f2_id));
182
184
185 out << " \n";
186 out << " TF12 *" << f12Name << " = new TF12(\"" << "*" << GetName() << "\", " << f2Name << ", " << fXY << ", "
187 << (fCase ? "\"y\"" : "\"x\"") << ");\n";
188
190
191 SaveFillAttributes(out, f12Name, -1, 0);
192 SaveMarkerAttributes(out, f12Name, -1, -1, -1);
193 SaveLineAttributes(out, f12Name, -1, -1, -1);
194
195 if (fHistogram && !strstr(option, "same")) {
196 GetXaxis()->SaveAttributes(out, f12Name, "->GetXaxis()");
197 GetYaxis()->SaveAttributes(out, f12Name, "->GetYaxis()");
198 }
199
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Set the value of the constant for the TF2
205///
206/// constant in X when projecting along Y
207/// constant in Y when projecting along X
208/// The function title is set to include the value of the constant
209/// The current pad is updated
210
212{
213 fXY = xy;
214 if (!fF2) return;
215 if (fCase == 0) SetTitle(TString::Format("%s (y=%g)",fF2->GetTitle(),xy));
216 else SetTitle(TString::Format("%s (x=%g)",fF2->GetTitle(),xy));
218 if (gPad) gPad->Modified();
219}
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 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: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:714
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:156
TF12()
TF12 default constructor.
Definition TF12.cxx:38
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TF12.cxx:175
void Copy(TObject &f12) const override
Copy this F2 to a new F2.
Definition TF12.cxx:97
~TF12() override
F2 default destructor.
Definition TF12.cxx:80
virtual void SetXY(Double_t xy)
Set the value of the constant for the TF2.
Definition TF12.cxx:211
TF1 * DrawCopy(Option_t *option="") const override
Draw a copy of this function with its current attributes.
Definition TF12.cxx:123
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:138
1-Dim function class
Definition TF1.h:182
virtual Double_t GetXmax() const
Definition TF1.h:540
EAddToList
Add to list behavior.
Definition TF1.h:189
TAxis * GetYaxis() const
Get y axis of the function.
Definition TF1.cxx:2436
Double_t fXmin
Lower bounds for the range.
Definition TF1.h:212
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
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:3589
void Copy(TObject &f1) const override
Copy this F1 to a new F1.
Definition TF1.cxx:1006
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2507
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=nullptr)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1475
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:1446
Double_t fXmax
Upper bounds for the range.
Definition TF1.h:213
virtual Double_t GetXmin() const
Definition TF1.h:536
TAxis * GetXaxis() const
Get x axis of the function.
Definition TF1.cxx:2425
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:862
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6766
void SavePrimitiveNameTitle(std::ostream &out, const char *variable_name)
Save object name and title into the output stream "out".
Definition TNamed.cxx:135
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:149
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:138
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
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:2384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
Double_t x[n]
Definition legend1.C:17