Wrong coordinates after creating a new window

From one window with drawn histogram, on mouseclick I create a new window and draw a different histogram:

	def pixel_click(self):
		hist = ROOT.gPad.GetSelected()
		
		if not hist: return
		# Check if it was the histogram that was clicked
		if not isinstance(hist, ROOT.TH2): return
		# Check if it was a mouse click (mouse-up)
		if ROOT.gPad.GetEvent()==11:
			print ROOT.gPad
			canv = self.Canvas.GetCanvas()
			cx, cy = canv.GetEventX(), canv.GetEventY()
			# Get the histogram bin
			pix_x = int(canv.AbsPixeltoX(cx))
			pix_y = int(canv.AbsPixeltoY(cy))
			# Calculate the pdm pixel number
			pmt_num = pix_x/8+pix_y/8*6
			x1 = pix_x-pmt_num%6*8
			y1 = pix_y-pmt_num/6*8
			pix_num = (y1+8*x1)*36+pmt_num
			print pix_num
			print pix_x, pix_y, hist.GetBinContent(pix_x+1, pix_y+1), cx, cy, canv.PadtoX(pix_x)
			if not self.AnalysisFrame: self.AnalysisFrame = pAnalysisFrame(self.parent, 800, 800)
			else: self.AnalysisFrame.Canvas.GetCanvas().cd()
			self.etosTree.Draw("avg_pc_data["+str(pix_num)+"]:threshold[0]", "", "*")

The problem is, that the coordinated computed by AbsPixelTo… od Padto… are wrong after such operation - probably they have now coordinates of the new histogram even when I cd() to the old pad (cd() is succesfull, for if I attempt to draw just after cd in the same procedure, I draw in the old window). The coordinates on clicking are correct again if I resize the old window. So during resize something is recomputed. Can you tell me what and how can I do it manually? Calling ResizePad() did not help.

I think the generic advice in a case like this is to add a line:

before trying to get coordinates from a pad. It is related to the fact that even if you change things at the object level in ROOT, the actual Pads and Canvases remain unchanged until updated. Some actions automatically update the Pad, as does clicking.

Jean-François

I forgot to mention that Upate() and Modify() did not help. I need to resize the window only once after its creation, but anyway, still looking for a solution…

Hi,

might be better to ask this in the ROOT support forum? Olivier is probably your best chance, and I don’t think he’s reading along here. It is in any case outside my level of expertise …

Cheers,
Wim

Sometimes I look here too :slight_smile:

I would prefer to have a .C macro as example. I do not use the Python version of ROOT usually.
Just one remark. have a look at the remark at the end of the header here. It might help.

root.cern.ch/root/html534/TCanvas.html

SetWindowSize() as in the TCanvas manual helped. However, I suspect this should not have to be called manually and probably is some kind of bug. I’ll try to make a C++ working example when I’ll have a little bit of time.