def pix2xy(pad):
    px=gPad.GetEventX()
    py=gPad.GetEventY()
    tl=[74,44]
    tr=[1346,44]
    br=[1346,401]
    bl=[74,401]
    x=int(float(px-tl[0])/(tr[0]-tl[0])*46)-23+1
    y=int(float(py-tl[1])/(bl[1]-tl[1])*11)-5
    if x<=0: x-=1
    return [x,-y]
Example #2
0
    def __call__(self):

        h = gPad.GetSelected()
        if not h:
            return

        if not isinstance(h, TH2):
            return

        gPad.GetCanvas().FeedbackMode(kTRUE)

        # erase old position and draw a line at current position
        px = gPad.GetEventX()
        py = gPad.GetEventY()

        uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
        uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
        pxmin, pxmax = gPad.XtoAbsPixel(uxmin), gPad.XtoAbsPixel(uxmax)
        pymin, pymax = gPad.YtoAbsPixel(uymin), gPad.YtoAbsPixel(uymax)

        if self._old != None:
            gVirtualX.DrawLine(pxmin, self._old[1], pxmax, self._old[1])
            gVirtualX.DrawLine(self._old[0], pymin, self._old[0], pymax)
        gVirtualX.DrawLine(pxmin, py, pxmax, py)
        gVirtualX.DrawLine(px, pymin, px, pymax)

        self._old = px, py

        upx = gPad.AbsPixeltoX(px)
        x = gPad.PadtoX(upx)
        upy = gPad.AbsPixeltoY(py)
        y = gPad.PadtoY(upy)

        padsav = gPad

        # create or set the display canvases
        if not self._cX:
            self._cX = TCanvas('c2', 'Projection Canvas in X', 730, 10, 700,
                               500)
        else:
            self._DestroyPrimitive('X')

        if not self._cY:
            self._cY = TCanvas('c3', 'Projection Canvas in Y', 10, 550, 700,
                               500)
        else:
            self._DestroyPrimitive('Y')

        self.DrawSlice(h, y, 'Y')
        self.DrawSlice(h, x, 'X')

        padsav.cd()
Example #3
0
def pix2xy(pad):
  px=gPad.GetEventX()
  py=gPad.GetEventY()
  # determined empirically (by clicking on canvas):
  tl=[71,79]
  tr=[709,44]
  br=[709,716]
  bl=[71,716]
  x=int(float(px-tl[0])/(tr[0]-tl[0])*22)-11
  y=int(float(py-tl[1])/(bl[1]-tl[1])*22)-11
  if x>=0: x+=1
  if y>=0: y+=1
  # swap y because pixel-coordinate inverted:
  y=-y
  # swap x to make it downstream view:
  x=-x
  return [x,y]
Example #4
0
   def __call__( self ):

      h = self.hname
      if not h:
         return

      if not isinstance( h, TH2 ):
         return

      gPad.GetCanvas().FeedbackMode( kTRUE )

      event = gPad.GetEvent()
      if (event==1): # left mouse click
         self.projection = not self.projection
      elif (event==12): # middle mouse click
         self.logy = not self.logy

    # erase old position and draw a line at current position
    #(gPad coordinate system)
      px = gPad.GetEventX()
      py = gPad.GetEventY()

      # min/max x values visible on the pad (xmin and xmax of the x-axis)
      uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
      uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
      # same in pixels
      pxmin, pxmax = gPad.XtoAbsPixel( uxmin ), gPad.XtoAbsPixel( uxmax )
      pymin, pymax = gPad.YtoAbsPixel( uymin ), gPad.YtoAbsPixel( uymax )

      # if self.projection:
      #    axis = h.GetYaxis()
      # else:
      #    axis = h.GetXaxis()

      scaleY = abs((pymax-pymin) / (uymax-uymin))
      scaleX = abs((pxmax-pxmin) / (uxmax-uxmin))

      width = 0.0 # arbitrary default value [cm]

      if self._old:
         width = self.range[1] - self.range[0]

      ywidth = int(width * scaleY)
      xwidth = int(width * scaleX)

      if self._old != None:
         if self.projection:
