Belle II Software  release-05-02-19
validationTestColorScheme.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """
5 <header>
6 <output>validationTestColorScheme.root</output>
7 <contact>Kilian Lieret, Kilian.Lieret@campus.lmu.de</contact>
8 </header>
9 """
10 
11 """
12 To test the color scheme.
13 Set generate_reference = True to generate the reference files.
14 """
15 
16 from validationtest import add_properties
17 from ROOT import TFile, TH1F, TNamed
18 import basf2
19 
20 
21 def generate_gaus(title, options, distort=0.):
22  """ Generate trivial gaus filled histogram.
23  Use the distort parameter (0<=distort<=1) for distortion to get histograms
24  with failing comparisons.
25  """
26  # fix seed, because we need to see failing and passing comparisons
27 
28  assert(0 <= distort <= 1)
29 
30  basf2.set_random_seed(10)
31 
32  norm = 300
33 
34  name = title.lower().replace(" ", "_")
35 
36  gaus = TH1F(name, title, 100, -3, 3)
37 
38  gaus.FillRandom("gaus", int((1 - distort) * norm))
39  # add a different histogram
40  basf2.set_random_seed(100)
41  distortion = TH1F(name, title, 100, -3, 3)
42  distortion.FillRandom("gaus", int(distort * norm))
43  gaus.Add(distortion)
44 
45  add_properties(gaus, options)
46  gaus.Write()
47 
48 
49 tfile = TFile("validationTestColorScheme.root", "RECREATE")
50 
51 TNamed(
52  "Description",
53  "These plots test the color scheme. Make sure to also check the 'expert' "
54  "plot checkbox to see the color scheme for expert plots."
55 ).Write()
56 
57 mop_expert = {
58  'Description': "Test color scheme",
59  'Check': "Check color",
60  'Contact': "Kilian Lieret, Kilian.Lieret@campus.lmu.de",
61  'MetaOptions': "pvalue-error=0.6"
62 }
63 mop_shifter = mop_expert.copy()
64 mop_shifter['MetaOptions'] += ", shifter"
65 
66 generate_reference = False
67 
68 if not generate_reference:
69  # No reference files for the plots that have to be checked manually
70  generate_gaus("manual", mop_shifter)
71  generate_gaus("manual expert", mop_expert)
72 
73 if generate_reference:
74  # The reference will contain the normal (undistorted) histogram
75  # always.
76  generate_gaus("pass", mop_shifter)
77  generate_gaus("pass expert", mop_expert)
78  generate_gaus("warn", mop_shifter)
79  generate_gaus("fail", mop_shifter)
80  generate_gaus("warn expert", mop_expert)
81  generate_gaus("fail expert", mop_expert)
82 else:
83  generate_gaus("pass", mop_shifter, distort=0.1)
84  generate_gaus("pass expert", mop_expert, distort=0.1)
85  generate_gaus("warn", mop_shifter, distort=0.5)
86  generate_gaus("fail", mop_shifter, distort=1)
87  generate_gaus("warn expert", mop_expert, distort=0.5)
88  generate_gaus("fail expert", mop_expert, distort=1)
89 
90 tfile.Close()