Logo ROOT   6.07/09
Reference Guide
gtime2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Example of TGraphTime showing how the class could be used to visualize
5 /// a set of particles with their time stamp in a MonteCarlo program.
6 ///
7 /// \macro_image
8 /// \macro_code
9 ///
10 /// \author Rene Brun
11 
12 #include "TRandom3.h"
13 #include "TMath.h"
14 #include "TMarker.h"
15 #include "TPaveLabel.h"
16 #include "TArrow.h"
17 #include "TGraphTime.h"
18 
19 void gtime2(Int_t nsteps = 200, Int_t np=5000) {
20  if (np > 5000) np = 5000;
21  Int_t color[5000];
22  Double_t cosphi[5000], sinphi[5000], speed[5000];
23  TRandom3 r;
24  Double_t xmin = 0, xmax = 10, ymin = -10, ymax = 10;
25  TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
26  g->SetTitle("TGraphTime demo 2;X;Y");
27  Int_t i,s;
28  Double_t phi,fact = xmax/Double_t(nsteps);
29  for (i=0;i<np;i++) { //calculate some object parameters
30  speed[i] = r.Uniform(0.5,1);
31  phi = r.Gaus(0,TMath::Pi()/6.);
32  cosphi[i] = fact*speed[i]*TMath::Cos(phi);
33  sinphi[i] = fact*speed[i]*TMath::Sin(phi);
34  Double_t rc = r.Rndm();
35  color[i] = kRed;
36  if (rc > 0.3) color[i] = kBlue;
37  if (rc > 0.7) color[i] = kYellow;
38  }
39  for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
40  for (i=0;i<np;i++) {
41  Double_t xx = s*cosphi[i];
42  if (xx < xmin) continue;
43  Double_t yy = s*sinphi[i];
44  TMarker *m = new TMarker(xx,yy,25);
45  m->SetMarkerColor(color[i]);
46  m->SetMarkerSize(1.5 -s/(speed[i]*nsteps));
47  g->Add(m,s);
48  }
49  g->Add(new TPaveLabel(.70,.92,.98,.99,Form("shower at %5.3f nsec",3.*s/nsteps),"brNDC"),s);
50  }
51  g->Draw();
52 }
53 
54 
55 
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax...
Definition: TGraphTime.h:31
float xmin
Definition: THbookFile.cxx:93
Random number generator class based on M.
Definition: TRandom3.h:29
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:94
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
Definition: Rtypes.h:61
float ymin
Definition: THbookFile.cxx:93
Manages Markers.
Definition: TMarker.h:31
int Int_t
Definition: RtypesCore.h:41
Definition: Rtypes.h:61
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:43
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:24
float ymax
Definition: THbookFile.cxx:93
TRandom2 r(17)
TMarker * m
Definition: textangle.C:8
char * Form(const char *fmt,...)
float xmax
Definition: THbookFile.cxx:93
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:46
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
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155