24from ROOT
import gRandom, gPad, gROOT
25from ROOT
import kTRUE, kRed
26from ROOT
import TCanvas, TH2, TH2F
38 h = gPad.GetSelected();
42 if not isinstance( h, TH2 ):
45 gPad.FeedbackMode( kTRUE )
49 upx = gPad.AbsPixeltoX( px )
50 upy = gPad.AbsPixeltoY( py )
52 uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax()
53 uymin, uymax = gPad.GetUymin(), gPad.GetUymax()
57 gPad.PaintLine( uxmin, self._old[1], uxmax, self._old[1] )
58 gPad.PaintLine( self._old[0], uymin, self._old[0], uymax )
59 gPad.PaintLine( uxmin, upy, uxmax, upy )
60 gPad.PaintLine( upx, uymin, upx, uymax )
64 x = gPad.PadtoX( upx )
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' )
109if __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 )
119 x, y = ctypes.c_double( 0.1 ), ctypes.c_double( 0.101 )
120 for i
in range( 50000 ):
122 gRandom.Rannor( x, y )
123 hpxpy.Fill( x.value, y.value )
128 __main__.slicer = DynamicExec()
129 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)