24from ROOT
import gRandom, gPad, gROOT, gVirtualX
25from ROOT
import kTRUE, kRed
26from ROOT
import TCanvas, TH2, TH2F
38 h = gPad.GetSelected();
42 if not isinstance( h, TH2 ):
45 gPad.GetCanvas().FeedbackMode( kTRUE )
51 uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
52 uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
53 pxmin, pxmax = gPad.XtoAbsPixel( uxmin ), gPad.XtoAbsPixel( uxmax )
54 pymin, pymax = gPad.YtoAbsPixel( uymin ), gPad.YtoAbsPixel( uymax )
57 gVirtualX.DrawLine( pxmin, self._old[1], pxmax, self._old[1] )
58 gVirtualX.DrawLine( self._old[0], pymin, self._old[0], pymax )
59 gVirtualX.DrawLine( pxmin, py, pxmax, py )
60 gVirtualX.DrawLine( px, pymin, px, pymax )
64 upx = gPad.AbsPixeltoX( px )
65 x = gPad.PadtoX( upx )
66 upy = gPad.AbsPixeltoY( py )
67 y = gPad.PadtoY( upy )
73 self._cX =
TCanvas(
'c2',
'Projection Canvas in X', 730, 10, 700, 500 )
75 self._DestroyPrimitive(
'X' )
78 self._cY =
TCanvas(
'c3',
'Projection Canvas in Y', 10, 550, 700, 500 )
80 self._DestroyPrimitive(
'Y' )
82 self.DrawSlice( h, y,
'Y' )
83 self.DrawSlice( h, x,
'X' )
87 def _DestroyPrimitive( self, xy ):
88 proj = getattr( self,
'_c'+xy ).GetPrimitive(
'Projection '+xy )
90 proj.IsA().Destructor( proj )
92 def DrawSlice( self, histo, value, xy ):
93 yx = xy ==
'X' and 'Y' or 'X'
96 canvas = getattr( self,
'_c'+xy )
100 bin = getattr( histo,
'Get%saxis' % xy )().FindBin( value )
101 hp = getattr( histo,
'Projection' + yx )(
'', bin, bin )
102 hp.SetFillColor( 38 )
103 hp.SetName(
'Projection ' + xy )
104 hp.SetTitle( xy +
'Projection of bin=%d' % bin )
105 hp.Fit(
'gaus',
'ql' )
111if __name__ ==
'__main__':
113 c1 =
TCanvas(
'c1',
'Dynamic Slice Example', 10, 10, 700, 500 )
114 c1.SetFillColor( 42 )
115 c1.SetFrameFillColor( 33 )
118 hpxpy =
TH2F(
'hpxpy',
'py vs px', 40, -4, 4, 40, -4, 4 )
120 x, y = ctypes.c_double( 0.1 ), ctypes.c_double( 0.101 )
121 for i
in range( 50000 ):
123 gRandom.Rannor( x, y )
124 hpxpy.Fill( x.value, y.value )
129 __main__.slicer = DynamicExec()
130 c1.AddExec(
'dynamic',
'TPython::Exec( "slicer()" );' )
Option_t Option_t SetLineWidth
Option_t Option_t SetLineColor
2-D histogram with a float per channel (see TH1 documentation)}