#            gVirtualX.DrawBox( pxmin, self._old[1]-ywidth, pxmax, self._old[1], kSolid)
            gVirtualX.DrawLine( pxmin, self._old[1], pxmax, self._old[1])
            gVirtualX.DrawLine( pxmin, self._old[1]-ywidth, pxmax, self._old[1]-ywidth)
         else:
#            gVirtualX.DrawBox( self._old[0], pymin, self._old[0]+ywidth, pymax, kSolid )
            gVirtualX.DrawLine( self._old[0], pymin, self._old[0], pymax)
            gVirtualX.DrawLine( self._old[0]+xwidth, pymin, self._old[0]+xwidth, pymax)

      # Normally these calls remove old lines, but we do not need them since we update the pad in the end of DrawSlice
      # BUG: the lines disappear when the mouse does not move. This happens if this gPad.Update() is called. TODO: How to fix it?
      # if self.projection:
      #    gVirtualX.DrawLine( pxmin, py, pxmax, py )
      #    gVirtualX.DrawLine( pxmin, py-ywidth, pxmax, py-ywidth )
      # else:
      #    gVirtualX.DrawLine( px, pymin, px, pymax)
      #    gVirtualX.DrawLine( px+xwidth, pymin, px+xwidth, pymax)

      if self.projection:
         gPad.SetUniqueID(py)
      else:
         gPad.SetUniqueID(px)

      self._old = px, py

      upx = gPad.AbsPixeltoX( px )
      x = gPad.PadtoX( upx )
      upy = gPad.AbsPixeltoY( py )
      y = gPad.PadtoY( upy )

      padsav = gPad

    # create or set the display canvases
      if not self._cX:
         self._cX = gPad.GetCanvas().GetPad(2)
      else:
         self._DestroyPrimitive( 'X' )

      if not self._cY:
         self._cY = gPad.GetCanvas().GetPad(2)
      else:
         self._DestroyPrimitive( 'Y' )

      if self.projection:
         self.range = self.DrawSlice( h, y, 'Y' )
      else:
         self.range = self.DrawSlice( h, x, 'X' )

      padsav.cd()
Example #5
0
    def __call__(self):

        h = self.hname
        if not h:
            return

        if not isinstance(h, TH2):
            return

        gPad.GetCanvas().FeedbackMode(kTRUE)

        event = gPad.GetEvent()
        if (event == 1):  # left mouse click
            self.projection = not self.projection
        elif (event == 12):  # middle mouse click
            self.logy = not self.logy

    # erase old position and draw a line at current position
    #(gPad coordinate system)
        px = gPad.GetEventX()
        py = gPad.GetEventY()

        uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
        uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
        pxmin, pxmax = gPad.XtoAbsPixel(uxmin), gPad.XtoAbsPixel(uxmax)
        pymin, pymax = gPad.YtoAbsPixel(uymin), gPad.YtoAbsPixel(uymax)

        # if self.projection:
        #    axis = h.GetYaxis()
        # else:
        #    axis = h.GetXaxis()

        width = 1

        if self._old != None:
            if self.projection:
                gVirtualX.DrawBox(pxmin, self._old[1] - width, pxmax,
                                  self._old[1], kSolid)
            else:
                gVirtualX.DrawBox(self._old[0], pymin, self._old[0] + width,
                                  pymax, kSolid)
        if self.projection:
            gVirtualX.DrawBox(pxmin, py, pxmax, py + width, kSolid)
        else:
            gVirtualX.DrawBox(px, pymin, px, pymax + width, kSolid)

        self._old = px, py

        upx = gPad.AbsPixeltoX(px)
        x = gPad.PadtoX(upx)
        upy = gPad.AbsPixeltoY(py)
        y = gPad.PadtoY(upy)

        padsav = gPad

        # create or set the display canvases
        if not self._cX:
            self._cX = gPad.GetCanvas().GetPad(2)
        else:
            self._DestroyPrimitive('X')

        if not self._cY:
            self._cY = gPad.GetCanvas().GetPad(2)
        else:
            self._DestroyPrimitive('Y')

        if self.projection:
            self.DrawSlice(h, y, 'Y')
        else:
            self.DrawSlice(h, x, 'X')

        padsav.cd()