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