Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr018_time2.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview 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/// See the [TGraphTime documentation](https://root.cern/doc/master/classTGraphTime.html)
8///
9/// \macro_image
10/// \macro_code
11/// \author Rene Brun
12
13#include "TRandom3.h"
14#include "TMath.h"
15#include "TMarker.h"
16#include "TPaveLabel.h"
17#include "TArrow.h"
18#include "TGraphTime.h"
19#include <vector>
20
21void gr018_time2(Int_t nsteps = 200, Int_t np = 5000)
22{
23 if (np > 5000) np = 5000;
24 std::vector<Int_t> color(np);
25 std::vector<Double_t> cosphi(np), sinphi(np), speed(np);
26 TRandom3 r;
27 Double_t xmin = 0, xmax = 10, ymin = -10, ymax = 10;
29 g->SetTitle("TGraphTime demo 2;X;Y");
31 for (Int_t i = 0; i < np; i++) { // calculate some object parameters
32 speed[i] = r.Uniform(0.5, 1);
33 Double_t phi = r.Gaus(0, TMath::Pi() / 6.);
34 cosphi[i] = fact * speed[i] * TMath::Cos(phi);
35 sinphi[i] = fact * speed[i] * TMath::Sin(phi);
36 Double_t rc = r.Rndm();
37 color[i] = kRed;
38 if (rc > 0.3) color[i] = kBlue;
39 if (rc > 0.7) color[i] = kYellow;
40 }
41 for (Int_t s = 0; s < nsteps; s++) { // fill the TGraphTime step by step
42 for (Int_t i = 0; i < np; i++) {
43 Double_t xx = s*cosphi[i];
44 if (xx < xmin) continue;
45 Double_t yy = s*sinphi[i];
46 TMarker *m = new TMarker(xx,yy,25);
47 m->SetMarkerColor(color[i]);
48 m->SetMarkerSize(1.5 -s/(speed[i]*nsteps));
49 g->Add(m, s);
50 }
51 g->Add(new TPaveLabel(.70,.92,.98,.99,TString::Format("shower at %5.3f nsec",3.*s/nsteps),"brNDC"),s);
52 }
53
54 g->Draw();
55
56 // save object as animated gif
57 // g->SaveAnimatedGif("gr18_time2.gif");
58
59 // start animation, can be stopped with g->Animate(kFALSE);
60 // g->Animate();
61}
62
63
64
#define g(i)
Definition RSha256.hxx:105
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
float xmin
float ymin
float xmax
float ymax
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:39
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:46
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
Definition TGraphTime.h:30
Manages Markers.
Definition TMarker.h:22
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
Random number generator class based on M.
Definition TRandom3.h:27
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
TMarker m
Definition textangle.C:8