histogram
histogram copied to clipboard
Add efficiency accumulator
Histograms are often used to compute efficiencies in HEP. This is best done with a dedicated accumulator, to avoid filling two separate histograms. If one uses two histograms, the bin lookup is done twice instead of once.
Code could look like this:
auto h = make_histogram_with(dense_storage<accumulator::efficiency<>>(), axis::regular<>(10, 0, 1));
h(0.1, sample(false)); // didn't pass
h(0.5, sample(true)); // did pass
h.at(0).value(); // gives the efficiency in that bin
h.at(0).variance(); // gives variance estimate for that bin
auto interval = h.at(0).confidence_interval(); // gives the confidence interval
The confidence_interval() method could have optional parameters for the desired coverage and for the way on how to compute the confidence interval, by which method (should default to Wilson). However, it is better to pass these options in statically as a template parameter in the accumulator, because you never request Clopper-Pearson intervals for some bins and Wilson intervals for others. If you want and need to switch the interval computation method, you should only have to change your code in the place where the histogram is created. Not in every call of the confidence_interval() method.
User guide on writing custom accumulators: https://www.boost.org/doc/libs/develop/libs/histogram/doc/html/histogram/guide.html#histogram.guide.expert.user_defined_accumulators
If anyone wants to work on this, I am happy to review and guide you. It is not a difficult task, but you will learn a lot about the nitty-gritty details of writing a high-quality library implementation. It requires patience and a willingness to learn and receive constructive criticism.
i want to contribute to this issue.......would you please explain it more to me??
Hi @psbro, thank you for your interest in contributing. You can start by reading the user guide on how to make a simple accumulator for boost histogram. Then have a look at the current accumulators in the library (include/boost/histogram/accumulators) to see how they are implemented. The new accumulator is similar to the mean accumulator.
Make an accumulator with two counters. Increment the first counter if the sample value passed to the accumulator is true, and increment the second counter if it is false. Let me know when you are there, then we discuss next steps.
Tipp: You can play around with Boost Histogram online on Godbolt, for example.
i cant get it excatly what you want to say....would you please elaboarte it
Hello ! I would like to contribute to this issue:))
@ShriyanshiSrivastava I am very sorry that I missed your comment, if you are still interested please go ahead with a draft, then make a pull request and we can discuss it.
Implemented in #361