def nextpad():
    pn = gPad.GetName()
    cn = gPad.GetCanvas().GetName()
    pad = pn.replace(cn, "").replace("_", "")
    if pad == "":
        gPad.cd(1)
    else:
        gPad.GetCanvas().cd(int(pad) + 1)
Beispiel #2
0
def run_calib_script(infile, cmds, img_outfile=None):
    infile.cd()
    if gPad != None:
        the_canvas = gPad.GetCanvas()
        the_canvas.Clear()
    run_root_commands(cmds)
    if img_outfile is not None:
        the_canvas = gPad.GetCanvas()
        the_canvas.Print(img_outfile)
Beispiel #3
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()
Beispiel #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()
    #root_command = args[1]
    root_command = ".x " + " ".join(args[1:])

    if options.input_file:
        # try to open file if specified
        input_file = TFile(options.input_file)
        if input_file is None or input_file.IsZombie():
            print "Could not open file: %s" % (options.input_file)
            sys.exit(1)

    # load library functions
    hdmon_root_utils.load_calibration_library()

    # run the actual command
    if "HALLD_RECON_HOME" not in os.environ:
        print "HALLD_RECON_HOME not set!"
    else:
        print "Running commmand = " + root_command
        hdmon_root_utils.run_root_commands([root_command])

    # save canvas
    if options.output_image_filename:
        #if gPad is not None:   # check error management later
        the_canvas = gPad.GetCanvas()
        #    if the_canvas is not None:
        the_canvas.Print(options.output_image_filename + "." + image_suffix)

    # cleanup
    if options.input_file:
        input_file.Close()
Beispiel #6
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()