How to execute commands after "Connect" method?

Dear colleagues,

I have a problem with GUI in ROOT. I have a script very similar to the “rqfiller.C” (“Connection” method used in this example) in tutorials and try to modify that for collect some coordinates of mouse clicks, after that terminate GUI and execute some calculations with these coordinates. But I have no idea how to terminate GUI and send obtained data to the next commands.

Thanks a lot in advance,

Nikita.

Hi Nikita,

I’m not sure I understand what you’re trying to achieve. Could you post a short running macro showing the issue you have?

Cheers, Bertrand

Thank you for response!

Here an example of my code:


1. #include <TROOT.h>
2. #include <TPad.h>
3. #include <TH1F.h>
4. #include <TCanvas.h>
5. #include <RQ_OBJECT.h>
6. #include "TF1.h"
7. #include <TMath.h>
8. #include "TROOT.h"
9. #include <TCanvas.h>
10. #include <cstring>
11. /////////////////////////////////////////////////////////////////////



12. class HFiller {

13. RQ_OBJECT("HFiller")  // for classes not derived from TQObject
14.                       // RQ_OBJECT macro should be used
15. private:
16.    TH1F   *fHist;   // histogram to fill
17.    TPad  *fPad;    // pad in which histogram is drawn
18.    TList *l;
19. public:
20.    ~HFiller() { }
21.    vector<double> x_vector;
22.    vector<double> y_vector;
23.    TH1F  *GetHist() const { return fHist; }
24.    TCanvas *c;// = (TCanvas *) gTQSender;
25.    TPad *pad;
26.    void  SetHist(TH1F *hist);
27.    TPad *GetPad() const { return fPad; }
28.    void  SetPad(TPad *pad);
29.    void  ExecuteEvent(Int_t event, Int_t px, Int_t py, TObject *sel);
30.    void  Draw(Option_t *opt = "") { fHist->AppendPad(opt); }
31. };

32. //___________________________________________________________________


33. void HFiller::SetHist(TH1F *hist)
34. {
35.    // Sets new hist for manual filling.

36.    if (!hist || (hist == fHist)) return;
37.    fHist = hist;
38. }

39. //___________________________________________________________________
40. void HFiller::SetPad(TPad *pad)
41. {
42.    // Sets new pad containing histogram.

43.    if (!pad || (pad == fPad)) return;
44.    fPad = pad;
45. }

46. //___________________________________________________________________
47. void HFiller::ExecuteEvent(Int_t event, Int_t px, Int_t py, TObject *sel)
48. {
49.    // Actions in reponse to mouse button events.

50.    //TCanvas *c = (TCanvas *) gTQSender;
51.    c = (TCanvas *) gTQSender;
52.    pad = (TPad *) c->GetSelectedPad();
53.    
54.    
55.    if (!pad || !fHist) return;
56.    if (pad != fPad) return;
57.    
58.    if(event==1) //left button click
59.    {
60. 		Float_t x = pad->AbsPixeltoX(px);
61. 		Float_t y = pad->AbsPixeltoY(py);
62. 		
63. 		x_vector.push_back(x);
64. 		y_vector.push_back(y);
65. 		
66. 		cout<<" x="<<x<<" y="<<y<<endl;
67.    }

68.    if(event == 3)//right button click
69.    {
70. 		//here I want to terminate gui
71.    }
72. }


73. //___________________________________________________________________
74. void rqfiller()
75. {
76.    // simple test of Pad Event Dispatcher
77. 	gROOT->Reset();
78.    TCanvas *c1 = new TCanvas("c1", "Test of Canvas Event Signal",
79.                               900, 500);

80.    TPad *p1 = new TPad("p1","",0.01,0.05,0.95,0.95);
81.    //TPad *p2 = new TPad("p2","",0.51,0.05,0.99,0.95);

82.    p1->Draw();
83.    ////// create 1-dim histogram filler

84.    p1->cd();

85.    HFiller *h1 = new HFiller();

86. 	TH1F* hist1 = new TH1F("h2","h2",1000,-4,4);
87. 	hist1->FillRandom("gaus",30000);
88. 	//hist1->Draw();
89.     
90. 	h1->SetPad(p1);
91. 	h1->SetHist(hist1);
92. 	h1->GetHist()->SetFillColor(16);
93.   
94.    h1->Draw();
95.  // connect signal to histogam 
96.    c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HFiller",h1, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");
97.    
98.    //I want to write coordinates of clicks:
99.    for(int i=0;i<h1->x_vector.size();i++)
100.    {
101. 	   cout<<"i="<<i<<" x="<<h1->x_vector[i]<<" y="<<h1->x_vector[i]<<endl;
102.    }

103. }

I want to collect mouse clicks (string 58), collect them (strings 63,64), after that terminate gui (string 68, but I have no idea how to terminate it) and print collected coordinates (strings 99-102).

Thank you.

   if(event == 3) { // right button click
      int k = 0, l = 0;
      // here I want to terminate gui
      c->Close();
      for (auto i = x_vector.begin(); i != x_vector.end(); ++i) {
        cout << "x[" << k++ <<  "]: " << *i << endl;
      }
      for (auto j = y_vector.begin(); j != y_vector.end(); ++j) {
        cout << "y[" << l++ <<  "]: " << *j << endl;
      }
   }

Or implement a Closed() method in the HFiller class and connect it to the Closed() signal of TCanvas:

//___________________________________________________________________
void HFiller::Closed()
{
   c = (TCanvas *) gTQSender;
   int k = 0, l = 0;
   for (auto i = x_vector.begin(); i != x_vector.end(); ++i) {
      cout << "x[" << k++ <<  "]: " << *i << endl;
   }
   for (auto j = y_vector.begin(); j != y_vector.end(); ++j) {
      cout << "y[" << l++ <<  "]: " << *j << endl;
   }
}

[...]

   if (event == 3) { // right button click
      // here I want to terminate gui
      c->Close();
   }

[...]

   // connect signal to histogam 
   c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HFiller", h1, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");
   c1->Connect("Closed()", "HFiller", h1, "Closed()");

Thanks a lot, Bertrand!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.