Histogram
puma.histogram.Histogram
#
Bases: puma.plot_base.PlotLineObject
Histogram class storing info about histogram and allows to calculate ratio w.r.t other histograms.
Initialise properties of histogram curve object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
numpy.ndarray
|
Input data for the histogram. If bin_edges is specified (not None) then this array is treated as the bin heights. |
required |
weights
|
numpy.ndarray
|
Weights for the input data. Has to be an array of same length as the input data with a weight for each entry. If not specified, weight 1 will be given to each entry. The uncertainties are calculated as the square root of the squared weights (for each bin separately). By default None. |
None
|
bin_edges
|
numpy.ndarray
|
If specified, the histogram is considered "filled": the array given to values is treated as if it was the bin heights corresponding to these bin_edges and the "weights" input is ignored. By default None. |
None
|
sum_squared_weights
|
numpy.ndarray
|
Only considered if the histogram is considered filled (i.e bin_edges is specified). It is the sum_squared_weights per bin. By default None. |
None
|
ratio_group
|
str
|
Name of the ratio group this histogram is compared with. The ratio group allows you to compare different groups of histograms within one plot. By default None |
None
|
flavour
|
str | ftag.Label
|
If set, the correct colour and a label prefix will be extracted from
|
None
|
add_flavour_label
|
bool
|
Set to False to suppress the automatic addition of the flavour label prefix
in the label of the curve (i.e. "b-jets" in the case of b-jets).
This is ignored if |
True
|
histtype
|
str
|
|
'step'
|
is_data
|
bool
|
Decide, if the plot object will be treated as data (black dots, no stacking), by default False |
False
|
**kwargs
|
kwargs
|
Keyword arguments passed to |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If input data is not of type np.ndarray or list |
ValueError
|
If weights are specified but have different length as the input values |
Source code in puma/histogram.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
divide
#
Calculate ratio between two class objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
histogram class
|
Second histogram object to calculate ratio with |
required |
Returns:
Type | Description |
---|---|
numpy.ndarray
|
Ratio |
numpy.ndarray
|
Ratio error |
Raises:
Type | Description |
---|---|
ValueError
|
If binning is not identical between 2 objects |
ValueError
|
If hist attribute is not set for one of the two histograms |
ValueError
|
If bin_edges attribute is not set for one of the two histograms |
Source code in puma/histogram.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
divide_data_mc
#
Similar as divide, but the second item doesn't need to be a histogram object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_hist
|
numpy.ndarray
|
Hist weights of the reference. |
required |
ref_unc
|
numpy.ndarray
|
Uncertainties of the reference |
required |
Returns:
Type | Description |
---|---|
tuple
|
Tuple of the ratios and ratio uncertaintes for the bins |
Source code in puma/histogram.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
puma.histogram.HistogramPlot
#
Bases: puma.plot_base.PlotBase
Histogram plot class.
Histogram plot properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bins
|
int or numpy.ndarray or list
|
If bins is an int, it defines the number of equal-width bins in the given range. If bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths (like in numpy.histogram). By default 40 |
40
|
bins_range
|
tuple
|
Tuple of two floats, specifying the range for the binning. If bins_range is specified and bins is an integer, equal-width bins from bins_range[0] to bins_range[1] are used for the histogram (like in numpy.histogram). By default None |
None
|
discrete_vals
|
list
|
List of values if a variable only has discrete values. If discrete_vals is specified only the bins containing these values are plotted. By default None. |
None
|
norm
|
bool
|
Specify if the histograms are normalised, this means that histograms are divided by the total numer of counts. Therefore, the sum of the bin counts is equal to one, but NOT the area under the curve, which would be sum(bin_counts * bin_width). By default True. |
True
|
logy
|
bool
|
Set log scale on y-axis, by default False. |
False
|
bin_width_in_ylabel
|
bool
|
Specify if the bin width should be added to the ylabel, by default False |
False
|
underoverflow
|
bool
|
Option to include under- and overflow values in outermost bins, by default True. |
True
|
grid
|
bool
|
Set the grid for the plots, by default False |
False
|
stacked
|
bool
|
Decide, if all histograms (which are not data) are stacked, by default False |
False
|
histtype
|
str
|
If stacked is used, define the type of histogram you would like to have, default is "bar" |
'bar'
|
**kwargs
|
kwargs
|
Keyword arguments from |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If n_ratio_panels > 1 |
Source code in puma/histogram.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
add
#
Adding histogram object to figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
histogram
|
Histogram class
|
Histogram curve |
required |
key
|
str
|
Unique identifier for histogram, by default None |
None
|
reference
|
bool
|
If this histogram is used as reference for ratio calculation, by default False |
False
|
Raises:
Type | Description |
---|---|
KeyError
|
If unique identifier key is used twice |
Source code in puma/histogram.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
add_bin_width_to_ylabel
#
Adds the bin width to the ylabel of a histogram plot. If the bin with is smaller than 0.01, scientific notation will be used.
Raises:
Type | Description |
---|---|
ValueError
|
If plotting_done is False (therefore |
Source code in puma/histogram.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 |
|
draw
#
Draw figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labelpad
|
int
|
Spacing in points from the axes bounding box including ticks and tick labels, by default "ratio" |
None
|
Source code in puma/histogram.py
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
|
get_discrete_values
#
Get discrete values of a variable and adjust the bins accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elem
|
histogram class
|
Histogram we want to calculate the bins containing discrete values for |
required |
Returns:
Name | Type | Description |
---|---|---|
bins |
numpy.ndarray
|
Recalculated bins including only the discrete values |
Raises:
Type | Description |
---|---|
ValueError
|
If the bin width is larger than 1 such that potentially not all discrete values are in a seperate bin |
ValueError
|
If the number of bins is set to 1 such that no values can be distinguished |
Source code in puma/histogram.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
|
get_reference_histo
#
Get reference histogram from list of references.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
histo
|
puma.histogram.Histogram
|
Histogram we want to calculate the ratio for |
required |
Returns:
Name | Type | Description |
---|---|---|
reference_histo_name |
(str, int)
|
Identifier of the corresponding reference histogram |
Raises:
Type | Description |
---|---|
ValueError
|
If no reference histo was found or multiple matches. |
Source code in puma/histogram.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
|
plot
#
Plotting curves. This also generates the bins of the histograms that are added to the plot. Plot objects are drawn in the same order as they were added to the plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments passed to matplotlib.axes.Axes.hist() |
{}
|
Returns:
Type | Description |
---|---|
puma.line_plot_2d.Line2D
|
matplotlib Line2D object |
Raises:
Type | Description |
---|---|
ValueError
|
If specified bins type is not supported. |
Source code in puma/histogram.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
|
plot_ratios
#
Plotting ratio histograms.
Raises:
Type | Description |
---|---|
ValueError
|
If no reference histogram is defined |
Source code in puma/histogram.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 |
|
set_reference
#
Setting the reference histogram curves used in the ratios.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier of histogram object |
required |
Source code in puma/histogram.py
374 375 376 377 378 379 380 381 382 383 384 385 386 |
|