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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12643, Mon Sep 5 07:25:22 2005 UTC revision 13304, Mon Nov 21 13:57:42 2005 UTC
# Line 1  Line 1 
1  // @(#)root/graf:$Name:  $:$Id: TMultiGraph.cxx,v 1.24 2005/08/29 14:43:30 brun Exp $  // @(#)root/graf:$Name:  $:$Id: TMultiGraph.cxx,v 1.25 2005/09/05 07:25:22 brun Exp $
2  // Author: Rene Brun   12/10/2000  // Author: Rene Brun   12/10/2000
3    
4  /*************************************************************************  /*************************************************************************
# Line 24  Line 24 
24    
25  ClassImp(TMultiGraph)  ClassImp(TMultiGraph)
26    
27    
28  //______________________________________________________________________________  //______________________________________________________________________________
29  //  //
30  //   A TMultiGraph is a collection of TGraph (or derived) objects  //   A TMultiGraph is a collection of TGraph (or derived) objects
# Line 44  Line 45 
45  //  otherwise the graph will be drawn with the option specified in  //  otherwise the graph will be drawn with the option specified in
46  //  TMultiGraph::Draw  //  TMultiGraph::Draw
47    
48    
49  //______________________________________________________________________________  //______________________________________________________________________________
50  TMultiGraph::TMultiGraph(): TNamed()  TMultiGraph::TMultiGraph(): TNamed()
51  {  {
# Line 56  Line 58 
58     fMinimum   = -1111;     fMinimum   = -1111;
59  }  }
60    
61    
62  //______________________________________________________________________________  //______________________________________________________________________________
63  TMultiGraph::TMultiGraph(const char *name, const char *title)  TMultiGraph::TMultiGraph(const char *name, const char *title)
64         : TNamed(name,title)         : TNamed(name,title)
65  {  {
66  // constructor with name and title  // constructor with name and title
67    
68     fGraphs    = 0;     fGraphs    = 0;
69     fFunctions = 0;     fFunctions = 0;
70     fHistogram = 0;     fHistogram = 0;
# Line 68  Line 72 
72     fMinimum   = -1111;     fMinimum   = -1111;
73  }  }
74    
75    
76  //______________________________________________________________________________  //______________________________________________________________________________
77  TMultiGraph::~TMultiGraph()  TMultiGraph::~TMultiGraph()
78  {  {
# Line 99  Line 104 
104     }     }
105  }  }
106    
107    
108  //______________________________________________________________________________  //______________________________________________________________________________
109  void TMultiGraph::Add(TGraph *graph, Option_t *chopt)  void TMultiGraph::Add(TGraph *graph, Option_t *chopt)
110  {  {
# Line 112  Line 118 
118     fGraphs->Add(graph,chopt);     fGraphs->Add(graph,chopt);
119  }  }
120    
121    
122  //______________________________________________________________________________  //______________________________________________________________________________
123  void TMultiGraph::Browse(TBrowser *)  void TMultiGraph::Browse(TBrowser *)
124  {  {
125       // Browse multigraph.
126    
127      Draw("alp");      Draw("alp");
128      gPad->Update();      gPad->Update();
129  }  }
130    
131    
132  //______________________________________________________________________________  //______________________________________________________________________________
133  Int_t TMultiGraph::DistancetoPrimitive(Int_t px, Int_t py)  Int_t TMultiGraph::DistancetoPrimitive(Int_t px, Int_t py)
134  {  {
135  // Compute distance from point px,py to each graph  // Compute distance from point px,py to each graph
 //  
136    
137  //*-*- Are we on the axis?     // Are we on the axis?
138     const Int_t kMaxDiff = 10;     const Int_t kMaxDiff = 10;
139     Int_t distance = 9999;     Int_t distance = 9999;
140     if (fHistogram) {     if (fHistogram) {
# Line 133  Line 142 
142        if (distance <= 0) return distance;        if (distance <= 0) return distance;
143     }     }
144    
145       // Loop on the list of graphs
 //*-*- Loop on the list of graphs  
146     if (!fGraphs) return distance;     if (!fGraphs) return distance;
147     TGraph *g;     TGraph *g;
148     TIter   next(fGraphs);     TIter   next(fGraphs);
# Line 146  Line 154 
154     return distance;     return distance;
155  }  }
156    
157    
158  //______________________________________________________________________________  //______________________________________________________________________________
159  void TMultiGraph::Draw(Option_t *option)  void TMultiGraph::Draw(Option_t *option)
160  {  {
161  //*-*-*-*-*-*-*-*-*-*-*Draw this multigraph with its current attributes*-*-*-*-*-*-*     // Draw this multigraph with its current attributes.
 //*-*                  ==========================================  
162  //  //
163  //   Options to draw a graph are described in TGraph::PainGraph  //   Options to draw a graph are described in TGraph::PainGraph
164  //  //
# Line 165  Line 173 
173    AppendPad(option);    AppendPad(option);
174  }  }
175    
176    
177  //______________________________________________________________________________  //______________________________________________________________________________
178  Int_t TMultiGraph::Fit(const char *fname, Option_t *option, Option_t *, Axis_t xmin, Axis_t xmax)  Int_t TMultiGraph::Fit(const char *fname, Option_t *option, Option_t *, Axis_t xmin, Axis_t xmax)
179  {  {
180  //*-*-*-*-*-*Fit this graph with function with name fname*-*-*-*-*-*-*-*-*-*     // Fit this graph with function with name fname.
181  //*-*        ============================================     //
182  //  interface to TF1::Fit(TF1 *f1...  //  interface to TF1::Fit(TF1 *f1...
183    
184     char *linear;     char *linear;
# Line 185  Line 194 
194     return Fit(f1,option,"",xmin,xmax);     return Fit(f1,option,"",xmin,xmax);
195  }  }
196    
197    
198  //______________________________________________________________________________  //______________________________________________________________________________
199  Int_t TMultiGraph::Fit(TF1 *f1, Option_t *option, Option_t *, Axis_t rxmin, Axis_t rxmax)  Int_t TMultiGraph::Fit(TF1 *f1, Option_t *option, Option_t *, Axis_t rxmin, Axis_t rxmax)
200  {  {
201  //*-*-*-*-*-*-*-*-*-*-*Fit this multigraph with function f1*-*-*-*-*-*-*-*-*-*     // Fit this multigraph with function f1.
 //*-*                  ==================================  
202  //  //
203  //   In this function all graphs of the multigraph are fitted simultaneously  //   In this function all graphs of the multigraph are fitted simultaneously
204  //  //
# Line 475  Line 484 
484     TVirtualFitter *grFitter = TVirtualFitter::Fitter(this, f1->GetNpar());     TVirtualFitter *grFitter = TVirtualFitter::Fitter(this, f1->GetNpar());
485     grFitter->Clear();     grFitter->Clear();
486    
487  //*-*- Get pointer to the function by searching in the list of functions in ROOT     // Get pointer to the function by searching in the list of functions in ROOT
488     grFitter->SetUserFunc(f1);     grFitter->SetUserFunc(f1);
489     grFitter->SetFitOption(fitOption);     grFitter->SetFitOption(fitOption);
490    
491  //*-*- Is a Fit range specified?     // Is a Fit range specified?
492     if (fitOption.Range) {     if (fitOption.Range) {
493        f1->GetRange(xmin, xmax);        f1->GetRange(xmin, xmax);
494     } else {     } else {
# Line 590  Line 599 
599           f1->SetParError(i,werr);           f1->SetParError(i,werr);
600        }        }
601     }     }
602  //*-*- Print final values of parameters.     // Print final values of parameters.
603     if (!fitOption.Quiet) {     if (!fitOption.Quiet) {
604        if (fitOption.Errors) grFitter->PrintResults(4,amin);        if (fitOption.Errors) grFitter->PrintResults(4,amin);
605        else                  grFitter->PrintResults(3,amin);        else                  grFitter->PrintResults(3,amin);
606     }     }
607     delete [] arglist;     delete [] arglist;
608    
609  //*-*- Store fitted function in histogram functions list and draw     // Store fitted function in histogram functions list and draw
610    
611     if (!fitOption.Nostore) {     if (!fitOption.Nostore) {
612        if (!fFunctions) fFunctions = new TList;        if (!fFunctions) fFunctions = new TList;
# Line 623  Line 632 
632        if (gPad) gPad->Modified();        if (gPad) gPad->Modified();
633     }     }
634    
   
635     return fitResult;     return fitResult;
   
636  }  }
637    
638    
# Line 644  Line 651 
651     return "";     return "";
652  }  }
653    
654    
655  //______________________________________________________________________________  //______________________________________________________________________________
656  void TMultiGraph::InitGaus(Double_t xmin, Double_t xmax)  void TMultiGraph::InitGaus(Double_t xmin, Double_t xmax)
657  {  {
658  //*-*-*-*-*-*Compute Initial values of parameters for a gaussian*-*-*-*-*-*-*     // Compute Initial values of parameters for a gaussian.
 //*-*        ===================================================  
659    
660     Double_t allcha, sumx, sumx2, x, val, rms, mean;     Double_t allcha, sumx, sumx2, x, val, rms, mean;
661     Int_t bin;     Int_t bin;
662     const Double_t sqrtpi = 2.506628;     const Double_t sqrtpi = 2.506628;
663    
664  //*-*- Compute mean value and RMS of the graph in the given range     // Compute mean value and RMS of the graph in the given range
665     Int_t np = 0;     Int_t np = 0;
666     allcha = sumx = sumx2 = 0;     allcha = sumx = sumx2 = 0;
667     TGraph *g;     TGraph *g;
# Line 689  Line 696 
696     f1->SetParLimits(2,0,10*rms);     f1->SetParLimits(2,0,10*rms);
697  }  }
698    
699    
700  //______________________________________________________________________________  //______________________________________________________________________________
701  void TMultiGraph::InitExpo(Double_t xmin, Double_t xmax)  void TMultiGraph::InitExpo(Double_t xmin, Double_t xmax)
702  {  {
703  //*-*-*-*-*-*Compute Initial values of parameters for an exponential*-*-*-*-*     // Compute Initial values of parameters for an exponential.
 //*-*        =======================================================  
704    
705     Double_t constant, slope;     Double_t constant, slope;
706     Int_t ifail;     Int_t ifail;
# Line 704  Line 711 
711     TF1 *f1 = (TF1*)grFitter->GetUserFunc();     TF1 *f1 = (TF1*)grFitter->GetUserFunc();
712     f1->SetParameter(0,constant);     f1->SetParameter(0,constant);
713     f1->SetParameter(1,slope);     f1->SetParameter(1,slope);
   
714  }  }
715    
716    
717  //______________________________________________________________________________  //______________________________________________________________________________
718  void TMultiGraph::InitPolynom(Double_t xmin, Double_t xmax)  void TMultiGraph::InitPolynom(Double_t xmin, Double_t xmax)
719  {  {
720  //*-*-*-*-*-*Compute Initial values of parameters for a polynom*-*-*-*-*-*-*     // Compute Initial values of parameters for a polynom.
 //*-*        ===================================================  
721    
722     Double_t fitpar[25];     Double_t fitpar[25];
723    
# Line 722  Line 728 
728     LeastSquareFit(npar, fitpar, xmin, xmax);     LeastSquareFit(npar, fitpar, xmin, xmax);
729    
730     for (Int_t i=0;i<npar;i++) f1->SetParameter(i, fitpar[i]);     for (Int_t i=0;i<npar;i++) f1->SetParameter(i, fitpar[i]);
   
731  }  }
732    
733    
734  //______________________________________________________________________________  //______________________________________________________________________________
735  void TMultiGraph::LeastSquareFit(Int_t m, Double_t *a, Double_t xmin, Double_t xmax)  void TMultiGraph::LeastSquareFit(Int_t m, Double_t *a, Double_t xmin, Double_t xmax)
736  {  {
737  //*-*-*-*-*-*-*-*Least squares lpolynomial fitting without weights*-*-*-*-*-*-*     // Least squares lpolynomial fitting without weights.
 //*-*            =================================================  
738  //  //
739  //  m     number of parameters  //  m     number of parameters
740  //  a     array of parameters  //  a     array of parameters
# Line 737  Line 742 
742  //  last  last point number to fit (default=fNpoints-1)  //  last  last point number to fit (default=fNpoints-1)
743  //  //
744  //   based on CERNLIB routine LSQ: Translated to C++ by Rene Brun  //   based on CERNLIB routine LSQ: Translated to C++ by Rene Brun
745  //  
 //  
746      const Double_t zero = 0.;      const Double_t zero = 0.;
747      const Double_t one = 1.;      const Double_t one = 1.;
748      const Int_t idim = 20;      const Int_t idim = 20;
# Line 818  Line 822 
822         return;         return;
823      }      }
824      for (i=0; i<m; ++i) a[i] = da[i];      for (i=0; i<m; ++i) a[i] = da[i];
   
825  }  }
826    
827    
828  //______________________________________________________________________________  //______________________________________________________________________________
829  void TMultiGraph::LeastSquareLinearFit(Int_t ndata, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin, Double_t xmax)  void TMultiGraph::LeastSquareLinearFit(Int_t ndata, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin, Double_t xmax)
830  {  {
831  //*-*-*-*-*-*-*-*-*-*Least square linear fit without weights*-*-*-*-*-*-*-*-*     // Least square linear fit without weights.
 //*-*                =======================================  
832  //  //
833  //  Fit a straight line (a0 + a1*x) to the data in this graph.  //  Fit a straight line (a0 + a1*x) to the data in this graph.
834  //  ndata:  number of points to fit  //  ndata:  number of points to fit
# Line 834  Line 837 
837  //  ifail:  return parameter indicating the status of the fit (ifail=0, fit is OK)  //  ifail:  return parameter indicating the status of the fit (ifail=0, fit is OK)
838  //  //
839  //   extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun  //   extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun
 //  
840    
841      Double_t xbar, ybar, x2bar;      Double_t xbar, ybar, x2bar;
842      Int_t i;      Int_t i;
# Line 880  Line 882 
882      ifail = 0;      ifail = 0;
883      a0 = (x2bar*ybar - xbar*xybar) / det;      a0 = (x2bar*ybar - xbar*xybar) / det;
884      a1 = (fn*xybar - xbar*ybar) / det;      a1 = (fn*xybar - xbar*ybar) / det;
   
   
   
885  }  }
886    
887    
888  //______________________________________________________________________________  //______________________________________________________________________________
889  TH1F *TMultiGraph::GetHistogram() const  TH1F *TMultiGraph::GetHistogram() const
890  {  {
# Line 902  Line 902 
902     return h1;     return h1;
903  }  }
904    
905    
906  //______________________________________________________________________________  //______________________________________________________________________________
907  TF1 *TMultiGraph::GetFunction(const char *name) const  TF1 *TMultiGraph::GetFunction(const char *name) const
908  {  {
909  //*-*-*-*-*Return pointer to function with name*-*-*-*-*-*-*-*-*-*-*-*-*     // Return pointer to function with name.
 //*-*      ===================================  
910  //  //
911  // Functions such as TGraph::Fit store the fitted function in the list of  // Functions such as TGraph::Fit store the fitted function in the list of
912  // functions of this graph.  // functions of this graph.
# Line 915  Line 915 
915     return (TF1*)fFunctions->FindObject(name);     return (TF1*)fFunctions->FindObject(name);
916  }  }
917    
918    
919  //______________________________________________________________________________  //______________________________________________________________________________
920  TAxis *TMultiGraph::GetXaxis() const  TAxis *TMultiGraph::GetXaxis() const
921  {  {
# Line 926  Line 927 
927     return h->GetXaxis();     return h->GetXaxis();
928  }  }
929    
930    
931  //______________________________________________________________________________  //______________________________________________________________________________
932  TAxis *TMultiGraph::GetYaxis() const  TAxis *TMultiGraph::GetYaxis() const
933  {  {
# Line 937  Line 939 
939     return h->GetYaxis();     return h->GetYaxis();
940  }  }
941    
942    
943  //______________________________________________________________________________  //______________________________________________________________________________
944  void TMultiGraph::Paint(Option_t *option)  void TMultiGraph::Paint(Option_t *option)
945  {  {
# Line 1057  Line 1060 
1060          fHistogram->GetYaxis()->SetLimits(rwymin,rwymax);          fHistogram->GetYaxis()->SetLimits(rwymin,rwymax);
1061       }       }
1062    
1063  //*-*-  Create a temporary histogram to draw the axis        // Create a temporary histogram to draw the axis
1064       if (!fHistogram) {       if (!fHistogram) {
1065          // the graph is created with at least as many channels as there are points          // the graph is created with at least as many channels as there are points
1066          // to permit zooming on the full range          // to permit zooming on the full range
# Line 1100  Line 1103 
1103        }        }
1104       }       }
1105     }     }
   
   
1106  }  }
1107    
1108    
1109  //______________________________________________________________________________  //______________________________________________________________________________
1110  void TMultiGraph::Print(Option_t *option) const  void TMultiGraph::Print(Option_t *option) const
1111  {  {
# Line 1118  Line 1120 
1120     }     }
1121  }  }
1122    
1123    
1124  //______________________________________________________________________________  //______________________________________________________________________________
1125  void TMultiGraph::RecursiveRemove(TObject *obj)  void TMultiGraph::RecursiveRemove(TObject *obj)
1126  {  {
# Line 1131  Line 1134 
1134     if (gPad) gPad->Modified();     if (gPad) gPad->Modified();
1135  }  }
1136    
1137    
1138  //______________________________________________________________________________  //______________________________________________________________________________
1139  void TMultiGraph::SavePrimitive(ofstream &out, Option_t *option)  void TMultiGraph::SavePrimitive(ofstream &out, Option_t *option)
1140  {  {
# Line 1165  Line 1169 
1169        <<quote<<option<<quote<<");"<<endl;        <<quote<<option<<quote<<");"<<endl;
1170  }  }
1171    
1172    
1173  //______________________________________________________________________________  //______________________________________________________________________________
1174  void TMultiGraph::SetMaximum(Double_t maximum)  void TMultiGraph::SetMaximum(Double_t maximum)
1175  {  {
1176       // Set multigraph maximum.
1177    
1178     fMaximum = maximum;     fMaximum = maximum;
1179     if (fHistogram)  fHistogram->SetMaximum(maximum);     if (fHistogram)  fHistogram->SetMaximum(maximum);
1180  }  }
1181    
1182    
1183  //______________________________________________________________________________  //______________________________________________________________________________
1184  void TMultiGraph::SetMinimum(Double_t minimum)  void TMultiGraph::SetMinimum(Double_t minimum)
1185  {  {
1186       // Set multigraph minimum.
1187    
1188     fMinimum = minimum;     fMinimum = minimum;
1189     if (fHistogram) fHistogram->SetMinimum(minimum);     if (fHistogram) fHistogram->SetMinimum(minimum);
1190  }  }

Legend:
Removed from v.12643  
changed lines
  Added in v.13304

Subversion Admin
ViewVC Help
Powered by ViewVC 1.0.9