ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gtime2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Example of TGraphTime showing how the class could be used to visualize
4 /// a set of particles with their time stamp in a MonteCarlo program.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
10 
11 #include "TRandom3.h"
12 #include "TMath.h"
13 #include "TMarker.h"
14 #include "TPaveLabel.h"
15 #include "TArrow.h"
16 #include "TGraphTime.h"
17 
18 void gtime2(Int_t nsteps = 200, Int_t np=5000) {
19  if (np > 5000) np = 5000;
20  Int_t color[5000];
21  Double_t cosphi[5000], sinphi[5000], speed[5000];
22  TRandom3 r;
23  Double_t xmin = 0, xmax = 10, ymin = -10, ymax = 10;
24  TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
25  g->SetTitle("TGraphTime demo 2;X;Y");
26  Int_t i,s;
27  Double_t phi,fact = xmax/Double_t(nsteps);
28  for (i=0;i<np;i++) { //calculate some object parameters
29  speed[i] = r.Uniform(0.5,1);
30  phi = r.Gaus(0,TMath::Pi()/6.);
31  cosphi[i] = fact*speed[i]*TMath::Cos(phi);
32  sinphi[i] = fact*speed[i]*TMath::Sin(phi);
33  Double_t rc = r.Rndm();
34  color[i] = kRed;
35  if (rc > 0.3) color[i] = kBlue;
36  if (rc > 0.7) color[i] = kYellow;
37  }
38  for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
39  for (i=0;i<np;i++) {
40  Double_t xx = s*cosphi[i];
41  if (xx < xmin) continue;
42  Double_t yy = s*sinphi[i];
43  TMarker *m = new TMarker(xx,yy,25);
44  m->SetMarkerColor(color[i]);
45  m->SetMarkerSize(1.5 -s/(speed[i]*nsteps));
46  g->Add(m,s);
47  }
48  g->Add(new TPaveLabel(.70,.92,.98,.99,Form("shower at %5.3f nsec",3.*s/nsteps),"brNDC"),s);
49  }
50  g->Draw();
51 }
52 
53 
54 
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax...
Definition: TGraphTime.h:31
Random number generator class based on M.
Definition: TRandom3.h:29
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:40
int Int_t
Definition: RtypesCore.h:41
Definition: Rtypes.h:61
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
Float_t phi
Definition: shapesAnim.C:6
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="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152