1 // Copyright 2019 Hans Dembinski
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //[ getting_started_listing_05
11 //////////////// Begin: put this in header file ////////////////////
13 #include <algorithm> // std::max_element
14 #include <boost/format.hpp> // only needed for printing
15 #include <boost/histogram.hpp> // make_histogram, integer, indexed
16 #include <iostream> // std::cout, std::endl
17 #include <sstream> // std::ostringstream
21 // use this when axis configuration is fix to get highest performance
22 struct HolderOfStaticHistogram
{
23 // put axis types here
24 using axes_t
= std::tuple
<
25 boost::histogram::axis::regular
<>,
26 boost::histogram::axis::integer
<>
28 using hist_t
= boost::histogram::histogram
<axes_t
>;
32 // use this when axis configuration should be flexible
33 struct HolderOfDynamicHistogram
{
34 // put all axis types here that you are going to use
35 using axis_t
= boost::histogram::axis::variant
<
36 boost::histogram::axis::regular
<>,
37 boost::histogram::axis::variable
<>,
38 boost::histogram::axis::integer
<>
40 using axes_t
= std::vector
<axis_t
>;
41 using hist_t
= boost::histogram::histogram
<axes_t
>;
45 //////////////// End: put this in header file ////////////////////
48 using namespace boost::histogram
;
50 HolderOfStaticHistogram hs
;
51 hs
.hist_
= make_histogram(axis::regular
<>(5, 0, 1), axis::integer
<>(0, 3));
52 // now assign a different histogram
53 hs
.hist_
= make_histogram(axis::regular
<>(3, 1, 2), axis::integer
<>(4, 6));
54 // hs.hist_ = make_histogram(axis::regular<>(5, 0, 1)); does not work;
55 // the static histogram cannot change the number or order of axis types
57 HolderOfDynamicHistogram hd
;
58 hd
.hist_
= make_histogram(axis::regular
<>(5, 0, 1), axis::integer
<>(0, 3));
59 // now assign a different histogram
60 hd
.hist_
= make_histogram(axis::regular
<>(3, -1, 2));
62 hd
.hist_
= make_histogram(axis::integer
<>(0, 5), axis::integer
<>(3, 5));