gtime.C

Go to the documentation of this file.
00001 // example of TGraphTime
00002 //Author: Rene Brun 14/07/2009
00003    
00004 #include "TCanvas.h"
00005 #include "TRandom3.h"
00006 #include "TMath.h"
00007 #include "TText.h"
00008 #include "TArrow.h"
00009 #include "TGraphTime.h"
00010 #include "TROOT.h"
00011    
00012 void gtime(Int_t nsteps = 500, Int_t np=100) {
00013    if (np > 1000) np = 1000;
00014    Int_t color[1000];
00015    Double_t rr[1000], phi[1000], dr[1000], size[1000];
00016    TRandom3 r;
00017    Double_t xmin = -10, xmax = 10, ymin = -10, ymax = 10;
00018    TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
00019    g->SetTitle("TGraphTime demo;X domain;Y domain");
00020    Int_t i,s;
00021    for (i=0;i<np;i++) { //calculate some object parameters
00022       rr[i]  = r.Uniform(0.1*xmax,0.2*xmax);
00023       phi[i] = r.Uniform(0,2*TMath::Pi());
00024       dr[i]  = r.Uniform(0,1)*0.9*xmax/Double_t(nsteps);
00025       Double_t rc = r.Rndm();
00026       color[i] = kRed;
00027       if (rc > 0.3) color[i] = kBlue;
00028       if (rc > 0.7) color[i] = kYellow;
00029       size[i] = r.Uniform(0.5,6);
00030    }
00031    for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
00032       for (i=0;i<np;i++) {
00033          Double_t newr = rr[i]+dr[i]*s;
00034          Double_t newsize = 0.2+size[i]*TMath::Abs(TMath::Sin(newr+10));
00035          Double_t newphi = phi[i] + 0.01*s;
00036          Double_t xx = newr*TMath::Cos(newphi);
00037          Double_t yy = newr*TMath::Sin(newphi);
00038          TMarker *m = new TMarker(xx,yy,20);
00039          m->SetMarkerColor(color[i]);
00040          m->SetMarkerSize(newsize);
00041          g->Add(m,s);
00042          if (i==np-1) g->Add(new TArrow(xmin,ymax,xx,yy,0.02,"-|>"), s);
00043       }
00044       g->Add(new TPaveLabel(.90,.92,.98,.97,Form("%d",s+1),"brNDC"),s);
00045    }
00046    g->Draw();
00047    
00048    //save object to a file
00049    TFile f("gtime.root","recreate");
00050    g->Write("g");
00051    //to view this object in another session do
00052    //  TFile f("gtime.root");
00053    //  g.Draw();
00054 }
00055    
00056    
00057    

Generated on Tue Jul 5 15:44:20 2011 for ROOT_528-00b_version by  doxygen 1.5.1