24from ROOT
import gRandom, gPad, gROOT, TCanvas, TH2, TH2F, kRed
34 h = gPad.GetSelected();
38 if not isinstance( h, TH2 ):
43 upx = gPad.AbsPixeltoX( px )
44 upy = gPad.AbsPixeltoY( py )
46 uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
47 uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
49 posx = array.array(
'd', [uxmin, uxmax])
50 posy = array.array(
'd', [upy, upy])
51 gPad.PaintPolyLine(2, posx, posy,
'i_slicex')
52 posx = array.array(
'd', [upx, upx])
53 posy = array.array(
'd', [uymin, uymax])
54 gPad.PaintPolyLine(2, posx, posy,
'i_slicey')
58 x = gPad.PadtoX( upx )
59 y = gPad.PadtoY( upy )
65 self._cX =
TCanvas(
'c2',
'Projection Canvas in X', 730, 10, 700, 500 )
67 self._DestroyPrimitive(
'X' )
70 self._cY =
TCanvas(
'c3',
'Projection Canvas in Y', 10, 550, 700, 500 )
72 self._DestroyPrimitive(
'Y' )
74 self.DrawSlice( h, y,
'Y' )
75 self.DrawSlice( h, x,
'X' )
79 def _DestroyPrimitive( self, xy ):
80 proj = getattr( self,
'_c'+xy ).GetPrimitive(
'Projection '+xy )
82 proj.IsA().Destructor( proj )
84 def DrawSlice( self, histo, value, xy ):
85 yx = xy ==
'X' and 'Y' or 'X'
88 canvas = getattr( self,
'_c'+xy )
92 bin = getattr( histo,
'Get%saxis' % xy )().FindBin( value )
93 hp = getattr( histo,
'Projection' + yx )(
'', bin, bin )
95 hp.SetName(
'Projection ' + xy )
96 hp.SetTitle( xy +
'Projection of bin=%d' % bin )
97 hp.Fit(
'gaus',
'ql' )
103if __name__ ==
'__main__':
105 gROOT.SetWebDisplay(
'off')
108 c1 =
TCanvas(
'c1',
'Dynamic Slice Example', 10, 10, 700, 500 )
109 c1.SetFillColor( 42 )
110 c1.SetFrameFillColor( 33 )
113 hpxpy =
TH2F(
'hpxpy',
'py vs px', 40, -4, 4, 40, -4, 4 )
115 x, y = ctypes.c_double( 0.1 ), ctypes.c_double( 0.101 )
116 for i
in range( 50000 ):
118 gRandom.Rannor( x, y )
119 hpxpy.Fill( x.value, y.value )
124 __main__.slicer = DynamicExec()
125 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)