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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/histo/histo_data (Version 11.3.0) and /externals/g4tools/include/tools/histo/histo_data (Version 11.1.1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_histo_histo_data                      4 #ifndef tools_histo_histo_data
  5 #define tools_histo_histo_data                      5 #define tools_histo_histo_data
  6                                                     6 
  7 #include <vector>                                   7 #include <vector>
  8 #include <map> //for annotations                    8 #include <map> //for annotations
  9                                                     9 
 10 #include "axes"                                    10 #include "axes"
 11 #include "../eqT"                                  11 #include "../eqT"
 12 //#include "../vmanip" //vequ                      12 //#include "../vmanip" //vequ
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace histo {                                  15 namespace histo {
 16                                                    16 
 17 inline unsigned int dim_planes(unsigned int a_     17 inline unsigned int dim_planes(unsigned int a_dim) {
 18   // m_dim = 1 -> 0                                18   // m_dim = 1 -> 0
 19   // m_dim = 2 -> 0+1=1                            19   // m_dim = 2 -> 0+1=1
 20   // m_dim = 3 -> 0+1+2=3                          20   // m_dim = 3 -> 0+1+2=3
 21   // m_dim = 4 -> 0+1+2+3=6                        21   // m_dim = 4 -> 0+1+2+3=6
 22   typedef unsigned int dim_t;                      22   typedef unsigned int dim_t;
 23   dim_t n = 0;                                     23   dim_t n = 0;
 24   for(dim_t i=0;i<a_dim;i++) n += i;               24   for(dim_t i=0;i<a_dim;i++) n += i;
 25   return n;                                        25   return n;
 26 }                                                  26 }
 27                                                    27 
 28 //TC is for a coordinate.                          28 //TC is for a coordinate.
 29 //TO is for an offset used to identify a bin.      29 //TO is for an offset used to identify a bin.
 30 //TN is for a number of entries.                   30 //TN is for a number of entries.
 31 //TW is for a weight.                              31 //TW is for a weight.
 32                                                    32 
 33 template <class TC,class TO,class TN,class TW>     33 template <class TC,class TO,class TN,class TW>
 34 class histo_data {                                 34 class histo_data {
 35 public:                                            35 public:
 36   typedef axis<TC,TO> axis_t;                      36   typedef axis<TC,TO> axis_t;
 37   typedef unsigned int dim_t;                      37   typedef unsigned int dim_t;
 38   typedef std::map<std::string,std::string> an     38   typedef std::map<std::string,std::string> annotations_t;
 39 public:                                            39 public:
 40   histo_data()                                     40   histo_data()
 41   :m_dimension(0)                                  41   :m_dimension(0)
 42   ,m_bin_number(0)                                 42   ,m_bin_number(0)
 43   ,m_all_entries(0)                                43   ,m_all_entries(0)
 44   ,m_in_range_entries(0)                           44   ,m_in_range_entries(0)
 45   ,m_in_range_Sw(0)                                45   ,m_in_range_Sw(0)
 46   ,m_in_range_Sw2(0)                               46   ,m_in_range_Sw2(0)
 47   {}                                               47   {}
 48 public:                                            48 public:
 49   histo_data(const histo_data& a_from)             49   histo_data(const histo_data& a_from)
 50   :m_title(a_from.m_title)                         50   :m_title(a_from.m_title)
 51   ,m_dimension(a_from.m_dimension)                 51   ,m_dimension(a_from.m_dimension)
 52   ,m_bin_number(a_from.m_bin_number)               52   ,m_bin_number(a_from.m_bin_number)
 53   ,m_bin_entries(a_from.m_bin_entries)             53   ,m_bin_entries(a_from.m_bin_entries)
 54   ,m_bin_Sw(a_from.m_bin_Sw)                       54   ,m_bin_Sw(a_from.m_bin_Sw)
 55   ,m_bin_Sw2(a_from.m_bin_Sw2)                     55   ,m_bin_Sw2(a_from.m_bin_Sw2)
 56   ,m_bin_Sxw(a_from.m_bin_Sxw)                     56   ,m_bin_Sxw(a_from.m_bin_Sxw)
 57   ,m_bin_Sx2w(a_from.m_bin_Sx2w)                   57   ,m_bin_Sx2w(a_from.m_bin_Sx2w)
 58   ,m_axes(a_from.m_axes)                           58   ,m_axes(a_from.m_axes)
 59   ,m_in_range_plane_Sxyw(a_from.m_in_range_pla     59   ,m_in_range_plane_Sxyw(a_from.m_in_range_plane_Sxyw)
 60   ,m_annotations(a_from.m_annotations)             60   ,m_annotations(a_from.m_annotations)
 61   ,m_all_entries(a_from.m_all_entries)             61   ,m_all_entries(a_from.m_all_entries)
 62   ,m_in_range_entries(a_from.m_in_range_entrie     62   ,m_in_range_entries(a_from.m_in_range_entries)
 63   ,m_in_range_Sw(a_from.m_in_range_Sw)             63   ,m_in_range_Sw(a_from.m_in_range_Sw)
 64   ,m_in_range_Sw2(a_from.m_in_range_Sw2)           64   ,m_in_range_Sw2(a_from.m_in_range_Sw2)
 65   ,m_in_range_Sxw(a_from.m_in_range_Sxw)           65   ,m_in_range_Sxw(a_from.m_in_range_Sxw)
 66   ,m_in_range_Sx2w(a_from.m_in_range_Sx2w)         66   ,m_in_range_Sx2w(a_from.m_in_range_Sx2w)
 67   {}                                               67   {}
 68                                                    68 
 69   histo_data& operator=(const histo_data& a_fr     69   histo_data& operator=(const histo_data& a_from) {
 70     if(&a_from==this) return *this;                70     if(&a_from==this) return *this;
 71     m_title = a_from.m_title;                      71     m_title = a_from.m_title;
 72     m_dimension = a_from.m_dimension;              72     m_dimension = a_from.m_dimension;
 73     m_bin_number = a_from.m_bin_number;            73     m_bin_number = a_from.m_bin_number;
 74     m_bin_entries = a_from.m_bin_entries;          74     m_bin_entries = a_from.m_bin_entries;
 75     m_bin_Sw = a_from.m_bin_Sw;                    75     m_bin_Sw = a_from.m_bin_Sw;
 76     m_bin_Sw2 = a_from.m_bin_Sw2;                  76     m_bin_Sw2 = a_from.m_bin_Sw2;
 77     m_bin_Sxw = a_from.m_bin_Sxw;                  77     m_bin_Sxw = a_from.m_bin_Sxw;
 78     m_bin_Sx2w = a_from.m_bin_Sx2w;                78     m_bin_Sx2w = a_from.m_bin_Sx2w;
 79     m_axes = a_from.m_axes;                        79     m_axes = a_from.m_axes;
 80     m_in_range_plane_Sxyw = a_from.m_in_range_     80     m_in_range_plane_Sxyw = a_from.m_in_range_plane_Sxyw;
 81     m_annotations = a_from.m_annotations;          81     m_annotations = a_from.m_annotations;
 82     m_all_entries = a_from.m_all_entries;          82     m_all_entries = a_from.m_all_entries;
 83     m_in_range_entries = a_from.m_in_range_ent     83     m_in_range_entries = a_from.m_in_range_entries;
 84     m_in_range_Sw = a_from.m_in_range_Sw;          84     m_in_range_Sw = a_from.m_in_range_Sw;
 85     m_in_range_Sw2 = a_from.m_in_range_Sw2;        85     m_in_range_Sw2 = a_from.m_in_range_Sw2;
 86     m_in_range_Sxw = a_from.m_in_range_Sxw;        86     m_in_range_Sxw = a_from.m_in_range_Sxw;
 87     m_in_range_Sx2w = a_from.m_in_range_Sx2w;      87     m_in_range_Sx2w = a_from.m_in_range_Sx2w;
 88     return *this;                                  88     return *this;
 89   }                                                89   }
 90                                                    90 
 91   virtual ~histo_data(){}                          91   virtual ~histo_data(){}
 92 protected:                                         92 protected:
 93   void reset_fast_getters(){                       93   void reset_fast_getters(){
 94     //m_in_range_plane_Sxyw is not a fast gett     94     //m_in_range_plane_Sxyw is not a fast getter.
 95     m_all_entries = 0;                             95     m_all_entries = 0;
 96     m_in_range_entries = 0;                        96     m_in_range_entries = 0;
 97     m_in_range_Sw = 0;                             97     m_in_range_Sw = 0;
 98     m_in_range_Sw2 = 0;                            98     m_in_range_Sw2 = 0;
 99     m_in_range_Sxw.assign(m_dimension,0);          99     m_in_range_Sxw.assign(m_dimension,0);
100     m_in_range_Sx2w.assign(m_dimension,0);        100     m_in_range_Sx2w.assign(m_dimension,0);
101   }                                               101   }
102 public:                                           102 public:
103   void update_fast_getters() {                    103   void update_fast_getters() {
104     reset_fast_getters();                         104     reset_fast_getters();
105    {for(TO ibin=0;ibin<m_bin_number;ibin++) {     105    {for(TO ibin=0;ibin<m_bin_number;ibin++) {
106       if(!histo::is_out(m_axes,ibin)) {           106       if(!histo::is_out(m_axes,ibin)) {
107         m_in_range_entries += m_bin_entries[ib    107         m_in_range_entries += m_bin_entries[ibin];
108         m_in_range_Sw += m_bin_Sw[ibin];          108         m_in_range_Sw += m_bin_Sw[ibin];
109         m_in_range_Sw2 += m_bin_Sw2[ibin];        109         m_in_range_Sw2 += m_bin_Sw2[ibin];
110         for(dim_t iaxis=0;iaxis<m_dimension;ia    110         for(dim_t iaxis=0;iaxis<m_dimension;iaxis++) {
111            m_in_range_Sxw[iaxis] += m_bin_Sxw[    111            m_in_range_Sxw[iaxis] += m_bin_Sxw[ibin][iaxis];
112            m_in_range_Sx2w[iaxis] += m_bin_Sx2    112            m_in_range_Sx2w[iaxis] += m_bin_Sx2w[ibin][iaxis];
113         }                                         113         }
114       }                                           114       }
115       m_all_entries += m_bin_entries[ibin];       115       m_all_entries += m_bin_entries[ibin];
116     }}                                            116     }}
117   }                                               117   }
118                                                   118 
119   bool equals(const histo_data& a_from,const T    119   bool equals(const histo_data& a_from,const TW& a_prec,TW(*a_fabs)(TW)) const {
120     if(&a_from==this) return true;                120     if(&a_from==this) return true;
121     if(m_title!=a_from.m_title) return false;     121     if(m_title!=a_from.m_title) return false;
122     if(m_dimension!=a_from.m_dimension) return    122     if(m_dimension!=a_from.m_dimension) return false;
123     if(m_bin_number!=a_from.m_bin_number) retu    123     if(m_bin_number!=a_from.m_bin_number) return false;
124     if(m_bin_entries!=a_from.m_bin_entries) re    124     if(m_bin_entries!=a_from.m_bin_entries) return false;
125   //if(!vequ(m_bin_entries,a_from.m_bin_entrie    125   //if(!vequ(m_bin_entries,a_from.m_bin_entries)) return false;
126     if(!vectors_are_equal(m_bin_Sw,a_from.m_bi    126     if(!vectors_are_equal(m_bin_Sw,a_from.m_bin_Sw,a_prec,a_fabs)) return false;
127     if(!vectors_are_equal(m_bin_Sw2,a_from.m_b    127     if(!vectors_are_equal(m_bin_Sw2,a_from.m_bin_Sw2,a_prec,a_fabs)) return false;
128     if(!vecvecs_are_equal(m_bin_Sxw,a_from.m_b    128     if(!vecvecs_are_equal(m_bin_Sxw,a_from.m_bin_Sxw,a_prec,a_fabs)) return false;
129     if(!vecvecs_are_equal(m_bin_Sx2w,a_from.m_    129     if(!vecvecs_are_equal(m_bin_Sx2w,a_from.m_bin_Sx2w,a_prec,a_fabs)) return false;
130     if(m_axes!=a_from.m_axes) return false;       130     if(m_axes!=a_from.m_axes) return false;
131     if(!vectors_are_equal(m_in_range_plane_Sxy    131     if(!vectors_are_equal(m_in_range_plane_Sxyw,a_from.m_in_range_plane_Sxyw,a_prec,a_fabs)) return false;
132     if(m_annotations!=a_from.m_annotations) re    132     if(m_annotations!=a_from.m_annotations) return false;
133                                                   133 
134     if(m_all_entries!=a_from.m_all_entries) re    134     if(m_all_entries!=a_from.m_all_entries) return false;
135     if(m_in_range_entries!=a_from.m_in_range_e    135     if(m_in_range_entries!=a_from.m_in_range_entries) return false;
136                                                   136 
137     if(!numbers_are_equal(m_in_range_Sw,a_from    137     if(!numbers_are_equal(m_in_range_Sw,a_from.m_in_range_Sw,a_prec,a_fabs)) return false;
138     if(!numbers_are_equal(m_in_range_Sw2,a_fro    138     if(!numbers_are_equal(m_in_range_Sw2,a_from.m_in_range_Sw2,a_prec,a_fabs)) return false;
139     if(!vectors_are_equal(m_in_range_Sxw,a_fro    139     if(!vectors_are_equal(m_in_range_Sxw,a_from.m_in_range_Sxw,a_prec,a_fabs)) return false;
140     if(!vectors_are_equal(m_in_range_Sx2w,a_fr    140     if(!vectors_are_equal(m_in_range_Sx2w,a_from.m_in_range_Sx2w,a_prec,a_fabs)) return false;
141                                                   141 
142     return true;                                  142     return true;
143   }                                               143   }
144   bool equals_TH(const histo_data& a_from,cons    144   bool equals_TH(const histo_data& a_from,const TW& a_prec,TW(*a_fabs)(TW),bool a_cmp_bin_Sw2) const {
145     // used to compare with an histo built fro    145     // used to compare with an histo built from a TH stream out from a CERN-ROOT file.
146     if(&a_from==this) return true;                146     if(&a_from==this) return true;
147     if(m_title!=a_from.m_title) return false;     147     if(m_title!=a_from.m_title) return false;
148     if(m_dimension!=a_from.m_dimension) return    148     if(m_dimension!=a_from.m_dimension) return false;
149     if(m_bin_number!=a_from.m_bin_number) retu    149     if(m_bin_number!=a_from.m_bin_number) return false;
150   //if(m_bin_entries!=a_from.m_bin_entries) re    150   //if(m_bin_entries!=a_from.m_bin_entries) return false;
151     if(!vectors_are_equal(m_bin_Sw,a_from.m_bi    151     if(!vectors_are_equal(m_bin_Sw,a_from.m_bin_Sw,a_prec,a_fabs)) return false;
152     if(a_cmp_bin_Sw2) if(!vectors_are_equal(m_    152     if(a_cmp_bin_Sw2) if(!vectors_are_equal(m_bin_Sw2,a_from.m_bin_Sw2,a_prec,a_fabs)) return false;
153   //if(!vecvecs_are_equal(m_bin_Sxw,a_from.m_b    153   //if(!vecvecs_are_equal(m_bin_Sxw,a_from.m_bin_Sxw,a_prec,a_fabs)) return false;
154   //if(!vecvecs_are_equal(m_bin_Sx2w,a_from.m_    154   //if(!vecvecs_are_equal(m_bin_Sx2w,a_from.m_bin_Sx2w,a_prec,a_fabs)) return false;
155     if(m_axes!=a_from.m_axes) return false;       155     if(m_axes!=a_from.m_axes) return false;
156     if(!vectors_are_equal(m_in_range_plane_Sxy    156     if(!vectors_are_equal(m_in_range_plane_Sxyw,a_from.m_in_range_plane_Sxyw,a_prec,a_fabs)) return false;
157   //if(m_annotations!=a_from.m_annotations) re    157   //if(m_annotations!=a_from.m_annotations) return false;
158                                                   158 
159     if(m_all_entries!=a_from.m_all_entries) re    159     if(m_all_entries!=a_from.m_all_entries) return false;
160   //if(m_in_range_entries!=a_from.m_in_range_e    160   //if(m_in_range_entries!=a_from.m_in_range_entries) return false;
161                                                   161 
162     if(!numbers_are_equal(m_in_range_Sw,a_from    162     if(!numbers_are_equal(m_in_range_Sw,a_from.m_in_range_Sw,a_prec,a_fabs)) return false;
163     if(!numbers_are_equal(m_in_range_Sw2,a_fro    163     if(!numbers_are_equal(m_in_range_Sw2,a_from.m_in_range_Sw2,a_prec,a_fabs)) return false;
164   //if(!vectors_are_equal(m_in_range_Sxw,a_fro    164   //if(!vectors_are_equal(m_in_range_Sxw,a_from.m_in_range_Sxw,a_prec,a_fabs)) return false;
165   //if(!vectors_are_equal(m_in_range_Sx2w,a_fr    165   //if(!vectors_are_equal(m_in_range_Sx2w,a_from.m_in_range_Sx2w,a_prec,a_fabs)) return false;
166                                                   166 
167     return true;                                  167     return true;
168   }                                               168   }
169 public:                                           169 public:
170   // General :                                    170   // General :
171   std::string m_title;                            171   std::string m_title;
172   dim_t m_dimension;                              172   dim_t m_dimension;
173   // Bins :                                       173   // Bins :
174   TO m_bin_number;                                174   TO m_bin_number;
175   std::vector<TN> m_bin_entries;                  175   std::vector<TN> m_bin_entries;
176   std::vector<TW> m_bin_Sw;                       176   std::vector<TW> m_bin_Sw;
177   std::vector<TW> m_bin_Sw2;                      177   std::vector<TW> m_bin_Sw2;
178   std::vector< std::vector<TC> > m_bin_Sxw;       178   std::vector< std::vector<TC> > m_bin_Sxw;
179   std::vector< std::vector<TC> > m_bin_Sx2w;      179   std::vector< std::vector<TC> > m_bin_Sx2w;
180   // Axes :                                       180   // Axes :
181   std::vector<axis_t> m_axes;                     181   std::vector<axis_t> m_axes;
182   // etc :                                        182   // etc :
183   std::vector<TC> m_in_range_plane_Sxyw; // il    183   std::vector<TC> m_in_range_plane_Sxyw; // ill-defined relative to slicing, sub, div, mult operations. Handled because of CERN-ROOT.
184   std::map<std::string,std::string> m_annotati    184   std::map<std::string,std::string> m_annotations;
185   // fast getters :                               185   // fast getters :
186   TN m_all_entries; //used if reading from a R    186   TN m_all_entries; //used if reading from a ROOT file.
187   TN m_in_range_entries;                          187   TN m_in_range_entries;
188   TW m_in_range_Sw;                               188   TW m_in_range_Sw;
189   TW m_in_range_Sw2;                              189   TW m_in_range_Sw2;
190   std::vector<TC> m_in_range_Sxw;                 190   std::vector<TC> m_in_range_Sxw;
191   std::vector<TC> m_in_range_Sx2w;                191   std::vector<TC> m_in_range_Sx2w;
192 };                                                192 };
193                                                   193 
194 }}                                                194 }}
195                                                   195 
196 #endif                                            196 #endif