| 15 | } |
| 16 | |
| 17 | int main() { |
| 18 | using namespace bh::literals; // enables _c suffix |
| 19 | |
| 20 | // make a 2d histogram |
| 21 | auto h = bh::make_static_histogram(bh::axis::regular<>(3, -1, 1), |
| 22 | bh::axis::integer<>(0, 4)); |
| 23 | |
| 24 | h(-0.9, 0); |
| 25 | h(0.9, 3); |
| 26 | h(0.1, 2); |
| 27 | |
| 28 | auto hr0 = h.reduce_to(0_c); // keep only first axis |
| 29 | auto hr1 = h.reduce_to(1_c); // keep only second axis |
| 30 | |
| 31 | /* |
| 32 | reduce does not remove counts; returned histograms are summed over |
| 33 | the removed axes, so h, hr0, and hr1 have same number of total counts |
| 34 | */ |
| 35 | std::cout << sum(h).value() << " " << sum(hr0).value() << " " |
| 36 | << sum(hr1).value() << std::endl; |
| 37 | // prints: 3 3 3 |
| 38 | |
| 39 | for (auto yi : h.axis(1_c)) { |
| 40 | for (auto xi : h.axis(0_c)) { std::cout << h.at(xi, yi).value() << " "; } |
| 41 | std::cout << std::endl; |
| 42 | } |
| 43 | // prints: 1 0 0 |
| 44 | // 0 0 0 |
| 45 | // 0 1 0 |
| 46 | // 0 0 1 |
| 47 | |
| 48 | for (auto xi : hr0.axis()) std::cout << hr0.at(xi).value() << " "; |
| 49 | std::cout << std::endl; |
| 50 | // prints: 1 1 1 |
| 51 | |
| 52 | for (auto yi : hr1.axis()) std::cout << hr1.at(yi).value() << " "; |
| 53 | std::cout << std::endl; |
| 54 | // prints: 1 0 1 1 |
| 55 | } |
| 56 | |
| 57 | //] |