7 from typing
import List, Tuple
13 import validationcomparison
18 """ Test get_comparison """
21 """ Set up testing of get_comparison """
25 "kolmogorov":
"kolmogorov",
26 "andersondarling":
"andersondarling"
28 basic_gaus_th1f = ROOT.TH1F(
"th1f",
"th1f", 5, -3, 3)
29 basic_gaus_th1f.FillRandom(
"gaus", 1000)
30 different_gaus_th1f = ROOT.TH1F(
"th1f",
"th1f", 5, -3, 3)
31 different_gaus_th1f.FillRandom(
"expo", 1000)
34 (basic_gaus_th1f, basic_gaus_th1f,
"equal"),
35 (basic_gaus_th1f, different_gaus_th1f,
"error"),
39 """ Use get_tester on the metaoptions to get the requested
40 comparison object and run that on two identical ROOT object.
41 Check that this indeed returns 'equal'.
47 obj1=obj[0].GetName(),
50 tester = validationcomparison.get_comparison(
57 self.assertEqual(tester.comparison_result, obj[2])
62 Various test cases for the Chi2Test wrapper class
69 Create a TProfile object with various content
71 p = ROOT.TProfile(name, name, 50, 0, 50.0)
72 entries_per_bin = int(entries / max_fill)
73 for i
in range(0, max_fill + 1):
74 for e
in range(0, entries_per_bin):
75 if fixed_number
is None:
76 p.Fill(i + 0.5, random.gauss(mu, sigma))
78 p.Fill(i + 0.5, fixed_number)
84 Creates and fills a root TEfficiency plot
86 p = ROOT.TEfficiency(name, name, bins, 0, 50)
88 for i
in range(0, 5000):
89 passed = random.uniform(0, 1.0) < eff
90 bin_content = random.uniform(0.0, 50.0)
91 p.Fill(passed, bin_content)
99 Create a TH1D and fill with random content
101 p = ROOT.TH1D(name, name, 50, 0, 20.0)
102 for i
in range(0, entries):
103 p.Fill(random.gauss(mu, sigma))
108 Generates unique names for ROOT objects
114 Setup method to generate profiles and histograms for tests
143 self.
root_name(
"profileZeroErrorBinsTwo"),
185 Test if comparing two similar TProfiles works
189 self.assertTrue(c.can_compare())
191 self.assertAlmostEqual(c._pvalue, 0.22495088947037362)
195 Test if comparing two identical TProfiles works
199 self.assertTrue(c.can_compare())
201 self.assertAlmostEqual(c._pvalue, 1)
204 """ Test if comparing to identical TProfiles with Kolmo Test works"""
206 self.assertTrue(c.can_compare())
208 self.assertAlmostEqual(c._pvalue, 1)
212 Test if the comparison of two TProfiles with very similar content works
214 c = validationcomparison.Chi2Test(
217 self.assertTrue(c.can_compare())
219 self.assertAlmostEqual(c._pvalue, 0.43093514577898634)
220 self.assertAlmostEqual(c._ndf, 49)
224 Test if bins with zero error are treated properly
235 c = validationcomparison.Chi2Test(
239 self.assertTrue(c.can_compare())
243 self.assertAlmostEqual(c._pvalue, 0.4835651485797353)
245 self.assertEqual(c._ndf, 49)
249 Test comparison of regular histograms
254 self.assertTrue(c.can_compare())
256 self.assertAlmostEqual(c._pvalue, 0.371600562118221)
257 self.assertAlmostEqual(c._chi2, 42.308970111484086)
258 self.assertAlmostEqual(c._chi2ndf, 1.0577242527871022)
259 self.assertEqual(c._ndf, 40)
263 Test if unsupported ROOT objects are treated properly
265 obj_not_supported = ROOT.TH2D(
"h2d",
"h2d", 50, 0, 50, 50, 0, 50)
266 c = validationcomparison.Chi2Test(self.
profileA, obj_not_supported)
267 self.assertFalse(c.can_compare())
271 Test if the comparison of differing objects is rejected
274 self.assertFalse(c.can_compare())
276 with self.assertRaises(validationcomparison.ObjectsNotSupported):
281 Test if two TEfficiency objects can be compared. Is a bit tricky
282 as TEfficiency does not support
285 c = validationcomparison.Chi2Test(self.
teffA, self.
teffB)
287 self.assertTrue(c.can_compare())
289 self.assertAlmostEqual(c._pvalue, 0.9760318312199932)
290 self.assertAlmostEqual(c._chi2, 8.16784873)
291 self.assertAlmostEqual(c._chi2ndf, 0.45376937)
292 self.assertEqual(c._ndf, 18)
296 Test if two TEfficiency objects can be compared. Is a bit tricky as
297 TEfficiency does not support Comparing the exact same TEfficiency
298 object should give back 100% agreement
301 c = validationcomparison.Chi2Test(self.
teffA, self.
teffA)
302 self.assertTrue(c.can_compare())
304 self.assertAlmostEqual(c._pvalue, 1.0)
305 self.assertAlmostEqual(c._chi2, 0.0)
306 self.assertAlmostEqual(c._chi2ndf, 0.0)
307 self.assertEqual(c._ndf, 18)
311 Test if the comparison attempt of profiles with differing bin count
314 c = validationcomparison.Chi2Test(
318 self.assertFalse(c.can_compare())
320 with self.assertRaises(validationcomparison.DifferingBinCount):
324 if __name__ ==
"__main__":
325 unittest.main(verbosity=2)