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
53TF12::TF12(const char *name, TF2 *f2, Double_t xy, Option_t *option, EAddToList addToGlobList)
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
123TF1 *TF12::DrawCopy(Option_t *option) const
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
138Double_t TF12::Eval(Double_t x, Double_t /*y*/, Double_t /*z*/, Double_t /*t*/) const
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
156Double_t TF12::EvalPar(const Double_t *x, const Double_t *params)
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
183 TString f12Name = TF1::ProvideSaveName(option);
184
185 out << " \n";
186 out << " TF12 *" << f12Name << " = new TF12(\"" << "*" << GetName() << "\", " << f2Name << ", " << fXY << ", "
187 << (fCase ? "\"y\"" : "\"x\"") << ");\n";
188
189 SavePrimitiveNameTitle(out, f12Name);
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
200 SavePrimitiveDraw(out, f12Name, option);
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
211void TF12::SetXY(Double_t xy)
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));
217 if (fHistogram) fHistogram->SetTitle(GetTitle());
218 if (gPad) gPad->Modified();
219}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
char name[80]
Definition TGX11.cxx:148
#define gInterpreter
#define gPad
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
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
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
virtual void SetXY(Double_t xy)
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
void Copy(TObject &f12) const override
Copy this to obj.
~TF12() override
TF1 * DrawCopy(Option_t *option="") const override
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
Definition TF1.h:182
virtual Double_t GetXmax() const
Definition TF1.h:525
TAxis * GetYaxis() const
TString ProvideSaveName(Option_t *option)
TH1 * fHistogram
! Pointer to histogram used for visualisation
Definition TF1.h:232
void SetTitle(const char *title="") override
Set the title of the TNamed.
void Copy(TObject &f1) const override
Copy this to obj.
virtual Double_t GetXmin() const
Definition TF1.h:521
TAxis * GetXaxis() const
Definition TF2.h:29
virtual Double_t GetYmax() const
Definition TF2.h:97
virtual Double_t GetYmin() const
Definition TF2.h:96
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
Mother of all ROOT objects.
Definition TObject.h:42
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:204
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:888
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:845
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
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:2385
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
Double_t x[n]
Definition legend1.C:17
gr SetName("gr")