[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 41541, Mon Oct 24 13:31:15 2011 UTC revision 43622, Tue Apr 3 13:24:13 2012 UTC
# Line 13  Line 13 
13  #include "TMultiGraph.h"  #include "TMultiGraph.h"
14  #include "TGraph.h"  #include "TGraph.h"
15  #include "TH1.h"  #include "TH1.h"
16    #include "TH2.h"
17    #include "TPolyLine3D.h"
18  #include "TVirtualPad.h"  #include "TVirtualPad.h"
19  #include "Riostream.h"  #include "Riostream.h"
20  #include "TVirtualFitter.h"  #include "TVirtualFitter.h"
# Line 60  Line 62 
62       mg->Add(gr2,"cp");       mg->Add(gr2,"cp");
63       mg->Draw("a");       mg->Draw("a");
64  </pre>  </pre>
65    A special option <tt>3D</tt> allows to draw the graphs in a 3D space. See the
66    following example:
67    End_Html
68    Begin_Macro(source)
69    {
70       c0 = new TCanvas("c1","multigraph L3",200,10,700,500);
71       c0->SetFrameFillColor(30);
72    
73       TMultiGraph *mg = new TMultiGraph();
74    
75       TGraph *gr1 = new TGraph(); gr1->SetLineColor(kBlue);
76       TGraph *gr2 = new TGraph(); gr2->SetLineColor(kRed);
77       TGraph *gr3 = new TGraph(); gr3->SetLineColor(kGreen);
78       TGraph *gr4 = new TGraph(); gr4->SetLineColor(kOrange);
79    
80       Double_t dx = 6.28/100;
81       Double_t x  = -3.14;
82    
83       for (int i=0; i<=100; i++) {
84          x = x+dx;
85          gr1->SetPoint(i,x,2.*TMath::Sin(x));
86          gr2->SetPoint(i,x,TMath::Cos(x));
87          gr3->SetPoint(i,x,TMath::Cos(x*x));
88          gr4->SetPoint(i,x,TMath::Cos(x*x*x));
89       }
90    
91       mg->Add(gr4); gr4->SetTitle("Cos(x*x*x)"); gr4->SetLineWidth(3);
92       mg->Add(gr3); gr3->SetTitle("Cos(x*x)")  ; gr3->SetLineWidth(3);
93       mg->Add(gr2); gr2->SetTitle("Cos(x)")    ; gr2->SetLineWidth(3);
94       mg->Add(gr1); gr1->SetTitle("2*Sin(x)")  ; gr1->SetLineWidth(3);
95    
96       mg->Draw("a fb l3d");
97       return c0;
98    }
99    End_Macro
100    Begin_Html
101  <p>  <p>
102  The number of graphs in a multigraph can be retrieve with:  The number of graphs in a multigraph can be retrieve with:
103  <pre>  <pre>
# Line 252  Line 290 
290  TMultiGraph::TMultiGraph(const char *name, const char *title)  TMultiGraph::TMultiGraph(const char *name, const char *title)
291         : TNamed(name,title)         : TNamed(name,title)
292  {  {
293     // constructor with name and title     // Constructor with name and title
294    
295     fGraphs    = 0;     fGraphs    = 0;
296     fFunctions = 0;     fFunctions = 0;
# Line 271  Line 309 
309    fMaximum(mg.fMaximum),    fMaximum(mg.fMaximum),
310    fMinimum(mg.fMinimum)    fMinimum(mg.fMinimum)
311  {  {
312     //copy constructor     // Copy constructor
313  }  }
314    
315    
316  //______________________________________________________________________________  //______________________________________________________________________________
317  TMultiGraph& TMultiGraph::operator=(const TMultiGraph& mg)  TMultiGraph& TMultiGraph::operator=(const TMultiGraph& mg)
318  {  {
319     //assignement operator     // Assignement operator
320    
321     if(this!=&mg) {     if(this!=&mg) {
322        TNamed::operator=(mg);        TNamed::operator=(mg);
323        fGraphs=mg.fGraphs;        fGraphs=mg.fGraphs;
# Line 326  Line 365 
365  //______________________________________________________________________________  //______________________________________________________________________________
366  void TMultiGraph::Add(TGraph *graph, Option_t *chopt)  void TMultiGraph::Add(TGraph *graph, Option_t *chopt)
367  {  {
368     // add a new graph to the list of graphs     // Add a new graph to the list of graphs.
369     // note that the graph is now owned by the TMultigraph.     // Note that the graph is now owned by the TMultigraph.
370     // Deleting the TMultiGraph object will automatically delete the graphs.     // Deleting the TMultiGraph object will automatically delete the graphs.
371     // You should not delete the graphs when the TMultigraph is still active.     // You should not delete the graphs when the TMultigraph is still active.
372    
# Line 340  Line 379 
379  //______________________________________________________________________________  //______________________________________________________________________________
380  void TMultiGraph::Add(TMultiGraph *multigraph, Option_t *chopt)  void TMultiGraph::Add(TMultiGraph *multigraph, Option_t *chopt)
381  {  {
382     // add all the graphs in "multigraph" to the list of graphs.     // Add all the graphs in "multigraph" to the list of graphs.
383    
384     TList *graphlist = multigraph->GetListOfGraphs();     TList *graphlist = multigraph->GetListOfGraphs();
385     if (!graphlist) return;     if (!graphlist) return;
# Line 588  Line 627 
627  //______________________________________________________________________________  //______________________________________________________________________________
628  void TMultiGraph::FitPanel()  void TMultiGraph::FitPanel()
629  {  {
630  //   -*-*-*-*-*Display a panel with all histogram fit options*-*-*-*-*-*     // Display a panel with all histogram fit options
 //             ==============================================  
 //  
631  //      See class TFitPanel for example  //      See class TFitPanel for example
632    
633     if (!gPad)     if (!gPad)
# Line 944  Line 981 
981  //______________________________________________________________________________  //______________________________________________________________________________
982  void TMultiGraph::Paint(Option_t *option)  void TMultiGraph::Paint(Option_t *option)
983  {  {
984     // paint all the graphs of this multigraph     // Paint all the graphs of this multigraph
985    
986     const TPickerStackGuard pushGuard(this);     const TPickerStackGuard pushGuard(this);
987    
988     if (!fGraphs) return;     if (!fGraphs) return;
# Line 956  Line 994 
994     Int_t i;     Int_t i;
995     for (i=0;i<nch;i++) chopt[i] = toupper(option[i]);     for (i=0;i<nch;i++) chopt[i] = toupper(option[i]);
996     chopt[nch] = 0;     chopt[nch] = 0;
997    
998       l = strstr(chopt,"3D");
999       if (l) {
1000          l = strstr(chopt,"L");
1001          if (l) PaintPolyLine3D(chopt);
1002          return;
1003       }
1004    
1005     TGraph *g;     TGraph *g;
1006    
1007     l = strstr(chopt,"A");     l = strstr(chopt,"A");
# Line 1129  Line 1175 
1175    
1176    
1177  //______________________________________________________________________________  //______________________________________________________________________________
1178    void TMultiGraph::PaintPolyLine3D(Option_t *option)
1179    {
1180       // Paint all the graphs of this multigraph as 3D lines
1181    
1182       Int_t i, npt;
1183       char *l;
1184       Double_t rwxmin, rwxmax, rwymin, rwymax;
1185       TIter next(fGraphs);
1186       TGraph *g;
1187    
1188       g = (TGraph*) next();
1189       if (g) {
1190          g->ComputeRange(rwxmin, rwymin, rwxmax, rwymax);
1191          npt = g->GetN();
1192       }
1193    
1194       while ((g = (TGraph*) next())) {
1195          Double_t rx1,ry1,rx2,ry2;
1196          g->ComputeRange(rx1, ry1, rx2, ry2);
1197          if (rx1 < rwxmin) rwxmin = rx1;
1198          if (ry1 < rwymin) rwymin = ry1;
1199          if (rx2 > rwxmax) rwxmax = rx2;
1200          if (ry2 > rwymax) rwymax = ry2;
1201          if (g->GetN() > npt) npt = g->GetN();
1202       }
1203    
1204       Int_t ndiv = fGraphs->GetSize();
1205       TH2F* frame = new TH2F("frame","", ndiv, 0., (Double_t)(ndiv),
1206                                          10, rwxmin, rwxmax);
1207    
1208       TAxis *Xaxis = frame->GetXaxis();
1209       Xaxis->SetNdivisions(-ndiv);
1210       next.Reset();
1211       for (i=ndiv; i>=1; i--) {
1212          g = (TGraph*) next();
1213          Xaxis->SetBinLabel(i, g->GetTitle());
1214       }
1215    
1216       frame->SetStats(kFALSE);
1217       frame->SetMinimum(rwymin);
1218       frame->SetMaximum(rwymax);
1219    
1220       l = strstr(option,"A");
1221       if (l) frame->Paint("lego0,fb,bb");
1222       l = strstr(option,"BB");
1223       if (!l) frame->Paint("lego0,fb,a,same");
1224    
1225       Double_t *x, *y;
1226       Double_t xyz1[3], xyz2[3];
1227    
1228       next.Reset();
1229       Int_t j = ndiv;
1230       while ((g = (TGraph*) next())) {
1231          npt = g->GetN();
1232          x   = g->GetX();
1233          y   = g->GetY();
1234          gPad->SetLineColor(g->GetLineColor());
1235          gPad->SetLineWidth(g->GetLineWidth());
1236          gPad->SetLineStyle(g->GetLineStyle());
1237          gPad->TAttLine::Modify();
1238          for (i=0; i<npt-1; i++) {
1239             xyz1[0] = j-0.5;
1240             xyz1[1] = x[i];
1241             xyz1[2] = y[i];
1242             xyz2[0] = j-0.5;
1243             xyz2[1] = x[i+1];
1244             xyz2[2] = y[i+1];
1245             gPad->PaintLine3D(xyz1, xyz2);
1246          }
1247          j--;
1248       }
1249    
1250       l = strstr(option,"FB");
1251       if (!l) frame->Paint("lego0,bb,a,same");
1252       delete frame;
1253    }
1254    
1255    
1256    //______________________________________________________________________________
1257  void TMultiGraph::Print(Option_t *option) const  void TMultiGraph::Print(Option_t *option) const
1258  {  {
1259     // Print the list of graphs     // Print the list of graphs

Legend:
Removed from v.41541  
changed lines
  Added in v.43622

Subversion Admin
ViewVC Help
Powered by ViewVC 1.0.9