Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches

Detailed Description

Example of a graph of data moving in time.

Use the canvas "File/Quit ROOT" to exit from this example

void gtime()
{
auto c1 = (TCanvas *)gROOT->FindObject("c1");
if (c1)
delete c1;
c1 = new TCanvas("c1");
const Int_t ng = 100;
const Int_t kNMAX = 10000;
std::vector<Double_t> X(kNMAX), Y(kNMAX);
Double_t x = 0, stepx = 0.1;
while (!gSystem->ProcessEvents()) {
if (cursor + ng >= kNMAX) {
cursor = 0;
for (Int_t i = 0; i < ng; i++) {
X[i] = x;
Y[i] = TMath::Sin(x);
x += stepx;
}
} else {
X[cursor + ng] = x;
Y[cursor + ng] = TMath::Sin(x);
x += stepx;
cursor++;
}
TGraph *g = new TGraph(ng, X.data() + cursor, Y.data() + cursor);
g->SetMarkerStyle(21);
g->SetMarkerColor(kBlue);
g->SetLineColor(kGreen);
g->SetBit(kCanDelete); // let canvas delete graph when call TCanvas::Clear()
c1->Clear();
g->Draw("alp");
c1->Update();
gSystem->Sleep(10);
}
}
#define g(i)
Definition RSha256.hxx:105
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kGreen
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
#define X(type, name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
const Int_t kNMAX
@ kCanDelete
Definition TObject.h:373
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
The Canvas class.
Definition TCanvas.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:416
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
Author
Olivier Couet

Definition in file gtime.C.