22 from ROOT
import gRandom, gPad, gROOT, gVirtualX
23 from ROOT
import kTRUE, kRed
24 from ROOT
import TCanvas, TH2, TH2F, Double
36 h = gPad.GetSelected();
40 if not isinstance( h, TH2 ):
43 gPad.GetCanvas().FeedbackMode( kTRUE )
49 uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
50 uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
51 pxmin, pxmax = gPad.XtoAbsPixel( uxmin ), gPad.XtoAbsPixel( uxmax )
52 pymin, pymax = gPad.YtoAbsPixel( uymin ), gPad.YtoAbsPixel( uymax )
55 gVirtualX.DrawLine( pxmin, self._old[1], pxmax, self._old[1] )
56 gVirtualX.DrawLine( self._old[0], pymin, self._old[0], pymax )
57 gVirtualX.DrawLine( pxmin, py, pxmax, py )
58 gVirtualX.DrawLine( px, pymin, px, pymax )
62 upx = gPad.AbsPixeltoX( px )
63 x = gPad.PadtoX( upx )
64 upy = gPad.AbsPixeltoY( py )
65 y = gPad.PadtoY( upy )
71 self._cX =
TCanvas(
'c2',
'Projection Canvas in X', 730, 10, 700, 500 )
73 self._DestroyPrimitive(
'X' )
76 self._cY =
TCanvas(
'c3',
'Projection Canvas in Y', 10, 550, 700, 500 )
78 self._DestroyPrimitive(
'Y' )
80 self.DrawSlice( h, y,
'Y' )
81 self.DrawSlice( h, x,
'X' )
85 def _DestroyPrimitive( self, xy ):
86 proj = getattr( self,
'_c'+xy ).GetPrimitive(
'Projection '+xy )
88 proj.IsA().Destructor( proj )
90 def DrawSlice( self, histo, value, xy ):
91 yx = xy ==
'X' and 'Y' or 'X'
94 canvas = getattr( self,
'_c'+xy )
98 bin = getattr( histo,
'Get%saxis' % xy )().FindBin( value )
99 hp = getattr( histo,
'Projection' + yx )(
'', bin, bin )
100 hp.SetFillColor( 38 )
101 hp.SetName(
'Projection ' + xy )
102 hp.SetTitle( xy +
'Projection of bin=%d' % bin )
103 hp.Fit(
'gaus',
'ql' )
109 if __name__ ==
'__main__':
111 c1 =
TCanvas(
'c1',
'Dynamic Slice Example', 10, 10, 700, 500 )
112 c1.SetFillColor( 42 )
113 c1.SetFrameFillColor( 33 )
116 hpxpy =
TH2F(
'hpxpy',
'py vs px', 40, -4, 4, 40, -4, 4 )
119 for i
in xrange( 50000 ):
120 gRandom.Rannor( x, y )
126 __main__.slicer = DynamicExec()
127 c1.AddExec(
'dynamic',
'TPython::Exec( "slicer()" );' )
2-D histogram with a float per channel (see TH1 documentation)}