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