ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gtime.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Example of TGraphTime.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Rene Brun
9 
10 #include "TCanvas.h"
11 #include "TRandom3.h"
12 #include "TMath.h"
13 #include "TText.h"
14 #include "TArrow.h"
15 #include "TGraphTime.h"
16 #include "TROOT.h"
17 
18 void gtime(Int_t nsteps = 500, Int_t np=100) {
19  if (np > 1000) np = 1000;
20  Int_t color[1000];
21  Double_t rr[1000], phi[1000], dr[1000], size[1000];
22  TRandom3 r;
23  Double_t xmin = -10, xmax = 10, ymin = -10, ymax = 10;
24  TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
25  g->SetTitle("TGraphTime demo;X domain;Y domain");
26  Int_t i,s;
27  for (i=0;i<np;i++) { //calculate some object parameters
28  rr[i] = r.Uniform(0.1*xmax,0.2*xmax);
29  phi[i] = r.Uniform(0,2*TMath::Pi());
30  dr[i] = r.Uniform(0,1)*0.9*xmax/Double_t(nsteps);
31  Double_t rc = r.Rndm();
32  color[i] = kRed;
33  if (rc > 0.3) color[i] = kBlue;
34  if (rc > 0.7) color[i] = kYellow;
35  size[i] = r.Uniform(0.5,6);
36  }
37  for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
38  for (i=0;i<np;i++) {
39  Double_t newr = rr[i]+dr[i]*s;
40  Double_t newsize = 0.2+size[i]*TMath::Abs(TMath::Sin(newr+10));
41  Double_t newphi = phi[i] + 0.01*s;
42  Double_t xx = newr*TMath::Cos(newphi);
43  Double_t yy = newr*TMath::Sin(newphi);
44  TMarker *m = new TMarker(xx,yy,20);
45  m->SetMarkerColor(color[i]);
46  m->SetMarkerSize(newsize);
47  g->Add(m,s);
48  if (i==np-1) g->Add(new TArrow(xmin,ymax,xx,yy,0.02,"-|>"), s);
49  }
50  g->Add(new TPaveLabel(.90,.92,.98,.97,Form("%d",s+1),"brNDC"),s);
51  }
52  g->Draw();
53 
54  //save object to a file
55  TFile f("gtime.root","recreate");
56  g->Write("g");
57  //to view this object in another session do
58  // TFile f("gtime.root");
59  // g.Draw();
60 }
61 
62 
63 
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax...
Definition: TGraphTime.h:31
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:823
Random number generator class based on M.
Definition: TRandom3.h:29
Definition: Rtypes.h:61
float ymin
Definition: THbookFile.cxx:93
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Manages Markers.
Definition: TMarker.h:40
int Int_t
Definition: RtypesCore.h:41
Definition: Rtypes.h:61
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
TFile * f
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
tuple np
Definition: multifit.py:30
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom3.cxx:94
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:32
float ymax
Definition: THbookFile.cxx:93
ROOT::R::TRInterface & r
Definition: Object.C:4
char * Form(const char *fmt,...)
float xmax
Definition: THbookFile.cxx:93
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
Double_t Cos(Double_t)
Definition: TMath.h:424
Double_t Pi()
Definition: TMath.h:44
virtual void Draw(Option_t *chopt="")
Draw this TGraphTime.
Definition: TGraphTime.cxx:124
double Double_t
Definition: RtypesCore.h:55
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:606
virtual Int_t Add(const TObject *obj, Int_t slot, Option_t *option="")
Add one object to a time slot.
Definition: TGraphTime.cxx:103
Double_t Sin(Double_t)
Definition: TMath.h:421
Definition: Rtypes.h:61
Draw all kinds of Arrows.
Definition: TArrow.h:35
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152