Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/wcsv_histo is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_wcsv_histo
0005 #define tools_wcsv_histo
0006 
0007 #include <ostream>
0008 #include <vector>
0009 #include <string>
0010 
0011 namespace tools {
0012 namespace wcsv {
0013 
0014 template <class AXIS>
0015 inline void axis_to(std::ostream& a_writer,const AXIS& a_axis,char a_hc) {
0016   if(a_axis.m_fixed) {
0017     a_writer << a_hc
0018              << "axis fixed " << a_axis.m_number_of_bins
0019              << " " << a_axis.m_minimum_value
0020              << " " << a_axis.m_maximum_value
0021              << std::endl;
0022   } else {
0023     a_writer << a_hc << "axis edges";
0024     for(unsigned int iedge=0;iedge<a_axis.m_edges.size();iedge++) {
0025       a_writer << " " << a_axis.m_edges[iedge];
0026     }
0027     a_writer << std::endl;
0028   }
0029 }
0030 
0031 template <class ANNOTATION>
0032 inline void annotations_to(std::ostream& a_writer,const ANNOTATION& a_ans,char a_hc) {
0033   typename ANNOTATION::const_iterator it;
0034   for(it=a_ans.begin();it!=a_ans.end();++it) {
0035     a_writer << a_hc << "annotation " << (*it).first << " " << (*it).second << std::endl;
0036   }
0037 }
0038 
0039 template <class HIST>
0040 inline void h_header(std::ostream& a_writer,const std::string& a_class,const HIST& a_h,char a_hc = '#') {
0041   a_writer << a_hc << "class " << a_class << std::endl;
0042   a_writer << a_hc << "title " << a_h.title() << std::endl;
0043   a_writer << a_hc << "dimension " << a_h.dimension() << std::endl;
0044   for(unsigned int iaxis=0;iaxis<a_h.dimension();iaxis++) axis_to(a_writer,a_h.get_axis(iaxis),a_hc);
0045  {const std::vector<typename HIST::coordinate_t>& planes = a_h.in_range_planes_xyw();
0046   if(planes.size()) {
0047     a_writer << a_hc << "planes_Sxyw";
0048     for(unsigned int iplane=0;iplane<planes.size();iplane++) a_writer << " " << planes[iplane];
0049     a_writer << std::endl;
0050   }}
0051   annotations_to(a_writer,a_h.annotations(),a_hc);
0052   a_writer << a_hc << "bin_number " << a_h.get_bins() << std::endl;
0053 }
0054 
0055 template <class HIST>
0056 inline bool hto(std::ostream& a_writer,const std::string& a_class,const HIST& a_h,
0057                 char a_sep = ',',char a_hc = '#',bool a_header = true) {
0058   if(a_header) h_header(a_writer,a_class,a_h,a_hc);
0059 
0060  {a_writer << "entries" << a_sep << "Sw" << a_sep << "Sw2";
0061   for(unsigned int iaxis=0;iaxis<a_h.dimension();iaxis++) {
0062     a_writer << a_sep << "Sxw" << iaxis << a_sep << "Sx2w" << iaxis;
0063   }
0064   a_writer << std::endl;}
0065 
0066   typedef typename HIST::coordinate_t coordinate_t;
0067   typedef typename HIST::dim_t dim_t;
0068   typedef typename HIST::offset_t offset_t;
0069   typedef typename HIST::num_entries_t num_entries_t;
0070   typedef typename HIST::weight_t weight_t;
0071 
0072   dim_t _dim = a_h.dimension();
0073   offset_t _bins = a_h.get_bins();
0074 
0075   const std::vector<num_entries_t>& _bin_entries = a_h.bins_entries();
0076   const std::vector<weight_t>& _bin_Sw = a_h.bins_sum_w();
0077   const std::vector<weight_t>& _bin_Sw2 = a_h.bins_sum_w2();
0078   const std::vector< std::vector<coordinate_t> >& _bin_Sxw = a_h.bins_sum_xw();
0079   const std::vector< std::vector<coordinate_t> >& _bin_Sx2w = a_h.bins_sum_x2w();
0080 
0081   for(unsigned int i=0;i<_bins;i++) {
0082     a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i];
0083     for(unsigned int iaxis=0;iaxis<_dim;iaxis++) {
0084       a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis];
0085     }
0086     a_writer << std::endl;
0087   }
0088 
0089   a_h.not_a_profile(); //trick to be sure to use this function on an histo and not a profile.
0090 
0091   return true;
0092 }
0093 
0094 template <class PROF>
0095 inline void p_header(std::ostream& a_writer,const std::string& a_class,const PROF& a_prof,char a_hc = '#') {
0096   a_writer << a_hc << "class " << a_class << std::endl;
0097   a_writer << a_hc << "title " << a_prof.title() << std::endl;
0098   a_writer << a_hc << "dimension " << a_prof.dimension() << std::endl;
0099   for(unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) axis_to(a_writer,a_prof.get_axis(iaxis),a_hc);
0100  {const std::vector<typename PROF::coordinate_t>& planes = a_prof.in_range_planes_xyw();
0101   if(planes.size()) {
0102     a_writer << a_hc << "planes_Sxyw";
0103     for(unsigned int iplane=0;iplane<planes.size();iplane++) a_writer << " " << planes[iplane];
0104     a_writer << std::endl;
0105   }}
0106   annotations_to(a_writer,a_prof.annotations(),a_hc);
0107   a_writer << a_hc << "cut_v " << (a_prof.cut_v()?"true":"false") << std::endl;
0108   a_writer << a_hc << "min_v " << a_prof.min_v() << std::endl;
0109   a_writer << a_hc << "max_v " << a_prof.max_v() << std::endl;
0110   a_writer << a_hc << "bin_number " << a_prof.get_bins() << std::endl;
0111 }
0112 
0113 template <class PROF>
0114 inline bool pto(std::ostream& a_writer,const std::string& a_class,const PROF& a_prof,
0115                 char a_sep = ',',char a_hc = '#',bool a_header = true) {
0116   if(a_header) p_header(a_writer,a_class,a_prof,a_hc);
0117 
0118  {a_writer << "entries" << a_sep << "Sw" << a_sep << "Sw2" << a_sep << "Svw" << a_sep << "Sv2w";
0119   for(unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) {
0120     a_writer << a_sep << "Sxw" << iaxis << a_sep << "Sx2w" << iaxis;
0121   }
0122   a_writer << std::endl;}
0123 
0124   typedef typename PROF::coordinate_t coordinate_t;
0125   typedef typename PROF::dim_t dim_t;
0126   typedef typename PROF::offset_t offset_t;
0127   typedef typename PROF::num_entries_t num_entries_t;
0128   typedef typename PROF::weight_t weight_t;
0129 
0130   dim_t _dim = a_prof.dimension();
0131   offset_t _bins = a_prof.get_bins();
0132 
0133   const std::vector<num_entries_t>& _bin_entries = a_prof.bins_entries();
0134   const std::vector<weight_t>& _bin_Sw = a_prof.bins_sum_w();
0135   const std::vector<weight_t>& _bin_Sw2 = a_prof.bins_sum_w2();
0136   const std::vector< std::vector<coordinate_t> >& _bin_Sxw = a_prof.bins_sum_xw();
0137   const std::vector< std::vector<coordinate_t> >& _bin_Sx2w = a_prof.bins_sum_x2w();
0138 
0139   typedef typename PROF::vs_t vs_t;
0140   const vs_t& _bin_Svw = a_prof.bins_sum_vw();
0141   const vs_t& _bin_Sv2w = a_prof.bins_sum_v2w();
0142 
0143   for(unsigned int i=0;i<_bins;i++) {
0144     a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i]
0145              << a_sep << _bin_Svw[i] << a_sep << _bin_Sv2w[i];
0146     for(unsigned int iaxis=0;iaxis<_dim;iaxis++) {
0147       a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis];
0148     }
0149     a_writer << std::endl;
0150   }
0151 
0152   return true;
0153 }
0154 
0155 }}
0156 
0157 #endif