4 #ifndef tools_wcsv_histo
5 #define tools_wcsv_histo
15 inline void axis_to(std::ostream& a_writer,
const AXIS& a_axis,
char a_hc) {
18 <<
"axis fixed " << a_axis.m_number_of_bins
19 <<
" " << a_axis.m_minimum_value
20 <<
" " << a_axis.m_maximum_value
24 a_writer << a_hc <<
"axis edges";
25 for(
unsigned int iedge=0;iedge<a_axis.m_edges.size();iedge++) {
26 a_writer <<
" " << a_axis.m_edges[iedge];
28 a_writer << std::endl;
32 template <
class ANNOTATION>
33 inline void annotations_to(std::ostream& a_writer,
const ANNOTATION& a_ans,
char a_hc) {
34 typename ANNOTATION::const_iterator it;
35 for(it=a_ans.begin();it!=a_ans.end();++it) {
36 a_writer << a_hc <<
"annotation " << (*it).first <<
" " << (*it).second << std::endl;
41 inline void h_header(std::ostream& a_writer,
const std::string& a_class,
const HIST& a_h,
char a_hc =
'#') {
42 a_writer << a_hc <<
"class " << a_class << std::endl;
43 a_writer << a_hc <<
"title " << a_h.title() << std::endl;
44 a_writer << a_hc <<
"dimension " << a_h.dimension() << std::endl;
45 for(
unsigned int iaxis=0;iaxis<a_h.dimension();iaxis++)
axis_to(a_writer,a_h.get_axis(iaxis),a_hc);
46 {
const std::vector<typename HIST::coordinate_t>& planes = a_h.in_range_planes_xyw();
48 a_writer << a_hc <<
"planes_Sxyw";
49 for(
unsigned int iplane=0;iplane<planes.size();iplane++) a_writer <<
" " << planes[iplane];
50 a_writer << std::endl;
53 a_writer << a_hc <<
"bin_number " << a_h.get_bins() << std::endl;
57 inline bool hto(std::ostream& a_writer,
const std::string& a_class,
const HIST& a_h,
58 char a_sep =
',',
char a_hc =
'#',
bool a_header =
true) {
59 if(a_header)
h_header(a_writer,a_class,a_h,a_hc);
61 {a_writer <<
"entries" << a_sep <<
"Sw" << a_sep <<
"Sw2";
62 for(
unsigned int iaxis=0;iaxis<a_h.dimension();iaxis++) {
63 a_writer << a_sep <<
"Sxw" << iaxis << a_sep <<
"Sx2w" << iaxis;
65 a_writer << std::endl;}
67 typedef typename HIST::coordinate_t coordinate_t;
68 typedef typename HIST::dim_t dim_t;
69 typedef typename HIST::offset_t offset_t;
70 typedef typename HIST::num_entries_t num_entries_t;
71 typedef typename HIST::weight_t weight_t;
73 dim_t _dim = a_h.dimension();
74 offset_t _bins = a_h.get_bins();
76 const std::vector<num_entries_t>& _bin_entries = a_h.bins_entries();
77 const std::vector<weight_t>& _bin_Sw = a_h.bins_sum_w();
78 const std::vector<weight_t>& _bin_Sw2 = a_h.bins_sum_w2();
79 const std::vector< std::vector<coordinate_t> >& _bin_Sxw = a_h.bins_sum_xw();
80 const std::vector< std::vector<coordinate_t> >& _bin_Sx2w = a_h.bins_sum_x2w();
82 for(
unsigned int i=0;i<_bins;i++) {
83 a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i];
84 for(
unsigned int iaxis=0;iaxis<_dim;iaxis++) {
85 a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis];
87 a_writer << std::endl;
96 inline void p_header(std::ostream& a_writer,
const std::string& a_class,
const PROF& a_prof,
char a_hc =
'#') {
97 a_writer << a_hc <<
"class " << a_class << std::endl;
98 a_writer << a_hc <<
"title " << a_prof.title() << std::endl;
99 a_writer << a_hc <<
"dimension " << a_prof.dimension() << std::endl;
100 for(
unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++)
axis_to(a_writer,a_prof.get_axis(iaxis),a_hc);
101 {
const std::vector<typename PROF::coordinate_t>& planes = a_prof.in_range_planes_xyw();
103 a_writer << a_hc <<
"planes_Sxyw";
104 for(
unsigned int iplane=0;iplane<planes.size();iplane++) a_writer <<
" " << planes[iplane];
105 a_writer << std::endl;
108 a_writer << a_hc <<
"cut_v " << (a_prof.cut_v()?
"true":
"false") << std::endl;
109 a_writer << a_hc <<
"min_v " << a_prof.min_v() << std::endl;
110 a_writer << a_hc <<
"max_v " << a_prof.max_v() << std::endl;
111 a_writer << a_hc <<
"bin_number " << a_prof.get_bins() << std::endl;
114 template <
class PROF>
115 inline bool pto(std::ostream& a_writer,
const std::string& a_class,
const PROF& a_prof,
116 char a_sep =
',',
char a_hc =
'#',
bool a_header =
true) {
117 if(a_header)
p_header(a_writer,a_class,a_prof,a_hc);
119 {a_writer <<
"entries" << a_sep <<
"Sw" << a_sep <<
"Sw2" << a_sep <<
"Svw" << a_sep <<
"Sv2w";
120 for(
unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) {
121 a_writer << a_sep <<
"Sxw" << iaxis << a_sep <<
"Sx2w" << iaxis;
123 a_writer << std::endl;}
125 typedef typename PROF::coordinate_t coordinate_t;
126 typedef typename PROF::dim_t dim_t;
127 typedef typename PROF::offset_t offset_t;
128 typedef typename PROF::num_entries_t num_entries_t;
129 typedef typename PROF::weight_t weight_t;
131 dim_t _dim = a_prof.dimension();
132 offset_t _bins = a_prof.get_bins();
134 const std::vector<num_entries_t>& _bin_entries = a_prof.bins_entries();
135 const std::vector<weight_t>& _bin_Sw = a_prof.bins_sum_w();
136 const std::vector<weight_t>& _bin_Sw2 = a_prof.bins_sum_w2();
137 const std::vector< std::vector<coordinate_t> >& _bin_Sxw = a_prof.bins_sum_xw();
138 const std::vector< std::vector<coordinate_t> >& _bin_Sx2w = a_prof.bins_sum_x2w();
140 typedef typename PROF::vs_t vs_t;
141 const vs_t& _bin_Svw = a_prof.bins_sum_vw();
142 const vs_t& _bin_Sv2w = a_prof.bins_sum_v2w();
144 for(
unsigned int i=0;i<_bins;i++) {
145 a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i]
146 << a_sep << _bin_Svw[i] << a_sep << _bin_Sv2w[i];
147 for(
unsigned int iaxis=0;iaxis<_dim;iaxis++) {
148 a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis];
150 a_writer << std::endl;