plothist 1.4.0__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plothist/_version.py +2 -2
- plothist/comparison.py +111 -105
- plothist/examples/1d_hist/1d_comparison_asymmetry.py +37 -0
- plothist/examples/1d_hist/1d_comparison_difference.py +40 -0
- plothist/examples/1d_hist/1d_comparison_efficiency.py +37 -0
- plothist/examples/1d_hist/1d_comparison_only_efficiency.py +33 -0
- plothist/examples/1d_hist/1d_comparison_pull.py +37 -0
- plothist/examples/1d_hist/1d_comparison_ratio.py +37 -0
- plothist/examples/1d_hist/1d_comparison_relative_difference.py +37 -0
- plothist/examples/1d_hist/1d_comparison_split_ratio.py +37 -0
- plothist/examples/1d_hist/1d_elt1.py +38 -0
- plothist/examples/1d_hist/1d_elt1_stacked.py +45 -0
- plothist/examples/1d_hist/1d_elt2.py +33 -0
- plothist/examples/1d_hist/1d_hist_simple.py +28 -0
- plothist/examples/1d_hist/1d_int_category.py +41 -0
- plothist/examples/1d_hist/1d_profile.py +33 -0
- plothist/examples/1d_hist/1d_side_by_side.py +58 -0
- plothist/examples/1d_hist/1d_str_category.py +41 -0
- plothist/examples/1d_hist/README.rst +4 -0
- plothist/examples/2d_hist/2d_hist_correlations.py +65 -0
- plothist/examples/2d_hist/2d_hist_simple.py +28 -0
- plothist/examples/2d_hist/2d_hist_simple_discrete_colormap.py +42 -0
- plothist/examples/2d_hist/2d_hist_uneven.py +28 -0
- plothist/examples/2d_hist/2d_hist_with_projections.py +36 -0
- plothist/examples/2d_hist/README.rst +4 -0
- plothist/examples/README.rst +7 -0
- plothist/examples/advanced/1d_comparison_advanced.py +87 -0
- plothist/examples/advanced/1d_side_by_side_with_numbers.py +81 -0
- plothist/examples/advanced/README.rst +4 -0
- plothist/examples/advanced/asymmetry_comparison_advanced.py +133 -0
- plothist/examples/advanced/model_examples_flatten2D.py +86 -0
- plothist/examples/func_1d/README.rst +4 -0
- plothist/examples/func_1d/fct_1d.py +27 -0
- plothist/examples/func_1d/fct_1d_stacked.py +42 -0
- plothist/examples/model_ex/README.rst +4 -0
- plothist/examples/model_ex/model_all_comparisons.py +103 -0
- plothist/examples/model_ex/model_all_comparisons_no_model_unc.py +115 -0
- plothist/examples/model_ex/model_examples_pull.py +56 -0
- plothist/examples/model_ex/model_examples_pull_no_model_unc.py +59 -0
- plothist/examples/model_ex/model_examples_stacked.py +74 -0
- plothist/examples/model_ex/model_examples_stacked_unstacked.py +60 -0
- plothist/examples/model_ex/model_examples_unstacked.py +57 -0
- plothist/examples/model_ex/model_with_stacked_and_unstacked_function_components.py +50 -0
- plothist/examples/model_ex/model_with_stacked_and_unstacked_histograms_components.py +69 -0
- plothist/examples/model_ex/ratio_data_vs_model_with_stacked_and_unstacked_function_components.py +61 -0
- plothist/examples/utility/README.rst +4 -0
- plothist/examples/utility/add_text_example.py +39 -0
- plothist/examples/utility/color_palette_hists.py +94 -0
- plothist/examples/utility/color_palette_squares.py +100 -0
- plothist/examples/utility/matplotlib_vs_plothist_style.py +63 -0
- plothist/histogramming.py +60 -39
- plothist/plothist_style.py +54 -57
- plothist/plotters.py +207 -194
- plothist/test_helpers.py +43 -0
- plothist/variable_registry.py +46 -30
- {plothist-1.4.0.dist-info → plothist-1.5.0.dist-info}/METADATA +1 -1
- plothist-1.5.0.dist-info/RECORD +63 -0
- plothist/scripts/__init__.py +0 -3
- plothist/scripts/make_examples.py +0 -209
- plothist-1.4.0.dist-info/RECORD +0 -17
- plothist-1.4.0.dist-info/entry_points.txt +0 -2
- {plothist-1.4.0.dist-info → plothist-1.5.0.dist-info}/WHEEL +0 -0
- {plothist-1.4.0.dist-info → plothist-1.5.0.dist-info}/licenses/AUTHORS.md +0 -0
- {plothist-1.4.0.dist-info → plothist-1.5.0.dist-info}/licenses/LICENSE +0 -0
plothist/_version.py
CHANGED
plothist/comparison.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import boost_histogram as bh
|
|
3
4
|
import numpy as np
|
|
4
5
|
from scipy import stats
|
|
5
6
|
|
|
6
7
|
from plothist.histogramming import _check_counting_histogram
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
def _check_uncertainty_type(uncertainty_type):
|
|
10
|
+
def _check_uncertainty_type(uncertainty_type: str) -> None:
|
|
10
11
|
"""
|
|
11
12
|
Check that the uncertainty type is valid.
|
|
12
13
|
|
|
@@ -27,13 +28,13 @@ def _check_uncertainty_type(uncertainty_type):
|
|
|
27
28
|
)
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
def _is_unweighted(hist):
|
|
31
|
+
def _is_unweighted(hist: bh.Histogram) -> bool:
|
|
31
32
|
"""
|
|
32
33
|
Check whether a histogram is unweighted.
|
|
33
34
|
|
|
34
35
|
Parameters
|
|
35
36
|
----------
|
|
36
|
-
hist :
|
|
37
|
+
hist : bh.Histogram
|
|
37
38
|
The histogram to check.
|
|
38
39
|
|
|
39
40
|
Returns
|
|
@@ -44,7 +45,9 @@ def _is_unweighted(hist):
|
|
|
44
45
|
return np.allclose(hist.variances(), hist.values())
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
def get_asymmetrical_uncertainties(
|
|
48
|
+
def get_asymmetrical_uncertainties(
|
|
49
|
+
hist: bh.Histogram,
|
|
50
|
+
) -> tuple[np.ndarray, np.ndarray]:
|
|
48
51
|
"""
|
|
49
52
|
Get Poisson asymmetrical uncertainties for a histogram via a frequentist approach based on a confidence-interval computation.
|
|
50
53
|
Asymmetrical uncertainties can only be computed for an unweighted histogram, because the bin contents of a weighted histogram do not follow a Poisson distribution.
|
|
@@ -52,14 +55,14 @@ def get_asymmetrical_uncertainties(hist):
|
|
|
52
55
|
|
|
53
56
|
Parameters
|
|
54
57
|
----------
|
|
55
|
-
hist :
|
|
58
|
+
hist : bh.Histogram
|
|
56
59
|
The histogram.
|
|
57
60
|
|
|
58
61
|
Returns
|
|
59
62
|
-------
|
|
60
|
-
uncertainties_low :
|
|
63
|
+
uncertainties_low : np.ndarray
|
|
61
64
|
The lower uncertainties.
|
|
62
|
-
uncertainties_high :
|
|
65
|
+
uncertainties_high : np.ndarray
|
|
63
66
|
The upper uncertainties.
|
|
64
67
|
|
|
65
68
|
Raise
|
|
@@ -83,13 +86,13 @@ def get_asymmetrical_uncertainties(hist):
|
|
|
83
86
|
return uncertainties_low, uncertainties_high
|
|
84
87
|
|
|
85
88
|
|
|
86
|
-
def _check_binning_consistency(hist_list):
|
|
89
|
+
def _check_binning_consistency(hist_list: list[bh.Histogram]) -> None:
|
|
87
90
|
"""
|
|
88
91
|
Check that all the histograms in the provided list share the same definition of their bins.
|
|
89
92
|
|
|
90
93
|
Parameters
|
|
91
94
|
----------
|
|
92
|
-
hist_list : list
|
|
95
|
+
hist_list : list[bh.Histogram]
|
|
93
96
|
The list of histograms to check.
|
|
94
97
|
|
|
95
98
|
Raise
|
|
@@ -106,15 +109,15 @@ def _check_binning_consistency(hist_list):
|
|
|
106
109
|
raise ValueError("The bins of the histograms must be equal.")
|
|
107
110
|
|
|
108
111
|
|
|
109
|
-
def get_ratio_variances(h1, h2):
|
|
112
|
+
def get_ratio_variances(h1: bh.Histogram, h2: bh.Histogram) -> np.ndarray:
|
|
110
113
|
"""
|
|
111
114
|
Calculate the variances of the ratio of two uncorrelated histograms (h1/h2).
|
|
112
115
|
|
|
113
116
|
Parameters
|
|
114
117
|
----------
|
|
115
|
-
h1 :
|
|
118
|
+
h1 : bh.Histogram
|
|
116
119
|
The first histogram.
|
|
117
|
-
h2 :
|
|
120
|
+
h2 : bh.Histogram
|
|
118
121
|
The second histogram.
|
|
119
122
|
|
|
120
123
|
Returns
|
|
@@ -131,38 +134,39 @@ def get_ratio_variances(h1, h2):
|
|
|
131
134
|
_check_counting_histogram(h1)
|
|
132
135
|
_check_counting_histogram(h2)
|
|
133
136
|
|
|
134
|
-
np.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
np.seterr(divide="warn", invalid="warn")
|
|
142
|
-
|
|
143
|
-
return ratio_variances
|
|
137
|
+
with np.errstate(divide="ignore", invalid="ignore"):
|
|
138
|
+
return np.where(
|
|
139
|
+
h2.values() != 0,
|
|
140
|
+
h1.variances() / h2.values() ** 2
|
|
141
|
+
+ h2.variances() * h1.values() ** 2 / h2.values() ** 4,
|
|
142
|
+
np.nan,
|
|
143
|
+
)
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
def get_pull(
|
|
146
|
+
def get_pull(
|
|
147
|
+
h1: bh.Histogram,
|
|
148
|
+
h2: bh.Histogram,
|
|
149
|
+
h1_uncertainty_type: str = "symmetrical",
|
|
150
|
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
|
147
151
|
"""
|
|
148
152
|
Compute the pull between two histograms.
|
|
149
153
|
|
|
150
154
|
Parameters
|
|
151
155
|
----------
|
|
152
|
-
h1 :
|
|
156
|
+
h1 : bh.Histogram
|
|
153
157
|
The first histogram.
|
|
154
|
-
h2 :
|
|
158
|
+
h2 : bh.Histogram
|
|
155
159
|
The second histogram.
|
|
156
160
|
h1_uncertainty_type : str, optional
|
|
157
161
|
What kind of bin uncertainty to use for h1: "symmetrical" for the Poisson standard deviation derived from the variance stored in the histogram object, "asymmetrical" for asymmetrical uncertainties based on a Poisson confidence interval. Default is "symmetrical".
|
|
158
162
|
|
|
159
163
|
Returns
|
|
160
164
|
-------
|
|
161
|
-
pull_values :
|
|
165
|
+
pull_values : np.ndarray
|
|
162
166
|
The pull values.
|
|
163
|
-
pull_uncertainties_low :
|
|
167
|
+
pull_uncertainties_low : np.ndarray
|
|
164
168
|
The lower uncertainties on the pull. Always ones.
|
|
165
|
-
pull_uncertainties_high :
|
|
169
|
+
pull_uncertainties_high : np.ndarray
|
|
166
170
|
The upper uncertainties on the pull. Always ones.
|
|
167
171
|
"""
|
|
168
172
|
_check_uncertainty_type(h1_uncertainty_type)
|
|
@@ -195,26 +199,30 @@ def get_pull(h1, h2, h1_uncertainty_type="symmetrical"):
|
|
|
195
199
|
)
|
|
196
200
|
|
|
197
201
|
|
|
198
|
-
def get_difference(
|
|
202
|
+
def get_difference(
|
|
203
|
+
h1: bh.Histogram,
|
|
204
|
+
h2: bh.Histogram,
|
|
205
|
+
h1_uncertainty_type: str = "symmetrical",
|
|
206
|
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
|
199
207
|
"""
|
|
200
208
|
Compute the difference between two histograms.
|
|
201
209
|
|
|
202
210
|
Parameters
|
|
203
211
|
----------
|
|
204
|
-
h1 :
|
|
212
|
+
h1 : bh.Histogram
|
|
205
213
|
The first histogram.
|
|
206
|
-
h2 :
|
|
214
|
+
h2 : bh.Histogram
|
|
207
215
|
The second histogram.
|
|
208
216
|
h1_uncertainty_type : str, optional
|
|
209
217
|
What kind of bin uncertainty to use for h1: "symmetrical" for the Poisson standard deviation derived from the variance stored in the histogram object, "asymmetrical" for asymmetrical uncertainties based on a Poisson confidence interval. Default is "symmetrical".
|
|
210
218
|
|
|
211
219
|
Returns
|
|
212
220
|
-------
|
|
213
|
-
difference_values :
|
|
221
|
+
difference_values : np.ndarray
|
|
214
222
|
The difference values.
|
|
215
|
-
difference_uncertainties_low :
|
|
223
|
+
difference_uncertainties_low : np.ndarray
|
|
216
224
|
The lower uncertainties on the difference.
|
|
217
|
-
difference_uncertainties_high :
|
|
225
|
+
difference_uncertainties_high : np.ndarray
|
|
218
226
|
The upper uncertainties on the difference.
|
|
219
227
|
"""
|
|
220
228
|
_check_uncertainty_type(h1_uncertainty_type)
|
|
@@ -240,7 +248,7 @@ def get_difference(h1, h2, h1_uncertainty_type="symmetrical"):
|
|
|
240
248
|
)
|
|
241
249
|
|
|
242
250
|
|
|
243
|
-
def
|
|
251
|
+
def get_efficiency(h1: bh.Histogram, h2: bh.Histogram) -> tuple[np.ndarray, np.ndarray]:
|
|
244
252
|
"""
|
|
245
253
|
Calculate the ratio of two correlated histograms (h1/h2), in which the entries of h1 are a subsample of the entries of h2.
|
|
246
254
|
The variances are calculated according to the formula given in :ref:`documentation-statistics-label`.
|
|
@@ -253,16 +261,16 @@ def get_efficency(h1, h2):
|
|
|
253
261
|
|
|
254
262
|
Parameters
|
|
255
263
|
----------
|
|
256
|
-
h1 :
|
|
264
|
+
h1 : bh.Histogram
|
|
257
265
|
The first histogram.
|
|
258
|
-
h2 :
|
|
266
|
+
h2 : bh.Histogram
|
|
259
267
|
The second histogram.
|
|
260
268
|
|
|
261
269
|
Returns
|
|
262
270
|
-------
|
|
263
|
-
efficiency_values :
|
|
271
|
+
efficiency_values : np.ndarray
|
|
264
272
|
The efficiency values.
|
|
265
|
-
efficiency_uncertainties :
|
|
273
|
+
efficiency_uncertainties : np.ndarray
|
|
266
274
|
The uncertainties on the efficiency values.
|
|
267
275
|
|
|
268
276
|
Raises
|
|
@@ -303,23 +311,23 @@ def get_efficency(h1, h2):
|
|
|
303
311
|
return efficiency_values, np.sqrt(efficiency_variances)
|
|
304
312
|
|
|
305
313
|
|
|
306
|
-
def get_asymmetry(h1, h2):
|
|
314
|
+
def get_asymmetry(h1: bh.Histogram, h2: bh.Histogram) -> tuple[np.ndarray, np.ndarray]:
|
|
307
315
|
"""
|
|
308
316
|
Get the asymmetry between two histograms h1 and h2, defined as (h1 - h2) / (h1 + h2).
|
|
309
317
|
Only symmetrical uncertainties are supported.
|
|
310
318
|
|
|
311
319
|
Parameters
|
|
312
320
|
----------
|
|
313
|
-
h1 :
|
|
321
|
+
h1 : bh.Histogram
|
|
314
322
|
The first histogram.
|
|
315
|
-
h2 :
|
|
323
|
+
h2 : bh.Histogram
|
|
316
324
|
The second histogram.
|
|
317
325
|
|
|
318
326
|
Returns
|
|
319
327
|
-------
|
|
320
|
-
asymmetry_values :
|
|
328
|
+
asymmetry_values : np.ndarray
|
|
321
329
|
The asymmetry values.
|
|
322
|
-
asymmetry_uncertainties :
|
|
330
|
+
asymmetry_uncertainties : np.ndarray
|
|
323
331
|
The uncertainties on the asymmetry.
|
|
324
332
|
"""
|
|
325
333
|
_check_binning_consistency([h1, h2])
|
|
@@ -339,19 +347,19 @@ def get_asymmetry(h1, h2):
|
|
|
339
347
|
|
|
340
348
|
|
|
341
349
|
def get_ratio(
|
|
342
|
-
h1,
|
|
343
|
-
h2,
|
|
344
|
-
h1_uncertainty_type="symmetrical",
|
|
345
|
-
ratio_uncertainty_type="uncorrelated",
|
|
346
|
-
):
|
|
350
|
+
h1: bh.Histogram,
|
|
351
|
+
h2: bh.Histogram,
|
|
352
|
+
h1_uncertainty_type: str = "symmetrical",
|
|
353
|
+
ratio_uncertainty_type: str = "uncorrelated",
|
|
354
|
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
|
347
355
|
"""
|
|
348
356
|
Compute the ratio h1/h2 between two uncorrelated histograms h1 and h2.
|
|
349
357
|
|
|
350
358
|
Parameters
|
|
351
359
|
----------
|
|
352
|
-
h1 :
|
|
360
|
+
h1 : bh.Histogram
|
|
353
361
|
The numerator histogram.
|
|
354
|
-
h2 :
|
|
362
|
+
h2 : bh.Histogram
|
|
355
363
|
The denominator histogram.
|
|
356
364
|
h1_uncertainty_type : str, optional
|
|
357
365
|
What kind of bin uncertainty to use for h1: "symmetrical" for the Poisson standard deviation derived from the variance stored in the histogram object, "asymmetrical" for asymmetrical uncertainties based on a Poisson confidence interval. Default is "symmetrical".
|
|
@@ -363,11 +371,11 @@ def get_ratio(
|
|
|
363
371
|
|
|
364
372
|
Returns
|
|
365
373
|
-------
|
|
366
|
-
ratio_values :
|
|
374
|
+
ratio_values : np.ndarray
|
|
367
375
|
The ratio values.
|
|
368
|
-
ratio_uncertainties_low :
|
|
376
|
+
ratio_uncertainties_low : np.ndarray
|
|
369
377
|
The lower uncertainties on the ratio.
|
|
370
|
-
ratio_uncertainties_high :
|
|
378
|
+
ratio_uncertainties_high : np.ndarray
|
|
371
379
|
The upper uncertainties on the ratio.
|
|
372
380
|
|
|
373
381
|
Raises
|
|
@@ -419,19 +427,19 @@ def get_ratio(
|
|
|
419
427
|
|
|
420
428
|
|
|
421
429
|
def get_comparison(
|
|
422
|
-
h1,
|
|
423
|
-
h2,
|
|
424
|
-
comparison,
|
|
425
|
-
h1_uncertainty_type="symmetrical",
|
|
426
|
-
):
|
|
430
|
+
h1: bh.Histogram,
|
|
431
|
+
h2: bh.Histogram,
|
|
432
|
+
comparison: str,
|
|
433
|
+
h1_uncertainty_type: str = "symmetrical",
|
|
434
|
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
|
427
435
|
"""
|
|
428
436
|
Compute the comparison between two histograms.
|
|
429
437
|
|
|
430
438
|
Parameters
|
|
431
439
|
----------
|
|
432
|
-
h1 :
|
|
440
|
+
h1 : bh.Histogram
|
|
433
441
|
The first histogram for comparison.
|
|
434
|
-
h2 :
|
|
442
|
+
h2 : bh.Histogram
|
|
435
443
|
The second histogram for comparison.
|
|
436
444
|
comparison : str
|
|
437
445
|
The type of comparison ("ratio", "split_ratio", "pull", "difference", "relative_difference", "efficiency", or "asymmetry").
|
|
@@ -443,11 +451,11 @@ def get_comparison(
|
|
|
443
451
|
|
|
444
452
|
Returns
|
|
445
453
|
-------
|
|
446
|
-
values :
|
|
454
|
+
values : np.ndarray
|
|
447
455
|
The comparison values.
|
|
448
|
-
lower_uncertainties :
|
|
456
|
+
lower_uncertainties : np.ndarray
|
|
449
457
|
The lower uncertainties on the comparison values.
|
|
450
|
-
upper_uncertainties :
|
|
458
|
+
upper_uncertainties : np.ndarray
|
|
451
459
|
The upper uncertainties on the comparison values.
|
|
452
460
|
|
|
453
461
|
Raises
|
|
@@ -462,49 +470,47 @@ def get_comparison(
|
|
|
462
470
|
_check_counting_histogram(h1)
|
|
463
471
|
_check_counting_histogram(h2)
|
|
464
472
|
|
|
465
|
-
np.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
h1, h2, h1_uncertainty_type, "uncorrelated"
|
|
470
|
-
)
|
|
471
|
-
elif comparison == "split_ratio":
|
|
472
|
-
values, lower_uncertainties, upper_uncertainties = get_ratio(
|
|
473
|
-
h1, h2, h1_uncertainty_type, "split"
|
|
474
|
-
)
|
|
475
|
-
elif comparison == "relative_difference":
|
|
476
|
-
values, lower_uncertainties, upper_uncertainties = get_ratio(
|
|
477
|
-
h1, h2, h1_uncertainty_type, "uncorrelated"
|
|
478
|
-
)
|
|
479
|
-
values -= 1 # relative difference is ratio-1
|
|
480
|
-
elif comparison == "pull":
|
|
481
|
-
values, lower_uncertainties, upper_uncertainties = get_pull(
|
|
482
|
-
h1, h2, h1_uncertainty_type
|
|
483
|
-
)
|
|
484
|
-
elif comparison == "difference":
|
|
485
|
-
values, lower_uncertainties, upper_uncertainties = get_difference(
|
|
486
|
-
h1, h2, h1_uncertainty_type
|
|
487
|
-
)
|
|
488
|
-
elif comparison == "asymmetry":
|
|
489
|
-
if h1_uncertainty_type == "asymmetrical":
|
|
490
|
-
raise ValueError(
|
|
491
|
-
"Asymmetrical uncertainties are not supported for the asymmetry comparison."
|
|
473
|
+
with np.errstate(divide="ignore", invalid="ignore"):
|
|
474
|
+
if comparison == "ratio":
|
|
475
|
+
values, lower_uncertainties, upper_uncertainties = get_ratio(
|
|
476
|
+
h1, h2, h1_uncertainty_type, "uncorrelated"
|
|
492
477
|
)
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
478
|
+
elif comparison == "split_ratio":
|
|
479
|
+
values, lower_uncertainties, upper_uncertainties = get_ratio(
|
|
480
|
+
h1, h2, h1_uncertainty_type, "split"
|
|
481
|
+
)
|
|
482
|
+
elif comparison == "relative_difference":
|
|
483
|
+
values, lower_uncertainties, upper_uncertainties = get_ratio(
|
|
484
|
+
h1, h2, h1_uncertainty_type, "uncorrelated"
|
|
485
|
+
)
|
|
486
|
+
values -= 1 # relative difference is ratio-1
|
|
487
|
+
elif comparison == "pull":
|
|
488
|
+
values, lower_uncertainties, upper_uncertainties = get_pull(
|
|
489
|
+
h1, h2, h1_uncertainty_type
|
|
490
|
+
)
|
|
491
|
+
elif comparison == "difference":
|
|
492
|
+
values, lower_uncertainties, upper_uncertainties = get_difference(
|
|
493
|
+
h1, h2, h1_uncertainty_type
|
|
494
|
+
)
|
|
495
|
+
elif comparison == "asymmetry":
|
|
496
|
+
if h1_uncertainty_type == "asymmetrical":
|
|
497
|
+
raise ValueError(
|
|
498
|
+
"Asymmetrical uncertainties are not supported for the asymmetry comparison."
|
|
499
|
+
)
|
|
500
|
+
values, uncertainties = get_asymmetry(h1, h2)
|
|
501
|
+
lower_uncertainties = uncertainties
|
|
502
|
+
upper_uncertainties = uncertainties
|
|
503
|
+
elif comparison == "efficiency":
|
|
504
|
+
if h1_uncertainty_type == "asymmetrical":
|
|
505
|
+
raise ValueError(
|
|
506
|
+
"Asymmetrical uncertainties are not supported in an efficiency computation."
|
|
507
|
+
)
|
|
508
|
+
values, uncertainties = get_efficiency(h1, h2)
|
|
509
|
+
lower_uncertainties = uncertainties
|
|
510
|
+
upper_uncertainties = uncertainties
|
|
511
|
+
else:
|
|
498
512
|
raise ValueError(
|
|
499
|
-
"
|
|
513
|
+
f"{comparison} not available as a comparison ('ratio', 'split_ratio', 'pull', 'difference', 'relative_difference', 'asymmetry' or 'efficiency')."
|
|
500
514
|
)
|
|
501
|
-
values, uncertainties = get_efficency(h1, h2)
|
|
502
|
-
lower_uncertainties = uncertainties
|
|
503
|
-
upper_uncertainties = uncertainties
|
|
504
|
-
else:
|
|
505
|
-
raise ValueError(
|
|
506
|
-
f"{comparison} not available as a comparison ('ratio', 'split_ratio', 'pull', 'difference', 'relative_difference', 'asymmetry' or 'efficiency')."
|
|
507
|
-
)
|
|
508
|
-
np.seterr(divide="warn", invalid="warn")
|
|
509
515
|
|
|
510
516
|
return values, lower_uncertainties, upper_uncertainties
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Asymmetry
|
|
3
|
+
=========
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the asymmetry comparison [(h1-h2)/(h1+h2)].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathbfit{h}_1$",
|
|
33
|
+
h2_label=r"$\mathbfit{h}_2$",
|
|
34
|
+
comparison="asymmetry", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_asymmetry.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Difference
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the difference [h1-h2].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import add_text, plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathcal{H}_{1}$",
|
|
33
|
+
h2_label=r"$\mathcal{H}_{2}$",
|
|
34
|
+
comparison="difference", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
add_text("Comparison of two hist with difference plot", ax=ax_main)
|
|
38
|
+
add_text("Difference ax", x="right", ax=ax_comparison)
|
|
39
|
+
|
|
40
|
+
fig.savefig("1d_comparison_difference.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Efficiency
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
Compare the ratio between two histograms h1 and h2 when the entries of h1 are a subset of the entries of h2.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x_total = df[name][df["category"] == 2]
|
|
15
|
+
x_sample = x_total[: int(len(x_total) * 0.75)]
|
|
16
|
+
|
|
17
|
+
x_range = (min(x_total), max(x_total))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h_sample = make_hist(x_sample, bins=50, range=x_range)
|
|
22
|
+
h_total = make_hist(x_total, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h_sample,
|
|
29
|
+
h_total,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathit{H}_{Sample}$",
|
|
33
|
+
h2_label=r"$\mathit{H}_{Total}$",
|
|
34
|
+
comparison="efficiency", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_efficiency.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Comparison
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
Plot the comparison between two 1D histograms.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x_total = df[name][df["category"] == 2]
|
|
15
|
+
x_sample = x_total[: int(len(x_total) * 0.75)]
|
|
16
|
+
|
|
17
|
+
x_range = (min(x_total), max(x_total))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h_sample = make_hist(x_sample, bins=50, range=x_range)
|
|
22
|
+
h_total = make_hist(x_total, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
import matplotlib.pyplot as plt
|
|
26
|
+
|
|
27
|
+
from plothist import plot_comparison
|
|
28
|
+
|
|
29
|
+
fig, ax = plt.subplots()
|
|
30
|
+
|
|
31
|
+
plot_comparison(h_sample, h_total, ax=ax, xlabel=name, comparison="efficiency")
|
|
32
|
+
|
|
33
|
+
fig.savefig("1d_comparison_only_efficiency.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pull
|
|
3
|
+
====
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the pull method.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$h_1$",
|
|
33
|
+
h2_label=r"$h_2$",
|
|
34
|
+
comparison="pull", # <---
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_pull.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Ratio
|
|
3
|
+
=====
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the ratio [h1/h2].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
# Default comparison is ratio
|
|
28
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
29
|
+
h1,
|
|
30
|
+
h2,
|
|
31
|
+
xlabel=name,
|
|
32
|
+
ylabel="Entries",
|
|
33
|
+
h1_label="h1",
|
|
34
|
+
h2_label="h2",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_ratio.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Relative difference
|
|
3
|
+
===================
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the relative difference [(h1-h2)/h2].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathbf{H\,\,1}$",
|
|
33
|
+
h2_label=r"$\mathbf{H\,\,2}$",
|
|
34
|
+
comparison="relative_difference", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_relative_difference.svg", bbox_inches="tight")
|