Dear Valery, Pasha, I finally manage to get it. There're mainly 2 corrections on my original code. (1) Change father from TH1 to TObject (2) Change "Draw" implementation to ** void test::Draw(Option_t option) ** { ** fpx->Draw(); ** AppendPad(option) ** } This is purly by chance but anyway, it works now. The attached file is the total code The running process is * aa = new test() * aa->Draw() When move the mouse, it'll print all the value of x and y. When Click the mouse, a new Canvas will Popup. Thank you very much for all the help ! Xie W__W W__W / \ PHONE : 972 8 9343372 (o) 9471872 (h) / \ ( 0 _ 0) Fax : 972-8-946-6253 (0 _ 0 ) \_ V_/ E-mail: xiewei@ceres.weizmann.ac.il \_^ _/ / \ / \ =OOOo=======oOOO====================================OOOo=======oOOO====== #ifndef _test_ #define _test_ #include <stdlib.h> #include <TROOT.h> #include <TApplication.h> #include <TObject.h> #include <TCanvas.h> #include <TH1.h> #include <TRandom.h> class test:public TObject { private: TH1F *fHpx; public: test(); Int_t DistancetoPrimitive(Int_t px, Int_t py); void ExecuteEvent(Int_t event, Int_t px, Int_t py); void Draw(Option_t *option); ClassDef(test,0) }; #endif #include "test.h" ClassImp(test) test::test(): TObject() { // Fill histograms till user clicks "Stop Filling" button. static int cnt; if (!fHpx) { fHpx = new TH1F("hpx","",100,-4,4); fHpx->SetFillColor(kRed); cnt = 0; } int kUPDATE = 1000; float px, py; Int_t num=0; while (num<1000) { num++; gRandom->Rannor(px,py); //px and py will be two gaussian random numbers fHpx->Fill(px); } } Int_t test::DistancetoPrimitive(Int_t px, Int_t py) { //return TH1::DistancetoPrimitive(px, py); return 0; } void test::ExecuteEvent(Int_t event, Int_t px, Int_t py) { Float_t x,y; switch(event) { case kMouseMotion: x = gPad->AbsPixeltoX(px); y = gPad->AbsPixeltoY(py); printf("x=%.3g, y=%.3g\n",gPad->PadtoX(x),gPad->PadtoY(y)); break; case kButton1Down: TCanvas *newCanvas = new TCanvas("newCanvas","",700,500); break; } } void test::Draw(Option_t *option) { fHpx->Draw(); AppendPad(option); }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET