gtime2.C

Go to the documentation of this file.
00001 // example of TGraphTime showing how the class could be used to visualize
00002 // a set of particles with their time stamp in a MonteCarlo program.
00003 //Author: Rene Brun 14/07/2009
00004    
00005 #include "TRandom3.h"
00006 #include "TMath.h"
00007 #include "TMarker.h"
00008 #include "TPaveLabel.h"
00009 #include "TArrow.h"
00010 #include "TGraphTime.h"
00011    
00012 void gtime2(Int_t nsteps = 200, Int_t np=5000) {
00013    if (np > 5000) np = 5000;
00014    Int_t color[5000];
00015    Double_t cosphi[5000], sinphi[5000], speed[5000];
00016    TRandom3 r;
00017    Double_t xmin = 0, xmax = 10, ymin = -10, ymax = 10;
00018    TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);
00019    g->SetTitle("TGraphTime demo 2;X;Y");
00020    Int_t i,s;
00021    Double_t phi,fact = xmax/Double_t(nsteps);
00022    for (i=0;i<np;i++) { //calculate some object parameters
00023       speed[i]  = r.Uniform(0.5,1);
00024       phi       = r.Gaus(0,TMath::Pi()/6.);
00025       cosphi[i] = fact*speed[i]*TMath::Cos(phi);
00026       sinphi[i] = fact*speed[i]*TMath::Sin(phi);
00027       Double_t rc = r.Rndm();
00028       color[i] = kRed;
00029       if (rc > 0.3) color[i] = kBlue;
00030       if (rc > 0.7) color[i] = kYellow;
00031    }
00032    for (s=0;s<nsteps;s++) { //fill the TGraphTime step by step
00033       for (i=0;i<np;i++) {
00034          Double_t xx = s*cosphi[i];
00035          if (xx < xmin) continue;
00036          Double_t yy = s*sinphi[i];
00037          TMarker *m = new TMarker(xx,yy,25);
00038          m->SetMarkerColor(color[i]);
00039          m->SetMarkerSize(1.5 -s/(speed[i]*nsteps));
00040          g->Add(m,s);
00041       }
00042       g->Add(new TPaveLabel(.70,.92,.98,.99,Form("shower at %5.3f nsec",3.*s/nsteps),"brNDC"),s);
00043    }
00044    g->Draw();
00045 }
00046    
00047    
00048    

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