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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/c1d (Version 11.3.0) and /externals/g4tools/include/tools/histo/c1d (Version 6.0)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_histo_c1d                           
  5 #define tools_histo_c1d                           
  6                                                   
  7 #include "base_cloud"                             
  8                                                   
  9 #include "../mnmx"                                
 10                                                   
 11 #include "h1d"                                    
 12                                                   
 13 namespace tools {                                 
 14 namespace histo {                                 
 15                                                   
 16 class c1d : public base_cloud {                   
 17 public:                                           
 18   static const std::string& s_class() {           
 19     static const std::string s_v("tools::histo    
 20     return s_v;                                   
 21   }                                               
 22 public:                                           
 23   bool set_title(const std::string& a_title){     
 24     m_title = a_title;                            
 25     if(m_histo) m_histo->set_title(a_title);      
 26     return true;                                  
 27   }                                               
 28                                                   
 29   unsigned int dimension() const {return 1;}      
 30   bool reset() {                                  
 31     clear();                                      
 32     delete m_histo;                               
 33     m_histo = 0;                                  
 34     return true;                                  
 35   }                                               
 36   unsigned int entries() const {                  
 37     return m_histo ? m_histo->all_entries() :     
 38   }                                               
 39 public:                                           
 40   double sum_of_weights() const {                 
 41     return (m_histo ? m_histo->sum_bin_heights    
 42   }                                               
 43                                                   
 44   bool convert_to_histogram(){                    
 45     if( (m_cnv_x_num<=0) || (m_cnv_x_max<=m_cn    
 46       // Cloud min, max should be included in     
 47       double dx = 0.01 * (upper_edge() - lower    
 48       return convert(BINS(),lower_edge(),upper    
 49     } else {                                      
 50       return convert(m_cnv_x_num,m_cnv_x_min,m    
 51     }                                             
 52   }                                               
 53                                                   
 54   bool is_converted() const {return m_histo ?     
 55   bool scale(double a_scale) {                    
 56     if(m_histo) {                                 
 57       return m_histo->scale(a_scale);             
 58     } else {                                      
 59       size_t number = m_ws.size();                
 60       for(size_t index=0;index<number;index++)    
 61       m_Sw *= a_scale;                            
 62       m_Sxw *= a_scale;                           
 63       m_Sx2w *= a_scale;                          
 64       return true;                                
 65     }                                             
 66   }                                               
 67                                                   
 68   bool set_histogram(h1d* a_histo){ //we take     
 69     reset();                                      
 70     m_histo = a_histo;                            
 71     return true;                                  
 72   }                                               
 73                                                   
 74 public:                                           
 75   bool fill(double aX,double aW = 1){             
 76     if(!m_histo && (m_limit!=UNLIMITED()) &&      
 77        ((int)m_xs.size()>=m_limit)){              
 78       convert_to_histogram();                     
 79     }                                             
 80                                                   
 81     if(m_histo) {                                 
 82       return m_histo->fill(aX,aW);                
 83     } else {                                      
 84       if(m_xs.size()) {                           
 85         m_lower_x = mn<double>(aX,m_lower_x);     
 86         m_upper_x = mx<double>(aX,m_upper_x);     
 87       } else {                                    
 88         m_lower_x = aX;                           
 89         m_upper_x = aX;                           
 90       }                                           
 91       m_xs.push_back(aX);                         
 92       m_ws.push_back(aW);                         
 93       m_Sw += aW;                                 
 94       double xw = aX * aW;                        
 95       m_Sxw += xw;                                
 96       m_Sx2w += aX * xw;                          
 97       return true;                                
 98     }                                             
 99   }                                               
100                                                   
101   double lower_edge() const {                     
102     return (m_histo ? m_histo->axis().lower_ed    
103   }                                               
104   double upper_edge() const {                     
105     return (m_histo ? m_histo->axis().upper_ed    
106   }                                               
107   double value(unsigned int a_index) const {re    
108   double weight(unsigned int a_index) const {r    
109   double mean() const {                           
110     return (m_histo ? m_histo->mean() : (m_Sw?    
111   }                                               
112   double rms() const {                            
113     double _rms = 0; //FIXME nan.                 
114     if(m_histo) {                                 
115       _rms = m_histo->rms();                      
116     } else {                                      
117       if(m_Sw==0) {                               
118       } else {                                    
119         double _mean = m_Sxw / m_Sw;              
120         _rms = ::sqrt(::fabs( (m_Sx2w / m_Sw)     
121       }                                           
122     }                                             
123     return _rms;                                  
124   }                                               
125                                                   
126   bool convert(unsigned int a_bins,double a_lo    
127     if(m_histo) return true;                      
128     m_histo = new histo::h1d(base_cloud::title    
129     if(!m_histo) return false;                    
130     bool status = fill_histogram(*m_histo);       
131     clear();                                      
132     return status;                                
133   }                                               
134                                                   
135   bool convert(const std::vector<double>& a_ed    
136     if(m_histo) return true;                      
137     m_histo = new histo::h1d(base_cloud::title    
138     if(!m_histo) return false;                    
139     bool status = fill_histogram(*m_histo);       
140     clear();                                      
141     return status;                                
142   }                                               
143                                                   
144   const histo::h1d& histogram() const {           
145     if(!m_histo) const_cast<c1d&>(*this).conve    
146     return *m_histo;                              
147   }                                               
148   template <class HISTO>                          
149   bool fill_histogram(HISTO& a_histo) const {     
150     size_t number = m_xs.size();                  
151     for(size_t index=0;index<number;index++) {    
152       if(!a_histo.fill(m_xs[index],m_ws[index]    
153     }                                             
154     return true;                                  
155   }                                               
156   bool set_conversion_parameters(unsigned int     
157                                  double aCnvXm    
158     m_cnv_x_num = aCnvXnumber;                    
159     m_cnv_x_min = aCnvXmin;                       
160     m_cnv_x_max = aCnvXmax;                       
161     return true;                                  
162   }                                               
163                                                   
164 public:                                           
165   c1d()                                           
166   :base_cloud(UNLIMITED())                        
167   ,m_lower_x(0),m_upper_x(0)                      
168   ,m_Sxw(0),m_Sx2w(0)                             
169   ,m_cnv_x_num(0),m_cnv_x_min(0),m_cnv_x_max(0    
170   {}                                              
171                                                   
172   c1d(const std::string& a_title,int aLimit =     
173   :base_cloud(aLimit)                             
174   ,m_lower_x(0),m_upper_x(0)                      
175   ,m_Sxw(0),m_Sx2w(0)                             
176   ,m_cnv_x_num(0),m_cnv_x_min(0),m_cnv_x_max(0    
177   {                                               
178     set_title(a_title);                           
179   }                                               
180                                                   
181   virtual ~c1d(){delete m_histo;}                 
182 public:                                           
183   c1d(const c1d& a_from)                          
184   :base_cloud(a_from)                             
185   ,m_xs(a_from.m_xs)                              
186   ,m_lower_x(a_from.m_lower_x)                    
187   ,m_upper_x(a_from.m_upper_x)                    
188   ,m_Sxw(a_from.m_Sxw)                            
189   ,m_Sx2w(a_from.m_Sx2w)                          
190   ,m_cnv_x_num(a_from.m_cnv_x_num)                
191   ,m_cnv_x_min(a_from.m_cnv_x_min)                
192   ,m_cnv_x_max(a_from.m_cnv_x_max)                
193   ,m_histo(0)                                     
194   {                                               
195     if(a_from.m_histo) {                          
196       m_histo = new histo::h1d(*a_from.m_histo    
197     }                                             
198   }                                               
199                                                   
200   c1d& operator=(const c1d& a_from){              
201     base_cloud::operator=(a_from);                
202     if(&a_from==this) return *this;               
203     m_xs = a_from.m_xs;                           
204     m_lower_x = a_from.m_lower_x;                 
205     m_upper_x = a_from.m_upper_x;                 
206     m_Sxw = a_from.m_Sxw;                         
207     m_Sx2w = a_from.m_Sx2w;                       
208     m_cnv_x_num = a_from.m_cnv_x_num;             
209     m_cnv_x_min = a_from.m_cnv_x_min;             
210     m_cnv_x_max = a_from.m_cnv_x_max;             
211     delete m_histo;                               
212     m_histo = 0;                                  
213     if(a_from.m_histo) {                          
214       m_histo = new histo::h1d(*a_from.m_histo    
215     }                                             
216     return *this;                                 
217   }                                               
218                                                   
219 public: //AIDA API                                
220   double lowerEdge() const {return lower_edge(    
221   double upperEdge() const {return upper_edge(    
222   template <class HISTO>                          
223   bool fillHistogram(HISTO& a_histo) const {re    
224 protected:                                        
225   void clear(){                                   
226     m_lower_x = 0;                                
227     m_upper_x = 0;                                
228     m_Sw = 0;                                     
229     m_Sxw = 0;                                    
230     m_Sx2w = 0;                                   
231     m_xs.clear();                                 
232     m_ws.clear();                                 
233   }                                               
234                                                   
235 protected:                                        
236   std::vector<double> m_xs;                       
237   double m_lower_x;                               
238   double m_upper_x;                               
239   double m_Sxw;                                   
240   double m_Sx2w;                                  
241   //                                              
242   unsigned int m_cnv_x_num;                       
243   double m_cnv_x_min;                             
244   double m_cnv_x_max;                             
245   histo::h1d* m_histo;                            
246 };                                                
247                                                   
248 }}                                                
249                                                   
250 #endif