Re: How to get coordinate information of a histogram

From: Wei Xie (xiewei@clever.weizmann.ac.il)
Date: Tue Aug 04 1998 - 17:34:28 MEST


Dear Valery

The class defination "test.h" and its implementation "test.c" is 
followed. The running is like

*      aa = new test();
*      aa->Draw();


In the code, the implentation "Draw()" is like: 

        void test::Draw()
        {
           fpx->Draw(); //fpx is a TH1 object
        }

When running like:
    
      aa = new test();
      aa->Draw();

It will produce a Canvas with a histogram in it. After selecting the
option "Event Status" in TCanvas, I can find three objects:
 
        c1   --> default Canvas
        fpx   -->the TH1 object.
        TFrame  --> Frame that contains the "fpx"

But can not find "aa". Deleting "aa" will have no effect on the existing 
TCanvas and Histograms.  It seems to say that "aa" is not in the Canvas.        

Sincerely yours

Xie

********
>>test.h
********
	#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 TH1 {

	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();


	   ClassDef(test,0)
	};

	#endif

**********
>> test.c  
*********
	#include "test.h"

	ClassImp(test)

	test::test(): TH1()
	{

	   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);
	}

	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",gPad->PadtoX(x),gPad->PadtoY(y));
	       break;
	   }

	}

	void test::Draw()
	{
	   fHpx->Draw();
	}



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET