Logo ROOT   6.12/07
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  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 
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 }
TF12()
TF12 default constructor.
Definition: TF12.cxx:33
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:904
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:125
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
virtual void SetXY(Double_t xy)
Set the value of the constant for the TF2.
Definition: TF12.cxx:184
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:92
TH1 * fHistogram
Parent object hooking this function (if one)
Definition: TF1.h:255
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
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:3436
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:1334
#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:570
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition: TF1.cxx:2354
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:133
#define gPad
Definition: TVirtualPad.h:285
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6154
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition: TF1.cxx:1363
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:170
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:151