Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr017_time.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview Example of TGraphTime. See the [TGraphTime documentation](https://root.cern/doc/master/classTGraphTime.html)
5///
6/// \macro_image
7/// \macro_code
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 <vector>
17
18void gr017_time(Int_t nsteps = 500, Int_t np = 100)
19{
20 if (np > 1000) np = 1000;
21 std::vector<Int_t> color(np);
22 std::vector<Double_t> rr(np), phi(np), dr(np), size(np);
23 TRandom3 r;
24 Double_t xmin = -10, xmax = 10, ymin = -10, ymax = 10;
25 auto g = new TGraphTime(nsteps, xmin, ymin, xmax, ymax);
26 g->SetTitle("TGraphTime demo;X domain;Y domain");
27 for (Int_t 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 if (rc > 0.7)
33 color[i] = kYellow;
34 else if (rc > 0.3)
35 color[i] = kBlue;
36 else
37 color[i] = kRed;
38
39 size[i] = r.Uniform(0.5, 6);
40 }
41 for (Int_t s = 0; s < nsteps; s++) { // fill the TGraphTime step by step
42 for (Int_t i = 0; i < np; i++) {
43 Double_t newr = rr[i] + dr[i] * s;
44 Double_t newsize = 0.2 + size[i] * TMath::Abs(TMath::Sin(newr + 10));
45 Double_t newphi = phi[i] + 0.01 * s;
48 TMarker *m = new TMarker(xx, yy, 20);
49 m->SetMarkerColor(color[i]);
51 g->Add(m, s);
52 if (i == np - 1)
53 g->Add(new TArrow(xmin, ymax, xx, yy, 0.02, "-|>"), s);
54 }
55 g->Add(new TPaveLabel(.90, .92, .98, .97, TString::Format("%d", s + 1), "brNDC"), s);
56 }
57
58 g->Draw();
59
60 // save object as animated gif
61 // g->SaveAnimatedGif("gr17_time.gif");
62
63 // save object to a file
64 auto f = TFile::Open("gr17_time.root","recreate");
65 f->WriteObject(g, "g");
66 delete f;
67
68 // to view this object in another session do
69 // TFile::Open("gr17_time.root");
70 // g->Draw();
71}
72
73
74
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
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 WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
float xmin
float ymin
float xmax
float ymax
Draw all kinds of Arrows.
Definition TArrow.h:29
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:39
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:46
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4130
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
Definition TGraphTime.h:30
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
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
TMarker m
Definition textangle.C:8