Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_wcsv_histo 5 #define tools_wcsv_histo 6 7 #include <ostream> 8 #include <vector> 9 #include <string> 10 11 namespace tools { 12 namespace wcsv { 13 14 template <class AXIS> 15 inline void axis_to(std::ostream& a_writer,con 16 if(a_axis.m_fixed) { 17 a_writer << a_hc 18 << "axis fixed " << a_axis.m_numb 19 << " " << a_axis.m_minimum_value 20 << " " << a_axis.m_maximum_value 21 // << " " << a_axis.m_bin_width 22 << std::endl; 23 } else { 24 a_writer << a_hc << "axis edges"; 25 for(unsigned int iedge=0;iedge<a_axis.m_ed 26 a_writer << " " << a_axis.m_edges[iedge] 27 } 28 a_writer << std::endl; 29 } 30 } 31 32 template <class ANNOTATION> 33 inline void annotations_to(std::ostream& a_wri 34 typename ANNOTATION::const_iterator it; 35 for(it=a_ans.begin();it!=a_ans.end();++it) { 36 a_writer << a_hc << "annotation " << (*it) 37 } 38 } 39 40 template <class HIST> 41 inline void h_header(std::ostream& a_writer,co 42 a_writer << a_hc << "class " << a_class << s 43 a_writer << a_hc << "title " << a_h.title() 44 a_writer << a_hc << "dimension " << a_h.dime 45 for(unsigned int iaxis=0;iaxis<a_h.dimension 46 {const std::vector<typename HIST::coordinate_ 47 if(planes.size()) { 48 a_writer << a_hc << "planes_Sxyw"; 49 for(unsigned int iplane=0;iplane<planes.si 50 a_writer << std::endl; 51 }} 52 annotations_to(a_writer,a_h.annotations(),a_ 53 a_writer << a_hc << "bin_number " << a_h.get 54 } 55 56 template <class HIST> 57 inline bool hto(std::ostream& a_writer,const s 58 char a_sep = ',',char a_hc = ' 59 if(a_header) h_header(a_writer,a_class,a_h,a 60 61 {a_writer << "entries" << a_sep << "Sw" << a_ 62 for(unsigned int iaxis=0;iaxis<a_h.dimension 63 a_writer << a_sep << "Sxw" << iaxis << a_s 64 } 65 a_writer << std::endl;} 66 67 typedef typename HIST::coordinate_t coordina 68 typedef typename HIST::dim_t dim_t; 69 typedef typename HIST::offset_t offset_t; 70 typedef typename HIST::num_entries_t num_ent 71 typedef typename HIST::weight_t weight_t; 72 73 dim_t _dim = a_h.dimension(); 74 offset_t _bins = a_h.get_bins(); 75 76 const std::vector<num_entries_t>& _bin_entri 77 const std::vector<weight_t>& _bin_Sw = a_h.b 78 const std::vector<weight_t>& _bin_Sw2 = a_h. 79 const std::vector< std::vector<coordinate_t> 80 const std::vector< std::vector<coordinate_t> 81 82 for(unsigned int i=0;i<_bins;i++) { 83 a_writer << _bin_entries[i] << a_sep << _b 84 for(unsigned int iaxis=0;iaxis<_dim;iaxis+ 85 a_writer << a_sep << _bin_Sxw[i][iaxis] 86 } 87 a_writer << std::endl; 88 } 89 90 a_h.not_a_profile(); //trick to be sure to u 91 92 return true; 93 } 94 95 template <class PROF> 96 inline void p_header(std::ostream& a_writer,co 97 a_writer << a_hc << "class " << a_class << s 98 a_writer << a_hc << "title " << a_prof.title 99 a_writer << a_hc << "dimension " << a_prof.d 100 for(unsigned int iaxis=0;iaxis<a_prof.dimens 101 {const std::vector<typename PROF::coordinate_ 102 if(planes.size()) { 103 a_writer << a_hc << "planes_Sxyw"; 104 for(unsigned int iplane=0;iplane<planes.si 105 a_writer << std::endl; 106 }} 107 annotations_to(a_writer,a_prof.annotations() 108 a_writer << a_hc << "cut_v " << (a_prof.cut_ 109 a_writer << a_hc << "min_v " << a_prof.min_v 110 a_writer << a_hc << "max_v " << a_prof.max_v 111 a_writer << a_hc << "bin_number " << a_prof. 112 } 113 114 template <class PROF> 115 inline bool pto(std::ostream& a_writer,const s 116 char a_sep = ',',char a_hc = ' 117 if(a_header) p_header(a_writer,a_class,a_pro 118 119 {a_writer << "entries" << a_sep << "Sw" << a_ 120 for(unsigned int iaxis=0;iaxis<a_prof.dimens 121 a_writer << a_sep << "Sxw" << iaxis << a_s 122 } 123 a_writer << std::endl;} 124 125 typedef typename PROF::coordinate_t coordina 126 typedef typename PROF::dim_t dim_t; 127 typedef typename PROF::offset_t offset_t; 128 typedef typename PROF::num_entries_t num_ent 129 typedef typename PROF::weight_t weight_t; 130 131 dim_t _dim = a_prof.dimension(); 132 offset_t _bins = a_prof.get_bins(); 133 134 const std::vector<num_entries_t>& _bin_entri 135 const std::vector<weight_t>& _bin_Sw = a_pro 136 const std::vector<weight_t>& _bin_Sw2 = a_pr 137 const std::vector< std::vector<coordinate_t> 138 const std::vector< std::vector<coordinate_t> 139 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( 143 144 for(unsigned int i=0;i<_bins;i++) { 145 a_writer << _bin_entries[i] << a_sep << _b 146 << a_sep << _bin_Svw[i] << a_sep 147 for(unsigned int iaxis=0;iaxis<_dim;iaxis+ 148 a_writer << a_sep << _bin_Sxw[i][iaxis] 149 } 150 a_writer << std::endl; 151 } 152 153 return true; 154 } 155 156 }} 157 158 #endif