[root] / trunk / hist / hist / src / TMultiGraph.cxx Repository:
ViewVC logotype

Annotation of /trunk/hist/hist/src/TMultiGraph.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11605 - (view) (download) (as text)
Original Path: trunk/graf/src/TMultiGraph.cxx

1 : brun 11605 // @(#)root/graf:$Name: $:$Id: TMultiGraph.cxx,v 1.19 2005/04/15 14:49:23 brun Exp $
2 : brun 754 // Author: Rene Brun 12/10/2000
3 :    
4 :     /*************************************************************************
5 :     * Copyright (C) 1995-2000, 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 "TROOT.h"
13 :     #include "TMultiGraph.h"
14 :     #include "TGraph.h"
15 :     #include "TH1.h"
16 :     #include "TVirtualPad.h"
17 : rdm 3748 #include "Riostream.h"
18 : brun 11226 #include "TVirtualFitter.h"
19 : brun 754
20 : brun 11226
21 : brun 754 #include <ctype.h>
22 :    
23 : brun 11226 extern void H1LeastSquareSeqnd(Int_t n, Double_t *a, Int_t idim, Int_t &ifail, Int_t k, Double_t *b);
24 : brun 754
25 :     ClassImp(TMultiGraph)
26 :    
27 :     //______________________________________________________________________________
28 :     //
29 :     // A TMultiGraph is a collection of TGraph (or derived) objects
30 :     // Use TMultiGraph::Add to add a new graph to the list.
31 :     // The TMultiGraph owns the objects in the list.
32 :     // Drawing options are the same as for TGraph
33 :     // Example;
34 :     // TGraph *gr1 = new TGraph(...
35 :     // TGraphErrors *gr2 = new TGraphErrors(...
36 :     // TMultiGraph *mg = new TMultiGraph();
37 : brun 4037 // mg->Add(gr1,"lp");
38 :     // mg->Add(gr2,"cp");
39 :     // mg->Draw("a");
40 :     //
41 :     // The drawing option for each TGraph may be specified as an optional
42 :     // second argument of the Add function.
43 :     // If a draw option is specified, it will be used to draw the graph,
44 :     // otherwise the graph will be drawn with the option specified in
45 :     // TMultiGraph::Draw
46 : brun 754
47 :     //______________________________________________________________________________
48 :     TMultiGraph::TMultiGraph(): TNamed()
49 :     {
50 :     // TMultiGraph default constructor
51 :    
52 :     fGraphs = 0;
53 : brun 11226 fFunctions = 0;
54 : brun 754 fHistogram = 0;
55 :     fMaximum = -1111;
56 :     fMinimum = -1111;
57 :     }
58 :    
59 :     //______________________________________________________________________________
60 :     TMultiGraph::TMultiGraph(const char *name, const char *title)
61 :     : TNamed(name,title)
62 :     {
63 :     // constructor with name and title
64 :     fGraphs = 0;
65 : brun 11226 fFunctions = 0;
66 : brun 754 fHistogram = 0;
67 :     fMaximum = -1111;
68 :     fMinimum = -1111;
69 :     }
70 :    
71 :     //______________________________________________________________________________
72 :     TMultiGraph::~TMultiGraph()
73 :     {
74 :     // TMultiGraph destructor
75 :    
76 :     if (!fGraphs) return;
77 : brun 5552 TGraph *g;
78 :     TIter next(fGraphs);
79 :     while ((g = (TGraph*) next())) {
80 :     g->ResetBit(kMustCleanup);
81 :     }
82 : brun 754 fGraphs->Delete();
83 :     delete fGraphs;
84 :     fGraphs = 0;
85 :     delete fHistogram;
86 :     fHistogram = 0;
87 : brun 11226 if (fFunctions) {
88 :     fFunctions->SetBit(kInvalidObject);
89 :     //special logic to support the case where the same object is
90 :     //added multiple times in fFunctions.
91 :     //This case happens when the same object is added with different
92 :     //drawing modes
93 :     TObject *obj;
94 :     while ((obj = fFunctions->First())) {
95 :     while(fFunctions->Remove(obj));
96 :     delete obj;
97 :     }
98 :     delete fFunctions;
99 :     }
100 : brun 754 }
101 :    
102 :     //______________________________________________________________________________
103 : brun 4037 void TMultiGraph::Add(TGraph *graph, Option_t *chopt)
104 : brun 754 {
105 :     // add a new graph to the list of graphs
106 : brun 6639 // note that the graph is now owned by the TMultigraph.
107 :     // Deleting the TMultiGraph object will automatically delete the graphs.
108 :     // You should not delete the graphs when the TMultigraph is still active.
109 : rdm 3742
110 : brun 754 if (!fGraphs) fGraphs = new TList();
111 : brun 5552 graph->SetBit(kMustCleanup);
112 : brun 4037 fGraphs->Add(graph,chopt);
113 : brun 754 }
114 :    
115 :     //______________________________________________________________________________
116 :     void TMultiGraph::Browse(TBrowser *)
117 :     {
118 :     Draw("alp");
119 :     gPad->Update();
120 :     }
121 :    
122 :     //______________________________________________________________________________
123 :     Int_t TMultiGraph::DistancetoPrimitive(Int_t px, Int_t py)
124 :     {
125 :     // Compute distance from point px,py to each graph
126 :     //
127 :    
128 :     //*-*- Are we on the axis?
129 :     const Int_t kMaxDiff = 10;
130 :     Int_t distance = 9999;
131 :     if (fHistogram) {
132 :     distance = fHistogram->DistancetoPrimitive(px,py);
133 :     if (distance <= 0) return distance;
134 :     }
135 :    
136 :    
137 :     //*-*- Loop on the list of graphs
138 :     if (!fGraphs) return distance;
139 :     TGraph *g;
140 :     TIter next(fGraphs);
141 :     while ((g = (TGraph*) next())) {
142 :     Int_t dist = g->DistancetoPrimitive(px,py);
143 : brun 4915 if (dist <= 0) return 0;
144 : brun 754 if (dist < kMaxDiff) {gPad->SetSelected(g); return dist;}
145 :     }
146 :     return distance;
147 :     }
148 :    
149 :     //______________________________________________________________________________
150 :     void TMultiGraph::Draw(Option_t *option)
151 :     {
152 :     //*-*-*-*-*-*-*-*-*-*-*Draw this multigraph with its current attributes*-*-*-*-*-*-*
153 :     //*-* ==========================================
154 :     //
155 :     // Options to draw a graph are described in TGraph::PainGraph
156 : brun 4037 //
157 :     // The drawing option for each TGraph may be specified as an optional
158 : brun 11584 // second argument of the Add function. You can use GetGraphDrawOption
159 :     // to return this option.
160 : brun 4037 // If a draw option is specified, it will be used to draw the graph,
161 :     // otherwise the graph will be drawn with the option specified in
162 : brun 11584 // TMultiGraph::Draw. Use GetDrawOption to return the option specified
163 :     // when drawin the TMultiGraph.
164 : brun 754
165 :     AppendPad(option);
166 :     }
167 :    
168 :     //______________________________________________________________________________
169 : brun 11226 Int_t TMultiGraph::Fit(const char *fname, Option_t *option, Option_t *, Axis_t xmin, Axis_t xmax)
170 :     {
171 :     //*-*-*-*-*-*Fit this graph with function with name fname*-*-*-*-*-*-*-*-*-*
172 :     //*-* ============================================
173 :     // interface to TF1::Fit(TF1 *f1...
174 :    
175 :     char *linear;
176 : brun 11231 linear= (char*)strstr(fname, "++");
177 : brun 11226 TF1 *f1=0;
178 :     if (linear)
179 :     f1=new TF1(fname, fname, xmin, xmax);
180 :     else {
181 :     f1 = (TF1*)gROOT->GetFunction(fname);
182 :     if (!f1) { Printf("Unknown function: %s",fname); return -1; }
183 :     }
184 :    
185 :     return Fit(f1,option,"",xmin,xmax);
186 :     }
187 :    
188 :     //______________________________________________________________________________
189 :     Int_t TMultiGraph::Fit(TF1 *f1, Option_t *option, Option_t *, Axis_t rxmin, Axis_t rxmax)
190 :     {
191 :     //*-*-*-*-*-*-*-*-*-*-*Fit this multigraph with function f1*-*-*-*-*-*-*-*-*-*
192 :     //*-* ==================================
193 :     //
194 :     // In this function all graphs of the multigraph are fitted simultaneously
195 :     //
196 :     // f1 is an already predefined function created by TF1.
197 :     // Predefined functions such as gaus, expo and poln are automatically
198 :     // created by ROOT.
199 :     //
200 :     // The list of fit options is given in parameter option.
201 :     // option = "W" Set all errors to 1
202 :     // = "U" Use a User specified fitting algorithm (via SetFCN)
203 :     // = "Q" Quiet mode (minimum printing)
204 :     // = "V" Verbose mode (default is between Q and V)
205 :     // = "B" Use this option when you want to fix one or more parameters
206 :     // and the fitting function is like "gaus","expo","poln","landau".
207 :     // = "R" Use the Range specified in the function range
208 :     // = "N" Do not store the graphics function, do not draw
209 :     // = "0" Do not plot the result of the fit. By default the fitted function
210 :     // is drawn unless the option"N" above is specified.
211 :     // = "+" Add this new fitted function to the list of fitted functions
212 :     // (by default, any previous function is deleted)
213 :     // = "C" In case of linear fitting, not calculate the chisquare
214 :     // (saves time)
215 : brun 11605 // = "F" If fitting a polN, switch to minuit fitter
216 : brun 11226 //
217 :     // When the fit is drawn (by default), the parameter goption may be used
218 :     // to specify a list of graphics options. See TGraph::Paint for a complete
219 :     // list of these options.
220 :     //
221 :     // In order to use the Range option, one must first create a function
222 :     // with the expression to be fitted. For example, if your graph
223 :     // has a defined range between -4 and 4 and you want to fit a gaussian
224 :     // only in the interval 1 to 3, you can do:
225 :     // TF1 *f1 = new TF1("f1","gaus",1,3);
226 :     // graph->Fit("f1","R");
227 :     //
228 :     //
229 :     // who is calling this function
230 :     // ============================
231 :     // Note that this function is called when calling TGraphErrors::Fit
232 :     // or TGraphAsymmErrors::Fit ot TGraphBentErrors::Fit
233 :     // see the discussion below on the errors calulation.
234 :     //
235 :     // Setting initial conditions
236 :     // ==========================
237 :     // Parameters must be initialized before invoking the Fit function.
238 :     // The setting of the parameter initial values is automatic for the
239 :     // predefined functions : poln, expo, gaus, landau. One can however disable
240 :     // this automatic computation by specifying the option "B".
241 :     // You can specify boundary limits for some or all parameters via
242 :     // f1->SetParLimits(p_number, parmin, parmax);
243 :     // if parmin>=parmax, the parameter is fixed
244 :     // Note that you are not forced to fix the limits for all parameters.
245 :     // For example, if you fit a function with 6 parameters, you can do:
246 :     // func->SetParameters(0,3.1,1.e-6,0.1,-8,100);
247 :     // func->SetParLimits(4,-10,-4);
248 :     // func->SetParLimits(5, 1,1);
249 :     // With this setup, parameters 0->3 can vary freely
250 :     // Parameter 4 has boundaries [-10,-4] with initial value -8
251 :     // Parameter 5 is fixed to 100.
252 :     //
253 :     // Fit range
254 :     // =========
255 :     // The fit range can be specified in two ways:
256 :     // - specify rxmax > rxmin (default is rxmin=rxmax=0)
257 :     // - specify the option "R". In this case, the function will be taken
258 :     // instead of the full graph range.
259 :     //
260 :     // Changing the fitting function
261 :     // =============================
262 :     // By default the fitting function GraphFitChisquare is used.
263 :     // To specify a User defined fitting function, specify option "U" and
264 :     // call the following functions:
265 :     // TVirtualFitter::Fitter(mygraph)->SetFCN(MyFittingFunction)
266 :     // where MyFittingFunction is of type:
267 :     // extern void MyFittingFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag);
268 :     //
269 :     // How errors are used in the chisquare function (see TFitter GraphFitChisquare)// Access to the fit results
270 :     // ============================================
271 :     // In case of a TGraphErrors object, ex, the error along x, is projected
272 :     // along the y-direction by calculating the function at the points x-exlow and
273 :     // x+exhigh.
274 :     //
275 :     // The chisquare is computed as the sum of the quantity below at each point:
276 :     //
277 :     // (y - f(x))**2
278 :     // -----------------------------------
279 :     // ey**2 + ((f(x+exhigh) - f(x-exlow))/2)**2
280 :     //
281 :     // where x and y are the point coordinates.
282 :     //
283 :     // In case the function lies below (above) the data point, ey is ey_low (ey_high).
284 :     //
285 :     // thanks to Andy Haas (haas@yahoo.com) for adding the case with TGraphasymmerrors
286 :     // University of Washington
287 :     //
288 :     // a little different approach to approximating the uncertainty in y because of the
289 :     // errors in x, is to make it equal the error in x times the slope of the line.
290 :     // The improvement, compared to the first method (f(x+ exhigh) - f(x-exlow))/2
291 :     // is of (error of x)**2 order. This approach is called "effective variance method".
292 :     // This improvement has been made in version 4.00/08 by Anna Kreshuk.
293 :     //
294 :     // Associated functions
295 :     // ====================
296 :     // One or more object (typically a TF1*) can be added to the list
297 :     // of functions (fFunctions) associated to each graph.
298 :     // When TGraph::Fit is invoked, the fitted function is added to this list.
299 :     // Given a graph gr, one can retrieve an associated function
300 :     // with: TF1 *myfunc = gr->GetFunction("myfunc");
301 :     //
302 :     // If the graph is made persistent, the list of
303 :     // associated functions is also persistent. Given a pointer (see above)
304 :     // to an associated function myfunc, one can retrieve the function/fit
305 :     // parameters with calls such as:
306 :     // Double_t chi2 = myfunc->GetChisquare();
307 :     // Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter
308 :     // Double_t err0 = myfunc->GetParError(0); //error on first parameter
309 :     //
310 :     // Fit Statistics
311 :     // ==============
312 :     // You can change the statistics box to display the fit parameters with
313 :     // the TStyle::SetOptFit(mode) method. This mode has four digits.
314 :     // mode = pcev (default = 0111)
315 :     // v = 1; print name/values of parameters
316 :     // e = 1; print errors (if e=1, v must be 1)
317 :     // c = 1; print Chisquare/Number of degress of freedom
318 :     // p = 1; print Probability
319 :     //
320 :     // For example: gStyle->SetOptFit(1011);
321 :     // prints the fit probability, parameter names/values, and errors.
322 :     // You can change the position of the statistics box with these lines
323 :     // (where g is a pointer to the TGraph):
324 :     //
325 :     // Root > TPaveStats *st = (TPaveStats*)g->GetListOfFunctions()->FindObject("stats")
326 :     // Root > st->SetX1NDC(newx1); //new x start position
327 :     // Root > st->SetX2NDC(newx2); //new x end position
328 :    
329 :    
330 :    
331 :     Int_t fitResult = 0;
332 :     Double_t xmin, xmax, ymin, ymax;
333 :     Int_t i, npar,nvpar,nparx;
334 :     Double_t par, we, al, bl;
335 :     Double_t eplus,eminus,eparab,globcc,amin,edm,errdef,werr;
336 :     Int_t np;
337 :     TF1 *fnew1;
338 :    
339 :     // Check validity of function
340 :     if (!f1) {
341 :     Error("Fit", "function may not be null pointer");
342 :     return 0;
343 :     }
344 :     if (f1->IsZombie()) {
345 :     Error("Fit", "function is zombie");
346 :     return 0;
347 :     }
348 :    
349 :     npar = f1->GetNpar();
350 :     if (npar <= 0) {
351 :     Error("Fit", "function %s has illegal number of parameters = %d", f1->GetName(), npar);
352 :     return 0;
353 :     }
354 :    
355 :     // Check that function has same dimension as graph
356 :     if (f1->GetNdim() > 1) {
357 :     Error("Fit", "function %s is not 1-D", f1->GetName());
358 :     return 0;
359 :     }
360 :    
361 :     TGraph *g;
362 :     TIter next(fGraphs);
363 :    
364 :     Double_t *arglist = new Double_t[100];
365 :     // Decode string choptin and fill fitOption structure
366 :     Foption_t fitOption;
367 :     fitOption.Quiet = 0;
368 :     fitOption.Verbose = 0;
369 :     fitOption.Bound = 0;
370 :     fitOption.Like = 0;
371 :     fitOption.W1 = 0;
372 :     fitOption.Errors = 0;
373 :     fitOption.Range = 0;
374 :     fitOption.Gradient= 0;
375 :     fitOption.Nograph = 0;
376 :     fitOption.Nostore = 0;
377 :     fitOption.Plus = 0;
378 :     fitOption.User = 0;
379 :     fitOption.Nochisq = 0;
380 : brun 11605 fitOption.Minuit = 0;
381 : brun 11226 TString opt = option;
382 :     opt.ToUpper();
383 :    
384 :     if (opt.Contains("U")) fitOption.User = 1;
385 :     if (opt.Contains("Q")) fitOption.Quiet = 1;
386 :     if (opt.Contains("V")){fitOption.Verbose = 1; fitOption.Quiet = 0;}
387 :     if (opt.Contains("W")) fitOption.W1 = 1;
388 :     if (opt.Contains("E")) fitOption.Errors = 1;
389 :     if (opt.Contains("R")) fitOption.Range = 1;
390 :     if (opt.Contains("N")) fitOption.Nostore = 1;
391 :     if (opt.Contains("0")) fitOption.Nograph = 1;
392 :     if (opt.Contains("+")) fitOption.Plus = 1;
393 :     if (opt.Contains("B")) fitOption.Bound = 1;
394 :     if (opt.Contains("C")) fitOption.Nochisq = 1;
395 : brun 11605 if (opt.Contains("F"))fitOption.Minuit = 1;
396 : brun 11226
397 :     if (rxmax > rxmin) {
398 :     xmin = rxmin;
399 :     xmax = rxmax;
400 :     } else {
401 :     g=(TGraph *)fGraphs->First();
402 :     if (!g) {
403 :     Error("Fit", "No graphs in the multigraph");
404 :     return 0;
405 :     }
406 :     Double_t *px, *py;
407 :     np=g->GetN();
408 :     px=g->GetX();
409 :     py=g->GetY();
410 :     xmin=px[0];
411 :     xmax=py[np-1];
412 :     ymin=px[0];
413 :     ymax=py[np-1];
414 :     Double_t err0=g->GetErrorX(0);
415 :     Double_t errn=g->GetErrorX(np-1);
416 :     if (err0 > 0) xmin -= 2*err0;
417 :     if (errn > 0) xmax += 2*errn;
418 :    
419 :     next.Reset();
420 :     while ((g = (TGraph*) next())) {
421 :     np=g->GetN();
422 :     px=g->GetX();
423 :     py=g->GetY();
424 :     for (i=0; i<np; i++) {
425 :     if (px[i] < xmin) xmin = px[i];
426 :     if (px[i] > xmax) xmax = px[i];
427 :     if (py[i] < ymin) ymin = py[i];
428 :     if (py[i] > ymax) ymax = py[i];
429 :     }
430 :     }
431 :     }
432 :    
433 :     ///////////////
434 :     //set the fitter
435 :     //////////////
436 : brun 11605
437 : brun 11226 Int_t special=f1->GetNumber();
438 :     Bool_t linear = f1->IsLinear();
439 :     if (special==299+npar)
440 :     linear=kTRUE;
441 : brun 11605 if (fitOption.Bound || fitOption.User || fitOption.Errors || fitOption.Minuit)
442 :     linear = kFALSE;
443 : brun 11226
444 :     char l[]="TLinearFitter";
445 :     Int_t strdiff = 0;
446 :     Bool_t IsSet = kFALSE;
447 :     if (TVirtualFitter::GetFitter()){
448 :     //Is a fitter already set? Is it linear?
449 :     IsSet = kTRUE;
450 :     strdiff = strcmp(TVirtualFitter::GetFitter()->IsA()->GetName(), l);
451 :     }
452 :     if (linear){
453 :     TClass *cl = gROOT->GetClass("TLinearFitter");
454 :     if (IsSet && strdiff!=0) {
455 :     delete TVirtualFitter::GetFitter();
456 :     IsSet=kFALSE;
457 :     }
458 :     if (!IsSet) {
459 :     TVirtualFitter::SetFitter((TVirtualFitter *)cl->New());
460 :     }
461 :     } else {
462 :     if (IsSet && strdiff==0){
463 :     delete TVirtualFitter::GetFitter();
464 :     IsSet=kFALSE;
465 :     }
466 :     if (!IsSet)
467 :     TVirtualFitter::SetFitter(0);
468 :     }
469 :    
470 :     TVirtualFitter *grFitter = TVirtualFitter::Fitter(this, f1->GetNpar());
471 :     grFitter->Clear();
472 :    
473 :     //*-*- Get pointer to the function by searching in the list of functions in ROOT
474 :     grFitter->SetUserFunc(f1);
475 :     grFitter->SetFitOption(fitOption);
476 :    
477 :     //*-*- Is a Fit range specified?
478 :     if (fitOption.Range) {
479 :     f1->GetRange(xmin, xmax);
480 :     } else {
481 :     f1->SetRange(xmin, xmax);
482 :     }
483 :    
484 : brun 11605 if (linear){
485 : brun 11226 grFitter->ExecuteCommand("FitMultiGraph", 0, 0);
486 :    
487 :     } else {
488 :    
489 :     //Int_t special = f1->GetNumber();
490 :     if (fitOption.Bound) special = 0;
491 :     if (special == 100) InitGaus(xmin,xmax);
492 :     else if (special == 400) InitGaus(xmin,xmax);
493 :     else if (special == 200) InitExpo(xmin,xmax);
494 :     else if (special == 299+npar) InitPolynom(xmin,xmax);
495 :    
496 :     //*-*- Some initialisations
497 :     if (!fitOption.Verbose) {
498 :     arglist[0] = -1;
499 :     grFitter->ExecuteCommand("SET PRINT", arglist,1);
500 :     arglist[0] = 0;
501 :     grFitter->ExecuteCommand("SET NOW", arglist,0);
502 :     }
503 :    
504 :     /////////////////////////////////////////////////////////
505 :     //*-*- Set error criterion for chisquare
506 :     arglist[0] = TVirtualFitter::GetErrorDef();
507 :     if (!fitOption.User) grFitter->SetFitMethod("MultiGraphFitChisquare");
508 :    
509 :    
510 :     fitResult = grFitter->ExecuteCommand("SET ERR",arglist,1);
511 :     if (fitResult != 0) {
512 :     // Abnormal termination, MIGRAD might not have converged on a
513 :     // minimum.
514 :     if (!fitOption.Quiet) {
515 :     Warning("Fit","Abnormal termination of minimization.");
516 :     }
517 :     delete [] arglist;
518 :     return fitResult;
519 :     }
520 :    
521 :     //*-*- Transfer names and initial values of parameters to Minuit
522 :     Int_t nfixed = 0;
523 :     for (i=0;i<npar;i++) {
524 :     par = f1->GetParameter(i);
525 :     f1->GetParLimits(i,al,bl);
526 :     if (al*bl != 0 && al >= bl) {
527 :     al = bl = 0;
528 :     arglist[nfixed] = i+1;
529 :     nfixed++;
530 :     }
531 :     we = 0.3*TMath::Abs(par);
532 :     if (we <= TMath::Abs(par)*1e-6) we = 1;
533 :     grFitter->SetParameter(i,f1->GetParName(i),par,we,al,bl);
534 :     }
535 :     if(nfixed > 0)grFitter->ExecuteCommand("FIX",arglist,nfixed); // Otto
536 :    
537 :     //*-*- Reset Print level
538 :     if (!fitOption.Quiet) {
539 :     if (fitOption.Verbose) { arglist[0] = 2; grFitter->ExecuteCommand("SET PRINT", arglist,1); }
540 :     else { arglist[0] = 0; grFitter->ExecuteCommand("SET PRINT", arglist,1); }
541 :     }
542 :     //*-*- Compute sum of squares of errors in the bin range
543 :     Bool_t hasErrors = kFALSE;
544 :     Double_t ex, ey, sumw2=0;
545 :     next.Reset();
546 :     while ((g = (TGraph*) next())) {
547 :     np=g->GetN();
548 :     for (i=0; i<np; i++){
549 :     ex=g->GetErrorX(i);
550 :     ey=g->GetErrorY(i);
551 :     if (ex > 0 || ey > 0) hasErrors=kTRUE;
552 :     sumw2+=ey*ey;
553 :     }
554 :     }
555 :    
556 :     //*-*- Perform minimization
557 :    
558 :     arglist[0] = TVirtualFitter::GetMaxIterations();
559 :     arglist[1] = sumw2*TVirtualFitter::GetPrecision();
560 :     grFitter->ExecuteCommand("MIGRAD",arglist,2);
561 :     if (fitOption.Errors) {
562 :     grFitter->ExecuteCommand("HESSE",arglist,0);
563 :     grFitter->ExecuteCommand("MINOS",arglist,0);
564 :     }
565 :    
566 :     grFitter->GetStats(amin,edm,errdef,nvpar,nparx);
567 :     f1->SetChisquare(amin);
568 :     Int_t ndf = f1->GetNumberFitPoints()-npar+nfixed;
569 :     f1->SetNDF(ndf);
570 :    
571 :     //*-*- Get return status
572 :     char parName[50];
573 :     for (i=0;i<npar;i++) {
574 :     grFitter->GetParameter(i,parName, par,we,al,bl);
575 :     if (!fitOption.Errors) werr = we;
576 :     else {
577 :     grFitter->GetErrors(i,eplus,eminus,eparab,globcc);
578 :     if (eplus > 0 && eminus < 0) werr = 0.5*(eplus-eminus);
579 :     else werr = we;
580 :     }
581 :     if (!hasErrors && ndf > 1) werr *= TMath::Sqrt(amin/(ndf-1));
582 :     f1->SetParameter(i,par);
583 :     f1->SetParError(i,werr);
584 :     }
585 :     }
586 :     //*-*- Print final values of parameters.
587 :     if (!fitOption.Quiet) {
588 :     if (fitOption.Errors) grFitter->PrintResults(4,amin);
589 :     else grFitter->PrintResults(3,amin);
590 :     }
591 :     delete [] arglist;
592 :    
593 :     //*-*- Store fitted function in histogram functions list and draw
594 :    
595 :     if (!fitOption.Nostore) {
596 :     if (!fFunctions) fFunctions = new TList;
597 :     if (!fitOption.Plus) {
598 :     TIter next2(fFunctions, kIterBackward);
599 :     TObject *obj;
600 :     while ((obj = next2())) {
601 :     if (obj->InheritsFrom(TF1::Class())){
602 :     obj = fFunctions->Remove(obj);
603 :     delete obj;
604 :     }
605 :     }
606 :     }
607 :     fnew1 = new TF1();
608 :     f1->Copy(*fnew1);
609 :     fFunctions->Add(fnew1);
610 :     fnew1->SetParent(this);
611 :     fnew1->Save(xmin,xmax,0,0,0,0);
612 :     if (fitOption.Nograph) fnew1->SetBit(TF1::kNotDraw);
613 :     fnew1->SetBit(TFormula::kNotGlobal);
614 :    
615 :     if (TestBit(kCanDelete)) return fitResult;
616 :     if (gPad) gPad->Modified();
617 :     }
618 :    
619 :    
620 :     return fitResult;
621 :    
622 :     }
623 :    
624 :    
625 :     //______________________________________________________________________________
626 : brun 11584 Option_t *TMultiGraph::GetGraphDrawOption(const TGraph *gr) const
627 :     {
628 :     // Return the draw option for the TGraph gr in this TMultiGraph
629 :     // The return option is the one specified when calling TMultiGraph::Add(gr,option).
630 :    
631 :     if (!fGraphs || !gr) return "";
632 :     TListIter next(fGraphs);
633 :     TObject *obj;
634 :     while ((obj = next())) {
635 : brun 11600 if (obj == (TObject*)gr) return next.GetOption();
636 : brun 11584 }
637 :     return "";
638 :     }
639 :    
640 :     //______________________________________________________________________________
641 : brun 11226 void TMultiGraph::InitGaus(Double_t xmin, Double_t xmax)
642 :     {
643 :     //*-*-*-*-*-*Compute Initial values of parameters for a gaussian*-*-*-*-*-*-*
644 :     //*-* ===================================================
645 :    
646 :     Double_t allcha, sumx, sumx2, x, val, rms, mean;
647 :     Int_t bin;
648 :     const Double_t sqrtpi = 2.506628;
649 :    
650 :     //*-*- Compute mean value and RMS of the graph in the given range
651 :     Int_t np = 0;
652 :     allcha = sumx = sumx2 = 0;
653 :     TGraph *g;
654 :     TIter next(fGraphs);
655 :     Double_t *px, *py;
656 :     Int_t npp; //number of points in each graph
657 :     while ((g = (TGraph*) next())) {
658 :     px=g->GetX();
659 :     py=g->GetY();
660 :     npp=g->GetN();
661 :     for (bin=0; bin<npp; bin++){
662 :     x=px[bin];
663 :     if (x<xmin || x>xmax) continue;
664 :     np++;
665 :     val=py[bin];
666 :     sumx+=val*x;
667 :     sumx2+=val*x*x;
668 :     allcha+=val;
669 :     }
670 :     }
671 :     if (np == 0 || allcha == 0) return;
672 :     mean = sumx/allcha;
673 :     rms = TMath::Sqrt(sumx2/allcha - mean*mean);
674 :    
675 :     Double_t binwidx = TMath::Abs((xmax-xmin)/np);
676 :     if (rms == 0) rms = 1;
677 :     TVirtualFitter *grFitter = TVirtualFitter::GetFitter();
678 :     TF1 *f1 = (TF1*)grFitter->GetUserFunc();
679 :     f1->SetParameter(0,binwidx*allcha/(sqrtpi*rms));
680 :     f1->SetParameter(1,mean);
681 :     f1->SetParameter(2,rms);
682 :     f1->SetParLimits(2,0,10*rms);
683 :     }
684 :    
685 :     //______________________________________________________________________________
686 :     void TMultiGraph::InitExpo(Double_t xmin, Double_t xmax)
687 :     {
688 :     //*-*-*-*-*-*Compute Initial values of parameters for an exponential*-*-*-*-*
689 :     //*-* =======================================================
690 :    
691 :     Double_t constant, slope;
692 :     Int_t ifail;
693 :    
694 :     LeastSquareLinearFit(-1, constant, slope, ifail, xmin, xmax);
695 :    
696 :     TVirtualFitter *grFitter = TVirtualFitter::GetFitter();
697 :     TF1 *f1 = (TF1*)grFitter->GetUserFunc();
698 :     f1->SetParameter(0,constant);
699 :     f1->SetParameter(1,slope);
700 :    
701 :     }
702 :    
703 :     //______________________________________________________________________________
704 :     void TMultiGraph::InitPolynom(Double_t xmin, Double_t xmax)
705 :     {
706 :     //*-*-*-*-*-*Compute Initial values of parameters for a polynom*-*-*-*-*-*-*
707 :     //*-* ===================================================
708 :    
709 :     Double_t fitpar[25];
710 :    
711 :     TVirtualFitter *grFitter = TVirtualFitter::GetFitter();
712 :     TF1 *f1 = (TF1*)grFitter->GetUserFunc();
713 :     Int_t npar = f1->GetNpar();
714 :    
715 :     LeastSquareFit(npar, fitpar, xmin, xmax);
716 :    
717 :     for (Int_t i=0;i<npar;i++) f1->SetParameter(i, fitpar[i]);
718 : brun 11605
719 : brun 11226 }
720 :    
721 :     //______________________________________________________________________________
722 :     void TMultiGraph::LeastSquareFit(Int_t m, Double_t *a, Double_t xmin, Double_t xmax)
723 :     {
724 :     //*-*-*-*-*-*-*-*Least squares lpolynomial fitting without weights*-*-*-*-*-*-*
725 :     //*-* =================================================
726 :     //
727 :     // m number of parameters
728 :     // a array of parameters
729 :     // first 1st point number to fit (default =0)
730 :     // last last point number to fit (default=fNpoints-1)
731 :     //
732 :     // based on CERNLIB routine LSQ: Translated to C++ by Rene Brun
733 :     //
734 :     //
735 :     const Double_t zero = 0.;
736 :     const Double_t one = 1.;
737 :     const Int_t idim = 20;
738 :    
739 :     Double_t b[400] /* was [20][20] */;
740 :     Int_t i, k, l, ifail, bin;
741 :     Double_t power;
742 :     Double_t da[20], xk, yk;
743 :    
744 :    
745 :     //count the total number of points to fit
746 :     TGraph *g;
747 :     TIter next(fGraphs);
748 :     Double_t *px, *py;
749 :     Int_t n=0;
750 :     Int_t npp;
751 :     while ((g = (TGraph*) next())) {
752 :     px=g->GetX();
753 :     py=g->GetY();
754 :     npp=g->GetN();
755 :     for (bin=0; bin<npp; bin++){
756 :     xk=px[bin];
757 :     if (xk < xmin || xk > xmax) continue;
758 :     n++;
759 :     }
760 :     }
761 :     if (m <= 2) {
762 :     LeastSquareLinearFit(n, a[0], a[1], ifail, xmin, xmax);
763 :     return;
764 :     }
765 :     if (m > idim || m > n) return;
766 :     da[0] = zero;
767 :     for (l = 2; l <= m; ++l) {
768 :     b[l-1] = zero;
769 :     b[m + l*20 - 21] = zero;
770 :     da[l-1] = zero;
771 :     }
772 :     Int_t np = 0;
773 :    
774 :     next.Reset();
775 :     while ((g = (TGraph*) next())) {
776 :     px=g->GetX();
777 :     py=g->GetY();
778 :     npp=g->GetN();
779 :    
780 :     for (k = 0; k <= npp; ++k) {
781 :     xk = px[k];
782 :     if (xk < xmin || xk > xmax) continue;
783 :     np++;
784 :     yk = py[k];
785 :     power = one;
786 :     da[0] += yk;
787 :     for (l = 2; l <= m; ++l) {
788 :     power *= xk;
789 :     b[l-1] += power;
790 :     da[l-1] += power*yk;
791 :     }
792 :     for (l = 2; l <= m; ++l) {
793 :     power *= xk;
794 :     b[m + l*20 - 21] += power;
795 :     }
796 :     }
797 :     }
798 :     b[0] = Double_t(np);
799 :     for (i = 3; i <= m; ++i) {
800 :     for (k = i; k <= m; ++k) {
801 :     b[k - 1 + (i-1)*20 - 21] = b[k + (i-2)*20 - 21];
802 :     }
803 :     }
804 :     H1LeastSquareSeqnd(m, b, idim, ifail, 1, da);
805 :    
806 :     if (ifail < 0) {
807 :     //a[0] = fY[0];
808 :     py=((TGraph *)fGraphs->First())->GetY();
809 :     a[0]=py[0];
810 :     for (i=1; i<m; ++i) a[i] = 0;
811 :     return;
812 :     }
813 :     for (i=0; i<m; ++i) a[i] = da[i];
814 :    
815 :     }
816 :    
817 :     //______________________________________________________________________________
818 :     void TMultiGraph::LeastSquareLinearFit(Int_t ndata, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin, Double_t xmax)
819 :     {
820 :     //*-*-*-*-*-*-*-*-*-*Least square linear fit without weights*-*-*-*-*-*-*-*-*
821 :     //*-* =======================================
822 :     //
823 :     // Fit a straight line (a0 + a1*x) to the data in this graph.
824 :     // ndata: number of points to fit
825 :     // first: first point number to fit
826 :     // last: last point to fit O(ndata should be last-first
827 :     // ifail: return parameter indicating the status of the fit (ifail=0, fit is OK)
828 :     //
829 :     // extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun
830 :     //
831 :    
832 :     Double_t xbar, ybar, x2bar;
833 :     Int_t i;
834 :     Double_t xybar;
835 :     Double_t fn, xk, yk;
836 :     Double_t det;
837 :    
838 :     ifail = -2;
839 :     xbar = ybar = x2bar = xybar = 0;
840 :     Int_t np = 0;
841 :     TGraph *g;
842 :     TIter next(fGraphs);
843 :     Double_t *px, *py;
844 :     Int_t npp;
845 :     while ((g = (TGraph*) next())) {
846 :     px=g->GetX();
847 :     py=g->GetY();
848 :     npp=g->GetN();
849 :     for (i = 0; i < npp; ++i) {
850 :     xk = px[i];
851 :     if (xk < xmin || xk > xmax) continue;
852 :     np++;
853 :     yk = py[i];
854 :     if (ndata < 0) {
855 :     if (yk <= 0) yk = 1e-9;
856 :     yk = TMath::Log(yk);
857 :     }
858 :     xbar += xk;
859 :     ybar += yk;
860 :     x2bar += xk*xk;
861 :     xybar += xk*yk;
862 :     }
863 :     }
864 :     fn = Double_t(np);
865 :     det = fn*x2bar - xbar*xbar;
866 :     ifail = -1;
867 :     if (det <= 0) {
868 :     if (fn > 0) a0 = ybar/fn;
869 :     else a0 = 0;
870 :     a1 = 0;
871 :     return;
872 :     }
873 :     ifail = 0;
874 :     a0 = (x2bar*ybar - xbar*xybar) / det;
875 :     a1 = (fn*xybar - xbar*ybar) / det;
876 :    
877 :    
878 :    
879 :     }
880 :    
881 :     //______________________________________________________________________________
882 : brun 1205 TH1F *TMultiGraph::GetHistogram() const
883 : brun 754 {
884 :     // Returns a pointer to the histogram used to draw the axis
885 :     // Takes into account the two following cases.
886 :     // 1- option 'A' was specified in TMultiGraph::Draw. Return fHistogram
887 :     // 2- user had called TPad::DrawFrame. return pointer to hframe histogram
888 :    
889 :     if (fHistogram) return fHistogram;
890 :     if (!gPad) return 0;
891 :     gPad->Modified();
892 :     gPad->Update();
893 :     if (fHistogram) return fHistogram;
894 :     TH1F *h1 = (TH1F*)gPad->FindObject("hframe");
895 :     return h1;
896 :     }
897 :    
898 :     //______________________________________________________________________________
899 : brun 11226 TF1 *TMultiGraph::GetFunction(const char *name) const
900 :     {
901 :     //*-*-*-*-*Return pointer to function with name*-*-*-*-*-*-*-*-*-*-*-*-*
902 :     //*-* ===================================
903 :     //
904 :     // Functions such as TGraph::Fit store the fitted function in the list of
905 :     // functions of this graph.
906 :    
907 :     if (!fFunctions) return 0;
908 :     return (TF1*)fFunctions->FindObject(name);
909 :     }
910 :    
911 :     //______________________________________________________________________________
912 : brun 1205 TAxis *TMultiGraph::GetXaxis() const
913 : brun 754 {
914 :     // Get x axis of the graph.
915 :    
916 :     if (!gPad) return 0;
917 : brun 4083 TH1 *h = GetHistogram();
918 :     if (!h) return 0;
919 :     return h->GetXaxis();
920 : brun 754 }
921 :    
922 :     //______________________________________________________________________________
923 : brun 1205 TAxis *TMultiGraph::GetYaxis() const
924 : brun 754 {
925 :     // Get y axis of the graph.
926 :    
927 :     if (!gPad) return 0;
928 : brun 4083 TH1 *h = GetHistogram();
929 :     if (!h) return 0;
930 :     return h->GetYaxis();
931 : brun 754 }
932 :    
933 :     //______________________________________________________________________________
934 :     void TMultiGraph::Paint(Option_t *option)
935 :     {
936 :     // paint all the graphs of this multigraph
937 :    
938 : brun 5552 if (fGraphs->GetSize() == 0) return;
939 :    
940 : brun 754 char *l;
941 :     static char chopt[33];
942 :     Int_t nch = strlen(option);
943 : brun 1500 Int_t i;
944 :     for (i=0;i<nch;i++) chopt[i] = toupper(option[i]);
945 : brun 754 chopt[nch] = 0;
946 : brun 1500 Double_t *x, *y;
947 : brun 3575 TGraph *g;
948 : rdm 3742
949 : brun 754 l = strstr(chopt,"A");
950 :     if (l) {
951 :     *l = ' ';
952 :     TIter next(fGraphs);
953 :     Int_t npt = 100;
954 :     Double_t maximum, minimum, rwxmin, rwxmax, rwymin, rwymax, uxmin, uxmax, dx, dy;
955 : brun 3575 rwxmin = gPad->GetUxmin();
956 :     rwxmax = gPad->GetUxmax();
957 :     rwymin = gPad->GetUymin();
958 :     rwymax = gPad->GetUymax();
959 : brun 3799 char *xtitle = 0;
960 :     char *ytitle = 0;
961 :     Int_t firstx = 0;
962 :     Int_t lastx = 0;
963 :    
964 : brun 754 if (fHistogram) {
965 : brun 3575 //cleanup in case of a previous unzoom
966 :     if (fHistogram->GetMinimum() >= fHistogram->GetMaximum()) {
967 : brun 3799 Int_t nch = strlen(fHistogram->GetXaxis()->GetTitle());
968 :     firstx = fHistogram->GetXaxis()->GetFirst();
969 :     lastx = fHistogram->GetXaxis()->GetLast();
970 :     if (nch) {
971 :     xtitle = new char[nch+1];
972 :     strcpy(xtitle,fHistogram->GetXaxis()->GetTitle());
973 :     }
974 :     nch = strlen(fHistogram->GetYaxis()->GetTitle());
975 :     if (nch) {
976 :     ytitle = new char[nch+1];
977 :     strcpy(ytitle,fHistogram->GetYaxis()->GetTitle());
978 :     }
979 : brun 3575 delete fHistogram;
980 :     fHistogram = 0;
981 :     }
982 :     }
983 :     if (fHistogram) {
984 :     minimum = fHistogram->GetYaxis()->GetXmin();
985 :     maximum = fHistogram->GetYaxis()->GetXmax();
986 :     uxmin = gPad->PadtoX(rwxmin);
987 :     uxmax = gPad->PadtoX(rwxmax);
988 : brun 754 } else {
989 :     rwxmin = 1e100;
990 :     rwxmax = -rwxmin;
991 :     rwymin = rwxmin;
992 :     rwymax = -rwymin;
993 :     while ((g = (TGraph*) next())) {
994 : brun 1500 Int_t npoints = g->GetN();
995 :     x = g->GetX();
996 :     y = g->GetY();
997 :     for (i=0;i<npoints;i++) {
998 :     if (x[i] < rwxmin) rwxmin = x[i];
999 :     if (x[i] > rwxmax) rwxmax = x[i];
1000 : brun 9245 if (y[i] > rwymax) rwymax = y[i];
1001 : brun 1500 if (y[i] < rwymin) rwymin = y[i];
1002 :     }
1003 : brun 754 g->ComputeRange(rwxmin, rwymin, rwxmax, rwymax);
1004 :     if (g->GetN() > npt) npt = g->GetN();
1005 :     }
1006 :     if (rwxmin == rwxmax) rwxmax += 1.;
1007 :     if (rwymin == rwymax) rwymax += 1.;
1008 : brun 3575 dx = 0.05*(rwxmax-rwxmin);
1009 :     dy = 0.05*(rwymax-rwymin);
1010 : brun 754 uxmin = rwxmin - dx;
1011 :     uxmax = rwxmax + dx;
1012 : brun 9245 if (gPad->GetLogy()) {
1013 :     if (rwymin <= 0) rwymin = 0.001*rwymax;
1014 :     minimum = rwymin/(1+0.5*TMath::Log10(rwymax/rwymin));
1015 :     maximum = rwymax*(1+0.2*TMath::Log10(rwymax/rwymin));
1016 :     } else {
1017 :     minimum = rwymin - dy;
1018 :     maximum = rwymax + dy;
1019 :     }
1020 : brun 9010 if (minimum < 0 && rwymin >= 0) minimum = 0;
1021 :     if (maximum > 0 && rwymax <= 0) maximum = 0;
1022 : brun 754 }
1023 :    
1024 :     if (fMinimum != -1111) rwymin = minimum = fMinimum;
1025 :     if (fMaximum != -1111) rwymax = maximum = fMaximum;
1026 :     if (uxmin < 0 && rwxmin >= 0) {
1027 :     if (gPad->GetLogx()) uxmin = 0.9*rwxmin;
1028 : brun 3575 //else uxmin = 0;
1029 : brun 754 }
1030 :     if (uxmax > 0 && rwxmax <= 0) {
1031 :     if (gPad->GetLogx()) uxmax = 1.1*rwxmax;
1032 : brun 3575 //else uxmax = 0;
1033 : brun 754 }
1034 :     if (minimum < 0 && rwymin >= 0) {
1035 :     if(gPad->GetLogy()) minimum = 0.9*rwymin;
1036 : brun 3575 //else minimum = 0;
1037 : brun 754 }
1038 :     if (maximum > 0 && rwymax <= 0) {
1039 :     if(gPad->GetLogy()) maximum = 1.1*rwymax;
1040 : brun 3575 //else maximum = 0;
1041 : brun 754 }
1042 :     if (minimum <= 0 && gPad->GetLogy()) minimum = 0.001*maximum;
1043 :     if (uxmin <= 0 && gPad->GetLogx()) {
1044 :     if (uxmax > 1000) uxmin = 1;
1045 :     else uxmin = 0.001*uxmax;
1046 :     }
1047 :     rwymin = minimum;
1048 :     rwymax = maximum;
1049 :     if (fHistogram) {
1050 : brun 3575 fHistogram->GetYaxis()->SetLimits(rwymin,rwymax);
1051 :     }
1052 :    
1053 :     //*-*- Create a temporary histogram to draw the axis
1054 :     if (!fHistogram) {
1055 :     // the graph is created with at least as many channels as there are points
1056 :     // to permit zooming on the full range
1057 :     rwxmin = uxmin;
1058 :     rwxmax = uxmax;
1059 :     fHistogram = new TH1F(GetName(),GetTitle(),npt,rwxmin,rwxmax);
1060 :     if (!fHistogram) return;
1061 : brun 754 fHistogram->SetMinimum(rwymin);
1062 : brun 3575 fHistogram->SetBit(TH1::kNoStats);
1063 : brun 754 fHistogram->SetMaximum(rwymax);
1064 : brun 3575 fHistogram->GetYaxis()->SetLimits(rwymin,rwymax);
1065 :     fHistogram->SetDirectory(0);
1066 : brun 3799 if (xtitle) {fHistogram->GetXaxis()->SetTitle(xtitle); delete [] xtitle;}
1067 :     if (ytitle) {fHistogram->GetYaxis()->SetTitle(ytitle); delete [] ytitle;}
1068 :     if (firstx != lastx) fHistogram->GetXaxis()->SetRange(firstx,lastx);
1069 : brun 754 }
1070 : brun 4037 fHistogram->Paint("0");
1071 : brun 3575 }
1072 : rdm 3742
1073 : brun 754 if (fGraphs) {
1074 : brun 4037 TObjOptLink *lnk = (TObjOptLink*)fGraphs->FirstLink();
1075 :     TObject *obj;
1076 :    
1077 :     while (lnk) {
1078 :     obj = lnk->GetObject();
1079 :     if (strlen(lnk->GetOption())) obj->Paint(lnk->GetOption());
1080 :     else obj->Paint(chopt);
1081 :     lnk = (TObjOptLink*)lnk->Next();
1082 :     }
1083 : brun 754 }
1084 : brun 11226
1085 :     TObject *f;
1086 :     if (fFunctions) {
1087 :     TIter next(fFunctions);
1088 :     while ((f = (TObject*) next())) {
1089 :     if (f->InheritsFrom(TF1::Class())) {
1090 :     if (f->TestBit(TF1::kNotDraw) == 0) f->Paint("lsame");
1091 :     } else {
1092 :     f->Paint();
1093 :     }
1094 :     }
1095 :     }
1096 :    
1097 :    
1098 : brun 754 }
1099 :    
1100 :     //______________________________________________________________________________
1101 : brun 1205 void TMultiGraph::Print(Option_t *option) const
1102 : brun 754 {
1103 :     // Print the list of graphs
1104 :    
1105 :     TGraph *g;
1106 :     if (fGraphs) {
1107 :     TIter next(fGraphs);
1108 :     while ((g = (TGraph*) next())) {
1109 :     g->Print(option);
1110 :     }
1111 :     }
1112 :     }
1113 :    
1114 :     //______________________________________________________________________________
1115 : brun 5552 void TMultiGraph::RecursiveRemove(TObject *obj)
1116 :     {
1117 :     // Recursively remove this object from a list. Typically implemented
1118 :     // by classes that can contain mulitple references to a same object.
1119 :    
1120 :     if (!fGraphs) return;
1121 :     TObject *objr = fGraphs->Remove(obj);
1122 :     if (!objr) return;
1123 :     delete fHistogram; fHistogram = 0;
1124 :     if (gPad) gPad->Modified();
1125 :     }
1126 :    
1127 :     //______________________________________________________________________________
1128 : brun 754 void TMultiGraph::SavePrimitive(ofstream &out, Option_t *option)
1129 :     {
1130 :     // Save primitive as a C++ statement(s) on output stream out
1131 :    
1132 :     char quote = '"';
1133 :     out<<" "<<endl;
1134 :     if (gROOT->ClassSaved(TMultiGraph::Class())) {
1135 :     out<<" ";
1136 :     } else {
1137 :     out<<" TMultiGraph *";
1138 :     }
1139 :     out<<"multigraph = new TMultiGraph();"<<endl;
1140 :     out<<" multigraph->SetName("<<quote<<GetName()<<quote<<");"<<endl;
1141 :     out<<" multigraph->SetTitle("<<quote<<GetTitle()<<quote<<");"<<endl;
1142 :    
1143 :     if (fGraphs) {
1144 : brun 10847 TObjOptLink *lnk = (TObjOptLink*)fGraphs->FirstLink();
1145 :     TObject *g;
1146 :    
1147 :     while (lnk) {
1148 :     g = lnk->GetObject();
1149 :     g->SavePrimitive(out,"multigraph");
1150 :    
1151 :     out<<" multigraph->Add(graph,"<<quote<<lnk->GetOption()<<quote<<");"<<endl;
1152 :    
1153 :     lnk = (TObjOptLink*)lnk->Next();
1154 :    
1155 : brun 754 }
1156 :     }
1157 :     out<<" multigraph->Draw("
1158 :     <<quote<<option<<quote<<");"<<endl;
1159 :     }
1160 :    
1161 :     //______________________________________________________________________________
1162 :     void TMultiGraph::SetMaximum(Double_t maximum)
1163 :     {
1164 :     fMaximum = maximum;
1165 :     if (fHistogram) fHistogram->SetMaximum(maximum);
1166 :     }
1167 :    
1168 :     //______________________________________________________________________________
1169 :     void TMultiGraph::SetMinimum(Double_t minimum)
1170 :     {
1171 :     fMinimum = minimum;
1172 :     if (fHistogram) fHistogram->SetMinimum(minimum);
1173 :     }

Subversion Admin
ViewVC Help
Powered by ViewVC 1.0.9