Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gtime.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// Example of TGraphTime.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Rene Brun
10
11#include "TCanvas.h"
12#include "TRandom3.h"
13#include "TMath.h"
14#include "TText.h"
15#include "TArrow.h"
16#include "TGraphTime.h"
17#include "TROOT.h"
18
19void gtime(Int_t nsteps = 500, Int_t np=100) {
20 if (np > 1000) np = 1000;
21 Int_t color[1000];
22 Double_t rr[1000], phi[1000], dr[1000], size[1000];
23 TRandom3 r;
24 Double_t xmin = -10, xmax = 10, ymin = -10, ymax = 10;
25 TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
26 g->SetTitle("TGraphTime demo;X domain;Y domain");
27 Int_t i,s;
28 for (i=0;i<np;i++) { //calculate some object parameters
29 rr[i] = r.Uniform(0.1*xmax,0.2*xmax);
30 phi[i] = r.Uniform(0,2*TMath::Pi());
31 dr[i] = r.Uniform(0,1)*0.9*xmax/Double_t(nsteps);
32 Double_t rc = r.Rndm();
33 color[i] = kRed;
34 if (rc > 0.3) color[i] = kBlue;
35 if (rc > 0.7) color[i] = kYellow;
36 size[i] = r.Uniform(0.5,6);
37 }
38 for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
39 for (i=0;i<np;i++) {
40 Double_t newr = rr[i]+dr[i]*s;
41 Double_t newsize = 0.2+size[i]*TMath::Abs(TMath::Sin(newr+10));
42 Double_t newphi = phi[i] + 0.01*s;
43 Double_t xx = newr*TMath::Cos(newphi);
44 Double_t yy = newr*TMath::Sin(newphi);
45 TMarker *m = new TMarker(xx,yy,20);
46 m->SetMarkerColor(color[i]);
47 m->SetMarkerSize(newsize);
48 g->Add(m,s);
49 if (i==np-1) g->Add(new TArrow(xmin,ymax,xx,yy,0.02,"-|>"), s);
50 }
51 g->Add(new TPaveLabel(.90,.92,.98,.97,Form("%d",s+1),"brNDC"),s);
52 }
53 g->Draw();
54
55 //save object to a file
56 TFile f("gtime.root","recreate");
57 g->Write("g");
58 //to view this object in another session do
59 // TFile f("gtime.root");
60 // g.Draw();
61}
62
63
64
ROOT::R::TRInterface & r
Definition Object.C:4
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
float xmin
float ymin
float xmax
float ymax
char * Form(const char *fmt,...)
Draw all kinds of Arrows.
Definition TArrow.h:29
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
Definition TGraphTime.h:29
Manages Markers.
Definition TMarker.h:22
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
Random number generator class based on M.
Definition TRandom3.h:27
Double_t Cos(Double_t)
Definition TMath.h:643
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Definition TMath.h:639
Short_t Abs(Short_t d)
Definition TMathBase.h:120
auto * m
Definition textangle.C:8