23 from ROOT
import gRandom, gPad, gROOT, gVirtualX
24 from ROOT
import kTRUE, kRed
25 from ROOT
import TCanvas, TH2, TH2F, Double
37 h = gPad.GetSelected();
41 if not isinstance( h, TH2 ):
44 gPad.GetCanvas().FeedbackMode( kTRUE )
50 uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
51 uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
52 pxmin, pxmax = gPad.XtoAbsPixel( uxmin ), gPad.XtoAbsPixel( uxmax )
53 pymin, pymax = gPad.YtoAbsPixel( uymin ), gPad.YtoAbsPixel( uymax )
56 gVirtualX.DrawLine( pxmin, self._old[1], pxmax, self._old[1] )
57 gVirtualX.DrawLine( self._old[0], pymin, self._old[0], pymax )
58 gVirtualX.DrawLine( pxmin, py, pxmax, py )
59 gVirtualX.DrawLine( px, pymin, px, pymax )
63 upx = gPad.AbsPixeltoX( px )
64 x = gPad.PadtoX( upx )
65 upy = gPad.AbsPixeltoY( py )
66 y = gPad.PadtoY( upy )
72 self._cX =
TCanvas(
'c2',
'Projection Canvas in X', 730, 10, 700, 500 )
74 self._DestroyPrimitive(
'X' )
77 self._cY =
TCanvas(
'c3',
'Projection Canvas in Y', 10, 550, 700, 500 )
79 self._DestroyPrimitive(
'Y' )
81 self.DrawSlice( h, y,
'Y' )
82 self.DrawSlice( h, x,
'X' )
86 def _DestroyPrimitive( self, xy ):
87 proj = getattr( self,
'_c'+xy ).GetPrimitive(
'Projection '+xy )
89 proj.IsA().Destructor( proj )
91 def DrawSlice( self, histo, value, xy ):
92 yx = xy ==
'X' and 'Y' or 'X' 95 canvas = getattr( self,
'_c'+xy )
99 bin = getattr( histo,
'Get%saxis' % xy )().FindBin( value )
100 hp = getattr( histo,
'Projection' + yx )(
'', bin, bin )
101 hp.SetFillColor( 38 )
102 hp.SetName(
'Projection ' + xy )
103 hp.SetTitle( xy +
'Projection of bin=%d' % bin )
104 hp.Fit(
'gaus',
'ql' )
110 if __name__ ==
'__main__':
112 c1 =
TCanvas(
'c1',
'Dynamic Slice Example', 10, 10, 700, 500 )
113 c1.SetFillColor( 42 )
114 c1.SetFrameFillColor( 33 )
117 hpxpy =
TH2F(
'hpxpy',
'py vs px', 40, -4, 4, 40, -4, 4 )
120 for i
in range( 50000 ):
121 gRandom.Rannor( x, y )
127 __main__.slicer = DynamicExec()
128 c1.AddExec(
'dynamic',
'TPython::Exec( "slicer()" );' )
2-D histogram with a float per channel (see TH1 documentation)}