Logo ROOT   6.10/09
Reference Guide
exec3.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// Example of using signal/slot in TCanvas/TPad to get feedback about processed events.
4 /// Note that slots can be either functions or class methods.
5 /// Compare this with tutorials $ROOTSYS/tutorials/hist/exec1.C and $ROOTSYS/tutorials/hist/exec2.C.
6 ///
7 /// \macro_code
8 ///
9 /// \author Ilka Antcheva
10 
11 #include <TH1.h>
12 #include <TCanvas.h>
13 #include <TQObject.h>
14 #include "TROOT.h"
15 
16 void exec3()
17 {
18  // Temporary work around the lack of automatic refresh of the list
19  // when a script is reloaded.
20  gROOT->GetListOfGlobalFunctions()->Delete();
21 
22  TH1F *h = new TH1F("h","h",100,-3,3);
23  h->FillRandom("gaus",1000);
24  TCanvas *c1=new TCanvas("c1");
25  h->Draw();
26  c1->Update();
27  c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
28  "exec3event(Int_t,Int_t,Int_t,TObject*)");
29 }
30 
31 void exec3event(Int_t event, Int_t x, Int_t y, TObject *selected)
32 {
33  TCanvas *c = (TCanvas *) gTQSender;
34  printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n", c->GetName(),
35  event, x, y, selected->IsA()->GetName());
36 }
return c1
Definition: legend1.C:41
R__EXTERN void * gTQSender
Definition: TQObject.h:45
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:375
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
int Int_t
Definition: RtypesCore.h:41
Double_t x[n]
Definition: legend1.C:17
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3294
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
The Canvas class.
Definition: TCanvas.h:31
Double_t y[n]
Definition: legend1.C:17
Mother of all ROOT objects.
Definition: TObject.h:37
const char * GetName() const
Returns name of object.
Definition: TPad.h:251
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2208
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364