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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 10.7.p1)


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