[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 12136 - (view) (download) (as text)
Original Path: trunk/graf/src/TMultiGraph.cxx

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

Subversion Admin
ViewVC Help
Powered by ViewVC 1.0.9