ROOT logo

From $ROOTSYS/tutorials/graphs/gtime2.C

// example of TGraphTime showing how the class could be used to visualize
// a set of particles with their time stamp in a MonteCarlo program.
//Author: Rene Brun 14/07/2009
   
#include "TRandom3.h"
#include "TMath.h"
#include "TMarker.h"
#include "TPaveLabel.h"
#include "TArrow.h"
#include "TGraphTime.h"
   
void gtime2(Int_t nsteps = 200, Int_t np=5000) {
   if (np > 5000) np = 5000;
   Int_t color[5000];
   Double_t cosphi[5000], sinphi[5000], speed[5000];
   TRandom3 r;
   Double_t xmin = 0, xmax = 10, ymin = -10, ymax = 10;
   TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
   g->SetTitle("TGraphTime demo 2;X;Y");
   Int_t i,s;
   Double_t phi,fact = xmax/Double_t(nsteps);
   for (i=0;i<np;i++) { //calculate some object parameters
      speed[i]  = r.Uniform(0.5,1);
      phi       = r.Gaus(0,TMath::Pi()/6.);
      cosphi[i] = fact*speed[i]*TMath::Cos(phi);
      sinphi[i] = fact*speed[i]*TMath::Sin(phi);
      Double_t rc = r.Rndm();
      color[i] = kRed;
      if (rc > 0.3) color[i] = kBlue;
      if (rc > 0.7) color[i] = kYellow;
   }
   for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
      for (i=0;i<np;i++) {
         Double_t xx = s*cosphi[i];
         if (xx < xmin) continue;
         Double_t yy = s*sinphi[i];
         TMarker *m = new TMarker(xx,yy,25);
         m->SetMarkerColor(color[i]);
         m->SetMarkerSize(1.5 -s/(speed[i]*nsteps));
         g->Add(m,s);
      }
      g->Add(new TPaveLabel(.70,.92,.98,.99,Form("shower at %5.3f nsec",3.*s/nsteps),"brNDC"),s);
   }
   g->Draw();
}
   
   
   
 gtime2.C:1
 gtime2.C:2
 gtime2.C:3
 gtime2.C:4
 gtime2.C:5
 gtime2.C:6
 gtime2.C:7
 gtime2.C:8
 gtime2.C:9
 gtime2.C:10
 gtime2.C:11
 gtime2.C:12
 gtime2.C:13
 gtime2.C:14
 gtime2.C:15
 gtime2.C:16
 gtime2.C:17
 gtime2.C:18
 gtime2.C:19
 gtime2.C:20
 gtime2.C:21
 gtime2.C:22
 gtime2.C:23
 gtime2.C:24
 gtime2.C:25
 gtime2.C:26
 gtime2.C:27
 gtime2.C:28
 gtime2.C:29
 gtime2.C:30
 gtime2.C:31
 gtime2.C:32
 gtime2.C:33
 gtime2.C:34
 gtime2.C:35
 gtime2.C:36
 gtime2.C:37
 gtime2.C:38
 gtime2.C:39
 gtime2.C:40
 gtime2.C:41
 gtime2.C:42
 gtime2.C:43
 gtime2.C:44
 gtime2.C:45
 gtime2.C:46
 gtime2.C:47
 gtime2.C:48
 gtime2.C:49