@@ -17,5 +17,42 @@ def test_GetBinError(self):
1717 self .assertEqual (h .GetBinErrorLow (1 , 1 ), 2 )
1818
1919
20+ class TH2Operations (unittest .TestCase ):
21+ """
22+ Test TH2D arithmetic operations
23+ """
24+
25+ def setUp (self ):
26+ self .h1 = ROOT .TH2D ("h1" , "h1" , 2 , 0 , 2 , 2 , 0 , 2 )
27+ self .h2 = ROOT .TH2D ("h2" , "h2" , 2 , 0 , 2 , 2 , 0 , 2 )
28+
29+ self .h1 .Fill (0.5 , 0.5 , 2.0 )
30+ self .h2 .Fill (0.5 , 0.5 , 3.0 )
31+
32+ def test_addition (self ):
33+ hsum = self .h1 + self .h2
34+ self .assertAlmostEqual (hsum .GetBinContent (1 , 1 ), 5.0 )
35+
36+ def test_subtraction (self ):
37+ hdiff = self .h2 - self .h1
38+ self .assertAlmostEqual (hdiff .GetBinContent (1 , 1 ), 1.0 )
39+
40+ def test_multiplication (self ):
41+ hprod = self .h1 * self .h2
42+ self .assertAlmostEqual (hprod .GetBinContent (1 , 1 ), 6.0 )
43+
44+ def test_division (self ):
45+ hdiv = self .h2 / self .h1
46+ self .assertAlmostEqual (hdiv .GetBinContent (1 , 1 ), 1.5 )
47+
48+ def test_scalar_multiplication_left (self ):
49+ hscaled = 2.0 * self .h1
50+ self .assertAlmostEqual (hscaled .GetBinContent (1 , 1 ), 4.0 )
51+
52+ def test_scalar_multiplication_right (self ):
53+ hscaled = self .h1 * 2.0
54+ self .assertAlmostEqual (hscaled .GetBinContent (1 , 1 ), 4.0 )
55+
56+
2057if __name__ == '__main__' :
2158 unittest .main ()
0 commit comments