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