Logo ROOT   6.10/09
Reference Guide
seism.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook -js
4 /// Strip chart example.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
10 
11 #include "TStopwatch.h"
12 #include "TDatime.h"
13 #include "TStyle.h"
14 #include "TH1F.h"
15 #include "TCanvas.h"
16 #include "TSystem.h"
17 #include "TRandom.h"
18 #include <stdio.h>
19 
20 void seism() {
21 
22  TStopwatch sw; sw.Start();
23  //set time offset
24  TDatime dtime;
25  gStyle->SetTimeOffset(dtime.Convert());
26 
27  TCanvas *c1 = new TCanvas("c1","Time on axis",10,10,1000,500);
28  c1->SetGrid();
29 
30  Float_t bintime = 1; //one bin = 1 second. change it to set the time scale
31  TH1F *ht = new TH1F("ht","The ROOT seism",10,0,10*bintime);
32  Float_t signalval = 1000;
33  ht->SetMaximum( signalval);
34  ht->SetMinimum(-signalval);
35  ht->SetStats(0);
36  ht->SetLineColor(2);
37  ht->GetXaxis()->SetTimeDisplay(1);
38  ht->GetYaxis()->SetNdivisions(520);
39  ht->Draw();
40 
41  for (Int_t i=1;i<2300;i++) {
42  //======= Build a signal : noisy damped sine ======
43  Float_t noise = gRandom->Gaus(0,120);
44  if (i > 700) noise += signalval*sin((i-700.)*6.28/30)*exp((700.-i)/300.);
45  ht->SetBinContent(i,noise);
46  c1->Modified();
47  c1->Update();
48  gSystem->ProcessEvents(); //canvas can be edited during the loop
49  }
50  printf("Real Time = %8.3fs, Cpu Time = %8.3fs\n",sw.RealTime(),sw.CpuTime());
51 }
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:423
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:110
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:375
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
float Float_t
Definition: RtypesCore.h:53
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
return c1
Definition: legend1.C:41
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:229
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:376
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:125
int Int_t
Definition: RtypesCore.h:41
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1478
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:323
double sin(double)
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:161
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition: TH1.cxx:8325
TAxis * GetYaxis()
Definition: TH1.h:301
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
The Canvas class.
Definition: TCanvas.h:31
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:181
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2208
double exp(double)
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8103
void Modified(Bool_t flag=1)
Definition: TPad.h:410
TAxis * GetXaxis()
Definition: TH1.h:300
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
Stopwatch class.
Definition: TStopwatch.h:28